From: Borislav Petkov <bp@alien8.de>
To: linux-kernel@vger.kernel.org
Cc: linux-tip-commits@vger.kernel.org,
Juergen Gross <jgross@suse.com>,
"Peter Zijlstra (Intel)" <peterz@infradead.org>,
x86@kernel.org
Subject: Re: [tip: x86/core] x86/alternative: Patch a single alternative location only once
Date: Tue, 14 Oct 2025 15:25:44 +0200 [thread overview]
Message-ID: <20251014132544.GBaO5PWEbKfbQFCXdB@fat_crate.local> (raw)
In-Reply-To: <20251014125909.GAaO5JHU_cgsPgstc_@fat_crate.local>
On Tue, Oct 14, 2025 at 02:59:09PM +0200, Borislav Petkov wrote:
> And frankly, the justification for this patch is also meh: an interrupt might
> use the location?!? If this is a real issue then we better disable IRQs around
> it. But not make the code yucky.
And this patch is not doing what it is claiming is doing:
Here's an incarnation of XSTATE_XSAVE which is a 3-way alternative:
At location ffffffff81283cd3, it replaces the default XSAVE with XSAVEOPT.
[ 2.456696] SMP alternatives: feat: 10*32+0, old: (save_fpregs_to_fpstate+0x43/0xa0 (ffffffff81283cd3) len: 6), repl: (ffffffff89c1e6d9, len: 6) flags: 0x0
[ 2.459317] SMP alternatives: ffffffff81283cd3: old_insn: 49 0f ae 64 24 40 xsave64 0x40(%r12)
[ 2.460806] SMP alternatives: ffffffff89c1e6d9: rpl_insn: 49 0f ae 74 24 40 xsaveopt64 0x40(%r12)
[ 2.463316] SMP alternatives: ffffffff81283cd3: final_insn: 49 0f ae 74 24 40
and then that exact same location:
[ 2.464757] SMP alternatives: feat: 10*32+1, old: (save_fpregs_to_fpstate+0x43/0xa0 (ffffffff81283cd3) len: 6), repl: (ffffffff89c1e6df, len: 6) flags: 0x0
[ 2.467317] SMP alternatives: ffffffff81283cd3: old_insn: 49 0f ae 64 24 40
[ 2.468746] SMP alternatives: ffffffff89c1e6df: rpl_insn: 49 0f c7 64 24 40 xsaves64 0x40(%r12)
[ 2.470167] SMP alternatives: ffffffff81283cd3: final_insn: 49 0f c7 64 24 40
gets XSAVES.
So, long story short, this needs more thought:
1. check whether patching is needed
2. a helper function evaluates all instances and figures out the final insn
bytes which need to be patched along with the proper padding
3. the proper bytes are copied into the target location and all good
But not like this - the idea is somewhat ok but it needs to be executed in
a cleaner manner.
I'd say.
Thx.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
next prev parent reply other threads:[~2025-10-14 13:26 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-29 11:29 [PATCH 0/3] x86/alternative: Make alternative patching more robust Juergen Gross
2025-09-29 11:29 ` [PATCH 1/3] x86/alternative: Drop not needed test after call of alt_replace_call() Juergen Gross
2025-10-14 8:42 ` [tip: x86/core] " tip-bot2 for Juergen Gross
2025-09-29 11:29 ` [PATCH 2/3] x86/alternative: Refactor apply_alternatives() Juergen Gross
2025-10-14 8:42 ` [tip: x86/core] " tip-bot2 for Juergen Gross
2025-09-29 11:29 ` [PATCH 3/3] x86/alternative: Patch a single alternative location only once Juergen Gross
2025-09-30 7:26 ` Peter Zijlstra
2025-09-30 7:33 ` Jürgen Groß
2025-09-30 7:39 ` Peter Zijlstra
2025-09-30 8:04 ` Jürgen Groß
2025-10-14 8:42 ` [tip: x86/core] " tip-bot2 for Juergen Gross
2025-10-14 12:59 ` Borislav Petkov
2025-10-14 13:25 ` Borislav Petkov [this message]
2025-10-14 14:13 ` Jürgen Groß
2025-10-14 14:17 ` Borislav Petkov
2025-10-14 14:18 ` Peter Zijlstra
2025-10-14 14:26 ` Juergen Gross
2025-10-14 14:29 ` Borislav Petkov
2025-10-14 14:08 ` Jürgen Groß
2025-10-14 14:12 ` Borislav Petkov
2025-10-14 14:22 ` Jürgen Groß
2025-10-14 14:26 ` Borislav Petkov
2025-10-14 14:31 ` Jürgen Groß
2025-10-14 14:39 ` Borislav Petkov
2025-10-14 14:46 ` Jürgen Groß
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251014132544.GBaO5PWEbKfbQFCXdB@fat_crate.local \
--to=bp@alien8.de \
--cc=jgross@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®