Re: [PATCH v3 6/9] xen/gntdev: Make private routines/structures accessible

2018-06-13 Thread Oleksandr Andrushchenko

On 06/13/2018 04:38 AM, Boris Ostrovsky wrote:



On 06/12/2018 09:41 AM, Oleksandr Andrushchenko wrote:

From: Oleksandr Andrushchenko 

This is in preparation for adding support of DMA buffer
functionality: make map/unmap related code and structures, used
privately by gntdev, ready for dma-buf extension, which will re-use
these. Rename corresponding structures as those become non-private
to gntdev now.

Signed-off-by: Oleksandr Andrushchenko 


---
  drivers/xen/gntdev-common.h |  86 +++
  drivers/xen/gntdev.c    | 132 
  2 files changed, 128 insertions(+), 90 deletions(-)
  create mode 100644 drivers/xen/gntdev-common.h

diff --git a/drivers/xen/gntdev-common.h b/drivers/xen/gntdev-common.h
new file mode 100644
index ..7a9845a6bee9
--- /dev/null
+++ b/drivers/xen/gntdev-common.h
@@ -0,0 +1,86 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+/*
+ * Common functionality of grant device.
+ *
+ * Copyright (c) 2006-2007, D G Murray.
+ *   (c) 2009 Gerd Hoffmann 
+ *   (c) 2018 Oleksandr Andrushchenko, EPAM Systems Inc.
+ */
+
+#ifndef _GNTDEV_COMMON_H
+#define _GNTDEV_COMMON_H
+
+#include 
+#include 
+#include 
+#include 
+
+struct gntdev_priv {
+    /* maps with visible offsets in the file descriptor */
+    struct list_head maps;
+    /* maps that are not visible; will be freed on munmap.
+ * Only populated if populate_freeable_maps == 1 */



Since you are touching this code please fix comment style.


I saw that while running checkpatch, but was not sure if I have to touch
those as they seemed to be not related to the change itself.
But I'll make sure all the comments are consistent.



+    struct list_head freeable_maps;
+    /* lock protects maps and freeable_maps */
+    struct mutex lock;
+    struct mm_struct *mm;
+    struct mmu_notifier mn;
+
+#ifdef CONFIG_XEN_GRANT_DMA_ALLOC
+    /* Device for which DMA memory is allocated. */
+    struct device *dma_dev;
+#endif
+};



With that fixed,

Reviewed-by: Boris Ostrovsky 


Thank you,
Oleksandr
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


Re: [PATCH v3 6/9] xen/gntdev: Make private routines/structures accessible

2018-06-13 Thread Boris Ostrovsky



On 06/12/2018 09:41 AM, Oleksandr Andrushchenko wrote:

From: Oleksandr Andrushchenko 

This is in preparation for adding support of DMA buffer
functionality: make map/unmap related code and structures, used
privately by gntdev, ready for dma-buf extension, which will re-use
these. Rename corresponding structures as those become non-private
to gntdev now.

Signed-off-by: Oleksandr Andrushchenko 
---
  drivers/xen/gntdev-common.h |  86 +++
  drivers/xen/gntdev.c| 132 
  2 files changed, 128 insertions(+), 90 deletions(-)
  create mode 100644 drivers/xen/gntdev-common.h

diff --git a/drivers/xen/gntdev-common.h b/drivers/xen/gntdev-common.h
new file mode 100644
index ..7a9845a6bee9
--- /dev/null
+++ b/drivers/xen/gntdev-common.h
@@ -0,0 +1,86 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+/*
+ * Common functionality of grant device.
+ *
+ * Copyright (c) 2006-2007, D G Murray.
+ *   (c) 2009 Gerd Hoffmann 
+ *   (c) 2018 Oleksandr Andrushchenko, EPAM Systems Inc.
+ */
+
+#ifndef _GNTDEV_COMMON_H
+#define _GNTDEV_COMMON_H
+
+#include 
+#include 
+#include 
+#include 
+
+struct gntdev_priv {
+   /* maps with visible offsets in the file descriptor */
+   struct list_head maps;
+   /* maps that are not visible; will be freed on munmap.
+* Only populated if populate_freeable_maps == 1 */



Since you are touching this code please fix comment style.



+   struct list_head freeable_maps;
+   /* lock protects maps and freeable_maps */
+   struct mutex lock;
+   struct mm_struct *mm;
+   struct mmu_notifier mn;
+
+#ifdef CONFIG_XEN_GRANT_DMA_ALLOC
+   /* Device for which DMA memory is allocated. */
+   struct device *dma_dev;
+#endif
+};



With that fixed,

Reviewed-by: Boris Ostrovsky 

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


[PATCH v3 6/9] xen/gntdev: Make private routines/structures accessible

2018-06-12 Thread Oleksandr Andrushchenko
From: Oleksandr Andrushchenko 

This is in preparation for adding support of DMA buffer
functionality: make map/unmap related code and structures, used
privately by gntdev, ready for dma-buf extension, which will re-use
these. Rename corresponding structures as those become non-private
to gntdev now.

Signed-off-by: Oleksandr Andrushchenko 
---
 drivers/xen/gntdev-common.h |  86 +++
 drivers/xen/gntdev.c| 132 
 2 files changed, 128 insertions(+), 90 deletions(-)
 create mode 100644 drivers/xen/gntdev-common.h

diff --git a/drivers/xen/gntdev-common.h b/drivers/xen/gntdev-common.h
new file mode 100644
index ..7a9845a6bee9
--- /dev/null
+++ b/drivers/xen/gntdev-common.h
@@ -0,0 +1,86 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+/*
+ * Common functionality of grant device.
+ *
+ * Copyright (c) 2006-2007, D G Murray.
+ *   (c) 2009 Gerd Hoffmann 
+ *   (c) 2018 Oleksandr Andrushchenko, EPAM Systems Inc.
+ */
+
+#ifndef _GNTDEV_COMMON_H
+#define _GNTDEV_COMMON_H
+
+#include 
+#include 
+#include 
+#include 
+
+struct gntdev_priv {
+   /* maps with visible offsets in the file descriptor */
+   struct list_head maps;
+   /* maps that are not visible; will be freed on munmap.
+* Only populated if populate_freeable_maps == 1 */
+   struct list_head freeable_maps;
+   /* lock protects maps and freeable_maps */
+   struct mutex lock;
+   struct mm_struct *mm;
+   struct mmu_notifier mn;
+
+#ifdef CONFIG_XEN_GRANT_DMA_ALLOC
+   /* Device for which DMA memory is allocated. */
+   struct device *dma_dev;
+#endif
+};
+
+struct gntdev_unmap_notify {
+   int flags;
+   /* Address relative to the start of the gntdev_grant_map */
+   int addr;
+   int event;
+};
+
+struct gntdev_grant_map {
+   struct list_head next;
+   struct vm_area_struct *vma;
+   int index;
+   int count;
+   int flags;
+   refcount_t users;
+   struct gntdev_unmap_notify notify;
+   struct ioctl_gntdev_grant_ref *grants;
+   struct gnttab_map_grant_ref   *map_ops;
+   struct gnttab_unmap_grant_ref *unmap_ops;
+   struct gnttab_map_grant_ref   *kmap_ops;
+   struct gnttab_unmap_grant_ref *kunmap_ops;
+   struct page **pages;
+   unsigned long pages_vm_start;
+
+#ifdef CONFIG_XEN_GRANT_DMA_ALLOC
+   /*
+* If dmabuf_vaddr is not NULL then this mapping is backed by DMA
+* capable memory.
+*/
+
+   struct device *dma_dev;
+   /* Flags used to create this DMA buffer: GNTDEV_DMA_FLAG_XXX. */
+   int dma_flags;
+   void *dma_vaddr;
+   dma_addr_t dma_bus_addr;
+   /* Needed to avoid allocation in gnttab_dma_free_pages(). */
+   xen_pfn_t *frames;
+#endif
+};
+
+struct gntdev_grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count,
+ int dma_flags);
+
+void gntdev_add_map(struct gntdev_priv *priv, struct gntdev_grant_map *add);
+
+void gntdev_put_map(struct gntdev_priv *priv, struct gntdev_grant_map *map);
+
+bool gntdev_account_mapped_pages(int count);
+
+int gntdev_map_grant_pages(struct gntdev_grant_map *map);
+
+#endif
diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c
index d6b79ad1cd6f..a09db23e9663 100644
--- a/drivers/xen/gntdev.c
+++ b/drivers/xen/gntdev.c
@@ -6,6 +6,7 @@
  *
  * Copyright (c) 2006-2007, D G Murray.
  *   (c) 2009 Gerd Hoffmann 
+ *   (c) 2018 Oleksandr Andrushchenko, EPAM Systems Inc.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -26,10 +27,6 @@
 #include 
 #include 
 #include 
-#include 
-#include 
-#include 
-#include 
 #include 
 #include 
 #include 
@@ -50,6 +47,8 @@
 #include 
 #include 
 
+#include "gntdev-common.h"
+
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Derek G. Murray , "
  "Gerd Hoffmann ");
@@ -65,73 +64,23 @@ static atomic_t pages_mapped = ATOMIC_INIT(0);
 static int use_ptemod;
 #define populate_freeable_maps use_ptemod
 
-struct gntdev_priv {
-   /* maps with visible offsets in the file descriptor */
-   struct list_head maps;
-   /* maps that are not visible; will be freed on munmap.
-* Only populated if populate_freeable_maps == 1 */
-   struct list_head freeable_maps;
-   /* lock protects maps and freeable_maps */
-   struct mutex lock;
-   struct mm_struct *mm;
-   struct mmu_notifier mn;
-
-#ifdef CONFIG_XEN_GRANT_DMA_ALLOC
-   /* Device for which DMA memory is allocated. */
-   struct device *dma_dev;
-#endif
-};
-
-struct unmap_notify {
-   int flags;
-   /* Address relative to the start of the grant_map */
-   int addr;
-   int event;
-};
-
-struct grant_map {
-   struct list_head next;
-   struct vm_area_struct *vma;
-   int index;
-   int count;
-   int flags;
-   refcount_t users;