From: Al Viro <viro@ZenIV.linux.org.uk>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org,
David Miller <davem@davemloft.net>,
Tony Luck <tony.luck@intel.com>, Will Deacon <will@kernel.org>
Subject: [PATCH 10/41] sparc32: get rid of odd callers of copy_regset_to_user()
Date: Mon, 29 Jun 2020 19:25:57 +0100 [thread overview]
Message-ID: <20200629182628.529995-10-viro@ZenIV.linux.org.uk> (raw)
In-Reply-To: <20200629182628.529995-1-viro@ZenIV.linux.org.uk>
From: Al Viro <viro@zeniv.linux.org.uk>
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...
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
arch/sparc/kernel/ptrace_32.c | 117 +++++++++++++++++++++++++++++-------------
1 file changed, 82 insertions(+), 35 deletions(-)
diff --git a/arch/sparc/kernel/ptrace_32.c b/arch/sparc/kernel/ptrace_32.c
index 47eb315d411c..f72b7d2c4716 100644
--- a/arch/sparc/kernel/ptrace_32.c
+++ b/arch/sparc/kernel/ptrace_32.c
@@ -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;
}
--
2.11.0
next prev parent reply other threads:[~2020-06-29 21:28 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-29 18:23 [RFC][PATCHSET] regset ->get() rework Al Viro
2020-06-29 18:25 ` [PATCH 01/41] introduction of regset ->get() wrappers, switching ELF coredumps to those Al Viro
2020-06-29 18:25 ` [PATCH 02/41] x86: copy_fpstate_to_sigframe(): have fpregs_soft_get() use kernel buffer Al Viro
2020-06-29 18:25 ` [PATCH 03/41] x86: kill dump_fpu() Al Viro
2020-06-29 18:25 ` [PATCH 04/41] [ia64] sanitize elf_access_gpreg() Al Viro
2020-06-29 18:25 ` [PATCH 05/41] [ia64] teach elf_access_reg() to handle the missing range (r16..r31) Al Viro
2020-06-29 18:25 ` [PATCH 06/41] [ia64] regularize do_gpregs_[gs]et() Al Viro
2020-06-29 18:25 ` [PATCH 07/41] [ia64] access_uarea(): stop bothering with gpregs_[gs]et() Al Viro
2020-06-29 18:25 ` [PATCH 08/41] [ia64] access_uarea(): don't bother with fpregs_[gs]et() Al Viro
2020-06-29 18:25 ` [PATCH 09/41] sparc64: switch genregs32_get() to use of get_from_target() Al Viro
2020-06-29 18:25 ` Al Viro [this message]
2020-06-29 18:25 ` [PATCH 11/41] sparc64: get rid of odd callers of copy_regset_to_user() Al Viro
2020-06-29 18:25 ` [PATCH 12/41] sparc32: get rid of odd callers of copy_regset_from_user() Al Viro
2020-06-29 18:26 ` [PATCH 13/41] sparc64: " Al Viro
2020-06-29 18:26 ` [PATCH 14/41] arm64: take fetching compat reg out of pt_regs into a new helper Al Viro
2020-06-29 18:26 ` [PATCH 15/41] arm64: get rid of copy_regset_to_user() in compat_ptrace_read_user() Al Viro
2020-06-29 18:26 ` [PATCH 16/41] arm64: sanitize compat_ptrace_write_user() Al Viro
2020-06-29 18:26 ` [PATCH 17/41] copy_regset_to_user(): do all copyout at once Al Viro
2020-06-29 18:26 ` [PATCH 18/41] regset: new method and helpers for it Al Viro
2020-06-29 19:23 ` Linus Torvalds
2020-06-29 20:30 ` Al Viro
2020-06-30 13:25 ` Al Viro
2020-06-30 16:53 ` Linus Torvalds
2020-06-30 19:40 ` Al Viro
2020-06-29 18:26 ` [PATCH 19/41] x86: switch to ->get2() Al Viro
2020-06-29 18:26 ` [PATCH 20/41] powerpc: " Al Viro
2020-06-29 18:26 ` [PATCH 21/41] s390: " Al Viro
2020-06-29 18:26 ` [PATCH 22/41] sparc: " Al Viro
2020-06-30 13:16 ` Al Viro
2020-06-29 18:26 ` [PATCH 23/41] mips: " Al Viro
2020-06-29 18:26 ` [PATCH 24/41] arm64: " Al Viro
2020-06-29 18:26 ` [PATCH 25/41] sh: convert " Al Viro
2020-06-29 18:26 ` [PATCH 26/41] arm: switch " Al Viro
2020-06-29 18:26 ` [PATCH 27/41] arc: " Al Viro
2020-06-29 18:26 ` [PATCH 28/41] ia64: " Al Viro
2020-06-29 18:26 ` [PATCH 29/41] c6x: " Al Viro
2020-06-29 18:26 ` [PATCH 30/41] riscv: " Al Viro
2020-06-29 18:26 ` [PATCH 31/41] openrisc: " Al Viro
2020-06-29 18:26 ` [PATCH 32/41] h8300: " Al Viro
2020-06-29 18:26 ` [PATCH 33/41] hexagon: " Al Viro
2020-08-11 18:35 ` Brian Cain
2020-06-29 18:26 ` [PATCH 34/41] nios2: " Al Viro
2020-06-29 18:26 ` [PATCH 35/41] nds32: " Al Viro
2020-06-29 18:26 ` [PATCH 36/41] parisc: " Al Viro
2020-06-29 18:26 ` [PATCH 37/41] xtensa: " Al Viro
2020-06-29 18:26 ` [PATCH 38/41] csky: " Al Viro
2020-06-29 18:26 ` [PATCH 39/41] regset: kill ->get() Al Viro
2020-06-29 18:26 ` [PATCH 40/41] regset(): kill ->get_size() Al Viro
2020-06-29 18:26 ` [PATCH 41/41] regset: kill user_regset_copyout{,_zero}() Al Viro
2020-07-23 8:00 ` [RFC][PATCHSET] regset ->get() rework Christoph Hellwig
2020-07-23 17:27 ` Al Viro
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200629182628.529995-10-viro@ZenIV.linux.org.uk \
--to=viro@zeniv.linux.org.uk \
--cc=davem@davemloft.net \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tony.luck@intel.com \
--cc=torvalds@linux-foundation.org \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).