Re: [PATCH v3 06/25] drm/xe: Add XE_BO_FLAG_PUT_VM_ASYNC

Matthew Brost
2026-04-01T22:38:18Z

On Wed, Apr 01, 2026 at 02:22:09PM +0200, Francois Dugast wrote:
> On Fri, Feb 27, 2026 at 05:34:42PM -0800, Matthew Brost wrote:
> > Add XE_BO_FLAG_PUT_VM_ASYNC, which indicates that an async BO put must
> > also drop an additional reference to the BO’s VM. This is useful when a
> > kernel BO, one that does not normally hold a VM reference, needs to be
> > put asynchronously, ensuring the shared dma-resv object does not
> > disappear before the BO.
> >
> > Signed-off-by: Matthew Brost <matthew.brost@intel.com>
> > ---
> > drivers/gpu/drm/xe/xe_bo.c | 8 +++++++-
> > drivers/gpu/drm/xe/xe_bo.h | 1 +
> > 2 files changed, 8 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
> > index 8ff193600443..d4c8ef8ff2c3 100644
> > --- a/drivers/gpu/drm/xe/xe_bo.c
> > +++ b/drivers/gpu/drm/xe/xe_bo.c
> > @@ -3567,8 +3567,14 @@ void xe_bo_put_commit(struct llist_head *deferred)
> > if (!freed)
> > return;
> >
> > - llist_for_each_entry_safe(bo, next, freed, freed)
> > + llist_for_each_entry_safe(bo, next, freed, freed) {
> > + struct xe_vm *vm = bo->vm;
> > + bool async = bo->flags & XE_BO_FLAG_PUT_VM_ASYNC;
> > +
> > drm_gem_object_free(&bo->ttm.base.refcount);
> > + if (async)
> > + xe_vm_put(vm);
> > + }
> > }
> >
> > static void xe_bo_dev_work_func(struct work_struct *work)
> > diff --git a/drivers/gpu/drm/xe/xe_bo.h b/drivers/gpu/drm/xe/xe_bo.h
> > index bf284ed47325..14be9c1bb09d 100644
> > --- a/drivers/gpu/drm/xe/xe_bo.h
> > +++ b/drivers/gpu/drm/xe/xe_bo.h
> > @@ -52,6 +52,7 @@
> > #define XE_BO_FLAG_CPU_ADDR_MIRROR BIT(24)
> > #define XE_BO_FLAG_FORCE_USER_VRAM BIT(25)
> > #define XE_BO_FLAG_NO_COMPRESSION BIT(26)
> > +#define XE_BO_FLAG_PUT_VM_ASYNC BIT(27)
>
> If I understand correctly, this flag should only be used in the deferred
> path, which is why it is ignored in the non-deferred path. Maybe it would
> be good to add an assert there to make sure we are not mistakenly leaking
> a VM reference.
>

I think we'd have to clear the flag here then too as we still get into
xe_gem_object_free + xe_ttm_bo_destroy eventually just not in the
naturnal ref counted way...

But that is probably a good idea though to make sure we don't screw this
up.

Matt

> Francois
>
> >
> > /* this one is trigger internally only */
> > #define XE_BO_FLAG_INTERNAL_TEST BIT(30)
> > --
> > 2.34.1
> >