Skip to content

Commit 3f6ca2b

Browse files
t-8chSasha Levin
authored andcommitted
LoongArch: vDSO: Correctly use asm parameters in syscall wrappers
commit e242bbb upstream. The syscall wrappers use the "a0" register for two different register variables, both the first argument and the return value. Here the "ret" variable is used as both input and output while the argument register is only used as input. Clang treats the conflicting input parameters as an undefined behaviour and optimizes away the argument assignment. The code seems to work by chance for the most part today but that may change in the future. Specifically clock_gettime_fallback() fails with clockids from 16 to 23, as implemented by the upcoming auxiliary clocks. Switch the "ret" register variable to a pure output, similar to the other architectures' vDSO code. This works in both clang and GCC. Link: https://lore.kernel.org/lkml/20250602102825-42aa84f0-23f1-4d10-89fc-e8bbaffd291a@linutronix.de/ Link: https://lore.kernel.org/lkml/[email protected]/ Fixes: c6b99be ("LoongArch: Add VDSO and VSYSCALL support") Fixes: 18efd0b ("LoongArch: vDSO: Wire up getrandom() vDSO implementation") Cc: [email protected] Reviewed-by: Nathan Chancellor <[email protected]> Reviewed-by: Yanteng Si <[email protected]> Reviewed-by: WANG Xuerui <[email protected]> Reviewed-by: Xi Ruoyao <[email protected]> Signed-off-by: Thomas Weißschuh <[email protected]> Signed-off-by: Huacai Chen <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 61fd40d commit 3f6ca2b

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

arch/loongarch/include/asm/vdso/getrandom.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ static __always_inline ssize_t getrandom_syscall(void *_buffer, size_t _len, uns
2020

2121
asm volatile(
2222
" syscall 0\n"
23-
: "+r" (ret)
23+
: "=r" (ret)
2424
: "r" (nr), "r" (buffer), "r" (len), "r" (flags)
2525
: "$t0", "$t1", "$t2", "$t3", "$t4", "$t5", "$t6", "$t7", "$t8",
2626
"memory");

arch/loongarch/include/asm/vdso/gettimeofday.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static __always_inline long gettimeofday_fallback(
2525

2626
asm volatile(
2727
" syscall 0\n"
28-
: "+r" (ret)
28+
: "=r" (ret)
2929
: "r" (nr), "r" (tv), "r" (tz)
3030
: "$t0", "$t1", "$t2", "$t3", "$t4", "$t5", "$t6", "$t7",
3131
"$t8", "memory");
@@ -44,7 +44,7 @@ static __always_inline long clock_gettime_fallback(
4444

4545
asm volatile(
4646
" syscall 0\n"
47-
: "+r" (ret)
47+
: "=r" (ret)
4848
: "r" (nr), "r" (clkid), "r" (ts)
4949
: "$t0", "$t1", "$t2", "$t3", "$t4", "$t5", "$t6", "$t7",
5050
"$t8", "memory");
@@ -63,7 +63,7 @@ static __always_inline int clock_getres_fallback(
6363

6464
asm volatile(
6565
" syscall 0\n"
66-
: "+r" (ret)
66+
: "=r" (ret)
6767
: "r" (nr), "r" (clkid), "r" (ts)
6868
: "$t0", "$t1", "$t2", "$t3", "$t4", "$t5", "$t6", "$t7",
6969
"$t8", "memory");

0 commit comments

Comments
 (0)