[PATCH 4/5] powerpc: Move barrier_nospec() out of allow_read_{from/write}_user()

Christophe Leroy
2025-06-22T10:20:53Z

Move barrier_nospec() out of allow_read_from_user() and
allow_read_write_user() in order to allow reuse of those
functions when implementing masked user access.

Don't add it back in raw_copy_from_user() as it is already done
by callers of raw_copy_from_user().

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
arch/powerpc/include/asm/kup.h | 2 --
arch/powerpc/include/asm/uaccess.h | 4 ++++
2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/include/asm/kup.h b/arch/powerpc/include/asm/kup.h
index 4c70be11b99a..4e2c79df4cdb 100644
--- a/arch/powerpc/include/asm/kup.h
+++ b/arch/powerpc/include/asm/kup.h
@@ -134,7 +134,6 @@ static __always_inline void kuap_assert_locked(void)

static __always_inline void allow_read_from_user(const void __user *from)
{
- barrier_nospec();
allow_user_access(NULL, from, KUAP_READ);
}

@@ -145,7 +144,6 @@ static __always_inline void allow_write_to_user(void __user *to)

static __always_inline void allow_read_write_user(void __user *to, const void __user *from)
{
- barrier_nospec();
allow_user_access(to, from, KUAP_READ_WRITE);
}

diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
index dd5cf325ecde..89d53d4c2236 100644
--- a/arch/powerpc/include/asm/uaccess.h
+++ b/arch/powerpc/include/asm/uaccess.h
@@ -301,6 +301,7 @@ do { \
__typeof__(sizeof(*(ptr))) __gu_size = sizeof(*(ptr)); \
\
might_fault(); \
+ barrier_nospec(); \
allow_read_from_user(__gu_addr); \
__get_user_size_allowed(__gu_val, __gu_addr, __gu_size, __gu_err); \
prevent_read_from_user(__gu_addr); \
@@ -329,6 +330,7 @@ raw_copy_in_user(void __user *to, const void __user *from, unsigned long n)
{
unsigned long ret;

+ barrier_nospec();
allow_read_write_user(to, from);
ret = __copy_tofrom_user(to, from, n);
prevent_read_write_user(to, from);
@@ -415,6 +417,7 @@ static __must_check __always_inline bool user_access_begin(const void __user *pt

might_fault();

+ barrier_nospec();
allow_read_write_user((void __user *)ptr, ptr);
return true;
}
@@ -431,6 +434,7 @@ user_read_access_begin(const void __user *ptr, size_t len)

might_fault();

+ barrier_nospec();
allow_read_from_user(ptr);
return true;
}
--
2.49.0