2021-09-14 23:36:59

by Jane Chu

[permalink] [raw]
Subject: [PATCH 3/3] libnvdimm/pmem: Provide pmem_dax_clear_poison for dax operation

Provide pmem_dax_clear_poison() to struct dax_operations.clear_poison.

Signed-off-by: Jane Chu <[email protected]>
---
drivers/nvdimm/pmem.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)

diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
index 1e0615b8565e..307a53aa3432 100644
--- a/drivers/nvdimm/pmem.c
+++ b/drivers/nvdimm/pmem.c
@@ -294,6 +294,22 @@ static int pmem_dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
PAGE_SIZE));
}

+static int pmem_dax_clear_poison(struct dax_device *dax_dev, pgoff_t pgoff,
+ size_t nr_pages)
+{
+ unsigned int len = PFN_PHYS(nr_pages);
+ sector_t sector = PFN_PHYS(pgoff) >> SECTOR_SHIFT;
+ struct pmem_device *pmem = dax_get_private(dax_dev);
+ phys_addr_t pmem_off = sector * 512 + pmem->data_offset;
+ blk_status_t ret;
+
+ if (!is_bad_pmem(&pmem->bb, sector, len))
+ return 0;
+
+ ret = pmem_clear_poison(pmem, pmem_off, len);
+ return (ret == BLK_STS_OK) ? 0 : -EIO;
+}
+
static long pmem_dax_direct_access(struct dax_device *dax_dev,
pgoff_t pgoff, long nr_pages, void **kaddr, pfn_t *pfn)
{
@@ -326,6 +342,7 @@ static const struct dax_operations pmem_dax_ops = {
.copy_from_iter = pmem_copy_from_iter,
.copy_to_iter = pmem_copy_to_iter,
.zero_page_range = pmem_dax_zero_page_range,
+ .clear_poison = pmem_dax_clear_poison,
};

static const struct attribute_group *pmem_attribute_groups[] = {
--
2.18.4


2021-11-04 17:59:27

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH 3/3] libnvdimm/pmem: Provide pmem_dax_clear_poison for dax operation

On Tue, Sep 14, 2021 at 05:31:32PM -0600, Jane Chu wrote:
> +static int pmem_dax_clear_poison(struct dax_device *dax_dev, pgoff_t pgoff,
> + size_t nr_pages)
> +{
> + unsigned int len = PFN_PHYS(nr_pages);
> + sector_t sector = PFN_PHYS(pgoff) >> SECTOR_SHIFT;
> + struct pmem_device *pmem = dax_get_private(dax_dev);
> + phys_addr_t pmem_off = sector * 512 + pmem->data_offset;
> + blk_status_t ret;
> +
> + if (!is_bad_pmem(&pmem->bb, sector, len))
> + return 0;
> +
> + ret = pmem_clear_poison(pmem, pmem_off, len);
> + return (ret == BLK_STS_OK) ? 0 : -EIO;

No need for the braces here (and I'd prefer a good old if anyway).

Otherwise looks good:

Reviewed-by: Christoph Hellwig <[email protected]>

2021-11-04 21:05:22

by Jane Chu

[permalink] [raw]
Subject: Re: [PATCH 3/3] libnvdimm/pmem: Provide pmem_dax_clear_poison for dax operation

On 11/4/2021 10:55 AM, Christoph Hellwig wrote:
> On Tue, Sep 14, 2021 at 05:31:32PM -0600, Jane Chu wrote:
>> +static int pmem_dax_clear_poison(struct dax_device *dax_dev, pgoff_t pgoff,
>> + size_t nr_pages)
>> +{
>> + unsigned int len = PFN_PHYS(nr_pages);
>> + sector_t sector = PFN_PHYS(pgoff) >> SECTOR_SHIFT;
>> + struct pmem_device *pmem = dax_get_private(dax_dev);
>> + phys_addr_t pmem_off = sector * 512 + pmem->data_offset;
>> + blk_status_t ret;
>> +
>> + if (!is_bad_pmem(&pmem->bb, sector, len))
>> + return 0;
>> +
>> + ret = pmem_clear_poison(pmem, pmem_off, len);
>> + return (ret == BLK_STS_OK) ? 0 : -EIO;
>
> No need for the braces here (and I'd prefer a good old if anyway).
>
> Otherwise looks good:
>
> Reviewed-by: Christoph Hellwig <[email protected]>
>

Thanks a lot! I'll keep in mind your comments.

-jane