[PATCH v1 3/3] LoongArch: No need to flush icache if copy failed

Tiezhu Yang posted 3 patches 1 month ago
[PATCH v1 3/3] LoongArch: No need to flush icache if copy failed
Posted by Tiezhu Yang 1 month ago
If copy_to_kernel_nofault() failed, no need to flush icache and just
return -EFAULT immediately.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 arch/loongarch/kernel/inst.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/loongarch/kernel/inst.c b/arch/loongarch/kernel/inst.c
index 77da3b886dcb..dd5e8864eff9 100644
--- a/arch/loongarch/kernel/inst.c
+++ b/arch/loongarch/kernel/inst.c
@@ -246,13 +246,15 @@ static int text_copy_cb(void *data)
 
 	if (smp_processor_id() == copy->cpu) {
 		ret = copy_to_kernel_nofault(copy->dst, copy->src, copy->len);
-		if (ret)
+		if (ret) {
 			pr_err("%s: operation failed\n", __func__);
+			return -EFAULT;
+		}
 	}
 
 	flush_icache_range((unsigned long)copy->dst, (unsigned long)copy->dst + copy->len);
 
-	return ret;
+	return 0;
 }
 
 int larch_insn_text_copy(void *dst, void *src, size_t len)
-- 
2.42.0
Re: [PATCH v1 3/3] LoongArch: No need to flush icache if copy failed
Posted by Huacai Chen 3 weeks, 4 days ago
Applied with small modifications (return ret rather than -EFAULT), thanks.

Huacai

On Tue, Mar 10, 2026 at 2:55 PM Tiezhu Yang <yangtiezhu@loongson.cn> wrote:
>
> If copy_to_kernel_nofault() failed, no need to flush icache and just
> return -EFAULT immediately.
>
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
> ---
>  arch/loongarch/kernel/inst.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/arch/loongarch/kernel/inst.c b/arch/loongarch/kernel/inst.c
> index 77da3b886dcb..dd5e8864eff9 100644
> --- a/arch/loongarch/kernel/inst.c
> +++ b/arch/loongarch/kernel/inst.c
> @@ -246,13 +246,15 @@ static int text_copy_cb(void *data)
>
>         if (smp_processor_id() == copy->cpu) {
>                 ret = copy_to_kernel_nofault(copy->dst, copy->src, copy->len);
> -               if (ret)
> +               if (ret) {
>                         pr_err("%s: operation failed\n", __func__);
> +                       return -EFAULT;
> +               }
>         }
>
>         flush_icache_range((unsigned long)copy->dst, (unsigned long)copy->dst + copy->len);
>
> -       return ret;
> +       return 0;
>  }
>
>  int larch_insn_text_copy(void *dst, void *src, size_t len)
> --
> 2.42.0
>