@@ -1640,7 +1640,7 @@ static void xe_vm_free_scratch(struct xe_vm *vm)
1640
1640
}
1641
1641
}
1642
1642
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 )
1644
1644
{
1645
1645
struct drm_gem_object * vm_resv_obj ;
1646
1646
struct xe_vm * vm ;
@@ -1661,9 +1661,10 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)
1661
1661
vm -> xe = xe ;
1662
1662
1663
1663
vm -> size = 1ull << xe -> info .va_bits ;
1664
-
1665
1664
vm -> flags = flags ;
1666
1665
1666
+ if (xef )
1667
+ vm -> xef = xe_file_get (xef );
1667
1668
/**
1668
1669
* GSC VMs are kernel-owned, only used for PXP ops and can sometimes be
1669
1670
* manipulated under the PXP mutex. However, the PXP mutex can be taken
@@ -1794,6 +1795,20 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)
1794
1795
if (number_tiles > 1 )
1795
1796
vm -> composite_fence_ctx = dma_fence_context_alloc (1 );
1796
1797
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
+
1797
1812
trace_xe_vm_create (vm );
1798
1813
1799
1814
return vm ;
@@ -1814,6 +1829,8 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)
1814
1829
for_each_tile (tile , xe , id )
1815
1830
xe_range_fence_tree_fini (& vm -> rftree [id ]);
1816
1831
ttm_lru_bulk_move_fini (& xe -> ttm , & vm -> lru_bulk_move );
1832
+ if (vm -> xef )
1833
+ xe_file_put (vm -> xef );
1817
1834
kfree (vm );
1818
1835
if (flags & XE_VM_FLAG_LR_MODE )
1819
1836
xe_pm_runtime_put (xe );
@@ -2059,9 +2076,8 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,
2059
2076
struct xe_device * xe = to_xe_device (dev );
2060
2077
struct xe_file * xef = to_xe_file (file );
2061
2078
struct drm_xe_vm_create * args = data ;
2062
- struct xe_tile * tile ;
2063
2079
struct xe_vm * vm ;
2064
- u32 id , asid ;
2080
+ u32 id ;
2065
2081
int err ;
2066
2082
u32 flags = 0 ;
2067
2083
@@ -2097,29 +2113,10 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,
2097
2113
if (args -> flags & DRM_XE_VM_CREATE_FLAG_FAULT_MODE )
2098
2114
flags |= XE_VM_FLAG_FAULT_MODE ;
2099
2115
2100
- vm = xe_vm_create (xe , flags );
2116
+ vm = xe_vm_create (xe , flags , xef );
2101
2117
if (IS_ERR (vm ))
2102
2118
return PTR_ERR (vm );
2103
2119
2104
- if (xe -> info .has_asid ) {
2105
- down_write (& xe -> usm .lock );
2106
- err = xa_alloc_cyclic (& xe -> usm .asid_to_vm , & asid , vm ,
2107
- XA_LIMIT (1 , XE_MAX_ASID - 1 ),
2108
- & xe -> usm .next_asid , GFP_KERNEL );
2109
- up_write (& xe -> usm .lock );
2110
- if (err < 0 )
2111
- goto err_close_and_put ;
2112
-
2113
- vm -> usm .asid = asid ;
2114
- }
2115
-
2116
- vm -> xef = xe_file_get (xef );
2117
-
2118
- /* Record BO memory for VM pagetable created against client */
2119
- for_each_tile (tile , xe , id )
2120
- if (vm -> pt_root [id ])
2121
- xe_drm_client_add_bo (vm -> xef -> client , vm -> pt_root [id ]-> bo );
2122
-
2123
2120
#if IS_ENABLED (CONFIG_DRM_XE_DEBUG_MEM )
2124
2121
/* Warning: Security issue - never enable by default */
2125
2122
args -> reserved [0 ] = xe_bo_main_addr (vm -> pt_root [0 ]-> bo , XE_PAGE_SIZE );
@@ -3421,6 +3418,7 @@ static int vm_bind_ioctl_check_args(struct xe_device *xe, struct xe_vm *vm,
3421
3418
free_bind_ops :
3422
3419
if (args -> num_binds > 1 )
3423
3420
kvfree (* bind_ops );
3421
+ * bind_ops = NULL ;
3424
3422
return err ;
3425
3423
}
3426
3424
@@ -3527,7 +3525,7 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
3527
3525
struct xe_exec_queue * q = NULL ;
3528
3526
u32 num_syncs , num_ufence = 0 ;
3529
3527
struct xe_sync_entry * syncs = NULL ;
3530
- struct drm_xe_vm_bind_op * bind_ops ;
3528
+ struct drm_xe_vm_bind_op * bind_ops = NULL ;
3531
3529
struct xe_vma_ops vops ;
3532
3530
struct dma_fence * fence ;
3533
3531
int err ;
0 commit comments