Re: [PATCH v3 03/11] drm/xe: Add xe_device_asid_to_vm helper

Matthew Brost
2026-01-13T01:36:20Z

On Mon, Jan 12, 2026 at 06:01:27PM -0700, Summers, Stuart wrote:
> On Mon, 2026-01-12 at 15:27 -0800, Matthew Brost wrote:
> > Introduce the xe_device_asid_to_vm helper, which can be used
> > throughout
> > the driver to resolve the VM from a given ASID.
> >
> > Signed-off-by: Matthew Brost <matthew.brost@intel.com>
> > Reviewed-by: Matt Atwood <matthew.s.atwood@intel.com>
> > ---
> >  drivers/gpu/drm/xe/xe_device.c | 25 +++++++++++++++++++++++++
> >  drivers/gpu/drm/xe/xe_device.h |  4 ++++
> >  2 files changed, 29 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/xe/xe_device.c
> > b/drivers/gpu/drm/xe/xe_device.c
> > index e400ad5c9f9e..445cf6da9dc7 100644
> > --- a/drivers/gpu/drm/xe/xe_device.c
> > +++ b/drivers/gpu/drm/xe/xe_device.c
> > @@ -1417,3 +1417,28 @@ const char *xe_wedged_mode_to_string(enum
> > xe_wedged_mode mode)
> >                 return "<invalid>";
> >         }
> >  }
> > +
> > +/**
> > + * xe_device_asid_to_vm() - Find VM from ASID
> > + * @xe: the &xe_device
> > + * @asid: Address space ID
> > + *
> > + * Find a VM from ASID and take a reference to VM which caller must
> > drop.
> > + * Reclaim safe.
> > + *
> > + * Return: VM on success, ERR_PTR on failure
> > + */
> > +struct xe_vm *xe_device_asid_to_vm(struct xe_device *xe, u32 asid)
> > +{
> > +       struct xe_vm *vm;
> > +
> > +       down_read(&xe->usm.lock);
> > +       vm = xa_load(&xe->usm.asid_to_vm, asid);
> > +       if (vm)
> > +               xe_vm_get(vm);
> > +       else
> > +               vm = ERR_PTR(-EINVAL);
> > +       up_read(&xe->usm.lock);
> > +
> > +       return vm;
> > +}
> > diff --git a/drivers/gpu/drm/xe/xe_device.h
> > b/drivers/gpu/drm/xe/xe_device.h
> > index 3740143790db..10d04c324257 100644
> > --- a/drivers/gpu/drm/xe/xe_device.h
> > +++ b/drivers/gpu/drm/xe/xe_device.h
> > @@ -6,6 +6,8 @@
> >  #ifndef _XE_DEVICE_H_
> >  #define _XE_DEVICE_H_
> >
> > +struct xe_vm;
>
> Can you move this down below the include statements below?
>

Yes, will do.

Matt

> Otherwise:
> Reviewed-by: Stuart Summers <stuart.summers@intel.com>
>
> Thanks,
> Stuart
>
> > +
> >  #include <drm/drm_util.h>
> >
> >  #include "xe_device_types.h"
> > @@ -204,6 +206,8 @@ int xe_is_injection_active(void);
> >
> >  bool xe_is_xe_file(const struct file *file);
> >
> > +struct xe_vm *xe_device_asid_to_vm(struct xe_device *xe, u32 asid);
> > +
> >  /*
> >   * Occasionally it is seen that the G2H worker starts running after
> > a delay of more than
> >   * a second even after being queued and activated by the Linux
> > workqueue subsystem. This
>