Skip to content

[PW_SID:968107] riscv: misaligned: fix misaligned accesses handling in put/get_user()#466

Closed
linux-riscv-bot wants to merge 4 commits into
workflow__riscv__for-nextfrom
pw968107
Closed

[PW_SID:968107] riscv: misaligned: fix misaligned accesses handling in put/get_user()#466
linux-riscv-bot wants to merge 4 commits into
workflow__riscv__for-nextfrom
pw968107

Conversation

@linux-riscv-bot
Copy link
Copy Markdown

PR for series 968107 applied to workflow__riscv__for-next

Name: riscv: misaligned: fix misaligned accesses handling in put/get_user()
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=968107
Version: 2

Linux RISC-V bot and others added 4 commits May 14, 2025 13:11
The current implementation is underperforming and in addition, it
triggers misaligned access traps on platforms which do not handle
misaligned accesses in hardware.

Use the existing assembly routines to solve both problems at once.

Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
The specification of prctl() for GET_UNALIGN_CTL states that the value is
returned in an unsigned int * address passed as an unsigned long. Change
the type to match that and avoid an unaligned access as well.

Signed-off-by: Clément Léger <cleger@rivosinc.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
Doing misaligned access to userspace memory would make a trap on
platform where it is emulated. Latest fixes removed the kernel
capability to do unaligned accesses to userspace memory safely since
interrupts are kept disabled at all time during that. Thus doing so
would crash the kernel.

Such behavior was detected with GET_UNALIGN_CTL() that was doing
a put_user() with an unsigned long* address that should have been an
unsigned int*. Reenabling kernel misaligned access emulation is a bit
risky and it would also degrade performances. Rather than doing that,
we will try to avoid any misaligned accessed by using copy_from/to_user()
which does not do any misaligned accesses. This can be done only for
!CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS and thus allows to only generate
a bit more code for this config.

Signed-off-by: Clément Léger <cleger@rivosinc.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2,1/3] riscv: make unsafe user copy routines use existing assembly routines"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 632.68 seconds
Result: ERROR
Output:

Redirect to /build/tmp.ppGIcyBKJY and /build/tmp.6DyT4lA1mF
Tree base:
cf099833ed4da ("Adding CI files")
Building the whole tree with the patch
error:
ld.lld: error: version script assignment of 'LINUX_4.15' to symbol '__vdso_getrandom' failed: symbol not defined
llvm-nm: error: arch/riscv/kernel/compat_vdso/compat_vdso.so.dbg: No such file or directory
/build/tmppsxckitr/arch/riscv/kernel/compat_signal.c:220:28: error: use of undeclared identifier 'compat__vdso_rt_sigreturn_offset'
ld.lld: error: version script assignment of 'LINUX_4.15' to symbol '__vdso_getrandom' failed: symbol not defined
llvm-objcopy: error: 'arch/riscv/kernel/compat_vdso/compat_vdso.so.dbg': No such file or directory



real	10m26.282s
user	404m19.709s
sys	75m6.082s

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2,1/3] riscv: make unsafe user copy routines use existing assembly routines"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 2412.90 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2,1/3] riscv: make unsafe user copy routines use existing assembly routines"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 19.79 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2,1/3] riscv: make unsafe user copy routines use existing assembly routines"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 21.10 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2,1/3] riscv: make unsafe user copy routines use existing assembly routines"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 2.32 seconds
Result: WARNING
Output:

CHECK: Alignment should match open parenthesis
#52: FILE: arch/riscv/include/asm/uaccess.h:454:
+unsigned long __must_check __asm_copy_to_user_sum_enabled(void __user *to,
+	const void *from, unsigned long n);

CHECK: Alignment should match open parenthesis
#54: FILE: arch/riscv/include/asm/uaccess.h:456:
+unsigned long __must_check __asm_copy_from_user_sum_enabled(void *to,
+	const void __user *from, unsigned long n);

WARNING: externs should be avoided in .c files
#92: FILE: arch/riscv/lib/riscv_v_helpers.c:19:
+int __asm_vector_usercopy_sum_enabled(void *dst, void *src, size_t n);

WARNING: externs should be avoided in .c files
#95: FILE: arch/riscv/lib/riscv_v_helpers.c:21:
+int fallback_scalar_usercopy_sum_enabled(void *dst, void *src, size_t n);

WARNING: line length of 113 exceeds 100 columns
#157: FILE: arch/riscv/lib/uaccess.S:45:
+	ALTERNATIVE("j fallback_scalar_usercopy_sum_enabled", "nop", 0, RISCV_ISA_EXT_ZVE32X, CONFIG_RISCV_ISA_V)

total: 0 errors, 3 warnings, 2 checks, 182 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 ec4855ced69e ("riscv: make unsafe user copy routines use existing assembly routines") 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, 3 warnings, 2 checks, 182 lines checked
CHECK: Alignment should match open parenthesis
WARNING: externs should be avoided in .c files
WARNING: line length of 113 exceeds 100 columns


@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2,1/3] riscv: make unsafe user copy routines use existing assembly routines"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 66.95 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2,1/3] riscv: make unsafe user copy routines use existing assembly routines"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.23 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2,1/3] riscv: make unsafe user copy routines use existing assembly routines"
kdoc
Desc: Detects for kdoc errors
Duration: 0.79 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2,1/3] riscv: make unsafe user copy routines use existing assembly routines"
module-param
Desc: Detect module_param changes
Duration: 0.26 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2,1/3] riscv: make unsafe user copy routines use existing assembly routines"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.22 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2,1/3] riscv: make unsafe user copy routines use existing assembly routines"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.30 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[v2,2/3] riscv: process: use unsigned int instead of unsigned long for put_user()"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 632.13 seconds
Result: ERROR
Output:

Redirect to /build/tmp.OtRI3qItkM and /build/tmp.ABz2axLhr0
Tree base:
ec4855ced69e7 ("riscv: make unsafe user copy routines use existing assembly routines")
Building the whole tree with the patch
error:
ld.lld: error: version script assignment of 'LINUX_4.15' to symbol '__vdso_getrandom' failed: symbol not defined
llvm-nm: error: arch/riscv/kernel/compat_vdso/compat_vdso.so.dbg: No such file or directory
ld.lld: error: version script assignment of 'LINUX_4.15' to symbol '__vdso_getrandom' failed: symbol not defined
llvm-objcopy: error: 'arch/riscv/kernel/compat_vdso/compat_vdso.so.dbg': No such file or directory
/build/tmpiwk500or/arch/riscv/kernel/compat_signal.c:220:28: error: use of undeclared identifier 'compat__vdso_rt_sigreturn_offset'



real	10m26.016s
user	404m33.145s
sys	75m2.179s

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[v2,2/3] riscv: process: use unsigned int instead of unsigned long for put_user()"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 1239.81 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[v2,2/3] riscv: process: use unsigned int instead of unsigned long for put_user()"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 19.93 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[v2,2/3] riscv: process: use unsigned int instead of unsigned long for put_user()"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 21.11 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[v2,2/3] riscv: process: use unsigned int instead of unsigned long for put_user()"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 0.72 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[v2,2/3] riscv: process: use unsigned int instead of unsigned long for put_user()"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 66.16 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[v2,2/3] riscv: process: use unsigned int instead of unsigned long for put_user()"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.22 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[v2,2/3] riscv: process: use unsigned int instead of unsigned long for put_user()"
kdoc
Desc: Detects for kdoc errors
Duration: 0.85 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[v2,2/3] riscv: process: use unsigned int instead of unsigned long for put_user()"
module-param
Desc: Detect module_param changes
Duration: 0.24 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[v2,2/3] riscv: process: use unsigned int instead of unsigned long for put_user()"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.22 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 2: "[v2,2/3] riscv: process: use unsigned int instead of unsigned long for put_user()"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.28 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 3: "[v2,3/3] riscv: uaccess: do not do misaligned accesses in get/put_user()"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 632.60 seconds
Result: ERROR
Output:

Redirect to /build/tmp.AQ3jDiaPkM and /build/tmp.WZhPZn0vzL
Tree base:
6c945342ca59c ("riscv: process: use unsigned int instead of unsigned long for put_user()")
Building the whole tree with the patch
error:
ld.lld: error: version script assignment of 'LINUX_4.15' to symbol '__vdso_getrandom' failed: symbol not defined
llvm-nm: error: arch/riscv/kernel/compat_vdso/compat_vdso.so.dbg: No such file or directory
ld.lld: error: version script assignment of 'LINUX_4.15' to symbol '__vdso_getrandom' failed: symbol not defined
llvm-objcopy: error: 'arch/riscv/kernel/compat_vdso/compat_vdso.so.dbg': No such file or directory
/build/tmpfmdna2fy/arch/riscv/kernel/compat_signal.c:220:28: error: use of undeclared identifier 'compat__vdso_rt_sigreturn_offset'



real	10m26.378s
user	404m34.623s
sys	75m6.310s

@linux-riscv-bot linux-riscv-bot force-pushed the workflow__riscv__for-next branch from cf09983 to 5864252 Compare June 2, 2025 22:18
@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 3: "[v2,3/3] riscv: uaccess: do not do misaligned accesses in get/put_user()"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 2411.30 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 3: "[v2,3/3] riscv: uaccess: do not do misaligned accesses in get/put_user()"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 19.94 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 3: "[v2,3/3] riscv: uaccess: do not do misaligned accesses in get/put_user()"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 21.00 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 3: "[v2,3/3] riscv: uaccess: do not do misaligned accesses in get/put_user()"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 1.43 seconds
Result: WARNING
Output:

CHECK: Alignment should match open parenthesis
#40: FILE: arch/riscv/include/asm/uaccess.h:173:
+unsigned long __must_check __asm_copy_to_user_sum_enabled(void __user *to,
+	const void *from, unsigned long n);

CHECK: Alignment should match open parenthesis
#42: FILE: arch/riscv/include/asm/uaccess.h:175:
+unsigned long __must_check __asm_copy_from_user_sum_enabled(void *to,
+	const void __user *from, unsigned long n);

total: 0 errors, 0 warnings, 2 checks, 43 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 ef0f24fdf9f1 ("riscv: uaccess: do not do misaligned accesses in get/put_user()") 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, 0 warnings, 2 checks, 43 lines checked
CHECK: Alignment should match open parenthesis


@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 3: "[v2,3/3] riscv: uaccess: do not do misaligned accesses in get/put_user()"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 67.42 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 3: "[v2,3/3] riscv: uaccess: do not do misaligned accesses in get/put_user()"
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 3: "[v2,3/3] riscv: uaccess: do not do misaligned accesses in get/put_user()"
kdoc
Desc: Detects for kdoc errors
Duration: 0.85 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 3: "[v2,3/3] riscv: uaccess: do not do misaligned accesses in get/put_user()"
module-param
Desc: Detect module_param changes
Duration: 0.24 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 3: "[v2,3/3] riscv: uaccess: do not do misaligned accesses in get/put_user()"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.22 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 3: "[v2,3/3] riscv: uaccess: do not do misaligned accesses in get/put_user()"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.28 seconds
Result: PASS

@linux-riscv-bot linux-riscv-bot force-pushed the workflow__riscv__for-next branch 3 times, most recently from 6481b11 to 6cce6cb Compare June 5, 2025 19:01
@linux-riscv-bot linux-riscv-bot deleted the pw968107 branch June 5, 2025 19:02
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.

2 participants