All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: speck@linutronix.de
Subject: [MODERATED] Re: [patch V10 00/10] Control knobs and Documentation 0
Date: Fri, 13 Jul 2018 18:22:47 +0200	[thread overview]
Message-ID: <6e2b04bb-4786-ae48-1fe8-e1bbdbcd8b92@redhat.com> (raw)
In-Reply-To: <20180712141902.576562442@linutronix.de>

[-- Attachment #1: Type: text/plain, Size: 5676 bytes --]

On 12/07/2018 16:19, speck for Thomas Gleixner wrote:
> The following series provides the following changes:
> 
>   - Fix EPT=off handling so it avoids flushing
>   
>   - Expose proper VMX mitigation information in sysfs
> 
>   - Drops the MSR list mechanism for flush 'always' to prepare for runtime
>     control. The default flush mechanism is conditional anyway and the MSR
>     list is set up at guest init time, which is nasty to run time switch
>     especially because the static key is a global control which can be
>     flipped by an update.
> 
>   - Make the flush always/conditional static key based.
> 
>   - Serialize the kvm parameter setter function
> 
>   - Enable runtime control for the kvm parameter
> 
>   - Add the l1tf command line option. It's not run time controllable as it
>     does not make sense to have 3 knobs at runtime. For the command line
>     the combo knob setting the default is convenient
> 
>   - Documentation update
> 
> This takes the review comments into account as much as still applicable.
> 
> Thanks to Jiri for testing the lot and debugging and fixing my brainfarts!
> 
> Git bundle follows in separate mail.

Another case on top of this series...

---------------------- 8< --------------------
From a0f605fed99cf1623f8716b22c11113653c258a3 Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <pbonzini@redhat.com>
Date: Fri, 13 Jul 2018 18:15:29 +0200
Subject: [PATCH] kvm: vmx: disable L1D flush when running as a nested
 hypervisor

VMENTER operations from the nested hypervisor into the nested guest
will always be processed by the bare metal hypervisor.  Therefore,
when running as a nested hypervisor, doing L1D cache flushes on vmentry
will result in twice the work and twice the slowdown, for no benefit.

Special case this situation and report it in sysfs.

(The three levels involved are usually called L0/L1/L2 in KVM slang.  I'm
avoiding that naming because of the confusion with cache levels).

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 Documentation/admin-guide/l1tf.rst | 23 ++++++++++++++++++++++-
 arch/x86/include/asm/vmx.h         |  1 +
 arch/x86/kernel/cpu/bugs.c         |  3 -++
 arch/x86/kvm/vmx.c                 |  5 +++++
 4 files changed, 30 insertions(+), 2 deletion(-)

diff --git a/Documentation/admin-guide/l1tf.rst b/Documentation/admin-guide/l1tf.rst
index 5adf7d7c2b4e..a962afbce156 100644
--- a/Documentation/admin-guide/l1tf.rst
+++ b/Documentation/admin-guide/l1tf.rst
@@ -528,6 +528,27 @@ available:
     EPT can be disabled in the hypervisor via the 'kvm-intel.ept'
     parameter.
 
+3.4. Nested virtual machines
+""""""""""""""""""""""""""""
+
+When nested virtualization is in use, three operating systems are involved:
+the bare metal hypervisor, the nested hypervisor, and the nested virtual
+machine.  VMENTER operations from the nested hypervisor into the nested
+guest will always be processed by the bare metal hypervisor.  Therefore,
+when running as a nested hypervisor, KVM will not perform any L1D cache
+flush, assuming instead that the "outermost" hypervisor takes care of
+flushing the L1D cache on VMENTER to nested guests.
+
+When running as a bare metal hypervisor, instead, KVM will:
+
+ - flush the L1D cache on every switch from nested hypervisor to
+   nested virtual machine, so that the nested hypervisor's secrets
+   are not exposed to the nested virtual machine;
+
+ - flush the L1D cache on every switch from nested virtual machine to
+   nested hypervisor; this is a complex operation, and flushing the L1D
+   cache avoids that the bare metal hypervisor's secrets be exposed
+   to the nested virtual machine.
 
 .. _default_mitigations:
 
@@ -540,7 +561,7 @@ Default mitigations
     unconditionally and cannot be controlled.
 
   - L1D conditional flushing on VMENTER when EPT is enabled for
-    a guest.
+    a guest, and the guest is not a nested virtual machine.
 
   The kernel does not by default enforce the disabling of SMT, which leaves
   SMT systems vulnerable when running untrusted guests with EPT enabled.
diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h
index 94a8547d915b..7c0438751fa5 100644
--- a/arch/x86/include/asm/vmx.h
+++ b/arch/x86/include/asm/vmx.h
@@ -579,6 +579,7 @@ enum vmx_l1d_flush_state {
 	VMENTER_L1D_FLUSH_COND,
 	VMENTER_L1D_FLUSH_ALWAYS,
 	VMENTER_L1D_FLUSH_EPT_DISABLED,
+	VMENTER_L1D_FLUSH_NESTED_VM,
 };
 
 extern enum vmx_l1d_flush_state l1tf_vmx_mitigation;
diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index d63cb1501784..87828f2f64a5 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -745,7 +745,8 @@ static const char *l1tf_vmx_states[] = {
 	[VMENTER_L1D_FLUSH_NEVER]	= "vulnerable",
 	[VMENTER_L1D_FLUSH_COND]	= "conditional cache flushes",
 	[VMENTER_L1D_FLUSH_ALWAYS]	= "cache flushes",
-	[VMENTER_L1D_FLUSH_EPT_DISABLED]= "EPT disabled"
+	[VMENTER_L1D_FLUSH_EPT_DISABLED]= "EPT disabled",
+	[VMENTER_L1D_FLUSH_NESTED_VM]   = "nested virtual machine",
 };
 
 static ssize_t l1tf_show_state(char *buf)
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index c5c0118b126d..a7e41ac4256f 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -212,6 +212,11 @@ static int vmx_setup_l1d_flush(enum vmx_l1d_flush_state l1tf)
 {
 	struct page *page;
 
+	if (static_cpu_has(X86_FEATURE_HYPERVISOR)) {
+		l1tf_vmx_mitigation = VMENTER_L1D_FLUSH_NESTED_VM;
+		return 0;
+	}
+
 	if (!enable_ept) {
 		l1tf_vmx_mitigation = VMENTER_L1D_FLUSH_EPT_DISABLED;
 		return 0;
-- 
2.17.1


  parent reply	other threads:[~2018-07-13 16:51 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-12 14:19 [patch V10 00/10] Control knobs and Documentation 0 Thomas Gleixner
2018-07-12 14:19 ` [patch V10 01/10] Control knobs and Documentation 1 Thomas Gleixner
2018-07-12 15:34   ` [MODERATED] " Greg KH
2018-07-12 15:38     ` Thomas Gleixner
2018-07-12 15:46       ` Thomas Gleixner
2018-07-12 17:08         ` [MODERATED] " Greg KH
2018-07-12 14:19 ` [patch V10 02/10] Control knobs and Documentation 2 Thomas Gleixner
2018-07-12 17:09   ` [MODERATED] " Greg KH
2018-07-12 14:19 ` [patch V10 03/10] Control knobs and Documentation 3 Thomas Gleixner
2018-07-12 16:13   ` [MODERATED] " Josh Poimboeuf
2018-07-13  9:10     ` Thomas Gleixner
2018-07-12 17:09   ` [MODERATED] " Greg KH
2018-07-12 14:19 ` [patch V10 04/10] Control knobs and Documentation 4 Thomas Gleixner
2018-07-12 17:10   ` [MODERATED] " Greg KH
2018-07-12 14:19 ` [patch V10 05/10] Control knobs and Documentation 5 Thomas Gleixner
2018-07-12 17:10   ` [MODERATED] " Greg KH
2018-07-12 14:19 ` [patch V10 06/10] Control knobs and Documentation 6 Thomas Gleixner
2018-07-12 16:14   ` [MODERATED] " Josh Poimboeuf
2018-07-12 17:10   ` Greg KH
2018-07-12 14:19 ` [patch V10 07/10] Control knobs and Documentation 7 Thomas Gleixner
2018-07-12 17:11   ` [MODERATED] " Greg KH
2018-07-12 14:19 ` [patch V10 08/10] Control knobs and Documentation 8 Thomas Gleixner
2018-07-12 16:22   ` [MODERATED] " Josh Poimboeuf
2018-07-12 17:12     ` Greg KH
2018-07-13  9:18     ` Thomas Gleixner
2018-07-12 17:17   ` [MODERATED] " Greg KH
2018-07-12 14:19 ` [patch V10 09/10] Control knobs and Documentation 9 Thomas Gleixner
2018-07-12 16:24   ` [MODERATED] " Josh Poimboeuf
2018-07-12 17:17     ` Greg KH
2018-07-12 17:16   ` Greg KH
2018-07-15  3:12   ` Kees Cook
2018-07-12 14:19 ` [patch V10 10/10] Control knobs and Documentation 10 Thomas Gleixner
2018-07-12 16:03   ` [MODERATED] " Linus Torvalds
2018-07-12 16:31     ` Peter Zijlstra
2018-07-12 16:13   ` Josh Poimboeuf
2018-07-12 16:26     ` Josh Poimboeuf
2018-07-13  9:09     ` Thomas Gleixner
2018-07-12 17:18   ` [MODERATED] " Greg KH
2018-07-15  7:30   ` Borislav Petkov
2018-07-27 16:41   ` Dave Hansen
2018-07-12 14:54 ` [patch V10 00/10] Control knobs and Documentation 0 Thomas Gleixner
2018-07-12 19:30 ` [MODERATED] " Josh Poimboeuf
2018-07-13 15:03   ` Thomas Gleixner
2018-07-13  8:30 ` [MODERATED] " Jiri Kosina
2018-07-13 16:22 ` Paolo Bonzini [this message]
2018-07-13 16:56   ` Andrew Cooper
2018-07-13 17:01     ` Paolo Bonzini
2018-07-13 17:28   ` Konrad Rzeszutek Wilk
2018-07-15 13:58     ` Paolo Bonzini

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=6e2b04bb-4786-ae48-1fe8-e1bbdbcd8b92@redhat.com \
    --to=pbonzini@redhat.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.