X-Received: by 10.43.152.9 with SMTP id ku9mr19887975icc.8.1427236208691;
        Tue, 24 Mar 2015 15:30:08 -0700 (PDT)
X-BeenThere: linux.kernel@googlegroups.com
Received: by 10.182.221.169 with SMTP id qf9ls66754obc.55.gmail; Tue, 24 Mar
 2015 15:30:03 -0700 (PDT)
X-Received: by 10.182.245.169 with SMTP id xp9mr7849679obc.44.1427236203026;
        Tue, 24 Mar 2015 15:30:03 -0700 (PDT)
MIME-Version: 1.0
Path: db6ni62418igc.0!nntp.google.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!goblin3!goblin2!goblin.stu.neva.ru!aioe.org!bofh.it!news.nic.it!robomod
From: Toshi Kani <toshi...@hp.com>
Newsgroups: linux.kernel
Subject: [PATCH v4 4/7] mtrr, x86: Fix MTRR state checks in mtrr_type_lookup()
Date: Tue, 24 Mar 2015 23:30:02 +0100
Message-ID: <p7FuG-21A-17@gated-at.bofh.it>
References: <p7FuG-21A-19@gated-at.bofh.it>
X-Original-To: ak...@linux-foundation.org, h...@zytor.com, tg...@linutronix.de,
	mi...@redhat.com
X-Mailer: git-send-email 1.9.3
Sender: rob...@news.nic.it
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-...@vger.kernel.org
Approved: rob...@news.nic.it
Lines: 110
Organization: linux.* mail to news gateway
X-Original-Cc: linu...@kvack.org, x...@kernel.org, linux-...@vger.kernel.org,
	dave....@intel.com, Ell...@hp.com, peb...@tiscali.nl,
	Toshi Kani <toshi...@hp.com>
X-Original-Date: Tue, 24 Mar 2015 16:08:38 -0600
X-Original-Message-ID: <1427234921-19737-5-git...@hp.com>
X-Original-References: <1427234921-19737-1-git...@hp.com>
X-Original-Sender: linux-ker...@vger.kernel.org
Bytes: 5663

'mtrr_state.enabled' contains the FE (fixed MTRRs enabled)
and E (MTRRs enabled) flags in MSR_MTRRdefType.  Intel SDM,
section 11.11.2.1, defines these flags as follows:
 - All MTRRs are disabled when the E flag is clear.
   The FE flag has no affect when the E flag is clear.
 - The default type is enabled when the E flag is set.
 - MTRR variable ranges are enabled when the E flag is set.
 - MTRR fixed ranges are enabled when both E and FE flags
   are set.

MTRR state checks in __mtrr_type_lookup() do not match with
SDM.  Hence, this patch makes the following changes:
 - The current code detects MTRRs disabled when both E and
   FE flags are clear in mtrr_state.enabled.  Fix to detect
   MTRRs disabled when the E flag is clear.
 - The current code does not check if the FE bit is set in
   mtrr_state.enabled when looking into the fixed entries.
   Fix to check the FE flag.
 - The current code returns the default type when the E flag
   is clear in mtrr_state.enabled.  However, the default type
   is also disabled when the E flag is clear.  Fix to remove
   the code as this case is handled as MTRR disabled with
   the 1st change.

In addition, this patch defines the E and FE flags in
mtrr_state.enabled as follows.
 - FE flag: MTRR_STATE_MTRR_FIXED_ENABLED
 - E  flag: MTRR_STATE_MTRR_ENABLED

print_mtrr_state() is also updated accordingly.

Signed-off-by: Toshi Kani <toshi...@hp.com>
---
 arch/x86/include/uapi/asm/mtrr.h   |    4 ++++
 arch/x86/kernel/cpu/mtrr/generic.c |   15 ++++++++-------
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/arch/x86/include/uapi/asm/mtrr.h b/arch/x86/include/uapi/asm/mtrr.h
index d0acb65..66ba88d 100644
--- a/arch/x86/include/uapi/asm/mtrr.h
+++ b/arch/x86/include/uapi/asm/mtrr.h
@@ -88,6 +88,10 @@ struct mtrr_state_type {
 	mtrr_type def_type;
 };
 
+/* Bit fields for enabled in struct mtrr_state_type */
+#define MTRR_STATE_MTRR_FIXED_ENABLED	0x01
+#define MTRR_STATE_MTRR_ENABLED		0x02
+
 #define MTRRphysBase_MSR(reg) (0x200 + 2 * (reg))
 #define MTRRphysMask_MSR(reg) (0x200 + 2 * (reg) + 1)
 
