cloudius-systems / osv

OSv, a new operating system for the cloud.
osv.io
Other
4.12k stars 605 forks source link

Implement arch_prctl syscall to support statically linked executables #1260

Closed wkozaczuk closed 1 year ago

wkozaczuk commented 1 year ago

This PR implements the arch_prctl syscall and makes other changes to support switching the FS register between the application and kernel TCB when running statically linked executables.

In essence, it makes it possible to launch simple statically linked executables like "Hello World" on OSv:

gcc -static -o hello-static-non-pie hello.c

./scripts/run.py -e /hello-static-non-pie
OSv v0.57.0-69-g053fc914
eth0: 192.168.122.15
Booted up in 193.02 ms
Cmdline: /hello-static-pie
WARNING: Statically linked executables are only supported to limited extent!
syscall(): unimplemented system call 218
syscall(): unimplemented system call 273
syscall(): unimplemented system call 334
syscall(): unimplemented system call 302
syscall(): unimplemented system call 89
syscall(): unimplemented system call 10
Hello from C code

Please note, that the code changes touch some critical places of the kernel functionality - context switching, syscall handling, exception handling, and VDSO implementation.

As far as context switching goes, this patch adds only a handful of memory read/write operations that do not seem to affect it in any measurable way based on what the misc-ctxsw.cc indicates.

On the other hand, one could see the syscall handling cost go up by 6 - 10 ns (6-10% of the total cost based on what misc-syscall-perf.cc measures) when executing statically linked executables due to the fact we need to switch the fsbase and turn interrupts off and on twice. The good news is that the syscall handling does not seem to be affected in any significant way when running dynamically linked executables.

Finally, I did not measure the impact of changes to the exception handling (interrupts, page faults, etc) but I think it should be lower than syscall handling given we do not need to turn interrupts on and off. Also, we should not see any impact when running dynamically linked executables.

Depends on https://github.com/cloudius-systems/osv/pull/1254 Closes #1137

wkozaczuk commented 1 year ago

Closing this one in lieu of the new one #1267 and another future one with an updated code to support switching between app and kernel TCB (the 2nd commit of this PR).

nyh commented 1 year ago

Closing this one in lieu of the new one #1267 and another future one with an updated code to support switching between app and kernel TCB (the 2nd commit of this PR).

Please take a look at my comments above, if they are still relevant in your new version.

wkozaczuk commented 1 year ago

Yes, I have addressed your comments in the new version.