linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Cathy Avery <cavery@redhat.com>
To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, pbonzini@redhat.com
Cc: vkuznets@redhat.com, wei.huang2@amd.com, mlevitsk@redhat.com,
	sean.j.christopherson@intel.com
Subject: [PATCH v3 1/2] KVM: SVM: Track asid from vcpu_svm
Date: Mon, 26 Oct 2020 13:42:21 -0400	[thread overview]
Message-ID: <20201026174222.21811-2-cavery@redhat.com> (raw)
In-Reply-To: <20201026174222.21811-1-cavery@redhat.com>

Track asid from svm->asid to allow for vmcb assignment
without regard to which level guest is running.

Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Cathy Avery <cavery@redhat.com>
---
 arch/x86/kvm/svm/svm.c | 16 ++++++++++++++--
 arch/x86/kvm/svm/svm.h |  2 ++
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index d4e18bda19c7..83b4f56883f8 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -1101,6 +1101,7 @@ static void init_vmcb(struct vcpu_svm *svm)
 		save->cr4 = 0;
 	}
 	svm->asid_generation = 0;
+	svm->asid = 0;
 
 	svm->nested.vmcb = 0;
 	svm->vcpu.arch.hflags = 0;
@@ -1659,11 +1660,11 @@ static void new_asid(struct vcpu_svm *svm, struct svm_cpu_data *sd)
 	if (sd->next_asid > sd->max_asid) {
 		++sd->asid_generation;
 		sd->next_asid = sd->min_asid;
-		svm->vmcb->control.tlb_ctl = TLB_CONTROL_FLUSH_ALL_ASID;
+		sd->flush_all_asid = true;
 	}
 
 	svm->asid_generation = sd->asid_generation;
-	svm->vmcb->control.asid = sd->next_asid++;
+	svm->asid = sd->next_asid++;
 
 	vmcb_mark_dirty(svm->vmcb, VMCB_ASID);
 }
@@ -3030,6 +3031,17 @@ static void pre_svm_run(struct vcpu_svm *svm)
 	/* FIXME: handle wraparound of asid_generation */
 	if (svm->asid_generation != sd->asid_generation)
 		new_asid(svm, sd);
+
+	if (sd->flush_all_asid) {
+		svm->vmcb->control.tlb_ctl = TLB_CONTROL_FLUSH_ALL_ASID;
+		sd->flush_all_asid = false;
+		vmcb_mark_dirty(svm->vmcb, VMCB_ASID);
+	}
+
+	if (unlikely(svm->asid != svm->vmcb->control.asid))
+		vmcb_mark_dirty(svm->vmcb, VMCB_ASID);
+
+	svm->vmcb->control.asid = svm->asid;
 }
 
 static void svm_inject_nmi(struct kvm_vcpu *vcpu)
diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h
index a798e1731709..22832362bced 100644
--- a/arch/x86/kvm/svm/svm.h
+++ b/arch/x86/kvm/svm/svm.h
@@ -104,6 +104,7 @@ struct vcpu_svm {
 	struct vmcb *vmcb;
 	unsigned long vmcb_pa;
 	struct svm_cpu_data *svm_data;
+	u32 asid;
 	uint64_t asid_generation;
 	uint64_t sysenter_esp;
 	uint64_t sysenter_eip;
@@ -164,6 +165,7 @@ struct svm_cpu_data {
 	int cpu;
 
 	u64 asid_generation;
+	bool flush_all_asid;
 	u32 max_asid;
 	u32 next_asid;
 	u32 min_asid;
-- 
2.20.1


  reply	other threads:[~2020-10-26 17:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-26 17:42 [PATCH v3 0/2] KVM: SVM: Create separate vmcbs for L1 and L2 Cathy Avery
2020-10-26 17:42 ` Cathy Avery [this message]
2020-10-26 17:42 ` [PATCH v3 2/2] KVM: SVM: Use a separate vmcb for the nested L2 guest Cathy Avery
2020-11-11 21:35 ` [PATCH v3 0/2] KVM: SVM: Create separate vmcbs for L1 and L2 Babu Moger
2020-11-12 13:52   ` Cathy Avery

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=20201026174222.21811-2-cavery@redhat.com \
    --to=cavery@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mlevitsk@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=sean.j.christopherson@intel.com \
    --cc=vkuznets@redhat.com \
    --cc=wei.huang2@amd.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).