Commit 652b56b1 authored by Samuel Holland's avatar Samuel Holland Committed by Palmer Dabbelt

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: default avatarBjörn Töpel <bjorn@rivosinc.com>
Signed-off-by: default avatarSamuel Holland <samuel.holland@sifive.com>
Link: https://lore.kernel.org/r/20240327160520.791322-2-samuel.holland@sifive.comSigned-off-by: default avatarPalmer Dabbelt <palmer@rivosinc.com>
parent 1613e604
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
#include <linux/types.h> #include <linux/types.h>
#include <asm/asm.h> #include <asm/asm.h>
#define HAVE_JUMP_LABEL_BATCH
#define JUMP_LABEL_NOP_SIZE 4 #define JUMP_LABEL_NOP_SIZE 4
static __always_inline bool arch_static_branch(struct static_key * const key, static __always_inline bool arch_static_branch(struct static_key * const key,
......
...@@ -9,12 +9,13 @@ ...@@ -9,12 +9,13 @@
#include <linux/memory.h> #include <linux/memory.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <asm/bug.h> #include <asm/bug.h>
#include <asm/cacheflush.h>
#include <asm/patch.h> #include <asm/patch.h>
#define RISCV_INSN_NOP 0x00000013U #define RISCV_INSN_NOP 0x00000013U
#define RISCV_INSN_JAL 0x0000006fU #define RISCV_INSN_JAL 0x0000006fU
void arch_jump_label_transform(struct jump_entry *entry, bool arch_jump_label_transform_queue(struct jump_entry *entry,
enum jump_label_type type) enum jump_label_type type)
{ {
void *addr = (void *)jump_entry_code(entry); void *addr = (void *)jump_entry_code(entry);
...@@ -24,7 +25,7 @@ void arch_jump_label_transform(struct jump_entry *entry, ...@@ -24,7 +25,7 @@ void arch_jump_label_transform(struct jump_entry *entry,
long offset = jump_entry_target(entry) - jump_entry_code(entry); long offset = jump_entry_target(entry) - jump_entry_code(entry);
if (WARN_ON(offset & 1 || offset < -524288 || offset >= 524288)) if (WARN_ON(offset & 1 || offset < -524288 || offset >= 524288))
return; return true;
insn = RISCV_INSN_JAL | insn = RISCV_INSN_JAL |
(((u32)offset & GENMASK(19, 12)) << (12 - 12)) | (((u32)offset & GENMASK(19, 12)) << (12 - 12)) |
...@@ -36,6 +37,13 @@ void arch_jump_label_transform(struct jump_entry *entry, ...@@ -36,6 +37,13 @@ void arch_jump_label_transform(struct jump_entry *entry,
} }
mutex_lock(&text_mutex); mutex_lock(&text_mutex);
patch_text_nosync(addr, &insn, sizeof(insn)); patch_insn_write(addr, &insn, sizeof(insn));
mutex_unlock(&text_mutex); mutex_unlock(&text_mutex);
return true;
}
void arch_jump_label_transform_apply(void)
{
flush_icache_all();
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment