* Re: [uml-devel] [PATCH] um: v3: Fix FP register size for XSTATE/XSAVE @ 2017-07-12 15:11 Thomas Meyer 2017-07-12 19:18 ` Richard Weinberger 2017-07-12 19:53 ` Richard Weinberger 0 siblings, 2 replies; 7+ messages in thread From: Thomas Meyer @ 2017-07-12 15:11 UTC (permalink / raw) To: Richard Weinberger; +Cc: user-mode-linux-devel [-- Attachment #1: Type: text/html, Size: 2152 bytes --] [-- Attachment #2: Type: text/plain, Size: 202 bytes --] ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot [-- Attachment #3: Type: text/plain, Size: 194 bytes --] _______________________________________________ User-mode-linux-devel mailing list User-mode-linux-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [uml-devel] [PATCH] um: v3: Fix FP register size for XSTATE/XSAVE 2017-07-12 15:11 [uml-devel] [PATCH] um: v3: Fix FP register size for XSTATE/XSAVE Thomas Meyer @ 2017-07-12 19:18 ` Richard Weinberger 2017-07-17 20:59 ` Thomas Meyer 2017-07-12 19:53 ` Richard Weinberger 1 sibling, 1 reply; 7+ messages in thread From: Richard Weinberger @ 2017-07-12 19:18 UTC (permalink / raw) To: Thomas Meyer; +Cc: user-mode-linux-devel Thomas, Am 12.07.2017 um 17:11 schrieb Thomas Meyer: > Am 10.07.2017 9:06 nachm. schrieb Richard Weinberger <richard@nod.at>: > > Thomas, > > Am 10.07.2017 um 00:33 schrieb Thomas Meyer: > > Hard code max size. Taken from > > https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=gdb/common/x86-xstate.h > > > > v3: use static fp_regs for get_skas_faultinfo > > > > Signed-off-by: Thomas Meyer <thomas@m3y3r.de> > > --- > > arch/um/os-Linux/skas/process.c | 7 ++++--- > > arch/x86/um/os-Linux/registers.c | 18 ++++++++++++------ > > arch/x86/um/user-offsets.c | 2 +- > > 3 files changed, 17 insertions(+), 10 deletions(-) > > > > diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/process.c > > index 03b3c4cc7735..b5fdef795985 100644 > > --- a/arch/um/os-Linux/skas/process.c > > +++ b/arch/um/os-Linux/skas/process.c > > @@ -88,12 +88,13 @@ void wait_stub_done(int pid) > > > > extern unsigned long current_stub_stack(void); > > > > +static unsigned long skas_faultinfo_fpregs[FP_SIZE]; > > + > > Uhmm, are you sure that this does not race with other userspace() instances? > > Oh, is it really possible that a task gets schedule while we are in userspace signal handling from ptrace? I hoped that you'd double check. ;) From my knowledge it is not possible, but this code was not written by me and UML internal semantics are more than tricky. Let's postpone this patch for -rc2 and check again. > Another question: when malloc a memory area in userspace: when does a userspace process end in userspace function!? Where would you free the malloced memory? It ends via handle_trap() when userspac does an exit syscall. I agree this is tricky to catch and needs more effort. Thanks, //richard ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ User-mode-linux-devel mailing list User-mode-linux-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [uml-devel] [PATCH] um: v3: Fix FP register size for XSTATE/XSAVE 2017-07-12 19:18 ` Richard Weinberger @ 2017-07-17 20:59 ` Thomas Meyer 0 siblings, 0 replies; 7+ messages in thread From: Thomas Meyer @ 2017-07-17 20:59 UTC (permalink / raw) To: Richard Weinberger; +Cc: user-mode-linux-devel On Wed, Jul 12, 2017 at 09:18:26PM +0200, Richard Weinberger wrote: > Thomas, > > Am 12.07.2017 um 17:11 schrieb Thomas Meyer: > > Am 10.07.2017 9:06 nachm. schrieb Richard Weinberger <richard@nod.at>: > > > > Thomas, > > > > Am 10.07.2017 um 00:33 schrieb Thomas Meyer: > > > Hard code max size. Taken from > > > https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=gdb/common/x86-xstate.h > > > > > > v3: use static fp_regs for get_skas_faultinfo > > > > > > Signed-off-by: Thomas Meyer <thomas@m3y3r.de> > > > --- > > > arch/um/os-Linux/skas/process.c | 7 ++++--- > > > arch/x86/um/os-Linux/registers.c | 18 ++++++++++++------ > > > arch/x86/um/user-offsets.c | 2 +- > > > 3 files changed, 17 insertions(+), 10 deletions(-) > > > > > > diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/process.c > > > index 03b3c4cc7735..b5fdef795985 100644 > > > --- a/arch/um/os-Linux/skas/process.c > > > +++ b/arch/um/os-Linux/skas/process.c > > > @@ -88,12 +88,13 @@ void wait_stub_done(int pid) > > > > > > extern unsigned long current_stub_stack(void); > > > > > > +static unsigned long skas_faultinfo_fpregs[FP_SIZE]; > > > + > > > > Uhmm, are you sure that this does not race with other userspace() instances? > > > > Oh, is it really possible that a task gets schedule while we are in userspace signal handling from ptrace? > > I hoped that you'd double check. ;) I just did write a little test program, which seems to survive this patch. Please have a look at this test program. As far as I understand the problem, the test program should cover above test case. Feel free to have a look at it: https://github.com/thomasmey/xmm-test/ > From my knowledge it is not possible, but this code was not written by me and UML internal > semantics are more than tricky. > Let's postpone this patch for -rc2 and check again. > > > Another question: when malloc a memory area in userspace: when does a userspace process end in userspace function!? Where would you free the malloced memory? > > It ends via handle_trap() when userspac does an exit syscall. > I agree this is tricky to catch and needs more effort. Ah, okay, that makes sense! > > Thanks, > //richard ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ User-mode-linux-devel mailing list User-mode-linux-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [uml-devel] [PATCH] um: v3: Fix FP register size for XSTATE/XSAVE 2017-07-12 15:11 [uml-devel] [PATCH] um: v3: Fix FP register size for XSTATE/XSAVE Thomas Meyer 2017-07-12 19:18 ` Richard Weinberger @ 2017-07-12 19:53 ` Richard Weinberger 2017-07-29 15:03 ` [uml-devel] [PATCH] um: v4: " Thomas Meyer 1 sibling, 1 reply; 7+ messages in thread From: Richard Weinberger @ 2017-07-12 19:53 UTC (permalink / raw) To: Thomas Meyer; +Cc: user-mode-linux-devel Thomas, what about something like that? (untested) Still not very pretty but IMHO better. 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 cd1fa97776c3..c1d4b6fbc919 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 2c7f721eccbc..691b83b10649 100644 --- a/arch/um/kernel/process.c +++ b/arch/um/kernel/process.c @@ -131,7 +131,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 */ @@ -150,7 +150,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 03b3c4cc7735..d92a0240dce4 100644 --- a/arch/um/os-Linux/skas/process.c +++ b/arch/um/os-Linux/skas/process.c @@ -88,12 +88,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); @@ -113,7 +112,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); @@ -121,9 +120,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); } @@ -303,7 +302,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.*/ @@ -372,11 +371,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); Thanks, //richard ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ User-mode-linux-devel mailing list User-mode-linux-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [uml-devel] [PATCH] um: v4: Fix FP register size for XSTATE/XSAVE 2017-07-12 19:53 ` Richard Weinberger @ 2017-07-29 15:03 ` Thomas Meyer 0 siblings, 0 replies; 7+ messages in thread From: Thomas Meyer @ 2017-07-29 15:03 UTC (permalink / raw) To: richard; +Cc: user-mode-linux-devel Hard code max size. Taken from https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=gdb/common/x86-xstate.h v3: use static fp_regs for get_skas_faultinfo v4: better be safe, about concurrent action, e.g. timer. move fpregs into thread_info Signed-off-by: Thomas Meyer <thomas@m3y3r.de> --- 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 | 2 +- 6 files changed, 27 insertions(+), 19 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 574e03fc7ba2..d8ddaf9790d2 100644 --- a/arch/um/include/shared/os.h +++ b/arch/um/include/shared/os.h @@ -278,7 +278,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 2c7f721eccbc..691b83b10649 100644 --- a/arch/um/kernel/process.c +++ b/arch/um/kernel/process.c @@ -131,7 +131,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 */ @@ -150,7 +150,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 819d68656673..c94c3bd70ccd 100644 --- a/arch/um/os-Linux/skas/process.c +++ b/arch/um/os-Linux/skas/process.c @@ -88,12 +88,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); @@ -113,7 +112,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); @@ -121,9 +120,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); } @@ -332,7 +331,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.*/ @@ -407,11 +406,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 ae4cd58c0c7a..345016ecc1c0 100644 --- a/arch/x86/um/user-offsets.c +++ b/arch/x86/um/user-offsets.c @@ -51,7 +51,7 @@ void foo(void) DEFINE(HOST_ORIG_AX, ORIG_EAX); #else #if defined(PTRACE_GETREGSET) && defined(PTRACE_SETREGSET) - DEFINE(HOST_FP_SIZE, sizeof(struct _xstate) / sizeof(unsigned long)); + DEFINE_LONGS(HOST_FP_SIZE, 2696); #else DEFINE(HOST_FP_SIZE, sizeof(struct _fpstate) / sizeof(unsigned long)); #endif -- 2.13.3 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ User-mode-linux-devel mailing list User-mode-linux-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [uml-devel] [PATCH] um: v2: Fix FP register size for XSTATE/XSAVE
@ 2017-07-07 22:13 Richard Weinberger
2017-07-09 22:33 ` [uml-devel] [PATCH] um: v3: " Thomas Meyer
0 siblings, 1 reply; 7+ messages in thread
From: Richard Weinberger @ 2017-07-07 22:13 UTC (permalink / raw)
To: Thomas Meyer; +Cc: user-mode-linux-devel@lists.sourceforge.net
Thomas,
On Fri, Jul 7, 2017 at 11:01 PM, Thomas Meyer <thomas@m3y3r.de> wrote:
> Hard code max size. Taken from
> https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=gdb/common/x86-xstate.h
>
> Signed-off-by: Thomas Meyer <thomas@m3y3r.de>
> ---
> arch/um/os-Linux/skas/process.c | 22 ++++++++++++++++++----
> arch/x86/um/os-Linux/registers.c | 16 +++++++++++-----
> arch/x86/um/user-offsets.c | 2 +-
> 3 files changed, 30 insertions(+), 10 deletions(-)
>
> diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/process.c
> index 03b3c4cc7735..1a7cce387950 100644
> --- a/arch/um/os-Linux/skas/process.c
> +++ b/arch/um/os-Linux/skas/process.c
> @@ -91,19 +91,25 @@ extern unsigned long current_stub_stack(void);
> static void get_skas_faultinfo(int pid, struct faultinfo *fi)
> {
> int err;
> - unsigned long fpregs[FP_SIZE];
> + void * fpregs;
> +
> + fpregs = malloc(FP_SIZE * sizeof(unsigned long));
> + if(fpregs == NULL) {
> + printk(UM_KERN_ERR "cannot alloc memory for save_fp_registers!");
> + goto errout;
> + }
Having a malloc() here is rather expensive.
I suggest to allocate a buffer in userspace() that can be used in
get_skas_faultinfo().
Thanks,
//richard
--
Thanks,
//richard
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
^ permalink raw reply [flat|nested] 7+ messages in thread* [uml-devel] [PATCH] um: v3: Fix FP register size for XSTATE/XSAVE 2017-07-07 22:13 [uml-devel] [PATCH] um: v2: " Richard Weinberger @ 2017-07-09 22:33 ` Thomas Meyer 2017-07-10 19:06 ` Richard Weinberger 0 siblings, 1 reply; 7+ messages in thread From: Thomas Meyer @ 2017-07-09 22:33 UTC (permalink / raw) To: richard.weinberger, user-mode-linux-devel Hard code max size. Taken from https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=gdb/common/x86-xstate.h v3: use static fp_regs for get_skas_faultinfo Signed-off-by: Thomas Meyer <thomas@m3y3r.de> --- arch/um/os-Linux/skas/process.c | 7 ++++--- arch/x86/um/os-Linux/registers.c | 18 ++++++++++++------ arch/x86/um/user-offsets.c | 2 +- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/process.c index 03b3c4cc7735..b5fdef795985 100644 --- a/arch/um/os-Linux/skas/process.c +++ b/arch/um/os-Linux/skas/process.c @@ -88,12 +88,13 @@ void wait_stub_done(int pid) extern unsigned long current_stub_stack(void); +static unsigned long skas_faultinfo_fpregs[FP_SIZE]; + static void get_skas_faultinfo(int pid, struct faultinfo *fi) { int err; - unsigned long fpregs[FP_SIZE]; - err = get_fp_registers(pid, fpregs); + err = get_fp_registers(pid, skas_faultinfo_fpregs); if (err < 0) { printk(UM_KERN_ERR "save_fp_registers returned %d\n", err); @@ -113,7 +114,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, skas_faultinfo_fpregs); if (err < 0) { printk(UM_KERN_ERR "put_fp_registers returned %d\n", err); diff --git a/arch/x86/um/os-Linux/registers.c b/arch/x86/um/os-Linux/registers.c index 00f54a91bb4b..2717911d1bef 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> @@ -30,7 +31,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; @@ -49,10 +50,9 @@ int restore_i387_registers(int pid, unsigned long *fp_regs) int restore_fp_registers(int pid, unsigned long *fp_regs) { 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; @@ -122,13 +122,19 @@ int put_fp_registers(int pid, unsigned long *regs) void arch_init_registers(int pid) { - 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 diff --git a/arch/x86/um/user-offsets.c b/arch/x86/um/user-offsets.c index cb3c22370cf5..c0111f093361 100644 --- a/arch/x86/um/user-offsets.c +++ b/arch/x86/um/user-offsets.c @@ -50,7 +50,7 @@ void foo(void) DEFINE(HOST_GS, GS); DEFINE(HOST_ORIG_AX, ORIG_EAX); #else - DEFINE(HOST_FP_SIZE, sizeof(struct _xstate) / sizeof(unsigned long)); + DEFINE_LONGS(HOST_FP_SIZE, 2696); DEFINE_LONGS(HOST_BX, RBX); DEFINE_LONGS(HOST_CX, RCX); DEFINE_LONGS(HOST_DI, RDI); -- 2.13.0 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ User-mode-linux-devel mailing list User-mode-linux-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [uml-devel] [PATCH] um: v3: Fix FP register size for XSTATE/XSAVE 2017-07-09 22:33 ` [uml-devel] [PATCH] um: v3: " Thomas Meyer @ 2017-07-10 19:06 ` Richard Weinberger 0 siblings, 0 replies; 7+ messages in thread From: Richard Weinberger @ 2017-07-10 19:06 UTC (permalink / raw) To: Thomas Meyer, user-mode-linux-devel Thomas, Am 10.07.2017 um 00:33 schrieb Thomas Meyer: > Hard code max size. Taken from > https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=gdb/common/x86-xstate.h > > v3: use static fp_regs for get_skas_faultinfo > > Signed-off-by: Thomas Meyer <thomas@m3y3r.de> > --- > arch/um/os-Linux/skas/process.c | 7 ++++--- > arch/x86/um/os-Linux/registers.c | 18 ++++++++++++------ > arch/x86/um/user-offsets.c | 2 +- > 3 files changed, 17 insertions(+), 10 deletions(-) > > diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/process.c > index 03b3c4cc7735..b5fdef795985 100644 > --- a/arch/um/os-Linux/skas/process.c > +++ b/arch/um/os-Linux/skas/process.c > @@ -88,12 +88,13 @@ void wait_stub_done(int pid) > > extern unsigned long current_stub_stack(void); > > +static unsigned long skas_faultinfo_fpregs[FP_SIZE]; > + Uhmm, are you sure that this does not race with other userspace() instances? Thanks, //richard ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ User-mode-linux-devel mailing list User-mode-linux-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-07-29 15:03 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2017-07-12 15:11 [uml-devel] [PATCH] um: v3: Fix FP register size for XSTATE/XSAVE Thomas Meyer 2017-07-12 19:18 ` Richard Weinberger 2017-07-17 20:59 ` Thomas Meyer 2017-07-12 19:53 ` Richard Weinberger 2017-07-29 15:03 ` [uml-devel] [PATCH] um: v4: " Thomas Meyer -- strict thread matches above, loose matches on Subject: below -- 2017-07-07 22:13 [uml-devel] [PATCH] um: v2: " Richard Weinberger 2017-07-09 22:33 ` [uml-devel] [PATCH] um: v3: " Thomas Meyer 2017-07-10 19:06 ` Richard Weinberger
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox