]> xenbits.xensource.com Git - unikraft/unikraft.git/commit
{lib,arch,plat}: Redo syscall ctx's and `swapgs` logic
authorSergiu Moga <sergiu@unikraft.io>
Sun, 3 Mar 2024 15:00:20 +0000 (17:00 +0200)
committerUnikraft Bot <monkey@unikraft.io>
Fri, 31 May 2024 13:45:34 +0000 (13:45 +0000)
commitc716bcca48223321f943b7d3d56fb411699e3ad6
tree0b3b166695fd58b60f7da105c0e794bc742b8139
parent67cefa3cbabf01e0ec43abd183f4f0345cf59b67
{lib,arch,plat}: Redo syscall ctx's and `swapgs` logic

To make git bisecting and rebasing significantly easier and avoid
builds breaking across commits, this whole set of changes shall be
introduced under one single all encompassing commit.

Following the introduction of the concept of auxiliary stack pointers,
swapgs, `struct uk_syscall_ctx` and `struct ukarch_sysregs`, a number
of things have emerged:
- the aforemenetioned structs are very generic so they should be moved
under libcontext (arch/)
- swapgs introduces a significant inconsistency between ARM64 and x86_64
as we never know during an exception the state of
MSR_GS_BASE/MSR_KERNEL_GS_BASE
- auxiliary stack pointers  have increased flexibility as every thread
and LCPU can have one and have private data stored in there than may
be accessed anytime, dependency free

Thus, this commit does the following:
1. Move/rename aforementioned structured to libcontext and document them
- lib/syscall_shim/arch/x86_64/sysregs.c -> arch/x86/sysctx.c
- lib/syscall_shim/arch/x86_64include/arch/sysregs.h -> arch/x86/x86_64include/uk/asm/sysctx.h
- s/struct ukarch_sysregs/struct ukarch_sysctx/ (and all related defs)
- struct uk_syscall_ctx from lib/syscall_shim/include/uk/syscall.h to
include/uk/arch/ctx.h as struct ukarch_execenv
- s/struct uk_syscall_ctx/struct ukarch_execenv/ (and all related defs)
- actually comment these functions
- re-adjust all places that make use of such definitions

2. Get rid of the `swapgs`, architecture specific holdback by exploiting
the flexibility of auxiliary stacks through the introduction of a new
always existing contrl block at their top end:
- introduce `struct ukarch_auxspcb` under libcontext
- add Unikraft system context as field to it so that we always have and
know Unikraft TLS (and LCPU in case ox x86_64) in a dependency free
and assumption free manner
- add a current frame pointer field: since the auxspscb will be part of
the auxiliary stack, we need to know the safe place where we can start
using the auxiliary stack area as a stack (this is also helpful in cases
where we need to nest on the auxstack)
-for the aforementione fields/structs, init/getter/setter functions have
been added and documented
- now the `swapgs` pair will only be done very early during system call
entry (and only there, not on clone child exit anymore either) just
enough so that we, first things first, switch to auxstack and push auxsp
so that on entry to C handler we will know that we must do a call to
`ukarch_sysctx_load` on the Unikraft sysctx we can get from the pushed
auxsp (another benefit of this is we get rid of MSR read/writes)

IMPORTANT NOTE: Additionally, some minor fixes have been made:
- Do not switch stack pointer to execenv pointer (previously
known as uk_syscall_ctx) during execenv loading as this implies that
functions such as `ukarch_ectx_load` or `ukarch_sysctx_load` would reuse
the space after the execenv as stack. While this is safe if the
execenv was passed through the stack, is definetely not safe if it was
passed through something like a heap buffer that may be bounded to the
execenv size by the caller. Instead, use one of the callee-saved
registers
- Set IRQ flag of the pushed flags of the caller during system call
early assembly entry (both native and binary for both architectures)
so that we don't have to explicitly set it during something like clone
child creation. This also reflects the reality better as no syscall
caller will have IRQ's disabled.
- Do not use spsr_el1, esr_el1 and elr_el1 during native system call
assembly prologue (UK_SYSCALL_EXECENV_PROLOGUE_DEFINE) on Arm, as they
are invalid because there is no actual SVC/exception happening. Instead,
try to emulate it by manually building sane values for them on the
created execenv to replicate an actual SVC while benefitting from not
dealing with the performance impacting flow of actually taking a SVC.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Simon Kuenzer <simon.kuenzer@unikraft.io>
GitHub-Closes: #1346
49 files changed:
arch/arm/Makefile.uk
arch/arm/arm64/execenv.S [new file with mode: 0644]
arch/arm/arm64/include/uk/asm/sysctx.h [new file with mode: 0644]
arch/arm/ctx.c
arch/arm/sysctx.c [new file with mode: 0644]
arch/x86/Makefile.uk
arch/x86/ctx.c
arch/x86/sysctx.c [new file with mode: 0644]
arch/x86/x86_64/execenv.S [new file with mode: 0644]
arch/x86/x86_64/include/uk/asm/sysctx.h [new file with mode: 0644]
include/uk/arch/ctx.h
include/uk/plat/syscall.h
lib/posix-process/Makefile.uk
lib/posix-process/arch/arm64/clone.c
lib/posix-process/arch/arm64/include/arch/clone.h
lib/posix-process/arch/x86_64/clone.c
lib/posix-process/arch/x86_64/include/arch/clone.h
lib/posix-process/clone.c
lib/posix-process/exportsyms.uk
lib/syscall_shim/Makefile.uk
lib/syscall_shim/arch/arm64/include/arch/regmap_usc.h [deleted file]
lib/syscall_shim/arch/arm64/include/arch/syscall_prologue.h
lib/syscall_shim/arch/arm64/include/arch/sysregs.h [deleted file]
lib/syscall_shim/arch/arm64/syscall_ctx.S [deleted file]
lib/syscall_shim/arch/arm64/sysregs.c [deleted file]
lib/syscall_shim/arch/regmap_linuxabi.h
lib/syscall_shim/arch/x86_64/include/arch/regmap_usc.h [deleted file]
lib/syscall_shim/arch/x86_64/include/arch/syscall_prologue.h
lib/syscall_shim/arch/x86_64/include/arch/sysregs.h [deleted file]
lib/syscall_shim/arch/x86_64/syscall_ctx.S [deleted file]
lib/syscall_shim/arch/x86_64/sysregs.c [deleted file]
lib/syscall_shim/include/uk/syscall.h
lib/syscall_shim/syscall_provided.awk
lib/syscall_shim/syscall_r_static.awk
lib/syscall_shim/syscall_stubs.awk
lib/syscall_shim/uk_syscall6_r.awk
lib/syscall_shim/uk_syscall_binary.c
lib/ukboot/boot.c
lib/uksched/thread.c
plat/common/arm/traps_arm64.c
plat/common/include/uk/plat/common/lcpu.h
plat/common/lcpu.c
plat/common/x86/lcpu.c
plat/common/x86/syscall.S
plat/kvm/arm/exceptions.S
plat/kvm/arm/lcpu.c
plat/kvm/x86/lcpu.c
plat/xen/lcpu.c
support/scripts/checkpatch.pl