Skip to content

Commit 2d6c8cf

Browse files
piorkovgregkh
authored andcommitted
drm/xe: Move ASID allocation and user PT BO tracking into xe_vm_create
[ Upstream commit 8a30114 ] 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 <matthew.auld@intel.com> Signed-off-by: Piotr Piórkowski <piotr.piorkowski@intel.com> Reviewed-by: Matthew Auld <matthew.auld@intel.com> Link: https://lore.kernel.org/r/20250811104358.2064150-3-piotr.piorkowski@intel.com Signed-off-by: Michał Winiarski <michal.winiarski@intel.com> (cherry picked from commit 30e0c3f) Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com> [Rodrigo: Added fixes tag] Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent b32e159 commit 2d6c8cf

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
@@ -1767,6 +1767,20 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags, struct xe_file *xef)
17671767
if (number_tiles > 1)
17681768
vm->composite_fence_ctx = dma_fence_context_alloc(1);
17691769

1770+
if (xef && xe->info.has_asid) {
1771+
u32 asid;
1772+
1773+
down_write(&xe->usm.lock);
1774+
err = xa_alloc_cyclic(&xe->usm.asid_to_vm, &asid, vm,
1775+
XA_LIMIT(1, XE_MAX_ASID - 1),
1776+
&xe->usm.next_asid, GFP_KERNEL);
1777+
up_write(&xe->usm.lock);
1778+
if (err < 0)
1779+
goto err_unlock_close;
1780+
1781+
vm->usm.asid = asid;
1782+
}
1783+
17701784
trace_xe_vm_create(vm);
17711785

17721786
return vm;
@@ -2034,9 +2048,8 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,
20342048
struct xe_device *xe = to_xe_device(dev);
20352049
struct xe_file *xef = to_xe_file(file);
20362050
struct drm_xe_vm_create *args = data;
2037-
struct xe_tile *tile;
20382051
struct xe_vm *vm;
2039-
u32 id, asid;
2052+
u32 id;
20402053
int err;
20412054
u32 flags = 0;
20422055

@@ -2076,23 +2089,6 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,
20762089
if (IS_ERR(vm))
20772090
return PTR_ERR(vm);
20782091

2079-
if (xe->info.has_asid) {
2080-
down_write(&xe->usm.lock);
2081-
err = xa_alloc_cyclic(&xe->usm.asid_to_vm, &asid, vm,
2082-
XA_LIMIT(1, XE_MAX_ASID - 1),
2083-
&xe->usm.next_asid, GFP_KERNEL);
2084-
up_write(&xe->usm.lock);
2085-
if (err < 0)
2086-
goto err_close_and_put;
2087-
2088-
vm->usm.asid = asid;
2089-
}
2090-
2091-
/* Record BO memory for VM pagetable created against client */
2092-
for_each_tile(tile, xe, id)
2093-
if (vm->pt_root[id])
2094-
xe_drm_client_add_bo(vm->xef->client, vm->pt_root[id]->bo);
2095-
20962092
#if IS_ENABLED(CONFIG_DRM_XE_DEBUG_MEM)
20972093
/* Warning: Security issue - never enable by default */
20982094
args->reserved[0] = xe_bo_main_addr(vm->pt_root[0]->bo, XE_PAGE_SIZE);

0 commit comments

Comments
 (0)