public inbox for linuxppc-dev@ozlabs.org
 help / color / mirror / Atom feed
* [PATCH] powerpc/align: Convert emulate_spe() to scoped user access
@ 2026-03-10 10:01 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:01 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 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



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] powerpc/align: Convert emulate_spe() to scoped user access
  2026-03-10 10:01 [PATCH] powerpc/align: Convert emulate_spe() 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:01:31 +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 emulate_spe() 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/align: Convert emulate_spe() to scoped user access
      https://git.kernel.org/powerpc/c/bf53ede0038fe2a7b02cad85f337aba43ced572a

cheers


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-04-08  4:28 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:01 [PATCH] powerpc/align: Convert emulate_spe() 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