All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jan Beulich" <JBeulich@suse.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>,
	Wei Liu <wei.liu2@citrix.com>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	George Dunlap <George.Dunlap@eu.citrix.com>,
	Tim Deegan <tim@xen.org>, Ian Jackson <Ian.Jackson@eu.citrix.com>,
	Dario Faggioli <dfaggioli@suse.com>,
	Martin Pohlack <mpohlack@amazon.de>,
	Julien Grall <julien.grall@arm.com>,
	nmanthey@amazon.de, "Martin Mazein(amazein)" <amazein@amazon.de>,
	xen-devel <xen-devel@lists.xenproject.org>,
	Julian Stecklina <jsteckli@amazon.de>,
	David Woodhouse <dwmw@amazon.co.uk>,
	Bjoern Doebel <doebel@amazon.de>
Subject: Re: [PATCH SpectreV1+L1TF v4 01/11] is_control_domain: block speculation
Date: Fri, 25 Jan 2019 02:19:18 -0700	[thread overview]
Message-ID: <5C4AD49602000078002110BD@prv1-mh.provo.novell.com> (raw)
In-Reply-To: <f905db93-1a63-c60a-1e82-4bb2fef8f7ff@citrix.com>

>>> On 24.01.19 at 21:33, <andrew.cooper3@citrix.com> wrote:
> On 24/01/2019 12:07, Norbert Manthey wrote:
>> On 1/23/19 14:20, Jan Beulich wrote:
>>>>>> On 23.01.19 at 12:51, <nmanthey@amazon.de> wrote:
>>>> --- a/xen/include/xen/nospec.h
>>>> +++ b/xen/include/xen/nospec.h
>>>> @@ -58,6 +58,21 @@ static inline unsigned long 
> array_index_mask_nospec(unsigned long index,
>>>>      (typeof(_i)) (_i & _mask);                                          \
>>>>  })
>>>>  
>>>> +/*
>>>> + * allow to insert a read memory barrier into conditionals
>>>> + */
>>>> +#ifdef CONFIG_X86
>>>> +static inline bool lfence_true(void) { rmb(); return true; }
>>>> +#else
>>>> +static inline bool lfence_true(void) { return true; }
>>>> +#endif
>>>> +
>>>> +/*
>>>> + * protect evaluation of conditional with respect to speculation
>>>> + */
>>>> +#define evaluate_nospec(condition)                                      \
>>>> +    (((condition) && lfence_true()) || !lfence_true())
>>> It may be just me, but I think
>>>
>>> #define evaluate_nospec(condition)                                      \
>>>     ((condition) ? lfence_true() : !lfence_true())
>>>
>>> would better express the two-way nature of this.
>> I compared the binary output of the two variants, and they are the same
>> (for my build environment). I'll switch to your variant, in case nobody
>> objects.
> 
> Is it safe though?  The original variant is required by C to only
> evaluate one of the lfence_true() blocks, whereas the second variation
> could execute both of them and cmov the 1 and 0 together, which is wasteful.

For one I don't understand the connection between the initial
question and the explanation boiling down to a performance
concern. But I think I see what safety concern you may have.

And then I'm having difficulty following your interpretation of
what evaluation requirements C imposes: &&, ||, and ?: are all
sequence points. I'm implying from this that, as long as the
evaluation of the expressions has no side effects, it can
happen irrespective of source arrangements, and in particular
the compiler could translate both into exactly the same code.

Neither variant excludes the asm() getting moved by the
compiler anyway, despite the volatile - this is what the gcc doc
has to say on the topic: "Note that the compiler can move even
volatile asm instructions relative to other code, including across
jump instructions." It then goes on to explain how this can be
improved in source; I wonder whether we may want to follow
that advice and add a dependency on the calculated branch
condition. But of course this may further impact performance.

What's worse, "Under certain circumstances, GCC may duplicate
(or remove duplicates of) your assembly code when optimizing"
suggests to me that neither of the two variants are really safe
from getting converted to code actually matching the behavior
of L1TF_LFENCE_INTERMEDIATE. Do we perhaps need to
further complicate things and use (using naming derived from
the current version)

static inline bool lfence_bool(bool cond) {
    asm volatile ( "lfence" : "+X" (cond) );
    return cond;
}

#define evaluate_nospec(condition) ({ \
    bool cond_ = (condition); \
    ((cond_) ? lfence_bool(cond_) : !lfence_bool(cond_))

Jan



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

  reply	other threads:[~2019-01-25  9:19 UTC|newest]

Thread overview: 150+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-23 11:51 SpectreV1+L1TF Patch Series Norbert Manthey
2019-01-23 11:51 ` [PATCH SpectreV1+L1TF v4 01/11] is_control_domain: block speculation Norbert Manthey
2019-01-23 13:07   ` Jan Beulich
2019-01-23 13:20     ` Julien Grall
2019-01-23 13:40       ` Jan Beulich
2019-01-23 13:20   ` Jan Beulich
2019-01-24 12:07     ` Norbert Manthey
2019-01-24 20:33       ` Andrew Cooper
2019-01-25  9:19         ` Jan Beulich [this message]
2019-01-23 11:51 ` [PATCH SpectreV1+L1TF v4 02/11] is_hvm/pv_domain: " Norbert Manthey
2019-01-23 11:51 ` [PATCH SpectreV1+L1TF v4 03/11] config: introduce L1TF_LFENCE option Norbert Manthey
2019-01-23 13:18   ` Jan Beulich
2019-01-24 12:11     ` Norbert Manthey
2019-01-23 13:24   ` Julien Grall
2019-01-23 13:39     ` Jan Beulich
2019-01-23 13:44       ` Julien Grall
2019-01-23 14:45         ` Jan Beulich
2019-01-24 12:21           ` Norbert Manthey
2019-01-24 21:29   ` Andrew Cooper
2019-01-25 10:14     ` Jan Beulich
2019-01-25 10:50       ` Norbert Manthey
2019-01-25 13:09         ` Jan Beulich
2019-01-27 20:28           ` Norbert Manthey
2019-01-28  7:35             ` Jan Beulich
2019-01-28  7:56               ` Norbert Manthey
2019-01-28  8:24                 ` Jan Beulich
2019-01-28 10:07                   ` Norbert Manthey
2019-01-31 22:39       ` Andrew Cooper
2019-02-01  8:02         ` Jan Beulich
2019-01-23 11:51 ` [PATCH SpectreV1+L1TF v4 04/11] x86/hvm: block speculative out-of-bound accesses Norbert Manthey
2019-01-31 19:31   ` Andrew Cooper
2019-02-01  9:06     ` Jan Beulich
2019-01-23 11:51 ` [PATCH SpectreV1+L1TF v4 05/11] common/grant_table: " Norbert Manthey
2019-01-23 13:37   ` Jan Beulich
2019-01-28 14:45     ` Norbert Manthey
2019-01-28 15:09       ` Jan Beulich
2019-01-29  8:33         ` Norbert Manthey
2019-01-29  9:46           ` Jan Beulich
2019-01-29 13:47             ` Norbert Manthey
2019-01-29 15:11               ` Jan Beulich
2019-01-30  8:06                 ` Norbert Manthey
2019-01-30 11:35                   ` Jan Beulich
2019-01-23 11:51 ` [PATCH SpectreV1+L1TF v4 06/11] common/memory: " Norbert Manthey
2019-01-23 11:57 ` [PATCH SpectreV1+L1TF v4 07/11] nospec: enable lfence on Intel Norbert Manthey
2019-01-24 22:29   ` Andrew Cooper
2019-01-27 20:09     ` Norbert Manthey
2019-01-23 11:57 ` [PATCH SpectreV1+L1TF v4 08/11] xen/evtchn: block speculative out-of-bound accesses Norbert Manthey
2019-01-24 16:56   ` Jan Beulich
2019-01-24 19:50     ` Norbert Manthey
2019-01-25  9:23       ` Jan Beulich
2019-01-23 11:57 ` [PATCH SpectreV1+L1TF v4 09/11] x86/vioapic: " Norbert Manthey
2019-01-25 16:34   ` Jan Beulich
2019-01-28 11:03     ` Norbert Manthey
2019-01-28 11:12       ` Jan Beulich
2019-01-28 12:20         ` Norbert Manthey
2019-01-23 11:57 ` [PATCH SpectreV1+L1TF v4 10/11] x86/hvm/hpet: " Norbert Manthey
2019-01-25 16:50   ` Jan Beulich
2019-01-23 11:57 ` [PATCH SpectreV1+L1TF v4 11/11] x86/CPUID: " Norbert Manthey
2019-01-24 21:05 ` SpectreV1+L1TF Patch Series Andrew Cooper
2019-01-28 13:56   ` Norbert Manthey
2019-01-28  8:28 ` Jan Beulich
     [not found] ` <5C4EBD1A0200007800211954@suse.com>
2019-01-28  8:47   ` Juergen Gross
2019-01-28  9:56     ` Jan Beulich
     [not found]       ` <9C03B9BA0200004637554D14@prv1-mh.provo.novell.com>
     [not found]         ` <00FAA7AF020000F8B1E090C7@prv1-mh.provo.novell.com>
     [not found]           ` <00FAE7AF020000F8B1E090C7@prv1-mh.provo.novell.com>
2019-01-31 15:05             ` [PATCH SpectreV1+L1TF v5 1/9] xen/evtchn: block speculative out-of-bound accesses Jan Beulich
2019-02-01 13:45               ` Norbert Manthey
2019-02-01 14:08                 ` Jan Beulich
2019-02-05 13:42                   ` Norbert Manthey
     [not found]           ` <00FA27AF020000F8B1E090C7@prv1-mh.provo.novell.com>
2019-01-31 16:05             ` [PATCH SpectreV1+L1TF v5 2/9] x86/vioapic: " Jan Beulich
2019-02-01 13:54               ` Norbert Manthey
     [not found]           ` <00F867AF020000F8B1E090C7@prv1-mh.provo.novell.com>
2019-01-31 16:19             ` [PATCH SpectreV1+L1TF v5 3/9] x86/hvm: " Jan Beulich
2019-01-31 20:02               ` Andrew Cooper
2019-02-01  8:23                 ` Jan Beulich
2019-02-01 14:06                   ` Norbert Manthey
2019-02-01 14:31                     ` Jan Beulich
2019-02-01 14:05               ` Norbert Manthey
     [not found]           ` <0101A7AF020000F8B1E090C7@prv1-mh.provo.novell.com>
2019-01-31 16:35             ` [PATCH SpectreV1+L1TF v5 4/9] spec: add l1tf-barrier Jan Beulich
2019-02-05 14:23               ` Norbert Manthey
2019-02-05 14:43                 ` Jan Beulich
2019-02-06 13:02                   ` Norbert Manthey
2019-02-06 13:20                     ` Jan Beulich
     [not found]           ` <0101E7AF020000F8B1E090C7@prv1-mh.provo.novell.com>
2019-01-31 17:05             ` [PATCH SpectreV1+L1TF v5 5/9] nospec: introduce evaluate_nospec Jan Beulich
2019-02-05 14:32               ` Norbert Manthey
2019-02-08 13:44                 ` SpectreV1+L1TF Patch Series v6 Norbert Manthey
2019-02-08 13:44                   ` [PATCH SpectreV1+L1TF v6 1/9] xen/evtchn: block speculative out-of-bound accesses Norbert Manthey
2019-02-08 13:44                   ` [PATCH SpectreV1+L1TF v6 2/9] x86/vioapic: " Norbert Manthey
2019-02-08 13:44                   ` [PATCH SpectreV1+L1TF v6 3/9] x86/hvm: " Norbert Manthey
2019-02-08 13:44                   ` [PATCH SpectreV1+L1TF v6 4/9] spec: add l1tf-barrier Norbert Manthey
2019-02-08 13:44                   ` [PATCH SpectreV1+L1TF v6 5/9] nospec: introduce evaluate_nospec Norbert Manthey
2019-02-08 13:44                   ` [PATCH SpectreV1+L1TF v6 6/9] is_control_domain: block speculation Norbert Manthey
2019-02-08 13:44                   ` [PATCH SpectreV1+L1TF v6 7/9] is_hvm/pv_domain: " Norbert Manthey
2019-02-08 13:44                   ` [PATCH SpectreV1+L1TF v6 8/9] common/grant_table: block speculative out-of-bound accesses Norbert Manthey
2019-02-08 13:44                   ` [PATCH SpectreV1+L1TF v6 9/9] common/memory: " Norbert Manthey
2019-02-08 14:32                   ` SpectreV1+L1TF Patch Series v6 Julien Grall
     [not found]               ` <A18FF6C80200006BB1E090C7@prv1-mh.provo.novell.com>
     [not found]                 ` <01CCAAAF02000039B1E090C7@prv1-mh.provo.novell.com>
     [not found]                   ` <01CCEAAF02000039B1E090C7@prv1-mh.provo.novell.com>
2019-02-12 13:08                     ` [PATCH SpectreV1+L1TF v6 1/9] xen/evtchn: block speculative out-of-bound accesses Jan Beulich
2019-02-14 13:10                       ` Norbert Manthey
2019-02-14 13:20                         ` Jan Beulich
     [not found]                   ` <01CC2AAF02000039B1E090C7@prv1-mh.provo.novell.com>
2019-02-12 13:16                     ` [PATCH SpectreV1+L1TF v6 2/9] x86/vioapic: " Jan Beulich
2019-02-14 13:16                       ` Norbert Manthey
     [not found]                   ` <01CE6AAF02000039B1E090C7@prv1-mh.provo.novell.com>
2019-02-12 13:25                     ` [PATCH SpectreV1+L1TF v6 3/9] x86/hvm: " Jan Beulich
2019-02-12 14:05                       ` Norbert Manthey
2019-02-12 14:14                         ` Jan Beulich
2019-02-15  8:05                           ` Norbert Manthey
2019-02-15  8:55                             ` Jan Beulich
2019-02-15 10:50                               ` Norbert Manthey
2019-02-15 11:46                                 ` Jan Beulich
2019-02-18 14:47                                   ` Norbert Manthey
2019-02-18 15:56                                     ` Jan Beulich
     [not found]                   ` <01CFAAAF02000039B1E090C7@prv1-mh.provo.novell.com>
2019-02-12 13:44                     ` [PATCH SpectreV1+L1TF v6 4/9] spec: add l1tf-barrier Jan Beulich
2019-02-15  9:13                       ` Norbert Manthey
     [not found]                   ` <01CFEAAF02000039B1E090C7@prv1-mh.provo.novell.com>
2019-02-12 13:50                     ` [PATCH SpectreV1+L1TF v6 5/9] nospec: introduce evaluate_nospec Jan Beulich
2019-02-14 13:37                       ` Norbert Manthey
2019-02-12 14:12                     ` Jan Beulich
2019-02-14 13:42                       ` Norbert Manthey
     [not found]                   ` <01CF2AAF02000039B1E090C7@prv1-mh.provo.novell.com>
2019-02-12 14:11                     ` [PATCH SpectreV1+L1TF v6 6/9] is_control_domain: block speculation Jan Beulich
2019-02-14 13:45                       ` Norbert Manthey
     [not found]                   ` <23D9419E02000017B1E090C7@prv1-mh.provo.novell.com>
2019-02-12 14:31                     ` [PATCH SpectreV1+L1TF v6 9/9] common/memory: block speculative out-of-bound accesses Jan Beulich
2019-02-14 14:04                       ` Norbert Manthey
     [not found]                   ` <01CEAAAF02000039B1E090C7@prv1-mh.provo.novell.com>
2019-02-13 11:50                     ` [PATCH SpectreV1+L1TF v6 8/9] common/grant_table: " Jan Beulich
2019-02-15  9:55                       ` Norbert Manthey
2019-02-15 10:34                         ` Jan Beulich
2019-02-18 13:49                           ` Norbert Manthey
2019-02-18 16:08                             ` Jan Beulich
2019-02-19 21:47                               ` Norbert Manthey
     [not found]           ` <0104A7AF020000F8B1E090C7@prv1-mh.provo.novell.com>
2019-02-06 14:52             ` [PATCH SpectreV1+L1TF v5 " Jan Beulich
2019-02-06 15:06               ` Norbert Manthey
2019-02-06 15:53                 ` Jan Beulich
2019-02-07  9:50                   ` Norbert Manthey
2019-02-07 10:20                     ` Norbert Manthey
2019-02-07 14:00                       ` Jan Beulich
2019-02-07 16:20                         ` Norbert Manthey
     [not found]           ` <010527AF020000F8B1E090C7@prv1-mh.provo.novell.com>
2019-02-06 15:03             ` [PATCH SpectreV1+L1TF v5 6/9] is_control_domain: block speculation Jan Beulich
2019-02-06 15:36               ` Norbert Manthey
2019-02-06 16:01                 ` Jan Beulich
2019-02-07 10:02                   ` Norbert Manthey
     [not found]           ` <20F3469E02000096B1E090C7@prv1-mh.provo.novell.com>
2019-02-06 15:25             ` [PATCH SpectreV1+L1TF v5 9/9] common/memory: block speculative out-of-bound accesses Jan Beulich
2019-02-06 15:39               ` Norbert Manthey
2019-02-06 16:08                 ` Jan Beulich
2019-02-07  7:20                   ` Norbert Manthey
2019-01-28 10:01 SpectreV1+L1TF Patch Series Juergen Gross
2019-01-29 14:43 ` SpectreV1+L1TF Patch Series v5 Norbert Manthey
2019-01-29 14:43   ` [PATCH SpectreV1+L1TF v5 1/9] xen/evtchn: block speculative out-of-bound accesses Norbert Manthey
2019-01-29 14:43   ` [PATCH SpectreV1+L1TF v5 2/9] x86/vioapic: " Norbert Manthey
2019-01-29 14:43   ` [PATCH SpectreV1+L1TF v5 3/9] x86/hvm: " Norbert Manthey
2019-01-29 14:43   ` [PATCH SpectreV1+L1TF v5 4/9] spec: add l1tf-barrier Norbert Manthey
2019-01-29 14:43   ` [PATCH SpectreV1+L1TF v5 5/9] nospec: introduce evaluate_nospec Norbert Manthey
2019-02-08  9:20     ` Julien Grall
2019-01-29 14:43   ` [PATCH SpectreV1+L1TF v5 6/9] is_control_domain: block speculation Norbert Manthey
2019-01-29 14:43   ` [PATCH SpectreV1+L1TF v5 7/9] is_hvm/pv_domain: " Norbert Manthey
2019-01-29 14:43   ` [PATCH SpectreV1+L1TF v5 8/9] common/grant_table: block speculative out-of-bound accesses Norbert Manthey
2019-01-29 14:43   ` [PATCH SpectreV1+L1TF v5 9/9] common/memory: " Norbert Manthey

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=5C4AD49602000078002110BD@prv1-mh.provo.novell.com \
    --to=jbeulich@suse.com \
    --cc=George.Dunlap@eu.citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=amazein@amazon.de \
    --cc=andrew.cooper3@citrix.com \
    --cc=dfaggioli@suse.com \
    --cc=doebel@amazon.de \
    --cc=dwmw@amazon.co.uk \
    --cc=jsteckli@amazon.de \
    --cc=julien.grall@arm.com \
    --cc=konrad.wilk@oracle.com \
    --cc=mpohlack@amazon.de \
    --cc=nmanthey@amazon.de \
    --cc=sstabellini@kernel.org \
    --cc=tim@xen.org \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.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.