Re: [PATCH V9 5/8] dax: Add dax_operations for use by fs-dax on fsdev dax

From: Jonathan Cameron

Date: Tue Mar 24 2026 - 10:52:43 EST


On Tue, 24 Mar 2026 00:39:04 +0000
John Groves <john@xxxxxxxxxxxxxx> wrote:

> From: John Groves <John@xxxxxxxxxx>
>
> fsdev: Add dax_operations for use by famfs.
>
> This replicates the functionality from drivers/nvdimm/pmem.c that
> conventional fs-dax file systems (e.g. xfs) use to support dax
> read/write/mmap to a daxdev - without which famfs can't sit atop a
> daxdev.
>
> - 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 <john@xxxxxxxxxx>
The indent of trailing parameter lines is very random in here.
Pick a style and stick to it. Few other trivial things inline.

Reviewed-by: Jonathan Cameron <jonathan.cameron@xxxxxxxxxx>


> ---
> drivers/dax/dax-private.h | 1 +
> drivers/dax/fsdev.c | 84 +++++++++++++++++++++++++++++++++++++++
> 2 files changed, 85 insertions(+)

> diff --git a/drivers/dax/fsdev.c b/drivers/dax/fsdev.c
> index c75478d3d548..be3d2b0e8418 100644
> --- a/drivers/dax/fsdev.c
> +++ b/drivers/dax/fsdev.c

> +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;
> +
> + 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 -EFAULT;
> + }
> +
> + if (kaddr)
> + *kaddr = virt_addr;
> +
> + local_pfn = PHYS_PFN(phys);
Trivial but if !pfn, local_pfn not used so...

if (pfn)
*pfn = PHYS_PFN(phys);

Obviously ignore this if it becomes used in some later patch.

> + if (pfn)
> + *pfn = local_pfn;
> +
> + /*
> + * Use cached_size which was computed at probe time. The size cannot
> + * change while the driver is bound (resize returns -EBUSY).
Might be worth capturing somewhere in code that using the value from
probe means you don't need locking.
> + */
> + return PHYS_PFN(min(size, dev_dax->cached_size - offset));
> +}
> +
> +static int fsdev_dax_zero_page_range(struct dax_device *dax_dev,
> + pgoff_t pgoff, size_t nr_pages)
Three tabs
> +{
> + void *kaddr;
> +
> + WARN_ONCE(nr_pages > 1, "%s: nr_pages > 1\n", __func__);
> + __fsdev_dax_direct_access(dax_dev, pgoff, 1, DAX_ACCESS, &kaddr, NULL);
> + fsdev_write_dax(kaddr, ZERO_PAGE(0), 0, PAGE_SIZE);
> + return 0;
> +}
> +
> +static long fsdev_dax_direct_access(struct dax_device *dax_dev,
> + pgoff_t pgoff, long nr_pages, enum dax_access_mode mode,

Why that indent? Two tabs and a couple of spaces...
Either two tabs, or align after (

> + void **kaddr, unsigned long *pfn)
> +{
> + return __fsdev_dax_direct_access(dax_dev, pgoff, nr_pages, mode,
> + kaddr, pfn);
> +}
> +
> +static size_t fsdev_dax_recovery_write(struct dax_device *dax_dev, pgoff_t pgoff,
> + void *addr, size_t bytes, struct iov_iter *i)
two tabs....
> +{
> + return _copy_from_iter_flushcache(addr, bytes, i);
> +}
> +
> +static const struct dax_operations dev_dax_ops = {
> + .direct_access = fsdev_dax_direct_access,
> + .zero_page_range = fsdev_dax_zero_page_range,
> + .recovery_write = fsdev_dax_recovery_write,
> +};