mm: fix panic caused by __page_handle_poison()
Subsystems (2)
PATCH 1/1 mm: fix panic caused by __page_handle_poison()
By commit 510d25c92ec4 ("mm/hwpoison: disable pcp for page_handle_poison()"), __page_handle_poison() was introduced, and if we mark:
RET_A = dissolve_free_huge_page();RET_B = take_page_off_buddy();
then __page_handle_poison was supposed to return TRUE When RET_A == 0 && RET_B == TRUE
But since it failed to take care the case when RET_A is -EBUSY or -ENOMEM, and just return the ret as a bool which actually become TRUE, it break the original logical.
The following result is a huge page in freelist but was referenced as poisoned, and lead into the final panic:
kernel BUG at mm/internal.h:95!
invalid opcode: 0000 [#1] SMP PTI
skip...
RIP: 0010:set_page_refcounted mm/internal.h:95 [inline] RIP: 0010:remove_hugetlb_page+0x23c/0x240 mm/hugetlb.c:1371 skip... Call Trace: remove_pool_huge_page+0xe4/0x110 mm/hugetlb.c:1892 return_unused_surplus_pages+0x8d/0x150 mm/hugetlb.c:2272 hugetlb_acct_memory.part.91+0x524/0x690 mm/hugetlb.c:4017
This patch replace 'bool' with 'int' to handle RET_A correctly.
--- mm/memory-failure.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/memory-failure.c +2 -2
@@ -68,7 +68,7 @@static bool __page_handle_poison (struct page *page) { -bool ret; +int ret;zone_pcp_disable (page_zone (page)); ret =dissolve_free_huge_page (page);
@@ -76,7 +76,7 @@ static bool __page_handle_poison(struct page *page) ret =take_page_off_buddy (page);zone_pcp_enable (page_zone (page)); -return ret; +return ret >0 ; }static bool page_handle_poison (struct page *page,bool hugepage_or_freepage,bool release)
Signature · 1 line
1.8.3.1
Quoted 7 lines · 王贇
By commit
510d25c92ec4("mm/hwpoison: disable pcp forpage_handle_poison()"),__page_handle_poison()was introduced, and if we mark:
RET_A=dissolve_free_huge_page();RET_B=take_page_off_buddy();
Quoted 6 lines
then
__page_handle_poisonwas supposed to return TRUE WhenRET_A== 0 &&RET_B== TRUEBut since it failed to take care the case when
RET_Ais-EBUSYor-ENOMEM, and just return the ret as a bool which actually become TRUE, it break the original logical.
s/logical/logic/ ?
Quoted 15 lines
The following result is a huge page in freelist but was referenced as poisoned, and lead into the final panic:
kernel BUG at
mm/internal.h:95!
invalid opcode: 0000 [#1] SMP PTI
skip...RIP: 0010:set_page_refcounted mm/internal.h:95 [inline] RIP: 0010:remove_hugetlb_page+0x23c/0x240 mm/hugetlb.c:1371 skip... Call Trace: remove_pool_huge_page+0xe4/0x110 mm/hugetlb.c:1892 return_unused_surplus_pages+0x8d/0x150 mm/hugetlb.c:2272 hugetlb_acct_memory.part.91+0x524/0x690 mm/hugetlb.c:4017
Quoted 4 lines
This patch replace 'bool' with 'int' to handle
RET_Acorrectly.Reported-by Abaci <[email protected]>Signed-off-by Michael Wang <[email protected]>
Thank you very much, this fix is totally right.
Could you add the following tags, too?
Thanks,
Naoya Horiguchi
Quoted 8 lines · HORIGUCHI NAOYA(堀口 直也)
Quoted 7 lines · 王贇
By commit
510d25c92ec4("mm/hwpoison: disable pcp forpage_handle_poison()"),__page_handle_poison()was introduced, and if we mark:
RET_A=dissolve_free_huge_page();RET_B=take_page_off_buddy();
Quoted 8 lines
Quoted 6 lines
then
__page_handle_poisonwas supposed to return TRUE WhenRET_A== 0 &&RET_B== TRUEBut since it failed to take care the case when
RET_Ais-EBUSYor-ENOMEM, and just return the ret as a bool which actually become TRUE, it break the original logical.s/logical/logic/ ?
Will Fix it in v2.
Quoted 21 lines
Quoted 16 lines
The following result is a huge page in freelist but was referenced as poisoned, and lead into the final panic:
kernel BUG at
mm/internal.h:95!
invalid opcode: 0000 [#1] SMP PTI
skip...RIP: 0010:set_page_refcounted mm/internal.h:95 [inline] RIP: 0010:remove_hugetlb_page+0x23c/0x240 mm/hugetlb.c:1371 skip... Call Trace: remove_pool_huge_page+0xe4/0x110 mm/hugetlb.c:1892 return_unused_surplus_pages+0x8d/0x150 mm/hugetlb.c:2272 hugetlb_acct_memory.part.91+0x524/0x690 mm/hugetlb.c:4017Quoted 4 lines
This patch replace 'bool' with 'int' to handle
RET_Acorrectly.Reported-by Abaci <[email protected]>Signed-off-by Michael Wang <[email protected]>
Quoted 8 lines
Thank you very much, this fix is totally right.
Acked-by Naoya Horiguchi <[email protected]>Could you add the following tags, too?
Fixes 510d25c92ec4 ("mm/hwpoison: disable pcp for page_handle_poison()")Cc <[email protected]> # 5.14
Thanks for the review, will add in v2 and send out soon.
Regards,
Michael Wang
Quoted 4 lines
Thanks,
Naoya Horiguchi
PATCH v2 1/1 mm: fix panic caused by __page_handle_poison()
In reply to 王贇By commit 510d25c92ec4 ("mm/hwpoison: disable pcp for page_handle_poison()"), __page_handle_poison() was introduced, and if we mark:
RET_A = dissolve_free_huge_page();RET_B = take_page_off_buddy();
then __page_handle_poison was supposed to return TRUE When RET_A == 0 && RET_B == TRUE
But since it failed to take care the case when RET_A is -EBUSY or -ENOMEM, and just return the ret as a bool which actually become TRUE, it break the original logic.
The following result is a huge page in freelist but was referenced as poisoned, and lead into the final panic:
kernel BUG at mm/internal.h:95!
invalid opcode: 0000 [#1] SMP PTI
skip...
RIP: 0010:set_page_refcounted mm/internal.h:95 [inline] RIP: 0010:remove_hugetlb_page+0x23c/0x240 mm/hugetlb.c:1371 skip... Call Trace: remove_pool_huge_page+0xe4/0x110 mm/hugetlb.c:1892 return_unused_surplus_pages+0x8d/0x150 mm/hugetlb.c:2272 hugetlb_acct_memory.part.91+0x524/0x690 mm/hugetlb.c:4017
This patch replace 'bool' with 'int' to handle RET_A correctly.
--- mm/memory-failure.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/memory-failure.c +2 -2
@@ -68,7 +68,7 @@static bool __page_handle_poison (struct page *page) { -bool ret; +int ret;zone_pcp_disable (page_zone (page)); ret =dissolve_free_huge_page (page);
@@ -76,7 +76,7 @@ static bool __page_handle_poison(struct page *page) ret =take_page_off_buddy (page);zone_pcp_enable (page_zone (page)); -return ret; +return ret >0 ; }static bool page_handle_poison (struct page *page,bool hugepage_or_freepage,bool release)
Signature · 1 line
1.8.3.1