Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Christian König" <christian.koenig@amd.com>
To: "Dmitry Osipenko" <dmitry.osipenko@collabora.com>,
	"Thomas Hellström (Intel)" <thomas_os@shipmail.org>
Cc: "David Airlie" <airlied@linux.ie>,
	dri-devel@lists.freedesktop.org,
	virtualization@lists.linux-foundation.org,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Dmitry Osipenko" <digetx@gmail.com>,
	kernel@collabora.com, "Sumit Semwal" <sumit.semwal@linaro.org>,
	"Rob Herring" <robh@kernel.org>,
	"Mauro Carvalho Chehab" <mchehab@kernel.org>,
	"Daniel Stone" <daniel@fooishbar.org>,
	"Steven Price" <steven.price@arm.com>,
	"Gustavo Padovan" <gustavo.padovan@collabora.com>,
	"Alyssa Rosenzweig" <alyssa.rosenzweig@collabora.com>,
	linux-media@vger.kernel.org, intel-gfx@lists.freedesktop.org,
	"Maxime Ripard" <mripard@kernel.org>,
	linaro-mm-sig@lists.linaro.org,
	"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
	linux-tegra@vger.kernel.org,
	"Gurchetan Singh" <gurchetansingh@chromium.org>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	amd-gfx@lists.freedesktop.org,
	"Tomeu Vizoso" <tomeu.vizoso@collabora.com>,
	"Gert Wollny" <gert.wollny@collabora.com>,
	"Pan, Xinhui" <Xinhui.Pan@amd.com>,
	linux-kernel@vger.kernel.org, "Tomasz Figa" <tfiga@chromium.org>,
	"Qiang Yu" <yuq825@gmail.com>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"Alex Deucher" <alexander.deucher@amd.com>,
	"Robin Murphy" <robin.murphy@arm.com>,
	"Christian König" <christian.koenig@amd.com>,
	"Emil Velikov" <"emil.l.veli kov"@gmail.com>
Subject: Re: [Intel-gfx] [Linaro-mm-sig] Re: [PATCH v6 02/22] drm/gem: Move mapping of imported dma-bufs to drm_gem_mmap_obj()
Date: Mon, 4 Jul 2022 14:33:19 +0200	[thread overview]
Message-ID: <0335814b-dc11-4a54-9f24-bb4e9dbef35c@amd.com> (raw)
In-Reply-To: <467a1cee-ba8c-98f3-0398-2a7a5a90b5c3@collabora.com>

Am 30.06.22 um 01:06 schrieb Dmitry Osipenko:
> On 6/29/22 11:43, Thomas Hellström (Intel) wrote:
>> On 6/29/22 10:22, Dmitry Osipenko wrote:
>>> On 6/29/22 09:40, Thomas Hellström (Intel) wrote:
>>>> On 5/27/22 01:50, Dmitry Osipenko wrote:
>>>>> Drivers that use drm_gem_mmap() and drm_gem_mmap_obj() helpers don't
>>>>> handle imported dma-bufs properly, which results in mapping of
>>>>> something
>>>>> else than the imported dma-buf. For example, on NVIDIA Tegra we get a
>>>>> hard
>>>>> lockup when userspace writes to the memory mapping of a dma-buf that
>>>>> was
>>>>> imported into Tegra's DRM GEM.
>>>>>
>>>>> To fix this bug, move mapping of imported dma-bufs to
>>>>> drm_gem_mmap_obj().
>>>>> Now mmaping of imported dma-bufs works properly for all DRM drivers.
>>>> Same comment about Fixes: as in patch 1,
>>>>> Cc: stable@vger.kernel.org
>>>>> Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
>>>>> ---
>>>>>     drivers/gpu/drm/drm_gem.c              | 3 +++
>>>>>     drivers/gpu/drm/drm_gem_shmem_helper.c | 9 ---------
>>>>>     drivers/gpu/drm/tegra/gem.c            | 4 ++++
>>>>>     3 files changed, 7 insertions(+), 9 deletions(-)
>>>>>
>>>>> diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
>>>>> index 86d670c71286..7c0b025508e4 100644
>>>>> --- a/drivers/gpu/drm/drm_gem.c
>>>>> +++ b/drivers/gpu/drm/drm_gem.c
>>>>> @@ -1038,6 +1038,9 @@ int drm_gem_mmap_obj(struct drm_gem_object *obj,
>>>>> unsigned long obj_size,
>>>>>         if (obj_size < vma->vm_end - vma->vm_start)
>>>>>             return -EINVAL;
>>>>>     +    if (obj->import_attach)
>>>>> +        return dma_buf_mmap(obj->dma_buf, vma, 0);
>>>> If we start enabling mmaping of imported dma-bufs on a majority of
>>>> drivers in this way, how do we ensure that user-space is not blindly
>>>> using the object mmap without calling the needed DMA_BUF_IOCTL_SYNC
>>>> which is needed before and after cpu access of mmap'ed dma-bufs?
>>>>
>>>> I was under the impression (admittedly without looking) that the few
>>>> drivers that actually called into dma_buf_mmap() had some private
>>>> user-mode driver code in place that ensured this happened.
>>> Since it's a userspace who does the mapping, then it should be a
>>> responsibility of userspace to do all the necessary syncing.
>> Sure, but nothing prohibits user-space to ignore the syncing thinking
>> "It works anyway", testing those drivers where the syncing is a NOP. And
>> when a driver that finally needs syncing is tested it's too late to fix
>> all broken user-space.
>>
>>>    I'm not
>>> sure whether anyone in userspace really needs to map imported dma-bufs
>>> in practice. Nevertheless, this use-case is broken and should be fixed
>>> by either allowing to do the mapping or prohibiting it.
>>>
>> Then I'd vote for prohibiting it, at least for now. And for the future
>> moving forward we could perhaps revisit the dma-buf need for syncing,
>> requiring those drivers that actually need it to implement emulated
>> coherent memory which can be done not too inefficiently (vmwgfx being
>> one example).
> Alright, I'll change it to prohibit the mapping. This indeed should be a
> better option.

Oh, yes please. But I would expect that some people start screaming.

Over time I've got tons of TTM patches because people illegally tried to 
mmap() imported DMA-bufs in their driver.

Anyway this is probably the right thing to do and we can work on fixing 
the fallout later on.

Regards,
Christian.



  reply	other threads:[~2022-07-04 16:23 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20220526235040.678984-1-dmitry.osipenko@collabora.com>
     [not found] ` <20220526235040.678984-23-dmitry.osipenko@collabora.com>
2022-05-27 11:48   ` [Intel-gfx] [PATCH v6 22/22] drm/panfrost: Switch to generic memory shrinker Alyssa Rosenzweig
     [not found] ` <20220526235040.678984-15-dmitry.osipenko@collabora.com>
2022-05-30  6:50   ` [Intel-gfx] [PATCH v6 14/22] dma-buf: Introduce new locking convention Christian König
     [not found]     ` <e6e17c52-43c2-064b-500e-325bb3ba3b2c@collabora.com>
2022-05-30 13:41       ` Christian König
     [not found]         ` <7372dd1b-06f7-5336-4738-15f9b4d4d4b3@collabora.com>
2022-06-28 21:26           ` Thomas Hellström (Intel)
2022-07-01 10:43             ` Dmitry Osipenko
2022-07-04 22:38               ` Dmitry Osipenko
2022-07-05 10:52                 ` Dmitry Osipenko
     [not found] ` <20220526235040.678984-5-dmitry.osipenko@collabora.com>
2022-05-27 15:56   ` [Intel-gfx] [PATCH v6 04/22] drm/panfrost: Fix shrinker list corruption by madvise IOCTL Alyssa Rosenzweig
2022-05-30  9:41   ` Steven Price
     [not found] ` <20220526235040.678984-18-dmitry.osipenko@collabora.com>
2022-06-05 16:47   ` [Intel-gfx] [PATCH v6 17/22] drm/shmem-helper: Add generic memory shrinker Daniel Vetter
2022-06-05 18:32     ` Rob Clark
2022-06-05 18:45       ` Daniel Vetter
2022-06-19 17:53   ` Rob Clark
     [not found]     ` <3bb3dc53-69fc-8cdb-ae37-583b9b2660a3@collabora.com>
2022-06-20 15:18       ` Rob Clark
2022-06-24 20:23         ` Daniel Vetter
2022-06-24 20:21     ` Daniel Vetter
2022-06-20 15:37   ` Rob Clark
2022-06-21 16:39     ` Dmitry Osipenko
     [not found] ` <49cc6f0c-e90e-8edd-52e7-4188620e2c28@arm.com>
2022-06-28 12:50   ` [Intel-gfx] [PATCH v6 00/22] Add generic memory shrinker to VirtIO-GPU and Panfrost DRM drivers Dmitry Osipenko
2022-06-28 16:48     ` Rob Clark
2022-06-28 23:11       ` Dmitry Osipenko
2022-06-28 12:51   ` Dmitry Osipenko
2022-06-28 13:11   ` Dmitry Osipenko
     [not found] ` <20220526235040.678984-2-dmitry.osipenko@collabora.com>
2022-06-28 20:12   ` [Intel-gfx] [PATCH v6 01/22] drm/gem: Properly annotate WW context on drm_gem_lock_reservations() error Thomas Hellström (Intel)
2022-06-29  8:23     ` Dmitry Osipenko
     [not found] ` <20220526235040.678984-3-dmitry.osipenko@collabora.com>
2022-06-29  6:40   ` [Intel-gfx] [PATCH v6 02/22] drm/gem: Move mapping of imported dma-bufs to drm_gem_mmap_obj() Thomas Hellström (Intel)
2022-06-29  8:22     ` Dmitry Osipenko
2022-06-29  8:43       ` Thomas Hellström (Intel)
2022-06-29 23:06         ` Dmitry Osipenko
2022-07-04 12:33           ` Christian König [this message]
2022-07-04 22:44             ` [Intel-gfx] [Linaro-mm-sig] " Dmitry Osipenko
     [not found] ` <20220526235040.678984-9-dmitry.osipenko@collabora.com>
2022-06-29  6:43   ` [Intel-gfx] [PATCH v6 08/22] drm/virtio: Unlock reservations on dma_resv_reserve_fences() error Thomas Hellström (Intel)

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=0335814b-dc11-4a54-9f24-bb4e9dbef35c@amd.com \
    --to=christian.koenig@amd.com \
    --cc="emil.l.veli kov"@gmail.com \
    --cc=Xinhui.Pan@amd.com \
    --cc=airlied@linux.ie \
    --cc=alexander.deucher@amd.com \
    --cc=alyssa.rosenzweig@collabora.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=daniel.almeida@collabora.com \
    --cc=daniel@fooishbar.org \
    --cc=digetx@gmail.com \
    --cc=dmitry.osipenko@collabora.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=kernel@collabora.com \
    --cc=kraxel@redhat.com \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=mripard@kernel.org \
    --cc=robh@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=steven.price@arm.com \
    --cc=sumit.semwal@linaro.org \
    --cc=tfiga@chromium.org \
    --cc=thomas_os@shipmail.org \
    --cc=tomeu.vizoso@collabora.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