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/3] drm/i915: Only update the current userptr worker
Date: Wed, 01 Jul 2015 11:58:46 +0100 [thread overview]
Message-ID: <5593C7E6.9020101@linux.intel.com> (raw)
In-Reply-To: <20150701095959.GC17910@nuc-i3427.alporthouse.com>
On 07/01/2015 10:59 AM, Chris Wilson wrote:
> On Wed, Jul 01, 2015 at 10:48:59AM +0100, Tvrtko Ursulin wrote:
>>
>> On 06/30/2015 05:55 PM, Chris Wilson wrote:
>>> The userptr worker allows for a slight race condition where upon there
>>> may two or more threads calling get_user_pages for the same object. When
>>> we have the array of pages, then we serialise the update of the object.
>>> However, the worker should only overwrite the obj->userptr.work pointer
>>> if and only if it is the active one. Currently we clear it for a
>>> secondary worker with the effect that we may rarely force a second
>>> lookup.
>>
>> Secondary worker can fire only if invalidate clears the current one,
>> no? (if (obj->userptr.work == NULL && ...))
>>
>> It then "cancels" the worker so that the st_set_pages path is avoided.
>
> I may have overegged the changelog, but what I did not like here was
> that we would touch obj->userptr.work when we clearly had lost ownership
> of that field.
Yes that part makes sense.
>>> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
>>> ---
>>> drivers/gpu/drm/i915/i915_gem_userptr.c | 16 ++++++++--------
>>> 1 file changed, 8 insertions(+), 8 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/i915/i915_gem_userptr.c b/drivers/gpu/drm/i915/i915_gem_userptr.c
>>> index 7a5242cd5ea5..cb367d9f7909 100644
>>> --- a/drivers/gpu/drm/i915/i915_gem_userptr.c
>>> +++ b/drivers/gpu/drm/i915/i915_gem_userptr.c
>>> @@ -581,17 +581,17 @@ __i915_gem_userptr_get_pages_worker(struct work_struct *_work)
>>> }
>>>
>>> mutex_lock(&dev->struct_mutex);
>>> - if (obj->userptr.work != &work->work) {
>>> - ret = 0;
>>> - } else if (pinned == num_pages) {
>>> - ret = st_set_pages(&obj->pages, pvec, num_pages);
>>> - if (ret == 0) {
>>> - list_add_tail(&obj->global_list, &to_i915(dev)->mm.unbound_list);
>>> - pinned = 0;
>>> + if (obj->userptr.work == &work->work) {
>>> + if (pinned == num_pages) {
>>> + ret = st_set_pages(&obj->pages, pvec, num_pages);
>>> + if (ret == 0) {
>>> + list_add_tail(&obj->global_list, &to_i915(dev)->mm.unbound_list);
>>> + pinned = 0;
>>> + }
>>> }
>>> + obj->userptr.work = ERR_PTR(ret);
>>> }
>>>
>>> - obj->userptr.work = ERR_PTR(ret);
>>> obj->userptr.workers--;
>>> drm_gem_object_unreference(&obj->base);
>>> mutex_unlock(&dev->struct_mutex);
>>
>> Previously the canceled worker would allow another worker to be
>> created in case it failed (obj->userptr.work != &work->work; ret =
>> 0;) and now it still does since obj->userptr.work remains at NULL
>> from cancellation.
>>
>> Both seem wrong, am I missing the change?
>
> No, the obj->userptr.work must remain NULL until a new get_pages()
> because we don't actually know if this worker's gup was before or after
> the cancellation - mmap_sem vs struct_mutex ordering.
No one is not wrong, or no I was not missing the change?
I am thinking more and more that we should just mark it canceled forever
and not allow get_pages to succeed ever since.
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-01 10:58 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-29 10:59 [PATCH] tests/gem_userptr_blits: subtests for MAP_FIXED mappings of regular bo Michał Winiarski
2015-06-29 11:09 ` [PATCH] drm/i915: Fix userptr deadlock with MAP_FIXED Chris Wilson
2015-06-29 11:17 ` [PATCH v2] " Chris Wilson
2015-06-29 15:57 ` Michał Winiarski
2015-06-29 15:57 ` Michał Winiarski
2015-06-30 14:52 ` Tvrtko Ursulin
2015-06-30 14:52 ` [Intel-gfx] " Tvrtko Ursulin
2015-06-30 15:31 ` Chris Wilson
2015-06-30 15:47 ` Chris Wilson
2015-06-29 14:01 ` [PATCH] tests/gem_userptr_blits: subtests for MAP_FIXED mappings of regular bo Tvrtko Ursulin
2015-06-29 14:07 ` Chris Wilson
2015-06-29 14:15 ` Tvrtko Ursulin
2015-06-29 14:25 ` Chris Wilson
2015-06-29 14:56 ` Tvrtko Ursulin
2015-06-29 15:03 ` Chris Wilson
2015-06-30 15:01 ` [PATCH v2] tests/gem_userptr_blits: subtests for MAP_FIXED mappings of regular BO Michał Winiarski
2015-06-30 16:55 ` [PATCH 1/3] drm/i915: Only update the current userptr worker Chris Wilson
2015-06-30 16:55 ` [PATCH 2/3] drm/i915: Fix userptr deadlock with MAP_FIXED Chris Wilson
2015-07-01 11:14 ` Tvrtko Ursulin
2015-07-01 11:14 ` [Intel-gfx] " Tvrtko Ursulin
2015-07-01 11:29 ` Chris Wilson
2015-06-30 16:55 ` [PATCH 3/3] drm/i915: Use a task to cancel the userptr on invalidate_range Chris Wilson
2015-07-01 12:56 ` Tvrtko Ursulin
2015-07-03 11:00 ` Chris Wilson
2015-07-02 16:40 ` shuang.he
2015-07-03 11:03 ` [PATCH] " Chris Wilson
2015-07-01 9:48 ` [PATCH 1/3] drm/i915: Only update the current userptr worker Tvrtko Ursulin
2015-07-01 9:59 ` Chris Wilson
2015-07-01 10:58 ` Tvrtko Ursulin [this message]
2015-07-01 11:09 ` Chris Wilson
2015-07-01 12:26 ` Tvrtko Ursulin
2015-07-01 13:11 ` Chris Wilson
2015-07-03 10:48 ` Michał Winiarski
2015-07-03 10:53 ` Chris Wilson
-- strict thread matches above, loose matches on Subject: below --
2015-10-01 11:34 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=5593C7E6.9020101@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.