diff mbox series

[RFC,3/6] udmabuf: enforce access flags

Message ID 20190801022517.1903-4-gurchetansingh@chromium.org (mailing list archive)
State New, archived
Headers show
Series udmabuf guest <--> host interaction model | expand

Commit Message

Gurchetan Singh Aug. 1, 2019, 2:25 a.m. UTC
Enforce the access flags that were added earlier.

Signed-off-by: Gurchetan Singh <gurchetansingh@chromium.org>
---
 drivers/dma-buf/udmabuf.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Gerd Hoffmann Aug. 1, 2019, 6:52 a.m. UTC | #1
>  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 ((vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) == 0)
>  		return -EINVAL;
>  
> +	if (ubuf->flags & UDMABUF_FLAGS_PROT_NONE)
> +		return -EINVAL;
> +
> +	if ((ubuf->flags & UDMABUF_FLAGS_PROT_READ) == 0)

"if ((vma->vm_flags & VM_READ) == 0)" ?

cheers,
  Gerd
diff mbox series

Patch

diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
index 4ecf2a94fed3..134e53d24c2b 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,10 +38,17 @@  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 ((vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) == 0)
 		return -EINVAL;
 
+	if (ubuf->flags & UDMABUF_FLAGS_PROT_NONE)
+		return -EINVAL;
+
+	if ((ubuf->flags & UDMABUF_FLAGS_PROT_READ) == 0)
+		vma->vm_page_prot = pgprot_writecombine(pgprot);
+
 	vma->vm_ops = &udmabuf_vm_ops;
 	vma->vm_private_data = ubuf;
 	return 0;
@@ -193,6 +201,7 @@  static long udmabuf_create(const struct udmabuf_create_list *head,
 	else if (head->flags & UDMABUF_FLAGS_PROT_WRITE)
 		exp_info.flags = O_WRONLY;
 
+	ubuf->flags = head->flags;
 	buf = dma_buf_export(&exp_info);
 	if (IS_ERR(buf)) {
 		ret = PTR_ERR(buf);