All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: "Jan Beulich" <JBeulich@suse.com>,
	"Roger Pau Monné" <roger.pau@citrix.com>
Cc: wei.liu2@citrix.com, xen-devel@lists.xen.org
Subject: Re: [PATCH v2 7/7] x86/build: Use new .nop directive when available
Date: Thu, 1 Mar 2018 16:58:36 +0000	[thread overview]
Message-ID: <b51b4ea4-464e-7cd8-29d1-0f57f4bfe890@citrix.com> (raw)
In-Reply-To: <5A97E9E802000078001AD36B@prv-mh.provo.novell.com>

On 01/03/18 10:54, Jan Beulich wrote:
>>>> On 01.03.18 at 11:36, <roger.pau@citrix.com> wrote:
>> On Thu, Mar 01, 2018 at 12:28:27AM -0700, Jan Beulich wrote:
>>>>>> Andrew Cooper <andrew.cooper3@citrix.com> 02/28/18 7:20 PM >>>
>>>> On 28/02/18 16:22, Jan Beulich wrote:
>>>>>>>> On 26.02.18 at 12:35, <andrew.cooper3@citrix.com> wrote:
>>>>>> --- a/xen/include/asm-x86/alternative-asm.h
>>>>>> +++ b/xen/include/asm-x86/alternative-asm.h
>>>>>> @@ -1,6 +1,8 @@
>>>>>>  #ifndef _ASM_X86_ALTERNATIVE_ASM_H_
>>>>>>  #define _ASM_X86_ALTERNATIVE_ASM_H_
>>>>>>  
>>>>>> +#include <asm/nops.h>
>>>>>> +
>>>>>>  #ifdef __ASSEMBLY__
>>>>>>  
>>>>>>  /*
>>>>>> @@ -18,6 +20,14 @@
>>>>>>      .byte \pad_len
>>>>>>  .endm
>>>>>>  
>>>>>> +.macro mknops nr_bytes
>>>>>> +#ifdef HAVE_AS_NOP_DIRECTIVE
>>>>>> +    .nop \nr_bytes, ASM_NOP_MAX
>>>>> And do you really need to specify ASM_NOP_MAX here? What's
>>>>> wrong with letting the assembler pick what it wants as the longest
>>>>> NOP?
>>>> I don't want a toolchain change to cause us to go beyond 11 byte nops,
>>>> because of the associated decode stall on almost all hardware.  Using
>>>> ASM_NOP_MAX seemed like the easiest way to keep the end result
>>>> consistent, irrespective of toolchain support.
>>> I don't understand - an earlier patch takes care of runtime replacing them
>>> anyway. What stalls can then result?
>> The runtime replacement won't happen when using the .nops directive
>> AFAICT, because the original padding section will likely be filled
>> with opcodes different than 0x90, and thus the runtime nop
>> optimization won't be performed.
> Oh, indeed. That puts under question the whole idea of using
> .nops in favor of .skip. Andrew, I'm sorry, but with this I prefer
> to withdraw my ack.
>
>> I also agree that using the default (not proving a second argument)
>> seems like a better solution. Why would the toolstack switch to
>> something that leads to worse performance? That would certainly be
>> considered a bug.
> Why? They may change it based on data available for newer /
> older / whatever hardware. Any build-time choice is going to be
> suboptimal somewhere, so I think we absolutely should not
> bypass runtime replacing these NOPs, the more that now we
> may have quite large sequences of them.

The pont of having the toolchain put out optimised nops is to avoid the
need for us to patch the site at all.  I.e. calling optimise_nops() on a
set of toolchain nops defeats the purpose in the overwhelming common
case of running on a system which prefers P6 nops.

The problem of working out when to optimise is that, when we come to
apply an individual alternative, we don't know if we've already patched
this site before.  Even the unoptimised algorithm has a corner case
which explodes, if there is a stream of 0x90's on the end of a
replacement e.g. in a imm or disp field.

Put simply, we cannot determine, by peeking at the patchsite, whether it
has been patched or not (other than keeping a full copy of the origin
site as a reference).  As soon as we chose to optimise the nops of the
origin site, we cannot determine anything at all.

Thinking out loud, we could perhaps have a section containing one byte
per origin site, which we use to track whether we've already optimised
the padding bytes, and whether the contents have been replaced.  This
would also add an extra long into struct altentry, but its all cold data
after boot.

~Andrew

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

  reply	other threads:[~2018-03-01 16:58 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
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 [this message]
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=b51b4ea4-464e-7cd8-29d1-0f57f4bfe890@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.