public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Joerg Roedel <joerg.roedel@amd.com>
To: Avi Kivity <avi@redhat.com>, Marcelo Tosatti <mtosatti@redhat.com>
Cc: <kvm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	Joerg Roedel <joerg.roedel@amd.com>
Subject: [PATCH 01/12] KVM: SVM: Add clean-bits infrastructure code
Date: Fri, 3 Dec 2010 11:45:48 +0100	[thread overview]
Message-ID: <1291373159-4822-2-git-send-email-joerg.roedel@amd.com> (raw)
In-Reply-To: <1291373159-4822-1-git-send-email-joerg.roedel@amd.com>

This patch adds the infrastructure for the implementation of
the individual clean-bits.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
 arch/x86/include/asm/svm.h |    6 +++++-
 arch/x86/kvm/svm.c         |   31 +++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 1 deletions(-)

diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h
index 11dbca7..d786399 100644
--- a/arch/x86/include/asm/svm.h
+++ b/arch/x86/include/asm/svm.h
@@ -49,6 +49,9 @@ enum {
 	INTERCEPT_MWAIT_COND,
 };
 
+enum {
+	VMCB_CLEAN_MAX,
+};
 
 struct __attribute__ ((__packed__)) vmcb_control_area {
 	u32 intercept_cr;
@@ -79,7 +82,8 @@ struct __attribute__ ((__packed__)) vmcb_control_area {
 	u32 event_inj_err;
 	u64 nested_cr3;
 	u64 lbr_ctl;
-	u64 reserved_5;
+	u32 clean;
+	u32 reserved_5;
 	u64 next_rip;
 	u8 reserved_6[816];
 };
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index c00ea90..3ee59b0 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -185,6 +185,28 @@ static int nested_svm_vmexit(struct vcpu_svm *svm);
 static int nested_svm_check_exception(struct vcpu_svm *svm, unsigned nr,
 				      bool has_error_code, u32 error_code);
 
+enum {
+	VMCB_DIRTY_MAX,
+};
+
+#define VMCB_ALWAYS_DIRTY_MASK	0U
+
+static inline void mark_all_dirty(struct vmcb *vmcb)
+{
+	vmcb->control.clean = 0;
+}
+
+static inline void mark_all_clean(struct vmcb *vmcb)
+{
+	vmcb->control.clean = ((1 << VMCB_DIRTY_MAX) - 1)
+			       & ~VMCB_ALWAYS_DIRTY_MASK;
+}
+
+static inline void mark_dirty(struct vmcb *vmcb, int bit)
+{
+	vmcb->control.clean &= ~(1 << bit);
+}
+
 static inline struct vcpu_svm *to_svm(struct kvm_vcpu *vcpu)
 {
 	return container_of(vcpu, struct vcpu_svm, vcpu);
@@ -973,6 +995,8 @@ static void init_vmcb(struct vcpu_svm *svm)
 		set_intercept(svm, INTERCEPT_PAUSE);
 	}
 
+	mark_all_dirty(svm->vmcb);
+
 	enable_gif(svm);
 }
 
@@ -1089,6 +1113,7 @@ static void svm_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
 
 	if (unlikely(cpu != vcpu->cpu)) {
 		svm->asid_generation = 0;
+		mark_all_dirty(svm->vmcb);
 	}
 
 #ifdef CONFIG_X86_64
@@ -2139,6 +2164,8 @@ static int nested_svm_vmexit(struct vcpu_svm *svm)
 	svm->vmcb->save.cpl = 0;
 	svm->vmcb->control.exit_int_info = 0;
 
+	mark_all_dirty(svm->vmcb);
+
 	nested_svm_unmap(page);
 
 	nested_svm_uninit_mmu_context(&svm->vcpu);
@@ -2350,6 +2377,8 @@ static bool nested_svm_vmrun(struct vcpu_svm *svm)
 
 	enable_gif(svm);
 
+	mark_all_dirty(svm->vmcb);
+
 	return true;
 }
 
@@ -3487,6 +3516,8 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
 	if (unlikely(svm->vmcb->control.exit_code ==
 		     SVM_EXIT_EXCP_BASE + MC_VECTOR))
 		svm_handle_mce(svm);
+
+	mark_all_clean(svm->vmcb);
 }
 
 #undef R
-- 
1.7.1



  reply	other threads:[~2010-12-03 10:49 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-03 10:45 [PATCH 0/12] KVM: SVM: Add support for VMCB state caching Joerg Roedel
2010-12-03 10:45 ` Joerg Roedel [this message]
2010-12-03 12:15   ` [PATCH 01/12] KVM: SVM: Add clean-bits infrastructure code Roedel, Joerg
2010-12-03 10:45 ` [PATCH 02/12] KVM: SVM: Add clean-bit for intercetps, tsc-offset and pause filter count Joerg Roedel
2010-12-03 10:45 ` [PATCH 03/12] KVM: SVM: Add clean-bit for IOPM_BASE and MSRPM_BASE Joerg Roedel
2010-12-03 10:45 ` [PATCH 04/12] KVM: SVM: Add clean-bit for the ASID Joerg Roedel
2010-12-03 10:45 ` [PATCH 05/12] KVM: SVM: Add clean-bit for interrupt state Joerg Roedel
2010-12-06 19:29   ` Marcelo Tosatti
2010-12-07  8:23     ` Joerg Roedel
2010-12-03 10:45 ` [PATCH 06/12] KVM: SVM: Add clean-bit for NPT state Joerg Roedel
2010-12-03 10:45 ` [PATCH 07/12] KVM: SVM: Add clean-bit for control registers Joerg Roedel
2010-12-03 10:45 ` [PATCH 08/12] KVM: SVM: Add clean-bit for DR6 and DR7 Joerg Roedel
2010-12-03 10:45 ` [PATCH 09/12] KVM: SVM: Add clean-bit for GDT and IDT Joerg Roedel
2010-12-03 10:45 ` [PATCH 10/12] KVM: SVM: Add clean-bit for Segements and CPL Joerg Roedel
2010-12-03 10:45 ` [PATCH 11/12] KVM: SVM: Add clean-bit for CR2 register Joerg Roedel
2010-12-03 10:45 ` [PATCH 12/12] KVM: SVM: Add clean-bit for LBR state Joerg Roedel
2010-12-06 19:49 ` [PATCH 0/12] KVM: SVM: Add support for VMCB state caching Marcelo Tosatti
2010-12-07  8:26   ` Joerg Roedel
2010-12-07  9:50 ` Avi Kivity

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=1291373159-4822-2-git-send-email-joerg.roedel@amd.com \
    --to=joerg.roedel@amd.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mtosatti@redhat.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