powerpc/ptrace: Convert gpr32_set_common_user() to scoped user access

Commit 861574d51b ("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>
Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com>
Link: https://patch.msgid.link/2409643daab08b4bc07004c2b88f42085d1ef45a.1773136838.git.chleroy@kernel.org
This commit is contained in:
Christophe Leroy (CS GROUP)
2026-03-10 11:00:53 +01:00
committed by Madhavan Srinivasan
parent 40a1b9d044
commit 679fa9c756

View File

@@ -758,39 +758,38 @@ 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;
scoped_user_read_access_size(ubuf, count, efault) {
u = ubuf;
pos /= sizeof(reg);
count /= sizeof(reg);
pos /= sizeof(reg);
count /= sizeof(reg);
for (; count > 0 && pos < PT_MSR; --count) {
unsafe_get_user(reg, u++, efault);
regs[pos++] = 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;
}
}
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);
count *= 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;
}