mm: fix potential infinite loop in dissolve_free_huge_pages()
Subsystems (3)
RFC PATCH 1/1 mm: fix potential infinite loop in dissolve_free_huge_pages()
It is possible for some platforms, such as powerpc to set HPAGE_SHIFT to 0 to indicate huge pages not supported.
When this is the case, hugetlbfs could be disabled during boot time:
hugetlbfs: disabling because there are no supported hugepage sizes
Then in dissolve_free_huge_pages(), order is kept maximum (64 for 64bits), and the for loop below won't end:
for (pfn = start_pfn; pfn < end_pfn; pfn += 1 << order)
The fix below returns directly if the order isn't set to a correct value.
--- mm/hugetlb.c | 4 ++++ 1 file changed, 4 insertions(+)
mm/hugetlb.c +4 -0
@@ -1093,6 +1093,10 @@ void dissolve_free_huge_pages(unsigned long start_pfn, unsigned long end_pfn)for_each_hstate (h)if (order >huge_page_order (h)) order =huge_page_order (h); + +if (order ==8 *sizeof (void *)) +return ; +VM_BUG_ON (!IS_ALIGNED (start_pfn,1 << order));for (pfn = start_pfn; pfn < end_pfn; pfn +=1 << order)dissolve_free_huge_page (pfn_to_page (pfn));
--
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 Zhong,
Quoted 9 lines · Li Zhong
It is possible for some platforms, such as powerpc to set
HPAGE_SHIFTto 0 to indicate huge pages not supported.When this is the case, hugetlbfs could be disabled during boot time:
hugetlbfs: disabling because there are no supported hugepage sizesThen in
dissolve_free_huge_pages(), order is kept maximum (64 for 64bits), and the for loop below won't end:
for (pfn =start_pfn; pfn <end_pfn; pfn += 1 << order)
At first I wonder that why could dissolve_free_huge_pages() is called if the platform doesn't support hugetlbfs. But I found that the function is called by memory hotplug code without checking hugepage support.
So it looks to me straightforward and self-descriptive to check hugepage_supported() just before calling dissolve_free_huge_pages().
Thanks,
Naoya Horiguchi
Quoted 26 lines
The fix below returns directly if the order isn't set to a correct value.
Signed-off-by Li Zhong <[email protected]>--- mm/hugetlb.c | 4 ++++ 1 file changed, 4 insertions(+)mm/hugetlb.c +4
-1@@ -1093,6 +1093,10 @@ void dissolve_free_huge_pages(unsigned long start_pfn, unsigned long end_pfn)for_each_hstate (h)if (order >huge_page_order (h)) order =huge_page_order (h); + +if (order ==8 *sizeof (void *)) +return ; +VM_BUG_ON (!IS_ALIGNED (start_pfn,1 << order));for (pfn = start_pfn; pfn < end_pfn; pfn +=1 << order)dissolve_free_huge_page (pfn_to_page (pfn)); --
Quoted 5 lines
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>
--
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 13 lines · Naoya Horiguchi
Hi Zhong,
Quoted 9 lines · Li Zhong
It is possible for some platforms, such as powerpc to set
HPAGE_SHIFTto 0 to indicate huge pages not supported.When this is the case, hugetlbfs could be disabled during boot time:
hugetlbfs: disabling because there are no supported hugepage sizesThen in
dissolve_free_huge_pages(), order is kept maximum (64 for 64bits), and the for loop below won't end:
for (pfn =start_pfn; pfn <end_pfn; pfn += 1 << order)
Quoted 6 lines
At first I wonder that why could
dissolve_free_huge_pages()is called if the platform doesn't support hugetlbfs. But I found that the function is called by memory hotplug code without checking hugepage support.So it looks to me straightforward and self-descriptive to check
hugepage_supported()just before callingdissolve_free_huge_pages().
Hi, Naoya,
Thank you for the review and suggestion.
I'll send a updated version.
Thanks, Zhong
Quoted 29 lines
Thanks,
Naoya HoriguchiQuoted 25 lines
The fix below returns directly if the order isn't set to a correct value.
Signed-off-by Li Zhong <[email protected]>--- mm/hugetlb.c | 4 ++++ 1 file changed, 4 insertions(+)mm/hugetlb.c +4
-0@@ -1093,6 +1093,10 @@ void dissolve_free_huge_pages(unsigned long start_pfn, unsigned long end_pfn)for_each_hstate (h)if (order >huge_page_order (h)) order =huge_page_order (h); + +if (order ==8 *sizeof (void *)) +return ; +VM_BUG_ON (!IS_ALIGNED (start_pfn,1 << order));for (pfn = start_pfn; pfn < end_pfn; pfn +=1 << order)dissolve_free_huge_page (pfn_to_page (pfn));
Quoted 7 lines
Quoted 6 lines
--
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>
--
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>
PATCH v2 1/1 mm: fix potential infinite loop in dissolve_free_huge_pages()
In reply to Naoya HoriguchiIt is possible for some platforms, such as powerpc to set HPAGE_SHIFT to 0 to indicate huge pages not supported.
When this is the case, hugetlbfs could be disabled during boot time:
hugetlbfs: disabling because there are no supported hugepage sizes
Then in dissolve_free_huge_pages(), order is kept maximum (64 for 64bits), and the for loop below won't end:
for (pfn = start_pfn; pfn < end_pfn; pfn += 1 << order)
As suggested by Naoya, below fix checks hugepages_supported() before calling dissolve_free_huge_pages().
--- mm/memory_hotplug.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
mm/memory_hotplug.c +2 -1
@@ -1695,7 +1695,8 @@ repeat:* dissolve free hugepages in the memory block before doing offlining * actually in order to make hugetlbfs's object counting consistent. */ -dissolve_free_huge_pages (start_pfn, end_pfn); +if (hugepages_supported ()) +dissolve_free_huge_pages (start_pfn, end_pfn);/* check again */ offlined_pages =check_pages_isolated (start_pfn, end_pfn);if (offlined_pages <0 ) {
--
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 · Li Zhong
It is possible for some platforms, such as powerpc to set
HPAGE_SHIFTto 0 to indicate huge pages not supported.When this is the case, hugetlbfs could be disabled during boot time:
hugetlbfs: disabling because there are no supported hugepage sizes
Quoted 8 lines
Then in
dissolve_free_huge_pages(), order is kept maximum (64 for 64bits), and the for loop below won't end:
for (pfn =start_pfn; pfn <end_pfn; pfn += 1 << order)As suggested by Naoya, below fix checks
hugepages_supported()before callingdissolve_free_huge_pages().Signed-off-by Li Zhong <[email protected]>
Thanks!
And I think that this patch can go into stable (3.12+) trees.
Quoted 21 lines
--- mm/memory_hotplug.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)mm/memory_hotplug.c +2
-2@@ -1695,7 +1695,8 @@ repeat:* dissolve free hugepages in the memory block before doing offlining * actually in order to make hugetlbfs's object counting consistent. */ -dissolve_free_huge_pages (start_pfn, end_pfn); +if (hugepages_supported ()) +dissolve_free_huge_pages (start_pfn, end_pfn);/* check again */ offlined_pages =check_pages_isolated (start_pfn, end_pfn);if (offlined_pages <0 ) { --
Quoted 5 lines
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>
--
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>
PATCH 1/1 mm: fix potential infinite loop in dissolve_free_huge_pages() fix
In reply to Li ZhongNo legitimate reason to call dissolve_free_huge_pages() when !hugepages_supported().
---
To be folded into mm-fix-potential-infinite-loop-in-dissolve_free_huge_pages.patch.
mm/hugetlb.c | 3 +++ mm/memory_hotplug.c | 3 +-- 2 files changed, 4 insertions(+), 2 deletions(-)
mm/hugetlb.c +3 -0
@@ -1088,6 +1088,9 @@ void dissolve_free_huge_pages(unsigned long start_pfn, unsigned long end_pfn)unsigned long pfn;struct hstate *h; +if (!hugepages_supported ()) +return ; +/* Set scan step to minimum hugepage size */ for_each_hstate (h)if (order >huge_page_order (h))
mm/memory_hotplug.c +1 -2
@@ -1726,8 +1726,7 @@ repeat:* dissolve free hugepages in the memory block before doing offlining * actually in order to make hugetlbfs's object counting consistent. */ -if (hugepages_supported ()) -dissolve_free_huge_pages (start_pfn, end_pfn); +dissolve_free_huge_pages (start_pfn, end_pfn);/* check again */ offlined_pages =check_pages_isolated (start_pfn, end_pfn);if (offlined_pages <0 ) {
--
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>