Puranjay Mohan <[email protected]> writes:
> The BPF JIT needs to write invalid instructions to RX regions of memory
> to invalidate removed BPF programs. This needs a function like memset()
> that can work with RX memory.
>
> Implement patch_text_set_nosync() which is similar to text_poke_set() of
> x86.
Some additional nits, in addition to the other comments (Song, kernel
test bot, Lehui).
> Signed-off-by: Puranjay Mohan <[email protected]>
> ---
> arch/riscv/include/asm/patch.h | 1 +
> arch/riscv/kernel/patch.c | 74 ++++++++++++++++++++++++++++++++++
> 2 files changed, 75 insertions(+)
>
> diff --git a/arch/riscv/include/asm/patch.h b/arch/riscv/include/asm/patch.h
> index 63c98833d510..aa5c1830ea43 100644
> --- a/arch/riscv/include/asm/patch.h
> +++ b/arch/riscv/include/asm/patch.h
> @@ -7,6 +7,7 @@
> #define _ASM_RISCV_PATCH_H
>
> int patch_text_nosync(void *addr, const void *insns, size_t len);
> +int patch_text_set_nosync(void *addr, const int c, size_t len);
> int patch_text(void *addr, u32 *insns, int ninsns);
>
> extern int riscv_patch_in_stop_machine;
> diff --git a/arch/riscv/kernel/patch.c b/arch/riscv/kernel/patch.c
> index 465b2eebbc37..24d49999ac1a 100644
> --- a/arch/riscv/kernel/patch.c
> +++ b/arch/riscv/kernel/patch.c
> @@ -13,6 +13,7 @@
> #include <asm/fixmap.h>
> #include <asm/ftrace.h>
> #include <asm/patch.h>
> +#include <asm/string.h>
>
> struct patch_insn {
> void *addr;
> @@ -53,6 +54,34 @@ static void patch_unmap(int fixmap)
> }
> NOKPROBE_SYMBOL(patch_unmap);
>
> +static int __patch_insn_set(void *addr, const int c, size_t len)
Drop the "const" from "const int c" everywhere in this patch, and let's
just use u8 instead of int. We don't need to carry the old memset()
legacy argumentts! We're more modern than that! ;-)
Björn