Skip to content

Commit 0de6528

Browse files
jones-drewpalmer-dabbelt
authored andcommitted
RISC-V: selftests: cbo: Ensure asm operands match constraints
The 'i' constraint expects a constant operand, which fn and its constant derivative MK_CBO(fn) are, but passing fn through a function as a parameter and using a local variable for MK_CBO(fn) allow the compiler to lose sight of that when no optimization is done. Use a macro instead of a function and skip the local variable to ensure the compiler uses constants, matching the asm constraints. Reported-by: Yunhui Cui <[email protected]> Closes: https://lore.kernel.org/all/[email protected] Fixes: a29e2a4 ("RISC-V: selftests: Add CBO tests") Signed-off-by: Andrew Jones <[email protected]> Link: https://lore.kernel.org/r/[email protected] Cc: [email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent a894e8e commit 0de6528

File tree

1 file changed

+8
-10
lines changed
  • tools/testing/selftests/riscv/hwprobe

1 file changed

+8
-10
lines changed

tools/testing/selftests/riscv/hwprobe/cbo.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,14 @@ static void sigill_handler(int sig, siginfo_t *info, void *context)
3636
regs[0] += 4;
3737
}
3838

39-
static void cbo_insn(char *base, int fn)
40-
{
41-
uint32_t insn = MK_CBO(fn);
42-
43-
asm volatile(
44-
"mv a0, %0\n"
45-
"li a1, %1\n"
46-
".4byte %2\n"
47-
: : "r" (base), "i" (fn), "i" (insn) : "a0", "a1", "memory");
48-
}
39+
#define cbo_insn(base, fn) \
40+
({ \
41+
asm volatile( \
42+
"mv a0, %0\n" \
43+
"li a1, %1\n" \
44+
".4byte %2\n" \
45+
: : "r" (base), "i" (fn), "i" (MK_CBO(fn)) : "a0", "a1", "memory"); \
46+
})
4947

5048
static void cbo_inval(char *base) { cbo_insn(base, 0); }
5149
static void cbo_clean(char *base) { cbo_insn(base, 1); }

0 commit comments

Comments
 (0)