Re: [PATCH v3] arm64: module: Use text-poke for late PLT/veneer emission
From: Rui Qi
Date: Thu Nov 26 2026 - 07:26:47 EST
On 11/25/26 8:24 PM, Catalin Marinas wrote:
> On Tue, 17 Nov 2026 19:35:35 +0800, Rui Qi wrote:
>> module_emit_plt_entry() and module_emit_veneer_for_adrp() write PLT
>> entries into the .plt section by direct assignment. Once a module is
>> fully formed its .plt is read-only/executable, so a late (livepatch)
>> relocation that falls back to PLT emission -- an out-of-range
>> R_AARCH64_CALL26/JUMP26, or an ADRP under CONFIG_ARM64_ERRATUM_843419
>> -- triggers a synchronous Data Abort and panics.
>>
>> [...]
>
> Applied to arm64 (for-next/fixes), thanks!
>
> [1/1] arm64: module: Use text-poke for late PLT/veneer emission
> https://git.kernel.org/arm64/c/a7e632493acf
>
> I folded in a small fix which addresses Sashiko's comment: the bounds
> check before the write must allow i == plt_max_entries since .plt has
> plt_max_entries + 1 slots (the last one is where a duplicate of the
> final entry is built before being discarded). I restored the
> plt_num_entries check after the duplicate test as well.
>
> I moved the module_write_place() prototype to asm/module.h, next
> to the other PLT emitters. I concluded it's a better fit than
> text-patching.h. My concern on v2 was the macro but now it's an
> out-of-line function. I also dropped the const from the val argument,
> which removes the (void *) cast when calling aarch64_insn_copy(). All
> callers pass non-const locals anyway. It would be a good cleanup in the
> future but that should also add const to aarch64_insn_copy().
>
> Please check that I got these right.
Thanks for applying the patch and for the adjustments.
I've checked the resulting patch, and the folded-in changes look correct
to me. Allowing i == plt_max_entries preserves the spare slot used to
build a candidate for the duplicate check, while the restored
post-duplicate check prevents a non-duplicate entry from exceeding the
reserved capacity.
Moving the declaration to asm/module.h makes sense now that the helper
is an out-of-line function. Dropping const also matches the current
aarch64_insn_copy() interface and avoids the cast.
>
> Sashiko had some comments on v2 which we concluded are existing
> problems, just exposed because we no longer take a fault. If you have
> time for a livepatch reload follow-up (probably not cc stable), there
> are two separate problems when the target module is unloaded and loaded
> again:
>
> - The livepatch module's .plt slots are reserved once but used again on
> every klp_module_coming(), so a reload eventually hits the WARN and
> the target module is rejected. This is safe but we need some slot
> rewinding or a clear_relocate_add().
>
> - With the A53 erratum 843419 workaround, if the first application
> replaced an ADRP with a B to a veneer, reloc_insn_adrp() reads the
> B back on reload as if it were an ADRP. It either encodes the ADR
> immediate into the B or decodes Rd from the branch offset. This
> corrupts the livepatch code silently on the first reload (unrelated to
> how many slots are left). Not sure yet how to fix this, maybe the
> original instruction needs restoring on unload (or saving).
>
> Thanks.
>
Thanks for detailing the reload issues. I agree that they need separate
handling: reclaiming PLT slots alone would not address the ADRP-to-B
case, since reapplying the relocation also needs the original
instruction, including its destination register. I'll look into the slot
lifecycle and instruction restoration for a separate follow-up,
initially without Cc'ing stable.
Thanks,
Rui