ptrace: fix ptrace_regset() comments and diagnose errors specifically
Subsystems (2)
PATCH 1/3 ptrace: fix ptrace_regset() comments and diagnose errors specifically
Return -EINVAL for the bad size and for unrecognized NT_* type in ptrace_regset() instead of -EIO.
Also update the comments for this ptrace interface with more clarifications.
--- include/linux/ptrace.h | 5 +++++ kernel/ptrace.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-)
kernel/ptrace.c +1 -1
@@ -537,7 +537,7 @@ static int ptrace_regset(struct task_strint regset_no;if (!regset || (kiov->iov_len % regset->size) !=0 ) -return -EIO ; +return -EINVAL ; regset_no = regset - view->regsets; kiov->iov_len = min(kiov->iov_len,
include/linux/ptrace.h +5 -0
@@ -30,6 +30,11 @@/* * Generic ptrace interface that exports the architecture specific regsets * using the corresponding NT_* types (which are also used in the core dump). +* Please note that the NT_PRSTATUS note type in a core dump contains a full +* 'struct elf_prstatus'. But the user_regset for NT_PRSTATUS contains just the +* elf_gregset_t that is the pr_reg field of 'struct elf_prstatus'. For all the +* other user_regset flavors, the user_regset layout and the ELF core dump note +* payload are exactly the same layout. * * This interface usage is as follows: * struct iovec iov = { buf, len};
PATCH 2/3 x86, ptrace: simplify xstateregs_get()
48 bytes (bytes 464..511) of the xstateregs payload come from the kernel defined structure (xstate_fx_sw_bytes). Rest comes from the xstate regs structure in the thread struct. Instead of having multiple user_regset_copyout()'s, simplify the xstateregs_get() by first copying the SW bytes into the xstate regs structure in the thread structure and then using one user_regset_copyout() to copyout the xstateregs.
--- arch/x86/kernel/i387.c | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-)
arch/x86/kernel/i387.c +7 -23
@@ -243,34 +243,18 @@ int xstateregs_get(struct task_struct *treturn ret;/* -* First copy the fxsave bytes 0..463. +* Copy the 48bytes defined by the software first into the xstate +* memory layout in the thread struct, so that we can copy the entire +* xstateregs to the user using one user_regset_copyout(). */ - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - &target->thread.xstate->xsave,0 , - offsetof(struct user_xstateregs , - i387.xstate_fx_sw)); -if (ret) -return ret; - -/* -* Copy the 48bytes defined by software. -*/ - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - xstate_fx_sw_bytes, - offsetof(struct user_xstateregs , - i387.xstate_fx_sw), - offsetof(struct user_xstateregs , - xsave_hdr)); -if (ret) -return ret; +memcpy (&target->thread.xstate->fxsave.sw_reserved, + xstate_fx_sw_bytes,sizeof (xstate_fx_sw_bytes));/* -* Copy the rest of xstate memory layout. +* Copy the xstate memory layout. */ ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - &target->thread.xstate->xsave.xsave_hdr, - offsetof(struct user_xstateregs , - xsave_hdr),-1 ); + &target->thread.xstate->xsave,0 ,-1 );return ret; }
Re: [patch 2/3] x86, ptrace: simplify xstateregs_get()
[tip:x86/ptrace] x86, ptrace: Simplify xstateregs_get()
In reply to Suresh SiddhaCommit-ID: ff7fbc72e0c3ef7e94a27a3a918fd09ec9a30204 Gitweb: http://git.kernel.org/tip/ff7fbc72e0c3ef7e94a27a3a918fd09ec9a30204 Author: Suresh Siddha <[email protected]> AuthorDate: Mon, 22 Feb 2010 14:51:33 -0800 Committer: H. Peter Anvin <[email protected]> CommitDate: Tue, 23 Feb 2010 13:45:27 -0800
x86, ptrace: Simplify xstateregs_get()
48 bytes (bytes 464..511) of the xstateregs payload come from the kernel defined structure (xstate_fx_sw_bytes). Rest comes from the xstate regs structure in the thread struct. Instead of having multiple user_regset_copyout()'s, simplify the xstateregs_get() by first copying the SW bytes into the xstate regs structure in the thread structure and then using one user_regset_copyout() to copyout the xstateregs.
LKML-Reference: <[email protected]>
--- arch/x86/kernel/i387.c | 30 +++++++----------------------- 1 files changed, 7 insertions(+), 23 deletions(-)
arch/x86/kernel/i387.c +7 -23
@@ -243,34 +243,18 @@ int xstateregs_get(struct task_struct *target, const struct user_regset *regset,return ret;/* -* First copy the fxsave bytes 0..463. +* Copy the 48bytes defined by the software first into the xstate +* memory layout in the thread struct, so that we can copy the entire +* xstateregs to the user using one user_regset_copyout(). */ - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - &target->thread.xstate->xsave,0 , - offsetof(struct user_xstateregs , - i387.xstate_fx_sw)); -if (ret) -return ret; - -/* -* Copy the 48bytes defined by software. -*/ - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - xstate_fx_sw_bytes, - offsetof(struct user_xstateregs , - i387.xstate_fx_sw), - offsetof(struct user_xstateregs , - xsave_hdr)); -if (ret) -return ret; +memcpy (&target->thread.xstate->fxsave.sw_reserved, + xstate_fx_sw_bytes,sizeof (xstate_fx_sw_bytes));/* -* Copy the rest of xstate memory layout. +* Copy the xstate memory layout. */ ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - &target->thread.xstate->xsave.xsave_hdr, - offsetof(struct user_xstateregs , - xsave_hdr),-1 ); + &target->thread.xstate->xsave,0 ,-1 );return ret; }
PATCH 3/3 x86, ptrace: remove set_stopped_child_used_math() in [x]fpregs_set
In reply to Suresh Siddhainit_fpu() already ensures that the used_math() is set for the stopped child. Remove the redundant set_stopped_child_used_math() in [x]fpregs_set()
--- arch/x86/kernel/i387.c | 4 ---- 1 file changed, 4 deletions(-)
arch/x86/kernel/i387.c +0 -4
@@ -209,8 +209,6 @@ int xfpregs_set(struct task_struct *targif (ret)return ret; -set_stopped_child_used_math (target); - ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, &target->thread.xstate->fxsave,0 ,-1 );
@@ -471,8 +469,6 @@ int fpregs_set(struct task_struct *targeif (ret)return ret; -set_stopped_child_used_math (target); -if (!HAVE_HWFP )return fpregs_soft_set (target, regset, pos, count, kbuf, ubuf);
Re: [patch 3/3] x86, ptrace: remove set_stopped_child_used_math() in [x]fpregs_set
[tip:x86/ptrace] x86, ptrace: Remove set_stopped_child_used_math() in [x]fpregs_set
In reply to Suresh SiddhaCommit-ID: 6dbbe14f21368a45aedba7eab0221857b8ad8d16 Gitweb: http://git.kernel.org/tip/6dbbe14f21368a45aedba7eab0221857b8ad8d16 Author: Suresh Siddha <[email protected]> AuthorDate: Mon, 22 Feb 2010 14:51:34 -0800 Committer: H. Peter Anvin <[email protected]> CommitDate: Tue, 23 Feb 2010 13:45:27 -0800
x86, ptrace: Remove set_stopped_child_used_math() in [x]fpregs_set
init_fpu() already ensures that the used_math() is set for the stopped child. Remove the redundant set_stopped_child_used_math() in [x]fpregs_set()
LKML-Reference: <[email protected]>
--- arch/x86/kernel/i387.c | 4 ---- 1 files changed, 0 insertions(+), 4 deletions(-)
arch/x86/kernel/i387.c +0 -4
@@ -209,8 +209,6 @@ int xfpregs_set(struct task_struct *target, const struct user_regset *regset,if (ret)return ret; -set_stopped_child_used_math (target); - ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, &target->thread.xstate->fxsave,0 ,-1 );
@@ -471,8 +469,6 @@ int fpregs_set(struct task_struct *target, const struct user_regset *regset,if (ret)return ret; -set_stopped_child_used_math (target); -if (!HAVE_HWFP )return fpregs_soft_set (target, regset, pos, count, kbuf, ubuf);
[tip:x86/ptrace] ptrace: Fix ptrace_regset() comments and diagnose errors specifically
In reply to Suresh SiddhaCommit-ID: c6a0dd7ec6fb2d4927979ed4dc562fc5c122d826 Gitweb: http://git.kernel.org/tip/c6a0dd7ec6fb2d4927979ed4dc562fc5c122d826 Author: Suresh Siddha <[email protected]> AuthorDate: Mon, 22 Feb 2010 14:51:32 -0800 Committer: H. Peter Anvin <[email protected]> CommitDate: Tue, 23 Feb 2010 13:45:26 -0800
ptrace: Fix ptrace_regset() comments and diagnose errors specifically
Return -EINVAL for the bad size and for unrecognized NT_* type in ptrace_regset() instead of -EIO.
Also update the comments for this ptrace interface with more clarifications.
LKML-Reference: <[email protected]>
--- include/linux/ptrace.h | 5 +++++ kernel/ptrace.c | 2 +- 2 files changed, 6 insertions(+), 1 deletions(-)
include/linux/ptrace.h +5 -0
@@ -30,6 +30,11 @@/* * Generic ptrace interface that exports the architecture specific regsets * using the corresponding NT_* types (which are also used in the core dump). +* Please note that the NT_PRSTATUS note type in a core dump contains a full +* 'struct elf_prstatus'. But the user_regset for NT_PRSTATUS contains just the +* elf_gregset_t that is the pr_reg field of 'struct elf_prstatus'. For all the +* other user_regset flavors, the user_regset layout and the ELF core dump note +* payload are exactly the same layout. * * This interface usage is as follows: * struct iovec iov = { buf, len};
kernel/ptrace.c +1 -1
@@ -537,7 +537,7 @@ static int ptrace_regset(struct task_struct *task, int req, unsigned int type,int regset_no;if (!regset || (kiov->iov_len % regset->size) !=0 ) -return -EIO ; +return -EINVAL ; regset_no = regset - view->regsets; kiov->iov_len = min(kiov->iov_len,