* [PATCH] drm/xe: Release the SVM prefetch ranges of unparsed ops
@ 2026-11-13 4:42 Changyul Lee
2026-11-13 15:46 ` Matthew Brost
0 siblings, 1 reply; 2+ messages in thread
From: Changyul Lee @ 2026-11-13 4:42 UTC (permalink / raw)
To: Matthew Brost, Thomas Hellström, Rodrigo Vivi
Cc: David Airlie, Simona Vetter, Himal Prasad Ghimiray, intel-xe,
dri-devel, linux-kernel, Changyul Lee
vm_bind_ioctl_ops_create() stores SVM ranges, each with a reference, in
op->prefetch_range.range for every PREFETCH op on a CPU address mirror
VMA. xe_vma_ops_fini() releases them only for the ops on vops->list.
When vm_bind_ioctl_ops_parse() fails, the ops after the failing one are
never added to that list, and xe_vm_bind_ioctl() frees them with
drm_gpuva_ops_free(), leaking their XArray nodes and range references.
A PREFETCH that covers a userptr VMA and a CPU address mirror VMA after
it does this when pinning the userptr pages fails.
Release the prefetch ranges of all ops before freeing them. Ranges
already released through vops->list leave an empty XArray, which
xe_vma_svm_prefetch_ranges_fini() skips.
Fixes: 09ba0a8f06cd ("drm/xe/svm: Implement prefetch support for SVM ranges")
Signed-off-by: Changyul Lee <lcy8047@gmail.com>
---
Found with a static analysis tool we are developing.
Compile-tested only, with x86_64_defconfig plus DRM_XE, DRM_XE_GPUSVM
and W=1.
drivers/gpu/drm/xe/xe_vm.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
index d25de5652767..ee35ead79371 100644
--- a/drivers/gpu/drm/xe/xe_vm.c
+++ b/drivers/gpu/drm/xe/xe_vm.c
@@ -4208,8 +4208,10 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
vm_bind_ioctl_ops_unwind(vm, ops, args->num_binds);
xe_vma_ops_fini(&vops);
for (i = args->num_binds - 1; i >= 0; --i)
- if (ops[i])
+ if (ops[i]) {
+ xe_svm_prefetch_gpuva_ops_fini(ops[i]);
drm_gpuva_ops_free(&vm->gpuvm, ops[i]);
+ }
free_syncs:
if (err == -ENODATA)
err = vm_bind_ioctl_signal_fences(vm, q, syncs, num_syncs);
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] drm/xe: Release the SVM prefetch ranges of unparsed ops
2026-11-13 4:42 [PATCH] drm/xe: Release the SVM prefetch ranges of unparsed ops Changyul Lee
@ 2026-11-13 15:46 ` Matthew Brost
0 siblings, 0 replies; 2+ messages in thread
From: Matthew Brost @ 2026-11-13 15:46 UTC (permalink / raw)
To: Changyul Lee
Cc: Thomas Hellström, Rodrigo Vivi, David Airlie, Simona Vetter,
Himal Prasad Ghimiray, intel-xe, dri-devel, linux-kernel
On Thu, Nov 12, 2026 at 11:42:39PM -0500, Changyul Lee wrote:
> vm_bind_ioctl_ops_create() stores SVM ranges, each with a reference, in
> op->prefetch_range.range for every PREFETCH op on a CPU address mirror
> VMA. xe_vma_ops_fini() releases them only for the ops on vops->list.
> When vm_bind_ioctl_ops_parse() fails, the ops after the failing one are
> never added to that list, and xe_vm_bind_ioctl() frees them with
> drm_gpuva_ops_free(), leaking their XArray nodes and range references.
> A PREFETCH that covers a userptr VMA and a CPU address mirror VMA after
> it does this when pinning the userptr pages fails.
>
> Release the prefetch ranges of all ops before freeing them. Ranges
> already released through vops->list leave an empty XArray, which
> xe_vma_svm_prefetch_ranges_fini() skips.
>
I believe I see the potential problem. I think this is right and safe
assuming xa_destroy is safe to be called twice which is appears to be.
Our CI will give use definitive answer which I have triggered your
behalf.
With that:
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
> Fixes: 09ba0a8f06cd ("drm/xe/svm: Implement prefetch support for SVM ranges")
> Signed-off-by: Changyul Lee <lcy8047@gmail.com>
> ---
> Found with a static analysis tool we are developing.
>
> Compile-tested only, with x86_64_defconfig plus DRM_XE, DRM_XE_GPUSVM
> and W=1.
>
> drivers/gpu/drm/xe/xe_vm.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c
> index d25de5652767..ee35ead79371 100644
> --- a/drivers/gpu/drm/xe/xe_vm.c
> +++ b/drivers/gpu/drm/xe/xe_vm.c
> @@ -4208,8 +4208,10 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
> vm_bind_ioctl_ops_unwind(vm, ops, args->num_binds);
> xe_vma_ops_fini(&vops);
> for (i = args->num_binds - 1; i >= 0; --i)
> - if (ops[i])
> + if (ops[i]) {
> + xe_svm_prefetch_gpuva_ops_fini(ops[i]);
> drm_gpuva_ops_free(&vm->gpuvm, ops[i]);
> + }
> free_syncs:
> if (err == -ENODATA)
> err = vm_bind_ioctl_signal_fences(vm, q, syncs, num_syncs);
>
> base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-13 15:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-13 4:42 [PATCH] drm/xe: Release the SVM prefetch ranges of unparsed ops Changyul Lee
2026-11-13 15:46 ` Matthew Brost
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®