From: Alexandre Chartre <alexandre.chartre@oracle.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: jpoimboe@redhat.com, linux-kernel@vger.kernel.org,
jthierry@redhat.com, tglx@linutronix.de, x86@kernel.org,
mbenes@suse.cz
Subject: Re: [PATCH 3/8] objtool: Rework allocating stack_ops on decode
Date: Fri, 24 Apr 2020 09:06:25 +0200 [thread overview]
Message-ID: <cc303a83-58eb-2b61-ddf1-672f2c8644e1@oracle.com> (raw)
In-Reply-To: <20200423155425.GW20730@hirez.programming.kicks-ass.net>
On 4/23/20 5:54 PM, Peter Zijlstra wrote:
> On Thu, Apr 23, 2020 at 05:40:38PM +0200, Alexandre Chartre wrote:
>
>>> @@ -77,6 +77,17 @@ unsigned long arch_jump_destination(stru
>>> return insn->offset + insn->len + insn->immediate;
>>> }
>>> +#define PUSH_OP(op) \
>>> +({ \
>>> + list_add_tail(&op->list, ops_list); \
>>> + NULL; \
>>> +})
>>> +
>>> +#define ADD_OP(op) \
>>> + if (!(op = calloc(1, sizeof(*op)))) \
>>> + return -1; \
>>> + else for (; op; op = PUSH_OP(op))
>>> +
>>
>> I would better have a function to alloc+add op instead of weird macros,
>> for example:
>>
>> static struct stack_op *add_op(void)
>> {
>> struct stack *op;
>>
>> op = calloc(1, sizeof(*op));
>> if (!op)
>> return NULL;
>> list_add_tail(&op->list, ops_list);
>> }
>>
>> Then it requires two more lines when using it but I think the code is much
>> cleaner and clearer, e.g.:
>>
>> op = add_op();
>> if (!op)
>> return -1;
>> op->src.type = OP_SRC_ADD;
>> op->src.reg = op_to_cfi_reg[modrm_reg][rex_r];
>> op->dest.type = OP_DEST_REG;
>> op->dest.reg = CFI_SP;
>
> The 'problem' which this is that it doesn't NULL op again, so any later
> use will do 'funny' things instead of crashing sensibly.
Then you can use a local variable:
{
struct stack_op *op = add_op();
if (!op)
return -1;
op->src.type = OP_SRC_ADD;
op->src.reg = op_to_cfi_reg[modrm_reg][rex_r];
op->dest.type = OP_DEST_REG;
op->dest.reg = CFI_SP;
}
> Also, I'm mightly lazy, I don't like endlessly repeating the same things.
Me too, I often try to use macros to avoid repeating the same thing, and usually
spend a lot of time trying fancy macros and eventually realize that this is
usually not worth it.
So here, we are down to a two line differences:
ADD_OP(op) {
...
}
vs.
{
struct stack *op = add_op();
if (!op)
return -1;
...
}
Anyway, I leave it up to you, that's just coding preferences.
In any case:
Reviewed-by: Alexandre Chartre <alexandre.chartre@oracle.com>
Thanks,
alex.
next prev parent reply other threads:[~2020-04-24 7:02 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-23 12:47 [PATCH 0/8] objtool vs retpoline Peter Zijlstra
2020-04-23 12:47 ` [PATCH 1/8] objtool: is_fentry_call() crashes if call has no destination Peter Zijlstra
2020-04-23 12:47 ` [PATCH 2/8] objtool: UNWIND_HINT_RET_OFFSET should not check registers Peter Zijlstra
2020-04-23 12:47 ` [PATCH 3/8] objtool: Rework allocating stack_ops on decode Peter Zijlstra
2020-04-23 15:40 ` Alexandre Chartre
2020-04-23 15:54 ` Peter Zijlstra
2020-04-24 7:06 ` Alexandre Chartre [this message]
2020-04-23 16:16 ` Peter Zijlstra
2020-04-24 9:43 ` Miroslav Benes
2020-04-23 12:47 ` [PATCH 4/8] objtool: Add support for intra-function calls Peter Zijlstra
2020-04-23 14:34 ` Miroslav Benes
2020-04-23 15:22 ` Peter Zijlstra
2020-04-24 9:37 ` Miroslav Benes
2020-04-24 14:07 ` Miroslav Benes
2020-04-23 12:47 ` [PATCH 5/8] x86/speculation: Change FILL_RETURN_BUFFER to work with objtool Peter Zijlstra
2020-04-23 15:45 ` Alexandre Chartre
2020-04-24 19:04 ` Josh Poimboeuf
2020-04-23 12:47 ` [PATCH 6/8] x86: Simplify retpoline declaration Peter Zijlstra
2020-04-24 19:09 ` Josh Poimboeuf
2020-04-23 12:47 ` [PATCH 7/8] x86: Change {JMP,CALL}_NOSPEC argument Peter Zijlstra
2020-04-23 12:47 ` [PATCH 8/8] x86/retpoline: Fix retpoline unwind Peter Zijlstra
2020-04-23 12:59 ` Peter Zijlstra
2020-04-24 19:30 ` Josh Poimboeuf
2020-04-28 18:30 ` Peter Zijlstra
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=cc303a83-58eb-2b61-ddf1-672f2c8644e1@oracle.com \
--to=alexandre.chartre@oracle.com \
--cc=jpoimboe@redhat.com \
--cc=jthierry@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mbenes@suse.cz \
--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®