]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
x86/alternative: Patch a single alternative location only once
authorJuergen Gross <jgross@suse.com>
Mon, 5 Jan 2026 08:04:52 +0000 (09:04 +0100)
committerBorislav Petkov (AMD) <bp@alien8.de>
Wed, 7 Jan 2026 15:13:00 +0000 (16:13 +0100)
commita4233c21e77375494223ade11da72523a0149d97
treef70cf8d037756e744e6211f4ebe3edf19935efd9
parent544b4e15ed106b0e8cd2d584f576e3fda13d8f5f
x86/alternative: Patch a single alternative location only once

Instead of patching a single location potentially multiple times in case of
nested ALTERNATIVE()s, do the patching only after having evaluated all
alt_instr instances for that location.

This has multiple advantages:

- In case of replacing an indirect with a direct call using the
  ALT_FLAG_DIRECT_CALL flag, there is no longer the need to have that
  instance before any other instances at the same location (the
  original instruction is needed for finding the target of the direct
  call).
  This issue has been hit when trying to do paravirt patching similar
  to the following:
    ALTERNATIVE_2(PARAVIRT_CALL,    // indirect call
                  instr, feature,   // native instruction
                  ALT_CALL_INSTR, X86_FEATURE_XENPV)  // Xen function
  In case "feature" was true, "instr" replaced the indirect call. Under
  Xen PV the patching to have a direct call failed, as the original
  indirect call was no longer there to find the call target.

- In case of nested ALTERNATIVE()s there is no intermediate replacement
  visible. This avoids any problems in case e.g. an interrupt is
  happening between the single instances and the patched location is
  used during handling the interrupt.

Signed-off-by: Juergen Gross <jgross@suse.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://patch.msgid.link/20260105080452.5064-3-jgross@suse.com
arch/x86/kernel/alternative.c