Conversation
According to the scripts/syscall.tbl in the Linux kernel source code, there were some errors in the host syscall table: - rt_sigalstack is not the correct syscall name, it is sigalstack instead - getrlimit and statfs are not lagacy syscalls This fixs them. Change-Id: Ia2a1b5c7f5faa98f0b84a4cf5e70e16c944e4136
3f51fdf to
f37bb13
Compare
This commit does the following things: - Support the riscv64 by reusing the aarch64 syscalls - Disable link time relaxation of riscv64 to reduce link time - Fetch the correct rootfs in build script Closed sysprog21#18 Change-Id: I271ce08e569f5947acbd75626c54b7fae9f0ce39
f37bb13 to
d8d82b1
Compare
|
#21 concerns the system call overhead in kbox, which has been observed to be as high as 33× compared to native (bare-metal) execution. Addressing this overhead is a prerequisite for improving overall system performance. To this end, I plan to prioritize closing #21 by exploring a solution based on binary rewriting. Given current infrastructure constraints and to ensure efficient validation, the initial implementation will focus on x86-64 and arm64 architectures, both of which are fully supported by the machines provided through GitHub Actions. After the proposed solution has been thoroughly implemented and validated on these architectures, we can proceed to extend support to RISC-V. |
| { \ | ||
| (unsigned short) (c), (unsigned char) (t), (unsigned char) (f), \ | ||
| (unsigned int) (val) \ | ||
| } |
There was a problem hiding this comment.
Looks like unrelated style changes?
Please keep the changes to a minimum.
Otherwise, this will make git blame messy.
There was a problem hiding this comment.
This change was made because the source code wasn't properly formatted with clang-format, which caused it to be blocked by the new commit-hook. Did you mean I have to separate it to another commit?
There was a problem hiding this comment.
Ideally, a single patch should contain only one logical change.
However, it looks like this patch is doing two things:
- Fixing a pre-existing clang-format error.
- Adding RISC-V support.
So, yes, I would prefer splitting this into two patches.
| const struct kbox_host_nrs *host_nrs = &HOST_NRS_X86_64; | ||
| #elif defined(__aarch64__) | ||
| #elif defined(__aarch64__) || (defined(__riscv) && __riscv_xlen == 64) | ||
| const struct kbox_host_nrs *host_nrs = &HOST_NRS_AARCH64; |
There was a problem hiding this comment.
Reusing the HOST_NRS_AARCH64 struct directly for RISC-V is semantically confusing for future maintenance. Maybe consider adding a preparatory refactoring patch to rename it to something more generic before wiring up RISC-V support?
This PR did the following things:
According to the kernel document[1], syscalls are specified in
arch/*/kernel/Makefile.syscallsandscripts/syscall.tbl.It is found that all the aarch64 host syscalls used in kbox has either common, 64 or rlimit tag in
scripts/syscall.tbl[2], which means riscv64 share the same host syscall table.Also, there are two errors found in the host syscall table. (Also according to
scripts/syscall.tbl[2]):The build script of rootfs is updated, so the following command can produce a usable alpine.ext4:
For the
fetch-lkl.shscript, the riscv64 support is added. However, the pre-built lkl binary has to be updated on GitHub (The github action has to be updated), so for now, it can only be compiled by explicitly assigning the LKL path in the config. The LKL build process is as follows (on x86-64 ubuntu 24.04):With the LKL path set in the config, the following command can successfully build the kbox:
The compiled kbox is successfully run on QEMU and execute /bin/sh.[3]
[1] https://docs.kernel.org/process/adding-syscalls.html#since-6-11
[2] https://github.com/torvalds/linux/blob/master/scripts/syscall.tbl
[3] https://hackmd.io/@rota1001/kbox-rv64#Run-it-on-riscv64
Summary by cubic
Adds riscv64 support by reusing the
aarch64host syscall table and updating build scripts for the correct Alpine rootfs. Also fixes host syscall table errors and speeds up riscv64 linking.New Features
HOST_NRS_AARCH64; apply seccomp filter for riscv64; add audit arch0xc00000f3.fetch-lkl.shandmkrootfs.sh; include Alpineriscv64SHA256; disable link-time relaxation with-Wl,--no-relax.riscv64as a supported architecture in README.Bug Fixes
sigaltstack(notrt_sigaltstack) in dispatch and host syscall tables.aarch64syscall numbers:getrlimit=163,statfs=43.Written for commit d8d82b1. Summary will update on new commits.