Skip to content

Commit afa8a93

Browse files
charlie-rivosAlexandre Ghiti
authored andcommitted
riscv: Move nop definition to insn-def.h
We have duplicated the definition of the nop instruction in ftrace.h and in jump_label.c. Move this definition into the generic file insn-def.h so that they can share the definition with each other and with future files. Signed-off-by: Charlie Jenkins <charlie@rivosinc.com> Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com> Tested-by: Alexandre Ghiti <alexghiti@rivosinc.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Link: https://lore.kernel.org/r/20250319-runtime_const_riscv-v10-1-745b31a11d65@rivosinc.com Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
1 parent 2014c95 commit afa8a93

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

arch/riscv/include/asm/ftrace.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ struct dyn_arch_ftrace {
7979
#define AUIPC_RA (0x00000097)
8080
#define JALR_T0 (0x000282e7)
8181
#define AUIPC_T0 (0x00000297)
82-
#define NOP4 (0x00000013)
8382

8483
#define to_jalr_t0(offset) \
8584
(((offset & JALR_OFFSET_MASK) << JALR_SHIFT) | JALR_T0)

arch/riscv/include/asm/insn-def.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,5 +199,8 @@
199199
#define RISCV_PAUSE ".4byte 0x100000f"
200200
#define ZAWRS_WRS_NTO ".4byte 0x00d00073"
201201
#define ZAWRS_WRS_STO ".4byte 0x01d00073"
202+
#define RISCV_NOP4 ".4byte 0x00000013"
203+
204+
#define RISCV_INSN_NOP4 _AC(0x00000013, U)
202205

203206
#endif /* __ASM_INSN_DEF_H */

arch/riscv/kernel/ftrace.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static int ftrace_check_current_call(unsigned long hook_pos,
3636
unsigned int *expected)
3737
{
3838
unsigned int replaced[2];
39-
unsigned int nops[2] = {NOP4, NOP4};
39+
unsigned int nops[2] = {RISCV_INSN_NOP4, RISCV_INSN_NOP4};
4040

4141
/* we expect nops at the hook position */
4242
if (!expected)
@@ -68,7 +68,7 @@ static int __ftrace_modify_call(unsigned long hook_pos, unsigned long target,
6868
bool enable, bool ra)
6969
{
7070
unsigned int call[2];
71-
unsigned int nops[2] = {NOP4, NOP4};
71+
unsigned int nops[2] = {RISCV_INSN_NOP4, RISCV_INSN_NOP4};
7272

7373
if (ra)
7474
make_call_ra(hook_pos, target, call);
@@ -97,7 +97,7 @@ int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
9797
int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec,
9898
unsigned long addr)
9999
{
100-
unsigned int nops[2] = {NOP4, NOP4};
100+
unsigned int nops[2] = {RISCV_INSN_NOP4, RISCV_INSN_NOP4};
101101

102102
if (patch_insn_write((void *)rec->ip, nops, MCOUNT_INSN_SIZE))
103103
return -EPERM;

arch/riscv/kernel/jump_label.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#include <asm/bug.h>
1212
#include <asm/cacheflush.h>
1313
#include <asm/text-patching.h>
14+
#include <asm/insn-def.h>
1415

15-
#define RISCV_INSN_NOP 0x00000013U
1616
#define RISCV_INSN_JAL 0x0000006fU
1717

1818
bool arch_jump_label_transform_queue(struct jump_entry *entry,
@@ -33,7 +33,7 @@ bool arch_jump_label_transform_queue(struct jump_entry *entry,
3333
(((u32)offset & GENMASK(10, 1)) << (21 - 1)) |
3434
(((u32)offset & GENMASK(20, 20)) << (31 - 20));
3535
} else {
36-
insn = RISCV_INSN_NOP;
36+
insn = RISCV_INSN_NOP4;
3737
}
3838

3939
if (early_boot_irqs_disabled) {

0 commit comments

Comments
 (0)