* [PATCH] um: add back support for FXSAVE registers
@ 2024-12-04 7:48 Benjamin Berg
2025-01-07 21:07 ` SeongJae Park
0 siblings, 1 reply; 3+ messages in thread
From: Benjamin Berg @ 2024-12-04 7:48 UTC (permalink / raw)
To: linux-um; +Cc: Benjamin Berg, SeongJae Park
From: Benjamin Berg <benjamin.berg@intel.com>
It was reported that qemu may not enable the XSTATE CPU extension, which
is a requirement after commit 3f17fed21491 ("um: switch to regset API
and depend on XSTATE"). Add a fallback to use FXSAVE (FP registers on
x86_64 and XFP on i386) which is just a shorter version of the same
data. The only difference is that the XSTATE magic should not be set in
the signal frame.
Note that this still drops support for the older i386 FP register layout
as supporting this would require more backward compatibility to build a
correct signal frame.
Fixes: 3f17fed21491 ("um: switch to regset API and depend on XSTATE")
Reported-by: SeongJae Park <sj@kernel.org>
Closes: https://lore.kernel.org/r/20241203070218.240797-1-sj@kernel.org
Tested-by: SeongJae Park <sj@kernel.org>
Signed-off-by: Benjamin Berg <benjamin.berg@intel.com>
---
arch/x86/um/os-Linux/registers.c | 21 ++++++++++++++++++---
arch/x86/um/signal.c | 5 +++++
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/arch/x86/um/os-Linux/registers.c b/arch/x86/um/os-Linux/registers.c
index 76eaeb93928c..eb1cdadc8a61 100644
--- a/arch/x86/um/os-Linux/registers.c
+++ b/arch/x86/um/os-Linux/registers.c
@@ -18,6 +18,7 @@
#include <registers.h>
#include <sys/mman.h>
+static unsigned long ptrace_regset;
unsigned long host_fp_size;
int get_fp_registers(int pid, unsigned long *regs)
@@ -27,7 +28,7 @@ int get_fp_registers(int pid, unsigned long *regs)
.iov_len = host_fp_size,
};
- if (ptrace(PTRACE_GETREGSET, pid, NT_X86_XSTATE, &iov) < 0)
+ if (ptrace(PTRACE_GETREGSET, pid, ptrace_regset, &iov) < 0)
return -errno;
return 0;
}
@@ -39,7 +40,7 @@ int put_fp_registers(int pid, unsigned long *regs)
.iov_len = host_fp_size,
};
- if (ptrace(PTRACE_SETREGSET, pid, NT_X86_XSTATE, &iov) < 0)
+ if (ptrace(PTRACE_SETREGSET, pid, ptrace_regset, &iov) < 0)
return -errno;
return 0;
}
@@ -58,9 +59,23 @@ int arch_init_registers(int pid)
return -ENOMEM;
/* GDB has x86_xsave_length, which uses x86_cpuid_count */
- ret = ptrace(PTRACE_GETREGSET, pid, NT_X86_XSTATE, &iov);
+ ptrace_regset = NT_X86_XSTATE;
+ ret = ptrace(PTRACE_GETREGSET, pid, ptrace_regset, &iov);
if (ret)
ret = -errno;
+
+ if (ret == -ENODEV) {
+#ifdef CONFIG_X86_32
+ ptrace_regset = NT_PRXFPREG;
+#else
+ ptrace_regset = NT_PRFPREG;
+#endif
+ iov.iov_len = 2 * 1024 * 1024;
+ ret = ptrace(PTRACE_GETREGSET, pid, ptrace_regset, &iov);
+ if (ret)
+ ret = -errno;
+ }
+
munmap(iov.iov_base, 2 * 1024 * 1024);
host_fp_size = iov.iov_len;
diff --git a/arch/x86/um/signal.c b/arch/x86/um/signal.c
index 75087e85b6fd..ea5b3bcc4245 100644
--- a/arch/x86/um/signal.c
+++ b/arch/x86/um/signal.c
@@ -187,7 +187,12 @@ static int copy_sc_to_user(struct sigcontext __user *to,
* Put magic/size values for userspace. We do not bother to verify them
* later on, however, userspace needs them should it try to read the
* XSTATE data. And ptrace does not fill in these parts.
+ *
+ * Skip this if we do not have an XSTATE frame.
*/
+ if (host_fp_size <= sizeof(to_fp64->fpstate))
+ return 0;
+
BUILD_BUG_ON(sizeof(int) != FP_XSTATE_MAGIC2_SIZE);
#ifdef CONFIG_X86_32
__put_user(offsetof(struct _fpstate_32, _fxsr_env) +
--
2.47.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] um: add back support for FXSAVE registers
2024-12-04 7:48 [PATCH] um: add back support for FXSAVE registers Benjamin Berg
@ 2025-01-07 21:07 ` SeongJae Park
2025-02-11 7:04 ` SeongJae Park
0 siblings, 1 reply; 3+ messages in thread
From: SeongJae Park @ 2025-01-07 21:07 UTC (permalink / raw)
To: Benjamin Berg; +Cc: SeongJae Park, linux-um, Benjamin Berg
Hello,
On Wed, 4 Dec 2024 08:48:27 +0100 Benjamin Berg <benjamin@sipsolutions.net> wrote:
> From: Benjamin Berg <benjamin.berg@intel.com>
>
> It was reported that qemu may not enable the XSTATE CPU extension, which
> is a requirement after commit 3f17fed21491 ("um: switch to regset API
> and depend on XSTATE"). Add a fallback to use FXSAVE (FP registers on
> x86_64 and XFP on i386) which is just a shorter version of the same
> data. The only difference is that the XSTATE magic should not be set in
> the signal frame.
>
> Note that this still drops support for the older i386 FP register layout
> as supporting this would require more backward compatibility to build a
> correct signal frame.
>
> Fixes: 3f17fed21491 ("um: switch to regset API and depend on XSTATE")
> Reported-by: SeongJae Park <sj@kernel.org>
> Closes: https://lore.kernel.org/r/20241203070218.240797-1-sj@kernel.org
> Tested-by: SeongJae Park <sj@kernel.org>
> Signed-off-by: Benjamin Berg <benjamin.berg@intel.com>
Seems this patch is not yet merged into uml/next or uml/fixes. May I ask the
timeline or blockers for this patch?
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] um: add back support for FXSAVE registers
2025-01-07 21:07 ` SeongJae Park
@ 2025-02-11 7:04 ` SeongJae Park
0 siblings, 0 replies; 3+ messages in thread
From: SeongJae Park @ 2025-02-11 7:04 UTC (permalink / raw)
To: SeongJae Park; +Cc: Benjamin Berg, linux-um, Benjamin Berg
On Tue, 7 Jan 2025 13:07:58 -0800 SeongJae Park <sj@kernel.org> wrote:
> Hello,
>
> On Wed, 4 Dec 2024 08:48:27 +0100 Benjamin Berg <benjamin@sipsolutions.net> wrote:
>
> > From: Benjamin Berg <benjamin.berg@intel.com>
> >
> > It was reported that qemu may not enable the XSTATE CPU extension, which
> > is a requirement after commit 3f17fed21491 ("um: switch to regset API
> > and depend on XSTATE"). Add a fallback to use FXSAVE (FP registers on
> > x86_64 and XFP on i386) which is just a shorter version of the same
> > data. The only difference is that the XSTATE magic should not be set in
> > the signal frame.
> >
> > Note that this still drops support for the older i386 FP register layout
> > as supporting this would require more backward compatibility to build a
> > correct signal frame.
> >
> > Fixes: 3f17fed21491 ("um: switch to regset API and depend on XSTATE")
> > Reported-by: SeongJae Park <sj@kernel.org>
> > Closes: https://lore.kernel.org/r/20241203070218.240797-1-sj@kernel.org
> > Tested-by: SeongJae Park <sj@kernel.org>
> > Signed-off-by: Benjamin Berg <benjamin.berg@intel.com>
>
> Seems this patch is not yet merged into uml/next or uml/fixes. May I ask the
> timeline or blockers for this patch?
A gentle reminder. :)
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-02-11 7:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-04 7:48 [PATCH] um: add back support for FXSAVE registers Benjamin Berg
2025-01-07 21:07 ` SeongJae Park
2025-02-11 7:04 ` SeongJae Park
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).