Thread (92 messages) 92 messages, 15 authors, 2020-11-10

Re: [PATCH RFC PKS/PMEM 57/58] nvdimm/pmem: Stray access protection for pmem->virt_addr

From: John Hubbard <jhubbard@nvidia.com>
Date: 2020-10-10 03:16:50
Also in: amd-gfx, bpf, ceph-devel, dri-devel, intel-gfx, intel-wired-lan, io-uring, kexec, kvm, linux-bcache, linux-block, linux-btrfs, linux-cifs, linux-doc, linux-efi, linux-ext4, linux-f2fs-devel, linux-fsdevel, linux-kselftest, linux-mm, linux-mmc, linux-nfs, linux-rdma, linux-scsi, linux-um, lkml, netdev, nvdimm, target-devel, xen-devel

On 10/9/20 12:50 PM, ira.weiny@intel.com wrote:
quoted hunk ↗ jump to hunk
From: Ira Weiny <ira.weiny@intel.com>

The pmem driver uses a cached virtual address to access its memory
directly.  Because the nvdimm driver is well aware of the special
protections it has mapped memory with, we call dev_access_[en|dis]able()
around the direct pmem->virt_addr (pmem_addr) usage instead of the
unnecessary overhead of trying to get a page to kmap.

Signed-off-by: Ira Weiny <ira.weiny@intel.com>
---
  drivers/nvdimm/pmem.c | 4 ++++
  1 file changed, 4 insertions(+)
diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c
index fab29b514372..e4dc1ae990fc 100644
--- a/drivers/nvdimm/pmem.c
+++ b/drivers/nvdimm/pmem.c
@@ -148,7 +148,9 @@ static blk_status_t pmem_do_read(struct pmem_device *pmem,
  	if (unlikely(is_bad_pmem(&pmem->bb, sector, len)))
  		return BLK_STS_IOERR;
  
+	dev_access_enable(false);
  	rc = read_pmem(page, page_off, pmem_addr, len);
+	dev_access_disable(false);
Hi Ira!

The APIs should be tweaked to use a symbol (GLOBAL, PER_THREAD), instead of
true/false. Try reading the above and you'll see that it sounds like it's
doing the opposite of what it is ("enable_this(false)" sounds like a clumsy
API design to *disable*, right?). And there is no hint about the scope.

And it *could* be so much more readable like this:

     dev_access_enable(DEV_ACCESS_THIS_THREAD);



thanks,
-- 
John Hubbard
NVIDIA
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help