From: Hajime Tazaki <thehajime@gmail.com>
To: benjamin@sipsolutions.net
Cc: linux-um@lists.infradead.org, ricarkol@google.com,
Liam.Howlett@oracle.com
Subject: Re: [PATCH v6 00/13] nommu UML
Date: Thu, 16 Jan 2025 19:09:38 +0900 [thread overview]
Message-ID: <m2jzav3w9p.wl-thehajime@gmail.com> (raw)
In-Reply-To: <6060a0e25f2b7903002e55182230da09c702b0e4.camel@sipsolutions.net>
Hello,
On Wed, 15 Jan 2025 18:30:41 +0900,
Benjamin Berg wrote:
> > > Maybe I am missing it, but I do not yet see proper FP register
> > > handling. This will be needed for task/thread switches and also signal
> > > emission/sigreturn. I am attaching the test program that I used to
> > > verify the correct behaviour when dealing with the recent changes to FP
> > > register handling in UML.
> >
> > thanks for the test program.
> >
> > I didn't address your comment on FP register handling as I couldn't
> > see any reproducer that causes the issue you raised (and maybe didn't
> > understand well the problem) so, the attached program helps a lot.
>
> Note that it doesn't directly test task/thread switches which only
> happen due to normal scheduling (i.e. via SIGALRM). So, it doesn't
> cover everything, but syscalls and signals are quite important by
> themselves. For normal UML both cases hit the same codepath, but I
> think in your case the SIGALRM entry point differs and should be tested
> separately.
indeed, scheduling works a different in nommu from normal UML.
> > Though nommu code only works with musl-libc, which I cannot use that
> > as-is, now I see what you meant with the first function, test_fp().
> >
> > (none):/# /root/test-signal-restore
> > pre-signal: 0.5
> > post-signal: 0.5
> > floating point register was not manipulated
> >
> > Tests on task switch (test_fp_ptrace) might need more work for me as
> > nommu only works with vfork(2) and vfork without exec(2) may not test
> > well on the implementation.
>
> Not sure you even have a working ptrace in nommu?
I don't think so.
> That reminds me. Please set arch_has_single_step to zero for nommu
> mode. If you figure out how to set the appropriate bit in EFLAGS when
> returning to userspace, then that would also work.
thanks, I'll fix this in the next revision.
> > and also I'm wishing to have this kind of useful tests as a reusable
> > way; as now I'm going to add a new configuration for UML, you're also
> > going for another SECCOMP mode over MMU, we may have at least 3
> > running modes for UML, which I think we should share the test
> > framework that we should pass. Not sure how it should be but using
> > Kunit is the first thing in my mind.
>
> My problem was, that I didn't know of a good place to put it. We could
> probably drop this test into tools/testing/selftests/x86, but how is it
> run then?
> As for kunit, that would be neat, but I it seems a bit more complicated
> to run userspace code from within the kernel.
thanks for sharing your experience.
I'll look for some nice place; for the moment, I would work with a
private/local environment.
for the fp register handling on syscall/signal, it is going to be like
this, not fully tested/verified yet though. with this, single syscall
adds 80 nsec delay (in my environment), which seems reasonable to me.
diff --git a/arch/x86/um/nommu/do_syscall_64.c b/arch/x86/um/nommu/do_syscall_64.c
index 796beb0089fc..48b3d29e2db1 100644
--- a/arch/x86/um/nommu/do_syscall_64.c
+++ b/arch/x86/um/nommu/do_syscall_64.c
@@ -48,6 +48,9 @@ __visible void do_syscall_64(struct pt_regs *regs)
/* set fs register to the original host one */
os_x86_arch_prctl(0, ARCH_SET_FS, (void *)host_fs);
+ /* save fp registers */
+ asm volatile("fxsaveq %0" : "=m"(*(struct _xstate *)regs->regs.fp));
+
if (likely(syscall < NR_syscalls)) {
PT_REGS_SET_SYSCALL_RETURN(regs,
EXECUTE_SYSCALL(syscall, regs));
@@ -66,6 +69,9 @@ __visible void do_syscall_64(struct pt_regs *regs)
set_thread_flag(TIF_SIGPENDING);
interrupt_end();
+ /* restore fp registers */
+ asm volatile("fxrstorq %0" : : "m"((current->thread.regs.regs.fp)));
+
/* restore back fs register to userspace configured one */
os_x86_arch_prctl(0, ARCH_SET_FS,
(void *)(current->thread.regs.regs.gp[FS_BASE
diff --git a/arch/x86/um/shared/sysdep/ptrace.h b/arch/x86/um/shared/sysdep/ptrace.h
index 8f7476ff6e95..7d553d9f05be 100644
--- a/arch/x86/um/shared/sysdep/ptrace.h
+++ b/arch/x86/um/shared/sysdep/ptrace.h
@@ -65,7 +65,7 @@ struct uml_pt_regs {
int is_user;
/* Dynamically sized FP registers (holds an XSTATE) */
- unsigned long fp[];
+ unsigned long fp[] __attribute__((aligned(16)));
};
-- Hajime
prev parent reply other threads:[~2025-01-16 10:09 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-14 11:30 [PATCH v6 00/13] nommu UML Hajime Tazaki
2025-01-14 11:30 ` [PATCH v6 01/13] x86/um: clean up elf specific definitions Hajime Tazaki
2025-01-14 11:30 ` [PATCH v6 02/13] x86/um: nommu: elf loader for fdpic Hajime Tazaki
2025-01-14 11:30 ` [PATCH v6 03/13] um: decouple MMU specific code from the common part Hajime Tazaki
2025-01-14 11:30 ` [PATCH v6 04/13] um: nommu: memory handling Hajime Tazaki
2025-01-14 11:30 ` [PATCH v6 05/13] x86/um: nommu: syscall handling Hajime Tazaki
2025-01-14 11:30 ` [PATCH v6 06/13] um: nommu: seccomp syscalls hook Hajime Tazaki
2025-01-14 11:30 ` [PATCH v6 07/13] x86/um: nommu: process/thread handling Hajime Tazaki
2025-01-14 11:30 ` [PATCH v6 08/13] um: nommu: configure fs register on host syscall invocation Hajime Tazaki
2025-01-14 11:30 ` [PATCH v6 09/13] x86/um/vdso: nommu: vdso memory update Hajime Tazaki
2025-01-14 11:30 ` [PATCH v6 10/13] x86/um: nommu: signal handling Hajime Tazaki
2025-01-14 11:30 ` [PATCH v6 11/13] um: change machine name for uname output Hajime Tazaki
2025-01-14 11:30 ` [PATCH v6 12/13] um: nommu: add documentation of nommu UML Hajime Tazaki
2025-01-14 11:30 ` [PATCH v6 13/13] um: nommu: plug nommu code into build system Hajime Tazaki
2025-01-14 18:53 ` [PATCH v6 00/13] nommu UML Benjamin Berg
2025-01-15 0:25 ` Hajime Tazaki
2025-01-15 9:30 ` Benjamin Berg
2025-01-16 10:09 ` Hajime Tazaki [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2jzav3w9p.wl-thehajime@gmail.com \
--to=thehajime@gmail.com \
--cc=Liam.Howlett@oracle.com \
--cc=benjamin@sipsolutions.net \
--cc=linux-um@lists.infradead.org \
--cc=ricarkol@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.