Re: [PATCH 3/3] arm64: module: Use text-poke for late PLT/veneer emission
From: Rui Qi
Date: Wed Nov 11 2026 - 02:01:33 EST
On 11/4/26 1:19 AM, Catalin Marinas wrote:
> On Sat, Oct 10, 2026 at 04:50:55PM +0800, Rui Qi wrote:
>> diff --git a/arch/arm64/kernel/module-plts.c b/arch/arm64/kernel/module-plts.c
>> index 7afd370da9f4..fa89ed014bd1 100644
>> --- a/arch/arm64/kernel/module-plts.c
>> +++ b/arch/arm64/kernel/module-plts.c
>> @@ -9,6 +9,29 @@
>> #include <linux/module.h>
>> #include <linux/moduleloader.h>
>> #include <linux/sort.h>
>> +#include <linux/text-patching.h>
>> +
>> +/*
>> + * The .plt section is marked ROX once the module is fully formed, so
>> + * late (livepatch) relocations that emit PLT entries cannot use direct
>> + * assignment. Mirror WRITE_PLACE() and route the write through the
>> + * text-poke API when the module is already loaded.
>> + *
>> + * Return: 0 on success, -EINVAL if the text-poke write failed.
>> + */
>> +static int plt_entry_write(struct plt_entry *plt,
>> + struct plt_entry *entry, struct module *mod)
>> +{
>> + if (mod->state == MODULE_STATE_UNFORMED) {
>> + *plt = *entry;
>> + return 0;
>> + }
>> +
>> + if (!aarch64_insn_copy(plt, entry, sizeof(*plt)))
>> + return -EINVAL;
>> +
>> + return 0;
>> +}
>
> As your comment says, this is fairly similar to WRITE_PLACE(). Can we
> have a single macro that's used in both places (and maybe give it an
> arm64 specific name if it ends up in a header)?
>
> Also do we need the !NULL check? plt and entry should be 4-byte aligned
> already, so it's an unnecessary check. WRITE_PLACE() doesn't do this
> either.
>
Hi Catalin,
Agreed on both points, and they interact nicely -- unifying the two
removes the redundant NULL check as a side effect.
On the NULL check: aarch64_insn_copy() returns NULL only when its dst
is not 4-byte aligned -- that alignment check is the sole failure path,
since __text_poke() always returns addr. &plt[i] is a struct plt_entry
made of __le32 fields in the .plt array, so it is always 4-byte aligned
and the check guards a condition that cannot occur. WRITE_PLACE() omits
the check for the same reason.
On unification: I moved WRITE_PLACE() into a shared header (asm/module.h,
where struct plt_entry already lives), gave it a module_-prefixed name,
and have module-plts.c use it directly. That drops the plt_entry_write()
helper and its error-return path entirely.
Addressed in v2.