[PATCH 42/54] fast-et-caching

Chris Wilson chris at chris-wilson.co.uk
Sun Jun 4 12:08:25 UTC 2017


---
 drivers/gpu/drm/i915/i915_drv.c |  2 +-
 drivers/gpu/drm/i915/i915_drv.h |  5 +++--
 drivers/gpu/drm/i915/i915_gem.c | 44 ++++++++++++++++++++++++++++-------------
 3 files changed, 34 insertions(+), 17 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index f6f72c68128c..f66b3f163230 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -2551,7 +2551,7 @@ static const struct drm_ioctl_desc i915_ioctls[] = {
 	DRM_IOCTL_DEF_DRV(I915_GEM_UNPIN, i915_gem_reject_pin_ioctl, DRM_AUTH|DRM_ROOT_ONLY),
 	DRM_DRIVER_IOCTL_DEF(I915_GEM_BUSY, i915_gem_busy_ioctl, DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF_DRV(I915_GEM_SET_CACHING, i915_gem_set_caching_ioctl, DRM_RENDER_ALLOW),
-	DRM_IOCTL_DEF_DRV(I915_GEM_GET_CACHING, i915_gem_get_caching_ioctl, DRM_RENDER_ALLOW),
+	DRM_DRIVER_IOCTL_DEF(I915_GEM_GET_CACHING, i915_gem_get_caching_ioctl, DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF_DRV(I915_GEM_THROTTLE, i915_gem_throttle_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF_DRV(I915_GEM_ENTERVT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
 	DRM_IOCTL_DEF_DRV(I915_GEM_LEAVEVT, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index a1d9d2584fa9..3f3fdeb18dd8 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -3209,8 +3209,9 @@ int i915_gem_execbuffer2(struct drm_device *dev, void *data,
 long i915_gem_busy_ioctl(struct file *filp,
 			 unsigned int cmd,
 			 unsigned long arg);
-int i915_gem_get_caching_ioctl(struct drm_device *dev, void *data,
-			       struct drm_file *file);
+long i915_gem_get_caching_ioctl(struct file *filp,
+				unsigned int cmd,
+				unsigned long data);
 int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,
 			       struct drm_file *file);
 int i915_gem_throttle_ioctl(struct drm_device *dev, void *data,
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 4ddfee765e2f..c52c9279736d 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -3711,37 +3711,53 @@ int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
 	return 0;
 }
 
-int i915_gem_get_caching_ioctl(struct drm_device *dev, void *data,
-			       struct drm_file *file)
+long i915_gem_get_caching_ioctl(struct file *filp,
+				unsigned int cmd,
+				unsigned long data)
 {
-	struct drm_i915_gem_caching *args = data;
+	struct drm_i915_gem_caching __user *user = (typeof(user))data;
+	struct drm_i915_gem_caching arg;
 	struct drm_i915_gem_object *obj;
-	int err = 0;
+
+	if (unlikely(!access_ok(VERIFY_WRITE, user, sizeof(*user))))
+		return -EFAULT;
+
+	user_access_begin();
+	unsafe_get_user(arg.handle, &user->handle, err_user);
+	user_access_end();
 
 	rcu_read_lock();
-	obj = i915_gem_object_lookup_rcu(file, args->handle);
-	if (!obj) {
-		err = -ENOENT;
-		goto out;
-	}
+	obj = i915_gem_object_lookup_rcu(filp->private_data, arg.handle);
+	if (unlikely(!obj))
+		goto err_obj;
 
 	switch (obj->cache_level) {
 	case I915_CACHE_LLC:
 	case I915_CACHE_L3_LLC:
-		args->caching = I915_CACHING_CACHED;
+		arg.caching = I915_CACHING_CACHED;
 		break;
 
 	case I915_CACHE_WT:
-		args->caching = I915_CACHING_DISPLAY;
+		arg.caching = I915_CACHING_DISPLAY;
 		break;
 
 	default:
-		args->caching = I915_CACHING_NONE;
+		arg.caching = I915_CACHING_NONE;
 		break;
 	}
-out:
 	rcu_read_unlock();
-	return err;
+
+	user_access_begin();
+	unsafe_put_user(arg.caching, &user->caching, err_user);
+	user_access_end();
+	return 0;
+
+err_obj:
+	rcu_read_unlock();
+	return -ENOENT;
+err_user:
+	user_access_end();
+	return -EFAULT;
 }
 
 int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,
-- 
2.11.0



More information about the Intel-gfx-trybot mailing list