public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Osipenko <dmitry.osipenko@collabora.com>
To: "Ruhl, Michael J" <michael.j.ruhl@intel.com>,
	"Dmitry Osipenko" <digetx@gmail.com>,
	"Jani Nikula" <jani.nikula@linux.intel.com>,
	"Joonas Lahtinen" <joonas.lahtinen@linux.intel.com>,
	"Vivi, Rodrigo" <rodrigo.vivi@intel.com>,
	"Tvrtko Ursulin" <tvrtko.ursulin@linux.intel.com>,
	"Thomas Hellström" <thomas_os@shipmail.org>,
	"Christian König" <christian.koenig@amd.com>,
	"Chris Wilson" <chris@chris-wilson.co.uk>
Cc: "dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-media@vger.kernel.org" <linux-media@vger.kernel.org>,
	"linaro-mm-sig@lists.linaro.org" <linaro-mm-sig@lists.linaro.org>,
	"amd-gfx@lists.freedesktop.org" <amd-gfx@lists.freedesktop.org>,
	"intel-gfx@lists.freedesktop.org"
	<intel-gfx@lists.freedesktop.org>,
	"kernel@collabora.com" <kernel@collabora.com>,
	"virtualization@lists.linux-foundation.org" 
	<virtualization@lists.linux-foundation.org>,
	"linux-rdma@vger.kernel.org" <linux-rdma@vger.kernel.org>,
	"linux-arm-msm@vger.kernel.org" <linux-arm-msm@vger.kernel.org>,
	David Airlie <airlied@linux.ie>,
	Gerd Hoffmann <kraxel@redhat.com>,
	Gurchetan Singh <gurchetansingh@chromium.org>,
	Chia-I Wu <olvaffe@gmail.com>, Daniel Vetter <daniel@ffwll.ch>,
	Daniel Almeida <daniel.almeida@collabora.com>,
	Gert Wollny <gert.wollny@collabora.com>,
	Gustavo Padovan <gustavo.padovan@collabora.com>,
	Daniel Stone <daniel@fooishbar.org>,
	Tomeu Vizoso <tomeu.vizoso@collabora.com>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	Rob Clark <robdclark@gmail.com>,
	Sumit Semwal <sumit.semwal@linaro.org>,
	"Pan, Xinhui" <Xinhui.Pan@amd.com>,
	Thierry Reding <thierry.reding@gmail.com>,
	Tomasz Figa <tfiga@chromium.org>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Alex Deucher <alexander.deucher@amd.com>,
	Qiang Yu <yuq825@gmail.com>,
	Srinivas Kandagatla <srinivas.kandagatla@linaro.org>,
	Amol Maheshwari <amahesh@qti.qualcomm.com>,
	Jason Gunthorpe <jgg@ziepe.ca>, Leon Romanovsky <leon@kernel.org>,
	"Gross, Jurgen" <jgross@suse.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>,
	Tomi Valkeinen <tomba@kernel.org>,
	Russell King <linux@armlinux.org.uk>,
	Lucas Stach <l.stach@pengutronix.de>,
	Christian Gmeiner <christian.gmeiner@gmail.com>
Subject: Re: [PATCH v4 06/21] drm/i915: Prepare to dynamic dma-buf locking specification
Date: Fri, 9 Sep 2022 20:36:48 +0300	[thread overview]
Message-ID: <588ff12e-d030-0db0-e248-1afd0dee4ae1@collabora.com> (raw)
In-Reply-To: <DM5PR11MB1324EDC7A97DE98C2DC6EDA8C17A9@DM5PR11MB1324.namprd11.prod.outlook.com>

On 9/2/22 19:26, Ruhl, Michael J wrote:
>> 02.09.2022 13:31, Dmitry Osipenko пишет:
>>> 01.09.2022 17:02, Ruhl, Michael J пишет:
>>> ...
>>>>> --- a/drivers/gpu/drm/i915/gem/i915_gem_object.c
>>>>> +++ b/drivers/gpu/drm/i915/gem/i915_gem_object.c
>>>>> @@ -331,7 +331,19 @@ static void __i915_gem_free_objects(struct
>>>>> drm_i915_private *i915,
>>>>> 			continue;
>>>>> 		}
>>>>>
>>>>> +		/*
>>>>> +		 * dma_buf_unmap_attachment() requires reservation to be
>>>>> +		 * locked. The imported GEM shouldn't share reservation lock,
>>>>> +		 * so it's safe to take the lock.
>>>>> +		 */
>>>>> +		if (obj->base.import_attach)
>>>>> +			i915_gem_object_lock(obj, NULL);
>>>>
>>>> There is a lot of stuff going here.  Taking the lock may be premature...
>>>>
>>>>> 		__i915_gem_object_pages_fini(obj);
>>>>
>>>> The i915_gem_dmabuf.c:i915_gem_object_put_pages_dmabuf is where
>>>> unmap_attachment is actually called, would it make more sense to make
>>>> do the locking there?
>>>
>>> The __i915_gem_object_put_pages() is invoked with a held reservation
>>> lock, while freeing object is a special time when we know that GEM is
>>> unused.
>>>
>>> The __i915_gem_free_objects() was taking the lock two weeks ago until
>>> the change made Chris Wilson [1] reached linux-next.
>>>
>>> [1]
>>> https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-
>> next.git/commit/?id=2826d447fbd60e6a05e53d5f918bceb8c04e315c
>>>
>>> I don't think we can take the lock within
>>> i915_gem_object_put_pages_dmabuf(), it may/should deadlock other code
>> paths.
>>
>> On the other hand, we can check whether the GEM's refcount number is
>> zero in i915_gem_object_put_pages_dmabuf() and then take the lock if
>> it's zero.
>>
>> Also, seems it should be possible just to bail out from
>> i915_gem_object_put_pages_dmabuf() if refcount=0. The further
>> drm_prime_gem_destroy() will take care of unmapping. Perhaps this could
>> be the best option, I'll give it a test.
> 
> i915_gem_object_put_pages() is uses the SG, and the usage for
> drm_prim_gem_destroy()
> 
> from __i915_gem_free_objects() doesn't use the SG because it has been "freed"
> already, I am not sure if that would work...
> 
> Hmm.. with that in mind, maybe moving the base.import_attach check to 
> __i915_gem_object_put_pages with your attach check?

I see you meant __i915_gem_object_pages_fini() here.

> 	atomic_set(&obj->mm.pages_pin_count, 0);
> 	if (obj->base.import)
> 		i915_gem_object_lock(obj, NULL);
> 
> 	__i915_gem_object_put_pages(obj);
> 
> 	if (obj->base.import)
> 		i915_gem_object_unlock(obj, NULL);
> 	GEM_BUG_ON(i915_gem_object_has_pages(obj));
> 
> Pretty much one step up from the dmabuf interface, but we are guaranteed to
> not have any pinned pages?

Importer shouldn't hold pages outside of dma-buf API, otherwise it
should be a bug.

> The other caller of __i915_gem_object_pages_fini is the i915_ttm move_notify
> which should not conflict (export side, not import side).
> 
> Since it appears that not locking during the clean up is desirable, trying to make sure take the lock
> is taken at the last moment might be the right path?

Reducing the scope of locking usually is preferred more. Yours
suggestion works okay, I couldn't spot any problems at least for a
non-TTM code paths.

It's indeed a bit not nice that __i915_gem_object_pages_fini() is used
by TTM, but should be safe for imported objects. Will be great if anyone
from i915 maintainers could ack this variant.

-- 
Best regards,
Dmitry

  reply	other threads:[~2022-09-09 17:37 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-31 15:37 [PATCH v4 00/21] Move all drivers to a common dma-buf locking convention Dmitry Osipenko
2022-08-31 15:37 ` [PATCH v4 01/21] dma-buf: Add unlocked variant of vmapping functions Dmitry Osipenko
2022-08-31 15:37 ` [PATCH v4 02/21] dma-buf: Add unlocked variant of attachment-mapping functions Dmitry Osipenko
2022-08-31 15:37 ` [PATCH v4 03/21] drm/gem: Take reservation lock for vmap/vunmap operations Dmitry Osipenko
2022-08-31 15:37 ` [PATCH v4 04/21] drm/prime: Prepare to dynamic dma-buf locking specification Dmitry Osipenko
2022-09-01  6:42   ` Christian König
2022-08-31 15:37 ` [PATCH v4 05/21] drm/armada: " Dmitry Osipenko
2022-09-01  6:43   ` Christian König
2022-08-31 15:37 ` [PATCH v4 06/21] drm/i915: " Dmitry Osipenko
2022-09-01  6:45   ` Christian König
2022-09-01 10:44     ` Dmitry Osipenko
2022-09-01 14:02   ` Ruhl, Michael J
2022-09-02 10:31     ` Dmitry Osipenko
2022-09-02 10:38       ` Dmitry Osipenko
2022-09-02 16:26         ` Ruhl, Michael J
2022-09-09 17:36           ` Dmitry Osipenko [this message]
2022-08-31 15:37 ` [PATCH v4 07/21] drm/omapdrm: " Dmitry Osipenko
2022-09-01  6:45   ` [Linaro-mm-sig] " Christian König
2022-08-31 15:37 ` [PATCH v4 08/21] drm/tegra: " Dmitry Osipenko
2022-09-01  6:49   ` Christian König
2022-08-31 15:37 ` [PATCH v4 09/21] drm/etnaviv: " Dmitry Osipenko
2022-09-01  6:50   ` Christian König
2022-09-01 10:41     ` Dmitry Osipenko
2022-08-31 15:37 ` [PATCH v4 10/21] RDMA/umem: " Dmitry Osipenko
2022-09-01  6:54   ` Christian König
2022-08-31 15:37 ` [PATCH v4 11/21] misc: fastrpc: " Dmitry Osipenko
2022-09-01  6:55   ` Christian König
2022-09-02  9:31   ` Srinivas Kandagatla
2022-09-02  9:31   ` Srinivas Kandagatla
2022-08-31 15:37 ` [PATCH v4 12/21] xen/gntdev: " Dmitry Osipenko
2022-08-31 15:43   ` Juergen Gross
2022-09-01  7:04   ` Christian König
2022-08-31 15:37 ` [PATCH v4 13/21] media: videobuf2: " Dmitry Osipenko
2022-09-01  7:04   ` Christian König
2022-08-31 15:37 ` [PATCH v4 14/21] media: tegra-vde: " Dmitry Osipenko
2022-09-01  7:05   ` Christian König
2022-08-31 15:37 ` [PATCH v4 15/21] dma-buf: Move dma_buf_vmap() to dynamic " Dmitry Osipenko
2022-08-31 15:37 ` [PATCH v4 16/21] dma-buf: Move dma_buf_attach() " Dmitry Osipenko
2022-09-01  7:07   ` Christian König
2022-08-31 15:37 ` [PATCH v4 17/21] dma-buf: Move dma_buf_map_attachment() " Dmitry Osipenko
2022-09-01  7:08   ` Christian König
2022-08-31 15:37 ` [PATCH v4 18/21] dma-buf: Move dma_buf_mmap() " Dmitry Osipenko
2022-08-31 15:37 ` [PATCH v4 19/21] dma-buf: Document dynamic locking convention Dmitry Osipenko
2022-09-01  7:16   ` Christian König
2022-08-31 15:37 ` [PATCH v4 20/21] media: videobuf2: Stop using internal dma-buf lock Dmitry Osipenko
2022-09-01  7:46   ` Christian König
2022-08-31 15:37 ` [PATCH v4 21/21] dma-buf: Remove obsoleted internal lock Dmitry Osipenko
2022-09-01  7:46   ` Christian König
2022-09-01  7:49 ` [PATCH v4 00/21] Move all drivers to a common dma-buf locking convention Christian König
2022-09-01 10:47   ` Dmitry Osipenko

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=588ff12e-d030-0db0-e248-1afd0dee4ae1@collabora.com \
    --to=dmitry.osipenko@collabora.com \
    --cc=Xinhui.Pan@amd.com \
    --cc=airlied@linux.ie \
    --cc=alexander.deucher@amd.com \
    --cc=amahesh@qti.qualcomm.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=chris@chris-wilson.co.uk \
    --cc=christian.gmeiner@gmail.com \
    --cc=christian.koenig@amd.com \
    --cc=daniel.almeida@collabora.com \
    --cc=daniel@ffwll.ch \
    --cc=daniel@fooishbar.org \
    --cc=digetx@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gert.wollny@collabora.com \
    --cc=gurchetansingh@chromium.org \
    --cc=gustavo.padovan@collabora.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=jgg@ziepe.ca \
    --cc=jgross@suse.com \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=kernel@collabora.com \
    --cc=kraxel@redhat.com \
    --cc=l.stach@pengutronix.de \
    --cc=leon@kernel.org \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=m.szyprowski@samsung.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mchehab@kernel.org \
    --cc=michael.j.ruhl@intel.com \
    --cc=mripard@kernel.org \
    --cc=oleksandr_tyshchenko@epam.com \
    --cc=olvaffe@gmail.com \
    --cc=robdclark@gmail.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=srinivas.kandagatla@linaro.org \
    --cc=sstabellini@kernel.org \
    --cc=sumit.semwal@linaro.org \
    --cc=tfiga@chromium.org \
    --cc=thierry.reding@gmail.com \
    --cc=thomas_os@shipmail.org \
    --cc=tomba@kernel.org \
    --cc=tomeu.vizoso@collabora.com \
    --cc=tvrtko.ursulin@linux.intel.com \
    --cc=tzimmermann@suse.de \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=yuq825@gmail.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