public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] KVM: MTRR: fix memory type handling if MTRR is completely disabled
@ 2015-07-15 19:25 Xiao Guangrong
  2015-07-15 19:25 ` [PATCH 2/3] KVM: MTRR: simplify kvm_mtrr_get_guest_memory_type Xiao Guangrong
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Xiao Guangrong @ 2015-07-15 19:25 UTC (permalink / raw)
  To: pbonzini
  Cc: gleb, mtosatti, kvm, linux-kernel, alex.williamson, bsd, lersek,
	jordan.l.justen, edk2-devel, Xiao Guangrong

From: Xiao Guangrong <guangrong.xiao@intel.com>

Currently code uses default memory type if MTRR is fully disabled,
fix it by using UC instead

Signed-off-by: Xiao Guangrong <guangrong.xiao@intel.com>
---
 arch/x86/kvm/mtrr.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/mtrr.c b/arch/x86/kvm/mtrr.c
index de1d2d8..e275013 100644
--- a/arch/x86/kvm/mtrr.c
+++ b/arch/x86/kvm/mtrr.c
@@ -120,6 +120,16 @@ static u8 mtrr_default_type(struct kvm_mtrr *mtrr_state)
 	return mtrr_state->deftype & IA32_MTRR_DEF_TYPE_TYPE_MASK;
 }
 
+static u8 mtrr_disabled_type(void)
+{
+	/*
+	 * Intel SDM 11.11.2.2: all MTRRs are disabled when
+	 * IA32_MTRR_DEF_TYPE.E bit is cleared, and the UC
+	 * memory type is applied to all of physical memory.
+	 */
+	return MTRR_TYPE_UNCACHABLE;
+}
+
 /*
 * Three terms are used in the following code:
 * - segment, it indicates the address segments covered by fixed MTRRs.
@@ -434,6 +444,8 @@ struct mtrr_iter {
 
 	/* output fields. */
 	int mem_type;
+	/* mtrr is completely disabled? */
+	bool mtrr_disabled;
 	/* [start, end) is not fully covered in MTRRs? */
 	bool partial_map;
 
@@ -549,7 +561,7 @@ static void mtrr_lookup_var_next(struct mtrr_iter *iter)
 static void mtrr_lookup_start(struct mtrr_iter *iter)
 {
 	if (!mtrr_is_enabled(iter->mtrr_state)) {
-		iter->partial_map = true;
+		iter->mtrr_disabled = true;
 		return;
 	}
 
@@ -563,6 +575,7 @@ static void mtrr_lookup_init(struct mtrr_iter *iter,
 	iter->mtrr_state = mtrr_state;
 	iter->start = start;
 	iter->end = end;
+	iter->mtrr_disabled = false;
 	iter->partial_map = false;
 	iter->fixed = false;
 	iter->range = NULL;
@@ -656,6 +669,9 @@ u8 kvm_mtrr_get_guest_memory_type(struct kvm_vcpu *vcpu, gfn_t gfn)
 		return MTRR_TYPE_WRBACK;
 	}
 
+	if (iter.mtrr_disabled)
+		return mtrr_disabled_type();
+
 	/* It is not covered by MTRRs. */
 	if (iter.partial_map) {
 		/*
@@ -689,6 +705,9 @@ bool kvm_mtrr_check_gfn_range_consistency(struct kvm_vcpu *vcpu, gfn_t gfn,
 			return false;
 	}
 
+	if (iter.mtrr_disabled)
+		return true;
+
 	if (!iter.partial_map)
 		return true;
 
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2015-07-30  7:21 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-15 19:25 [PATCH 1/3] KVM: MTRR: fix memory type handling if MTRR is completely disabled Xiao Guangrong
2015-07-15 19:25 ` [PATCH 2/3] KVM: MTRR: simplify kvm_mtrr_get_guest_memory_type Xiao Guangrong
2015-07-29 19:07   ` Alex Williamson
2015-07-30  7:21     ` [edk2] " Paolo Bonzini
2015-07-15 19:25 ` [PATCH 3/3] KVM: x86: quirkily apply WB to all memory if cache is disabled Xiao Guangrong
2015-07-23  5:56   ` Paolo Bonzini
2015-07-23  6:03     ` Xiao Guangrong
2015-07-16  4:10 ` [PATCH 1/3] KVM: MTRR: fix memory type handling if MTRR is completely disabled Alex Williamson
2015-07-23  6:21   ` Paolo Bonzini
2015-07-23  6:29     ` Xiao Guangrong
2015-07-23  7:18       ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox