Re: [PATCH v6 5/6] pmem: refactor pmem_clear_poison()

From: Jane Chu
Date: Tue Mar 22 2022 - 19:46:09 EST


On 3/22/2022 1:53 AM, Christoph Hellwig wrote:
>> -static void hwpoison_clear(struct pmem_device *pmem,
>> - phys_addr_t phys, unsigned int len)
>> +static phys_addr_t to_phys(struct pmem_device *pmem, phys_addr_t offset)
>> {
>> + return pmem->phys_addr + offset;
>> +}
>> +
>> +static sector_t to_sect(struct pmem_device *pmem, phys_addr_t offset)
>> +{
>> + return (offset - pmem->data_offset) / 512;
>> +}
>> +
>> +static phys_addr_t to_offset(struct pmem_device *pmem, sector_t sector)
>> +{
>> + return sector * 512 + pmem->data_offset;
>> +}
>
> The multiplicate / divison using 512 could use shifts using
> SECTOR_SHIFT.

Nice, will do.

>
>> +
>> +static void clear_hwpoison(struct pmem_device *pmem, phys_addr_t offset,
>> + unsigned int len)
>
>> +static void clear_bb(struct pmem_device *pmem, sector_t sector, long blks)
>
> All these functions lack a pmem_ prefix.

Did you mean all of the helpers or just "clear_hwpoison" and "clear_bb"?
The reason I ask is that there are existing static helpers without
pmem_ prefix, just short function names.

>
>> +static blk_status_t __pmem_clear_poison(struct pmem_device *pmem,
>> + phys_addr_t offset, unsigned int len,
>> + unsigned int *blks)
>> +{
>> + phys_addr_t phys = to_phys(pmem, offset);
>> long cleared;
>> + blk_status_t rc;
>>
>> + cleared = nvdimm_clear_poison(to_dev(pmem), phys, len);
>> + *blks = cleared / 512;
>> + rc = (cleared < len) ? BLK_STS_IOERR : BLK_STS_OK;
>> + if (cleared <= 0 || *blks == 0)
>> + return rc;
>
> This look odd. I think just returing the cleared byte value would
> make much more sense:
>
> static long __pmem_clear_poison(struct pmem_device *pmem,
> phys_addr_t offset, unsigned int len)
> {
> long cleared = nvdimm_clear_poison(to_dev(pmem), phys, len);
>
> if (cleared > 0) {
> clear_hwpoison(pmem, offset, cleared);
> arch_invalidate_pmem(pmem->virt_addr + offset, len);
> }
>
> return cleared;
> }

Yes, this is cleaner, will do.

Thanks!
-jane