Skip to content

Commit 5e63215

Browse files
vwoolpalmer-dabbelt
authored andcommitted
riscv: xip: support runtime trap patching
RISCV_ERRATA_ALTERNATIVE patches text at runtime which is currently not possible when the kernel is executed from the flash in XIP mode. Since runtime patching concerns only traps at the moment, let's just have all the traps reside in RAM anyway if RISCV_ERRATA_ALTERNATIVE is set. Thus, these functions will be patch-able even when the .text section is in flash. Signed-off-by: Vitaly Wool <[email protected]> Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 160ce36 commit 5e63215

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

arch/riscv/kernel/traps.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,13 @@ static void do_trap_error(struct pt_regs *regs, int signo, int code,
8686
}
8787
}
8888

89+
#if defined (CONFIG_XIP_KERNEL) && defined (CONFIG_RISCV_ERRATA_ALTERNATIVE)
90+
#define __trap_section __section(".xip.traps")
91+
#else
92+
#define __trap_section
93+
#endif
8994
#define DO_ERROR_INFO(name, signo, code, str) \
90-
asmlinkage __visible void name(struct pt_regs *regs) \
95+
asmlinkage __visible __trap_section void name(struct pt_regs *regs) \
9196
{ \
9297
do_trap_error(regs, signo, code, regs->epc, "Oops - " str); \
9398
}
@@ -111,15 +116,15 @@ DO_ERROR_INFO(do_trap_store_misaligned,
111116
int handle_misaligned_load(struct pt_regs *regs);
112117
int handle_misaligned_store(struct pt_regs *regs);
113118

114-
asmlinkage void do_trap_load_misaligned(struct pt_regs *regs)
119+
asmlinkage void __trap_section do_trap_load_misaligned(struct pt_regs *regs)
115120
{
116121
if (!handle_misaligned_load(regs))
117122
return;
118123
do_trap_error(regs, SIGBUS, BUS_ADRALN, regs->epc,
119124
"Oops - load address misaligned");
120125
}
121126

122-
asmlinkage void do_trap_store_misaligned(struct pt_regs *regs)
127+
asmlinkage void __trap_section do_trap_store_misaligned(struct pt_regs *regs)
123128
{
124129
if (!handle_misaligned_store(regs))
125130
return;
@@ -146,7 +151,7 @@ static inline unsigned long get_break_insn_length(unsigned long pc)
146151
return GET_INSN_LENGTH(insn);
147152
}
148153

149-
asmlinkage __visible void do_trap_break(struct pt_regs *regs)
154+
asmlinkage __visible __trap_section void do_trap_break(struct pt_regs *regs)
150155
{
151156
#ifdef CONFIG_KPROBES
152157
if (kprobe_single_step_handler(regs))

arch/riscv/kernel/vmlinux-xip.lds.S

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,22 @@ SECTIONS
9999
}
100100
PERCPU_SECTION(L1_CACHE_BYTES)
101101

102-
. = ALIGN(PAGE_SIZE);
102+
. = ALIGN(8);
103+
.alternative : {
104+
__alt_start = .;
105+
*(.alternative)
106+
__alt_end = .;
107+
}
103108
__init_end = .;
104109

110+
. = ALIGN(16);
111+
.xip.traps : {
112+
__xip_traps_start = .;
113+
*(.xip.traps)
114+
__xip_traps_end = .;
115+
}
116+
117+
. = ALIGN(PAGE_SIZE);
105118
.sdata : {
106119
__global_pointer$ = . + 0x800;
107120
*(.sdata*)

0 commit comments

Comments
 (0)