dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Maarten Lankhorst <maarten.lankhorst@canonical.com>
To: David Herrmann <dh.herrmann@gmail.com>
Cc: Thomas Hellstrom <thellstrom@vmware.com>,
	Martin Peres <martin.peres@labri.fr>,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	Ben Skeggs <bskeggs@redhat.com>,
	Alex Deucher <alexander.deucher@amd.com>,
	Dave Airlie <airlied@redhat.com>
Subject: Re: [PATCH v3 3/4] drm/ttm: convert to unified vma offset manager
Date: Fri, 19 Jul 2013 09:24:56 +0200	[thread overview]
Message-ID: <51E8E9C8.1040908@canonical.com> (raw)
In-Reply-To: <CANq1E4SNzPqp-g7Ryo+n+GwpcJHZaLQVTc3AvHEXCvhuz8465w@mail.gmail.com>

Op 18-07-13 22:54, David Herrmann schreef:
> Hi
>
> On Thu, Jul 18, 2013 at 1:24 PM, Thomas Hellstrom <thellstrom@vmware.com> wrote:
>> On 07/18/2013 01:07 PM, David Herrmann wrote:
>>> Hi
>>>
>>> On Thu, Jul 18, 2013 at 10:53 AM, Thomas Hellstrom
>>> <thellstrom@vmware.com> wrote:
>>>> A quick look, but not a full review:
>>>>
>>>> Looks mostly good, but it looks like the TTM vm lock isn't needed at all
>>>> anymore (provided the vma offset manager is properly protected), since
>>>> kref_get_unless_zero() is used when a reference after lookup is taken.
>>>> (please see the kref_get_unless_zero documentation examples). When
>>>> drm_vma_offset_remove() is called, the kref value is unconditionally
>>>> zero,
>>>> and that should block any successful lookup.
>>> If we drop vm_lock without modifying TTM, this will not work. Even
>>> kref_get_unless_zero() needs some guarantee that the object is still
>>> valid. Assume this scenario:
>>>
>>> drm_vma_offset_lookup() returns a valid node, however, before we call
>>> kref_get_*(), another thread destroys the last reference to the bo so
>>> it gets kfree()d. kref_get_unless_zero() will thus reference memory
>>> which can be _anything_ and is not guarantee to stay 0.
>>> (Documentation/kref.txt mentions this, too, and I guess it was you who
>>> wrote that).
>>>
>>> I cannot see any locking around the mmap call that could guarantee
>>> this except vm_lock.
>>
>> You're right. My apologies. Parental leave has taken its toll.
>>
>>
>>>> Otherwise, if the vma offset manager always needs external locking to
>>>> make
>>>> lookup + referencing atomic, then perhaps locking should be completely
>>>> left to the caller?
>>> I would actually prefer to keep it in the VMA manager. It allows some
>>> fast-paths which otherwise would need special semantics for the caller
>>> (for instance see the access-management patches which are based on
>>> this patchset or the reduced locking during setup/release). We'd also
>>> require the caller to use rwsems for good performance, which is not
>>> the case for gem.
>>>
>>> So how about Daniel's proposal to add an _unlocked() version and
>>> provide _lock_lookup() and _unlock_lookup() helpers which just wrap
>>> the read_lock() and read_unlock?
>>>
>>> Thanks!
>>> David
>>
>> I think that if there are good reasons to keep locking internal, I'm fine
>> with that, (And also, of course, with
>> Daniel's proposal). Currently the add / remove / lookup paths are mostly
>> used by TTM during object creation and
>> destruction.
>>
>> However, if the lookup path is ever used by pread / pwrite, that situation
>> might change and we would then like to
>> minimize the locking.
> I tried to keep the change as minimal as I could. Follow-up patches
> are welcome. I just thought pushing the lock into drm_vma_* would
> simplify things. If there are benchmarks that prove me wrong, I'll
> gladly spend some time optimizing that.
>
> Apart from this, I'd like to see someone ack the
> ttm_buffer_object_transfer() changes. I am not very confident with
> that. Everything else should be trivial.
>
The transfer object only exists to kill off the memory backing during asynchronous eviction,
by using the delayed destroyed mechanism. The re-initialization there looks correct to me.

~Maarten

  parent reply	other threads:[~2013-07-19  7:25 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-17 18:14 [PATCH v3 0/4] Unified VMA Offset Manager v3 David Herrmann
2013-07-17 18:14 ` [PATCH v3 1/4] drm: add unified vma offset manager David Herrmann
2013-07-17 18:14 ` [PATCH v3 2/4] drm/gem: convert to new unified vma manager David Herrmann
2013-07-18 19:01   ` Patrik Jakobsson
2013-07-17 18:14 ` [PATCH v3 3/4] drm/ttm: convert to unified vma offset manager David Herrmann
2013-07-18  8:53   ` Thomas Hellstrom
2013-07-18 11:02     ` Daniel Vetter
2013-07-18 11:07     ` David Herrmann
2013-07-18 11:24       ` Thomas Hellstrom
2013-07-18 20:54         ` David Herrmann
2013-07-19  2:03           ` Jerome Glisse
2013-07-19  7:24           ` Maarten Lankhorst [this message]
2013-07-19  9:13           ` Thomas Hellstrom
     [not found]             ` <CANq1E4SSLtezptzo18TD3fLG_zoRwR17kMxEi96-e957F5wL1A@mail.gmail.com>
2013-07-22 10:55               ` David Herrmann
2013-07-22 11:45                 ` Thomas Hellstrom
2013-07-17 18:14 ` [PATCH v3 4/4] drm/vma: provide drm_vma_node_unmap() helper David Herrmann
2013-07-23 12:47 ` [PATCH v4 0/4] Unified VMA Offset Manager David Herrmann
2013-07-23 12:47   ` [PATCH v4 1/4] drm: add unified vma offset manager David Herrmann
2013-07-24 15:35     ` Daniel Vetter
2013-07-24 16:10       ` David Herrmann
2013-07-24 19:06     ` [PATCH v5 " David Herrmann
2013-07-23 12:47   ` [PATCH v4 2/4] drm/gem: convert to new unified vma manager David Herrmann
2013-07-24 15:52     ` Daniel Vetter
2013-07-24 16:27       ` David Herrmann
2013-07-24 19:07     ` [PATCH v5 " David Herrmann
2013-07-23 12:47   ` [PATCH v4 3/4] drm/ttm: convert to unified vma offset manager David Herrmann
2013-07-24 15:57     ` Daniel Vetter
2013-07-24 19:08     ` [PATCH v5 " David Herrmann
2013-07-23 12:47   ` [PATCH v4 4/4] drm/vma: provide drm_vma_node_unmap() helper David Herrmann
2013-07-24 15:58     ` Daniel Vetter
2013-07-24 19:10     ` [PATCH v5 " David Herrmann

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=51E8E9C8.1040908@canonical.com \
    --to=maarten.lankhorst@canonical.com \
    --cc=airlied@redhat.com \
    --cc=alexander.deucher@amd.com \
    --cc=bskeggs@redhat.com \
    --cc=dh.herrmann@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=martin.peres@labri.fr \
    --cc=thellstrom@vmware.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox