mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-29 07:04:10 +08:00
7e6b9db27d
Instead of defaulting to patching NOP opcodes at init time, and leaving it to the architectures to override this if this is not needed, switch to a model where doing nothing is the default. This is the common case by far, as only MIPS requires NOP patching at init time. On all other architectures, the correct encodings are emitted by the compiler and so no initial patching is needed. Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Mark Rutland <mark.rutland@arm.com> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lore.kernel.org/r/20220615154142.1574619-4-ardb@kernel.org
42 lines
1.0 KiB
C
42 lines
1.0 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Copyright (C) 2020 Emil Renner Berthing
|
|
*
|
|
* Based on arch/arm64/kernel/jump_label.c
|
|
*/
|
|
#include <linux/jump_label.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/memory.h>
|
|
#include <linux/mutex.h>
|
|
#include <asm/bug.h>
|
|
#include <asm/patch.h>
|
|
|
|
#define RISCV_INSN_NOP 0x00000013U
|
|
#define RISCV_INSN_JAL 0x0000006fU
|
|
|
|
void arch_jump_label_transform(struct jump_entry *entry,
|
|
enum jump_label_type type)
|
|
{
|
|
void *addr = (void *)jump_entry_code(entry);
|
|
u32 insn;
|
|
|
|
if (type == JUMP_LABEL_JMP) {
|
|
long offset = jump_entry_target(entry) - jump_entry_code(entry);
|
|
|
|
if (WARN_ON(offset & 1 || offset < -524288 || offset >= 524288))
|
|
return;
|
|
|
|
insn = RISCV_INSN_JAL |
|
|
(((u32)offset & GENMASK(19, 12)) << (12 - 12)) |
|
|
(((u32)offset & GENMASK(11, 11)) << (20 - 11)) |
|
|
(((u32)offset & GENMASK(10, 1)) << (21 - 1)) |
|
|
(((u32)offset & GENMASK(20, 20)) << (31 - 20));
|
|
} else {
|
|
insn = RISCV_INSN_NOP;
|
|
}
|
|
|
|
mutex_lock(&text_mutex);
|
|
patch_text_nosync(addr, &insn, sizeof(insn));
|
|
mutex_unlock(&text_mutex);
|
|
}
|