linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: x86@kernel.org, jgross@suse.com, mbenes@suse.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 12/14] objtool: Allow archs to rewrite retpolines
Date: Fri, 19 Mar 2021 12:21:03 +0100	[thread overview]
Message-ID: <YFSJH0/wiHLkteLw@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20210319025440.ah5kr7aztz4jbzer@treble>

On Thu, Mar 18, 2021 at 09:54:40PM -0500, Josh Poimboeuf wrote:
> On Thu, Mar 18, 2021 at 06:11:15PM +0100, Peter Zijlstra wrote:
> > @@ -1212,6 +1225,8 @@ static int handle_group_alt(struct objto
> >  		dest_off = arch_jump_destination(insn);
> >  		if (dest_off == special_alt->new_off + special_alt->new_len)
> >  			insn->jump_dest = next_insn_same_sec(file, last_orig_insn);
> > +		else
> > +			insn->jump_dest = find_insn(file, insn->sec, dest_off);
> >  
> >  		if (!insn->jump_dest) {
> >  			WARN_FUNC("can't find alternative jump destination",
> 
> So I assume this change is because of the ordering change: now this is
> done before add_jump_destinations().

Correct.

> Also the new hunk to be an oversimplified version of
> add_jump_destinations().  I'm not quite convinced that it will always do
> the right thing for this case.

You're right; this is because of the reorder. At the time I thought this
was right, but looking at it now, I'm not sure. Esp. so when ARM64 comes
along and allows more relocations in alternatives.

Let me see if I can come up with something better.

> But doesn't that mean the alternative jump modification (changing the
> dest to the end of the original insns) will get overwritten later?

Good point, should be simple enough to fix by having
add_jump_destination() skip all that already have insn->jump_dest set I
suppose.

> > @@ -1797,11 +1812,15 @@ static int decode_sections(struct objtoo
> >  	if (ret)
> >  		return ret;
> >  
> > -	ret = add_jump_destinations(file);
> > +	/*
> > +	 * Must be before add_{jump,call}_destination; for they can add
> > +	 * magic alternatives.
> > +	 */
> > +	ret = add_special_section_alts(file);
> 
> This reordering is unfortunate.  Maybe there's a better way, though I
> don't have any ideas, at least until I get to the most controversial
> patch.

So the thing no longer crashes on the alternatives it writes, so we
*could* read back our own alternatives, but it does seem somewhat
unfortunate to do that. Too easy to get into cycles that way.

  reply	other threads:[~2021-03-19 11:21 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-18 17:11 [PATCH v2 00/14] x86,objtool: Optimize !RETPOLINE Peter Zijlstra
2021-03-18 17:11 ` [PATCH v2 01/14] x86: Add insn_decode_kernel() Peter Zijlstra
2021-03-19 10:40   ` Borislav Petkov
2021-03-18 17:11 ` [PATCH v2 02/14] x86/alternatives: Optimize optimize_nops() Peter Zijlstra
2021-03-21 12:06   ` Borislav Petkov
2021-03-22  8:17     ` Peter Zijlstra
2021-03-22 11:07       ` Borislav Petkov
2021-03-18 17:11 ` [PATCH v2 03/14] x86/retpoline: Simplify retpolines Peter Zijlstra
2021-03-19 17:18   ` David Laight
2021-03-22  9:32     ` Peter Zijlstra
2021-03-22 15:41       ` David Laight
2021-03-18 17:11 ` [PATCH v2 04/14] objtool: Correctly handle retpoline thunk calls Peter Zijlstra
2021-03-18 17:11 ` [PATCH v2 05/14] objtool: Per arch retpoline naming Peter Zijlstra
2021-03-19  2:38   ` Josh Poimboeuf
2021-03-19  9:07     ` Peter Zijlstra
2021-03-18 17:11 ` [PATCH v2 06/14] objtool: Fix static_call list generation Peter Zijlstra
2021-03-22 12:44   ` Miroslav Benes
2021-03-18 17:11 ` [PATCH v2 07/14] objtool: Rework rebuild_reloc logic Peter Zijlstra
2021-03-18 17:11 ` [PATCH v2 08/14] objtool: Add elf_create_reloc() helper Peter Zijlstra
2021-03-19  1:42   ` Josh Poimboeuf
2021-03-19  9:47     ` Peter Zijlstra
2021-03-19 15:12       ` Josh Poimboeuf
2021-03-19 15:24         ` Peter Zijlstra
2021-03-19 15:37           ` Josh Poimboeuf
2021-03-18 17:11 ` [PATCH v2 09/14] objtool: Extract elf_strtab_concat() Peter Zijlstra
2021-03-19  2:10   ` Josh Poimboeuf
2021-03-19  9:52     ` Peter Zijlstra
2021-03-18 17:11 ` [PATCH v2 10/14] objtool: Extract elf_symbol_add() Peter Zijlstra
2021-03-19  2:14   ` Josh Poimboeuf
2021-03-19  9:54     ` Peter Zijlstra
2021-03-19 15:04       ` Josh Poimboeuf
2021-03-18 17:11 ` [PATCH v2 11/14] objtool: Add elf_create_undef_symbol() Peter Zijlstra
2021-03-19  2:29   ` Josh Poimboeuf
2021-03-19  7:56     ` Peter Zijlstra
2021-03-18 17:11 ` [PATCH v2 12/14] objtool: Allow archs to rewrite retpolines Peter Zijlstra
2021-03-19  2:54   ` Josh Poimboeuf
2021-03-19 11:21     ` Peter Zijlstra [this message]
2021-03-19 13:28       ` Peter Zijlstra
2021-03-18 17:11 ` [PATCH v2 13/14] objtool: Skip magical retpoline .altinstr_replacement Peter Zijlstra
2021-03-18 17:11 ` [PATCH v2 14/14] objtool,x86: Rewrite retpoline thunk calls Peter Zijlstra
2021-03-19  3:29   ` Josh Poimboeuf
2021-03-19  8:06     ` Peter Zijlstra
2021-03-19 15:30       ` Josh Poimboeuf
2021-03-19 15:56         ` Peter Zijlstra
2021-03-19 22:52           ` Josh Poimboeuf

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=YFSJH0/wiHLkteLw@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=jgross@suse.com \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mbenes@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).