Skip to contentSkip to conversation

KVM: SVM: Add support Flush-By-ASID feature

PATCH Applied Joerg Roedel 3 participants 6 messages Dec 3, 2010 – Dec 7, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover KVM: SVM: Add support Flush-By-ASID feature

Hi Avi, Hi Marcelo,

here is the patch-set to add support for the Flush-By-ASID feature to KVM on AMD. Patches 1 and 2 clean up the code a little bit and patch 3 implements the feature itself.

Regards,

Joerg

 arch/x86/include/asm/svm.h |    2 ++
 arch/x86/kvm/svm.c         |   32 ++++++++++++++------------------
 2 files changed, 16 insertions(+), 18 deletions(-)

Joerg Roedel (3):
KVM: SVM: Remove flush_guest_tlb function
KVM: SVM: Use svm_flush_tlb instead of force_new_asid
KVM: SVM: Implement Flush-By-Asid feature

#1 lore raw

PATCH 1/3 KVM: SVM: Remove flush_guest_tlb function

This function is unused and there is svm_flush_tlb which does the same. So this function can be removed.

---
 arch/x86/kvm/svm.c |    5 -----
 1 files changed, 0 insertions(+), 5 deletions(-)
arch/x86/kvm/svm.c +0 -5
index c00ea90..772d48e 100644
@@ -389,11 +389,6 @@ static inline void force_new_asid(struct kvm_vcpu *vcpu)
 	to_svm(vcpu)->asid_generation--;
 }
 
-static inline void flush_guest_tlb(struct kvm_vcpu *vcpu)
-{
-	force_new_asid(vcpu);
-}
-
 static int get_npt_level(void)
 {
 #ifdef CONFIG_X86_64
Signature · 1 line
1.7.1
#2 lore raw

PATCH 2/3 KVM: SVM: Use svm_flush_tlb instead of force_new_asid

In reply to Joerg Roedel

This patch replaces all calls to force_new_asid which are intended to flush the guest-tlb by the more appropriate function svm_flush_tlb. As a side-effect the force_new_asid function is removed.

---
 arch/x86/kvm/svm.c |   19 +++++++------------
 1 files changed, 7 insertions(+), 12 deletions(-)
arch/x86/kvm/svm.c +7 -12
index 772d48e..b70a1e8 100644
@@ -384,11 +384,6 @@ static inline void invlpga(unsigned long addr, u32 asid)
 	asm volatile (__ex(SVM_INVLPGA) : : "a"(addr), "c"(asid));
 }
 
-static inline void force_new_asid(struct kvm_vcpu *vcpu)
-{
-	to_svm(vcpu)->asid_generation--;
-}
-
 static int get_npt_level(void)
 {
 #ifdef CONFIG_X86_64
@@ -958,7 +953,7 @@ static void init_vmcb(struct vcpu_svm *svm)
 		save->cr3 = 0;
 		save->cr4 = 0;
 	}
-	force_new_asid(&svm->vcpu);
+	svm->asid_generation = 0;
 
 	svm->nested.vmcb = 0;
 	svm->vcpu.arch.hflags = 0;
@@ -1371,7 +1366,7 @@ static void svm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
 	unsigned long old_cr4 = to_svm(vcpu)->vmcb->save.cr4;
 
 	if (npt_enabled && ((old_cr4 ^ cr4) & X86_CR4_PGE))
-		force_new_asid(vcpu);
+		svm_flush_tlb(vcpu);
 
 	vcpu->arch.cr4 = cr4;
 	if (!npt_enabled)
@@ -1706,7 +1701,7 @@ static void nested_svm_set_tdp_cr3(struct kvm_vcpu *vcpu,
 	struct vcpu_svm *svm = to_svm(vcpu);
 
 	svm->vmcb->control.nested_cr3 = root;
-	force_new_asid(vcpu);
+	svm_flush_tlb(vcpu);
 }
 
 static void nested_svm_inject_npf_exit(struct kvm_vcpu *vcpu)
@@ -2307,7 +2302,7 @@ static bool nested_svm_vmrun(struct vcpu_svm *svm)
 	svm->nested.intercept_exceptions = nested_vmcb->control.intercept_exceptions;
 	svm->nested.intercept            = nested_vmcb->control.intercept;
 
-	force_new_asid(&svm->vcpu);
+	svm_flush_tlb(&svm->vcpu);
 	svm->vmcb->control.int_ctl = nested_vmcb->control.int_ctl | V_INTR_MASKING_MASK;
 	if (nested_vmcb->control.int_ctl & V_INTR_MASKING_MASK)
 		svm->vcpu.arch.hflags |= HF_VINTR_MASK;
@@ -3242,7 +3237,7 @@ static int svm_set_tss_addr(struct kvm *kvm, unsigned int addr)
 
 static void svm_flush_tlb(struct kvm_vcpu *vcpu)
 {
-	force_new_asid(vcpu);
+	to_svm(vcpu)->asid_generation--;
 }
 
 static void svm_prepare_guest_switch(struct kvm_vcpu *vcpu)
@@ -3491,7 +3486,7 @@ static void svm_set_cr3(struct kvm_vcpu *vcpu, unsigned long root)
 	struct vcpu_svm *svm = to_svm(vcpu);
 
 	svm->vmcb->save.cr3 = root;
-	force_new_asid(vcpu);
+	svm_flush_tlb(vcpu);
 }
 
 static void set_tdp_cr3(struct kvm_vcpu *vcpu, unsigned long root)
@@ -3503,7 +3498,7 @@ static void set_tdp_cr3(struct kvm_vcpu *vcpu, unsigned long root)
 	/* Also sync guest cr3 here in case we live migrate */
 	svm->vmcb->save.cr3 = vcpu->arch.cr3;
 
-	force_new_asid(vcpu);
+	svm_flush_tlb(vcpu);
 }
 
 static int is_disabled(void)
Signature · 1 line
1.7.1
#3 lore raw

PATCH 3/3 KVM: SVM: Implement Flush-By-Asid feature

In reply to Joerg Roedel

This patch adds the new flush-by-asid of upcoming AMD processors to the KVM-AMD module.

---
 arch/x86/include/asm/svm.h |    2 ++
 arch/x86/kvm/svm.c         |   10 ++++++++--
 2 files changed, 10 insertions(+), 2 deletions(-)
arch/x86/include/asm/svm.h +2 -0
index 11dbca7..f20ff4f 100644
@@ -87,6 +87,8 @@ struct __attribute__ ((__packed__)) vmcb_control_area {
 
 #define TLB_CONTROL_DO_NOTHING 0
 #define TLB_CONTROL_FLUSH_ALL_ASID 1
+#define TLB_CONTROL_FLUSH_ASID 3
+#define TLB_CONTROL_FLUSH_ASID_LOCAL 7
 
 #define V_TPR_MASK 0x0f
 
arch/x86/kvm/svm.c +8 -2
index b70a1e8..cdc8ab9 100644
@@ -3093,7 +3093,6 @@ static void pre_svm_run(struct vcpu_svm *svm)
 
 	struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
 
-	svm->vmcb->control.tlb_ctl = TLB_CONTROL_DO_NOTHING;
 	/* FIXME: handle wraparound of asid_generation */
 	if (svm->asid_generation != sd->asid_generation)
 		new_asid(svm, sd);
@@ -3237,7 +3236,12 @@ static int svm_set_tss_addr(struct kvm *kvm, unsigned int addr)
 
 static void svm_flush_tlb(struct kvm_vcpu *vcpu)
 {
-	to_svm(vcpu)->asid_generation--;
+	struct vcpu_svm *svm = to_svm(vcpu);
+
+	if (static_cpu_has(X86_FEATURE_FLUSHBYASID))
+		svm->vmcb->control.tlb_ctl = TLB_CONTROL_FLUSH_ASID;
+	else
+		svm->asid_generation--;
 }
 
 static void svm_prepare_guest_switch(struct kvm_vcpu *vcpu)
@@ -3461,6 +3465,8 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
 
 	svm->next_rip = 0;
 
+	svm->vmcb->control.tlb_ctl = TLB_CONTROL_DO_NOTHING;
+
 	/* if exit due to PF check for async PF */
 	if (svm->vmcb->control.exit_code == SVM_EXIT_EXCP_BASE + PF_VECTOR)
 		svm->apf_reason = kvm_read_and_reset_pf_reason();
Signature · 1 line
1.7.1
#4 lore raw
In reply to Joerg Roedel
Quoted 10 lines · Joerg Roedel

Hi Avi, Hi Marcelo,

here is the patch-set to add support for the Flush-By-ASID feature to KVM on AMD. Patches 1 and 2 clean up the code a little bit and patch 3 implements the feature itself.

Regards,

Joerg

Quoted 9 lines
 arch/x86/include/asm/svm.h |    2 ++
 arch/x86/kvm/svm.c         |   32 ++++++++++++++------------------
 2 files changed, 16 insertions(+), 18 deletions(-)

Joerg Roedel (3):
KVM: SVM: Remove flush_guest_tlb function
KVM: SVM: Use svm_flush_tlb instead of force_new_asid
KVM: SVM: Implement Flush-By-Asid feature

Looks good to me.

Applied
#5 lore raw
In reply to Joerg Roedel
Quoted 5 lines · Joerg Roedel

Hi Avi, Hi Marcelo,

here is the patch-set to add support for the Flush-By-ASID feature to KVM on AMD. Patches 1 and 2 clean up the code a little bit and patch 3 implements the feature itself.

Applied, thanks.

Signature · 1 line
error compiling committee.c: too many arguments to function