Re: [PATCH 1/2] objtool: Optimize re-writing jump_label

From: Josh Poimboeuf
Date: Fri Oct 08 2021 - 12:29:07 EST


On Fri, Oct 08, 2021 at 12:03:31PM +0200, Peter Zijlstra wrote:
> On Thu, Oct 07, 2021 at 11:55:50PM -0700, Josh Poimboeuf wrote:
> > On Thu, Oct 07, 2021 at 11:22:12PM +0200, Peter Zijlstra wrote:
> > > There's no point to re-write the jump_label NOP when it's already a NOP.
> > >
> > > Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
> > > ---
> > > tools/objtool/check.c | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > --- a/tools/objtool/check.c
> > > +++ b/tools/objtool/check.c
> > > @@ -1397,7 +1397,7 @@ static int handle_jump_alt(struct objtoo
> > > return -1;
> > > }
> > >
> > > - if (special_alt->key_addend & 2) {
> > > + if ((special_alt->key_addend & 2) && orig_insn->type != INSN_NOP) {
> > > struct reloc *reloc = insn_reloc(file, orig_insn);
> > >
> > > if (reloc) {
> >
> > While you're at it, a comment would be very helpful for that whole
> > clause.
>
> Like so?
>
> --- a/tools/objtool/check.c
> +++ b/tools/objtool/check.c
> @@ -1397,7 +1397,16 @@ static int handle_jump_alt(struct objtoo
> return -1;
> }
>
> - if (special_alt->key_addend & 2) {
> + /*
> + * When, for whatever reason, the jump-label site cannot emit a right
> + * sized NOP, then it can use Bit-1 of the struct static_key pointer to
> + * indicate this instruction should be NOP'ed by objtool.
> + *
> + * Also see arch/x86/include/asm/jump_label.h:arch_static_branch(),
> + * where we leave the assembler to pick between jmp.d8 and jmp.d32
> + * based on destination offset.
> + */
> + if ((special_alt->key_addend & 2) && orig_insn->type != INSN_NOP) {
> struct reloc *reloc = insn_reloc(file, orig_insn);
>
> if (reloc) {
>

Much better! Can you also mention why it's checking INSN_NOP? The "run
objtool twice" case is far from obvious.

--
Josh