Skip to content

Commit 52c8b6e

Browse files
committed
Merge tag 'drm-xe-fixes-2024-04-18' of https://gitlab.freedesktop.org/drm/xe/kernel into drm-fixes
- Fix bo leak on error path during fb init - Fix use-after-free due to order vm is put and destroyed Signed-off-by: Dave Airlie <[email protected]> From: Lucas De Marchi <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/xjguifyantaibyrnymuiotxws6akiexi6r7tqyieqxgquovubc@kkrtbe24hjjr
2 parents 5493bf2 + ca7c52a commit 52c8b6e

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

drivers/gpu/drm/xe/display/intel_fb_bo.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ int intel_fb_bo_framebuffer_init(struct intel_framebuffer *intel_fb,
3131

3232
ret = ttm_bo_reserve(&bo->ttm, true, false, NULL);
3333
if (ret)
34-
return ret;
34+
goto err;
3535

3636
if (!(bo->flags & XE_BO_SCANOUT_BIT)) {
3737
/*
@@ -42,12 +42,16 @@ int intel_fb_bo_framebuffer_init(struct intel_framebuffer *intel_fb,
4242
*/
4343
if (XE_IOCTL_DBG(i915, !list_empty(&bo->ttm.base.gpuva.list))) {
4444
ttm_bo_unreserve(&bo->ttm);
45-
return -EINVAL;
45+
ret = -EINVAL;
46+
goto err;
4647
}
4748
bo->flags |= XE_BO_SCANOUT_BIT;
4849
}
4950
ttm_bo_unreserve(&bo->ttm);
51+
return 0;
5052

53+
err:
54+
xe_bo_put(bo);
5155
return ret;
5256
}
5357

drivers/gpu/drm/xe/xe_vm.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,16 @@ void xe_vm_close_and_put(struct xe_vm *vm)
15771577
xe->usm.num_vm_in_fault_mode--;
15781578
else if (!(vm->flags & XE_VM_FLAG_MIGRATION))
15791579
xe->usm.num_vm_in_non_fault_mode--;
1580+
1581+
if (vm->usm.asid) {
1582+
void *lookup;
1583+
1584+
xe_assert(xe, xe->info.has_asid);
1585+
xe_assert(xe, !(vm->flags & XE_VM_FLAG_MIGRATION));
1586+
1587+
lookup = xa_erase(&xe->usm.asid_to_vm, vm->usm.asid);
1588+
xe_assert(xe, lookup == vm);
1589+
}
15801590
mutex_unlock(&xe->usm.lock);
15811591

15821592
for_each_tile(tile, xe, id)
@@ -1592,24 +1602,15 @@ static void vm_destroy_work_func(struct work_struct *w)
15921602
struct xe_device *xe = vm->xe;
15931603
struct xe_tile *tile;
15941604
u8 id;
1595-
void *lookup;
15961605

15971606
/* xe_vm_close_and_put was not called? */
15981607
xe_assert(xe, !vm->size);
15991608

16001609
mutex_destroy(&vm->snap_mutex);
16011610

1602-
if (!(vm->flags & XE_VM_FLAG_MIGRATION)) {
1611+
if (!(vm->flags & XE_VM_FLAG_MIGRATION))
16031612
xe_device_mem_access_put(xe);
16041613

1605-
if (xe->info.has_asid && vm->usm.asid) {
1606-
mutex_lock(&xe->usm.lock);
1607-
lookup = xa_erase(&xe->usm.asid_to_vm, vm->usm.asid);
1608-
xe_assert(xe, lookup == vm);
1609-
mutex_unlock(&xe->usm.lock);
1610-
}
1611-
}
1612-
16131614
for_each_tile(tile, xe, id)
16141615
XE_WARN_ON(vm->pt_root[id]);
16151616

0 commit comments

Comments
 (0)