]> git.dujemihanovic.xyz Git - linux.git/commitdiff
RISC-V: selftests: cbo: Ensure asm operands match constraints
authorAndrew Jones <ajones@ventanamicro.com>
Wed, 17 Jan 2024 13:09:34 +0000 (14:09 +0100)
committerPalmer Dabbelt <palmer@rivosinc.com>
Thu, 18 Jan 2024 01:46:55 +0000 (17:46 -0800)
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 <cuiyunhui@bytedance.com>
Closes: https://lore.kernel.org/all/20240117082514.42967-1-cuiyunhui@bytedance.com
Fixes: a29e2a48afe3 ("RISC-V: selftests: Add CBO tests")
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
Link: https://lore.kernel.org/r/20240117130933.57514-2-ajones@ventanamicro.com
Cc: stable@vger.kernel.org
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
tools/testing/selftests/riscv/hwprobe/cbo.c

index c6a83ab11e22336464b499a6127b9910b548efcb..c537d52fafc586d5644ca6f7ec13a4358b4051c0 100644 (file)
@@ -36,16 +36,14 @@ static void sigill_handler(int sig, siginfo_t *info, void *context)
        regs[0] += 4;
 }
 
-static void cbo_insn(char *base, int fn)
-{
-       uint32_t insn = MK_CBO(fn);
-
-       asm volatile(
-       "mv     a0, %0\n"
-       "li     a1, %1\n"
-       ".4byte %2\n"
-       : : "r" (base), "i" (fn), "i" (insn) : "a0", "a1", "memory");
-}
+#define cbo_insn(base, fn)                                                     \
+({                                                                             \
+       asm volatile(                                                           \
+       "mv     a0, %0\n"                                                       \
+       "li     a1, %1\n"                                                       \
+       ".4byte %2\n"                                                           \
+       : : "r" (base), "i" (fn), "i" (MK_CBO(fn)) : "a0", "a1", "memory");     \
+})
 
 static void cbo_inval(char *base) { cbo_insn(base, 0); }
 static void cbo_clean(char *base) { cbo_insn(base, 1); }