X-Received: by 10.194.236.196 with SMTP id uw4mr4486656wjc.5.1426282807031;
        Fri, 13 Mar 2015 14:40:07 -0700 (PDT)
X-BeenThere: linux.kernel@googlegroups.com
Received: by 10.180.83.9 with SMTP id m9ls236404wiy.16.gmail; Fri, 13 Mar 2015
 14:40:02 -0700 (PDT)
X-Received: by 10.180.80.132 with SMTP id r4mr4270499wix.4.1426282802048;
        Fri, 13 Mar 2015 14:40:02 -0700 (PDT)
MIME-Version: 1.0
Path: vt8ni24025lbb.0!nntp.google.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 v3 2/5] mtrr, x86: Fix MTRR lookup to handle inclusive entry
Date: Fri, 13 Mar 2015 22:40:01 +0100
Message-ID: <p3Ftf-563-11@gated-at.bofh.it>
References: <p3Ftf-563-13@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: 65
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: Fri, 13 Mar 2015 15:33:38 -0600
X-Original-Message-ID: <1426282421-25385-3-git...@hp.com>
X-Original-References: <1426282421-25385-1-git...@hp.com>
X-Original-Sender: linux-ker...@vger.kernel.org

When an MTRR entry is inclusive to a requested range, i.e.
the start and end of the request are not within the MTRR
entry range but the range contains the MTRR entry entirely,
__mtrr_type_lookup() ignores such a case because both
start_state and end_state are set to zero.

This patch fixes the issue by adding a new flag, 'inclusive',
to detect the case.  This case is then handled in the same
way as (!start_state && end_state).

Signed-off-by: Toshi Kani <toshi...@hp.com>
---
 arch/x86/kernel/cpu/mtrr/generic.c |   17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/arch/x86/kernel/cpu/mtrr/generic.c b/arch/x86/kernel/cpu/mtrr/generic.c
index 7d74f7b..a82e370 100644
--- a/arch/x86/kernel/cpu/mtrr/generic.c
+++ b/arch/x86/kernel/cpu/mtrr/generic.c
@@ -154,7 +154,7 @@ static u8 __mtrr_type_lookup(u64 start, u64 end, u64 *partial_end, int *repeat)
 
 	prev_match = 0xFF;
 	for (i = 0; i < num_var_ranges; ++i) {
-		unsigned short start_state, end_state;
+		unsigned short start_state, end_state, inclusive;
 
 		if (!(mtrr_state.var_ranges[i].mask_lo & (1 << 11)))
 			continue;
@@ -166,15 +166,16 @@ static u8 __mtrr_type_lookup(u64 start, u64 end, u64 *partial_end, int *repeat)
 
 		start_state = ((start & mask) == (base & mask));
 		end_state = ((end & mask) == (base & mask));
+		inclusive = ((start < base) && (end > base));
 
-		if (start_state != end_state) {
+		if ((start_state != end_state) || inclusive) {
 			/*
 			 * We have start:end spanning across an MTRR.
-			 * We split the region into
-			 * either
-			 * (start:mtrr_end) (mtrr_end:end)
-			 * or
-			 * (start:mtrr_start) (mtrr_start:end)
+			 * We split the region into either
+			 * - start_state:1
+			 *     (start:mtrr_end) (mtrr_end:end)
+			 * - end_state:1 or inclusive:1
+			 *     (start:mtrr_start) (mtrr_start:end)
 			 * depending on kind of overlap.
 			 * Return the type for first region and a pointer to
 			 * the start of second region so that caller will
@@ -195,7 +196,7 @@ static u8 __mtrr_type_lookup(u64 start, u64 end, u64 *partial_end, int *repeat)
 			*repeat = 1;
 		}
 
-		if ((start & mask) != (base & mask))
+		if (!start_state)
 			continue;
 
 		curr_match = mtrr_state.var_ranges[i].base_lo & 0xff;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

