All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andi Kleen <ak@linux.intel.com>
To: speck@linutronix.de
Subject: [MODERATED] Re: [PATCH v2 3/8] MDSv2 5
Date: Mon, 10 Dec 2018 16:03:03 -0800	[thread overview]
Message-ID: <20181211000303.GB16024@tassilo.jf.intel.com> (raw)
In-Reply-To: <CAHk-=wg8+Dkp0abqFa6TZAWJq-KT9sgSr=XZuw7w96fmufuoyA@mail.gmail.com>


Hi Linus,

> So you have a non-inline function that
> 
>  - has a test to return early
> 
>  - does a *single* instruction
> 
>  - the instruction gets nop'ed out if it's not valid
> 
> all of which just *screams* "that's wrong" to me. Why isn't it inline
> and a static branch?

I tried inline originally, but it caused bad include loops with alternative.h
and mwait.h.

It could be done, but would need some restructuring in the includes.

I don't think it's worth it because going into idle 
isn't really that performance sensitive. Also if the
side effect is there its overhead really swamps any 
call overhead.

alternative already handles the noping, so I don't think we would
need a static branch, unless you want to toggle it at runtime?

> 
> The actual asm sequence also seems bad to me.
> 
> Why isn't that just using
> 
>         int val = __KERNEL_DS;
> 
> with the asm just doing
> 
>         "verw %[kernelds]" ..  [kernelds] "m" (val)
> 
> instead, letting gcc do the stack setup part.

It has to be the memory form, only that has the necessary side effect
in the microcode.

> 
> Maybe none of this matters simply because it's in the idle case, but
> the exact same issues happen for the kernel exit case.

kernel exit doesn't use the C code, it's custom assembler.

The only case where it may matter is KVM entry, but that is
only used with the software sequence, and that is quite
expensive anyways.

> 
> And no, we're not doing that insane kernel exit software case by
> default. Not without a whole lot of examples of horrid badness.
> 
> The data that system calls touch is basically already user data. Sure,
> there may be kernel pointers etc there, but we've already accepted
> those leaking locally for all the usual reasons that we have no
> control over.

It's encryption keys etc. too. But yes.

Another case is interrupt data -- for example the TCP stack
sometimes copies packet data.  Ok you could argue they 
should encrypt on the wire, but it still seems bogus 
to leak it.

Then if there are drivers which copy data in interrupts
they may also leak, but presumably that's rare these
days.

> 
> So the whole "let's add crazy long sequences to every kernel exit" is
> not going to happen. Not without a lot more explanations.

So you would prefer to only flush on context switch, and perhaps
for kernel crypto code and perhaps TCP stack if it copied anything?

One issue here is that to be really sure there no such other
cases it would need some way to audit all the code. I'm not 
sure there's a practical way to do such an audit.

FWIW from our tests so far the performance loss from the kernel exit overhead
doesn't seem to be that bad.

-Andi

  reply	other threads:[~2018-12-11  0:03 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-10 17:53 [MODERATED] [PATCH v2 0/8] MDSv2 8 Andi Kleen
2018-12-10 17:53 ` [MODERATED] [PATCH v2 1/8] MDSv2 4 Andi Kleen
2018-12-11 14:14   ` [MODERATED] " Paolo Bonzini
2018-12-12 21:22   ` Konrad Rzeszutek Wilk
2018-12-12 21:28     ` Andi Kleen
2018-12-12 21:25   ` Konrad Rzeszutek Wilk
2018-12-10 17:53 ` [MODERATED] [PATCH v2 2/8] MDSv2 1 Andi Kleen
2018-12-10 22:49   ` [MODERATED] " Jiri Kosina
2018-12-11  0:03     ` Andi Kleen
2018-12-11  0:13     ` Kanth Ghatraju
2018-12-11  2:00       ` Andi Kleen
2018-12-11  5:36       ` Jiri Kosina
2018-12-11 10:03       ` Borislav Petkov
2018-12-12 21:31         ` Konrad Rzeszutek Wilk
2018-12-12 21:43           ` Andi Kleen
2018-12-12 22:17           ` Borislav Petkov
2018-12-12 22:40             ` Konrad Rzeszutek Wilk
2018-12-12 22:45               ` Borislav Petkov
2018-12-13 15:15                 ` Andrew Cooper
2018-12-13 16:52                   ` Borislav Petkov
2018-12-10 17:53 ` [MODERATED] [PATCH v2 3/8] MDSv2 5 Andi Kleen
2018-12-10 23:00   ` [MODERATED] " Linus Torvalds
2018-12-11  0:03     ` Andi Kleen [this message]
2018-12-11  0:43       ` Linus Torvalds
2018-12-11  1:33         ` Linus Torvalds
2018-12-11  2:12           ` Andi Kleen
2018-12-11  2:20           ` Linus Torvalds
2018-12-11  3:25             ` Andi Kleen
2018-12-11 17:55               ` Linus Torvalds
2018-12-11 18:10                 ` Borislav Petkov
2018-12-11 18:21                 ` Linus Torvalds
2018-12-11 18:26                   ` Borislav Petkov
2018-12-11 19:47                   ` Andi Kleen
2018-12-11 21:22                   ` Thomas Gleixner
2018-12-12 14:02               ` [MODERATED] " Paolo Bonzini
2018-12-12 17:58                 ` Andi Kleen
2018-12-12 18:47                   ` Linus Torvalds
2018-12-13 19:44                     ` Linus Torvalds
2018-12-13 20:48                       ` Andi Kleen
2018-12-13 20:56                         ` Linus Torvalds
2018-12-15  0:30                         ` Andi Kleen
2018-12-11  2:10         ` Andi Kleen
2018-12-11  0:09     ` Andrew Cooper
2018-12-10 17:53 ` [MODERATED] [PATCH v2 4/8] MDSv2 0 Andi Kleen
2018-12-12 21:45   ` [MODERATED] " Konrad Rzeszutek Wilk
2018-12-12 22:09     ` Andi Kleen
2018-12-12 22:36       ` Konrad Rzeszutek Wilk
2018-12-10 17:53 ` [MODERATED] [PATCH v2 5/8] MDSv2 7 Andi Kleen
2018-12-11  0:33   ` [MODERATED] " Andrew Cooper
2018-12-12 18:05     ` Andrew Cooper
2018-12-12 21:41   ` Konrad Rzeszutek Wilk
2018-12-12 22:12     ` Andi Kleen
2018-12-10 17:53 ` [MODERATED] [PATCH v2 6/8] MDSv2 3 Andi Kleen
2018-12-11  0:37   ` [MODERATED] " Andrew Cooper
2018-12-11  0:46     ` Luck, Tony
2018-12-11  1:02       ` Andrew Cooper
2018-12-11  1:53       ` Andi Kleen
2018-12-10 17:53 ` [MODERATED] [PATCH v2 7/8] MDSv2 6 Andi Kleen
2018-12-10 17:53 ` [MODERATED] [PATCH v2 8/8] MDSv2 2 Andi Kleen

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=20181211000303.GB16024@tassilo.jf.intel.com \
    --to=ak@linux.intel.com \
    --cc=speck@linutronix.de \
    /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.