Skip to content

Commit 2b95186

Browse files
xry111palmer-dabbelt
authored andcommitted
RISC-V: vDSO: Correct inline assembly constraints in the getrandom syscall wrapper
As recently pointed out by Thomas, if a register is forced for two different register variables, among them one is used as "+" (both input and output) and another is only used as input, Clang would treat the conflicting input parameters as undefined behaviour and optimize away the argument assignment. Instead use "=r" (only output) for the output parameter and "r" (only input) for the input parameter. While the example from the GCC documentation uses "0" for the input parameter, this is not necessary as confirmed by the GCC developers and "r" matches what the other architectures' vDSO implementations are using. [ alex: Update log to match v2 (Thomas) ] Link: https://lore.kernel.org/all/[email protected]/ Link: https://gcc.gnu.org/onlinedocs/gcc-15.1.0/gcc/Local-Register-Variables.html Link: https://gcc.gnu.org/pipermail/gcc-help/2025-June/144266.html Cc: Thomas Weißschuh <[email protected]> Cc: Nathan Chancellor <[email protected]> Signed-off-by: Xi Ruoyao <[email protected]> Reviewed-by: Thomas Weißschuh <[email protected]> Fixes: ee0d030 ("RISC-V: vDSO: Wire up getrandom() vDSO") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexandre Ghiti <[email protected]> Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 4262bd0 commit 2b95186

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static __always_inline ssize_t getrandom_syscall(void *_buffer, size_t _len, uns
1818
register unsigned int flags asm("a2") = _flags;
1919

2020
asm volatile ("ecall\n"
21-
: "+r" (ret)
21+
: "=r" (ret)
2222
: "r" (nr), "r" (buffer), "r" (len), "r" (flags)
2323
: "memory");
2424

0 commit comments

Comments
 (0)