[dpdk-dev,RFC,v3,1/2] vhost: Add callback and private data for vhost PMD

Message ID 1445507150-1481-2-git-send-email-mukawa@igel.co.jp (mailing list archive)
State Superseded, archived
Headers

Commit Message

Tetsuya Mukawa Oct. 22, 2015, 9:45 a.m. UTC
  These variables are needed to be able to manage one of virtio devices
using both vhost library APIs and vhost PMD.
For example, if vhost PMD uses current callback handler and private data
provided by vhost library, A DPDK application that links vhost library
cannot use some of vhost library APIs. To avoid it, callback and private
data for vhost PMD are needed.

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_vhost/rte_virtio_net.h             |  3 ++
 lib/librte_vhost/vhost_user/virtio-net-user.c |  8 +++---
 lib/librte_vhost/virtio-net.c                 | 40 +++++++++++++++++++++++++--
 lib/librte_vhost/virtio-net.h                 |  3 +-
 4 files changed, 47 insertions(+), 7 deletions(-)
  

Comments

Tetsuya Mukawa Oct. 27, 2015, 6:12 a.m. UTC | #1
The patch introduces a new PMD. This PMD is implemented as thin wrapper
of librte_vhost. The patch will work on below patch series.
 - [PATCH v5 00/28] remove pci driver from vdevs

* Known issue.
We may see issues while handling RESET_OWNER message.
These handlings are done in vhost library, so not a part of vhost PMD.
So far, we are waiting for QEMU fixing.

PATCH v4 changes:
 - Support vhost multiple queues.
 - Rebase on "remove pci driver from vdevs".
 - Optimize RX/TX functions.
 - Fix resource leaks.
 - Fix compile issue.
 - Add patch to fix vhost library.

PATCH v3 changes:
 - Optimize performance.
   In RX/TX functions, change code to access only per core data.
 - Add below API to allow user to use vhost library APIs for a port managed
   by vhost PMD. There are a few limitations. See "rte_eth_vhost.h".
    - rte_eth_vhost_portid2vdev()
   To support this functionality, vhost library is also changed.
   Anyway, if users doesn't use vhost PMD, can fully use vhost library APIs.
 - Add code to support vhost multiple queues.
   Actually, multiple queues functionality is not enabled so far.

PATCH v2 changes:
 - Fix issues reported by checkpatch.pl
   (Thanks to Stephen Hemminger)


Tetsuya Mukawa (3):
  vhost: Fix wrong handling of virtqueue array index
  vhost: Add callback and private data for vhost PMD
  vhost: Add VHOST PMD

 config/common_linuxapp                        |   6 +
 doc/guides/nics/index.rst                     |   1 +
 doc/guides/nics/vhost.rst                     |  82 +++
 doc/guides/rel_notes/release_2_2.rst          |   2 +
 drivers/net/Makefile                          |   4 +
 drivers/net/vhost/Makefile                    |  62 +++
 drivers/net/vhost/rte_eth_vhost.c             | 765 ++++++++++++++++++++++++++
 drivers/net/vhost/rte_eth_vhost.h             |  65 +++
 drivers/net/vhost/rte_pmd_vhost_version.map   |   8 +
 lib/librte_vhost/rte_vhost_version.map        |   6 +
 lib/librte_vhost/rte_virtio_net.h             |   3 +
 lib/librte_vhost/vhost_user/virtio-net-user.c |  33 +-
 lib/librte_vhost/virtio-net.c                 |  61 +-
 lib/librte_vhost/virtio-net.h                 |   4 +-
 mk/rte.app.mk                                 |   8 +-
 15 files changed, 1085 insertions(+), 25 deletions(-)
 create mode 100644 doc/guides/nics/vhost.rst
 create mode 100644 drivers/net/vhost/Makefile
 create mode 100644 drivers/net/vhost/rte_eth_vhost.c
 create mode 100644 drivers/net/vhost/rte_eth_vhost.h
 create mode 100644 drivers/net/vhost/rte_pmd_vhost_version.map
  
Tetsuya Mukawa Oct. 27, 2015, 7:54 a.m. UTC | #2
Below patch has been submitted as a separate patch.

-  [dpdk-dev,1/3] vhost: Fix wrong handling of virtqueue array index
    (http://dpdk.org/dev/patchwork/patch/8038/)

Tetsuya

On 2015/10/27 15:12, Tetsuya Mukawa wrote:
> The patch introduces a new PMD. This PMD is implemented as thin wrapper
> of librte_vhost. The patch will work on below patch series.
>  - [PATCH v5 00/28] remove pci driver from vdevs
>
> * Known issue.
> We may see issues while handling RESET_OWNER message.
> These handlings are done in vhost library, so not a part of vhost PMD.
> So far, we are waiting for QEMU fixing.
>
> PATCH v4 changes:
>  - Support vhost multiple queues.
>  - Rebase on "remove pci driver from vdevs".
>  - Optimize RX/TX functions.
>  - Fix resource leaks.
>  - Fix compile issue.
>  - Add patch to fix vhost library.
>
> PATCH v3 changes:
>  - Optimize performance.
>    In RX/TX functions, change code to access only per core data.
>  - Add below API to allow user to use vhost library APIs for a port managed
>    by vhost PMD. There are a few limitations. See "rte_eth_vhost.h".
>     - rte_eth_vhost_portid2vdev()
>    To support this functionality, vhost library is also changed.
>    Anyway, if users doesn't use vhost PMD, can fully use vhost library APIs.
>  - Add code to support vhost multiple queues.
>    Actually, multiple queues functionality is not enabled so far.
>
> PATCH v2 changes:
>  - Fix issues reported by checkpatch.pl
>    (Thanks to Stephen Hemminger)
>
>
> Tetsuya Mukawa (3):
>   vhost: Fix wrong handling of virtqueue array index
>   vhost: Add callback and private data for vhost PMD
>   vhost: Add VHOST PMD
>
>  config/common_linuxapp                        |   6 +
>  doc/guides/nics/index.rst                     |   1 +
>  doc/guides/nics/vhost.rst                     |  82 +++
>  doc/guides/rel_notes/release_2_2.rst          |   2 +
>  drivers/net/Makefile                          |   4 +
>  drivers/net/vhost/Makefile                    |  62 +++
>  drivers/net/vhost/rte_eth_vhost.c             | 765 ++++++++++++++++++++++++++
>  drivers/net/vhost/rte_eth_vhost.h             |  65 +++
>  drivers/net/vhost/rte_pmd_vhost_version.map   |   8 +
>  lib/librte_vhost/rte_vhost_version.map        |   6 +
>  lib/librte_vhost/rte_virtio_net.h             |   3 +
>  lib/librte_vhost/vhost_user/virtio-net-user.c |  33 +-
>  lib/librte_vhost/virtio-net.c                 |  61 +-
>  lib/librte_vhost/virtio-net.h                 |   4 +-
>  mk/rte.app.mk                                 |   8 +-
>  15 files changed, 1085 insertions(+), 25 deletions(-)
>  create mode 100644 doc/guides/nics/vhost.rst
>  create mode 100644 drivers/net/vhost/Makefile
>  create mode 100644 drivers/net/vhost/rte_eth_vhost.c
>  create mode 100644 drivers/net/vhost/rte_eth_vhost.h
>  create mode 100644 drivers/net/vhost/rte_pmd_vhost_version.map
>
  
Thomas Monjalon Oct. 30, 2015, 6:30 p.m. UTC | #3
2015-10-27 16:54, Tetsuya Mukawa:
> Below patch has been submitted as a separate patch.
> 
> -  [dpdk-dev,1/3] vhost: Fix wrong handling of virtqueue array index
>     (http://dpdk.org/dev/patchwork/patch/8038/)

Please could you rebase only the two last patches?
Thanks

PS:
WARNING:TYPO_SPELLING: 'failuer' may be misspelled - perhaps 'failure'?
#606: FILE: drivers/net/vhost/rte_eth_vhost.c:272:
+               RTE_LOG(INFO, PMD, "failuer to find a ethdev\n");
WARNING:TYPO_SPELLING: 'accesing' may be misspelled - perhaps 'accessing'?
#612: FILE: drivers/net/vhost/rte_eth_vhost.c:278:
+       /* Wait until rx/tx_pkt_burst stops accesing vhost device */
  
Tetsuya Mukawa Nov. 2, 2015, 3:15 a.m. UTC | #4
On 2015/10/31 3:30, Thomas Monjalon wrote:
> 2015-10-27 16:54, Tetsuya Mukawa:
>> Below patch has been submitted as a separate patch.
>>
>> -  [dpdk-dev,1/3] vhost: Fix wrong handling of virtqueue array index
>>     (http://dpdk.org/dev/patchwork/patch/8038/)
> Please could you rebase only the two last patches?
> Thanks
>
> PS:
> WARNING:TYPO_SPELLING: 'failuer' may be misspelled - perhaps 'failure'?
> #606: FILE: drivers/net/vhost/rte_eth_vhost.c:272:
> +               RTE_LOG(INFO, PMD, "failuer to find a ethdev\n");
> WARNING:TYPO_SPELLING: 'accesing' may be misspelled - perhaps 'accessing'?
> #612: FILE: drivers/net/vhost/rte_eth_vhost.c:278:
> +       /* Wait until rx/tx_pkt_burst stops accesing vhost device */
>

Hi Thomas,

Thank you so much for checking my patches.
I have fixed a few typos, and rebased on latest tree (with Bernard's patch).
I will submit again soon.

Regards,
Tetsuya
  

Patch

diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h
index 93d3e27..ec84c9b 100644
--- a/lib/librte_vhost/rte_virtio_net.h
+++ b/lib/librte_vhost/rte_virtio_net.h
@@ -108,6 +108,7 @@  struct virtio_net {
 	uint32_t		virt_qp_nb;
 	uint32_t		mem_idx;	/** Used in set memory layout, unique for each queue within virtio device. */
 	void			*priv;		/**< private context */
+	void			*pmd_priv;	/**< private context for vhost PMD */
 } __rte_cache_aligned;
 
 /**
@@ -198,6 +199,8 @@  int rte_vhost_driver_unregister(const char *dev_name);
 
 /* Register callbacks. */
 int rte_vhost_driver_callback_register(struct virtio_net_device_ops const * const);
+/* Register callbacks for vhost PMD (Only for internal). */
+int rte_vhost_driver_pmd_callback_register(struct virtio_net_device_ops const * const);
 /* Start vhost driver session blocking loop. */
 int rte_vhost_driver_session_start(void);
 
diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c
index 6a12d96..a75697f 100644
--- a/lib/librte_vhost/vhost_user/virtio-net-user.c
+++ b/lib/librte_vhost/vhost_user/virtio-net-user.c
@@ -288,7 +288,7 @@  user_set_vring_kick(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
 
 	if (virtio_is_ready(dev) &&
 		!(dev->flags & VIRTIO_DEV_RUNNING))
-			notify_ops->new_device(dev);
+			notify_new_device(dev);
 }
 
 /*
@@ -302,7 +302,7 @@  user_get_vring_base(struct vhost_device_ctx ctx,
 
 	/* We have to stop the queue (virtio) if it is running. */
 	if (dev->flags & VIRTIO_DEV_RUNNING)
-		notify_ops->destroy_device(dev);
+		notify_destroy_device(dev);
 
 	/* Here we are safe to get the last used index */
 	ops->get_vring_base(ctx, state->index, state);
@@ -333,7 +333,7 @@  user_reset_owner(struct vhost_device_ctx ctx,
 
 	/* We have to stop the queue (virtio) if it is running. */
 	if (dev->flags & VIRTIO_DEV_RUNNING)
-		notify_ops->destroy_device(dev);
+		notify_destroy_device(dev);
 
 	RTE_LOG(INFO, VHOST_CONFIG,
 		"reset owner --- state idx:%d state num:%d\n", state->index, state->num);
@@ -379,7 +379,7 @@  user_destroy_device(struct vhost_device_ctx ctx)
 	uint32_t i;
 
 	if (dev && (dev->flags & VIRTIO_DEV_RUNNING))
-		notify_ops->destroy_device(dev);
+		notify_destroy_device(dev);
 
 	for (i = 0; i < dev->virt_qp_nb; i++)
 		if (dev && dev->mem_arr[i]) {
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index 3131719..eec3c22 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -64,6 +64,8 @@  struct virtio_net_config_ll {
 
 /* device ops to add/remove device to/from data core. */
 struct virtio_net_device_ops const *notify_ops;
+/* device ops for vhost PMD to add/remove device to/from data core. */
+struct virtio_net_device_ops const *pmd_notify_ops;
 /* root address of the linked list of managed virtio devices */
 static struct virtio_net_config_ll *ll_root;
 
@@ -84,6 +86,29 @@  static uint64_t VHOST_FEATURES = VHOST_SUPPORTED_FEATURES;
 
 static uint64_t VHOST_PROTOCOL_FEATURES = VHOST_SUPPORTED_PROTOCOL_FEATURES;
 
+int
+notify_new_device(struct virtio_net *dev)
+{
+	if ((pmd_notify_ops != NULL) && (pmd_notify_ops->new_device != NULL)) {
+		int ret = pmd_notify_ops->new_device(dev);
+		if (ret != 0)
+			return ret;
+	}
+	if ((notify_ops != NULL) && (notify_ops->new_device != NULL))
+		return notify_ops->new_device(dev);
+
+	return 0;
+}
+
+void
+notify_destroy_device(volatile struct virtio_net *dev)
+{
+	if ((pmd_notify_ops != NULL) && (pmd_notify_ops->destroy_device != NULL))
+		pmd_notify_ops->destroy_device(dev);
+	if ((notify_ops != NULL) && (notify_ops->destroy_device != NULL))
+		notify_ops->destroy_device(dev);
+}
+
 /*
  * Converts QEMU virtual address to Vhost virtual address. This function is
  * used to convert the ring addresses to our address space.
@@ -421,7 +446,7 @@  destroy_device(struct vhost_device_ctx ctx)
 			 * the function to remove it from the data core.
 			 */
 			if ((ll_dev_cur->dev.flags & VIRTIO_DEV_RUNNING))
-				notify_ops->destroy_device(&(ll_dev_cur->dev));
+				notify_destroy_device(&(ll_dev_cur->dev));
 			ll_dev_cur = rm_config_ll_entry(ll_dev_cur,
 					ll_dev_last);
 		} else {
@@ -884,7 +909,7 @@  set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
 				dev->virtqueue[VIRTIO_RXQ]->enabled = 1;
 				dev->virtqueue[VIRTIO_TXQ]->enabled = 1;
 			}
-			return notify_ops->new_device(dev);
+			return notify_new_device(dev);
 		}
 	/* Otherwise we remove it. */
 	} else
@@ -1006,3 +1031,14 @@  rte_vhost_driver_callback_register(struct virtio_net_device_ops const * const op
 
 	return 0;
 }
+
+/*
+ * Register ops so that we can add/remove device to data core.
+ */
+int
+rte_vhost_driver_pmd_callback_register(struct virtio_net_device_ops const * const ops)
+{
+	pmd_notify_ops = ops;
+
+	return 0;
+}
diff --git a/lib/librte_vhost/virtio-net.h b/lib/librte_vhost/virtio-net.h
index ef6efae..f92ed73 100644
--- a/lib/librte_vhost/virtio-net.h
+++ b/lib/librte_vhost/virtio-net.h
@@ -39,7 +39,8 @@ 
 
 #define VHOST_USER_PROTOCOL_F_VRING_FLAG 2
 
-struct virtio_net_device_ops const *notify_ops;
 struct virtio_net *get_device(struct vhost_device_ctx ctx);
 
+int notify_new_device(struct virtio_net *dev);
+void notify_destroy_device(volatile struct virtio_net *dev);
 #endif