From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Chris Wilson <chris@chris-wilson.co.uk>, intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH 1/2] drm/i915/userptr: Probe existence of backing struct pages upon creation
Date: Thu, 9 Nov 2017 16:10:47 +0000 [thread overview]
Message-ID: <c6ff559a-e79d-aba9-a1b6-e37aa9159072@linux.intel.com> (raw)
In-Reply-To: <20171108185148.20081-1-chris@chris-wilson.co.uk>
On 08/11/2017 18:51, Chris Wilson wrote:
> Jason Ekstrand requested a more efficient method than userptr+set-domain
> to determine if the userptr object was backed by a complete set of pages
> upon creation. To be more efficient than simply populating the userptr
> using get_user_pages() (as done by the call to set-domain or execbuf),
> we can walk the tree of vm_area_struct and check for gaps or vma not
> backed by struct page (VM_PFNMAP). The question is how to handle
> VM_MIXEDMAP which may be either struct page or pfn backed...
First reaction is that it sounds like a bad idea. Well maybe not bad,
but a bit questionable since if the userspace doesn't know, then there
are no guarantees the result of probe will remain valid until the time
to actually instantiate the backing store comes.
The populate idea from the next patch sounds okay on the other hand. So
is there an use case where extremely controlling userspace would benefit
from probe rather than just using populate?
Regards,
Tvrtko
>
> Testcase: igt/gem_userptr_blits/probe
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> Cc: Michał Winiarski <michal.winiarski@intel.com>
> Cc: Jason Ekstrand <jason@jlekstrand.net>
> ---
> drivers/gpu/drm/i915/i915_gem_userptr.c | 38 +++++++++++++++++++++++++++++++++
> include/uapi/drm/i915_drm.h | 5 +++--
> 2 files changed, 41 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_gem_userptr.c b/drivers/gpu/drm/i915/i915_gem_userptr.c
> index e26b23171b56..dbc5818dd28b 100644
> --- a/drivers/gpu/drm/i915/i915_gem_userptr.c
> +++ b/drivers/gpu/drm/i915/i915_gem_userptr.c
> @@ -719,6 +719,33 @@ static const struct drm_i915_gem_object_ops i915_gem_userptr_ops = {
> .release = i915_gem_userptr_release,
> };
>
> +static int
> +probe_range(struct mm_struct *mm, unsigned long addr, unsigned long len)
> +{
> + const unsigned long end = addr + len;
> + struct vm_area_struct *vma;
> + int ret = -EFAULT;
> +
> + down_read(&mm->mmap_sem);
> + for (vma = find_vma(mm, addr); vma; vma = vma->vm_next) {
> + if (vma->vm_start > addr)
> + break;
> +
> + if (vma->vm_flags & (VM_PFNMAP | VM_MIXEDMAP))
> + break;
> +
> + if (vma->vm_end >= end) {
> + ret = 0;
> + break;
> + }
> +
> + addr = vma->vm_end;
> + }
> + up_read(&mm->mmap_sem);
> +
> + return ret;
> +}
> +
> /**
> * Creates a new mm object that wraps some normal memory from the process
> * context - user memory.
> @@ -771,6 +798,7 @@ i915_gem_userptr_ioctl(struct drm_device *dev, void *data, struct drm_file *file
> }
>
> if (args->flags & ~(I915_USERPTR_READ_ONLY |
> + I915_USERPTR_PROBE |
> I915_USERPTR_UNSYNCHRONIZED))
> return -EINVAL;
>
> @@ -788,6 +816,16 @@ i915_gem_userptr_ioctl(struct drm_device *dev, void *data, struct drm_file *file
> return -ENODEV;
> }
>
> + if (args->flags & I915_USERPTR_PROBE) {
> + /*
> + * Check that the range pointed to represents real struct
> + * pages and not iomappings (at this moment in time!)
> + */
> + ret = probe_range(current->mm, args->user_ptr, args->user_size);
> + if (ret)
> + return ret;
> + }
> +
> obj = i915_gem_object_alloc(dev_priv);
> if (obj == NULL)
> return -ENOMEM;
> diff --git a/include/uapi/drm/i915_drm.h b/include/uapi/drm/i915_drm.h
> index ac3c6503ca27..392ede2ca63e 100644
> --- a/include/uapi/drm/i915_drm.h
> +++ b/include/uapi/drm/i915_drm.h
> @@ -1352,8 +1352,9 @@ struct drm_i915_gem_userptr {
> __u64 user_ptr;
> __u64 user_size;
> __u32 flags;
> -#define I915_USERPTR_READ_ONLY 0x1
> -#define I915_USERPTR_UNSYNCHRONIZED 0x80000000
> +#define I915_USERPTR_READ_ONLY 0x1
> +#define I915_USERPTR_PROBE 0x2
> +#define I915_USERPTR_UNSYNCHRONIZED 0x80000000
> /**
> * Returned handle for the object.
> *
>
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2017-11-09 16:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-08 18:51 [PATCH 1/2] drm/i915/userptr: Probe existence of backing struct pages upon creation Chris Wilson
2017-11-08 18:51 ` [PATCH 2/2] drm/i915/userptr: Add a flag to populate the userptr on creation Chris Wilson
2017-11-08 19:05 ` Jason Ekstrand
2017-11-08 19:25 ` ✓ Fi.CI.BAT: success for series starting with [1/2] drm/i915/userptr: Probe existence of backing struct pages upon creation Patchwork
2017-11-08 20:49 ` ✓ Fi.CI.IGT: " Patchwork
2017-11-09 16:10 ` Tvrtko Ursulin [this message]
2017-11-09 16:22 ` [PATCH 1/2] " Chris Wilson
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=c6ff559a-e79d-aba9-a1b6-e37aa9159072@linux.intel.com \
--to=tvrtko.ursulin@linux.intel.com \
--cc=chris@chris-wilson.co.uk \
--cc=intel-gfx@lists.freedesktop.org \
/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.