From nobody Thu Apr 9 07:18:08 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C4BBE24E4B4 for ; Tue, 10 Mar 2026 10:01:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773136861; cv=none; b=Tnce6/CdXUfB/f8nVMvY27HuRuWp74v9a2idxAqaSLqfooRZBYi8OLjeN91yEyuW1lr9OpDzO+IRwy7jsF9luDX60mtp2QO33O431XG8AS4N75jDa1u/mkXXVFF2t+ZQLhTmGvXHboT55knOrQllpK1Yrkd4gq2+gtgqXM14XpE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773136861; c=relaxed/simple; bh=yMp5vTyT2e6ZkOlPwYQ0o7+Oylg3y9LZSAfa9XFNRJg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ZSGCnojiXkJnQhhZnzTmuC1IPm/p2EGoaa8UEueLFnn1kP/77jtzYlTuCyJVjleXrkAuuXGQOFQA6IYyBChZLeA8b1Rbq8QRSxejn1ALfsmSfzLHOcrB2aW7ROHg16ONoOOBBiFSHgqTii8ILmCLmDnWDLXXvFWKHWgvIgtI2qs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EznNiFNZ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EznNiFNZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05CE7C19423; Tue, 10 Mar 2026 10:00:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773136861; bh=yMp5vTyT2e6ZkOlPwYQ0o7+Oylg3y9LZSAfa9XFNRJg=; h=From:To:Cc:Subject:Date:From; b=EznNiFNZ4phD4Eqz+YA9FN+hZJOYF4tc/OTkLdk/5OYGZUSdNJ62OIANvWoibC2li 0QpyNJ4Wyx9H9WsQ5m6P8JKzmFG+ichxhPtjlktmZ6AKPwSr6IZgjYd30N+zUnv3n/ P4UsXpAp1jdh9wTDOaMTbg7pSwjoENfQ7Wu1LN5tvkT/Qyq2MppVs6V674cZzAP7Uw T8ltJSFTJIPXJHL5h0MhyUk1ks3LsDW+XTn79jSQHqdC/y09WLYTKRqU6H+IfWnI6a iWckwNyCCp5r7P+3MKx3eGoGirzW8hQGm4j4+LZWTmhRxBnx4ICSCCXruley1J5UwP B7Rl5bOuZtArg== From: "Christophe Leroy (CS GROUP)" To: Michael Ellerman , Nicholas Piggin , Madhavan Srinivasan Cc: "Christophe Leroy (CS GROUP)" , 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 Message-ID: <2409643daab08b4bc07004c2b88f42085d1ef45a.1773136838.git.chleroy@kernel.org> X-Mailer: git-send-email 2.49.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2875; i=chleroy@kernel.org; h=from:subject:message-id; bh=yMp5vTyT2e6ZkOlPwYQ0o7+Oylg3y9LZSAfa9XFNRJg=; b=owGbwMvMwCV2d0KB2p7V54MZT6slMWSuf33tv1KUVQmDkP3Xii1XXA6r50hpqnWx/HohJZPHk HpP9+CRjlIWBjEuBlkxRZbj/7l3zej6kpo/dZc+zBxWJpAhDFycAjARWWGGv6KTfl16Hraz/dOp et9Qtp1W8w2vfWfziThz/YzYao2LX/0Z/qmIvKn97HA++8WnSGdFIc59X7lLSu/lfvp5RKAn6pP rfn4A X-Developer-Key: i=chleroy@kernel.org; a=openpgp; fpr=10FFE6F8B390DE17ACC2632368A92FEB01B8DD78 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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) --- This patch applies on top of v7.0-rc3, it requires commit af4e9ef3d784 ("ua= ccess: 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 =3D NULL; compat_ulong_t reg; =20 - if (!user_read_access_begin(u, count)) - return -EFAULT; - - pos /=3D sizeof(reg); - count /=3D sizeof(reg); - - for (; count > 0 && pos < PT_MSR; --count) { - unsafe_get_user(reg, u++, Efault); - regs[pos++] =3D reg; - } - - if (count > 0 && pos =3D=3D PT_MSR) { - unsafe_get_user(reg, u++, Efault); - set_user_msr(target, reg); - ++pos; - --count; - } - - for (; count > 0 && pos <=3D PT_MAX_PUT_REG; --count) { - unsafe_get_user(reg, u++, Efault); - regs[pos++] =3D reg; - } - for (; count > 0 && pos < PT_TRAP; --count, ++pos) - unsafe_get_user(reg, u++, Efault); - - if (count > 0 && pos =3D=3D PT_TRAP) { - unsafe_get_user(reg, u++, Efault); - set_user_trap(target, reg); - ++pos; - --count; + scoped_user_read_access_size(ubuf, count, efault) { + u =3D ubuf; + pos /=3D sizeof(reg); + count /=3D sizeof(reg); + + for (; count > 0 && pos < PT_MSR; --count) { + unsafe_get_user(reg, u++, efault); + regs[pos++] =3D reg; + } + + if (count > 0 && pos =3D=3D PT_MSR) { + unsafe_get_user(reg, u++, efault); + set_user_msr(target, reg); + ++pos; + --count; + } + + for (; count > 0 && pos <=3D PT_MAX_PUT_REG; --count) { + unsafe_get_user(reg, u++, efault); + regs[pos++] =3D reg; + } + for (; count > 0 && pos < PT_TRAP; --count, ++pos) + unsafe_get_user(reg, u++, efault); + + if (count > 0 && pos =3D=3D PT_TRAP) { + unsafe_get_user(reg, u++, efault); + set_user_trap(target, reg); + ++pos; + --count; + } } - user_read_access_end(); =20 ubuf =3D u; pos *=3D sizeof(reg); @@ -798,8 +797,7 @@ static int gpr32_set_common_user(struct task_struct *ta= rget, (PT_TRAP + 1) * sizeof(reg), -1); return 0; =20 -Efault: - user_read_access_end(); +efault: return -EFAULT; } =20 --=20 2.49.0