Skip to content

Commit

Permalink
RISC-V: selftests: cbo: Ensure asm operands match constraints, take 2
Browse files Browse the repository at this point in the history
Commit 0de6528 ("RISC-V: selftests: cbo: Ensure asm operands
match constraints") attempted to ensure MK_CBO() would always
provide to a compile-time constant when given a constant, but
cpu_to_le32() isn't necessarily going to do that. Switch to manually
shifting the bytes, when needed, to finally get this right.

Reported-by: Woodrow Shen <woodrow.shen@sifive.com>
Closes: https://lore.kernel.org/all/CABquHATcBTUwfLpd9sPObBgNobqQKEAZ2yxk+TWSpyO5xvpXpg@mail.gmail.com/
Fixes: a29e2a4 ("RISC-V: selftests: Add CBO tests")
Fixes: 0de6528 ("RISC-V: selftests: cbo: Ensure asm operands match constraints")
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
Link: https://lore.kernel.org/r/20240322134728.151255-2-ajones@ventanamicro.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
  • Loading branch information
jones-drew authored and palmer-dabbelt committed Apr 26, 2024
1 parent 9c49085 commit 4940840
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tools/testing/selftests/riscv/hwprobe/cbo.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "hwprobe.h"
#include "../../kselftest.h"

#define MK_CBO(fn) cpu_to_le32((fn) << 20 | 10 << 15 | 2 << 12 | 0 << 7 | 15)
#define MK_CBO(fn) le32_bswap((uint32_t)(fn) << 20 | 10 << 15 | 2 << 12 | 0 << 7 | 15)

static char mem[4096] __aligned(4096) = { [0 ... 4095] = 0xa5 };

Expand Down
10 changes: 10 additions & 0 deletions tools/testing/selftests/riscv/hwprobe/hwprobe.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
#include <stddef.h>
#include <asm/hwprobe.h>

#if __BYTE_ORDER == __BIG_ENDIAN
# define le32_bswap(_x) \
((((_x) & 0x000000ffU) << 24) | \
(((_x) & 0x0000ff00U) << 8) | \
(((_x) & 0x00ff0000U) >> 8) | \
(((_x) & 0xff000000U) >> 24))
#else
# define le32_bswap(_x) (_x)
#endif

/*
* Rather than relying on having a new enough libc to define this, just do it
* ourselves. This way we don't need to be coupled to a new-enough libc to
Expand Down

0 comments on commit 4940840

Please sign in to comment.