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

Jane Chu
2022-01-28T21:33:01Z

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@oracle.com>
---
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 f2d6b34d48de..283890084d58 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