Skip to content

Commit d5b6f0c

Browse files
piorkovgregkh
authored andcommitted
drm/xe: Assign ioctl xe file handler to vm in xe_vm_create
[ Upstream commit 658a1c8 ] In several code paths, such as xe_pt_create(), the vm->xef field is used to determine whether a VM originates from userspace or the kernel. Previously, this handler was only assigned in xe_vm_create_ioctl(), after the VM was created by xe_vm_create(). However, xe_vm_create() triggers page table creation, and that function assumes vm->xef should be already set. This could lead to incorrect origin detection. To fix this problem and ensure consistency in the initialization of the VM object, let's move the assignment of this handler to xe_vm_create. v2: - take reference to the xe file object only when xef is not NULL - release the reference to the xe file object on the error path (Matthew) Fixes: 7f387e6 ("drm/xe: add XE_BO_FLAG_PINNED_LATE_RESTORE") Signed-off-by: Piotr Piórkowski <piotr.piorkowski@intel.com> Cc: Matthew Auld <matthew.auld@intel.com> Reviewed-by: Matthew Auld <matthew.auld@intel.com> Link: https://lore.kernel.org/r/20250811104358.2064150-2-piotr.piorkowski@intel.com Signed-off-by: Michał Winiarski <michal.winiarski@intel.com> (cherry picked from commit 9337166) Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 6efb026 commit d5b6f0c

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

drivers/gpu/drm/xe/xe_migrate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ struct xe_migrate *xe_migrate_init(struct xe_tile *tile)
408408

409409
/* Special layout, prepared below.. */
410410
vm = xe_vm_create(xe, XE_VM_FLAG_MIGRATION |
411-
XE_VM_FLAG_SET_TILE_ID(tile));
411+
XE_VM_FLAG_SET_TILE_ID(tile), NULL);
412412
if (IS_ERR(vm))
413413
return ERR_CAST(vm);
414414

drivers/gpu/drm/xe/xe_pxp_submit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static int allocate_gsc_client_resources(struct xe_gt *gt,
101101
xe_assert(xe, hwe);
102102

103103
/* PXP instructions must be issued from PPGTT */
104-
vm = xe_vm_create(xe, XE_VM_FLAG_GSC);
104+
vm = xe_vm_create(xe, XE_VM_FLAG_GSC, NULL);
105105
if (IS_ERR(vm))
106106
return PTR_ERR(vm);
107107

drivers/gpu/drm/xe/xe_vm.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,7 +1612,7 @@ static void xe_vm_free_scratch(struct xe_vm *vm)
16121612
}
16131613
}
16141614

1615-
struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)
1615+
struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags, struct xe_file *xef)
16161616
{
16171617
struct drm_gem_object *vm_resv_obj;
16181618
struct xe_vm *vm;
@@ -1633,9 +1633,10 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)
16331633
vm->xe = xe;
16341634

16351635
vm->size = 1ull << xe->info.va_bits;
1636-
16371636
vm->flags = flags;
16381637

1638+
if (xef)
1639+
vm->xef = xe_file_get(xef);
16391640
/**
16401641
* GSC VMs are kernel-owned, only used for PXP ops and can sometimes be
16411642
* manipulated under the PXP mutex. However, the PXP mutex can be taken
@@ -1786,6 +1787,8 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)
17861787
for_each_tile(tile, xe, id)
17871788
xe_range_fence_tree_fini(&vm->rftree[id]);
17881789
ttm_lru_bulk_move_fini(&xe->ttm, &vm->lru_bulk_move);
1790+
if (vm->xef)
1791+
xe_file_put(vm->xef);
17891792
kfree(vm);
17901793
if (flags & XE_VM_FLAG_LR_MODE)
17911794
xe_pm_runtime_put(xe);
@@ -2069,7 +2072,7 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,
20692072
if (args->flags & DRM_XE_VM_CREATE_FLAG_FAULT_MODE)
20702073
flags |= XE_VM_FLAG_FAULT_MODE;
20712074

2072-
vm = xe_vm_create(xe, flags);
2075+
vm = xe_vm_create(xe, flags, xef);
20732076
if (IS_ERR(vm))
20742077
return PTR_ERR(vm);
20752078

@@ -2085,8 +2088,6 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,
20852088
vm->usm.asid = asid;
20862089
}
20872090

2088-
vm->xef = xe_file_get(xef);
2089-
20902091
/* Record BO memory for VM pagetable created against client */
20912092
for_each_tile(tile, xe, id)
20922093
if (vm->pt_root[id])

drivers/gpu/drm/xe/xe_vm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct xe_sync_entry;
2626
struct xe_svm_range;
2727
struct drm_exec;
2828

29-
struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags);
29+
struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags, struct xe_file *xef);
3030

3131
struct xe_vm *xe_vm_lookup(struct xe_file *xef, u32 id);
3232
int xe_vma_cmp_vma_cb(const void *key, const struct rb_node *node);

0 commit comments

Comments
 (0)