Re: [PATCH v3 02/13] device/dax: update devdax to use mmap_prepare

Lorenzo Stoakes
2025-09-17T13:55:26Z

On Wed, Sep 17, 2025 at 11:37:07AM +0100, Pedro Falcato wrote:
> On Tue, Sep 16, 2025 at 03:11:48PM +0100, Lorenzo Stoakes wrote:
> > The devdax driver does nothing special in its f_op->mmap hook, so
> > straightforwardly update it to use the mmap_prepare hook instead.
> >
> > Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
> > Acked-by: David Hildenbrand <david@redhat.com>
> > Reviewed-by: Jan Kara <jack@suse.cz>
>
> Acked-by: Pedro Falcato <pfalcato@suse.de>

Thanks!

>
> > ---
> > drivers/dax/device.c | 32 +++++++++++++++++++++-----------
> > 1 file changed, 21 insertions(+), 11 deletions(-)
> >
> > diff --git a/drivers/dax/device.c b/drivers/dax/device.c
> > index 2bb40a6060af..c2181439f925 100644
> > --- a/drivers/dax/device.c
> > +++ b/drivers/dax/device.c
> > @@ -13,8 +13,9 @@
> > #include "dax-private.h"
> > #include "bus.h"
> >
> > -static int check_vma(struct dev_dax *dev_dax, struct vm_area_struct *vma,
> > - const char *func)
> > +static int __check_vma(struct dev_dax *dev_dax, vm_flags_t vm_flags,
> > + unsigned long start, unsigned long end, struct file *file,
> > + const char *func)
> > {
> > struct device *dev = &dev_dax->dev;
> > unsigned long mask;
> > @@ -23,7 +24,7 @@ static int check_vma(struct dev_dax *dev_dax, struct vm_area_struct *vma,
> > return -ENXIO;
> >
> > /* prevent private mappings from being established */
> > - if ((vma->vm_flags & VM_MAYSHARE) != VM_MAYSHARE) {
> > + if ((vm_flags & VM_MAYSHARE) != VM_MAYSHARE) {
> > dev_info_ratelimited(dev,
> > "%s: %s: fail, attempted private mapping\n",
> > current->comm, func);
> > @@ -31,15 +32,15 @@ static int check_vma(struct dev_dax *dev_dax, struct vm_area_struct *vma,
> > }
> >
> > mask = dev_dax->align - 1;
> > - if (vma->vm_start & mask || vma->vm_end & mask) {
> > + if (start & mask || end & mask) {
> > dev_info_ratelimited(dev,
> > "%s: %s: fail, unaligned vma (%#lx - %#lx, %#lx)\n",
> > - current->comm, func, vma->vm_start, vma->vm_end,
> > + current->comm, func, start, end,
> > mask);
> > return -EINVAL;
> > }
> >
> > - if (!vma_is_dax(vma)) {
> > + if (!file_is_dax(file)) {
> > dev_info_ratelimited(dev,
> > "%s: %s: fail, vma is not DAX capable\n",
> > current->comm, func);
> > @@ -49,6 +50,13 @@ static int check_vma(struct dev_dax *dev_dax, struct vm_area_struct *vma,
> > return 0;
> > }
> >
> > +static int check_vma(struct dev_dax *dev_dax, struct vm_area_struct *vma,
> > + const char *func)
> > +{
> > + return __check_vma(dev_dax, vma->vm_flags, vma->vm_start, vma->vm_end,
> > + vma->vm_file, func);
> > +}
> > +
>
> Side comment: I'm no DAX expert at all, but this check_vma() thing looks... smelly?
> Besides the !dax_alive() check, I don't see the need to recheck vma limits at
> every ->huge_fault() call. Even taking mremap() into account,
> ->get_unmapped_area() should Do The Right Thing, no?

Let's keep this out of the series though please, am only humbly converting ->
mmap_prepare, this series isn't about solving the problems of every mmap caller
:)

>
> --
> Pedro

Thanks, Lorenzo