All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gurchetan Singh <gurchetansingh@chromium.org>
To: dri-devel@lists.freedesktop.org
Cc: Gurchetan Singh <gurchetansingh@chromium.org>,
	kraxel@redhat.com, hch@lst.de
Subject: [PATCH 2/5] udmabuf: allow userspace to set map attributes
Date: Mon, 25 Nov 2019 17:10:53 -0800	[thread overview]
Message-ID: <20191126011056.67928-2-gurchetansingh@chromium.org> (raw)
In-Reply-To: <20191126011056.67928-1-gurchetansingh@chromium.org>

The main use for udmabuf is sending guest memory pages
to the host.

It's generally a bad idea to have to separate mappings with
different attributes. For example, a WC mapping the guest
kernel and cached mapping on the host is problematic.

v2: Cache attribute flags instead of read/write flags (kraxel@)
---
 drivers/dma-buf/udmabuf.c    | 12 ++++++++++++
 include/uapi/linux/udmabuf.h |  2 ++
 2 files changed, 14 insertions(+)

diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
index b345e91d831a..ce9caaaa9e4b 100644
--- a/drivers/dma-buf/udmabuf.c
+++ b/drivers/dma-buf/udmabuf.c
@@ -16,6 +16,7 @@ static const u32    list_limit = 1024;  /* udmabuf_create_list->count limit */
 static const size_t size_limit_mb = 64; /* total dmabuf size, in megabytes  */
 
 struct udmabuf {
+	u32 flags;
 	pgoff_t pagecount;
 	struct page **pages;
 };
@@ -37,6 +38,12 @@ static const struct vm_operations_struct udmabuf_vm_ops = {
 static int mmap_udmabuf(struct dma_buf *buf, struct vm_area_struct *vma)
 {
 	struct udmabuf *ubuf = buf->priv;
+	pgprot_t pgprot = vm_get_page_prot(vma->vm_flags);
+
+	if (ubuf->flags & UDMABUF_FLAGS_WC)
+		vma->vm_page_prot = pgprot_writecombine(pgprot);
+	else if (ubuf->flags & UDMABUF_FLAGS_NONCACHED)
+		vma->vm_page_prot = pgprot_noncached(pgprot);
 
 	if ((vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) == 0)
 		return -EINVAL;
@@ -132,6 +139,10 @@ static long udmabuf_create(const struct udmabuf_create_list *head,
 	int seals, ret = -EINVAL;
 	u32 i, flags;
 
+	if ((head->flags & UDMABUF_FLAGS_NONCACHED) &&
+	    (head->flags & UDMABUF_FLAGS_WC))
+		return -EINVAL;
+
 	ubuf = kzalloc(sizeof(*ubuf), GFP_KERNEL);
 	if (!ubuf)
 		return -ENOMEM;
@@ -188,6 +199,7 @@ static long udmabuf_create(const struct udmabuf_create_list *head,
 	exp_info.priv = ubuf;
 	exp_info.flags = O_RDWR;
 
+	ubuf->flags = head->flags;
 	buf = dma_buf_export(&exp_info);
 	if (IS_ERR(buf)) {
 		ret = PTR_ERR(buf);
diff --git a/include/uapi/linux/udmabuf.h b/include/uapi/linux/udmabuf.h
index 46b6532ed855..f90831f2bb0d 100644
--- a/include/uapi/linux/udmabuf.h
+++ b/include/uapi/linux/udmabuf.h
@@ -6,6 +6,8 @@
 #include <linux/ioctl.h>
 
 #define UDMABUF_FLAGS_CLOEXEC	0x01
+#define UDMABUF_FLAGS_WC	0x02
+#define UDMABUF_FLAGS_NONCACHED 0x04
 
 struct udmabuf_create {
 	__u32 memfd;
-- 
2.24.0.432.g9d3f5f5b63-goog

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2019-11-26  1:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-26  1:10 [PATCH 1/5] udmabuf: use cache_sgt_mapping option Gurchetan Singh
2019-11-26  1:10 ` Gurchetan Singh [this message]
2019-11-28 11:48   ` [PATCH 2/5] udmabuf: allow userspace to set map attributes Gerd Hoffmann
2019-12-03  1:48     ` Gurchetan Singh
2019-11-26  1:10 ` [PATCH 3/5] udmabuf: add a pointer to the miscdevice in dma-buf private data Gurchetan Singh
2019-11-26  1:10 ` [PATCH 4/5] udmabuf: separate out creating/destroying scatter-table Gurchetan Singh
2019-11-26  1:10 ` [PATCH 5/5] udmabuf: implement begin_cpu_access/end_cpu_access hooks Gurchetan Singh

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=20191126011056.67928-2-gurchetansingh@chromium.org \
    --to=gurchetansingh@chromium.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hch@lst.de \
    --cc=kraxel@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.