kernel.h: add u64_to_user_ptr()
authorGustavo Padovan <gustavo.padovan@collabora.co.uk>
Tue, 26 Apr 2016 15:32:27 +0000 (12:32 -0300)
committerAlex Shi <alex.shi@linaro.org>
Thu, 6 Jul 2017 03:07:39 +0000 (11:07 +0800)
This function had copies in 3 different files. Unify them in kernel.h.

Cc: Joe Perches <joe@perches.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: David Airlie <airlied@linux.ie>
Cc: Daniel Vetter <daniel.vetter@intel.com>
Cc: Rob Clark <robdclark@gmail.com>
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Acked-by: Daniel Vetter <daniel.vetter@intel.com> [drm/i915/]
Acked-by: Rob Clark <robdclark@gmail.com> [drm/msm/]
Acked-by: Lucas Stach <l.stach@pengutronix.de> [drm/etinav/]
Acked-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 3ed605bc8a0a688d8750a1e2eff39c854418c5cf)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
Conflicts:
drop drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c

drivers/gpu/drm/i915/i915_drv.h
drivers/gpu/drm/i915/i915_gem.c
drivers/gpu/drm/i915/i915_gem_execbuffer.c
drivers/gpu/drm/msm/msm_gem_submit.c
include/linux/kernel.h

index 5044f2257e89f5fa10672e432753cb402e74ce70..6fca39e1c419a03b21c646ac45163fe14f45783a 100644 (file)
@@ -3475,11 +3475,6 @@ static inline uint32_t i915_vgacntrl_reg(struct drm_device *dev)
                return VGACNTRL;
 }
 
-static inline void __user *to_user_ptr(u64 address)
-{
-       return (void __user *)(uintptr_t)address;
-}
-
 static inline unsigned long msecs_to_jiffies_timeout(const unsigned int m)
 {
        unsigned long j = msecs_to_jiffies(m);
index f56af0aaafde511c1add59ce5f89fe2fa9be5c42..659b90657f36c3b9a4757adb6f03e982814389b2 100644 (file)
@@ -324,7 +324,7 @@ i915_gem_phys_pwrite(struct drm_i915_gem_object *obj,
 {
        struct drm_device *dev = obj->base.dev;
        void *vaddr = obj->phys_handle->vaddr + args->offset;
-       char __user *user_data = to_user_ptr(args->data_ptr);
+       char __user *user_data = u64_to_user_ptr(args->data_ptr);
        int ret = 0;
 
        /* We manually control the domain here and pretend that it
@@ -605,7 +605,7 @@ i915_gem_shmem_pread(struct drm_device *dev,
        int needs_clflush = 0;
        struct sg_page_iter sg_iter;
 
-       user_data = to_user_ptr(args->data_ptr);
+       user_data = u64_to_user_ptr(args->data_ptr);
        remain = args->size;
 
        obj_do_bit17_swizzling = i915_gem_object_needs_bit17_swizzle(obj);
@@ -692,7 +692,7 @@ i915_gem_pread_ioctl(struct drm_device *dev, void *data,
                return 0;
 
        if (!access_ok(VERIFY_WRITE,
-                      to_user_ptr(args->data_ptr),
+                      u64_to_user_ptr(args->data_ptr),
                       args->size))
                return -EFAULT;
 
@@ -783,7 +783,7 @@ i915_gem_gtt_pwrite_fast(struct drm_device *dev,
        if (ret)
                goto out_unpin;
 
-       user_data = to_user_ptr(args->data_ptr);
+       user_data = u64_to_user_ptr(args->data_ptr);
        remain = args->size;
 
        offset = i915_gem_obj_ggtt_offset(obj) + args->offset;
@@ -907,7 +907,7 @@ i915_gem_shmem_pwrite(struct drm_device *dev,
        int needs_clflush_before = 0;
        struct sg_page_iter sg_iter;
 
-       user_data = to_user_ptr(args->data_ptr);
+       user_data = u64_to_user_ptr(args->data_ptr);
        remain = args->size;
 
        obj_do_bit17_swizzling = i915_gem_object_needs_bit17_swizzle(obj);
@@ -1036,12 +1036,12 @@ i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
                return 0;
 
        if (!access_ok(VERIFY_READ,
-                      to_user_ptr(args->data_ptr),
+                      u64_to_user_ptr(args->data_ptr),
                       args->size))
                return -EFAULT;
 
        if (likely(!i915.prefault_disable)) {
-               ret = fault_in_multipages_readable(to_user_ptr(args->data_ptr),
+               ret = fault_in_multipages_readable(u64_to_user_ptr(args->data_ptr),
                                                   args->size);
                if (ret)
                        return -EFAULT;
index 6ed7d63a0688384830894f4a455463bd7e9e060c..c66307c58a7f377233aab6fbbaf7099716277b95 100644 (file)
@@ -492,7 +492,7 @@ i915_gem_execbuffer_relocate_vma(struct i915_vma *vma,
        struct drm_i915_gem_exec_object2 *entry = vma->exec_entry;
        int remain, ret;
 
-       user_relocs = to_user_ptr(entry->relocs_ptr);
+       user_relocs = u64_to_user_ptr(entry->relocs_ptr);
 
        remain = entry->relocation_count;
        while (remain) {
@@ -833,7 +833,7 @@ i915_gem_execbuffer_relocate_slow(struct drm_device *dev,
                u64 invalid_offset = (u64)-1;
                int j;
 
-               user_relocs = to_user_ptr(exec[i].relocs_ptr);
+               user_relocs = u64_to_user_ptr(exec[i].relocs_ptr);
 
                if (copy_from_user(reloc+total, user_relocs,
                                   exec[i].relocation_count * sizeof(*reloc))) {
@@ -977,7 +977,7 @@ validate_exec_list(struct drm_device *dev,
                invalid_flags |= EXEC_OBJECT_NEEDS_GTT;
 
        for (i = 0; i < count; i++) {
-               char __user *ptr = to_user_ptr(exec[i].relocs_ptr);
+               char __user *ptr = u64_to_user_ptr(exec[i].relocs_ptr);
                int length; /* limited by fault_in_pages_readable() */
 
                if (exec[i].flags & invalid_flags)
@@ -1635,7 +1635,7 @@ i915_gem_execbuffer(struct drm_device *dev, void *data,
                return -ENOMEM;
        }
        ret = copy_from_user(exec_list,
-                            to_user_ptr(args->buffers_ptr),
+                            u64_to_user_ptr(args->buffers_ptr),
                             sizeof(*exec_list) * args->buffer_count);
        if (ret != 0) {
                DRM_DEBUG("copy %d exec entries failed %d\n",
@@ -1671,7 +1671,7 @@ i915_gem_execbuffer(struct drm_device *dev, void *data,
        ret = i915_gem_do_execbuffer(dev, data, file, &exec2, exec2_list);
        if (!ret) {
                struct drm_i915_gem_exec_object __user *user_exec_list =
-                       to_user_ptr(args->buffers_ptr);
+                       u64_to_user_ptr(args->buffers_ptr);
 
                /* Copy the new buffer offsets back to the user's exec list. */
                for (i = 0; i < args->buffer_count; i++) {
@@ -1723,7 +1723,7 @@ i915_gem_execbuffer2(struct drm_device *dev, void *data,
                return -ENOMEM;
        }
        ret = copy_from_user(exec2_list,
-                            to_user_ptr(args->buffers_ptr),
+                            u64_to_user_ptr(args->buffers_ptr),
                             sizeof(*exec2_list) * args->buffer_count);
        if (ret != 0) {
                DRM_DEBUG("copy %d exec entries failed %d\n",
@@ -1736,7 +1736,7 @@ i915_gem_execbuffer2(struct drm_device *dev, void *data,
        if (!ret) {
                /* Copy the new buffer offsets back to the user's exec list. */
                struct drm_i915_gem_exec_object2 __user *user_exec_list =
-                                  to_user_ptr(args->buffers_ptr);
+                                  u64_to_user_ptr(args->buffers_ptr);
                int i;
 
                for (i = 0; i < args->buffer_count; i++) {
index 1847f83b1e33a2a206b5361facace9df9ebcc236..f2cc9690dbb7980a682ad9a2c992ca9b98e5b843 100644 (file)
 #define BO_LOCKED   0x4000
 #define BO_PINNED   0x2000
 
-static inline void __user *to_user_ptr(u64 address)
-{
-       return (void __user *)(uintptr_t)address;
-}
-
 static struct msm_gem_submit *submit_create(struct drm_device *dev,
                struct msm_gpu *gpu, int nr)
 {
@@ -77,7 +72,7 @@ static int submit_lookup_objects(struct msm_gem_submit *submit,
                struct drm_gem_object *obj;
                struct msm_gem_object *msm_obj;
                void __user *userptr =
-                       to_user_ptr(args->bos + (i * sizeof(submit_bo)));
+                       u64_to_user_ptr(args->bos + (i * sizeof(submit_bo)));
 
                ret = copy_from_user_inatomic(&submit_bo, userptr, sizeof(submit_bo));
                if (unlikely(ret)) {
@@ -274,7 +269,7 @@ static int submit_reloc(struct msm_gem_submit *submit, struct msm_gem_object *ob
        for (i = 0; i < nr_relocs; i++) {
                struct drm_msm_gem_submit_reloc submit_reloc;
                void __user *userptr =
-                       to_user_ptr(relocs + (i * sizeof(submit_reloc)));
+                       u64_to_user_ptr(relocs + (i * sizeof(submit_reloc)));
                uint32_t iova, off;
                bool valid;
 
@@ -374,7 +369,7 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data,
        for (i = 0; i < args->nr_cmds; i++) {
                struct drm_msm_gem_submit_cmd submit_cmd;
                void __user *userptr =
-                       to_user_ptr(args->cmds + (i * sizeof(submit_cmd)));
+                       u64_to_user_ptr(args->cmds + (i * sizeof(submit_cmd)));
                struct msm_gem_object *msm_obj;
                uint32_t iova;
 
index 50220cab738c1d816f7f4117c2ae19baeb2561da..05b63a1e9f849e09a6b7e42f53348d2978c1290a 100644 (file)
 
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
 
+#define u64_to_user_ptr(x) (           \
+{                                      \
+       typecheck(u64, x);              \
+       (void __user *)(uintptr_t)x;    \
+}                                      \
+)
+
 /*
  * This looks more complex than it should be. But we need to
  * get the type for the ~ right in round_down (it needs to be