mm/memory_hotplug: fix wrong casting for __remove_section()
Subsystems (2)
PATCH 1/1 mm/memory_hotplug: fix wrong casting for __remove_section()
__remove_section() calls __remove_zone() to shrink zone and pgdat. But due to wrong castings, __remvoe_zone() cannot shrink zone and pgdat correctly if pfn is over 0xffffffff.
So the patch fixes the following 3 wrong castings.
1. find_smallest_section_pfn() returns 0 or start_pfn which defined as unsigned long. But the function always returns 32bit value since the function is defined as int.
2. find_biggest_section_pfn() returns 0 or pfn which defined as unsigned long. the function always returns 32bit value since the function is defined as int.
3. __remove_section() calculates start_pfn using section_nr_to_pfn() and scn_nr. section_nr_to_pfn() just shifts scn_nr by PFN_SECTION_SHIFT bit. But since scn_nr is defined as int, section_nr_to_pfn() always return 32 bit value.
The patch fixes the wrong castings.
--- mm/memory_hotplug.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
mm/memory_hotplug.c +3 -3
@@ -331,7 +331,7 @@ int __ref __add_pages(int nid, unsigned long phys_start_pfn,#ifdef CONFIG_MEMORY_HOTREMOVE /* find the smallest valid pfn in the range [start_pfn, end_pfn) */ -static int find_smallest_section_pfn (int nid,struct zone *zone, +static unsigned long find_smallest_section_pfn (int nid,struct zone *zone,unsigned long start_pfn,unsigned long end_pfn) {
@@ -356,7 +356,7 @@ static int find_smallest_section_pfn(int nid, struct zone *zone, }/* find the biggest valid pfn in the range [start_pfn, end_pfn). */ -static int find_biggest_section_pfn (int nid,struct zone *zone, +static unsigned long find_biggest_section_pfn (int nid,struct zone *zone,unsigned long start_pfn,unsigned long end_pfn) {
@@ -544,7 +544,7 @@ static int __remove_section(struct zone *zone, struct mem_section *ms,return ret; scn_nr =__section_nr (ms); - start_pfn =section_nr_to_pfn (scn_nr); + start_pfn =section_nr_to_pfn ((unsigned long )scn_nr);__remove_zone (zone, start_pfn);sparse_remove_one_section (zone, ms, map_offset);
Signature · 7 lines
1.8.3.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 6 lines · YASUAKI ISHIMATSU
__remove_section()calls__remove_zone()to shrink zone and pgdat. But due to wrong castings,__remvoe_zone()cannot shrink zone and pgdat correctly if pfn is over0xffffffff.So the patch fixes the following 3 wrong castings.
Quoted 7 lines
1.
find_smallest_section_pfn()returns 0 orstart_pfnwhich defined as unsigned long. But the function always returns 32bit value since the function is defined as int.2.
find_biggest_section_pfn()returns 0 or pfn which defined as unsigned long. the function always returns 32bit value since the function is defined as int.
this is indeed wrong. Pfns over would be really broken 15TB. Not that unrealistic these days
Quoted 5 lines
3.
__remove_section()calculatesstart_pfnusingsection_nr_to_pfn()andscn_nr.section_nr_to_pfn()just shiftsscn_nrbyPFN_SECTION_SHIFTbit. But sincescn_nris defined as int,section_nr_to_pfn()always return 32 bit value.
Dohh, those nasty macros. This is hidden quite well. It seems other callers are using unsigned long properly. But I would rather make sure we won't repeat that error again. Can we instead make section_nr_to_pfn resp. pfn_to_section_nr static inline and enfore proper types?
I would also split this into two patches.
Thanks!
Quoted 41 lines
The patch fixes the wrong castings.
Signed-off-by Yasuaki Ishimatsu <[email protected]>--- mm/memory_hotplug.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)mm/memory_hotplug.c +3
-3@@ -331,7 +331,7 @@ int __ref __add_pages(int nid, unsigned long phys_start_pfn,#ifdef CONFIG_MEMORY_HOTREMOVE /* find the smallest valid pfn in the range [start_pfn, end_pfn) */ -static int find_smallest_section_pfn (int nid,struct zone *zone, +static unsigned long find_smallest_section_pfn (int nid,struct zone *zone,unsigned long start_pfn,unsigned long end_pfn) {@@ -356,7 +356,7 @@ static int find_smallest_section_pfn(int nid, struct zone *zone, }/* find the biggest valid pfn in the range [start_pfn, end_pfn). */ -static int find_biggest_section_pfn (int nid,struct zone *zone, +static unsigned long find_biggest_section_pfn (int nid,struct zone *zone,unsigned long start_pfn,unsigned long end_pfn) {@@ -544,7 +544,7 @@ static int __remove_section(struct zone *zone, struct mem_section *ms,return ret; scn_nr =__section_nr (ms); - start_pfn =section_nr_to_pfn (scn_nr); + start_pfn =section_nr_to_pfn ((unsigned long )scn_nr);__remove_zone (zone, start_pfn);sparse_remove_one_section (zone, ms, map_offset);Signature · 1 line
1.8.3.1
Signature · 8 lines
Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hi Michal,
Thanks you for reviewing my patch.
Quoted 11 lines · Michal Hocko
Quoted 10 lines · YASUAKI ISHIMATSU
__remove_section()calls__remove_zone()to shrink zone and pgdat. But due to wrong castings,__remvoe_zone()cannot shrink zone and pgdat correctly if pfn is over0xffffffff.So the patch fixes the following 3 wrong castings.
1.
find_smallest_section_pfn()returns 0 orstart_pfnwhich defined as unsigned long. But the function always returns 32bit value since the function is defined as int.
Quoted 6 lines
Quoted 3 lines
2.
find_biggest_section_pfn()returns 0 or pfn which defined as unsigned long. the function always returns 32bit value since the function is defined as int.this is indeed wrong. Pfns over would be really broken 15TB. Not that unrealistic these days
Why 15TB?
Actually, all callers use pfn which defined as unsigned long to receive the return value of find_{smallest|biggest}_section_nr(). So it will break over 16TB.
Quoted 11 lines
Quoted 6 lines
3.
__remove_section()calculatesstart_pfnusingsection_nr_to_pfn()andscn_nr.section_nr_to_pfn()just shiftsscn_nrbyPFN_SECTION_SHIFTbit. But sincescn_nris defined as int,section_nr_to_pfn()always return 32 bit value.Dohh, those nasty macros. This is hidden quite well. It seems other callers are using unsigned long properly. But I would rather make sure we won't repeat that error again. Can we instead make
section_nr_to_pfnresp.pfn_to_section_nrstatic inline and enfore proper types?
I'll update it.
Quoted 2 lines
I would also split this into two patches.
I'll update it.
Thanks,
Yasuaki Ishimatsu
Quoted 40 lines
Thanks!
Quoted 37 lines
The patch fixes the wrong castings.
Signed-off-by Yasuaki Ishimatsu <[email protected]>--- mm/memory_hotplug.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)mm/memory_hotplug.c +3
-3@@ -331,7 +331,7 @@ int __ref __add_pages(int nid, unsigned long phys_start_pfn,#ifdef CONFIG_MEMORY_HOTREMOVE /* find the smallest valid pfn in the range [start_pfn, end_pfn) */ -static int find_smallest_section_pfn (int nid,struct zone *zone, +static unsigned long find_smallest_section_pfn (int nid,struct zone *zone,unsigned long start_pfn,unsigned long end_pfn) {@@ -356,7 +356,7 @@ static int find_smallest_section_pfn(int nid, struct zone *zone, }/* find the biggest valid pfn in the range [start_pfn, end_pfn). */ -static int find_biggest_section_pfn (int nid,struct zone *zone, +static unsigned long find_biggest_section_pfn (int nid,struct zone *zone,unsigned long start_pfn,unsigned long end_pfn) {@@ -544,7 +544,7 @@ static int __remove_section(struct zone *zone, struct mem_section *ms,return ret; scn_nr =__section_nr (ms); - start_pfn =section_nr_to_pfn (scn_nr); + start_pfn =section_nr_to_pfn ((unsigned long )scn_nr);__remove_zone (zone, start_pfn);
Quoted 5 lines
Quoted 4 lines
mm/memory_hotplug.c +0
-0sparse_remove_one_section (zone, ms, map_offset);Signature · 1 line
1.8.3.1
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 16 lines · YASUAKI ISHIMATSU
Hi Michal,
Thanks you for reviewing my patch.
Quoted 11 lines · Michal Hocko
Quoted 10 lines · YASUAKI ISHIMATSU
__remove_section()calls__remove_zone()to shrink zone and pgdat. But due to wrong castings,__remvoe_zone()cannot shrink zone and pgdat correctly if pfn is over0xffffffff.So the patch fixes the following 3 wrong castings.
1.
find_smallest_section_pfn()returns 0 orstart_pfnwhich defined as unsigned long. But the function always returns 32bit value since the function is defined as int.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
2.
find_biggest_section_pfn()returns 0 or pfn which defined as unsigned long. the function always returns 32bit value since the function is defined as int.this is indeed wrong. Pfns over would be really broken 15TB. Not that unrealistic these days
Why 15TB?
0xffffffff>>28
Signature · 2 lines
Michal Hocko SUSE Labs
Hi Michal,
Quoted 21 lines · Michal Hocko
Quoted 20 lines · YASUAKI ISHIMATSU
Hi Michal,
Thanks you for reviewing my patch.
Quoted 15 lines · Michal Hocko
Quoted 13 lines · YASUAKI ISHIMATSU
__remove_section()calls__remove_zone()to shrink zone and pgdat. But due to wrong castings,__remvoe_zone()cannot shrink zone and pgdat correctly if pfn is over0xffffffff.So the patch fixes the following 3 wrong castings.
1.
find_smallest_section_pfn()returns 0 orstart_pfnwhich defined as unsigned long. But the function always returns 32bit value since the function is defined as int.2.
find_biggest_section_pfn()returns 0 or pfn which defined as unsigned long. the function always returns 32bit value since the function is defined as int.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
this is indeed wrong. Pfns over would be really broken 15TB. Not that unrealistic these days
Why 15TB?
0xffffffff>>28
Even thought I see your explanation, I cannot understand.
In my understanding, find_{smallest|biggest}_section_pfn() return integer. So the functions always return 0x00000000 - 0xffffffff. Therefore if pfn is over 0xffffffff (under 16TB), then the function cannot work correctly.
What am I wrong?
Thanks,
Yasuaki Ishimatsu
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 32 lines · YASUAKI ISHIMATSU
Hi Michal,
Quoted 21 lines · Michal Hocko
Quoted 20 lines · YASUAKI ISHIMATSU
Hi Michal,
Thanks you for reviewing my patch.
Quoted 15 lines · Michal Hocko
Quoted 13 lines · YASUAKI ISHIMATSU
__remove_section()calls__remove_zone()to shrink zone and pgdat. But due to wrong castings,__remvoe_zone()cannot shrink zone and pgdat correctly if pfn is over0xffffffff.So the patch fixes the following 3 wrong castings.
1.
find_smallest_section_pfn()returns 0 orstart_pfnwhich defined as unsigned long. But the function always returns 32bit value since the function is defined as int.2.
find_biggest_section_pfn()returns 0 or pfn which defined as unsigned long. the function always returns 32bit value since the function is defined as int.Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
this is indeed wrong. Pfns over would be really broken 15TB. Not that unrealistic these days
Why 15TB?
0xffffffff>>28
Quoted 7 lines
Even thought I see your explanation, I cannot understand.
In my understanding, find_{smallest|biggest}_section_pfn() return integer. So the functions always return
0x00000000-0xffffffff. Therefore if pfn is over0xffffffff(under 16TB), then the function cannot work correctly.What am I wrong?
You are not wrong. We are talking about the same thing AFAICS. I was just less precise...
Signature · 8 lines
Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>