Skip to content

Commit 3dd859c

Browse files
piorkovwangjinchao
authored andcommitted
drm/xe: Move ASID allocation and user PT BO tracking into xe_vm_create
Currently, ASID assignment for user VMs and page-table BO accounting for client memory tracking are performed in xe_vm_create_ioctl. To consolidate VM object initialization, move this logic to xe_vm_create. v2: - removed unnecessary duplicate BO tracking code - using the local variable xef to verify whether the VM is being created by userspace Fixes: 658a1c8 ("drm/xe: Assign ioctl xe file handler to vm in xe_vm_create") Suggested-by: Matthew Auld <[email protected]> Signed-off-by: Piotr Piórkowski <[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 30e0c3f) Signed-off-by: Rodrigo Vivi <[email protected]> [Rodrigo: Added fixes tag]
1 parent 9786613 commit 3dd859c

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

drivers/gpu/drm/xe/xe_vm.c

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,6 +1795,20 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags, struct xe_file *xef)
17951795
if (number_tiles > 1)
17961796
vm->composite_fence_ctx = dma_fence_context_alloc(1);
17971797

1798+
if (xef && xe->info.has_asid) {
1799+
u32 asid;
1800+
1801+
down_write(&xe->usm.lock);
1802+
err = xa_alloc_cyclic(&xe->usm.asid_to_vm, &asid, vm,
1803+
XA_LIMIT(1, XE_MAX_ASID - 1),
1804+
&xe->usm.next_asid, GFP_KERNEL);
1805+
up_write(&xe->usm.lock);
1806+
if (err < 0)
1807+
goto err_unlock_close;
1808+
1809+
vm->usm.asid = asid;
1810+
}
1811+
17981812
trace_xe_vm_create(vm);
17991813

18001814
return vm;
@@ -2062,9 +2076,8 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,
20622076
struct xe_device *xe = to_xe_device(dev);
20632077
struct xe_file *xef = to_xe_file(file);
20642078
struct drm_xe_vm_create *args = data;
2065-
struct xe_tile *tile;
20662079
struct xe_vm *vm;
2067-
u32 id, asid;
2080+
u32 id;
20682081
int err;
20692082
u32 flags = 0;
20702083

@@ -2104,23 +2117,6 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,
21042117
if (IS_ERR(vm))
21052118
return PTR_ERR(vm);
21062119

2107-
if (xe->info.has_asid) {
2108-
down_write(&xe->usm.lock);
2109-
err = xa_alloc_cyclic(&xe->usm.asid_to_vm, &asid, vm,
2110-
XA_LIMIT(1, XE_MAX_ASID - 1),
2111-
&xe->usm.next_asid, GFP_KERNEL);
2112-
up_write(&xe->usm.lock);
2113-
if (err < 0)
2114-
goto err_close_and_put;
2115-
2116-
vm->usm.asid = asid;
2117-
}
2118-
2119-
/* Record BO memory for VM pagetable created against client */
2120-
for_each_tile(tile, xe, id)
2121-
if (vm->pt_root[id])
2122-
xe_drm_client_add_bo(vm->xef->client, vm->pt_root[id]->bo);
2123-
21242120
#if IS_ENABLED(CONFIG_DRM_XE_DEBUG_MEM)
21252121
/* Warning: Security issue - never enable by default */
21262122
args->reserved[0] = xe_bo_main_addr(vm->pt_root[0]->bo, XE_PAGE_SIZE);

0 commit comments

Comments
 (0)