[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aDXQYMcLle2E_b2d@pathway.suse.cz>
Date: Tue, 27 May 2025 16:46:56 +0200
From: Petr Mladek <pmladek@...e.com>
To: Dylan Hatch <dylanbhatch@...gle.com>
Cc: Catalin Marinas <catalin.marinas@....com>,
Will Deacon <will@...nel.org>, Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org,
"H. Peter Anvin" <hpa@...or.com>,
Josh Poimboeuf <jpoimboe@...nel.org>,
Jiri Kosina <jikos@...nel.org>, Miroslav Benes <mbenes@...e.cz>,
Joe Lawrence <joe.lawrence@...hat.com>, Song Liu <song@...nel.org>,
Ard Biesheuvel <ardb@...nel.org>,
Sami Tolvanen <samitolvanen@...gle.com>,
Peter Zijlstra <peterz@...radead.org>,
"Mike Rapoport (Microsoft)" <rppt@...nel.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Dan Carpenter <dan.carpenter@...aro.org>,
linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org,
live-patching@...r.kernel.org,
Roman Gushchin <roman.gushchin@...ux.dev>,
Toshiyuki Sato <fj6611ie@...jp.fujitsu.com>
Subject: Re: [PATCH v4 1/2] livepatch, x86/module: Generalize late module
relocation locking.
On Thu 2025-05-22 20:52:04, Dylan Hatch wrote:
> Late module relocations are an issue on any arch that supports
> livepatch, so move the text_mutex locking to the livepatch core code.
>
> Signed-off-by: Dylan Hatch <dylanbhatch@...gle.com>
> Acked-by: Song Liu <song@...nel.org>
> ---
> arch/x86/kernel/module.c | 8 ++------
> kernel/livepatch/core.c | 18 +++++++++++++-----
> 2 files changed, 15 insertions(+), 11 deletions(-)
>
> --- a/arch/x86/kernel/module.c
> +++ b/arch/x86/kernel/module.c
> @@ -197,18 +197,14 @@ static int write_relocate_add(Elf64_Shdr *sechdrs,
> bool early = me->state == MODULE_STATE_UNFORMED;
> void *(*write)(void *, const void *, size_t) = memcpy;
>
> - if (!early) {
> + if (!early)
> write = text_poke;
> - mutex_lock(&text_mutex);
> - }
>
> ret = __write_relocate_add(sechdrs, strtab, symindex, relsec, me,
> write, apply);
>
> - if (!early) {
> + if (!early)
> text_poke_sync();
> - mutex_unlock(&text_mutex);
> - }
>
> return ret;
> }
> diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
> index 0e73fac55f8eb..9968441f73510 100644
> --- a/kernel/livepatch/core.c
> +++ b/kernel/livepatch/core.c
> @@ -319,12 +320,19 @@ static int klp_write_section_relocs(struct module *pmod, Elf_Shdr *sechdrs,
> sec, sec_objname);
> if (ret)
> return ret;
> -
> - return apply_relocate_add(sechdrs, strtab, symndx, secndx, pmod);
> }
>
> - clear_relocate_add(sechdrs, strtab, symndx, secndx, pmod);
> - return 0;
> + if (!early)
> + mutex_lock(&text_mutex);
I understand why you do this but it opens some questions.
As this patch suggests, the "text_mutex" has been used to
sychronize apply_relocate_add() only on x86_64 so far.
s390x seems to rely on "s390_kernel_write_lock" taken by:
+ apply_relocate_add()
+ s390_kernel_write()
+ __s390_kernel_write()
And powerpc seems to rely on "pte" locking taken by
+ apply_relocate_add()
+ patch_instruction()
+ patch_mem()
+ __do_patch_mem_mm()
+ get_locked_pte()
I see two possibilities:
1. Either this change makes a false feeling that "text_mutex"
sychronizes apply_relocate_add() on all architextures.
This does not seems to be the case on, for example, s390
and powerpc.
=> The code is misleading and could lead to troubles.
2. Or it actually provides some sychronization on all
architectures, for example, against kprobe code.
In this case, it might actually fix an existing race.
It should be described in the commit message
and nominated for backporting to stable.
I am sorry if this has already been discussed. But I have been
in Cc only for v3 and v4. And there is no changelog in
the cover letter.
> +
> + if (apply)
> + ret = apply_relocate_add(sechdrs, strtab, symndx, secndx, pmod);
> + else
> + clear_relocate_add(sechdrs, strtab, symndx, secndx, pmod);
> +
> + if (!early)
> + mutex_unlock(&text_mutex);
> + return ret;
> }
Best Regards,
Petr
Powered by blists - more mailing lists