Re: [PATCH 1/4] mm: filemap: check if any subpage is hwpoisoned for PMD page fault

From: Kirill A. Shutemov
Date: Wed Sep 15 2021 - 07:46:21 EST


On Tue, Sep 14, 2021 at 11:37:15AM -0700, Yang Shi wrote:
> diff --git a/mm/memory.c b/mm/memory.c
> index 25fc46e87214..1765bf72ed16 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -3920,8 +3920,17 @@ vm_fault_t do_set_pmd(struct vm_fault *vmf, struct page *page)
> if (unlikely(!pmd_none(*vmf->pmd)))
> goto out;
>
> - for (i = 0; i < HPAGE_PMD_NR; i++)
> + for (i = 0; i < HPAGE_PMD_NR; i++) {
> + /*
> + * Just backoff if any subpage of a THP is corrupted otherwise
> + * the corrupted page may mapped by PMD silently to escape the
> + * check. This kind of THP just can be PTE mapped. Access to
> + * the corrupted subpage should trigger SIGBUS as expected.
> + */
> + if (PageHWPoison(page + i))
> + goto out;
> flush_icache_page(vma, page + i);
> + }

This is somewhat costly.

flush_icache_page() is empty on most archs so compiler makes the loop go
away before the change. Also page->flags for most of the pages will not
necessary be hot.

I wounder if we should consider making PG_hwpoison to cover full compound
page. On marking page hwpoison we try to split it and mark relevant base
page, if split fails -- mark full compound page.

As alternative we can have one more flag that indicates that the compound
page contains at least one hwpoisoned base page. We should have enough
space in the first tail page.

--
Kirill A. Shutemov