All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Chris Wilson <chris@chris-wilson.co.uk>, intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm/i915/userptr: Probe vma range before gup
Date: Fri, 15 Dec 2017 09:43:47 +0000	[thread overview]
Message-ID: <17061494-9f98-6f6b-469f-682b40bea7d7@linux.intel.com> (raw)
In-Reply-To: <20171215092727.11504-1-chris@chris-wilson.co.uk>


On 15/12/2017 09:27, Chris Wilson wrote:
> We want to exclude any GGTT objects from being present on our internal
> lists to avoid the deadlock we may run into with our requirement for
> struct_mutex during invalidate. However, if the gup_fast fails, we put
> the userptr onto the workqueue and mark it as active, so that we
> remember to serialise the worker upon mmu_invalidate.
> 
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=104209
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> Cc: Michał Winiarski <michal.winiarski@intel.com>
> ---
>   drivers/gpu/drm/i915/i915_gem_userptr.c | 40 +++++++++++++++++++++++++++++++--
>   1 file changed, 38 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_gem_userptr.c b/drivers/gpu/drm/i915/i915_gem_userptr.c
> index 382a77a1097e..562b869dc750 100644
> --- a/drivers/gpu/drm/i915/i915_gem_userptr.c
> +++ b/drivers/gpu/drm/i915/i915_gem_userptr.c
> @@ -598,6 +598,39 @@ __i915_gem_userptr_get_pages_schedule(struct drm_i915_gem_object *obj)
>   	return ERR_PTR(-EAGAIN);
>   }
>   
> +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;
> +
> +		/*
> +		 * Exclude any VMA that is backed only by struct_page, i.e.
> +		 * IO regions that include our own GGTT mmaps. We cannot handle
> +		 * such ranges, as we may encounter deadlocks around our
> +		 * struct_mutex on mmu_invalidate_range.
> +		 */
> +		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;
> +}
> +
>   static int i915_gem_userptr_get_pages(struct drm_i915_gem_object *obj)
>   {
>   	const int num_pages = obj->base.size >> PAGE_SHIFT;
> @@ -632,9 +665,12 @@ static int i915_gem_userptr_get_pages(struct drm_i915_gem_object *obj)
>   			return -EAGAIN;
>   	}
>   
> -	pvec = NULL;
> -	pinned = 0;
> +	/* Quickly exclude any invalid VMA */
> +	pinned = probe_range(mm, obj->userptr.ptr, obj->base.size);
> +	if (pinned)
> +		return pinned;
>   
> +	pvec = NULL;
>   	if (mm == current->mm) {
>   		pvec = kvmalloc_array(num_pages, sizeof(struct page *),
>   				      GFP_KERNEL |
> 

Okay as a band-aid, but open to exploitation, which I think was my issue 
last time you posted something similar? Anyways.. it's not worse so 
lesson learnt, of some sort.

Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

Regards,

Tvrtko
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2017-12-15  9:43 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-15  9:27 [PATCH] drm/i915/userptr: Probe vma range before gup Chris Wilson
2017-12-15  9:43 ` Tvrtko Ursulin [this message]
2017-12-15  9:46 ` Chris Wilson
2017-12-15  9:49 ` ✓ Fi.CI.BAT: success for " Patchwork
2017-12-15  9:53 ` [PATCH v2] " Chris Wilson
2017-12-15 10:06   ` Chris Wilson
2017-12-15 10:09 ` [PATCH v3] " Chris Wilson
2017-12-15 10:49   ` Chris Wilson
2017-12-15 10:33 ` ✓ Fi.CI.BAT: success for drm/i915/userptr: Probe vma range before gup (rev3) Patchwork
2017-12-15 10:38 ` ✗ Fi.CI.IGT: warning for drm/i915/userptr: Probe vma range before gup Patchwork
2017-12-15 11:20 ` [PATCH v4] " Chris Wilson
2017-12-15 11:57 ` ✗ Fi.CI.IGT: failure for drm/i915/userptr: Probe vma range before gup (rev3) Patchwork
2017-12-15 12:22 ` ✓ Fi.CI.BAT: success for drm/i915/userptr: Probe vma range before gup (rev4) Patchwork
2017-12-15 14:33 ` ✗ Fi.CI.IGT: failure " Patchwork
2017-12-15 14:48 ` [PATCH v5] drm/i915/userptr: Probe vma range before gup Chris Wilson
2017-12-18 13:17   ` Tvrtko Ursulin
2017-12-15 15:36 ` ✓ Fi.CI.BAT: success for drm/i915/userptr: Probe vma range before gup (rev5) Patchwork
2017-12-15 18:09 ` ✓ Fi.CI.IGT: " Patchwork
2018-02-08 18:02 ` [PATCH v6] drm/i915/userptr: Probe vma range before gup Chris Wilson
2018-02-09  9:23   ` [PATCH v7] " Chris Wilson
2018-02-08 18:48 ` ✓ Fi.CI.BAT: success for drm/i915/userptr: Probe vma range before gup (rev6) Patchwork
2018-02-09  4:02 ` ✗ Fi.CI.IGT: failure " Patchwork
2018-02-09 14:06 ` ✗ Fi.CI.BAT: failure for drm/i915/userptr: Probe vma range before gup (rev7) Patchwork
2018-02-09 20:56 ` ✓ Fi.CI.BAT: success " Patchwork
2018-02-09 22:27 ` ✗ Fi.CI.IGT: warning " Patchwork

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=17061494-9f98-6f6b-469f-682b40bea7d7@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.