]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
drm/xe: Assign ioctl xe file handler to vm in xe_vm_create
authorPiotr Piórkowski <piotr.piorkowski@intel.com>
Mon, 11 Aug 2025 10:43:57 +0000 (12:43 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 28 Aug 2025 14:34:47 +0000 (16:34 +0200)
[ Upstream commit 658a1c8e0a66d0777e0e37a11ba19f27a81e77f4 ]

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: 7f387e6012b6 ("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 9337166fa1d80f7bb7c7d3a8f901f21c348c0f2a)
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/xe/xe_migrate.c
drivers/gpu/drm/xe/xe_pxp_submit.c
drivers/gpu/drm/xe/xe_vm.c
drivers/gpu/drm/xe/xe_vm.h

index 1e3fd139dfcbca61e4b80e9fa26c84bc19f85be0..0a481190f3e6ae7680e5f0eabe3b1ffbfb68b2b7 100644 (file)
@@ -408,7 +408,7 @@ struct xe_migrate *xe_migrate_init(struct xe_tile *tile)
 
        /* Special layout, prepared below.. */
        vm = xe_vm_create(xe, XE_VM_FLAG_MIGRATION |
-                         XE_VM_FLAG_SET_TILE_ID(tile));
+                         XE_VM_FLAG_SET_TILE_ID(tile), NULL);
        if (IS_ERR(vm))
                return ERR_CAST(vm);
 
index d92ec0f515b03486f29628751431b67f7ed90460..ca95f2a4d4ef5def6f41a4411406e5ab06322114 100644 (file)
@@ -101,7 +101,7 @@ static int allocate_gsc_client_resources(struct xe_gt *gt,
        xe_assert(xe, hwe);
 
        /* PXP instructions must be issued from PPGTT */
-       vm = xe_vm_create(xe, XE_VM_FLAG_GSC);
+       vm = xe_vm_create(xe, XE_VM_FLAG_GSC, NULL);
        if (IS_ERR(vm))
                return PTR_ERR(vm);
 
index 8615777469293b11c991a181712423a7ca68a5b0..7251f23b919c8ed833fa1b4a30fee52e40e01356 100644 (file)
@@ -1612,7 +1612,7 @@ static void xe_vm_free_scratch(struct xe_vm *vm)
        }
 }
 
-struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)
+struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags, struct xe_file *xef)
 {
        struct drm_gem_object *vm_resv_obj;
        struct xe_vm *vm;
@@ -1633,9 +1633,10 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)
        vm->xe = xe;
 
        vm->size = 1ull << xe->info.va_bits;
-
        vm->flags = flags;
 
+       if (xef)
+               vm->xef = xe_file_get(xef);
        /**
         * GSC VMs are kernel-owned, only used for PXP ops and can sometimes be
         * manipulated under the PXP mutex. However, the PXP mutex can be taken
@@ -1786,6 +1787,8 @@ err_no_resv:
        for_each_tile(tile, xe, id)
                xe_range_fence_tree_fini(&vm->rftree[id]);
        ttm_lru_bulk_move_fini(&xe->ttm, &vm->lru_bulk_move);
+       if (vm->xef)
+               xe_file_put(vm->xef);
        kfree(vm);
        if (flags & XE_VM_FLAG_LR_MODE)
                xe_pm_runtime_put(xe);
@@ -2069,7 +2072,7 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,
        if (args->flags & DRM_XE_VM_CREATE_FLAG_FAULT_MODE)
                flags |= XE_VM_FLAG_FAULT_MODE;
 
-       vm = xe_vm_create(xe, flags);
+       vm = xe_vm_create(xe, flags, xef);
        if (IS_ERR(vm))
                return PTR_ERR(vm);
 
@@ -2085,8 +2088,6 @@ int xe_vm_create_ioctl(struct drm_device *dev, void *data,
                vm->usm.asid = asid;
        }
 
-       vm->xef = xe_file_get(xef);
-
        /* Record BO memory for VM pagetable created against client */
        for_each_tile(tile, xe, id)
                if (vm->pt_root[id])
index 494af6bdc646b4b331d3c3b4306e37c1f13f5390..0158ec0ae3b2301f9da1bbf6957b1a0b85266fb2 100644 (file)
@@ -26,7 +26,7 @@ struct xe_sync_entry;
 struct xe_svm_range;
 struct drm_exec;
 
-struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags);
+struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags, struct xe_file *xef);
 
 struct xe_vm *xe_vm_lookup(struct xe_file *xef, u32 id);
 int xe_vma_cmp_vma_cb(const void *key, const struct rb_node *node);