mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wentao Liang <vulab@iscas.ac.cn>
To: Jani Nikula <jani.nikula@linux.intel.com>,
	Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
	Rodrigo Vivi <rodrigo.vivi@intel.com>,
	Tvrtko Ursulin <tursulin@ursulin.net>
Cc: David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
	Andi Shyti <andi.shyti@linux.intel.com>,
	Matthew D Roper <matthew.d.roper@intel.com>,
	Sujaritha Sundaresan <sujaritha.sundaresan@intel.com>,
	intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH v2] drm/i915/selftests: Release GT VM reference on mock device teardown
Date: Sat, 07 Nov 2026 17:10:00 +0000	[thread overview]
Message-ID: <1794071400.2684480.vulab@iscas.ac.cn> (raw)
In-Reply-To: <178962823827.28653.5098493516220452854@jlahtine-mobl>

mock_gem_device() takes an additional reference to the GGTT VM when
initializing gt->vm. However, the mock device cleanup does not release
this reference, either during normal teardown or when initialization
fails.

The regular i915 driver releases gt->vm through
intel_gt_driver_release(), but the mock device does not use that
teardown path. As a result, the additional VM reference can remain
held after the mock device has been cleaned up.

Release the reference during normal teardown after draining the GEM
workqueue and before finalizing the mock GGTT. Also release it during
initialization error unwinding, before destroying the workqueues.

This change is limited to the mock device used by the i915 selftests
and does not affect normal driver operation.

The issue was identified through static analysis, with AI assistance
used to examine the finding and prepare the fix. The resulting change
was manually reviewed and build-tested with
CONFIG_DRM_I915_SELFTEST=y.

Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
Changes in v2:
- Remove the Fixes and Cc: stable tags, as this is a selftest-only
  cleanup rather than a fix requiring stable backporting.
- Correct the subject prefix to drm/i915/selftests.
- Adjust the error-path cleanup ordering so the VM reference is
  released before the workqueues are destroyed.
- Clarify the scope of the change and document the use of AI tools.

 drivers/gpu/drm/i915/selftests/mock_gem_device.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/gpu/drm/i915/selftests/mock_gem_device.c b/drivers/gpu/drm/i915/selftests/mock_gem_device.c
index 796c9b070e41..88cd83f28586 100644
--- a/drivers/gpu/drm/i915/selftests/mock_gem_device.c
+++ b/drivers/gpu/drm/i915/selftests/mock_gem_device.c
@@ -71,6 +71,7 @@ static void mock_device_release(struct drm_device *dev)
 
 	i915_gem_drain_workqueue(i915);
 
+	i915_vm_put(fetch_and_zero(&to_gt(i915)->vm));
 	mock_fini_ggtt(to_gt(i915)->ggtt);
 	destroy_workqueue(i915->unordered_wq);
 	destroy_workqueue(i915->wq);
@@ -145,6 +146,7 @@ struct drm_i915_private *mock_gem_device(void)
 #endif
 	struct drm_i915_private *i915;
 	struct intel_display *display;
+	struct i915_address_space *vm;
 	struct pci_dev *pdev;
 	int ret;
 
@@ -257,6 +259,9 @@ struct drm_i915_private *mock_gem_device(void)
 err_context:
 	intel_gt_driver_remove(to_gt(i915));
 err_unlock:
+	vm = fetch_and_zero(&to_gt(i915)->vm);
+	if (vm)
+		i915_vm_put(vm);
 	destroy_workqueue(i915->unordered_wq);
 err_wq:
 	destroy_workqueue(i915->wq);
-- 
2.34.1


      parent reply	other threads:[~2026-11-07 18:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16 17:19 [PATCH] drm/i915: Fix vm reference leak in mock_gem_device() Wentao Liang
2026-09-17  6:57 ` Joonas Lahtinen
2026-11-07 17:09   ` Wentao Liang
2026-11-07 19:30     ` Greg KH
2026-11-07 17:10   ` Wentao Liang [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=1794071400.2684480.vulab@iscas.ac.cn \
    --to=vulab@iscas.ac.cn \
    --cc=airlied@gmail.com \
    --cc=andi.shyti@linux.intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthew.d.roper@intel.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=simona@ffwll.ch \
    --cc=sujaritha.sundaresan@intel.com \
    --cc=tursulin@ursulin.net \
    /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

all inboxes | Powered by JetHome®