arch/powerpc/kernel/ptrace/ptrace-view.c | 64 ++++++++++++------------ 1 file changed, 31 insertions(+), 33 deletions(-)
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
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
© 2016 - 2026 Red Hat, Inc.