Skip to content

[PW_SID:1086311] uaccess: Convert small fixed size copy_{to/from}_user() to scoped user access#1825

Closed
linux-riscv-bot wants to merge 10 commits into
workflowfrom
pw1086311
Closed

[PW_SID:1086311] uaccess: Convert small fixed size copy_{to/from}_user() to scoped user access#1825
linux-riscv-bot wants to merge 10 commits into
workflowfrom
pw1086311

Conversation

@linux-riscv-bot
Copy link
Copy Markdown

PR for series 1086311 applied to workflow

Name: uaccess: Convert small fixed size copy_{to/from}_user() to scoped user access
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1086311
Version: 1

Linux RISC-V bot and others added 10 commits April 26, 2026 22:07
Until commit f5a1a53 ("lib: introduce copy_struct_from_user()
helper"), lib/usercopy.c was containing only the out-line version
of user copy fonctions.

That commit added function check_zeroed_user() into the same file.
Move that function into a new file named usercheck.c, so that next
patch can change usercopy.c build to a conditional build.

Signed-off-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
…efery

Among the 21 architectures supported by the kernel, 16 define both
INLINE_COPY_TO_USER and INLINE_COPY_FROM_USER while the 5 other ones
don't define any of the two.

To simplify and reduce risk of mistakes, convert them to a single
kconfig item named CONFIG_ARCH_WANTS_NOINLINE_COPY which will be
selected by the 5 architectures that don't want inlined copy.

To minimise complication in a later patch, also remove
ifdefery and replace it with IS_ENABLED().

Signed-off-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
fixup_umip_exception() calls copy_to_user() and checks whether
the returned value is strictly positive.

A subsequent patch will change the return of copy_to_user() to
return -EFAULT in case of error.

Change the test to checking that the result is not 0.

At the time being copy_to_user() return an unsigned value so
'strictly positive' is the same as 'not 0'.

Signed-off-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Today there are approximately 3000 calls for copy_to_user() and
3000 calls to copy_from_user().

The majority of callers of copy_{to/from}_user() don't care about the
return value, they only check whether it is 0 or not, and when it is
not 0 they handle it as a -EACCES.

In order to allow better optimisation of copy_{to/from}_user() when
the size of the copy is known at build time, create new fonctions
named copy_{to/from}_user_partial() to be used by the few callers
that are interested in partial copies and need to now how many
bytes remain at the end of the copy.

For the time being it is just the same as copy_{to/from}_user().

Signed-off-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
In a subsequent patch, copy_{to/from}_user() will be modified to
return -EFAULT when copy fails.

Among the 6000 calls to copy_{to/from}_user(), around 2% rely on
copy_{to/from}_user() doing partial copies and returning amount of not
copied bytes. Change those users to copy_{to/from}_user_partial().

This change was done based on whether callers assign the returned value
to a variable or just check whether the return value is 0 or not.

Several of them only use it for debug to print the amount of bytes not
copied. Those could maybe be changed to stop reporting that amount and
not be converted to partial copy.

Some not trivial handling might have been unecessarily converted. This
is not a problem and they can be converted back later for better
performance.

The callers where located with following commands then reviewed one by
one:

	sed -i s/"return copy_to_user("/"return copy_to_user_partial("/g `git grep -l "return copy_to_user("`
	sed -i s/" = copy_to_user("/" = copy_to_user_partial("/g `git grep -l " = copy_to_user("`
	sed -i s/" += copy_to_user("/" += copy_to_user_partial("/g `git grep -l " += copy_to_user("`
	sed -i s/" -= copy_to_user("/" -= copy_to_user_partial("/g `git grep -l " -= copy_to_user("`

Then the same was done with copy_from_user().

During the review, patterns like the following were rejected and kept
as is:

-	return copy_to_user(osf_stat, &tmp, sizeof(tmp)) ? -EFAULT : 0;
+	return copy_to_user_partial(osf_stat, &tmp, sizeof(tmp)) ? -EFAULT : 0;

Signed-off-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Now that copy_{to/from}_user_partial() are used by callers which expect
partial copy with number of not copied bytes as return value, change
copy_{to/from}_user() to return an int, and return -EFAULT when the
copy is not complete.

Signed-off-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
At the time being, x86 and arm64 are missing unsafe_copy_from_user().

Add it.

Signed-off-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
At the time being, x86 and arm64 are missing unsafe_copy_from_user().

Add it.

Signed-off-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
…r access

copy_{to/from}_user() is a heavy function optimised for copy of large
blocs of memory between user and kernel space.

When the number of bytes to be copied is known at build time and small,
using scoped user access removes the burden of that optimisation.

Signed-off-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[RFC,v1,1/9] uaccess: Split check_zeroed_user() out of usercopy.c"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 139.68 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[RFC,v1,1/9] uaccess: Split check_zeroed_user() out of usercopy.c"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 1132.54 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[RFC,v1,1/9] uaccess: Split check_zeroed_user() out of usercopy.c"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 1686.92 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[RFC,v1,1/9] uaccess: Split check_zeroed_user() out of usercopy.c"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 25.96 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[RFC,v1,1/9] uaccess: Split check_zeroed_user() out of usercopy.c"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 26.95 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[RFC,v1,1/9] uaccess: Split check_zeroed_user() out of usercopy.c"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 2.56 seconds
Result: WARNING
Output:

WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#36: 
new file mode 100644

CHECK: No space is necessary after a cast
#66: FILE: lib/usercheck.c:26:
+	uintptr_t align = (uintptr_t) from % sizeof(unsigned long);

CHECK: No space is necessary after a cast
#77: FILE: lib/usercheck.c:37:
+	unsafe_get_user(val, (unsigned long __user *) from, err_fault);

CHECK: No space is necessary after a cast
#88: FILE: lib/usercheck.c:48:
+		unsafe_get_user(val, (unsigned long __user *) from, err_fault);

total: 0 errors, 1 warnings, 3 checks, 85 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 645cf4babfcb ("uaccess: Split check_zeroed_user() out of usercopy.c") has style problems, please review.

NOTE: Ignored message types: ALLOC_SIZEOF_STRUCT CAMELCASE COMMIT_LOG_LONG_LINE GIT_COMMIT_ID MACRO_ARG_REUSE NO_AUTHOR_SIGN_OFF

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.
total: 0 errors, 1 warnings, 3 checks, 85 lines checked
CHECK: No space is necessary after a cast
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?


@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[RFC,v1,1/9] uaccess: Split check_zeroed_user() out of usercopy.c"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 88.66 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[RFC,v1,1/9] uaccess: Split check_zeroed_user() out of usercopy.c"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.24 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[RFC,v1,1/9] uaccess: Split check_zeroed_user() out of usercopy.c"
kdoc
Desc: Detects for kdoc errors
Duration: 0.93 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[RFC,v1,1/9] uaccess: Split check_zeroed_user() out of usercopy.c"
module-param
Desc: Detect module_param changes
Duration: 0.26 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[RFC,v1,1/9] uaccess: Split check_zeroed_user() out of usercopy.c"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.23 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[RFC,v1,1/9] uaccess: Split check_zeroed_user() out of usercopy.c"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.31 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[RFC,v1,2/9] uaccess: Convert INLINE_COPY_{TO/FROM}_USER to kconfig and reduce ifdefery"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 141.14 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[RFC,v1,2/9] uaccess: Convert INLINE_COPY_{TO/FROM}_USER to kconfig and reduce ifdefery"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 2235.13 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[RFC,v1,2/9] uaccess: Convert INLINE_COPY_{TO/FROM}_USER to kconfig and reduce ifdefery"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 3028.98 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[RFC,v1,2/9] uaccess: Convert INLINE_COPY_{TO/FROM}_USER to kconfig and reduce ifdefery"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 25.79 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[RFC,v1,2/9] uaccess: Convert INLINE_COPY_{TO/FROM}_USER to kconfig and reduce ifdefery"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 26.97 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[RFC,v1,2/9] uaccess: Convert INLINE_COPY_{TO/FROM}_USER to kconfig and reduce ifdefery"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 7.35 seconds
Result: WARNING
Output:

WARNING: IS_ENABLED(ARCH_WANTS_NOINLINE_COPY_USER) is normally used as IS_ENABLED(CONFIG_ARCH_WANTS_NOINLINE_COPY_USER)
#411: FILE: include/linux/uaccess.h:218:
+	if (IS_ENABLED(ARCH_WANTS_NOINLINE_COPY_USER))

WARNING: IS_ENABLED(ARCH_WANTS_NOINLINE_COPY_USER) is normally used as IS_ENABLED(CONFIG_ARCH_WANTS_NOINLINE_COPY_USER)
#427: FILE: include/linux/uaccess.h:230:
+	if (IS_ENABLED(ARCH_WANTS_NOINLINE_COPY_USER))

total: 0 errors, 2 warnings, 0 checks, 304 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 4790d0faa675 ("uaccess: Convert INLINE_COPY_{TO/FROM}_USER to kconfig and reduce ifdefery") has style problems, please review.

NOTE: Ignored message types: ALLOC_SIZEOF_STRUCT CAMELCASE COMMIT_LOG_LONG_LINE GIT_COMMIT_ID MACRO_ARG_REUSE NO_AUTHOR_SIGN_OFF

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.
total: 0 errors, 2 warnings, 0 checks, 304 lines checked
WARNING: IS_ENABLED(ARCH_WANTS_NOINLINE_COPY_USER) is normally used as IS_ENABLED(CONFIG_ARCH_WANTS_NOINLINE_COPY_USER)


@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[RFC,v1,2/9] uaccess: Convert INLINE_COPY_{TO/FROM}_USER to kconfig and reduce ifdefery"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 88.38 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[RFC,v1,2/9] uaccess: Convert INLINE_COPY_{TO/FROM}_USER to kconfig and reduce ifdefery"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.29 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 8: "[RFC,v1,8/9] arm64: Add unsafe_copy_from_user()"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.24 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 8: "[RFC,v1,8/9] arm64: Add unsafe_copy_from_user()"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.34 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 9: "[RFC,v1,9/9] uaccess: Convert small fixed size copy_{to/from}_user() to scoped user access"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 139.84 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 9: "[RFC,v1,9/9] uaccess: Convert small fixed size copy_{to/from}_user() to scoped user access"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 2212.23 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 9: "[RFC,v1,9/9] uaccess: Convert small fixed size copy_{to/from}_user() to scoped user access"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 3017.03 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 9: "[RFC,v1,9/9] uaccess: Convert small fixed size copy_{to/from}_user() to scoped user access"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 25.82 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 9: "[RFC,v1,9/9] uaccess: Convert small fixed size copy_{to/from}_user() to scoped user access"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 27.22 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 9: "[RFC,v1,9/9] uaccess: Convert small fixed size copy_{to/from}_user() to scoped user access"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 0.82 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 9: "[RFC,v1,9/9] uaccess: Convert small fixed size copy_{to/from}_user() to scoped user access"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 87.70 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 9: "[RFC,v1,9/9] uaccess: Convert small fixed size copy_{to/from}_user() to scoped user access"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.25 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 9: "[RFC,v1,9/9] uaccess: Convert small fixed size copy_{to/from}_user() to scoped user access"
kdoc
Desc: Detects for kdoc errors
Duration: 0.89 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 9: "[RFC,v1,9/9] uaccess: Convert small fixed size copy_{to/from}_user() to scoped user access"
module-param
Desc: Detect module_param changes
Duration: 0.25 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 9: "[RFC,v1,9/9] uaccess: Convert small fixed size copy_{to/from}_user() to scoped user access"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.23 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 9: "[RFC,v1,9/9] uaccess: Convert small fixed size copy_{to/from}_user() to scoped user access"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.31 seconds
Result: PASS

@linux-riscv-bot linux-riscv-bot force-pushed the workflow branch 14 times, most recently from 7e5dc03 to c37daaa Compare May 5, 2026 02:05
@linux-riscv-bot linux-riscv-bot deleted the pw1086311 branch May 5, 2026 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant