From: "Christophe Leroy (CS GROUP)" <chleroy@kernel.org>
To: Michael Ellerman <mpe@ellerman.id.au>,
Nicholas Piggin <npiggin@gmail.com>,
Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: "Christophe Leroy (CS GROUP)" <chleroy@kernel.org>,
linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org
Subject: [PATCH] powerpc/ptrace: Convert gpr32_set_common_user() to scoped user access
Date: Tue, 10 Mar 2026 11:00:53 +0100 [thread overview]
Message-ID: <2409643daab08b4bc07004c2b88f42085d1ef45a.1773136838.git.chleroy@kernel.org> (raw)
Commit 861574d51bbd ("powerpc/uaccess: Implement masked user access")
provides optimised user access by avoiding the cost of access_ok().
Convert gpr32_set_common_user() to scoped user access to benefit
from masked user access.
Scoped user access also make the code simpler.
Also changes label from Efault to efault to avoid checkpatch
complaining about CamelCase.
Signed-off-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
---
This patch applies on top of v7.0-rc3, it requires commit af4e9ef3d784 ("uaccess: Fix scoped_user_read_access() for 'pointer to const'")
---
arch/powerpc/kernel/ptrace/ptrace-view.c | 64 ++++++++++++------------
1 file changed, 31 insertions(+), 33 deletions(-)
diff --git a/arch/powerpc/kernel/ptrace/ptrace-view.c b/arch/powerpc/kernel/ptrace/ptrace-view.c
index 0310f9097e39..eb5f2091bb59 100644
--- a/arch/powerpc/kernel/ptrace/ptrace-view.c
+++ b/arch/powerpc/kernel/ptrace/ptrace-view.c
@@ -758,38 +758,37 @@ static int gpr32_set_common_user(struct task_struct *target,
const void *kbuf = NULL;
compat_ulong_t reg;
- if (!user_read_access_begin(u, count))
- return -EFAULT;
-
- pos /= sizeof(reg);
- count /= sizeof(reg);
-
- for (; count > 0 && pos < PT_MSR; --count) {
- unsafe_get_user(reg, u++, Efault);
- regs[pos++] = reg;
- }
-
- if (count > 0 && pos == PT_MSR) {
- unsafe_get_user(reg, u++, Efault);
- set_user_msr(target, reg);
- ++pos;
- --count;
- }
-
- for (; count > 0 && pos <= PT_MAX_PUT_REG; --count) {
- unsafe_get_user(reg, u++, Efault);
- regs[pos++] = reg;
- }
- for (; count > 0 && pos < PT_TRAP; --count, ++pos)
- unsafe_get_user(reg, u++, Efault);
-
- if (count > 0 && pos == PT_TRAP) {
- unsafe_get_user(reg, u++, Efault);
- set_user_trap(target, reg);
- ++pos;
- --count;
+ scoped_user_read_access_size(ubuf, count, efault) {
+ u = ubuf;
+ pos /= sizeof(reg);
+ count /= sizeof(reg);
+
+ for (; count > 0 && pos < PT_MSR; --count) {
+ unsafe_get_user(reg, u++, efault);
+ regs[pos++] = reg;
+ }
+
+ if (count > 0 && pos == PT_MSR) {
+ unsafe_get_user(reg, u++, efault);
+ set_user_msr(target, reg);
+ ++pos;
+ --count;
+ }
+
+ for (; count > 0 && pos <= PT_MAX_PUT_REG; --count) {
+ unsafe_get_user(reg, u++, efault);
+ regs[pos++] = reg;
+ }
+ for (; count > 0 && pos < PT_TRAP; --count, ++pos)
+ unsafe_get_user(reg, u++, efault);
+
+ if (count > 0 && pos == PT_TRAP) {
+ unsafe_get_user(reg, u++, efault);
+ set_user_trap(target, reg);
+ ++pos;
+ --count;
+ }
}
- user_read_access_end();
ubuf = u;
pos *= sizeof(reg);
@@ -798,8 +797,7 @@ static int gpr32_set_common_user(struct task_struct *target,
(PT_TRAP + 1) * sizeof(reg), -1);
return 0;
-Efault:
- user_read_access_end();
+efault:
return -EFAULT;
}
--
2.49.0
next reply other threads:[~2026-03-10 10:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-10 10:00 Christophe Leroy (CS GROUP) [this message]
2026-04-08 4:28 ` [PATCH] powerpc/ptrace: Convert gpr32_set_common_user() to scoped user access Madhavan Srinivasan
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=2409643daab08b4bc07004c2b88f42085d1ef45a.1773136838.git.chleroy@kernel.org \
--to=chleroy@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=mpe@ellerman.id.au \
--cc=npiggin@gmail.com \
/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