Commit a41f6b0d authored by Matthew Brost's avatar Matthew Brost Committed by Thomas Hellström

drm/xe: Use vmalloc for array of bind allocation in bind IOCTL

Use vmalloc in effort to allow a user pass in a large number of binds in
an IOCTL (mesa use case). Also use array allocations rather open coding
the size calculation.

v2: Use __GFP_ACCOUNT for allocations (Thomas)

Fixes: dd08ebf6 ("drm/xe: Introduce a new DRM driver for Intel GPUs")
Signed-off-by: default avatarMatthew Brost <matthew.brost@intel.com>
Reviewed-by: default avatarThomas Hellström <thomas.hellstrom@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240226155554.103384-1-matthew.brost@intel.com
(cherry picked from commit 35ed1d2b)
Signed-off-by: default avatarThomas Hellström <thomas.hellstrom@linux.intel.com>
parent ccff0b21
...@@ -2740,8 +2740,9 @@ static int vm_bind_ioctl_check_args(struct xe_device *xe, ...@@ -2740,8 +2740,9 @@ static int vm_bind_ioctl_check_args(struct xe_device *xe,
u64 __user *bind_user = u64 __user *bind_user =
u64_to_user_ptr(args->vector_of_binds); u64_to_user_ptr(args->vector_of_binds);
*bind_ops = kmalloc(sizeof(struct drm_xe_vm_bind_op) * *bind_ops = kvmalloc_array(args->num_binds,
args->num_binds, GFP_KERNEL); sizeof(struct drm_xe_vm_bind_op),
GFP_KERNEL | __GFP_ACCOUNT);
if (!*bind_ops) if (!*bind_ops)
return -ENOMEM; return -ENOMEM;
...@@ -2831,7 +2832,7 @@ static int vm_bind_ioctl_check_args(struct xe_device *xe, ...@@ -2831,7 +2832,7 @@ static int vm_bind_ioctl_check_args(struct xe_device *xe,
free_bind_ops: free_bind_ops:
if (args->num_binds > 1) if (args->num_binds > 1)
kfree(*bind_ops); kvfree(*bind_ops);
return err; return err;
} }
...@@ -2919,13 +2920,15 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file) ...@@ -2919,13 +2920,15 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
} }
if (args->num_binds) { if (args->num_binds) {
bos = kcalloc(args->num_binds, sizeof(*bos), GFP_KERNEL); bos = kvcalloc(args->num_binds, sizeof(*bos),
GFP_KERNEL | __GFP_ACCOUNT);
if (!bos) { if (!bos) {
err = -ENOMEM; err = -ENOMEM;
goto release_vm_lock; goto release_vm_lock;
} }
ops = kcalloc(args->num_binds, sizeof(*ops), GFP_KERNEL); ops = kvcalloc(args->num_binds, sizeof(*ops),
GFP_KERNEL | __GFP_ACCOUNT);
if (!ops) { if (!ops) {
err = -ENOMEM; err = -ENOMEM;
goto release_vm_lock; goto release_vm_lock;
...@@ -3066,10 +3069,10 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file) ...@@ -3066,10 +3069,10 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
for (i = 0; bos && i < args->num_binds; ++i) for (i = 0; bos && i < args->num_binds; ++i)
xe_bo_put(bos[i]); xe_bo_put(bos[i]);
kfree(bos); kvfree(bos);
kfree(ops); kvfree(ops);
if (args->num_binds > 1) if (args->num_binds > 1)
kfree(bind_ops); kvfree(bind_ops);
return err; return err;
...@@ -3093,10 +3096,10 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file) ...@@ -3093,10 +3096,10 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
if (q) if (q)
xe_exec_queue_put(q); xe_exec_queue_put(q);
free_objs: free_objs:
kfree(bos); kvfree(bos);
kfree(ops); kvfree(ops);
if (args->num_binds > 1) if (args->num_binds > 1)
kfree(bind_ops); kvfree(bind_ops);
return err; return err;
} }
......
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