Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sanjay Yadav" <sanjay.kumar.yadav@intel.com>,
	intel-xe@lists.freedesktop.org
Subject: Re: [PATCH v2] drm/xe/vm: Hold a device reference until VM teardown completes
Date: Mon, 23 Nov 2026 08:35:11 +0000	[thread overview]
Message-ID: <sashiko-outbox-228904@kernel.org> (raw)
In-Reply-To: <20261123081438.3640008-2-sanjay.kumar.yadav@intel.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/xe/vm: race in xe_vm_free() still lets drm_gpuvm_free()
  drop last dev ref
--

commit 80967a1a111f8536a1b5834e96436f633bdd34db
Author: Sanjay Yadav <sanjay.kumar.yadav@intel.com>

drm/xe/vm: Hold a device reference until VM teardown completes

This commit takes a drm_device reference in xe_vm_free(), queues
vm->destroy_work on xe_destroy_wq, and drops the device reference at the end
of vm_destroy_work_func().

> diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
> index dd855876f571c..bd589b1268eb9 100644
> --- a/drivers/gpu/drm/xe/xe_vm.c
> +++ b/drivers/gpu/drm/xe/xe_vm.c
> @@ -2109,6 +2109,9 @@ static void vm_destroy_work_func(struct work_struct *w)
>  		xe_file_put(vm->xef);
>  
>  	kfree(vm);
> +
> +	/* Pairs with xe_vm_free(), may run device teardown. */
> +	drm_dev_put(&xe->drm);
>  }
>  
>  static void xe_vm_free(struct drm_gpuvm *gpuvm)
> @@ -2116,11 +2119,12 @@ static void xe_vm_free(struct drm_gpuvm *gpuvm)
>  	struct xe_vm *vm = container_of(gpuvm, struct xe_vm, gpuvm);
>  
>  	/*
> -	 * To destroy the VM we need to be able to sleep.
> -	 * drm_gpuvm keeps at least one device reference at this
> -	 * point so xe->destroy_wq must still be alive.
> +	 * Destroy needs to sleep. Hold a device ref until it is done so a VM
> +	 * put can't drop the last one, and use xe_destroy_wq since
> +	 * xe->destroy_wq goes away with the device.
>  	 */
> -	queue_work(vm->xe->destroy_wq, &vm->destroy_work);
> +	drm_dev_get(&vm->xe->drm);
> +	xe_destroy_wq_queue(&vm->destroy_work);
>  }

[Severity: Medium]
Can drm_gpuvm_free() still drop the last drm_device reference in the
xe_vm_put() caller's context if vm_destroy_work_func() finishes first?

drm_gpuvm_free() drops its own drm_device reference after
gpuvm->ops->vm_free() returns:

drivers/gpu/drm/drm_gpuvm.c:drm_gpuvm_free() {
    ...
	gpuvm->ops->vm_free(gpuvm);
	drm_dev_put(drm);
}

Because xe_destroy_wq is unbound, a worker on another CPU can run
vm_destroy_work_func() to completion before the caller executes that trailing
drm_dev_put():

CPU0 (xe_bo_dev_work_func)        CPU1 (xe_destroy_wq)
drm_gpuvm_free()
  xe_vm_free()
    drm_dev_get(&vm->xe->drm)
    xe_destroy_wq_queue(...)
                                  vm_destroy_work_func()
                                    ...
                                    kfree(vm)
                                    drm_dev_put(&xe->drm)
  drm_dev_put(drm)
    ...
      xe_bo_dev_fini()
        flush_work(&bo_dev->async_free)
          <-- recursive flush deadlock

When the dying VM holds the last device reference, CPU1 drops the refcount
from 2 to 1 and CPU0 drops it from 1 to 0, running device teardown
synchronously in the caller (deadlocking in xe_bo_dev_fini() or freeing
xe_device underneath xe_ttm_bo_destroy()).

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123081438.3640008-2-sanjay.kumar.yadav@intel.com?part=1

      parent reply	other threads:[~2026-11-23  8:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23  8:14 [PATCH v2] drm/xe/vm: Hold a device reference until VM teardown completes Sanjay Yadav
2026-11-23  8:32 ` ✗ CI.KUnit: failure for " Patchwork
2026-11-23  8:35 ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-228904@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=sanjay.kumar.yadav@intel.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox