[RFC 14/15] riscv: ftrace big endian updates

Ben Dooks
2024-12-20T15:58:28Z

Make the ftrace code work with big endian by ensuring the
instruction stream is accessed little endian.

Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
---
arch/riscv/include/asm/ftrace.h | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/riscv/include/asm/ftrace.h b/arch/riscv/include/asm/ftrace.h
index 2cddd79ff21b..233428aeab1d 100644
--- a/arch/riscv/include/asm/ftrace.h
+++ b/arch/riscv/include/asm/ftrace.h
@@ -79,7 +79,7 @@ struct dyn_arch_ftrace {
#define AUIPC_RA (0x00000097)
#define JALR_T0 (0x000282e7)
#define AUIPC_T0 (0x00000297)
-#define NOP4 (0x00000013)
+#define NOP4 (le32_to_cpu(0x00000013))

#define to_jalr_t0(offset) \
(((offset & JALR_OFFSET_MASK) << JALR_SHIFT) | JALR_T0)
@@ -93,8 +93,8 @@ struct dyn_arch_ftrace {
do { \
unsigned int offset = \
(unsigned long) callee - (unsigned long) caller; \
- call[0] = to_auipc_t0(offset); \
- call[1] = to_jalr_t0(offset); \
+ call[0] = cpu_to_le32(to_auipc_t0(offset)); \
+ call[1] = cpu_to_le32(to_jalr_t0(offset)); \
} while (0)

#define to_jalr_ra(offset) \
@@ -109,8 +109,8 @@ do { \
do { \
unsigned int offset = \
(unsigned long) callee - (unsigned long) caller; \
- call[0] = to_auipc_ra(offset); \
- call[1] = to_jalr_ra(offset); \
+ call[0] = cpu_to_le32(to_auipc_ra(offset)); \
+ call[1] = cpu_to_le32(to_jalr_ra(offset)); \
} while (0)

/*