From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: ankitprasad.r.sharma@intel.com, intel-gfx@lists.freedesktop.org
Cc: akash.goel@intel.com, shashidhar.hiremath@intel.com
Subject: Re: [PATCH 4/4] drm/i915: Support for pread/pwrite from/to non shmem backed objects
Date: Thu, 02 Jul 2015 11:42:44 +0100 [thread overview]
Message-ID: <559515A4.4040205@linux.intel.com> (raw)
In-Reply-To: <1435742747-3782-5-git-send-email-ankitprasad.r.sharma@intel.com>
On 07/01/2015 10:25 AM, ankitprasad.r.sharma@intel.com wrote:
> From: Ankitprasad Sharma <ankitprasad.r.sharma@intel.com>
>
> This patch adds support for extending the pread/pwrite functionality
> for objects not backed by shmem. The access will be made through
> gtt interface.
> This will cover prime objects as well as stolen memory backed objects
> but for userptr objects it is still forbidden.
>
> v2: drop locks around slow_user_access, prefault the pages before
> access (Chris)
>
> v3: Rebased to the latest drm-intel-nightly (Ankit)
>
> testcase: igt/gem_stolen
>
> Signed-off-by: Ankitprasad Sharma <ankitprasad.r.sharma@intel.com>
> ---
> drivers/gpu/drm/i915/i915_gem.c | 137 +++++++++++++++++++++++++++++++++++-----
> 1 file changed, 120 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
> index 4acf331..4be6eb4 100644
> --- a/drivers/gpu/drm/i915/i915_gem.c
> +++ b/drivers/gpu/drm/i915/i915_gem.c
> @@ -629,6 +629,102 @@ shmem_pread_slow(struct page *page, int shmem_page_offset, int page_length,
> return ret ? - EFAULT : 0;
> }
>
> +static inline int
> +slow_user_access(struct io_mapping *mapping,
> + loff_t page_base, int page_offset,
> + char __user *user_data,
> + int length, bool write)
> +{
> + void __iomem *vaddr_inatomic;
> + void *vaddr;
> + unsigned long unwritten;
> +
> + vaddr_inatomic = io_mapping_map_wc(mapping, page_base);
> + /* We can use the cpu mem copy function because this is X86. */
> + vaddr = (void __force *)vaddr_inatomic + page_offset;
> + if (write)
> + unwritten = __copy_from_user(vaddr, user_data, length);
> + else
> + unwritten = __copy_to_user(user_data, vaddr, length);
> +
> + io_mapping_unmap(vaddr_inatomic);
> + return unwritten;
> +}
I am not super familiar with low level mapping business. But it looks
correct to me. Just one question would be if there are any downsides to
WC mapping? If in the read case it would be any advantage not to ask for WC?
> +static int
> +i915_gem_gtt_pread_pwrite(struct drm_device *dev,
> + struct drm_i915_gem_object *obj, uint64_t size,
> + uint64_t data_offset, uint64_t data_ptr, bool write)
> +{
> + struct drm_i915_private *dev_priv = dev->dev_private;
> + char __user *user_data;
> + ssize_t remain;
> + loff_t offset, page_base;
> + int page_offset, page_length, ret = 0;
> +
> + ret = i915_gem_obj_ggtt_pin(obj, 0, PIN_MAPPABLE);
> + if (ret)
> + goto out;
> +
> + ret = i915_gem_object_set_to_gtt_domain(obj, write);
> + if (ret)
> + goto out_unpin;
> +
> + ret = i915_gem_object_put_fence(obj);
> + if (ret)
> + goto out_unpin;
> +
> + user_data = to_user_ptr(data_ptr);
> + remain = size;
Strictly speaking uint64_t can overflow ssize_t, compiler does not care
in this case?
> +
> + offset = i915_gem_obj_ggtt_offset(obj) + data_offset;
> +
> + if (write)
> + intel_fb_obj_invalidate(obj, ORIGIN_GTT);
> +
> + mutex_unlock(&dev->struct_mutex);
> + if (!write && likely(!i915.prefault_disable))
> + ret = fault_in_multipages_writeable(user_data, remain);
A bit confusing read/write inversion. :) But correct. Just wondering if
it would make sense to invert the boolean at least in slow_user_access.
Or in fact just call it pwrite instead of write to reflect pwrite ==
true is _reading_ from user memory.
> + while (remain > 0) {
> + /* Operation in this page
> + *
> + * page_base = page offset within aperture
> + * page_offset = offset within page
> + * page_length = bytes to copy for this page
> + */
> + page_base = offset & PAGE_MASK;
> + page_offset = offset_in_page(offset);
> + page_length = remain;
> + if ((page_offset + remain) > PAGE_SIZE)
> + page_length = PAGE_SIZE - page_offset;
It would save some arithmetics and branching to pull out the first
potentially unaligned copy out of the loop and then page_offset would be
zero for 2nd page onwards.
> + /* This is a slow read/write as it tries to read from
> + * and write to user memory which may result into page
> + * faults
> + */
> + ret = slow_user_access(dev_priv->gtt.mappable, page_base,
> + page_offset, user_data,
> + page_length, write);
> +
> + if (ret) {
> + ret = -EINVAL;
> + break;
> + }
> +
> + remain -= page_length;
> + user_data += page_length;
> + offset += page_length;
> + }
> +
> + mutex_lock(&dev->struct_mutex);
Caller had it interruptible.
> +
> +out_unpin:
> + i915_gem_object_ggtt_unpin(obj);
> +out:
> + return ret;
> +}
> +
> static int
> i915_gem_shmem_pread(struct drm_device *dev,
> struct drm_i915_gem_object *obj,
> @@ -752,17 +848,19 @@ i915_gem_pread_ioctl(struct drm_device *dev, void *data,
> goto out;
> }
>
> - /* prime objects have no backing filp to GEM pread/pwrite
> - * pages from.
> - */
> - if (!obj->base.filp) {
> - ret = -EINVAL;
> - goto out;
> - }
> -
> trace_i915_gem_object_pread(obj, args->offset, args->size);
>
> - ret = i915_gem_shmem_pread(dev, obj, args, file);
> + /* pread for non shmem backed objects */
> + if (!obj->base.filp) {
> + if (obj->tiling_mode == I915_TILING_NONE)
> + ret = i915_gem_gtt_pread_pwrite(dev, obj, args->size,
> + args->offset,
> + args->data_ptr,
> + false);
> + else
> + ret = -EINVAL;
> + } else
> + ret = i915_gem_shmem_pread(dev, obj, args, file);
Same coding style disagreement on whether or not both blocks should have
braces.
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2015-07-02 10:42 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-01 9:25 [PATCH v4 0/4] Support for creating/using Stolen memory backed objects ankitprasad.r.sharma
2015-07-01 9:25 ` [PATCH 1/4] drm/i915: Clearing buffer objects via blitter engine ankitprasad.r.sharma
2015-07-01 14:54 ` Tvrtko Ursulin
2015-07-01 16:30 ` Chris Wilson
2015-07-02 9:30 ` Tvrtko Ursulin
2015-07-02 9:50 ` Chris Wilson
2015-07-07 7:42 ` Ankitprasad Sharma
2015-07-07 8:46 ` Chris Wilson
2015-07-07 8:52 ` Ankitprasad Sharma
2015-07-01 9:25 ` [PATCH 2/4] drm/i915: Support for creating Stolen memory backed objects ankitprasad.r.sharma
2015-07-01 15:06 ` Tvrtko Ursulin
2015-07-01 16:19 ` Chris Wilson
2015-07-02 9:37 ` Tvrtko Ursulin
2015-07-02 9:43 ` Chris Wilson
2015-07-01 16:20 ` Tvrtko Ursulin
2015-07-01 9:25 ` [PATCH 3/4] drm/i915: Add support for stealing purgable stolen pages ankitprasad.r.sharma
2015-07-01 16:17 ` Tvrtko Ursulin
2015-07-01 9:25 ` [PATCH 4/4] drm/i915: Support for pread/pwrite from/to non shmem backed objects ankitprasad.r.sharma
2015-07-01 9:54 ` Chris Wilson
2015-07-02 10:42 ` Tvrtko Ursulin [this message]
2015-07-02 11:00 ` Chris Wilson
2015-07-02 11:27 ` Tvrtko Ursulin
2015-07-02 11:58 ` Chris Wilson
2015-07-03 5:07 ` shuang.he
-- strict thread matches above, loose matches on Subject: below --
2015-09-15 8:33 [PATCH v6 0/4] Support for creating/using Stolen memory " ankitprasad.r.sharma
2015-09-15 8:33 ` [PATCH 4/4] drm/i915: Support for pread/pwrite from/to non shmem " ankitprasad.r.sharma
2015-09-15 9:54 ` Chris Wilson
2015-09-15 10:35 ` Ankitprasad Sharma
2015-07-22 13:51 [PATCH v5 0/4] Support for creating/using Stolen memory " ankitprasad.r.sharma
2015-07-22 13:51 ` [PATCH 4/4] drm/i915: Support for pread/pwrite from/to non shmem " ankitprasad.r.sharma
2015-07-22 14:39 ` Chris Wilson
2015-07-31 13:16 ` Goel, Akash
2015-09-10 17:50 ` Ankitprasad Sharma
2015-09-15 9:58 ` Chris Wilson
2015-07-22 15:46 ` Tvrtko Ursulin
2015-07-22 16:05 ` Daniel Vetter
2015-07-22 16:17 ` Tvrtko Ursulin
2015-05-06 10:15 [PATCH v3 0/4] Support for creating/using Stolen memory " ankitprasad.r.sharma
2015-05-06 10:16 ` [PATCH 4/4] drm/i915: Support for pread/pwrite from/to non shmem " ankitprasad.r.sharma
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=559515A4.4040205@linux.intel.com \
--to=tvrtko.ursulin@linux.intel.com \
--cc=akash.goel@intel.com \
--cc=ankitprasad.r.sharma@intel.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=shashidhar.hiremath@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.