Skip to content

Commit 9786613

Browse files
piorkovwangjinchao
authored andcommitted
drm/xe: Assign ioctl xe file handler to vm in xe_vm_create
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 <[email protected]> Cc: Matthew Auld <[email protected]> Reviewed-by: Matthew Auld <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Michał Winiarski <[email protected]> (cherry picked from commit 9337166) Signed-off-by: Rodrigo Vivi <[email protected]>
1 parent df068e8 commit 9786613

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
@@ -1640,7 +1640,7 @@ static void xe_vm_free_scratch(struct xe_vm *vm)
16401640
}
16411641
}
16421642

1643-
struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)
1643+
struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags, struct xe_file *xef)
16441644
{
16451645
struct drm_gem_object *vm_resv_obj;
16461646
struct xe_vm *vm;
@@ -1661,9 +1661,10 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)
16611661
vm->xe = xe;
16621662

16631663
vm->size = 1ull << xe->info.va_bits;
1664-
16651664
vm->flags = flags;
16661665

1666+
if (xef)
1667+
vm->xef = xe_file_get(xef);
16671668
/**
16681669
* GSC VMs are kernel-owned, only used for PXP ops and can sometimes be
16691670
* manipulated under the PXP mutex. However, the PXP mutex can be taken
@@ -1814,6 +1815,8 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)
18141815
for_each_tile(tile, xe, id)
18151816
xe_range_fence_tree_fini(&vm->rftree[id]);
18161817
ttm_lru_bulk_move_fini(&xe->ttm, &vm->lru_bulk_move);
1818+
if (vm->xef)
1819+
xe_file_put(vm->xef);
18171820
kfree(vm);
18181821
if (flags & XE_VM_FLAG_LR_MODE)
18191822
xe_pm_runtime_put(xe);
@@ -2097,7 +2100,7 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,
20972100
if (args->flags & DRM_XE_VM_CREATE_FLAG_FAULT_MODE)
20982101
flags |= XE_VM_FLAG_FAULT_MODE;
20992102

2100-
vm = xe_vm_create(xe, flags);
2103+
vm = xe_vm_create(xe, flags, xef);
21012104
if (IS_ERR(vm))
21022105
return PTR_ERR(vm);
21032106

@@ -2113,8 +2116,6 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,
21132116
vm->usm.asid = asid;
21142117
}
21152118

2116-
vm->xef = xe_file_get(xef);
2117-
21182119
/* Record BO memory for VM pagetable created against client */
21192120
for_each_tile(tile, xe, id)
21202121
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)