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/align: Convert emulate_spe() to scoped user access
Date: Tue, 10 Mar 2026 11:01:31 +0100 [thread overview]
Message-ID: <4ff83cb240da4e2d0c34e2bce4b8b6ef19a33777.1773136880.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 emulate_spe() to scoped user access to benefit from masked
user access.
Scoped user access also make the code simpler.
Signed-off-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
---
arch/powerpc/kernel/align.c | 75 ++++++++++++++++---------------------
1 file changed, 33 insertions(+), 42 deletions(-)
diff --git a/arch/powerpc/kernel/align.c b/arch/powerpc/kernel/align.c
index 3e37ece06739..61409431138f 100644
--- a/arch/powerpc/kernel/align.c
+++ b/arch/powerpc/kernel/align.c
@@ -165,25 +165,23 @@ static int emulate_spe(struct pt_regs *regs, unsigned int reg,
temp.ll = data.ll = 0;
p = addr;
- if (!user_read_access_begin(addr, nb))
- return -EFAULT;
-
- switch (nb) {
- case 8:
- unsafe_get_user(temp.v[0], p++, Efault_read);
- unsafe_get_user(temp.v[1], p++, Efault_read);
- unsafe_get_user(temp.v[2], p++, Efault_read);
- unsafe_get_user(temp.v[3], p++, Efault_read);
- fallthrough;
- case 4:
- unsafe_get_user(temp.v[4], p++, Efault_read);
- unsafe_get_user(temp.v[5], p++, Efault_read);
- fallthrough;
- case 2:
- unsafe_get_user(temp.v[6], p++, Efault_read);
- unsafe_get_user(temp.v[7], p++, Efault_read);
+ scoped_user_read_access_size(addr, nb, efault) {
+ switch (nb) {
+ case 8:
+ unsafe_get_user(temp.v[0], p++, efault);
+ unsafe_get_user(temp.v[1], p++, efault);
+ unsafe_get_user(temp.v[2], p++, efault);
+ unsafe_get_user(temp.v[3], p++, efault);
+ fallthrough;
+ case 4:
+ unsafe_get_user(temp.v[4], p++, efault);
+ unsafe_get_user(temp.v[5], p++, efault);
+ fallthrough;
+ case 2:
+ unsafe_get_user(temp.v[6], p++, efault);
+ unsafe_get_user(temp.v[7], p++, efault);
+ }
}
- user_read_access_end();
switch (instr) {
case EVLDD:
@@ -252,25 +250,23 @@ static int emulate_spe(struct pt_regs *regs, unsigned int reg,
if (flags & ST) {
p = addr;
- if (!user_write_access_begin(addr, nb))
- return -EFAULT;
-
- switch (nb) {
- case 8:
- unsafe_put_user(data.v[0], p++, Efault_write);
- unsafe_put_user(data.v[1], p++, Efault_write);
- unsafe_put_user(data.v[2], p++, Efault_write);
- unsafe_put_user(data.v[3], p++, Efault_write);
- fallthrough;
- case 4:
- unsafe_put_user(data.v[4], p++, Efault_write);
- unsafe_put_user(data.v[5], p++, Efault_write);
- fallthrough;
- case 2:
- unsafe_put_user(data.v[6], p++, Efault_write);
- unsafe_put_user(data.v[7], p++, Efault_write);
+ scoped_user_write_access_size(addr, nb, efault) {
+ switch (nb) {
+ case 8:
+ unsafe_put_user(data.v[0], p++, efault);
+ unsafe_put_user(data.v[1], p++, efault);
+ unsafe_put_user(data.v[2], p++, efault);
+ unsafe_put_user(data.v[3], p++, efault);
+ fallthrough;
+ case 4:
+ unsafe_put_user(data.v[4], p++, efault);
+ unsafe_put_user(data.v[5], p++, efault);
+ fallthrough;
+ case 2:
+ unsafe_put_user(data.v[6], p++, efault);
+ unsafe_put_user(data.v[7], p++, efault);
+ }
}
- user_write_access_end();
} else {
*evr = data.w[0];
regs->gpr[reg] = data.w[1];
@@ -278,12 +274,7 @@ static int emulate_spe(struct pt_regs *regs, unsigned int reg,
return 1;
-Efault_read:
- user_read_access_end();
- return -EFAULT;
-
-Efault_write:
- user_write_access_end();
+efault:
return -EFAULT;
}
#endif /* CONFIG_SPE */
--
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:01 Christophe Leroy (CS GROUP) [this message]
2026-04-08 4:28 ` [PATCH] powerpc/align: Convert emulate_spe() 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=4ff83cb240da4e2d0c34e2bce4b8b6ef19a33777.1773136880.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