From: "Christian König" <christian.koenig@amd.com>
To: Andi Shyti <andi.shyti@linux.intel.com>,
Sumit Semwal <sumit.semwal@linaro.org>
Cc: intel-gfx <intel-gfx@lists.freedesktop.org>,
Chris Wilson <chris.p.wilson@linux.intel.com>,
dri-devel <dri-devel@lists.freedesktop.org>,
linux-media@vger.kernel.org
Subject: Re: [Intel-gfx] [PATCH] dma-buf: Deny copy-on-writes mmaps
Date: Wed, 4 Oct 2023 16:16:12 +0200 [thread overview]
Message-ID: <d69ec998-b540-46b3-bc0c-9030ddebfef2@amd.com> (raw)
In-Reply-To: <20231003230332.513051-1-andi.shyti@linux.intel.com>
Am 04.10.23 um 01:03 schrieb Andi Shyti:
> From: Chris Wilson <chris.p.wilson@linux.intel.com>
>
> Enforce that an mmap of a dmabuf is always using MAP_SHARED so that all
> access (both read and writes) using the device memory and not a local
> copy-on-write page in system memory.
As much as I would like to do this I fear that this won't work.
First of all interesting approach to do this in .get_unmapped_area. The
standard handling is to have the check like "if
(is_cow_mapping(vma->vm_flags)) return -EINVAL;", see TTM for example.
Then IIRC we already tried this and had to revert it because it breaks
the UAPI. Some broken applications actually use shared mappings (but not
really cow) and we would like to keep them working.
Regards,
Christian.
>
> Signed-off-by: Chris Wilson <chris.p.wilson@linux.intel.com>
> Signed-off-by: Andi Shyti <andi.shyti@linux.intel.com>
> ---
> drivers/dma-buf/dma-buf.c | 15 +++++++++++++++
> 1 file changed, 15 insertions(+)
>
> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
> index 21916bba77d5..1ec297241842 100644
> --- a/drivers/dma-buf/dma-buf.c
> +++ b/drivers/dma-buf/dma-buf.c
> @@ -25,6 +25,7 @@
> #include <linux/poll.h>
> #include <linux/dma-resv.h>
> #include <linux/mm.h>
> +#include <linux/mman.h>
> #include <linux/mount.h>
> #include <linux/pseudo_fs.h>
>
> @@ -128,6 +129,19 @@ static struct file_system_type dma_buf_fs_type = {
> .kill_sb = kill_anon_super,
> };
>
> +static unsigned long
> +dma_buf_get_unmapped_area(struct file *file,
> + unsigned long addr,
> + unsigned long len,
> + unsigned long pgoff,
> + unsigned long flags)
> +{
> + if ((flags & MAP_TYPE) == MAP_PRIVATE)
> + return -EINVAL;
> +
> + return current->mm->get_unmapped_area(file, addr, len, pgoff, flags);
> +}
> +
> static int dma_buf_mmap_internal(struct file *file, struct vm_area_struct *vma)
> {
> struct dma_buf *dmabuf;
> @@ -508,6 +522,7 @@ static void dma_buf_show_fdinfo(struct seq_file *m, struct file *file)
>
> static const struct file_operations dma_buf_fops = {
> .release = dma_buf_file_release,
> + .get_unmapped_area = dma_buf_get_unmapped_area,
> .mmap = dma_buf_mmap_internal,
> .llseek = dma_buf_llseek,
> .poll = dma_buf_poll,
prev parent reply other threads:[~2023-10-04 14:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-03 23:03 [Intel-gfx] [PATCH] dma-buf: Deny copy-on-writes mmaps Andi Shyti
2023-10-04 0:02 ` [Intel-gfx] ✓ Fi.CI.BAT: success for " Patchwork
2023-10-04 2:14 ` [Intel-gfx] ✗ Fi.CI.IGT: failure " Patchwork
2023-10-04 3:54 ` [Intel-gfx] [PATCH] " kernel test robot
2023-10-04 14:16 ` 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=d69ec998-b540-46b3-bc0c-9030ddebfef2@amd.com \
--to=christian.koenig@amd.com \
--cc=andi.shyti@linux.intel.com \
--cc=chris.p.wilson@linux.intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=linux-media@vger.kernel.org \
--cc=sumit.semwal@linaro.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox