]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
uaccess: unify inline vs outline copy_{from,to}_user() selection
authorYury Norov <ynorov@nvidia.com>
Sat, 25 Apr 2026 02:08:56 +0000 (22:08 -0400)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 29 May 2026 04:24:44 +0000 (21:24 -0700)
The kernel allows arches to select between inline and outline
implementations of the copy_{from,to}_user() by defining individual
INLINE_COPY_FROM_USER and INLINE_COPY_TO_USER, correspondingly.  However,
all arches enable or disable them always together.

Without the real use-case for one helper being inlined while the other
outlined, having independent controls is excessive and error prone.

Switch the codebase to the single unified INLINE_COPY_USER control.

Link: https://lore.kernel.org/20260425020857.356850-3-ynorov@nvidia.com
Signed-off-by: Yury Norov <ynorov@nvidia.com>
Tested-by: Alice Ryhl <aliceryhl@google.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Viktor Malik <vmalik@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
21 files changed:
arch/arc/include/asm/uaccess.h
arch/arm/include/asm/uaccess.h
arch/arm64/include/asm/uaccess.h
arch/hexagon/include/asm/uaccess.h
arch/loongarch/include/asm/uaccess.h
arch/m68k/include/asm/uaccess.h
arch/microblaze/include/asm/uaccess.h
arch/mips/include/asm/uaccess.h
arch/nios2/include/asm/uaccess.h
arch/openrisc/include/asm/uaccess.h
arch/parisc/include/asm/uaccess.h
arch/s390/include/asm/uaccess.h
arch/sh/include/asm/uaccess.h
arch/sparc/include/asm/uaccess_32.h
arch/sparc/include/asm/uaccess_64.h
arch/um/include/asm/uaccess.h
arch/xtensa/include/asm/uaccess.h
include/asm-generic/uaccess.h
include/linux/uaccess.h
lib/usercopy.c
rust/helpers/uaccess.c

index 1e8809ea000a35ff37673585654ff5ba514542af..6df2209541ac016bf6375fbab94c45d123a14d5a 100644 (file)
@@ -628,8 +628,7 @@ static inline unsigned long __clear_user(void __user *to, unsigned long n)
        return res;
 }
 
-#define INLINE_COPY_TO_USER
-#define INLINE_COPY_FROM_USER
+#define INLINE_COPY_USER
 
 #define __clear_user                   __clear_user
 
index d6ae80b5df36f65f5f289472f5cfd5532d2aca8f..1593cf3b9800887820f8525084ec89e2c6139461 100644 (file)
@@ -616,8 +616,7 @@ raw_copy_to_user(void __user *to, const void *from, unsigned long n)
 }
 #define __clear_user(addr, n)          (memset((void __force *)addr, 0, n), 0)
 #endif
-#define INLINE_COPY_TO_USER
-#define INLINE_COPY_FROM_USER
+#define INLINE_COPY_USER
 
 static inline unsigned long __must_check clear_user(void __user *to, unsigned long n)
 {
index b0c83a08dda97bafad4784e71509b2cadb604c09..9f5bd9c69c249a85c8a05e7cecdfbc8e45e9394c 100644 (file)
@@ -456,8 +456,7 @@ do {                                                                        \
        unsafe_copy_loop(__ucu_dst, __ucu_src, __ucu_len, u8, label);   \
 } while (0)
 
-#define INLINE_COPY_TO_USER
-#define INLINE_COPY_FROM_USER
+#define INLINE_COPY_USER
 
 extern unsigned long __must_check __arch_clear_user(void __user *to, unsigned long n);
 static inline unsigned long __must_check __clear_user(void __user *to, unsigned long n)
index bff77efc0d9a9c308f9b44d0f995a5bb0dba222d..1aecf60ec4f5a375bf020579be5a40505563d3f0 100644 (file)
@@ -26,8 +26,7 @@ unsigned long raw_copy_from_user(void *to, const void __user *from,
                                     unsigned long n);
 unsigned long raw_copy_to_user(void __user *to, const void *from,
                                   unsigned long n);
-#define INLINE_COPY_FROM_USER
-#define INLINE_COPY_TO_USER
+#define INLINE_COPY_USER
 
 __kernel_size_t __clear_user_hexagon(void __user *dest, unsigned long count);
 #define __clear_user(a, s) __clear_user_hexagon((a), (s))
index 438269313e78c454d6c1b901e20ddd817b47b6fb..428f373feabf18bd1c9b825750bd01825a996580 100644 (file)
@@ -292,8 +292,7 @@ raw_copy_to_user(void __user *to, const void *from, unsigned long n)
        return __copy_user((__force void *)to, from, n);
 }
 
-#define INLINE_COPY_FROM_USER
-#define INLINE_COPY_TO_USER
+#define INLINE_COPY_USER
 
 /*
  * __clear_user: - Zero a block of memory in user space, with less checking.
index 64914872a5c98da40ed604a28fb6ac36a36d65f5..31d133faa45ef4536ef557387d3ecdf78136eefa 100644 (file)
@@ -377,8 +377,7 @@ raw_copy_to_user(void __user *to, const void *from, unsigned long n)
                return __constant_copy_to_user(to, from, n);
        return __generic_copy_to_user(to, from, n);
 }
-#define INLINE_COPY_FROM_USER
-#define INLINE_COPY_TO_USER
+#define INLINE_COPY_USER
 
 #define __get_kernel_nofault(dst, src, type, err_label)                        \
 do {                                                                   \
index 3aab2f17e04628ffb68fc8b88e53e032c8410eb0..afa0dd8d013fbc222d02c0821e46e017b4a74033 100644 (file)
@@ -250,8 +250,7 @@ raw_copy_to_user(void __user *to, const void *from, unsigned long n)
 {
        return __copy_tofrom_user(to, (__force const void __user *)from, n);
 }
-#define INLINE_COPY_FROM_USER
-#define INLINE_COPY_TO_USER
+#define INLINE_COPY_USER
 
 /*
  * Copy a null terminated string from userspace.
index c0cede273c7c04a86313741ac9af0c1cfd4dac66..f00c36676b7378b6eade137896e43850f6d16282 100644 (file)
@@ -433,8 +433,7 @@ raw_copy_to_user(void __user *to, const void *from, unsigned long n)
        return __cu_len_r;
 }
 
-#define INLINE_COPY_FROM_USER
-#define INLINE_COPY_TO_USER
+#define INLINE_COPY_USER
 
 extern __kernel_size_t __bzero(void __user *addr, __kernel_size_t size);
 
index 6ccc9a232c2394c92dc9cc6bd5f17f270765cd68..5e6e05cc6efc73cf7e91fbf9667c77394bd59ebf 100644 (file)
@@ -57,8 +57,7 @@ extern unsigned long
 raw_copy_from_user(void *to, const void __user *from, unsigned long n);
 extern unsigned long
 raw_copy_to_user(void __user *to, const void *from, unsigned long n);
-#define INLINE_COPY_FROM_USER
-#define INLINE_COPY_TO_USER
+#define INLINE_COPY_USER
 
 extern long strncpy_from_user(char *__to, const char __user *__from,
                              long __len);
index d6500a374e18340e5858d469ec4b56c0ce448ad9..db934ebc0069f28f0aacb6326175e2e8bdb967cd 100644 (file)
@@ -218,8 +218,7 @@ raw_copy_to_user(void __user *to, const void *from, unsigned long size)
 {
        return __copy_tofrom_user((__force void *)to, from, size);
 }
-#define INLINE_COPY_FROM_USER
-#define INLINE_COPY_TO_USER
+#define INLINE_COPY_USER
 
 extern unsigned long __clear_user(void __user *addr, unsigned long size);
 
index 6c531d2c847eb11c3ad290e3c2712445d345355c..0d17f81c8b2708f83cec7169479d0704f2fcaca5 100644 (file)
@@ -197,7 +197,6 @@ unsigned long __must_check raw_copy_to_user(void __user *dst, const void *src,
                                            unsigned long len);
 unsigned long __must_check raw_copy_from_user(void *dst, const void __user *src,
                                            unsigned long len);
-#define INLINE_COPY_TO_USER
-#define INLINE_COPY_FROM_USER
+#define INLINE_COPY_USER
 
 #endif /* __PARISC_UACCESS_H */
index dff035372601e7a56cae2973a2512a36fad3940b..a9f32c53f699b8efabaf1f321f1bd6fc10ed8498 100644 (file)
@@ -30,8 +30,7 @@ void debug_user_asce(int exit);
 #define uaccess_kmsan_or_inline __always_inline
 #endif
 
-#define INLINE_COPY_FROM_USER
-#define INLINE_COPY_TO_USER
+#define INLINE_COPY_USER
 
 static uaccess_kmsan_or_inline __must_check unsigned long
 raw_copy_from_user(void *to, const void __user *from, unsigned long size)
index a79609eb14be43606e1ba32677e0d7b8f280cd30..02e7a066538ec3037a7fc78d5f9dc7bc7e19a0b1 100644 (file)
@@ -95,8 +95,7 @@ raw_copy_to_user(void __user *to, const void *from, unsigned long n)
 {
        return __copy_user((__force void *)to, from, n);
 }
-#define INLINE_COPY_FROM_USER
-#define INLINE_COPY_TO_USER
+#define INLINE_COPY_USER
 
 /*
  * Clear the area and return remaining number of bytes
index 43284b6ec46a684360acaeb5eda65f39c4efed32..5542d5b32994fa93ecb677c000f490fbfeb13f2d 100644 (file)
@@ -190,8 +190,7 @@ static inline unsigned long raw_copy_from_user(void *to, const void __user *from
        return __copy_user((__force void __user *) to, from, n);
 }
 
-#define INLINE_COPY_FROM_USER
-#define INLINE_COPY_TO_USER
+#define INLINE_COPY_USER
 
 static inline unsigned long __clear_user(void __user *addr, unsigned long size)
 {
index b825a5dd0210ea47bd9fb3905071eced2200bcc2..e2989cfba626d5337719eebf543cd384c67bb141 100644 (file)
@@ -231,8 +231,7 @@ unsigned long __must_check raw_copy_from_user(void *to,
 unsigned long __must_check raw_copy_to_user(void __user *to,
                                           const void *from,
                                           unsigned long size);
-#define INLINE_COPY_FROM_USER
-#define INLINE_COPY_TO_USER
+#define INLINE_COPY_USER
 
 unsigned long __must_check raw_copy_in_user(void __user *to,
                                           const void __user *from,
index 0df9ea4abda8305df46517648b170d0c9d47a95d..4417c8b1d37a6d8105feb9fa4e74a8e5b5fd6e76 100644 (file)
@@ -27,8 +27,7 @@ static inline int __access_ok(const void __user *ptr, unsigned long size);
 #define __access_ok __access_ok
 #define __clear_user __clear_user
 
-#define INLINE_COPY_FROM_USER
-#define INLINE_COPY_TO_USER
+#define INLINE_COPY_USER
 
 #include <asm-generic/uaccess.h>
 
index 56aec6d504fee3197e2f1b37671ddaee52d9e3cd..6538a29a2bbd4cff6fe71c04ea503c27ec90f10c 100644 (file)
@@ -237,8 +237,7 @@ raw_copy_to_user(void __user *to, const void *from, unsigned long n)
        prefetch(from);
        return __xtensa_copy_user((__force void *)to, from, n);
 }
-#define INLINE_COPY_FROM_USER
-#define INLINE_COPY_TO_USER
+#define INLINE_COPY_USER
 
 /*
  * We need to return the number of bytes not cleared.  Our memset()
index b276f783494c4b1b197e49a05f632e3fb02b9d3e..4569045e7139fd7c6cd8af06081d75d78f180444 100644 (file)
@@ -91,8 +91,7 @@ raw_copy_to_user(void __user *to, const void *from, unsigned long n)
        memcpy((void __force *)to, from, n);
        return 0;
 }
-#define INLINE_COPY_FROM_USER
-#define INLINE_COPY_TO_USER
+#define INLINE_COPY_USER
 #endif /* CONFIG_UACCESS_MEMCPY */
 
 /*
index 56328601218c5a7c9a23f3c8e3c2dcd764720fbd..6100f1046546347c639eca1624d6c3bacb033b8d 100644 (file)
@@ -84,7 +84,7 @@
  * the 6 functions (copy_{to,from}_user(), __copy_{to,from}_user_inatomic())
  * that are used instead.  Out of those, __... ones are inlined.  Plain
  * copy_{to,from}_user() might or might not be inlined.  If you want them
- * inlined, have asm/uaccess.h define INLINE_COPY_{TO,FROM}_USER.
+ * inlined, have asm/uaccess.h define INLINE_COPY_USER.
  *
  * NOTE: only copy_from_user() zero-pads the destination in case of short copy.
  * Neither __copy_from_user() nor __copy_from_user_inatomic() zero anything
@@ -157,7 +157,7 @@ __copy_to_user(void __user *to, const void *from, unsigned long n)
 }
 
 /*
- * Architectures that #define INLINE_COPY_TO_USER use this function
+ * Architectures that #define INLINE_COPY_USER use this function
  * directly in the normal copy_to/from_user(), the other ones go
  * through an extern _copy_to/from_user(), which expands the same code
  * here.
@@ -190,7 +190,7 @@ fail:
        memset(to + (n - res), 0, res);
        return res;
 }
-#ifndef INLINE_COPY_FROM_USER
+#ifndef INLINE_COPY_USER
 extern __must_check unsigned long
 _copy_from_user(void *, const void __user *, unsigned long);
 #endif
@@ -207,7 +207,7 @@ _inline_copy_to_user(void __user *to, const void *from, unsigned long n)
        }
        return n;
 }
-#ifndef INLINE_COPY_TO_USER
+#ifndef INLINE_COPY_USER
 extern __must_check unsigned long
 _copy_to_user(void __user *, const void *, unsigned long);
 #endif
@@ -217,7 +217,7 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
 {
        if (!check_copy_size(to, n, false))
                return n;
-#ifdef INLINE_COPY_FROM_USER
+#ifdef INLINE_COPY_USER
        return _inline_copy_from_user(to, from, n);
 #else
        return _copy_from_user(to, from, n);
@@ -230,7 +230,7 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
        if (!check_copy_size(from, n, true))
                return n;
 
-#ifdef INLINE_COPY_TO_USER
+#ifdef INLINE_COPY_USER
        return _inline_copy_to_user(to, from, n);
 #else
        return _copy_to_user(to, from, n);
index b00a3a957de6be4d074dfecbe95388e75b709317..e2f0bf104a591bfee0231f4747c362f849964218 100644 (file)
 
 /* out-of-line parts */
 
-#if !defined(INLINE_COPY_FROM_USER)
+#if !defined(INLINE_COPY_USER)
 unsigned long _copy_from_user(void *to, const void __user *from, unsigned long n)
 {
        return _inline_copy_from_user(to, from, n);
 }
 EXPORT_SYMBOL(_copy_from_user);
-#endif
 
-#if !defined(INLINE_COPY_TO_USER)
 unsigned long _copy_to_user(void __user *to, const void *from, unsigned long n)
 {
        return _inline_copy_to_user(to, from, n);
index aff22f16ab3884199cb1478b4069f0181ab218a7..6e59cc9c665cced78a4d7cbed7a890f5c8da70a8 100644 (file)
@@ -14,15 +14,13 @@ rust_helper_copy_to_user(void __user *to, const void *from, unsigned long n)
        return copy_to_user(to, from, n);
 }
 
-#ifdef INLINE_COPY_FROM_USER
+#ifdef INLINE_COPY_USER
 __rust_helper
 unsigned long rust_helper__copy_from_user(void *to, const void __user *from, unsigned long n)
 {
        return _inline_copy_from_user(to, from, n);
 }
-#endif
 
-#ifdef INLINE_COPY_TO_USER
 __rust_helper
 unsigned long rust_helper__copy_to_user(void __user *to, const void *from, unsigned long n)
 {