Re: [PATCH v2 10/11] x86/alternatives: Simplify ALTERNATIVE_n()

From: Peter Zijlstra
Date: Tue Sep 12 2023 - 05:27:39 EST


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.