# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1276597903 -3600
# Node ID ba2c0eecaf7f0df5266e3d6c0f3736da3335ecae
# Parent 4d92fdd85762456d3a53e3a6b239389179687ed6
VMX: enforce INVVPID checking
Escalate to use a wider context invalidation if the requested context
invalidation is not supported.
Signed-off-by: Xin Li <xin.li@xxxxxxxxx>
xen-unstable changeset: 21598:a822156d9fbb
xen-unstable date: Fri Jun 11 09:34:58 2010 +0100
---
xen/arch/x86/hvm/vmx/vmcs.c | 9 ++++++++
xen/include/asm-x86/hvm/vmx/vmcs.h | 6 +++++
xen/include/asm-x86/hvm/vmx/vmx.h | 39 +++++++++++++++++++++++++++++++++----
3 files changed, 50 insertions(+), 4 deletions(-)
diff -r 4d92fdd85762 -r ba2c0eecaf7f xen/arch/x86/hvm/vmx/vmcs.c
--- a/xen/arch/x86/hvm/vmx/vmcs.c Tue Jun 15 11:31:19 2010 +0100
+++ b/xen/arch/x86/hvm/vmx/vmcs.c Tue Jun 15 11:31:43 2010 +0100
@@ -193,6 +193,15 @@ static void vmx_init_vmcs_config(void)
!(_vmx_ept_vpid_cap & VMX_EPT_WALK_LENGTH_4_SUPPORTED) ||
!(_vmx_ept_vpid_cap & VMX_EPT_INVEPT_ALL_CONTEXT) )
_vmx_secondary_exec_control &= ~SECONDARY_EXEC_ENABLE_EPT;
+
+ /*
+ * the CPU must support INVVPID all context invalidation, because we
+ * will use it as final resort if other types are not supported.
+ *
+ * Or we just don't use VPID.
+ */
+ if ( !(_vmx_ept_vpid_cap & VMX_VPID_INVVPID_ALL_CONTEXT) )
+ _vmx_secondary_exec_control &= ~SECONDARY_EXEC_ENABLE_VPID;
}
if ( _vmx_secondary_exec_control & SECONDARY_EXEC_ENABLE_EPT )
diff -r 4d92fdd85762 -r ba2c0eecaf7f xen/include/asm-x86/hvm/vmx/vmcs.h
--- a/xen/include/asm-x86/hvm/vmx/vmcs.h Tue Jun 15 11:31:19 2010 +0100
+++ b/xen/include/asm-x86/hvm/vmx/vmcs.h Tue Jun 15 11:31:43 2010 +0100
@@ -189,6 +189,12 @@ extern bool_t cpu_has_vmx_ins_outs_instr
#define VMX_EPT_INVEPT_INSTRUCTION 0x00100000
#define VMX_EPT_INVEPT_SINGLE_CONTEXT 0x02000000
#define VMX_EPT_INVEPT_ALL_CONTEXT 0x04000000
+
+#define VMX_VPID_INVVPID_INSTRUCTION 0x100000000ULL
+#define VMX_VPID_INVVPID_INDIVIDUAL_ADDR 0x10000000000ULL
+#define VMX_VPID_INVVPID_SINGLE_CONTEXT 0x20000000000ULL
+#define VMX_VPID_INVVPID_ALL_CONTEXT 0x40000000000ULL
+#define VMX_VPID_INVVPID_SINGLE_CONTEXT_RETAINING_GLOBAL 0x80000000000ULL
#define cpu_has_wbinvd_exiting \
(vmx_secondary_exec_control & SECONDARY_EXEC_WBINVD_EXITING)
diff -r 4d92fdd85762 -r ba2c0eecaf7f xen/include/asm-x86/hvm/vmx/vmx.h
--- a/xen/include/asm-x86/hvm/vmx/vmx.h Tue Jun 15 11:31:19 2010 +0100
+++ b/xen/include/asm-x86/hvm/vmx/vmx.h Tue Jun 15 11:31:43 2010 +0100
@@ -200,6 +200,18 @@ extern u64 vmx_ept_vpid_cap;
#define INVEPT_SINGLE_CONTEXT 1
#define INVEPT_ALL_CONTEXT 2
+#define cpu_has_vmx_vpid_invvpid_individual_addr \
+ (vmx_ept_vpid_cap & VMX_VPID_INVVPID_INDIVIDUAL_ADDR)
+#define cpu_has_vmx_vpid_invvpid_single_context \
+ (vmx_ept_vpid_cap & VMX_VPID_INVVPID_SINGLE_CONTEXT)
+#define cpu_has_vmx_vpid_invvpid_single_context_retaining_global \
+ (vmx_ept_vpid_cap & VMX_VPID_INVVPID_SINGLE_CONTEXT_RETAINING_GLOBAL)
+
+#define INVVPID_INDIVIDUAL_ADDR 0
+#define INVVPID_SINGLE_CONTEXT 1
+#define INVVPID_ALL_CONTEXT 2
+#define INVVPID_SINGLE_CONTEXT_RETAINING_GLOBAL 3
+
static inline void __vmptrld(u64 addr)
{
asm volatile ( VMPTRLD_OPCODE
@@ -305,7 +317,7 @@ static inline void __invept(int type, u6
: "memory" );
}
-static inline void __invvpid(int ext, u16 vpid, u64 gva)
+static inline void __invvpid(int type, u16 vpid, u64 gva)
{
struct {
u64 vpid:16;
@@ -322,7 +334,7 @@ static inline void __invvpid(int ext, u1
" "__FIXUP_WORD" 1b,2b\n"
".previous"
:
- : "a" (&operand), "c" (ext)
+ : "a" (&operand), "c" (type)
: "memory" );
}
@@ -335,12 +347,31 @@ void ept_sync_domain(struct domain *d);
static inline void vpid_sync_vcpu_gva(struct vcpu *v, unsigned long gva)
{
- __invvpid(0, v->arch.hvm_vcpu.asid, (u64)gva);
+ int type = INVVPID_INDIVIDUAL_ADDR;
+
+ /*
+ * If individual address invalidation is not supported, we escalate to
+ * use single context invalidation.
+ */
+ if ( likely(cpu_has_vmx_vpid_invvpid_individual_addr) )
+ goto execute_invvpid;
+
+ type = INVVPID_SINGLE_CONTEXT;
+
+ /*
+ * If single context invalidation is not supported, we escalate to
+ * use all context invalidation.
+ */
+ if ( !cpu_has_vmx_vpid_invvpid_single_context )
+ type = INVVPID_ALL_CONTEXT;
+
+execute_invvpid:
+ __invvpid(type, v->arch.hvm_vcpu.asid, (u64)gva);
}
static inline void vpid_sync_all(void)
{
- __invvpid(2, 0, 0);
+ __invvpid(INVVPID_ALL_CONTEXT, 0, 0);
}
static inline void __vmxoff(void)
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|