Linux filesystem development
 help / color / mirror / Atom feed
From: "David Hildenbrand (Arm)" <david@kernel.org>
To: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Jane Chu <jane.chu@oracle.com>,
	linux-mm@kvack.org
Cc: Muchun Song <muchun.song@linux.dev>,
	Oscar Salvador <osalvador@suse.de>,
	Miaohe Lin <linmiaohe@huawei.com>,
	Naoya Horiguchi <nao.horiguchi@gmail.com>,
	Jan Kara <jack@suse.cz>,
	linux-fsdevel@vger.kernel.org,
	Christian Brauner <christian@brauner.io>,
	Jiaqi Yan <jiaqiyan@google.com>,
	"Gregory Price (Meta)" <gourry@gourry.net>
Subject: Re: [PATCH v9 06/15] kpageflags: Use is_page_hwpoison() to set KPF_HWPOISON
Date: Thu, 13 Aug 2026 11:01:02 +0200	[thread overview]
Message-ID: <e68018a5-a8d0-4ca6-b3f7-7a151d17be31@kernel.org> (raw)
In-Reply-To: <3e609c64-a393-4667-be74-6cb2bbdcb717@kernel.org>

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) <willy@infradead.org>
>> Reviewed-by: Jane Chu <jane.chu@oracle.com>
>> Reviewed-by: Gregory Price (Meta) <gourry@gourry.net>
>> ---
>>  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

  reply	other threads:[~2026-08-13  9:01 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-05 21:05 [PATCH v9 00/15] Use generic_file_read_iter() in hugetlbfs Matthew Wilcox (Oracle)
2026-08-05 21:05 ` [PATCH v9 01/15] memory-failure: Fix hardware poison check in unpoison_memory() again Matthew Wilcox (Oracle)
2026-08-05 21:05 ` [PATCH v9 02/15] memory-failure: Prevent hugetlb freeing during unpoisoning Matthew Wilcox (Oracle)
2026-08-05 21:05 ` [PATCH v9 03/15] mm: Rename folio_contain_hwpoison_page() to folio_has_hwpoison_page() Matthew Wilcox (Oracle)
2026-08-13  7:20   ` David Hildenbrand (Arm)
2026-08-05 21:05 ` [PATCH v9 04/15] hugetlb: Mark some function arguments as const Matthew Wilcox (Oracle)
2026-08-05 21:05 ` [PATCH v9 05/15] guest_memfd: Use folio_has_hwpoisoned_page() Matthew Wilcox (Oracle)
2026-08-13  7:20   ` David Hildenbrand (Arm)
2026-08-13 11:50     ` Matthew Wilcox
2026-08-05 21:05 ` [PATCH v9 06/15] kpageflags: Use is_page_hwpoison() to set KPF_HWPOISON Matthew Wilcox (Oracle)
2026-08-13  7:25   ` David Hildenbrand (Arm)
2026-08-13  9:01     ` David Hildenbrand (Arm) [this message]
2026-08-05 21:05 ` [PATCH v9 07/15] hugetlb: Move poison to pages before clearing hugetlb page type Matthew Wilcox (Oracle)
2026-08-05 21:05 ` [PATCH v9 08/15] hugetlb: Use the has_hwpoisoned flag Matthew Wilcox (Oracle)
2026-08-13  8:29   ` David Hildenbrand (Arm)
2026-08-13 16:17     ` Matthew Wilcox
2026-08-13 11:12   ` Pedro Falcato
2026-08-05 21:05 ` [PATCH v9 09/15] mm: Remove locking mf_mutex in is_raw_hwpoison_page_in_hugepage() Matthew Wilcox (Oracle)
2026-08-05 21:05 ` [PATCH v9 10/15] mm: Check individual hugetlb pages for poison Matthew Wilcox (Oracle)
2026-08-05 21:05 ` [PATCH v9 11/15] filemap: Add hwpoison handling to filemap_read() Matthew Wilcox (Oracle)
2026-08-13 10:55   ` Pedro Falcato
2026-08-13 16:33     ` Matthew Wilcox
2026-08-05 21:05 ` [PATCH v9 12/15] filemap: Remove checks in mapping_set_folio_order_range() Matthew Wilcox (Oracle)
2026-08-13 11:05   ` Pedro Falcato
2026-08-05 21:05 ` [PATCH v9 13/15] hugetlb: Set mapping folio order Matthew Wilcox (Oracle)
2026-08-13 11:06   ` Pedro Falcato
2026-08-05 21:05 ` [PATCH v9 14/15] filemap: Add support for authoritative mappings Matthew Wilcox (Oracle)
2026-08-13 11:10   ` Pedro Falcato
2026-08-05 21:05 ` [PATCH v9 15/15] hugetlb: replace hugetlbfs_read_iter() with generic_file_read_iter() Matthew Wilcox (Oracle)
2026-08-13 11:10   ` Pedro Falcato
2026-08-06 19:47 ` [PATCH v9 00/15] Use generic_file_read_iter() in hugetlbfs jane.chu
2026-08-13  8:37 ` Lorenzo Stoakes (ARM)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e68018a5-a8d0-4ca6-b3f7-7a151d17be31@kernel.org \
    --to=david@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=christian@brauner.io \
    --cc=gourry@gourry.net \
    --cc=jack@suse.cz \
    --cc=jane.chu@oracle.com \
    --cc=jiaqiyan@google.com \
    --cc=linmiaohe@huawei.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=muchun.song@linux.dev \
    --cc=nao.horiguchi@gmail.com \
    --cc=osalvador@suse.de \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox