All of lore.kernel.org
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: speck@linutronix.de
Subject: [MODERATED] Re: [PATCH] L1TF KVM ARCH_CAPABILITIES #0
Date: Mon, 16 Jul 2018 16:44:18 -0400	[thread overview]
Message-ID: <20180716204418.GA17294@char.US.ORACLE.com> (raw)
In-Reply-To: <20180715135716.1874-1-pbonzini@redhat.com>

On Sun, Jul 15, 2018 at 03:57:12PM +0200, speck for Paolo Bonzini wrote:
> Support for ARCH_CAPABILITIES bit 3, which can already be used to disable
> the mitigations on a nested hypervisor.  Patch 3 will shortly go to Linus's
> tree.

Paolo,

I am thinking I am missing something here. I was expecting if I do
rdmsr 0x10a inside the guest I would get '8' but instead I got '0'?

The guest does see CPUID.7.EDX. Bit 29 so the guest does expose 'arch_capability'
in the /proc/cpuinfo flags.

And the data |= ARCH_CAP_SKIP.. is certainly run (added a printk there just
in case).

Thoughts?

(I wrote the patch before I saw the Intel's patch). This is on top of yesterday
QEMU's master tree.

From 09742087d36c6b786c10cc2bc0539aaed0f80e96 Mon Sep 17 00:00:00 2001
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Date: Fri, 13 Jul 2018 13:57:31 +0000
Subject: [PATCH] i386: Define the IA32_ARCH_CAPABILITIES capability.

GeminiLake CPUs have this and exposing this to the guest
allows kernels to sample the Enhanced IBRS support.

The definition of this MSR and detection (CPUID.(EAX=7H,ECX=0):EDX[29])
is nicely described in the Intel whitepaper titled:
336996-Speculative-Execution-Side-Channel-Mitigations.pdf

A copy of this document is available at
   https://bugzilla.kernel.org/show_bug.cgi?id=199511

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
---
 target/i386/cpu.c     |  2 +-
 target/i386/cpu.h     |  3 ++-
 target/i386/kvm.c     | 13 +++++++++++++
 target/i386/machine.c | 20 ++++++++++++++++++++
 4 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index e0e2f2e..070cb7c 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -1000,7 +1000,7 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
             NULL, NULL, NULL, NULL,
             NULL, NULL, NULL, NULL,
             NULL, NULL, "spec-ctrl", NULL,
-            NULL, NULL, NULL, "ssbd",
+            NULL, "arch-cap", NULL, "ssbd",
         },
         .cpuid_eax = 7,
         .cpuid_needs_ecx = true, .cpuid_ecx = 0,
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 2c5a0d9..2211b01 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -355,7 +355,7 @@ typedef enum X86Seg {
 #define MSR_IA32_SPEC_CTRL              0x48
 #define MSR_VIRT_SSBD                   0xc001011f
 #define MSR_IA32_TSCDEADLINE            0x6e0
-
+#define MSR_IA32_ARCH_CAPABILITIES	0x0000010a
 #define FEATURE_CONTROL_LOCKED                    (1<<0)
 #define FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX (1<<2)
 #define FEATURE_CONTROL_LMCE                      (1<<20)
@@ -1212,6 +1212,7 @@ typedef struct CPUX86State {
 
     uint64_t spec_ctrl;
     uint64_t virt_ssbd;
+    uint64_t arch_cap;
 
     /* End of state preserved by INIT (dummy marker).  */
     struct {} end_init_save;
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
index ebb2d23..b96d9f6 100644
--- a/target/i386/kvm.c
+++ b/target/i386/kvm.c
@@ -93,6 +93,7 @@ static bool has_msr_hv_reenlightenment;
 static bool has_msr_xss;
 static bool has_msr_spec_ctrl;
 static bool has_msr_virt_ssbd;
+static bool has_msr_arch_cap;
 static bool has_msr_smi_count;
 
 static uint32_t has_architectural_pmu_version;
@@ -1288,6 +1289,9 @@ static int kvm_get_supported_msrs(KVMState *s)
                 case MSR_VIRT_SSBD:
                     has_msr_virt_ssbd = true;
                     break;
+                case MSR_IA32_ARCH_CAPABILITIES:
+                    has_msr_arch_cap = true;
+                    break;
                 }
             }
         }
@@ -1802,6 +1806,9 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
     if (has_msr_virt_ssbd) {
         kvm_msr_entry_add(cpu, MSR_VIRT_SSBD, env->virt_ssbd);
     }
+    if (has_msr_arch_cap) {
+        kvm_msr_entry_add(cpu, MSR_IA32_ARCH_CAPABILITIES, env->arch_cap);
+    }
 
 #ifdef TARGET_X86_64
     if (lm_capable_kernel) {
@@ -2185,6 +2192,9 @@ static int kvm_get_msrs(X86CPU *cpu)
     if (has_msr_virt_ssbd) {
         kvm_msr_entry_add(cpu, MSR_VIRT_SSBD, 0);
     }
+    if (has_msr_arch_cap) {
+        kvm_msr_entry_add(cpu, MSR_IA32_ARCH_CAPABILITIES, 0);
+    }
     if (!env->tsc_valid) {
         kvm_msr_entry_add(cpu, MSR_IA32_TSC, 0);
         env->tsc_valid = !runstate_is_running();
@@ -2567,6 +2577,9 @@ static int kvm_get_msrs(X86CPU *cpu)
         case MSR_VIRT_SSBD:
             env->virt_ssbd = msrs[i].data;
             break;
+        case MSR_IA32_ARCH_CAPABILITIES:
+            env->arch_cap = msrs[i].data;
+            break;
         case MSR_IA32_RTIT_CTL:
             env->msr_rtit_ctrl = msrs[i].data;
             break;
diff --git a/target/i386/machine.c b/target/i386/machine.c
index 8b64dff..963cfc0 100644
--- a/target/i386/machine.c
+++ b/target/i386/machine.c
@@ -955,6 +955,25 @@ static const VMStateDescription vmstate_svm_npt = {
     }
 };
 
+static bool arch_cap_needed(void *opaque)
+{
+    X86CPU *cpu = opaque;
+    CPUX86State *env = &cpu->env;
+
+    return env->arch_cap != 0;
+}
+
+static const VMStateDescription vmstate_msr_arch_cap = {
+    .name = "cpu/arch_cap",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .needed = arch_cap_needed,
+    .fields = (VMStateField[]){
+        VMSTATE_UINT64(env.arch_cap, X86CPU),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 VMStateDescription vmstate_x86_cpu = {
     .name = "cpu",
     .version_id = 12,
@@ -1080,6 +1099,7 @@ VMStateDescription vmstate_x86_cpu = {
         &vmstate_msr_intel_pt,
         &vmstate_msr_virt_ssbd,
         &vmstate_svm_npt,
+        &vmstate_msr_arch_cap,
         NULL
     }
 };
-- 
1.8.3.1


> 
> Paolo Bonzini (4):
>   KVM: test L1TF EPT bug separately from X86_BUG_L1TF
>   x86: use ARCH_CAPABILITIES to skip L1D flush on vmentry
>   KVM: VMX: support MSR_IA32_ARCH_CAPABILITIES as a feature MSR
>   KVM: VMX: tell nested hypervisor to skip L1D flush on vmentry
> 
>  Documentation/admin-guide/l1tf.rst | 24 ++++++++++++++++++++++++
>  arch/x86/include/asm/kvm_host.h    |  1 +
>  arch/x86/include/asm/msr-index.h   |  1 +
>  arch/x86/include/asm/vmx.h         |  1 +
>  arch/x86/kernel/cpu/bugs.c         | 26 ++++++++++++++++++++------
>  arch/x86/kvm/vmx.c                 | 35 ++++++++++++++++++++++++-----------
>  arch/x86/kvm/x86.c                 | 17 ++++++++++++++++-
>  7 files changed, 87 insertions(+), 18 deletions(-)
> 
> -- 
> 1.8.3.1

  parent reply	other threads:[~2018-07-16 20:44 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-15 13:57 [MODERATED] [PATCH] L1TF KVM ARCH_CAPABILITIES #0 Paolo Bonzini
2018-07-15 13:57 ` [MODERATED] [PATCH] L1TF KVM ARCH_CAPABILITIES #1 Paolo Bonzini
2018-07-16 14:36   ` [MODERATED] " Konrad Rzeszutek Wilk
2018-07-16 20:02   ` Thomas Gleixner
2018-07-17 11:20     ` [MODERATED] " Paolo Bonzini
2018-07-17 11:28       ` Thomas Gleixner
2018-07-17 17:11         ` [MODERATED] " Paolo Bonzini
2018-07-17 19:23           ` Thomas Gleixner
2018-07-15 13:57 ` [MODERATED] [PATCH] L1TF KVM ARCH_CAPABILITIES #2 Paolo Bonzini
2018-07-16 20:04   ` Thomas Gleixner
2018-07-16 20:31     ` Thomas Gleixner
2018-07-16 20:41       ` [MODERATED] " Luck, Tony
2018-07-16 21:13         ` Thomas Gleixner
2018-07-15 13:57 ` [MODERATED] [PATCH] L1TF KVM ARCH_CAPABILITIES #3 Paolo Bonzini
2018-07-15 13:57 ` [MODERATED] [PATCH] L1TF KVM ARCH_CAPABILITIES #4 Paolo Bonzini
2018-07-16 14:58   ` [MODERATED] " Konrad Rzeszutek Wilk
2018-07-16 20:06   ` Thomas Gleixner
2018-07-17 11:14     ` [MODERATED] " Paolo Bonzini
2018-07-16 20:44 ` Konrad Rzeszutek Wilk [this message]
2018-07-17 11:22   ` [MODERATED] Re: [PATCH] L1TF KVM ARCH_CAPABILITIES #0 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=20180716204418.GA17294@char.US.ORACLE.com \
    --to=konrad.wilk@oracle.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.