From: "Christian König" <christian.koenig@amd.com>
To: "T.J. Mercier" <tjmercier@google.com>,
Chris Wiseman <chriswiseman@google.com>,
Sumit Semwal <sumit.semwal@linaro.org>
Cc: John Stultz <jstultz@google.com>,
Benjamin Gaignard <benjamin.gaignard@collabora.com>,
Brian Starkey <Brian.Starkey@arm.com>,
Philipp Stanner <phasta@kernel.org>,
linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org,
linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH] dma-buf: system_heap: Reject private mappings in system_heap_mmap()
Date: Mon, 2 Nov 2026 12:09:23 +0100 [thread overview]
Message-ID: <a10ab532-1e9e-4a85-a79e-b712868889c8@amd.com> (raw)
In-Reply-To: <CABdmKX0YRmr0ovk7teNQdXdLmC2LKruT59EQarpDMFcxoOFcQg@mail.gmail.com>
On 10/31/26 02:44, T.J. Mercier wrote:
> On Fri, Oct 30, 2026 at 1:44 PM Chris Wiseman <chriswiseman@google.com> wrote:
>>
>> When commit 381295758792 ("dma-buf: system_heap: Rework system heap to
>> use sgtables instead of pagelists") stopped using heap_helpers.c and
>> added a custom system_heap_mmap(), the check rejecting private mappings
>> was dropped.
>>
>> Other exporters and buffer allocators reject private or copy-on-write
>> mappings in their mmap handlers: cma_heap_mmap() and mmap_udmabuf()
>> check that VM_SHARED or VM_MAYSHARE is set, and drm_gem_shmem_mmap()
>> and ttm_bo_mmap_obj() reject vma_is_cow_mapping(vma).
>>
>> However, system_heap_mmap() omits this check and calls remap_pfn_range()
>> even when userspace requests MAP_PRIVATE with PROT_WRITE. As a result,
>> subsequent CPU writes to a MAP_PRIVATE mapping of a system heap buffer
>> fault into do_wp_page() -> wp_page_copy(), silently allocating private
>> anonymous copy-on-write pages whose writes never reach the underlying
>> system heap buffer pages.
>>
>> Reject non-shared mappings in system_heap_mmap() with -EINVAL to match
>> cma_heap_mmap() and mmap_udmabuf().
>>
>> Fixes: 381295758792 ("dma-buf: system_heap: Rework system heap to use sgtables instead of pagelists")
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Chris Wiseman <chriswiseman@google.com>
>
> Reviewed-by: T.J. Mercier <tjmercier@google.com>
>
> I wonder if we should have this in dma_buf_mmap_internal() though. Any
> thoughts Sumit or Christian?
I do remember that this was once already discussed with Simona and a couple of others, but I don't remember what the outcome was.
On the other hand I can't think of a reason why anybody would want a private mapping with DMA-buf copy on write clearly won't work. Maybe for backward compatibility with broken userspace, not for a real use case.
I would say let's push this patch to drm-misc-fixes and apply another patch to drm-misc-next to enforce this for all DMA-bufs and see if anybody complains that this breaks userspace.
Should I push it to drm-misc-fixes or want somebody else take that?
Regards,
Christian.
prev parent reply other threads:[~2026-11-02 11:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-30 20:44 Chris Wiseman
2026-10-31 1:44 ` T.J. Mercier
2026-11-02 11:09 ` Christian König [this message]
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=a10ab532-1e9e-4a85-a79e-b712868889c8@amd.com \
--to=christian.koenig@amd.com \
--cc=Brian.Starkey@arm.com \
--cc=benjamin.gaignard@collabora.com \
--cc=chriswiseman@google.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=jstultz@google.com \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=phasta@kernel.org \
--cc=stable@vger.kernel.org \
--cc=sumit.semwal@linaro.org \
--cc=tjmercier@google.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
all inboxes | Powered by JetHome®