Commit 4550d66d authored by Danilo Krummrich's avatar Danilo Krummrich Committed by Maxime Ripard

drm/imagination: vm: check for drm_gpuvm_range_valid()

Extend pvr_device_addr_and_size_are_valid() by the corresponding GPUVM
sanity checks. This includes a, previously missing, overflow check for
the base address and size of the requested mapping.

Fixes: ff5f643d ("drm/imagination: Add GEM and VM related code")
Signed-off-by: default avatarDanilo Krummrich <dakr@redhat.com>
Reviewed-by: default avatarDonald Robson <donald.robson@imgtec.com>
Tested-by: default avatarFrank Binns <frank.binns@imgtec.com>
Signed-off-by: default avatarMaxime Ripard <mripard@kernel.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20231124233650.152653-3-dakr@redhat.com
parent 4aa89e86
...@@ -239,7 +239,7 @@ pvr_vm_bind_op_map_init(struct pvr_vm_bind_op *bind_op, ...@@ -239,7 +239,7 @@ pvr_vm_bind_op_map_init(struct pvr_vm_bind_op *bind_op,
return -EINVAL; return -EINVAL;
} }
if (!pvr_device_addr_and_size_are_valid(device_addr, size) || if (!pvr_device_addr_and_size_are_valid(vm_ctx, device_addr, size) ||
offset & ~PAGE_MASK || size & ~PAGE_MASK || offset & ~PAGE_MASK || size & ~PAGE_MASK ||
offset >= pvr_obj_size || offset_plus_size > pvr_obj_size) offset >= pvr_obj_size || offset_plus_size > pvr_obj_size)
return -EINVAL; return -EINVAL;
...@@ -295,7 +295,7 @@ pvr_vm_bind_op_unmap_init(struct pvr_vm_bind_op *bind_op, ...@@ -295,7 +295,7 @@ pvr_vm_bind_op_unmap_init(struct pvr_vm_bind_op *bind_op,
{ {
int err; int err;
if (!pvr_device_addr_and_size_are_valid(device_addr, size)) if (!pvr_device_addr_and_size_are_valid(vm_ctx, device_addr, size))
return -EINVAL; return -EINVAL;
bind_op->type = PVR_VM_BIND_TYPE_UNMAP; bind_op->type = PVR_VM_BIND_TYPE_UNMAP;
...@@ -505,6 +505,7 @@ pvr_device_addr_is_valid(u64 device_addr) ...@@ -505,6 +505,7 @@ pvr_device_addr_is_valid(u64 device_addr)
/** /**
* pvr_device_addr_and_size_are_valid() - Tests whether a device-virtual * pvr_device_addr_and_size_are_valid() - Tests whether a device-virtual
* address and associated size are both valid. * address and associated size are both valid.
* @vm_ctx: Target VM context.
* @device_addr: Virtual device address to test. * @device_addr: Virtual device address to test.
* @size: Size of the range based at @device_addr to test. * @size: Size of the range based at @device_addr to test.
* *
...@@ -523,9 +524,11 @@ pvr_device_addr_is_valid(u64 device_addr) ...@@ -523,9 +524,11 @@ pvr_device_addr_is_valid(u64 device_addr)
* * %false otherwise. * * %false otherwise.
*/ */
bool bool
pvr_device_addr_and_size_are_valid(u64 device_addr, u64 size) pvr_device_addr_and_size_are_valid(struct pvr_vm_context *vm_ctx,
u64 device_addr, u64 size)
{ {
return pvr_device_addr_is_valid(device_addr) && return pvr_device_addr_is_valid(device_addr) &&
drm_gpuvm_range_valid(&vm_ctx->gpuvm_mgr, device_addr, size) &&
size != 0 && (size & ~PVR_DEVICE_PAGE_MASK) == 0 && size != 0 && (size & ~PVR_DEVICE_PAGE_MASK) == 0 &&
(device_addr + size <= PVR_PAGE_TABLE_ADDR_SPACE_SIZE); (device_addr + size <= PVR_PAGE_TABLE_ADDR_SPACE_SIZE);
} }
......
...@@ -29,7 +29,8 @@ struct drm_exec; ...@@ -29,7 +29,8 @@ struct drm_exec;
/* Functions defined in pvr_vm.c */ /* Functions defined in pvr_vm.c */
bool pvr_device_addr_is_valid(u64 device_addr); bool pvr_device_addr_is_valid(u64 device_addr);
bool pvr_device_addr_and_size_are_valid(u64 device_addr, u64 size); bool pvr_device_addr_and_size_are_valid(struct pvr_vm_context *vm_ctx,
u64 device_addr, u64 size);
struct pvr_vm_context *pvr_vm_create_context(struct pvr_device *pvr_dev, struct pvr_vm_context *pvr_vm_create_context(struct pvr_device *pvr_dev,
bool is_userspace_context); bool is_userspace_context);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment