Skip to contentSkip to conversation

ASID: Flush by ASID

RFC PATCH In review Wei Wang2 2 participants 2 messages Jan 11, 2011 – Jan 12, 2011

lore
Share & tools
lore

Wei Wang2

author
#0 lore raw

RFC PATCH 2/2 ASID: Flush by ASID

This patch implements flush by asid feature for AMD CPUs. Thanks,
Wei

--
Advanced Micro Devices GmbH
Sitz: Dornach, Gemeinde Aschheim,
Landkreis München Registergericht München,
HRB Nr. 43632
WEEE-Reg-Nr: DE 12919551
Geschäftsführer:
Alberto Bozzo, Andrew Bowd

xen/arch/x86/hvm/svm/asid.c +11 -4
diff -r 940b8760c604 xen/arch/x86/hvm/svm/asid.c
@@ -26,12 +26,16 @@ void svm_asid_init(struct cpuinfo_x86 *c
 void svm_asid_init(struct cpuinfo_x86 *c)
 {
     int nasids = 0;
+    int svm_features = 0;
 
     /* Check for erratum #170, and leave ASIDs disabled if it's present. */
     if ( !cpu_has_amd_erratum(c, AMD_ERRATUM_170) )
         nasids = cpuid_ebx(0x8000000A);
-
-    hvm_asid_init(nasids, 0);
+    
+    /* We can't use cpu_has_flush_by_asid here because svm_feature_flags has
+     * been initialized yet. Use CPUID to find out instead. */
+    svm_features = cpuid_edx(0x8000000A);
+    hvm_asid_init(nasids, svm_features & (1 << SVM_FEATURE_FLUSHBYASID));
 }
 
 /*
@@ -42,7 +46,7 @@ asmlinkage void svm_asid_handle_vmrun(vo
 {
     struct vcpu *curr = current;
     struct vmcb_struct *vmcb = curr->arch.hvm_svm.vmcb;
-    bool_t need_flush = !!hvm_asid_handle_vmenter();
+    asid_action_t asid_action = hvm_asid_handle_vmenter();
 
     /* ASID 0 indicates that ASIDs are disabled. */
     if ( curr->arch.hvm_vcpu.asid == 0 )
@@ -53,7 +57,10 @@ asmlinkage void svm_asid_handle_vmrun(vo
     }
 
     vmcb_set_guest_asid(vmcb, curr->arch.hvm_vcpu.asid);
-    vmcb->tlb_control = need_flush;
+
+    /* Note: make sure asid_action value returned from hvm_asid_handle_vmenter
+    * matches SVM's definition here. */
+    curr->arch.hvm_svm.vmcb->tlb_control = asid_action;
 }
 
 /*
xen/include/asm-x86/hvm/svm/svm.h +1 -0
diff -r 940b8760c604 xen/include/asm-x86/hvm/svm/svm.h
@@ -80,6 +80,7 @@ extern u32 svm_feature_flags;
 #define cpu_has_svm_svml      cpu_has_svm_feature(SVM_FEATURE_SVML)
 #define cpu_has_svm_nrips     cpu_has_svm_feature(SVM_FEATURE_NRIPS)
 #define cpu_has_svm_cleanbits cpu_has_svm_feature(SVM_FEATURE_VMCBCLEAN)
+#define cpu_has_flush_by_asid cpu_has_svm_feature(SVM_FEATURE_FLUSHBYASID)
 #define cpu_has_pause_filter  cpu_has_svm_feature(SVM_FEATURE_PAUSEFILTER)
 
 #endif /* __ASM_X86_HVM_SVM_H__ */

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw

xen/arch/x86/hvm/svm/asid.c asmlinkage void svm_asid_handle_vmrun(vo · line 62

Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 11.01.11 at 18:55, Wei Wang2 <[email protected]> wrote:
xen/arch/x86/hvm/svm/asid.c +2 -0
+    /* Note: make sure asid_action value returned from hvm_asid_handle_vmenter
+    * matches SVM's definition here. */

Probably a good use case for BUILD_BUG_ON()?

Quoted 1 line

+ curr->arch.hvm_svm.vmcb->tlb_control = asid_action;

Jan