-
Notifications
You must be signed in to change notification settings - Fork 1.5k
riscv: Fix fork() system call #12812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Forgot to save FPU, fill fix it asap |
|
This is now tested to work in protected mode, just like before, and SHOULD work with kernel stack as well, but could not test it yet. I will still test it but vfork() has some kind of a bug for kernel mode which prevents doing this. I'll look into it tomorrow. |
|
I tried this locally but |
|
Yes I noticed late last night there is an error; the child returns to userspace with kernel privileges. I did a fix but did not have time to push. FPU state is also not copied to the child. The patch is incomplete. |
f8fd331 to
e8c9576
Compare
|
@yf13 thanks for testing, I fixed the aforementioned issues; the child now returns to user space with user privileges and FPU registers are also copied to the child. |
|
@pussuw, thanks for the updates, it works here. Also I added two in-place comemnts. |
Nice! Your comments are not visible to me, maybe you need to "submit review" ? |
|
@pussuw, thanks for teaching, I submitted the reviews. Please see if they are visibile now? Sorry for inconveninces as I never added in-place comments before. |
bc74ffb to
fde44de
Compare
|
Seems that the warning with |
|
@pussuw let's rebase to the latest.master. |
The per CPU scratch register is needed by system calls -> enable it by default.
Simplifies the implementation of dispatch_syscall, making it easier to understand and maintain. Let the C-compiler do most of the work, instead of doing everything as inline assembly.
When executing fork() via a system call, the parent's stack gets corrupted by the child, as during exception return the child loads the parent's stack pointer from the context save area. This happens because the full parent stack (including what has been pushed during the system call) is copied to the child. What should be copied, is only the user stack of the parent (the kernel stack is not interesting). Fix this by only copying the parent's user stack to the child; and make the child return directly to userspace (not via dispatch_syscall).
fde44de to
aeb7447
Compare
|
Seems like some defconfigs need to be normalized after adding new Kconfig dependency |
Summary
When executing fork() via a system call, the parent's stack gets corrupted
by the child, as during exception return the child loads the parent's
stack pointer from the context save area.
This happens because the full parent stack (including what has been pushed
during the system call) is copied to the child. What should be copied, is
only the user stack of the parent (the kernel stack is not interesting).
Fix this by only copying the parent's user stack to the child; and make
the child return directly to userspace (not via dispatch_syscall).
Impact
Fixes fork() when LIB_SYSCALL=y
Testing
rv-virt:pnsh64