-
Notifications
You must be signed in to change notification settings - Fork 596
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
port to riscv64 #2234
port to riscv64 #2234
Conversation
If you did this work together with Yixue, you can add Great work! I'll take a look and review this. |
Thank you Alex! I will make the updates with Yixue tomorrow. If you'd like to test it locally, this branch should be functional with the kernel patch below, though with tons of messy commits and debugging stuff 😂 Patch: ---
arch/riscv/kernel/signal.c | 71 +++++++++++++++++++++++++++++++-------
1 file changed, 58 insertions(+), 13 deletions(-)
diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c
index 9aff9d720590..01ccb949d26e 100644
--- a/arch/riscv/kernel/signal.c
+++ b/arch/riscv/kernel/signal.c
@@ -16,6 +16,7 @@
#include <asm/ucontext.h>
#include <asm/vdso.h>
+#include <asm/syscall.h>
#include <asm/signal.h>
#include <asm/signal32.h>
#include <asm/switch_to.h>
@@ -284,35 +285,79 @@ static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
void arch_do_signal_or_restart(struct pt_regs *regs)
{
+ unsigned long continue_addr = 0, restart_addr = 0;
+ int retval = 0;
struct ksignal ksig;
-
- if (get_signal(&ksig)) {
- /* Actually deliver the signal */
- handle_signal(&ksig, regs);
- return;
- }
+ bool syscall = (regs->cause == EXC_SYSCALL);
/* Did we come from a system call? */
- if (regs->cause == EXC_SYSCALL) {
+ if (syscall) {
+ continue_addr = regs->epc;
+ restart_addr = continue_addr - 4;
+ retval = regs->a0;
+
/* Avoid additional syscall restarting via ret_from_exception */
regs->cause = -1UL;
- /* Restart the system call - no handlers present */
- switch (regs->a0) {
+ /*
+ * Prepare for system call restart. We do this here so that a
+ * debugger will see the already changed PC.
+ */
+ switch (retval) {
case -ERESTARTNOHAND:
case -ERESTARTSYS:
case -ERESTARTNOINTR:
- regs->a0 = regs->orig_a0;
- regs->epc -= 0x4;
+ regs->a0 = regs->orig_a0;
+ regs->epc = restart_addr;
break;
case -ERESTART_RESTARTBLOCK:
- regs->a0 = regs->orig_a0;
+ regs->a0 = regs->orig_a0;
regs->a7 = __NR_restart_syscall;
- regs->epc -= 0x4;
+ regs->epc = restart_addr;
break;
}
}
+ // printk("~RISCV~ Before get_signal: a7 = %ld, a0 = %ld, orig_a0 = %ld, cause = %ld\n",
+ // regs->a7, regs->a0, regs->orig_a0, regs->cause);
+
+ /*
+ * Get the signal to deliver. When running under ptrace, at this point
+ * the debugger may change all of our registers.
+ */
+ if (get_signal(&ksig)) {
+ /*
+ * Depending on the signal settings, we may need to revert the
+ * decision to restart the system call, but skip this if a
+ * debugger has chosen to restart at a different PC.
+ */
+ if (regs->epc == restart_addr &&
+ (retval == -ERESTARTNOHAND ||
+ retval == -ERESTART_RESTARTBLOCK ||
+ (retval == -ERESTARTSYS &&
+ !(ksig.ka.sa.sa_flags & SA_RESTART)))) {
+ syscall_set_return_value(current, regs, -EINTR, 0);
+ regs->epc = continue_addr;
+ }
+
+ /* Actually deliver the signal */
+ handle_signal(&ksig, regs);
+ return;
+ }
+
+ // printk("~RISCV~ After get_signal: a7 = %ld, a0 = %ld, orig_a0 = %ld, cause = %ld\n",
+ // regs->a7, regs->a0, regs->orig_a0, regs->cause);
+
+ /*
+ * Handle restarting a different system call. As above, if a debugger
+ * has chosen to restart at a different PC, ignore the restart.
+ */
+ if (syscall && regs->epc == restart_addr) {
+ if (retval == -ERESTART_RESTARTBLOCK)
+ regs->a7 = __NR_restart_syscall;
+ // user_rewind_single_step(current);
+ }
+
/*
* If there is no signal to deliver, we just put the saved
* sigmask back. Copied from my gitter msg:
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## criu-dev #2234 +/- ##
============================================
+ Coverage 70.21% 70.23% +0.02%
============================================
Files 132 131 -1
Lines 34372 34370 -2
============================================
+ Hits 24134 24141 +7
+ Misses 10238 10229 -9 ☔ View full report in Codecov by Sentry. |
46eac0c
to
0f38ebf
Compare
Update: The @mihalicyn, I have a small question about running make lint locally. I'm experiencing many more errors with flake8 on my side, even after reverting to the version used by CI (flake8 == 5.0.3). Do you have any idea what might be causing this difference? Thanks! haorong at haorong:/criu [riscv64-upstream]$ make lint
flake8 --version
5.0.3 (mccabe: 0.7.0, pycodestyle: 2.9.1, pyflakes: 2.5.0, tryceratops: 2.3.2) CPython 3.10.4 on Linux
flake8 --config=scripts/flake8.cfg test/zdtm.py
test/zdtm.py:492:13: TRY200 Use 'raise from' to specify exception cause
test/zdtm.py:550:13: TRY003 Avoid specifying long messages outside the exception class
test/zdtm.py:590:17: TRY003 Avoid specifying long messages outside the exception class
test/zdtm.py:648:13: TRY003 Avoid specifying long messages outside the exception class
test/zdtm.py:979:13: TRY003 Avoid specifying long messages outside the exception class
test/zdtm.py:981:13: TRY003 Avoid specifying long messages outside the exception class
test/zdtm.py:983:13: TRY003 Avoid specifying long messages outside the exception class
test/zdtm.py:998:21: TRY003 Avoid specifying long messages outside the exception class
test/zdtm.py:1276:13: TRY003 Avoid specifying long messages outside the exception class
test/zdtm.py:1489:17: TRY300 Consider moving this statement to an 'else' block
test/zdtm.py:1664:17: TRY201 Simply use 'raise' without specifying exception object again
test/zdtm.py:1687:13: TRY003 Avoid specifying long messages outside the exception class
test/zdtm.py:1700:17: TRY003 Avoid specifying long messages outside the exception class
test/zdtm.py:1713:13: TRY003 Avoid specifying long messages outside the exception class
test/zdtm.py:1722:13: TRY003 Avoid specifying long messages outside the exception class
test/zdtm.py:1937:21: TRY003 Avoid specifying long messages outside the exception class
test/zdtm.py:2011:17: TRY002 Create your own exception
test/zdtm.py:2040:13: TRY002 Create your own exception
test/zdtm.py:2113:17: TRY201 Simply use 'raise' without specifying exception object again
test/zdtm.py:2230:13: TRY003 Avoid specifying long messages outside the exception class
test/zdtm.py:2363:13: TRY002 Create your own exception
test/zdtm.py:2363:13: TRY003 Avoid specifying long messages outside the exception class
test/zdtm.py:2368:13: TRY002 Create your own exception
test/zdtm.py:2368:13: TRY003 Avoid specifying long messages outside the exception class
test/zdtm.py:2374:13: TRY002 Create your own exception
test/zdtm.py:2374:13: TRY003 Avoid specifying long messages outside the exception class
test/zdtm.py:2628:9: TRY300 Consider moving this statement to an 'else' block
make: *** [Makefile:439: lint] Error 1 |
0f38ebf
to
d14fe95
Compare
d14fe95
to
7ad7f13
Compare
Port upstream riscv64 support pull request: checkpoint-restore/criu#2234 Applies loongarch64 support as well so patches don't fail.
Port upstream riscv64 support pull request: checkpoint-restore/criu#2234 Applies loongarch64 support as well so patches don't fail.
A friendly reminder that this PR had no activity for 30 days. |
Really sorry for the delay. The past two months turned out to be more "fast-paced" than I had anticipated, and the riscv ubuntu VM I've been using for development got messed up after I installed a buggy kernel :( This led me to somewhat negatively sideline this PR and the corresponding kernel patch. Fortunately, I dug out an old VM snapshot from deep in my hard drive and successfully restored it to a dev-ready state today. I'll return to the PR as soon as my work schedule lightens up. Thanks for your patience and continued support! 🙏 |
The patch is fetched from https://github.com/Cryolitia-Forks/criu/compare/c2b48ff423aa663b3534a5ba96907366e4c1b408..fcac93c764fac7e283e33ac4cb4d9c95770c444a.patch Originally based on checkpoint-restore/criu#2234 , rebasing the PR on v4.0 - Change return page size to unsigned long for riscv64 Link: checkpoint-restore/criu@28adebe - dump+restore: Implement membarrier() registration c/r. for riscv64 Link: checkpoint-restore/criu@e07155e - include: don't use GCC's __builtin_ffs on riscv64 to fix link failure
Hello, sorry for bother. Is there any progress? I have rebased and fixed this PR on v4.0, in my repo: https://github.com/Cryolitia-Forks/criu/tree/ricv64 Hope this PR can be merged eventually. best wishes. |
The patch is fetched from https://github.com/Cryolitia-Forks/criu/compare/c2b48ff423aa663b3534a5ba96907366e4c1b408..fcac93c764fac7e283e33ac4cb4d9c95770c444a.patch Originally based on checkpoint-restore/criu#2234 , rebasing the PR on v4.0 - Change return page size to unsigned long for riscv64 Link: checkpoint-restore/criu@28adebe - dump+restore: Implement membarrier() registration c/r. for riscv64 Link: checkpoint-restore/criu@e07155e - include: don't use GCC's __builtin_ffs on riscv64 to fix link failure
The patch is fetched from https://github.com/Cryolitia-Forks/criu/compare/c2b48ff423aa663b3534a5ba96907366e4c1b408..fcac93c764fac7e283e33ac4cb4d9c95770c444a.patch Originally based on checkpoint-restore/criu#2234 , rebasing the PR on v4.0 - Change return page size to unsigned long for riscv64 Link: checkpoint-restore/criu@28adebe - dump+restore: Implement membarrier() registration c/r. for riscv64 Link: checkpoint-restore/criu@e07155e - include: don't use GCC's __builtin_ffs on riscv64 to fix link failure
@Cryolitia I will find time this week to review this series. |
91d3cfd
to
05a0f54
Compare
Hey @Cryolitia, thanks for your work on this! I see that in your branch you also have some fixes on top and support for I'll update this PR myself (rebase and make small adjustments to make linter happy) as it's easier. |
Of course sure you could. Feel free to use it just keep me as co-author. ^_^ I'm afraid of that these fix are needed for criu to successfully build, at least on Arch Linix RISC-V. |
no doubt. All your authorship on the commits will be kept. ;-) |
be0cc47
to
629e6d3
Compare
Hey @Cryolitia, please, can you add |
It's worth mentioning that we have a signal issue (described in #2234 (comment)) fix in the kernel torvalds/linux@ce4f78f thanks to Haorong Lu (@ancientmodern). |
sure, all done |
Co-authored-by: Yixue Zhao <felicitia2010@gmail.com> Co-authored-by: stove <stove@rivosinc.com> Signed-off-by: Haorong Lu <ancientmodern4@gmail.com> --- - rebased - imported a page_size() type fix (authored by Cryolitia PukNgae) Signed-off-by: PukNgae Cryolitia <Cryolitia@gmail.com> Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
Co-authored-by: Yixue Zhao <felicitia2010@gmail.com> Co-authored-by: stove <stove@rivosinc.com> Signed-off-by: Haorong Lu <ancientmodern4@gmail.com> --- - rebased - added a membarrier() to syscall table (fix authored by Cryolitia PukNgae) Signed-off-by: PukNgae Cryolitia <Cryolitia@gmail.com> Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
Co-authored-by: Yixue Zhao <felicitia2010@gmail.com> Co-authored-by: stove <stove@rivosinc.com> Signed-off-by: Haorong Lu <ancientmodern4@gmail.com>
Co-authored-by: Yixue Zhao <felicitia2010@gmail.com> Co-authored-by: stove <stove@rivosinc.com> Signed-off-by: Haorong Lu <ancientmodern4@gmail.com>
Signed-off-by: Haorong Lu <ancientmodern4@gmail.com>
Signed-off-by: Haorong Lu <ancientmodern4@gmail.com>
629e6d3
to
467ee1b
Compare
Link: SerenityOS/serenity@e300da4 Signed-off-by: PukNgae Cryolitia <Cryolitia@gmail.com> --- - cherry-picked Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
I'm currently playing with this one on a real hardware:
Getting the following error:
I'll sort this stuff out. |
Ok, I know what's wrong with this
We have hardcoded
but my MMU is SV39. I should improve this logic to detect MMU and choose a proper |
and... this:
should be fixed before. |
In general, I think we can merge this as it is for now (with only support for SV48 MMU). But I'll have to do some improvements on top to support cheaper SV39 MMU and more modern SV57. But we are pretty limited in access to hardware now and sometimes we have to move blindly... |
I'm sorry that I don't have much developing experience on kernel, but if you need more riscv64 hardware for simple testing. We (PLCT Lab) have A truckload of various riscv64 hardware from HiFive Unmatched, LicheePi 4A to SG2042. Feel free to tell me if it's needed. I pay my highest respects to your work. |
Thanks to all involved in this work. This is a great starting point. |
Add riscv64 support to CRIU. Hopefully solve issue #1702
Present status of zdtm tests:
@mihalicyn @felicitia for you reference
WIP: I'll enrich this pull request with more details by tomorrow. And some sections might have been affected when I removed debug info from our code :)