From: Alexandre Chartre <alexandre.chartre@oracle.com>
To: Julien Thierry <jthierry@redhat.com>, x86@kernel.org
Cc: linux-kernel@vger.kernel.org, jpoimboe@redhat.com,
peterz@infradead.org, tglx@linutronix.de
Subject: Re: [PATCH 2/7] objtool: Allow branches within the same alternative.
Date: Thu, 2 Apr 2020 14:38:16 +0200 [thread overview]
Message-ID: <0824494b-15a9-f810-e81e-003d3d3b85cd@oracle.com> (raw)
In-Reply-To: <50e8a5d8-7cb4-f25c-9657-eb11038bd0b5@redhat.com>
On 4/2/20 2:03 PM, Julien Thierry wrote:
> Hi Alexandre,
>
> I ran into the same issue for the arm64 work:
> https://lkml.org/lkml/2020/1/9/656
Thanks for the reference, I didn't notice that change, but I saw a more
recent one where you were just removing the branch to alternative check
(https://lkml.org/lkml/2020/3/25/151).
> Your solution seems nicer however.
>
> On 4/2/20 9:22 AM, Alexandre Chartre wrote:
>> Currently objtool prevents any branch to an alternative. While preventing
>> branching from the outside to the middle of an alternative makes perfect
>> sense, branching within the same alternative should be allowed. To do so,
>> identify each alternative and check that a branch to an alternative comes
>> from the same alternative.
>>
>> Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com>
>> ---
>> tools/objtool/check.c | 19 +++++++++++++------
>> tools/objtool/check.h | 3 ++-
>> 2 files changed, 15 insertions(+), 7 deletions(-)
>>
>> diff --git a/tools/objtool/check.c b/tools/objtool/check.c
>> index 708562fb89e1..214809ac2776 100644
>> --- a/tools/objtool/check.c
>> +++ b/tools/objtool/check.c
>> @@ -712,7 +712,9 @@ static int handle_group_alt(struct objtool_file *file,
>> struct instruction *orig_insn,
>> struct instruction **new_insn)
>> {
>> + static unsigned int alt_group_next_index = 1;
>> struct instruction *last_orig_insn, *last_new_insn, *insn, *fake_jump = NULL;
>> + unsigned int alt_group = alt_group_next_index++;
>> unsigned long dest_off;
>> last_orig_insn = NULL;
>> @@ -721,7 +723,7 @@ static int handle_group_alt(struct objtool_file *file,
>> if (insn->offset >= special_alt->orig_off + special_alt->orig_len)
>> break;
>> - insn->alt_group = true;
>> + insn->alt_group = alt_group;
>> last_orig_insn = insn;
>> }
>> @@ -1942,6 +1944,7 @@ static int validate_sibling_call(struct instruction *insn, struct insn_state *st
>> * tools/objtool/Documentation/stack-validation.txt.
>> */
>> static int validate_branch(struct objtool_file *file, struct symbol *func,
>> + struct instruction *from,
>
> Maybe instead of passing a new instruction pointer, just the
> alt_group could be passed? 0 Meaning it was not in an alt group>
>> struct instruction *first, struct insn_state state)
>> {
>> struct alternative *alt;
>> @@ -1953,7 +1956,9 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,
>> insn = first;
>> sec = insn->sec;
>> - if (insn->alt_group && list_empty(&insn->alts)) {
>> + if (insn->alt_group &&
>> + (!from || from->alt_group != insn->alt_group) &&
>> + list_empty(&insn->alts)) {
>
> This would become
>
> if (insn->alt_group != alt_group && list_empty(&insn->alts))
>
> And the recursive validate_branch() calls would just take
> insn->alt_group as parameter (and the calls in validate_functions()
> and validate_unwind_hints() would take 0).
>
> Any opinions on that?
Yes, that would work too. I choose to pass the instruction pointer because
I was thinking that having the "from" instruction might be useful in the
future if there's a need to do additional check about the origin of the
branch.
alex.
>> WARN_FUNC("don't know how to handle branch to middle of alternative instruction group",
>> sec, insn->offset);
>> return 1;
>> @@ -2035,7 +2040,8 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,
>> if (alt->skip_orig)
>> skip_orig = true;
>> - ret = validate_branch(file, func, alt->insn, state);
>> + ret = validate_branch(file, func,
>> + NULL, alt->insn, state);
>> if (ret) {
>> if (backtrace)
>> BT_FUNC("(alt)", insn);
>> @@ -2105,7 +2111,7 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,
>> return ret;
>> } else if (insn->jump_dest) {
>> - ret = validate_branch(file, func,
>> + ret = validate_branch(file, func, insn,
>> insn->jump_dest, state);
>> if (ret) {
>> if (backtrace)
>> @@ -2236,7 +2242,8 @@ static int validate_unwind_hints(struct objtool_file *file)
>> for_each_insn(file, insn) {
>> if (insn->hint && !insn->visited) {
>> - ret = validate_branch(file, insn->func, insn, state);
>> + ret = validate_branch(file, insn->func,
>> + NULL, insn, state);
>> if (ret && backtrace)
>> BT_FUNC("<=== (hint)", insn);
>> warnings += ret;
>> @@ -2377,7 +2384,7 @@ static int validate_functions(struct objtool_file *file)
>> state.uaccess = func->uaccess_safe;
>> - ret = validate_branch(file, func, insn, state);
>> + ret = validate_branch(file, func, NULL, insn, state);
>> if (ret && backtrace)
>> BT_FUNC("<=== (func)", insn);
>> warnings += ret;
>> diff --git a/tools/objtool/check.h b/tools/objtool/check.h
>> index 6d875ca6fce0..cffb23d81782 100644
>> --- a/tools/objtool/check.h
>> +++ b/tools/objtool/check.h
>> @@ -33,7 +33,8 @@ struct instruction {
>> unsigned int len;
>> enum insn_type type;
>> unsigned long immediate;
>> - bool alt_group, dead_end, ignore, hint, save, restore, ignore_alts;
>> + unsigned int alt_group;
>> + bool dead_end, ignore, hint, save, restore, ignore_alts;
>> bool retpoline_safe;
>> u8 visited;
>> struct symbol *call_dest;
>>
>
> Cheers,
>
next prev parent reply other threads:[~2020-04-02 12:34 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-02 8:22 [PATCH 0/7] objtool changes to remove most ANNOTATE_NOSPEC_ALTERNATIVE Alexandre Chartre
2020-04-02 8:22 ` [PATCH 1/7] objtool: is_fentry_call() crashes if call has no destination Alexandre Chartre
2020-04-02 8:22 ` [PATCH 2/7] objtool: Allow branches within the same alternative Alexandre Chartre
2020-04-02 12:03 ` Julien Thierry
2020-04-02 12:38 ` Alexandre Chartre [this message]
2020-04-02 8:22 ` [PATCH 3/7] objtool: Add support for intra-function calls Alexandre Chartre
2020-04-02 12:53 ` Julien Thierry
2020-04-02 13:24 ` Alexandre Chartre
2020-04-02 13:38 ` Julien Thierry
2020-04-02 14:56 ` Alexandre Chartre
2020-04-02 15:04 ` Peter Zijlstra
2020-04-02 15:54 ` Josh Poimboeuf
2020-04-03 7:06 ` Alexandre Chartre
2020-04-02 15:49 ` Josh Poimboeuf
2020-04-02 17:27 ` Josh Poimboeuf
2020-04-03 8:01 ` Julien Thierry
2020-04-03 12:41 ` Peter Zijlstra
2020-04-03 12:49 ` Julien Thierry
2020-04-03 14:37 ` Peter Zijlstra
2020-04-03 14:44 ` Josh Poimboeuf
2020-04-02 8:22 ` [PATCH 4/7] objtool: Add support for return trampoline call Alexandre Chartre
2020-04-02 13:26 ` Julien Thierry
2020-04-02 14:46 ` Alexandre Chartre
2020-04-02 15:31 ` Julien Thierry
2020-04-02 15:40 ` Peter Zijlstra
2020-04-03 8:11 ` Julien Thierry
2020-04-03 15:17 ` Josh Poimboeuf
2020-04-03 15:22 ` Josh Poimboeuf
2020-04-03 15:32 ` Josh Poimboeuf
2020-04-03 15:46 ` Peter Zijlstra
2020-04-03 15:55 ` Josh Poimboeuf
2020-04-04 13:32 ` Peter Zijlstra
2020-04-04 14:22 ` Josh Poimboeuf
2020-04-04 15:51 ` Peter Zijlstra
2020-04-06 8:19 ` Alexandre Chartre
2020-04-06 9:31 ` Peter Zijlstra
2020-04-06 11:03 ` Alexandre Chartre
2020-04-06 14:16 ` Josh Poimboeuf
2020-04-02 15:27 ` Peter Zijlstra
2020-04-03 7:19 ` Alexandre Chartre
2020-04-06 14:34 ` Alexandre Chartre
2020-04-06 14:55 ` Alexandre Chartre
2020-04-02 8:22 ` [PATCH 5/7] x86/speculation: Annotate intra-function calls Alexandre Chartre
2020-04-03 16:05 ` Josh Poimboeuf
2020-04-03 16:16 ` Josh Poimboeuf
2020-04-03 17:14 ` Alexandre Chartre
2020-04-03 17:18 ` Peter Zijlstra
2020-04-03 17:24 ` Josh Poimboeuf
2020-04-03 18:20 ` Peter Zijlstra
2020-04-02 8:22 ` [PATCH 6/7] x86/speculation: Annotate retpoline return instructions Alexandre Chartre
2020-04-02 8:22 ` [PATCH 7/7] x86/speculation: Remove most ANNOTATE_NOSPEC_ALTERNATIVE Alexandre Chartre
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=0824494b-15a9-f810-e81e-003d3d3b85cd@oracle.com \
--to=alexandre.chartre@oracle.com \
--cc=jpoimboe@redhat.com \
--cc=jthierry@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--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®