From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 96BF42E1EE5 for ; Thu, 26 Mar 2026 13:44:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774532686; cv=none; b=FH7drbEJ160tImCOLPUIqCcbuT3VOFsuPv/GFcNh0WTL32+/FdLL7FldL1YZKwFeF5GoUnB4H6jy8ZIoqTDGkZQR3GE6V4IsH93mQGCGdaIq4IqLO1dajx+D51GdCaaGXNkT9TVvFTfAIsCTF9VNpeEc6YHkggFsYB1080pZn3o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774532686; c=relaxed/simple; bh=RMt2PKVDBc9/SMombscN+rPVjvTVwbJIX6jCycHypD0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=SAiYCWql4JY8eE8RkY5BT1UQfnm0hUPZbH1UJrp2ywd2/O0zVz0A0qMWtZ+lrZqwV6GRf/F0ElrbS2eBi2zc441dl8NWAcrGqbi9HiwsXVoyTX+BL+Mgy/WfmlqnqqcYkSUTaUgFgzBjMrliobE4RdweIfeUl+YfIJq19r3A6PI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=m/RZwjxG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="m/RZwjxG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E61F2C116C6; Thu, 26 Mar 2026 13:44:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774532686; bh=RMt2PKVDBc9/SMombscN+rPVjvTVwbJIX6jCycHypD0=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=m/RZwjxGzZQME/R5P2rtcdd+B+y89i7bJw8yRgzspvBn528zVOqynTT81DjwDIVIq yT6/W/oa10VIM2NT45585YuZj5Ps+QsJcmyNNuqOAw+36W88QbLoY3EEvFpNn9QKYx M4tmCPTskK+jYUjw1C/UQgcKI1k7RuB4V5sj1vIFuWy5hxT0q4NlEkzyyoyXFtw9Zm 2Kn8rPs3+7gsSW6KLOqkr9aDg3K5vhxYSEbBLvwWGzW25ZY7UXS+zMcH2CmAi2pPZc 0qwADhdDZtDgGsrMOf87jjewj1LPr153YOOR3HEvJ+OPpRvROIauB8bWybudnXbPca 49jtdC/DuXwng== Message-ID: <6ce733b4-5fae-49ac-ab0e-9c87e620e830@kernel.org> Date: Thu, 26 Mar 2026 14:44:40 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2] uaccess: unify inline vs outline copy_{from,to}_user() selection To: Yury Norov , Andrew Morton , Thomas Gleixner , "Peter Zijlstra (Intel)" , Mathieu Desnoyers , Alice Ryhl , Viktor Malik , Randy Dunlap , David Laight , linux-kernel@vger.kernel.org Cc: Yury Norov References: <20260325163313.749336-1-ynorov@nvidia.com> <20260325163313.749336-2-ynorov@nvidia.com> Content-Language: fr-FR From: "Christophe Leroy (CS GROUP)" In-Reply-To: <20260325163313.749336-2-ynorov@nvidia.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Le 25/03/2026 à 17:33, Yury Norov a écrit : > 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): diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index ad7a2fe63a2a..58743cb0e305 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -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 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h index b276f783494c..fb33a71fd24e 100644 --- a/include/asm-generic/uaccess.h +++ b/include/asm-generic/uaccess.h @@ -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 */ /* diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h index 1f3804245c06..bcfa8c11e49f 100644 --- a/include/linux/uaccess.h +++ b/include/linux/uaccess.h @@ -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); diff --git a/lib/Kconfig b/lib/Kconfig index 0f2fb9610647..0106c1facfa4 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -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 diff --git a/lib/usercopy.c b/lib/usercopy.c index b00a3a957de6..aa52ac3f5d6b 100644 --- a/lib/usercopy.c +++ b/lib/usercopy.c @@ -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); diff --git a/rust/helpers/uaccess.c b/rust/helpers/uaccess.c index d9625b9ee046..79d950425dd9 100644 --- a/rust/helpers/uaccess.c +++ b/rust/helpers/uaccess.c @@ -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) { > > Reported-by: "Christophe Leroy (CS GROUP)" > Closes: https://lore.kernel.org/all/746c9c50-20c4-4dc9-a539-bf1310ff9414@kernel.org/ > Fixes: 1f9a8286bc0c ("uaccess: always export _copy_[from|to]_user with CONFIG_RUST") > Signed-off-by: Yury Norov Christophe