Skip to content

Commit 1dd2bfc

Browse files
yishimatsutorvalds
authored andcommitted
mm/memory_hotplug: change pfn_to_section_nr/section_nr_to_pfn macro to inline function
pfn_to_section_nr() and section_nr_to_pfn() are defined as macro. pfn_to_section_nr() has no issue even if it is defined as macro. But section_nr_to_pfn() has overflow issue if sec is defined as int. section_nr_to_pfn() just shifts sec by PFN_SECTION_SHIFT. If sec is defined as unsigned long, section_nr_to_pfn() returns pfn as 64 bit value. But if sec is defined as int, section_nr_to_pfn() returns pfn as 32 bit value. __remove_section() calculates start_pfn using section_nr_to_pfn() and scn_nr defined as int. So if hot-removed memory address is over 16TB, overflow issue occurs and section_nr_to_pfn() does not calculate correct pfn. To make callers use proper arg, the patch changes the macros to inline functions. Fixes: 815121d ("memory_hotplug: clear zone when removing the memory") Link: http://lkml.kernel.org/r/e643a387-e573-6bbf-d418-c60c8ee3d15e@gmail.com Signed-off-by: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com> Acked-by: Michal Hocko <mhocko@suse.com> Cc: Xishi Qiu <qiuxishi@huawei.com> Cc: Reza Arbab <arbab@linux.vnet.ibm.com> Cc: Vlastimil Babka <vbabka@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent c965385 commit 1dd2bfc

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

‎include/linux/mmzone.h‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,8 +1094,14 @@ static inline unsigned long early_pfn_to_nid(unsigned long pfn)
10941094
#error Allocator MAX_ORDER exceeds SECTION_SIZE
10951095
#endif
10961096

1097-
#define pfn_to_section_nr(pfn) ((pfn) >> PFN_SECTION_SHIFT)
1098-
#define section_nr_to_pfn(sec) ((sec) << PFN_SECTION_SHIFT)
1097+
static inline unsigned long pfn_to_section_nr(unsigned long pfn)
1098+
{
1099+
return pfn >> PFN_SECTION_SHIFT;
1100+
}
1101+
static inline unsigned long section_nr_to_pfn(unsigned long sec)
1102+
{
1103+
return sec << PFN_SECTION_SHIFT;
1104+
}
10991105

11001106
#define SECTION_ALIGN_UP(pfn) (((pfn) + PAGES_PER_SECTION - 1) & PAGE_SECTION_MASK)
11011107
#define SECTION_ALIGN_DOWN(pfn) ((pfn) & PAGE_SECTION_MASK)

‎mm/memory_hotplug.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ static int __remove_section(struct zone *zone, struct mem_section *ms,
551551
return ret;
552552

553553
scn_nr = __section_nr(ms);
554-
start_pfn = section_nr_to_pfn(scn_nr);
554+
start_pfn = section_nr_to_pfn((unsigned long)scn_nr);
555555
__remove_zone(zone, start_pfn);
556556

557557
sparse_remove_one_section(zone, ms, map_offset);

0 commit comments

Comments
 (0)