Re: [PATCH v1 2/3] LoongArch: Check return values for set_memory_{rw,rox}

From: Huacai Chen

Date: Sun Mar 15 2026 - 04:05:51 EST


Applied with small modifications, thanks.

Huacai

On Tue, Mar 10, 2026 at 2:55 PM Tiezhu Yang <yangtiezhu@xxxxxxxxxxx> wrote:
>
> set_memory_rw() and set_memory_rox() may failed, it should check the
> return values and return immediately in larch_insn_text_copy().
>
> Signed-off-by: Tiezhu Yang <yangtiezhu@xxxxxxxxxxx>
> ---
> arch/loongarch/kernel/inst.c | 15 +++++++++++++--
> 1 file changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/arch/loongarch/kernel/inst.c b/arch/loongarch/kernel/inst.c
> index 7545ae3c796e..77da3b886dcb 100644
> --- a/arch/loongarch/kernel/inst.c
> +++ b/arch/loongarch/kernel/inst.c
> @@ -258,6 +258,7 @@ static int text_copy_cb(void *data)
> int larch_insn_text_copy(void *dst, void *src, size_t len)
> {
> int ret = 0;
> + int err = 0;
> size_t start, end;
> struct insn_copy copy = {
> .dst = dst,
> @@ -275,9 +276,19 @@ int larch_insn_text_copy(void *dst, void *src, size_t len)
> start = round_down((size_t)dst, PAGE_SIZE);
> end = round_up((size_t)dst + len, PAGE_SIZE);
>
> - set_memory_rw(start, (end - start) / PAGE_SIZE);
> + err = set_memory_rw(start, (end - start) / PAGE_SIZE);
> + if (err) {
> + pr_info("%s: set_memory_rw failed\n", __func__);
> + return err;
> + }
> +
> ret = stop_machine_cpuslocked(text_copy_cb, &copy, cpu_online_mask);
> - set_memory_rox(start, (end - start) / PAGE_SIZE);
> +
> + err = set_memory_rox(start, (end - start) / PAGE_SIZE);
> + if (err) {
> + pr_info("%s: set_memory_rox failed\n", __func__);
> + return err;
> + }
>
> return ret;
> }
> --
> 2.42.0
>
>