[PATCH 2/3] drm/i915: Refactor relocs ptr pre-fault
Tvrtko Ursulin
tursulin at ursulin.net
Wed May 31 13:22:43 UTC 2017
From: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
Remove the reliance on relocs_max handling the limitation of
fault_in_pages_readable and also remove the data type mismatch.
This will allow the refactoring of relocation_count and
relocs_total range checking in the following patch.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
---
drivers/gpu/drm/i915/i915_gem_execbuffer.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
index ee269de7d778..a5e748d226f6 100644
--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
@@ -1192,7 +1192,7 @@ validate_exec_list(struct drm_device *dev,
for (i = 0; i < count; i++) {
char __user *ptr = u64_to_user_ptr(exec[i].relocs_ptr);
- int length; /* limited by fault_in_pages_readable() */
+ u64 length;
if (exec[i].flags & invalid_flags)
return -EINVAL;
@@ -1232,18 +1232,29 @@ validate_exec_list(struct drm_device *dev,
relocs_total += exec[i].relocation_count;
length = exec[i].relocation_count *
- sizeof(struct drm_i915_gem_relocation_entry);
+ sizeof(struct drm_i915_gem_relocation_entry);
+
/*
* We must check that the entire relocation array is safe
* to read, but since we may need to update the presumed
* offsets during execution, check for full write access.
+ *
+ * Do it in INT_MAX sized chunks to account for the limitation
+ * of fault_in_pages_readable.
*/
- if (!access_ok(VERIFY_WRITE, ptr, length))
- return -EFAULT;
+ while (length) {
+ int size = min_t(u64, length, INT_MAX);
- if (likely(!i915.prefault_disable)) {
- if (fault_in_pages_readable(ptr, length))
+ if (!access_ok(VERIFY_WRITE, ptr, size))
return -EFAULT;
+
+ if (likely(!i915.prefault_disable)) {
+ if (fault_in_pages_readable(ptr, size))
+ return -EFAULT;
+ }
+
+ ptr += size;
+ length -= size;
}
}
--
2.9.4
More information about the Intel-gfx-trybot
mailing list