* [PATCH 4.9 1/2] um: Allow building and running on older hosts
@ 2019-07-22 10:33 Alessio Balsini
2019-07-22 10:33 ` [PATCH 4.9 2/2] um: Fix FP register size for XSTATE/XSAVE Alessio Balsini
2019-07-24 12:07 ` [PATCH 4.9 1/2] um: Allow building and running on older hosts Greg KH
0 siblings, 2 replies; 4+ messages in thread
From: Alessio Balsini @ 2019-07-22 10:33 UTC (permalink / raw)
To: gregkh; +Cc: astrachan, maennich, kernel-team, stable
commit 0a987645672ebde7844a9c0732a5a25f3d4bb6c6 upstream.
Commit a78ff1112263 ("um: add extended processor state save/restore
support") and b6024b21fec8 ("um: extend fpstate to _xstate to support
YMM registers") forced the use of the x86 FP _xstate and
PTRACE_GETREGSET/SETREGSET. On older hosts, we would neither be able to
build UML nor run it anymore with these two commits applied because we
don't have definitions for struct _xstate nor these two ptrace requests.
We can determine at build time which fp context structure to check
against, just like we can keep using the old i387 fp save/restore if
PTRACE_GETRESET/SETREGSET are not defined.
Fixes: a78ff1112263 ("um: add extended processor state save/restore support")
Fixes: b6024b21fec8 ("um: extend fpstate to _xstate to support YMM registers")
Change-Id: I2cda034c8a6637de392c2740a993982ad132bda5
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Alessio Balsini <balsini@android.com>
---
arch/x86/um/os-Linux/registers.c | 12 ++++++++----
arch/x86/um/user-offsets.c | 4 ++++
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/arch/x86/um/os-Linux/registers.c b/arch/x86/um/os-Linux/registers.c
index 00f54a91bb4b..28775f55bde2 100644
--- a/arch/x86/um/os-Linux/registers.c
+++ b/arch/x86/um/os-Linux/registers.c
@@ -26,6 +26,7 @@ int save_i387_registers(int pid, unsigned long *fp_regs)
int save_fp_registers(int pid, unsigned long *fp_regs)
{
+#ifdef PTRACE_GETREGSET
struct iovec iov;
if (have_xstate_support) {
@@ -34,9 +35,9 @@ int save_fp_registers(int pid, unsigned long *fp_regs)
if (ptrace(PTRACE_GETREGSET, pid, NT_X86_XSTATE, &iov) < 0)
return -errno;
return 0;
- } else {
+ } else
+#endif
return save_i387_registers(pid, fp_regs);
- }
}
int restore_i387_registers(int pid, unsigned long *fp_regs)
@@ -48,6 +49,7 @@ int restore_i387_registers(int pid, unsigned long *fp_regs)
int restore_fp_registers(int pid, unsigned long *fp_regs)
{
+#ifdef PTRACE_SETREGSET
struct iovec iov;
if (have_xstate_support) {
@@ -56,9 +58,9 @@ int restore_fp_registers(int pid, unsigned long *fp_regs)
if (ptrace(PTRACE_SETREGSET, pid, NT_X86_XSTATE, &iov) < 0)
return -errno;
return 0;
- } else {
+ } else
+#endif
return restore_i387_registers(pid, fp_regs);
- }
}
#ifdef __i386__
@@ -122,6 +124,7 @@ int put_fp_registers(int pid, unsigned long *regs)
void arch_init_registers(int pid)
{
+#ifdef PTRACE_GETREGSET
struct _xstate fp_regs;
struct iovec iov;
@@ -129,6 +132,7 @@ void arch_init_registers(int pid)
iov.iov_len = sizeof(struct _xstate);
if (ptrace(PTRACE_GETREGSET, pid, NT_X86_XSTATE, &iov) == 0)
have_xstate_support = 1;
+#endif
}
#endif
diff --git a/arch/x86/um/user-offsets.c b/arch/x86/um/user-offsets.c
index cb3c22370cf5..8af0fb5d2780 100644
--- a/arch/x86/um/user-offsets.c
+++ b/arch/x86/um/user-offsets.c
@@ -50,7 +50,11 @@ void foo(void)
DEFINE(HOST_GS, GS);
DEFINE(HOST_ORIG_AX, ORIG_EAX);
#else
+#if defined(PTRACE_GETREGSET) && defined(PTRACE_SETREGSET)
DEFINE(HOST_FP_SIZE, sizeof(struct _xstate) / sizeof(unsigned long));
+#else
+ DEFINE(HOST_FP_SIZE, sizeof(struct _fpstate) / sizeof(unsigned long));
+#endif
DEFINE_LONGS(HOST_BX, RBX);
DEFINE_LONGS(HOST_CX, RCX);
DEFINE_LONGS(HOST_DI, RDI);
--
2.22.0.657.g960e92d24f-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 4.9 2/2] um: Fix FP register size for XSTATE/XSAVE
2019-07-22 10:33 [PATCH 4.9 1/2] um: Allow building and running on older hosts Alessio Balsini
@ 2019-07-22 10:33 ` Alessio Balsini
2019-07-24 12:07 ` [PATCH 4.9 1/2] um: Allow building and running on older hosts Greg KH
1 sibling, 0 replies; 4+ messages in thread
From: Alessio Balsini @ 2019-07-22 10:33 UTC (permalink / raw)
To: gregkh; +Cc: astrachan, maennich, kernel-team, stable
From: Thomas Meyer <thomas@m3y3r.de>
commit 6f602afda7275c24c20ba38b5b6cd4ed08561fff upstream.
Hard code max size. Taken from
https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=gdb/common/x86-xstate.h
Change-Id: Iae6c1559b757e0c6a1d221f8e677573642dde05c
Signed-off-by: Thomas Meyer <thomas@m3y3r.de>
Signed-off-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Alessio Balsini <balsini@android.com>
---
arch/um/include/asm/thread_info.h | 3 +++
arch/um/include/shared/os.h | 2 +-
arch/um/kernel/process.c | 4 ++--
arch/um/os-Linux/skas/process.c | 17 ++++++++---------
arch/x86/um/os-Linux/registers.c | 18 ++++++++++++------
arch/x86/um/user-offsets.c | 4 ++--
6 files changed, 28 insertions(+), 20 deletions(-)
diff --git a/arch/um/include/asm/thread_info.h b/arch/um/include/asm/thread_info.h
index 053baff03674..9300f7630d2a 100644
--- a/arch/um/include/asm/thread_info.h
+++ b/arch/um/include/asm/thread_info.h
@@ -11,6 +11,7 @@
#include <asm/types.h>
#include <asm/page.h>
#include <asm/segment.h>
+#include <sysdep/ptrace_user.h>
struct thread_info {
struct task_struct *task; /* main task structure */
@@ -22,6 +23,8 @@ struct thread_info {
0-0xBFFFFFFF for user
0-0xFFFFFFFF for kernel */
struct thread_info *real_thread; /* Points to non-IRQ stack */
+ unsigned long aux_fp_regs[FP_SIZE]; /* auxiliary fp_regs to save/restore
+ them out-of-band */
};
#define INIT_THREAD_INFO(tsk) \
diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h
index de5d572225f3..cc64f0579949 100644
--- a/arch/um/include/shared/os.h
+++ b/arch/um/include/shared/os.h
@@ -274,7 +274,7 @@ extern int protect(struct mm_id * mm_idp, unsigned long addr,
extern int is_skas_winch(int pid, int fd, void *data);
extern int start_userspace(unsigned long stub_stack);
extern int copy_context_skas0(unsigned long stack, int pid);
-extern void userspace(struct uml_pt_regs *regs);
+extern void userspace(struct uml_pt_regs *regs, unsigned long *aux_fp_regs);
extern int map_stub_pages(int fd, unsigned long code, unsigned long data,
unsigned long stack);
extern void new_thread(void *stack, jmp_buf *buf, void (*handler)(void));
diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
index 034b42c7ab40..787568044a2a 100644
--- a/arch/um/kernel/process.c
+++ b/arch/um/kernel/process.c
@@ -128,7 +128,7 @@ void new_thread_handler(void)
* callback returns only if the kernel thread execs a process
*/
n = fn(arg);
- userspace(¤t->thread.regs.regs);
+ userspace(¤t->thread.regs.regs, current_thread_info()->aux_fp_regs);
}
/* Called magically, see new_thread_handler above */
@@ -147,7 +147,7 @@ void fork_handler(void)
current->thread.prev_sched = NULL;
- userspace(¤t->thread.regs.regs);
+ userspace(¤t->thread.regs.regs, current_thread_info()->aux_fp_regs);
}
int copy_thread(unsigned long clone_flags, unsigned long sp,
diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/process.c
index 0a99d4515065..cd4a6ff676a8 100644
--- a/arch/um/os-Linux/skas/process.c
+++ b/arch/um/os-Linux/skas/process.c
@@ -87,12 +87,11 @@ void wait_stub_done(int pid)
extern unsigned long current_stub_stack(void);
-static void get_skas_faultinfo(int pid, struct faultinfo *fi)
+static void get_skas_faultinfo(int pid, struct faultinfo *fi, unsigned long *aux_fp_regs)
{
int err;
- unsigned long fpregs[FP_SIZE];
- err = get_fp_registers(pid, fpregs);
+ err = get_fp_registers(pid, aux_fp_regs);
if (err < 0) {
printk(UM_KERN_ERR "save_fp_registers returned %d\n",
err);
@@ -112,7 +111,7 @@ static void get_skas_faultinfo(int pid, struct faultinfo *fi)
*/
memcpy(fi, (void *)current_stub_stack(), sizeof(*fi));
- err = put_fp_registers(pid, fpregs);
+ err = put_fp_registers(pid, aux_fp_regs);
if (err < 0) {
printk(UM_KERN_ERR "put_fp_registers returned %d\n",
err);
@@ -120,9 +119,9 @@ static void get_skas_faultinfo(int pid, struct faultinfo *fi)
}
}
-static void handle_segv(int pid, struct uml_pt_regs * regs)
+static void handle_segv(int pid, struct uml_pt_regs *regs, unsigned long *aux_fp_regs)
{
- get_skas_faultinfo(pid, ®s->faultinfo);
+ get_skas_faultinfo(pid, ®s->faultinfo, aux_fp_regs);
segv(regs->faultinfo, 0, 1, NULL);
}
@@ -305,7 +304,7 @@ int start_userspace(unsigned long stub_stack)
return err;
}
-void userspace(struct uml_pt_regs *regs)
+void userspace(struct uml_pt_regs *regs, unsigned long *aux_fp_regs)
{
int err, status, op, pid = userspace_pid[0];
/* To prevent races if using_sysemu changes under us.*/
@@ -374,11 +373,11 @@ void userspace(struct uml_pt_regs *regs)
case SIGSEGV:
if (PTRACE_FULL_FAULTINFO) {
get_skas_faultinfo(pid,
- ®s->faultinfo);
+ ®s->faultinfo, aux_fp_regs);
(*sig_info[SIGSEGV])(SIGSEGV, (struct siginfo *)&si,
regs);
}
- else handle_segv(pid, regs);
+ else handle_segv(pid, regs, aux_fp_regs);
break;
case SIGTRAP + 0x80:
handle_trap(pid, regs, local_using_sysemu);
diff --git a/arch/x86/um/os-Linux/registers.c b/arch/x86/um/os-Linux/registers.c
index 28775f55bde2..3c423dfcd78b 100644
--- a/arch/x86/um/os-Linux/registers.c
+++ b/arch/x86/um/os-Linux/registers.c
@@ -5,6 +5,7 @@
*/
#include <errno.h>
+#include <stdlib.h>
#include <sys/ptrace.h>
#ifdef __i386__
#include <sys/user.h>
@@ -31,7 +32,7 @@ int save_fp_registers(int pid, unsigned long *fp_regs)
if (have_xstate_support) {
iov.iov_base = fp_regs;
- iov.iov_len = sizeof(struct _xstate);
+ iov.iov_len = FP_SIZE * sizeof(unsigned long);
if (ptrace(PTRACE_GETREGSET, pid, NT_X86_XSTATE, &iov) < 0)
return -errno;
return 0;
@@ -51,10 +52,9 @@ int restore_fp_registers(int pid, unsigned long *fp_regs)
{
#ifdef PTRACE_SETREGSET
struct iovec iov;
-
if (have_xstate_support) {
iov.iov_base = fp_regs;
- iov.iov_len = sizeof(struct _xstate);
+ iov.iov_len = FP_SIZE * sizeof(unsigned long);
if (ptrace(PTRACE_SETREGSET, pid, NT_X86_XSTATE, &iov) < 0)
return -errno;
return 0;
@@ -125,13 +125,19 @@ int put_fp_registers(int pid, unsigned long *regs)
void arch_init_registers(int pid)
{
#ifdef PTRACE_GETREGSET
- struct _xstate fp_regs;
+ void * fp_regs;
struct iovec iov;
- iov.iov_base = &fp_regs;
- iov.iov_len = sizeof(struct _xstate);
+ fp_regs = malloc(FP_SIZE * sizeof(unsigned long));
+ if(fp_regs == NULL)
+ return;
+
+ iov.iov_base = fp_regs;
+ iov.iov_len = FP_SIZE * sizeof(unsigned long);
if (ptrace(PTRACE_GETREGSET, pid, NT_X86_XSTATE, &iov) == 0)
have_xstate_support = 1;
+
+ free(fp_regs);
#endif
}
#endif
diff --git a/arch/x86/um/user-offsets.c b/arch/x86/um/user-offsets.c
index 8af0fb5d2780..7bcd10614f8b 100644
--- a/arch/x86/um/user-offsets.c
+++ b/arch/x86/um/user-offsets.c
@@ -50,8 +50,8 @@ void foo(void)
DEFINE(HOST_GS, GS);
DEFINE(HOST_ORIG_AX, ORIG_EAX);
#else
-#if defined(PTRACE_GETREGSET) && defined(PTRACE_SETREGSET)
- DEFINE(HOST_FP_SIZE, sizeof(struct _xstate) / sizeof(unsigned long));
+#ifdef FP_XSTATE_MAGIC1
+ DEFINE_LONGS(HOST_FP_SIZE, 2696);
#else
DEFINE(HOST_FP_SIZE, sizeof(struct _fpstate) / sizeof(unsigned long));
#endif
--
2.22.0.657.g960e92d24f-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 4.9 1/2] um: Allow building and running on older hosts
2019-07-22 10:33 [PATCH 4.9 1/2] um: Allow building and running on older hosts Alessio Balsini
2019-07-22 10:33 ` [PATCH 4.9 2/2] um: Fix FP register size for XSTATE/XSAVE Alessio Balsini
@ 2019-07-24 12:07 ` Greg KH
2019-07-25 3:40 ` Sasha Levin
1 sibling, 1 reply; 4+ messages in thread
From: Greg KH @ 2019-07-24 12:07 UTC (permalink / raw)
To: Alessio Balsini; +Cc: astrachan, maennich, kernel-team, stable
On Mon, Jul 22, 2019 at 11:33:37AM +0100, Alessio Balsini wrote:
> commit 0a987645672ebde7844a9c0732a5a25f3d4bb6c6 upstream.
>
> Commit a78ff1112263 ("um: add extended processor state save/restore
> support") and b6024b21fec8 ("um: extend fpstate to _xstate to support
> YMM registers") forced the use of the x86 FP _xstate and
> PTRACE_GETREGSET/SETREGSET. On older hosts, we would neither be able to
> build UML nor run it anymore with these two commits applied because we
> don't have definitions for struct _xstate nor these two ptrace requests.
>
> We can determine at build time which fp context structure to check
> against, just like we can keep using the old i387 fp save/restore if
> PTRACE_GETRESET/SETREGSET are not defined.
>
> Fixes: a78ff1112263 ("um: add extended processor state save/restore support")
> Fixes: b6024b21fec8 ("um: extend fpstate to _xstate to support YMM registers")
> Change-Id: I2cda034c8a6637de392c2740a993982ad132bda5
No need for change-id in upstream patches :)
let me see if I can just take what is already in 4.13 directly...
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 4.9 1/2] um: Allow building and running on older hosts
2019-07-24 12:07 ` [PATCH 4.9 1/2] um: Allow building and running on older hosts Greg KH
@ 2019-07-25 3:40 ` Sasha Levin
0 siblings, 0 replies; 4+ messages in thread
From: Sasha Levin @ 2019-07-25 3:40 UTC (permalink / raw)
To: Greg KH; +Cc: Alessio Balsini, astrachan, maennich, kernel-team, stable
On Wed, Jul 24, 2019 at 02:07:53PM +0200, Greg KH wrote:
>On Mon, Jul 22, 2019 at 11:33:37AM +0100, Alessio Balsini wrote:
>> commit 0a987645672ebde7844a9c0732a5a25f3d4bb6c6 upstream.
>>
>> Commit a78ff1112263 ("um: add extended processor state save/restore
>> support") and b6024b21fec8 ("um: extend fpstate to _xstate to support
>> YMM registers") forced the use of the x86 FP _xstate and
>> PTRACE_GETREGSET/SETREGSET. On older hosts, we would neither be able to
>> build UML nor run it anymore with these two commits applied because we
>> don't have definitions for struct _xstate nor these two ptrace requests.
>>
>> We can determine at build time which fp context structure to check
>> against, just like we can keep using the old i387 fp save/restore if
>> PTRACE_GETRESET/SETREGSET are not defined.
>>
>> Fixes: a78ff1112263 ("um: add extended processor state save/restore support")
>> Fixes: b6024b21fec8 ("um: extend fpstate to _xstate to support YMM registers")
>> Change-Id: I2cda034c8a6637de392c2740a993982ad132bda5
>
>No need for change-id in upstream patches :)
>
>let me see if I can just take what is already in 4.13 directly...
Alessio,
Do we also need 2fb44600fe784 ("um: Fix check for _xstate for older
hosts")?
--
Thanks,
Sasha
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-07-25 3:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-22 10:33 [PATCH 4.9 1/2] um: Allow building and running on older hosts Alessio Balsini
2019-07-22 10:33 ` [PATCH 4.9 2/2] um: Fix FP register size for XSTATE/XSAVE Alessio Balsini
2019-07-24 12:07 ` [PATCH 4.9 1/2] um: Allow building and running on older hosts Greg KH
2019-07-25 3:40 ` Sasha Levin
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).