[PATCH 2/4] nvdimm/pmem: avoid HWPoison flag updates for clean pages

From: Muchun Song

Date: Thu Sep 03 2026 - 08:29:03 EST


pmem_mkpage_present() is called after persistent-memory poison has been
cleared. It only needs to clear PG_hwpoison and undo the MCE nospec state
for PFNs that are still marked poisoned.

For clean PFNs, test_and_clear_pmem_poison() has no semantic effect, but it
still performs an atomic clear operation against struct page flags. That is
unnecessary today and conflicts with the FS-DAX vmemmap optimization added
later in the series, where clean PFNs may be backed by shared read-only
metadata.

Check PageHWPoison() first so only poisoned PFNs update the page state.
Poison recovery keeps the same behavior, while clean PFNs no longer require
writable per-PFN metadata.

Signed-off-by: Muchun Song <songmuchun@xxxxxxxxxxxxx>
---
drivers/nvdimm/pmem.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
index 30a51c365ce8..b14f75daeda7 100644
--- a/drivers/nvdimm/pmem.c
+++ b/drivers/nvdimm/pmem.c
@@ -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 (PageHWPoison(page) && test_and_clear_pmem_poison(page))
clear_mce_nospec(pfn);
}
}
--
2.54.0