[RFC 2/6] udmabuf: add ability to set access flags on udmabuf

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

Add creation time flags so the user has responsibility for
the specific use case.

Signed-off-by: Gurchetan Singh <gurchetansingh@xxxxxxxxxxxx>
---
 drivers/dma-buf/udmabuf.c    | 7 ++++++-
 include/uapi/linux/udmabuf.h | 5 ++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
index b345e91d831a..4ecf2a94fed3 100644
--- a/drivers/dma-buf/udmabuf.c
+++ b/drivers/dma-buf/udmabuf.c
@@ -186,7 +186,12 @@ static long udmabuf_create(const struct udmabuf_create_list *head,
 	exp_info.ops  = &udmabuf_ops;
 	exp_info.size = ubuf->pagecount << PAGE_SHIFT;
 	exp_info.priv = ubuf;
-	exp_info.flags = O_RDWR;
+
+	if ((head->flags & UDMABUF_FLAGS_PROT_READ) &&
+	    (head->flags & UDMABUF_FLAGS_PROT_WRITE))
+		exp_info.flags = O_RDWR;
+	else if (head->flags & UDMABUF_FLAGS_PROT_WRITE)
+		exp_info.flags = O_WRONLY;
 
 	buf = dma_buf_export(&exp_info);
 	if (IS_ERR(buf)) {
diff --git a/include/uapi/linux/udmabuf.h b/include/uapi/linux/udmabuf.h
index 46b6532ed855..21290cb9696c 100644
--- a/include/uapi/linux/udmabuf.h
+++ b/include/uapi/linux/udmabuf.h
@@ -5,7 +5,10 @@
 #include <linux/types.h>
 #include <linux/ioctl.h>
 
-#define UDMABUF_FLAGS_CLOEXEC	0x01
+#define UDMABUF_FLAGS_CLOEXEC    0x01
+#define UDMABUF_FLAGS_PROT_NONE  0x02
+#define UDMABUF_FLAGS_PROT_READ  0x04
+#define UDMABUF_FLAGS_PROT_WRITE 0x08
 
 struct udmabuf_create {
 	__u32 memfd;
-- 
2.17.1

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




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux