* [PATCH 1/2] drm/i915/gvt: Fix potential GGTT leak on scratch tree failure
2026-12-04 13:31 [PATCH 0/2] drm-i915: Fix resource lifetime and error-unwind issues Tian Xuechen
@ 2026-12-04 13:31 ` Tian Xuechen
2026-12-04 13:49 ` sashiko-bot
2026-12-04 13:31 ` [PATCH 2/2] drm/i915/selftests: Fix potential instance ID leak Tian Xuechen
1 sibling, 1 reply; 4+ messages in thread
From: Tian Xuechen @ 2026-12-04 13:31 UTC (permalink / raw)
To: zhenyuw.linux
Cc: zhi.wang.linux, jani.nikula, joonas.lahtinen, rodrigo.vivi,
tursulin, airlied, simona, ping.a.gao, intel-gfx, dri-devel,
linux-kernel, matthew.auld, thomas.hellstrom
GGTT allocation precedes scratch page-tree creation. If the latter fails,
its local unwind releases only scratch pages, and the outer vGPU unwind
skips GTT cleanup because initialization did not succeed.
Drop the newly created GGTT and clear its pointer on this failure.
This issue was found by our static analysis tool under development.
Fixes: 3b6411c2c205 ("drm/i915/gvt: implement scratch page table tree for shadow PPGTT")
Signed-off-by: Tian Xuechen <202300460064@mail.sdu.edu.cn>
---
drivers/gpu/drm/i915/gvt/gtt.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/i915/gvt/gtt.c b/drivers/gpu/drm/i915/gvt/gtt.c
index 5056a5887b31..17d61548ec05 100644
--- a/drivers/gpu/drm/i915/gvt/gtt.c
+++ b/drivers/gpu/drm/i915/gvt/gtt.c
@@ -2403,6 +2403,7 @@ static int create_scratch_page_tree(struct intel_vgpu *vgpu)
int intel_vgpu_init_gtt(struct intel_vgpu *vgpu)
{
struct intel_vgpu_gtt *gtt = &vgpu->gtt;
+ int ret;
INIT_RADIX_TREE(>t->spt_tree, GFP_KERNEL);
@@ -2420,7 +2421,13 @@ int intel_vgpu_init_gtt(struct intel_vgpu *vgpu)
INIT_LIST_HEAD(>t->ggtt_mm->ggtt_mm.partial_pte_list);
- return create_scratch_page_tree(vgpu);
+ ret = create_scratch_page_tree(vgpu);
+ if (ret) {
+ intel_vgpu_destroy_mm(gtt->ggtt_mm);
+ gtt->ggtt_mm = NULL;
+ }
+
+ return ret;
}
void intel_vgpu_destroy_all_ppgtt_mm(struct intel_vgpu *vgpu)
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 2/2] drm/i915/selftests: Fix potential instance ID leak
2026-12-04 13:31 [PATCH 0/2] drm-i915: Fix resource lifetime and error-unwind issues Tian Xuechen
2026-12-04 13:31 ` [PATCH 1/2] drm/i915/gvt: Fix potential GGTT leak on scratch tree failure Tian Xuechen
@ 2026-12-04 13:31 ` Tian Xuechen
1 sibling, 0 replies; 4+ messages in thread
From: Tian Xuechen @ 2026-12-04 13:31 UTC (permalink / raw)
To: zhenyuw.linux
Cc: zhi.wang.linux, jani.nikula, joonas.lahtinen, rodrigo.vivi,
tursulin, airlied, simona, ping.a.gao, intel-gfx, dri-devel,
linux-kernel, matthew.auld, thomas.hellstrom
mock_region_create() reserves an ID before creating the memory region.
Early construction failures do not call the release callback, leaking
that ID. Later memtest failures do call release, so unconditionally
freeing the ID again in the caller would double-free it.
Keep ID ownership in the caller during construction and transfer it to
the normal release callback only after successful creation.
This issue was found by our static analysis tool under development.
Fixes: d148738923fd ("drm/i915/ttm Initialize the ttm device and memory managers")
Signed-off-by: Tian Xuechen <202300460064@mail.sdu.edu.cn>
---
drivers/gpu/drm/i915/selftests/mock_region.c | 22 ++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/i915/selftests/mock_region.c b/drivers/gpu/drm/i915/selftests/mock_region.c
index 6324eb32d4dd..debc1ba29d40 100644
--- a/drivers/gpu/drm/i915/selftests/mock_region.c
+++ b/drivers/gpu/drm/i915/selftests/mock_region.c
@@ -102,6 +102,13 @@ static const struct intel_memory_region_ops mock_region_ops = {
.init_object = mock_object_init,
};
+/* Construction failures must leave the instance ID with the caller. */
+static const struct intel_memory_region_ops mock_region_create_ops = {
+ .init = intel_region_ttm_init,
+ .release = intel_region_ttm_fini,
+ .init_object = mock_object_init,
+};
+
struct intel_memory_region *
mock_region_create(struct drm_i915_private *i915,
resource_size_t start,
@@ -110,6 +117,7 @@ mock_region_create(struct drm_i915_private *i915,
resource_size_t io_start,
resource_size_t io_size)
{
+ struct intel_memory_region *mem;
int instance = ida_alloc_max(&i915->selftest.mock_region_instances,
TTM_NUM_MEM_TYPES - TTM_PL_PRIV - 1,
GFP_KERNEL);
@@ -117,8 +125,14 @@ mock_region_create(struct drm_i915_private *i915,
if (instance < 0)
return ERR_PTR(instance);
- return intel_memory_region_create(i915, start, size, min_page_size,
- io_start, io_size,
- INTEL_MEMORY_MOCK, instance,
- &mock_region_ops);
+ mem = intel_memory_region_create(i915, start, size, min_page_size,
+ io_start, io_size,
+ INTEL_MEMORY_MOCK, instance,
+ &mock_region_create_ops);
+ if (IS_ERR(mem))
+ ida_free(&i915->selftest.mock_region_instances, instance);
+ else
+ mem->ops = &mock_region_ops;
+
+ return mem;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread