regset ->get() rework
Subsystems (20)
Al Viro
maintainerRFC PATCH 1/1 regset ->get() rework
There are several problems with regset API:
regsets' methods are too generic, clumsy as hell and the inline helpers
intended to hide most of the headache have very inconvenient calling conventions. For starters, ->get() (the method used to fetch a part of regset)
* can have both userland and kernel destination (gets two pointers, one of
them being NULL)
* can (theoretically) be called to fetch _any_ part of regset - possibly
starting in the middle of the damn thing. There are very few (and very irregular) users of that, er, feature. Moreover, all of them know which ->get() instance they are going to hit and quite a few ->get() instances outright say that they rely upon nobody calling them that way. Even more instances say nothing and still rely upon the same. And even the instances that *are* called that way rely upon the knowledge of the specific offsets that might be requested. "Brittle" doesn't begin to describe that; it also makes the instances that attempt to handle arbitrary offsets convoluted for no good reason. And all the irregular callers are easily dealt with without playing with that.
* the helpers attempt to be too flexible and end up being too inconvenient.
They try to allow writing the pieces of data out of order - pwrite(2) rather than write(2), if you will. And their calling conventions are worse than those of pwrite(2)... It's also an attractive nuisance - if you end up having skipped some range of offsets, there's no way for the caller to know. Out of all the instances only one tried to make use of those non-sequential writes - and fucked up in process.
* instances have to deal with the possibility of uaccess failures halfway
through. Again, it complicates the logics for no good reason.
* instances have no way to report how much data would they like to produce;
as the result, an additional method (->get_size()) had been invented (with only one instance). And handling of that thing in PTRACE_GETREGSET is broken - it's *not* reported to the caller and there's no direct way to tell that the end of userland buffer is left unmodified.
Life would be much simpler if we replaced ->get() with something that
1) always writes to kernel space.
2) always writes sequentially, starting from offset 0 and up to given (bounded) size.
3) returns an error or the amount of space left in the buffer.
Turns out it's not that hard to do. Callers that want the data to
go to userland can bloody well do copy_to_user() themselves. Non-sequential stores are simply not there anymore - not since the x86 bug got fixed last cycle.
Callers that want non-zero starting offsets are very few and are essentially
trying to paste pieces of regset together, possibly with some parts skipped/in different order/with different alignments/etc. Those are easily dealt with by providing a separate regset with the desired contents. There are 4 locations where specific ->get() instances are called directly and 3 locations that call ->get() instances via method. Let's take them in order:
[ia64] access_uarea() contains direct calls of fpregs_get() and gpregs_get().
Destination is a kernel buffer, the subset being accessed is a word at varying offset in the corresponding regset. That needs careful teasing apart; it's better to have access_uarea() use the lower-level helpers instead of calling [gf]pregs_[gs]et() there. Doable with some massage.
[sh] dump_fpu() calls (sh) fpregs_get(); destination is a kernel buffer,
the entire regset contents gets written out. Used by ELF_FDPIC coredumps; ELF coredumps on sh are _not_ reaching that code. We need to switch ELF_FDPIC coredumps to the same machinery ELF coredumps use; then this will become dead code. However, as far as ->get() API change is concerned, that call is nothing irregular - we write the entire regset out to a kernel buffer. So we can leave the removal of that code until we deal with ELF_FDPIC and for now just keep in mind that this instance of ->get2() is called directly. Just change the arguments to match the new calling conventions and that's it.
[x86] dump_fpu() calls (x86) fpregs_get(). That one is very simple to deal
with, seeing that the only caller used to be aout coredump support, which got (finally) removed last year. Dead code, IOW...
[ELF] a couple of callers in fill_thread_core_info(). That's what ELF coredumps
normally use; destination is a kernel buffer, the entire regset gets written out.
Finally, there's copy_regset_to_user(). That's the only place where we
ask ->get() to write to userland and it can bloody well allocate a kernel buffer, let ->get() fill it and then do copy_to_user() of the entire thing. That function is used by handlers of various ptrace(2) commands (the most generic one is PTRACE_GETREGSET). Almost all callers ask to write a range starting at the beginning of regset (and most of those ask to write the entire regset out); However, there are few exceptions:
[arm64] compat_ptrace_read_user() uses copy_regset_to_user() to fetch the
value of given register and write it to userland. Pointless kludge, since it's much easier to do what native arm does - supply a trivial function that returns given register of given process and copy the result to userland, same way as we do in other cases of compat_ptrace_read_user().
[sparc] PTRACE_GETREGS and PTRACE_GETFPREGS cobble the layout they
want out of pieces of regsets. It's much easier to provide a regset producing just the layout they want and use it instead of the generic ones.
IOW, we can regularize the callers with a bit of preliminary work,
then convert to new method with better calling conventions. The following series attempts to do that; it can be found ingit://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs.git #work.regset (and in the followups to this posting). Based at 5.8-rc1, there are 5 short branches with preparations (#regset.{base,x86,sparc,arm64,ia64}) merged together and followed by the bulk of the series.
Patch overviews follow:
#regset.base:
01/41) helpers for regset ->get() replacement
We start with providing wrappers for ->get() that have saner calling
conventions than ->get() itself. That is,
* they always copy to kernel buffer
* they are given the upper limit on the amount to copy and return the
amount actually copied or -E... on error. If regset has less than the amount required, it writes as much as it can.
One of those wrappers copies into preexisting buffer, another allocates
and writes there (allocation size is bounded by the size limit and by the amount regset is expected to have; user asking for half a gigabyte worth of register contents won't trigger half a gigabyte allocation).
Those wrappers live in (newly added) kernel/regset.c; none of them
is going to be called on sufficiently hot codepath to warrant inlining. Initially we can't convert all callers of ->get() to those. ELF coredump callers can be immediately converted, but ptrace ones need more preparations.
Now we regularize the callers. That's done on per-architecture basis:
#regset.x86
02/41) x86: copy_fpstate_to_sigframe(): have fpregs_soft_get() use kernel buffer 03/41) x86: kill dump_fpu()
On x86 we have two irregularities: there's a part of an instance of ->get()
(helper with the identical calling conventions, that is) that gets directly called with userland destination. It's _not_ a fast path - we need FPU emulation to be used in order to hit it, and at that point extra copying of 108 bytes is noise by any definition. Fuck it; call that ->get() instance with local variable as destination, then copy_to_user().
Another direct call of an instance is in dead code (dump_fpu(), not used
since the removal of aout coredumps). That one simply gets removed.
NB: calling conventions of copy_fpstate_to_sigframe() are silly. If you look at the call chains, anything negative ends up with force_sigsegv(); 0 or any positive qualifies as success. IOW, it really returns just one bit of information, while creating an impression that we somehow are reporting details. We are, after all, trying to save the userland state while entering a signal handler; whom could we possibly return an error to? copy_fpstate_to_sigframe(), along with __setup_rt_frame(), etc. ought to return bool.
#regset.ia64:
04/41) [ia64] sanitize elf_access_gpreg()
05/41) [ia64] teach elf_access_reg() to handle the missing range (r16..r31) 06/41) [ia64] regularize do_gpregs_[gs]et()
07/41) [ia64] access_uarea(): stop bothering with gpregs_[gs]et() 08/41) [ia64] access_uarea(): don't bother with fpregs_[gs]et()
The problem here is that access_uarea() (the guts of PTRAGE_POKEUSR/PTRACE_PEEKUSR) contains direct calls of ->get() (and ->set()) instances, for accessing single registers. They already have a function for doing pretty much that - access_elf_reg() (almost - it doesn't handle r16..r31, but that's trivial to do, simplifying the logics in callers).
gpregs_get() and gpregs_set() arrange for stack unwinder to collect
the information of where the user callee-saved registers have ended up spilled on kernel stack. Then they start calling access_elf_reg(), with bloody awful switches that remap the offsets in regset to register numbers. access_uarea(), in turn, remaps _its_ offsets into regset ones and calls gpregs_get()/gpregs_set().
A lot of extra complexity comes from gpregs_get() trying to bunch
the copyouts together - it puts the values of several registers into an array, then copies them out all at once.
In that branch:
* clean elf_access_breg() up, get rid of the switch in the damn thing.
* teach elf_access_reg() to handle the missing range of registers (r16..r31)
* regularize the after-unwind part of gpregs_get()/gpregs_set() - with elf_access_reg() becoming able to handle that range, the bunching logics in those become much simpler.
* switch access_uarea() to calling elf_access_reg() directly, eliminating the calls of gpregs_get()/gpregs_set() in there.
* same for floating point registers, only there we used to call different ->get()/->set() instances.
One note on access_uarea(): it never returns positive and its
callers choose between using "not zero" and "negative" pretty much at random.
#regset.sparc
09/41) sparc64: switch genregs32_get() to use of get_from_target() 10/41) sparc32: get rid of odd callers of copy_regset_to_user() 11/41) sparc64: get rid of odd callers of copy_regset_to_user() 12/41) sparc32: get rid of odd callers of copy_regset_from_user() 13/41) sparc64: get rid of odd callers of copy_regset_from_user()
First patch in the series is a cleanup in one of the ->get()
instances (open-coded reading the target's memory, rather than using the helper already in the same file). That's right next to the place that will need modifications in ->get() conversion later, so splitting that into a separate commit makes the things easier to follow.
Next several "paste pieces of regset together and copy them to
userland" are dealt with by adding new regsets, with ->get() instances directly producing the layout wanted by those ptrace commands, so that a single copy_regset_to_user() would do the right thing. Incidentally, that simplifies ->get() instances that used to be called by those ptrace commands - now they are never called with non-zero offset.
While not strictly necessary for this series, the same thing is
done to copy_regset_from_user() counterparts of those, so that all pasting pieces of regsets together would be gone.
NB: PTRAGE_GETREGS64 has a minor behaviour change - it used to
leave pregs->uregs[15] untouched, now it zeroes it.
#regset.arm64:
14/41) arm64: take fetching compat reg out of pt_regs into a new helper 15/41) arm64: get rid of copy_regset_to_user() in compat_ptrace_read_user() 16/41) arm64: sanitize compat_ptrace_write_user()
arm64 compat handling of PTRACE_PEEKUSR/PTRACE_POKEUSR abuses
copy_regset_{to,from}_user(). All we want in those is access to a single register; it's easier to lift the logics for fetching a register out of compat_gpr_get() into a helper function, call it in PTRACE_PEEKUSR handler and use put_user() to store its return value; that's pretty much what the native arm ptrace does. PTRACE_POKEUSR is, strictly speaking, unrelated to this series, but it's too obscene to live - it has the value to store into given register, so it does set_fs(KERNEL_DS) and calls copy_regset_from_user() with the address of the local variable that contains the new value. That's one hell of a way to copy a value into a field of pt_regs...
At that point we are done with prep work. The branches above
(#regset.{base,x86,ia64,sparc,arm64}) converge into #work.regset.
#work.regset
17/41) copy_regset_to_user(): do all copyout at once.
By now callers of ->get() instances pass 0 as offset and
all but one (copy_regset_to_user()) have kernel-space destinations. Convert that last caller to use of regset_get_alloc().
18/41) regset: new method and helpers for it
This is the core of the series. A replacement for ->get() is introduced, hopefully with saner calling conventions. ->get2() takes task+regset+buffer, returns the amount of
free space left in the buffer on success and -E... on error. buffer is represented as struct membuf - a pair of (kernel) pointer and amount of space left. Note that buffer is passed by value - that leads to better code generation, since the instances can just keep the components in registers - stores to those don't need to be visible to the caller.
Primitives for writing to such:
* membuf_write(buf, data, size)
* membuf_zero(buf, size)
* membuf_store(buf, value)
These are implemented as inlines (in case of membuf_store - a macro). All writes are sequential; they become no-ops when there's no space left. Return value of all primitives is the amount of space left after the operation, so they can be used as return values of ->get2().
Example of use:
// stores pt_regs of task + 64 bytes worth of zeroes + 32bit PID of task int foo_get(struct task_struct *task, const struct regset *regset,
struct membuf to)
{
membuf_write(&to, task_pt_regs(task), sizeof(struct pt_regs));
membuf_zero(&to, 64);
return membuf_store(&to, (u32)task_tgid_vnr(task));
}regset_get()/regset_get_alloc() taught to use that thing if present. By the end of the series all users of ->get() will be converted; then ->get() and ->get_size() can go.
Note that unlike ->get() this thing always starts at offset 0
and, since it only writes to kernel buffer, can't fail on copyout. It can, of course, fail for other reasons, but those tend to be less numerous.
The caller guarantees that the buffer size won't be bigger thanregset->n * regset->size. That simplifies life for quite a few instances.
Now we are going to convert architectures from ->get() to ->get2().
19/41) x86: switch to ->get2()
20/41) powerpc: switch to ->get2()
21/41) s390: switch to ->get2()
22/41) sparc: switch to ->get2()
23/41) mips: switch to ->get2()
24/41) arm64: switch to ->get2()
25/41) sh: convert to ->get2()
26/41) arm: switch to ->get2()
27/41) arc: switch to ->get2()
28/41) ia64: switch to ->get2()
29/41) c6x: switch to ->get2()
30/41) riscv: switch to ->get2()
31/41) openrisc: switch to ->get2()
32/41) h8300: switch to ->get2()
33/41) hexagon: switch to ->get2()
34/41) nios2: switch to ->get2()
35/41) nds32: switch to ->get2()
36/41) parisc: switch to ->get2()
37/41) xtensa: switch to ->get2()
38/41) csky: switch to ->get2()
With those done we have no ->get() instances left. Moreover, the only ->get_size() call is unreachable. And no callers of old helpers remain either.
39/41) regset: kill ->get()
40/41) regset(): kill ->get_size()
41/41) regset: kill user_regset_copyout{,_zero}()
This is *not* all I have for regsets, but I'd rather keep
e.g. fdpic conversion to regsets as part of ELF coredump work. This just deals with ->get(). Please, review and comment.
Diffstat:
arch/arc/kernel/ptrace.c | 148 +++---- arch/arm/kernel/ptrace.c | 52 +-- arch/arm64/kernel/ptrace.c | 303 +++++--------- arch/c6x/kernel/ptrace.c | 11 +- arch/csky/kernel/ptrace.c | 24 +- arch/h8300/kernel/ptrace.c | 17 +- arch/hexagon/kernel/ptrace.c | 62 +-- arch/ia64/kernel/ptrace.c | 396 +++++++------------ arch/mips/kernel/ptrace.c | 204 +++------- arch/nds32/kernel/ptrace.c | 9 +- arch/nios2/kernel/ptrace.c | 51 +-- arch/openrisc/kernel/ptrace.c | 26 +- arch/parisc/kernel/ptrace.c | 84 +--- arch/powerpc/kernel/ptrace/ptrace-altivec.c | 37 +- arch/powerpc/kernel/ptrace/ptrace-decl.h | 44 +-- arch/powerpc/kernel/ptrace/ptrace-novsx.c | 5 +- arch/powerpc/kernel/ptrace/ptrace-spe.c | 16 +- arch/powerpc/kernel/ptrace/ptrace-tm.c | 152 +++---- arch/powerpc/kernel/ptrace/ptrace-view.c | 185 ++++----- arch/powerpc/kernel/ptrace/ptrace-vsx.c | 13 +- arch/riscv/kernel/ptrace.c | 33 +- arch/s390/kernel/ptrace.c | 199 +++------- arch/sh/kernel/process_32.c | 5 +- arch/sh/kernel/ptrace_32.c | 48 +-- arch/sparc/kernel/ptrace_32.c | 265 +++++++------ arch/sparc/kernel/ptrace_64.c | 591 ++++++++++++++-------------- arch/x86/include/asm/fpu/internal.h | 1 - arch/x86/include/asm/fpu/regset.h | 4 +- arch/x86/include/asm/fpu/xstate.h | 4 +- arch/x86/kernel/fpu/regset.c | 55 +-- arch/x86/kernel/fpu/signal.c | 13 +- arch/x86/kernel/fpu/xstate.c | 164 ++------ arch/x86/kernel/ptrace.c | 75 ++-- arch/x86/kernel/tls.c | 32 +- arch/x86/kernel/tls.h | 2 +- arch/x86/math-emu/fpu_entry.c | 19 +- arch/xtensa/kernel/ptrace.c | 16 +- fs/binfmt_elf.c | 54 ++- include/linux/regset.h | 218 +++------- kernel/Makefile | 2 +- kernel/regset.c | 76 ++++ 41 files changed, 1368 insertions(+), 2347 deletions(-)
Al Viro
maintainerPATCH 1/41 introduction of regset ->get() wrappers, switching ELF coredumps to those
From: Al Viro <[email protected]>
Two new helpers: given a process and regset, dump into a buffer. regset_get() takes a buffer and size, regset_get_alloc() takes size and allocates a buffer.
Return value in both cases is the amount of data actually dumped in case of success or -E... on error.
In both cases the size is capped by regset->n * regset->size, so ->get() is called with offset 0 and size no more than what regset expects.
binfmt_elf.c callers of ->get() are switched to using those; the other caller (copy_regset_to_user()) will need some preparations to switch.
--- fs/binfmt_elf.c | 54 ++++++++++++++++++++++++-------------------------- include/linux/regset.h | 9 +++++++++ kernel/Makefile | 2 +- kernel/regset.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 90 insertions(+), 29 deletions(-) create mode 100644 kernel/regset.c
fs/binfmt_elf.c +26 -28
@@ -1821,7 +1821,7 @@ static int fill_thread_core_info(struct elf_thread_core_info *t, long signr, size_t *total) {unsigned int i; -unsigned int regset0_size =regset_size (t->task, &view->regsets[0 ]); +unsigned int regset0_size;/* * NT_PRSTATUS is the one special case, because the regset data
@@ -1830,8 +1830,10 @@ static int fill_thread_core_info(struct elf_thread_core_info *t,* We assume that regset 0 is NT_PRSTATUS. */ fill_prstatus (&t->prstatus, t->task, signr); - (void ) view->regsets[0 ].get (t->task, &view->regsets[0 ],0 , regset0_size, - &t->prstatus.pr_reg,NULL ); + regset0_size =regset_get (t->task, &view->regsets[0 ], +sizeof (t->prstatus.pr_reg), &t->prstatus.pr_reg); +if (regset0_size <0 ) +return 0 ;fill_note (&t->notes[0 ],"CORE" ,NT_PRSTATUS ,PRSTATUS_SIZE (t->prstatus, regset0_size), &t->prstatus);
@@ -1846,32 +1848,28 @@ static int fill_thread_core_info(struct elf_thread_core_info *t,*/ for (i =1 ; i < view->n; ++i) {const struct user_regset *regset = &view->regsets[i]; +int note_type = regset->core_note_type; +bool is_fpreg = note_type ==NT_PRFPREG ; +void *data; +int ret; +do_thread_regset_writeback (t->task, regset); -if (regset->core_note_type && regset->get && - (!regset->active || regset->active (t->task, regset) >0 )) { -int ret; -size_t size =regset_size (t->task, regset); -void *data =kzalloc (size,GFP_KERNEL ); -if (unlikely (!data)) -return 0 ; - ret = regset->get (t->task, regset, -0 , size, data,NULL ); -if (unlikely (ret)) -kfree (data); -else { -if (regset->core_note_type !=NT_PRFPREG ) -fill_note (&t->notes[i],"LINUX" , - regset->core_note_type, - size, data); -else { -SET_PR_FPVALID (&t->prstatus, -1 , regset0_size); -fill_note (&t->notes[i],"CORE" , -NT_PRFPREG , size, data); - } - *total +=notesize (&t->notes[i]); - } - } +if (!note_type)// not for coredumps +continue ; +if (regset->active && regset->active (t->task, regset) <=0 ) +continue ; + + ret =regset_get_alloc (t->task, regset, ~0U , &data); +if (ret <0 ) +continue ; + +if (is_fpreg) +SET_PR_FPVALID (&t->prstatus,1 , regset0_size); + +fill_note (&t->notes[i], is_fpreg ?"CORE" :"LINUX" , + note_type, ret, data); + + *total +=notesize (&t->notes[i]); }return 1 ;
include/linux/regset.h +9 -0
@@ -353,6 +353,15 @@ static inline int user_regset_copyin_ignore(unsigned int *pos,return 0 ; } +extern int regset_get (struct task_struct *target, +const struct user_regset *regset, +unsigned int size,void *data); + +extern int regset_get_alloc (struct task_struct *target, +const struct user_regset *regset, +unsigned int size, +void **data); +/** * copy_regset_to_user - fetch a thread's user_regset data into user memory * @target: thread to be examined
kernel/Makefile +1 -1
@@ -10,7 +10,7 @@ obj-y = fork.o exec_domain.o panic.o \ extable.o params.o \ kthread.o sys_ni.o nsproxy.o \ notifier.o ksysfs.o cred.o reboot.o \ - async.o range.o smpboot.o ucount.o + async.o range.o smpboot.o ucount.o regset.o obj-$(CONFIG_MODULES) += kmod.o obj-$(CONFIG_MULTIUSER) += groups.o
kernel/regset.c new file +54 -0
54 lines not on this page · raw message
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 2/41 x86: copy_fpstate_to_sigframe(): have fpregs_soft_get() use kernel buffer
From: Al Viro <[email protected]>
... then copy_to_user() the results
--- arch/x86/kernel/fpu/signal.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
arch/x86/kernel/fpu/signal.c +6 -6
@@ -170,14 +170,14 @@ int copy_fpstate_to_sigframe(void __user *buf, void __user *buf_fx, int size) ia32_fxstate &= (IS_ENABLED (CONFIG_X86_32 ) ||IS_ENABLED (CONFIG_IA32_EMULATION )); +if (!static_cpu_has (X86_FEATURE_FPU )) { +struct user_i387_ia32_struct fp; +fpregs_soft_get (current,NULL ,0 ,sizeof (fp), &fp,NULL ); +return copy_to_user (buf, &fp,sizeof (fp)) ? -EFAULT :0 ; + } +if (!access_ok (buf, size))return -EACCES ; - -if (!static_cpu_has (X86_FEATURE_FPU )) -return fpregs_soft_get (current,NULL ,0 , -sizeof (struct user_i387_ia32_struct ),NULL , - (struct _fpstate_32 __user *) buf) ?-1 :1 ; - retry:/* * Load the FPU registers if they are not valid for the current task.
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 3/41 x86: kill dump_fpu()
In reply to Al ViroFrom: Al Viro <[email protected]>
dead since the removal of aout coredump support...
--- arch/x86/include/asm/fpu/internal.h | 1 - arch/x86/kernel/fpu/regset.c | 16 ---------------- 2 files changed, 17 deletions(-)
arch/x86/include/asm/fpu/internal.h +0 -1
@@ -34,7 +34,6 @@ extern int fpu__copy(struct task_struct *dst, struct task_struct *src);extern void fpu__clear_user_states (struct fpu *fpu);extern void fpu__clear_all (struct fpu *fpu);extern int fpu__exception_code (struct fpu *fpu,int trap_nr); -extern int dump_fpu (struct pt_regs *ptregs,struct user_i387_struct *fpstate);/* * Boot time FPU initialization functions:
arch/x86/kernel/fpu/regset.c +0 -16
@@ -356,20 +356,4 @@ int fpregs_set(struct task_struct *target, const struct user_regset *regset, return ret; } -/* -* FPU state for core dumps. -* This is only used for a.out dumps now. -* It is declared generically using elf_fpregset_t (which is -* struct user_i387_struct) but is in fact only used for 32-bit -* dumps, so on 64-bit it is really struct user_i387_ia32_struct. -*/ -int dump_fpu (struct pt_regs *regs,struct user_i387_struct *ufpu) -{ -struct task_struct *tsk = current; - -return !fpregs_get (tsk,NULL ,0 ,sizeof (struct user_i387_ia32_struct ), - ufpu,NULL ); -} -EXPORT_SYMBOL (dump_fpu); -#endif /* CONFIG_X86_32 || CONFIG_IA32_EMULATION */
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 4/41 sanitize elf_access_gpreg()
In reply to Al ViroFrom: Al Viro <[email protected]>
The function takes the register number, finds the corresponding field of pt_regs for registers that are saved there or does the unwind for the registers that end up spilled on the kernel stack. Then it reads from or writes to the resulting location.
Unfortunately, finding the required pt_regs field is done by rather horrible switch. It's microoptimized in all the wrong places - it even uses the knowledge that fields for r8..r11 follow each other in pt_regs layout, while r12..r13 are not adjacent to those, etc.
All of that is to encode the mapping from register numbers to offsets + the information that r4..r7 are not to be found in pt_regs.
It's deeply in nasal demon territory, at that - the games it plays with pointer arithmetics on addresses of structure members are undefined behaviour.
Valid C ends up with better code in this case: just initialize a constant array with offsets of relevant pt_regs fields and we don't need that switch anymore.
--- arch/ia64/kernel/ptrace.c | 57 +++++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 34 deletions(-)
arch/ia64/kernel/ptrace.c +23 -34
@@ -1273,52 +1273,41 @@ struct regset_getset {int ret; }; +static const ptrdiff_t pt_offsets[16 ] = +{ +#define R(n) offsetof(struct pt_regs, r##n) + [0 ] =-1 ,R (1 ),R (2 ),R (3 ), + [4 ] =-1 , [5 ] =-1 , [6 ] =-1 , [7 ] =-1 , +R (8 ),R (9 ),R (10 ),R (11 ),R (12 ),R (13 ),R (14 ),R (15 ), +#undef R +}; +static int access_elf_gpreg (struct task_struct *target,struct unw_frame_info *info,unsigned long addr,unsigned long *data,int write_access) { -struct pt_regs *pt; -unsigned long *ptr =NULL ; -int ret; -char nat =0 ; +struct pt_regs *pt =task_pt_regs (target); +unsigned reg = addr /sizeof (unsigned long ); +ptrdiff_t d = pt_offsets[reg]; - pt =task_pt_regs (target); -switch (addr) { -case ELF_GR_OFFSET (1 ): - ptr = &pt->r1; -break ; -case ELF_GR_OFFSET (2 ): -case ELF_GR_OFFSET (3 ): - ptr = (void *)&pt->r2 + (addr -ELF_GR_OFFSET (2 )); -break ; - case ELF_GR_OFFSET(4) ... ELF_GR_OFFSET(7): +if (d >=0 ) { +unsigned long *ptr = (void *)pt + d; +if (write_access) + *ptr = *data; +else + *data = *ptr; +return 0 ; + }else { +char nat =0 ;if (write_access) {/* read NaT bit first: */ unsigned long dummy; - - ret =unw_get_gr (info, addr/8 , &dummy, &nat); +int ret =unw_get_gr (info, reg, &dummy, &nat);if (ret <0 )return ret; } -return unw_access_gr (info, addr/8 , data, &nat, write_access); - case ELF_GR_OFFSET(8) ... ELF_GR_OFFSET(11): - ptr = (void *)&pt->r8 + addr -ELF_GR_OFFSET (8 ); -break ; -case ELF_GR_OFFSET (12 ): -case ELF_GR_OFFSET (13 ): - ptr = (void *)&pt->r12 + addr -ELF_GR_OFFSET (12 ); -break ; -case ELF_GR_OFFSET (14 ): - ptr = &pt->r14; -break ; -case ELF_GR_OFFSET (15 ): - ptr = &pt->r15; +return unw_access_gr (info, reg, data, &nat, write_access); } -if (write_access) - *ptr = *data; -else - *data = *ptr; -return 0 ; } static int
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 5/41 teach elf_access_reg() to handle the missing range (r16..r31)
In reply to Al ViroFrom: Al Viro <[email protected]>
Now it's easy to make elf_access_gpreg() handle the rest of global registers (r16..r31). That gets rid of the hole in the registers elf_access_reg() can handle, which will allow to simplify its callers later in the series.
--- arch/ia64/kernel/ptrace.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
arch/ia64/kernel/ptrace.c +4 -2
@@ -1273,12 +1273,14 @@ struct regset_getset {int ret; }; -static const ptrdiff_t pt_offsets[16 ] = +static const ptrdiff_t pt_offsets[32 ] = { #define R(n) offsetof(struct pt_regs, r##n) [0 ] =-1 ,R (1 ),R (2 ),R (3 ), [4 ] =-1 , [5 ] =-1 , [6 ] =-1 , [7 ] =-1 ,R (8 ),R (9 ),R (10 ),R (11 ),R (12 ),R (13 ),R (14 ),R (15 ), +R (16 ),R (17 ),R (18 ),R (19 ),R (20 ),R (21 ),R (22 ),R (23 ), +R (24 ),R (25 ),R (26 ),R (27 ),R (28 ),R (29 ),R (30 ),R (31 ), #undef R };
@@ -1479,7 +1481,7 @@ static int access_elf_reg(struct task_struct *target, struct unw_frame_info *info, unsigned long addr, unsigned long *data, int write_access) { - if (addr >= ELF_GR_OFFSET(1) && addr <= ELF_GR_OFFSET(15)) + if (addr >= ELF_GR_OFFSET(1) && addr <= ELF_GR_OFFSET(31)) return access_elf_gpreg(target, info, addr, data, write_access); else if (addr >= ELF_BR_OFFSET(0) && addr <= ELF_BR_OFFSET(7)) return access_elf_breg(target, info, addr, data, write_access);
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 6/41 regularize do_gpregs_[gs]et()
In reply to Al ViroFrom: Al Viro <[email protected]>
now access_elf_reg() does the right thing for everything other than r0, we can simplify do_grepgs_[gs]et()
--- arch/ia64/kernel/ptrace.c | 155 ++++++++++------------------------------------ 1 file changed, 31 insertions(+), 124 deletions(-)
arch/ia64/kernel/ptrace.c +31 -124
@@ -1491,10 +1491,7 @@ access_elf_reg(struct task_struct *target, struct unw_frame_info *info,void do_gpregs_get (struct unw_frame_info *info,void *arg) { -struct pt_regs *pt;struct regset_getset *dst = arg; -elf_greg_t tmp[16 ]; -unsigned int i, index, min_copy;if (unw_unwind_to_user (info) <0 )return ;
@@ -1517,160 +1514,70 @@ void do_gpregs_get(struct unw_frame_info *info, void *arg) &dst->u.get.kbuf, &dst->u.get.ubuf, 0, ELF_GR_OFFSET(1)); -if (dst->ret || dst->count ==0 ) -return ; - } - -/* gr1 - gr15 */ -if (dst->count >0 && dst->pos <ELF_GR_OFFSET (16 )) { - index = (dst->pos -ELF_GR_OFFSET (1 )) /sizeof (elf_greg_t); - min_copy =ELF_GR_OFFSET (16 ) > (dst->pos + dst->count) ? - (dst->pos + dst->count) :ELF_GR_OFFSET (16 ); -for (i = dst->pos; i < min_copy; i +=sizeof (elf_greg_t), - index++) -if (access_elf_reg (dst->target, info, i, - &tmp[index],0 ) <0 ) { - dst->ret = -EIO ; -return ; - } - dst->ret =user_regset_copyout (&dst->pos, &dst->count, - &dst->u.get.kbuf, &dst->u.get.ubuf, tmp, -ELF_GR_OFFSET (1 ),ELF_GR_OFFSET (16 )); -if (dst->ret || dst->count ==0 ) -return ; - } - -/* r16-r31 */ -if (dst->count >0 && dst->pos <ELF_NAT_OFFSET ) { - pt =task_pt_regs (dst->target); - dst->ret =user_regset_copyout (&dst->pos, &dst->count, - &dst->u.get.kbuf, &dst->u.get.ubuf, &pt->r16, -ELF_GR_OFFSET (16 ),ELF_NAT_OFFSET ); -if (dst->ret || dst->count ==0 ) +if (dst->ret)return ; } -/* nat, pr, b0 - b7 */ -if (dst->count >0 && dst->pos <ELF_CR_IIP_OFFSET ) { - index = (dst->pos -ELF_NAT_OFFSET ) /sizeof (elf_greg_t); - min_copy =ELF_CR_IIP_OFFSET > (dst->pos + dst->count) ? - (dst->pos + dst->count) :ELF_CR_IIP_OFFSET ; -for (i = dst->pos; i < min_copy; i +=sizeof (elf_greg_t), - index++) -if (access_elf_reg (dst->target, info, i, - &tmp[index],0 ) <0 ) { +while (dst->count && dst->pos <ELF_AR_END_OFFSET ) { +unsigned int n, from, to; +elf_greg_t tmp[16 ]; + + from = dst->pos; + to = from +min (dst->count, (unsigned )sizeof (tmp)); +if (to >ELF_AR_END_OFFSET ) + to =ELF_AR_END_OFFSET ; +for (n =0 ; from < to; from +=sizeof (elf_greg_t), n++) { +if (access_elf_reg (dst->target, info, from, + &tmp[n],0 ) <0 ) { dst->ret = -EIO ;return ; } + } dst->ret =user_regset_copyout (&dst->pos, &dst->count, &dst->u.get.kbuf, &dst->u.get.ubuf, tmp, -ELF_NAT_OFFSET ,ELF_CR_IIP_OFFSET ); -if (dst->ret || dst->count ==0 ) + dst->pos, to); +if (dst->ret)return ; } - -/* ip cfm psr ar.rsc ar.bsp ar.bspstore ar.rnat -* ar.ccv ar.unat ar.fpsr ar.pfs ar.lc ar.ec ar.csd ar.ssd -*/ -if (dst->count >0 && dst->pos < (ELF_AR_END_OFFSET )) { - index = (dst->pos -ELF_CR_IIP_OFFSET ) /sizeof (elf_greg_t); - min_copy =ELF_AR_END_OFFSET > (dst->pos + dst->count) ? - (dst->pos + dst->count) :ELF_AR_END_OFFSET ; -for (i = dst->pos; i < min_copy; i +=sizeof (elf_greg_t), - index++) -if (access_elf_reg (dst->target, info, i, - &tmp[index],0 ) <0 ) { - dst->ret = -EIO ; -return ; - } - dst->ret =user_regset_copyout (&dst->pos, &dst->count, - &dst->u.get.kbuf, &dst->u.get.ubuf, tmp, -ELF_CR_IIP_OFFSET ,ELF_AR_END_OFFSET ); - } }void do_gpregs_set (struct unw_frame_info *info,void *arg) { -struct pt_regs *pt;struct regset_getset *dst = arg; -elf_greg_t tmp[16 ]; -unsigned int i, index;if (unw_unwind_to_user (info) <0 )return ; +if (!dst->count) +return ;/* Skip r0 */ -if (dst->count >0 && dst->pos <ELF_GR_OFFSET (1 )) { +if (dst->pos <ELF_GR_OFFSET (1 )) { dst->ret =user_regset_copyin_ignore (&dst->pos, &dst->count, &dst->u.set.kbuf, &dst->u.set.ubuf,0 ,ELF_GR_OFFSET (1 )); -if (dst->ret || dst->count ==0 ) -return ; - } - -/* gr1-gr15 */ -if (dst->count >0 && dst->pos <ELF_GR_OFFSET (16 )) { - i = dst->pos; - index = (dst->pos -ELF_GR_OFFSET (1 )) /sizeof (elf_greg_t); - dst->ret =user_regset_copyin (&dst->pos, &dst->count, - &dst->u.set.kbuf, &dst->u.set.ubuf, tmp, -ELF_GR_OFFSET (1 ),ELF_GR_OFFSET (16 ));if (dst->ret)return ; -for ( ; i < dst->pos; i +=sizeof (elf_greg_t), index++) -if (access_elf_reg (dst->target, info, i, - &tmp[index],1 ) <0 ) { - dst->ret = -EIO ; -return ; - } -if (dst->count ==0 ) -return ; - } - -/* gr16-gr31 */ -if (dst->count >0 && dst->pos <ELF_NAT_OFFSET ) { - pt =task_pt_regs (dst->target); - dst->ret =user_regset_copyin (&dst->pos, &dst->count, - &dst->u.set.kbuf, &dst->u.set.ubuf, &pt->r16, -ELF_GR_OFFSET (16 ),ELF_NAT_OFFSET ); -if (dst->ret || dst->count ==0 ) -return ; } -/* nat, pr, b0 - b7 */ -if (dst->count >0 && dst->pos <ELF_CR_IIP_OFFSET ) { - i = dst->pos; - index = (dst->pos -ELF_NAT_OFFSET ) /sizeof (elf_greg_t); - dst->ret =user_regset_copyin (&dst->pos, &dst->count, - &dst->u.set.kbuf, &dst->u.set.ubuf, tmp, -ELF_NAT_OFFSET ,ELF_CR_IIP_OFFSET ); -if (dst->ret) -return ; -for (; i < dst->pos; i +=sizeof (elf_greg_t), index++) -if (access_elf_reg (dst->target, info, i, - &tmp[index],1 ) <0 ) { - dst->ret = -EIO ; -return ; - } -if (dst->count ==0 ) -return ; - } +while (dst->count && dst->pos <ELF_AR_END_OFFSET ) { +unsigned int n, from, to; +elf_greg_t tmp[16 ]; -/* ip cfm psr ar.rsc ar.bsp ar.bspstore ar.rnat -* ar.ccv ar.unat ar.fpsr ar.pfs ar.lc ar.ec ar.csd ar.ssd -*/ -if (dst->count >0 && dst->pos < (ELF_AR_END_OFFSET )) { - i = dst->pos; - index = (dst->pos -ELF_CR_IIP_OFFSET ) /sizeof (elf_greg_t); + from = dst->pos; + to = from +sizeof (tmp); +if (to >ELF_AR_END_OFFSET ) + to =ELF_AR_END_OFFSET ; +/* get up to 16 values */ dst->ret =user_regset_copyin (&dst->pos, &dst->count, &dst->u.set.kbuf, &dst->u.set.ubuf, tmp, -ELF_CR_IIP_OFFSET ,ELF_AR_END_OFFSET ); + from, to);if (dst->ret)return ; -for ( ; i < dst->pos; i +=sizeof (elf_greg_t), index++) -if (access_elf_reg (dst->target, info, i, - &tmp[index],1 ) <0 ) { +/* now copy them into registers */ +for (n =0 ; from < dst->pos; from +=sizeof (elf_greg_t), n++) +if (access_elf_reg (dst->target, info, from, + &tmp[n],1 ) <0 ) { dst->ret = -EIO ;return ; }
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 7/41 access_uarea(): stop bothering with gpregs_[gs]et()
In reply to Al ViroFrom: Al Viro <[email protected]>
We know this won't be called for child == current, so we don't need to bother with callbacks, etc. - just do unw_init_from_blocked_task(), unw_unwind_to_user() and do the payload of gpregs_[gs]et(). For one register. Which is to say, access_elf_reg().
--- arch/ia64/kernel/ptrace.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
arch/ia64/kernel/ptrace.c +8 -9
@@ -1936,15 +1936,14 @@ access_uarea(struct task_struct *child, unsigned long addr, }if (pos !=-1 ) { -if (write_access) - ret =gpregs_set (child,NULL , pos, -sizeof (unsigned long ), data,NULL ); -else - ret =gpregs_get (child,NULL , pos, -sizeof (unsigned long ), data,NULL ); -if (ret !=0 ) -return -1 ; -return 0 ; +struct unw_frame_info info; + +memset (&info,0 ,sizeof (info)); +unw_init_from_blocked_task (&info, child); +if (unw_unwind_to_user (&info) <0 ) +return 0 ; + +return access_elf_reg (child, &info, pos, data, write_access); }/* access debug registers */
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 8/41 access_uarea(): don't bother with fpregs_[gs]et()
In reply to Al ViroFrom: Al Viro <[email protected]>
similar to previous commit...
--- arch/ia64/kernel/ptrace.c | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-)
arch/ia64/kernel/ptrace.c +33 -9
@@ -1811,7 +1811,6 @@ access_uarea(struct task_struct *child, unsigned long addr, unsigned long *data, int write_access) {unsigned int pos =-1 ;/* an invalid value */ -int ret;unsigned long *ptr, regnum;if ((addr &0x7 ) !=0 ) {
@@ -1843,14 +1842,39 @@ access_uarea(struct task_struct *child, unsigned long addr, }if (pos !=-1 ) { -if (write_access) - ret =fpregs_set (child,NULL , pos, -sizeof (unsigned long ), data,NULL ); -else - ret =fpregs_get (child,NULL , pos, -sizeof (unsigned long ), data,NULL ); -if (ret !=0 ) -return -1 ; +unsigned reg = pos /sizeof (elf_fpreg_t); +int which_half = (pos /sizeof (unsigned long )) &1 ; + +if (reg <32 ) {/* fr2-fr31 */ +struct unw_frame_info info; +elf_fpreg_t fpreg; + +memset (&info,0 ,sizeof (info)); +unw_init_from_blocked_task (&info, child); +if (unw_unwind_to_user (&info) <0 ) +return 0 ; + +if (unw_get_fr (&info, reg, &fpreg)) +return -1 ; +if (write_access) { + fpreg.u.bits[which_half] = *data; +if (unw_set_fr (&info, reg, fpreg)) +return -1 ; + }else { + *data = fpreg.u.bits[which_half]; + } + }else {/* fph */ +elf_fpreg_t *p = &child->thread.fph[reg -32 ]; +unsigned long *bits = &p->u.bits[which_half]; + +ia64_sync_fph (child); +if (write_access) + *bits = *data; +else if (child->thread.flags &IA64_THREAD_FPH_VALID ) + *data = *bits; +else + *data =0 ; + }return 0 ; }
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 9/41 sparc64: switch genregs32_get() to use of get_from_target()
In reply to Al ViroFrom: Al Viro <[email protected]>
... for fetching the register window from target's stack, rather than open-coding it.
--- arch/sparc/kernel/ptrace_64.c | 59 ++++++++++++------------------------------- 1 file changed, 16 insertions(+), 43 deletions(-)
arch/sparc/kernel/ptrace_64.c +16 -43
@@ -518,10 +518,10 @@ static int genregs32_get(struct task_struct *target, void *kbuf, void __user *ubuf) {const struct pt_regs *regs =task_pt_regs (target); -compat_ulong_t __user *reg_window;compat_ulong_t *k = kbuf;compat_ulong_t __user *u = ubuf; -compat_ulong_t reg; +u32 uregs[16 ]; +u32 reg;if (target == current)flushw_user ();
@@ -533,52 +533,25 @@ static int genregs32_get(struct task_struct *target,for (; count >0 && pos <16 ; count--) *k++ = regs->u_regs[pos++]; - reg_window = (compat_ulong_t __user *) regs->u_regs[UREG_I6 ]; - reg_window -=16 ; -if (target == current) { -for (; count >0 && pos <32 ; count--) { -if (get_user (*k++, ®_window[pos++])) -return -EFAULT ; - } - }else { -for (; count >0 && pos <32 ; count--) { -if (access_process_vm (target, - (unsigned long ) - ®_window[pos], - k,sizeof (*k), -FOLL_FORCE ) - !=sizeof (*k)) -return -EFAULT ; - k++; - pos++; - } +if (count && pos <32 ) { +if (get_from_target (target, regs->u_regs[UREG_I6 ], + uregs,sizeof (uregs))) +return -EFAULT ; +for (; count >0 && pos <32 ; count--) + *k++ = uregs[pos++ -16 ]; + } }else { -for (; count >0 && pos <16 ; count--) { +for (; count >0 && pos <16 ; count--)if (put_user ((compat_ulong_t ) regs->u_regs[pos++], u++))return -EFAULT ; - } - - reg_window = (compat_ulong_t __user *) regs->u_regs[UREG_I6 ]; - reg_window -=16 ; -if (target == current) { -for (; count >0 && pos <32 ; count--) { -if (get_user (reg, ®_window[pos++]) || -put_user (reg, u++)) -return -EFAULT ; - } - }else { -for (; count >0 && pos <32 ; count--) { -if (access_process_vm (target, - (unsigned long ) - ®_window[pos++], - ®,sizeof (reg), -FOLL_FORCE ) - !=sizeof (reg)) -return -EFAULT ; -if (put_user (reg, u++)) +if (count && pos <32 ) { +if (get_from_target (target, regs->u_regs[UREG_I6 ], + uregs,sizeof (uregs))) +return -EFAULT ; +for (; count >0 && pos <32 ; count--) +if (put_user (uregs[pos++ -16 ], u++))return -EFAULT ; - } } }while (count >0 ) {
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 10/41 sparc32: get rid of odd callers of copy_regset_to_user()
In reply to Al ViroFrom: Al Viro <[email protected]>
the life is much simpler if copy_regset_to_user() (and ->get()) gets called only with pos == 0; sparc32 PTRACE_GETREGS and PTRACE_GETFPREGS are among the few things that use it to fetch pieces of regset _not_ starting at the beginning. It's actually easier to define a separate regset that would provide what we need, rather than trying to cobble that from the one PTRACE_GETREGSET uses.
Extra ->get() instances do not amount to much code and once we get the conversion of ->get() to new API (dependent upon the lack of weird callers of ->get()) they'll shrink a lot, along with the rest of ->get() instances...
--- arch/sparc/kernel/ptrace_32.c | 117 +++++++++++++++++++++++++++++------------- 1 file changed, 82 insertions(+), 35 deletions(-)
arch/sparc/kernel/ptrace_32.c +82 -35
@@ -99,15 +99,13 @@ static int genregs32_get(struct task_struct *target,if (ret || !count)return ret; -if (pos <32 *sizeof (u32)) { -if (regwindow32_get (target, regs, uregs)) -return -EFAULT ; - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - uregs, -16 *sizeof (u32),32 *sizeof (u32)); -if (ret || !count) -return ret; - } +if (regwindow32_get (target, regs, uregs)) +return -EFAULT ; + ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, + uregs, +16 *sizeof (u32),32 *sizeof (u32)); +if (ret) +return ret; uregs[0 ] = regs->psr; uregs[1 ] = regs->pc;
@@ -288,6 +286,73 @@ static const struct user_regset sparc32_regsets[] = { }, }; +static int getregs_get (struct task_struct *target, +const struct user_regset *regset, +unsigned int pos,unsigned int count, +void *kbuf,void __user *ubuf) +{ +const struct pt_regs *regs = target->thread.kregs; +u32 v[4 ]; +int ret; + +if (target == current) +flush_user_windows (); + + v[0 ] = regs->psr; + v[1 ] = regs->pc; + v[2 ] = regs->npc; + v[3 ] = regs->y; + ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, + v, +0 *sizeof (u32),4 *sizeof (u32)); +if (ret) +return ret; + +return user_regset_copyout (&pos, &count, &kbuf, &ubuf, + regs->u_regs +1 , +4 *sizeof (u32),19 *sizeof (u32)); +} + +static int getfpregs_get (struct task_struct *target, +const struct user_regset *regset, +unsigned int pos,unsigned int count, +void *kbuf,void __user *ubuf) +{ +const unsigned long *fpregs = target->thread.float_regs; +int ret =0 ; + +#if 0 +if (target == current) +save_and_clear_fpu (); +#endif + + ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, + fpregs, +0 ,32 *sizeof (u32)); +if (ret) +return ret; + ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, + &target->thread.fsr, +32 *sizeof (u32),33 *sizeof (u32)); +if (ret) +return ret; +return user_regset_copyout_zero (&pos, &count, &kbuf, &ubuf, +33 *sizeof (u32),68 *sizeof (u32)); +} + +static const struct user_regset ptrace32_regsets[] = { + [REGSET_GENERAL ] = { + .n =19 , .size =sizeof (u32), .get = getregs_get, + }, + [REGSET_FP ] = { + .n =68 , .size =sizeof (u32), .get = getfpregs_get, + }, +}; + +static const struct user_regset_view ptrace32_view = { + .regsets = ptrace32_regsets, .n =ARRAY_SIZE (ptrace32_regsets) +}; +static const struct user_regset_view user_sparc32_view = { .name ="sparc" , .e_machine =EM_SPARC , .regsets = sparc32_regsets, .n =ARRAY_SIZE (sparc32_regsets)
@@ -327,15 +392,10 @@ long arch_ptrace(struct task_struct *child, long request,switch (request) {case PTRACE_GETREGS : { - ret =copy_regset_to_user (child, view,REGSET_GENERAL , -32 *sizeof (u32), -4 *sizeof (u32), - &pregs->psr); -if (!ret) -copy_regset_to_user (child, view,REGSET_GENERAL , -1 *sizeof (u32), -15 *sizeof (u32), - &pregs->u_regs[0 ]); + ret =copy_regset_to_user (child, &ptrace32_view, +REGSET_GENERAL ,0 , +19 *sizeof (u32), + pregs);break ; }
@@ -353,23 +413,10 @@ long arch_ptrace(struct task_struct *child, long request, }case PTRACE_GETFPREGS : { - ret =copy_regset_to_user (child, view,REGSET_FP , -0 *sizeof (u32), -32 *sizeof (u32), - &fps->regs[0 ]); -if (!ret) - ret =copy_regset_to_user (child, view,REGSET_FP , -33 *sizeof (u32), -1 *sizeof (u32), - &fps->fsr); - -if (!ret) { -if (__put_user (0 , &fps->fpqd) || -__put_user (0 , &fps->flags) || -__put_user (0 , &fps->extra) || -clear_user (fps->fpq,sizeof (fps->fpq))) - ret = -EFAULT ; - } + ret =copy_regset_to_user (child, &ptrace32_view, +REGSET_FP ,0 , +68 *sizeof (u32), + fps);break ; }
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 11/41 sparc64: get rid of odd callers of copy_regset_to_user()
In reply to Al ViroFrom: Al Viro <[email protected]>
same as for sparc32, and that's it - no more caller of ->get() with non-zero pos.
--- arch/sparc/kernel/ptrace_64.c | 175 ++++++++++++++++++++++++++++++++---------- 1 file changed, 136 insertions(+), 39 deletions(-)
arch/sparc/kernel/ptrace_64.c +136 -39
@@ -258,7 +258,7 @@ static int genregs64_get(struct task_struct *target, ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, regs->u_regs,0 ,16 *sizeof (u64)); -if (!ret && count && pos < (32 *sizeof (u64))) { +if (!ret && count) {struct reg_window window;if (regwindow64_get (target, regs, &window))
@@ -506,6 +506,57 @@ static const struct user_regset sparc64_regsets[] = { }, }; +static int getregs64_get (struct task_struct *target, +const struct user_regset *regset, +unsigned int pos,unsigned int count, +void *kbuf,void __user *ubuf) +{ +const struct pt_regs *regs =task_pt_regs (target); +int ret; + +if (target == current) +flushw_user (); + + ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, + regs->u_regs +1 , +0 ,15 *sizeof (u64)); +if (!ret) + ret =user_regset_copyout_zero (&pos, &count, &kbuf, &ubuf, +15 *sizeof (u64),16 *sizeof (u64)); +if (!ret) { +/* TSTATE, TPC, TNPC */ + ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, + ®s->tstate, +16 *sizeof (u64), +19 *sizeof (u64)); + } +if (!ret) { +unsigned long y = regs->y; + + ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, + &y, +19 *sizeof (u64), +20 *sizeof (u64)); + } +return ret; +} + +static const struct user_regset ptrace64_regsets[] = { +/* Format is: +* G1 --> G7 +* O0 --> O7 +* 0 +* TSTATE, TPC, TNPC, Y +*/ + [REGSET_GENERAL ] = { + .n =20 , .size =sizeof (u64), .get = getregs64_get, + }, +}; + +static const struct user_regset_view ptrace64_view = { + .regsets = ptrace64_regsets, .n =ARRAY_SIZE (ptrace64_regsets) +}; +static const struct user_regset_view user_sparc64_view = { .name ="sparc64" , .e_machine =EM_SPARCV9 , .regsets = sparc64_regsets, .n =ARRAY_SIZE (sparc64_regsets)
@@ -533,7 +584,7 @@ static int genregs32_get(struct task_struct *target,for (; count >0 && pos <16 ; count--) *k++ = regs->u_regs[pos++]; -if (count && pos <32 ) { +if (count) {if (get_from_target (target, regs->u_regs[UREG_I6 ], uregs,sizeof (uregs)))return -EFAULT ;
@@ -545,7 +596,7 @@ static int genregs32_get(struct task_struct *target,for (; count >0 && pos <16 ; count--)if (put_user ((compat_ulong_t ) regs->u_regs[pos++], u++))return -EFAULT ; -if (count && pos <32 ) { +if (count) {if (get_from_target (target, regs->u_regs[UREG_I6 ], uregs,sizeof (uregs)))return -EFAULT ;
@@ -840,6 +891,76 @@ static const struct user_regset sparc32_regsets[] = { }, }; +static int getregs_get (struct task_struct *target, +const struct user_regset *regset, +unsigned int pos,unsigned int count, +void *kbuf,void __user *ubuf) +{ +const struct pt_regs *regs =task_pt_regs (target); +u32 uregs[19 ]; +int i; + +if (target == current) +flushw_user (); + + uregs[0 ] =tstate_to_psr (regs->tstate); + uregs[1 ] = regs->tpc; + uregs[2 ] = regs->tnpc; + uregs[3 ] = regs->y; +for (i =1 ; i <16 ; i++) + uregs[3 + i] = regs->u_regs[i]; +return user_regset_copyout (&pos, &count, &kbuf, &ubuf, + uregs, +0 ,19 *sizeof (u32)); +} + +static int getfpregs_get (struct task_struct *target, +const struct user_regset *regset, +unsigned int pos,unsigned int count, +void *kbuf,void __user *ubuf) +{ +const unsigned long *fpregs =task_thread_info (target)->fpregs; +unsigned long fprs; +compat_ulong_t fsr; +int ret =0 ; + +if (target == current) +save_and_clear_fpu (); + + fprs =task_thread_info (target)->fpsaved[0 ]; +if (fprs &FPRS_FEF ) { + fsr =task_thread_info (target)->xfsr[0 ]; + }else { + fsr =0 ; + } + + ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, + fpregs, +0 ,32 *sizeof (u32)); +if (!ret) + ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, + &fsr, +32 *sizeof (u32), +33 *sizeof (u32)); +if (!ret) + ret =user_regset_copyout_zero (&pos, &count, &kbuf, &ubuf, +33 *sizeof (u32),68 *sizeof (u32)); +return ret; +} + +static const struct user_regset ptrace32_regsets[] = { + [REGSET_GENERAL ] = { + .n =19 , .size =sizeof (u32), .get = getregs_get, + }, + [REGSET_FP ] = { + .n =68 , .size =sizeof (u32), .get = getfpregs_get, + }, +}; + +static const struct user_regset_view ptrace32_view = { + .regsets = ptrace32_regsets, .n =ARRAY_SIZE (ptrace32_regsets) +}; +static const struct user_regset_view user_sparc32_view = { .name ="sparc" , .e_machine =EM_SPARC , .regsets = sparc32_regsets, .n =ARRAY_SIZE (sparc32_regsets)
@@ -889,15 +1010,10 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,break ;case PTRACE_GETREGS : - ret =copy_regset_to_user (child, view,REGSET_GENERAL , -32 *sizeof (u32), -4 *sizeof (u32), - &pregs->psr); -if (!ret) - ret =copy_regset_to_user (child, view,REGSET_GENERAL , -1 *sizeof (u32), -15 *sizeof (u32), - &pregs->u_regs[0 ]); + ret =copy_regset_to_user (child, &ptrace32_view, +REGSET_GENERAL ,0 , +19 *sizeof (u32), + pregs);break ;case PTRACE_SETREGS :
@@ -913,22 +1029,10 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,break ;case PTRACE_GETFPREGS : - ret =copy_regset_to_user (child, view,REGSET_FP , -0 *sizeof (u32), -32 *sizeof (u32), - &fps->regs[0 ]); -if (!ret) - ret =copy_regset_to_user (child, view,REGSET_FP , -33 *sizeof (u32), -1 *sizeof (u32), - &fps->fsr); -if (!ret) { -if (__put_user (0 , &fps->flags) || -__put_user (0 , &fps->extra) || -__put_user (0 , &fps->fpqd) || -clear_user (&fps->fpq[0 ],32 *sizeof (unsigned int ))) - ret = -EFAULT ; - } + ret =copy_regset_to_user (child, &ptrace32_view, +REGSET_FP ,0 , +68 *sizeof (u32), + fps);break ;case PTRACE_SETFPREGS :
@@ -999,17 +1103,10 @@ long arch_ptrace(struct task_struct *child, long request,break ;case PTRACE_GETREGS64 : - ret =copy_regset_to_user (child, view,REGSET_GENERAL , -1 *sizeof (u64), -15 *sizeof (u64), - &pregs->u_regs[0 ]); -if (!ret) { -/* XXX doesn't handle 'y' register correctly XXX */ - ret =copy_regset_to_user (child, view,REGSET_GENERAL , -32 *sizeof (u64), -4 *sizeof (u64), - &pregs->tstate); - } + ret =copy_regset_to_user (child, &ptrace64_view, +REGSET_GENERAL ,0 , +19 *sizeof (u64), + pregs);break ;case PTRACE_SETREGS64 :
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 12/41 sparc32: get rid of odd callers of copy_regset_from_user()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- arch/sparc/kernel/ptrace_32.c | 109 ++++++++++++++++++++++++++++-------------- 1 file changed, 73 insertions(+), 36 deletions(-)
arch/sparc/kernel/ptrace_32.c +73 -36
@@ -137,19 +137,18 @@ static int genregs32_set(struct task_struct *target,if (ret || !count)return ret; -if (pos <32 *sizeof (u32)) { -if (regwindow32_get (target, regs, uregs)) -return -EFAULT ; - ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, - uregs, -16 *sizeof (u32),32 *sizeof (u32)); -if (ret) -return ret; -if (regwindow32_set (target, regs, uregs)) -return -EFAULT ; -if (!count) -return 0 ; - } +if (regwindow32_get (target, regs, uregs)) +return -EFAULT ; + ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, + uregs, +16 *sizeof (u32),32 *sizeof (u32)); +if (ret) +return ret; +if (regwindow32_set (target, regs, uregs)) +return -EFAULT ; +if (!count) +return 0 ; + ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, &psr,32 *sizeof (u32),33 *sizeof (u32));
@@ -241,13 +240,11 @@ static int fpregs32_set(struct task_struct *target,user_regset_copyin_ignore (&pos, &count, &kbuf, &ubuf,32 *sizeof (u32),33 *sizeof (u32)); -if (!ret && count >0 ) { +if (!ret) ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, &target->thread.fsr,33 *sizeof (u32),34 *sizeof (u32)); - } -if (!ret) ret =user_regset_copyin_ignore (&pos, &count, &kbuf, &ubuf,34 *sizeof (u32),-1 );
@@ -313,6 +310,31 @@ static int getregs_get(struct task_struct *target, 4 * sizeof(u32), 19 * sizeof(u32)); } +static int setregs_set (struct task_struct *target, +const struct user_regset *regset, +unsigned int pos,unsigned int count, +const void *kbuf,const void __user *ubuf) +{ +struct pt_regs *regs = target->thread.kregs; +u32 v[4 ]; +int ret; + +if (target == current) +flush_user_windows (); + + ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, + v, +0 ,4 *sizeof (u32)); + regs->psr = (regs->psr & ~(PSR_ICC |PSR_SYSCALL )) | + (v[0 ] & (PSR_ICC |PSR_SYSCALL )); + regs->pc = v[1 ]; + regs->npc = v[2 ]; + regs->y = v[3 ]; +return user_regset_copyin (&pos, &count, &kbuf, &ubuf, + regs->u_regs +1 , +4 *sizeof (u32) ,19 *sizeof (u32)); +} + static int getfpregs_get(struct task_struct *target, const struct user_regset *regset, unsigned int pos, unsigned int count,
@@ -340,12 +362,37 @@ static int getfpregs_get(struct task_struct *target, 33 * sizeof(u32), 68 * sizeof(u32)); } +static int setfpregs_set (struct task_struct *target, +const struct user_regset *regset, +unsigned int pos,unsigned int count, +const void *kbuf,const void __user *ubuf) +{ +unsigned long *fpregs = target->thread.float_regs; +int ret; + +#if 0 +if (target == current) +save_and_clear_fpu (); +#endif + ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, + fpregs, +0 ,32 *sizeof (u32)); +if (ret) +return ret; +return user_regset_copyin (&pos, &count, &kbuf, &ubuf, + &target->thread.fsr, +32 *sizeof (u32), +33 *sizeof (u32)); +} +static const struct user_regset ptrace32_regsets[] = { [REGSET_GENERAL ] = { - .n =19 , .size =sizeof (u32), .get = getregs_get, + .n =19 , .size =sizeof (u32), + .get = getregs_get, .set = setregs_set, }, [REGSET_FP ] = { - .n =68 , .size =sizeof (u32), .get = getfpregs_get, + .n =68 , .size =sizeof (u32), + .get = getfpregs_get, .set = setfpregs_set, }, };
@@ -400,15 +447,10 @@ long arch_ptrace(struct task_struct *child, long request, }case PTRACE_SETREGS : { - ret =copy_regset_from_user (child, view,REGSET_GENERAL , -32 *sizeof (u32), -4 *sizeof (u32), - &pregs->psr); -if (!ret) -copy_regset_from_user (child, view,REGSET_GENERAL , -1 *sizeof (u32), -15 *sizeof (u32), - &pregs->u_regs[0 ]); + ret =copy_regset_from_user (child, &ptrace32_view, +REGSET_GENERAL ,0 , +19 *sizeof (u32), + pregs);break ; }
@@ -421,15 +463,10 @@ long arch_ptrace(struct task_struct *child, long request, }case PTRACE_SETFPREGS : { - ret =copy_regset_from_user (child, view,REGSET_FP , -0 *sizeof (u32), -32 *sizeof (u32), - &fps->regs[0 ]); -if (!ret) - ret =copy_regset_from_user (child, view,REGSET_FP , -33 *sizeof (u32), -1 *sizeof (u32), - &fps->fsr); + ret =copy_regset_from_user (child, &ptrace32_view, +REGSET_FP ,0 , +33 *sizeof (u32), + fps);break ; }
Signature · 1 line
2.11.0
kernel test robot
build botRe: [PATCH 12/41] sparc32: get rid of odd callers of copy_regset_from_user()
Thank you for the patch! Yet something to improve:
Hi Al,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on sparc/master]
[also build test ERROR on powerpc/next linus/master v5.8-rc3 next-20200701] [cannot apply to tip/x86/core sparc-next/master]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Al-Viro/introduction-of-regset-get-wrappers-switching-ELF-coredumps-to-those/20200630-053337 base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc.git master config: sparc-randconfig-s032-20200701 (attached as .config) compiler: sparc-linux-gcc (GCC) 9.3.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.2-3-gfa153962-dirty
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=sparc
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
arch/sparc/kernel/ptrace_32.c: In function 'setregs_set':
>> arch/sparc/kernel/ptrace_32.c:320:6: error: variable 'ret' set but not used [-Werror=unused-but-set-variable]
320 | int ret;
| ^~~
arch/sparc/kernel/ptrace_32.c: In function 'arch_ptrace':
>> arch/sparc/kernel/ptrace_32.c:430:33: error: variable 'view' set but not used [-Werror=unused-but-set-variable]
430 | const struct user_regset_view *view;
| ^~~~cc1: all warnings being treated as errors
vim +/ret +320 arch/sparc/kernel/ptrace_32.c
312
313 static int setregs_set(struct task_struct *target,
314 const struct user_regset *regset,
315 unsigned int pos, unsigned int count,
316 const void *kbuf, const void __user *ubuf)
317 {
318 struct pt_regs *regs = target->thread.kregs;
319 u32 v[4];
> 320 int ret;
321
322 if (target == current)
323 flush_user_windows();
324
325 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
326 v,
327 0, 4 * sizeof(u32));
328 regs->psr = (regs->psr & ~(PSR_ICC | PSR_SYSCALL)) |
329 (v[0] & (PSR_ICC | PSR_SYSCALL));
330 regs->pc = v[1];
331 regs->npc = v[2];
332 regs->y = v[3];
333 return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
334 regs->u_regs + 1,
335 4 * sizeof(u32) , 19 * sizeof(u32));
336 }
337
338 static int getfpregs_get(struct task_struct *target,
339 const struct user_regset *regset,
340 unsigned int pos, unsigned int count,
341 void *kbuf, void __user *ubuf)
342 {
343 const unsigned long *fpregs = target->thread.float_regs;
344 int ret = 0;
345
346 #if 0
347 if (target == current)
348 save_and_clear_fpu();
349 #endif
350
351 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
352 fpregs,
353 0, 32 * sizeof(u32));
354 if (ret)
355 return ret;
356 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
357 &target->thread.fsr,
358 32 * sizeof(u32), 33 * sizeof(u32));
359 if (ret)
360 return ret;
361 return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
362 33 * sizeof(u32), 68 * sizeof(u32));
363 }
364
365 static int setfpregs_set(struct task_struct *target,
366 const struct user_regset *regset,
367 unsigned int pos, unsigned int count,
368 const void *kbuf, const void __user *ubuf)
369 {
370 unsigned long *fpregs = target->thread.float_regs;
371 int ret;
372
373 #if 0
374 if (target == current)
375 save_and_clear_fpu();
376 #endif
377 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
378 fpregs,
379 0, 32 * sizeof(u32));
380 if (ret)
381 return ret;
382 return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
383 &target->thread.fsr,
384 32 * sizeof(u32),
385 33 * sizeof(u32));
386 }
387
388 static const struct user_regset ptrace32_regsets[] = {
389 [REGSET_GENERAL] = {
390 .n = 19, .size = sizeof(u32),
391 .get = getregs_get, .set = setregs_set,
392 },
393 [REGSET_FP] = {
394 .n = 68, .size = sizeof(u32),
395 .get = getfpregs_get, .set = setfpregs_set,
396 },
397 };
398
399 static const struct user_regset_view ptrace32_view = {
400 .regsets = ptrace32_regsets, .n = ARRAY_SIZE(ptrace32_regsets)
401 };
402
403 static const struct user_regset_view user_sparc32_view = {
404 .name = "sparc", .e_machine = EM_SPARC,
405 .regsets = sparc32_regsets, .n = ARRAY_SIZE(sparc32_regsets)
406 };
407
408 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
409 {
410 return &user_sparc32_view;
411 }
412
413 struct fps {
414 unsigned long regs[32];
415 unsigned long fsr;
416 unsigned long flags;
417 unsigned long extra;
418 unsigned long fpqd;
419 struct fq {
420 unsigned long *insnaddr;
421 unsigned long insn;
422 } fpq[16];
423 };
424
425 long arch_ptrace(struct task_struct *child, long request,
426 unsigned long addr, unsigned long data)
427 {
428 unsigned long addr2 = current->thread.kregs->u_regs[UREG_I4];
429 void __user *addr2p;
> 430 const struct user_regset_view *view;
431 struct pt_regs __user *pregs;
432 struct fps __user *fps;
433 int ret;
434
435 view = task_user_regset_view(current);
436 addr2p = (void __user *) addr2;
437 pregs = (struct pt_regs __user *) addr;
438 fps = (struct fps __user *) addr;
439
440 switch(request) {
441 case PTRACE_GETREGS: {
442 ret = copy_regset_to_user(child, &ptrace32_view,
443 REGSET_GENERAL, 0,
444 19 * sizeof(u32),
445 pregs);
446 break;
447 }
448
449 case PTRACE_SETREGS: {
450 ret = copy_regset_from_user(child, &ptrace32_view,
451 REGSET_GENERAL, 0,
452 19 * sizeof(u32),
453 pregs);
454 break;
455 }
456
457 case PTRACE_GETFPREGS: {
458 ret = copy_regset_to_user(child, &ptrace32_view,
459 REGSET_FP, 0,
460 68 * sizeof(u32),
461 fps);
462 break;
463 }
464
465 case PTRACE_SETFPREGS: {
466 ret = copy_regset_from_user(child, &ptrace32_view,
467 REGSET_FP, 0,
468 33 * sizeof(u32),
469 fps); 470 break;
471 }
472
473 case PTRACE_READTEXT:
474 case PTRACE_READDATA:
475 ret = ptrace_readdata(child, addr, addr2p, data);
476
477 if (ret == data)
478 ret = 0;
479 else if (ret >= 0)
480 ret = -EIO;
481 break;
482
483 case PTRACE_WRITETEXT:
484 case PTRACE_WRITEDATA:
485 ret = ptrace_writedata(child, addr2p, addr, data);
486
487 if (ret == data)
488 ret = 0;
489 else if (ret >= 0)
490 ret = -EIO;
491 break;
492
493 default:
494 if (request == PTRACE_SPARC_DETACH)
495 request = PTRACE_DETACH;
496 ret = ptrace_request(child, request, addr, data);
497 break;
498 }
499
500 return ret;
501 }
502
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Al Viro
maintainerPATCH 13/41 sparc64: get rid of odd callers of copy_regset_from_user()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- arch/sparc/kernel/ptrace_64.c | 177 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 144 insertions(+), 33 deletions(-)
arch/sparc/kernel/ptrace_64.c +144 -33
@@ -541,6 +541,60 @@ static int getregs64_get(struct task_struct *target,return ret; } +static int setregs64_set (struct task_struct *target, +const struct user_regset *regset, +unsigned int pos,unsigned int count, +const void *kbuf,const void __user *ubuf) +{ +struct pt_regs *regs =task_pt_regs (target); +unsigned long y = regs->y; +unsigned long tstate; +int ret; + +if (target == current) +flushw_user (); + + ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, + regs->u_regs +1 , +0 *sizeof (u64), +15 *sizeof (u64)); +if (ret) +return ret; + ret =user_regset_copyin_ignore (&pos, &count, &kbuf, &ubuf, +15 *sizeof (u64),16 *sizeof (u64)); +if (ret) +return ret; +/* TSTATE */ + ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, + &tstate, +16 *sizeof (u64), +17 *sizeof (u64)); +if (ret) +return ret; +/* Only the condition codes and the "in syscall" +* state can be modified in the %tstate register. +*/ + tstate &= (TSTATE_ICC |TSTATE_XCC |TSTATE_SYSCALL ); + regs->tstate &= ~(TSTATE_ICC |TSTATE_XCC |TSTATE_SYSCALL ); + regs->tstate |= tstate; + +/* TPC, TNPC */ + ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, + ®s->tpc, +17 *sizeof (u64), +19 *sizeof (u64)); +if (ret) +return ret; +/* Y */ + ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, + &y, +19 *sizeof (u64), +20 *sizeof (u64)); +if (!ret) + regs->y = y; +return ret; +} +static const struct user_regset ptrace64_regsets[] = {/* Format is: * G1 --> G7
@@ -549,7 +603,8 @@ static const struct user_regset ptrace64_regsets[] = {* TSTATE, TPC, TNPC, Y */ [REGSET_GENERAL ] = { - .n =20 , .size =sizeof (u64), .get = getregs64_get, + .n =20 , .size =sizeof (u64), + .get = getregs64_get, .set = setregs64_set, }, };
@@ -914,6 +969,40 @@ static int getregs_get(struct task_struct *target, 0, 19 * sizeof(u32)); } +static int setregs_set (struct task_struct *target, +const struct user_regset *regset, +unsigned int pos,unsigned int count, +const void *kbuf,const void __user *ubuf) +{ +struct pt_regs *regs =task_pt_regs (target); +unsigned long tstate; +u32 uregs[19 ]; +int i, ret; + +if (target == current) +flushw_user (); + + ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, + uregs, +0 ,19 *sizeof (u32)); +if (ret) +return ret; + + tstate = regs->tstate; + tstate &= ~(TSTATE_ICC |TSTATE_XCC |TSTATE_SYSCALL ); + tstate |=psr_to_tstate_icc (uregs[0 ]); +if (uregs[0 ] &PSR_SYSCALL ) + tstate |=TSTATE_SYSCALL ; + regs->tstate = tstate; + regs->tpc = uregs[1 ]; + regs->tnpc = uregs[2 ]; + regs->y = uregs[3 ]; + +for (i =1 ; i <15 ; i++) + regs->u_regs[i] = uregs[3 + i]; +return 0 ; +} + static int getfpregs_get(struct task_struct *target, const struct user_regset *regset, unsigned int pos, unsigned int count,
@@ -948,12 +1037,52 @@ static int getfpregs_get(struct task_struct *target,return ret; } +static int setfpregs_set (struct task_struct *target, +const struct user_regset *regset, +unsigned int pos,unsigned int count, +const void *kbuf,const void __user *ubuf) +{ +unsigned long *fpregs =task_thread_info (target)->fpregs; +unsigned long fprs; +int ret; + +if (target == current) +save_and_clear_fpu (); + + fprs =task_thread_info (target)->fpsaved[0 ]; + + ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, + fpregs, +0 ,32 *sizeof (u32)); +if (!ret) { +compat_ulong_t fsr; +unsigned long val; + + ret =user_regset_copyin (&pos, &count, &kbuf, &ubuf, + &fsr, +32 *sizeof (u32), +33 *sizeof (u32)); +if (!ret) { + val =task_thread_info (target)->xfsr[0 ]; + val &=0xffffffff00000000UL ; + val |= fsr; +task_thread_info (target)->xfsr[0 ] = val; + } + } + + fprs |= (FPRS_FEF |FPRS_DL ); +task_thread_info (target)->fpsaved[0 ] = fprs; +return ret; +} +static const struct user_regset ptrace32_regsets[] = { [REGSET_GENERAL ] = { - .n =19 , .size =sizeof (u32), .get = getregs_get, + .n =19 , .size =sizeof (u32), + .get = getregs_get, .set = setregs_set, }, [REGSET_FP ] = { - .n =68 , .size =sizeof (u32), .get = getfpregs_get, + .n =68 , .size =sizeof (u32), + .get = getfpregs_get, .set = setfpregs_set, }, };
@@ -992,7 +1121,6 @@ struct compat_fps {long compat_arch_ptrace (struct task_struct *child,compat_long_t request,compat_ulong_t caddr,compat_ulong_t cdata) { -const struct user_regset_view *view =task_user_regset_view (current);compat_ulong_t caddr2 =task_pt_regs (current)->u_regs[UREG_I4 ];struct pt_regs32 __user *pregs;struct compat_fps __user *fps;
@@ -1017,15 +1145,10 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,break ;case PTRACE_SETREGS : - ret =copy_regset_from_user (child, view,REGSET_GENERAL , -32 *sizeof (u32), -4 *sizeof (u32), - &pregs->psr); -if (!ret) - ret =copy_regset_from_user (child, view,REGSET_GENERAL , -1 *sizeof (u32), -15 *sizeof (u32), - &pregs->u_regs[0 ]); + ret =copy_regset_from_user (child, &ptrace32_view, +REGSET_GENERAL ,0 , +19 *sizeof (u32), + pregs);break ;case PTRACE_GETFPREGS :
@@ -1036,15 +1159,10 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,break ;case PTRACE_SETFPREGS : - ret =copy_regset_from_user (child, view,REGSET_FP , -0 *sizeof (u32), -32 *sizeof (u32), - &fps->regs[0 ]); -if (!ret) - ret =copy_regset_from_user (child, view,REGSET_FP , -33 *sizeof (u32), -1 *sizeof (u32), - &fps->fsr); + ret =copy_regset_from_user (child, &ptrace32_view, +REGSET_FP ,0 , +33 *sizeof (u32), + fps);break ;case PTRACE_READTEXT :
@@ -1110,17 +1228,10 @@ long arch_ptrace(struct task_struct *child, long request,break ;case PTRACE_SETREGS64 : - ret =copy_regset_from_user (child, view,REGSET_GENERAL , -1 *sizeof (u64), -15 *sizeof (u64), - &pregs->u_regs[0 ]); -if (!ret) { -/* XXX doesn't handle 'y' register correctly XXX */ - ret =copy_regset_from_user (child, view,REGSET_GENERAL , -32 *sizeof (u64), -4 *sizeof (u64), - &pregs->tstate); - } + ret =copy_regset_from_user (child, &ptrace64_view, +REGSET_GENERAL ,0 , +19 *sizeof (u64), + pregs);break ;case PTRACE_GETFPREGS64 :
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 14/41 arm64: take fetching compat reg out of pt_regs into a new helper
In reply to Al ViroFrom: Al Viro <[email protected]>
--- arch/arm64/kernel/ptrace.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-)
arch/arm64/kernel/ptrace.c +17 -17
@@ -1237,6 +1237,22 @@ enum compat_regset { REGSET_COMPAT_VFP, }; +static inline compat_ulong_t compat_get_user_reg (struct task_struct *task,int idx) +{ +struct pt_regs *regs =task_pt_regs (task); + +switch (idx) { +case 15 : +return regs->pc; +case 16 : +return pstate_to_compat_psr (regs->pstate); +case 17 : +return regs->orig_x0; +default : +return regs->regs[idx]; + } +} + static int compat_gpr_get(struct task_struct *target, const struct user_regset *regset, unsigned int pos, unsigned int count,
@@ -1255,23 +1271,7 @@ static int compat_gpr_get(struct task_struct *target,return -EIO ;for (i =0 ; i < num_regs; ++i) { -unsigned int idx = start + i; -compat_ulong_t reg; - -switch (idx) { -case 15 : - reg =task_pt_regs (target)->pc; -break ; -case 16 : - reg =task_pt_regs (target)->pstate; - reg =pstate_to_compat_psr (reg); -break ; -case 17 : - reg =task_pt_regs (target)->orig_x0; -break ; -default : - reg =task_pt_regs (target)->regs[idx]; - } +compat_ulong_t reg =compat_get_user_reg (target, start + i);if (kbuf) {memcpy (kbuf, ®,sizeof (reg));
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 15/41 arm64: get rid of copy_regset_to_user() in compat_ptrace_read_user()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- arch/arm64/kernel/ptrace.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
arch/arm64/kernel/ptrace.c +1 -3
@@ -1541,9 +1541,7 @@ static int compat_ptrace_read_user(struct task_struct *tsk, compat_ulong_t off,else if (off ==COMPAT_PT_TEXT_END_ADDR ) tmp = tsk->mm->end_code;else if (off <sizeof (compat_elf_gregset_t)) -return copy_regset_to_user (tsk, &user_aarch32_view, -REGSET_COMPAT_GPR , off, -sizeof (compat_ulong_t), ret); + tmp =compat_get_user_reg (tsk, off >>2 );else if (off >=COMPAT_USER_SZ )return -EIO ;else
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 16/41 arm64: sanitize compat_ptrace_write_user()
In reply to Al ViroFrom: Al Viro <[email protected]>
don't bother with copy_regset_from_user() (not to mention set_fs())
--- arch/arm64/kernel/ptrace.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-)
arch/arm64/kernel/ptrace.c +20 -9
@@ -1553,8 +1553,8 @@ static int compat_ptrace_read_user(struct task_struct *tsk, compat_ulong_t off,static int compat_ptrace_write_user (struct task_struct *tsk,compat_ulong_t off,compat_ulong_t val) { -int ret; -mm_segment_t old_fs =get_fs (); +struct pt_regs newregs = *task_pt_regs (tsk); +unsigned int idx = off /4 ;if (off &3 || off >=COMPAT_USER_SZ )return -EIO ;
@@ -1562,14 +1562,25 @@ static int compat_ptrace_write_user(struct task_struct *tsk, compat_ulong_t off,if (off >=sizeof (compat_elf_gregset_t))return 0 ; -set_fs (KERNEL_DS ); - ret =copy_regset_from_user (tsk, &user_aarch32_view, -REGSET_COMPAT_GPR , off, -sizeof (compat_ulong_t), - &val); -set_fs (old_fs); +switch (idx) { +case 15 : + newregs.pc = val; +break ; +case 16 : + newregs.pstate =compat_psr_to_pstate (val); +break ; +case 17 : + newregs.orig_x0 = val; +break ; +default : + newregs.regs[idx] = val; + } + +if (!valid_user_regs (&newregs.user_regs, tsk)) +return -EINVAL ; -return ret; + *task_pt_regs (tsk) = newregs; +return 0 ; }#ifdef CONFIG_HAVE_HW_BREAKPOINT
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 17/41 copy_regset_to_user(): do all copyout at once.
In reply to Al ViroFrom: Al Viro <[email protected]>
Turn copy_regset_to_user() into regset_get_alloc() + copy_to_user(). Now all ->get() calls have a kernel buffer as destination.
Note that we'd already eliminated the callers of copy_regset_to_user() with non-zero offset; now that argument is simply unused.
Uninlined, while we are at it.
--- include/linux/regset.h | 29 ++++------------------------- kernel/regset.c | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 25 deletions(-)
include/linux/regset.h +4 -25
@@ -362,31 +362,10 @@ extern int regset_get_alloc(struct task_struct *target,unsigned int size, void **data); -/** -* copy_regset_to_user - fetch a thread's user_regset data into user memory -* @target: thread to be examined -* @view: &struct user_regset_view describing user thread machine state -* @setno: index in @view->regsets -* @offset: offset into the regset data, in bytes -* @size: amount of data to copy, in bytes -* @data: user-mode pointer to copy into -*/ -static inline int copy_regset_to_user (struct task_struct *target, -const struct user_regset_view *view, -unsigned int setno, -unsigned int offset,unsigned int size, -void __user *data) -{ -const struct user_regset *regset = &view->regsets[setno]; - -if (!regset->get) -return -EOPNOTSUPP ; - -if (!access_ok (data, size)) -return -EFAULT ; - -return regset->get (target, regset, offset, size,NULL , data); -} +extern int copy_regset_to_user (struct task_struct *target, +const struct user_regset_view *view, +unsigned int setno,unsigned int offset, +unsigned int size,void __user *data);/** * copy_regset_from_user - store into thread's user_regset data from user memory
kernel/regset.c +26 -0
@@ -52,3 +52,29 @@ int regset_get_alloc(struct task_struct *target,return __regset_get (target, regset, size, data); }EXPORT_SYMBOL (regset_get_alloc); + +/** +* copy_regset_to_user - fetch a thread's user_regset data into user memory +* @target: thread to be examined +* @view: &struct user_regset_view describing user thread machine state +* @setno: index in @view->regsets +* @offset: offset into the regset data, in bytes +* @size: amount of data to copy, in bytes +* @data: user-mode pointer to copy into +*/ +int copy_regset_to_user (struct task_struct *target, +const struct user_regset_view *view, +unsigned int setno, +unsigned int offset,unsigned int size, +void __user *data) +{ +const struct user_regset *regset = &view->regsets[setno]; +void *buf; +int ret; + + ret =regset_get_alloc (target, regset, size, &buf); +if (ret >0 ) + ret =copy_to_user (data, buf, ret) ? -EFAULT :0 ; +kfree (buf); +return ret; +}
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 18/41 regset: new method and helpers for it
In reply to Al ViroFrom: Al Viro <[email protected]>
->get2() takes task+regset+buffer, returns the amount of free space left in the buffer on success and -E... on error.
buffer is represented as struct membuf - a pair of (kernel) pointer and amount of space left
Primitives for writing to such:
* membuf_write(buf, data, size)
* membuf_zero(buf, size)
* membuf_store(buf, value)
These are implemented as inlines (in case of membuf_store - a macro). All writes are sequential; they become no-ops when there's no space left. Return value of all primitives is the amount of space left after the operation, so they can be used as return values of ->get2().
Example of use:
// stores pt_regs of task + 64 bytes worth of zeroes + 32bit PID of task int foo_get(struct task_struct *task, const struct regset *regset,
struct membuf to)
{
membuf_write(&to, task_pt_regs(task), sizeof(struct pt_regs));
membuf_zero(&to, 64);
return membuf_store(&to, (u32)task_tgid_vnr(task));
}regset_get()/regset_get_alloc() taught to use that thing if present. By the end of the series all users of ->get() will be converted; then ->get() and ->get_size() can go.
Note that unlike ->get() this thing always starts at offset 0 and, since it only writes to kernel buffer, can't fail on copyout. It can, of course, fail for other reasons, but those tend to be less numerous.
The caller guarantees that the buffer size won't be bigger than regset->n * regset->size. That simplifies life for quite a few instances.
--- include/linux/regset.h | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ kernel/regset.c | 12 +++++++++++- 2 files changed, 62 insertions(+), 1 deletion(-)
include/linux/regset.h +51 -0
@@ -17,6 +17,52 @@struct task_struct ;struct user_regset ; +struct membuf { +void *p; +size_t left; +}; + +static inline int membuf_zero (struct membuf *s,size_t size) +{ +if (s->left) { +if (size > s->left) + size = s->left; +memset (s->p,0 , size); + s->p += size; + s->left -= size; + } +return s->left; +} + +static inline int membuf_write (struct membuf *s,const void *v,size_t size) +{ +if (s->left) { +if (size > s->left) + size = s->left; +memcpy (s->p, v, size); + s->p += size; + s->left -= size; + } +return s->left; +} + +/* current s->p must be aligned for v; v must be a scalar */ +#define membuf_store (s, v) \ +({ \ + struct membuf *__s = (s); \ + if (__s->left) { \ + typeof(v) __v = (v); \ + size_t __size = sizeof(__v); \ + if (unlikely(__size > __s->left)) { \ + __size = __s->left; \ + memcpy(__s->p, &__v, __size); \ + } else { \ + *(typeof(__v + 0) *)__s->p = __v; \ + } \ + __s->p += __size; \ + __s->left -= __size; \ + } \ + __s->left;})/** * user_regset_active_fn - type of @active function in &struct user_regset
@@ -57,6 +103,10 @@ typedef int user_regset_get_fn(struct task_struct *target, unsigned int pos, unsigned int count, void *kbuf, void __user *ubuf); +typedef int user_regset_get2_fn (struct task_struct *target, +const struct user_regset *regset, +struct membuf to); +/** * user_regset_set_fn - type of @set function in &struct user_regset * @target: thread being examined
@@ -186,6 +236,7 @@ typedef unsigned int user_regset_get_size_fn(struct task_struct *target,*/ struct user_regset {user_regset_get_fn *get; +user_regset_get2_fn *get2;user_regset_set_fn *set;user_regset_active_fn *active;user_regset_writeback_fn *writeback;
kernel/regset.c +11 -1
@@ -11,7 +11,7 @@ static int __regset_get(struct task_struct *target,void *p = *data, *to_free =NULL ;int res; -if (!regset->get) +if (!regset->get && !regset->get2)return -EOPNOTSUPP ;if (size > regset->n * regset->size) size = regset->n * regset->size;
@@ -20,6 +20,16 @@ static int __regset_get(struct task_struct *target,if (!p)return -ENOMEM ; } +if (regset->get2) { + res = regset->get2 (target, regset, + (struct membuf ){.p = p, .left = size}); +if (res <0 ) { +kfree (to_free); +return res; + } + *data = p; +return size - res; + } res = regset->get (target, regset,0 , size, p,NULL );if (unlikely (res <0 )) {kfree (to_free);
Signature · 1 line
2.11.0
Re: [PATCH 18/41] regset: new method and helpers for it
Quoted 3 lines · Al Viro
->get2() takes task+regset+buffer, returns the amount of free space left in the buffer on success and -E... on error.
Can we please give it a better name than "get2"?
That's not a great name to begin with, and it's a completely nonsensical name by the end of this series when you've removed the original "get" function.
So either:
(a) add one final patch to rename "get2" all back to "get" after you
got rid of the old "get"
(b) or just call it something better to begin with. Maybe just
"get_regset" instead?
I'd prefer (b) just because I think it will be a lot clearer if we ever end up having old patches forward-ported (or, more likely, newpatches back-ported), so having a "get" function that changed semantics but got back the old name sounds bad to me.
Other than that, I can't really argue with the numbers:
41 files changed, 1368 insertions(+), 2347 deletions(-)
looks good to me, and the code seems more understandable.
But I only scanned the individual patches, maybe I missed some other horror.
Linus
Al Viro
maintainerRe: [PATCH 18/41] regset: new method and helpers for it
Quoted 7 lines · Linus Torvalds
Quoted 3 lines · Al Viro
->get2() takes task+regset+buffer, returns the amount of free space left in the buffer on success and -E... on error.
Can we please give it a better name than "get2"?
Quoted 8 lines
That's not a great name to begin with, and it's a completely nonsensical name by the end of this series when you've removed the original "get" function.
So either:
(a) add one final patch to rename "get2" all back to "get" after you
got rid of the old "get"
Bad idea, IMO...
Quoted 2 lines
(b) or just call it something better to begin with. Maybe just
"get_regset" instead?
<nod>
Frankly, other field names there are also nasty - 'set' is not fun to grep for, but there are 'n' and 'size' as well. There's also 'bias' and 'align' (both completely unused)...
Quoted 10 lines
I'd prefer (b) just because I think it will be a lot clearer if we ever end up having old patches forward-ported (or, more likely, newpatches back-ported), so having a "get" function that changed semantics but got back the old name sounds bad to me.
Other than that, I can't really argue with the numbers:
41 files changed, 1368 insertions(+), 2347 deletions(-)looks good to me, and the code seems more understandable.
FWIW, there's also ->set() side of that thing. Tons of boilerplate in those; I hadn't seriously looked into that part, but I suspect that "do copyin in the caller, pass the kernel buffer to the method, always start at offset 0" would also trim a lot of crap. I'd rather leave that one for later - this series had been painful enough.
Other things in the same area: conversion of fdpic coredumps to regset (fairly easy, I've a patch series doing that in the local tree), conversion of the few remaining non-regset architectures to regset-based coredump (kill a large chunk of rotting code in fs/binfmt_elf.c, along with quite a few pieces of old per-arch coredump helpers), unification of compat ELF (done locally, mipsn32/mipso32 gone, all compat done via compat_binfmt_elf.c, x32 horrors sanitized - IMO
#define PRSTATUS_SIZE \
(test_thread_flag(TIF_X32) \
? sizeof(struct compat_elf_prstatus) \
: sizeof(struct i386_elf_prstatus))
#define SET_PR_FPVALID(S) \
(*(test_thread_flag(TIF_X32) \
? &(S)->pr_fpvalid \
: &((struct i386_elf_prstatus *)(S))->pr_fpvalid) = 1)is much better than
#define PRSTATUS_SIZE(S, R) (R != sizeof(S.pr_reg) ? 144 : 296) #define SET_PR_FPVALID(S, V, R) \
do { *(int *) (((void *) &((S)->pr_reg)) + R) = (V); } \
while (0)
) and a bunch of assorted cleanups that got trimmed from the regset series...
I'll probably post fdpic and compat series tonight and get back to uaccess and VFS stuff.
Al Viro
maintainerRe: [PATCH 18/41] regset: new method and helpers for it
Quoted 8 lines · Al Viro
Quoted 2 lines
(b) or just call it something better to begin with. Maybe just
"get_regset" instead?<nod>
Frankly, other field names there are also nasty - 'set' is not fun to grep for, but there are 'n' and 'size' as well. There's also 'bias' and 'align' (both completely unused)...
How about ->regset_get()? I've force-pushed a variant with that change + removal of leftover unused variables (caught by Intel build bot) + braino fix in sparc conversion (spotted when looking through the patchset again); same branch names. Not sure if it's worth a repost of the entire patchbomb...
Re: [PATCH 18/41] regset: new method and helpers for it
Quoted 2 lines · Al Viro
How about ->regset_get()?
Sounds good to me. And if you ever do something similar for 'set', you have a natural name to pick.
No need to repost as far as I'm concerned if it's just the name change and some minor nots found by the bots.
Linus
Al Viro
maintainerRe: [PATCH 18/41] regset: new method and helpers for it
Quoted 6 lines · Linus Torvalds
Quoted 2 lines · Al Viro
How about ->regset_get()?
Sounds good to me. And if you ever do something similar for 'set', you have a natural name to pick.
Umm... Something similar for 'set' would, AFAICS, work reasonably well with the following primitives.membuf_read(&from, data, size) -- copy min(size, amount left) membuf_fetch(&from, data) -- copy min(sizeof(data), amount left) into data
(obviously a macro)membuf_skip(&from, size) -- obviousmembuf_pick(&from, size), along the lines of
if (unlikely(size > p->left) return ERR_PTR(-EINVAL); res = p->p; p->p += size; p->left -= size; return res;
So it would be something like
int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
struct membuf from)
{
const struct user_desc *info;
int n = from.left / sizeof(*info);
int i;
info = membuf_pick(&from, n * sizeof(*info)); // can't fail here
for (i = 0; i < n; i++)
if (!tls_desc_okay(info + i))
return -EINVAL;
set_tls_desc(target, GDT_ENTRY_TLS_MIN, info, n);
return 0;
}and
static int genregs32_set(struct task_struct *target,
const struct user_regset *regset, struct membuf from)
{
int err;
unsigned pos, v;
for (pos = 0; from.left; pos += sizeof(u32)) {
membuf_fetch(&from, v);
err = putreg32(target, pos, v);
if (err)
return err;
}
return 0;
}or
/*
* Copy the supplied 64-bit NT_MIPS_DSP buffer to the DSP context. */
static int dsp64_set(struct task_struct *target,
const struct user_regset *regset, struct membuf from)
{
if (!cpu_has_dsp)
return -EIO;
membuf_read(&from, target->thread.dsp.dspr, NUM_DSP_REGS * sizeof(u64));
return membuf_read(&from, target->thread.dsp.dspcontrol, sizeof(u64));
}etc.
Al Viro
maintainerPATCH 19/41 x86: switch to ->get2()
In reply to Al ViroFrom: Al Viro <[email protected]>
All instances of ->get() in arch/x86 switched; that might or might
not be worth splitting up. Notes:
* for xstateregs_get() the amount we want to store is determined at
the boot time; see init_xstate_size() and update_regset_xstate_info() for details. task->thread.fpu.state.xsave ends with a flexible array member and the amount of data in it depends upon the FPU features supported/enabled.
* fpregs_get() writes slightly less than full ->thread.fpu.state.fsave
(the last word is not copied); we pass the full size of state.fsave and let membuf_write() trim to the amount declared by regset - __regset_get() will make sure that the space in buffer is no more than that.
* copy_xstate_to_user() and its helpers are gone now.
* fpregs_soft_get() was getting user_regset_copyout() arguments
wrong. Since "x86: x86 user_regset math_emu" back in 2008... I really doubt that it's worth splitting out for -stable, though - you need a 486SX box for that to trigger...
--- arch/x86/include/asm/fpu/regset.h | 4 +- arch/x86/include/asm/fpu/xstate.h | 4 +- arch/x86/kernel/fpu/regset.c | 39 ++++----- arch/x86/kernel/fpu/signal.c | 3 +- arch/x86/kernel/fpu/xstate.c | 164 +++++++------------------------------- arch/x86/kernel/ptrace.c | 75 ++++++----------- arch/x86/kernel/tls.c | 32 ++------ arch/x86/kernel/tls.h | 2 +- arch/x86/math-emu/fpu_entry.c | 19 ++--- 9 files changed, 83 insertions(+), 259 deletions(-)
arch/x86/include/asm/fpu/regset.h +2 -2
@@ -8,8 +8,8 @@#include <linux/regset.h> extern user_regset_active_fn regset_fpregs_active, regset_xregset_fpregs_active; -extern user_regset_get_fn fpregs_get, xfpregs_get, fpregs_soft_get, - xstateregs_get; +extern user_regset_get2_fn fpregs_get, xfpregs_get, fpregs_soft_get, + xstateregs_get;extern user_regset_set_fn fpregs_set, xfpregs_set, fpregs_soft_set, xstateregs_set;
arch/x86/include/asm/fpu/xstate.h +2 -2
@@ -71,8 +71,8 @@ extern void __init update_regset_xstate_info(unsigned int size,void *get_xsave_addr (struct xregs_state *xsave,int xfeature_nr);const void *get_xsave_field_ptr (int xfeature_nr);int using_compacted_format (void ); -int copy_xstate_to_kernel (void *kbuf,struct xregs_state *xsave,unsigned int offset,unsigned int size); -int copy_xstate_to_user (void __user *ubuf,struct xregs_state *xsave,unsigned int offset,unsigned int size); +struct membuf ; +void copy_xstate_to_kernel (struct membuf to,struct xregs_state *xsave);int copy_kernel_to_xstate (struct xregs_state *xsave,const void *kbuf);int copy_user_to_xstate (struct xregs_state *xsave,const void __user *ubuf);void copy_supervisor_to_kernel (struct xregs_state *xsave);
arch/x86/kernel/fpu/regset.c +15 -24
@@ -27,8 +27,7 @@ int regset_xregset_fpregs_active(struct task_struct *target, const struct user_r }int xfpregs_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) {struct fpu *fpu = &target->thread.fpu;
@@ -38,8 +37,7 @@ int xfpregs_get(struct task_struct *target, const struct user_regset *regset,fpu__prepare_read (fpu);fpstate_sanitize_xstate (fpu); -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, - &fpu->state.fxsave,0 ,-1 ); +return membuf_write (&to, &fpu->state.fxsave,sizeof (struct fxregs_state )); } int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
@@ -74,12 +72,10 @@ int xfpregs_set(struct task_struct *target, const struct user_regset *regset, }int xstateregs_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) {struct fpu *fpu = &target->thread.fpu;struct xregs_state *xsave; -int ret;if (!boot_cpu_has (X86_FEATURE_XSAVE ))return -ENODEV ;
@@ -89,10 +85,8 @@ int xstateregs_get(struct task_struct *target, const struct user_regset *regset,fpu__prepare_read (fpu);if (using_compacted_format ()) { -if (kbuf) - ret =copy_xstate_to_kernel (kbuf, xsave, pos, count); -else - ret =copy_xstate_to_user (ubuf, xsave, pos, count); +copy_xstate_to_kernel (to, xsave); +return 0 ; }else {fpstate_sanitize_xstate (fpu);/*
@@ -105,9 +99,8 @@ int xstateregs_get(struct task_struct *target, const struct user_regset *regset,/* * Copy the xstate memory layout. */ - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, xsave,0 ,-1 ); +return membuf_write (&to, xsave, fpu_user_xstate_size); } -return ret; } int xstateregs_set(struct task_struct *target, const struct user_regset *regset,
@@ -293,8 +286,7 @@ void convert_to_fxsr(struct fxregs_state *fxsave, }int fpregs_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) {struct fpu *fpu = &target->thread.fpu;struct user_i387_ia32_struct env;
@@ -302,23 +294,22 @@ int fpregs_get(struct task_struct *target, const struct user_regset *regset,fpu__prepare_read (fpu);if (!boot_cpu_has (X86_FEATURE_FPU )) -return fpregs_soft_get (target, regset, pos, count, kbuf, ubuf); +return fpregs_soft_get (target, regset, to); -if (!boot_cpu_has (X86_FEATURE_FXSR )) -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, - &fpu->state.fsave,0 , --1 ); +if (!boot_cpu_has (X86_FEATURE_FXSR )) { +return membuf_write (&to, &fpu->state.fsave, +sizeof (struct fregs_state )); + }fpstate_sanitize_xstate (fpu); -if (kbuf && pos ==0 && count ==sizeof (env)) { -convert_from_fxsr (kbuf, target); +if (to.left ==sizeof (env)) { +convert_from_fxsr (to.p, target);return 0 ; }convert_from_fxsr (&env, target); - -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, &env,0 ,-1 ); +return membuf_write (&to, &env,sizeof (env)); } int fpregs_set(struct task_struct *target, const struct user_regset *regset,
arch/x86/kernel/fpu/signal.c +2 -1
@@ -172,7 +172,8 @@ int copy_fpstate_to_sigframe(void __user *buf, void __user *buf_fx, int size)if (!static_cpu_has (X86_FEATURE_FPU )) {struct user_i387_ia32_struct fp; -fpregs_soft_get (current,NULL ,0 ,sizeof (fp), &fp,NULL ); +fpregs_soft_get (current,NULL , (struct membuf ){.p = &fp, + .left =sizeof (fp)});return copy_to_user (buf, &fp,sizeof (fp)) ? -EFAULT :0 ; }
arch/x86/kernel/fpu/xstate.c +27 -137
210 lines not on this page · raw message
arch/x86/kernel/ptrace.c +23 -52
155 lines not on this page · raw message
arch/x86/kernel/tls.c +6 -26
@@ -256,36 +256,16 @@ int regset_tls_active(struct task_struct *target, }int regset_tls_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) {const struct desc_struct *tls; +struct user_desc v; +int pos; -if (pos >=GDT_ENTRY_TLS_ENTRIES *sizeof (struct user_desc ) || - (pos %sizeof (struct user_desc )) !=0 || - (count %sizeof (struct user_desc )) !=0 ) -return -EINVAL ; - - pos /=sizeof (struct user_desc ); - count /=sizeof (struct user_desc ); - - tls = &target->thread.tls_array[pos]; - -if (kbuf) { -struct user_desc *info = kbuf; -while (count-- >0 ) -fill_user_desc (info++,GDT_ENTRY_TLS_MIN + pos++, - tls++); - }else { -struct user_desc __user *u_info = ubuf; -while (count-- >0 ) { -struct user_desc info; -fill_user_desc (&info,GDT_ENTRY_TLS_MIN + pos++, tls++); -if (__copy_to_user (u_info++, &info,sizeof (info))) -return -EFAULT ; - } +for (pos =0 , tls = target->thread.tls_array; to.left; pos++, tls++) { +fill_user_desc (&v,GDT_ENTRY_TLS_MIN + pos, tls); +membuf_write (&to, &v,sizeof (v)); } -return 0 ; }
arch/x86/kernel/tls.h +1 -1
@@ -12,7 +12,7 @@#include <linux/regset.h> extern user_regset_active_fn regset_tls_active; -extern user_regset_get_fn regset_tls_get; +extern user_regset_get2_fn regset_tls_get;extern user_regset_set_fn regset_tls_set;#endif /* _ARCH_X86_KERNEL_TLS_H */
arch/x86/math-emu/fpu_entry.c +5 -14
@@ -689,12 +689,10 @@ int fpregs_soft_set(struct task_struct *target,int fpregs_soft_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) {struct swregs_state *s387 = &target->thread.fpu.state.soft;const void *space = s387->st_space; -int ret;int offset = (S387 ->ftop &7 ) *10 , other =80 - offset;RE_ENTRANT_CHECK_OFF ;
@@ -709,18 +707,11 @@ int fpregs_soft_get(struct task_struct *target,S387 ->fos |=0xffff0000 ;#endif /* PECULIAR_486 */ - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, s387,0 , - offsetof(struct swregs_state , st_space)); - -/* Copy all registers in stack order. */ -if (!ret) - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - space + offset,0 , other); -if (!ret) - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - space,0 , offset); +membuf_write (&to, s387, offsetof(struct swregs_state , st_space)); +membuf_write (&to, space + offset, other); +membuf_write (&to, space, offset);RE_ENTRANT_CHECK_ON ; -return ret; +return 0 ; }
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 20/41 powerpc: switch to ->get2()
In reply to Al ViroFrom: Al Viro <[email protected]>
Note: compat variant of REGSET_TM_CGPR is almost certainly wrong; it claims to be 48*64bit, but just as compat REGSET_GPR it stores 44*32bit of (truncated) registers + 4 32bit zeros... followed by 48 more 32bit zeroes. Might be too late to change - it's a userland ABI, after all ;-/
--- arch/powerpc/kernel/ptrace/ptrace-altivec.c | 37 ++---- arch/powerpc/kernel/ptrace/ptrace-decl.h | 44 +++---- arch/powerpc/kernel/ptrace/ptrace-novsx.c | 5 +- arch/powerpc/kernel/ptrace/ptrace-spe.c | 16 +-- arch/powerpc/kernel/ptrace/ptrace-tm.c | 152 +++++++---------------- arch/powerpc/kernel/ptrace/ptrace-view.c | 185 ++++++++++------------------ arch/powerpc/kernel/ptrace/ptrace-vsx.c | 13 +- 7 files changed, 148 insertions(+), 304 deletions(-)
arch/powerpc/kernel/ptrace/ptrace-altivec.c +12 -25
@@ -41,38 +41,25 @@ int vr_active(struct task_struct *target, const struct user_regset *regset)* }; */ int vr_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count,void *kbuf,void __user *ubuf) +struct membuf to) { -int ret; +union { +elf_vrreg_t reg; +u32 word; + } vrsave;flush_altivec_to_thread (target);BUILD_BUG_ON (offsetof(struct thread_vr_state , vscr) != offsetof(struct thread_vr_state, vr[32])); - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - &target->thread.vr_state,0 , -33 *sizeof (vector128)); -if (!ret) { -/* -* Copy out only the low-order word of vrsave. -*/ -int start, end; -union { -elf_vrreg_t reg; -u32 word; - } vrsave; -memset (&vrsave,0 ,sizeof (vrsave)); - - vrsave.word = target->thread.vrsave; - - start =33 *sizeof (vector128); - end = start +sizeof (vrsave); - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, &vrsave, - start, end); - } - -return ret; +membuf_write (&to, &target->thread.vr_state,33 *sizeof (vector128)); +/* +* Copy out only the low-order word of vrsave. +*/ +memset (&vrsave,0 ,sizeof (vrsave)); + vrsave.word = target->thread.vrsave; +return membuf_write (&to, &vrsave,sizeof (vrsave)); }/*
arch/powerpc/kernel/ptrace/ptrace-decl.h +15 -29
111 lines not on this page · raw message
arch/powerpc/kernel/ptrace/ptrace-novsx.c +2 -3
@@ -19,15 +19,14 @@* }; */ int fpr_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count,void *kbuf,void __user *ubuf) +struct membuf to) {BUILD_BUG_ON (offsetof(struct thread_fp_state , fpscr) != offsetof(struct thread_fp_state, fpr[32]));flush_fp_to_thread (target); -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, - &target->thread.fp_state,0 ,-1 ); +return membuf_write (&to, &target->thread.fp_state,33 *sizeof (u64)); }/*
arch/powerpc/kernel/ptrace/ptrace-spe.c +4 -12
@@ -23,25 +23,17 @@ int evr_active(struct task_struct *target, const struct user_regset *regset) }int evr_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count,void *kbuf,void __user *ubuf) +struct membuf to) { -int ret; -flush_spe_to_thread (target); - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - &target->thread.evr, -0 ,sizeof (target->thread.evr)); +membuf_write (&to, &target->thread.evr,sizeof (target->thread.evr));BUILD_BUG_ON (offsetof(struct thread_struct , acc) +sizeof (u64) != offsetof(struct thread_struct , spefscr)); -if (!ret) - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - &target->thread.acc, -sizeof (target->thread.evr),-1 ); - -return ret; +return membuf_write (&to, &target->thread.acc, +sizeof (u64) +sizeof (u32)); } int evr_set(struct task_struct *target, const struct user_regset *regset,
arch/powerpc/kernel/ptrace/ptrace-tm.c +44 -108
300 lines not on this page · raw message
arch/powerpc/kernel/ptrace/ptrace-view.c +66 -119
445 lines not on this page · raw message
arch/powerpc/kernel/ptrace/ptrace-vsx.c +5 -8
@@ -19,7 +19,7 @@* }; */ int fpr_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count,void *kbuf,void __user *ubuf) +struct membuf to) {u64 buf[33 ];int i;
@@ -30,7 +30,7 @@ int fpr_get(struct task_struct *target, const struct user_regset *regset,for (i =0 ; i <32 ; i++) buf[i] = target->thread.TS_FPR (i); buf[32 ] = target->thread.fp_state.fpscr; -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, buf,0 ,-1 ); +return membuf_write (&to, buf,33 *sizeof (u64)); }/*
@@ -95,10 +95,10 @@ int vsr_active(struct task_struct *target, const struct user_regset *regset)* }; */ int vsr_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count,void *kbuf,void __user *ubuf) +struct membuf to) {u64 buf[32 ]; -int ret, i; +int i;flush_tmregs_to_thread (target);flush_fp_to_thread (target);
@@ -108,10 +108,7 @@ int vsr_get(struct task_struct *target, const struct user_regset *regset,for (i =0 ; i <32 ; i++) buf[i] = target->thread.fp_state.fpr[i][TS_VSRLOWOFFSET ]; - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - buf,0 ,32 *sizeof (double )); - -return ret; +return membuf_write (&to, buf,32 *sizeof (double )); }/*
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 21/41 s390: switch to ->get2()
In reply to Al ViroFrom: Al Viro <[email protected]>
NB: compat NT_S390_LAST_BREAK might be better as compat_long_t rather than long. User-visible ABI, again...
--- arch/s390/kernel/ptrace.c | 199 ++++++++++++++-------------------------------- 1 file changed, 58 insertions(+), 141 deletions(-)
arch/s390/kernel/ptrace.c +58 -141
@@ -890,28 +890,14 @@ asmlinkage void do_syscall_trace_exit(struct pt_regs *regs)static int s390_regs_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) { +unsigned pos;if (target == current)save_access_regs (target->thread.acrs); -if (kbuf) { -unsigned long *k = kbuf; -while (count >0 ) { - *k++ =__peek_user (target, pos); - count -=sizeof (*k); - pos +=sizeof (*k); - } - }else { -unsigned long __user *u = ubuf; -while (count >0 ) { -if (__put_user (__peek_user (target, pos), u++)) -return -EFAULT ; - count -=sizeof (*u); - pos +=sizeof (*u); - } - } +for (pos =0 ; pos <sizeof (s390_regs); pos +=sizeof (long )) +membuf_store (&to,__peek_user (target, pos));return 0 ; }
@@ -952,8 +938,8 @@ static int s390_regs_set(struct task_struct *target, }static int s390_fpregs_get (struct task_struct *target, -const struct user_regset *regset,unsigned int pos, -unsigned int count,void *kbuf,void __user *ubuf) +const struct user_regset *regset, +struct membuf to) {_s390_fp_regs fp_regs;
@@ -963,8 +949,7 @@ static int s390_fpregs_get(struct task_struct *target, fp_regs.fpc = target->thread.fpu.fpc;fpregs_store (&fp_regs, &target->thread.fpu); -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, - &fp_regs,0 ,-1 ); +return membuf_write (&to, &fp_regs,sizeof (fp_regs)); } static int s390_fpregs_set(struct task_struct *target,
@@ -1011,20 +996,9 @@ static int s390_fpregs_set(struct task_struct *target,static int s390_last_break_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) { -if (count >0 ) { -if (kbuf) { -unsigned long *k = kbuf; - *k = target->thread.last_break; - }else { -unsigned long __user *u = ubuf; -if (__put_user (target->thread.last_break, u)) -return -EFAULT ; - } - } -return 0 ; +return membuf_store (&to, target->thread.last_break); } static int s390_last_break_set(struct task_struct *target,
@@ -1037,16 +1011,13 @@ static int s390_last_break_set(struct task_struct *target,static int s390_tdb_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) {struct pt_regs *regs =task_pt_regs (target); -unsigned char *data;if (!(regs->int_code &0x200 ))return -ENODATA ; - data = target->thread.trap_tdb; -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, data,0 ,256 ); +return membuf_write (&to, target->thread.trap_tdb,256 ); } static int s390_tdb_set(struct task_struct *target,
@@ -1059,8 +1030,7 @@ static int s390_tdb_set(struct task_struct *target,static int s390_vxrs_low_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) {__u64 vxrs[__NUM_VXRS_LOW];int i;
@@ -1071,7 +1041,7 @@ static int s390_vxrs_low_get(struct task_struct *target,save_fpu_regs ();for (i =0 ; i < __NUM_VXRS_LOW; i++) vxrs[i] = *((__u64 *)(target->thread.fpu.vxrs + i) +1 ); -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, vxrs,0 ,-1 ); +return membuf_write (&to, vxrs,sizeof (vxrs)); } static int s390_vxrs_low_set(struct task_struct *target,
@@ -1100,18 +1070,14 @@ static int s390_vxrs_low_set(struct task_struct *target,static int s390_vxrs_high_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) { -__vector128 vxrs[__NUM_VXRS_HIGH]; -if (!MACHINE_HAS_VX )return -ENODEV ;if (target == current)save_fpu_regs (); -memcpy (vxrs, target->thread.fpu.vxrs + __NUM_VXRS_LOW,sizeof (vxrs)); - -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, vxrs,0 ,-1 ); +return membuf_write (&to, target->thread.fpu.vxrs + __NUM_VXRS_LOW, + __NUM_VXRS_HIGH *sizeof (__vector128)); } static int s390_vxrs_high_set(struct task_struct *target,
@@ -1133,12 +1099,9 @@ static int s390_vxrs_high_set(struct task_struct *target,static int s390_system_call_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) { -unsigned int *data = &target->thread.system_call; -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, - data,0 ,sizeof (unsigned int )); +return membuf_store (&to, target->thread.system_call); } static int s390_system_call_set(struct task_struct *target,
@@ -1153,8 +1116,7 @@ static int s390_system_call_set(struct task_struct *target,static int s390_gs_cb_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) {struct gs_cb *data = target->thread.gs_cb;
@@ -1164,8 +1126,7 @@ static int s390_gs_cb_get(struct task_struct *target,return -ENODATA ;if (target == current)save_gs_cb (data); -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, - data,0 ,sizeof (struct gs_cb )); +return membuf_write (&to, data,sizeof (struct gs_cb )); } static int s390_gs_cb_set(struct task_struct *target,
@@ -1209,8 +1170,7 @@ static int s390_gs_cb_set(struct task_struct *target,static int s390_gs_bc_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) {struct gs_cb *data = target->thread.gs_bc_cb;
@@ -1218,8 +1178,7 @@ static int s390_gs_bc_get(struct task_struct *target,return -ENODEV ;if (!data)return -ENODATA ; -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, - data,0 ,sizeof (struct gs_cb )); +return membuf_write (&to, data,sizeof (struct gs_cb )); } static int s390_gs_bc_set(struct task_struct *target,
@@ -1270,8 +1229,7 @@ static bool is_ri_cb_valid(struct runtime_instr_cb *cb)static int s390_runtime_instr_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) {struct runtime_instr_cb *data = target->thread.ri_cb;
@@ -1280,8 +1238,7 @@ static int s390_runtime_instr_get(struct task_struct *target,if (!data)return -ENODATA ; -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, - data,0 ,sizeof (struct runtime_instr_cb )); +return membuf_write (&to, data,sizeof (struct runtime_instr_cb )); } static int s390_runtime_instr_set(struct task_struct *target,
@@ -1337,7 +1294,7 @@ static const struct user_regset s390_regsets[] = { .n = sizeof(s390_regs) / sizeof(long), .size = sizeof(long), .align = sizeof(long), - .get = s390_regs_get, + .get2 = s390_regs_get, .set = s390_regs_set, }, {
@@ -1345,7 +1302,7 @@ static const struct user_regset s390_regsets[] = { .n = sizeof(s390_fp_regs) / sizeof(long), .size = sizeof(long), .align = sizeof(long), - .get = s390_fpregs_get, + .get2 = s390_fpregs_get, .set = s390_fpregs_set, }, {
@@ -1353,7 +1310,7 @@ static const struct user_regset s390_regsets[] = { .n = 1, .size = sizeof(unsigned int), .align = sizeof(unsigned int), - .get = s390_system_call_get, + .get2 = s390_system_call_get, .set = s390_system_call_set, }, {
@@ -1361,7 +1318,7 @@ static const struct user_regset s390_regsets[] = { .n = 1, .size = sizeof(long), .align = sizeof(long), - .get = s390_last_break_get, + .get2 = s390_last_break_get, .set = s390_last_break_set, }, {
@@ -1369,7 +1326,7 @@ static const struct user_regset s390_regsets[] = { .n = 1, .size = 256, .align = 1, - .get = s390_tdb_get, + .get2 = s390_tdb_get, .set = s390_tdb_set, }, {
@@ -1377,7 +1334,7 @@ static const struct user_regset s390_regsets[] = { .n = __NUM_VXRS_LOW, .size = sizeof(__u64), .align = sizeof(__u64), - .get = s390_vxrs_low_get, + .get2 = s390_vxrs_low_get, .set = s390_vxrs_low_set, }, {
@@ -1385,7 +1342,7 @@ static const struct user_regset s390_regsets[] = { .n = __NUM_VXRS_HIGH, .size = sizeof(__vector128), .align = sizeof(__vector128), - .get = s390_vxrs_high_get, + .get2 = s390_vxrs_high_get, .set = s390_vxrs_high_set, }, {
@@ -1393,7 +1350,7 @@ static const struct user_regset s390_regsets[] = { .n = sizeof(struct gs_cb) / sizeof(__u64), .size = sizeof(__u64), .align = sizeof(__u64), - .get = s390_gs_cb_get, + .get2 = s390_gs_cb_get, .set = s390_gs_cb_set, }, {
@@ -1401,7 +1358,7 @@ static const struct user_regset s390_regsets[] = { .n = sizeof(struct gs_cb) / sizeof(__u64), .size = sizeof(__u64), .align = sizeof(__u64), - .get = s390_gs_bc_get, + .get2 = s390_gs_bc_get, .set = s390_gs_bc_set, }, {
@@ -1409,7 +1366,7 @@ static const struct user_regset s390_regsets[] = { .n = sizeof(struct runtime_instr_cb) / sizeof(__u64), .size = sizeof(__u64), .align = sizeof(__u64), - .get = s390_runtime_instr_get, + .get2 = s390_runtime_instr_get, .set = s390_runtime_instr_set, }, };
@@ -1424,28 +1381,15 @@ static const struct user_regset_view user_s390_view = {#ifdef CONFIG_COMPAT static int s390_compat_regs_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) { +unsigned n; +if (target == current)save_access_regs (target->thread.acrs); -if (kbuf) { -compat_ulong_t *k = kbuf; -while (count >0 ) { - *k++ =__peek_user_compat (target, pos); - count -=sizeof (*k); - pos +=sizeof (*k); - } - }else { -compat_ulong_t __user *u = ubuf; -while (count >0 ) { -if (__put_user (__peek_user_compat (target, pos), u++)) -return -EFAULT ; - count -=sizeof (*u); - pos +=sizeof (*u); - } - } +for (n =0 ; n <sizeof (s390_compat_regs); n +=sizeof (compat_ulong_t)) +membuf_store (&to,__peek_user_compat (target, n));return 0 ; }
@@ -1487,29 +1431,14 @@ static int s390_compat_regs_set(struct task_struct *target,static int s390_compat_regs_high_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) {compat_ulong_t *gprs_high; +int i; - gprs_high = (compat_ulong_t *) - &task_pt_regs (target)->gprs[pos /sizeof (compat_ulong_t)]; -if (kbuf) { -compat_ulong_t *k = kbuf; -while (count >0 ) { - *k++ = *gprs_high; - gprs_high +=2 ; - count -=sizeof (*k); - } - }else { -compat_ulong_t __user *u = ubuf; -while (count >0 ) { -if (__put_user (*gprs_high, u++)) -return -EFAULT ; - gprs_high +=2 ; - count -=sizeof (*u); - } - } + gprs_high = (compat_ulong_t *)task_pt_regs (target)->gprs; +for (i =0 ; i <NUM_GPRS ; i++, gprs_high +=2 ) +membuf_store (&to, *gprs_high);return 0 ; }
@@ -1548,23 +1477,11 @@ static int s390_compat_regs_high_set(struct task_struct *target,static int s390_compat_last_break_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) { -compat_ulong_t last_break; +compat_ulong_t last_break = target->thread.last_break; -if (count >0 ) { - last_break = target->thread.last_break; -if (kbuf) { -unsigned long *k = kbuf; - *k = last_break; - }else { -unsigned long __user *u = ubuf; -if (__put_user (last_break, u)) -return -EFAULT ; - } - } -return 0 ; +return membuf_store (&to, (unsigned long )last_break); } static int s390_compat_last_break_set(struct task_struct *target,
@@ -1581,7 +1498,7 @@ static const struct user_regset s390_compat_regsets[] = { .n = sizeof(s390_compat_regs) / sizeof(compat_long_t), .size = sizeof(compat_long_t), .align = sizeof(compat_long_t), - .get = s390_compat_regs_get, + .get2 = s390_compat_regs_get, .set = s390_compat_regs_set, }, {
@@ -1589,7 +1506,7 @@ static const struct user_regset s390_compat_regsets[] = { .n = sizeof(s390_fp_regs) / sizeof(compat_long_t), .size = sizeof(compat_long_t), .align = sizeof(compat_long_t), - .get = s390_fpregs_get, + .get2 = s390_fpregs_get, .set = s390_fpregs_set, }, {
@@ -1597,7 +1514,7 @@ static const struct user_regset s390_compat_regsets[] = { .n = 1, .size = sizeof(compat_uint_t), .align = sizeof(compat_uint_t), - .get = s390_system_call_get, + .get2 = s390_system_call_get, .set = s390_system_call_set, }, {
@@ -1605,7 +1522,7 @@ static const struct user_regset s390_compat_regsets[] = { .n = 1, .size = sizeof(long), .align = sizeof(long), - .get = s390_compat_last_break_get, + .get2 = s390_compat_last_break_get, .set = s390_compat_last_break_set, }, {
@@ -1613,7 +1530,7 @@ static const struct user_regset s390_compat_regsets[] = { .n = 1, .size = 256, .align = 1, - .get = s390_tdb_get, + .get2 = s390_tdb_get, .set = s390_tdb_set, }, {
@@ -1621,7 +1538,7 @@ static const struct user_regset s390_compat_regsets[] = { .n = __NUM_VXRS_LOW, .size = sizeof(__u64), .align = sizeof(__u64), - .get = s390_vxrs_low_get, + .get2 = s390_vxrs_low_get, .set = s390_vxrs_low_set, }, {
@@ -1629,7 +1546,7 @@ static const struct user_regset s390_compat_regsets[] = { .n = __NUM_VXRS_HIGH, .size = sizeof(__vector128), .align = sizeof(__vector128), - .get = s390_vxrs_high_get, + .get2 = s390_vxrs_high_get, .set = s390_vxrs_high_set, }, {
@@ -1637,7 +1554,7 @@ static const struct user_regset s390_compat_regsets[] = { .n = sizeof(s390_compat_regs_high) / sizeof(compat_long_t), .size = sizeof(compat_long_t), .align = sizeof(compat_long_t), - .get = s390_compat_regs_high_get, + .get2 = s390_compat_regs_high_get, .set = s390_compat_regs_high_set, }, {
@@ -1645,7 +1562,7 @@ static const struct user_regset s390_compat_regsets[] = { .n = sizeof(struct gs_cb) / sizeof(__u64), .size = sizeof(__u64), .align = sizeof(__u64), - .get = s390_gs_cb_get, + .get2 = s390_gs_cb_get, .set = s390_gs_cb_set, }, {
@@ -1653,7 +1570,7 @@ static const struct user_regset s390_compat_regsets[] = { .n = sizeof(struct gs_cb) / sizeof(__u64), .size = sizeof(__u64), .align = sizeof(__u64), - .get = s390_gs_bc_get, + .get2 = s390_gs_bc_get, .set = s390_gs_bc_set, }, {
@@ -1661,7 +1578,7 @@ static const struct user_regset s390_compat_regsets[] = { .n = sizeof(struct runtime_instr_cb) / sizeof(__u64), .size = sizeof(__u64), .align = sizeof(__u64), - .get = s390_runtime_instr_get, + .get2 = s390_runtime_instr_get, .set = s390_runtime_instr_set, }, };
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 22/41 sparc: switch to ->get2()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- arch/sparc/kernel/ptrace_32.c | 127 ++++----------- arch/sparc/kernel/ptrace_64.c | 352 ++++++++++-------------------------------- 2 files changed, 110 insertions(+), 369 deletions(-)
arch/sparc/kernel/ptrace_32.c +30 -97
@@ -83,39 +83,25 @@ static int regwindow32_set(struct task_struct *target,static int genregs32_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) {const struct pt_regs *regs = target->thread.kregs;u32 uregs[16 ]; -int ret;if (target == current)flush_user_windows (); - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - regs->u_regs, -0 ,16 *sizeof (u32)); -if (ret || !count) -return ret; - +membuf_write (&to, regs->u_regs,16 *sizeof (u32)); +if (!to.left) +return 0 ;if (regwindow32_get (target, regs, uregs))return -EFAULT ; - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - uregs, -16 *sizeof (u32),32 *sizeof (u32)); -if (ret) -return ret; - - uregs[0 ] = regs->psr; - uregs[1 ] = regs->pc; - uregs[2 ] = regs->npc; - uregs[3 ] = regs->y; - uregs[4 ] =0 ;/* WIM */ - uregs[5 ] =0 ;/* TBR */ -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, - uregs, -32 *sizeof (u32),38 *sizeof (u32)); +membuf_write (&to, uregs,16 *sizeof (u32)); +membuf_store (&to, regs->psr); +membuf_store (&to, regs->pc); +membuf_store (&to, regs->npc); +membuf_store (&to, regs->y); +return membuf_zero (&to,2 *sizeof (u32)); } static int genregs32_set(struct task_struct *target,
@@ -179,46 +165,18 @@ static int genregs32_set(struct task_struct *target,static int fpregs32_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) { -const unsigned long *fpregs = target->thread.float_regs; -int ret =0 ; -#if 0 if (target == current)save_and_clear_fpu ();#endif - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - fpregs, -0 ,32 *sizeof (u32)); - -if (!ret) - ret =user_regset_copyout_zero (&pos, &count, &kbuf, &ubuf, -32 *sizeof (u32), -33 *sizeof (u32)); -if (!ret) - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - &target->thread.fsr, -33 *sizeof (u32), -34 *sizeof (u32)); - -if (!ret) { -unsigned long val; - - val = (1 <<8 ) | (8 <<16 ); - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - &val, -34 *sizeof (u32), -35 *sizeof (u32)); - } - -if (!ret) - ret =user_regset_copyout_zero (&pos, &count, &kbuf, &ubuf, -35 *sizeof (u32),-1 ); - -return ret; +membuf_write (&to, target->thread.float_regs,32 *sizeof (u32)); +membuf_zero (&to,sizeof (u32)); +membuf_write (&to, &target->thread.fsr,sizeof (u32)); +membuf_store (&to, (u32)((1 <<8 ) | (8 <<16 ))); +return membuf_zero (&to,64 *sizeof (u32)); } static int fpregs32_set(struct task_struct *target,
@@ -263,7 +221,7 @@ static const struct user_regset sparc32_regsets[] = { .core_note_type = NT_PRSTATUS, .n = 38, .size = sizeof(u32), .align = sizeof(u32), - .get = genregs32_get, .set = genregs32_set + .get2 = genregs32_get, .set = genregs32_set },/* Format is: * F0 --> F31
@@ -279,35 +237,24 @@ static const struct user_regset sparc32_regsets[] = { .core_note_type = NT_PRFPREG, .n = 99, .size = sizeof(u32), .align = sizeof(u32), - .get = fpregs32_get, .set = fpregs32_set + .get2 = fpregs32_get, .set = fpregs32_set }, };static int getregs_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) {const struct pt_regs *regs = target->thread.kregs; -u32 v[4 ]; -int ret;if (target == current)flush_user_windows (); - v[0 ] = regs->psr; - v[1 ] = regs->pc; - v[2 ] = regs->npc; - v[3 ] = regs->y; - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - v, -0 *sizeof (u32),4 *sizeof (u32)); -if (ret) -return ret; - -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, - regs->u_regs +1 , -4 *sizeof (u32),19 *sizeof (u32)); +membuf_store (&to, regs->psr); +membuf_store (&to, regs->pc); +membuf_store (&to, regs->npc); +membuf_store (&to, regs->y); +return membuf_write (&to, regs->u_regs +1 ,15 *sizeof (u32)); } static int setregs_set(struct task_struct *target,
@@ -337,29 +284,15 @@ static int setregs_set(struct task_struct *target,static int getfpregs_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) { -const unsigned long *fpregs = target->thread.float_regs; -int ret =0 ; -#if 0 if (target == current)save_and_clear_fpu ();#endif - - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - fpregs, -0 ,32 *sizeof (u32)); -if (ret) -return ret; - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - &target->thread.fsr, -32 *sizeof (u32),33 *sizeof (u32)); -if (ret) -return ret; -return user_regset_copyout_zero (&pos, &count, &kbuf, &ubuf, -33 *sizeof (u32),68 *sizeof (u32)); +membuf_write (&to, &target->thread.float_regs,32 *sizeof (u32)); +membuf_write (&to, &target->thread.fsr,sizeof (u32)); +return membuf_zero (&to,35 *sizeof (u32)); } static int setfpregs_set(struct task_struct *target,
@@ -388,11 +321,11 @@ static int setfpregs_set(struct task_struct *target,static const struct user_regset ptrace32_regsets[] = { [REGSET_GENERAL ] = { .n =19 , .size =sizeof (u32), - .get = getregs_get, .set = setregs_set, + .get2 = getregs_get, .set = setregs_set, }, [REGSET_FP ] = { .n =68 , .size =sizeof (u32), - .get = getfpregs_get, .set = setfpregs_set, + .get2 = getfpregs_get, .set = setfpregs_set, }, };
arch/sparc/kernel/ptrace_64.c +80 -272
480 lines not on this page · raw message
Signature · 1 line
2.11.0
Al Viro
maintainerRe: [PATCH 22/41] sparc: switch to ->get2()
Quoted 26 lines · Al Viro
static int getregs64_get(struct
task_struct*target,arch/sparc/kernel/ptrace_64.c +1
-17const struct user_regset *regset, - unsigned int pos, unsigned int count, - void *kbuf, void __user *ubuf) + struct membuf to) {const struct pt_regs *regs =task_pt_regs (target); -int ret;if (target == current)flushw_user (); - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - regs->u_regs +1 , -0 ,15 *sizeof (u64)); -if (!ret) - ret =user_regset_copyout_zero (&pos, &count, &kbuf, &ubuf, -15 *sizeof (u64),16 *sizeof (u64)); -if (!ret) { -/* TSTATE, TPC, TNPC */ - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - ®s->tstate, -16 *sizeof (u64), -19 *sizeof (u64)); - } -if (!ret) {
arch/sparc/kernel/ptrace_64.c static const struct user_regset sparc64_regsets[] = { · line 453
Quoted 10 lines
arch/sparc/kernel/ptrace_64.c +2
-8-unsigned long y = regs->y; - - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - &y, -19 *sizeof (u64), -20 *sizeof (u64)); - } -return ret; +membuf_write (&to, regs->u_regs +1 ,15 *sizeof (u64)); +return membuf_store (&to, (u64 )0 );
^^^^^^
Er... That should be simply
+ membuf_store(&to, (u64)0);
Quoted 3 lines
arch/sparc/kernel/ptrace_64.c +2
-0+membuf_write (&to, ®s->tstate,3 *sizeof (u64)); +return membuf_store (&to, (u64 )regs->y); }
Al Viro
maintainerPATCH 23/41 mips: switch to ->get2()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- arch/mips/kernel/ptrace.c | 204 +++++++++++++--------------------------------- 1 file changed, 58 insertions(+), 146 deletions(-)
arch/mips/kernel/ptrace.c +58 -146
@@ -210,15 +210,13 @@ int ptrace_set_watch_regs(struct task_struct *child,static int gpr32_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) {struct pt_regs *regs =task_pt_regs (target);u32 uregs[ELF_NGREG ] = {};mips_dump_regs32 (uregs, regs); -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, uregs,0 , -sizeof (uregs)); +return membuf_write (&to, uregs,sizeof (uregs)); } static int gpr32_set(struct task_struct *target,
@@ -277,15 +275,13 @@ static int gpr32_set(struct task_struct *target,static int gpr64_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) {struct pt_regs *regs =task_pt_regs (target);u64 uregs[ELF_NGREG ] = {};mips_dump_regs64 (uregs, regs); -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, uregs,0 , -sizeof (uregs)); +return membuf_write (&to, uregs,sizeof (uregs)); } static int gpr64_set(struct task_struct *target,
@@ -408,13 +404,11 @@ int ptrace_setfpregs(struct task_struct *child, __u32 __user *data)* !CONFIG_CPU_HAS_MSA variant. FP context's general register slots * correspond 1:1 to buffer slots. Only general registers are copied. */ -static int fpr_get_fpa (struct task_struct *target, -unsigned int *pos,unsigned int *count, -void **kbuf,void __user **ubuf) +static void fpr_get_fpa (struct task_struct *target, +struct membuf *to) { -return user_regset_copyout (pos, count, kbuf, ubuf, - &target->thread.fpu, -0 ,NUM_FPU_REGS *sizeof (elf_fpreg_t)); +membuf_write (to, &target->thread.fpu, +NUM_FPU_REGS *sizeof (elf_fpreg_t)); }/*
@@ -423,25 +417,13 @@ static int fpr_get_fpa(struct task_struct *target,* general register slots are copied to buffer slots. Only general * registers are copied. */ -static int fpr_get_msa (struct task_struct *target, -unsigned int *pos,unsigned int *count, -void **kbuf,void __user **ubuf) +static void fpr_get_msa (struct task_struct *target,struct membuf *to) {unsigned int i; -u64 fpr_val; -int err; - -BUILD_BUG_ON (sizeof (fpr_val) !=sizeof (elf_fpreg_t)); -for (i =0 ; i <NUM_FPU_REGS ; i++) { - fpr_val =get_fpr64 (&target->thread.fpu.fpr[i],0 ); - err =user_regset_copyout (pos, count, kbuf, ubuf, - &fpr_val, i *sizeof (elf_fpreg_t), - (i +1 ) *sizeof (elf_fpreg_t)); -if (err) -return err; - } -return 0 ; +BUILD_BUG_ON (sizeof (u64) !=sizeof (elf_fpreg_t)); +for (i =0 ; i <NUM_FPU_REGS ; i++) +membuf_store (to,get_fpr64 (&target->thread.fpu.fpr[i],0 )); }/*
@@ -451,31 +433,16 @@ static int fpr_get_msa(struct task_struct *target,*/ static int fpr_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) { -const int fcr31_pos =NUM_FPU_REGS *sizeof (elf_fpreg_t); -const int fir_pos = fcr31_pos +sizeof (u32); -int err; -if (sizeof (target->thread.fpu.fpr[0 ]) ==sizeof (elf_fpreg_t)) - err =fpr_get_fpa (target, &pos, &count, &kbuf, &ubuf); +fpr_get_fpa (target, &to);else - err =fpr_get_msa (target, &pos, &count, &kbuf, &ubuf); -if (err) -return err; - - err =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - &target->thread.fpu.fcr31, - fcr31_pos, fcr31_pos +sizeof (u32)); -if (err) -return err; +fpr_get_msa (target, &to); - err =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - &boot_cpu_data.fpu_id, - fir_pos, fir_pos +sizeof (u32)); - -return err; +membuf_write (&to, &target->thread.fpu.fcr31,sizeof (u32)); +membuf_write (&to, &boot_cpu_data.fpu_id,sizeof (u32)); +return 0 ; }/*
@@ -576,14 +543,9 @@ static int fpr_set(struct task_struct *target,/* Copy the FP mode setting to the supplied NT_MIPS_FP_MODE buffer. */ static int fp_mode_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) { -int fp_mode; - - fp_mode =mips_get_process_fp_mode (target); -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, &fp_mode,0 , -sizeof (fp_mode)); +return membuf_store (&to, (int )mips_get_process_fp_mode (target)); }/*
@@ -630,13 +592,12 @@ struct msa_control_regs {unsigned int msacsr; }; -static int copy_pad_fprs (struct task_struct *target, +static void copy_pad_fprs (struct task_struct *target,const struct user_regset *regset, -unsigned int *ppos,unsigned int *pcount, -void **pkbuf,void __user **pubuf, +struct membuf *to,unsigned int live_sz) { -int i, j, start, start_pad, err; +int i, j;unsigned long long fill = ~0ull ;unsigned int cp_sz, pad_sz;
@@ -644,28 +605,16 @@ static int copy_pad_fprs(struct task_struct *target, pad_sz = regset->size - cp_sz;WARN_ON (pad_sz %sizeof (fill)); - i = start = err =0 ; -for (; i <NUM_FPU_REGS ; i++, start += regset->size) { - err |=user_regset_copyout (ppos, pcount, pkbuf, pubuf, - &target->thread.fpu.fpr[i], - start, start + cp_sz); - - start_pad = start + cp_sz; -for (j =0 ; j < (pad_sz /sizeof (fill)); j++) { - err |=user_regset_copyout (ppos, pcount, pkbuf, pubuf, - &fill, start_pad, - start_pad +sizeof (fill)); - start_pad +=sizeof (fill); - } +for (i =0 ; i <NUM_FPU_REGS ; i++) { +membuf_write (to, &target->thread.fpu.fpr[i], cp_sz); +for (j =0 ; j < (pad_sz /sizeof (fill)); j++) +membuf_store (to, fill); } - -return err; }static int msa_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) {const unsigned int wr_size =NUM_FPU_REGS * regset->size;const struct msa_control_regs ctrl_regs = {
@@ -674,32 +623,23 @@ static int msa_get(struct task_struct *target, .msair = boot_cpu_data.msa_id, .msacsr = target->thread.fpu.msacsr, }; -int err;if (!tsk_used_math (target)) {/* The task hasn't used FP or MSA, fill with 0xff */ - err =copy_pad_fprs (target, regset, &pos, &count, - &kbuf, &ubuf,0 ); +copy_pad_fprs (target, regset, &to,0 ); }else if (!test_tsk_thread_flag (target,TIF_MSA_CTX_LIVE )) {/* Copy scalar FP context, fill the rest with 0xff */ - err =copy_pad_fprs (target, regset, &pos, &count, - &kbuf, &ubuf,8 ); +copy_pad_fprs (target, regset, &to,8 ); }else if (sizeof (target->thread.fpu.fpr[0 ]) == regset->size) {/* Trivially copy the vector registers */ - err =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - &target->thread.fpu.fpr, -0 , wr_size); +membuf_write (&to, &target->thread.fpu.fpr, wr_size); }else {/* Copy as much context as possible, fill the rest with 0xff */ - err =copy_pad_fprs (target, regset, &pos, &count, - &kbuf, &ubuf, -sizeof (target->thread.fpu.fpr[0 ])); +copy_pad_fprs (target, regset, &to, +sizeof (target->thread.fpu.fpr[0 ])); } - err |=user_regset_copyout (&pos, &count, &kbuf, &ubuf, - &ctrl_regs, wr_size, - wr_size +sizeof (ctrl_regs)); -return err; +return membuf_write (&to, &ctrl_regs,sizeof (ctrl_regs)); } static int msa_set(struct task_struct *target,
@@ -752,34 +692,20 @@ static int msa_set(struct task_struct *target,*/ static int dsp32_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) { -unsigned int start, num_regs, i;u32 dspregs[NUM_DSP_REGS +1 ]; +unsigned int i; -BUG_ON (count %sizeof (u32)); +BUG_ON (to.left %sizeof (u32));if (!cpu_has_dsp)return -EIO ; - start = pos /sizeof (u32); - num_regs = count /sizeof (u32); - -if (start + num_regs >NUM_DSP_REGS +1 ) -return -EIO ; - -for (i = start; i < num_regs; i++) -switch (i) { - case 0 ... NUM_DSP_REGS - 1: - dspregs[i] = target->thread.dsp.dspr[i]; -break ; -case NUM_DSP_REGS : - dspregs[i] = target->thread.dsp.dspcontrol; -break ; - } -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, dspregs,0 , -sizeof (dspregs)); +for (i =0 ; i <NUM_DSP_REGS ; i++) + dspregs[i] = target->thread.dsp.dspr[i]; + dspregs[NUM_DSP_REGS ] = target->thread.dsp.dspcontrol; +return membuf_write (&to, dspregs,sizeof (dspregs)); }/*
@@ -832,34 +758,20 @@ static int dsp32_set(struct task_struct *target,*/ static int dsp64_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) { -unsigned int start, num_regs, i;u64 dspregs[NUM_DSP_REGS +1 ]; +unsigned int i; -BUG_ON (count %sizeof (u64)); +BUG_ON (to.left %sizeof (u64));if (!cpu_has_dsp)return -EIO ; - start = pos /sizeof (u64); - num_regs = count /sizeof (u64); - -if (start + num_regs >NUM_DSP_REGS +1 ) -return -EIO ; - -for (i = start; i < num_regs; i++) -switch (i) { - case 0 ... NUM_DSP_REGS - 1: - dspregs[i] = target->thread.dsp.dspr[i]; -break ; -case NUM_DSP_REGS : - dspregs[i] = target->thread.dsp.dspcontrol; -break ; - } -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, dspregs,0 , -sizeof (dspregs)); +for (i =0 ; i <NUM_DSP_REGS ; i++) + dspregs[i] = target->thread.dsp.dspr[i]; + dspregs[NUM_DSP_REGS ] = target->thread.dsp.dspcontrol; +return membuf_write (&to, dspregs,sizeof (dspregs)); }/*
@@ -1018,7 +930,7 @@ static const struct user_regset mips_regsets[] = { .n = ELF_NGREG, .size = sizeof(unsigned int), .align = sizeof(unsigned int), - .get = gpr32_get, + .get2 = gpr32_get, .set = gpr32_set, }, [REGSET_DSP] = {
@@ -1026,7 +938,7 @@ static const struct user_regset mips_regsets[] = { .n = NUM_DSP_REGS + 1, .size = sizeof(u32), .align = sizeof(u32), - .get = dsp32_get, + .get2 = dsp32_get, .set = dsp32_set, .active = dsp_active, },
@@ -1036,7 +948,7 @@ static const struct user_regset mips_regsets[] = { .n = ELF_NFPREG, .size = sizeof(elf_fpreg_t), .align = sizeof(elf_fpreg_t), - .get = fpr_get, + .get2 = fpr_get, .set = fpr_set, }, [REGSET_FP_MODE] = {
@@ -1044,7 +956,7 @@ static const struct user_regset mips_regsets[] = { .n = 1, .size = sizeof(int), .align = sizeof(int), - .get = fp_mode_get, + .get2 = fp_mode_get, .set = fp_mode_set, },#endif
@@ -1054,7 +966,7 @@ static const struct user_regset mips_regsets[] = { .n = NUM_FPU_REGS + 1, .size = 16, .align = 16, - .get = msa_get, + .get2 = msa_get, .set = msa_set, },#endif
@@ -1078,7 +990,7 @@ static const struct user_regset mips64_regsets[] = { .n = ELF_NGREG, .size = sizeof(unsigned long), .align = sizeof(unsigned long), - .get = gpr64_get, + .get2 = gpr64_get, .set = gpr64_set, }, [REGSET_DSP] = {
@@ -1086,7 +998,7 @@ static const struct user_regset mips64_regsets[] = { .n = NUM_DSP_REGS + 1, .size = sizeof(u64), .align = sizeof(u64), - .get = dsp64_get, + .get2 = dsp64_get, .set = dsp64_set, .active = dsp_active, },
@@ -1096,7 +1008,7 @@ static const struct user_regset mips64_regsets[] = { .n = 1, .size = sizeof(int), .align = sizeof(int), - .get = fp_mode_get, + .get2 = fp_mode_get, .set = fp_mode_set, }, [REGSET_FPR] = {
@@ -1104,7 +1016,7 @@ static const struct user_regset mips64_regsets[] = { .n = ELF_NFPREG, .size = sizeof(elf_fpreg_t), .align = sizeof(elf_fpreg_t), - .get = fpr_get, + .get2 = fpr_get, .set = fpr_set, },#endif
@@ -1114,7 +1026,7 @@ static const struct user_regset mips64_regsets[] = { .n = NUM_FPU_REGS + 1, .size = 16, .align = 16, - .get = msa_get, + .get2 = msa_get, .set = msa_set, },#endif
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 24/41 arm64: switch to ->get2()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- arch/arm64/kernel/ptrace.c | 225 +++++++++++++-------------------------------- 1 file changed, 62 insertions(+), 163 deletions(-)
arch/arm64/kernel/ptrace.c +62 -163
@@ -474,11 +474,10 @@ static int ptrace_hbp_set_addr(unsigned int note_type,static int hw_break_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) {unsigned int note_type = regset->core_note_type; -int ret, idx =0 , offset, limit; +int ret, idx =0 ;u32 info, ctrl;u64 addr;
@@ -487,49 +486,21 @@ static int hw_break_get(struct task_struct *target,if (ret)return ret; - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, &info,0 , -sizeof (info)); -if (ret) -return ret; - -/* Pad */ - offset = offsetof(struct user_hwdebug_state , pad); - ret =user_regset_copyout_zero (&pos, &count, &kbuf, &ubuf, offset, - offset +PTRACE_HBP_PAD_SZ ); -if (ret) -return ret; - +membuf_write (&to, &info,sizeof (info)); +membuf_zero (&to,sizeof (u32));/* (address, ctrl) registers */ - offset = offsetof(struct user_hwdebug_state , dbg_regs); - limit = regset->n * regset->size; -while (count && offset < limit) { +while (to.left) { ret =ptrace_hbp_get_addr (note_type, target, idx, &addr);if (ret)return ret; - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, &addr, - offset, offset +PTRACE_HBP_ADDR_SZ ); -if (ret) -return ret; - offset +=PTRACE_HBP_ADDR_SZ ; - ret =ptrace_hbp_get_ctrl (note_type, target, idx, &ctrl);if (ret)return ret; - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, &ctrl, - offset, offset +PTRACE_HBP_CTRL_SZ ); -if (ret) -return ret; - offset +=PTRACE_HBP_CTRL_SZ ; - - ret =user_regset_copyout_zero (&pos, &count, &kbuf, &ubuf, - offset, - offset +PTRACE_HBP_PAD_SZ ); -if (ret) -return ret; - offset +=PTRACE_HBP_PAD_SZ ; +membuf_store (&to, addr); +membuf_store (&to, ctrl); +membuf_zero (&to,sizeof (u32)); idx++; } -return 0 ; }
@@ -589,11 +560,10 @@ static int hw_break_set(struct task_struct *target,static int gpr_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) {struct user_pt_regs *uregs = &task_pt_regs (target)->user_regs; -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, uregs,0 ,-1 ); +return membuf_write (&to, uregs,sizeof (*uregs)); } static int gpr_set(struct task_struct *target, const struct user_regset *regset,
@@ -626,8 +596,7 @@ static int fpr_active(struct task_struct *target, const struct user_regset *regs*/ static int __fpr_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf,unsigned int start_pos) +struct membuf to) {struct user_fpsimd_state *uregs;
@@ -635,13 +604,11 @@ static int __fpr_get(struct task_struct *target, uregs = &target->thread.uw.fpsimd_state; -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, uregs, - start_pos, start_pos +sizeof (*uregs)); +return membuf_write (&to, uregs,sizeof (*uregs)); }static int fpr_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) {if (!system_supports_fpsimd ())return -EINVAL ;
@@ -649,7 +616,7 @@ static int fpr_get(struct task_struct *target, const struct user_regset *regset,if (target == current)fpsimd_preserve_current_state (); -return __fpr_get (target, regset, pos, count, kbuf, ubuf,0 ); +return __fpr_get (target, regset, to); } static int __fpr_set(struct task_struct *target,
@@ -699,15 +666,12 @@ static int fpr_set(struct task_struct *target, const struct user_regset *regset, }static int tls_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) { -unsigned long *tls = &target->thread.uw.tp_value; -if (target == current)tls_preserve_current_state (); -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, tls,0 ,-1 ); +return membuf_store (&to, target->thread.uw.tp_value); } static int tls_set(struct task_struct *target, const struct user_regset *regset,
@@ -727,13 +691,9 @@ static int tls_set(struct task_struct *target, const struct user_regset *regset,static int system_call_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) { -int syscallno =task_pt_regs (target)->syscallno; - -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, - &syscallno,0 ,-1 ); +return membuf_store (&to,task_pt_regs (target)->syscallno); } static int system_call_set(struct task_struct *target,
@@ -794,10 +754,8 @@ static unsigned int sve_get_size(struct task_struct *target,static int sve_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) { -int ret;struct user_sve_header header;unsigned int vq;unsigned long start, end;
@@ -809,10 +767,7 @@ static int sve_get(struct task_struct *target,sve_init_header_from_task (&header, target); vq =sve_vq_from_vl (header.vl); - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, &header, -0 ,sizeof (header)); -if (ret) -return ret; +membuf_write (&to, &header,sizeof (header));if (target == current)fpsimd_preserve_current_state ();
@@ -821,26 +776,18 @@ static int sve_get(struct task_struct *target,BUILD_BUG_ON (SVE_PT_FPSIMD_OFFSET !=sizeof (header));if ((header.flags &SVE_PT_REGS_MASK ) ==SVE_PT_REGS_FPSIMD ) -return __fpr_get (target, regset, pos, count, kbuf, ubuf, -SVE_PT_FPSIMD_OFFSET ); +return __fpr_get (target, regset, to);/* Otherwise: full SVE case */ BUILD_BUG_ON (SVE_PT_SVE_OFFSET !=sizeof (header)); start =SVE_PT_SVE_OFFSET ; end =SVE_PT_SVE_FFR_OFFSET (vq) +SVE_PT_SVE_FFR_SIZE (vq); - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - target->thread.sve_state, - start, end); -if (ret) -return ret; +membuf_write (&to, target->thread.sve_state, end - start); start = end; end =SVE_PT_SVE_FPSR_OFFSET (vq); - ret =user_regset_copyout_zero (&pos, &count, &kbuf, &ubuf, - start, end); -if (ret) -return ret; +membuf_zero (&to, end - start);/* * Copy fpsr, and fpcr which must follow contiguously in
@@ -848,16 +795,11 @@ static int sve_get(struct task_struct *target,*/ start = end; end =SVE_PT_SVE_FPCR_OFFSET (vq) +SVE_PT_SVE_FPCR_SIZE ; - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - &target->thread.uw.fpsimd_state.fpsr, - start, end); -if (ret) -return ret; +membuf_write (&to, &target->thread.uw.fpsimd_state.fpsr, end - start); start = end; end =sve_size_from_header (&header); -return user_regset_copyout_zero (&pos, &count, &kbuf, &ubuf, - start, end); +return membuf_zero (&to, end - start); } static int sve_set(struct task_struct *target,
@@ -961,8 +903,7 @@ static int sve_set(struct task_struct *target,#ifdef CONFIG_ARM64_PTR_AUTH static int pac_mask_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) {/* * The PAC bits can differ across data and instruction pointers
@@ -978,7 +919,7 @@ static int pac_mask_get(struct task_struct *target,if (!system_supports_address_auth ())return -EINVAL ; -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, &uregs,0 ,-1 ); +return membuf_write (&to, &uregs,sizeof (uregs)); }#ifdef CONFIG_CHECKPOINT_RESTORE
@@ -1017,8 +958,7 @@ static void pac_address_keys_from_user(struct ptrauth_keys_user *keys,static int pac_address_keys_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) {struct ptrauth_keys_user *keys = &target->thread.keys_user;struct user_pac_address_keys user_keys;
@@ -1028,8 +968,7 @@ static int pac_address_keys_get(struct task_struct *target,pac_address_keys_to_user (&user_keys, keys); -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, - &user_keys,0 ,-1 ); +return membuf_write (&to, &user_keys,sizeof (user_keys)); } static int pac_address_keys_set(struct task_struct *target,
@@ -1068,8 +1007,7 @@ static void pac_generic_keys_from_user(struct ptrauth_keys_user *keys,static int pac_generic_keys_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) {struct ptrauth_keys_user *keys = &target->thread.keys_user;struct user_pac_generic_keys user_keys;
@@ -1079,8 +1017,7 @@ static int pac_generic_keys_get(struct task_struct *target,pac_generic_keys_to_user (&user_keys, keys); -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, - &user_keys,0 ,-1 ); +return membuf_write (&to, &user_keys,sizeof (user_keys)); } static int pac_generic_keys_set(struct task_struct *target,
@@ -1134,7 +1071,7 @@ static const struct user_regset aarch64_regsets[] = { .n = sizeof(struct user_pt_regs) / sizeof(u64), .size = sizeof(u64), .align = sizeof(u64), - .get = gpr_get, + .get2 = gpr_get, .set = gpr_set }, [REGSET_FPR] = {
@@ -1147,7 +1084,7 @@ static const struct user_regset aarch64_regsets[] = { .size = sizeof(u32), .align = sizeof(u32), .active = fpr_active, - .get = fpr_get, + .get2 = fpr_get, .set = fpr_set }, [REGSET_TLS] = {
@@ -1155,7 +1092,7 @@ static const struct user_regset aarch64_regsets[] = { .n = 1, .size = sizeof(void *), .align = sizeof(void *), - .get = tls_get, + .get2 = tls_get, .set = tls_set, },#ifdef CONFIG_HAVE_HW_BREAKPOINT
@@ -1164,7 +1101,7 @@ static const struct user_regset aarch64_regsets[] = { .n = sizeof(struct user_hwdebug_state) / sizeof(u32), .size = sizeof(u32), .align = sizeof(u32), - .get = hw_break_get, + .get2 = hw_break_get, .set = hw_break_set, }, [REGSET_HW_WATCH] = {
@@ -1172,7 +1109,7 @@ static const struct user_regset aarch64_regsets[] = { .n = sizeof(struct user_hwdebug_state) / sizeof(u32), .size = sizeof(u32), .align = sizeof(u32), - .get = hw_break_get, + .get2 = hw_break_get, .set = hw_break_set, },#endif
@@ -1181,7 +1118,7 @@ static const struct user_regset aarch64_regsets[] = { .n = 1, .size = sizeof(int), .align = sizeof(int), - .get = system_call_get, + .get2 = system_call_get, .set = system_call_set, },#ifdef CONFIG_ARM64_SVE
@@ -1191,7 +1128,7 @@ static const struct user_regset aarch64_regsets[] = { SVE_VQ_BYTES), .size = SVE_VQ_BYTES, .align = SVE_VQ_BYTES, - .get = sve_get, + .get2 = sve_get, .set = sve_set, .get_size = sve_get_size, },
@@ -1202,7 +1139,7 @@ static const struct user_regset aarch64_regsets[] = { .n = sizeof(struct user_pac_mask) / sizeof(u64), .size = sizeof(u64), .align = sizeof(u64), - .get = pac_mask_get, + .get2 = pac_mask_get, /* this cannot be set dynamically */ },#ifdef CONFIG_CHECKPOINT_RESTORE
@@ -1211,7 +1148,7 @@ static const struct user_regset aarch64_regsets[] = { .n = sizeof(struct user_pac_address_keys) / sizeof(__uint128_t), .size = sizeof(__uint128_t), .align = sizeof(__uint128_t), - .get = pac_address_keys_get, + .get2 = pac_address_keys_get, .set = pac_address_keys_set, }, [REGSET_PACG_KEYS] = {
@@ -1219,7 +1156,7 @@ static const struct user_regset aarch64_regsets[] = { .n = sizeof(struct user_pac_generic_keys) / sizeof(__uint128_t), .size = sizeof(__uint128_t), .align = sizeof(__uint128_t), - .get = pac_generic_keys_get, + .get2 = pac_generic_keys_get, .set = pac_generic_keys_set, },#endif
@@ -1255,39 +1192,13 @@ static inline compat_ulong_t compat_get_user_reg(struct task_struct *task, int istatic int compat_gpr_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) { -int ret =0 ; -unsigned int i, start, num_regs; - -/* Calculate the number of AArch32 registers contained in count */ - num_regs = count / regset->size; - -/* Convert pos into an register number */ - start = pos / regset->size; - -if (start + num_regs > regset->n) -return -EIO ; - -for (i =0 ; i < num_regs; ++i) { -compat_ulong_t reg =compat_get_user_reg (target, start + i); - -if (kbuf) { -memcpy (kbuf, ®,sizeof (reg)); - kbuf +=sizeof (reg); - }else { - ret =copy_to_user (ubuf, ®,sizeof (reg)); -if (ret) { - ret = -EFAULT ; -break ; - } +int i =0 ; - ubuf +=sizeof (reg); - } - } - -return ret; +while (to.left) +membuf_store (&to,compat_get_user_reg (target, i++)); +return 0 ; } static int compat_gpr_set(struct task_struct *target,
@@ -1354,12 +1265,10 @@ static int compat_gpr_set(struct task_struct *target,static int compat_vfp_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) {struct user_fpsimd_state *uregs;compat_ulong_t fpscr; -int ret, vregs_end_pos;if (!system_supports_fpsimd ())return -EINVAL ;
@@ -1373,19 +1282,10 @@ static int compat_vfp_get(struct task_struct *target,* The VFP registers are packed into the fpsimd_state, so they all sit * nicely together for us. We just need to create the fpscr separately. */ - vregs_end_pos =VFP_STATE_SIZE -sizeof (compat_ulong_t); - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, uregs, -0 , vregs_end_pos); - -if (count && !ret) { - fpscr = (uregs->fpsr &VFP_FPSCR_STAT_MASK ) | - (uregs->fpcr &VFP_FPSCR_CTRL_MASK ); - - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, &fpscr, - vregs_end_pos,VFP_STATE_SIZE ); - } - -return ret; +membuf_write (&to, uregs,VFP_STATE_SIZE -sizeof (compat_ulong_t)); + fpscr = (uregs->fpsr &VFP_FPSCR_STAT_MASK ) | + (uregs->fpcr &VFP_FPSCR_CTRL_MASK ); +return membuf_store (&to, fpscr); } static int compat_vfp_set(struct task_struct *target,
@@ -1420,11 +1320,10 @@ static int compat_vfp_set(struct task_struct *target, }static int compat_tls_get (struct task_struct *target, -const struct user_regset *regset,unsigned int pos, -unsigned int count,void *kbuf,void __user *ubuf) +const struct user_regset *regset, +struct membuf to) { -compat_ulong_t tls = (compat_ulong_t )target->thread.uw.tp_value; -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, &tls,0 ,-1 ); +return membuf_store (&to, (compat_ulong_t )target->thread.uw.tp_value); } static int compat_tls_set(struct task_struct *target,
@@ -1449,7 +1348,7 @@ static const struct user_regset aarch32_regsets[] = { .n = COMPAT_ELF_NGREG, .size = sizeof(compat_elf_greg_t), .align = sizeof(compat_elf_greg_t), - .get = compat_gpr_get, + .get2 = compat_gpr_get, .set = compat_gpr_set }, [REGSET_COMPAT_VFP] = {
@@ -1458,7 +1357,7 @@ static const struct user_regset aarch32_regsets[] = { .size = sizeof(compat_ulong_t), .align = sizeof(compat_ulong_t), .active = fpr_active, - .get = compat_vfp_get, + .get2 = compat_vfp_get, .set = compat_vfp_set }, };
@@ -1474,7 +1373,7 @@ static const struct user_regset aarch32_ptrace_regsets[] = { .n = COMPAT_ELF_NGREG, .size = sizeof(compat_elf_greg_t), .align = sizeof(compat_elf_greg_t), - .get = compat_gpr_get, + .get2 = compat_gpr_get, .set = compat_gpr_set }, [REGSET_FPR] = {
@@ -1482,7 +1381,7 @@ static const struct user_regset aarch32_ptrace_regsets[] = { .n = VFP_STATE_SIZE / sizeof(compat_ulong_t), .size = sizeof(compat_ulong_t), .align = sizeof(compat_ulong_t), - .get = compat_vfp_get, + .get2 = compat_vfp_get, .set = compat_vfp_set }, [REGSET_TLS] = {
@@ -1490,7 +1389,7 @@ static const struct user_regset aarch32_ptrace_regsets[] = { .n = 1, .size = sizeof(compat_ulong_t), .align = sizeof(compat_ulong_t), - .get = compat_tls_get, + .get2 = compat_tls_get, .set = compat_tls_set, },#ifdef CONFIG_HAVE_HW_BREAKPOINT
@@ -1499,7 +1398,7 @@ static const struct user_regset aarch32_ptrace_regsets[] = { .n = sizeof(struct user_hwdebug_state) / sizeof(u32), .size = sizeof(u32), .align = sizeof(u32), - .get = hw_break_get, + .get2 = hw_break_get, .set = hw_break_set, }, [REGSET_HW_WATCH] = {
@@ -1507,7 +1406,7 @@ static const struct user_regset aarch32_ptrace_regsets[] = { .n = sizeof(struct user_hwdebug_state) / sizeof(u32), .size = sizeof(u32), .align = sizeof(u32), - .get = hw_break_get, + .get2 = hw_break_get, .set = hw_break_set, },#endif
@@ -1516,7 +1415,7 @@ static const struct user_regset aarch32_ptrace_regsets[] = { .n = 1, .size = sizeof(int), .align = sizeof(int), - .get = system_call_get, + .get2 = system_call_get, .set = system_call_set, }, };
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 25/41 sh: convert to ->get2()
In reply to Al ViroFrom: Al Viro <[email protected]>
NB: there's a direct call of fpregs_get() left in dump_fpu(). To be taken out once we convert ELF_FDPIC to use of regset.
--- arch/sh/kernel/process_32.c | 5 ++--- arch/sh/kernel/ptrace_32.c | 48 ++++++++++----------------------------------- 2 files changed, 12 insertions(+), 41 deletions(-)
arch/sh/kernel/process_32.c +2 -3
@@ -103,9 +103,8 @@ int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu) fpvalid = !!tsk_used_math (tsk);if (fpvalid) - fpvalid = !fpregs_get (tsk,NULL ,0 , -sizeof (struct user_fpu_struct ), - fpu,NULL ); + fpvalid = !fpregs_get (tsk,NULL , + (struct membuf ){fpu,sizeof (*fpu)});#endif return fpvalid;
arch/sh/kernel/ptrace_32.c +10 -38
97 lines not on this page · raw message
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 26/41 arm: switch to ->get2()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- arch/arm/kernel/ptrace.c | 52 +++++++++++------------------------------------- 1 file changed, 12 insertions(+), 40 deletions(-)
arch/arm/kernel/ptrace.c +12 -40
@@ -569,14 +569,9 @@ static int ptrace_sethbpregs(struct task_struct *tsk, long num,static int gpr_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) { -struct pt_regs *regs =task_pt_regs (target); - -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, - regs, -0 ,sizeof (*regs)); +return membuf_write (&to,task_pt_regs (target),sizeof (struct pt_regs )); } static int gpr_set(struct task_struct *target,
@@ -602,12 +597,10 @@ static int gpr_set(struct task_struct *target,static int fpa_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) { -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, - &task_thread_info (target)->fpstate, -0 ,sizeof (struct user_fp )); +return membuf_write (&to, &task_thread_info (target)->fpstate, +sizeof (struct user_fp )); } static int fpa_set(struct task_struct *target,
@@ -642,41 +635,20 @@ static int fpa_set(struct task_struct *target,* vfp_set() ignores this chunk * * 1 word for the FPSCR -* -* The bounds-checking logic built into user_regset_copyout and friends -* means that we can make a simple sequence of calls to map the relevant data -* to/from the specified slice of the user regset structure. */ static int vfp_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) { -int ret;struct thread_info *thread =task_thread_info (target);struct vfp_hard_struct const *vfp = &thread->vfpstate.hard; -const size_t user_fpregs_offset = offsetof(struct user_vfp , fpregs);const size_t user_fpscr_offset = offsetof(struct user_vfp , fpscr);vfp_sync_hwstate (thread); - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - &vfp->fpregs, - user_fpregs_offset, - user_fpregs_offset +sizeof (vfp->fpregs)); -if (ret) -return ret; - - ret =user_regset_copyout_zero (&pos, &count, &kbuf, &ubuf, - user_fpregs_offset +sizeof (vfp->fpregs), - user_fpscr_offset); -if (ret) -return ret; - -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, - &vfp->fpscr, - user_fpscr_offset, - user_fpscr_offset +sizeof (vfp->fpscr)); +membuf_write (&to, vfp->fpregs,sizeof (vfp->fpregs)); +membuf_zero (&to, user_fpscr_offset -sizeof (vfp->fpregs)); +return membuf_store (&to, vfp->fpscr); }/*
@@ -739,7 +711,7 @@ static const struct user_regset arm_regsets[] = { .n = ELF_NGREG, .size = sizeof(u32), .align = sizeof(u32), - .get = gpr_get, + .get2 = gpr_get, .set = gpr_set }, [REGSET_FPR] = {
@@ -751,7 +723,7 @@ static const struct user_regset arm_regsets[] = { .n = sizeof(struct user_fp) / sizeof(u32), .size = sizeof(u32), .align = sizeof(u32), - .get = fpa_get, + .get2 = fpa_get, .set = fpa_set },#ifdef CONFIG_VFP
@@ -764,7 +736,7 @@ static const struct user_regset arm_regsets[] = { .n = ARM_VFPREGS_SIZE / sizeof(u32), .size = sizeof(u32), .align = sizeof(u32), - .get = vfp_get, + .get2 = vfp_get, .set = vfp_set },#endif /* CONFIG_VFP */
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 27/41 arc: switch to ->get2()
In reply to Al ViroFrom: Al Viro <[email protected]>
NB: it used to do short store; fix is needed earlier in the series.
--- arch/arc/kernel/ptrace.c | 148 +++++++++++++++++++---------------------------- 1 file changed, 58 insertions(+), 90 deletions(-)
arch/arc/kernel/ptrace.c +58 -90
@@ -18,88 +18,61 @@ static struct callee_regs *task_callee_regs(struct task_struct *tsk)static int genregs_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) {const struct pt_regs *ptregs =task_pt_regs (target);const struct callee_regs *cregs =task_callee_regs (target); -int ret =0 ;unsigned int stop_pc_val; -#define REG_O_CHUNK (START ,END ,PTR ) \ - if (!ret) \ - ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, PTR, \ - offsetof(struct user_regs_struct, START), \ - offsetof(struct user_regs_struct, END)); - -#define REG_O_ONE (LOC ,PTR ) \ - if (!ret) \ - ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, PTR, \ - offsetof(struct user_regs_struct, LOC), \ - offsetof(struct user_regs_struct, LOC) + 4); - -#define REG_O_ZERO (LOC ) \ - if (!ret) \ - ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf, \ - offsetof(struct user_regs_struct, LOC), \ - offsetof(struct user_regs_struct, LOC) + 4); - -REG_O_ZERO (pad); -REG_O_ONE (scratch.bta, &ptregs->bta); -REG_O_ONE (scratch.lp_start, &ptregs->lp_start); -REG_O_ONE (scratch.lp_end, &ptregs->lp_end); -REG_O_ONE (scratch.lp_count, &ptregs->lp_count); -REG_O_ONE (scratch.status32, &ptregs->status32); -REG_O_ONE (scratch.ret, &ptregs->ret); -REG_O_ONE (scratch.blink, &ptregs->blink); -REG_O_ONE (scratch.fp, &ptregs->fp); -REG_O_ONE (scratch.gp, &ptregs->r26); -REG_O_ONE (scratch.r12, &ptregs->r12); -REG_O_ONE (scratch.r11, &ptregs->r11); -REG_O_ONE (scratch.r10, &ptregs->r10); -REG_O_ONE (scratch.r9, &ptregs->r9); -REG_O_ONE (scratch.r8, &ptregs->r8); -REG_O_ONE (scratch.r7, &ptregs->r7); -REG_O_ONE (scratch.r6, &ptregs->r6); -REG_O_ONE (scratch.r5, &ptregs->r5); -REG_O_ONE (scratch.r4, &ptregs->r4); -REG_O_ONE (scratch.r3, &ptregs->r3); -REG_O_ONE (scratch.r2, &ptregs->r2); -REG_O_ONE (scratch.r1, &ptregs->r1); -REG_O_ONE (scratch.r0, &ptregs->r0); -REG_O_ONE (scratch.sp, &ptregs->sp); - -REG_O_ZERO (pad2); - -REG_O_ONE (callee.r25, &cregs->r25); -REG_O_ONE (callee.r24, &cregs->r24); -REG_O_ONE (callee.r23, &cregs->r23); -REG_O_ONE (callee.r22, &cregs->r22); -REG_O_ONE (callee.r21, &cregs->r21); -REG_O_ONE (callee.r20, &cregs->r20); -REG_O_ONE (callee.r19, &cregs->r19); -REG_O_ONE (callee.r18, &cregs->r18); -REG_O_ONE (callee.r17, &cregs->r17); -REG_O_ONE (callee.r16, &cregs->r16); -REG_O_ONE (callee.r15, &cregs->r15); -REG_O_ONE (callee.r14, &cregs->r14); -REG_O_ONE (callee.r13, &cregs->r13); - -REG_O_ONE (efa, &target->thread.fault_address); - -if (!ret) { -if (in_brkpt_trap (ptregs)) { - stop_pc_val = target->thread.fault_address; -pr_debug ("\t\tstop_pc (brk-pt)\n" ); - }else { - stop_pc_val = ptregs->ret; -pr_debug ("\t\tstop_pc (others)\n" ); - } - -REG_O_ONE (stop_pc, &stop_pc_val); +membuf_zero (&to,4 );// pad +membuf_store (&to, ptregs->bta); +membuf_store (&to, ptregs->lp_start); +membuf_store (&to, ptregs->lp_end); +membuf_store (&to, ptregs->lp_count); +membuf_store (&to, ptregs->status32); +membuf_store (&to, ptregs->ret); +membuf_store (&to, ptregs->blink); +membuf_store (&to, ptregs->fp); +membuf_store (&to, ptregs->r26);// gp +membuf_store (&to, ptregs->r12); +membuf_store (&to, ptregs->r11); +membuf_store (&to, ptregs->r10); +membuf_store (&to, ptregs->r9); +membuf_store (&to, ptregs->r8); +membuf_store (&to, ptregs->r7); +membuf_store (&to, ptregs->r6); +membuf_store (&to, ptregs->r5); +membuf_store (&to, ptregs->r4); +membuf_store (&to, ptregs->r3); +membuf_store (&to, ptregs->r2); +membuf_store (&to, ptregs->r1); +membuf_store (&to, ptregs->r0); +membuf_store (&to, ptregs->sp); +membuf_zero (&to,4 );// pad2 +membuf_store (&to, cregs->r25); +membuf_store (&to, cregs->r24); +membuf_store (&to, cregs->r23); +membuf_store (&to, cregs->r22); +membuf_store (&to, cregs->r21); +membuf_store (&to, cregs->r20); +membuf_store (&to, cregs->r19); +membuf_store (&to, cregs->r18); +membuf_store (&to, cregs->r17); +membuf_store (&to, cregs->r16); +membuf_store (&to, cregs->r15); +membuf_store (&to, cregs->r14); +membuf_store (&to, cregs->r13); +membuf_store (&to, target->thread.fault_address);// efa + +if (in_brkpt_trap (ptregs)) { + stop_pc_val = target->thread.fault_address; +pr_debug ("\t\tstop_pc (brk-pt)\n" ); + }else { + stop_pc_val = ptregs->ret; +pr_debug ("\t\tstop_pc (others)\n" ); } -return ret; +return membuf_store (&to, stop_pc_val);// stop_pc } static int genregs_set(struct task_struct *target,
@@ -184,25 +157,20 @@ static int genregs_set(struct task_struct *target,#ifdef CONFIG_ISA_ARCV2 static int arcv2regs_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) {const struct pt_regs *regs =task_pt_regs (target); -int ret, copy_sz;if (IS_ENABLED (CONFIG_ARC_HAS_ACCL_REGS )) - copy_sz =sizeof (struct user_regs_arcv2 ); -else - copy_sz =4 ;/* r30 only */ +/* +* itemized copy not needed like above as layout of regs (r30,r58,r59) +* is exactly same in kernel (pt_regs) and userspace (user_regs_arcv2) +*/ +return membuf_write (&to, ®s->r30,sizeof (struct user_regs_arcv2 )); -/* -* itemized copy not needed like above as layout of regs (r30,r58,r59) -* is exactly same in kernel (pt_regs) and userspace (user_regs_arcv2) -*/ - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, ®s->r30, -0 , copy_sz); -return ret; +membuf_write (&to, ®s->r30,4 );/* r30 only */ +return membuf_zero (&to,sizeof (struct user_regs_arcv2 ) -4 ); } static int arcv2regs_set(struct task_struct *target,
@@ -237,7 +205,7 @@ static const struct user_regset arc_regsets[] = { .n = ELF_NGREG, .size = sizeof(unsigned long), .align = sizeof(unsigned long), - .get = genregs_get, + .get2 = genregs_get, .set = genregs_set, },#ifdef CONFIG_ISA_ARCV2
@@ -246,7 +214,7 @@ static const struct user_regset arc_regsets[] = { .n = ELF_ARCV2REG, .size = sizeof(unsigned long), .align = sizeof(unsigned long), - .get = arcv2regs_get, + .get2 = arcv2regs_get, .set = arcv2regs_set, },#endif
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 28/41 ia64: switch to ->get2()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- arch/ia64/kernel/ptrace.c | 149 ++++++++++++++++++---------------------------- 1 file changed, 58 insertions(+), 91 deletions(-)
arch/ia64/kernel/ptrace.c +58 -91
@@ -1489,9 +1489,17 @@ access_elf_reg(struct task_struct *target, struct unw_frame_info *info,return access_elf_areg (target, info, addr, data, write_access); } +struct regset_membuf { +struct membuf to; +int ret; +}; +void do_gpregs_get (struct unw_frame_info *info,void *arg) { -struct regset_getset *dst = arg; +struct regset_membuf *dst = arg; +struct membuf to = dst->to; +unsigned int n; +elf_greg_t reg;if (unw_unwind_to_user (info) <0 )return ;
@@ -1509,35 +1517,13 @@ void do_gpregs_get(struct unw_frame_info *info, void *arg)/* Skip r0 */ -if (dst->count >0 && dst->pos <ELF_GR_OFFSET (1 )) { - dst->ret =user_regset_copyout_zero (&dst->pos, &dst->count, - &dst->u.get.kbuf, - &dst->u.get.ubuf, -0 ,ELF_GR_OFFSET (1 )); -if (dst->ret) +membuf_zero (&to,8 ); +for (n =8 ; to.left && n <ELF_AR_END_OFFSET ; n +=8 ) { +if (access_elf_reg (info->task, info, n, ®,0 ) <0 ) { + dst->ret = -EIO ;return ; - } - -while (dst->count && dst->pos <ELF_AR_END_OFFSET ) { -unsigned int n, from, to; -elf_greg_t tmp[16 ]; - - from = dst->pos; - to = from +min (dst->count, (unsigned )sizeof (tmp)); -if (to >ELF_AR_END_OFFSET ) - to =ELF_AR_END_OFFSET ; -for (n =0 ; from < to; from +=sizeof (elf_greg_t), n++) { -if (access_elf_reg (dst->target, info, from, - &tmp[n],0 ) <0 ) { - dst->ret = -EIO ; -return ; - } } - dst->ret =user_regset_copyout (&dst->pos, &dst->count, - &dst->u.get.kbuf, &dst->u.get.ubuf, tmp, - dst->pos, to); -if (dst->ret) -return ; +membuf_store (&to, reg); } }
@@ -1588,60 +1574,36 @@ void do_gpregs_set(struct unw_frame_info *info, void *arg)void do_fpregs_get (struct unw_frame_info *info,void *arg) { -struct regset_getset *dst = arg; -struct task_struct *task = dst->target; -elf_fpreg_t tmp[30 ]; -int index, min_copy, i; +struct task_struct *task = info->task; +struct regset_membuf *dst = arg; +struct membuf to = dst->to; +elf_fpreg_t reg; +unsigned int n;if (unw_unwind_to_user (info) <0 )return ;/* Skip pos 0 and 1 */ -if (dst->count >0 && dst->pos <ELF_FP_OFFSET (2 )) { - dst->ret =user_regset_copyout_zero (&dst->pos, &dst->count, - &dst->u.get.kbuf, - &dst->u.get.ubuf, -0 ,ELF_FP_OFFSET (2 )); -if (dst->count ==0 || dst->ret) -return ; - } +membuf_zero (&to,2 *sizeof (elf_fpreg_t));/* fr2-fr31 */ -if (dst->count >0 && dst->pos <ELF_FP_OFFSET (32 )) { - index = (dst->pos -ELF_FP_OFFSET (2 )) /sizeof (elf_fpreg_t); - - min_copy =min (((unsigned int )ELF_FP_OFFSET (32 )), - dst->pos + dst->count); -for (i = dst->pos; i < min_copy; i +=sizeof (elf_fpreg_t), - index++) -if (unw_get_fr (info, i /sizeof (elf_fpreg_t), - &tmp[index])) { - dst->ret = -EIO ; -return ; - } - dst->ret =user_regset_copyout (&dst->pos, &dst->count, - &dst->u.get.kbuf, &dst->u.get.ubuf, tmp, -ELF_FP_OFFSET (2 ),ELF_FP_OFFSET (32 )); -if (dst->count ==0 || dst->ret) +for (n =2 ; to.left && n <32 ; n++) { +if (unw_get_fr (info, n, ®)) { + dst->ret = -EIO ;return ; + } +membuf_write (&to, ®,sizeof (reg)); }/* fph */ -if (dst->count >0 ) { -ia64_flush_fph (dst->target); -if (task->thread.flags &IA64_THREAD_FPH_VALID ) - dst->ret =user_regset_copyout ( - &dst->pos, &dst->count, - &dst->u.get.kbuf, &dst->u.get.ubuf, - &dst->target->thread.fph, -ELF_FP_OFFSET (32 ),-1 ); -else -/* Zero fill instead. */ - dst->ret =user_regset_copyout_zero ( - &dst->pos, &dst->count, - &dst->u.get.kbuf, &dst->u.get.ubuf, -ELF_FP_OFFSET (32 ),-1 ); - } +if (!to.left) +return ; + +ia64_flush_fph (task); +if (task->thread.flags &IA64_THREAD_FPH_VALID ) +membuf_write (&to, &task->thread.fph,96 *sizeof (reg)); +else +membuf_zero (&to,96 *sizeof (reg)); }void do_fpregs_set (struct unw_frame_info *info,void *arg)
@@ -1717,6 +1679,20 @@ void do_fpregs_set(struct unw_frame_info *info, void *arg) } } +static void +unwind_and_call (void (*call)(struct unw_frame_info *,void *), +struct task_struct *target,void *data) +{ +if (target == current) +unw_init_running (call, data); +else { +struct unw_frame_info info; +memset (&info,0 ,sizeof (info)); +unw_init_from_blocked_task (&info, target); + (*call)(&info, data); + } +} + static int do_regset_call(void (*call)(struct unw_frame_info *, void *), struct task_struct *target,
@@ -1728,27 +1704,18 @@ do_regset_call(void (*call)(struct unw_frame_info *, void *), .pos = pos, .count = count, .u.set = { .kbuf = kbuf, .ubuf = ubuf }, .ret = 0 }; - -if (target == current) -unw_init_running (call, &info); -else { -struct unw_frame_info ufi; -memset (&ufi,0 ,sizeof (ufi)); -unw_init_from_blocked_task (&ufi, target); - (*call)(&ufi, &info); - } - +unwind_and_call (call, target, &info);return info.ret; }static int gpregs_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) { -return do_regset_call (do_gpregs_get, target, regset, pos, count, - kbuf, ubuf); +struct regset_membuf info = {.to = to}; +unwind_and_call (do_gpregs_get, target, &info); +return info.ret; } static int gpregs_set(struct task_struct *target,
@@ -1790,11 +1757,11 @@ fpregs_active(struct task_struct *target, const struct user_regset *regset)static int fpregs_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) { -return do_regset_call (do_fpregs_get, target, regset, pos, count, - kbuf, ubuf); +struct regset_membuf info = {.to = to}; +unwind_and_call (do_fpregs_get, target, &info); +return info.ret; } static int fpregs_set(struct task_struct *target,
@@ -2033,14 +2000,14 @@ static const struct user_regset native_regsets[] = { .core_note_type = NT_PRSTATUS, .n = ELF_NGREG, .size = sizeof(elf_greg_t), .align = sizeof(elf_greg_t), - .get = gpregs_get, .set = gpregs_set, + .get2 = gpregs_get, .set = gpregs_set, .writeback = gpregs_writeback }, { .core_note_type = NT_PRFPREG, .n = ELF_NFPREG, .size = sizeof(elf_fpreg_t), .align = sizeof(elf_fpreg_t), - .get = fpregs_get, .set = fpregs_set, .active = fpregs_active + .get2 = fpregs_get, .set = fpregs_set, .active = fpregs_active }, };
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 29/41 c6x: switch to ->get2()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- arch/c6x/kernel/ptrace.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
arch/c6x/kernel/ptrace.c +3 -8
@@ -57,14 +57,9 @@ static inline int put_reg(struct task_struct *task,static int gpr_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) { -struct pt_regs *regs =task_pt_regs (target); - -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, - regs, -0 ,sizeof (*regs)); +return membuf_write (&to,task_pt_regs (target),sizeof (struct pt_regs )); }enum c6x_regset {
@@ -77,7 +72,7 @@ static const struct user_regset c6x_regsets[] = { .n = ELF_NGREG, .size = sizeof(u32), .align = sizeof(u32), - .get = gpr_get, + .get2 = gpr_get, }, };
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 30/41 riscv: switch to ->get2()
In reply to Al ViroFrom: Al Viro <[email protected]>
Note: riscv_fpr_get() used to forget to zero-pad at the end. Not worth -stable...
--- arch/riscv/kernel/ptrace.c | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-)
arch/riscv/kernel/ptrace.c +11 -22
@@ -30,13 +30,10 @@ enum riscv_regset {static int riscv_gpr_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) { -struct pt_regs *regs; - - regs =task_pt_regs (target); -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, regs,0 ,-1 ); +return membuf_write (&to,task_pt_regs (target), +sizeof (struct user_regs_struct )); } static int riscv_gpr_set(struct task_struct *target,
@@ -55,21 +52,13 @@ static int riscv_gpr_set(struct task_struct *target,#ifdef CONFIG_FPU static int riscv_fpr_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) { -int ret;struct __riscv_d_ext_state *fstate = &target->thread.fstate; - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, fstate,0 , - offsetof(struct __riscv_d_ext_state , fcsr)); -if (!ret) { - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, fstate,0 , - offsetof(struct __riscv_d_ext_state , fcsr) + -sizeof (fstate->fcsr)); - } - -return ret; +membuf_write (&to, fstate, offsetof(struct __riscv_d_ext_state , fcsr)); +membuf_store (&to, fstate->fcsr); +return membuf_zero (&to,4 );// explicitly pad } static int riscv_fpr_set(struct task_struct *target,
@@ -98,8 +87,8 @@ static const struct user_regset riscv_user_regset[] = { .n = ELF_NGREG, .size = sizeof(elf_greg_t), .align = sizeof(elf_greg_t), - .get = &riscv_gpr_get, - .set = &riscv_gpr_set, + .get2 = riscv_gpr_get, + .set = riscv_gpr_set, }, #ifdef CONFIG_FPU [REGSET_F] = {
@@ -107,8 +96,8 @@ static const struct user_regset riscv_user_regset[] = { .n = ELF_NFPREG, .size = sizeof(elf_fpreg_t), .align = sizeof(elf_fpreg_t), - .get = &riscv_fpr_get, - .set = &riscv_fpr_set, + .get2 = riscv_fpr_get, + .set = riscv_fpr_set, },#endif };
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 31/41 openrisc: switch to ->get2()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- arch/openrisc/kernel/ptrace.c | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-)
arch/openrisc/kernel/ptrace.c +6 -20
@@ -44,29 +44,15 @@*/ static int genregs_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user * ubuf) +struct membuf to) {const struct pt_regs *regs =task_pt_regs (target); -int ret;/* r0 */ - ret =user_regset_copyout_zero (&pos, &count, &kbuf, &ubuf,0 ,4 ); - -if (!ret) - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - regs->gpr+1 ,4 ,4 *32 ); -if (!ret) - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - ®s->pc,4 *32 ,4 *33 ); -if (!ret) - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - ®s->sr,4 *33 ,4 *34 ); -if (!ret) - ret =user_regset_copyout_zero (&pos, &count, &kbuf, &ubuf, -4 *34 ,-1 ); - -return ret; +membuf_zero (&to,4 ); +membuf_write (&to, regs->gpr +1 ,31 *4 ); +membuf_store (&to, regs->pc); +return membuf_store (&to, regs->sr); }/*
@@ -114,7 +100,7 @@ static const struct user_regset or1k_regsets[] = { .n = ELF_NGREG, .size = sizeof(long), .align = sizeof(long), - .get = genregs_get, + .get2 = genregs_get, .set = genregs_set, }, };
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 32/41 h8300: switch to ->get2()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- arch/h8300/kernel/ptrace.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)
arch/h8300/kernel/ptrace.c +6 -11
@@ -87,20 +87,15 @@ int h8300_put_reg(struct task_struct *task, int regno, unsigned long data)static int regs_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) {int r; -struct user_regs_struct regs; -long *reg = (long *)®s; -/* build user regs in buffer */ -BUILD_BUG_ON (sizeof (regs) %sizeof (long ) !=0 ); -for (r =0 ; r <sizeof (regs) /sizeof (long ); r++) - *reg++ =h8300_get_reg (target, r); +BUILD_BUG_ON (sizeof (struct user_regs_struct ) %sizeof (long ) !=0 ); +for (r =0 ; r <ELF_NGREG ; r++) +membuf_store (&to,h8300_get_reg (target, r)); -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, - ®s,0 ,sizeof (regs)); +return 0 ; } static int regs_set(struct task_struct *target,
@@ -139,7 +134,7 @@ static const struct user_regset h8300_regsets[] = { .n = ELF_NGREG, .size = sizeof(long), .align = sizeof(long), - .get = regs_get, + .get2 = regs_get, .set = regs_set, }, };
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 33/41 hexagon: switch to ->get2()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- arch/hexagon/kernel/ptrace.c | 62 +++++++++++++++----------------------------- 1 file changed, 21 insertions(+), 41 deletions(-)
arch/hexagon/kernel/ptrace.c +21 -41
@@ -35,58 +35,38 @@ void user_disable_single_step(struct task_struct *child)static int genregs_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) + srtuct membuf to) { -int ret; -unsigned int dummy;struct pt_regs *regs =task_pt_regs (target); - -if (!regs) -return -EIO ; -/* The general idea here is that the copyout must happen in * exactly the same order in which the userspace expects these * regs. Now, the sequence in userspace does not match the * sequence in the kernel, so everything past the 32 gprs * happens one at a time. */ - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - ®s->r00,0 ,32 *sizeof (unsigned long )); - -#define ONEXT (KPT_REG ,USR_REG ) \ - if (!ret) \ - ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, \ - KPT_REG, offsetof(struct user_regs_struct, USR_REG), \ - offsetof(struct user_regs_struct, USR_REG) + \ - sizeof(unsigned long)); - +membuf_write (&to, ®s->r00,32 *sizeof (unsigned long ));/* Must be exactly same sequence as struct user_regs_struct */ -ONEXT (®s->sa0, sa0); -ONEXT (®s->lc0, lc0); -ONEXT (®s->sa1, sa1); -ONEXT (®s->lc1, lc1); -ONEXT (®s->m0, m0); -ONEXT (®s->m1, m1); -ONEXT (®s->usr, usr); -ONEXT (®s->preds, p3_0); -ONEXT (®s->gp, gp); -ONEXT (®s->ugp, ugp); -ONEXT (&pt_elr (regs), pc); - dummy =pt_cause (regs); -ONEXT (&dummy, cause); -ONEXT (&pt_badva (regs), badva); +membuf_store (&to, regs->sa0); +membuf_store (&to, regs->lc0); +membuf_store (&to, regs->sa1); +membuf_store (&to, regs->lc1); +membuf_store (&to, regs->m0); +membuf_store (&to, regs->m1); +membuf_store (&to, regs->usr); +membuf_store (&to, regs->p3_0); +membuf_store (&to, regs->gp); +membuf_store (&to, regs->ugp); +membuf_store (&to,pt_elr (regs));// pc +membuf_store (&to, (unsigned long )pt_cause (regs));// cause +membuf_store (&to,pt_badva (regs));// badva #if CONFIG_HEXAGON_ARCH_VERSION >=4 -ONEXT (®s->cs0, cs0); -ONEXT (®s->cs1, cs1); +membuf_store (&to, regs->cs0); +membuf_store (&to, regs->cs1); +return membuf_zero (&to,sizeof (unsigned long )); +#else +return membuf_zero (&to,3 *sizeof (unsigned long ));#endif - -/* Pad the rest with zeros, if needed */ -if (!ret) - ret =user_regset_copyout_zero (&pos, &count, &kbuf, &ubuf, - offsetof(struct user_regs_struct , pad1),-1 ); -return ret; } static int genregs_set(struct task_struct *target,
@@ -159,7 +139,7 @@ static const struct user_regset hexagon_regsets[] = { .n = ELF_NGREG, .size = sizeof(unsigned long), .align = sizeof(unsigned long), - .get = genregs_get, + .get2 = genregs_get, .set = genregs_set, }, };
Signature · 1 line
2.11.0
RE: [PATCH 33/41] hexagon: switch to ->get2()
Quoted 4 lines
-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Al Viro
Quoted 5 lines
From: Al Viro <[email protected]>
Signed-off-by Al Viro <[email protected]>--- arch/hexagon/kernel/ptrace.c | 62
+++++++++++++++-----------------------------
arch/hexagon/kernel/ptrace.c
Quoted 3 lines
1 file changed, 21 insertions(+), 41 deletions(-)arch/hexagon/kernel/ptrace.c +0
-0
index
arch/hexagon/kernel/ptrace.c void user_disable_single_step(struct task_struct
Quoted 4 lines
dcbf7ea960cc..fa6287d1a061100644arch/hexagon/kernel/ptrace.c +0
-0@@ -35,58 +35,38 @@ void user_disable_single_step(struct task_struct
*child)
Quoted 69 lines
arch/hexagon/kernel/ptrace.c +19
-34static int genregs_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) + srtuct membuf to) { -int ret; -unsigned int dummy;struct pt_regs *regs =task_pt_regs (target); - -if (!regs) -return -EIO ; -/* The general idea here is that the copyout must happen in * exactly the same order in which the userspace expects these * regs. Now, the sequence in userspace does not match the * sequence in the kernel, so everything past the 32 gprs * happens one at a time. */ - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - ®s->r00,0 ,32 *sizeof (unsigned long )); - -#define ONEXT (KPT_REG ,USR_REG ) \ - if (!ret) \ - ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, \ - KPT_REG, offsetof(struct user_regs_struct, USR_REG), \ - offsetof(struct user_regs_struct , USR_REG) + \ - sizeof(unsigned long)); - +membuf_write (&to, ®s->r00,32 *sizeof (unsigned long ));/* Must be exactly same sequence as struct user_regs_struct */ -ONEXT (®s->sa0, sa0); -ONEXT (®s->lc0, lc0); -ONEXT (®s->sa1, sa1); -ONEXT (®s->lc1, lc1); -ONEXT (®s->m0, m0); -ONEXT (®s->m1, m1); -ONEXT (®s->usr, usr); -ONEXT (®s->preds, p3_0); -ONEXT (®s->gp, gp); -ONEXT (®s->ugp, ugp); -ONEXT (&pt_elr (regs), pc); - dummy =pt_cause (regs); -ONEXT (&dummy, cause); -ONEXT (&pt_badva (regs), badva); +membuf_store (&to, regs->sa0); +membuf_store (&to, regs->lc0); +membuf_store (&to, regs->sa1); +membuf_store (&to, regs->lc1); +membuf_store (&to, regs->m0); +membuf_store (&to, regs->m1); +membuf_store (&to, regs->usr); +membuf_store (&to, regs->p3_0); +membuf_store (&to, regs->gp); +membuf_store (&to, regs->ugp); +membuf_store (&to,pt_elr (regs));// pc +membuf_store (&to, (unsigned long )pt_cause (regs));// cause +membuf_store (&to,pt_badva (regs));// badva #if CONFIG_HEXAGON_ARCH_VERSION >=4 -ONEXT (®s->cs0, cs0); -ONEXT (®s->cs1, cs1); +membuf_store (&to, regs->cs0); +membuf_store (&to, regs->cs1); +return membuf_zero (&to,sizeof (unsigned long ));#else +return membuf_zero (&to,3 *sizeof (unsigned long ));#endif
arch/hexagon/kernel/ptrace.c void user_disable_single_step(struct task_struct *child)
Quoted 10 lines
arch/hexagon/kernel/ptrace.c +0
-6- -/* Pad the rest with zeros, if needed */ -if (!ret) - ret =user_regset_copyout_zero (&pos, &count, &kbuf, &ubuf, - offsetof(struct user_regs_struct , pad1), -1); -return ret; } static int genregs_set(struct task_struct *target, @@ -159,7 +139,7 @@
static
Quoted 11 lines
const struct
user_regsethexagon_regsets[] = {arch/hexagon/kernel/ptrace.c +1
-2.n = ELF_NGREG, .size = sizeof(unsigned long), .align = sizeof(unsigned long), - .get = genregs_get, + .get2 = genregs_get, .set = genregs_set, }, }; --2.11.0
Al Viro
maintainerPATCH 34/41 nios2: switch to ->get2()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- arch/nios2/kernel/ptrace.c | 51 ++++++++++++++-------------------------------- 1 file changed, 15 insertions(+), 36 deletions(-)
arch/nios2/kernel/ptrace.c +15 -36
@@ -21,45 +21,24 @@static int genregs_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) {const struct pt_regs *regs =task_pt_regs (target);const struct switch_stack *sw = (struct switch_stack *)regs -1 ; -int ret =0 ; - -#define REG_O_ZERO_RANGE (START ,END ) \ - if (!ret) \ - ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf, \ - START * 4, (END * 4) + 4); - -#define REG_O_ONE (PTR ,LOC ) \ - if (!ret) \ - ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, PTR, \ - LOC * 4, (LOC * 4) + 4); -#define REG_O_RANGE (PTR ,START ,END ) \ - if (!ret) \ - ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, PTR, \ - START * 4, (END * 4) + 4); - -REG_O_ZERO_RANGE (PTR_R0 ,PTR_R0 ); -REG_O_RANGE (®s->r1,PTR_R1 ,PTR_R7 ); -REG_O_RANGE (®s->r8,PTR_R8 ,PTR_R15 ); -REG_O_RANGE (sw,PTR_R16 ,PTR_R23 ); -REG_O_ZERO_RANGE (PTR_R24 ,PTR_R25 );/* et and bt */ -REG_O_ONE (®s->gp,PTR_GP ); -REG_O_ONE (®s->sp,PTR_SP ); -REG_O_ONE (®s->fp,PTR_FP ); -REG_O_ONE (®s->ea,PTR_EA ); -REG_O_ZERO_RANGE (PTR_BA ,PTR_BA ); -REG_O_ONE (®s->ra,PTR_RA ); -REG_O_ONE (®s->ea,PTR_PC );/* use ea for PC */ -if (!ret) - ret =user_regset_copyout_zero (&pos, &count, &kbuf, &ubuf, -PTR_STATUS *4 ,-1 ); - -return ret; +membuf_zero (&to,4 );// R0 +membuf_write (&to, ®s->r1,7 *4 );// R1..R7 +membuf_write (&to, ®s->r8,8 *4 );// R8..R15 +membuf_write (&to, sw,8 *4 );// R16..R23 +membuf_zero (&to,2 *4 );/* et and bt */ +membuf_store (&to, regs->gp); +membuf_store (&to, regs->sp); +membuf_store (&to, regs->fp); +membuf_store (&to, regs->ea); +membuf_zero (&to,4 );// PTR_BA +membuf_store (&to, regs->ra); +membuf_store (&to, regs->ea);/* use ea for PC */ +return membuf_zero (&to, (NUM_PTRACE_REG -PTR_PC ) *4 ); }/*
@@ -121,7 +100,7 @@ static const struct user_regset nios2_regsets[] = { .n = NUM_PTRACE_REG, .size = sizeof(unsigned long), .align = sizeof(unsigned long), - .get = genregs_get, + .get2 = genregs_get, .set = genregs_set, } };
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 35/41 nds32: switch to ->get2()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- arch/nds32/kernel/ptrace.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
arch/nds32/kernel/ptrace.c +4 -5
@@ -13,11 +13,10 @@ enum nds32_regset {static int gpr_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user * ubuf) +struct membuf to) { -struct user_pt_regs *uregs = &task_pt_regs (target)->user_regs; -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, uregs,0 ,-1 ); +return membuf_write (&to, &task_pt_regs (target)->user_regs, +sizeof (struct user_pt_regs )); } static int gpr_set(struct task_struct *target, const struct user_regset *regset,
@@ -41,7 +40,7 @@ static const struct user_regset nds32_regsets[] = { .n = sizeof(struct user_pt_regs) / sizeof(u32), .size = sizeof(elf_greg_t), .align = sizeof(elf_greg_t), - .get = gpr_get, + .get2 = gpr_get, .set = gpr_set} };
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 36/41 parisc: switch to ->get2()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- arch/parisc/kernel/ptrace.c | 84 +++++++++------------------------------------ 1 file changed, 16 insertions(+), 68 deletions(-)
arch/parisc/kernel/ptrace.c +16 -68
@@ -391,31 +391,11 @@ void do_syscall_trace_exit(struct pt_regs *regs)static int fpr_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) {struct pt_regs *regs =task_regs (target); -__u64 *k = kbuf; -__u64 __user *u = ubuf; -__u64 reg; - - pos /=sizeof (reg); - count /=sizeof (reg); - -if (kbuf) -for (; count >0 && pos <ELF_NFPREG ; --count) - *k++ = regs->fr[pos++]; -else -for (; count >0 && pos <ELF_NFPREG ; --count) -if (__put_user (regs->fr[pos++], u++)) -return -EFAULT ; - kbuf = k; - ubuf = u; - pos *=sizeof (reg); - count *=sizeof (reg); -return user_regset_copyout_zero (&pos, &count, &kbuf, &ubuf, -ELF_NFPREG *sizeof (reg),-1 ); +return membuf_write (&to, regs->fr,ELF_NFPREG *sizeof (__u64)); } static int fpr_set(struct task_struct *target,
@@ -527,30 +507,14 @@ static void set_reg(struct pt_regs *regs, int num, unsigned long val)static int gpr_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) {struct pt_regs *regs =task_regs (target); -unsigned long *k = kbuf; -unsigned long __user *u = ubuf; -unsigned long reg; +unsigned int pos; - pos /=sizeof (reg); - count /=sizeof (reg); - -if (kbuf) -for (; count >0 && pos <ELF_NGREG ; --count) - *k++ =get_reg (regs, pos++); -else -for (; count >0 && pos <ELF_NGREG ; --count) -if (__put_user (get_reg (regs, pos++), u++)) -return -EFAULT ; - kbuf = k; - ubuf = u; - pos *=sizeof (reg); - count *=sizeof (reg); -return user_regset_copyout_zero (&pos, &count, &kbuf, &ubuf, -ELF_NGREG *sizeof (reg),-1 ); +for (pos =0 ; pos <ELF_NGREG ; pos++) +membuf_store (&to,get_reg (regs, pos)); +return 0 ; } static int gpr_set(struct task_struct *target,
@@ -588,12 +552,12 @@ static const struct user_regset native_regsets[] = { [REGSET_GENERAL ] = { .core_note_type =NT_PRSTATUS , .n =ELF_NGREG , .size =sizeof (long ), .align =sizeof (long ), - .get = gpr_get, .set = gpr_set + .get2 = gpr_get, .set = gpr_set }, [REGSET_FP ] = { .core_note_type =NT_PRFPREG , .n =ELF_NFPREG , .size =sizeof (__u64), .align =sizeof (__u64), - .get = fpr_get, .set = fpr_set + .get2 = fpr_get, .set = fpr_set } };
@@ -607,31 +571,15 @@ static const struct user_regset_view user_parisc_native_view = {static int gpr32_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) {struct pt_regs *regs =task_regs (target); -compat_ulong_t *k = kbuf; -compat_ulong_t __user *u = ubuf; -compat_ulong_t reg; +unsigned int pos; - pos /=sizeof (reg); - count /=sizeof (reg); +for (pos =0 ; pos <ELF_NGREG ; pos++) +membuf_store (&to, (compat_ulong_t )get_reg (regs, pos)); -if (kbuf) -for (; count >0 && pos <ELF_NGREG ; --count) - *k++ =get_reg (regs, pos++); -else -for (; count >0 && pos <ELF_NGREG ; --count) -if (__put_user ((compat_ulong_t )get_reg (regs, pos++), u++)) -return -EFAULT ; - - kbuf = k; - ubuf = u; - pos *=sizeof (reg); - count *=sizeof (reg); -return user_regset_copyout_zero (&pos, &count, &kbuf, &ubuf, -ELF_NGREG *sizeof (reg),-1 ); +return 0 ; } static int gpr32_set(struct task_struct *target,
@@ -672,12 +620,12 @@ static const struct user_regset compat_regsets[] = { [REGSET_GENERAL ] = { .core_note_type =NT_PRSTATUS , .n =ELF_NGREG , .size =sizeof (compat_long_t), .align =sizeof (compat_long_t), - .get = gpr32_get, .set = gpr32_set + .get2 = gpr32_get, .set = gpr32_set }, [REGSET_FP ] = { .core_note_type =NT_PRFPREG , .n =ELF_NFPREG , .size =sizeof (__u64), .align =sizeof (__u64), - .get = fpr_get, .set = fpr_set + .get2 = fpr_get, .set = fpr_set } };
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 37/41 xtensa: switch to ->get2()
In reply to Al ViroFrom: Al Viro <[email protected]>
--- arch/xtensa/kernel/ptrace.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
arch/xtensa/kernel/ptrace.c +6 -10
@@ -37,8 +37,7 @@static int gpr_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) {struct pt_regs *regs =task_pt_regs (target);struct user_pt_regs newregs = {
@@ -60,8 +59,7 @@ static int gpr_get(struct task_struct *target, regs->areg, (WSBITS - regs->windowbase) * 16); -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, - &newregs,0 ,-1 ); +return membuf_write (&to, &newregs,sizeof (newregs)); } static int gpr_set(struct task_struct *target,
@@ -115,8 +113,7 @@ static int gpr_set(struct task_struct *target,static int tie_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) {int ret;struct pt_regs *regs =task_pt_regs (target);
@@ -141,8 +138,7 @@ static int tie_get(struct task_struct *target, newregs->cp6 = ti->xtregs_cp.cp6; newregs->cp7 = ti->xtregs_cp.cp7;#endif - ret =user_regset_copyout (&pos, &count, &kbuf, &ubuf, - newregs,0 ,-1 ); + ret =membuf_write (&to, newregs,sizeof (*newregs));kfree (newregs);return ret; }
@@ -197,7 +193,7 @@ static const struct user_regset xtensa_regsets[] = { .n = sizeof(struct user_pt_regs) / sizeof(u32), .size = sizeof(u32), .align = sizeof(u32), - .get = gpr_get, + .get2 = gpr_get, .set = gpr_set, }, [REGSET_TIE] = {
@@ -205,7 +201,7 @@ static const struct user_regset xtensa_regsets[] = { .n = sizeof(elf_xtregs_t) / sizeof(u32), .size = sizeof(u32), .align = sizeof(u32), - .get = tie_get, + .get2 = tie_get, .set = tie_set, }, };
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 38/41 csky: switch to ->get2()
In reply to Al ViroFrom: Al Viro <[email protected]>
NB: WTF is fpregs_get() playing at???
--- arch/csky/kernel/ptrace.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-)
arch/csky/kernel/ptrace.c +10 -14
@@ -76,17 +76,14 @@ enum csky_regset {static int gpr_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) { -struct pt_regs *regs; - - regs =task_pt_regs (target); +struct pt_regs *regs =task_pt_regs (target);/* Abiv1 regs->tls is fake and we need sync here. */ regs->tls =task_thread_info (target)->tp_value; -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, regs,0 ,-1 ); +return membuf_write (&to, regs,sizeof (regs)); } static int gpr_set(struct task_struct *target,
@@ -114,8 +111,7 @@ static int gpr_set(struct task_struct *target,static int fpr_get (struct task_struct *target,const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf) +struct membuf to) {struct user_fp *regs = (struct user_fp *)&target->thread.user_fp;
@@ -131,9 +127,9 @@ static int fpr_get(struct task_struct *target,for (i =0 ; i <32 ; i++) tmp.vr[64 + i] = regs->vr[32 + i]; -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, &tmp,0 ,-1 ); +return membuf_write (&to, &tmp,sizeof (tmp));#else -return user_regset_copyout (&pos, &count, &kbuf, &ubuf, regs,0 ,-1 ); +return membuf_write (&to, regs,sizeof (*regs));#endif }
@@ -173,16 +169,16 @@ static const struct user_regset csky_regsets[] = { .n = sizeof(struct pt_regs) / sizeof(u32), .size = sizeof(u32), .align = sizeof(u32), - .get = &gpr_get, - .set = &gpr_set, + .get2 = gpr_get, + .set = gpr_set, }, [REGSET_FPR] = { .core_note_type = NT_PRFPREG, .n = sizeof(struct user_fp) / sizeof(u32), .size = sizeof(u32), .align = sizeof(u32), - .get = &fpr_get, - .set = &fpr_set, + .get2 = fpr_get, + .set = fpr_set, }, };
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 39/41 regset: kill ->get()
In reply to Al ViroFrom: Al Viro <[email protected]>
no instances left
--- include/linux/regset.h | 22 ---------------------- kernel/regset.c | 24 +++++------------------- 2 files changed, 5 insertions(+), 41 deletions(-)
include/linux/regset.h +0 -22
@@ -82,27 +82,6 @@ static inline int membuf_write(struct membuf *s, const void *v, size_t size)typedef int user_regset_active_fn (struct task_struct *target,const struct user_regset *regset); -/** -* user_regset_get_fn - type of @get function in &struct user_regset -* @target: thread being examined -* @regset: regset being examined -* @pos: offset into the regset data to access, in bytes -* @count: amount of data to copy, in bytes -* @kbuf: if not %NULL, a kernel-space pointer to copy into -* @ubuf: if @kbuf is %NULL, a user-space pointer to copy into -* -* Fetch register values. Return %0 on success; -%EIO or -%ENODEV -* are usual failure returns. The @pos and @count values are in -* bytes, but must be properly aligned. If @kbuf is non-null, that -* buffer is used and @ubuf is ignored. If @kbuf is %NULL, then -* ubuf gives a userland pointer to access directly, and an -%EFAULT -* return value is possible. -*/ -typedef int user_regset_get_fn (struct task_struct *target, -const struct user_regset *regset, -unsigned int pos,unsigned int count, -void *kbuf,void __user *ubuf); -typedef int user_regset_get2_fn (struct task_struct *target,const struct user_regset *regset,struct membuf to);
@@ -235,7 +214,6 @@ typedef unsigned int user_regset_get_size_fn(struct task_struct *target,* omitted when there is an @active function and it returns zero. */ struct user_regset { -user_regset_get_fn *get;user_regset_get2_fn *get2;user_regset_set_fn *set;user_regset_active_fn *active;
kernel/regset.c +5 -19
@@ -11,7 +11,7 @@ static int __regset_get(struct task_struct *target,void *p = *data, *to_free =NULL ;int res; -if (!regset->get && !regset->get2) +if (!regset->get2)return -EOPNOTSUPP ;if (size > regset->n * regset->size) size = regset->n * regset->size;
@@ -20,28 +20,14 @@ static int __regset_get(struct task_struct *target,if (!p)return -ENOMEM ; } -if (regset->get2) { - res = regset->get2 (target, regset, - (struct membuf ){.p = p, .left = size}); -if (res <0 ) { -kfree (to_free); -return res; - } - *data = p; -return size - res; - } - res = regset->get (target, regset,0 , size, p,NULL ); -if (unlikely (res <0 )) { + res = regset->get2 (target, regset, + (struct membuf ){.p = p, .left = size}); +if (res <0 ) {kfree (to_free);return res; } *data = p; -if (regset->get_size) {// arm64-only kludge, will go away -unsigned max_size = regset->get_size (target, regset); -if (size > max_size) - size = max_size; - } -return size; +return size - res; } int regset_get(struct task_struct *target,
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 40/41 regset(): kill ->get_size()
In reply to Al ViroFrom: Al Viro <[email protected]>
not used anymore
--- arch/arm64/kernel/ptrace.c | 13 ------------- include/linux/regset.h | 48 +--------------------------------------------- 2 files changed, 1 insertion(+), 60 deletions(-)
arch/arm64/kernel/ptrace.c +0 -13
@@ -740,18 +740,6 @@ static unsigned int sve_size_from_header(struct user_sve_header const *header)return ALIGN (header->size,SVE_VQ_BYTES ); } -static unsigned int sve_get_size (struct task_struct *target, -const struct user_regset *regset) -{ -struct user_sve_header header; - -if (!system_supports_sve ()) -return 0 ; - -sve_init_header_from_task (&header, target); -return sve_size_from_header (&header); -} -static int sve_get (struct task_struct *target,const struct user_regset *regset,struct membuf to)
@@ -1130,7 +1118,6 @@ static const struct user_regset aarch64_regsets[] = { .align = SVE_VQ_BYTES, .get2 = sve_get, .set = sve_set, - .get_size = sve_get_size, },#endif #ifdef CONFIG_ARM64_PTR_AUTH
include/linux/regset.h +1 -47
76 lines not on this page · raw message
Signature · 1 line
2.11.0
Al Viro
maintainerPATCH 41/41 regset: kill user_regset_copyout{,_zero}()
In reply to Al ViroFrom: Al Viro <[email protected]>
no callers left
--- include/linux/regset.h | 67 -------------------------------------------------- 1 file changed, 67 deletions(-)
include/linux/regset.h +0 -67
@@ -238,44 +238,6 @@ struct user_regset_view {*/ const struct user_regset_view *task_user_regset_view (struct task_struct *tsk); - -/* -* These are helpers for writing regset get/set functions in arch code. -* Because @start_pos and @end_pos are always compile-time constants, -* these are inlined into very little code though they look large. -* -* Use one or more calls sequentially for each chunk of regset data stored -* contiguously in memory. Call with constants for @start_pos and @end_pos, -* giving the range of byte positions in the regset that data corresponds -* to; @end_pos can be -1 if this chunk is at the end of the regset layout. -* Each call updates the arguments to point past its chunk. -*/ - -static inline int user_regset_copyout (unsigned int *pos,unsigned int *count, -void **kbuf, -void __user **ubuf,const void *data, -const int start_pos,const int end_pos) -{ -if (*count ==0 ) -return 0 ; -BUG_ON (*pos < start_pos); -if (end_pos <0 || *pos < end_pos) { -unsigned int copy = (end_pos <0 ? *count - :min (*count, end_pos - *pos)); - data += *pos - start_pos; -if (*kbuf) { -memcpy (*kbuf, data, copy); - *kbuf += copy; - }else if (__copy_to_user (*ubuf, data, copy)) -return -EFAULT ; -else - *ubuf += copy; - *pos += copy; - *count -= copy; - } -return 0 ; -} - static inline int user_regset_copyin(unsigned int *pos, unsigned int *count, const void **kbuf, const void __user **ubuf, void *data,
@@ -301,35 +263,6 @@ static inline int user_regset_copyin(unsigned int *pos, unsigned int *count,return 0 ; } -/* -* These two parallel the two above, but for portions of a regset layout -* that always read as all-zero or for which writes are ignored. -*/ -static inline int user_regset_copyout_zero (unsigned int *pos, -unsigned int *count, -void **kbuf,void __user **ubuf, -const int start_pos, -const int end_pos) -{ -if (*count ==0 ) -return 0 ; -BUG_ON (*pos < start_pos); -if (end_pos <0 || *pos < end_pos) { -unsigned int copy = (end_pos <0 ? *count - :min (*count, end_pos - *pos)); -if (*kbuf) { -memset (*kbuf,0 , copy); - *kbuf += copy; - }else if (clear_user (*ubuf, copy)) -return -EFAULT ; -else - *ubuf += copy; - *pos += copy; - *count -= copy; - } -return 0 ; -} - static inline int user_regset_copyin_ignore(unsigned int *pos, unsigned int *count, const void **kbuf,
Signature · 1 line
2.11.0
Hi Al,
what's the state of the series? I noticed it hasn't shown up in linux-next so far.
Al Viro
maintainerQuoted 4 lines · Christoph Hellwig
Hi Al,
what's the state of the series? I noticed it hasn't shown up in linux-next so far.
It (as well as fdpic coredump stuff) will go into -next as soon as I post the second variant of csum_and_copy stuff (later today).