Re: [PATCH 3/3] arm64: module: Use text-poke for late PLT/veneer emission
From: Catalin Marinas
Date: Tue Nov 03 2026 - 12:20:23 EST
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.
--
Catalin