diff mbox series

riscv: patch: Remove redundant functions

Message ID 20240717084102.150914-1-alexghiti@rivosinc.com (mailing list archive)
State Not Applicable
Delegated to: BPF
Headers show
Series riscv: patch: Remove redundant functions | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch
bpf/vmtest-bpf-next-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-5 success Logs for aarch64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Unittests
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Validate matrix.py
bpf/vmtest-bpf-next-VM_Test-10 success Logs for aarch64-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-16 success Logs for s390x-gcc / test (test_verifier, false, 360) / test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-21 success Logs for x86_64-gcc / test (test_maps, false, 360) / test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-17 success Logs for s390x-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-6 success Logs for aarch64-gcc / test (test_maps, false, 360) / test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-15 fail Logs for s390x-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-11 success Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-34 success Logs for x86_64-llvm-17 / veristat
bpf/vmtest-bpf-next-VM_Test-37 success Logs for x86_64-llvm-18 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-19 success Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-12 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-42 success Logs for x86_64-llvm-18 / veristat
bpf/vmtest-bpf-next-VM_Test-8 success Logs for aarch64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-18 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-4 success Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-39 success Logs for x86_64-llvm-18 / test (test_progs_cpuv4, false, 360) / test_progs_cpuv4 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-28 success Logs for x86_64-llvm-17 / build / build for x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-7 success Logs for aarch64-gcc / test (test_progs, false, 360) / test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-36 success Logs for x86_64-llvm-18 / build-release / build for x86_64 with llvm-18-O2
bpf/vmtest-bpf-next-VM_Test-32 success Logs for x86_64-llvm-17 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-24 success Logs for x86_64-gcc / test (test_progs_no_alu32_parallel, true, 30) / test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-41 success Logs for x86_64-llvm-18 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-23 success Logs for x86_64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-38 success Logs for x86_64-llvm-18 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-31 success Logs for x86_64-llvm-17 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-26 success Logs for x86_64-gcc / test (test_verifier, false, 360) / test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-13 success Logs for s390x-gcc / test (test_maps, false, 360) / test_maps on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-30 success Logs for x86_64-llvm-17 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-25 success Logs for x86_64-gcc / test (test_progs_parallel, true, 30) / test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-20 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-9 success Logs for aarch64-gcc / test (test_verifier, false, 360) / test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-29 success Logs for x86_64-llvm-17 / build-release / build for x86_64 with llvm-17-O2
bpf/vmtest-bpf-next-VM_Test-27 success Logs for x86_64-gcc / veristat / veristat on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-35 success Logs for x86_64-llvm-18 / build / build for x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-33 success Logs for x86_64-llvm-17 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-40 success Logs for x86_64-llvm-18 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-22 success Logs for x86_64-gcc / test (test_progs, false, 360) / test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-PR fail PR summary
bpf/vmtest-bpf-next-VM_Test-14 success Logs for s390x-gcc / test (test_progs, false, 360) / test_progs on s390x with gcc

Commit Message

Alexandre Ghiti July 17, 2024, 8:41 a.m. UTC
Commit edf2d546bfd6f5c4 ("riscv: patch: Flush the icache right after
patching to avoid illegal insns") removed the last differences between
patch_text_set_nosync() and patch_insn_set(), and between
patch_text_nosync() and patch_insn_write().

So remove the redundant *_nosync() functions.

Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Closes: https://lore.kernel.org/linux-riscv/CAMuHMdUwx=rU2MWhFTE6KhYHm64phxx2Y6u05-aBLGfeG5696A@mail.gmail.com/
Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
---
 arch/riscv/errata/sifive/errata.c |  4 ++--
 arch/riscv/errata/thead/errata.c  |  2 +-
 arch/riscv/include/asm/patch.h    |  3 +--
 arch/riscv/kernel/alternative.c   |  4 ++--
 arch/riscv/kernel/cpufeature.c    |  2 +-
 arch/riscv/kernel/jump_label.c    |  2 +-
 arch/riscv/kernel/patch.c         | 24 +-----------------------
 arch/riscv/net/bpf_jit_core.c     |  4 ++--
 8 files changed, 11 insertions(+), 34 deletions(-)

Comments

Andrew Jones July 17, 2024, 1:15 p.m. UTC | #1
On Wed, Jul 17, 2024 at 10:41:02AM GMT, Alexandre Ghiti wrote:
> Commit edf2d546bfd6f5c4 ("riscv: patch: Flush the icache right after
> patching to avoid illegal insns") removed the last differences between
> patch_text_set_nosync() and patch_insn_set(), and between
> patch_text_nosync() and patch_insn_write().
> 
> So remove the redundant *_nosync() functions.
> 
> Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
> Closes: https://lore.kernel.org/linux-riscv/CAMuHMdUwx=rU2MWhFTE6KhYHm64phxx2Y6u05-aBLGfeG5696A@mail.gmail.com/
> Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
> ---
>  arch/riscv/errata/sifive/errata.c |  4 ++--
>  arch/riscv/errata/thead/errata.c  |  2 +-
>  arch/riscv/include/asm/patch.h    |  3 +--
>  arch/riscv/kernel/alternative.c   |  4 ++--
>  arch/riscv/kernel/cpufeature.c    |  2 +-
>  arch/riscv/kernel/jump_label.c    |  2 +-
>  arch/riscv/kernel/patch.c         | 24 +-----------------------
>  arch/riscv/net/bpf_jit_core.c     |  4 ++--
>  8 files changed, 11 insertions(+), 34 deletions(-)
>

Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Samuel Holland July 19, 2024, 1:55 a.m. UTC | #2
Hi Alex,

On 2024-07-17 3:41 AM, Alexandre Ghiti wrote:
> Commit edf2d546bfd6f5c4 ("riscv: patch: Flush the icache right after
> patching to avoid illegal insns") removed the last differences between
> patch_text_set_nosync() and patch_insn_set(), and between
> patch_text_nosync() and patch_insn_write().
> 
> So remove the redundant *_nosync() functions.

My understanding was that we would eventually revert that patch, once we are
sure we never non-atomically patch the text patching code. So it's helpful to
keep the semantic distinction between the two sets of functions.

And looking at this closer, I think the original patch should not have removed
the calls to flush_icache_range() anyway. It replaces a global icache flush with
a local icache flush, which is wrong if there is more than one CPU online, and
there are a couple of places (bpf_jit_core.c, kprobes.c) where those functions
are called at runtime.

Regards,
Samuel

> Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
> Closes: https://lore.kernel.org/linux-riscv/CAMuHMdUwx=rU2MWhFTE6KhYHm64phxx2Y6u05-aBLGfeG5696A@mail.gmail.com/
> Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
> ---
>  arch/riscv/errata/sifive/errata.c |  4 ++--
>  arch/riscv/errata/thead/errata.c  |  2 +-
>  arch/riscv/include/asm/patch.h    |  3 +--
>  arch/riscv/kernel/alternative.c   |  4 ++--
>  arch/riscv/kernel/cpufeature.c    |  2 +-
>  arch/riscv/kernel/jump_label.c    |  2 +-
>  arch/riscv/kernel/patch.c         | 24 +-----------------------
>  arch/riscv/net/bpf_jit_core.c     |  4 ++--
>  8 files changed, 11 insertions(+), 34 deletions(-)
> 
> diff --git a/arch/riscv/errata/sifive/errata.c b/arch/riscv/errata/sifive/errata.c
> index 716cfedad3a2..5253b205aa17 100644
> --- a/arch/riscv/errata/sifive/errata.c
> +++ b/arch/riscv/errata/sifive/errata.c
> @@ -112,8 +112,8 @@ void sifive_errata_patch_func(struct alt_entry *begin, struct alt_entry *end,
>  		tmp = (1U << alt->patch_id);
>  		if (cpu_req_errata & tmp) {
>  			mutex_lock(&text_mutex);
> -			patch_text_nosync(ALT_OLD_PTR(alt), ALT_ALT_PTR(alt),
> -					  alt->alt_len);
> +			patch_insn_write(ALT_OLD_PTR(alt), ALT_ALT_PTR(alt),
> +					 alt->alt_len);
>  			mutex_unlock(&text_mutex);
>  			cpu_apply_errata |= tmp;
>  		}
> diff --git a/arch/riscv/errata/thead/errata.c b/arch/riscv/errata/thead/errata.c
> index bf6a0a6318ee..0ce280a190b6 100644
> --- a/arch/riscv/errata/thead/errata.c
> +++ b/arch/riscv/errata/thead/errata.c
> @@ -182,7 +182,7 @@ void thead_errata_patch_func(struct alt_entry *begin, struct alt_entry *end,
>  				memcpy(oldptr, altptr, alt->alt_len);
>  			} else {
>  				mutex_lock(&text_mutex);
> -				patch_text_nosync(oldptr, altptr, alt->alt_len);
> +				patch_insn_write(oldptr, altptr, alt->alt_len);
>  				mutex_unlock(&text_mutex);
>  			}
>  		}
> diff --git a/arch/riscv/include/asm/patch.h b/arch/riscv/include/asm/patch.h
> index 9f5d6e14c405..6b0e9b8a321b 100644
> --- a/arch/riscv/include/asm/patch.h
> +++ b/arch/riscv/include/asm/patch.h
> @@ -6,9 +6,8 @@
>  #ifndef _ASM_RISCV_PATCH_H
>  #define _ASM_RISCV_PATCH_H
>  
> +int patch_insn_set(void *addr, u8 c, size_t len);
>  int patch_insn_write(void *addr, const void *insn, size_t len);
> -int patch_text_nosync(void *addr, const void *insns, size_t len);
> -int patch_text_set_nosync(void *addr, u8 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/alternative.c b/arch/riscv/kernel/alternative.c
> index 0128b161bfda..a8b508d99cf8 100644
> --- a/arch/riscv/kernel/alternative.c
> +++ b/arch/riscv/kernel/alternative.c
> @@ -83,7 +83,7 @@ static void riscv_alternative_fix_auipc_jalr(void *ptr, u32 auipc_insn,
>  	riscv_insn_insert_utype_itype_imm(&call[0], &call[1], imm);
>  
>  	/* patch the call place again */
> -	patch_text_nosync(ptr, call, sizeof(u32) * 2);
> +	patch_insn_write(ptr, call, sizeof(u32) * 2);
>  }
>  
>  static void riscv_alternative_fix_jal(void *ptr, u32 jal_insn, int patch_offset)
> @@ -98,7 +98,7 @@ static void riscv_alternative_fix_jal(void *ptr, u32 jal_insn, int patch_offset)
>  	riscv_insn_insert_jtype_imm(&jal_insn, imm);
>  
>  	/* patch the call place again */
> -	patch_text_nosync(ptr, &jal_insn, sizeof(u32));
> +	patch_insn_write(ptr, &jal_insn, sizeof(u32));
>  }
>  
>  void riscv_alternative_fix_offsets(void *alt_ptr, unsigned int len,
> diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c
> index 5ef48cb20ee1..4c040a857c7e 100644
> --- a/arch/riscv/kernel/cpufeature.c
> +++ b/arch/riscv/kernel/cpufeature.c
> @@ -795,7 +795,7 @@ void __init_or_module riscv_cpufeature_patch_func(struct alt_entry *begin,
>  		altptr = ALT_ALT_PTR(alt);
>  
>  		mutex_lock(&text_mutex);
> -		patch_text_nosync(oldptr, altptr, alt->alt_len);
> +		patch_insn_write(oldptr, altptr, alt->alt_len);
>  		riscv_alternative_fix_offsets(oldptr, alt->alt_len, oldptr - altptr);
>  		mutex_unlock(&text_mutex);
>  	}
> diff --git a/arch/riscv/kernel/jump_label.c b/arch/riscv/kernel/jump_label.c
> index e6694759dbd0..74b5ebfacf4a 100644
> --- a/arch/riscv/kernel/jump_label.c
> +++ b/arch/riscv/kernel/jump_label.c
> @@ -36,6 +36,6 @@ void arch_jump_label_transform(struct jump_entry *entry,
>  	}
>  
>  	mutex_lock(&text_mutex);
> -	patch_text_nosync(addr, &insn, sizeof(insn));
> +	patch_insn_write(addr, &insn, sizeof(insn));
>  	mutex_unlock(&text_mutex);
>  }
> diff --git a/arch/riscv/kernel/patch.c b/arch/riscv/kernel/patch.c
> index ab03732d06c4..bf45b507f900 100644
> --- a/arch/riscv/kernel/patch.c
> +++ b/arch/riscv/kernel/patch.c
> @@ -177,7 +177,7 @@ static int __patch_insn_write(void *addr, const void *insn, size_t len)
>  NOKPROBE_SYMBOL(__patch_insn_write);
>  #endif /* CONFIG_MMU */
>  
> -static int patch_insn_set(void *addr, u8 c, size_t len)
> +int patch_insn_set(void *addr, u8 c, size_t len)
>  {
>  	size_t patched = 0;
>  	size_t size;
> @@ -198,17 +198,6 @@ static int patch_insn_set(void *addr, u8 c, size_t len)
>  }
>  NOKPROBE_SYMBOL(patch_insn_set);
>  
> -int patch_text_set_nosync(void *addr, u8 c, size_t len)
> -{
> -	u32 *tp = addr;
> -	int ret;
> -
> -	ret = patch_insn_set(tp, c, len);
> -
> -	return ret;
> -}
> -NOKPROBE_SYMBOL(patch_text_set_nosync);
> -
>  int patch_insn_write(void *addr, const void *insn, size_t len)
>  {
>  	size_t patched = 0;
> @@ -230,17 +219,6 @@ int patch_insn_write(void *addr, const void *insn, size_t len)
>  }
>  NOKPROBE_SYMBOL(patch_insn_write);
>  
> -int patch_text_nosync(void *addr, const void *insns, size_t len)
> -{
> -	u32 *tp = addr;
> -	int ret;
> -
> -	ret = patch_insn_write(tp, insns, len);
> -
> -	return ret;
> -}
> -NOKPROBE_SYMBOL(patch_text_nosync);
> -
>  static int patch_text_cb(void *data)
>  {
>  	struct patch_insn *patch = data;
> diff --git a/arch/riscv/net/bpf_jit_core.c b/arch/riscv/net/bpf_jit_core.c
> index 0a96abdaca65..b053ae5c4191 100644
> --- a/arch/riscv/net/bpf_jit_core.c
> +++ b/arch/riscv/net/bpf_jit_core.c
> @@ -226,7 +226,7 @@ void *bpf_arch_text_copy(void *dst, void *src, size_t len)
>  	int ret;
>  
>  	mutex_lock(&text_mutex);
> -	ret = patch_text_nosync(dst, src, len);
> +	ret = patch_insn_write(dst, src, len);
>  	mutex_unlock(&text_mutex);
>  
>  	if (ret)
> @@ -240,7 +240,7 @@ int bpf_arch_text_invalidate(void *dst, size_t len)
>  	int ret;
>  
>  	mutex_lock(&text_mutex);
> -	ret = patch_text_set_nosync(dst, 0, len);
> +	ret = patch_insn_set(dst, 0, len);
>  	mutex_unlock(&text_mutex);
>  
>  	return ret;
Alexandre Ghiti July 19, 2024, 12:10 p.m. UTC | #3
On Fri, Jul 19, 2024 at 3:56 AM Samuel Holland
<samuel.holland@sifive.com> wrote:
>
> Hi Alex,
>
> On 2024-07-17 3:41 AM, Alexandre Ghiti wrote:
> > Commit edf2d546bfd6f5c4 ("riscv: patch: Flush the icache right after
> > patching to avoid illegal insns") removed the last differences between
> > patch_text_set_nosync() and patch_insn_set(), and between
> > patch_text_nosync() and patch_insn_write().
> >
> > So remove the redundant *_nosync() functions.
>
> My understanding was that we would eventually revert that patch, once we are
> sure we never non-atomically patch the text patching code. So it's helpful to
> keep the semantic distinction between the two sets of functions.
>
> And looking at this closer, I think the original patch should not have removed
> the calls to flush_icache_range() anyway. It replaces a global icache flush with
> a local icache flush, which is wrong if there is more than one CPU online, and
> there are a couple of places (bpf_jit_core.c, kprobes.c) where those functions
> are called at runtime.

Ouch, thanks for catching this, I agree the global icache flush should
not have been removed.

I'll fix that right now,

Thanks,

Alex

>
> Regards,
> Samuel
>
> > Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
> > Closes: https://lore.kernel.org/linux-riscv/CAMuHMdUwx=rU2MWhFTE6KhYHm64phxx2Y6u05-aBLGfeG5696A@mail.gmail.com/
> > Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
> > ---
> >  arch/riscv/errata/sifive/errata.c |  4 ++--
> >  arch/riscv/errata/thead/errata.c  |  2 +-
> >  arch/riscv/include/asm/patch.h    |  3 +--
> >  arch/riscv/kernel/alternative.c   |  4 ++--
> >  arch/riscv/kernel/cpufeature.c    |  2 +-
> >  arch/riscv/kernel/jump_label.c    |  2 +-
> >  arch/riscv/kernel/patch.c         | 24 +-----------------------
> >  arch/riscv/net/bpf_jit_core.c     |  4 ++--
> >  8 files changed, 11 insertions(+), 34 deletions(-)
> >
> > diff --git a/arch/riscv/errata/sifive/errata.c b/arch/riscv/errata/sifive/errata.c
> > index 716cfedad3a2..5253b205aa17 100644
> > --- a/arch/riscv/errata/sifive/errata.c
> > +++ b/arch/riscv/errata/sifive/errata.c
> > @@ -112,8 +112,8 @@ void sifive_errata_patch_func(struct alt_entry *begin, struct alt_entry *end,
> >               tmp = (1U << alt->patch_id);
> >               if (cpu_req_errata & tmp) {
> >                       mutex_lock(&text_mutex);
> > -                     patch_text_nosync(ALT_OLD_PTR(alt), ALT_ALT_PTR(alt),
> > -                                       alt->alt_len);
> > +                     patch_insn_write(ALT_OLD_PTR(alt), ALT_ALT_PTR(alt),
> > +                                      alt->alt_len);
> >                       mutex_unlock(&text_mutex);
> >                       cpu_apply_errata |= tmp;
> >               }
> > diff --git a/arch/riscv/errata/thead/errata.c b/arch/riscv/errata/thead/errata.c
> > index bf6a0a6318ee..0ce280a190b6 100644
> > --- a/arch/riscv/errata/thead/errata.c
> > +++ b/arch/riscv/errata/thead/errata.c
> > @@ -182,7 +182,7 @@ void thead_errata_patch_func(struct alt_entry *begin, struct alt_entry *end,
> >                               memcpy(oldptr, altptr, alt->alt_len);
> >                       } else {
> >                               mutex_lock(&text_mutex);
> > -                             patch_text_nosync(oldptr, altptr, alt->alt_len);
> > +                             patch_insn_write(oldptr, altptr, alt->alt_len);
> >                               mutex_unlock(&text_mutex);
> >                       }
> >               }
> > diff --git a/arch/riscv/include/asm/patch.h b/arch/riscv/include/asm/patch.h
> > index 9f5d6e14c405..6b0e9b8a321b 100644
> > --- a/arch/riscv/include/asm/patch.h
> > +++ b/arch/riscv/include/asm/patch.h
> > @@ -6,9 +6,8 @@
> >  #ifndef _ASM_RISCV_PATCH_H
> >  #define _ASM_RISCV_PATCH_H
> >
> > +int patch_insn_set(void *addr, u8 c, size_t len);
> >  int patch_insn_write(void *addr, const void *insn, size_t len);
> > -int patch_text_nosync(void *addr, const void *insns, size_t len);
> > -int patch_text_set_nosync(void *addr, u8 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/alternative.c b/arch/riscv/kernel/alternative.c
> > index 0128b161bfda..a8b508d99cf8 100644
> > --- a/arch/riscv/kernel/alternative.c
> > +++ b/arch/riscv/kernel/alternative.c
> > @@ -83,7 +83,7 @@ static void riscv_alternative_fix_auipc_jalr(void *ptr, u32 auipc_insn,
> >       riscv_insn_insert_utype_itype_imm(&call[0], &call[1], imm);
> >
> >       /* patch the call place again */
> > -     patch_text_nosync(ptr, call, sizeof(u32) * 2);
> > +     patch_insn_write(ptr, call, sizeof(u32) * 2);
> >  }
> >
> >  static void riscv_alternative_fix_jal(void *ptr, u32 jal_insn, int patch_offset)
> > @@ -98,7 +98,7 @@ static void riscv_alternative_fix_jal(void *ptr, u32 jal_insn, int patch_offset)
> >       riscv_insn_insert_jtype_imm(&jal_insn, imm);
> >
> >       /* patch the call place again */
> > -     patch_text_nosync(ptr, &jal_insn, sizeof(u32));
> > +     patch_insn_write(ptr, &jal_insn, sizeof(u32));
> >  }
> >
> >  void riscv_alternative_fix_offsets(void *alt_ptr, unsigned int len,
> > diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c
> > index 5ef48cb20ee1..4c040a857c7e 100644
> > --- a/arch/riscv/kernel/cpufeature.c
> > +++ b/arch/riscv/kernel/cpufeature.c
> > @@ -795,7 +795,7 @@ void __init_or_module riscv_cpufeature_patch_func(struct alt_entry *begin,
> >               altptr = ALT_ALT_PTR(alt);
> >
> >               mutex_lock(&text_mutex);
> > -             patch_text_nosync(oldptr, altptr, alt->alt_len);
> > +             patch_insn_write(oldptr, altptr, alt->alt_len);
> >               riscv_alternative_fix_offsets(oldptr, alt->alt_len, oldptr - altptr);
> >               mutex_unlock(&text_mutex);
> >       }
> > diff --git a/arch/riscv/kernel/jump_label.c b/arch/riscv/kernel/jump_label.c
> > index e6694759dbd0..74b5ebfacf4a 100644
> > --- a/arch/riscv/kernel/jump_label.c
> > +++ b/arch/riscv/kernel/jump_label.c
> > @@ -36,6 +36,6 @@ void arch_jump_label_transform(struct jump_entry *entry,
> >       }
> >
> >       mutex_lock(&text_mutex);
> > -     patch_text_nosync(addr, &insn, sizeof(insn));
> > +     patch_insn_write(addr, &insn, sizeof(insn));
> >       mutex_unlock(&text_mutex);
> >  }
> > diff --git a/arch/riscv/kernel/patch.c b/arch/riscv/kernel/patch.c
> > index ab03732d06c4..bf45b507f900 100644
> > --- a/arch/riscv/kernel/patch.c
> > +++ b/arch/riscv/kernel/patch.c
> > @@ -177,7 +177,7 @@ static int __patch_insn_write(void *addr, const void *insn, size_t len)
> >  NOKPROBE_SYMBOL(__patch_insn_write);
> >  #endif /* CONFIG_MMU */
> >
> > -static int patch_insn_set(void *addr, u8 c, size_t len)
> > +int patch_insn_set(void *addr, u8 c, size_t len)
> >  {
> >       size_t patched = 0;
> >       size_t size;
> > @@ -198,17 +198,6 @@ static int patch_insn_set(void *addr, u8 c, size_t len)
> >  }
> >  NOKPROBE_SYMBOL(patch_insn_set);
> >
> > -int patch_text_set_nosync(void *addr, u8 c, size_t len)
> > -{
> > -     u32 *tp = addr;
> > -     int ret;
> > -
> > -     ret = patch_insn_set(tp, c, len);
> > -
> > -     return ret;
> > -}
> > -NOKPROBE_SYMBOL(patch_text_set_nosync);
> > -
> >  int patch_insn_write(void *addr, const void *insn, size_t len)
> >  {
> >       size_t patched = 0;
> > @@ -230,17 +219,6 @@ int patch_insn_write(void *addr, const void *insn, size_t len)
> >  }
> >  NOKPROBE_SYMBOL(patch_insn_write);
> >
> > -int patch_text_nosync(void *addr, const void *insns, size_t len)
> > -{
> > -     u32 *tp = addr;
> > -     int ret;
> > -
> > -     ret = patch_insn_write(tp, insns, len);
> > -
> > -     return ret;
> > -}
> > -NOKPROBE_SYMBOL(patch_text_nosync);
> > -
> >  static int patch_text_cb(void *data)
> >  {
> >       struct patch_insn *patch = data;
> > diff --git a/arch/riscv/net/bpf_jit_core.c b/arch/riscv/net/bpf_jit_core.c
> > index 0a96abdaca65..b053ae5c4191 100644
> > --- a/arch/riscv/net/bpf_jit_core.c
> > +++ b/arch/riscv/net/bpf_jit_core.c
> > @@ -226,7 +226,7 @@ void *bpf_arch_text_copy(void *dst, void *src, size_t len)
> >       int ret;
> >
> >       mutex_lock(&text_mutex);
> > -     ret = patch_text_nosync(dst, src, len);
> > +     ret = patch_insn_write(dst, src, len);
> >       mutex_unlock(&text_mutex);
> >
> >       if (ret)
> > @@ -240,7 +240,7 @@ int bpf_arch_text_invalidate(void *dst, size_t len)
> >       int ret;
> >
> >       mutex_lock(&text_mutex);
> > -     ret = patch_text_set_nosync(dst, 0, len);
> > +     ret = patch_insn_set(dst, 0, len);
> >       mutex_unlock(&text_mutex);
> >
> >       return ret;
>
diff mbox series

Patch

diff --git a/arch/riscv/errata/sifive/errata.c b/arch/riscv/errata/sifive/errata.c
index 716cfedad3a2..5253b205aa17 100644
--- a/arch/riscv/errata/sifive/errata.c
+++ b/arch/riscv/errata/sifive/errata.c
@@ -112,8 +112,8 @@  void sifive_errata_patch_func(struct alt_entry *begin, struct alt_entry *end,
 		tmp = (1U << alt->patch_id);
 		if (cpu_req_errata & tmp) {
 			mutex_lock(&text_mutex);
-			patch_text_nosync(ALT_OLD_PTR(alt), ALT_ALT_PTR(alt),
-					  alt->alt_len);
+			patch_insn_write(ALT_OLD_PTR(alt), ALT_ALT_PTR(alt),
+					 alt->alt_len);
 			mutex_unlock(&text_mutex);
 			cpu_apply_errata |= tmp;
 		}
diff --git a/arch/riscv/errata/thead/errata.c b/arch/riscv/errata/thead/errata.c
index bf6a0a6318ee..0ce280a190b6 100644
--- a/arch/riscv/errata/thead/errata.c
+++ b/arch/riscv/errata/thead/errata.c
@@ -182,7 +182,7 @@  void thead_errata_patch_func(struct alt_entry *begin, struct alt_entry *end,
 				memcpy(oldptr, altptr, alt->alt_len);
 			} else {
 				mutex_lock(&text_mutex);
-				patch_text_nosync(oldptr, altptr, alt->alt_len);
+				patch_insn_write(oldptr, altptr, alt->alt_len);
 				mutex_unlock(&text_mutex);
 			}
 		}
diff --git a/arch/riscv/include/asm/patch.h b/arch/riscv/include/asm/patch.h
index 9f5d6e14c405..6b0e9b8a321b 100644
--- a/arch/riscv/include/asm/patch.h
+++ b/arch/riscv/include/asm/patch.h
@@ -6,9 +6,8 @@ 
 #ifndef _ASM_RISCV_PATCH_H
 #define _ASM_RISCV_PATCH_H
 
+int patch_insn_set(void *addr, u8 c, size_t len);
 int patch_insn_write(void *addr, const void *insn, size_t len);
-int patch_text_nosync(void *addr, const void *insns, size_t len);
-int patch_text_set_nosync(void *addr, u8 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/alternative.c b/arch/riscv/kernel/alternative.c
index 0128b161bfda..a8b508d99cf8 100644
--- a/arch/riscv/kernel/alternative.c
+++ b/arch/riscv/kernel/alternative.c
@@ -83,7 +83,7 @@  static void riscv_alternative_fix_auipc_jalr(void *ptr, u32 auipc_insn,
 	riscv_insn_insert_utype_itype_imm(&call[0], &call[1], imm);
 
 	/* patch the call place again */
-	patch_text_nosync(ptr, call, sizeof(u32) * 2);
+	patch_insn_write(ptr, call, sizeof(u32) * 2);
 }
 
 static void riscv_alternative_fix_jal(void *ptr, u32 jal_insn, int patch_offset)
@@ -98,7 +98,7 @@  static void riscv_alternative_fix_jal(void *ptr, u32 jal_insn, int patch_offset)
 	riscv_insn_insert_jtype_imm(&jal_insn, imm);
 
 	/* patch the call place again */
-	patch_text_nosync(ptr, &jal_insn, sizeof(u32));
+	patch_insn_write(ptr, &jal_insn, sizeof(u32));
 }
 
 void riscv_alternative_fix_offsets(void *alt_ptr, unsigned int len,
diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c
index 5ef48cb20ee1..4c040a857c7e 100644
--- a/arch/riscv/kernel/cpufeature.c
+++ b/arch/riscv/kernel/cpufeature.c
@@ -795,7 +795,7 @@  void __init_or_module riscv_cpufeature_patch_func(struct alt_entry *begin,
 		altptr = ALT_ALT_PTR(alt);
 
 		mutex_lock(&text_mutex);
-		patch_text_nosync(oldptr, altptr, alt->alt_len);
+		patch_insn_write(oldptr, altptr, alt->alt_len);
 		riscv_alternative_fix_offsets(oldptr, alt->alt_len, oldptr - altptr);
 		mutex_unlock(&text_mutex);
 	}
diff --git a/arch/riscv/kernel/jump_label.c b/arch/riscv/kernel/jump_label.c
index e6694759dbd0..74b5ebfacf4a 100644
--- a/arch/riscv/kernel/jump_label.c
+++ b/arch/riscv/kernel/jump_label.c
@@ -36,6 +36,6 @@  void arch_jump_label_transform(struct jump_entry *entry,
 	}
 
 	mutex_lock(&text_mutex);
-	patch_text_nosync(addr, &insn, sizeof(insn));
+	patch_insn_write(addr, &insn, sizeof(insn));
 	mutex_unlock(&text_mutex);
 }
diff --git a/arch/riscv/kernel/patch.c b/arch/riscv/kernel/patch.c
index ab03732d06c4..bf45b507f900 100644
--- a/arch/riscv/kernel/patch.c
+++ b/arch/riscv/kernel/patch.c
@@ -177,7 +177,7 @@  static int __patch_insn_write(void *addr, const void *insn, size_t len)
 NOKPROBE_SYMBOL(__patch_insn_write);
 #endif /* CONFIG_MMU */
 
-static int patch_insn_set(void *addr, u8 c, size_t len)
+int patch_insn_set(void *addr, u8 c, size_t len)
 {
 	size_t patched = 0;
 	size_t size;
@@ -198,17 +198,6 @@  static int patch_insn_set(void *addr, u8 c, size_t len)
 }
 NOKPROBE_SYMBOL(patch_insn_set);
 
-int patch_text_set_nosync(void *addr, u8 c, size_t len)
-{
-	u32 *tp = addr;
-	int ret;
-
-	ret = patch_insn_set(tp, c, len);
-
-	return ret;
-}
-NOKPROBE_SYMBOL(patch_text_set_nosync);
-
 int patch_insn_write(void *addr, const void *insn, size_t len)
 {
 	size_t patched = 0;
@@ -230,17 +219,6 @@  int patch_insn_write(void *addr, const void *insn, size_t len)
 }
 NOKPROBE_SYMBOL(patch_insn_write);
 
-int patch_text_nosync(void *addr, const void *insns, size_t len)
-{
-	u32 *tp = addr;
-	int ret;
-
-	ret = patch_insn_write(tp, insns, len);
-
-	return ret;
-}
-NOKPROBE_SYMBOL(patch_text_nosync);
-
 static int patch_text_cb(void *data)
 {
 	struct patch_insn *patch = data;
diff --git a/arch/riscv/net/bpf_jit_core.c b/arch/riscv/net/bpf_jit_core.c
index 0a96abdaca65..b053ae5c4191 100644
--- a/arch/riscv/net/bpf_jit_core.c
+++ b/arch/riscv/net/bpf_jit_core.c
@@ -226,7 +226,7 @@  void *bpf_arch_text_copy(void *dst, void *src, size_t len)
 	int ret;
 
 	mutex_lock(&text_mutex);
-	ret = patch_text_nosync(dst, src, len);
+	ret = patch_insn_write(dst, src, len);
 	mutex_unlock(&text_mutex);
 
 	if (ret)
@@ -240,7 +240,7 @@  int bpf_arch_text_invalidate(void *dst, size_t len)
 	int ret;
 
 	mutex_lock(&text_mutex);
-	ret = patch_text_set_nosync(dst, 0, len);
+	ret = patch_insn_set(dst, 0, len);
 	mutex_unlock(&text_mutex);
 
 	return ret;