xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Jan Beulich <JBeulich@suse.com>
Cc: "Roger Pau Monné" <roger.pau@citrix.com>,
	"Wei Liu" <wei.liu2@citrix.com>,
	Xen-devel <xen-devel@lists.xen.org>
Subject: Re: [PATCH v2 5/7] x86/alt: Support for automatic padding calculations
Date: Wed, 28 Feb 2018 17:26:28 +0000	[thread overview]
Message-ID: <792eabfa-0de5-1b9d-395e-0af8613bb787@citrix.com> (raw)
In-Reply-To: <5A96E3FE02000078001ACF16@prv-mh.provo.novell.com>

On 28/02/18 16:16, Jan Beulich wrote:
>>>> On 26.02.18 at 12:35, <andrew.cooper3@citrix.com> wrote:
>> --- a/xen/arch/x86/Rules.mk
>> +++ b/xen/arch/x86/Rules.mk
>> @@ -24,6 +24,10 @@ $(call as-option-add,CFLAGS,CC,".equ \"x\"$$(comma)1", \
>>                       -U__OBJECT_LABEL__ -DHAVE_GAS_QUOTED_SYM \
>>                       '-D__OBJECT_LABEL__=$(subst $(BASEDIR)/,,$(CURDIR))/$$@')
>>  
>> +# GCC's idea of true is -1.  Clang's idea is 1
>> +$(call as-option-add,CFLAGS,CC,\
>> +    ".if ((1 > 0) < 0); .error \"\";.endif",,-DHAVE_AS_NEGATIVE_TRUE)
> With GCC replaced by gas, as indicated already be Roger
> (also in alternative*.h then)
> Reviewed-by: Jan Beulich <jbeulich@suse.com>
>
> However, I have a question to raise and a remark to make:
>
>>  .macro ALTERNATIVE oldinstr, newinstr, feature
>>  .L\@_orig_s:
>>      \oldinstr
>>  .L\@_orig_e:
>> +    /*
>> +     * Calculate the difference in size between the replacement and original
>> +     * instructions, to derive how much padding to introduce.
>> +     */
>> +    .L\@_diff = repl_len(1) - orig_len
>> +
>> +    .skip as_true(.L\@_diff > 0) * .L\@_diff, 0x90
> How certain are you that these forward references actually work on
> at least all half way recent gas versions? IOW I wonder whether it
> wouldn't be more safe to make these backward references (i.e.
> emitting the replacement code first).

This code is used unconditionally in Linux, so any binutils within their
minimum set work.

So overall, I'm going to err on the side of "yes" in answer to your
question.

>
>> @@ -45,18 +70,31 @@
>>  .L\@_orig_s:
>>      \oldinstr
>>  .L\@_orig_e:
>> +    /*
>> +     * Calculate the difference in size between the largest replacement and
>> +     * the original instructions, to derive how much padding to introduce.
>> +     */
>> +    .L\@_diff = as_max(repl_len(1), repl_len(2)) - orig_len
>> +
>> +     .skip as_true(.L\@_diff > 0) * .L\@_diff, 0x90
>> +.L\@_orig_p:
>>  
>>      .pushsection .altinstructions, "a", @progbits
>>  
>>      altinstruction_entry .L\@_orig_s, .L\@_repl_s1, \feature1, \
>> -        orig_len, repl_len(1)
>> +        orig_len, repl_len(1), pad_len
>>      altinstruction_entry .L\@_orig_s, .L\@_repl_s2, \feature2, \
>> -        orig_len, repl_len(2)
>> +        orig_len, repl_len(2), pad_len
>>  
>>      .section .discard, "a", @progbits
>> -    /* Assembler-time check that \newinstr{1,2} aren't longer than \oldinstr. */
>> -    .byte 0xff + repl_len(1) - orig_len
>> -    .byte 0xff + repl_len(2) - orig_len
>> +    /*
>> +     * Assembler-time checks:
>> +     *   - total_len <= 255
>> +     *   - \newinstr* <= total_len
>> +     */
>> +    .byte total_len
>> +    .byte 0xff + repl_len(1) - total_len
>> +    .byte 0xff + repl_len(2) - total_len
> Use as_max() here and emit only a single byte? I don't think the
> diagnostic will be any less helpful, as iirc it doesn't point out the
> line inside the macro anyway, so the developer will be left guessing
> anyway which of the two alternatives it was. Otoh with the
> padding size now being calculated, I don't see much point in these
> checks anymore anyway.

The bytes are discarded, so the quantity doesn't matter.  I can use max,
and you are correct that the line reference only ends up pointing to the
.macro itself.

However, I would prefer to keep these.  They've spotted two bugs in the
binutils development effort of .nops, and I'd prefer to be safe than sorry.

~Andrew

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2018-02-28 17:26 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-26 11:34 [PATCH RESEND v2 0/7] x86/alternatives: Support for automatic padding calculations Andrew Cooper
2018-02-26 11:34 ` [PATCH v2 1/7] x86/alt: Drop unused alternative infrastructure Andrew Cooper
2018-02-26 11:34 ` [PATCH v2 2/7] x86/alt: Clean up struct alt_instr and its users Andrew Cooper
2018-02-26 11:35 ` [PATCH v2 3/7] x86/alt: Clean up the assembly used to generate alternatives Andrew Cooper
2018-02-26 14:09   ` Roger Pau Monné
2018-02-28 15:59   ` Jan Beulich
2018-03-01 12:44   ` Wei Liu
2018-02-26 11:35 ` [PATCH v2 4/7] x86/asm: Remove opencoded uses of altinstruction_entry Andrew Cooper
2018-02-26 11:35 ` [PATCH v2 5/7] x86/alt: Support for automatic padding calculations Andrew Cooper
2018-02-28 16:16   ` Jan Beulich
2018-02-28 17:26     ` Andrew Cooper [this message]
2018-03-01  7:26       ` Jan Beulich
2018-02-26 11:35 ` [PATCH v2 6/7] x86/alt: Drop explicit padding of origin sites Andrew Cooper
2018-02-26 11:35 ` [PATCH v2 7/7] x86/build: Use new .nop directive when available Andrew Cooper
2018-02-26 12:31   ` Roger Pau Monné
2018-02-26 13:08     ` Andrew Cooper
2018-02-26 14:27       ` Roger Pau Monné
2018-02-28 16:22   ` Jan Beulich
2018-02-28 17:45     ` Andrew Cooper
2018-03-01  7:28       ` Jan Beulich
2018-03-01 10:36         ` Roger Pau Monné
2018-03-01 10:54           ` Jan Beulich
2018-03-01 16:58             ` Andrew Cooper
2018-03-02  7:10               ` Jan Beulich
2018-03-02 19:34                 ` Andrew Cooper
2018-03-05  8:33                   ` Jan Beulich

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=792eabfa-0de5-1b9d-395e-0af8613bb787@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=roger.pau@citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.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).