* [PATCH 1/2] x86,mtrr: Fix original mtrr range get for mtrr_cleanup
@ 2013-06-09 20:00 Yinghai Lu
2013-06-09 20:00 ` [PATCH 2/2] x86, range: make add_range use blank slot Yinghai Lu
0 siblings, 1 reply; 2+ messages in thread
From: Yinghai Lu @ 2013-06-09 20:00 UTC (permalink / raw)
To: H. Peter Anvin, Andrew Morton
Cc: Thomas Gleixner, Ingo Molnar, Joshua Covington, linux-kernel,
Yinghai Lu, stable
Joshua reported: Commit cd7b304dfaf1 (x86, range: fix missing merge
during add range) broke mtrr cleanup on his setup in 3.9.5.
corresponding commit in upstream is fbe06b7bae7c.
*BAD*gran_size: 64K chunk_size: 16M num_reg: 6 lose cover RAM: -0G
https://bugzilla.kernel.org/show_bug.cgi?id=59491
So it rejects new var mtrr layout.
It turns out we have some problem with initial mtrr range retrievel.
current sequence is:
x86_get_mtrr_mem_range
==> bunchs of add_range_with_merge
==> bunchs of subract_range
==> clean_sort_range
add_range_with_merge for [0,1M)
sort_range()
add_range_with_merge could have blank slots, so we can not just
sort only, that will have final result have extra blank slot in head.
So move that calling add_range_with_merge for [0,1M), with that we
could avoid extra clean_sort_range calling.
Reported-by: Joshua Covington <joshuacov@googlemail.com>
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: <stable@vger.kernel.org> v3.9
---
arch/x86/kernel/cpu/mtrr/cleanup.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
Index: linux-2.6/arch/x86/kernel/cpu/mtrr/cleanup.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/cpu/mtrr/cleanup.c
+++ linux-2.6/arch/x86/kernel/cpu/mtrr/cleanup.c
@@ -714,15 +714,15 @@ int __init mtrr_cleanup(unsigned address
if (mtrr_tom2)
x_remove_size = (mtrr_tom2 >> PAGE_SHIFT) - x_remove_base;
- nr_range = x86_get_mtrr_mem_range(range, 0, x_remove_base, x_remove_size);
/*
* [0, 1M) should always be covered by var mtrr with WB
* and fixed mtrrs should take effect before var mtrr for it:
*/
nr_range = add_range_with_merge(range, RANGE_NUM, nr_range, 0,
1ULL<<(20 - PAGE_SHIFT));
- /* Sort the ranges: */
- sort_range(range, nr_range);
+ /* add from var mtrr at last */
+ nr_range = x86_get_mtrr_mem_range(range, nr_range,
+ x_remove_base, x_remove_size);
range_sums = sum_ranges(range, nr_range);
printk(KERN_INFO "total RAM covered: %ldM\n",
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH 2/2] x86, range: make add_range use blank slot
2013-06-09 20:00 [PATCH 1/2] x86,mtrr: Fix original mtrr range get for mtrr_cleanup Yinghai Lu
@ 2013-06-09 20:00 ` Yinghai Lu
0 siblings, 0 replies; 2+ messages in thread
From: Yinghai Lu @ 2013-06-09 20:00 UTC (permalink / raw)
To: H. Peter Anvin, Andrew Morton
Cc: Thomas Gleixner, Ingo Molnar, Joshua Covington, linux-kernel,
Yinghai Lu, stable
Now add_range_with_merge will generate blank slot as subtract_range.
we could reach the array limit because of blank slots.
We can let add_range to have second try to use blank slot.
Also use WARN_ONCE to print trace.
Reported-by: Joshua Covington <joshuacov@googlemail.com>
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Cc: <stable@vger.kernel.org> v3.9
---
kernel/range.c | 34 ++++++++++++++++++++++------------
1 file changed, 22 insertions(+), 12 deletions(-)
Index: linux-2.6/kernel/range.c
===================================================================
--- linux-2.6.orig/kernel/range.c
+++ linux-2.6/kernel/range.c
@@ -3,23 +3,34 @@
*/
#include <linux/kernel.h>
#include <linux/init.h>
+#include <linux/bug.h>
#include <linux/sort.h>
-
#include <linux/range.h>
int add_range(struct range *range, int az, int nr_range, u64 start, u64 end)
{
- if (start >= end)
- return nr_range;
+ int i;
- /* Out of slots: */
- if (nr_range >= az)
+ if (start >= end)
return nr_range;
- range[nr_range].start = start;
- range[nr_range].end = end;
+ /* Out of slots ? */
+ if (nr_range < az) {
+ i = nr_range;
+ nr_range++;
+ } else {
+ /* find blank slot */
+ for (i = 0; i < az; i++)
+ if (!range[i].end)
+ break;
+ if (i == az) {
+ WARN_ONCE(1, "run out of slot in ranges\n");
+ return az;
+ }
+ }
- nr_range++;
+ range[i].start = start;
+ range[i].end = end;
return nr_range;
}
@@ -98,10 +109,9 @@ void subtract_range(struct range *range,
if (i < az) {
range[i].end = range[j].end;
range[i].start = end;
- } else {
- pr_err("%s: run out of slot in ranges\n",
- __func__);
- }
+ } else
+ WARN_ONCE(1, "run out of slot in ranges\n");
+
range[j].end = start;
continue;
}
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-06-09 20:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-09 20:00 [PATCH 1/2] x86,mtrr: Fix original mtrr range get for mtrr_cleanup Yinghai Lu
2013-06-09 20:00 ` [PATCH 2/2] x86, range: make add_range use blank slot Yinghai Lu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox