[PATCH V3 1/5] vhost: factor out IOTLB

2020-02-19 Thread Jason Wang
This patch factors out IOTLB into a dedicated module in order to be
reused by other modules like vringh. User may choose to enable the
automatic retiring by specifying VHOST_IOTLB_FLAG_RETIRE flag to fit
for the case of vhost device IOTLB implementation.

Signed-off-by: Jason Wang 
---
 MAINTAINERS |   1 +
 drivers/vhost/Kconfig   |   7 ++
 drivers/vhost/Makefile  |   2 +
 drivers/vhost/net.c |   2 +-
 drivers/vhost/vhost.c   | 221 +++-
 drivers/vhost/vhost.h   |  36 ++
 drivers/vhost/vhost_iotlb.c | 171 
 include/linux/vhost_iotlb.h |  45 
 8 files changed, 304 insertions(+), 181 deletions(-)
 create mode 100644 drivers/vhost/vhost_iotlb.c
 create mode 100644 include/linux/vhost_iotlb.h

diff --git a/MAINTAINERS b/MAINTAINERS
index c74e4ea714a5..0fb645b5a7df 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -17768,6 +17768,7 @@ T:  git 
git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git
 S: Maintained
 F: drivers/vhost/
 F: include/uapi/linux/vhost.h
+F: include/linux/vhost_iotlb.h
 
 VIRTIO INPUT DRIVER
 M: Gerd Hoffmann 
diff --git a/drivers/vhost/Kconfig b/drivers/vhost/Kconfig
index 3d03ccbd1adc..eef634ff9a6e 100644
--- a/drivers/vhost/Kconfig
+++ b/drivers/vhost/Kconfig
@@ -36,6 +36,7 @@ config VHOST_VSOCK
 
 config VHOST
tristate
+   select VHOST_IOTLB
---help---
  This option is selected by any driver which needs to access
  the core of vhost.
@@ -54,3 +55,9 @@ config VHOST_CROSS_ENDIAN_LEGACY
  adds some overhead, it is disabled by default.
 
  If unsure, say "N".
+
+config VHOST_IOTLB
+   tristate
+   default m
+   help
+ Generic IOTLB implementation for vhost and vringh.
diff --git a/drivers/vhost/Makefile b/drivers/vhost/Makefile
index 6c6df24f770c..df99756fbb26 100644
--- a/drivers/vhost/Makefile
+++ b/drivers/vhost/Makefile
@@ -11,3 +11,5 @@ vhost_vsock-y := vsock.o
 obj-$(CONFIG_VHOST_RING) += vringh.o
 
 obj-$(CONFIG_VHOST)+= vhost.o
+
+obj-$(CONFIG_VHOST_IOTLB) += vhost_iotlb.o
diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index e158159671fa..e4a20d7a2921 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -1594,7 +1594,7 @@ static long vhost_net_reset_owner(struct vhost_net *n)
struct socket *tx_sock = NULL;
struct socket *rx_sock = NULL;
long err;
-   struct vhost_umem *umem;
+   struct vhost_iotlb *umem;
 
mutex_lock(&n->dev.mutex);
err = vhost_dev_check_owner(&n->dev);
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index f44340b41494..9059b95cac83 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -50,10 +50,6 @@ enum {
 #define vhost_used_event(vq) ((__virtio16 __user *)&vq->avail->ring[vq->num])
 #define vhost_avail_event(vq) ((__virtio16 __user *)&vq->used->ring[vq->num])
 
-INTERVAL_TREE_DEFINE(struct vhost_umem_node,
-rb, __u64, __subtree_last,
-START, LAST, static inline, vhost_umem_interval_tree);
-
 #ifdef CONFIG_VHOST_CROSS_ENDIAN_LEGACY
 static void vhost_disable_cross_endian(struct vhost_virtqueue *vq)
 {
@@ -581,21 +577,25 @@ long vhost_dev_set_owner(struct vhost_dev *dev)
 }
 EXPORT_SYMBOL_GPL(vhost_dev_set_owner);
 
-struct vhost_umem *vhost_dev_reset_owner_prepare(void)
+static struct vhost_iotlb *iotlb_alloc(void)
+{
+   return vhost_iotlb_alloc(max_iotlb_entries,
+VHOST_IOTLB_FLAG_RETIRE);
+}
+
+struct vhost_iotlb *vhost_dev_reset_owner_prepare(void)
 {
-   return kvzalloc(sizeof(struct vhost_umem), GFP_KERNEL);
+   return iotlb_alloc();
 }
 EXPORT_SYMBOL_GPL(vhost_dev_reset_owner_prepare);
 
 /* Caller should have device mutex */
-void vhost_dev_reset_owner(struct vhost_dev *dev, struct vhost_umem *umem)
+void vhost_dev_reset_owner(struct vhost_dev *dev, struct vhost_iotlb *umem)
 {
int i;
 
vhost_dev_cleanup(dev);
 
-   /* Restore memory to default empty mapping. */
-   INIT_LIST_HEAD(&umem->umem_list);
dev->umem = umem;
/* We don't need VQ locks below since vhost_dev_cleanup makes sure
 * VQs aren't running.
@@ -618,28 +618,6 @@ void vhost_dev_stop(struct vhost_dev *dev)
 }
 EXPORT_SYMBOL_GPL(vhost_dev_stop);
 
-static void vhost_umem_free(struct vhost_umem *umem,
-   struct vhost_umem_node *node)
-{
-   vhost_umem_interval_tree_remove(node, &umem->umem_tree);
-   list_del(&node->link);
-   kfree(node);
-   umem->numem--;
-}
-
-static void vhost_umem_clean(struct vhost_umem *umem)
-{
-   struct vhost_umem_node *node, *tmp;
-
-   if (!umem)
-   return;
-
-   list_for_each_entry_safe(node, tmp, &umem->umem_list, link)
-   vhost_umem_free(umem, node);
-
-   kvfree(umem);
-}
-
 static void vhost_clear_msg(struct vhost_dev *dev)
 {
struct vhost_msg_n

Re: [PATCH V3 1/5] vhost: factor out IOTLB

2020-02-19 Thread Randy Dunlap
On 2/19/20 7:56 PM, Jason Wang wrote:
> This patch factors out IOTLB into a dedicated module in order to be
> reused by other modules like vringh. User may choose to enable the
> automatic retiring by specifying VHOST_IOTLB_FLAG_RETIRE flag to fit
> for the case of vhost device IOTLB implementation.
> 
> Signed-off-by: Jason Wang 
> ---
>  MAINTAINERS |   1 +
>  drivers/vhost/Kconfig   |   7 ++
>  drivers/vhost/Makefile  |   2 +
>  drivers/vhost/net.c |   2 +-
>  drivers/vhost/vhost.c   | 221 +++-
>  drivers/vhost/vhost.h   |  36 ++
>  drivers/vhost/vhost_iotlb.c | 171 
>  include/linux/vhost_iotlb.h |  45 
>  8 files changed, 304 insertions(+), 181 deletions(-)
>  create mode 100644 drivers/vhost/vhost_iotlb.c
>  create mode 100644 include/linux/vhost_iotlb.h
> 

Hi,
Sorry if you have gone over this previously:

> diff --git a/drivers/vhost/Kconfig b/drivers/vhost/Kconfig
> index 3d03ccbd1adc..eef634ff9a6e 100644
> --- a/drivers/vhost/Kconfig
> +++ b/drivers/vhost/Kconfig
> @@ -36,6 +36,7 @@ config VHOST_VSOCK
>  
>  config VHOST
>   tristate
> + select VHOST_IOTLB
>   ---help---
> This option is selected by any driver which needs to access
> the core of vhost.
> @@ -54,3 +55,9 @@ config VHOST_CROSS_ENDIAN_LEGACY
> adds some overhead, it is disabled by default.
>  
> If unsure, say "N".
> +
> +config VHOST_IOTLB
> + tristate
> + default m

"default m" should not be needed. Just make whatever needs it select it.

> + help
> +   Generic IOTLB implementation for vhost and vringh.


-- 
~Randy

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


Re: [PATCH V3 1/5] vhost: factor out IOTLB

2020-02-19 Thread Jason Wang


On 2020/2/20 下午12:04, Randy Dunlap wrote:

On 2/19/20 7:56 PM, Jason Wang wrote:

This patch factors out IOTLB into a dedicated module in order to be
reused by other modules like vringh. User may choose to enable the
automatic retiring by specifying VHOST_IOTLB_FLAG_RETIRE flag to fit
for the case of vhost device IOTLB implementation.

Signed-off-by: Jason Wang 
---
  MAINTAINERS |   1 +
  drivers/vhost/Kconfig   |   7 ++
  drivers/vhost/Makefile  |   2 +
  drivers/vhost/net.c |   2 +-
  drivers/vhost/vhost.c   | 221 +++-
  drivers/vhost/vhost.h   |  36 ++
  drivers/vhost/vhost_iotlb.c | 171 
  include/linux/vhost_iotlb.h |  45 
  8 files changed, 304 insertions(+), 181 deletions(-)
  create mode 100644 drivers/vhost/vhost_iotlb.c
  create mode 100644 include/linux/vhost_iotlb.h


Hi,
Sorry if you have gone over this previously:



Thanks for the review, it's really helpful.





diff --git a/drivers/vhost/Kconfig b/drivers/vhost/Kconfig
index 3d03ccbd1adc..eef634ff9a6e 100644
--- a/drivers/vhost/Kconfig
+++ b/drivers/vhost/Kconfig
@@ -36,6 +36,7 @@ config VHOST_VSOCK
  
  config VHOST

tristate
+   select VHOST_IOTLB
---help---
  This option is selected by any driver which needs to access
  the core of vhost.
@@ -54,3 +55,9 @@ config VHOST_CROSS_ENDIAN_LEGACY
  adds some overhead, it is disabled by default.
  
  	  If unsure, say "N".

+
+config VHOST_IOTLB
+   tristate
+   default m

"default m" should not be needed. Just make whatever needs it select it.



Yes, will fix.

Thanks





+   help
+ Generic IOTLB implementation for vhost and vringh.




___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization