Commit 0b100760 authored by Chris Wilson's avatar Chris Wilson

drm/i915/userptr: Enable read-only support on gen8+

On gen8 and onwards, we can mark GPU accesses through the ppGTT as being
read-only, that is cause any GPU write onto that page to be discarded
(not triggering a fault). This is all that we need to finally support
the read-only flag for userptr!

v2: Check default address space for read only support as a proxy for the
user context/ppgtt.

Testcase: igt/gem_userptr_blits/readonly*
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Cc: Jon Bloomfield <jon.bloomfield@intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Reviewed-by: default avatarJoonas Lahtinen <joonas.lahtinen@linux.intel.com>
Reviewed-by: default avatarMatthew Auld <matthew.william.auld@gmail.com>
Reviewed-by: default avatarJon Bloomfield <jon.bloomfield@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20180712191430.9269-1-chris@chris-wilson.co.uk
parent f8c1cce3
...@@ -267,7 +267,6 @@ struct drm_i915_gem_object { ...@@ -267,7 +267,6 @@ struct drm_i915_gem_object {
union { union {
struct i915_gem_userptr { struct i915_gem_userptr {
uintptr_t ptr; uintptr_t ptr;
unsigned read_only :1;
struct i915_mm_struct *mm; struct i915_mm_struct *mm;
struct i915_mmu_object *mmu_object; struct i915_mmu_object *mmu_object;
......
...@@ -507,7 +507,7 @@ __i915_gem_userptr_get_pages_worker(struct work_struct *_work) ...@@ -507,7 +507,7 @@ __i915_gem_userptr_get_pages_worker(struct work_struct *_work)
struct mm_struct *mm = obj->userptr.mm->mm; struct mm_struct *mm = obj->userptr.mm->mm;
unsigned int flags = 0; unsigned int flags = 0;
if (!obj->userptr.read_only) if (!i915_gem_object_is_readonly(obj))
flags |= FOLL_WRITE; flags |= FOLL_WRITE;
ret = -EFAULT; ret = -EFAULT;
...@@ -643,7 +643,7 @@ static int i915_gem_userptr_get_pages(struct drm_i915_gem_object *obj) ...@@ -643,7 +643,7 @@ static int i915_gem_userptr_get_pages(struct drm_i915_gem_object *obj)
if (pvec) /* defer to worker if malloc fails */ if (pvec) /* defer to worker if malloc fails */
pinned = __get_user_pages_fast(obj->userptr.ptr, pinned = __get_user_pages_fast(obj->userptr.ptr,
num_pages, num_pages,
!obj->userptr.read_only, !i915_gem_object_is_readonly(obj),
pvec); pvec);
} }
...@@ -789,9 +789,14 @@ i915_gem_userptr_ioctl(struct drm_device *dev, ...@@ -789,9 +789,14 @@ i915_gem_userptr_ioctl(struct drm_device *dev,
return -EFAULT; return -EFAULT;
if (args->flags & I915_USERPTR_READ_ONLY) { if (args->flags & I915_USERPTR_READ_ONLY) {
/* On almost all of the current hw, we cannot tell the GPU that a struct i915_hw_ppgtt *ppgtt;
* page is readonly, so this is just a placeholder in the uAPI.
/*
* On almost all of the older hw, we cannot tell the GPU that
* a page is readonly.
*/ */
ppgtt = dev_priv->kernel_context->ppgtt;
if (!ppgtt || !ppgtt->vm.has_read_only)
return -ENODEV; return -ENODEV;
} }
...@@ -806,7 +811,8 @@ i915_gem_userptr_ioctl(struct drm_device *dev, ...@@ -806,7 +811,8 @@ i915_gem_userptr_ioctl(struct drm_device *dev,
i915_gem_object_set_cache_coherency(obj, I915_CACHE_LLC); i915_gem_object_set_cache_coherency(obj, I915_CACHE_LLC);
obj->userptr.ptr = args->user_ptr; obj->userptr.ptr = args->user_ptr;
obj->userptr.read_only = !!(args->flags & I915_USERPTR_READ_ONLY); if (args->flags & I915_USERPTR_READ_ONLY)
i915_gem_object_set_readonly(obj);
/* And keep a pointer to the current->mm for resolving the user pages /* And keep a pointer to the current->mm for resolving the user pages
* at binding. This means that we need to hook into the mmu_notifier * at binding. This means that we need to hook into the mmu_notifier
......
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