drm/xe/vm: Fix an error path
Subsystems (2)
Thomas Hellström
maintainerPATCH 1/1 drm/xe/vm: Fix an error path
If using the VM_BIND_OP_UNMAP_ALL without any bound vmas for the vm, we will end up dereferencin an uninitialized variable and leak a bo lock. Fix this.
--- drivers/gpu/drm/xe/xe_vm.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/gpu/drm/xe/xe_vm.c +5 -3
@@ -2063,9 +2063,11 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_bo *bo,if (err)return ERR_PTR (err); - vm_bo =drm_gpuvm_bo_find (&vm->gpuvm, obj); -if (!vm_bo) -break ; + vm_bo =drm_gpuvm_bo_obtain (&vm->gpuvm, obj); +if (IS_ERR (vm_bo)) { +xe_bo_unlock (bo); +return ERR_CAST (vm_bo); + } ops =drm_gpuvm_bo_unmap_ops_create (vm_bo);drm_gpuvm_bo_put (vm_bo);
Signature · 1 line
2.42.0
Quoted 2 lines · Thomas Hellström
If using the
VM_BIND_OP_UNMAP_ALLwithout any bound vmas for the vm, we will end up dereferencin an uninitialized variable and leak a
dereferencing
Quoted 7 lines
bo lock. Fix this.
Reported-by Dafna Hirschfeld <[email protected]>Closes https://lore.kernel.org/intel-xe/jrwua7ckbiozfcaodx4gg2h4taiuxs53j5zlpf3qzvyhyiyl2d@pbs3plurokrj/ open hereSuggested-by Dafna Hirschfeld <[email protected]>Fixes 9f232f4ae249 ("drm/xe: Port Xe to GPUVA")
^ this newline needs to be removed so `git log --format="%(trailers)"' shows everything, not only your s-o-b.
Quoted 10 lines
Signed-off-by Thomas Hellström <[email protected]>---
drivers/gpu/drm/xe/xe_vm.c| 8 +++++---1 file changed, 5 insertions(+), 3 deletions(-)drivers/gpu/drm/xe/xe_vm.c +0
-0
drivers/gpu/drm/xe/xe_vm.c vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_bo *bo, · line 2066
Quoted 7 lines
drivers/gpu/drm/xe/xe_vm.c +1
-3@@ -2063,9 +2063,11 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_bo *bo,if (err)return ERR_PTR (err); - vm_bo =drm_gpuvm_bo_find (&vm->gpuvm, obj); -if (!vm_bo) -break ; + vm_bo =drm_gpuvm_bo_obtain (&vm->gpuvm, obj);
if the issue with that we don't have any bound vmas, why are we going to create a new one just to be released?
Lucas De Marchi
Quoted 10 lines
drivers/gpu/drm/xe/xe_vm.c +4
-0+if (IS_ERR (vm_bo)) { +xe_bo_unlock (bo); +return ERR_CAST (vm_bo); + } ops =drm_gpuvm_bo_unmap_ops_create (vm_bo);drm_gpuvm_bo_put (vm_bo);Signature · 1 line
2.42.0
Thomas Hellström
maintainerQuoted 8 lines · Lucas De Marchi
Quoted 2 lines · Thomas Hellström
If using the
VM_BIND_OP_UNMAP_ALLwithout any bound vmas for the vm, we will end up dereferencin an uninitialized variable and leak adereferencing
Quoted 2 lines
bo lock. Fix this.
Quoted 8 lines
Quoted 5 lines
Reported-by Dafna Hirschfeld <[email protected]>Closes https://lore.kernel.org/intel-xe/jrwua7ckbiozfcaodx4gg2h4taiuxs53j5zlpf3qzvyhyiyl2d@pbs3plurokrj/ open hereSuggested-by Dafna Hirschfeld <[email protected]>Fixes 9f232f4ae249 ("drm/xe: Port Xe to GPUVA")^ this newline needs to be removed so `git log --format="%(trailers)"' shows everything, not only your s-o-b.
Will fix these.
Quoted 15 lines
Quoted 15 lines
Signed-off-by Thomas Hellström <[email protected]>---
drivers/gpu/drm/xe/xe_vm.c| 8 +++++---1 file changed, 5 insertions(+), 3 deletions(-)drivers/gpu/drm/xe/xe_vm.c +0
-0@@ -2063,9 +2063,11 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm,struct xe_bo *bo, if (err) return ERR_PTR(err);
Quoted 7 lines
drivers/gpu/drm/xe/xe_vm.c vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_bo *bo, · line 2066
Quoted 4 lines
drivers/gpu/drm/xe/xe_vm.c +1
-3- vm_bo = drm_gpuvm_bo_find(&vm->gpuvm, obj); - if (!vm_bo) - break; + vm_bo = drm_gpuvm_bo_obtain(&vm->gpuvm, obj);if the issue with that we don't have any bound vmas, why are we going to create a new one just to be released?
The expected outcome of this operation, AFAICT is, rather than to error, to create an ops with an empty list of operations, so we could in theory kmalloc ops and just initialize its list. However that would be fragile and second-guessing what gpuvm does internally, so I opted for this solution instead.
/Thomas
Quoted 13 lines
Lucas De Marchi
Quoted 10 lines
drivers/gpu/drm/xe/xe_vm.c +4
-0+ if (IS_ERR(vm_bo)) { + xe_bo_unlock(bo); + return ERR_CAST(vm_bo); + } ops = drm_gpuvm_bo_unmap_ops_create(vm_bo);
drm_gpuvm_bo_put(vm_bo);Signature · 1 line
2.42.0
Lucas De Marchi
Acked-byQuoted 42 lines · Thomas Hellström
Quoted 8 lines · Lucas De Marchi
Quoted 2 lines · Thomas Hellström
If using the
VM_BIND_OP_UNMAP_ALLwithout any bound vmas for the vm, we will end up dereferencin an uninitialized variable and leak adereferencing
Quoted 2 lines
bo lock. Fix this.
Quoted 8 lines
Quoted 5 lines
Reported-by Dafna Hirschfeld <[email protected]>Closes https://lore.kernel.org/intel-xe/jrwua7ckbiozfcaodx4gg2h4taiuxs53j5zlpf3qzvyhyiyl2d@pbs3plurokrj/ open hereSuggested-by Dafna Hirschfeld <[email protected]>Fixes 9f232f4ae249 ("drm/xe: Port Xe to GPUVA")^ this newline needs to be removed so `git log --format="%(trailers)"' shows everything, not only your s-o-b.
Will fix these.
Quoted 15 lines
Quoted 15 lines
Signed-off-by Thomas Hellström <[email protected]>---
drivers/gpu/drm/xe/xe_vm.c| 8 +++++---1 file changed, 5 insertions(+), 3 deletions(-)drivers/gpu/drm/xe/xe_vm.c +0
-0@@ -2063,9 +2063,11 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm,struct xe_bo *bo, if (err) return ERR_PTR(err);Quoted 7 lines
drivers/gpu/drm/xe/xe_vm.c vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_bo *bo, · line 2066
Quoted 4 lines
drivers/gpu/drm/xe/xe_vm.c +1
-3- vm_bo = drm_gpuvm_bo_find(&vm->gpuvm, obj); - if (!vm_bo) - break; + vm_bo = drm_gpuvm_bo_obtain(&vm->gpuvm, obj);if the issue with that we don't have any bound vmas, why are we going to create a new one just to be released?
Quoted 1 line
The expected outcome of this operation, AFAICT is, rather than to error, to create an ops with an empty list of operations, so we could in theory kmalloc ops and just initialize its list. However that would be fragile and second-guessing what gpuvm does internally, so I opted for this solution instead.
ok,
Adding dri-devel and Danilo to Cc as it looks like we are the first users of this api.
The NULL vs ptr-error between _find and _obtain looked suspicious when I first looked, but they match the current implementation.
thanks
Lucas De Marchi
Quoted 18 lines
/Thomas
Quoted 13 lines
Lucas De Marchi
Quoted 10 lines
drivers/gpu/drm/xe/xe_vm.c +4
-0+ if (IS_ERR(vm_bo)) { + xe_bo_unlock(bo); + return ERR_CAST(vm_bo); + } ops = drm_gpuvm_bo_unmap_ops_create(vm_bo);
drm_gpuvm_bo_put(vm_bo);Signature · 1 line
2.42.0
Thomas Hellström
maintainerQuoted 49 lines · Lucas De Marchi
Quoted 42 lines · Thomas Hellström
Quoted 8 lines · Lucas De Marchi
Quoted 2 lines · Thomas Hellström
If using the
VM_BIND_OP_UNMAP_ALLwithout any bound vmas for the vm, we will end up dereferencin an uninitialized variable and leak adereferencing
Quoted 2 lines
bo lock. Fix this.
Quoted 8 lines
Quoted 5 lines
Reported-by Dafna Hirschfeld <[email protected]>Closes https://lore.kernel.org/intel-xe/jrwua7ckbiozfcaodx4gg2h4taiuxs53j5zlpf3qzvyhyiyl2d@pbs3plurokrj/ open hereSuggested-by Dafna Hirschfeld <[email protected]>Fixes 9f232f4ae249 ("drm/xe: Port Xe to GPUVA")^ this newline needs to be removed so `git log --format="%(trailers)"' shows everything, not only your s-o-b.
Will fix these.
Quoted 15 lines
Quoted 15 lines
Signed-off-by Thomas Hellström <[email protected]>---
drivers/gpu/drm/xe/xe_vm.c| 8 +++++---1 file changed, 5 insertions(+), 3 deletions(-)drivers/gpu/drm/xe/xe_vm.c +0
-0@@ -2063,9 +2063,11 @@ vm_bind_ioctl_ops_create(struct xe_vm *vm,struct xe_bo *bo, if (err) return ERR_PTR(err);Quoted 7 lines
drivers/gpu/drm/xe/xe_vm.c vm_bind_ioctl_ops_create(struct xe_vm *vm, struct xe_bo *bo, · line 2066
Quoted 4 lines
drivers/gpu/drm/xe/xe_vm.c +1
-3- vm_bo = drm_gpuvm_bo_find(&vm->gpuvm, obj); - if (!vm_bo) - break; + vm_bo = drm_gpuvm_bo_obtain(&vm->gpuvm, obj);if the issue with that we don't have any bound vmas, why are we going to create a new one just to be released?
Quoted 1 line
The expected outcome of this operation, AFAICT is, rather than to error, to create an ops with an empty list of operations, so we could in theory kmalloc ops and just initialize its list. However that would be fragile and second-guessing what gpuvm does internally, so I opted for this solution instead.
ok,
Acked-by Lucas De Marchi <[email protected]>
Quoted 8 lines
Adding dri-devel and Danilo to Cc as it looks like we are the first users of this api.
The NULL vs ptr-error between
_findand_obtainlooked suspicious when I first looked, but they match the current implementation.thanks
Lucas De Marchi
Thanks for reviewing, Lucas.
/Thomas
Quoted 19 lines
Quoted 19 lines
/Thomas
Quoted 13 lines
Lucas De Marchi
Quoted 10 lines
drivers/gpu/drm/xe/xe_vm.c +4
-0+ if (IS_ERR(vm_bo)) { + xe_bo_unlock(bo); + return ERR_CAST(vm_bo); + } ops = drm_gpuvm_bo_unmap_ops_create(vm_bo);
drm_gpuvm_bo_put(vm_bo);Signature · 1 line
2.42.0