提交 cafd6659 编写于 作者: S Shane Wang 提交者: Avi Kivity

KVM: VMX: enable VMXON check with SMX enabled (Intel TXT)

Per document, for feature control MSR:

  Bit 1 enables VMXON in SMX operation. If the bit is clear, execution
        of VMXON in SMX operation causes a general-protection exception.
  Bit 2 enables VMXON outside SMX operation. If the bit is clear, execution
        of VMXON outside SMX operation causes a general-protection exception.

This patch is to enable this kind of check with SMX for VMXON in KVM.
Signed-off-by: NShane Wang <shane.wang@intel.com>
Signed-off-by: NAvi Kivity <avi@redhat.com>
上级 f1d86e46
...@@ -202,8 +202,9 @@ ...@@ -202,8 +202,9 @@
#define MSR_IA32_EBL_CR_POWERON 0x0000002a #define MSR_IA32_EBL_CR_POWERON 0x0000002a
#define MSR_IA32_FEATURE_CONTROL 0x0000003a #define MSR_IA32_FEATURE_CONTROL 0x0000003a
#define FEATURE_CONTROL_LOCKED (1<<0) #define FEATURE_CONTROL_LOCKED (1<<0)
#define FEATURE_CONTROL_VMXON_ENABLED (1<<2) #define FEATURE_CONTROL_VMXON_ENABLED_INSIDE_SMX (1<<1)
#define FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX (1<<2)
#define MSR_IA32_APICBASE 0x0000001b #define MSR_IA32_APICBASE 0x0000001b
#define MSR_IA32_APICBASE_BSP (1<<8) #define MSR_IA32_APICBASE_BSP (1<<8)
......
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
/* Global pointer to shared data; NULL means no measured launch. */ /* Global pointer to shared data; NULL means no measured launch. */
struct tboot *tboot __read_mostly; struct tboot *tboot __read_mostly;
EXPORT_SYMBOL(tboot);
/* timeout for APs (in secs) to enter wait-for-SIPI state during shutdown */ /* timeout for APs (in secs) to enter wait-for-SIPI state during shutdown */
#define AP_WAIT_TIMEOUT 1 #define AP_WAIT_TIMEOUT 1
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
#include <linux/ftrace_event.h> #include <linux/ftrace_event.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/tboot.h>
#include "kvm_cache_regs.h" #include "kvm_cache_regs.h"
#include "x86.h" #include "x86.h"
...@@ -1272,9 +1273,16 @@ static __init int vmx_disabled_by_bios(void) ...@@ -1272,9 +1273,16 @@ static __init int vmx_disabled_by_bios(void)
u64 msr; u64 msr;
rdmsrl(MSR_IA32_FEATURE_CONTROL, msr); rdmsrl(MSR_IA32_FEATURE_CONTROL, msr);
return (msr & (FEATURE_CONTROL_LOCKED | if (msr & FEATURE_CONTROL_LOCKED) {
FEATURE_CONTROL_VMXON_ENABLED)) if (!(msr & FEATURE_CONTROL_VMXON_ENABLED_INSIDE_SMX)
== FEATURE_CONTROL_LOCKED; && tboot_enabled())
return 1;
if (!(msr & FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX)
&& !tboot_enabled())
return 1;
}
return 0;
/* locked but not enabled */ /* locked but not enabled */
} }
...@@ -1282,21 +1290,23 @@ static int hardware_enable(void *garbage) ...@@ -1282,21 +1290,23 @@ static int hardware_enable(void *garbage)
{ {
int cpu = raw_smp_processor_id(); int cpu = raw_smp_processor_id();
u64 phys_addr = __pa(per_cpu(vmxarea, cpu)); u64 phys_addr = __pa(per_cpu(vmxarea, cpu));
u64 old; u64 old, test_bits;
if (read_cr4() & X86_CR4_VMXE) if (read_cr4() & X86_CR4_VMXE)
return -EBUSY; return -EBUSY;
INIT_LIST_HEAD(&per_cpu(vcpus_on_cpu, cpu)); INIT_LIST_HEAD(&per_cpu(vcpus_on_cpu, cpu));
rdmsrl(MSR_IA32_FEATURE_CONTROL, old); rdmsrl(MSR_IA32_FEATURE_CONTROL, old);
if ((old & (FEATURE_CONTROL_LOCKED |
FEATURE_CONTROL_VMXON_ENABLED)) test_bits = FEATURE_CONTROL_LOCKED;
!= (FEATURE_CONTROL_LOCKED | test_bits |= FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX;
FEATURE_CONTROL_VMXON_ENABLED)) if (tboot_enabled())
test_bits |= FEATURE_CONTROL_VMXON_ENABLED_INSIDE_SMX;
if ((old & test_bits) != test_bits) {
/* enable and lock */ /* enable and lock */
wrmsrl(MSR_IA32_FEATURE_CONTROL, old | wrmsrl(MSR_IA32_FEATURE_CONTROL, old | test_bits);
FEATURE_CONTROL_LOCKED | }
FEATURE_CONTROL_VMXON_ENABLED);
write_cr4(read_cr4() | X86_CR4_VMXE); /* FIXME: not cpu hotplug safe */ write_cr4(read_cr4() | X86_CR4_VMXE); /* FIXME: not cpu hotplug safe */
asm volatile (ASM_VMX_VMXON_RAX asm volatile (ASM_VMX_VMXON_RAX
: : "a"(&phys_addr), "m"(phys_addr) : : "a"(&phys_addr), "m"(phys_addr)
......
...@@ -150,6 +150,7 @@ extern int tboot_force_iommu(void); ...@@ -150,6 +150,7 @@ extern int tboot_force_iommu(void);
#else #else
#define tboot_enabled() 0
#define tboot_probe() do { } while (0) #define tboot_probe() do { } while (0)
#define tboot_shutdown(shutdown_type) do { } while (0) #define tboot_shutdown(shutdown_type) do { } while (0)
#define tboot_sleep(sleep_state, pm1a_control, pm1b_control) \ #define tboot_sleep(sleep_state, pm1a_control, pm1b_control) \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册