Re: [PATCH v9 06/15] kpageflags: Use is_page_hwpoison() to set KPF_HWPOISON
"David Hildenbrand (Arm)" <[email protected]>
| Newsgroups | org.kernel.vger.linux-fsdevel,org.kvack.linux-mm |
|---|---|
| Message-ID | <[email protected]> |
On 8/13/26 09:25, David Hildenbrand (Arm) wrote: > On 8/5/26 23:05, Matthew Wilcox (Oracle) wrote: >> Instead of knowing how hugetlb handles hwpoison, just ask >> is_page_hwpoison(). This gives us the flexibility to change how hwpoison >> is handled without updating this function in the future. >> >> Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> >> Reviewed-by: Jane Chu <[email protected]> >> Reviewed-by: Gregory Price (Meta) <[email protected]> >> --- >> fs/proc/page.c | 8 ++------ >> 1 file changed, 2 insertions(+), 6 deletions(-) >> >> diff --git a/fs/proc/page.c b/fs/proc/page.c >> index 7d9387143435..323e4c049f69 100644 >> --- a/fs/proc/page.c >> +++ b/fs/proc/page.c >> @@ -233,12 +233,8 @@ u64 stable_page_flags(const struct page *page) >> u |= kpf_copy_bit(k, KPF_UNEVICTABLE, PG_unevictable); >> u |= kpf_copy_bit(k, KPF_MLOCKED, PG_mlocked); >> >> -#ifdef CONFIG_MEMORY_FAILURE >> - if (u & (1 << KPF_HUGE)) >> - u |= kpf_copy_bit(k, KPF_HWPOISON, PG_hwpoison); >> - else >> - u |= kpf_copy_bit(ps.page_snapshot.flags.f, KPF_HWPOISON, PG_hwpoison); >> -#endif >> + if (is_page_hwpoison(page)) >> + u |= 1 << KPF_HWPOISON; I also just realized, that other users in this function now use BIT_ULL. > > snapshot_page() takes a snapshot of the folio and the page. If you look at > "page", you start going to the live version again. > If we really cannot use the snapshot_page, one alternative to avoid using "page" after actually snapshotting it would be: diff --git a/fs/proc/page.c b/fs/proc/page.c index 260772b20bd99..f2fc0917f0b6c 100644 --- a/fs/proc/page.c +++ b/fs/proc/page.c @@ -223,12 +223,8 @@ u64 stable_page_flags(const struct page *page) u |= kpf_copy_bit(k, KPF_UNEVICTABLE, PG_unevictable); u |= kpf_copy_bit(k, KPF_MLOCKED, PG_mlocked); -#ifdef CONFIG_MEMORY_FAILURE - if (u & BIT_ULL(KPF_HUGE)) - u |= kpf_copy_bit(k, KPF_HWPOISON, PG_hwpoison); - else - u |= kpf_copy_bit(ps.page_snapshot.flags.f, KPF_HWPOISON, PG_hwpoison); -#endif + if (ps.flags & PAGE_SNAPSHOT_HWPOISON) + u |= BIT_ULL(KPF_HWPOISON); u |= kpf_copy_bit(k, KPF_RESERVED, PG_reserved); u |= kpf_copy_bit(k, KPF_OWNER_2, PG_owner_2); diff --git a/include/linux/mm.h b/include/linux/mm.h index 29f13cc6b52a2..7e14e58b98c38 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -5496,6 +5496,7 @@ static inline bool page_pool_page_is_pp(const struct page *page) #define PAGE_SNAPSHOT_FAITHFUL (1 << 0) #define PAGE_SNAPSHOT_PG_BUDDY (1 << 1) #define PAGE_SNAPSHOT_PG_IDLE (1 << 2) +#define PAGE_SNAPSHOT_HWPOISON (1 << 3) struct page_snapshot { struct folio folio_snapshot; diff --git a/mm/util.c b/mm/util.c index bf0513d1d3d08..06195d0801130 100644 --- a/mm/util.c +++ b/mm/util.c @@ -1294,6 +1294,8 @@ static void set_ps_flags(struct page_snapshot *ps, const struct folio *folio, ps->flags |= PAGE_SNAPSHOT_PG_BUDDY; else if (page_count(page) == 0 && is_free_buddy_page(page)) ps->flags |= PAGE_SNAPSHOT_PG_BUDDY; + if (is_page_hwpoison(page)) + ps->flags |= PAGE_SNAPSHOT_HWPOISON; if (folio_test_idle(folio)) ps->flags |= PAGE_SNAPSHOT_PG_IDLE; (I'm starting to hate all these different hwpoison helpers) -- Cheers, David