Make HWPoison helpers config-independent
Subsystems (4)
cover Make HWPoison helpers config-independent
Make the HWPoison page flag's test-and-set and test-and-clear accessors available regardless of CONFIG_MEMORY_FAILURE. When memory failure handling is disabled, the accessors return false, matching the absence of HWPoison state and providing a consistent interface across configurations.
Use the config-independent interface in the pmem driver to remove its private test_and_clear_pmem_poison() wrapper and the associated header dependency. No functional change is intended.
Kaitao Cheng (2):
mm/page-flags: Define HWPoison test-and-change helpers unconditionally nvdimm/pmem: Remove test_and_clear_pmem_poison()
drivers/nvdimm/pmem.c | 2 +- drivers/nvdimm/pmem.h | 12 ------------ include/linux/page-flags.h | 1 + 3 files changed, 2 insertions(+), 13 deletions(-)
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH 1/2 mm/page-flags: Define HWPoison test-and-change helpers unconditionally
From: Kaitao Cheng <[email protected]>
Page flag helpers for configuration-dependent flags provide false or no-op variants so that their users can be independent of the configuration.
The HWPoison helpers do not fully follow this pattern. When CONFIG_MEMORY_FAILURE is enabled, PAGEFLAG() and TESTSCFLAG() provide the regular, test-and-set, and test-and-clear operations. When it is disabled, only PAGEFLAG_FALSE() is instantiated, leaving TestSetPageHWPoison() and TestClearPageHWPoison() undefined.
Use TESTSCFLAG_FALSE() to provide the missing accessors when memory failure handling is disabled. Both accessors return false, which is consistent with HWPoison state being unavailable, and makes the accessor interface consistent across configurations.
--- include/linux/page-flags.h | 1 + 1 file changed, 1 insertion(+)
include/linux/page-flags.h +1 -0
@@ -656,6 +656,7 @@ TESTSCFLAG(HWPoison, hwpoison, PF_ANY)#define __PG_HWPOISON (1UL << PG_hwpoison)#else PAGEFLAG_FALSE(HWPoison, hwpoison) +TESTSCFLAG_FALSE(HWPoison, hwpoison)#define __PG_HWPOISON 0#endif
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH 2/2 nvdimm/pmem: Remove test_and_clear_pmem_poison()
In reply to Kaitao ChengFrom: Kaitao Cheng <[email protected]>
TestClearPageHWPoison() is now defined regardless of whether CONFIG_MEMORY_FAILURE is enabled, returning false when memory failure handling is unavailable.
The test_and_clear_pmem_poison() wrapper duplicates this configuration handling and has no other pmem-specific behavior.
Call TestClearPageHWPoison() directly and remove the redundant wrapper. This also removes the need to include page-flags.h from pmem.h.
No functional change is intended.
--- drivers/nvdimm/pmem.c | 2 +- drivers/nvdimm/pmem.h | 12 ------------ 2 files changed, 1 insertion(+), 13 deletions(-)
drivers/nvdimm/pmem.c +1 -1
@@ -80,7 +80,7 @@ static void pmem_mkpage_present(struct pmem_device *pmem, phys_addr_t offset,* here since we're in the driver I/O path and * outstanding I/O requests pin the dev_pagemap. */ -if (test_and_clear_pmem_poison (page)) +if (TestClearPageHWPoison (page))clear_mce_nospec (pfn); } }
drivers/nvdimm/pmem.h +0 -12
@@ -1,7 +1,6 @@/* SPDX-License-Identifier: GPL-2.0 */ #ifndef __NVDIMM_PMEM_H__#define __NVDIMM_PMEM_H__ -#include <linux/page-flags.h> #include <linux/badblocks.h> #include <linux/memremap.h> #include <linux/types.h>
@@ -31,15 +30,4 @@ long __pmem_direct_access(struct pmem_device *pmem, pgoff_t pgoff, long nr_pages, enum dax_access_mode mode, void **kaddr, unsigned long *pfn); -#ifdef CONFIG_MEMORY_FAILURE -static inline bool test_and_clear_pmem_poison (struct page *page) -{ -return TestClearPageHWPoison (page); -} -#else -static inline bool test_and_clear_pmem_poison (struct page *page) -{ -return false; -} -#endif #endif /* __NVDIMM_PMEM_H__ */
Signature · 1 line
2.50.1 (Apple Git-155)
Re: [PATCH 1/2] mm/page-flags: Define HWPoison test-and-change helpers unconditionally
In reply to Kaitao ChengQuoted 15 lines · Kaitao Cheng
From: Kaitao Cheng <[email protected]>
Page flag helpers for configuration-dependent flags provide false or no-op variants so that their users can be independent of the configuration.
The HWPoison helpers do not fully follow this pattern. When
CONFIG_MEMORY_FAILUREis enabled,PAGEFLAG()andTESTSCFLAG()provide the regular, test-and-set, and test-and-clear operations. When it is disabled, onlyPAGEFLAG_FALSE()is instantiated, leavingTestSetPageHWPoison()andTestClearPageHWPoison()undefined.
Quoted 6 lines
Use
TESTSCFLAG_FALSE()to provide the missing accessors when memory failure handling is disabled. Both accessors return false, which is consistent with HWPoison state being unavailable, and makes the accessor interface consistent across configurations.Signed-off-by Kaitao Cheng <[email protected]>
Thanks.
Re: [PATCH 2/2] nvdimm/pmem: Remove test_and_clear_pmem_poison()
In reply to Kaitao ChengQuoted 13 lines · Kaitao Cheng
From: Kaitao Cheng <[email protected]>
TestClearPageHWPoison()is now defined regardless of whetherCONFIG_MEMORY_FAILUREis enabled, returning false when memory failure handling is unavailable.The
test_and_clear_pmem_poison()wrapper duplicates this configuration handling and has no other pmem-specific behavior.
Quoted 6 lines
Call
TestClearPageHWPoison()directly and remove the redundant wrapper. This also removes the need to includepage-flags.hfrompmem.h.No functional change is intended.
Signed-off-by Kaitao Cheng <[email protected]>
The code becomes simpler.
Thanks.
David Hildenbrand (Arm)
maintainerRe: [PATCH 1/2] mm/page-flags: Define HWPoison test-and-change helpers unconditionally
In reply to Kaitao ChengQuoted 26 lines · Kaitao Cheng
From: Kaitao Cheng <[email protected]>
Page flag helpers for configuration-dependent flags provide false or no-op variants so that their users can be independent of the configuration.
The HWPoison helpers do not fully follow this pattern. When
CONFIG_MEMORY_FAILUREis enabled,PAGEFLAG()andTESTSCFLAG()provide the regular, test-and-set, and test-and-clear operations. When it is disabled, onlyPAGEFLAG_FALSE()is instantiated, leavingTestSetPageHWPoison()andTestClearPageHWPoison()undefined.Use
TESTSCFLAG_FALSE()to provide the missing accessors when memory failure handling is disabled. Both accessors return false, which is consistent with HWPoison state being unavailable, and makes the accessor interface consistent across configurations.Signed-off-by Kaitao Cheng <[email protected]>--- include/linux/page-flags.h | 1 + 1 file changed, 1 insertion(+)include/linux/page-flags.h +0
-0
include/linux/page-flags.h TESTSCFLAG(HWPoison, hwpoison, PF_ANY) · line 662
Quoted 7 lines
include/linux/page-flags.h +1
-0@@ -656,6 +656,7 @@ TESTSCFLAG(HWPoison, hwpoison, PF_ANY)#define __PG_HWPOISON (1UL << PG_hwpoison)#else PAGEFLAG_FALSE(HWPoison, hwpoison) +TESTSCFLAG_FALSE(HWPoison, hwpoison)#define __PG_HWPOISON 0#endif
Can we just squash this patch into #2 please?
Signature · 3 lines
Cheers, David
Re: [PATCH 2/2] nvdimm/pmem: Remove test_and_clear_pmem_poison()
In reply to Kaitao ChengQuoted 51 lines · Kaitao Cheng
From: Kaitao Cheng <[email protected]>
TestClearPageHWPoison()is now defined regardless of whetherCONFIG_MEMORY_FAILUREis enabled, returning false when memory failure handling is unavailable.The
test_and_clear_pmem_poison()wrapper duplicates this configuration handling and has no other pmem-specific behavior.Call
TestClearPageHWPoison()directly and remove the redundant wrapper. This also removes the need to includepage-flags.hfrompmem.h.No functional change is intended.
Signed-off-by Kaitao Cheng <[email protected]>--- drivers/nvdimm/pmem.c | 2 +- drivers/nvdimm/pmem.h | 12 ------------ 2 files changed, 1 insertion(+), 13 deletions(-)drivers/nvdimm/pmem.c +1
-1@@ -80,7 +80,7 @@ static void pmem_mkpage_present(struct pmem_device *pmem, phys_addr_t offset,* here since we're in the driver I/O path and * outstanding I/O requests pin the dev_pagemap. */ -if (test_and_clear_pmem_poison (page)) +if (TestClearPageHWPoison (page))clear_mce_nospec (pfn); } }drivers/nvdimm/pmem.h +0
-3@@ -1,7 +1,6 @@/* SPDX-License-Identifier: GPL-2.0 */ #ifndef __NVDIMM_PMEM_H__#define __NVDIMM_PMEM_H__ -#include <linux/page-flags.h> #include <linux/badblocks.h> #include <linux/memremap.h> #include <linux/types.h> @@ -31,15 +30,4 @@ long __pmem_direct_access(struct pmem_device *pmem, pgoff_t pgoff, long nr_pages, enum dax_access_mode mode, void **kaddr, unsigned long *pfn); -#ifdef CONFIG_MEMORY_FAILURE -static inline bool test_and_clear_pmem_poison (struct page *page)
drivers/nvdimm/pmem.h long __pmem_direct_access(struct pmem_device *pmem, pgoff_t pgoff, · line 33
Quoted 10 lines
drivers/nvdimm/pmem.h +0
-9-{ -return TestClearPageHWPoison (page); -} -#else -static inline bool test_and_clear_pmem_poison (struct page *page) -{ -return false; -} -#endif #endif /* __NVDIMM_PMEM_H__ */
With #1 squashed and the patch description updated accordingly:
Signature · 3 lines
Cheers, David
Re: [PATCH 2/2] nvdimm/pmem: Remove test_and_clear_pmem_poison()
In reply to Kaitao ChengQuoted 9 lines · Kaitao Cheng
From: Kaitao Cheng <[email protected]>
TestClearPageHWPoison()is now defined regardless of whetherCONFIG_MEMORY_FAILUREis enabled, returning false when memory failure handling is unavailable.The
test_and_clear_pmem_poison()wrapper duplicates this configuration handling and has no other pmem-specific behavior.
Quoted 6 lines
Call
TestClearPageHWPoison()directly and remove the redundant wrapper. This also removes the need to includepage-flags.hfrompmem.h.No functional change is intended.
Signed-off-by Kaitao Cheng <[email protected]>
Nice cleanup, but as David noted, please squash patch#1 into this one.
Signature · 2 lines
Oscar Salvador SUSE Labs
Re: [PATCH 2/2] nvdimm/pmem: Remove test_and_clear_pmem_poison()
Quoted 10 lines · Oscar Salvador (SUSE)
Quoted 9 lines · Kaitao Cheng
From: Kaitao Cheng <[email protected]>
TestClearPageHWPoison()is now defined regardless of whetherCONFIG_MEMORY_FAILUREis enabled, returning false when memory failure handling is unavailable.The
test_and_clear_pmem_poison()wrapper duplicates this configuration handling and has no other pmem-specific behavior.
Quoted 8 lines
Quoted 6 lines
Call
TestClearPageHWPoison()directly and remove the redundant wrapper. This also removes the need to includepage-flags.hfrompmem.h.No functional change is intended.
Signed-off-by Kaitao Cheng <[email protected]>Nice cleanup, but as David noted, please squash patch#1 into this one.
Although NVDIMM is currently the only external user of TestClearPageHWPoison, I still consider it a generic declaration. Combining the two patches might give the impression that TestClearPageHWPoison exists solely to serve a specific driver.
That said, I’m not opposed to merging the two patches, as doing so would make the submission more concise.
I think both approaches have their own advantages and disadvantages, which is why I haven’t sent a v2 yet.
Quoted 3 lines
Reviewed-by Oscar Salvador <[email protected]>
Signature · 2 lines
Thanks Kaitao Cheng
David Hildenbrand (Arm)
maintainerRe: [PATCH 2/2] nvdimm/pmem: Remove test_and_clear_pmem_poison()
Quoted 20 lines · Kaitao Cheng
Quoted 10 lines · Oscar Salvador (SUSE)
Quoted 9 lines · Kaitao Cheng
From: Kaitao Cheng <[email protected]>
TestClearPageHWPoison()is now defined regardless of whetherCONFIG_MEMORY_FAILUREis enabled, returning false when memory failure handling is unavailable.The
test_and_clear_pmem_poison()wrapper duplicates this configuration handling and has no other pmem-specific behavior.Quoted 8 lines
Quoted 6 lines
Call
TestClearPageHWPoison()directly and remove the redundant wrapper. This also removes the need to includepage-flags.hfrompmem.h.No functional change is intended.
Signed-off-by Kaitao Cheng <[email protected]>Nice cleanup, but as David noted, please squash patch#1 into this one.
Quoted 7 lines
Although NVDIMM is currently the only external user of TestClearPageHWPoison, I still consider it a generic declaration. Combining the two patches might give the impression that TestClearPageHWPoison exists solely to serve a specific driver.
That said, I’m not opposed to merging the two patches, as doing so would make the submission more concise.
Just squash them.
Signature · 3 lines
Cheers, David
Andrew Morton
maintainer Acked-by Muchun Song Acked-by David Hildenbrand (Arm) Reviewed-by Oscar SalvadorRe: [PATCH 1/2] mm/page-flags: Define HWPoison test-and-change helpers unconditionally
In reply to David Hildenbrand (Arm)Quoted 22 lines · On Mon, 7 Sep 2026 17:42:11 +0200 "David Hildenbrand (Arm)" <[email protected]>…
Quoted 21 lines · Kaitao Cheng
From: Kaitao Cheng <[email protected]>
Page flag helpers for configuration-dependent flags provide false or no-op variants so that their users can be independent of the configuration.
The HWPoison helpers do not fully follow this pattern. When
CONFIG_MEMORY_FAILUREis enabled,PAGEFLAG()andTESTSCFLAG()provide the regular, test-and-set, and test-and-clear operations. When it is disabled, onlyPAGEFLAG_FALSE()is instantiated, leavingTestSetPageHWPoison()andTestClearPageHWPoison()undefined.Use
TESTSCFLAG_FALSE()to provide the missing accessors when memory failure handling is disabled. Both accessors return false, which is consistent with HWPoison state being unavailable, and makes the accessor interface consistent across configurations.Signed-off-by Kaitao Cheng <[email protected]>--- include/linux/page-flags.h | 1 + 1 file changed, 1 insertion(+)
Quoted 14 lines
include/linux/page-flags.h TESTSCFLAG(HWPoison, hwpoison, PF_ANY) · line 662
Quoted 12 lines
include/linux/page-flags.h +1
-0@@ -656,6 +656,7 @@ TESTSCFLAG(HWPoison, hwpoison, PF_ANY)#define __PG_HWPOISON (1UL << PG_hwpoison)#else PAGEFLAG_FALSE(HWPoison, hwpoison) +TESTSCFLAG_FALSE(HWPoison, hwpoison)#define __PG_HWPOISON 0#endif Can we just squash this patch into #2 please?
I did that.
From: Kaitao Cheng <[email protected]>
Subject: mm/page-flags: define HWPoison test-and-change helpers unconditionally
Date: Thu, 3 Sep 2026 13:35:34 +0800
Page flag helpers for configuration-dependent flags provide false or no-op variants so that their users can be independent of the configuration.
The HWPoison helpers do not fully follow this pattern. When CONFIG_MEMORY_FAILURE is enabled, PAGEFLAG() and TESTSCFLAG() provide the regular, test-and-set, and test-and-clear operations. When it is disabled, only PAGEFLAG_FALSE() is instantiated, leaving TestSetPageHWPoison() and TestClearPageHWPoison() undefined.
Use TESTSCFLAG_FALSE() to provide the missing accessors when memory failure handling is disabled. Both accessors return false, which is consistent with HWPoison state being unavailable, and makes the accessor interface consistent across configurations.
Also remove now-unneeded test_and_clear_pmem_poison() from nvdimm/pmem.
---
drivers/nvdimm/pmem.c | 2 +- drivers/nvdimm/pmem.h | 12 ------------ include/linux/page-flags.h | 1 + 3 files changed, 2 insertions(+), 13 deletions(-)
include/linux/page-flags.h renamed from include/linux/page-flags.h~mm-page-flags-define-hwpoison-test-and-change-helpers-unconditionally +1 -0
@@ -655,6 +655,7 @@ TESTSCFLAG(HWPoison, hwpoison, PF_ANY)#define __PG_HWPOISON (1UL << PG_hwpoison)#else PAGEFLAG_FALSE(HWPoison, hwpoison) +TESTSCFLAG_FALSE(HWPoison, hwpoison)#define __PG_HWPOISON 0#endif
drivers/nvdimm/pmem.c renamed from drivers/nvdimm/pmem.c~mm-page-flags-define-hwpoison-test-and-change-helpers-unconditionally +1 -1
@@ -80,7 +80,7 @@ static void pmem_mkpage_present(struct p* here since we're in the driver I/O path and * outstanding I/O requests pin the dev_pagemap. */ -if (test_and_clear_pmem_poison (page)) +if (TestClearPageHWPoison (page))clear_mce_nospec (pfn); } }
drivers/nvdimm/pmem.h renamed from drivers/nvdimm/pmem.h~mm-page-flags-define-hwpoison-test-and-change-helpers-unconditionally +0 -12
@@ -1,7 +1,6 @@/* SPDX-License-Identifier: GPL-2.0 */ #ifndef __NVDIMM_PMEM_H__#define __NVDIMM_PMEM_H__ -#include <linux/page-flags.h> #include <linux/badblocks.h> #include <linux/memremap.h> #include <linux/types.h>
@@ -31,15 +30,4 @@ long __pmem_direct_access(struct pmem_de long nr_pages, enum dax_access_mode mode, void **kaddr, unsigned long *pfn); -#ifdef CONFIG_MEMORY_FAILURE -static inline bool test_and_clear_pmem_poison (struct page *page) -{ -return TestClearPageHWPoison (page); -} -#else -static inline bool test_and_clear_pmem_poison (struct page *page) -{ -return false; -} -#endif #endif /* __NVDIMM_PMEM_H__ */
_
Re: [PATCH 1/2] mm/page-flags: Define HWPoison test-and-change helpers unconditionally
Quoted 39 lines · Andrew Morton
Quoted 22 lines · On Mon, 7 Sep 2026 17:42:11 +0200 "David Hildenbrand (Arm)" <[email protected]>…
Quoted 21 lines · Kaitao Cheng
From: Kaitao Cheng <[email protected]>
Page flag helpers for configuration-dependent flags provide false or no-op variants so that their users can be independent of the configuration.
The HWPoison helpers do not fully follow this pattern. When
CONFIG_MEMORY_FAILUREis enabled,PAGEFLAG()andTESTSCFLAG()provide the regular, test-and-set, and test-and-clear operations. When it is disabled, onlyPAGEFLAG_FALSE()is instantiated, leavingTestSetPageHWPoison()andTestClearPageHWPoison()undefined.Use
TESTSCFLAG_FALSE()to provide the missing accessors when memory failure handling is disabled. Both accessors return false, which is consistent with HWPoison state being unavailable, and makes the accessor interface consistent across configurations.Signed-off-by Kaitao Cheng <[email protected]>--- include/linux/page-flags.h | 1 + 1 file changed, 1 insertion(+)Quoted 14 lines
include/linux/page-flags.h TESTSCFLAG(HWPoison, hwpoison, PF_ANY) · line 662
Quoted 12 lines
include/linux/page-flags.h +1
-0@@ -656,6 +656,7 @@ TESTSCFLAG(HWPoison, hwpoison, PF_ANY)#define __PG_HWPOISON (1UL << PG_hwpoison)#else PAGEFLAG_FALSE(HWPoison, hwpoison) +TESTSCFLAG_FALSE(HWPoison, hwpoison)#define __PG_HWPOISON 0#endif Can we just squash this patch into #2 please?
Quoted 1 line
I did that.
I’ve also posted a v2 version.
https://lore.kernel.org/all/[email protected]/
Quoted 94 lines
From: Kaitao Cheng <[email protected]>
Subject:mm/page-flags: define HWPoison test-and-change helpers unconditionally
Date: Thu, 3 Sep 2026 13:35:34 +0800Page flag helpers for configuration-dependent flags provide false or no-op variants so that their users can be independent of the configuration.
The HWPoison helpers do not fully follow this pattern. When
CONFIG_MEMORY_FAILUREis enabled,PAGEFLAG()andTESTSCFLAG()provide the regular, test-and-set, and test-and-clear operations. When it is disabled, onlyPAGEFLAG_FALSE()is instantiated, leavingTestSetPageHWPoison()andTestClearPageHWPoison()undefined.Use
TESTSCFLAG_FALSE()to provide the missing accessors when memory failure handling is disabled. Both accessors return false, which is consistent with HWPoison state being unavailable, and makes the accessor interface consistent across configurations.Also remove now-unneeded
test_and_clear_pmem_poison()from nvdimm/pmem.Signed-off-by Kaitao Cheng <[email protected]>Signed-off-by Andrew Morton <[email protected]>Acked-by Muchun Song <[email protected]>Reviewed-by Oscar Salvador <[email protected]>Cc Alison Schofield <[email protected]>Cc Dave Jiang <[email protected]>Cc Liam R. Howlett <[email protected]>Cc Lorenzo Stoakes <[email protected]>Cc Michal Hocko <[email protected]>Cc Mike Rapoport <[email protected]>Cc Suren Baghdasaryan <[email protected]>Cc Vishal Verma <[email protected]>Cc Vlastimil Babka <[email protected]>Cc Ira Weiny <[email protected]>---
drivers/nvdimm/pmem.c | 2 +- drivers/nvdimm/pmem.h | 12 ------------ include/linux/page-flags.h | 1 + 3 files changed, 2 insertions(+), 13 deletions(-)include/linux/page-flags.h renamed from include/linux/page-flags.h~mm-page-flags-define-hwpoison-test-and-change-helpers-unconditionally +1
-0@@ -655,6 +655,7 @@ TESTSCFLAG(HWPoison, hwpoison, PF_ANY)#define __PG_HWPOISON (1UL << PG_hwpoison)#else PAGEFLAG_FALSE(HWPoison, hwpoison) +TESTSCFLAG_FALSE(HWPoison, hwpoison)#define __PG_HWPOISON 0#endif drivers/nvdimm/pmem.c renamed from drivers/nvdimm/pmem.c~mm-page-flags-define-hwpoison-test-and-change-helpers-unconditionally +1
-1@@ -80,7 +80,7 @@ static void pmem_mkpage_present(struct p* here since we're in the driver I/O path and * outstanding I/O requests pin the dev_pagemap. */ -if (test_and_clear_pmem_poison (page)) +if (TestClearPageHWPoison (page))clear_mce_nospec (pfn); } }drivers/nvdimm/pmem.h renamed from drivers/nvdimm/pmem.h~mm-page-flags-define-hwpoison-test-and-change-helpers-unconditionally +0
-12@@ -1,7 +1,6 @@/* SPDX-License-Identifier: GPL-2.0 */ #ifndef __NVDIMM_PMEM_H__#define __NVDIMM_PMEM_H__ -#include <linux/page-flags.h> #include <linux/badblocks.h> #include <linux/memremap.h> #include <linux/types.h> @@ -31,15 +30,4 @@ long __pmem_direct_access(struct pmem_de long nr_pages, enum dax_access_mode mode, void **kaddr, unsigned long *pfn); -#ifdef CONFIG_MEMORY_FAILURE -static inline bool test_and_clear_pmem_poison (struct page *page) -{ -return TestClearPageHWPoison (page); -} -#else -static inline bool test_and_clear_pmem_poison (struct page *page) -{ -return false; -} -#endif #endif /* __NVDIMM_PMEM_H__ */ _
Signature · 2 lines
Thanks Kaitao Cheng