aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/range.c
diff options
context:
space:
mode:
authorYinghai Lu <yinghai@kernel.org>2013-06-13 16:17:02 -0400
committerH. Peter Anvin <hpa@linux.intel.com>2013-06-18 12:32:10 -0400
commit0541881502a1276149889fe468662ff6a8fc8f6d (patch)
tree14bdb51938b710d8b224215bccaea4cbf680b818 /kernel/range.c
parentd8d386c10630d8f7837700f4c466443d49e12cc0 (diff)
range: Do not add new blank slot with add_range_with_merge
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. The reason is add_range_with_merge could generate blank spot. We could avoid that by searching new expanded start/end, that new range should include all connected ranges in range array. At last add the new expanded start/end to the range array. Also move up left array so do not add new blank slot in the range array. -v2: move left array to avoid enhance add_range() -v3: include fix from Joshua about memmove declaring when DYN_DEBUG is used. Reported-by: Joshua Covington <joshuacov@googlemail.com> Tested-by: Joshua Covington <joshuacov@googlemail.com> Signed-off-by: Yinghai Lu <yinghai@kernel.org> Link: http://lkml.kernel.org/r/1371154622-8929-3-git-send-email-yinghai@kernel.org Cc: <stable@vger.kernel.org> v3.9 Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Diffstat (limited to 'kernel/range.c')
-rw-r--r--kernel/range.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/kernel/range.c b/kernel/range.c
index eb911dbce267..322ea8e93e4b 100644
--- a/kernel/range.c
+++ b/kernel/range.c
@@ -4,7 +4,7 @@
4#include <linux/kernel.h> 4#include <linux/kernel.h>
5#include <linux/init.h> 5#include <linux/init.h>
6#include <linux/sort.h> 6#include <linux/sort.h>
7 7#include <linux/string.h>
8#include <linux/range.h> 8#include <linux/range.h>
9 9
10int add_range(struct range *range, int az, int nr_range, u64 start, u64 end) 10int add_range(struct range *range, int az, int nr_range, u64 start, u64 end)
@@ -32,9 +32,8 @@ int add_range_with_merge(struct range *range, int az, int nr_range,
32 if (start >= end) 32 if (start >= end)
33 return nr_range; 33 return nr_range;
34 34
35 /* Try to merge it with old one: */ 35 /* get new start/end: */
36 for (i = 0; i < nr_range; i++) { 36 for (i = 0; i < nr_range; i++) {
37 u64 final_start, final_end;
38 u64 common_start, common_end; 37 u64 common_start, common_end;
39 38
40 if (!range[i].end) 39 if (!range[i].end)
@@ -45,14 +44,16 @@ int add_range_with_merge(struct range *range, int az, int nr_range,
45 if (common_start > common_end) 44 if (common_start > common_end)
46 continue; 45 continue;
47 46
48 final_start = min(range[i].start, start); 47 /* new start/end, will add it back at last */
49 final_end = max(range[i].end, end); 48 start = min(range[i].start, start);
49 end = max(range[i].end, end);
50 50
51 /* clear it and add it back for further merge */ 51 memmove(&range[i], &range[i + 1],
52 range[i].start = 0; 52 (nr_range - (i + 1)) * sizeof(range[i]));
53 range[i].end = 0; 53 range[nr_range - 1].start = 0;
54 return add_range_with_merge(range, az, nr_range, 54 range[nr_range - 1].end = 0;
55 final_start, final_end); 55 nr_range--;
56 i--;
56 } 57 }
57 58
58 /* Need to add it: */ 59 /* Need to add it: */