Commit 9aab8bff authored by Chris Wilson's avatar Chris Wilson Committed by Jani Nikula

drm/i915: Only copy back the modified fields to userspace from execbuffer

We only want to modifiy a single field in the userspace view of the
execbuffer command buffer, so explicitly change that rather than copy
everything back again.

This serves two purposes:

1. The single fields are much cheaper to copy (constant size so the
copy uses special case code) and much smaller than the whole array.

2. We modify the array for internal use that need to be masked from
the user.

Note: We need this backported since without it the next bugfix will
blow up when userspace recycles batchbuffers and relocations.
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: stable@vger.kernel.org
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
parent 00731155
...@@ -773,9 +773,9 @@ i915_gem_execbuffer_relocate_slow(struct drm_device *dev, ...@@ -773,9 +773,9 @@ i915_gem_execbuffer_relocate_slow(struct drm_device *dev,
* relocations were valid. * relocations were valid.
*/ */
for (j = 0; j < exec[i].relocation_count; j++) { for (j = 0; j < exec[i].relocation_count; j++) {
if (copy_to_user(&user_relocs[j].presumed_offset, if (__copy_to_user(&user_relocs[j].presumed_offset,
&invalid_offset, &invalid_offset,
sizeof(invalid_offset))) { sizeof(invalid_offset))) {
ret = -EFAULT; ret = -EFAULT;
mutex_lock(&dev->struct_mutex); mutex_lock(&dev->struct_mutex);
goto err; goto err;
...@@ -1355,18 +1355,21 @@ i915_gem_execbuffer(struct drm_device *dev, void *data, ...@@ -1355,18 +1355,21 @@ i915_gem_execbuffer(struct drm_device *dev, void *data,
ret = i915_gem_do_execbuffer(dev, data, file, &exec2, exec2_list); ret = i915_gem_do_execbuffer(dev, data, file, &exec2, exec2_list);
if (!ret) { if (!ret) {
struct drm_i915_gem_exec_object __user *user_exec_list =
to_user_ptr(args->buffers_ptr);
/* Copy the new buffer offsets back to the user's exec list. */ /* Copy the new buffer offsets back to the user's exec list. */
for (i = 0; i < args->buffer_count; i++) for (i = 0; i < args->buffer_count; i++) {
exec_list[i].offset = exec2_list[i].offset; ret = __copy_to_user(&user_exec_list[i].offset,
/* ... and back out to userspace */ &exec2_list[i].offset,
ret = copy_to_user(to_user_ptr(args->buffers_ptr), sizeof(user_exec_list[i].offset));
exec_list, if (ret) {
sizeof(*exec_list) * args->buffer_count); ret = -EFAULT;
if (ret) { DRM_DEBUG("failed to copy %d exec entries "
ret = -EFAULT; "back to user (%d)\n",
DRM_DEBUG("failed to copy %d exec entries " args->buffer_count, ret);
"back to user (%d)\n", break;
args->buffer_count, ret); }
} }
} }
...@@ -1412,14 +1415,21 @@ i915_gem_execbuffer2(struct drm_device *dev, void *data, ...@@ -1412,14 +1415,21 @@ i915_gem_execbuffer2(struct drm_device *dev, void *data,
ret = i915_gem_do_execbuffer(dev, data, file, args, exec2_list); ret = i915_gem_do_execbuffer(dev, data, file, args, exec2_list);
if (!ret) { if (!ret) {
/* Copy the new buffer offsets back to the user's exec list. */ /* Copy the new buffer offsets back to the user's exec list. */
ret = copy_to_user(to_user_ptr(args->buffers_ptr), struct drm_i915_gem_exec_object2 *user_exec_list =
exec2_list, to_user_ptr(args->buffers_ptr);
sizeof(*exec2_list) * args->buffer_count); int i;
if (ret) {
ret = -EFAULT; for (i = 0; i < args->buffer_count; i++) {
DRM_DEBUG("failed to copy %d exec entries " ret = __copy_to_user(&user_exec_list[i].offset,
"back to user (%d)\n", &exec2_list[i].offset,
args->buffer_count, ret); sizeof(user_exec_list[i].offset));
if (ret) {
ret = -EFAULT;
DRM_DEBUG("failed to copy %d exec entries "
"back to user\n",
args->buffer_count);
break;
}
} }
} }
......
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