x86, range: Do not add new blank slot with add_range_with_merge
PATCH v2 2/2 x86, 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()
--- arch/x86/kernel/cpu/mtrr/cleanup.c | 2 +- kernel/range.c | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-)
kernel/range.c +11 -10
@@ -32,9 +32,8 @@ int add_range_with_merge(struct range *rif (start >= end)return nr_range; -/* Try to merge it with old one: */ +/* get new start/end: */ for (i =0 ; i < nr_range; i++) { -u64 final_start, final_end;u64 common_start, common_end;if (!range[i].end)
@@ -45,14 +44,16 @@ int add_range_with_merge(struct range *rif (common_start > common_end)continue ; - final_start =min (range[i].start, start); - final_end =max (range[i].end, end); - -/* clear it and add it back for further merge */ - range[i].start =0 ; - range[i].end =0 ; -return add_range_with_merge (range, az, nr_range, - final_start, final_end); +/* new start/end, will add it back at last */ + start =min (range[i].start, start); + end =max (range[i].end, end); + +memmove (&range[i], &range[i +1 ], + (nr_range - (i +1 )) *sizeof (range[i])); + range[nr_range -1 ].start =0 ; + range[nr_range -1 ].end =0 ; + nr_range--; + i--; }/* Need to add it: */
Hi,
Quoted 64 lines · Yinghai Lu
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 isfbe06b7bae7c.The reason is
add_range_with_mergecould 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()Reported-by Joshua Covington <[email protected]>Signed-off-by Yinghai Lu <[email protected]>Cc <[email protected]> v3.9--- arch/x86/kernel/cpu/mtrr/cleanup.c | 2 +- kernel/range.c | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-)Index:
linux-2.6/kernel/range.c
===================================================================kernel/range.c +11
-11@@ -32,9 +32,8 @@ int add_range_with_merge(struct range *rif (start >= end)return nr_range; -/* Try to merge it with old one: */ +/* get new start/end: */ for (i =0 ; i < nr_range; i++) { -u64 final_start, final_end;u64 common_start, common_end;if (!range[i].end)@@ -45,14 +44,16 @@ int add_range_with_merge(struct range *rif (common_start > common_end)continue ; - final_start =min (range[i].start, start); - final_end =max (range[i].end, end); - -/* clear it and add it back for further merge */ - range[i].start =0 ; - range[i].end =0 ; -return add_range_with_merge (range, az, nr_range, - final_start, final_end); +/* new start/end, will add it back at last */ + start =min (range[i].start, start); + end =max (range[i].end, end); + +memmove (&range[i], &range[i +1 ], + (nr_range - (i +1 )) *sizeof (range[i])); + range[nr_range -1 ].start =0 ; + range[nr_range -1 ].end =0 ; + nr_range--; + i--; }/* Need to add it: */ --
Quoted 4 lines
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
patches 1,2(latest one) have not helped me on 3.9.5:
rathamahata@piledriver /usr/local/src/linux-3.9.5 $ cat /proc/cmdline BOOT_IMAGE=/boot/linux-3.9.5 root=/dev/sda1 rootflags=commit=9 elevator=cfq enable_mtrr_cleanup mtrr_spare_reg_nr=1 rathamahata@piledriver /usr/local/src/linux-3.9.5 $ cat /proc/mtrr
reg00: base=0x000000000 ( 0MB), size= 2048MB, count=1: write-back
reg01: base=0x080000000 ( 2048MB), size= 256MB, count=1: write-back
reg02: base=0x08f800000 ( 2296MB), size= 8MB, count=1: uncachable
reg03: base=0x0b0000000 ( 2816MB), size= 256MB, count=1: write-combining
reg04: base=0x0c0000000 ( 3072MB), size= 256MB, count=1: write-combining rathamahata@piledriver /usr/local/src/linux-3.9.5 $ free -m
total used free shared buffers cached Mem: 7370 714 6656 0 35 243 -/+ buffers/cache: 434 6935 Swap: 3659 0 3659
rathamahata@piledriver /usr/local/src/linux-3.9.5 $
Quoted 1 line · Sergey Meirovich
patches 1,2(latest one) have not helped me on 3.9.5:
So v1:
https://patchwork.kernel.org/patch/2694981/
https://patchwork.kernel.org/patch/2694971/
and v2:
https://patchwork.kernel.org/patch/2695891/
https://patchwork.kernel.org/patch/2695881/
Neither of two versions fix the problem on your setup?
Can you post boot log with mtrr_cleanup_debug on 3.9.4?
Thanks
Yinghai
2013/6/10 Yinghai Lu <[email protected]>:
Quoted 12 lines · Sergey Meirovich
Quoted 2 lines
patches 1,2(latest one) have not helped me on 3.9.5:
So v1:
https://patchwork.kernel.org/patch/2694981/
https://patchwork.kernel.org/patch/2694971/and v2:
https://patchwork.kernel.org/patch/2695891/
https://patchwork.kernel.org/patch/2695881/
Quoted 7 lines
Neither of two versions fix the problem on your setup?
Can you post boot log with
mtrr_cleanup_debugon 3.9.4?Thanks
Yinghai
I got some warnings when trying to build v2 of the patches:
# make -s ARCH=x86_64 V=1 -j4 bzImage kernel/range.c: In function 'add_range_with_merge': kernel/range.c:51:3: error: implicit declaration of function 'memmove' [-Werror=implicit-function-declaration] kernel/range.c:51:3: warning: incompatible implicit declaration of built-in function 'memmove' [enabled by default] cc1: some warnings being treated as errors scripts/Makefile.build:307: recipe for target 'kernel/range.o' failed make[1]: *** [kernel/range.o] Error 1 Makefile:793: recipe for target 'kernel' failed make: *** [kernel] Error 2 make: *** Waiting for unfinished jobs....
--
--joshua
2013/6/11 Joshua C. <[email protected]>:
Quoted 37 lines
2013/6/10 Yinghai Lu <[email protected]>:
Quoted 12 lines · Sergey Meirovich
Quoted 2 lines
patches 1,2(latest one) have not helped me on 3.9.5:
So v1:
https://patchwork.kernel.org/patch/2694981/
https://patchwork.kernel.org/patch/2694971/and v2:
https://patchwork.kernel.org/patch/2695891/
https://patchwork.kernel.org/patch/2695881/Quoted 7 lines
Neither of two versions fix the problem on your setup?
Can you post boot log with
mtrr_cleanup_debugon 3.9.4?Thanks
Yinghai
I got some warnings when trying to build v2 of the patches:
# make -s ARCH=x86_64 V=1 -j4 bzImage kernel/range.c: In function 'add_range_with_merge': kernel/range.c:51:3: error: implicit declaration of function 'memmove' [-Werror=implicit-function-declaration] kernel/range.c:51:3: warning: incompatible implicit declaration of built-in function 'memmove' [enabled by default] cc1: some warnings being treated as errors scripts/Makefile.build:307: recipe for target 'kernel/range.o' failed make[1]: *** [kernel/range.o] Error 1 Makefile:793: recipe for target 'kernel' failed make: *** [kernel] Error 2 make: *** Waiting for unfinished jobs....
Quoted 2 lines
--
--joshua
A trivial fix for the above warnings:
kernel/range.c +1 -0
@@ -4,6 +4,7 @@#include <linux/kernel.h> #include <linux/init.h> #include <linux/sort.h> +#include <linux/string.h> #include <linux/range.h>
--
--joshua
Quoted 40 lines · Joshua C.
2013/6/11 Joshua C. <[email protected]>:
Quoted 39 lines
2013/6/10 Yinghai Lu <[email protected]>:
Quoted 12 lines · Sergey Meirovich
Quoted 2 lines
patches 1,2(latest one) have not helped me on 3.9.5:
So v1:
https://patchwork.kernel.org/patch/2694981/
https://patchwork.kernel.org/patch/2694971/and v2:
https://patchwork.kernel.org/patch/2695891/
https://patchwork.kernel.org/patch/2695881/Quoted 7 lines
Neither of two versions fix the problem on your setup?
Can you post boot log with
mtrr_cleanup_debugon 3.9.4?Thanks
Yinghai
I got some warnings when trying to build v2 of the patches:
# make -s ARCH=x86_64 V=1 -j4 bzImage kernel/range.c: In function 'add_range_with_merge': kernel/range.c:51:3: error: implicit declaration of function 'memmove' [-Werror=implicit-function-declaration] kernel/range.c:51:3: warning: incompatible implicit declaration of built-in function 'memmove' [enabled by default] cc1: some warnings being treated as errors scripts/Makefile.build:307: recipe for target 'kernel/range.o' failed make[1]: *** [kernel/range.o] Error 1 Makefile:793: recipe for target 'kernel' failed make: *** [kernel] Error 2 make: *** Waiting for unfinished jobs....--
--joshua
it does not report warning when I compile it with
gcc (SUSE Linux) 4.7.2 20130108 [gcc-4_7-branch revision 195012
Quoted 13 lines
A trivial fix for the above warnings:
kernel/range.c +1
-0@@ -4,6 +4,7 @@#include <linux/kernel.h> #include <linux/init.h> #include <linux/sort.h> +#include <linux/string.h> #include <linux/range.h>
2013/6/11 Yinghai Lu <[email protected]>:
Quoted 57 lines · Joshua C.
Quoted 40 lines
2013/6/11 Joshua C. <[email protected]>:
Quoted 39 lines
2013/6/10 Yinghai Lu <[email protected]>:
Quoted 12 lines · Sergey Meirovich
Quoted 2 lines
patches 1,2(latest one) have not helped me on 3.9.5:
So v1:
https://patchwork.kernel.org/patch/2694981/
https://patchwork.kernel.org/patch/2694971/and v2:
https://patchwork.kernel.org/patch/2695891/
https://patchwork.kernel.org/patch/2695881/Quoted 7 lines
Neither of two versions fix the problem on your setup?
Can you post boot log with
mtrr_cleanup_debugon 3.9.4?Thanks
Yinghai
I got some warnings when trying to build v2 of the patches:
# make -s ARCH=x86_64 V=1 -j4 bzImage kernel/range.c: In function 'add_range_with_merge': kernel/range.c:51:3: error: implicit declaration of function 'memmove' [-Werror=implicit-function-declaration] kernel/range.c:51:3: warning: incompatible implicit declaration of built-in function 'memmove' [enabled by default] cc1: some warnings being treated as errors scripts/Makefile.build:307: recipe for target 'kernel/range.o' failed make[1]: *** [kernel/range.o] Error 1 Makefile:793: recipe for target 'kernel' failed make: *** [kernel] Error 2 make: *** Waiting for unfinished jobs....--
--joshuait does not report warning when I compile it with
gcc (SUSE Linux) 4.7.2 20130108 [gcc-4_7-branch revision 195012
Quoted 11 lines
A trivial fix for the above warnings:
kernel/range.c +1
-0@@ -4,6 +4,7 @@#include <linux/kernel.h> #include <linux/init.h> #include <linux/sort.h> +#include <linux/string.h>
Quoted 2 lines
kernel/range.c line 10
Quoted 2 lines
kernel/range.c +0
-0#include <linux/range.h>
I use fedora17 with gcc version 4.7.3 (git checkout on 20130411). I have no idea where this came from...
--
--joshua
Quoted 58 lines · Joshua C.
2013/6/11 Yinghai Lu <[email protected]>:
Quoted 57 lines · Joshua C.
Quoted 40 lines
2013/6/11 Joshua C. <[email protected]>:
Quoted 39 lines
2013/6/10 Yinghai Lu <[email protected]>:
Quoted 12 lines · Sergey Meirovich
Quoted 2 lines
patches 1,2(latest one) have not helped me on 3.9.5:
So v1:
https://patchwork.kernel.org/patch/2694981/
https://patchwork.kernel.org/patch/2694971/and v2:
https://patchwork.kernel.org/patch/2695891/
https://patchwork.kernel.org/patch/2695881/Quoted 7 lines
Neither of two versions fix the problem on your setup?
Can you post boot log with
mtrr_cleanup_debugon 3.9.4?Thanks
Yinghai
I got some warnings when trying to build v2 of the patches:
# make -s ARCH=x86_64 V=1 -j4 bzImage kernel/range.c: In function 'add_range_with_merge': kernel/range.c:51:3: error: implicit declaration of function 'memmove' [-Werror=implicit-function-declaration] kernel/range.c:51:3: warning: incompatible implicit declaration of built-in function 'memmove' [enabled by default] cc1: some warnings being treated as errors scripts/Makefile.build:307: recipe for target 'kernel/range.o' failed make[1]: *** [kernel/range.o] Error 1 Makefile:793: recipe for target 'kernel' failed make: *** [kernel] Error 2 make: *** Waiting for unfinished jobs....--
--joshuait does not report warning when I compile it with
gcc (SUSE Linux) 4.7.2 20130108 [gcc-4_7-branch revision 195012
Quoted 11 lines
A trivial fix for the above warnings:
kernel/range.c +1
-0@@ -4,6 +4,7 @@#include <linux/kernel.h> #include <linux/init.h> #include <linux/sort.h> +#include <linux/string.h>
Quoted 5 lines
Quoted 2 lines
kernel/range.c line 10
Quoted 2 lines
kernel/range.c +0
-0#include <linux/range.h> I use fedora17 with gcc version 4.7.3 (git checkout on 20130411). I have no idea where this came from...
Ok. Your config should have CONFIG_DYNAMIC_DEBUG defined, and my config does not have that defined.
we have linux/kernel.h
linux/printk.h
linux/dynamic_debug.h
dynamic_debug.h will include linux/string.h when CONFIG_DYNAMIC_DEBUG is not defined.
Hi, Andrew,
How to fix this inconsistency caused by dynamic_debug.h
1. let linux/kernel.h include string.h directly
2. or let dynamic_debug include string.h always
3. let printk.h include string.h.
...
Yinghai
2013/6/11 Yinghai Lu <[email protected]>:
Quoted 77 lines · Joshua C.
Quoted 58 lines
2013/6/11 Yinghai Lu <[email protected]>:
Quoted 57 lines · Joshua C.
Quoted 40 lines
2013/6/11 Joshua C. <[email protected]>:
Quoted 39 lines
2013/6/10 Yinghai Lu <[email protected]>:
Quoted 12 lines · Sergey Meirovich
Quoted 2 lines
patches 1,2(latest one) have not helped me on 3.9.5:
So v1:
https://patchwork.kernel.org/patch/2694981/
https://patchwork.kernel.org/patch/2694971/and v2:
https://patchwork.kernel.org/patch/2695891/
https://patchwork.kernel.org/patch/2695881/Quoted 7 lines
Neither of two versions fix the problem on your setup?
Can you post boot log with
mtrr_cleanup_debugon 3.9.4?Thanks
Yinghai
I got some warnings when trying to build v2 of the patches:
# make -s ARCH=x86_64 V=1 -j4 bzImage kernel/range.c: In function 'add_range_with_merge': kernel/range.c:51:3: error: implicit declaration of function 'memmove' [-Werror=implicit-function-declaration] kernel/range.c:51:3: warning: incompatible implicit declaration of built-in function 'memmove' [enabled by default] cc1: some warnings being treated as errors scripts/Makefile.build:307: recipe for target 'kernel/range.o' failed make[1]: *** [kernel/range.o] Error 1 Makefile:793: recipe for target 'kernel' failed make: *** [kernel] Error 2 make: *** Waiting for unfinished jobs....--
--joshuait does not report warning when I compile it with
gcc (SUSE Linux) 4.7.2 20130108 [gcc-4_7-branch revision 195012
Quoted 11 lines
A trivial fix for the above warnings:
kernel/range.c +1
-0@@ -4,6 +4,7 @@#include <linux/kernel.h> #include <linux/init.h> #include <linux/sort.h> +#include <linux/string.h> Quoted 5 lines
Quoted 2 lines
kernel/range.c line 10
Quoted 2 lines
kernel/range.c +0
-0#include <linux/range.h> I use fedora17 with gcc version 4.7.3 (git checkout on 20130411). I have no idea where this came from...
Ok. Your config should have
CONFIG_DYNAMIC_DEBUGdefined, and my config does not have that defined.we have
linux/kernel.h
linux/printk.h
linux/dynamic_debug.h
dynamic_debug.hwill includelinux/string.hwhenCONFIG_DYNAMIC_DEBUGis not defined.Hi, Andrew,
Quoted 8 lines
How to fix this inconsistency caused by
dynamic_debug.h1. let
linux/kernel.hincludestring.hdirectly
2. or letdynamic_debugincludestring.halways
3. letprintk.hincludestring.h.
...Yinghai
You guys are better at kernel coding than I am, but can't we just directly add 'string.h' just like the small patch I posted? In the worst case the file will be included twice... Maybe this is not a good coding style but it solves the problem and doesn't cause any side effects. So why not do it the way I did?
--
--joshua