linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [bug report] mm, hwpoison: memory_failure races with alloc_fresh_huge_page/free_huge_page
@ 2022-08-02  2:00 Miaohe Lin
  2022-08-02  4:07 ` Muchun Song
  0 siblings, 1 reply; 6+ messages in thread
From: Miaohe Lin @ 2022-08-02  2:00 UTC (permalink / raw)
  To: Linux-MM, linux-kernel
  Cc: Andrew Morton, Mike Kravetz, Naoya Horiguchi, Muchun Song

Hi all:
    When I investigate the mm/memory-failure.c code again, I found there's a possible race window
between memory_failure and alloc_fresh_huge_page/free_huge_page. Thank about the below scene:

CPU 1							CPU 2
alloc_fresh_huge_page -- page refcnt > 0		memory_failure
  prep_new_huge_page					  get_huge_page_for_hwpoison
							    !PageHeadHuge -- so 2(not a hugepage) is returned
    hugetlb_vmemmap_optimize -- subpages is read-only
    set_compound_page_dtor -- PageHuge is true now, but too late!!!
							  TestSetPageHWPoison(p)
							    -- We might write to read-only subpages here!!!

Another similar scene:

CPU 1							CPU 2
free_huge_page -- page refcnt == 0 and not PageHuge	memory_failure
							  get_huge_page_for_hwpoison
							    !PageHeadHuge -- so 2(not a hugepage) is returned
							  TestSetPageHWPoison(p)
							    -- We might write to read-only subpages here!!!
  hugetlb_vmemmap_restore -- subpages can be written to now, but too late!!!

I think the above scenes are possible. But I can't found a stable solution to fix it. Any suggestions?
Or is it not worth to fix it as it's too rare? Or am I miss something?

Any response would be appreciated!

Thanks!

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-08-05  2:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-02  2:00 [bug report] mm, hwpoison: memory_failure races with alloc_fresh_huge_page/free_huge_page Miaohe Lin
2022-08-02  4:07 ` Muchun Song
2022-08-02  6:27   ` Miaohe Lin
2022-08-04  7:40     ` Naoya Horiguchi
2022-08-04  7:44       ` Naoya Horiguchi
2022-08-05  2:33         ` Miaohe Lin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).