diff options
author | Zhang Yanfei <zhangyanfei@cn.fujitsu.com> | 2013-11-12 18:07:43 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-11-12 22:09:06 -0500 |
commit | 81556b02525181e19ef073a798ba9d48db96f708 (patch) | |
tree | b052b2fa8c92c80885245c3e13b6ef1ec4304fc1 | |
parent | 85b35feaecd4d2284505b22708795bc1f03fc897 (diff) |
mm/sparsemem: fix a bug in free_map_bootmem when CONFIG_SPARSEMEM_VMEMMAP
We pass the number of pages which hold page structs of a memory section
to free_map_bootmem(). This is right when !CONFIG_SPARSEMEM_VMEMMAP but
wrong when CONFIG_SPARSEMEM_VMEMMAP. When CONFIG_SPARSEMEM_VMEMMAP, we
should pass the number of pages of a memory section to free_map_bootmem.
So the fix is removing the nr_pages parameter. When
CONFIG_SPARSEMEM_VMEMMAP, we directly use the prefined marco
PAGES_PER_SECTION in free_map_bootmem. When !CONFIG_SPARSEMEM_VMEMMAP,
we calculate page numbers needed to hold the page structs for a memory
section and use the value in free_map_bootmem().
This was found by reading the code. And I have no machine that support
memory hot-remove to test the bug now.
Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Reviewed-by: Wanpeng Li <liwanp@linux.vnet.ibm.com>
Cc: Wen Congyang <wency@cn.fujitsu.com>
Cc: Tang Chen <tangchen@cn.fujitsu.com>
Cc: Toshi Kani <toshi.kani@hp.com>
Cc: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: Yasunori Goto <y-goto@jp.fujitsu.com>
Cc: Andy Whitcroft <apw@shadowen.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | mm/sparse.c | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/mm/sparse.c b/mm/sparse.c index fbb9dbc6aca9..8cc7be0e9590 100644 --- a/mm/sparse.c +++ b/mm/sparse.c | |||
@@ -603,10 +603,10 @@ static void __kfree_section_memmap(struct page *memmap) | |||
603 | vmemmap_free(start, end); | 603 | vmemmap_free(start, end); |
604 | } | 604 | } |
605 | #ifdef CONFIG_MEMORY_HOTREMOVE | 605 | #ifdef CONFIG_MEMORY_HOTREMOVE |
606 | static void free_map_bootmem(struct page *memmap, unsigned long nr_pages) | 606 | static void free_map_bootmem(struct page *memmap) |
607 | { | 607 | { |
608 | unsigned long start = (unsigned long)memmap; | 608 | unsigned long start = (unsigned long)memmap; |
609 | unsigned long end = (unsigned long)(memmap + nr_pages); | 609 | unsigned long end = (unsigned long)(memmap + PAGES_PER_SECTION); |
610 | 610 | ||
611 | vmemmap_free(start, end); | 611 | vmemmap_free(start, end); |
612 | } | 612 | } |
@@ -648,12 +648,15 @@ static void __kfree_section_memmap(struct page *memmap) | |||
648 | } | 648 | } |
649 | 649 | ||
650 | #ifdef CONFIG_MEMORY_HOTREMOVE | 650 | #ifdef CONFIG_MEMORY_HOTREMOVE |
651 | static void free_map_bootmem(struct page *memmap, unsigned long nr_pages) | 651 | static void free_map_bootmem(struct page *memmap) |
652 | { | 652 | { |
653 | unsigned long maps_section_nr, removing_section_nr, i; | 653 | unsigned long maps_section_nr, removing_section_nr, i; |
654 | unsigned long magic; | 654 | unsigned long magic, nr_pages; |
655 | struct page *page = virt_to_page(memmap); | 655 | struct page *page = virt_to_page(memmap); |
656 | 656 | ||
657 | nr_pages = PAGE_ALIGN(PAGES_PER_SECTION * sizeof(struct page)) | ||
658 | >> PAGE_SHIFT; | ||
659 | |||
657 | for (i = 0; i < nr_pages; i++, page++) { | 660 | for (i = 0; i < nr_pages; i++, page++) { |
658 | magic = (unsigned long) page->lru.next; | 661 | magic = (unsigned long) page->lru.next; |
659 | 662 | ||
@@ -756,7 +759,6 @@ static inline void clear_hwpoisoned_pages(struct page *memmap, int nr_pages) | |||
756 | static void free_section_usemap(struct page *memmap, unsigned long *usemap) | 759 | static void free_section_usemap(struct page *memmap, unsigned long *usemap) |
757 | { | 760 | { |
758 | struct page *usemap_page; | 761 | struct page *usemap_page; |
759 | unsigned long nr_pages; | ||
760 | 762 | ||
761 | if (!usemap) | 763 | if (!usemap) |
762 | return; | 764 | return; |
@@ -777,12 +779,8 @@ static void free_section_usemap(struct page *memmap, unsigned long *usemap) | |||
777 | * on the section which has pgdat at boot time. Just keep it as is now. | 779 | * on the section which has pgdat at boot time. Just keep it as is now. |
778 | */ | 780 | */ |
779 | 781 | ||
780 | if (memmap) { | 782 | if (memmap) |
781 | nr_pages = PAGE_ALIGN(PAGES_PER_SECTION * sizeof(struct page)) | 783 | free_map_bootmem(memmap); |
782 | >> PAGE_SHIFT; | ||
783 | |||
784 | free_map_bootmem(memmap, nr_pages); | ||
785 | } | ||
786 | } | 784 | } |
787 | 785 | ||
788 | void sparse_remove_one_section(struct zone *zone, struct mem_section *ms) | 786 | void sparse_remove_one_section(struct zone *zone, struct mem_section *ms) |