Re: [PATCH 3/3] libnvdimm, pmem: clear poison on write

From: Verma, Vishal L
Date: Thu Mar 10 2016 - 19:40:18 EST


On Tue, 2016-03-08 at 14:47 -0800, Dan Williams wrote:
> If a write is directed at a known bad block perform the following:
>
> 1/ write the data
>
> 2/ send a clear poison command
>
> 3/ invalidate the poison out of the cache hierarchy
>
> Cc: <x86@xxxxxxxxxx>
> Cc: Vishal Verma <vishal.l.verma@xxxxxxxxx>
> Cc: Ross Zwisler <ross.zwisler@xxxxxxxxxxxxxxx>
> Signed-off-by: Dan Williams <dan.j.williams@xxxxxxxxx>
> ---
> Âarch/x86/include/asm/pmem.h |ÂÂÂÂ5 +++++
> Âdrivers/nvdimm/bus.cÂÂÂÂÂÂÂÂ|ÂÂÂ46
> +++++++++++++++++++++++++++++++++++++++++++
> Âdrivers/nvdimm/nd.hÂÂÂÂÂÂÂÂÂ|ÂÂÂÂ2 ++
> Âdrivers/nvdimm/pmem.cÂÂÂÂÂÂÂ|ÂÂÂ29 ++++++++++++++++++++++++++-
> Âinclude/linux/pmem.hÂÂÂÂÂÂÂÂ|ÂÂÂ19 ++++++++++++++++++
> Â5 files changed, 100 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/include/asm/pmem.h b/arch/x86/include/asm/pmem.h
> index c57fd1ea9689..bf8b35d2035a 100644
> --- a/arch/x86/include/asm/pmem.h
> +++ b/arch/x86/include/asm/pmem.h

<>

> Âstatic int pmem_do_bvec(struct pmem_device *pmem, struct page *page,
> Â unsigned int len, unsigned int off, int rw,
> Â sector_t sector)
> Â{
> Â int rc = 0;
> + bool bad_pmem = false;
> Â void *mem = kmap_atomic(page);
> Â phys_addr_t pmem_off = sector * 512 + pmem->data_offset;
> Â void __pmem *pmem_addr = pmem->virt_addr + pmem_off;
> Â
> + if (unlikely(is_bad_pmem(&pmem->bb, sector, len)))
> + bad_pmem = true;
> +
> Â if (rw == READ) {
> - if (unlikely(is_bad_pmem(&pmem->bb, sector, len)))
> + if (unlikely(bad_pmem))
> Â rc = -EIO;
> Â else {
> Â memcpy_from_pmem(mem + off, pmem_addr, len);
> @@ -81,6 +104,10 @@ static int pmem_do_bvec(struct pmem_device *pmem,
> struct page *page,
> Â } else {
> Â flush_dcache_page(page);
> Â memcpy_to_pmem(pmem_addr, mem + off, len);
> + if (unlikely(bad_pmem)) {
> + pmem_clear_poison(pmem, pmem_off, len);
> + memcpy_to_pmem(pmem_addr, mem + off, len);
> + }
> Â }

Just noticed this -- why do we memcpy_to_pmem twice in the error case?
Sh
ouldn't it be:

if (unlikely(bad_pmem))
pmem_clear_poison(pmem, pmem_off, len);
memcpy_to_pmem(pmem_addr, mem + off, len);