From: Peter Zijlstra <peterz@infradead.org>
To: Borislav Petkov <bp@alien8.de>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
David.Kaplan@amd.com, Andrew.Cooper3@citrix.com,
jpoimboe@kernel.org, gregkh@linuxfoundation.org,
nik.borisov@suse.com
Subject: Re: [PATCH v2 10/11] x86/alternatives: Simplify ALTERNATIVE_n()
Date: Tue, 12 Sep 2023 11:44:41 +0200 [thread overview]
Message-ID: <20230912094441.GA13926@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20230912092709.GE35261@noisy.programming.kicks-ass.net>
On Tue, Sep 12, 2023 at 11:27:09AM +0200, Peter Zijlstra wrote:
> On Sun, Sep 10, 2023 at 04:42:27PM +0200, Borislav Petkov wrote:
> > On Sat, Sep 09, 2023 at 11:25:54AM +0200, Peter Zijlstra wrote:
> > > So what you end up with is:
> > >
> > > 661:
> > > "one byte orig insn"
> > > "one nop because alt1 is 2 bytes"
> > > "one nop because alt2 is 3 bytes"
> > >
> > > right?
> >
> > Right.
> >
> > > This becomes more of a problem with your example above where the
> > > respective lengths are 0, 5, 16. In that case, when you patch 5, you'll
> > > leave 11 single nops in there.
> >
> > Well, I know what you mean but the code handles that gracefully and it
> > works. Watch this:
>
> Aah, because we run optimize_nops() for all alternatives, irrespective
> of it being selected. And thus also for the longest and then that'll fix
> things up.
>
> OK, let me check on objtool.
OK, I think objtool really does need the hunk you took out.
The problem there is that we're having to create ORC data that is valid
for all possible alternatives -- there is only one ORC table (unless we
go dynamically patch the ORC table too, but so far we've managed to
avoid doing that).
The constraint we have is that for every address the ORC data must match
between the alternatives, but because x86 is a variable length
instruction encoding we can (and do) play games. As long as the
instruction addresses do not line up, they can have different ORC data.
One place where this matters is the tail, if we consider this a string
of single byte nops, that forces a bunch of ORC state to match. So what
we do is that we assume the tail is a single large NOP, this way we get
minimal overlap / ORC conflicts.
As such, we need to know the max length when constructing the
alternatives, otherwise you get short alternatives jumping to somewhere
in the middle of the actual range and well, see above.
next prev parent reply other threads:[~2023-09-12 9:45 UTC|newest]
Thread overview: 74+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-14 11:44 [PATCH v2 00/11] Fix up SRSO stuff Peter Zijlstra
2023-08-14 11:44 ` [PATCH v2 01/11] x86/cpu: Fixup __x86_return_thunk Peter Zijlstra
2023-08-16 7:55 ` [tip: x86/urgent] x86/cpu: Fix __x86_return_thunk symbol type tip-bot2 for Peter Zijlstra
2023-08-14 11:44 ` [PATCH v2 02/11] x86/cpu: Fix up srso_safe_ret() and __x86_return_thunk() Peter Zijlstra
2023-08-16 7:55 ` [tip: x86/urgent] " tip-bot2 for Peter Zijlstra
2023-08-14 11:44 ` [PATCH v2 03/11] objtool/x86: Fix SRSO mess Peter Zijlstra
2023-08-14 12:54 ` Andrew.Cooper3
2023-08-16 7:55 ` [tip: x86/urgent] " tip-bot2 for Peter Zijlstra
2023-08-16 11:59 ` Peter Zijlstra
2023-08-16 20:31 ` Josh Poimboeuf
2023-08-16 22:08 ` [PATCH] objtool/x86: Fixup frame-pointer vs rethunk Peter Zijlstra
2023-08-16 22:22 ` Josh Poimboeuf
2023-08-17 8:39 ` [tip: x86/urgent] " tip-bot2 for Peter Zijlstra
2023-08-14 11:44 ` [PATCH v2 04/11] x86/alternative: Make custom return thunk unconditional Peter Zijlstra
2023-08-16 7:55 ` [tip: x86/urgent] " tip-bot2 for Peter Zijlstra
2023-08-14 11:44 ` [PATCH v2 05/11] x86/cpu: Clean up SRSO return thunk mess Peter Zijlstra
2023-08-14 13:02 ` Borislav Petkov
2023-08-14 17:48 ` Borislav Petkov
2023-08-15 21:29 ` Nathan Chancellor
2023-08-15 22:43 ` Peter Zijlstra
2023-08-16 7:38 ` Borislav Petkov
2023-08-16 14:52 ` Nathan Chancellor
2023-08-16 15:08 ` Borislav Petkov
2023-08-16 7:55 ` [tip: x86/urgent] " tip-bot2 for Peter Zijlstra
2023-08-16 18:58 ` Nathan Chancellor
2023-08-16 19:24 ` Borislav Petkov
2023-08-16 19:30 ` Nathan Chancellor
2023-08-16 19:42 ` Borislav Petkov
2023-08-16 19:57 ` Borislav Petkov
2023-08-16 21:20 ` tip-bot2 for Peter Zijlstra
2023-08-14 11:44 ` [PATCH v2 06/11] x86/cpu: Rename original retbleed methods Peter Zijlstra
2023-08-14 19:41 ` Josh Poimboeuf
2023-08-16 7:55 ` [tip: x86/urgent] " tip-bot2 for Peter Zijlstra
2023-08-16 21:20 ` tip-bot2 for Peter Zijlstra
2023-08-14 11:44 ` [PATCH v2 07/11] x86/cpu: Rename srso_(.*)_alias to srso_alias_\1 Peter Zijlstra
2023-08-16 7:55 ` [tip: x86/urgent] " tip-bot2 for Peter Zijlstra
2023-08-16 21:20 ` tip-bot2 for Peter Zijlstra
2023-08-14 11:44 ` [PATCH v2 08/11] x86/cpu: Cleanup the untrain mess Peter Zijlstra
2023-08-16 7:55 ` [tip: x86/urgent] " tip-bot2 for Peter Zijlstra
2023-08-16 21:20 ` tip-bot2 for Peter Zijlstra
2023-08-14 11:44 ` [PATCH v2 09/11] x86/cpu/kvm: Provide UNTRAIN_RET_VM Peter Zijlstra
2023-08-16 7:55 ` [tip: x86/urgent] " tip-bot2 for Peter Zijlstra
2023-08-16 21:20 ` tip-bot2 for Peter Zijlstra
2023-08-14 11:44 ` [PATCH v2 10/11] x86/alternatives: Simplify ALTERNATIVE_n() Peter Zijlstra
2023-08-15 20:49 ` Nikolay Borisov
2023-08-15 22:44 ` Peter Zijlstra
2023-09-07 8:31 ` Borislav Petkov
2023-09-07 11:09 ` Peter Zijlstra
2023-09-07 11:11 ` Peter Zijlstra
2023-09-07 11:16 ` Peter Zijlstra
2023-09-07 15:06 ` Borislav Petkov
2023-09-07 15:30 ` Borislav Petkov
2023-09-09 7:50 ` Borislav Petkov
2023-09-09 9:25 ` Peter Zijlstra
2023-09-09 9:42 ` Peter Zijlstra
2023-09-10 14:42 ` Borislav Petkov
2023-09-12 9:27 ` Peter Zijlstra
2023-09-12 9:44 ` Peter Zijlstra [this message]
2023-09-13 4:37 ` Borislav Petkov
2023-09-13 8:46 ` Peter Zijlstra
2023-09-13 14:38 ` Borislav Petkov
2023-09-13 16:14 ` Peter Zijlstra
2023-09-15 7:46 ` Peter Zijlstra
2023-09-15 7:51 ` Peter Zijlstra
2023-09-15 12:05 ` Borislav Petkov
2023-09-13 4:24 ` Borislav Petkov
2023-08-14 11:44 ` [PATCH v2 11/11] x86/cpu: Use fancy alternatives to get rid of entry_untrain_ret() Peter Zijlstra
2023-08-14 16:44 ` [PATCH v2 00/11] Fix up SRSO stuff Borislav Petkov
2023-08-14 19:51 ` Josh Poimboeuf
2023-08-14 19:57 ` Borislav Petkov
2023-08-14 20:01 ` Josh Poimboeuf
2023-08-14 20:09 ` Borislav Petkov
2023-08-15 14:26 ` [PATCH] x86/srso: Explain the untraining sequences a bit more Borislav Petkov
2023-08-15 15:41 ` Nikolay Borisov
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=20230912094441.GA13926@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=Andrew.Cooper3@citrix.com \
--cc=David.Kaplan@amd.com \
--cc=bp@alien8.de \
--cc=gregkh@linuxfoundation.org \
--cc=jpoimboe@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nik.borisov@suse.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.