* [PATCH] powerpc/ptrace: Convert gpr32_set_common_user() to scoped user access
@ 2026-03-10 10:00 Christophe Leroy (CS GROUP)
2026-04-08 4:28 ` Madhavan Srinivasan
0 siblings, 1 reply; 2+ messages in thread
From: Christophe Leroy (CS GROUP) @ 2026-03-10 10:00 UTC (permalink / raw)
To: Michael Ellerman, Nicholas Piggin, Madhavan Srinivasan
Cc: Christophe Leroy (CS GROUP), linux-kernel, linuxppc-dev
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] powerpc/ptrace: Convert gpr32_set_common_user() to scoped user access
2026-03-10 10:00 [PATCH] powerpc/ptrace: Convert gpr32_set_common_user() to scoped user access Christophe Leroy (CS GROUP)
@ 2026-04-08 4:28 ` Madhavan Srinivasan
0 siblings, 0 replies; 2+ messages in thread
From: Madhavan Srinivasan @ 2026-04-08 4:28 UTC (permalink / raw)
To: Michael Ellerman, Nicholas Piggin, Christophe Leroy (CS GROUP)
Cc: linux-kernel, linuxppc-dev
On Tue, 10 Mar 2026 11:00:53 +0100, Christophe Leroy (CS GROUP) wrote:
> 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.
>
> [...]
Applied to powerpc/next.
[1/1] powerpc/ptrace: Convert gpr32_set_common_user() to scoped user access
https://git.kernel.org/powerpc/c/679fa9c756c7d6fcb6ae611f695d286c53dca076
cheers
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-04-08 4:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-10 10:00 [PATCH] powerpc/ptrace: Convert gpr32_set_common_user() to scoped user access Christophe Leroy (CS GROUP)
2026-04-08 4:28 ` Madhavan Srinivasan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox