John Groves wrote:
> From: John Groves <[email protected]>
> 
> fsdev: Add dax_operations for use by famfs
> 
> - These methods are based on pmem_dax_ops from drivers/nvdimm/pmem.c
> - fsdev_dax_direct_access() returns the hpa, pfn and kva. The kva was
>   newly stored as dev_dax->virt_addr by dev_dax_probe().
> - The hpa/pfn are used for mmap (dax_iomap_fault()), and the kva is used
>   for read/write (dax_iomap_rw())
> - fsdev_dax_recovery_write() and dev_dax_zero_page_range() have not been
>   tested yet. I'm looking for suggestions as to how to test those.
> - dax-private.h: add dev_dax->cached_size, which fsdev needs to
>   remember. The dev_dax size cannot change while a driver is bound
>   (dev_dax_resize returns -EBUSY if dev->driver is set). Caching the size
>   at probe time allows fsdev's direct_access path can use it without
>   acquiring dax_dev_rwsem (which isn't exported anyway).
> 
> Signed-off-by: John Groves <[email protected]>

[snip]

> +
> +static long __fsdev_dax_direct_access(struct dax_device *dax_dev, pgoff_t 
> pgoff,
> +                     long nr_pages, enum dax_access_mode mode, void **kaddr,
> +                     unsigned long *pfn)
> +{
> +     struct dev_dax *dev_dax = dax_get_private(dax_dev);
> +     size_t size = nr_pages << PAGE_SHIFT;
> +     size_t offset = pgoff << PAGE_SHIFT;
> +     void *virt_addr = dev_dax->virt_addr + offset;
> +     phys_addr_t phys;
> +     unsigned long local_pfn;
> +
> +     WARN_ON(!dev_dax->virt_addr);

WARN_ON_ONCE.  But frankly I'm pretty sure this is impossible to hit given
the probe call, so best remove it.  Also yall already used dev_dax->virt_addr
above.  And will hand back a bad address to the caller.  So...

> +
> +     phys = dax_pgoff_to_phys(dev_dax, pgoff, nr_pages << PAGE_SHIFT);
> +     if (phys == -1) {
> +             dev_dbg(&dev_dax->dev,
> +                     "pgoff (%#lx) out of range\n", pgoff);
> +             return -ERANGE;

EFAULT?

Ira

[snip]

Reply via email to