[PATCH v3 7/7] pmem: fix pmem_do_write() avoid writing to 'np' page

From: Jane Chu
Date: Tue Jan 11 2022 - 14:00:57 EST


Since poisoned page is marked as not-present, the first of the
two back-to-back write_pmem() calls can only be made when there
is no poison in the range, otherwise kernel Oops.

Signed-off-by: Jane Chu <jane.chu@xxxxxxxxxx>
---
drivers/nvdimm/pmem.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
index dd2db4905c85..6e395014da5e 100644
--- a/drivers/nvdimm/pmem.c
+++ b/drivers/nvdimm/pmem.c
@@ -187,10 +187,15 @@ static blk_status_t pmem_do_write(struct pmem_device *pmem,
* after clear poison.
*/
flush_dcache_page(page);
- write_pmem(pmem_addr, page, page_off, len);
- if (unlikely(bad_pmem)) {
- rc = pmem_clear_poison(pmem, pmem_off, len);
+ if (!bad_pmem) {
write_pmem(pmem_addr, page, page_off, len);
+ } else {
+ rc = pmem_clear_poison(pmem, pmem_off, len);
+ if (rc == BLK_STS_OK)
+ write_pmem(pmem_addr, page, page_off, len);
+ else
+ pr_warn("%s: failed to clear poison\n",
+ __func__);
}

return rc;
--
2.18.4