Skip to contentSkip to conversation

uaccess: unify inline vs outline copy_{from,to}_user() selection

PATCH Superseded Yury Norov 4 participants 11 messages Mar 25 – Apr 25

Subsystems (20)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Yury Norov

author
#0 lore raw

cover uaccess: unify inline vs outline copy_{from,to}_user() selection

Christophe has pointed in [1] that one my patch incorrectly defines rust_helper__copy_to_user() wrapper based on INLINE_COPY_FROM_USER.

Having separate controls for 'from' and 'to' versions is pretty useless, and has proven to be error prone. So, instead of fixing the rust portion, simply switch the kernel to a single knob.

[1] https://lore.kernel.org/all/[email protected]/

Yury Norov (2):
uaccess: unify inline vs outline copy_{from,to}_user() selection
uaccess: minimize INLINE_COPY_USER-related ifdefery

 arch/arc/include/asm/uaccess.h        |  3 +--
 arch/arm/include/asm/uaccess.h        |  3 +--
 arch/arm64/include/asm/uaccess.h      |  3 +--
 arch/hexagon/include/asm/uaccess.h    |  3 +--
 arch/loongarch/include/asm/uaccess.h  |  3 +--
 arch/m68k/include/asm/uaccess.h       |  3 +--
 arch/microblaze/include/asm/uaccess.h |  3 +--
 arch/mips/include/asm/uaccess.h       |  3 +--
 arch/nios2/include/asm/uaccess.h      |  3 +--
 arch/openrisc/include/asm/uaccess.h   |  3 +--
 arch/parisc/include/asm/uaccess.h     |  3 +--
 arch/s390/include/asm/uaccess.h       |  3 +--
 arch/sh/include/asm/uaccess.h         |  3 +--
 arch/sparc/include/asm/uaccess_32.h   |  3 +--
 arch/sparc/include/asm/uaccess_64.h   |  3 +--
 arch/um/include/asm/uaccess.h         |  3 +--
 arch/xtensa/include/asm/uaccess.h     |  3 +--
 include/asm-generic/uaccess.h         |  3 +--
 include/linux/uaccess.h               | 25 ++++++++++---------------
 lib/usercopy.c                        |  4 +---
 rust/helpers/uaccess.c                |  2 +-
 21 files changed, 30 insertions(+), 55 deletions(-)
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH 1/2 uaccess: unify inline vs outline copy_{from,to}_user() selection

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.

Fixes 1f9a8286bc0c ("uaccess: always export _copy_[from|to]_user with CONFIG_RUST")
---
 arch/arc/include/asm/uaccess.h        |  3 +--
 arch/arm/include/asm/uaccess.h        |  3 +--
 arch/arm64/include/asm/uaccess.h      |  3 +--
 arch/hexagon/include/asm/uaccess.h    |  3 +--
 arch/loongarch/include/asm/uaccess.h  |  3 +--
 arch/m68k/include/asm/uaccess.h       |  3 +--
 arch/microblaze/include/asm/uaccess.h |  3 +--
 arch/mips/include/asm/uaccess.h       |  3 +--
 arch/nios2/include/asm/uaccess.h      |  3 +--
 arch/openrisc/include/asm/uaccess.h   |  3 +--
 arch/parisc/include/asm/uaccess.h     |  3 +--
 arch/s390/include/asm/uaccess.h       |  3 +--
 arch/sh/include/asm/uaccess.h         |  3 +--
 arch/sparc/include/asm/uaccess_32.h   |  3 +--
 arch/sparc/include/asm/uaccess_64.h   |  3 +--
 arch/um/include/asm/uaccess.h         |  3 +--
 arch/xtensa/include/asm/uaccess.h     |  3 +--
 include/asm-generic/uaccess.h         |  3 +--
 include/linux/uaccess.h               | 12 ++++++------
 lib/usercopy.c                        |  4 +---
 rust/helpers/uaccess.c                |  2 +-
 21 files changed, 26 insertions(+), 46 deletions(-)
arch/arc/include/asm/uaccess.h +1 -2
index 1e8809ea000a..6df2209541ac 100644
@@ -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
 
arch/arm/include/asm/uaccess.h +1 -2
index d6ae80b5df36..1593cf3b9800 100644
@@ -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)
 {
arch/arm64/include/asm/uaccess.h +1 -2
index 9810106a3f66..d8be8cb45050 100644
@@ -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)
arch/hexagon/include/asm/uaccess.h +1 -2
index bff77efc0d9a..1aecf60ec4f5 100644
@@ -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))
arch/loongarch/include/asm/uaccess.h +1 -2
index 438269313e78..428f373feabf 100644
@@ -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.
arch/m68k/include/asm/uaccess.h +1 -2
index 64914872a5c9..31d133faa45e 100644
@@ -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 {									\
arch/microblaze/include/asm/uaccess.h +1 -2
index 3aab2f17e046..afa0dd8d013f 100644
@@ -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.
arch/mips/include/asm/uaccess.h +1 -2
index c0cede273c7c..f00c36676b73 100644
@@ -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);
 
arch/nios2/include/asm/uaccess.h +1 -2
index 6ccc9a232c23..5e6e05cc6efc 100644
@@ -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);
arch/openrisc/include/asm/uaccess.h +1 -2
index d6500a374e18..db934ebc0069 100644
@@ -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);
 
arch/parisc/include/asm/uaccess.h +1 -2
index 6c531d2c847e..0d17f81c8b27 100644
@@ -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 */
arch/s390/include/asm/uaccess.h +1 -2
index dff035372601..a9f32c53f699 100644
@@ -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)
arch/sh/include/asm/uaccess.h +1 -2
index a79609eb14be..02e7a066538e 100644
@@ -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
arch/sparc/include/asm/uaccess_32.h +1 -2
index 43284b6ec46a..5542d5b32994 100644
@@ -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)
 {
arch/sparc/include/asm/uaccess_64.h +1 -2
index b825a5dd0210..e2989cfba626 100644
@@ -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,
arch/um/include/asm/uaccess.h +1 -2
index 0df9ea4abda8..4417c8b1d37a 100644
@@ -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>
 
arch/xtensa/include/asm/uaccess.h +1 -2
index 56aec6d504fe..6538a29a2bbd 100644
@@ -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()
include/asm-generic/uaccess.h +1 -2
index b276f783494c..4569045e7139 100644
@@ -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 */
 
 /*
include/linux/uaccess.h +6 -6
index 4fe63169d5a2..0ddd2806d7f5 100644
@@ -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 @@ _inline_copy_from_user(void *to, const void __user *from, unsigned long n)
 	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);
lib/usercopy.c +1 -3
index b00a3a957de6..e2f0bf104a59 100644
@@ -12,15 +12,13 @@
 
 /* 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);
rust/helpers/uaccess.c +1 -1
index d9625b9ee046..6e59cc9c665c 100644
@@ -14,7 +14,7 @@ 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)
 {
Signature · 1 line
2.43.0
#2 lore raw

Le 25/03/2026 à 17:33, Yury Norov a écrit :

Quoted 9 lines

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.

Could we use a (non user selectable) Kconfig item instead, e.g. CONFIG_ARCH_WANT_OUTLINE_USER_COPY ?

Also, looks like only powerpc doesn't select INLINE_COPY. Would it be cleaner to change the logic to a flag for OUTLINE_COPY ?

Something like (untested):

arch/powerpc/Kconfig +1 -0
index ad7a2fe63a2a..58743cb0e305 100644
@@ -186,6 +186,7 @@ config PPC
 	select ARCH_WANT_IRQS_OFF_ACTIVATE_MM
 	select ARCH_WANT_LD_ORPHAN_WARN
 	select ARCH_WANT_OPTIMIZE_DAX_VMEMMAP	if PPC_RADIX_MMU
+	select ARCH_WANT_OUTLINE_USER_COPY
 	select ARCH_WANTS_MODULES_DATA_IN_VMALLOC	if PPC_BOOK3S_32 || PPC_8xx
 	select ARCH_WEAK_RELEASE_ACQUIRE
 	select BINFMT_ELF
include/asm-generic/uaccess.h +0 -2
index b276f783494c..fb33a71fd24e 100644
@@ -91,8 +91,6 @@ 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
 #endif /* CONFIG_UACCESS_MEMCPY */
 
 /*
include/linux/uaccess.h +0 -0
index 1f3804245c06..bcfa8c11e49f 100644
@@ -83,8 +83,8 @@
  * with that.  They should not be used directly; they are used to 

implement
* 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.
+ * copy_{to,from}_user() might or might not be inlined. If you don't want them
+ * inlined, select CONFIG_ARCH_WANT_OUTLINE_USER_COPY.
*
* 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,8 +157,8 @@ __copy_to_user(void __user *to, const void *from, unsigned long n)
}

/*
- * Architectures that #define INLINE_COPY_TO_USER use this function
- * directly in the normal copy_to/from_user(), the other ones go
+ * Architectures that don't select CONFIG_ARCH_WANT_OUTLINE_USER_COPY 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 @@ _inline_copy_from_user(void *to, const void __user *from, unsigned long n)
memset(to + (n - res), 0, res);
return res;
}
-#ifndef INLINE_COPY_FROM_USER
+#ifndef CONFIG_ARCH_WANT_OUTLINE_USER_COPY
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 CONFIG_ARCH_WANT_OUTLINE_USER_COPY
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
+#ifndef CONFIG_ARCH_WANT_OUTLINE_USER_COPY
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
+#ifndef CONFIG_ARCH_WANT_OUTLINE_USER_COPY
return _inline_copy_to_user(to, from, n);
#else
return _copy_to_user(to, from, n);

lib/Kconfig +3 -0
index 0f2fb9610647..0106c1facfa4 100644
@@ -550,6 +550,9 @@ config ARCH_HAS_UACCESS_FLUSHCACHE
 config ARCH_HAS_COPY_MC
 	bool
 
+config ARCH_WANT_OUTLINE_USER_COPY
+	bool
+
 # Temporary. Goes away when all archs are cleaned up
 config ARCH_STACKWALK
        bool
lib/usercopy.c +1 -1
index b00a3a957de6..aa52ac3f5d6b 100644
@@ -12,15 +12,13 @@
 
 /* out-of-line parts */
 
-#if !defined(INLINE_COPY_FROM_USER)
+#ifdef CONFIG_ARCH_WANT_OUTLINE_USER_COPY
 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);

rust/helpers/uaccess.c +1 -1
index d9625b9ee046..79d950425dd9 100644
@@ -14,7 +14,7 @@ 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
+#ifndef CONFIG_ARCH_WANT_OUTLINE_USER_COPY
 __rust_helper
 unsigned long rust_helper__copy_from_user(void *to, const void __user 

*from, unsigned long n)
{

Quoted 5 lines
Fixes 1f9a8286bc0c ("uaccess: always export _copy_[from|to]_user with CONFIG_RUST")

Christophe

author
#3 lore raw
Quoted 8 lines · Christophe Leroy (CS GROUP)

Le 25/03/2026 à 17:33, Yury Norov a écrit :

Quoted 5 lines

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.

Quoted 7 lines
Quoted 4 lines

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.

Could we use a (non user selectable) Kconfig item instead, e.g. CONFIG_ARCH_WANT_OUTLINE_USER_COPY ?

This sounds interesting. I need to wrap it around my head for a while. Right now, I believe, the best solution is to isolate this setting from the sources as much as we can, and your suggestion looks like a step forward.

Overall, I'm puzzled why some arches enable this while the others don't. The next question is why copy_{from,to}_user is so special. If this function benefits from being inlined for that particular arch or compiler, which functions would also benefit and why?

Reasoning logically, if this WANT_INLINE thing makes sense, it would make much more sense if we create a machinery for something like:

        unsigned long __arch_inline copy_to_user();
Quoted 2 lines

Also, looks like only powerpc doesn't select INLINE_COPY. Would it be cleaner to change the logic to a flag for OUTLINE_COPY ?

How that? x86_64 outlines it. Check it yourself:

  @@ -206,7 +206,9 @@ _inline_copy_to_user(void __user *to, const void *from, unsigned long n)
   #ifdef INLINE_COPY_USER
   # define _copy_to_user _inline_copy_to_user
   # define _copy_from_user _inline_copy_from_user
  +#error INLINE_COPY_USER
   #else
  +#error OUTLINE_COPY_USER
   extern __must_check unsigned long
   _copy_from_user(void *, const void __user *, unsigned long);

If it was really a single arch, it would be worth to discuss what for do we need this customization at all.

#4 lore raw

Le 26/03/2026 à 18:29, Yury Norov a écrit :

Quoted 47 lines · Christophe Leroy (CS GROUP)
Quoted 8 lines

Le 25/03/2026 à 17:33, Yury Norov a écrit :

Quoted 5 lines

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.

Quoted 7 lines
Quoted 4 lines

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.

Could we use a (non user selectable) Kconfig item instead, e.g. CONFIG_ARCH_WANT_OUTLINE_USER_COPY ?

This sounds interesting. I need to wrap it around my head for a while. Right now, I believe, the best solution is to isolate this setting from the sources as much as we can, and your suggestion looks like a step forward.

Overall, I'm puzzled why some arches enable this while the others don't. The next question is why copy_{from,to}_user is so special. If this function benefits from being inlined for that particular arch or compiler, which functions would also benefit and why?

Reasoning logically, if this WANT_INLINE thing makes sense, it would make much more sense if we create a machinery for something like:

         unsigned long __arch_inline copy_to_user();
Quoted 2 lines

Also, looks like only powerpc doesn't select INLINE_COPY. Would it be cleaner to change the logic to a flag for OUTLINE_COPY ?

How that? x86_64 outlines it. Check it yourself:

   @@ -206,7 +206,9 @@ _inline_copy_to_user(void __user *to, const void *from, unsigned long n)
    #ifdef INLINE_COPY_USER
    # define _copy_to_user _inline_copy_to_user
    # define _copy_from_user _inline_copy_from_user
   +#error INLINE_COPY_USER
    #else
   +#error OUTLINE_COPY_USER
    extern __must_check unsigned long
    _copy_from_user(void *, const void __user *, unsigned long);
Quoted 2 lines

If it was really a single arch, it would be worth to discuss what for do we need this customization at all.

Hum ... You are right. I don't know why, I thought powerpc was the only one.

Nevertheless, among the 21 architectures in arch/ , 17 of them select INLINE_COPY_FROM_USER, which means only 4 don't define it.

So might still be interesting to reverse the logic, then only 4 arches will have to select it, similar to the exemple below with powerpc:

arch/powerpc/Kconfig +1 -0
index ad7a2fe63a2a..58743cb0e305 100644
@@ -186,6 +186,7 @@ config PPC
 	select ARCH_WANT_IRQS_OFF_ACTIVATE_MM
 	select ARCH_WANT_LD_ORPHAN_WARN
 	select ARCH_WANT_OPTIMIZE_DAX_VMEMMAP	if PPC_RADIX_MMU
+	select ARCH_WANT_OUTLINE_USER_COPY
 	select ARCH_WANTS_MODULES_DATA_IN_VMALLOC	if PPC_BOOK3S_32 || PPC_8xx
 	select ARCH_WEAK_RELEASE_ACQUIRE
 	select BINFMT_ELF
lib/Kconfig +3 -0
index 0f2fb9610647..0106c1facfa4 100644
@@ -550,6 +550,9 @@ config ARCH_HAS_UACCESS_FLUSHCACHE
 config ARCH_HAS_COPY_MC
 	bool
 
+config ARCH_WANT_OUTLINE_USER_COPY
+	bool
+
 # Temporary. Goes away when all archs are cleaned up
 config ARCH_STACKWALK
        bool

Christophe

author
#5 lore raw

PATCH 2/2 uaccess: minimize INLINE_COPY_USER-related ifdefery

In reply to Yury Norov

Now that we've got the same knob selecting inline vs outline copy_to_user() and copy_from_user(), we can simplify the corresponding logic in the uaccess.h.

---
 include/linux/uaccess.h | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)
include/linux/uaccess.h +8 -13
index 0ddd2806d7f5..19079588c78c 100644
@@ -190,10 +190,6 @@ _inline_copy_from_user(void *to, const void __user *from, unsigned long n)
 	memset(to + (n - res), 0, res);
 	return res;
 }
-#ifndef INLINE_COPY_USER
-extern __must_check unsigned long
-_copy_from_user(void *, const void __user *, unsigned long);
-#endif
 
 static inline __must_check unsigned long
 _inline_copy_to_user(void __user *to, const void *from, unsigned long n)
@@ -207,7 +203,13 @@ _inline_copy_to_user(void __user *to, const void *from, unsigned long n)
 	}
 	return n;
 }
-#ifndef INLINE_COPY_USER
+#ifdef INLINE_COPY_USER
+# define _copy_to_user _inline_copy_to_user
+# define _copy_from_user _inline_copy_from_user
+#else
+extern __must_check unsigned long
+_copy_from_user(void *, const void __user *, unsigned long);
+
 extern __must_check unsigned long
 _copy_to_user(void __user *, const void *, unsigned long);
 #endif
@@ -217,11 +219,8 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
 {
 	if (!check_copy_size(to, n, false))
 		return n;
-#ifdef INLINE_COPY_USER
-	return _inline_copy_from_user(to, from, n);
-#else
+
 	return _copy_from_user(to, from, n);
-#endif
 }
 
 static __always_inline unsigned long __must_check
@@ -230,11 +229,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_USER
-	return _inline_copy_to_user(to, from, n);
-#else
 	return _copy_to_user(to, from, n);
-#endif
 }
 
 #ifndef copy_mc_to_kernel
Signature · 1 line
2.43.0
reviewer Tested-by on v1 2/2
#6 lore raw

Re: [PATCH 2/2] uaccess: minimize INLINE_COPY_USER-related ifdefery

Quoted 5 lines · Yury Norov

Now that we've got the same knob selecting inline vs outline copy_to_user() and copy_from_user(), we can simplify the corresponding logic in the uaccess.h.

Both patches are:

But I can't help but think if it wouldn't be slightly better to split up the first patch in a targeted Fixes: path that just fixes the FROM/TO mixup, and a follow-up non-fix that actually deduplicates the two ifdefs.

include/linux/uaccess.h copy_from_user(void *to, const void __user *from, unsigned long n) · line 224

Quoted 10 lines
include/linux/uaccess.h +1 -4
@@ -217,11 +219,8 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
 {
 	if (!check_copy_size(to, n, false))
 		return n;
-#ifdef INLINE_COPY_USER
-	return _inline_copy_from_user(to, from, n);
-#else
+
 	return _copy_from_user(to, from, n);
-#endif

Spurious extra empty line here?

Alice

#7 lore raw

Re: [PATCH 2/2] uaccess: minimize INLINE_COPY_USER-related ifdefery

In reply to Yury Norov

Le 25/03/2026 à 17:33, Yury Norov a écrit :

Quoted 3 lines

Now that we've got the same knob selecting inline vs outline copy_to_user() and copy_from_user(), we can simplify the corresponding logic in the uaccess.h.

I think we should get rid of ifdefery completly, see below. And with comment to previous patch,

__is_defined(INLINE_COPY_TO_USER)

becomes

!IS_ENABLED(CONFIG_ARCH_WANT_OUTLINE_USER_COPY)

include/linux/uaccess.h +2 -4
index 327f967a24b8..02a05dd61a77 100644
@@ -190,10 +190,9 @@ _inline_copy_from_user(void *to, const void __user *from, unsigned long n)
 	memset(to + (n - res), 0, res);
 	return res;
 }
-#ifndef INLINE_COPY_FROM_USER
+
 extern __must_check unsigned long
 _copy_from_user(void *, const void __user *, unsigned long);
-#endif
 
 static inline __must_check unsigned long
 _inline_copy_to_user(void __user *to, const void *from, unsigned long n)
@@ -207,21 +206,19 @@ _inline_copy_to_user(void __user *to, const void *from, unsigned long n)
 	}
 	return n;
 }
-#ifndef INLINE_COPY_TO_USER
+
 extern __must_check unsigned long
 _copy_to_user(void __user *, const void *, unsigned long);
-#endif
 
 static __always_inline unsigned long __must_check
 copy_from_user_common(void *to, const void __user *from, unsigned long 

n, bool partial)
{
if (!check_copy_size(to, n, false))
return n;
-#ifdef INLINE_COPY_FROM_USER
- return _inline_copy_from_user(to, from, n);
-#else
- return _copy_from_user(to, from, n);
-#endif
+ if (__is_defined(INLINE_COPY_FROM_USER))
+ return _inline_copy_from_user(to, from, n);
+ else
+ return _copy_from_user(to, from, n);
}

static __always_inline unsigned long __must_check
@@ -242,11 +239,10 @@ copy_to_user_common(void __user *to, const void *from, unsigned long n, bool par
if (!check_copy_size(from, n, true))
return n;

-#ifdef INLINE_COPY_TO_USER
- return _inline_copy_to_user(to, from, n);
-#else
- return _copy_to_user(to, from, n);
-#endif
+ if (__is_defined(INLINE_COPY_TO_USER))
+ return _inline_copy_to_user(to, from, n);
+ else
+ return _copy_to_user(to, from, n);
}

static __always_inline unsigned long __must_check

Christophe

author
#8 lore raw

Re: [PATCH 2/2] uaccess: minimize INLINE_COPY_USER-related ifdefery

Quoted 7 lines · Christophe Leroy (CS GROUP)

Le 25/03/2026 à 17:33, Yury Norov a écrit :

Quoted 3 lines

Now that we've got the same knob selecting inline vs outline copy_to_user() and copy_from_user(), we can simplify the corresponding logic in the uaccess.h.

Quoted 8 lines

I think we should get rid of ifdefery completly, see below. And with comment to previous patch,

__is_defined(INLINE_COPY_TO_USER)

becomes

!IS_ENABLED(CONFIG_ARCH_WANT_OUTLINE_USER_COPY)

It's out of the scope of the series. Feel free to submit a follow-up.

Quoted 18 lines
include/linux/uaccess.h +1 -2
index 327f967a24b8..02a05dd61a77 100644
@@ -190,10 +190,9 @@ _inline_copy_from_user(void *to, const void __user
 *from, unsigned long n)
 	memset(to + (n - res), 0, res);
 	return res;
 }
-#ifndef INLINE_COPY_FROM_USER
+
 extern __must_check unsigned long
 _copy_from_user(void *, const void __user *, unsigned long);
-#endif
 
 static inline __must_check unsigned long

_inline_copy_to_user(void __user *to, const void *from, unsigned long n)

include/linux/uaccess.h _inline_copy_to_user(void __user *to, const void · line 214

Quoted 9 lines
include/linux/uaccess.h +1 -2
@@ -207,21 +206,19 @@ _inline_copy_to_user(void __user *to, const void
 *from, unsigned long n)
 	}
 	return n;
 }
-#ifndef INLINE_COPY_TO_USER
+
 extern __must_check unsigned long
 _copy_to_user(void __user *, const void *, unsigned long);
-#endif

This declares a function that may have no implementation. It's wrong.

Quoted 5 lines
include/linux/uaccess.h +0 -0
 static __always_inline unsigned long __must_check
 copy_from_user_common(void *to, const void __user *from, unsigned long n,
 bool partial)
 {
 	if (!check_copy_size(to, n, false))

include/linux/uaccess.h _inline_copy_to_user(void __user *to, const void · line 222

Quoted 10 lines
include/linux/uaccess.h +4 -5
 		return n;
-#ifdef INLINE_COPY_FROM_USER
-	return _inline_copy_from_user(to, from, n);
-#else
-	return _copy_from_user(to, from, n);
-#endif
+	if (__is_defined(INLINE_COPY_FROM_USER))
+		return _inline_copy_from_user(to, from, n);
+	else
+		return _copy_from_user(to, from, n);

To me, this is just another form of ifdefery. I prefer to minimize the number of IS_DEFINED() blocks, just as #ifdef. But it's maybe just me.

Let's merge INLINE_COPY_USER series, and then see how you follow up would look?

Quoted 23 lines
include/linux/uaccess.h +0 -0
 }
 

static __always_inline unsigned long __must_check

include/linux/uaccess.h +0 -0
@@ -242,11 +239,10 @@ copy_to_user_common(void __user *to, const void *from,

unsigned long n, bool par

include/linux/uaccess.h +4 -5
 	if (!check_copy_size(from, n, true))
 		return n;
 
-#ifdef INLINE_COPY_TO_USER
-	return _inline_copy_to_user(to, from, n);
-#else
-	return _copy_to_user(to, from, n);
-#endif
+	if (__is_defined(INLINE_COPY_TO_USER))
+		return _inline_copy_to_user(to, from, n);
+	else
+		return _copy_to_user(to, from, n);
 }
 
 static __always_inline unsigned long __must_check

Christophe

#9 lore raw

Re: [PATCH 2/2] uaccess: minimize INLINE_COPY_USER-related ifdefery

Le 24/04/2026 à 21:50, Yury Norov a écrit :

Quoted 11 lines · Christophe Leroy (CS GROUP)
Quoted 10 lines

Le 25/03/2026 à 17:33, Yury Norov a écrit :

Quoted 3 lines

Now that we've got the same knob selecting inline vs outline copy_to_user() and copy_from_user(), we can simplify the corresponding logic in the uaccess.h.

I think we should get rid of ifdefery completly, see below. And with comment to previous patch,

Quoted 7 lines
Quoted 5 lines

__is_defined(INLINE_COPY_TO_USER)

becomes

!IS_ENABLED(CONFIG_ARCH_WANT_OUTLINE_USER_COPY)

It's out of the scope of the series. Feel free to submit a follow-up.

Why ? Seting an option through a const macro in a header is historical. Nowadays this is done with Kconfig. If you are going to change INLINE_COPY_TO_USER/INLINE_COPY_FROM_USER to a new symbol, why remain with historical/deprecated practice ?

Quoted 16 lines
Quoted 16 lines
include/linux/uaccess.h +1 -2
index 327f967a24b8..02a05dd61a77 100644
@@ -190,10 +190,9 @@ _inline_copy_from_user(void *to, const void __user
 *from, unsigned long n)
  	memset(to + (n - res), 0, res);
  	return res;
  }
-#ifndef INLINE_COPY_FROM_USER
+
  extern __must_check unsigned long
  _copy_from_user(void *, const void __user *, unsigned long);
-#endif
 
Quoted 14 lines

include/linux/uaccess.h _inline_copy_to_user(void __user *to, const void · line 214

Quoted 12 lines
include/linux/uaccess.h +0 -0
  static inline __must_check unsigned long

_inline_copy_to_user(void __user *to, const void *from, unsigned long n)

include/linux/uaccess.h +1 -2
@@ -207,21 +206,19 @@ _inline_copy_to_user(void __user *to, const void
 *from, unsigned long n)
  	}
  	return n;
  }
-#ifndef INLINE_COPY_TO_USER
+
  extern __must_check unsigned long
  _copy_to_user(void __user *, const void *, unsigned long);
-#endif

This declares a function that may have no implementation. It's wrong.

This is common practice in the kernel, what's wrong with that ?

Quoted 11 lines
Quoted 11 lines
include/linux/uaccess.h +0 -4
  static __always_inline unsigned long __must_check
  copy_from_user_common(void *to, const void __user *from, unsigned long n,
 bool partial)
  {
  	if (!check_copy_size(to, n, false))
  		return n;
-#ifdef INLINE_COPY_FROM_USER
-	return _inline_copy_from_user(to, from, n);
-#else
-	return _copy_from_user(to, from, n);
Quoted 8 lines

include/linux/uaccess.h _inline_copy_to_user(void __user *to, const void · line 222

Quoted 5 lines
include/linux/uaccess.h +4 -1
-#endif
+	if (__is_defined(INLINE_COPY_FROM_USER))
+		return _inline_copy_from_user(to, from, n);
+	else
+		return _copy_from_user(to, from, n);

To me, this is just another form of ifdefery. I prefer to minimize the number of IS_DEFINED() blocks, just as #ifdef. But it's maybe just me.

Have you read https://docs.kernel.org/process/coding-style.html#conditional-compilation ?

Quoted 3 lines

Let's merge INLINE_COPY_USER series, and then see how you follow up would look?

Does this series have a real added value ? Is the churn in the arch's asm/uaccess.h worth it ? Why don't go immediatly to a Kconfig option which is the current practice nowadays ?

Christophe

maintainer
#10 lore raw
In reply to Yury Norov
Quoted 8 lines · On Wed, 25 Mar 2026 12:33:10 -0400 Yury Norov <[email protected]> wrote:

Christophe has pointed in [1] that one my patch incorrectly defines rust_helper__copy_to_user() wrapper based on INLINE_COPY_FROM_USER.

Having separate controls for 'from' and 'to' versions is pretty useless, and has proven to be error prone. So, instead of fixing the rust portion, simply switch the kernel to a single knob.

[1] https://lore.kernel.org/all/[email protected]/

Some changelog whining:

As this series is aimed at mainline inclusion, I don't see much value in changelogging which refers to previous development versions of the patchset. That's useful material to include below the ^---$ separator, but it isn't of interest to our target audience: people who are reading this patchset three years hence.

So can we please have a clean description of what this patchset does and why it does it?

Also, [1/2] says

Fixes 1f9a8286bc0c ("uaccess: always export _copy_[from|to]_user with CONFIG_RUST")

but I'm not actually seeing a description of what was wrong with 1f9a8286bc0c. Can we please have a description of the motivation in here somewhere?