powerpc: fix KUAP warning in VMX usercopy path
PATCH v3 1/2 powerpc: fix KUAP warning in VMX usercopy path
On powerpc with PREEMPT_FULL or PREEMPT_LAZY and function tracing enabled, KUAP warnings can be triggered from the VMX usercopy path under memory stress workloads.
KUAP requires that no subfunctions are called once userspace access has been enabled. The existing VMX copy implementation violates this requirement by invoking enter_vmx_usercopy() from the assembly path after userspace access has already been enabled. If preemption occurs in this window, the AMR state may not be preserved correctly, leading to unexpected userspace access state and resulting in KUAP warnings.
Fix this by restructuring the VMX usercopy flow so that VMX selection and VMX state management are centralized in raw_copy_tofrom_user(), which is invoked by the raw_copy_{to,from,in}_user() wrappers.
The new flow is:
- raw_copy_{to,from,in}_user() calls raw_copy_tofrom_user()
- raw_copy_tofrom_user() decides whether to use the VMX path based on size and CPU capability
- Call enter_vmx_usercopy() before enabling userspace access
- Enable userspace access as per the copy direction and perform the VMX copy
- Disable userspace access as per the copy direction
- Call exit_vmx_usercopy()
- Fall back to the base copy routine if the VMX copy faults
With this change, the VMX assembly routines no longer perform VMX state management or call helper functions; they only implement the copy operations.
The previous feature-section based VMX selection inside __copy_tofrom_user_power7() is removed, and a dedicated __copy_tofrom_user_power7_vmx() entry point is introduced.
This ensures correct KUAP ordering, avoids subfunction calls while KUAP is unlocked, and eliminates the warnings while preserving the VMX fast path.
---
v2->v3
- Addressd as per review feedback by removing usercopy_mode enum and using the copy direction directly for KUAP permission handling.
- Integrated __copy_tofrom_user_vmx() functionality into raw_copy_tofrom_user() in uaccess.h as a static __always_inline implementation.
- Exported enter_vmx_usercopy() and exit_vmx_usercopy()
to support VMX usercopy handling from the common path.
v2: https://lore.kernel.org/all/[email protected]/
--- arch/powerpc/include/asm/uaccess.h | 66 ++++++++++++++++++++++-------- arch/powerpc/lib/copyuser_64.S | 1 + arch/powerpc/lib/copyuser_power7.S | 45 +++++++------------- arch/powerpc/lib/vmx-helper.c | 2 + 4 files changed, 66 insertions(+), 48 deletions(-)
arch/powerpc/include/asm/uaccess.h +48 -18
@@ -15,6 +15,9 @@#define TASK_SIZE_MAX TASK_SIZE_USER64#endif +/* Threshold above which VMX copy path is used */ +#define VMX_COPY_THRESHOLD 3328 +#include <asm-generic/access_ok.h> /*
@@ -326,40 +329,67 @@ do { \extern unsigned long __copy_tofrom_user (void __user *to,const void __user *from,unsigned long size); -#ifdef __powerpc64__ -static inline unsigned long -raw_copy_in_user (void __user *to,const void __user *from,unsigned long n) +unsigned long __copy_tofrom_user_base (void __user *to, +const void __user *from,unsigned long size); + +unsigned long __copy_tofrom_user_power7_vmx (void __user *to, +const void __user *from,unsigned long size); + + +static __always_inline bool will_use_vmx(unsigned long n) +{ +return IS_ENABLED (CONFIG_ALTIVEC ) && +cpu_has_feature (CPU_FTR_VMX_COPY ) && + n >VMX_COPY_THRESHOLD ; +} + +static __always_inline unsigned long raw_copy_tofrom_user (void __user *to, +const void __user *from,unsigned long n, +unsigned long dir) {unsigned long ret; -barrier_nospec (); -allow_user_access (to,KUAP_READ_WRITE ); +if (will_use_vmx (n) &&enter_vmx_usercopy ()) { +allow_user_access (to, dir); + ret =__copy_tofrom_user_power7_vmx (to, from, n); +prevent_user_access (dir); +exit_vmx_usercopy (); + +if (unlikely (ret)) { +allow_user_access (to, dir); + ret =__copy_tofrom_user_base (to, from, n); +prevent_user_access (dir); + } +return ret; + } + +allow_user_access (to, dir); ret =__copy_tofrom_user (to, from, n); -prevent_user_access (KUAP_READ_WRITE ); +prevent_user_access (dir);return ret; } + +#ifdef __powerpc64__ +static inline unsigned long +raw_copy_in_user (void __user *to,const void __user *from,unsigned long n) +{ +barrier_nospec (); +return raw_copy_tofrom_user (to, from, n,KUAP_READ_WRITE ); +}#endif /* __powerpc64__ */ static inline unsigned long raw_copy_from_user (void *to,const void __user *from,unsigned long n) { -unsigned long ret; - -allow_user_access (NULL ,KUAP_READ ); - ret =__copy_tofrom_user ((__force void __user *)to, from, n); -prevent_user_access (KUAP_READ ); -return ret; +return raw_copy_tofrom_user ((__force void __user *)to, from, + n,KUAP_READ ); }static inline unsigned long raw_copy_to_user (void __user *to,const void *from,unsigned long n) { -unsigned long ret; - -allow_user_access (to,KUAP_WRITE ); - ret =__copy_tofrom_user (to, (__force const void __user *)from, n); -prevent_user_access (KUAP_WRITE ); -return ret; +return raw_copy_tofrom_user (to, (__force const void __user *)from, + n,KUAP_WRITE ); }unsigned long __arch_clear_user (void __user *addr,unsigned long size);
arch/powerpc/lib/copyuser_64.S +1 -0
@@ -562,3 +562,4 @@ exc; std r10,32(3) li r5,4096 b .Ldst_aligned EXPORT_SYMBOL(__copy_tofrom_user) +EXPORT_SYMBOL(__copy_tofrom_user_base)
arch/powerpc/lib/copyuser_power7.S +15 -30
100 lines not on this page · raw message
arch/powerpc/lib/vmx-helper.c +2 -0
@@ -27,6 +27,7 @@ int enter_vmx_usercopy(void)return 1 ; } +EXPORT_SYMBOL (enter_vmx_usercopy);/* * This function must return 0 because we tail call optimise when calling
@@ -49,6 +50,7 @@ int exit_vmx_usercopy(void)set_dec (1 );return 0 ; } +EXPORT_SYMBOL (exit_vmx_usercopy);int enter_vmx_ops (void ) {
Signature · 1 line
2.52.0
PATCH v3 2/2 powerpc/selftests/copyloops: extend selftest to exercise __copy_tofrom_user_power7_vmx
The new PowerPC VMX fast path (__copy_tofrom_user_power7_vmx) is not exercised by existing copyloops selftests. This patch updates the selftest to exercise the VMX variant, ensuring the VMX copy path is validated.
Changes include:
- COPY_LOOP=test___copy_tofrom_user_power7_vmx with -D VMX_TEST is used in existing selftest build targets.
- Inclusion of ../utils.c to provide get_auxv_entry() for hardware feature detection.
- At runtime, the test skips execution if Altivec is not available.
- Copy sizes above VMX_COPY_THRESHOLD are used to ensure the VMX path is taken.
This enables validation of the VMX fast path without affecting systems that do not support Altivec.
---
v2->v3
No changes in the patch.
v2: https://lore.kernel.org/all/[email protected]/
--- .../selftests/powerpc/copyloops/.gitignore | 4 ++-- .../testing/selftests/powerpc/copyloops/Makefile | 11 ++++++++--- tools/testing/selftests/powerpc/copyloops/stubs.S | 8 -------- .../selftests/powerpc/copyloops/validate.c | 15 ++++++++++++++- 4 files changed, 24 insertions(+), 14 deletions(-)
tools/testing/selftests/powerpc/copyloops/.gitignore +2 -2
@@ -2,8 +2,8 @@ copyuser_64_t0 copyuser_64_t1 copyuser_64_t2 -copyuser_p7_t0 -copyuser_p7_t1 +copyuser_p7 +copyuser_p7_vmx memcpy_64_t0 memcpy_64_t1 memcpy_64_t2
tools/testing/selftests/powerpc/copyloops/Makefile +8 -3
@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 TEST_GEN_PROGS := copyuser_64_t0 copyuser_64_t1 copyuser_64_t2 \ - copyuser_p7_t0 copyuser_p7_t1 \ + copyuser_p7 copyuser_p7_vmx \ memcpy_64_t0 memcpy_64_t1 memcpy_64_t2 \ memcpy_p7_t0 memcpy_p7_t1 copy_mc_64 \ copyuser_64_exc_t0 copyuser_64_exc_t1 copyuser_64_exc_t2 \
@@ -28,10 +28,15 @@ $(OUTPUT)/copyuser_64_t%: copyuser_64.S $(EXTRA_SOURCES) -D SELFTEST_CASE=$(subst copyuser_64_t,,$(notdir $@)) \ -o $@ $^ -$(OUTPUT)/copyuser_p7_t%: copyuser_power7.S $(EXTRA_SOURCES) +$(OUTPUT)/copyuser_p7: copyuser_power7.S $(EXTRA_SOURCES) $(CC) $(CPPFLAGS) $(CFLAGS) \ -D COPY_LOOP=test___copy_tofrom_user_power7 \ - -D SELFTEST_CASE=$(subst copyuser_p7_t,,$(notdir $@)) \ + -o $@ $^ + +$(OUTPUT)/copyuser_p7_vmx: copyuser_power7.S $(EXTRA_SOURCES) ../utils.c + $(CC) $(CPPFLAGS) $(CFLAGS) \ + -D COPY_LOOP=test___copy_tofrom_user_power7_vmx \ + -D VMX_TEST \ -o $@ $^ # Strictly speaking, we only need the memcpy_64 test cases for big-endian
tools/testing/selftests/powerpc/copyloops/stubs.S +0 -8
@@ -1,13 +1,5 @@ #include <asm/ppc_asm.h> -FUNC_START(enter_vmx_usercopy) - li r3,1 - blr - -FUNC_START(exit_vmx_usercopy) - li r3,0 - blr - FUNC_START(enter_vmx_ops) li r3,1 blr
tools/testing/selftests/powerpc/copyloops/validate.c +14 -1
@@ -12,6 +12,10 @@#define BUFLEN (MAX_LEN+MAX_OFFSET+2*MIN_REDZONE)#define POISON 0xa5 +#ifdef VMX_TEST +#define VMX_COPY_THRESHOLD 3328 +#endif +unsigned long COPY_LOOP (void *to,const void *from,unsigned long size); static void do_one(char *src, char *dst, unsigned long src_off,
@@ -81,8 +85,12 @@ int test_copy_loop(void)/* Fill with sequential bytes */ for (i =0 ; i <BUFLEN ; i++) fill[i] = i &0xff ; - +#ifdef VMX_TEST +/* Force sizes above kernel VMX threshold (3328) */ +for (len =VMX_COPY_THRESHOLD +1 ; len <MAX_LEN ; len++) { +#else for (len =1 ; len <MAX_LEN ; len++) { +#endif for (src_off =0 ; src_off <MAX_OFFSET ; src_off++) {for (dst_off =0 ; dst_off <MAX_OFFSET ; dst_off++) { do_one(src, dst, src_off, dst_off, len,
@@ -96,5 +104,10 @@ int test_copy_loop(void)int main (void ) { +#ifdef VMX_TEST +/* Skip if Altivec not present */ +SKIP_IF_MSG (!have_hwcap (PPC_FEATURE_HAS_ALTIVEC ),"ALTIVEC not supported" ); +#endif +return test_harness (test_copy_loop,str (COPY_LOOP )); }
Signature · 1 line
2.52.0
Christophe Leroy (CS GROUP)
reviewerHi Sayali,
Le 04/03/2026 à 06:35, Sayali Patil a écrit :
Quoted 39 lines
On powerpc with
PREEMPT_FULLorPREEMPT_LAZYand function tracing enabled, KUAP warnings can be triggered from the VMX usercopy path under memory stress workloads.KUAP requires that no subfunctions are called once userspace access has been enabled. The existing VMX copy implementation violates this requirement by invoking
enter_vmx_usercopy()from the assembly path after userspace access has already been enabled. If preemption occurs in this window, the AMR state may not be preserved correctly, leading to unexpected userspace access state and resulting in KUAP warnings.Fix this by restructuring the VMX usercopy flow so that VMX selection and VMX state management are centralized in
raw_copy_tofrom_user(), which is invoked by the raw_copy_{to,from,in}_user() wrappers.The new flow is:
- raw_copy_{to,from,in}_user() calls
raw_copy_tofrom_user()
-raw_copy_tofrom_user()decides whether to use the VMX path based on size and CPU capability
- Callenter_vmx_usercopy()before enabling userspace access
- Enable userspace access as per the copy direction and perform the VMX copy
- Disable userspace access as per the copy direction
- Callexit_vmx_usercopy()
- Fall back to the base copy routine if the VMX copy faultsWith this change, the VMX assembly routines no longer perform VMX state management or call helper functions; they only implement the copy operations.
The previous feature-section based VMX selection inside__copy_tofrom_user_power7()is removed, and a dedicated__copy_tofrom_user_power7_vmx()entry point is introduced.This ensures correct KUAP ordering, avoids subfunction calls while KUAP is unlocked, and eliminates the warnings while preserving the VMX fast path.
Quoted 7 lines
Fixes de78a9c42a79 ("powerpc: Add a framework for Kernel Userspace Access Protection")Reported-by Shrikanth Hegde <[email protected]>Suggested-by Christophe Leroy <[email protected]>Co-developed-by Aboorva Devarajan <[email protected]>Signed-off-by Aboorva Devarajan <[email protected]>Signed-off-by Sayali Patil <[email protected]>
That looks almost good, some editorial comments below.
With those fixed, you can add Reviewed-by: Christophe Leroy (CS GROUP) <[email protected]>
Quoted 38 lines
---
v2->v3
- Addressd as per review feedback by removingusercopy_modeenum and using the copy direction directly for KUAP permission handling.
- Integrated__copy_tofrom_user_vmx()functionality intoraw_copy_tofrom_user()inuaccess.has a static__always_inlineimplementation.
- Exportedenter_vmx_usercopy()andexit_vmx_usercopy()to support VMX usercopy handling from the common path.v2: https://lore.kernel.org/all/[email protected]/
--- arch/powerpc/include/asm/uaccess.h | 66 ++++++++++++++++++++++-------- arch/powerpc/lib/copyuser_64.S | 1 + arch/powerpc/lib/copyuser_power7.S | 45 +++++++------------- arch/powerpc/lib/vmx-helper.c | 2 + 4 files changed, 66 insertions(+), 48 deletions(-)arch/powerpc/include/asm/uaccess.h +3
-0@@ -15,6 +15,9 @@#define TASK_SIZE_MAX TASK_SIZE_USER64#endif +/* Threshold above which VMX copy path is used */ +#define VMX_COPY_THRESHOLD 3328 +#include <asm-generic/access_ok.h> /* @@ -326,40 +329,67 @@ do { \extern unsigned long __copy_tofrom_user (void __user *to,const void __user *from,unsigned long size);
arch/powerpc/include/asm/uaccess.h do { \ · line 338
Quoted 10 lines
arch/powerpc/include/asm/uaccess.h +7
-3-#ifdef __powerpc64__ -static inline unsigned long -raw_copy_in_user (void __user *to,const void __user *from,unsigned long n) +unsigned long __copy_tofrom_user_base (void __user *to, +const void __user *from,unsigned long size); + +unsigned long __copy_tofrom_user_power7_vmx (void __user *to, +const void __user *from,unsigned long size); + +
Remove one line.
arch/powerpc/include/asm/uaccess.h do { \ · line 343
Quoted 5 lines
arch/powerpc/include/asm/uaccess.h +5
-0+static __always_inline bool will_use_vmx(unsigned long n) +{ +return IS_ENABLED (CONFIG_ALTIVEC ) && +cpu_has_feature (CPU_FTR_VMX_COPY ) && + n >VMX_COPY_THRESHOLD ;
Avoid too many line when possible. Nowadays up to 100 chars per line are allowed.
Take care of alignment of second line, the second line should start at same position as IS_ENABLED, meaning you have to insert 7 spaces instead of a tab.
arch/powerpc/include/asm/uaccess.h do { \ · line 348
Quoted 5 lines
arch/powerpc/include/asm/uaccess.h +5
-0+} + +static __always_inline unsigned long raw_copy_tofrom_user (void __user *to, +const void __user *from,unsigned long n, +unsigned long dir)
Subsequent lines should start at same position as the ( of the first line, therefore I'd suggest following form instead:
static __always_inline unsigned longraw_copy_tofrom_user(void __user *to,const void __user *from, unsigned long n, unsigned long dir)
Quoted 17 lines
arch/powerpc/include/asm/uaccess.h +12
-2{unsigned long ret; -barrier_nospec (); -allow_user_access (to,KUAP_READ_WRITE ); +if (will_use_vmx (n) &&enter_vmx_usercopy ()) { +allow_user_access (to, dir); + ret =__copy_tofrom_user_power7_vmx (to, from, n); +prevent_user_access (dir); +exit_vmx_usercopy (); + +if (unlikely (ret)) { +allow_user_access (to, dir); + ret =__copy_tofrom_user_base (to, from, n); +prevent_user_access (dir); + } +return ret;
arch/powerpc/include/asm/uaccess.h do { \ · line 372
Quoted 10 lines
arch/powerpc/include/asm/uaccess.h +6
-1+ } + +allow_user_access (to, dir); ret =__copy_tofrom_user (to, from, n); -prevent_user_access (KUAP_READ_WRITE ); +prevent_user_access (dir);return ret; } + +#ifdef __powerpc64__
I know it was already there before, but checkpatch is not happy about __power64__. It should be replaced by CONFIG_PPC64.
arch/powerpc/include/asm/uaccess.h do { \ · line 382
Quoted 10 lines
arch/powerpc/include/asm/uaccess.h +6
-0+static inline unsigned long +raw_copy_in_user (void __user *to,const void __user *from,unsigned long n) +{ +barrier_nospec (); +return raw_copy_tofrom_user (to, from, n,KUAP_READ_WRITE ); +}#endif /* __powerpc64__ */ static inline unsigned long raw_copy_from_user (void *to,const void __user *from,unsigned long n)
Same problem with alignment of second line. Prefer the form used for raw_copy_in_user() or raw_copy_to_user(), ie:
static inline unsigned longraw_copy_from_user(void *to, const void __user *from, unsigned long n)
arch/powerpc/include/asm/uaccess.h do { \ · line 385
Quoted 9 lines
arch/powerpc/include/asm/uaccess.h +2
-6{ -unsigned long ret; - -allow_user_access (NULL ,KUAP_READ ); - ret =__copy_tofrom_user ((__force void __user *)to, from, n); -prevent_user_access (KUAP_READ ); -return ret; +return raw_copy_tofrom_user ((__force void __user *)to, from, + n,KUAP_READ );
100 chars are allowed per line, this should fit on a single line.
arch/powerpc/include/asm/uaccess.h do { \ · line 392
Quoted 13 lines
arch/powerpc/include/asm/uaccess.h +2
-6}static inline unsigned long raw_copy_to_user (void __user *to,const void *from,unsigned long n) { -unsigned long ret; - -allow_user_access (to,KUAP_WRITE ); - ret =__copy_tofrom_user (to, (__force const void __user *)from, n); -prevent_user_access (KUAP_WRITE ); -return ret; +return raw_copy_tofrom_user (to, (__force const void __user *)from, + n,KUAP_WRITE );
100 chars are allowed per line, this should fit on a single line.
arch/powerpc/include/asm/uaccess.h do { \ · line 395
Quoted 3 lines
arch/powerpc/include/asm/uaccess.h +0
-0}unsigned long __arch_clear_user (void __user *addr,unsigned long size);
Run checkpatch before submitting patches:
$ ./scripts/checkpatch.pl --strict -g HEAD~ CHECK: Alignment should match open parenthesis #83: FILE: arch/powerpc/include/asm/uaccess.h:333: +unsigned long __copy_tofrom_user_base(void __user *to, + const void __user *from, unsigned long size);
CHECK: Alignment should match open parenthesis
#86: FILE: arch/powerpc/include/asm/uaccess.h:336:
+unsigned long __copy_tofrom_user_power7_vmx(void __user *to,
+ const void __user *from, unsigned long size);
CHECK: Please don't use multiple blank lines #88: FILE: arch/powerpc/include/asm/uaccess.h:338:
+
+
CHECK: Alignment should match open parenthesis
#97: FILE: arch/powerpc/include/asm/uaccess.h:347:
+static __always_inline unsigned long raw_copy_tofrom_user(void __user *to,
+ const void __user *from, unsigned long n,
CHECK: architecture specific defines should be avoided #125: FILE: arch/powerpc/include/asm/uaccess.h:372:
+#ifdef __powerpc64__
total: 0 errors, 0 warnings, 5 checks, 212 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or
--fix-inplace.
Commit 3a44f6614d88 ("powerpc: fix KUAP warning in VMX usercopy path") has style problems, please review.
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
Sayali Patil
Reviewed-by Christophe Leroy (CS GROUP)Quoted 231 lines · Christophe Leroy (CS GROUP)
Hi Sayali,
Le 04/03/2026 à 06:35, Sayali Patil a écrit :
Quoted 39 lines
On powerpc with
PREEMPT_FULLorPREEMPT_LAZYand function tracing enabled, KUAP warnings can be triggered from the VMX usercopy path under memory stress workloads.KUAP requires that no subfunctions are called once userspace access has been enabled. The existing VMX copy implementation violates this requirement by invoking
enter_vmx_usercopy()from the assembly path after userspace access has already been enabled. If preemption occurs in this window, the AMR state may not be preserved correctly, leading to unexpected userspace access state and resulting in KUAP warnings.Fix this by restructuring the VMX usercopy flow so that VMX selection and VMX state management are centralized in
raw_copy_tofrom_user(), which is invoked by the raw_copy_{to,from,in}_user() wrappers.The new flow is:
- raw_copy_{to,from,in}_user() calls
raw_copy_tofrom_user()
-raw_copy_tofrom_user()decides whether to use the VMX path based on size and CPU capability
- Callenter_vmx_usercopy()before enabling userspace access
- Enable userspace access as per the copy direction and perform the VMX copy
- Disable userspace access as per the copy direction
- Callexit_vmx_usercopy()
- Fall back to the base copy routine if the VMX copy faultsWith this change, the VMX assembly routines no longer perform VMX state management or call helper functions; they only implement the copy operations.
The previous feature-section based VMX selection inside__copy_tofrom_user_power7()is removed, and a dedicated__copy_tofrom_user_power7_vmx()entry point is introduced.This ensures correct KUAP ordering, avoids subfunction calls while KUAP is unlocked, and eliminates the warnings while preserving the VMX fast path.
Quoted 7 lines
Fixes de78a9c42a79 ("powerpc: Add a framework for Kernel Userspace Access Protection")Reported-by Shrikanth Hegde <[email protected]>Suggested-by Christophe Leroy <[email protected]>Co-developed-by Aboorva Devarajan <[email protected]>Signed-off-by Aboorva Devarajan <[email protected]>Signed-off-by Sayali Patil <[email protected]>That looks almost good, some editorial comments below.
With those fixed, you can add Reviewed-by: Christophe Leroy (CS GROUP) <[email protected]>
Quoted 39 lines
---
v2->v3
- Addressd as per review feedback by removingusercopy_modeenum and using the copy direction directly for KUAP permission handling.
- Integrated__copy_tofrom_user_vmx()functionality intoraw_copy_tofrom_user()inuaccess.has a static__always_inlineimplementation.
- Exportedenter_vmx_usercopy()andexit_vmx_usercopy()to support VMX usercopy handling from the common path.v2: https://lore.kernel.org/all/[email protected]/
---
arch/powerpc/include/asm/uaccess.h| 66 ++++++++++++++++++++++-------- arch/powerpc/lib/copyuser_64.S | 1 +arch/powerpc/lib/copyuser_power7.S| 45 +++++++------------- arch/powerpc/lib/vmx-helper.c | 2 +4 files changed, 66 insertions(+), 48 deletions(-)arch/powerpc/include/asm/uaccess.h +0
-0@@ -15,6 +15,9 @@ #define TASK_SIZE_MAX TASK_SIZE_USER64 #endif+/* Threshold above which VMX copy path is used */
arch/powerpc/include/asm/uaccess.h +2
-0+#define VMX_COPY_THRESHOLD 3328 +#include <
asm-generic/access_ok.h>
/*arch/powerpc/include/asm/uaccess.h +0
-0@@ -326,40 +329,67 @@ do { \ extern unsigned long __copy_tofrom_user(void __user *to, const void __user *from, unsigned long size);-#ifdef
__powerpc64__arch/powerpc/include/asm/uaccess.h +0
-2-static inline unsigned long -raw_copy_in_user(void __user *to, const void __user *from, unsignedlong n)
arch/powerpc/include/asm/uaccess.h do { \ · line 338
Quoted 7 lines
arch/powerpc/include/asm/uaccess.h +7
-0+unsigned long __copy_tofrom_user_base (void __user *to, + const void __user *from, unsigned long size); + +unsigned long __copy_tofrom_user_power7_vmx (void __user *to, + const void __user *from, unsigned long size); + +Remove one line.
arch/powerpc/include/asm/uaccess.h do { \ · line 343
Quoted 5 lines
arch/powerpc/include/asm/uaccess.h +5
-0+static __always_inline bool will_use_vmx(unsigned long n) +{ + return IS_ENABLED(CONFIG_ALTIVEC) && + cpu_has_feature(CPU_FTR_VMX_COPY) && + n > VMX_COPY_THRESHOLD;Avoid too many line when possible. Nowadays up to 100 chars per line are allowed.
Take care of alignment of second line, the second line should start at same position as
IS_ENABLED, meaning you have to insert 7 spaces instead of a tab.Quoted 6 lines
arch/powerpc/include/asm/uaccess.h +3
-0+} + +static __always_inline unsigned long raw_copy_tofrom_user(void
__user*to,
+ const void__user*from, unsigned long n, + unsigned long dir)Subsequent lines should start at same position as the ( of the first line, therefore I'd suggest following form instead:
static
__always_inlineunsigned longraw_copy_tofrom_user(void __user *to,const void __user *from, unsigned long n, unsigned long dir)Quoted 24 lines
{
unsigned long ret;
-barrier_nospec();
-allow_user_access(to, KUAP_READ_WRITE);
+ if (will_use_vmx(n)&&enter_vmx_usercopy()) { +allow_user_access(to, dir);
+ ret =__copy_tofrom_user_power7_vmx(to, from, n); +prevent_user_access(dir);
+exit_vmx_usercopy();arch/powerpc/include/asm/uaccess.h +10
-0+ + if (unlikely(ret)) { + allow_user_access(to, dir); + ret = __copy_tofrom_user_base(to, from, n); + prevent_user_access(dir); + } + return ret; + } + + allow_user_access(to, dir);ret =
__copy_tofrom_user(to, from, n);
-prevent_user_access(KUAP_READ_WRITE);
+prevent_user_access(dir);
return ret;
}arch/powerpc/include/asm/uaccess.h
Quoted 2 lines
arch/powerpc/include/asm/uaccess.h +2
-0+ +#ifdef __powerpc64__I know it was already there before, but checkpatch is not happy about
__power64__. It should be replaced byCONFIG_PPC64.Quoted 10 lines
arch/powerpc/include/asm/uaccess.h +2
-0+static inline unsigned long +raw_copy_in_user(void __user *to, const void __user *from, unsignedlong n)
arch/powerpc/include/asm/uaccess.h +4
-0+{ + barrier_nospec(); + return raw_copy_tofrom_user(to, from, n, KUAP_READ_WRITE); +}#endif /*
__powerpc64__*/
static inline unsigned longraw_copy_from_user(void *to, const void __user *from, unsigned long n)Same problem with alignment of second line. Prefer the form used for
raw_copy_in_user()orraw_copy_to_user(), ie:static inline unsigned long
raw_copy_from_user(void *to, const void __user *from, unsigned long n)Quoted 9 lines
{
- unsigned long ret;
-
-allow_user_access(NULL, KUAP_READ);
- ret =__copy_tofrom_user((__force void __user *)to, from, n); -prevent_user_access(KUAP_READ);
- return ret;
+ returnraw_copy_tofrom_user((__force void __user *)to, from, + n, KUAP_READ);100 chars are allowed per line, this should fit on a single line.
Quoted 4 lines
}
static inline unsigned long
raw_copy_to_user(void __user *to, const void *from, unsigned long n){Quoted 8 lines
- unsigned long ret;
-
-allow_user_access(to, KUAP_WRITE);
- ret =__copy_tofrom_user(to, (__force const void __user *)from, n); -prevent_user_access(KUAP_WRITE);
- return ret;
+ returnraw_copy_tofrom_user(to, (__force const void __user *)from, + n, KUAP_WRITE);100 chars are allowed per line, this should fit on a single line.
Quoted 2 lines
}
unsigned long__arch_clear_user(void __user *addr, unsigned long size);Run checkpatch before submitting patches:
$ ./scripts/checkpatch.pl --strict -g HEAD~ CHECK: Alignment should match open parenthesis #83: FILE: arch/powerpc/include/asm/uaccess.h:333: +unsigned long __copy_tofrom_user_base(void __user *to, + const void __user *from, unsigned long size);CHECK: Alignment should match open parenthesis
#86: FILE:arch/powerpc/include/asm/uaccess.h:336:
+unsigned long__copy_tofrom_user_power7_vmx(void __user *to, + const void __user *from, unsigned long size);CHECK: Please don't use multiple blank lines #88: FILE:
arch/powerpc/include/asm/uaccess.h:338:(quoted diff) +2
-0+ +CHECK: Alignment should match open parenthesis
#97: FILE:arch/powerpc/include/asm/uaccess.h:347:
+static__always_inlineunsigned long raw_copy_tofrom_user(void__user*to,
+ const void__user*from, unsigned long n,CHECK: architecture specific defines should be avoided #125: FILE:
arch/powerpc/include/asm/uaccess.h:372:
+#ifdef__powerpc64__total: 0 errors, 0 warnings, 5 checks, 212 lines checked
Quoted 9 lines
NOTE: For some of the reported defects, checkpatch may be able to mechanically convert to the typical style using --fix or --fix-inplace.
Commit
3a44f6614d88("powerpc: fix KUAP warning in VMX usercopy path") has style problems, please review.NOTE: If any of the errors are false positives, please report them to the maintainer, see CHECKPATCH in
MAINTAINERS.
Thanks Christophe for the review.
I have addressed the comments and incorporated the changes in v4.
As suggested, I have added: