Skip to content

Commit 652b56b

Browse files
SiFiveHollandpalmer-dabbelt
authored andcommitted
riscv: jump_label: Batch icache maintenance
Switch to the batched version of the jump label update functions so instruction cache maintenance is deferred until the end of the update. Reviewed-by: Björn Töpel <[email protected]> Signed-off-by: Samuel Holland <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 1613e60 commit 652b56b

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

arch/riscv/include/asm/jump_label.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <linux/types.h>
1313
#include <asm/asm.h>
1414

15+
#define HAVE_JUMP_LABEL_BATCH
16+
1517
#define JUMP_LABEL_NOP_SIZE 4
1618

1719
static __always_inline bool arch_static_branch(struct static_key * const key,

arch/riscv/kernel/jump_label.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
#include <linux/memory.h>
1010
#include <linux/mutex.h>
1111
#include <asm/bug.h>
12+
#include <asm/cacheflush.h>
1213
#include <asm/patch.h>
1314

1415
#define RISCV_INSN_NOP 0x00000013U
1516
#define RISCV_INSN_JAL 0x0000006fU
1617

17-
void arch_jump_label_transform(struct jump_entry *entry,
18-
enum jump_label_type type)
18+
bool arch_jump_label_transform_queue(struct jump_entry *entry,
19+
enum jump_label_type type)
1920
{
2021
void *addr = (void *)jump_entry_code(entry);
2122
u32 insn;
@@ -24,7 +25,7 @@ void arch_jump_label_transform(struct jump_entry *entry,
2425
long offset = jump_entry_target(entry) - jump_entry_code(entry);
2526

2627
if (WARN_ON(offset & 1 || offset < -524288 || offset >= 524288))
27-
return;
28+
return true;
2829

2930
insn = RISCV_INSN_JAL |
3031
(((u32)offset & GENMASK(19, 12)) << (12 - 12)) |
@@ -36,6 +37,13 @@ void arch_jump_label_transform(struct jump_entry *entry,
3637
}
3738

3839
mutex_lock(&text_mutex);
39-
patch_text_nosync(addr, &insn, sizeof(insn));
40+
patch_insn_write(addr, &insn, sizeof(insn));
4041
mutex_unlock(&text_mutex);
42+
43+
return true;
44+
}
45+
46+
void arch_jump_label_transform_apply(void)
47+
{
48+
flush_icache_all();
4149
}

0 commit comments

Comments
 (0)