Commit e242bbbb authored by Thomas Weißschuh's avatar Thomas Weißschuh Committed by Huacai Chen
Browse files

LoongArch: vDSO: Correctly use asm parameters in syscall wrappers

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/20250519082042.742926976@linutronix.de/


Fixes: c6b99bed ("LoongArch: Add VDSO and VSYSCALL support")
Fixes: 18efd0b1 ("LoongArch: vDSO: Wire up getrandom() vDSO implementation")
Cc: stable@vger.kernel.org
Reviewed-by: default avatarNathan Chancellor <nathan@kernel.org>
Reviewed-by: default avatarYanteng Si <si.yanteng@linux.dev>
Reviewed-by: default avatarWANG Xuerui <git@xen0n.name>
Reviewed-by: default avatarXi Ruoyao <xry111@xry111.site>
Signed-off-by: default avatarThomas Weißschuh <thomas.weissschuh@linutronix.de>
Signed-off-by: default avatarHuacai Chen <chenhuacai@loongson.cn>
parent ee084fa9
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ static __always_inline ssize_t getrandom_syscall(void *_buffer, size_t _len, uns

	asm volatile(
	"      syscall 0\n"
	: "+r" (ret)
	: "=r" (ret)
	: "r" (nr), "r" (buffer), "r" (len), "r" (flags)
	: "$t0", "$t1", "$t2", "$t3", "$t4", "$t5", "$t6", "$t7", "$t8",
	  "memory");
+3 −3
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ static __always_inline long gettimeofday_fallback(

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

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

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