Skip to contentSkip to conversation

net/virtio: Virtio PMD rework

PATCH Applied Maxime Coquelin 6 participants 62 messages Jan 26, 2021 – Feb 1, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v4 cover net/virtio: Virtio PMD rework

This V3 fixes comments from Chenbo on patch 44 and implements the ABI exception in patch 2.

This series significantly rework Virtio PMD to improve the Virtio-user PMD and its backends integration.

First part of the series removes the dependency of Virtio-user ethdev on Virtio PCI, by creating generic files, adding per-bus meta data, ...

Main (if not single) functionnal change of this first part is to remove the hack for Virtio-user to work in IOVA as PA mode, this hack being very fragile.

Second part of the series reworks Virtio-user internal, by reworking the requests handling so that vDPA and Kernel backends no more hack into being Vhost-user backend. It implies implementing new ops for all the request types. Also, all the backend specific actions are moved from the virtio_user_dev.c and virtio_user_ethdev.c to their backend files.

Only functionnal change in this second part is making the Vhost-user server mode blocking at init time, as long as a client is not connected. The goal of this change is to make the Vhost-user support much more robust, as without blocking, the driver has to assume features that are going to be supported by the client, which is very fragile and error prone. As a side-effect, it also simplifies the logic nin several place of the virtio-user PMD.

Main changes in v4:
- Add ABI exception (David)
- Close FDs only up to max_queue_pairs
- virtio_user_dev_uninit_notify() to return void

Main changes in v3:
- Rename .intr_event to .intr_detect
- Rework last patch, properly clean allocated resources on failure.
- Rebase on top of latest net-next/main
- Minor typo fixes in comments and log improvements

Main changes in v2:
===================
- Introduce vdev driver flag for drivers to require IOVA VA mode
- Rebase on top of -rc1 changes
- Fix regressions introduced in V1 (vhost-kernel broken, vhost-user reconnect...)
- Various minor issues & typos fixed
- Fix status feature issue introduced in v20.11, only reproduceable now that server mode is made blocking
- Improve failure handling in Virtio-user
- Improve logging

Testing coverage (All passed)
=============================
- Virtio-pci PMD
* Virtio PMD in guest with Vhost-user backend in host
* Virtio PMD in guest with Vhost-kernel backend in host
- Virtio-user PMD with Vhost-user backend
* Vhost-user PMD server <-> Virtio-user client PMD IO loopback
* Vhost-user PMD client <-> Virtio-user server PMD IO loopback
* Vhost-user PMD client <-> Virtio-user server PMD reconnect
- Virtio-user PMD with Vhost-kernel backend
* iperf test case
* Txonly testpmd
- Virtio-user PMD with Vhost-vDPA backend
* vdpa-sim (IO loopback)
* CX-6 DX Kernel vDPA (Tx only)

Maxime Coquelin (44):
bus/vdev: add helper to get vdev from ethdev bus/vdev: add driver IOVA VA mode requirement net/virtio: fix getting old status on reconnect net/virtio: introduce Virtio bus type net/virtio: refactor virtio-user device net/virtio: introduce PCI device metadata net/virtio: move PCI device init in dedicated file net/virtio: move PCI specific dev init to PCI ethdev init net/virtio: move MSIX detection to PCI ethdev net/virtio: force IOVA as VA mode for Virtio-user net/virtio: store PCI type in Virtio device metadata net/virtio: add callback for device closing net/virtio: validate features at bus level net/virtio: remove bus type enum
net/virtio: move PCI-specific fields to PCI device net/virtio: pack virtio HW struct
net/virtio: move legacy IO to Virtio PCI net/virtio: introduce generic virtio header net/virtio: move features definition to generic header net/virtio: move virtqueue defines in generic header net/virtio: move config definitions to generic header net/virtio: make interrupt handling more generic net/virtio: move vring alignment to generic header net/virtio: remove last PCI refs in non-PCI code net/virtio: make Vhost-user request sender consistent net/virtio: add Virtio-user ops to set owner net/virtio: add Virtio-user features ops net/virtio: add Virtio-user protocol features ops net/virtio: add Virtio-user memory tables ops net/virtio: add Virtio-user vring setting ops net/virtio: add Virtio-user vring file ops net/virtio: add Virtio-user vring address ops net/virtio: add Virtio-user status ops net/virtio: remove useless request ops net/virtio: improve Virtio-user errors handling net/virtio: move Vhost-user requests to Vhost-user backend net/virtio: make server mode blocking net/virtio: move protocol features to Vhost-user net/virtio: introduce backend data
net/virtio: move Vhost-user specifics to its backend net/virtio: move Vhost-kernel data to its backend net/virtio: move Vhost-vDPA data to its backend net/virtio: improve Vhost-user error logging net/virtio: handle Virtio-user setup failure properly

 devtools/libabigail.abignore                  |   2 +
 drivers/bus/vdev/rte_bus_vdev.h               |   6 +
 drivers/bus/vdev/vdev.c                       |  29 +
 drivers/net/virtio/meson.build                |   6 +-
 drivers/net/virtio/virtio.c                   |  71 ++
 drivers/net/virtio/virtio.h                   | 246 +++++
 drivers/net/virtio/virtio_ethdev.c            | 457 +++------
 drivers/net/virtio/virtio_ethdev.h            |   6 +-
 drivers/net/virtio/virtio_pci.c               | 448 +++++----
 drivers/net/virtio/virtio_pci.h               | 286 +-----
 drivers/net/virtio/virtio_pci_ethdev.c        | 226 +++++
 drivers/net/virtio/virtio_ring.h              |   2 +-
 drivers/net/virtio/virtio_rxtx.c              |  90 +-
 drivers/net/virtio/virtio_rxtx_packed.h       |  10 +-
 drivers/net/virtio/virtio_rxtx_packed_avx.h   |  10 +-
 drivers/net/virtio/virtio_rxtx_packed_neon.h  |  10 +-
 drivers/net/virtio/virtio_rxtx_simple.h       |   3 +-
 drivers/net/virtio/virtio_user/vhost.h        |  79 +-
 drivers/net/virtio/virtio_user/vhost_kernel.c | 461 ++++++---
 .../net/virtio/virtio_user/vhost_kernel_tap.c |  25 +-
 .../net/virtio/virtio_user/vhost_kernel_tap.h |   1 +
 drivers/net/virtio/virtio_user/vhost_user.c   | 898 ++++++++++++++----
 drivers/net/virtio/virtio_user/vhost_vdpa.c   | 323 +++++--
 .../net/virtio/virtio_user/virtio_user_dev.c  | 573 ++++++-----
 .../net/virtio/virtio_user/virtio_user_dev.h  |  21 +-
 drivers/net/virtio/virtio_user_ethdev.c       | 301 +-----
 drivers/net/virtio/virtqueue.c                |   6 +-
 drivers/net/virtio/virtqueue.h                |  45 +-
 28 files changed, 2742 insertions(+), 1899 deletions(-)
 create mode 100644 drivers/net/virtio/virtio.c
 create mode 100644 drivers/net/virtio/virtio.h
 create mode 100644 drivers/net/virtio/virtio_pci_ethdev.c
Signature · 1 line
2.29.2
#1 lore raw

PATCH v4 1/44 bus/vdev: add helper to get vdev from ethdev

This patch adds an helper macro to get the rte_vdev_device pointer from a rte_eth_dev pointer.

This is similar to RTE_ETH_DEV_TO_PCI().

---
 drivers/bus/vdev/rte_bus_vdev.h | 2 ++
 1 file changed, 2 insertions(+)
drivers/bus/vdev/rte_bus_vdev.h +2 -0
index d14eeb41b0..f99a41f825 100644
@@ -34,6 +34,8 @@ struct rte_vdev_device {
 #define RTE_DEV_TO_VDEV_CONST(ptr) \
 	container_of(ptr, const struct rte_vdev_device, device)
 
+#define RTE_ETH_DEV_TO_VDEV(eth_dev)	RTE_DEV_TO_VDEV((eth_dev)->device)
+
 static inline const char *
 rte_vdev_device_name(const struct rte_vdev_device *dev)
 {
Signature · 1 line
2.29.2
#2 lore raw

PATCH v4 2/44 bus/vdev: add driver IOVA VA mode requirement

In reply to Maxime Coquelin

This patch adds driver flag in vdev bus driver so that vdev drivers can require VA IOVA mode to be used, which for example the case of Virtio-user PMD.

The patch implements the .get_iommu_class() callback, that is called before devices probing to determine the IOVA mode to be used, and adds a check right before the device is probed to ensure compatible IOVA mode has been selected.

It also adds a ABI exception rule to accommodate with an update on the driver registration API

---
 devtools/libabigail.abignore    |  2 ++
 drivers/bus/vdev/rte_bus_vdev.h |  4 ++++
 drivers/bus/vdev/vdev.c         | 29 +++++++++++++++++++++++++++++
 3 files changed, 35 insertions(+)
devtools/libabigail.abignore +2 -0
index 1dc84fa74b..170304c876 100644
@@ -11,6 +11,8 @@
 ; Explicit ignore for driver-only ABI
 [suppress_type]
         name = eth_dev_ops
+[suppress_function]
+        name_regexp = rte_vdev_(|un)register
 
 ; Ignore fields inserted in cacheline boundary of rte_cryptodev
 [suppress_type]
drivers/bus/vdev/rte_bus_vdev.h +4 -0
index f99a41f825..fc315d10fa 100644
@@ -113,8 +113,12 @@ struct rte_vdev_driver {
 	rte_vdev_remove_t *remove;       /**< Virtual device remove function. */
 	rte_vdev_dma_map_t *dma_map;     /**< Virtual device DMA map function. */
 	rte_vdev_dma_unmap_t *dma_unmap; /**< Virtual device DMA unmap function. */
+	uint32_t drv_flags;              /**< Flags RTE_VDEV_DRV_*. */
 };
 
+/** Device driver needs IOVA as VA and cannot work with IOVA as PA */
+#define RTE_VDEV_DRV_NEED_IOVA_AS_VA 0x0001
+
 /**
  * Register a virtual device driver.
  *
drivers/bus/vdev/vdev.c +29 -0
index acfd78828f..9a673347ae 100644
@@ -189,6 +189,7 @@ vdev_probe_all_drivers(struct rte_vdev_device *dev)
 {
 	const char *name;
 	struct rte_vdev_driver *driver;
+	enum rte_iova_mode iova_mode;
 	int ret;
 
 	if (rte_dev_is_probed(&dev->device))
@@ -199,6 +200,14 @@ vdev_probe_all_drivers(struct rte_vdev_device *dev)
 
 	if (vdev_parse(name, &driver))
 		return -1;
+
+	iova_mode = rte_eal_iova_mode();
+	if ((driver->drv_flags & RTE_VDEV_DRV_NEED_IOVA_AS_VA) && (iova_mode == RTE_IOVA_PA)) {
+		VDEV_LOG(ERR, "%s requires VA IOVA mode but current mode is PA, not initializing",
+				name);
+		return -1;
+	}
+
 	ret = driver->probe(dev);
 	if (ret == 0)
 		dev->device.driver = &driver->driver;
@@ -594,6 +603,25 @@ vdev_unplug(struct rte_device *dev)
 	return rte_vdev_uninit(dev->name);
 }
 
+static enum rte_iova_mode
+vdev_get_iommu_class(void)
+{
+	const char *name;
+	struct rte_vdev_device *dev;
+	struct rte_vdev_driver *driver;
+
+	TAILQ_FOREACH(dev, &vdev_device_list, next) {
+		name = rte_vdev_device_name(dev);
+		if (vdev_parse(name, &driver))
+			continue;
+
+		if (driver->drv_flags & RTE_VDEV_DRV_NEED_IOVA_AS_VA)
+			return RTE_IOVA_VA;
+	}
+
+	return RTE_IOVA_DC;
+}
+
 static struct rte_bus rte_vdev_bus = {
 	.scan = vdev_scan,
 	.probe = vdev_probe,
@@ -603,6 +631,7 @@ static struct rte_bus rte_vdev_bus = {
 	.parse = vdev_parse,
 	.dma_map = vdev_dma_map,
 	.dma_unmap = vdev_dma_unmap,
+	.get_iommu_class = vdev_get_iommu_class,
 	.dev_iterate = rte_vdev_dev_iterate,
 };
 
Signature · 1 line
2.29.2
Reviewed-by on v4 2/44
#3 lore raw

Re: [dpdk-dev] [PATCH v4 02/44] bus/vdev: add driver IOVA VA mode requirement

Quoted 124 lines

-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Tuesday, January 26, 2021 6:16 PM
To: [email protected]; Xia, Chenbo <[email protected]>; [email protected]; [email protected]; [email protected]
Cc: Maxime Coquelin <[email protected]>
Subject: [PATCH v4 02/44] bus/vdev: add driver IOVA VA mode requirement

This patch adds driver flag in vdev bus driver so that vdev drivers can require VA IOVA mode to be used, which for example the case of Virtio-user PMD.

The patch implements the .get_iommu_class() callback, that is called before devices probing to determine the IOVA mode to be used, and adds a check right before the device is probed to ensure compatible IOVA mode has been selected.

It also adds a ABI exception rule to accommodate with an update on the driver registration API

---
 devtools/libabigail.abignore    |  2 ++
 drivers/bus/vdev/rte_bus_vdev.h |  4 ++++
 drivers/bus/vdev/vdev.c         | 29 +++++++++++++++++++++++++++++
 3 files changed, 35 insertions(+)
devtools/libabigail.abignore +2 -0
index 1dc84fa74b..170304c876 100644
@@ -11,6 +11,8 @@
 ; Explicit ignore for driver-only ABI
 [suppress_type]
         name = eth_dev_ops
+[suppress_function]
+        name_regexp = rte_vdev_(|un)register
 
 ; Ignore fields inserted in cacheline boundary of rte_cryptodev
 [suppress_type]
drivers/bus/vdev/rte_bus_vdev.h +4 -0
index f99a41f825..fc315d10fa 100644
@@ -113,8 +113,12 @@ struct rte_vdev_driver {
 	rte_vdev_remove_t *remove;       /**< Virtual device remove function. */
 	rte_vdev_dma_map_t *dma_map;     /**< Virtual device DMA map function.
 */
 	rte_vdev_dma_unmap_t *dma_unmap; /**< Virtual device DMA unmap function.
 */
+	uint32_t drv_flags;              /**< Flags RTE_VDEV_DRV_*. */
 };
 
+/** Device driver needs IOVA as VA and cannot work with IOVA as PA */
+#define RTE_VDEV_DRV_NEED_IOVA_AS_VA 0x0001
+
 /**

* Register a virtual device driver.
*

drivers/bus/vdev/vdev.c +9 -0
index acfd78828f..9a673347ae 100644
@@ -189,6 +189,7 @@ vdev_probe_all_drivers(struct rte_vdev_device *dev)
 {
 	const char *name;
 	struct rte_vdev_driver *driver;
+	enum rte_iova_mode iova_mode;
 	int ret;
 
 	if (rte_dev_is_probed(&dev->device))
@@ -199,6 +200,14 @@ vdev_probe_all_drivers(struct rte_vdev_device *dev)
 
 	if (vdev_parse(name, &driver))
 		return -1;
+
+	iova_mode = rte_eal_iova_mode();
+	if ((driver->drv_flags & RTE_VDEV_DRV_NEED_IOVA_AS_VA) && (iova_mode ==
 RTE_IOVA_PA)) {
+		VDEV_LOG(ERR, "%s requires VA IOVA mode but current mode is PA,
 not initializing",
+				name);
+		return -1;
+	}
+
 	ret = driver->probe(dev);
drivers/bus/vdev/vdev.c +20 -1
 	if (ret == 0)
 		dev->device.driver = &driver->driver;
@@ -594,6 +603,25 @@ vdev_unplug(struct rte_device *dev)
 	return rte_vdev_uninit(dev->name);
 }
 
+static enum rte_iova_mode
+vdev_get_iommu_class(void)
+{
+	const char *name;
+	struct rte_vdev_device *dev;
+	struct rte_vdev_driver *driver;
+
+	TAILQ_FOREACH(dev, &vdev_device_list, next) {
+		name = rte_vdev_device_name(dev);
+		if (vdev_parse(name, &driver))
+			continue;
+
+		if (driver->drv_flags & RTE_VDEV_DRV_NEED_IOVA_AS_VA)
+			return RTE_IOVA_VA;
+	}
+
+	return RTE_IOVA_DC;
+}
+
 static struct rte_bus rte_vdev_bus = {
 	.scan = vdev_scan,
 	.probe = vdev_probe,
@@ -603,6 +631,7 @@ static struct rte_bus rte_vdev_bus = {
 	.parse = vdev_parse,
 	.dma_map = vdev_dma_map,
 	.dma_unmap = vdev_dma_unmap,
+	.get_iommu_class = vdev_get_iommu_class,
 	.dev_iterate = rte_vdev_dev_iterate,
 };
 
--
Quoted 1 line

2.29.2

#4 lore raw

Re: [dpdk-dev] [PATCH v4 02/44] bus/vdev: add driver IOVA VA mode requirement

In reply to Maxime Coquelin
Quoted 26 lines · Maxime Coquelin

This patch adds driver flag in vdev bus driver so that vdev drivers can require VA IOVA mode to be used, which for example the case of Virtio-user PMD.

The patch implements the .get_iommu_class() callback, that is called before devices probing to determine the IOVA mode to be used, and adds a check right before the device is probed to ensure compatible IOVA mode has been selected.

It also adds a ABI exception rule to accommodate with an update on the driver registration API

---
 devtools/libabigail.abignore    |  2 ++
 drivers/bus/vdev/rte_bus_vdev.h |  4 ++++
 drivers/bus/vdev/vdev.c         | 29 +++++++++++++++++++++++++++++
 3 files changed, 35 insertions(+)
devtools/libabigail.abignore +0 -0
index 1dc84fa74b..170304c876 100644

devtools/libabigail.abignore line 18

Quoted 8 lines
devtools/libabigail.abignore +2 -0
@@ -11,6 +11,8 @@
 ; Explicit ignore for driver-only ABI
 [suppress_type]
         name = eth_dev_ops
+[suppress_function]
+        name_regexp = rte_vdev_(|un)register
 
 ; Ignore fields inserted in cacheline boundary of rte_cryptodev
 [suppress_type]

Ray,
Are you okay with this exception?

Thanks.

Signature · 1 line
David Marchand
#5 lore raw

Re: [dpdk-dev] [PATCH v4 02/44] bus/vdev: add driver IOVA VA mode requirement

Quoted 34 lines · David Marchand
Quoted 32 lines · Maxime Coquelin

This patch adds driver flag in vdev bus driver so that vdev drivers can require VA IOVA mode to be used, which for example the case of Virtio-user PMD.

The patch implements the .get_iommu_class() callback, that is called before devices probing to determine the IOVA mode to be used, and adds a check right before the device is probed to ensure compatible IOVA mode has been selected.

It also adds a ABI exception rule to accommodate with an update on the driver registration API

---
 devtools/libabigail.abignore    |  2 ++
 drivers/bus/vdev/rte_bus_vdev.h |  4 ++++
 drivers/bus/vdev/vdev.c         | 29 +++++++++++++++++++++++++++++
 3 files changed, 35 insertions(+)
devtools/libabigail.abignore +2 -0
index 1dc84fa74b..170304c876 100644
@@ -11,6 +11,8 @@
 ; Explicit ignore for driver-only ABI
 [suppress_type]
         name = eth_dev_ops
+[suppress_function]
+        name_regexp = rte_vdev_(|un)register
 
Quoted 5 lines

devtools/libabigail.abignore line 18

Quoted 2 lines
devtools/libabigail.abignore +0 -0
 ; Ignore fields inserted in cacheline boundary of rte_cryptodev
 [suppress_type]

Ray,
Are you okay with this exception?

Ask a perhaps silly question,
shouldn't rte_vdev_register & rte_vdev_unregister have been INTERNAL in any case?

Quoted 2 lines

Thanks.

Ray K

#6 lore raw

Re: [dpdk-dev] [PATCH v4 02/44] bus/vdev: add driver IOVA VA mode requirement

Quoted 11 lines · Ray
Quoted 11 lines
Quoted 11 lines
devtools/libabigail.abignore +2 -0
index 1dc84fa74b..170304c876 100644
@@ -11,6 +11,8 @@
 ; Explicit ignore for driver-only ABI
 [suppress_type]
         name = eth_dev_ops
+[suppress_function]
+        name_regexp = rte_vdev_(|un)register
 
Quoted 8 lines
Quoted 5 lines

devtools/libabigail.abignore line 18

Quoted 2 lines
devtools/libabigail.abignore +0 -0
 ; Ignore fields inserted in cacheline boundary of rte_cryptodev
 [suppress_type]

Ray,
Are you okay with this exception?

Ask a perhaps silly question,
shouldn't rte_vdev_register & rte_vdev_unregister have been INTERNAL in any case?

I discussed with Thomas earlier.

The INTERNAL exception rule we have suppresses changes on symbols already versioned INTERNAL.
If we mark these two symbols INTERNAL now, they are part of the stable v21 ABI in any case.
libabigail will still complain about them disappearing.

$ abidiff --suppr
/home/dmarchan/dpdk/devtools/../devtools/libabigail.abignore
--no-added-syms --headers-dir1
/home/dmarchan/abi/v20.11/build-gcc-shared/usr/local/include
--headers-dir2 /home/dmarchan/builds/build-gcc-shared/install/usr/local/include
/home/dmarchan/abi/v20.11/build-gcc-shared/dump/librte_bus_vdev.dump
/home/dmarchan/builds/build-gcc-shared/install/dump/librte_bus_vdev.dump
Functions changes summary: 2 Removed, 0 Changed, 0 Added functions
Variables changes summary: 0 Removed, 0 Changed, 0 Added variable

2 Removed functions:

[D] 'function void rte_vdev_register(rte_vdev_driver*)'
{rte_vdev_register@@DPDK_21}
[D] 'function void rte_vdev_unregister(rte_vdev_driver*)'
{rte_vdev_unregister@@DPDK_21}

We will need an exception in any case for them.

Signature · 1 line
David Marchand
#7 lore raw

Re: [dpdk-dev] [PATCH v4 02/44] bus/vdev: add driver IOVA VA mode requirement

Quoted 39 lines · David Marchand
Quoted 11 lines · Ray
Quoted 11 lines
Quoted 11 lines
devtools/libabigail.abignore +2 -0
index 1dc84fa74b..170304c876 100644
@@ -11,6 +11,8 @@
 ; Explicit ignore for driver-only ABI
 [suppress_type]
         name = eth_dev_ops
+[suppress_function]
+        name_regexp = rte_vdev_(|un)register
 
Quoted 8 lines
Quoted 5 lines

devtools/libabigail.abignore line 18

Quoted 2 lines
devtools/libabigail.abignore +0 -0
 ; Ignore fields inserted in cacheline boundary of rte_cryptodev
 [suppress_type]

Ray,
Are you okay with this exception?

Ask a perhaps silly question,
shouldn't rte_vdev_register & rte_vdev_unregister have been INTERNAL in any case?

I discussed with Thomas earlier.

The INTERNAL exception rule we have suppresses changes on symbols already versioned INTERNAL.
If we mark these two symbols INTERNAL now, they are part of the stable v21 ABI in any case.
libabigail will still complain about them disappearing.

$ abidiff --suppr
/home/dmarchan/dpdk/devtools/../devtools/libabigail.abignore
--no-added-syms --headers-dir1
/home/dmarchan/abi/v20.11/build-gcc-shared/usr/local/include
--headers-dir2 /home/dmarchan/builds/build-gcc-shared/install/usr/local/include
/home/dmarchan/abi/v20.11/build-gcc-shared/dump/librte_bus_vdev.dump
/home/dmarchan/builds/build-gcc-shared/install/dump/librte_bus_vdev.dump
Functions changes summary: 2 Removed, 0 Changed, 0 Added functions
Variables changes summary: 0 Removed, 0 Changed, 0 Added variable
Quoted 9 lines

2 Removed functions:

[D] 'function void rte_vdev_register(rte_vdev_driver*)'
{rte_vdev_register@@DPDK_21}
[D] 'function void rte_vdev_unregister(rte_vdev_driver*)'
{rte_vdev_unregister@@DPDK_21}

We will need an exception in any case for them.

Agreed, I didn't miss that are still going to need the exception.

If we agree that everything that is in rte_vdev_bus should be internal. We can also fix that, while we are aware of it.

The rule above gets my +1 and I will fix rte_vdev_bus.

#8 lore raw

Re: [dpdk-dev] [PATCH v4 02/44] bus/vdev: add driver IOVA VA mode requirement

In reply to Maxime Coquelin
Quoted 10 lines · Maxime Coquelin

This patch adds driver flag in vdev bus driver so that vdev drivers can require VA IOVA mode to be used, which for example the case of Virtio-user PMD.

The patch implements the .get_iommu_class() callback, that is called before devices probing to determine the IOVA mode to be used, and adds a check right before the device is probed to ensure compatible IOVA mode has been selected.

Quoted 5 lines

It also adds a ABI exception rule to accommodate with an update on the driver registration API

I only suggested some changes.
This patch looks good to me.
Can you change this Sob as a Acked-by?

Thanks Maxime.

Signature · 1 line
David Marchand
#9 lore raw

Re: [dpdk-dev] [PATCH v4 02/44] bus/vdev: add driver IOVA VA mode requirement

Quoted 15 lines · David Marchand
Quoted 13 lines · Maxime Coquelin

This patch adds driver flag in vdev bus driver so that vdev drivers can require VA IOVA mode to be used, which for example the case of Virtio-user PMD.

The patch implements the .get_iommu_class() callback, that is called before devices probing to determine the IOVA mode to be used, and adds a check right before the device is probed to ensure compatible IOVA mode has been selected.

It also adds a ABI exception rule to accommodate with an update on the driver registration API

Quoted 6 lines
Quoted 2 lines

I only suggested some changes.
This patch looks good to me.
Can you change this Sob as a Acked-by?

Sure, I can do that.

Thanks!
Maxime

Quoted 2 lines

Thanks Maxime.

#10 lore raw

PATCH v4 3/44 net/virtio: fix getting old status on reconnect

In reply to Maxime Coquelin

This patch fixes getting reset status from the restarted vhost-user backend in case of reconnection, instead of the status at the time of the disconnection.

This issue was not spotted earlier because Vhost-user protocol status feature was disabled in server mode.

Fixes 47235f16505f ("net/virtio-user: set status on socket reconnect")
---
 drivers/net/virtio/virtio_user_ethdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio/virtio_user_ethdev.c +1 -1
index 241808cd8f..7abba1f1ee 100644
@@ -77,7 +77,7 @@ virtio_user_server_reconnect(struct virtio_user_dev *dev)
 		return -1;
 
 	dev->vhostfd = connectfd;
-	old_status = vtpci_get_status(hw);
+	old_status = dev->status;
 
 	vtpci_reset(hw);
 
Signature · 1 line
2.29.2
#11 lore raw

PATCH v4 4/44 net/virtio: introduce Virtio bus type

In reply to Maxime Coquelin

This patch is preliminary work for introducing a bus layer in Virtio PMD, in order to improve Virtio-user integration.

A new bus type is added to provide a unified way to distinguish which bus type is used (PCI modern, PCI legacy or Virtio-user).

---
 drivers/net/virtio/virtio_ethdev.c      | 40 +++++++++++++------------
 drivers/net/virtio/virtio_pci.c         |  4 +--
 drivers/net/virtio/virtio_pci.h         |  9 +++++-
 drivers/net/virtio/virtio_user_ethdev.c |  2 +-
 4 files changed, 32 insertions(+), 23 deletions(-)
drivers/net/virtio/virtio_ethdev.c +21 -19
index 92a3d4efa5..0ba10c274a 100644
@@ -592,9 +592,9 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)
 	 * we use virtual address. And we need properly set _offset_, please see
 	 * VIRTIO_MBUF_DATA_DMA_ADDR in virtqueue.h for more information.
 	 */
-	if (!hw->virtio_user_dev)
+	if (hw->bus_type == VIRTIO_BUS_PCI_LEGACY || hw->bus_type == VIRTIO_BUS_PCI_MODERN) {
 		vq->offset = offsetof(struct rte_mbuf, buf_iova);
-	else {
+	} else if (hw->bus_type == VIRTIO_BUS_USER) {
 		vq->vq_ring_mem = (uintptr_t)mz->addr;
 		vq->offset = offsetof(struct rte_mbuf, buf_addr);
 		if (queue_type == VTNET_TQ)
@@ -746,13 +746,13 @@ virtio_dev_close(struct rte_eth_dev *dev)
 	virtio_free_queues(hw);
 
 #ifdef RTE_VIRTIO_USER
-	if (hw->virtio_user_dev)
+	if (hw->bus_type == VIRTIO_BUS_USER)
 		virtio_user_dev_uninit(hw->virtio_user_dev);
 	else
 #endif
 	if (dev->device) {
 		rte_pci_unmap_device(RTE_ETH_DEV_TO_PCI(dev));
-		if (!hw->modern)
+		if (hw->bus_type == VIRTIO_BUS_PCI_LEGACY)
 			rte_pci_ioport_unmap(VTPCI_IO(hw));
 	}
 
@@ -1299,7 +1299,7 @@ virtio_intr_unmask(struct rte_eth_dev *dev)
 	if (rte_intr_ack(dev->intr_handle) < 0)
 		return -1;
 
-	if (!hw->virtio_user_dev)
+	if (hw->bus_type == VIRTIO_BUS_PCI_LEGACY || hw->bus_type == VIRTIO_BUS_PCI_MODERN)
 		hw->use_msix = vtpci_msix_detect(RTE_ETH_DEV_TO_PCI(dev));
 
 	return 0;
@@ -1313,7 +1313,7 @@ virtio_intr_enable(struct rte_eth_dev *dev)
 	if (rte_intr_enable(dev->intr_handle) < 0)
 		return -1;
 
-	if (!hw->virtio_user_dev)
+	if (hw->bus_type == VIRTIO_BUS_PCI_LEGACY || hw->bus_type == VIRTIO_BUS_PCI_MODERN)
 		hw->use_msix = vtpci_msix_detect(RTE_ETH_DEV_TO_PCI(dev));
 
 	return 0;
@@ -1327,7 +1327,7 @@ virtio_intr_disable(struct rte_eth_dev *dev)
 	if (rte_intr_disable(dev->intr_handle) < 0)
 		return -1;
 
-	if (!hw->virtio_user_dev)
+	if (hw->bus_type == VIRTIO_BUS_PCI_LEGACY || hw->bus_type == VIRTIO_BUS_PCI_MODERN)
 		hw->use_msix = vtpci_msix_detect(RTE_ETH_DEV_TO_PCI(dev));
 
 	return 0;
@@ -1368,13 +1368,13 @@ virtio_negotiate_features(struct virtio_hw *hw, uint64_t req_features)
 	PMD_INIT_LOG(DEBUG, "features after negotiate = %" PRIx64,
 		hw->guest_features);
 
-	if (hw->modern && !vtpci_with_feature(hw, VIRTIO_F_VERSION_1)) {
+	if (hw->bus_type == VIRTIO_BUS_PCI_MODERN && !vtpci_with_feature(hw, VIRTIO_F_VERSION_1)) {
 		PMD_INIT_LOG(ERR,
 			"VIRTIO_F_VERSION_1 features is not enabled.");
 		return -1;
 	}
 
-	if (hw->modern || hw->virtio_user_dev) {
+	if (hw->bus_type == VIRTIO_BUS_PCI_MODERN || hw->bus_type == VIRTIO_BUS_USER) {
 		vtpci_set_status(hw, VIRTIO_CONFIG_STATUS_FEATURES_OK);
 		if (!(vtpci_get_status(hw) & VIRTIO_CONFIG_STATUS_FEATURES_OK)) {
 			PMD_INIT_LOG(ERR,
@@ -1709,7 +1709,7 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
 
 	hw->weak_barriers = !vtpci_with_feature(hw, VIRTIO_F_ORDER_PLATFORM);
 
-	if (!hw->virtio_user_dev)
+	if (hw->bus_type == VIRTIO_BUS_PCI_LEGACY || hw->bus_type == VIRTIO_BUS_PCI_MODERN)
 		pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
 
 	/* If host does not support both status and MSI-X then disable LSC */
@@ -1856,7 +1856,7 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
 static int
 virtio_remap_pci(struct rte_pci_device *pci_dev, struct virtio_hw *hw)
 {
-	if (hw->modern) {
+	if (hw->bus_type == VIRTIO_BUS_PCI_MODERN) {
 		/*
 		 * We don't have to re-parse the PCI config space, since
 		 * rte_pci_map_device() makes sure the mapped address
@@ -1872,7 +1872,7 @@ virtio_remap_pci(struct rte_pci_device *pci_dev, struct virtio_hw *hw)
 			PMD_INIT_LOG(DEBUG, "failed to map pci device!");
 			return -1;
 		}
-	} else {
+	} else if (hw->bus_type == VIRTIO_BUS_PCI_LEGACY) {
 		if (rte_pci_ioport_map(pci_dev, 0, VTPCI_IO(hw)) < 0)
 			return -1;
 	}
@@ -1884,14 +1884,16 @@ static void
 virtio_set_vtpci_ops(struct virtio_hw *hw)
 {
 #ifdef RTE_VIRTIO_USER
-	if (hw->virtio_user_dev)
+	if (hw->bus_type == VIRTIO_BUS_USER)
 		VTPCI_OPS(hw) = &virtio_user_ops;
 	else
 #endif
-	if (hw->modern)
+	if (hw->bus_type == VIRTIO_BUS_PCI_MODERN)
 		VTPCI_OPS(hw) = &modern_ops;
-	else
+	else if (hw->bus_type == VIRTIO_BUS_PCI_LEGACY)
 		VTPCI_OPS(hw) = &legacy_ops;
+
+	return;
 }
 
 /*
@@ -1919,7 +1921,7 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 	eth_dev->rx_descriptor_done = virtio_dev_rx_queue_done;
 
 	if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
-		if (!hw->virtio_user_dev) {
+		if (hw->bus_type != VIRTIO_BUS_USER) {
 			ret = virtio_remap_pci(RTE_ETH_DEV_TO_PCI(eth_dev), hw);
 			if (ret)
 				return ret;
@@ -1950,7 +1952,7 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 	/* For virtio_user case the hw->virtio_user_dev is populated by
 	 * virtio_user_eth_dev_alloc() before eth_virtio_dev_init() is called.
 	 */
-	if (!hw->virtio_user_dev) {
+	if (hw->bus_type != VIRTIO_BUS_USER) {
 		ret = vtpci_init(RTE_ETH_DEV_TO_PCI(eth_dev), hw);
 		if (ret)
 			goto err_vtpci_init;
@@ -1982,9 +1984,9 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 	return 0;
 
 err_virtio_init:
-	if (!hw->virtio_user_dev) {
+	if (hw->bus_type == VIRTIO_BUS_PCI_MODERN || hw->bus_type == VIRTIO_BUS_PCI_LEGACY) {
 		rte_pci_unmap_device(RTE_ETH_DEV_TO_PCI(eth_dev));
-		if (!hw->modern)
+		if (hw->bus_type == VIRTIO_BUS_PCI_LEGACY)
 			rte_pci_ioport_unmap(VTPCI_IO(hw));
 	}
 err_vtpci_init:
drivers/net/virtio/virtio_pci.c +2 -2
index d6b950ee69..1692268f30 100644
@@ -697,7 +697,7 @@ vtpci_init(struct rte_pci_device *dev, struct virtio_hw *hw)
 	if (virtio_read_caps(dev, hw) == 0) {
 		PMD_INIT_LOG(INFO, "modern virtio pci detected.");
 		virtio_hw_internal[hw->port_id].vtpci_ops = &modern_ops;
-		hw->modern = 1;
+		hw->bus_type = VIRTIO_BUS_PCI_MODERN;
 		return 0;
 	}
 
@@ -716,7 +716,7 @@ vtpci_init(struct rte_pci_device *dev, struct virtio_hw *hw)
 	}
 
 	virtio_hw_internal[hw->port_id].vtpci_ops = &legacy_ops;
-	hw->modern   = 0;
+	hw->bus_type = VIRTIO_BUS_PCI_LEGACY;
 
 	return 0;
 }
drivers/net/virtio/virtio_pci.h +8 -1
index ab61e911b8..6388f0a74d 100644
@@ -243,7 +243,15 @@ struct virtio_pci_ops {
 
 struct virtio_net_config;
 
+enum virtio_bus_type {
+	VIRTIO_BUS_UNKNOWN,
+	VIRTIO_BUS_PCI_LEGACY,
+	VIRTIO_BUS_PCI_MODERN,
+	VIRTIO_BUS_USER,
+};
+
 struct virtio_hw {
+	enum virtio_bus_type bus_type;
 	struct virtnet_ctl *cvq;
 	uint64_t    req_guest_features;
 	uint64_t    guest_features;
@@ -253,7 +261,6 @@ struct virtio_hw {
 	uint16_t    vtnet_hdr_size;
 	uint8_t	    vlan_strip;
 	uint8_t	    use_msix;
-	uint8_t     modern;
 	uint8_t     use_vec_rx;
 	uint8_t     use_vec_tx;
 	uint8_t     use_inorder_rx;
drivers/net/virtio/virtio_user_ethdev.c +1 -1
index 7abba1f1ee..441721b6ca 100644
@@ -629,7 +629,7 @@ virtio_user_eth_dev_alloc(struct rte_vdev_device *vdev)
 	 * Here just pretend that we support msix.
 	 */
 	hw->use_msix = 1;
-	hw->modern   = 0;
+	hw->bus_type = VIRTIO_BUS_USER;
 	hw->use_vec_rx = 0;
 	hw->use_vec_tx = 0;
 	hw->use_inorder_rx = 0;
Signature · 1 line
2.29.2
#12 lore raw

PATCH v4 5/44 net/virtio: refactor virtio-user device

In reply to Maxime Coquelin

This patch moves the virtio_hw structure into the virtio_user_dev structure, with the goal of making virtio_hw bus-agnostic.

---
 drivers/net/virtio/virtio_ethdev.c            |  2 +-
 drivers/net/virtio/virtio_pci.h               |  1 -
 .../net/virtio/virtio_user/virtio_user_dev.h  |  1 +
 drivers/net/virtio/virtio_user_ethdev.c       | 64 ++++++++-----------
 4 files changed, 29 insertions(+), 39 deletions(-)
drivers/net/virtio/virtio_ethdev.c +1 -1
index 0ba10c274a..c8a01a46df 100644
@@ -747,7 +747,7 @@ virtio_dev_close(struct rte_eth_dev *dev)
 
 #ifdef RTE_VIRTIO_USER
 	if (hw->bus_type == VIRTIO_BUS_USER)
-		virtio_user_dev_uninit(hw->virtio_user_dev);
+		virtio_user_dev_uninit(dev->data->dev_private);
 	else
 #endif
 	if (dev->device) {
drivers/net/virtio/virtio_pci.h +0 -1
index 6388f0a74d..b35a596169 100644
@@ -277,7 +277,6 @@ struct virtio_hw {
 	uint16_t    *notify_base;
 	struct virtio_pci_common_cfg *common_cfg;
 	struct virtio_net_config *dev_cfg;
-	void	    *virtio_user_dev;
 	/*
 	 * App management thread and virtio interrupt handler thread
 	 * both can change device state, this lock is meant to avoid
drivers/net/virtio/virtio_user/virtio_user_dev.h +1 -0
index 3b5b6bc3ae..b3776cc7a0 100644
@@ -24,6 +24,7 @@ struct virtio_user_queue {
 };
 
 struct virtio_user_dev {
+	struct virtio_hw hw;
 	enum virtio_user_backend_type backend_type;
 	/* for vhost_user backend */
 	int		vhostfd;
drivers/net/virtio/virtio_user_ethdev.c +27 -37

174 lines not on this page · raw message

Signature · 1 line
2.29.2
#13 lore raw

PATCH v4 6/44 net/virtio: introduce PCI device metadata

In reply to Maxime Coquelin

This patch initiate refactoring of Virtio PCI, by introducing a new device structure for PCI-specific metadata.

---
 drivers/net/virtio/virtio_ethdev.c | 2 +-
 drivers/net/virtio/virtio_pci.c    | 2 ++
 drivers/net/virtio/virtio_pci.h    | 5 +++++
 3 files changed, 8 insertions(+), 1 deletion(-)
drivers/net/virtio/virtio_ethdev.c +1 -1
index c8a01a46df..aafba15ac2 100644
@@ -2154,7 +2154,7 @@ static int eth_virtio_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
 	if (vdpa == 1)
 		return 1;
 
-	return rte_eth_dev_pci_generic_probe(pci_dev, sizeof(struct virtio_hw),
+	return rte_eth_dev_pci_generic_probe(pci_dev, sizeof(struct virtio_pci_dev),
 		eth_virtio_dev_init);
 }
 
drivers/net/virtio/virtio_pci.c +2 -0
index 1692268f30..345d73f868 100644
@@ -689,6 +689,8 @@ virtio_read_caps(struct rte_pci_device *dev, struct virtio_hw *hw)
 int
 vtpci_init(struct rte_pci_device *dev, struct virtio_hw *hw)
 {
+	RTE_BUILD_BUG_ON(offsetof(struct virtio_pci_dev, hw) != 0);
+
 	/*
 	 * Try if we can succeed reading virtio pci caps, which exists
 	 * only on modern pci device. If failed, we fallback to legacy
drivers/net/virtio/virtio_pci.h +5 -0
index b35a596169..59f6688218 100644
@@ -289,6 +289,11 @@ struct virtio_hw {
 	struct virtqueue **vqs;
 };
 
+struct virtio_pci_dev {
+	struct virtio_hw hw;
+};
+
+#define virtio_pci_get_dev(hwp) container_of(hwp, struct virtio_pci_dev, hw)
 
 /*
  * While virtio_hw is stored in shared memory, this structure stores
Signature · 1 line
2.29.2
#14 lore raw

PATCH v4 7/44 net/virtio: move PCI device init in dedicated file

In reply to Maxime Coquelin

This patch moves the PCI Ethernet device registration bits in a dedicated patch. In following patches, more code will be moved there, with the goal of making virtio_ethdev.c truly bus-agnostic.

---
 drivers/net/virtio/meson.build         |   1 +
 drivers/net/virtio/virtio_ethdev.c     | 117 +------------------
 drivers/net/virtio/virtio_ethdev.h     |   2 +
 drivers/net/virtio/virtio_pci_ethdev.c | 149 +++++++++++++++++++++++++
 4 files changed, 157 insertions(+), 112 deletions(-)
 create mode 100644 drivers/net/virtio/virtio_pci_ethdev.c
drivers/net/virtio/meson.build +1 -0
index 0e78d1243b..07e085376b 100644
@@ -8,6 +8,7 @@ if is_windows
 endif
 
 sources += files('virtio_ethdev.c',
+	'virtio_pci_ethdev.c',
 	'virtio_pci.c',
 	'virtio_rxtx.c',
 	'virtio_rxtx_simple.c',
drivers/net/virtio/virtio_ethdev.c +5 -112

192 lines not on this page · raw message

drivers/net/virtio/virtio_ethdev.h +2 -0
index b7d52d497f..13395937c8 100644
@@ -117,6 +117,8 @@ void virtio_interrupt_handler(void *param);
 
 int virtio_dev_pause(struct rte_eth_dev *dev);
 void virtio_dev_resume(struct rte_eth_dev *dev);
+int virtio_dev_stop(struct rte_eth_dev *dev);
+int virtio_dev_close(struct rte_eth_dev *dev);
 int virtio_inject_pkts(struct rte_eth_dev *dev, struct rte_mbuf **tx_pkts,
 		int nb_pkts);
 
drivers/net/virtio/virtio_pci_ethdev.c new file +149 -0

149 lines not on this page · raw message

Signature · 1 line
2.29.2
#15 lore raw

PATCH v4 8/44 net/virtio: move PCI specific dev init to PCI ethdev init

In reply to Maxime Coquelin

This patch moves the PCI specific initialization from eth_virtio_dev_init() to eth_virtio_pci_init().

---
 drivers/net/virtio/virtio_ethdev.c     | 63 +----------------------
 drivers/net/virtio/virtio_pci_ethdev.c | 71 +++++++++++++++++++++++++-
 2 files changed, 71 insertions(+), 63 deletions(-)
drivers/net/virtio/virtio_ethdev.c +1 -62
index ad7e9efd5f..a3e81f336d 100644
@@ -1676,7 +1676,6 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
 	struct virtio_hw *hw = eth_dev->data->dev_private;
 	struct virtio_net_config *config;
 	struct virtio_net_config local_config;
-	struct rte_pci_device *pci_dev = NULL;
 	int ret;
 
 	/* Reset the device although not necessary at startup */
@@ -1697,9 +1696,6 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
 
 	hw->weak_barriers = !vtpci_with_feature(hw, VIRTIO_F_ORDER_PLATFORM);
 
-	if (hw->bus_type == VIRTIO_BUS_PCI_LEGACY || hw->bus_type == VIRTIO_BUS_PCI_MODERN)
-		pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
-
 	/* If host does not support both status and MSI-X then disable LSC */
 	if (vtpci_with_feature(hw, VIRTIO_NET_F_STATUS) &&
 	    hw->use_msix != VIRTIO_MSIX_NONE)
@@ -1828,45 +1824,9 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
 
 	vtpci_reinit_complete(hw);
 
-	if (pci_dev)
-		PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x",
-			eth_dev->data->port_id, pci_dev->id.vendor_id,
-			pci_dev->id.device_id);
-
 	return 0;
 }
 
-/*
- * Remap the PCI device again (IO port map for legacy device and
- * memory map for modern device), so that the secondary process
- * could have the PCI initiated correctly.
- */
-static int
-virtio_remap_pci(struct rte_pci_device *pci_dev, struct virtio_hw *hw)
-{
-	if (hw->bus_type == VIRTIO_BUS_PCI_MODERN) {
-		/*
-		 * We don't have to re-parse the PCI config space, since
-		 * rte_pci_map_device() makes sure the mapped address
-		 * in secondary process would equal to the one mapped in
-		 * the primary process: error will be returned if that
-		 * requirement is not met.
-		 *
-		 * That said, we could simply reuse all cap pointers
-		 * (such as dev_cfg, common_cfg, etc.) parsed from the
-		 * primary process, which is stored in shared memory.
-		 */
-		if (rte_pci_map_device(pci_dev)) {
-			PMD_INIT_LOG(DEBUG, "failed to map pci device!");
-			return -1;
-		}
-	} else if (hw->bus_type == VIRTIO_BUS_PCI_LEGACY) {
-		if (rte_pci_ioport_map(pci_dev, 0, VTPCI_IO(hw)) < 0)
-			return -1;
-	}
-
-	return 0;
-}
 
 static void
 virtio_set_vtpci_ops(struct virtio_hw *hw)
@@ -1909,17 +1869,11 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 	eth_dev->rx_descriptor_done = virtio_dev_rx_queue_done;
 
 	if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
-		if (hw->bus_type != VIRTIO_BUS_USER) {
-			ret = virtio_remap_pci(RTE_ETH_DEV_TO_PCI(eth_dev), hw);
-			if (ret)
-				return ret;
-		}
-
 		virtio_set_vtpci_ops(hw);
 		set_rxtx_funcs(eth_dev);
-
 		return 0;
 	}
+
 	ret = virtio_dev_devargs_parse(eth_dev->device->devargs, &speed, &vectorized);
 	if (ret < 0)
 		return ret;
@@ -1936,15 +1890,6 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 	}
 
 	hw->port_id = eth_dev->data->port_id;
-	/* For virtio_user case the hw->virtio_user_dev is populated by
-	 * virtio_user_eth_dev_alloc() before eth_virtio_dev_init() is called.
-	 */
-	if (hw->bus_type != VIRTIO_BUS_USER) {
-		ret = vtpci_init(RTE_ETH_DEV_TO_PCI(eth_dev), hw);
-		if (ret)
-			goto err_vtpci_init;
-	}
-
 	rte_spinlock_init(&hw->state_lock);
 
 	/* reset device and negotiate default features */
@@ -1971,12 +1916,6 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 	return 0;
 
 err_virtio_init:
-	if (hw->bus_type == VIRTIO_BUS_PCI_MODERN || hw->bus_type == VIRTIO_BUS_PCI_LEGACY) {
-		rte_pci_unmap_device(RTE_ETH_DEV_TO_PCI(eth_dev));
-		if (hw->bus_type == VIRTIO_BUS_PCI_LEGACY)
-			rte_pci_ioport_unmap(VTPCI_IO(hw));
-	}
-err_vtpci_init:
 	rte_free(eth_dev->data->mac_addrs);
 	eth_dev->data->mac_addrs = NULL;
 	return ret;
drivers/net/virtio/virtio_pci_ethdev.c +70 -1

80 lines not on this page · raw message

Signature · 1 line
2.29.2
#16 lore raw

PATCH v4 9/44 net/virtio: move MSIX detection to PCI ethdev

In reply to Maxime Coquelin

This patch introduces a new callback to notify the bus driver some interrupt related operation was done.

This is used by Virtio PCI driver to check msix status.

---
 drivers/net/virtio/virtio_ethdev.c     |  12 +--
 drivers/net/virtio/virtio_pci.c        | 120 ++++++++++++++-----------
 drivers/net/virtio/virtio_pci.h        |   6 +-
 drivers/net/virtio/virtio_pci_ethdev.c |   2 +
 4 files changed, 82 insertions(+), 58 deletions(-)
drivers/net/virtio/virtio_ethdev.c +6 -6
index a3e81f336d..52eb878c42 100644
@@ -1287,8 +1287,8 @@ virtio_intr_unmask(struct rte_eth_dev *dev)
 	if (rte_intr_ack(dev->intr_handle) < 0)
 		return -1;
 
-	if (hw->bus_type == VIRTIO_BUS_PCI_LEGACY || hw->bus_type == VIRTIO_BUS_PCI_MODERN)
-		hw->use_msix = vtpci_msix_detect(RTE_ETH_DEV_TO_PCI(dev));
+	if (VTPCI_OPS(hw)->intr_detect)
+		VTPCI_OPS(hw)->intr_detect(hw);
 
 	return 0;
 }
@@ -1301,8 +1301,8 @@ virtio_intr_enable(struct rte_eth_dev *dev)
 	if (rte_intr_enable(dev->intr_handle) < 0)
 		return -1;
 
-	if (hw->bus_type == VIRTIO_BUS_PCI_LEGACY || hw->bus_type == VIRTIO_BUS_PCI_MODERN)
-		hw->use_msix = vtpci_msix_detect(RTE_ETH_DEV_TO_PCI(dev));
+	if (VTPCI_OPS(hw)->intr_detect)
+		VTPCI_OPS(hw)->intr_detect(hw);
 
 	return 0;
 }
@@ -1315,8 +1315,8 @@ virtio_intr_disable(struct rte_eth_dev *dev)
 	if (rte_intr_disable(dev->intr_handle) < 0)
 		return -1;
 
-	if (hw->bus_type == VIRTIO_BUS_PCI_LEGACY || hw->bus_type == VIRTIO_BUS_PCI_MODERN)
-		hw->use_msix = vtpci_msix_detect(RTE_ETH_DEV_TO_PCI(dev));
+	if (VTPCI_OPS(hw)->intr_detect)
+		VTPCI_OPS(hw)->intr_detect(hw);
 
 	return 0;
 }
drivers/net/virtio/virtio_pci.c +70 -50

168 lines not on this page · raw message

drivers/net/virtio/virtio_pci.h +4 -2
index 59f6688218..b29bbb8074 100644
@@ -239,6 +239,7 @@ struct virtio_pci_ops {
 	int (*setup_queue)(struct virtio_hw *hw, struct virtqueue *vq);
 	void (*del_queue)(struct virtio_hw *hw, struct virtqueue *vq);
 	void (*notify_queue)(struct virtio_hw *hw, struct virtqueue *vq);
+	void (*intr_detect)(struct virtio_hw *hw);
 };
 
 struct virtio_net_config;
@@ -303,10 +304,13 @@ struct virtio_pci_dev {
 struct virtio_hw_internal {
 	const struct virtio_pci_ops *vtpci_ops;
 	struct rte_pci_ioport io;
+	struct rte_pci_device *dev;
 };
 
 #define VTPCI_OPS(hw)	(virtio_hw_internal[(hw)->port_id].vtpci_ops)
 #define VTPCI_IO(hw)	(&virtio_hw_internal[(hw)->port_id].io)
+#define VTPCI_DEV(hw)	(virtio_hw_internal[(hw)->port_id].dev)
+
 
 extern struct virtio_hw_internal virtio_hw_internal[RTE_MAX_ETHPORTS];
 
@@ -383,8 +387,6 @@ void vtpci_read_dev_config(struct virtio_hw *, size_t, void *, int);
 
 uint8_t vtpci_isr(struct virtio_hw *);
 
-enum virtio_msix_status vtpci_msix_detect(struct rte_pci_device *dev);
-
 extern const struct virtio_pci_ops legacy_ops;
 extern const struct virtio_pci_ops modern_ops;
 extern const struct virtio_pci_ops virtio_user_ops;
drivers/net/virtio/virtio_pci_ethdev.c +2 -0
index 6a0ef6edc3..045b134ef2 100644
@@ -73,6 +73,8 @@ eth_virtio_pci_init(struct rte_eth_dev *eth_dev)
 	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
 	int ret;
 
+	VTPCI_DEV(hw) = pci_dev;
+
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
 		ret = vtpci_init(RTE_ETH_DEV_TO_PCI(eth_dev), hw);
 		if (ret) {
Signature · 1 line
2.29.2
#17 lore raw

PATCH v4 10/44 net/virtio: force IOVA as VA mode for Virtio-user

In reply to Maxime Coquelin

At least Vhost-user backend of Virtio-user PMD requires IOVA as VA mode. Until now, it was implemented as a hack by forcing to use mbuf's buf_addr field instead of buf_iova.

This patch removes all this logic and just fails probing if IOVA as VA mode is not selected. It simplifies the code overall, and removes some bus-specific logic from generic virtio_ethdev.c.

---
 drivers/net/virtio/virtio_ethdev.c           | 15 ---------
 drivers/net/virtio/virtio_rxtx.c             | 34 ++++++++------------
 drivers/net/virtio/virtio_rxtx_packed.h      |  2 +-
 drivers/net/virtio/virtio_rxtx_packed_avx.h  |  8 ++---
 drivers/net/virtio/virtio_rxtx_packed_neon.h |  8 ++---
 drivers/net/virtio/virtio_rxtx_simple.h      |  3 +-
 drivers/net/virtio/virtio_user_ethdev.c      |  1 +
 drivers/net/virtio/virtqueue.h               | 25 +-------------
 8 files changed, 26 insertions(+), 70 deletions(-)
drivers/net/virtio/virtio_ethdev.c +0 -15
index 52eb878c42..fb789460e8 100644
@@ -576,21 +576,6 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)
 		hw->cvq = cvq;
 	}
 
-	/* For virtio_user case (that is when hw->virtio_user_dev is not NULL),
-	 * we use virtual address. And we need properly set _offset_, please see
-	 * VIRTIO_MBUF_DATA_DMA_ADDR in virtqueue.h for more information.
-	 */
-	if (hw->bus_type == VIRTIO_BUS_PCI_LEGACY || hw->bus_type == VIRTIO_BUS_PCI_MODERN) {
-		vq->offset = offsetof(struct rte_mbuf, buf_iova);
-	} else if (hw->bus_type == VIRTIO_BUS_USER) {
-		vq->vq_ring_mem = (uintptr_t)mz->addr;
-		vq->offset = offsetof(struct rte_mbuf, buf_addr);
-		if (queue_type == VTNET_TQ)
-			txvq->virtio_net_hdr_mem = (uintptr_t)hdr_mz->addr;
-		else if (queue_type == VTNET_CQ)
-			cvq->virtio_net_hdr_mem = (uintptr_t)hdr_mz->addr;
-	}
-
 	if (queue_type == VTNET_TQ) {
 		struct virtio_tx_region *txr;
 		unsigned int i;
drivers/net/virtio/virtio_rxtx.c +14 -20
index 622d4bf201..6875c8fbee 100644
@@ -271,13 +271,10 @@ virtqueue_enqueue_refill_inorder(struct virtqueue *vq,
 		dxp->cookie = (void *)cookies[i];
 		dxp->ndescs = 1;
 
-		start_dp[idx].addr =
-				VIRTIO_MBUF_ADDR(cookies[i], vq) +
-				RTE_PKTMBUF_HEADROOM - hw->vtnet_hdr_size;
-		start_dp[idx].len =
-				cookies[i]->buf_len -
-				RTE_PKTMBUF_HEADROOM +
-				hw->vtnet_hdr_size;
+		start_dp[idx].addr = cookies[i]->buf_iova +
+			RTE_PKTMBUF_HEADROOM - hw->vtnet_hdr_size;
+		start_dp[idx].len = cookies[i]->buf_len -
+			RTE_PKTMBUF_HEADROOM + hw->vtnet_hdr_size;
 		start_dp[idx].flags =  VRING_DESC_F_WRITE;
 
 		vq_update_avail_ring(vq, idx);
@@ -313,12 +310,10 @@ virtqueue_enqueue_recv_refill(struct virtqueue *vq, struct rte_mbuf **cookie,
 		dxp->cookie = (void *)cookie[i];
 		dxp->ndescs = 1;
 
-		start_dp[idx].addr =
-			VIRTIO_MBUF_ADDR(cookie[i], vq) +
+		start_dp[idx].addr = cookie[i]->buf_iova +
 			RTE_PKTMBUF_HEADROOM - hw->vtnet_hdr_size;
-		start_dp[idx].len =
-			cookie[i]->buf_len - RTE_PKTMBUF_HEADROOM +
-			hw->vtnet_hdr_size;
+		start_dp[idx].len = cookie[i]->buf_len -
+			RTE_PKTMBUF_HEADROOM + hw->vtnet_hdr_size;
 		start_dp[idx].flags = VRING_DESC_F_WRITE;
 		vq->vq_desc_head_idx = start_dp[idx].next;
 		vq_update_avail_ring(vq, idx);
@@ -355,10 +350,10 @@ virtqueue_enqueue_recv_refill_packed(struct virtqueue *vq,
 		dxp->cookie = (void *)cookie[i];
 		dxp->ndescs = 1;
 
-		start_dp[idx].addr = VIRTIO_MBUF_ADDR(cookie[i], vq) +
-				RTE_PKTMBUF_HEADROOM - hw->vtnet_hdr_size;
-		start_dp[idx].len = cookie[i]->buf_len - RTE_PKTMBUF_HEADROOM
-					+ hw->vtnet_hdr_size;
+		start_dp[idx].addr = cookie[i]->buf_iova +
+			RTE_PKTMBUF_HEADROOM - hw->vtnet_hdr_size;
+		start_dp[idx].len = cookie[i]->buf_len -
+			RTE_PKTMBUF_HEADROOM + hw->vtnet_hdr_size;
 
 		vq->vq_desc_head_idx = dxp->next;
 		if (vq->vq_desc_head_idx == VQ_RING_DESC_CHAIN_END)
@@ -455,8 +450,7 @@ virtqueue_enqueue_xmit_inorder(struct virtnet_tx *txvq,
 		else
 			virtqueue_xmit_offload(hdr, cookies[i], true);
 
-		start_dp[idx].addr  =
-			VIRTIO_MBUF_DATA_DMA_ADDR(cookies[i], vq) - head_size;
+		start_dp[idx].addr  = rte_mbuf_data_iova(cookies[i]) - head_size;
 		start_dp[idx].len   = cookies[i]->data_len + head_size;
 		start_dp[idx].flags = 0;
 
@@ -503,7 +497,7 @@ virtqueue_enqueue_xmit_packed_fast(struct virtnet_tx *txvq,
 	else
 		virtqueue_xmit_offload(hdr, cookie, true);
 
-	dp->addr = VIRTIO_MBUF_DATA_DMA_ADDR(cookie, vq) - head_size;
+	dp->addr = rte_mbuf_data_iova(cookie) - head_size;
 	dp->len  = cookie->data_len + head_size;
 	dp->id   = id;
 
@@ -590,7 +584,7 @@ virtqueue_enqueue_xmit(struct virtnet_tx *txvq, struct rte_mbuf *cookie,
 	virtqueue_xmit_offload(hdr, cookie, vq->hw->has_tx_offload);
 
 	do {
-		start_dp[idx].addr  = VIRTIO_MBUF_DATA_DMA_ADDR(cookie, vq);
+		start_dp[idx].addr  = rte_mbuf_data_iova(cookie);
 		start_dp[idx].len   = cookie->data_len;
 		if (prepend_header) {
 			start_dp[idx].addr -= head_size;
drivers/net/virtio/virtio_rxtx_packed.h +1 -1
index 016b6fb247..c0fad41c3d 100644
@@ -288,7 +288,7 @@ virtio_recv_refill_packed_vec(struct virtnet_rx *rxvq,
 			dxp = &vq->vq_descx[idx + i];
 			dxp->cookie = (void *)cookie[total_num + i];
 
-			addr = VIRTIO_MBUF_ADDR(cookie[total_num + i], vq) +
+			addr = cookie[total_num + i]->buf_iova +
 				RTE_PKTMBUF_HEADROOM - hw->vtnet_hdr_size;
 			start_dp[idx + i].addr = addr;
 			start_dp[idx + i].len = cookie[total_num + i]->buf_len
drivers/net/virtio/virtio_rxtx_packed_avx.h +4 -4
index f831828845..2c610d57de 100644
@@ -71,13 +71,13 @@ virtqueue_enqueue_batch_packed_vec(struct virtnet_tx *txvq,
 	}
 
 	__m512i descs_base = _mm512_set_epi64(tx_pkts[3]->data_len,
-			VIRTIO_MBUF_ADDR(tx_pkts[3], vq),
+			tx_pkts[3]->buf_iova,
 			tx_pkts[2]->data_len,
-			VIRTIO_MBUF_ADDR(tx_pkts[2], vq),
+			tx_pkts[2]->buf_iova,
 			tx_pkts[1]->data_len,
-			VIRTIO_MBUF_ADDR(tx_pkts[1], vq),
+			tx_pkts[1]->buf_iova,
 			tx_pkts[0]->data_len,
-			VIRTIO_MBUF_ADDR(tx_pkts[0], vq));
+			tx_pkts[0]->buf_iova);
 
 	/* id offset and data offset */
 	__m512i data_offsets = _mm512_set_epi64((uint64_t)3 << ID_BITS_OFFSET,
drivers/net/virtio/virtio_rxtx_packed_neon.h +4 -4
index 01c77b712d..ae2d099c0b 100644
@@ -97,12 +97,12 @@ virtqueue_enqueue_batch_packed_vec(struct virtnet_tx *txvq,
 
 	uint64x2x2_t desc[PACKED_BATCH_SIZE / 2];
 	uint64x2_t base_addr0 = {
-		VIRTIO_MBUF_ADDR(tx_pkts[0], vq) + tx_pkts[0]->data_off,
-		VIRTIO_MBUF_ADDR(tx_pkts[1], vq) + tx_pkts[1]->data_off
+		tx_pkts[0]->buf_iova + tx_pkts[0]->data_off,
+		tx_pkts[1]->buf_iova + tx_pkts[1]->data_off
 	};
 	uint64x2_t base_addr1 = {
-		VIRTIO_MBUF_ADDR(tx_pkts[2], vq) + tx_pkts[2]->data_off,
-		VIRTIO_MBUF_ADDR(tx_pkts[3], vq) + tx_pkts[3]->data_off
+		tx_pkts[2]->buf_iova + tx_pkts[2]->data_off,
+		tx_pkts[3]->buf_iova + tx_pkts[3]->data_off
 	};
 
 	desc[0].val[0] = base_addr0;
drivers/net/virtio/virtio_rxtx_simple.h +1 -2
index 3d1296a23c..f2a5aedf97 100644
@@ -43,8 +43,7 @@ virtio_rxq_rearm_vec(struct virtnet_rx *rxvq)
 		p = (uintptr_t)&sw_ring[i]->rearm_data;
 		*(uint64_t *)p = rxvq->mbuf_initializer;
 
-		start_dp[i].addr =
-			VIRTIO_MBUF_ADDR(sw_ring[i], vq) +
+		start_dp[i].addr = sw_ring[i]->buf_iova +
 			RTE_PKTMBUF_HEADROOM - vq->hw->vtnet_hdr_size;
 		start_dp[i].len = sw_ring[i]->buf_len -
 			RTE_PKTMBUF_HEADROOM + vq->hw->vtnet_hdr_size;
drivers/net/virtio/virtio_user_ethdev.c +1 -0
index 620ecb126c..241fe373b9 100644
@@ -953,6 +953,7 @@ static struct rte_vdev_driver virtio_user_driver = {
 	.remove = virtio_user_pmd_remove,
 	.dma_map = virtio_user_pmd_dma_map,
 	.dma_unmap = virtio_user_pmd_dma_unmap,
+	.drv_flags = RTE_VDEV_DRV_NEED_IOVA_AS_VA,
 };
 
 RTE_PMD_REGISTER_VDEV(net_virtio_user, virtio_user_driver);
drivers/net/virtio/virtqueue.h +1 -24
index d78b943443..7611317581 100644
@@ -113,29 +113,6 @@ virtqueue_store_flags_packed(struct vring_packed_desc *dp,
 
 #define VIRTQUEUE_MAX_NAME_SZ 32
 
-#ifdef RTE_VIRTIO_USER
-/**
- * Return the physical address (or virtual address in case of
- * virtio-user) of mbuf data buffer.
- *
- * The address is firstly casted to the word size (sizeof(uintptr_t))
- * before casting it to uint64_t. This is to make it work with different
- * combination of word size (64 bit and 32 bit) and virtio device
- * (virtio-pci and virtio-user).
- */
-#define VIRTIO_MBUF_ADDR(mb, vq) \
-	((uint64_t)(*(uintptr_t *)((uintptr_t)(mb) + (vq)->offset)))
-#else
-#define VIRTIO_MBUF_ADDR(mb, vq) ((mb)->buf_iova)
-#endif
-
-/**
- * Return the physical address (or virtual address in case of
- * virtio-user) of mbuf data buffer, taking care of mbuf data offset
- */
-#define VIRTIO_MBUF_DATA_DMA_ADDR(mb, vq) \
-	(VIRTIO_MBUF_ADDR(mb, vq) + (mb)->data_off)
-
 #define VTNET_SQ_RQ_QUEUE_IDX 0
 #define VTNET_SQ_TQ_QUEUE_IDX 1
 #define VTNET_SQ_CQ_QUEUE_IDX 2
@@ -763,7 +740,7 @@ virtqueue_enqueue_xmit_packed(struct virtnet_tx *txvq, struct rte_mbuf *cookie,
 	do {
 		uint16_t flags;
 
-		start_dp[idx].addr = VIRTIO_MBUF_DATA_DMA_ADDR(cookie, vq);
+		start_dp[idx].addr = rte_mbuf_data_iova(cookie);
 		start_dp[idx].len  = cookie->data_len;
 		if (prepend_header) {
 			start_dp[idx].addr -= head_size;
Signature · 1 line
2.29.2
#18 lore raw

PATCH v4 11/44 net/virtio: store PCI type in Virtio device metadata

In reply to Maxime Coquelin

Going further in making the Virtio ethdev layer bus agnostic, this patch adds a boolean in the Virtio PCI device metadata.

---
 drivers/net/virtio/virtio_pci.c        | 18 +++++++++++-------
 drivers/net/virtio/virtio_pci.h        |  3 ++-
 drivers/net/virtio/virtio_pci_ethdev.c | 12 +++++++-----
 3 files changed, 20 insertions(+), 13 deletions(-)
drivers/net/virtio/virtio_pci.c +11 -7
index 556be1e3da..6d9c712fd5 100644
@@ -751,8 +751,10 @@ virtio_read_caps(struct rte_pci_device *dev, struct virtio_hw *hw)
  * Return 0 on success.
  */
 int
-vtpci_init(struct rte_pci_device *dev, struct virtio_hw *hw)
+vtpci_init(struct rte_pci_device *pci_dev, struct virtio_pci_dev *dev)
 {
+	struct virtio_hw *hw = &dev->hw;
+
 	RTE_BUILD_BUG_ON(offsetof(struct virtio_pci_dev, hw) != 0);
 
 	/*
@@ -760,19 +762,20 @@ vtpci_init(struct rte_pci_device *dev, struct virtio_hw *hw)
 	 * only on modern pci device. If failed, we fallback to legacy
 	 * virtio handling.
 	 */
-	if (virtio_read_caps(dev, hw) == 0) {
+	if (virtio_read_caps(pci_dev, hw) == 0) {
 		PMD_INIT_LOG(INFO, "modern virtio pci detected.");
 		virtio_hw_internal[hw->port_id].vtpci_ops = &modern_ops;
 		hw->bus_type = VIRTIO_BUS_PCI_MODERN;
+		dev->modern = true;
 		goto msix_detect;
 	}
 
 	PMD_INIT_LOG(INFO, "trying with legacy virtio pci.");
-	if (rte_pci_ioport_map(dev, 0, VTPCI_IO(hw)) < 0) {
-		rte_pci_unmap_device(dev);
-		if (dev->kdrv == RTE_PCI_KDRV_UNKNOWN &&
-		    (!dev->device.devargs ||
-		     dev->device.devargs->bus !=
+	if (rte_pci_ioport_map(pci_dev, 0, VTPCI_IO(hw)) < 0) {
+		rte_pci_unmap_device(pci_dev);
+		if (pci_dev->kdrv == RTE_PCI_KDRV_UNKNOWN &&
+		    (!pci_dev->device.devargs ||
+		     pci_dev->device.devargs->bus !=
 		     rte_bus_find_by_name("pci"))) {
 			PMD_INIT_LOG(INFO,
 				"skip kernel managed virtio device.");
@@ -783,6 +786,7 @@ vtpci_init(struct rte_pci_device *dev, struct virtio_hw *hw)
 
 	virtio_hw_internal[hw->port_id].vtpci_ops = &legacy_ops;
 	hw->bus_type = VIRTIO_BUS_PCI_LEGACY;
+	dev->modern = false;
 
 msix_detect:
 	VTPCI_OPS(hw)->intr_detect(hw);
drivers/net/virtio/virtio_pci.h +2 -1
index b29bbb8074..4c22692414 100644
@@ -292,6 +292,7 @@ struct virtio_hw {
 
 struct virtio_pci_dev {
 	struct virtio_hw hw;
+	bool modern;
 };
 
 #define virtio_pci_get_dev(hwp) container_of(hwp, struct virtio_pci_dev, hw)
@@ -371,7 +372,7 @@ vtpci_packed_queue(struct virtio_hw *hw)
 /*
  * Function declaration from virtio_pci.c
  */
-int vtpci_init(struct rte_pci_device *dev, struct virtio_hw *hw);
+int vtpci_init(struct rte_pci_device *pci_dev, struct virtio_pci_dev *dev);
 void vtpci_reset(struct virtio_hw *);
 
 void vtpci_reinit_complete(struct virtio_hw *);
drivers/net/virtio/virtio_pci_ethdev.c +7 -5
index 045b134ef2..076a5dbced 100644
@@ -39,9 +39,11 @@ static const struct rte_pci_id pci_id_virtio_map[] = {
  * could have the PCI initiated correctly.
  */
 static int
-virtio_remap_pci(struct rte_pci_device *pci_dev, struct virtio_hw *hw)
+virtio_remap_pci(struct rte_pci_device *pci_dev, struct virtio_pci_dev *dev)
 {
-	if (hw->bus_type == VIRTIO_BUS_PCI_MODERN) {
+	struct virtio_hw *hw = &dev->hw;
+
+	if (dev->modern) {
 		/*
 		 * We don't have to re-parse the PCI config space, since
 		 * rte_pci_map_device() makes sure the mapped address
@@ -57,7 +59,7 @@ virtio_remap_pci(struct rte_pci_device *pci_dev, struct virtio_hw *hw)
 			PMD_INIT_LOG(DEBUG, "failed to map pci device!");
 			return -1;
 		}
-	} else if (hw->bus_type == VIRTIO_BUS_PCI_LEGACY) {
+	} else {
 		if (rte_pci_ioport_map(pci_dev, 0, VTPCI_IO(hw)) < 0)
 			return -1;
 	}
@@ -76,13 +78,13 @@ eth_virtio_pci_init(struct rte_eth_dev *eth_dev)
 	VTPCI_DEV(hw) = pci_dev;
 
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
-		ret = vtpci_init(RTE_ETH_DEV_TO_PCI(eth_dev), hw);
+		ret = vtpci_init(RTE_ETH_DEV_TO_PCI(eth_dev), dev);
 		if (ret) {
 			PMD_INIT_LOG(ERR, "Failed to init PCI device\n");
 			return -1;
 		}
 	} else {
-		ret = virtio_remap_pci(RTE_ETH_DEV_TO_PCI(eth_dev), hw);
+		ret = virtio_remap_pci(RTE_ETH_DEV_TO_PCI(eth_dev), dev);
 		if (ret < 0) {
 			PMD_INIT_LOG(ERR, "Failed to remap PCI device\n");
 			return -1;
Signature · 1 line
2.29.2
#19 lore raw

PATCH v4 12/44 net/virtio: add callback for device closing

In reply to Maxime Coquelin

This patch introduces a new callback for device closing, making virtio_dev_close() bus-agnostic.

---
 drivers/net/virtio/meson.build          |  2 --
 drivers/net/virtio/virtio_ethdev.c      | 13 +------------
 drivers/net/virtio/virtio_pci.c         | 25 +++++++++++++++++++++++++
 drivers/net/virtio/virtio_pci.h         |  2 ++
 drivers/net/virtio/virtio_user_ethdev.c | 11 +++++++++++
 5 files changed, 39 insertions(+), 14 deletions(-)
drivers/net/virtio/meson.build +0 -2
index 07e085376b..f2873d6180 100644
@@ -44,8 +44,6 @@ elif arch_subdir == 'arm' and host_machine.cpu_family().startswith('aarch64')
 endif
 
 if is_linux
-	dpdk_conf.set('RTE_VIRTIO_USER', 1)
-
 	sources += files('virtio_user_ethdev.c',
 		'virtio_user/vhost_kernel.c',
 		'virtio_user/vhost_kernel_tap.c',
drivers/net/virtio/virtio_ethdev.c +1 -12
index fb789460e8..84edcd4724 100644
@@ -718,18 +718,7 @@ virtio_dev_close(struct rte_eth_dev *dev)
 	virtio_dev_free_mbufs(dev);
 	virtio_free_queues(hw);
 
-#ifdef RTE_VIRTIO_USER
-	if (hw->bus_type == VIRTIO_BUS_USER)
-		virtio_user_dev_uninit(dev->data->dev_private);
-	else
-#endif
-	if (dev->device) {
-		rte_pci_unmap_device(RTE_ETH_DEV_TO_PCI(dev));
-		if (hw->bus_type == VIRTIO_BUS_PCI_LEGACY)
-			rte_pci_ioport_unmap(VTPCI_IO(hw));
-	}
-
-	return 0;
+	return VTPCI_OPS(hw)->dev_close(hw);
 }
 
 static int
drivers/net/virtio/virtio_pci.c +25 -0
index 6d9c712fd5..ea4ab381a6 100644
@@ -297,6 +297,17 @@ legacy_intr_detect(struct virtio_hw *hw)
 	hw->use_msix = vtpci_msix_detect(VTPCI_DEV(hw));
 }
 
+static int
+legacy_dev_close(struct virtio_hw *hw)
+{
+	struct virtio_pci_dev *dev = virtio_pci_get_dev(hw);
+
+	rte_pci_unmap_device(dev->pci_dev);
+	rte_pci_ioport_unmap(VTPCI_IO(hw));
+
+	return 0;
+}
+
 const struct virtio_pci_ops legacy_ops = {
 	.read_dev_cfg	= legacy_read_dev_config,
 	.write_dev_cfg	= legacy_write_dev_config,
@@ -312,6 +323,7 @@ const struct virtio_pci_ops legacy_ops = {
 	.del_queue	= legacy_del_queue,
 	.notify_queue	= legacy_notify_queue,
 	.intr_detect	= legacy_intr_detect,
+	.dev_close	= legacy_dev_close,
 };
 
 static inline void
@@ -511,6 +523,16 @@ modern_intr_detect(struct virtio_hw *hw)
 	hw->use_msix = vtpci_msix_detect(VTPCI_DEV(hw));
 }
 
+static int
+modern_dev_close(struct virtio_hw *hw)
+{
+	struct virtio_pci_dev *dev = virtio_pci_get_dev(hw);
+
+	rte_pci_unmap_device(dev->pci_dev);
+
+	return 0;
+}
+
 const struct virtio_pci_ops modern_ops = {
 	.read_dev_cfg	= modern_read_dev_config,
 	.write_dev_cfg	= modern_write_dev_config,
@@ -526,6 +548,7 @@ const struct virtio_pci_ops modern_ops = {
 	.del_queue	= modern_del_queue,
 	.notify_queue	= modern_notify_queue,
 	.intr_detect	= modern_intr_detect,
+	.dev_close	= modern_dev_close,
 };
 
 
@@ -757,6 +780,8 @@ vtpci_init(struct rte_pci_device *pci_dev, struct virtio_pci_dev *dev)
 
 	RTE_BUILD_BUG_ON(offsetof(struct virtio_pci_dev, hw) != 0);
 
+	dev->pci_dev = pci_dev;
+
 	/*
 	 * Try if we can succeed reading virtio pci caps, which exists
 	 * only on modern pci device. If failed, we fallback to legacy
drivers/net/virtio/virtio_pci.h +2 -0
index 4c22692414..0515bbb247 100644
@@ -240,6 +240,7 @@ struct virtio_pci_ops {
 	void (*del_queue)(struct virtio_hw *hw, struct virtqueue *vq);
 	void (*notify_queue)(struct virtio_hw *hw, struct virtqueue *vq);
 	void (*intr_detect)(struct virtio_hw *hw);
+	int (*dev_close)(struct virtio_hw *hw);
 };
 
 struct virtio_net_config;
@@ -292,6 +293,7 @@ struct virtio_hw {
 
 struct virtio_pci_dev {
 	struct virtio_hw hw;
+	struct rte_pci_device *pci_dev;
 	bool modern;
 };
 
drivers/net/virtio/virtio_user_ethdev.c +11 -0
index 241fe373b9..3cbf310c03 100644
@@ -462,6 +462,16 @@ virtio_user_notify_queue(struct virtio_hw *hw, struct virtqueue *vq)
 			    strerror(errno));
 }
 
+static int
+virtio_user_dev_close(struct virtio_hw *hw)
+{
+	struct virtio_user_dev *dev = virtio_user_get_dev(hw);
+
+	virtio_user_dev_uninit(dev);
+
+	return 0;
+}
+
 const struct virtio_pci_ops virtio_user_ops = {
 	.read_dev_cfg	= virtio_user_read_dev_config,
 	.write_dev_cfg	= virtio_user_write_dev_config,
@@ -476,6 +486,7 @@ const struct virtio_pci_ops virtio_user_ops = {
 	.setup_queue	= virtio_user_setup_queue,
 	.del_queue	= virtio_user_del_queue,
 	.notify_queue	= virtio_user_notify_queue,
+	.dev_close	= virtio_user_dev_close,
 };
 
 static const char *valid_args[] = {
Signature · 1 line
2.29.2
#20 lore raw

PATCH v4 13/44 net/virtio: validate features at bus level

In reply to Maxime Coquelin

This patch provides a new callback for the bus type to validate negotiated features are compatible with it.

Only user for now is PCI modern bus type, which implies that the device supports Virtio 1.0+.

---
 drivers/net/virtio/virtio_ethdev.c      | 11 ++++-------
 drivers/net/virtio/virtio_pci.c         | 19 +++++++++++++++++++
 drivers/net/virtio/virtio_pci.h         |  1 +
 drivers/net/virtio/virtio_user_ethdev.c |  7 +++++++
 4 files changed, 31 insertions(+), 7 deletions(-)
drivers/net/virtio/virtio_ethdev.c +4 -7
index 84edcd4724..72f527144e 100644
@@ -1330,17 +1330,14 @@ virtio_negotiate_features(struct virtio_hw *hw, uint64_t req_features)
 	PMD_INIT_LOG(DEBUG, "features after negotiate = %" PRIx64,
 		hw->guest_features);
 
-	if (hw->bus_type == VIRTIO_BUS_PCI_MODERN && !vtpci_with_feature(hw, VIRTIO_F_VERSION_1)) {
-		PMD_INIT_LOG(ERR,
-			"VIRTIO_F_VERSION_1 features is not enabled.");
+	if (VTPCI_OPS(hw)->features_ok(hw) < 0)
 		return -1;
-	}
 
-	if (hw->bus_type == VIRTIO_BUS_PCI_MODERN || hw->bus_type == VIRTIO_BUS_USER) {
+	if (vtpci_with_feature(hw, VIRTIO_F_VERSION_1)) {
 		vtpci_set_status(hw, VIRTIO_CONFIG_STATUS_FEATURES_OK);
+
 		if (!(vtpci_get_status(hw) & VIRTIO_CONFIG_STATUS_FEATURES_OK)) {
-			PMD_INIT_LOG(ERR,
-				"failed to set FEATURES_OK status!");
+			PMD_INIT_LOG(ERR, "Failed to set FEATURES_OK status!");
 			return -1;
 		}
 	}
drivers/net/virtio/virtio_pci.c +19 -0
index ea4ab381a6..1c8d4b7ddd 100644
@@ -201,6 +201,12 @@ legacy_set_features(struct virtio_hw *hw, uint64_t features)
 		VIRTIO_PCI_GUEST_FEATURES);
 }
 
+static int
+legacy_features_ok(struct virtio_hw *hw __rte_unused)
+{
+	return 0;
+}
+
 static uint8_t
 legacy_get_status(struct virtio_hw *hw)
 {
@@ -315,6 +321,7 @@ const struct virtio_pci_ops legacy_ops = {
 	.set_status	= legacy_set_status,
 	.get_features	= legacy_get_features,
 	.set_features	= legacy_set_features,
+	.features_ok	= legacy_features_ok,
 	.get_isr	= legacy_get_isr,
 	.set_config_irq	= legacy_set_config_irq,
 	.set_queue_irq  = legacy_set_queue_irq,
@@ -389,6 +396,17 @@ modern_set_features(struct virtio_hw *hw, uint64_t features)
 		    &hw->common_cfg->guest_feature);
 }
 
+static int
+modern_features_ok(struct virtio_hw *hw)
+{
+	if (!vtpci_with_feature(hw, VIRTIO_F_VERSION_1)) {
+		PMD_INIT_LOG(ERR, "Version 1+ required with modern devices\n");
+		return -1;
+	}
+
+	return 0;
+}
+
 static uint8_t
 modern_get_status(struct virtio_hw *hw)
 {
@@ -540,6 +558,7 @@ const struct virtio_pci_ops modern_ops = {
 	.set_status	= modern_set_status,
 	.get_features	= modern_get_features,
 	.set_features	= modern_set_features,
+	.features_ok	= modern_features_ok,
 	.get_isr	= modern_get_isr,
 	.set_config_irq	= modern_set_config_irq,
 	.set_queue_irq  = modern_set_queue_irq,
drivers/net/virtio/virtio_pci.h +1 -0
index 0515bbb247..6aacc942fc 100644
@@ -227,6 +227,7 @@ struct virtio_pci_ops {
 
 	uint64_t (*get_features)(struct virtio_hw *hw);
 	void     (*set_features)(struct virtio_hw *hw, uint64_t features);
+	int      (*features_ok)(struct virtio_hw *hw);
 
 	uint8_t (*get_isr)(struct virtio_hw *hw);
 
drivers/net/virtio/virtio_user_ethdev.c +7 -0
index 3cbf310c03..bf958de571 100644
@@ -327,6 +327,12 @@ virtio_user_set_features(struct virtio_hw *hw, uint64_t features)
 	dev->features = features & dev->device_features;
 }
 
+static int
+virtio_user_features_ok(struct virtio_hw *hw __rte_unused)
+{
+	return 0;
+}
+
 static uint8_t
 virtio_user_get_isr(struct virtio_hw *hw __rte_unused)
 {
@@ -479,6 +485,7 @@ const struct virtio_pci_ops virtio_user_ops = {
 	.set_status	= virtio_user_set_status,
 	.get_features	= virtio_user_get_features,
 	.set_features	= virtio_user_set_features,
+	.features_ok	= virtio_user_features_ok,
 	.get_isr	= virtio_user_get_isr,
 	.set_config_irq	= virtio_user_set_config_irq,
 	.set_queue_irq	= virtio_user_set_queue_irq,
Signature · 1 line
2.29.2
#21 lore raw

PATCH v4 14/44 net/virtio: remove bus type enum

In reply to Maxime Coquelin

Bus type awareness at the generic ethdev level is no more needed as previous patches have made it bus-agnostic.

This patch removes it from struct virtio_hw.

---
 drivers/net/virtio/virtio_ethdev.c      | 18 ------------------
 drivers/net/virtio/virtio_pci.c         |  2 --
 drivers/net/virtio/virtio_pci.h         |  8 --------
 drivers/net/virtio/virtio_pci_ethdev.c  |  7 ++++++-
 drivers/net/virtio/virtio_user_ethdev.c |  5 ++++-
 5 files changed, 10 insertions(+), 30 deletions(-)
drivers/net/virtio/virtio_ethdev.c +0 -18
index 72f527144e..c46fe4adf6 100644
@@ -1798,23 +1798,6 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
 	return 0;
 }
 
-
-static void
-virtio_set_vtpci_ops(struct virtio_hw *hw)
-{
-#ifdef RTE_VIRTIO_USER
-	if (hw->bus_type == VIRTIO_BUS_USER)
-		VTPCI_OPS(hw) = &virtio_user_ops;
-	else
-#endif
-	if (hw->bus_type == VIRTIO_BUS_PCI_MODERN)
-		VTPCI_OPS(hw) = &modern_ops;
-	else if (hw->bus_type == VIRTIO_BUS_PCI_LEGACY)
-		VTPCI_OPS(hw) = &legacy_ops;
-
-	return;
-}
-
 /*
  * This function is based on probe() function in virtio_pci.c
  * It returns 0 on success.
@@ -1840,7 +1823,6 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 	eth_dev->rx_descriptor_done = virtio_dev_rx_queue_done;
 
 	if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
-		virtio_set_vtpci_ops(hw);
 		set_rxtx_funcs(eth_dev);
 		return 0;
 	}
drivers/net/virtio/virtio_pci.c +0 -2
index 1c8d4b7ddd..20599774a7 100644
@@ -809,7 +809,6 @@ vtpci_init(struct rte_pci_device *pci_dev, struct virtio_pci_dev *dev)
 	if (virtio_read_caps(pci_dev, hw) == 0) {
 		PMD_INIT_LOG(INFO, "modern virtio pci detected.");
 		virtio_hw_internal[hw->port_id].vtpci_ops = &modern_ops;
-		hw->bus_type = VIRTIO_BUS_PCI_MODERN;
 		dev->modern = true;
 		goto msix_detect;
 	}
@@ -829,7 +828,6 @@ vtpci_init(struct rte_pci_device *pci_dev, struct virtio_pci_dev *dev)
 	}
 
 	virtio_hw_internal[hw->port_id].vtpci_ops = &legacy_ops;
-	hw->bus_type = VIRTIO_BUS_PCI_LEGACY;
 	dev->modern = false;
 
 msix_detect:
drivers/net/virtio/virtio_pci.h +0 -8
index 6aacc942fc..2cede4a100 100644
@@ -246,15 +246,7 @@ struct virtio_pci_ops {
 
 struct virtio_net_config;
 
-enum virtio_bus_type {
-	VIRTIO_BUS_UNKNOWN,
-	VIRTIO_BUS_PCI_LEGACY,
-	VIRTIO_BUS_PCI_MODERN,
-	VIRTIO_BUS_USER,
-};
-
 struct virtio_hw {
-	enum virtio_bus_type bus_type;
 	struct virtnet_ctl *cvq;
 	uint64_t    req_guest_features;
 	uint64_t    guest_features;
drivers/net/virtio/virtio_pci_ethdev.c +6 -1
index 076a5dbced..8cc6561914 100644
@@ -84,6 +84,11 @@ eth_virtio_pci_init(struct rte_eth_dev *eth_dev)
 			return -1;
 		}
 	} else {
+		if (dev->modern)
+			VTPCI_OPS(hw) = &modern_ops;
+		else
+			VTPCI_OPS(hw) = &legacy_ops;
+
 		ret = virtio_remap_pci(RTE_ETH_DEV_TO_PCI(eth_dev), dev);
 		if (ret < 0) {
 			PMD_INIT_LOG(ERR, "Failed to remap PCI device\n");
@@ -105,7 +110,7 @@ eth_virtio_pci_init(struct rte_eth_dev *eth_dev)
 
 err_unmap:
 	rte_pci_unmap_device(RTE_ETH_DEV_TO_PCI(eth_dev));
-	if (hw->bus_type == VIRTIO_BUS_PCI_LEGACY)
+	if (!dev->modern)
 		rte_pci_ioport_unmap(VTPCI_IO(hw));
 
 	return ret;
drivers/net/virtio/virtio_user_ethdev.c +4 -1
index bf958de571..61880a8e02 100644
@@ -641,7 +641,6 @@ virtio_user_eth_dev_alloc(struct rte_vdev_device *vdev)
 	 * Here just pretend that we support msix.
 	 */
 	hw->use_msix = 1;
-	hw->bus_type = VIRTIO_BUS_USER;
 	hw->use_vec_rx = 0;
 	hw->use_vec_tx = 0;
 	hw->use_inorder_rx = 0;
@@ -691,6 +690,10 @@ virtio_user_pmd_probe(struct rte_vdev_device *vdev)
 			return -1;
 		}
 
+		dev = eth_dev->data->dev_private;
+		hw = &dev->hw;
+		VTPCI_OPS(hw) = &virtio_user_ops;
+
 		if (eth_virtio_dev_init(eth_dev) < 0) {
 			PMD_INIT_LOG(ERR, "eth_virtio_dev_init fails");
 			rte_eth_dev_release_port(eth_dev);
Signature · 1 line
2.29.2
#22 lore raw

PATCH v4 15/44 net/virtio: move PCI-specific fields to PCI device

In reply to Maxime Coquelin

This patch moves the fields from virtio_hw structure that are PCI-specific to virtio_pci_dev_struct.

---
 drivers/net/virtio/virtio_pci.c | 139 ++++++++++++++++++--------------
 drivers/net/virtio/virtio_pci.h |  10 +--
 2 files changed, 85 insertions(+), 64 deletions(-)
drivers/net/virtio/virtio_pci.c +80 -59
index 20599774a7..b347e5fbc0 100644
@@ -344,18 +344,19 @@ static void
 modern_read_dev_config(struct virtio_hw *hw, size_t offset,
 		       void *dst, int length)
 {
+	struct virtio_pci_dev *dev = virtio_pci_get_dev(hw);
 	int i;
 	uint8_t *p;
 	uint8_t old_gen, new_gen;
 
 	do {
-		old_gen = rte_read8(&hw->common_cfg->config_generation);
+		old_gen = rte_read8(&dev->common_cfg->config_generation);
 
 		p = dst;
 		for (i = 0;  i < length; i++)
-			*p++ = rte_read8((uint8_t *)hw->dev_cfg + offset + i);
+			*p++ = rte_read8((uint8_t *)dev->dev_cfg + offset + i);
 
-		new_gen = rte_read8(&hw->common_cfg->config_generation);
+		new_gen = rte_read8(&dev->common_cfg->config_generation);
 	} while (old_gen != new_gen);
 }
 
@@ -363,23 +364,25 @@ static void
 modern_write_dev_config(struct virtio_hw *hw, size_t offset,
 			const void *src, int length)
 {
+	struct virtio_pci_dev *dev = virtio_pci_get_dev(hw);
 	int i;
 	const uint8_t *p = src;
 
 	for (i = 0;  i < length; i++)
-		rte_write8((*p++), (((uint8_t *)hw->dev_cfg) + offset + i));
+		rte_write8((*p++), (((uint8_t *)dev->dev_cfg) + offset + i));
 }
 
 static uint64_t
 modern_get_features(struct virtio_hw *hw)
 {
+	struct virtio_pci_dev *dev = virtio_pci_get_dev(hw);
 	uint32_t features_lo, features_hi;
 
-	rte_write32(0, &hw->common_cfg->device_feature_select);
-	features_lo = rte_read32(&hw->common_cfg->device_feature);
+	rte_write32(0, &dev->common_cfg->device_feature_select);
+	features_lo = rte_read32(&dev->common_cfg->device_feature);
 
-	rte_write32(1, &hw->common_cfg->device_feature_select);
-	features_hi = rte_read32(&hw->common_cfg->device_feature);
+	rte_write32(1, &dev->common_cfg->device_feature_select);
+	features_hi = rte_read32(&dev->common_cfg->device_feature);
 
 	return ((uint64_t)features_hi << 32) | features_lo;
 }
@@ -387,13 +390,15 @@ modern_get_features(struct virtio_hw *hw)
 static void
 modern_set_features(struct virtio_hw *hw, uint64_t features)
 {
-	rte_write32(0, &hw->common_cfg->guest_feature_select);
+	struct virtio_pci_dev *dev = virtio_pci_get_dev(hw);
+
+	rte_write32(0, &dev->common_cfg->guest_feature_select);
 	rte_write32(features & ((1ULL << 32) - 1),
-		    &hw->common_cfg->guest_feature);
+		    &dev->common_cfg->guest_feature);
 
-	rte_write32(1, &hw->common_cfg->guest_feature_select);
+	rte_write32(1, &dev->common_cfg->guest_feature_select);
 	rte_write32(features >> 32,
-		    &hw->common_cfg->guest_feature);
+		    &dev->common_cfg->guest_feature);
 }
 
 static int
@@ -410,46 +415,59 @@ modern_features_ok(struct virtio_hw *hw)
 static uint8_t
 modern_get_status(struct virtio_hw *hw)
 {
-	return rte_read8(&hw->common_cfg->device_status);
+	struct virtio_pci_dev *dev = virtio_pci_get_dev(hw);
+
+	return rte_read8(&dev->common_cfg->device_status);
 }
 
 static void
 modern_set_status(struct virtio_hw *hw, uint8_t status)
 {
-	rte_write8(status, &hw->common_cfg->device_status);
+	struct virtio_pci_dev *dev = virtio_pci_get_dev(hw);
+
+	rte_write8(status, &dev->common_cfg->device_status);
 }
 
 static uint8_t
 modern_get_isr(struct virtio_hw *hw)
 {
-	return rte_read8(hw->isr);
+	struct virtio_pci_dev *dev = virtio_pci_get_dev(hw);
+
+	return rte_read8(dev->isr);
 }
 
 static uint16_t
 modern_set_config_irq(struct virtio_hw *hw, uint16_t vec)
 {
-	rte_write16(vec, &hw->common_cfg->msix_config);
-	return rte_read16(&hw->common_cfg->msix_config);
+	struct virtio_pci_dev *dev = virtio_pci_get_dev(hw);
+
+	rte_write16(vec, &dev->common_cfg->msix_config);
+	return rte_read16(&dev->common_cfg->msix_config);
 }
 
 static uint16_t
 modern_set_queue_irq(struct virtio_hw *hw, struct virtqueue *vq, uint16_t vec)
 {
-	rte_write16(vq->vq_queue_index, &hw->common_cfg->queue_select);
-	rte_write16(vec, &hw->common_cfg->queue_msix_vector);
-	return rte_read16(&hw->common_cfg->queue_msix_vector);
+	struct virtio_pci_dev *dev = virtio_pci_get_dev(hw);
+
+	rte_write16(vq->vq_queue_index, &dev->common_cfg->queue_select);
+	rte_write16(vec, &dev->common_cfg->queue_msix_vector);
+	return rte_read16(&dev->common_cfg->queue_msix_vector);
 }
 
 static uint16_t
 modern_get_queue_num(struct virtio_hw *hw, uint16_t queue_id)
 {
-	rte_write16(queue_id, &hw->common_cfg->queue_select);
-	return rte_read16(&hw->common_cfg->queue_size);
+	struct virtio_pci_dev *dev = virtio_pci_get_dev(hw);
+
+	rte_write16(queue_id, &dev->common_cfg->queue_select);
+	return rte_read16(&dev->common_cfg->queue_size);
 }
 
 static int
 modern_setup_queue(struct virtio_hw *hw, struct virtqueue *vq)
 {
+	struct virtio_pci_dev *dev = virtio_pci_get_dev(hw);
 	uint64_t desc_addr, avail_addr, used_addr;
 	uint16_t notify_off;
 
@@ -462,20 +480,20 @@ modern_setup_queue(struct virtio_hw *hw, struct virtqueue *vq)
 							 ring[vq->vq_nentries]),
 				   VIRTIO_PCI_VRING_ALIGN);
 
-	rte_write16(vq->vq_queue_index, &hw->common_cfg->queue_select);
+	rte_write16(vq->vq_queue_index, &dev->common_cfg->queue_select);
 
-	io_write64_twopart(desc_addr, &hw->common_cfg->queue_desc_lo,
-				      &hw->common_cfg->queue_desc_hi);
-	io_write64_twopart(avail_addr, &hw->common_cfg->queue_avail_lo,
-				       &hw->common_cfg->queue_avail_hi);
-	io_write64_twopart(used_addr, &hw->common_cfg->queue_used_lo,
-				      &hw->common_cfg->queue_used_hi);
+	io_write64_twopart(desc_addr, &dev->common_cfg->queue_desc_lo,
+				      &dev->common_cfg->queue_desc_hi);
+	io_write64_twopart(avail_addr, &dev->common_cfg->queue_avail_lo,
+				       &dev->common_cfg->queue_avail_hi);
+	io_write64_twopart(used_addr, &dev->common_cfg->queue_used_lo,
+				      &dev->common_cfg->queue_used_hi);
 
-	notify_off = rte_read16(&hw->common_cfg->queue_notify_off);
-	vq->notify_addr = (void *)((uint8_t *)hw->notify_base +
-				notify_off * hw->notify_off_multiplier);
+	notify_off = rte_read16(&dev->common_cfg->queue_notify_off);
+	vq->notify_addr = (void *)((uint8_t *)dev->notify_base +
+				notify_off * dev->notify_off_multiplier);
 
-	rte_write16(1, &hw->common_cfg->queue_enable);
+	rte_write16(1, &dev->common_cfg->queue_enable);
 
 	PMD_INIT_LOG(DEBUG, "queue %u addresses:", vq->vq_queue_index);
 	PMD_INIT_LOG(DEBUG, "\t desc_addr: %" PRIx64, desc_addr);
@@ -490,16 +508,18 @@ modern_setup_queue(struct virtio_hw *hw, struct virtqueue *vq)
 static void
 modern_del_queue(struct virtio_hw *hw, struct virtqueue *vq)
 {
-	rte_write16(vq->vq_queue_index, &hw->common_cfg->queue_select);
+	struct virtio_pci_dev *dev = virtio_pci_get_dev(hw);
+
+	rte_write16(vq->vq_queue_index, &dev->common_cfg->queue_select);
 
-	io_write64_twopart(0, &hw->common_cfg->queue_desc_lo,
-				  &hw->common_cfg->queue_desc_hi);
-	io_write64_twopart(0, &hw->common_cfg->queue_avail_lo,
-				  &hw->common_cfg->queue_avail_hi);
-	io_write64_twopart(0, &hw->common_cfg->queue_used_lo,
-				  &hw->common_cfg->queue_used_hi);
+	io_write64_twopart(0, &dev->common_cfg->queue_desc_lo,
+				  &dev->common_cfg->queue_desc_hi);
+	io_write64_twopart(0, &dev->common_cfg->queue_avail_lo,
+				  &dev->common_cfg->queue_avail_hi);
+	io_write64_twopart(0, &dev->common_cfg->queue_used_lo,
+				  &dev->common_cfg->queue_used_hi);
 
-	rte_write16(0, &hw->common_cfg->queue_enable);
+	rte_write16(0, &dev->common_cfg->queue_enable);
 }
 
 static void
@@ -671,18 +691,19 @@ get_cfg_addr(struct rte_pci_device *dev, struct virtio_pci_cap *cap)
 }
 
 static int
-virtio_read_caps(struct rte_pci_device *dev, struct virtio_hw *hw)
+virtio_read_caps(struct rte_pci_device *pci_dev, struct virtio_hw *hw)
 {
+	struct virtio_pci_dev *dev = virtio_pci_get_dev(hw);
 	uint8_t pos;
 	struct virtio_pci_cap cap;
 	int ret;
 
-	if (rte_pci_map_device(dev)) {
+	if (rte_pci_map_device(pci_dev)) {
 		PMD_INIT_LOG(DEBUG, "failed to map pci device!");
 		return -1;
 	}
 
-	ret = rte_pci_read_config(dev, &pos, 1, PCI_CAPABILITY_LIST);
+	ret = rte_pci_read_config(pci_dev, &pos, 1, PCI_CAPABILITY_LIST);
 	if (ret != 1) {
 		PMD_INIT_LOG(DEBUG,
 			     "failed to read pci capability list, ret %d", ret);
@@ -690,7 +711,7 @@ virtio_read_caps(struct rte_pci_device *dev, struct virtio_hw *hw)
 	}
 
 	while (pos) {
-		ret = rte_pci_read_config(dev, &cap, 2, pos);
+		ret = rte_pci_read_config(pci_dev, &cap, 2, pos);
 		if (ret != 2) {
 			PMD_INIT_LOG(DEBUG,
 				     "failed to read pci cap at pos: %x ret %d",
@@ -706,7 +727,7 @@ virtio_read_caps(struct rte_pci_device *dev, struct virtio_hw *hw)
 			 */
 			uint16_t flags;
 
-			ret = rte_pci_read_config(dev, &flags, sizeof(flags),
+			ret = rte_pci_read_config(pci_dev, &flags, sizeof(flags),
 					pos + 2);
 			if (ret != sizeof(flags)) {
 				PMD_INIT_LOG(DEBUG,
@@ -728,7 +749,7 @@ virtio_read_caps(struct rte_pci_device *dev, struct virtio_hw *hw)
 			goto next;
 		}
 
-		ret = rte_pci_read_config(dev, &cap, sizeof(cap), pos);
+		ret = rte_pci_read_config(pci_dev, &cap, sizeof(cap), pos);
 		if (ret != sizeof(cap)) {
 			PMD_INIT_LOG(DEBUG,
 				     "failed to read pci cap at pos: %x ret %d",
@@ -742,24 +763,24 @@ virtio_read_caps(struct rte_pci_device *dev, struct virtio_hw *hw)
 
 		switch (cap.cfg_type) {
 		case VIRTIO_PCI_CAP_COMMON_CFG:
-			hw->common_cfg = get_cfg_addr(dev, &cap);
+			dev->common_cfg = get_cfg_addr(pci_dev, &cap);
 			break;
 		case VIRTIO_PCI_CAP_NOTIFY_CFG:
-			ret = rte_pci_read_config(dev,
-					&hw->notify_off_multiplier,
+			ret = rte_pci_read_config(pci_dev,
+					&dev->notify_off_multiplier,
 					4, pos + sizeof(cap));
 			if (ret != 4)
 				PMD_INIT_LOG(DEBUG,
 					"failed to read notify_off_multiplier, ret %d",
 					ret);
 			else
-				hw->notify_base = get_cfg_addr(dev, &cap);
+				dev->notify_base = get_cfg_addr(pci_dev, &cap);
 			break;
 		case VIRTIO_PCI_CAP_DEVICE_CFG:
-			hw->dev_cfg = get_cfg_addr(dev, &cap);
+			dev->dev_cfg = get_cfg_addr(pci_dev, &cap);
 			break;
 		case VIRTIO_PCI_CAP_ISR_CFG:
-			hw->isr = get_cfg_addr(dev, &cap);
+			dev->isr = get_cfg_addr(pci_dev, &cap);
 			break;
 		}
 
@@ -767,19 +788,19 @@ virtio_read_caps(struct rte_pci_device *dev, struct virtio_hw *hw)
 		pos = cap.cap_next;
 	}
 
-	if (hw->common_cfg == NULL || hw->notify_base == NULL ||
-	    hw->dev_cfg == NULL    || hw->isr == NULL) {
+	if (dev->common_cfg == NULL || dev->notify_base == NULL ||
+	    dev->dev_cfg == NULL    || dev->isr == NULL) {
 		PMD_INIT_LOG(INFO, "no modern virtio pci device found.");
 		return -1;
 	}
 
 	PMD_INIT_LOG(INFO, "found modern virtio pci device.");
 
-	PMD_INIT_LOG(DEBUG, "common cfg mapped at: %p", hw->common_cfg);
-	PMD_INIT_LOG(DEBUG, "device cfg mapped at: %p", hw->dev_cfg);
-	PMD_INIT_LOG(DEBUG, "isr cfg mapped at: %p", hw->isr);
+	PMD_INIT_LOG(DEBUG, "common cfg mapped at: %p", dev->common_cfg);
+	PMD_INIT_LOG(DEBUG, "device cfg mapped at: %p", dev->dev_cfg);
+	PMD_INIT_LOG(DEBUG, "isr cfg mapped at: %p", dev->isr);
 	PMD_INIT_LOG(DEBUG, "notify base: %p, notify off multiplier: %u",
-		hw->notify_base, hw->notify_off_multiplier);
+		dev->notify_base, dev->notify_off_multiplier);
 
 	return 0;
 }
drivers/net/virtio/virtio_pci.h +5 -5
index 2cede4a100..4f3690032b 100644
@@ -265,13 +265,8 @@ struct virtio_hw {
 	bool        has_rx_offload;
 	uint16_t    port_id;
 	uint8_t     mac_addr[RTE_ETHER_ADDR_LEN];
-	uint32_t    notify_off_multiplier;
 	uint32_t    speed;  /* link speed in MB */
 	uint8_t     duplex;
-	uint8_t     *isr;
-	uint16_t    *notify_base;
-	struct virtio_pci_common_cfg *common_cfg;
-	struct virtio_net_config *dev_cfg;
 	/*
 	 * App management thread and virtio interrupt handler thread
 	 * both can change device state, this lock is meant to avoid
@@ -287,6 +282,11 @@ struct virtio_hw {
 struct virtio_pci_dev {
 	struct virtio_hw hw;
 	struct rte_pci_device *pci_dev;
+	struct virtio_pci_common_cfg *common_cfg;
+	struct virtio_net_config *dev_cfg;
+	uint8_t *isr;
+	uint16_t *notify_base;
+	uint32_t notify_off_multiplier;
 	bool modern;
 };
 
Signature · 1 line
2.29.2
#23 lore raw

PATCH v4 16/44 net/virtio: pack virtio HW struct

In reply to Maxime Coquelin

This patch improves the virtio_hw struct packing, going from 88 down to 80 bytes with a 6 bytes hole in the end of the first cacheline. Fields only used in the slow path are placed in the end, so that hot path only uses the first cacheline.

The patch also changes booleans fields to uint8_t type, and fix inconsistencies in their assignments.

---
 drivers/net/virtio/virtio_ethdev.c | 12 ++++----
 drivers/net/virtio/virtio_pci.h    | 45 +++++++++++++++---------------
 drivers/net/virtio/virtqueue.h     |  2 +-
 3 files changed, 29 insertions(+), 30 deletions(-)
drivers/net/virtio/virtio_ethdev.c +6 -6
index c46fe4adf6..c1d7b14dda 100644
@@ -699,7 +699,7 @@ virtio_dev_close(struct rte_eth_dev *dev)
 
 	if (!hw->opened)
 		return 0;
-	hw->opened = false;
+	hw->opened = 0;
 
 	/* reset the NIC */
 	if (dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)
@@ -1864,7 +1864,7 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 		}
 	}
 
-	hw->opened = true;
+	hw->opened = 1;
 
 	return 0;
 
@@ -1973,7 +1973,7 @@ virtio_dev_devargs_parse(struct rte_devargs *devargs, uint32_t *speed, int *vect
 	return ret;
 }
 
-static bool
+static uint8_t
 rx_offload_enabled(struct virtio_hw *hw)
 {
 	return vtpci_with_feature(hw, VIRTIO_NET_F_GUEST_CSUM) ||
@@ -1981,7 +1981,7 @@ rx_offload_enabled(struct virtio_hw *hw)
 		vtpci_with_feature(hw, VIRTIO_NET_F_GUEST_TSO6);
 }
 
-static bool
+static uint8_t
 tx_offload_enabled(struct virtio_hw *hw)
 {
 	return vtpci_with_feature(hw, VIRTIO_NET_F_CSUM) ||
@@ -2267,7 +2267,7 @@ virtio_dev_start(struct rte_eth_dev *dev)
 	}
 
 	set_rxtx_funcs(dev);
-	hw->started = true;
+	hw->started = 1;
 
 	/* Initialize Link state */
 	virtio_dev_link_update(dev, 0);
@@ -2336,7 +2336,7 @@ virtio_dev_stop(struct rte_eth_dev *dev)
 	rte_spinlock_lock(&hw->state_lock);
 	if (!hw->started)
 		goto out_unlock;
-	hw->started = false;
+	hw->started = 0;
 
 	if (intr_conf->lsc || intr_conf->rxq) {
 		virtio_intr_disable(dev);
drivers/net/virtio/virtio_pci.h +22 -23

57 lines not on this page · raw message

drivers/net/virtio/virtqueue.h +1 -1
index 7611317581..3a9ce29069 100644
@@ -615,7 +615,7 @@ virtqueue_notify(struct virtqueue *vq)
 static inline void
 virtqueue_xmit_offload(struct virtio_net_hdr *hdr,
 			struct rte_mbuf *cookie,
-			bool offload)
+			uint8_t offload)
 {
 	if (offload) {
 		if (cookie->ol_flags & PKT_TX_TCP_SEG)
Signature · 1 line
2.29.2
#24 lore raw

PATCH v4 17/44 net/virtio: move legacy IO to Virtio PCI

In reply to Maxime Coquelin

This patch moves Virtio PCI legacy IO handling to virtio_pci.c. Two functions are created so that virtio_pci_ethdev does not have to care about it.

---
 drivers/net/virtio/virtio_pci.c        | 28 ++++++++++++++++++++++++--
 drivers/net/virtio/virtio_pci.h        |  9 +++------
 drivers/net/virtio/virtio_pci_ethdev.c |  6 ++----
 3 files changed, 31 insertions(+), 12 deletions(-)
drivers/net/virtio/virtio_pci.c +26 -2
index b347e5fbc0..3fe0631a30 100644
@@ -31,6 +31,15 @@
 #define VIRTIO_PCI_CONFIG(hw) \
 		(((hw)->use_msix == VIRTIO_MSIX_ENABLED) ? 24 : 20)
 
+
+struct virtio_pci_internal {
+	struct rte_pci_ioport io;
+};
+
+#define VTPCI_IO(hw) (&virtio_pci_internal[(hw)->port_id].io)
+
+struct virtio_pci_internal virtio_pci_internal[RTE_MAX_ETHPORTS];
+
 static inline int
 check_vq_phys_addr_ok(struct virtqueue *vq)
 {
@@ -300,7 +309,9 @@ legacy_notify_queue(struct virtio_hw *hw, struct virtqueue *vq)
 static void
 legacy_intr_detect(struct virtio_hw *hw)
 {
-	hw->use_msix = vtpci_msix_detect(VTPCI_DEV(hw));
+	struct virtio_pci_dev *dev = virtio_pci_get_dev(hw);
+
+	hw->use_msix = vtpci_msix_detect(dev->pci_dev);
 }
 
 static int
@@ -558,7 +569,9 @@ modern_notify_queue(struct virtio_hw *hw, struct virtqueue *vq)
 static void
 modern_intr_detect(struct virtio_hw *hw)
 {
-	hw->use_msix = vtpci_msix_detect(VTPCI_DEV(hw));
+	struct virtio_pci_dev *dev = virtio_pci_get_dev(hw);
+
+	hw->use_msix = vtpci_msix_detect(dev->pci_dev);
 }
 
 static int
@@ -857,3 +870,14 @@ vtpci_init(struct rte_pci_device *pci_dev, struct virtio_pci_dev *dev)
 	return 0;
 }
 
+void vtpci_legacy_ioport_unmap(struct virtio_hw *hw)
+{
+	rte_pci_ioport_unmap(VTPCI_IO(hw));
+}
+
+int vtpci_legacy_ioport_map(struct virtio_hw *hw)
+{
+	struct virtio_pci_dev *dev = virtio_pci_get_dev(hw);
+
+	return rte_pci_ioport_map(dev->pci_dev, 0, VTPCI_IO(hw));
+}
drivers/net/virtio/virtio_pci.h +3 -6
index 15f8144fc6..def8faca72 100644
@@ -298,18 +298,12 @@ struct virtio_pci_dev {
  */
 struct virtio_hw_internal {
 	const struct virtio_pci_ops *vtpci_ops;
-	struct rte_pci_ioport io;
-	struct rte_pci_device *dev;
 };
 
 #define VTPCI_OPS(hw)	(virtio_hw_internal[(hw)->port_id].vtpci_ops)
-#define VTPCI_IO(hw)	(&virtio_hw_internal[(hw)->port_id].io)
-#define VTPCI_DEV(hw)	(virtio_hw_internal[(hw)->port_id].dev)
-
 
 extern struct virtio_hw_internal virtio_hw_internal[RTE_MAX_ETHPORTS];
 
-
 /*
  * This structure is just a reference to read
  * net device specific config space; it just a chodu structure
@@ -382,6 +376,9 @@ void vtpci_read_dev_config(struct virtio_hw *, size_t, void *, int);
 
 uint8_t vtpci_isr(struct virtio_hw *);
 
+void vtpci_legacy_ioport_unmap(struct virtio_hw *hw);
+int vtpci_legacy_ioport_map(struct virtio_hw *hw);
+
 extern const struct virtio_pci_ops legacy_ops;
 extern const struct virtio_pci_ops modern_ops;
 extern const struct virtio_pci_ops virtio_user_ops;
drivers/net/virtio/virtio_pci_ethdev.c +2 -4
index 8cc6561914..9fe59feb51 100644
@@ -60,7 +60,7 @@ virtio_remap_pci(struct rte_pci_device *pci_dev, struct virtio_pci_dev *dev)
 			return -1;
 		}
 	} else {
-		if (rte_pci_ioport_map(pci_dev, 0, VTPCI_IO(hw)) < 0)
+		if (vtpci_legacy_ioport_map(hw) < 0)
 			return -1;
 	}
 
@@ -75,8 +75,6 @@ eth_virtio_pci_init(struct rte_eth_dev *eth_dev)
 	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
 	int ret;
 
-	VTPCI_DEV(hw) = pci_dev;
-
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
 		ret = vtpci_init(RTE_ETH_DEV_TO_PCI(eth_dev), dev);
 		if (ret) {
@@ -111,7 +109,7 @@ eth_virtio_pci_init(struct rte_eth_dev *eth_dev)
 err_unmap:
 	rte_pci_unmap_device(RTE_ETH_DEV_TO_PCI(eth_dev));
 	if (!dev->modern)
-		rte_pci_ioport_unmap(VTPCI_IO(hw));
+		vtpci_legacy_ioport_unmap(hw);
 
 	return ret;
 }
Signature · 1 line
2.29.2
#25 lore raw

PATCH v4 18/44 net/virtio: introduce generic virtio header

In reply to Maxime Coquelin

This patch moves virtio_hw and virtio callbacks into a generic virtio header, now that they have been curated from PCI references.

---
 drivers/net/virtio/virtio.h             | 74 ++++++++++++++++++++++
 drivers/net/virtio/virtio_ethdev.c      | 32 +++++-----
 drivers/net/virtio/virtio_pci.c         | 28 ++++-----
 drivers/net/virtio/virtio_pci.h         | 84 ++-----------------------
 drivers/net/virtio/virtio_pci_ethdev.c  |  5 +-
 drivers/net/virtio/virtio_user_ethdev.c |  8 +--
 drivers/net/virtio/virtqueue.h          |  2 +-
 7 files changed, 116 insertions(+), 117 deletions(-)
 create mode 100644 drivers/net/virtio/virtio.h
drivers/net/virtio/virtio.h new file +74 -0
new file mode 100644
index 0000000000..e55e3329f9
@@ -0,0 +1,74 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2010-2014 Intel Corporation
+ * Copyright(c) 2021 Red Hat, Inc.
+ */
+
+#ifndef _VIRTIO_H_
+#define _VIRTIO_H_
+
+#include <rte_ether.h>
+
+struct virtio_hw {
+	struct virtqueue **vqs;
+	uint64_t guest_features;
+	uint16_t vtnet_hdr_size;
+	uint8_t started;
+	uint8_t weak_barriers;
+	uint8_t vlan_strip;
+	uint8_t has_tx_offload;
+	uint8_t has_rx_offload;
+	uint8_t use_vec_rx;
+	uint8_t use_vec_tx;
+	uint8_t use_inorder_rx;
+	uint8_t use_inorder_tx;
+	uint8_t opened;
+	uint16_t port_id;
+	uint8_t mac_addr[RTE_ETHER_ADDR_LEN];
+	uint32_t speed;  /* link speed in MB */
+	uint8_t duplex;
+	uint8_t use_msix;
+	uint16_t max_mtu;
+	/*
+	 * App management thread and virtio interrupt handler thread
+	 * both can change device state, this lock is meant to avoid
+	 * such a contention.
+	 */
+	rte_spinlock_t state_lock;
+	struct rte_mbuf **inject_pkts;
+	uint16_t max_queue_pairs;
+	uint64_t req_guest_features;
+	struct virtnet_ctl *cvq;
+};
+
+struct virtio_ops {
+	void (*read_dev_cfg)(struct virtio_hw *hw, size_t offset, void *dst, int len);
+	void (*write_dev_cfg)(struct virtio_hw *hw, size_t offset, const void *src, int len);
+	uint8_t (*get_status)(struct virtio_hw *hw);
+	void (*set_status)(struct virtio_hw *hw, uint8_t status);
+	uint64_t (*get_features)(struct virtio_hw *hw);
+	void (*set_features)(struct virtio_hw *hw, uint64_t features);
+	int (*features_ok)(struct virtio_hw *hw);
+	uint8_t (*get_isr)(struct virtio_hw *hw);
+	uint16_t (*set_config_irq)(struct virtio_hw *hw, uint16_t vec);
+	uint16_t (*set_queue_irq)(struct virtio_hw *hw, struct virtqueue *vq, uint16_t vec);
+	uint16_t (*get_queue_num)(struct virtio_hw *hw, uint16_t queue_id);
+	int (*setup_queue)(struct virtio_hw *hw, struct virtqueue *vq);
+	void (*del_queue)(struct virtio_hw *hw, struct virtqueue *vq);
+	void (*notify_queue)(struct virtio_hw *hw, struct virtqueue *vq);
+	void (*intr_detect)(struct virtio_hw *hw);
+	int (*dev_close)(struct virtio_hw *hw);
+};
+
+/*
+ * This structure stores per-process data. Only virtio_ops for now.
+ */
+struct virtio_hw_internal {
+	const struct virtio_ops *virtio_ops;
+};
+
+#define VIRTIO_OPS(hw)	(virtio_hw_internal[(hw)->port_id].virtio_ops)
+
+extern struct virtio_hw_internal virtio_hw_internal[RTE_MAX_ETHPORTS];
+
+
+#endif /* _VIRTIO_H_ */
drivers/net/virtio/virtio_ethdev.c +16 -16
index c1d7b14dda..4b22622d2d 100644
@@ -446,7 +446,7 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)
 	 * Read the virtqueue size from the Queue Size field
 	 * Always power of 2 and if 0 virtqueue does not exist
 	 */
-	vq_size = VTPCI_OPS(hw)->get_queue_num(hw, vtpci_queue_idx);
+	vq_size = VIRTIO_OPS(hw)->get_queue_num(hw, vtpci_queue_idx);
 	PMD_INIT_LOG(DEBUG, "vq_size: %u", vq_size);
 	if (vq_size == 0) {
 		PMD_INIT_LOG(ERR, "virtqueue does not exist");
@@ -608,7 +608,7 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)
 		}
 	}
 
-	if (VTPCI_OPS(hw)->setup_queue(hw, vq) < 0) {
+	if (VIRTIO_OPS(hw)->setup_queue(hw, vq) < 0) {
 		PMD_INIT_LOG(ERR, "setup_queue failed");
 		return -EINVAL;
 	}
@@ -703,7 +703,7 @@ virtio_dev_close(struct rte_eth_dev *dev)
 
 	/* reset the NIC */
 	if (dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)
-		VTPCI_OPS(hw)->set_config_irq(hw, VIRTIO_MSI_NO_VECTOR);
+		VIRTIO_OPS(hw)->set_config_irq(hw, VIRTIO_MSI_NO_VECTOR);
 	if (intr_conf->rxq)
 		virtio_queues_unbind_intr(dev);
 
@@ -718,7 +718,7 @@ virtio_dev_close(struct rte_eth_dev *dev)
 	virtio_dev_free_mbufs(dev);
 	virtio_free_queues(hw);
 
-	return VTPCI_OPS(hw)->dev_close(hw);
+	return VIRTIO_OPS(hw)->dev_close(hw);
 }
 
 static int
@@ -1261,8 +1261,8 @@ virtio_intr_unmask(struct rte_eth_dev *dev)
 	if (rte_intr_ack(dev->intr_handle) < 0)
 		return -1;
 
-	if (VTPCI_OPS(hw)->intr_detect)
-		VTPCI_OPS(hw)->intr_detect(hw);
+	if (VIRTIO_OPS(hw)->intr_detect)
+		VIRTIO_OPS(hw)->intr_detect(hw);
 
 	return 0;
 }
@@ -1275,8 +1275,8 @@ virtio_intr_enable(struct rte_eth_dev *dev)
 	if (rte_intr_enable(dev->intr_handle) < 0)
 		return -1;
 
-	if (VTPCI_OPS(hw)->intr_detect)
-		VTPCI_OPS(hw)->intr_detect(hw);
+	if (VIRTIO_OPS(hw)->intr_detect)
+		VIRTIO_OPS(hw)->intr_detect(hw);
 
 	return 0;
 }
@@ -1289,8 +1289,8 @@ virtio_intr_disable(struct rte_eth_dev *dev)
 	if (rte_intr_disable(dev->intr_handle) < 0)
 		return -1;
 
-	if (VTPCI_OPS(hw)->intr_detect)
-		VTPCI_OPS(hw)->intr_detect(hw);
+	if (VIRTIO_OPS(hw)->intr_detect)
+		VIRTIO_OPS(hw)->intr_detect(hw);
 
 	return 0;
 }
@@ -1305,7 +1305,7 @@ virtio_negotiate_features(struct virtio_hw *hw, uint64_t req_features)
 		req_features);
 
 	/* Read device(host) feature bits */
-	host_features = VTPCI_OPS(hw)->get_features(hw);
+	host_features = VIRTIO_OPS(hw)->get_features(hw);
 	PMD_INIT_LOG(DEBUG, "host_features before negotiate = %" PRIx64,
 		host_features);
 
@@ -1330,7 +1330,7 @@ virtio_negotiate_features(struct virtio_hw *hw, uint64_t req_features)
 	PMD_INIT_LOG(DEBUG, "features after negotiate = %" PRIx64,
 		hw->guest_features);
 
-	if (VTPCI_OPS(hw)->features_ok(hw) < 0)
+	if (VIRTIO_OPS(hw)->features_ok(hw) < 0)
 		return -1;
 
 	if (vtpci_with_feature(hw, VIRTIO_F_VERSION_1)) {
@@ -1564,7 +1564,7 @@ virtio_queues_bind_intr(struct rte_eth_dev *dev)
 	PMD_INIT_LOG(INFO, "queue/interrupt binding");
 	for (i = 0; i < dev->data->nb_rx_queues; ++i) {
 		dev->intr_handle->intr_vec[i] = i + 1;
-		if (VTPCI_OPS(hw)->set_queue_irq(hw, hw->vqs[i * 2], i + 1) ==
+		if (VIRTIO_OPS(hw)->set_queue_irq(hw, hw->vqs[i * 2], i + 1) ==
 						 VIRTIO_MSI_NO_VECTOR) {
 			PMD_DRV_LOG(ERR, "failed to set queue vector");
 			return -EBUSY;
@@ -1582,7 +1582,7 @@ virtio_queues_unbind_intr(struct rte_eth_dev *dev)
 
 	PMD_INIT_LOG(INFO, "queue/interrupt unbinding");
 	for (i = 0; i < dev->data->nb_rx_queues; ++i)
-		VTPCI_OPS(hw)->set_queue_irq(hw,
+		VIRTIO_OPS(hw)->set_queue_irq(hw,
 					     hw->vqs[i * VTNET_CQ],
 					     VIRTIO_MSI_NO_VECTOR);
 }
@@ -2092,7 +2092,7 @@ virtio_dev_configure(struct rte_eth_dev *dev)
 
 	if (dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)
 		/* Enable vector (0) for Link State Intrerrupt */
-		if (VTPCI_OPS(hw)->set_config_irq(hw, 0) ==
+		if (VIRTIO_OPS(hw)->set_config_irq(hw, 0) ==
 				VIRTIO_MSI_NO_VECTOR) {
 			PMD_DRV_LOG(ERR, "failed to set config vector");
 			return -EBUSY;
@@ -2433,7 +2433,7 @@ virtio_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	dev_info->max_rx_pktlen = VIRTIO_MAX_RX_PKTLEN;
 	dev_info->max_mac_addrs = VIRTIO_MAX_MAC_ADDRS;
 
-	host_features = VTPCI_OPS(hw)->get_features(hw);
+	host_features = VIRTIO_OPS(hw)->get_features(hw);
 	dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP;
 	dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_JUMBO_FRAME;
 	if (host_features & (1ULL << VIRTIO_NET_F_GUEST_CSUM)) {
drivers/net/virtio/virtio_pci.c +14 -14
index 3fe0631a30..e0d8a53ca6 100644
@@ -325,7 +325,7 @@ legacy_dev_close(struct virtio_hw *hw)
 	return 0;
 }
 
-const struct virtio_pci_ops legacy_ops = {
+const struct virtio_ops legacy_ops = {
 	.read_dev_cfg	= legacy_read_dev_config,
 	.write_dev_cfg	= legacy_write_dev_config,
 	.get_status	= legacy_get_status,
@@ -584,7 +584,7 @@ modern_dev_close(struct virtio_hw *hw)
 	return 0;
 }
 
-const struct virtio_pci_ops modern_ops = {
+const struct virtio_ops modern_ops = {
 	.read_dev_cfg	= modern_read_dev_config,
 	.write_dev_cfg	= modern_write_dev_config,
 	.get_status	= modern_get_status,
@@ -608,14 +608,14 @@ void
 vtpci_read_dev_config(struct virtio_hw *hw, size_t offset,
 		      void *dst, int length)
 {
-	VTPCI_OPS(hw)->read_dev_cfg(hw, offset, dst, length);
+	VIRTIO_OPS(hw)->read_dev_cfg(hw, offset, dst, length);
 }
 
 void
 vtpci_write_dev_config(struct virtio_hw *hw, size_t offset,
 		       const void *src, int length)
 {
-	VTPCI_OPS(hw)->write_dev_cfg(hw, offset, src, length);
+	VIRTIO_OPS(hw)->write_dev_cfg(hw, offset, src, length);
 }
 
 uint64_t
@@ -628,7 +628,7 @@ vtpci_negotiate_features(struct virtio_hw *hw, uint64_t host_features)
 	 * host all support.
 	 */
 	features = host_features & hw->guest_features;
-	VTPCI_OPS(hw)->set_features(hw, features);
+	VIRTIO_OPS(hw)->set_features(hw, features);
 
 	return features;
 }
@@ -636,9 +636,9 @@ vtpci_negotiate_features(struct virtio_hw *hw, uint64_t host_features)
 void
 vtpci_reset(struct virtio_hw *hw)
 {
-	VTPCI_OPS(hw)->set_status(hw, VIRTIO_CONFIG_STATUS_RESET);
+	VIRTIO_OPS(hw)->set_status(hw, VIRTIO_CONFIG_STATUS_RESET);
 	/* flush status write */
-	VTPCI_OPS(hw)->get_status(hw);
+	VIRTIO_OPS(hw)->get_status(hw);
 }
 
 void
@@ -651,21 +651,21 @@ void
 vtpci_set_status(struct virtio_hw *hw, uint8_t status)
 {
 	if (status != VIRTIO_CONFIG_STATUS_RESET)
-		status |= VTPCI_OPS(hw)->get_status(hw);
+		status |= VIRTIO_OPS(hw)->get_status(hw);
 
-	VTPCI_OPS(hw)->set_status(hw, status);
+	VIRTIO_OPS(hw)->set_status(hw, status);
 }
 
 uint8_t
 vtpci_get_status(struct virtio_hw *hw)
 {
-	return VTPCI_OPS(hw)->get_status(hw);
+	return VIRTIO_OPS(hw)->get_status(hw);
 }
 
 uint8_t
 vtpci_isr(struct virtio_hw *hw)
 {
-	return VTPCI_OPS(hw)->get_isr(hw);
+	return VIRTIO_OPS(hw)->get_isr(hw);
 }
 
 static void *
@@ -842,7 +842,7 @@ vtpci_init(struct rte_pci_device *pci_dev, struct virtio_pci_dev *dev)
 	 */
 	if (virtio_read_caps(pci_dev, hw) == 0) {
 		PMD_INIT_LOG(INFO, "modern virtio pci detected.");
-		virtio_hw_internal[hw->port_id].vtpci_ops = &modern_ops;
+		VIRTIO_OPS(hw) = &modern_ops;
 		dev->modern = true;
 		goto msix_detect;
 	}
@@ -861,11 +861,11 @@ vtpci_init(struct rte_pci_device *pci_dev, struct virtio_pci_dev *dev)
 		return -1;
 	}
 
-	virtio_hw_internal[hw->port_id].vtpci_ops = &legacy_ops;
+	VIRTIO_OPS(hw) = &legacy_ops;
 	dev->modern = false;
 
 msix_detect:
-	VTPCI_OPS(hw)->intr_detect(hw);
+	VIRTIO_OPS(hw)->intr_detect(hw);
 
 	return 0;
 }
drivers/net/virtio/virtio_pci.h +4 -80

107 lines not on this page · raw message

drivers/net/virtio/virtio_pci_ethdev.c +3 -2
index 9fe59feb51..fb462572fb 100644
@@ -19,6 +19,7 @@
 #include <rte_dev.h>
 #include <rte_kvargs.h>
 
+#include "virtio.h"
 #include "virtio_ethdev.h"
 #include "virtio_pci.h"
 #include "virtio_logs.h"
@@ -83,9 +84,9 @@ eth_virtio_pci_init(struct rte_eth_dev *eth_dev)
 		}
 	} else {
 		if (dev->modern)
-			VTPCI_OPS(hw) = &modern_ops;
+			VIRTIO_OPS(hw) = &modern_ops;
 		else
-			VTPCI_OPS(hw) = &legacy_ops;
+			VIRTIO_OPS(hw) = &legacy_ops;
 
 		ret = virtio_remap_pci(RTE_ETH_DEV_TO_PCI(eth_dev), dev);
 		if (ret < 0) {
drivers/net/virtio/virtio_user_ethdev.c +4 -4
index 61880a8e02..6597c16539 100644
@@ -20,7 +20,7 @@
 
 #include "virtio_ethdev.h"
 #include "virtio_logs.h"
-#include "virtio_pci.h"
+#include "virtio.h"
 #include "virtqueue.h"
 #include "virtio_rxtx.h"
 #include "virtio_user/virtio_user_dev.h"
@@ -478,7 +478,7 @@ virtio_user_dev_close(struct virtio_hw *hw)
 	return 0;
 }
 
-const struct virtio_pci_ops virtio_user_ops = {
+const struct virtio_ops virtio_user_ops = {
 	.read_dev_cfg	= virtio_user_read_dev_config,
 	.write_dev_cfg	= virtio_user_write_dev_config,
 	.get_status	= virtio_user_get_status,
@@ -635,7 +635,7 @@ virtio_user_eth_dev_alloc(struct rte_vdev_device *vdev)
 
 	hw->port_id = data->port_id;
 	dev->port_id = data->port_id;
-	virtio_hw_internal[hw->port_id].vtpci_ops = &virtio_user_ops;
+	VIRTIO_OPS(hw) = &virtio_user_ops;
 	/*
 	 * MSIX is required to enable LSC (see virtio_init_device).
 	 * Here just pretend that we support msix.
@@ -692,7 +692,7 @@ virtio_user_pmd_probe(struct rte_vdev_device *vdev)
 
 		dev = eth_dev->data->dev_private;
 		hw = &dev->hw;
-		VTPCI_OPS(hw) = &virtio_user_ops;
+		VIRTIO_OPS(hw) = &virtio_user_ops;
 
 		if (eth_virtio_dev_init(eth_dev) < 0) {
 			PMD_INIT_LOG(ERR, "eth_virtio_dev_init fails");
drivers/net/virtio/virtqueue.h +1 -1
index 3a9ce29069..6293cd2604 100644
@@ -563,7 +563,7 @@ virtqueue_kick_prepare_packed(struct virtqueue *vq)
 static inline void
 virtqueue_notify(struct virtqueue *vq)
 {
-	VTPCI_OPS(vq->hw)->notify_queue(vq->hw, vq);
+	VIRTIO_OPS(vq->hw)->notify_queue(vq->hw, vq);
 }
 
 #ifdef RTE_LIBRTE_VIRTIO_DEBUG_DUMP
Signature · 1 line
2.29.2
#26 lore raw

PATCH v4 19/44 net/virtio: move features definition to generic header

In reply to Maxime Coquelin

This patch moves all the Virtio definition to the generic header. It also renames some helpers to no more reference PCI.

---
 drivers/net/virtio/meson.build                |   3 +-
 drivers/net/virtio/virtio.c                   |  22 ++++
 drivers/net/virtio/virtio.h                   |  94 +++++++++++++++
 drivers/net/virtio/virtio_ethdev.c            | 114 +++++++++---------
 drivers/net/virtio/virtio_pci.c               |  21 +---
 drivers/net/virtio/virtio_pci.h               |  90 --------------
 drivers/net/virtio/virtio_ring.h              |   2 +-
 drivers/net/virtio/virtio_rxtx.c              |  38 +++---
 drivers/net/virtio/virtio_rxtx_packed.h       |   6 +-
 .../net/virtio/virtio_user/vhost_kernel_tap.c |   2 +-
 drivers/net/virtio/virtio_user_ethdev.c       |   6 +-
 drivers/net/virtio/virtqueue.c                |   4 +-
 drivers/net/virtio/virtqueue.h                |   8 +-
 13 files changed, 211 insertions(+), 199 deletions(-)
 create mode 100644 drivers/net/virtio/virtio.c
drivers/net/virtio/meson.build +2 -1
index f2873d6180..d595cfdcab 100644
@@ -7,7 +7,8 @@ if is_windows
 	subdir_done()
 endif
 
-sources += files('virtio_ethdev.c',
+sources += files('virtio.c',
+	'virtio_ethdev.c',
 	'virtio_pci_ethdev.c',
 	'virtio_pci.c',
 	'virtio_rxtx.c',
drivers/net/virtio/virtio.c new file +22 -0
new file mode 100644
index 0000000000..d8d6bf7add
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2010-2014 Intel Corporation
+ * Copyright(c) 2020 Red Hat, Inc.
+ */
+
+#include "virtio.h"
+
+uint64_t
+virtio_negotiate_features(struct virtio_hw *hw, uint64_t host_features)
+{
+	uint64_t features;
+
+	/*
+	 * Limit negotiated features to what the driver, virtqueue, and
+	 * host all support.
+	 */
+	features = host_features & hw->guest_features;
+	VIRTIO_OPS(hw)->set_features(hw, features);
+
+	return features;
+}
+
drivers/net/virtio/virtio.h +94 -0

104 lines not on this page · raw message

drivers/net/virtio/virtio_ethdev.c +57 -57

383 lines not on this page · raw message

drivers/net/virtio/virtio_pci.c +3 -18
index e0d8a53ca6..977a21317f 100644
@@ -415,7 +415,7 @@ modern_set_features(struct virtio_hw *hw, uint64_t features)
 static int
 modern_features_ok(struct virtio_hw *hw)
 {
-	if (!vtpci_with_feature(hw, VIRTIO_F_VERSION_1)) {
+	if (!virtio_with_feature(hw, VIRTIO_F_VERSION_1)) {
 		PMD_INIT_LOG(ERR, "Version 1+ required with modern devices\n");
 		return -1;
 	}
@@ -538,12 +538,12 @@ modern_notify_queue(struct virtio_hw *hw, struct virtqueue *vq)
 {
 	uint32_t notify_data;
 
-	if (!vtpci_with_feature(hw, VIRTIO_F_NOTIFICATION_DATA)) {
+	if (!virtio_with_feature(hw, VIRTIO_F_NOTIFICATION_DATA)) {
 		rte_write16(vq->vq_queue_index, vq->notify_addr);
 		return;
 	}
 
-	if (vtpci_with_feature(hw, VIRTIO_F_RING_PACKED)) {
+	if (virtio_with_packed_queue(hw)) {
 		/*
 		 * Bit[0:15]: vq queue index
 		 * Bit[16:30]: avail index
@@ -618,21 +618,6 @@ vtpci_write_dev_config(struct virtio_hw *hw, size_t offset,
 	VIRTIO_OPS(hw)->write_dev_cfg(hw, offset, src, length);
 }
 
-uint64_t
-vtpci_negotiate_features(struct virtio_hw *hw, uint64_t host_features)
-{
-	uint64_t features;
-
-	/*
-	 * Limit negotiated features to what the driver, virtqueue, and
-	 * host all support.
-	 */
-	features = host_features & hw->guest_features;
-	VIRTIO_OPS(hw)->set_features(hw, features);
-
-	return features;
-}
-
 void
 vtpci_reset(struct virtio_hw *hw)
 {
drivers/net/virtio/virtio_pci.h +0 -90

108 lines not on this page · raw message

drivers/net/virtio/virtio_ring.h +1 -1
index 0f6574f684..17a56b0a73 100644
@@ -133,7 +133,7 @@ vring_size(struct virtio_hw *hw, unsigned int num, unsigned long align)
 {
 	size_t size;
 
-	if (vtpci_packed_queue(hw)) {
+	if (virtio_with_packed_queue(hw)) {
 		size = num * sizeof(struct vring_packed_desc);
 		size += sizeof(struct vring_packed_desc_event);
 		size = RTE_ALIGN_CEIL(size, align);
drivers/net/virtio/virtio_rxtx.c +19 -19
index 6875c8fbee..728085e99b 100644
@@ -685,14 +685,14 @@ virtio_dev_rx_queue_setup_finish(struct rte_eth_dev *dev, uint16_t queue_idx)
 	struct rte_mbuf *m;
 	uint16_t desc_idx;
 	int error, nbufs, i;
-	bool in_order = vtpci_with_feature(hw, VIRTIO_F_IN_ORDER);
+	bool in_order = virtio_with_feature(hw, VIRTIO_F_IN_ORDER);
 
 	PMD_INIT_FUNC_TRACE();
 
 	/* Allocate blank mbufs for the each rx descriptor */
 	nbufs = 0;
 
-	if (hw->use_vec_rx && !vtpci_packed_queue(hw)) {
+	if (hw->use_vec_rx && !virtio_with_packed_queue(hw)) {
 		for (desc_idx = 0; desc_idx < vq->vq_nentries;
 		     desc_idx++) {
 			vq->vq_split.ring.avail->ring[desc_idx] = desc_idx;
@@ -710,12 +710,12 @@ virtio_dev_rx_queue_setup_finish(struct rte_eth_dev *dev, uint16_t queue_idx)
 			&rxvq->fake_mbuf;
 	}
 
-	if (hw->use_vec_rx && !vtpci_packed_queue(hw)) {
+	if (hw->use_vec_rx && !virtio_with_packed_queue(hw)) {
 		while (vq->vq_free_cnt >= RTE_VIRTIO_VPMD_RX_REARM_THRESH) {
 			virtio_rxq_rearm_vec(rxvq);
 			nbufs += RTE_VIRTIO_VPMD_RX_REARM_THRESH;
 		}
-	} else if (!vtpci_packed_queue(vq->hw) && in_order) {
+	} else if (!virtio_with_packed_queue(vq->hw) && in_order) {
 		if ((!virtqueue_full(vq))) {
 			uint16_t free_cnt = vq->vq_free_cnt;
 			struct rte_mbuf *pkts[free_cnt];
@@ -741,7 +741,7 @@ virtio_dev_rx_queue_setup_finish(struct rte_eth_dev *dev, uint16_t queue_idx)
 				break;
 
 			/* Enqueue allocated buffers */
-			if (vtpci_packed_queue(vq->hw))
+			if (virtio_with_packed_queue(vq->hw))
 				error = virtqueue_enqueue_recv_refill_packed(vq,
 						&m, 1);
 			else
@@ -754,7 +754,7 @@ virtio_dev_rx_queue_setup_finish(struct rte_eth_dev *dev, uint16_t queue_idx)
 			nbufs++;
 		}
 
-		if (!vtpci_packed_queue(vq->hw))
+		if (!virtio_with_packed_queue(vq->hw))
 			vq_update_avail_idx(vq);
 	}
 
@@ -829,8 +829,8 @@ virtio_dev_tx_queue_setup_finish(struct rte_eth_dev *dev,
 
 	PMD_INIT_FUNC_TRACE();
 
-	if (!vtpci_packed_queue(hw)) {
-		if (vtpci_with_feature(hw, VIRTIO_F_IN_ORDER))
+	if (!virtio_with_packed_queue(hw)) {
+		if (virtio_with_feature(hw, VIRTIO_F_IN_ORDER))
 			vq->vq_split.ring.desc[vq->vq_nentries - 1].next = 0;
 	}
 
@@ -847,7 +847,7 @@ virtio_discard_rxbuf(struct virtqueue *vq, struct rte_mbuf *m)
 	 * Requeue the discarded mbuf. This should always be
 	 * successful since it was just dequeued.
 	 */
-	if (vtpci_packed_queue(vq->hw))
+	if (virtio_with_packed_queue(vq->hw))
 		error = virtqueue_enqueue_recv_refill_packed(vq, &m, 1);
 	else
 		error = virtqueue_enqueue_recv_refill(vq, &m, 1);
@@ -1209,7 +1209,7 @@ virtio_recv_pkts_inorder(void *rx_queue,
 			 ((char *)rxm->buf_addr + RTE_PKTMBUF_HEADROOM
 			 - hdr_size);
 
-		if (vtpci_with_feature(hw, VIRTIO_NET_F_MRG_RXBUF)) {
+		if (virtio_with_feature(hw, VIRTIO_NET_F_MRG_RXBUF)) {
 			seg_num = header->num_buffers;
 			if (seg_num == 0)
 				seg_num = 1;
@@ -1735,7 +1735,7 @@ virtio_xmit_pkts_packed(void *tx_queue, struct rte_mbuf **tx_pkts,
 	struct virtio_hw *hw = vq->hw;
 	uint16_t hdr_size = hw->vtnet_hdr_size;
 	uint16_t nb_tx = 0;
-	bool in_order = vtpci_with_feature(hw, VIRTIO_F_IN_ORDER);
+	bool in_order = virtio_with_feature(hw, VIRTIO_F_IN_ORDER);
 
 	if (unlikely(hw->started == 0 && tx_pkts != hw->inject_pkts))
 		return nb_tx;
@@ -1754,8 +1754,8 @@ virtio_xmit_pkts_packed(void *tx_queue, struct rte_mbuf **tx_pkts,
 		int can_push = 0, use_indirect = 0, slots, need;
 
 		/* optimize ring usage */
-		if ((vtpci_with_feature(hw, VIRTIO_F_ANY_LAYOUT) ||
-		      vtpci_with_feature(hw, VIRTIO_F_VERSION_1)) &&
+		if ((virtio_with_feature(hw, VIRTIO_F_ANY_LAYOUT) ||
+		      virtio_with_feature(hw, VIRTIO_F_VERSION_1)) &&
 		    rte_mbuf_refcnt_read(txm) == 1 &&
 		    RTE_MBUF_DIRECT(txm) &&
 		    txm->nb_segs == 1 &&
@@ -1763,7 +1763,7 @@ virtio_xmit_pkts_packed(void *tx_queue, struct rte_mbuf **tx_pkts,
 		    rte_is_aligned(rte_pktmbuf_mtod(txm, char *),
 			   __alignof__(struct virtio_net_hdr_mrg_rxbuf)))
 			can_push = 1;
-		else if (vtpci_with_feature(hw, VIRTIO_RING_F_INDIRECT_DESC) &&
+		else if (virtio_with_feature(hw, VIRTIO_RING_F_INDIRECT_DESC) &&
 			 txm->nb_segs < VIRTIO_MAX_TX_INDIRECT)
 			use_indirect = 1;
 		/* How many main ring entries are needed to this Tx?
@@ -1835,8 +1835,8 @@ virtio_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
 		int can_push = 0, use_indirect = 0, slots, need;
 
 		/* optimize ring usage */
-		if ((vtpci_with_feature(hw, VIRTIO_F_ANY_LAYOUT) ||
-		      vtpci_with_feature(hw, VIRTIO_F_VERSION_1)) &&
+		if ((virtio_with_feature(hw, VIRTIO_F_ANY_LAYOUT) ||
+		      virtio_with_feature(hw, VIRTIO_F_VERSION_1)) &&
 		    rte_mbuf_refcnt_read(txm) == 1 &&
 		    RTE_MBUF_DIRECT(txm) &&
 		    txm->nb_segs == 1 &&
@@ -1844,7 +1844,7 @@ virtio_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
 		    rte_is_aligned(rte_pktmbuf_mtod(txm, char *),
 				   __alignof__(struct virtio_net_hdr_mrg_rxbuf)))
 			can_push = 1;
-		else if (vtpci_with_feature(hw, VIRTIO_RING_F_INDIRECT_DESC) &&
+		else if (virtio_with_feature(hw, VIRTIO_RING_F_INDIRECT_DESC) &&
 			 txm->nb_segs < VIRTIO_MAX_TX_INDIRECT)
 			use_indirect = 1;
 
@@ -1937,8 +1937,8 @@ virtio_xmit_pkts_inorder(void *tx_queue,
 		int slots;
 
 		/* optimize ring usage */
-		if ((vtpci_with_feature(hw, VIRTIO_F_ANY_LAYOUT) ||
-		     vtpci_with_feature(hw, VIRTIO_F_VERSION_1)) &&
+		if ((virtio_with_feature(hw, VIRTIO_F_ANY_LAYOUT) ||
+		     virtio_with_feature(hw, VIRTIO_F_VERSION_1)) &&
 		     rte_mbuf_refcnt_read(txm) == 1 &&
 		     RTE_MBUF_DIRECT(txm) &&
 		     txm->nb_segs == 1 &&
drivers/net/virtio/virtio_rxtx_packed.h +3 -3
index c0fad41c3d..8d99caeead 100644
@@ -111,12 +111,12 @@ virtqueue_enqueue_single_packed_vec(struct virtnet_tx *txvq,
 	int16_t need;
 
 	/* optimize ring usage */
-	if ((vtpci_with_feature(hw, VIRTIO_F_ANY_LAYOUT) ||
-	     vtpci_with_feature(hw, VIRTIO_F_VERSION_1)) &&
+	if ((virtio_with_feature(hw, VIRTIO_F_ANY_LAYOUT) ||
+	     virtio_with_feature(hw, VIRTIO_F_VERSION_1)) &&
 	     rte_mbuf_refcnt_read(txm) == 1 && RTE_MBUF_DIRECT(txm) &&
 	     txm->nb_segs == 1 && rte_pktmbuf_headroom(txm) >= hdr_size)
 		can_push = 1;
-	else if (vtpci_with_feature(hw, VIRTIO_RING_F_INDIRECT_DESC) &&
+	else if (virtio_with_feature(hw, VIRTIO_RING_F_INDIRECT_DESC) &&
 		 txm->nb_segs < VIRTIO_MAX_TX_INDIRECT)
 		use_indirect = 1;
 
drivers/net/virtio/virtio_user/vhost_kernel_tap.c +1 -1
index 79b8446f8e..eade702c5c 100644
@@ -16,7 +16,7 @@
 
 #include "vhost_kernel_tap.h"
 #include "../virtio_logs.h"
-#include "../virtio_pci.h"
+#include "../virtio.h"
 
 int
 vhost_kernel_tap_set_offload(int fd, uint64_t features)
drivers/net/virtio/virtio_user_ethdev.c +3 -3
index 6597c16539..8e609333c6 100644
@@ -122,7 +122,7 @@ virtio_user_server_reconnect(struct virtio_user_dev *dev)
 	dev->features &= dev->device_features;
 
 	/* For packed ring, resetting queues is required in reconnection. */
-	if (vtpci_packed_queue(hw) &&
+	if (virtio_with_packed_queue(hw) &&
 	   (old_status & VIRTIO_CONFIG_STATUS_DRIVER_OK)) {
 		PMD_INIT_LOG(NOTICE, "Packets on the fly will be dropped"
 				" when packed ring reconnecting.");
@@ -423,7 +423,7 @@ virtio_user_setup_queue(struct virtio_hw *hw, struct virtqueue *vq)
 {
 	struct virtio_user_dev *dev = virtio_user_get_dev(hw);
 
-	if (vtpci_packed_queue(hw))
+	if (virtio_with_packed_queue(hw))
 		virtio_user_setup_queue_packed(vq, dev);
 	else
 		virtio_user_setup_queue_split(vq, dev);
@@ -456,7 +456,7 @@ virtio_user_notify_queue(struct virtio_hw *hw, struct virtqueue *vq)
 	struct virtio_user_dev *dev = virtio_user_get_dev(hw);
 
 	if (hw->cvq && (hw->cvq->vq == vq)) {
-		if (vtpci_packed_queue(vq->hw))
+		if (virtio_with_packed_queue(vq->hw))
 			virtio_user_handle_cq_packed(dev, vq->vq_queue_index);
 		else
 			virtio_user_handle_cq(dev, vq->vq_queue_index);
drivers/net/virtio/virtqueue.c +2 -2
index 2702e120ee..59a2cb6599 100644
@@ -32,7 +32,7 @@ virtqueue_detach_unused(struct virtqueue *vq)
 	end = (vq->vq_avail_idx + vq->vq_free_cnt) & (vq->vq_nentries - 1);
 
 	for (idx = 0; idx < vq->vq_nentries; idx++) {
-		if (hw->use_vec_rx && !vtpci_packed_queue(hw) &&
+		if (hw->use_vec_rx && !virtio_with_packed_queue(hw) &&
 		    type == VTNET_RQ) {
 			if (start <= end && idx >= start && idx < end)
 				continue;
@@ -137,7 +137,7 @@ virtqueue_rxvq_flush(struct virtqueue *vq)
 {
 	struct virtio_hw *hw = vq->hw;
 
-	if (vtpci_packed_queue(hw))
+	if (virtio_with_packed_queue(hw))
 		virtqueue_rxvq_flush_packed(vq);
 	else
 		virtqueue_rxvq_flush_split(vq);
drivers/net/virtio/virtqueue.h +4 -4
index 6293cd2604..f419c0aa99 100644
@@ -12,7 +12,7 @@
 #include <rte_mempool.h>
 #include <rte_net.h>
 
-#include "virtio_pci.h"
+#include "virtio.h"
 #include "virtio_ring.h"
 #include "virtio_logs.h"
 #include "virtio_rxtx.h"
@@ -385,7 +385,7 @@ virtqueue_disable_intr_split(struct virtqueue *vq)
 static inline void
 virtqueue_disable_intr(struct virtqueue *vq)
 {
-	if (vtpci_packed_queue(vq->hw))
+	if (virtio_with_packed_queue(vq->hw))
 		virtqueue_disable_intr_packed(vq);
 	else
 		virtqueue_disable_intr_split(vq);
@@ -419,7 +419,7 @@ virtqueue_enable_intr_split(struct virtqueue *vq)
 static inline void
 virtqueue_enable_intr(struct virtqueue *vq)
 {
-	if (vtpci_packed_queue(vq->hw))
+	if (virtio_with_packed_queue(vq->hw))
 		virtqueue_enable_intr_packed(vq);
 	else
 		virtqueue_enable_intr_split(vq);
@@ -572,7 +572,7 @@ virtqueue_notify(struct virtqueue *vq)
 	used_idx = __atomic_load_n(&(vq)->vq_split.ring.used->idx, \
 				   __ATOMIC_RELAXED); \
 	nused = (uint16_t)(used_idx - (vq)->vq_used_cons_idx); \
-	if (vtpci_packed_queue((vq)->hw)) { \
+	if (virtio_with_packed_queue((vq)->hw)) { \
 		PMD_INIT_LOG(DEBUG, \
 		"VQ: - size=%d; free=%d; used_cons_idx=%d; avail_idx=%d;" \
 		" cached_flags=0x%x; used_wrap_counter=%d", \
Signature · 1 line
2.29.2
#27 lore raw

PATCH v4 20/44 net/virtio: move virtqueue defines in generic header

In reply to Maxime Coquelin

This patch moves the virtqueues defines from PCI header to the generic one.

---
 drivers/net/virtio/virtio.h                    | 18 ++++++++++++++++++
 drivers/net/virtio/virtio_ethdev.h             |  4 +++-
 drivers/net/virtio/virtio_pci.h                | 17 -----------------
 .../net/virtio/virtio_user/virtio_user_dev.h   |  3 ++-
 4 files changed, 23 insertions(+), 19 deletions(-)
drivers/net/virtio/virtio.h +18 -0
index cdfee5d182..0c2b3525d5 100644
@@ -88,6 +88,24 @@
 #define VIRTIO_NET_S_LINK_UP	1	/* Link is up */
 #define VIRTIO_NET_S_ANNOUNCE	2	/* Announcement is needed */
 
+/*
+ * Each virtqueue indirect descriptor list must be physically contiguous.
+ * To allow us to malloc(9) each list individually, limit the number
+ * supported to what will fit in one page. With 4KB pages, this is a limit
+ * of 256 descriptors. If there is ever a need for more, we can switch to
+ * contigmalloc(9) for the larger allocations, similar to what
+ * bus_dmamem_alloc(9) does.
+ *
+ * Note the sizeof(struct vring_desc) is 16 bytes.
+ */
+#define VIRTIO_MAX_INDIRECT ((int)(PAGE_SIZE / 16))
+
+/*
+ * Maximum number of virtqueues per device.
+ */
+#define VIRTIO_MAX_VIRTQUEUE_PAIRS 8
+#define VIRTIO_MAX_VIRTQUEUES (VIRTIO_MAX_VIRTQUEUE_PAIRS * 2 + 1)
+
 struct virtio_hw {
 	struct virtqueue **vqs;
 	uint64_t guest_features;
drivers/net/virtio/virtio_ethdev.h +3 -1
index 13395937c8..d82856df9b 100644
@@ -7,7 +7,9 @@
 
 #include <stdint.h>
 
-#include "virtio_pci.h"
+#include <rte_ethdev_driver.h>
+
+#include "virtio.h"
 
 #ifndef PAGE_SIZE
 #define PAGE_SIZE 4096
drivers/net/virtio/virtio_pci.h +0 -17
index 3d93e74f36..2c27c906fb 100644
@@ -67,23 +67,6 @@ struct virtnet_ctl;
 #define VIRTIO_CONFIG_STATUS_DEV_NEED_RESET	0x40
 #define VIRTIO_CONFIG_STATUS_FAILED		0x80
 
-/*
- * Each virtqueue indirect descriptor list must be physically contiguous.
- * To allow us to malloc(9) each list individually, limit the number
- * supported to what will fit in one page. With 4KB pages, this is a limit
- * of 256 descriptors. If there is ever a need for more, we can switch to
- * contigmalloc(9) for the larger allocations, similar to what
- * bus_dmamem_alloc(9) does.
- *
- * Note the sizeof(struct vring_desc) is 16 bytes.
- */
-#define VIRTIO_MAX_INDIRECT ((int) (PAGE_SIZE / 16))
-
-/*
- * Maximum number of virtqueues per device.
- */
-#define VIRTIO_MAX_VIRTQUEUE_PAIRS 8
-#define VIRTIO_MAX_VIRTQUEUES (VIRTIO_MAX_VIRTQUEUE_PAIRS * 2 + 1)
 
 /* Common configuration */
 #define VIRTIO_PCI_CAP_COMMON_CFG	1
drivers/net/virtio/virtio_user/virtio_user_dev.h +2 -1
index b3776cc7a0..ab62463a5b 100644
@@ -7,7 +7,8 @@
 
 #include <limits.h>
 #include <stdbool.h>
-#include "../virtio_pci.h"
+
+#include "../virtio.h"
 #include "../virtio_ring.h"
 
 enum virtio_user_backend_type {
Signature · 1 line
2.29.2
#28 lore raw

PATCH v4 21/44 net/virtio: move config definitions to generic header

In reply to Maxime Coquelin

This patch moves config and status definitions from the PCI header to the generic one.

---
 drivers/net/virtio/virtio.c             | 43 +++++++++++++++++++
 drivers/net/virtio/virtio.h             | 50 ++++++++++++++++++++++
 drivers/net/virtio/virtio_ethdev.c      | 36 ++++++++--------
 drivers/net/virtio/virtio_pci.c         | 44 --------------------
 drivers/net/virtio/virtio_pci.h         | 55 -------------------------
 drivers/net/virtio/virtio_user_ethdev.c | 10 ++---
 6 files changed, 116 insertions(+), 122 deletions(-)
drivers/net/virtio/virtio.c +43 -0
index d8d6bf7add..ba3203e68b 100644
@@ -20,3 +20,46 @@ virtio_negotiate_features(struct virtio_hw *hw, uint64_t host_features)
 	return features;
 }
 
+
+void
+virtio_read_dev_config(struct virtio_hw *hw, size_t offset,
+		      void *dst, int length)
+{
+	VIRTIO_OPS(hw)->read_dev_cfg(hw, offset, dst, length);
+}
+
+void
+virtio_write_dev_config(struct virtio_hw *hw, size_t offset,
+		       const void *src, int length)
+{
+	VIRTIO_OPS(hw)->write_dev_cfg(hw, offset, src, length);
+}
+
+void
+virtio_reset(struct virtio_hw *hw)
+{
+	VIRTIO_OPS(hw)->set_status(hw, VIRTIO_CONFIG_STATUS_RESET);
+	/* flush status write */
+	VIRTIO_OPS(hw)->get_status(hw);
+}
+
+void
+virtio_reinit_complete(struct virtio_hw *hw)
+{
+	virtio_set_status(hw, VIRTIO_CONFIG_STATUS_DRIVER_OK);
+}
+
+void
+virtio_set_status(struct virtio_hw *hw, uint8_t status)
+{
+	if (status != VIRTIO_CONFIG_STATUS_RESET)
+		status |= VIRTIO_OPS(hw)->get_status(hw);
+
+	VIRTIO_OPS(hw)->set_status(hw, status);
+}
+
+uint8_t
+virtio_get_status(struct virtio_hw *hw)
+{
+	return VIRTIO_OPS(hw)->get_status(hw);
+}
drivers/net/virtio/virtio.h +50 -0

61 lines not on this page · raw message

drivers/net/virtio/virtio_ethdev.c +18 -18
index 1771844fe7..dfd8d29f60 100644
@@ -714,7 +714,7 @@ virtio_dev_close(struct rte_eth_dev *dev)
 		dev->intr_handle->intr_vec = NULL;
 	}
 
-	vtpci_reset(hw);
+	virtio_reset(hw);
 	virtio_dev_free_mbufs(dev);
 	virtio_free_queues(hw);
 
@@ -1096,7 +1096,7 @@ virtio_dev_stats_reset(struct rte_eth_dev *dev)
 static void
 virtio_set_hwaddr(struct virtio_hw *hw)
 {
-	vtpci_write_dev_config(hw,
+	virtio_write_dev_config(hw,
 			offsetof(struct virtio_net_config, mac),
 			&hw->mac_addr, RTE_ETHER_ADDR_LEN);
 }
@@ -1105,7 +1105,7 @@ static void
 virtio_get_hwaddr(struct virtio_hw *hw)
 {
 	if (virtio_with_feature(hw, VIRTIO_NET_F_MAC)) {
-		vtpci_read_dev_config(hw,
+		virtio_read_dev_config(hw,
 			offsetof(struct virtio_net_config, mac),
 			&hw->mac_addr, RTE_ETHER_ADDR_LEN);
 	} else {
@@ -1313,7 +1313,7 @@ virtio_ethdev_negotiate_features(struct virtio_hw *hw, uint64_t req_features)
 	if (host_features & req_features & (1ULL << VIRTIO_NET_F_MTU)) {
 		struct virtio_net_config config;
 
-		vtpci_read_dev_config(hw,
+		virtio_read_dev_config(hw,
 			offsetof(struct virtio_net_config, mtu),
 			&config.mtu, sizeof(config.mtu));
 
@@ -1334,9 +1334,9 @@ virtio_ethdev_negotiate_features(struct virtio_hw *hw, uint64_t req_features)
 		return -1;
 
 	if (virtio_with_feature(hw, VIRTIO_F_VERSION_1)) {
-		vtpci_set_status(hw, VIRTIO_CONFIG_STATUS_FEATURES_OK);
+		virtio_set_status(hw, VIRTIO_CONFIG_STATUS_FEATURES_OK);
 
-		if (!(vtpci_get_status(hw) & VIRTIO_CONFIG_STATUS_FEATURES_OK)) {
+		if (!(virtio_get_status(hw) & VIRTIO_CONFIG_STATUS_FEATURES_OK)) {
 			PMD_INIT_LOG(ERR, "Failed to set FEATURES_OK status!");
 			return -1;
 		}
@@ -1468,7 +1468,7 @@ virtio_interrupt_handler(void *param)
 						     NULL);
 
 		if (virtio_with_feature(hw, VIRTIO_NET_F_STATUS)) {
-			vtpci_read_dev_config(hw,
+			virtio_read_dev_config(hw,
 				offsetof(struct virtio_net_config, status),
 				&status, sizeof(status));
 			if (status & VIRTIO_NET_S_ANNOUNCE) {
@@ -1650,7 +1650,7 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
 	int ret;
 
 	/* Reset the device although not necessary at startup */
-	vtpci_reset(hw);
+	virtio_reset(hw);
 
 	if (hw->vqs) {
 		virtio_dev_free_mbufs(eth_dev);
@@ -1658,10 +1658,10 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
 	}
 
 	/* Tell the host we've noticed this device. */
-	vtpci_set_status(hw, VIRTIO_CONFIG_STATUS_ACK);
+	virtio_set_status(hw, VIRTIO_CONFIG_STATUS_ACK);
 
 	/* Tell the host we've known how to drive the device. */
-	vtpci_set_status(hw, VIRTIO_CONFIG_STATUS_DRIVER);
+	virtio_set_status(hw, VIRTIO_CONFIG_STATUS_DRIVER);
 	if (virtio_ethdev_negotiate_features(hw, req_features) < 0)
 		return -1;
 
@@ -1696,10 +1696,10 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
 	if (hw->speed == ETH_SPEED_NUM_UNKNOWN) {
 		if (virtio_with_feature(hw, VIRTIO_NET_F_SPEED_DUPLEX)) {
 			config = &local_config;
-			vtpci_read_dev_config(hw,
+			virtio_read_dev_config(hw,
 				offsetof(struct virtio_net_config, speed),
 				&config->speed, sizeof(config->speed));
-			vtpci_read_dev_config(hw,
+			virtio_read_dev_config(hw,
 				offsetof(struct virtio_net_config, duplex),
 				&config->duplex, sizeof(config->duplex));
 			hw->speed = config->speed;
@@ -1713,12 +1713,12 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
 	if (virtio_with_feature(hw, VIRTIO_NET_F_CTRL_VQ)) {
 		config = &local_config;
 
-		vtpci_read_dev_config(hw,
+		virtio_read_dev_config(hw,
 			offsetof(struct virtio_net_config, mac),
 			&config->mac, sizeof(config->mac));
 
 		if (virtio_with_feature(hw, VIRTIO_NET_F_STATUS)) {
-			vtpci_read_dev_config(hw,
+			virtio_read_dev_config(hw,
 				offsetof(struct virtio_net_config, status),
 				&config->status, sizeof(config->status));
 		} else {
@@ -1728,7 +1728,7 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
 		}
 
 		if (virtio_with_feature(hw, VIRTIO_NET_F_MQ)) {
-			vtpci_read_dev_config(hw,
+			virtio_read_dev_config(hw,
 				offsetof(struct virtio_net_config, max_virtqueue_pairs),
 				&config->max_virtqueue_pairs,
 				sizeof(config->max_virtqueue_pairs));
@@ -1741,7 +1741,7 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
 		hw->max_queue_pairs = config->max_virtqueue_pairs;
 
 		if (virtio_with_feature(hw, VIRTIO_NET_F_MTU)) {
-			vtpci_read_dev_config(hw,
+			virtio_read_dev_config(hw,
 				offsetof(struct virtio_net_config, mtu),
 				&config->mtu,
 				sizeof(config->mtu));
@@ -1793,7 +1793,7 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
 		}
 	}
 
-	vtpci_reinit_complete(hw);
+	virtio_reinit_complete(hw);
 
 	return 0;
 }
@@ -2374,7 +2374,7 @@ virtio_dev_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complet
 		link.link_speed = ETH_SPEED_NUM_NONE;
 	} else if (virtio_with_feature(hw, VIRTIO_NET_F_STATUS)) {
 		PMD_INIT_LOG(DEBUG, "Get link status from hw");
-		vtpci_read_dev_config(hw,
+		virtio_read_dev_config(hw,
 				offsetof(struct virtio_net_config, status),
 				&status, sizeof(status));
 		if ((status & VIRTIO_NET_S_LINK_UP) == 0) {
drivers/net/virtio/virtio_pci.c +0 -44

50 lines not on this page · raw message

drivers/net/virtio/virtio_pci.h +0 -55

73 lines not on this page · raw message

drivers/net/virtio/virtio_user_ethdev.c +5 -5
index 8e609333c6..6e59fe4b58 100644
@@ -79,11 +79,11 @@ virtio_user_server_reconnect(struct virtio_user_dev *dev)
 	dev->vhostfd = connectfd;
 	old_status = dev->status;
 
-	vtpci_reset(hw);
+	virtio_reset(hw);
 
-	vtpci_set_status(hw, VIRTIO_CONFIG_STATUS_ACK);
+	virtio_set_status(hw, VIRTIO_CONFIG_STATUS_ACK);
 
-	vtpci_set_status(hw, VIRTIO_CONFIG_STATUS_DRIVER);
+	virtio_set_status(hw, VIRTIO_CONFIG_STATUS_DRIVER);
 
 	if (dev->ops->send_request(dev, VHOST_USER_GET_FEATURES,
 				   &dev->device_features) < 0) {
@@ -129,10 +129,10 @@ virtio_user_server_reconnect(struct virtio_user_dev *dev)
 		virtio_user_reset_queues_packed(eth_dev);
 	}
 
-	vtpci_set_status(hw, VIRTIO_CONFIG_STATUS_FEATURES_OK);
+	virtio_set_status(hw, VIRTIO_CONFIG_STATUS_FEATURES_OK);
 
 	/* Start the device */
-	vtpci_set_status(hw, VIRTIO_CONFIG_STATUS_DRIVER_OK);
+	virtio_set_status(hw, VIRTIO_CONFIG_STATUS_DRIVER_OK);
 	if (!dev->started)
 		return -1;
 
Signature · 1 line
2.29.2
#29 lore raw

PATCH v4 22/44 net/virtio: make interrupt handling more generic

In reply to Maxime Coquelin

This patch aims at isolating MSIX notion into PCI
layer.

---
 drivers/net/virtio/virtio.c             |  6 ++++
 drivers/net/virtio/virtio.h             | 11 +++++--
 drivers/net/virtio/virtio_ethdev.c      |  7 ++---
 drivers/net/virtio/virtio_pci.c         | 38 ++++++++++++-------------
 drivers/net/virtio/virtio_pci.h         | 24 +++++-----------
 drivers/net/virtio/virtio_user_ethdev.c |  9 ++----
 6 files changed, 46 insertions(+), 49 deletions(-)
drivers/net/virtio/virtio.c +6 -0
index ba3203e68b..7e1e77797f 100644
@@ -63,3 +63,9 @@ virtio_get_status(struct virtio_hw *hw)
 {
 	return VIRTIO_OPS(hw)->get_status(hw);
 }
+
+uint8_t
+virtio_get_isr(struct virtio_hw *hw)
+{
+	return VIRTIO_OPS(hw)->get_isr(hw);
+}
drivers/net/virtio/virtio.h +9 -2
index 0ac5328c57..a7629ad16b 100644
@@ -124,6 +124,13 @@
 #define VIRTIO_CONFIG_STATUS_DEV_NEED_RESET	0x40
 #define VIRTIO_CONFIG_STATUS_FAILED		0x80
 
+/* The bit of the ISR which indicates a device has an interrupt. */
+#define VIRTIO_ISR_INTR   0x1
+/* The bit of the ISR which indicates a device configuration change. */
+#define VIRTIO_ISR_CONFIG 0x2
+/* Vector value used to disable MSI for queue. */
+#define VIRTIO_MSI_NO_VECTOR 0xFFFF
+
 /*
  * This structure is just a reference to read net device specific
  * config space; it is just a shadow structure.
@@ -168,7 +175,7 @@ struct virtio_hw {
 	uint8_t mac_addr[RTE_ETHER_ADDR_LEN];
 	uint32_t speed;  /* link speed in MB */
 	uint8_t duplex;
-	uint8_t use_msix;
+	uint8_t intr_lsc;
 	uint16_t max_mtu;
 	/*
 	 * App management thread and virtio interrupt handler thread
@@ -232,5 +239,5 @@ void virtio_write_dev_config(struct virtio_hw *hw, size_t offset, const void *sr
 void virtio_read_dev_config(struct virtio_hw *hw, size_t offset, void *dst, int length);
 void virtio_reset(struct virtio_hw *hw);
 void virtio_reinit_complete(struct virtio_hw *hw);
-
+uint8_t virtio_get_isr(struct virtio_hw *hw);
 #endif /* _VIRTIO_H_ */
drivers/net/virtio/virtio_ethdev.c +3 -4
index dfd8d29f60..51eb5aebf3 100644
@@ -1455,13 +1455,13 @@ virtio_interrupt_handler(void *param)
 	uint16_t status;
 
 	/* Read interrupt status which clears interrupt */
-	isr = vtpci_isr(hw);
+	isr = virtio_get_isr(hw);
 	PMD_DRV_LOG(INFO, "interrupt status = %#x", isr);
 
 	if (virtio_intr_unmask(dev) < 0)
 		PMD_DRV_LOG(ERR, "interrupt enable failed");
 
-	if (isr & VIRTIO_PCI_ISR_CONFIG) {
+	if (isr & VIRTIO_ISR_CONFIG) {
 		if (virtio_dev_link_update(dev, 0) == 0)
 			rte_eth_dev_callback_process(dev,
 						     RTE_ETH_EVENT_INTR_LSC,
@@ -1668,8 +1668,7 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
 	hw->weak_barriers = !virtio_with_feature(hw, VIRTIO_F_ORDER_PLATFORM);
 
 	/* If host does not support both status and MSI-X then disable LSC */
-	if (virtio_with_feature(hw, VIRTIO_NET_F_STATUS) &&
-	    hw->use_msix != VIRTIO_MSIX_NONE)
+	if (virtio_with_feature(hw, VIRTIO_NET_F_STATUS) && hw->intr_lsc)
 		eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
 	else
 		eth_dev->data->dev_flags &= ~RTE_ETH_DEV_INTR_LSC;
drivers/net/virtio/virtio_pci.c +18 -20
index baadc79c43..905534ac72 100644
@@ -28,8 +28,8 @@
  * The remaining space is defined by each driver as the per-driver
  * configuration space.
  */
-#define VIRTIO_PCI_CONFIG(hw) \
-		(((hw)->use_msix == VIRTIO_MSIX_ENABLED) ? 24 : 20)
+#define VIRTIO_PCI_CONFIG(dev) \
+		(((dev)->msix_status == VIRTIO_MSIX_ENABLED) ? 24 : 20)
 
 
 struct virtio_pci_internal {
@@ -121,6 +121,7 @@ static void
 legacy_read_dev_config(struct virtio_hw *hw, size_t offset,
 		       void *dst, int length)
 {
+	struct virtio_pci_dev *dev = virtio_pci_get_dev(hw);
 #ifdef RTE_ARCH_PPC_64
 	int size;
 
@@ -128,17 +129,17 @@ legacy_read_dev_config(struct virtio_hw *hw, size_t offset,
 		if (length >= 4) {
 			size = 4;
 			rte_pci_ioport_read(VTPCI_IO(hw), dst, size,
-				VIRTIO_PCI_CONFIG(hw) + offset);
+				VIRTIO_PCI_CONFIG(dev) + offset);
 			*(uint32_t *)dst = rte_be_to_cpu_32(*(uint32_t *)dst);
 		} else if (length >= 2) {
 			size = 2;
 			rte_pci_ioport_read(VTPCI_IO(hw), dst, size,
-				VIRTIO_PCI_CONFIG(hw) + offset);
+				VIRTIO_PCI_CONFIG(dev) + offset);
 			*(uint16_t *)dst = rte_be_to_cpu_16(*(uint16_t *)dst);
 		} else {
 			size = 1;
 			rte_pci_ioport_read(VTPCI_IO(hw), dst, size,
-				VIRTIO_PCI_CONFIG(hw) + offset);
+				VIRTIO_PCI_CONFIG(dev) + offset);
 		}
 
 		dst = (char *)dst + size;
@@ -147,7 +148,7 @@ legacy_read_dev_config(struct virtio_hw *hw, size_t offset,
 	}
 #else
 	rte_pci_ioport_read(VTPCI_IO(hw), dst, length,
-		VIRTIO_PCI_CONFIG(hw) + offset);
+		VIRTIO_PCI_CONFIG(dev) + offset);
 #endif
 }
 
@@ -155,6 +156,7 @@ static void
 legacy_write_dev_config(struct virtio_hw *hw, size_t offset,
 			const void *src, int length)
 {
+	struct virtio_pci_dev *dev = virtio_pci_get_dev(hw);
 #ifdef RTE_ARCH_PPC_64
 	union {
 		uint32_t u32;
@@ -167,16 +169,16 @@ legacy_write_dev_config(struct virtio_hw *hw, size_t offset,
 			size = 4;
 			tmp.u32 = rte_cpu_to_be_32(*(const uint32_t *)src);
 			rte_pci_ioport_write(VTPCI_IO(hw), &tmp.u32, size,
-				VIRTIO_PCI_CONFIG(hw) + offset);
+				VIRTIO_PCI_CONFIG(dev) + offset);
 		} else if (length >= 2) {
 			size = 2;
 			tmp.u16 = rte_cpu_to_be_16(*(const uint16_t *)src);
 			rte_pci_ioport_write(VTPCI_IO(hw), &tmp.u16, size,
-				VIRTIO_PCI_CONFIG(hw) + offset);
+				VIRTIO_PCI_CONFIG(dev) + offset);
 		} else {
 			size = 1;
 			rte_pci_ioport_write(VTPCI_IO(hw), src, size,
-				VIRTIO_PCI_CONFIG(hw) + offset);
+				VIRTIO_PCI_CONFIG(dev) + offset);
 		}
 
 		src = (const char *)src + size;
@@ -185,7 +187,7 @@ legacy_write_dev_config(struct virtio_hw *hw, size_t offset,
 	}
 #else
 	rte_pci_ioport_write(VTPCI_IO(hw), src, length,
-		VIRTIO_PCI_CONFIG(hw) + offset);
+		VIRTIO_PCI_CONFIG(dev) + offset);
 #endif
 }
 
@@ -311,7 +313,8 @@ legacy_intr_detect(struct virtio_hw *hw)
 {
 	struct virtio_pci_dev *dev = virtio_pci_get_dev(hw);
 
-	hw->use_msix = vtpci_msix_detect(dev->pci_dev);
+	dev->msix_status = vtpci_msix_detect(dev->pci_dev);
+	hw->intr_lsc = !!dev->msix_status;
 }
 
 static int
@@ -571,7 +574,8 @@ modern_intr_detect(struct virtio_hw *hw)
 {
 	struct virtio_pci_dev *dev = virtio_pci_get_dev(hw);
 
-	hw->use_msix = vtpci_msix_detect(dev->pci_dev);
+	dev->msix_status = vtpci_msix_detect(dev->pci_dev);
+	hw->intr_lsc = !!dev->msix_status;
 }
 
 static int
@@ -603,12 +607,6 @@ const struct virtio_ops modern_ops = {
 	.dev_close	= modern_dev_close,
 };
 
-uint8_t
-vtpci_isr(struct virtio_hw *hw)
-{
-	return VIRTIO_OPS(hw)->get_isr(hw);
-}
-
 static void *
 get_cfg_addr(struct rte_pci_device *dev, struct virtio_pci_cap *cap)
 {
@@ -691,9 +689,9 @@ virtio_read_caps(struct rte_pci_device *pci_dev, struct virtio_hw *hw)
 			}
 
 			if (flags & PCI_MSIX_ENABLE)
-				hw->use_msix = VIRTIO_MSIX_ENABLED;
+				dev->msix_status = VIRTIO_MSIX_ENABLED;
 			else
-				hw->use_msix = VIRTIO_MSIX_DISABLED;
+				dev->msix_status = VIRTIO_MSIX_DISABLED;
 		}
 
 		if (cap.cap_vndr != PCI_CAP_ID_VNDR) {
drivers/net/virtio/virtio_pci.h +7 -17
index cc1a3a37fd..68f36dc0dd 100644
@@ -42,13 +42,6 @@ struct virtnet_ctl;
 #define VIRTIO_MSI_QUEUE_VECTOR	  22 /* vector for selected VQ notifications
 				      (16, RW) */
 
-/* The bit of the ISR which indicates a device has an interrupt. */
-#define VIRTIO_PCI_ISR_INTR   0x1
-/* The bit of the ISR which indicates a device configuration change. */
-#define VIRTIO_PCI_ISR_CONFIG 0x2
-/* Vector value used to disable MSI for queue. */
-#define VIRTIO_MSI_NO_VECTOR 0xFFFF
-
 /* Common configuration */
 #define VIRTIO_PCI_CAP_COMMON_CFG	1
 /* Notifications */
@@ -103,11 +96,18 @@ struct virtio_pci_common_cfg {
 	uint32_t queue_used_hi;		/* read-write */
 };
 
+enum virtio_msix_status {
+	VIRTIO_MSIX_NONE = 0,
+	VIRTIO_MSIX_DISABLED = 1,
+	VIRTIO_MSIX_ENABLED = 2
+};
+
 struct virtio_pci_dev {
 	struct virtio_hw hw;
 	struct rte_pci_device *pci_dev;
 	struct virtio_pci_common_cfg *common_cfg;
 	struct virtio_net_config *dev_cfg;
+	enum virtio_msix_status msix_status;
 	uint8_t *isr;
 	uint16_t *notify_base;
 	uint32_t notify_off_multiplier;
@@ -125,20 +125,10 @@ struct virtio_pci_dev {
 /* The alignment to use between consumer and producer parts of vring. */
 #define VIRTIO_PCI_VRING_ALIGN 4096
 
-enum virtio_msix_status {
-	VIRTIO_MSIX_NONE = 0,
-	VIRTIO_MSIX_DISABLED = 1,
-	VIRTIO_MSIX_ENABLED = 2
-};
-
-
 /*
  * Function declaration from virtio_pci.c
  */
 int vtpci_init(struct rte_pci_device *pci_dev, struct virtio_pci_dev *dev);
-
-uint8_t vtpci_isr(struct virtio_hw *);
-
 void vtpci_legacy_ioport_unmap(struct virtio_hw *hw);
 int vtpci_legacy_ioport_map(struct virtio_hw *hw);
 
drivers/net/virtio/virtio_user_ethdev.c +3 -6
index 6e59fe4b58..c3dc3908d6 100644
@@ -339,7 +339,7 @@ virtio_user_get_isr(struct virtio_hw *hw __rte_unused)
 	/* rxq interrupts and config interrupt are separated in virtio-user,
 	 * here we only report config change.
 	 */
-	return VIRTIO_PCI_ISR_CONFIG;
+	return VIRTIO_ISR_CONFIG;
 }
 
 static uint16_t
@@ -636,11 +636,8 @@ virtio_user_eth_dev_alloc(struct rte_vdev_device *vdev)
 	hw->port_id = data->port_id;
 	dev->port_id = data->port_id;
 	VIRTIO_OPS(hw) = &virtio_user_ops;
-	/*
-	 * MSIX is required to enable LSC (see virtio_init_device).
-	 * Here just pretend that we support msix.
-	 */
-	hw->use_msix = 1;
+
+	hw->intr_lsc = 1;
 	hw->use_vec_rx = 0;
 	hw->use_vec_tx = 0;
 	hw->use_inorder_rx = 0;
Signature · 1 line
2.29.2
#30 lore raw

PATCH v4 23/44 net/virtio: move vring alignment to generic header

In reply to Maxime Coquelin

This patch moves vring alignment define to the generic Virtio header.

---
 drivers/net/virtio/virtio.h             |  3 +++
 drivers/net/virtio/virtio_ethdev.c      | 10 +++++-----
 drivers/net/virtio/virtio_pci.c         |  2 +-
 drivers/net/virtio/virtio_pci.h         |  3 ---
 drivers/net/virtio/virtio_user_ethdev.c |  4 ++--
 5 files changed, 11 insertions(+), 11 deletions(-)
drivers/net/virtio/virtio.h +3 -0
index a7629ad16b..21d54904e7 100644
@@ -131,6 +131,9 @@
 /* Vector value used to disable MSI for queue. */
 #define VIRTIO_MSI_NO_VECTOR 0xFFFF
 
+/* The alignment to use between consumer and producer parts of vring. */
+#define VIRTIO_VRING_ALIGN 4096
+
 /*
  * This structure is just a reference to read net device specific
  * config space; it is just a shadow structure.
drivers/net/virtio/virtio_ethdev.c +5 -5
index 51eb5aebf3..a2195bdda8 100644
@@ -407,12 +407,12 @@ virtio_init_vring(struct virtqueue *vq)
 	memset(vq->vq_descx, 0, sizeof(struct vq_desc_extra) * vq->vq_nentries);
 	if (virtio_with_packed_queue(vq->hw)) {
 		vring_init_packed(&vq->vq_packed.ring, ring_mem,
-				  VIRTIO_PCI_VRING_ALIGN, size);
+				  VIRTIO_VRING_ALIGN, size);
 		vring_desc_init_packed(vq, size);
 	} else {
 		struct vring *vr = &vq->vq_split.ring;
 
-		vring_init_split(vr, ring_mem, VIRTIO_PCI_VRING_ALIGN, size);
+		vring_init_split(vr, ring_mem, VIRTIO_VRING_ALIGN, size);
 		vring_desc_init_split(vr->desc, size);
 	}
 	/*
@@ -497,14 +497,14 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)
 	/*
 	 * Reserve a memzone for vring elements
 	 */
-	size = vring_size(hw, vq_size, VIRTIO_PCI_VRING_ALIGN);
-	vq->vq_ring_size = RTE_ALIGN_CEIL(size, VIRTIO_PCI_VRING_ALIGN);
+	size = vring_size(hw, vq_size, VIRTIO_VRING_ALIGN);
+	vq->vq_ring_size = RTE_ALIGN_CEIL(size, VIRTIO_VRING_ALIGN);
 	PMD_INIT_LOG(DEBUG, "vring_size: %d, rounded_vring_size: %d",
 		     size, vq->vq_ring_size);
 
 	mz = rte_memzone_reserve_aligned(vq_name, vq->vq_ring_size,
 			numa_node, RTE_MEMZONE_IOVA_CONTIG,
-			VIRTIO_PCI_VRING_ALIGN);
+			VIRTIO_VRING_ALIGN);
 	if (mz == NULL) {
 		if (rte_errno == EEXIST)
 			mz = rte_memzone_lookup(vq_name);
drivers/net/virtio/virtio_pci.c +1 -1
index 905534ac72..d27e9eb515 100644
@@ -492,7 +492,7 @@ modern_setup_queue(struct virtio_hw *hw, struct virtqueue *vq)
 	avail_addr = desc_addr + vq->vq_nentries * sizeof(struct vring_desc);
 	used_addr = RTE_ALIGN_CEIL(avail_addr + offsetof(struct vring_avail,
 							 ring[vq->vq_nentries]),
-				   VIRTIO_PCI_VRING_ALIGN);
+				   VIRTIO_VRING_ALIGN);
 
 	rte_write16(vq->vq_queue_index, &dev->common_cfg->queue_select);
 
drivers/net/virtio/virtio_pci.h +0 -3
index 68f36dc0dd..6cdf2c55dd 100644
@@ -122,9 +122,6 @@ struct virtio_pci_dev {
  */
 #define VIRTIO_PCI_QUEUE_ADDR_SHIFT 12
 
-/* The alignment to use between consumer and producer parts of vring. */
-#define VIRTIO_PCI_VRING_ALIGN 4096
-
 /*
  * Function declaration from virtio_pci.c
  */
drivers/net/virtio/virtio_user_ethdev.c +2 -2
index c3dc3908d6..91794b8645 100644
@@ -388,7 +388,7 @@ virtio_user_setup_queue_packed(struct virtqueue *vq,
 		sizeof(struct vring_packed_desc);
 	used_addr = RTE_ALIGN_CEIL(avail_addr +
 			   sizeof(struct vring_packed_desc_event),
-			   VIRTIO_PCI_VRING_ALIGN);
+			   VIRTIO_VRING_ALIGN);
 	vring->num = vq->vq_nentries;
 	vring->desc = (void *)(uintptr_t)desc_addr;
 	vring->driver = (void *)(uintptr_t)avail_addr;
@@ -410,7 +410,7 @@ virtio_user_setup_queue_split(struct virtqueue *vq, struct virtio_user_dev *dev)
 	avail_addr = desc_addr + vq->vq_nentries * sizeof(struct vring_desc);
 	used_addr = RTE_ALIGN_CEIL(avail_addr + offsetof(struct vring_avail,
 							 ring[vq->vq_nentries]),
-				   VIRTIO_PCI_VRING_ALIGN);
+				   VIRTIO_VRING_ALIGN);
 
 	dev->vrings[queue_idx].num = vq->vq_nentries;
 	dev->vrings[queue_idx].desc = (void *)(uintptr_t)desc_addr;
Signature · 1 line
2.29.2
#31 lore raw

PATCH v4 24/44 net/virtio: remove last PCI refs in non-PCI code

In reply to Maxime Coquelin

This patch finalizes the bus isolation part of this refactoring.

---
 drivers/net/virtio/virtio_ethdev.c           | 21 +++++++++-----------
 drivers/net/virtio/virtio_rxtx.c             | 18 ++++++++---------
 drivers/net/virtio/virtio_rxtx_packed.h      |  2 +-
 drivers/net/virtio/virtio_rxtx_packed_avx.h  |  2 +-
 drivers/net/virtio/virtio_rxtx_packed_neon.h |  2 +-
 drivers/net/virtio/virtio_user/vhost.h       |  4 +++-
 drivers/net/virtio/virtqueue.c               |  2 +-
 drivers/net/virtio/virtqueue.h               |  8 ++++----
 8 files changed, 29 insertions(+), 30 deletions(-)
drivers/net/virtio/virtio_ethdev.c +9 -12
index a2195bdda8..5f7ea390c8 100644
@@ -9,14 +9,11 @@
 #include <unistd.h>
 
 #include <rte_ethdev_driver.h>
-#include <rte_ethdev_pci.h>
 #include <rte_memcpy.h>
 #include <rte_string_fns.h>
 #include <rte_memzone.h>
 #include <rte_malloc.h>
 #include <rte_branch_prediction.h>
-#include <rte_pci.h>
-#include <rte_bus_pci.h>
 #include <rte_ether.h>
 #include <rte_ip.h>
 #include <rte_arp.h>
@@ -32,7 +29,7 @@
 #include <rte_kvargs.h>
 
 #include "virtio_ethdev.h"
-#include "virtio_pci.h"
+#include "virtio.h"
 #include "virtio_logs.h"
 #include "virtqueue.h"
 #include "virtio_rxtx.h"
@@ -422,7 +419,7 @@ virtio_init_vring(struct virtqueue *vq)
 }
 
 static int
-virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)
+virtio_init_queue(struct rte_eth_dev *dev, uint16_t queue_idx)
 {
 	char vq_name[VIRTQUEUE_MAX_NAME_SZ];
 	char vq_hdr_name[VIRTQUEUE_MAX_NAME_SZ];
@@ -435,18 +432,18 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)
 	struct virtqueue *vq;
 	size_t sz_hdr_mz = 0;
 	void *sw_ring = NULL;
-	int queue_type = virtio_get_queue_type(hw, vtpci_queue_idx);
+	int queue_type = virtio_get_queue_type(hw, queue_idx);
 	int ret;
 	int numa_node = dev->device->numa_node;
 
 	PMD_INIT_LOG(INFO, "setting up queue: %u on NUMA node %d",
-			vtpci_queue_idx, numa_node);
+			queue_idx, numa_node);
 
 	/*
 	 * Read the virtqueue size from the Queue Size field
 	 * Always power of 2 and if 0 virtqueue does not exist
 	 */
-	vq_size = VIRTIO_OPS(hw)->get_queue_num(hw, vtpci_queue_idx);
+	vq_size = VIRTIO_OPS(hw)->get_queue_num(hw, queue_idx);
 	PMD_INIT_LOG(DEBUG, "vq_size: %u", vq_size);
 	if (vq_size == 0) {
 		PMD_INIT_LOG(ERR, "virtqueue does not exist");
@@ -459,7 +456,7 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)
 	}
 
 	snprintf(vq_name, sizeof(vq_name), "port%d_vq%d",
-		 dev->data->port_id, vtpci_queue_idx);
+		 dev->data->port_id, queue_idx);
 
 	size = RTE_ALIGN_CEIL(sizeof(*vq) +
 				vq_size * sizeof(struct vq_desc_extra),
@@ -481,10 +478,10 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)
 		PMD_INIT_LOG(ERR, "can not allocate vq");
 		return -ENOMEM;
 	}
-	hw->vqs[vtpci_queue_idx] = vq;
+	hw->vqs[queue_idx] = vq;
 
 	vq->hw = hw;
-	vq->vq_queue_index = vtpci_queue_idx;
+	vq->vq_queue_index = queue_idx;
 	vq->vq_nentries = vq_size;
 	if (virtio_with_packed_queue(hw)) {
 		vq->vq_packed.used_wrap_counter = 1;
@@ -527,7 +524,7 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)
 
 	if (sz_hdr_mz) {
 		snprintf(vq_hdr_name, sizeof(vq_hdr_name), "port%d_vq%d_hdr",
-			 dev->data->port_id, vtpci_queue_idx);
+			 dev->data->port_id, queue_idx);
 		hdr_mz = rte_memzone_reserve_aligned(vq_hdr_name, sz_hdr_mz,
 				numa_node, RTE_MEMZONE_IOVA_CONTIG,
 				RTE_CACHE_LINE_SIZE);
drivers/net/virtio/virtio_rxtx.c +9 -9
index 728085e99b..b5657d5c83 100644
@@ -27,7 +27,7 @@
 
 #include "virtio_logs.h"
 #include "virtio_ethdev.h"
-#include "virtio_pci.h"
+#include "virtio.h"
 #include "virtqueue.h"
 #include "virtio_rxtx.h"
 #include "virtio_rxtx_simple.h"
@@ -628,9 +628,9 @@ virtio_dev_rx_queue_setup(struct rte_eth_dev *dev,
 			const struct rte_eth_rxconf *rx_conf,
 			struct rte_mempool *mp)
 {
-	uint16_t vtpci_queue_idx = 2 * queue_idx + VTNET_SQ_RQ_QUEUE_IDX;
+	uint16_t vq_idx = 2 * queue_idx + VTNET_SQ_RQ_QUEUE_IDX;
 	struct virtio_hw *hw = dev->data->dev_private;
-	struct virtqueue *vq = hw->vqs[vtpci_queue_idx];
+	struct virtqueue *vq = hw->vqs[vq_idx];
 	struct virtnet_rx *rxvq;
 	uint16_t rx_free_thresh;
 
@@ -678,9 +678,9 @@ virtio_dev_rx_queue_setup(struct rte_eth_dev *dev,
 int
 virtio_dev_rx_queue_setup_finish(struct rte_eth_dev *dev, uint16_t queue_idx)
 {
-	uint16_t vtpci_queue_idx = 2 * queue_idx + VTNET_SQ_RQ_QUEUE_IDX;
+	uint16_t vq_idx = 2 * queue_idx + VTNET_SQ_RQ_QUEUE_IDX;
 	struct virtio_hw *hw = dev->data->dev_private;
-	struct virtqueue *vq = hw->vqs[vtpci_queue_idx];
+	struct virtqueue *vq = hw->vqs[vq_idx];
 	struct virtnet_rx *rxvq = &vq->rxq;
 	struct rte_mbuf *m;
 	uint16_t desc_idx;
@@ -779,9 +779,9 @@ virtio_dev_tx_queue_setup(struct rte_eth_dev *dev,
 			unsigned int socket_id __rte_unused,
 			const struct rte_eth_txconf *tx_conf)
 {
-	uint8_t vtpci_queue_idx = 2 * queue_idx + VTNET_SQ_TQ_QUEUE_IDX;
+	uint8_t vq_idx = 2 * queue_idx + VTNET_SQ_TQ_QUEUE_IDX;
 	struct virtio_hw *hw = dev->data->dev_private;
-	struct virtqueue *vq = hw->vqs[vtpci_queue_idx];
+	struct virtqueue *vq = hw->vqs[vq_idx];
 	struct virtnet_tx *txvq;
 	uint16_t tx_free_thresh;
 
@@ -823,9 +823,9 @@ int
 virtio_dev_tx_queue_setup_finish(struct rte_eth_dev *dev,
 				uint16_t queue_idx)
 {
-	uint8_t vtpci_queue_idx = 2 * queue_idx + VTNET_SQ_TQ_QUEUE_IDX;
+	uint8_t vq_idx = 2 * queue_idx + VTNET_SQ_TQ_QUEUE_IDX;
 	struct virtio_hw *hw = dev->data->dev_private;
-	struct virtqueue *vq = hw->vqs[vtpci_queue_idx];
+	struct virtqueue *vq = hw->vqs[vq_idx];
 
 	PMD_INIT_FUNC_TRACE();
 
drivers/net/virtio/virtio_rxtx_packed.h +1 -1
index 8d99caeead..3037c8c871 100644
@@ -15,7 +15,7 @@
 
 #include "virtio_logs.h"
 #include "virtio_ethdev.h"
-#include "virtio_pci.h"
+#include "virtio.h"
 #include "virtqueue.h"
 
 #define BYTE_SIZE 8
drivers/net/virtio/virtio_rxtx_packed_avx.h +1 -1
index 2c610d57de..49e845d02a 100644
@@ -12,7 +12,7 @@
 
 #include "virtio_logs.h"
 #include "virtio_ethdev.h"
-#include "virtio_pci.h"
+#include "virtio.h"
 #include "virtio_rxtx_packed.h"
 #include "virtqueue.h"
 
drivers/net/virtio/virtio_rxtx_packed_neon.h +1 -1
index ae2d099c0b..af9dede41b 100644
@@ -12,7 +12,7 @@
 #include <rte_vect.h>
 
 #include "virtio_ethdev.h"
-#include "virtio_pci.h"
+#include "virtio.h"
 #include "virtio_rxtx_packed.h"
 #include "virtqueue.h"
 
drivers/net/virtio/virtio_user/vhost.h +3 -1
index be286173b0..8ec3a6a62c 100644
@@ -9,7 +9,9 @@
 #include <linux/types.h>
 #include <linux/ioctl.h>
 
-#include "../virtio_pci.h"
+#include <rte_errno.h>
+
+#include "../virtio.h"
 #include "../virtio_logs.h"
 #include "../virtqueue.h"
 
drivers/net/virtio/virtqueue.c +1 -1
index 59a2cb6599..1f9af3c31b 100644
@@ -7,7 +7,7 @@
 
 #include "virtqueue.h"
 #include "virtio_logs.h"
-#include "virtio_pci.h"
+#include "virtio.h"
 #include "virtio_rxtx_simple.h"
 
 /*
drivers/net/virtio/virtqueue.h +4 -4
index f419c0aa99..71b66f3208 100644
@@ -259,7 +259,7 @@ struct virtqueue {
 	 */
 	uint16_t  vq_desc_head_idx;
 	uint16_t  vq_desc_tail_idx;
-	uint16_t  vq_queue_index;   /**< PCI queue index */
+	uint16_t  vq_queue_index;
 	uint16_t offset; /**< relative offset to obtain addr in mbuf */
 	uint16_t  *notify_addr;
 	struct rte_mbuf **sw_ring;  /**< RX software ring. */
@@ -448,11 +448,11 @@ virtqueue_full(const struct virtqueue *vq)
 }
 
 static inline int
-virtio_get_queue_type(struct virtio_hw *hw, uint16_t vtpci_queue_idx)
+virtio_get_queue_type(struct virtio_hw *hw, uint16_t vq_idx)
 {
-	if (vtpci_queue_idx == hw->max_queue_pairs * 2)
+	if (vq_idx == hw->max_queue_pairs * 2)
 		return VTNET_CQ;
-	else if (vtpci_queue_idx % 2 == 0)
+	else if (vq_idx % 2 == 0)
 		return VTNET_RQ;
 	else
 		return VTNET_TQ;
Signature · 1 line
2.29.2
#32 lore raw

PATCH v4 25/44 net/virtio: make Vhost-user request sender consistent

In reply to Maxime Coquelin

This patch makes vhost_user_write() consistent with vhost_user_read(), by passing a Vhost-user message pointer instead of a buffer pointer and its length, which is now calculated in the function.

---
 drivers/net/virtio/virtio_user/vhost_user.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/net/virtio/virtio_user/vhost_user.c +4 -6
index 350eed4182..55c813333a 100644
@@ -51,7 +51,7 @@ struct vhost_user_msg {
 	(sizeof(struct vhost_user_msg) - VHOST_USER_HDR_SIZE)
 
 static int
-vhost_user_write(int fd, void *buf, int len, int *fds, int fd_num)
+vhost_user_write(int fd, struct vhost_user_msg *msg, int *fds, int fd_num)
 {
 	int r;
 	struct msghdr msgh;
@@ -63,8 +63,8 @@ vhost_user_write(int fd, void *buf, int len, int *fds, int fd_num)
 	memset(&msgh, 0, sizeof(msgh));
 	memset(control, 0, sizeof(control));
 
-	iov.iov_base = (uint8_t *)buf;
-	iov.iov_len = len;
+	iov.iov_base = (uint8_t *)msg;
+	iov.iov_len = VHOST_USER_HDR_SIZE + msg->size;
 
 	msgh.msg_iov = &iov;
 	msgh.msg_iovlen = 1;
@@ -259,7 +259,6 @@ vhost_user_sock(struct virtio_user_dev *dev,
 	int has_reply_ack = 0;
 	int fds[VHOST_MEMORY_MAX_NREGIONS];
 	int fd_num = 0;
-	int len;
 	int vhostfd = dev->vhostfd;
 
 	RTE_SET_USED(m);
@@ -364,8 +363,7 @@ vhost_user_sock(struct virtio_user_dev *dev,
 		return -1;
 	}
 
-	len = VHOST_USER_HDR_SIZE + msg.size;
-	if (vhost_user_write(vhostfd, &msg, len, fds, fd_num) < 0) {
+	if (vhost_user_write(vhostfd, &msg, fds, fd_num) < 0) {
 		PMD_DRV_LOG(ERR, "%s failed: %s",
 			    vhost_msg_strings[req], strerror(errno));
 		return -1;
Signature · 1 line
2.29.2
#33 lore raw

PATCH v4 26/44 net/virtio: add Virtio-user ops to set owner

In reply to Maxime Coquelin

This patch implements a dedicated callback for
sending owner request. All the requests will be
converted that way so that backends other than
Vhost-user don't have to work around being it.

---
 drivers/net/virtio/virtio_user/vhost.h        |  1 +
 drivers/net/virtio/virtio_user/vhost_kernel.c | 28 +++++++++++++++--
 drivers/net/virtio/virtio_user/vhost_user.c   | 21 +++++++++++--
 drivers/net/virtio/virtio_user/vhost_vdpa.c   | 30 ++++++++++++++++---
 .../net/virtio/virtio_user/virtio_user_dev.c  |  3 +-
 5 files changed, 72 insertions(+), 11 deletions(-)
drivers/net/virtio/virtio_user/vhost.h +1 -0
index 8ec3a6a62c..5413ec6778 100644
@@ -109,6 +109,7 @@ struct virtio_user_dev;
 
 struct virtio_user_backend_ops {
 	int (*setup)(struct virtio_user_dev *dev);
+	int (*set_owner)(struct virtio_user_dev *dev);
 	int (*send_request)(struct virtio_user_dev *dev,
 			    enum vhost_user_request req,
 			    void *arg);
drivers/net/virtio/virtio_user/vhost_kernel.c +25 -3
index 2c805077af..b79dcad179 100644
@@ -6,6 +6,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <errno.h>
 
 #include <rte_memory.h>
 
@@ -55,8 +56,28 @@ get_vhost_kernel_max_regions(void)
 	close(fd);
 }
 
+static int
+vhost_kernel_ioctl(int fd, uint64_t request, void *arg)
+{
+	int ret;
+
+	ret = ioctl(fd, request, arg);
+	if (ret) {
+		PMD_DRV_LOG(ERR, "Vhost-kernel ioctl %"PRIu64" failed (%s)",
+				request, strerror(errno));
+		return -1;
+	}
+
+	return 0;
+}
+
+static int
+vhost_kernel_set_owner(struct virtio_user_dev *dev)
+{
+	return vhost_kernel_ioctl(dev->vhostfds[0], VHOST_SET_OWNER, NULL);
+}
+
 static uint64_t vhost_req_user_to_kernel[] = {
-	[VHOST_USER_SET_OWNER] = VHOST_SET_OWNER,
 	[VHOST_USER_RESET_OWNER] = VHOST_RESET_OWNER,
 	[VHOST_USER_SET_FEATURES] = VHOST_SET_FEATURES,
 	[VHOST_USER_GET_FEATURES] = VHOST_GET_FEATURES,
@@ -175,7 +196,7 @@ tap_support_features(void)
 }
 
 static int
-vhost_kernel_ioctl(struct virtio_user_dev *dev,
+vhost_kernel_send_request(struct virtio_user_dev *dev,
 		   enum vhost_user_request req,
 		   void *arg)
 {
@@ -385,6 +406,7 @@ vhost_kernel_enable_queue_pair(struct virtio_user_dev *dev,
 
 struct virtio_user_backend_ops virtio_ops_kernel = {
 	.setup = vhost_kernel_setup,
-	.send_request = vhost_kernel_ioctl,
+	.set_owner = vhost_kernel_set_owner,
+	.send_request = vhost_kernel_send_request,
 	.enable_qp = vhost_kernel_enable_queue_pair
 };
drivers/net/virtio/virtio_user/vhost_user.c +19 -2
index 55c813333a..ea3bd4ca10 100644
@@ -125,6 +125,24 @@ vhost_user_read(int fd, struct vhost_user_msg *msg)
 	return -1;
 }
 
+static int
+vhost_user_set_owner(struct virtio_user_dev *dev)
+{
+	int ret;
+	struct vhost_user_msg msg = {
+		.request = VHOST_USER_SET_OWNER,
+		.flags = VHOST_USER_VERSION,
+	};
+
+	ret = vhost_user_write(dev->vhostfd, &msg, NULL, 0);
+	if (ret < 0) {
+		PMD_DRV_LOG(ERR, "Failed to set owner");
+		return -1;
+	}
+
+	return 0;
+}
+
 struct walk_arg {
 	struct vhost_memory *vm;
 	int *fds;
@@ -230,7 +248,6 @@ prepare_vhost_memory_user(struct vhost_user_msg *msg, int fds[])
 static struct vhost_user_msg m;
 
 const char * const vhost_msg_strings[] = {
-	[VHOST_USER_SET_OWNER] = "VHOST_SET_OWNER",
 	[VHOST_USER_RESET_OWNER] = "VHOST_RESET_OWNER",
 	[VHOST_USER_SET_FEATURES] = "VHOST_SET_FEATURES",
 	[VHOST_USER_GET_FEATURES] = "VHOST_GET_FEATURES",
@@ -308,7 +325,6 @@ vhost_user_sock(struct virtio_user_dev *dev,
 		msg.size = sizeof(m.payload.u64);
 		break;
 
-	case VHOST_USER_SET_OWNER:
 	case VHOST_USER_RESET_OWNER:
 		break;
 
@@ -519,6 +535,7 @@ vhost_user_enable_queue_pair(struct virtio_user_dev *dev,
 
 struct virtio_user_backend_ops virtio_ops_user = {
 	.setup = vhost_user_setup,
+	.set_owner = vhost_user_set_owner,
 	.send_request = vhost_user_sock,
 	.enable_qp = vhost_user_enable_queue_pair
 };
drivers/net/virtio/virtio_user/vhost_vdpa.c +26 -4
index 004802b9eb..d9bc213e0d 100644
@@ -39,7 +39,6 @@
 #define VHOST_GET_BACKEND_FEATURES _IOR(VHOST_VIRTIO, 0x26, __u64)
 
 static uint64_t vhost_req_user_to_vdpa[] = {
-	[VHOST_USER_SET_OWNER] = VHOST_SET_OWNER,
 	[VHOST_USER_RESET_OWNER] = VHOST_RESET_OWNER,
 	[VHOST_USER_SET_FEATURES] = VHOST_SET_FEATURES,
 	[VHOST_USER_GET_FEATURES] = VHOST_GET_FEATURES,
@@ -86,6 +85,28 @@ struct vhost_msg {
 	};
 };
 
+
+static int
+vhost_vdpa_ioctl(int fd, uint64_t request, void *arg)
+{
+	int ret;
+
+	ret = ioctl(fd, request, arg);
+	if (ret) {
+		PMD_DRV_LOG(ERR, "Vhost-vDPA ioctl %"PRIu64" failed (%s)",
+				request, strerror(errno));
+		return -1;
+	}
+
+	return 0;
+}
+
+static int
+vhost_vdpa_set_owner(struct virtio_user_dev *dev)
+{
+	return vhost_vdpa_ioctl(dev->vhostfd, VHOST_SET_OWNER, NULL);
+}
+
 static int
 vhost_vdpa_iotlb_batch_begin(struct virtio_user_dev *dev)
 {
@@ -308,7 +329,7 @@ vhost_vdpa_dma_map_all(struct virtio_user_dev *dev)
 	 (1ULL << VIRTIO_NET_F_CSUM))
 
 static int
-vhost_vdpa_ioctl(struct virtio_user_dev *dev,
+vhost_vdpa_send_request(struct virtio_user_dev *dev,
 		   enum vhost_user_request req,
 		   void *arg)
 {
@@ -396,7 +417,7 @@ vhost_vdpa_enable_queue_pair(struct virtio_user_dev *dev,
 			.num   = enable,
 		};
 
-		if (vhost_vdpa_ioctl(dev, VHOST_USER_SET_VRING_ENABLE, &state))
+		if (vhost_vdpa_send_request(dev, VHOST_USER_SET_VRING_ENABLE, &state))
 			return -1;
 	}
 
@@ -407,7 +428,8 @@ vhost_vdpa_enable_queue_pair(struct virtio_user_dev *dev,
 
 struct virtio_user_backend_ops virtio_ops_vdpa = {
 	.setup = vhost_vdpa_setup,
-	.send_request = vhost_vdpa_ioctl,
+	.set_owner = vhost_vdpa_set_owner,
+	.send_request = vhost_vdpa_send_request,
 	.enable_qp = vhost_vdpa_enable_queue_pair,
 	.dma_map = vhost_vdpa_dma_map_batch,
 	.dma_unmap = vhost_vdpa_dma_unmap_batch,
drivers/net/virtio/virtio_user/virtio_user_dev.c +1 -2
index 202431ca22..f4b97d8489 100644
@@ -490,8 +490,7 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
 			(1ULL << VHOST_USER_F_PROTOCOL_FEATURES);
 
 	if (!dev->is_server) {
-		if (dev->ops->send_request(dev, VHOST_USER_SET_OWNER,
-					   NULL) < 0) {
+		if (dev->ops->set_owner(dev) < 0) {
 			PMD_INIT_LOG(ERR, "set_owner fails: %s",
 				     strerror(errno));
 			return -1;
Signature · 1 line
2.29.2
#34 lore raw

PATCH v4 27/44 net/virtio: add Virtio-user features ops

In reply to Maxime Coquelin

This patch introduces new callbacks for getting and setting Virtio features, and implements them for the different backend types.

---
 drivers/net/virtio/virtio_user/vhost.h        |   2 +
 drivers/net/virtio/virtio_user/vhost_kernel.c | 150 +++++++++---------
 .../net/virtio/virtio_user/vhost_kernel_tap.c |  23 +++
 .../net/virtio/virtio_user/vhost_kernel_tap.h |   1 +
 drivers/net/virtio/virtio_user/vhost_user.c   |  64 +++++++-
 drivers/net/virtio/virtio_user/vhost_vdpa.c   |  38 +++--
 .../net/virtio/virtio_user/virtio_user_dev.c  |   5 +-
 drivers/net/virtio/virtio_user_ethdev.c       |   3 +-
 8 files changed, 190 insertions(+), 96 deletions(-)
drivers/net/virtio/virtio_user/vhost.h +2 -0
index 5413ec6778..13a88c7671 100644
@@ -110,6 +110,8 @@ struct virtio_user_dev;
 struct virtio_user_backend_ops {
 	int (*setup)(struct virtio_user_dev *dev);
 	int (*set_owner)(struct virtio_user_dev *dev);
+	int (*get_features)(struct virtio_user_dev *dev, uint64_t *features);
+	int (*set_features)(struct virtio_user_dev *dev, uint64_t features);
 	int (*send_request)(struct virtio_user_dev *dev,
 			    enum vhost_user_request req,
 			    void *arg);
drivers/net/virtio/virtio_user/vhost_kernel.c +73 -77

194 lines not on this page · raw message

drivers/net/virtio/virtio_user/vhost_kernel_tap.c +23 -0
index eade702c5c..99096bdf39 100644
@@ -18,6 +18,29 @@
 #include "../virtio_logs.h"
 #include "../virtio.h"
 
+
+int
+tap_support_features(unsigned int *tap_features)
+{
+	int tapfd;
+
+	tapfd = open(PATH_NET_TUN, O_RDWR);
+	if (tapfd < 0) {
+		PMD_DRV_LOG(ERR, "fail to open %s: %s",
+			    PATH_NET_TUN, strerror(errno));
+		return -1;
+	}
+
+	if (ioctl(tapfd, TUNGETFEATURES, tap_features) == -1) {
+		PMD_DRV_LOG(ERR, "TUNGETFEATURES failed: %s", strerror(errno));
+		close(tapfd);
+		return -1;
+	}
+
+	close(tapfd);
+	return 0;
+}
+
 int
 vhost_kernel_tap_set_offload(int fd, uint64_t features)
 {
drivers/net/virtio/virtio_user/vhost_kernel_tap.h +1 -0
index 5c4447b296..ed03fce21e 100644
@@ -43,5 +43,6 @@ int vhost_kernel_open_tap(char **p_ifname, int hdr_size, int req_mq,
 			 const char *mac, uint64_t features);
 int vhost_kernel_tap_set_offload(int fd, uint64_t features);
 int vhost_kernel_tap_set_queue(int fd, bool attach);
+int tap_support_features(unsigned int *tap_features);
 
 #endif
drivers/net/virtio/virtio_user/vhost_user.c +60 -4

94 lines not on this page · raw message

drivers/net/virtio/virtio_user/vhost_vdpa.c +28 -10
index d9bc213e0d..22a329526a 100644
@@ -40,8 +40,6 @@
 
 static uint64_t vhost_req_user_to_vdpa[] = {
 	[VHOST_USER_RESET_OWNER] = VHOST_RESET_OWNER,
-	[VHOST_USER_SET_FEATURES] = VHOST_SET_FEATURES,
-	[VHOST_USER_GET_FEATURES] = VHOST_GET_FEATURES,
 	[VHOST_USER_SET_VRING_CALL] = VHOST_SET_VRING_CALL,
 	[VHOST_USER_SET_VRING_NUM] = VHOST_SET_VRING_NUM,
 	[VHOST_USER_SET_VRING_BASE] = VHOST_SET_VRING_BASE,
@@ -107,6 +105,32 @@ vhost_vdpa_set_owner(struct virtio_user_dev *dev)
 	return vhost_vdpa_ioctl(dev->vhostfd, VHOST_SET_OWNER, NULL);
 }
 
+static int
+vhost_vdpa_get_features(struct virtio_user_dev *dev, uint64_t *features)
+{
+	int ret;
+
+	ret = vhost_vdpa_ioctl(dev->vhostfd, VHOST_GET_FEATURES, features);
+	if (ret) {
+		PMD_DRV_LOG(ERR, "Failed to get features");
+		return -1;
+	}
+
+	/* Multiqueue not supported for now */
+	*features &= ~(1ULL << VIRTIO_NET_F_MQ);
+
+	return 0;
+}
+
+static int
+vhost_vdpa_set_features(struct virtio_user_dev *dev, uint64_t features)
+{
+	/* WORKAROUND */
+	features |= 1ULL << VIRTIO_F_IOMMU_PLATFORM;
+
+	return vhost_vdpa_ioctl(dev->vhostfd, VHOST_SET_FEATURES, &features);
+}
+
 static int
 vhost_vdpa_iotlb_batch_begin(struct virtio_user_dev *dev)
 {
@@ -343,14 +367,6 @@ vhost_vdpa_send_request(struct virtio_user_dev *dev,
 	if (req_vdpa == VHOST_SET_MEM_TABLE)
 		return vhost_vdpa_dma_map_all(dev);
 
-	if (req_vdpa == VHOST_SET_FEATURES) {
-		/* WORKAROUND */
-		*(uint64_t *)arg |= 1ULL << VIRTIO_F_IOMMU_PLATFORM;
-
-		/* Multiqueue not supported for now */
-		*(uint64_t *)arg &= ~(1ULL << VIRTIO_NET_F_MQ);
-	}
-
 	switch (req_vdpa) {
 	case VHOST_SET_VRING_NUM:
 	case VHOST_SET_VRING_ADDR:
@@ -429,6 +445,8 @@ vhost_vdpa_enable_queue_pair(struct virtio_user_dev *dev,
 struct virtio_user_backend_ops virtio_ops_vdpa = {
 	.setup = vhost_vdpa_setup,
 	.set_owner = vhost_vdpa_set_owner,
+	.get_features = vhost_vdpa_get_features,
+	.set_features = vhost_vdpa_set_features,
 	.send_request = vhost_vdpa_send_request,
 	.enable_qp = vhost_vdpa_enable_queue_pair,
 	.dma_map = vhost_vdpa_dma_map_batch,
drivers/net/virtio/virtio_user/virtio_user_dev.c +2 -3
index f4b97d8489..1f3bbae663 100644
@@ -141,7 +141,7 @@ virtio_user_dev_set_features(struct virtio_user_dev *dev)
 	/* Strip VIRTIO_NET_F_CTRL_VQ, as devices do not really need to know */
 	features &= ~(1ull << VIRTIO_NET_F_CTRL_VQ);
 	features &= ~(1ull << VIRTIO_NET_F_STATUS);
-	ret = dev->ops->send_request(dev, VHOST_USER_SET_FEATURES, &features);
+	ret = dev->ops->set_features(dev, features);
 	if (ret < 0)
 		goto error;
 	PMD_DRV_LOG(INFO, "set features: %" PRIx64, features);
@@ -496,8 +496,7 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
 			return -1;
 		}
 
-		if (dev->ops->send_request(dev, VHOST_USER_GET_FEATURES,
-					   &dev->device_features) < 0) {
+		if (dev->ops->get_features(dev, &dev->device_features) < 0) {
 			PMD_INIT_LOG(ERR, "get_features failed: %s",
 				     strerror(errno));
 			return -1;
drivers/net/virtio/virtio_user_ethdev.c +1 -2
index 91794b8645..56c379bc15 100644
@@ -85,8 +85,7 @@ virtio_user_server_reconnect(struct virtio_user_dev *dev)
 
 	virtio_set_status(hw, VIRTIO_CONFIG_STATUS_DRIVER);
 
-	if (dev->ops->send_request(dev, VHOST_USER_GET_FEATURES,
-				   &dev->device_features) < 0) {
+	if (dev->ops->get_features(dev, &dev->device_features) < 0) {
 		PMD_INIT_LOG(ERR, "get_features failed: %s",
 			     strerror(errno));
 		return -1;
Signature · 1 line
2.29.2
#35 lore raw

PATCH v4 28/44 net/virtio: add Virtio-user protocol features ops

In reply to Maxime Coquelin

This patch introduces new callbacks for getting
and setting Vhost-user protocol features.

---
 drivers/net/virtio/virtio_user/vhost.h        |  2 +
 drivers/net/virtio/virtio_user/vhost_user.c   | 64 +++++++++++++++++--
 drivers/net/virtio/virtio_user/vhost_vdpa.c   | 14 ++++
 .../net/virtio/virtio_user/virtio_user_dev.c  | 14 ++--
 drivers/net/virtio/virtio_user_ethdev.c       | 14 ++--
 5 files changed, 82 insertions(+), 26 deletions(-)
drivers/net/virtio/virtio_user/vhost.h +2 -0
index 13a88c7671..d805526130 100644
@@ -112,6 +112,8 @@ struct virtio_user_backend_ops {
 	int (*set_owner)(struct virtio_user_dev *dev);
 	int (*get_features)(struct virtio_user_dev *dev, uint64_t *features);
 	int (*set_features)(struct virtio_user_dev *dev, uint64_t features);
+	int (*get_protocol_features)(struct virtio_user_dev *dev, uint64_t *features);
+	int (*set_protocol_features)(struct virtio_user_dev *dev, uint64_t features);
 	int (*send_request)(struct virtio_user_dev *dev,
 			    enum vhost_user_request req,
 			    void *arg);
drivers/net/virtio/virtio_user/vhost_user.c +58 -6

100 lines not on this page · raw message

drivers/net/virtio/virtio_user/vhost_vdpa.c +14 -0
index 22a329526a..f627afbcfc 100644
@@ -105,6 +105,18 @@ vhost_vdpa_set_owner(struct virtio_user_dev *dev)
 	return vhost_vdpa_ioctl(dev->vhostfd, VHOST_SET_OWNER, NULL);
 }
 
+static int
+vhost_vdpa_get_backend_features(struct virtio_user_dev *dev, uint64_t *features)
+{
+	return vhost_vdpa_ioctl(dev->vhostfd, VHOST_GET_BACKEND_FEATURES, features);
+}
+
+static int
+vhost_vdpa_set_backend_features(struct virtio_user_dev *dev, uint64_t features)
+{
+	return vhost_vdpa_ioctl(dev->vhostfd, VHOST_SET_BACKEND_FEATURES, &features);
+}
+
 static int
 vhost_vdpa_get_features(struct virtio_user_dev *dev, uint64_t *features)
 {
@@ -447,6 +459,8 @@ struct virtio_user_backend_ops virtio_ops_vdpa = {
 	.set_owner = vhost_vdpa_set_owner,
 	.get_features = vhost_vdpa_get_features,
 	.set_features = vhost_vdpa_set_features,
+	.get_protocol_features = vhost_vdpa_get_backend_features,
+	.set_protocol_features = vhost_vdpa_set_backend_features,
 	.send_request = vhost_vdpa_send_request,
 	.enable_qp = vhost_vdpa_enable_queue_pair,
 	.dma_map = vhost_vdpa_dma_map_batch,
drivers/net/virtio/virtio_user/virtio_user_dev.c +4 -10
index 1f3bbae663..45417bbc5d 100644
@@ -505,22 +505,16 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
 
 		if ((dev->device_features & (1ULL << VHOST_USER_F_PROTOCOL_FEATURES)) ||
 				(dev->backend_type == VIRTIO_USER_BACKEND_VHOST_VDPA)) {
-			if (dev->ops->send_request(dev,
-					VHOST_USER_GET_PROTOCOL_FEATURES,
-					&protocol_features))
+			if (dev->ops->get_protocol_features(dev, &protocol_features))
 				return -1;
 
 			dev->protocol_features &= protocol_features;
 
-			if (dev->ops->send_request(dev,
-					VHOST_USER_SET_PROTOCOL_FEATURES,
-					&dev->protocol_features))
+			if (dev->ops->set_protocol_features(dev, dev->protocol_features))
 				return -1;
 
-			if (!(dev->protocol_features &
-					(1ULL << VHOST_USER_PROTOCOL_F_MQ)))
-				dev->unsupported_features |=
-					(1ull << VIRTIO_NET_F_MQ);
+			if (!(dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_MQ)))
+				dev->unsupported_features |= (1ull << VIRTIO_NET_F_MQ);
 		}
 	} else {
 		/* We just pretend vhost-user can support all these features.
drivers/net/virtio/virtio_user_ethdev.c +4 -10
index 56c379bc15..5e256f4e6d 100644
@@ -93,23 +93,17 @@ virtio_user_server_reconnect(struct virtio_user_dev *dev)
 
 	if (dev->device_features &
 			(1ULL << VHOST_USER_F_PROTOCOL_FEATURES)) {
-		if (dev->ops->send_request(dev,
-					VHOST_USER_GET_PROTOCOL_FEATURES,
-					&protocol_features))
+		if (dev->ops->get_protocol_features(dev, &protocol_features))
 			return -1;
 
 		/* Offer VHOST_USER_PROTOCOL_F_STATUS */
-		dev->protocol_features |=
-			(1ULL << VHOST_USER_PROTOCOL_F_STATUS);
+		dev->protocol_features |= (1ULL << VHOST_USER_PROTOCOL_F_STATUS);
 		dev->protocol_features &= protocol_features;
 
-		if (dev->ops->send_request(dev,
-					VHOST_USER_SET_PROTOCOL_FEATURES,
-					&dev->protocol_features))
+		if (dev->ops->set_protocol_features(dev, dev->protocol_features))
 			return -1;
 
-		if (!(dev->protocol_features &
-				(1ULL << VHOST_USER_PROTOCOL_F_MQ)))
+		if (!(dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_MQ)))
 			dev->unsupported_features |= (1ull << VIRTIO_NET_F_MQ);
 	}
 
Signature · 1 line
2.29.2
#36 lore raw

PATCH v4 29/44 net/virtio: add Virtio-user memory tables ops

In reply to Maxime Coquelin

This patch implements a dedicated callback for preparing and sending memory table to the backends.

---
 drivers/net/virtio/virtio_user/vhost.h        |  1 +
 drivers/net/virtio/virtio_user/vhost_kernel.c | 60 ++++++-------
 drivers/net/virtio/virtio_user/vhost_user.c   | 86 ++++++++++++++-----
 drivers/net/virtio/virtio_user/vhost_vdpa.c   |  8 +-
 .../net/virtio/virtio_user/virtio_user_dev.c  |  4 +-
 5 files changed, 101 insertions(+), 58 deletions(-)
drivers/net/virtio/virtio_user/vhost.h +1 -0
index d805526130..463801f563 100644
@@ -114,6 +114,7 @@ struct virtio_user_backend_ops {
 	int (*set_features)(struct virtio_user_dev *dev, uint64_t features);
 	int (*get_protocol_features)(struct virtio_user_dev *dev, uint64_t *features);
 	int (*set_protocol_features)(struct virtio_user_dev *dev, uint64_t features);
+	int (*set_memory_table)(struct virtio_user_dev *dev);
 	int (*send_request)(struct virtio_user_dev *dev,
 			    enum vhost_user_request req,
 			    void *arg);
drivers/net/virtio/virtio_user/vhost_kernel.c +30 -30

112 lines not on this page · raw message

drivers/net/virtio/virtio_user/vhost_user.c +66 -20

134 lines not on this page · raw message

drivers/net/virtio/virtio_user/vhost_vdpa.c +2 -6
index f627afbcfc..bd7daebf0c 100644
@@ -19,7 +19,6 @@
 #define VHOST_SET_FEATURES _IOW(VHOST_VIRTIO, 0x00, __u64)
 #define VHOST_SET_OWNER _IO(VHOST_VIRTIO, 0x01)
 #define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02)
-#define VHOST_SET_MEM_TABLE _IOW(VHOST_VIRTIO, 0x03, void *)
 #define VHOST_SET_LOG_BASE _IOW(VHOST_VIRTIO, 0x04, __u64)
 #define VHOST_SET_LOG_FD _IOW(VHOST_VIRTIO, 0x07, int)
 #define VHOST_SET_VRING_NUM _IOW(VHOST_VIRTIO, 0x10, struct vhost_vring_state)
@@ -46,7 +45,6 @@ static uint64_t vhost_req_user_to_vdpa[] = {
 	[VHOST_USER_GET_VRING_BASE] = VHOST_GET_VRING_BASE,
 	[VHOST_USER_SET_VRING_ADDR] = VHOST_SET_VRING_ADDR,
 	[VHOST_USER_SET_VRING_KICK] = VHOST_SET_VRING_KICK,
-	[VHOST_USER_SET_MEM_TABLE] = VHOST_SET_MEM_TABLE,
 	[VHOST_USER_SET_STATUS] = VHOST_VDPA_SET_STATUS,
 	[VHOST_USER_GET_STATUS] = VHOST_VDPA_GET_STATUS,
 	[VHOST_USER_SET_VRING_ENABLE] = VHOST_VDPA_SET_VRING_ENABLE,
@@ -319,7 +317,7 @@ vhost_vdpa_map(const struct rte_memseg_list *msl, const struct rte_memseg *ms,
 }
 
 static int
-vhost_vdpa_dma_map_all(struct virtio_user_dev *dev)
+vhost_vdpa_set_memory_table(struct virtio_user_dev *dev)
 {
 	int ret;
 
@@ -376,9 +374,6 @@ vhost_vdpa_send_request(struct virtio_user_dev *dev,
 
 	req_vdpa = vhost_req_user_to_vdpa[req];
 
-	if (req_vdpa == VHOST_SET_MEM_TABLE)
-		return vhost_vdpa_dma_map_all(dev);
-
 	switch (req_vdpa) {
 	case VHOST_SET_VRING_NUM:
 	case VHOST_SET_VRING_ADDR:
@@ -461,6 +456,7 @@ struct virtio_user_backend_ops virtio_ops_vdpa = {
 	.set_features = vhost_vdpa_set_features,
 	.get_protocol_features = vhost_vdpa_get_backend_features,
 	.set_protocol_features = vhost_vdpa_set_backend_features,
+	.set_memory_table = vhost_vdpa_set_memory_table,
 	.send_request = vhost_vdpa_send_request,
 	.enable_qp = vhost_vdpa_enable_queue_pair,
 	.dma_map = vhost_vdpa_dma_map_batch,
drivers/net/virtio/virtio_user/virtio_user_dev.c +2 -2
index 45417bbc5d..cb8f8a872c 100644
@@ -177,7 +177,7 @@ virtio_user_start_device(struct virtio_user_dev *dev)
 		goto error;
 
 	/* Step 2: share memory regions */
-	ret = dev->ops->send_request(dev, VHOST_USER_SET_MEM_TABLE, NULL);
+	ret = dev->ops->set_memory_table(dev);
 	if (ret < 0)
 		goto error;
 
@@ -352,7 +352,7 @@ virtio_user_mem_event_cb(enum rte_mem_event type __rte_unused,
 		dev->ops->enable_qp(dev, i, 0);
 
 	/* Step 2: update memory regions */
-	dev->ops->send_request(dev, VHOST_USER_SET_MEM_TABLE, NULL);
+	dev->ops->set_memory_table(dev);
 
 	/* Step 3: resume the active queues */
 	for (i = 0; i < dev->queue_pairs; i++)
Signature · 1 line
2.29.2
#37 lore raw

PATCH v4 30/44 net/virtio: add Virtio-user vring setting ops

In reply to Maxime Coquelin

This patch introduces new callbacks for setting
and getting vring state.

---
 drivers/net/virtio/virtio_user/vhost.h        |   3 +
 drivers/net/virtio/virtio_user/vhost_kernel.c |  49 +++++++-
 drivers/net/virtio/virtio_user/vhost_user.c   | 113 +++++++++++++-----
 drivers/net/virtio/virtio_user/vhost_vdpa.c   |  41 +++++--
 .../net/virtio/virtio_user/virtio_user_dev.c  |   9 +-
 5 files changed, 165 insertions(+), 50 deletions(-)
drivers/net/virtio/virtio_user/vhost.h +3 -0
index 463801f563..2d433d5966 100644
@@ -115,6 +115,9 @@ struct virtio_user_backend_ops {
 	int (*get_protocol_features)(struct virtio_user_dev *dev, uint64_t *features);
 	int (*set_protocol_features)(struct virtio_user_dev *dev, uint64_t features);
 	int (*set_memory_table)(struct virtio_user_dev *dev);
+	int (*set_vring_num)(struct virtio_user_dev *dev, struct vhost_vring_state *state);
+	int (*set_vring_base)(struct virtio_user_dev *dev, struct vhost_vring_state *state);
+	int (*get_vring_base)(struct virtio_user_dev *dev, struct vhost_vring_state *state);
 	int (*send_request)(struct virtio_user_dev *dev,
 			    enum vhost_user_request req,
 			    void *arg);
drivers/net/virtio/virtio_user/vhost_kernel.c +43 -6

71 lines not on this page · raw message

drivers/net/virtio/virtio_user/vhost_user.c +86 -27

152 lines not on this page · raw message

drivers/net/virtio/virtio_user/vhost_vdpa.c +29 -12

82 lines not on this page · raw message

drivers/net/virtio/virtio_user/virtio_user_dev.c +4 -5
index cb8f8a872c..0b30c10016 100644
@@ -73,13 +73,13 @@ virtio_user_kick_queue(struct virtio_user_dev *dev, uint32_t queue_sel)
 
 	state.index = queue_sel;
 	state.num = vring->num;
-	dev->ops->send_request(dev, VHOST_USER_SET_VRING_NUM, &state);
+	dev->ops->set_vring_num(dev, &state);
 
 	state.index = queue_sel;
 	state.num = 0; /* no reservation */
 	if (dev->features & (1ULL << VIRTIO_F_RING_PACKED))
 		state.num |= (1 << 15);
-	dev->ops->send_request(dev, VHOST_USER_SET_VRING_BASE, &state);
+	dev->ops->set_vring_base(dev, &state);
 
 	dev->ops->send_request(dev, VHOST_USER_SET_VRING_ADDR, &addr);
 
@@ -218,9 +218,8 @@ int virtio_user_stop_device(struct virtio_user_dev *dev)
 	/* Stop the backend. */
 	for (i = 0; i < dev->max_queue_pairs * 2; ++i) {
 		state.index = i;
-		if (dev->ops->send_request(dev, VHOST_USER_GET_VRING_BASE,
-					   &state) < 0) {
-			PMD_DRV_LOG(ERR, "get_vring_base failed, index=%u\n",
+		if (dev->ops->get_vring_base(dev, &state) < 0) {
+			PMD_DRV_LOG(ERR, "get_vring_base failed, index=%u",
 				    i);
 			error = -1;
 			goto out;
Signature · 1 line
2.29.2
#38 lore raw

PATCH v4 31/44 net/virtio: add Virtio-user vring file ops

In reply to Maxime Coquelin

This patch introduces new callbacks for setting
vring files (kick and call).

---
 drivers/net/virtio/virtio_user/vhost.h        |  2 +
 drivers/net/virtio/virtio_user/vhost_kernel.c | 41 +++++++++++++++--
 drivers/net/virtio/virtio_user/vhost_user.c   | 46 +++++++++++++++++--
 drivers/net/virtio/virtio_user/vhost_vdpa.c   | 18 ++++++--
 .../net/virtio/virtio_user/virtio_user_dev.c  |  4 +-
 5 files changed, 97 insertions(+), 14 deletions(-)
drivers/net/virtio/virtio_user/vhost.h +2 -0
index 2d433d5966..94c524547e 100644
@@ -118,6 +118,8 @@ struct virtio_user_backend_ops {
 	int (*set_vring_num)(struct virtio_user_dev *dev, struct vhost_vring_state *state);
 	int (*set_vring_base)(struct virtio_user_dev *dev, struct vhost_vring_state *state);
 	int (*get_vring_base)(struct virtio_user_dev *dev, struct vhost_vring_state *state);
+	int (*set_vring_call)(struct virtio_user_dev *dev, struct vhost_vring_file *file);
+	int (*set_vring_kick)(struct virtio_user_dev *dev, struct vhost_vring_file *file);
 	int (*send_request)(struct virtio_user_dev *dev,
 			    enum vhost_user_request req,
 			    void *arg);
drivers/net/virtio/virtio_user/vhost_kernel.c +37 -4

62 lines not on this page · raw message

drivers/net/virtio/virtio_user/vhost_user.c +42 -4

69 lines not on this page · raw message

drivers/net/virtio/virtio_user/vhost_vdpa.c +14 -4
index 323751093a..304a808b55 100644
@@ -38,9 +38,7 @@
 
 static uint64_t vhost_req_user_to_vdpa[] = {
 	[VHOST_USER_RESET_OWNER] = VHOST_RESET_OWNER,
-	[VHOST_USER_SET_VRING_CALL] = VHOST_SET_VRING_CALL,
 	[VHOST_USER_SET_VRING_ADDR] = VHOST_SET_VRING_ADDR,
-	[VHOST_USER_SET_VRING_KICK] = VHOST_SET_VRING_KICK,
 	[VHOST_USER_SET_STATUS] = VHOST_VDPA_SET_STATUS,
 	[VHOST_USER_GET_STATUS] = VHOST_VDPA_GET_STATUS,
 };
@@ -364,6 +362,18 @@ vhost_vdpa_get_vring_base(struct virtio_user_dev *dev, struct vhost_vring_state
 	return vhost_vdpa_ioctl(dev->vhostfd, VHOST_GET_VRING_BASE, state);
 }
 
+static int
+vhost_vdpa_set_vring_call(struct virtio_user_dev *dev, struct vhost_vring_file *file)
+{
+	return vhost_vdpa_ioctl(dev->vhostfd, VHOST_SET_VRING_CALL, file);
+}
+
+static int
+vhost_vdpa_set_vring_kick(struct virtio_user_dev *dev, struct vhost_vring_file *file)
+{
+	return vhost_vdpa_ioctl(dev->vhostfd, VHOST_SET_VRING_KICK, file);
+}
+
 /* with below features, vhost vdpa does not need to do the checksum and TSO,
  * these info will be passed to virtio_user through virtio net header.
  */
@@ -393,8 +403,6 @@ vhost_vdpa_send_request(struct virtio_user_dev *dev,
 
 	switch (req_vdpa) {
 	case VHOST_SET_VRING_ADDR:
-	case VHOST_SET_VRING_KICK:
-	case VHOST_SET_VRING_CALL:
 		PMD_DRV_LOG(DEBUG, "vhostfd=%d, index=%u",
 			    dev->vhostfd, *(unsigned int *)arg);
 		break;
@@ -474,6 +482,8 @@ struct virtio_user_backend_ops virtio_ops_vdpa = {
 	.set_vring_num = vhost_vdpa_set_vring_num,
 	.set_vring_base = vhost_vdpa_set_vring_base,
 	.get_vring_base = vhost_vdpa_get_vring_base,
+	.set_vring_call = vhost_vdpa_set_vring_call,
+	.set_vring_kick = vhost_vdpa_set_vring_kick,
 	.send_request = vhost_vdpa_send_request,
 	.enable_qp = vhost_vdpa_enable_queue_pair,
 	.dma_map = vhost_vdpa_dma_map_batch,
drivers/net/virtio/virtio_user/virtio_user_dev.c +2 -2
index 0b30c10016..4383e403da 100644
@@ -40,7 +40,7 @@ virtio_user_create_queue(struct virtio_user_dev *dev, uint32_t queue_sel)
 
 	file.index = queue_sel;
 	file.fd = dev->callfds[queue_sel];
-	dev->ops->send_request(dev, VHOST_USER_SET_VRING_CALL, &file);
+	dev->ops->set_vring_call(dev, &file);
 
 	return 0;
 }
@@ -89,7 +89,7 @@ virtio_user_kick_queue(struct virtio_user_dev *dev, uint32_t queue_sel)
 	 */
 	file.index = queue_sel;
 	file.fd = dev->kickfds[queue_sel];
-	dev->ops->send_request(dev, VHOST_USER_SET_VRING_KICK, &file);
+	dev->ops->set_vring_kick(dev, &file);
 
 	return 0;
 }
Signature · 1 line
2.29.2
#39 lore raw

PATCH v4 32/44 net/virtio: add Virtio-user vring address ops

In reply to Maxime Coquelin

This patch introduces a new callback for setting
vrings addresses.

---
 drivers/net/virtio/virtio_user/vhost.h        |  1 +
 drivers/net/virtio/virtio_user/vhost_kernel.c | 32 +++++++++++++------
 drivers/net/virtio/virtio_user/vhost_user.c   | 29 +++++++++++++----
 drivers/net/virtio/virtio_user/vhost_vdpa.c   |  8 ++++-
 .../net/virtio/virtio_user/virtio_user_dev.c  |  2 +-
 5 files changed, 55 insertions(+), 17 deletions(-)
drivers/net/virtio/virtio_user/vhost.h +1 -0
index 94c524547e..19040dfdc2 100644
@@ -120,6 +120,7 @@ struct virtio_user_backend_ops {
 	int (*get_vring_base)(struct virtio_user_dev *dev, struct vhost_vring_state *state);
 	int (*set_vring_call)(struct virtio_user_dev *dev, struct vhost_vring_file *file);
 	int (*set_vring_kick)(struct virtio_user_dev *dev, struct vhost_vring_file *file);
+	int (*set_vring_addr)(struct virtio_user_dev *dev, struct vhost_vring_addr *addr);
 	int (*send_request)(struct virtio_user_dev *dev,
 			    enum vhost_user_request req,
 			    void *arg);
drivers/net/virtio/virtio_user/vhost_kernel.c +23 -9
index bdef436595..48eeb77aec 100644
@@ -294,9 +294,30 @@ vhost_kernel_set_vring_call(struct virtio_user_dev *dev, struct vhost_vring_file
 	return vhost_kernel_set_vring_file(dev, VHOST_SET_VRING_CALL, file);
 }
 
+static int
+vhost_kernel_set_vring_addr(struct virtio_user_dev *dev, struct vhost_vring_addr *addr)
+{
+	int ret, fd;
+	unsigned int index = addr->index;
+
+	/* Convert from queue index to queue-pair & offset */
+	fd = dev->vhostfds[addr->index / 2];
+	addr->index %= 2;
+
+	ret = vhost_kernel_ioctl(fd, VHOST_SET_VRING_ADDR, addr);
+	if (ret < 0) {
+		PMD_DRV_LOG(ERR, "Failed to set vring address");
+		return -1;
+	}
+
+	/* restore index back to queue index */
+	addr->index = index;
+
+	return 0;
+}
+
 static uint64_t vhost_req_user_to_kernel[] = {
 	[VHOST_USER_RESET_OWNER] = VHOST_RESET_OWNER,
-	[VHOST_USER_SET_VRING_ADDR] = VHOST_SET_VRING_ADDR,
 };
 
 static int
@@ -308,20 +329,12 @@ vhost_kernel_send_request(struct virtio_user_dev *dev,
 	unsigned int i;
 	uint64_t req_kernel;
 	int vhostfd;
-	unsigned int queue_sel;
 
 	PMD_DRV_LOG(INFO, "%s", vhost_msg_strings[req]);
 
 	req_kernel = vhost_req_user_to_kernel[req];
 
 	switch (req_kernel) {
-	case VHOST_SET_VRING_ADDR:
-		queue_sel = *(unsigned int *)arg;
-		vhostfd = dev->vhostfds[queue_sel / 2];
-		*(unsigned int *)arg = queue_sel % 2;
-		PMD_DRV_LOG(DEBUG, "vhostfd=%d, index=%u",
-			    vhostfd, *(unsigned int *)arg);
-		break;
 	default:
 		vhostfd = -1;
 	}
@@ -473,6 +486,7 @@ struct virtio_user_backend_ops virtio_ops_kernel = {
 	.get_vring_base = vhost_kernel_get_vring_base,
 	.set_vring_call = vhost_kernel_set_vring_call,
 	.set_vring_kick = vhost_kernel_set_vring_kick,
+	.set_vring_addr = vhost_kernel_set_vring_addr,
 	.send_request = vhost_kernel_send_request,
 	.enable_qp = vhost_kernel_enable_queue_pair
 };
drivers/net/virtio/virtio_user/vhost_user.c +23 -6
index ccb40484f4..9ff49d2b1d 100644
@@ -538,11 +538,32 @@ vhost_user_set_vring_kick(struct virtio_user_dev *dev, struct vhost_vring_file *
 	return vhost_user_set_vring_file(dev, VHOST_USER_SET_VRING_KICK, file);
 }
 
+
+static int
+vhost_user_set_vring_addr(struct virtio_user_dev *dev, struct vhost_vring_addr *addr)
+{
+	int ret;
+	struct vhost_user_msg msg = {
+		.request = VHOST_USER_SET_VRING_ADDR,
+		.flags = VHOST_USER_VERSION,
+		.size = sizeof(*addr),
+		.payload.addr = *addr,
+	};
+
+	ret = vhost_user_write(dev->vhostfd, &msg, NULL, 0);
+	if (ret < 0) {
+		PMD_DRV_LOG(ERR, "Failed to send vring addresses");
+		return -1;
+	}
+
+	return 0;
+}
+
+
 static struct vhost_user_msg m;
 
 const char * const vhost_msg_strings[] = {
 	[VHOST_USER_RESET_OWNER] = "VHOST_RESET_OWNER",
-	[VHOST_USER_SET_VRING_ADDR] = "VHOST_SET_VRING_ADDR",
 	[VHOST_USER_SET_STATUS] = "VHOST_SET_STATUS",
 	[VHOST_USER_GET_STATUS] = "VHOST_GET_STATUS",
 };
@@ -610,11 +631,6 @@ vhost_user_sock(struct virtio_user_dev *dev,
 		fds[fd_num++] = *((int *)arg);
 		break;
 
-	case VHOST_USER_SET_VRING_ADDR:
-		memcpy(&msg.payload.addr, arg, sizeof(msg.payload.addr));
-		msg.size = sizeof(m.payload.addr);
-		break;
-
 	case VHOST_USER_SET_VRING_ERR:
 		file = arg;
 		msg.payload.u64 = file->index & VHOST_USER_VRING_IDX_MASK;
@@ -787,6 +803,7 @@ struct virtio_user_backend_ops virtio_ops_user = {
 	.get_vring_base = vhost_user_get_vring_base,
 	.set_vring_call = vhost_user_set_vring_call,
 	.set_vring_kick = vhost_user_set_vring_kick,
+	.set_vring_addr = vhost_user_set_vring_addr,
 	.send_request = vhost_user_sock,
 	.enable_qp = vhost_user_enable_queue_pair
 };
drivers/net/virtio/virtio_user/vhost_vdpa.c +7 -1
index 304a808b55..1ec6bb26f2 100644
@@ -38,7 +38,6 @@
 
 static uint64_t vhost_req_user_to_vdpa[] = {
 	[VHOST_USER_RESET_OWNER] = VHOST_RESET_OWNER,
-	[VHOST_USER_SET_VRING_ADDR] = VHOST_SET_VRING_ADDR,
 	[VHOST_USER_SET_STATUS] = VHOST_VDPA_SET_STATUS,
 	[VHOST_USER_GET_STATUS] = VHOST_VDPA_GET_STATUS,
 };
@@ -374,6 +373,12 @@ vhost_vdpa_set_vring_kick(struct virtio_user_dev *dev, struct vhost_vring_file *
 	return vhost_vdpa_ioctl(dev->vhostfd, VHOST_SET_VRING_KICK, file);
 }
 
+static int
+vhost_vdpa_set_vring_addr(struct virtio_user_dev *dev, struct vhost_vring_addr *addr)
+{
+	return vhost_vdpa_ioctl(dev->vhostfd, VHOST_SET_VRING_ADDR, addr);
+}
+
 /* with below features, vhost vdpa does not need to do the checksum and TSO,
  * these info will be passed to virtio_user through virtio net header.
  */
@@ -484,6 +489,7 @@ struct virtio_user_backend_ops virtio_ops_vdpa = {
 	.get_vring_base = vhost_vdpa_get_vring_base,
 	.set_vring_call = vhost_vdpa_set_vring_call,
 	.set_vring_kick = vhost_vdpa_set_vring_kick,
+	.set_vring_addr = vhost_vdpa_set_vring_addr,
 	.send_request = vhost_vdpa_send_request,
 	.enable_qp = vhost_vdpa_enable_queue_pair,
 	.dma_map = vhost_vdpa_dma_map_batch,
drivers/net/virtio/virtio_user/virtio_user_dev.c +1 -1
index 4383e403da..7e365d0570 100644
@@ -81,7 +81,7 @@ virtio_user_kick_queue(struct virtio_user_dev *dev, uint32_t queue_sel)
 		state.num |= (1 << 15);
 	dev->ops->set_vring_base(dev, &state);
 
-	dev->ops->send_request(dev, VHOST_USER_SET_VRING_ADDR, &addr);
+	dev->ops->set_vring_addr(dev, &addr);
 
 	/* Of all per virtqueue MSGs, make sure VHOST_USER_SET_VRING_KICK comes
 	 * lastly because vhost depends on this msg to judge if
Signature · 1 line
2.29.2
#40 lore raw

PATCH v4 33/44 net/virtio: add Virtio-user status ops

In reply to Maxime Coquelin

This patch introduces new callbacks to
get and set the device status.

---
 drivers/net/virtio/virtio_user/vhost.h        |   2 +
 drivers/net/virtio/virtio_user/vhost_kernel.c |  14 ++
 drivers/net/virtio/virtio_user/vhost_user.c   | 121 +++++++++++++-----
 drivers/net/virtio/virtio_user/vhost_vdpa.c   |  16 ++-
 .../net/virtio/virtio_user/virtio_user_dev.c  |  42 ++----
 5 files changed, 129 insertions(+), 66 deletions(-)
drivers/net/virtio/virtio_user/vhost.h +2 -0
index 19040dfdc2..c896f0836d 100644
@@ -121,6 +121,8 @@ struct virtio_user_backend_ops {
 	int (*set_vring_call)(struct virtio_user_dev *dev, struct vhost_vring_file *file);
 	int (*set_vring_kick)(struct virtio_user_dev *dev, struct vhost_vring_file *file);
 	int (*set_vring_addr)(struct virtio_user_dev *dev, struct vhost_vring_addr *addr);
+	int (*get_status)(struct virtio_user_dev *dev, uint8_t *status);
+	int (*set_status)(struct virtio_user_dev *dev, uint8_t status);
 	int (*send_request)(struct virtio_user_dev *dev,
 			    enum vhost_user_request req,
 			    void *arg);
drivers/net/virtio/virtio_user/vhost_kernel.c +14 -0
index 48eeb77aec..4de4b669d2 100644
@@ -316,6 +316,18 @@ vhost_kernel_set_vring_addr(struct virtio_user_dev *dev, struct vhost_vring_addr
 	return 0;
 }
 
+static int
+vhost_kernel_get_status(struct virtio_user_dev *dev __rte_unused, uint8_t *status __rte_unused)
+{
+	return -ENOTSUP;
+}
+
+static int
+vhost_kernel_set_status(struct virtio_user_dev *dev __rte_unused, uint8_t status __rte_unused)
+{
+	return -ENOTSUP;
+}
+
 static uint64_t vhost_req_user_to_kernel[] = {
 	[VHOST_USER_RESET_OWNER] = VHOST_RESET_OWNER,
 };
@@ -487,6 +499,8 @@ struct virtio_user_backend_ops virtio_ops_kernel = {
 	.set_vring_call = vhost_kernel_set_vring_call,
 	.set_vring_kick = vhost_kernel_set_vring_kick,
 	.set_vring_addr = vhost_kernel_set_vring_addr,
+	.get_status = vhost_kernel_get_status,
+	.set_status = vhost_kernel_set_status,
 	.send_request = vhost_kernel_send_request,
 	.enable_qp = vhost_kernel_enable_queue_pair
 };
drivers/net/virtio/virtio_user/vhost_user.c +91 -30

161 lines not on this page · raw message

drivers/net/virtio/virtio_user/vhost_vdpa.c +14 -2
index 1ec6bb26f2..8ebc679f1b 100644
@@ -38,8 +38,6 @@
 
 static uint64_t vhost_req_user_to_vdpa[] = {
 	[VHOST_USER_RESET_OWNER] = VHOST_RESET_OWNER,
-	[VHOST_USER_SET_STATUS] = VHOST_VDPA_SET_STATUS,
-	[VHOST_USER_GET_STATUS] = VHOST_VDPA_GET_STATUS,
 };
 
 /* no alignment requirement */
@@ -379,6 +377,18 @@ vhost_vdpa_set_vring_addr(struct virtio_user_dev *dev, struct vhost_vring_addr *
 	return vhost_vdpa_ioctl(dev->vhostfd, VHOST_SET_VRING_ADDR, addr);
 }
 
+static int
+vhost_vdpa_get_status(struct virtio_user_dev *dev, uint8_t *status)
+{
+	return vhost_vdpa_ioctl(dev->vhostfd, VHOST_VDPA_GET_STATUS, status);
+}
+
+static int
+vhost_vdpa_set_status(struct virtio_user_dev *dev, uint8_t status)
+{
+	return vhost_vdpa_ioctl(dev->vhostfd, VHOST_VDPA_SET_STATUS, &status);
+}
+
 /* with below features, vhost vdpa does not need to do the checksum and TSO,
  * these info will be passed to virtio_user through virtio net header.
  */
@@ -490,6 +500,8 @@ struct virtio_user_backend_ops virtio_ops_vdpa = {
 	.set_vring_call = vhost_vdpa_set_vring_call,
 	.set_vring_kick = vhost_vdpa_set_vring_kick,
 	.set_vring_addr = vhost_vdpa_set_vring_addr,
+	.get_status = vhost_vdpa_get_status,
+	.set_status = vhost_vdpa_set_status,
 	.send_request = vhost_vdpa_send_request,
 	.enable_qp = vhost_vdpa_enable_queue_pair,
 	.dma_map = vhost_vdpa_dma_map_batch,
drivers/net/virtio/virtio_user/virtio_user_dev.c +8 -34

70 lines not on this page · raw message

Signature · 1 line
2.29.2
#41 lore raw

PATCH v4 34/44 net/virtio: remove useless request ops

In reply to Maxime Coquelin

Now that all the ops have been implemented, we
can remove the send_request ops for all backends.

---
 drivers/net/virtio/virtio_user/vhost.h        |  15 +--
 drivers/net/virtio/virtio_user/vhost_kernel.c |  43 --------
 drivers/net/virtio/virtio_user/vhost_user.c   | 102 ------------------
 drivers/net/virtio/virtio_user/vhost_vdpa.c   |  49 ---------
 4 files changed, 3 insertions(+), 206 deletions(-)
drivers/net/virtio/virtio_user/vhost.h +3 -12
index c896f0836d..6294b8afee 100644
@@ -96,8 +96,6 @@ enum vhost_user_request {
 #define VHOST_BACKEND_F_IOTLB_BATCH 2
 #endif
 
-extern const char * const vhost_msg_strings[VHOST_USER_MAX];
-
 struct vhost_memory_region {
 	uint64_t guest_phys_addr;
 	uint64_t memory_size; /* bytes */
@@ -123,16 +121,9 @@ struct virtio_user_backend_ops {
 	int (*set_vring_addr)(struct virtio_user_dev *dev, struct vhost_vring_addr *addr);
 	int (*get_status)(struct virtio_user_dev *dev, uint8_t *status);
 	int (*set_status)(struct virtio_user_dev *dev, uint8_t status);
-	int (*send_request)(struct virtio_user_dev *dev,
-			    enum vhost_user_request req,
-			    void *arg);
-	int (*enable_qp)(struct virtio_user_dev *dev,
-			 uint16_t pair_idx,
-			 int enable);
-	int (*dma_map)(struct virtio_user_dev *dev, void *addr,
-				  uint64_t iova, size_t len);
-	int (*dma_unmap)(struct virtio_user_dev *dev, void *addr,
-				  uint64_t iova, size_t len);
+	int (*enable_qp)(struct virtio_user_dev *dev, uint16_t pair_idx, int enable);
+	int (*dma_map)(struct virtio_user_dev *dev, void *addr, uint64_t iova, size_t len);
+	int (*dma_unmap)(struct virtio_user_dev *dev, void *addr, uint64_t iova, size_t len);
 };
 
 extern struct virtio_user_backend_ops virtio_ops_user;
drivers/net/virtio/virtio_user/vhost_kernel.c +0 -43

54 lines not on this page · raw message

drivers/net/virtio/virtio_user/vhost_user.c +0 -102

113 lines not on this page · raw message

drivers/net/virtio/virtio_user/vhost_vdpa.c +0 -49

67 lines not on this page · raw message

Signature · 1 line
2.29.2
#42 lore raw

PATCH v4 35/44 net/virtio: improve Virtio-user errors handling

In reply to Maxime Coquelin

This patch adds error logs and propagates errors reported by the backend. It also adds the device path in error logs to make it easier to distinguish which device is facing the issue.

---
 .../net/virtio/virtio_user/virtio_user_dev.c  | 154 ++++++++++++------
 1 file changed, 104 insertions(+), 50 deletions(-)
drivers/net/virtio/virtio_user/virtio_user_dev.c +104 -50
index 33a25f4684..95204ea955 100644
@@ -37,10 +37,15 @@ virtio_user_create_queue(struct virtio_user_dev *dev, uint32_t queue_sel)
 	 * pair.
 	 */
 	struct vhost_vring_file file;
+	int ret;
 
 	file.index = queue_sel;
 	file.fd = dev->callfds[queue_sel];
-	dev->ops->set_vring_call(dev, &file);
+	ret = dev->ops->set_vring_call(dev, &file);
+	if (ret < 0) {
+		PMD_INIT_LOG(ERR, "(%s) Failed to create queue %u\n", dev->path, queue_sel);
+		return -1;
+	}
 
 	return 0;
 }
@@ -48,6 +53,7 @@ virtio_user_create_queue(struct virtio_user_dev *dev, uint32_t queue_sel)
 static int
 virtio_user_kick_queue(struct virtio_user_dev *dev, uint32_t queue_sel)
 {
+	int ret;
 	struct vhost_vring_file file;
 	struct vhost_vring_state state;
 	struct vring *vring = &dev->vrings[queue_sel];
@@ -73,15 +79,21 @@ virtio_user_kick_queue(struct virtio_user_dev *dev, uint32_t queue_sel)
 
 	state.index = queue_sel;
 	state.num = vring->num;
-	dev->ops->set_vring_num(dev, &state);
+	ret = dev->ops->set_vring_num(dev, &state);
+	if (ret < 0)
+		goto err;
 
 	state.index = queue_sel;
 	state.num = 0; /* no reservation */
 	if (dev->features & (1ULL << VIRTIO_F_RING_PACKED))
 		state.num |= (1 << 15);
-	dev->ops->set_vring_base(dev, &state);
+	ret = dev->ops->set_vring_base(dev, &state);
+	if (ret < 0)
+		goto err;
 
-	dev->ops->set_vring_addr(dev, &addr);
+	ret = dev->ops->set_vring_addr(dev, &addr);
+	if (ret < 0)
+		goto err;
 
 	/* Of all per virtqueue MSGs, make sure VHOST_USER_SET_VRING_KICK comes
 	 * lastly because vhost depends on this msg to judge if
@@ -89,9 +101,15 @@ virtio_user_kick_queue(struct virtio_user_dev *dev, uint32_t queue_sel)
 	 */
 	file.index = queue_sel;
 	file.fd = dev->kickfds[queue_sel];
-	dev->ops->set_vring_kick(dev, &file);
+	ret = dev->ops->set_vring_kick(dev, &file);
+	if (ret < 0)
+		goto err;
 
 	return 0;
+err:
+	PMD_INIT_LOG(ERR, "(%s) Failed to kick queue %u\n", dev->path, queue_sel);
+
+	return -1;
 }
 
 static int
@@ -103,14 +121,14 @@ virtio_user_queue_setup(struct virtio_user_dev *dev,
 	for (i = 0; i < dev->max_queue_pairs; ++i) {
 		queue_sel = 2 * i + VTNET_SQ_RQ_QUEUE_IDX;
 		if (fn(dev, queue_sel) < 0) {
-			PMD_DRV_LOG(INFO, "setup rx vq fails: %u", i);
+			PMD_DRV_LOG(ERR, "(%s) setup rx vq %u failed", dev->path, i);
 			return -1;
 		}
 	}
 	for (i = 0; i < dev->max_queue_pairs; ++i) {
 		queue_sel = 2 * i + VTNET_SQ_TQ_QUEUE_IDX;
 		if (fn(dev, queue_sel) < 0) {
-			PMD_DRV_LOG(INFO, "setup tx vq fails: %u", i);
+			PMD_DRV_LOG(INFO, "(%s) setup tx vq %u failed", dev->path, i);
 			return -1;
 		}
 	}
@@ -144,7 +162,7 @@ virtio_user_dev_set_features(struct virtio_user_dev *dev)
 	ret = dev->ops->set_features(dev, features);
 	if (ret < 0)
 		goto error;
-	PMD_DRV_LOG(INFO, "set features: %" PRIx64, features);
+	PMD_DRV_LOG(INFO, "(%s) set features: 0x%" PRIx64, dev->path, features);
 error:
 	pthread_mutex_unlock(&dev->mutex);
 
@@ -172,9 +190,10 @@ virtio_user_start_device(struct virtio_user_dev *dev)
 	rte_mcfg_mem_read_lock();
 	pthread_mutex_lock(&dev->mutex);
 
+	/* Vhost-user client not connected yet, will start later */
 	if (dev->backend_type == VIRTIO_USER_BACKEND_VHOST_USER &&
 			dev->vhostfd < 0)
-		goto error;
+		goto out;
 
 	/* Step 2: share memory regions */
 	ret = dev->ops->set_memory_table(dev);
@@ -182,15 +201,19 @@ virtio_user_start_device(struct virtio_user_dev *dev)
 		goto error;
 
 	/* Step 3: kick queues */
-	if (virtio_user_queue_setup(dev, virtio_user_kick_queue) < 0)
+	ret = virtio_user_queue_setup(dev, virtio_user_kick_queue);
+	if (ret < 0)
 		goto error;
 
 	/* Step 4: enable queues
 	 * we enable the 1st queue pair by default.
 	 */
-	dev->ops->enable_qp(dev, 0, 1);
+	ret = dev->ops->enable_qp(dev, 0, 1);
+	if (ret < 0)
+		goto error;
 
 	dev->started = true;
+out:
 	pthread_mutex_unlock(&dev->mutex);
 	rte_mcfg_mem_read_unlock();
 
@@ -198,6 +221,9 @@ virtio_user_start_device(struct virtio_user_dev *dev)
 error:
 	pthread_mutex_unlock(&dev->mutex);
 	rte_mcfg_mem_read_unlock();
+
+	PMD_INIT_LOG(ERR, "(%s) Failed to start device\n", dev->path);
+
 	/* TODO: free resource here or caller to check */
 	return -1;
 }
@@ -206,31 +232,40 @@ int virtio_user_stop_device(struct virtio_user_dev *dev)
 {
 	struct vhost_vring_state state;
 	uint32_t i;
-	int error = 0;
+	int ret;
 
 	pthread_mutex_lock(&dev->mutex);
 	if (!dev->started)
 		goto out;
 
-	for (i = 0; i < dev->max_queue_pairs; ++i)
-		dev->ops->enable_qp(dev, i, 0);
+	for (i = 0; i < dev->max_queue_pairs; ++i) {
+		ret = dev->ops->enable_qp(dev, i, 0);
+		if (ret < 0)
+			goto err;
+	}
 
 	/* Stop the backend. */
 	for (i = 0; i < dev->max_queue_pairs * 2; ++i) {
 		state.index = i;
-		if (dev->ops->get_vring_base(dev, &state) < 0) {
-			PMD_DRV_LOG(ERR, "get_vring_base failed, index=%u",
-				    i);
-			error = -1;
-			goto out;
+		ret = dev->ops->get_vring_base(dev, &state);
+		if (ret < 0) {
+			PMD_DRV_LOG(ERR, "(%s) get_vring_base failed, index=%u", dev->path, i);
+			goto err;
 		}
 	}
 
 	dev->started = false;
+
 out:
 	pthread_mutex_unlock(&dev->mutex);
 
-	return error;
+	return 0;
+err:
+	pthread_mutex_unlock(&dev->mutex);
+
+	PMD_INIT_LOG(ERR, "(%s) Failed to stop device\n", dev->path);
+
+	return -1;
 }
 
 static inline void
@@ -270,13 +305,13 @@ virtio_user_dev_init_notify(struct virtio_user_dev *dev)
 		 */
 		callfd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
 		if (callfd < 0) {
-			PMD_DRV_LOG(ERR, "callfd error, %s", strerror(errno));
+			PMD_DRV_LOG(ERR, "(%s) callfd error, %s", dev->path, strerror(errno));
 			break;
 		}
 		kickfd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
 		if (kickfd < 0) {
 			close(callfd);
-			PMD_DRV_LOG(ERR, "kickfd error, %s", strerror(errno));
+			PMD_DRV_LOG(ERR, "(%s) kickfd error, %s", dev->path, strerror(errno));
 			break;
 		}
 		dev->callfds[i] = callfd;
@@ -304,7 +339,7 @@ virtio_user_fill_intr_handle(struct virtio_user_dev *dev)
 	if (!eth_dev->intr_handle) {
 		eth_dev->intr_handle = malloc(sizeof(*eth_dev->intr_handle));
 		if (!eth_dev->intr_handle) {
-			PMD_DRV_LOG(ERR, "fail to allocate intr_handle");
+			PMD_DRV_LOG(ERR, "(%s) failed to allocate intr_handle", dev->path);
 			return -1;
 		}
 		memset(eth_dev->intr_handle, 0, sizeof(*eth_dev->intr_handle));
@@ -335,6 +370,7 @@ virtio_user_mem_event_cb(enum rte_mem_event type __rte_unused,
 	struct virtio_user_dev *dev = arg;
 	struct rte_memseg_list *msl;
 	uint16_t i;
+	int ret = 0;
 
 	/* ignore externally allocated memory */
 	msl = rte_mem_virt2memseg_list(addr);
@@ -347,18 +383,29 @@ virtio_user_mem_event_cb(enum rte_mem_event type __rte_unused,
 		goto exit;
 
 	/* Step 1: pause the active queues */
-	for (i = 0; i < dev->queue_pairs; i++)
-		dev->ops->enable_qp(dev, i, 0);
+	for (i = 0; i < dev->queue_pairs; i++) {
+		ret = dev->ops->enable_qp(dev, i, 0);
+		if (ret < 0)
+			goto exit;
+	}
 
 	/* Step 2: update memory regions */
-	dev->ops->set_memory_table(dev);
+	ret = dev->ops->set_memory_table(dev);
+	if (ret < 0)
+		goto exit;
 
 	/* Step 3: resume the active queues */
-	for (i = 0; i < dev->queue_pairs; i++)
-		dev->ops->enable_qp(dev, i, 1);
+	for (i = 0; i < dev->queue_pairs; i++) {
+		ret = dev->ops->enable_qp(dev, i, 1);
+		if (ret < 0)
+			goto exit;
+	}
 
 exit:
 	pthread_mutex_unlock(&dev->mutex);
+
+	if (ret < 0)
+		PMD_DRV_LOG(ERR, "(%s) Failed to update memory table\n", dev->path);
 }
 
 static int
@@ -388,7 +435,7 @@ virtio_user_dev_setup(struct virtio_user_dev *dev)
 			dev->tapfds = malloc(dev->max_queue_pairs *
 					     sizeof(int));
 			if (!dev->vhostfds || !dev->tapfds) {
-				PMD_INIT_LOG(ERR, "Failed to malloc");
+				PMD_INIT_LOG(ERR, "(%s) Failed to allocate FDs", dev->path);
 				return -1;
 			}
 
@@ -400,19 +447,25 @@ virtio_user_dev_setup(struct virtio_user_dev *dev)
 				VIRTIO_USER_BACKEND_VHOST_VDPA) {
 			dev->ops = &virtio_ops_vdpa;
 		} else {
-			PMD_DRV_LOG(ERR, "Unknown backend type");
+			PMD_DRV_LOG(ERR, "(%s) Unknown backend type", dev->path);
 			return -1;
 		}
 	}
 
-	if (dev->ops->setup(dev) < 0)
+	if (dev->ops->setup(dev) < 0) {
+		PMD_INIT_LOG(ERR, "(%s) Failed to setup backend\n", dev->path);
 		return -1;
+	}
 
-	if (virtio_user_dev_init_notify(dev) < 0)
+	if (virtio_user_dev_init_notify(dev) < 0) {
+		PMD_INIT_LOG(ERR, "(%s) Failed to init notifiers\n", dev->path);
 		return -1;
+	}
 
-	if (virtio_user_fill_intr_handle(dev) < 0)
+	if (virtio_user_fill_intr_handle(dev) < 0) {
+		PMD_INIT_LOG(ERR, "(%s) Failed to init interrupt handler\n", dev->path);
 		return -1;
+	}
 
 	return 0;
 }
@@ -480,7 +533,7 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
 	}
 
 	if (virtio_user_dev_setup(dev) < 0) {
-		PMD_INIT_LOG(ERR, "backend set up fails");
+		PMD_INIT_LOG(ERR, "(%s) backend set up fails", dev->path);
 		return -1;
 	}
 
@@ -490,27 +543,31 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
 
 	if (!dev->is_server) {
 		if (dev->ops->set_owner(dev) < 0) {
-			PMD_INIT_LOG(ERR, "set_owner fails: %s",
-				     strerror(errno));
+			PMD_INIT_LOG(ERR, "(%s) Failed to set backend owner", dev->path);
 			return -1;
 		}
 
 		if (dev->ops->get_features(dev, &dev->device_features) < 0) {
-			PMD_INIT_LOG(ERR, "get_features failed: %s",
-				     strerror(errno));
+			PMD_INIT_LOG(ERR, "(%s) Failed to get backend features", dev->path);
 			return -1;
 		}
 
 
 		if ((dev->device_features & (1ULL << VHOST_USER_F_PROTOCOL_FEATURES)) ||
 				(dev->backend_type == VIRTIO_USER_BACKEND_VHOST_VDPA)) {
-			if (dev->ops->get_protocol_features(dev, &protocol_features))
+			if (dev->ops->get_protocol_features(dev, &protocol_features)) {
+				PMD_INIT_LOG(ERR, "(%s) Failed to get backend protocol features",
+						dev->path);
 				return -1;
+			}
 
 			dev->protocol_features &= protocol_features;
 
-			if (dev->ops->set_protocol_features(dev, dev->protocol_features))
+			if (dev->ops->set_protocol_features(dev, dev->protocol_features)) {
+				PMD_INIT_LOG(ERR, "(%s) Failed to set backend protocol features",
+						dev->path);
 				return -1;
+			}
 
 			if (!(dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_MQ)))
 				dev->unsupported_features |= (1ull << VIRTIO_NET_F_MQ);
@@ -577,8 +634,8 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
 	if (rte_mem_event_callback_register(VIRTIO_USER_MEM_EVENT_CLB_NAME,
 				virtio_user_mem_event_cb, dev)) {
 		if (rte_errno != ENOTSUP) {
-			PMD_INIT_LOG(ERR, "Failed to register mem event"
-					" callback\n");
+			PMD_INIT_LOG(ERR, "(%s) Failed to register mem event callback\n",
+					dev->path);
 			return -1;
 		}
 	}
@@ -631,8 +688,8 @@ virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs)
 	uint8_t ret = 0;
 
 	if (q_pairs > dev->max_queue_pairs) {
-		PMD_INIT_LOG(ERR, "multi-q config %u, but only %u supported",
-			     q_pairs, dev->max_queue_pairs);
+		PMD_INIT_LOG(ERR, "(%s) multi-q config %u, but only %u supported",
+			     dev->path, q_pairs, dev->max_queue_pairs);
 		return -1;
 	}
 
@@ -818,10 +875,8 @@ virtio_user_dev_set_status(struct virtio_user_dev *dev, uint8_t status)
 	pthread_mutex_lock(&dev->mutex);
 	dev->status = status;
 	ret = dev->ops->set_status(dev, status);
-	if (ret && ret != -ENOTSUP) {
-		PMD_INIT_LOG(ERR, "Virtio-user set status failed (%d): %s", ret,
-			     strerror(errno));
-	}
+	if (ret && ret != -ENOTSUP)
+		PMD_INIT_LOG(ERR, "(%s) Failed to set backend status\n", dev->path);
 
 	pthread_mutex_unlock(&dev->mutex);
 	return ret;
@@ -855,8 +910,7 @@ virtio_user_dev_update_status(struct virtio_user_dev *dev)
 			!!(dev->status & VIRTIO_CONFIG_STATUS_DEV_NEED_RESET),
 			!!(dev->status & VIRTIO_CONFIG_STATUS_FAILED));
 	} else if (ret != -ENOTSUP) {
-		PMD_INIT_LOG(ERR, "Virtio-user get status failed (%d): %s", ret,
-			     strerror(errno));
+		PMD_INIT_LOG(ERR, "(%s) Failed to get backend status\n", dev->path);
 	}
 
 	pthread_mutex_unlock(&dev->mutex);
Signature · 1 line
2.29.2
#43 lore raw

PATCH v4 36/44 net/virtio: move Vhost-user requests to Vhost-user backend

In reply to Maxime Coquelin

Now that we have a proper isolation of the backends, we can move Vhost-user requests declaration to the Vhost-user backend file.

---
 drivers/net/virtio/virtio_user/vhost.h      | 25 ---------------------
 drivers/net/virtio/virtio_user/vhost_user.c | 25 +++++++++++++++++++++
 2 files changed, 25 insertions(+), 25 deletions(-)
drivers/net/virtio/virtio_user/vhost.h +0 -25
index 6294b8afee..2aa6b2cb70 100644
@@ -63,31 +63,6 @@ struct vhost_vring_addr {
 #define VHOST_USER_PROTOCOL_F_STATUS 16
 #endif
 
-enum vhost_user_request {
-	VHOST_USER_NONE = 0,
-	VHOST_USER_GET_FEATURES = 1,
-	VHOST_USER_SET_FEATURES = 2,
-	VHOST_USER_SET_OWNER = 3,
-	VHOST_USER_RESET_OWNER = 4,
-	VHOST_USER_SET_MEM_TABLE = 5,
-	VHOST_USER_SET_LOG_BASE = 6,
-	VHOST_USER_SET_LOG_FD = 7,
-	VHOST_USER_SET_VRING_NUM = 8,
-	VHOST_USER_SET_VRING_ADDR = 9,
-	VHOST_USER_SET_VRING_BASE = 10,
-	VHOST_USER_GET_VRING_BASE = 11,
-	VHOST_USER_SET_VRING_KICK = 12,
-	VHOST_USER_SET_VRING_CALL = 13,
-	VHOST_USER_SET_VRING_ERR = 14,
-	VHOST_USER_GET_PROTOCOL_FEATURES = 15,
-	VHOST_USER_SET_PROTOCOL_FEATURES = 16,
-	VHOST_USER_GET_QUEUE_NUM = 17,
-	VHOST_USER_SET_VRING_ENABLE = 18,
-	VHOST_USER_SET_STATUS = 39,
-	VHOST_USER_GET_STATUS = 40,
-	VHOST_USER_MAX
-};
-
 #ifndef VHOST_BACKEND_F_IOTLB_MSG_V2
 #define VHOST_BACKEND_F_IOTLB_MSG_V2 1
 #endif
drivers/net/virtio/virtio_user/vhost_user.c +25 -0
index 165cf820b4..ba02fdcb65 100644
@@ -27,6 +27,31 @@ struct vhost_memory {
 	struct vhost_memory_region regions[VHOST_MEMORY_MAX_NREGIONS];
 };
 
+enum vhost_user_request {
+	VHOST_USER_NONE = 0,
+	VHOST_USER_GET_FEATURES = 1,
+	VHOST_USER_SET_FEATURES = 2,
+	VHOST_USER_SET_OWNER = 3,
+	VHOST_USER_RESET_OWNER = 4,
+	VHOST_USER_SET_MEM_TABLE = 5,
+	VHOST_USER_SET_LOG_BASE = 6,
+	VHOST_USER_SET_LOG_FD = 7,
+	VHOST_USER_SET_VRING_NUM = 8,
+	VHOST_USER_SET_VRING_ADDR = 9,
+	VHOST_USER_SET_VRING_BASE = 10,
+	VHOST_USER_GET_VRING_BASE = 11,
+	VHOST_USER_SET_VRING_KICK = 12,
+	VHOST_USER_SET_VRING_CALL = 13,
+	VHOST_USER_SET_VRING_ERR = 14,
+	VHOST_USER_GET_PROTOCOL_FEATURES = 15,
+	VHOST_USER_SET_PROTOCOL_FEATURES = 16,
+	VHOST_USER_GET_QUEUE_NUM = 17,
+	VHOST_USER_SET_VRING_ENABLE = 18,
+	VHOST_USER_SET_STATUS = 39,
+	VHOST_USER_GET_STATUS = 40,
+	VHOST_USER_MAX
+};
+
 struct vhost_user_msg {
 	enum vhost_user_request request;
 
Signature · 1 line
2.29.2
#44 lore raw

PATCH v4 37/44 net/virtio: make server mode blocking

In reply to Maxime Coquelin

This patch makes the Vhost-user backend server mode blocking at init, waiting for the client connection.

The goal is to make the driver more reliable, as without waiting for client connection, the Virtio driver has to assume the Vhost-user backend will support all the features it has advertized, which could lead to undefined behaviour.

For example, without this patch, if the user enables packed ring Virtio feature but the backend does not support it, the ring initialized by the driver will not be compatible with the backend.

---
 drivers/net/virtio/virtio_user/vhost_user.c   |   9 +-
 .../net/virtio/virtio_user/virtio_user_dev.c  | 121 +++++++-----------
 drivers/net/virtio/virtio_user_ethdev.c       |   5 -
 3 files changed, 55 insertions(+), 80 deletions(-)
drivers/net/virtio/virtio_user/vhost_user.c +8 -1
index ba02fdcb65..90fed6fe97 100644
@@ -692,6 +692,14 @@ virtio_user_start_server(struct virtio_user_dev *dev, struct sockaddr_un *un)
 	if (ret < 0)
 		return -1;
 
+	PMD_DRV_LOG(NOTICE, "(%s) waiting for client connection...", dev->path);
+	dev->vhostfd = accept(fd, NULL, NULL);
+	if (dev->vhostfd < 0) {
+		PMD_DRV_LOG(ERR, "Failed to accept initial client connection (%s)",
+				strerror(errno));
+		return -1;
+	}
+
 	flag = fcntl(fd, F_GETFL);
 	if (fcntl(fd, F_SETFL, flag | O_NONBLOCK) < 0) {
 		PMD_DRV_LOG(ERR, "fcntl failed, %s", strerror(errno));
@@ -736,7 +744,6 @@ vhost_user_setup(struct virtio_user_dev *dev)
 			close(fd);
 			return -1;
 		}
-		dev->vhostfd = -1;
 	} else {
 		if (connect(fd, (struct sockaddr *)&un, sizeof(un)) < 0) {
 			PMD_DRV_LOG(ERR, "connect error, %s", strerror(errno));
drivers/net/virtio/virtio_user/virtio_user_dev.c +47 -74

165 lines not on this page · raw message

drivers/net/virtio/virtio_user_ethdev.c +0 -5
index 5e256f4e6d..e822d93690 100644
@@ -174,11 +174,6 @@ virtio_user_delayed_handler(void *param)
 		if (dev->vhostfd >= 0) {
 			close(dev->vhostfd);
 			dev->vhostfd = -1;
-			/* Until the featuers are negotiated again, don't assume
-			 * the backend supports VHOST_USER_PROTOCOL_F_STATUS
-			 */
-			dev->protocol_features &=
-				~(1ULL << VHOST_USER_PROTOCOL_F_STATUS);
 		}
 		eth_dev->intr_handle->fd = dev->listenfd;
 		rte_intr_callback_register(eth_dev->intr_handle,
Signature · 1 line
2.29.2
#45 lore raw

PATCH v4 38/44 net/virtio: move protocol features to Vhost-user

In reply to Maxime Coquelin

Since only protocol features are specific to Vhost-user backend, this patch moves all related code to Vhost-user file.

---
 drivers/net/virtio/virtio_user/vhost.h        | 20 +----
 drivers/net/virtio/virtio_user/vhost_kernel.c |  9 ++
 drivers/net/virtio/virtio_user/vhost_user.c   | 83 +++++++++++++++----
 drivers/net/virtio/virtio_user/vhost_vdpa.c   | 34 +++++++-
 .../net/virtio/virtio_user/virtio_user_dev.c  | 47 ++---------
 drivers/net/virtio/virtio_user_ethdev.c       | 17 ----
 6 files changed, 113 insertions(+), 97 deletions(-)
drivers/net/virtio/virtio_user/vhost.h +1 -19
index 2aa6b2cb70..dfa2735a20 100644
@@ -46,23 +46,6 @@ struct vhost_vring_addr {
 	uint64_t log_guest_addr;
 };
 
-#ifndef VHOST_USER_F_PROTOCOL_FEATURES
-#define VHOST_USER_F_PROTOCOL_FEATURES 30
-#endif
-
-/** Protocol features. */
-#ifndef VHOST_USER_PROTOCOL_F_MQ
-#define VHOST_USER_PROTOCOL_F_MQ 0
-#endif
-
-#ifndef VHOST_USER_PROTOCOL_F_REPLY_ACK
-#define VHOST_USER_PROTOCOL_F_REPLY_ACK 3
-#endif
-
-#ifndef VHOST_USER_PROTOCOL_F_STATUS
-#define VHOST_USER_PROTOCOL_F_STATUS 16
-#endif
-
 #ifndef VHOST_BACKEND_F_IOTLB_MSG_V2
 #define VHOST_BACKEND_F_IOTLB_MSG_V2 1
 #endif
@@ -82,11 +65,10 @@ struct virtio_user_dev;
 
 struct virtio_user_backend_ops {
 	int (*setup)(struct virtio_user_dev *dev);
+	int (*get_backend_features)(uint64_t *features);
 	int (*set_owner)(struct virtio_user_dev *dev);
 	int (*get_features)(struct virtio_user_dev *dev, uint64_t *features);
 	int (*set_features)(struct virtio_user_dev *dev, uint64_t features);
-	int (*get_protocol_features)(struct virtio_user_dev *dev, uint64_t *features);
-	int (*set_protocol_features)(struct virtio_user_dev *dev, uint64_t features);
 	int (*set_memory_table)(struct virtio_user_dev *dev);
 	int (*set_vring_num)(struct virtio_user_dev *dev, struct vhost_vring_state *state);
 	int (*set_vring_base)(struct virtio_user_dev *dev, struct vhost_vring_state *state);
drivers/net/virtio/virtio_user/vhost_kernel.c +9 -0
index 16065c8d11..2047d41a50 100644
@@ -445,8 +445,17 @@ vhost_kernel_enable_queue_pair(struct virtio_user_dev *dev,
 	return 0;
 }
 
+static int
+vhost_kernel_get_backend_features(uint64_t *features)
+{
+	*features = 0;
+
+	return 0;
+}
+
 struct virtio_user_backend_ops virtio_ops_kernel = {
 	.setup = vhost_kernel_setup,
+	.get_backend_features = vhost_kernel_get_backend_features,
 	.set_owner = vhost_kernel_set_owner,
 	.get_features = vhost_kernel_get_features,
 	.set_features = vhost_kernel_set_features,
drivers/net/virtio/virtio_user/vhost_user.c +65 -18

174 lines not on this page · raw message

drivers/net/virtio/virtio_user/vhost_vdpa.c +30 -4
index 7fb1249569..8d354b298e 100644
@@ -13,6 +13,10 @@
 #include "vhost.h"
 #include "virtio_user_dev.h"
 
+#define VHOST_VDPA_SUPPORTED_BACKEND_FEATURES		\
+	(1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2	|	\
+	1ULL << VHOST_BACKEND_F_IOTLB_BATCH)
+
 /* vhost kernel & vdpa ioctls */
 #define VHOST_VIRTIO 0xAF
 #define VHOST_GET_FEATURES _IOR(VHOST_VIRTIO, 0x00, __u64)
@@ -88,13 +92,13 @@ vhost_vdpa_set_owner(struct virtio_user_dev *dev)
 }
 
 static int
-vhost_vdpa_get_backend_features(struct virtio_user_dev *dev, uint64_t *features)
+vhost_vdpa_get_protocol_features(struct virtio_user_dev *dev, uint64_t *features)
 {
 	return vhost_vdpa_ioctl(dev->vhostfd, VHOST_GET_BACKEND_FEATURES, features);
 }
 
 static int
-vhost_vdpa_set_backend_features(struct virtio_user_dev *dev, uint64_t features)
+vhost_vdpa_set_protocol_features(struct virtio_user_dev *dev, uint64_t features)
 {
 	return vhost_vdpa_ioctl(dev->vhostfd, VHOST_SET_BACKEND_FEATURES, &features);
 }
@@ -113,6 +117,21 @@ vhost_vdpa_get_features(struct virtio_user_dev *dev, uint64_t *features)
 	/* Multiqueue not supported for now */
 	*features &= ~(1ULL << VIRTIO_NET_F_MQ);
 
+	/* Negotiated vDPA backend features */
+	ret = vhost_vdpa_get_protocol_features(dev, &dev->protocol_features);
+	if (ret < 0) {
+		PMD_DRV_LOG(ERR, "Failed to get backend features");
+		return -1;
+	}
+
+	dev->protocol_features &= VHOST_VDPA_SUPPORTED_BACKEND_FEATURES;
+
+	ret = vhost_vdpa_set_protocol_features(dev, dev->protocol_features);
+	if (ret < 0) {
+		PMD_DRV_LOG(ERR, "Failed to set backend features");
+		return -1;
+	}
+
 	return 0;
 }
 
@@ -438,13 +457,20 @@ vhost_vdpa_enable_queue_pair(struct virtio_user_dev *dev,
 	return 0;
 }
 
+static int
+vhost_vdpa_get_backend_features(uint64_t *features)
+{
+	*features = 0;
+
+	return 0;
+}
+
 struct virtio_user_backend_ops virtio_ops_vdpa = {
 	.setup = vhost_vdpa_setup,
+	.get_backend_features = vhost_vdpa_get_backend_features,
 	.set_owner = vhost_vdpa_set_owner,
 	.get_features = vhost_vdpa_get_features,
 	.set_features = vhost_vdpa_set_features,
-	.get_protocol_features = vhost_vdpa_get_backend_features,
-	.set_protocol_features = vhost_vdpa_set_backend_features,
 	.set_memory_table = vhost_vdpa_set_memory_table,
 	.set_vring_num = vhost_vdpa_set_vring_num,
 	.set_vring_base = vhost_vdpa_set_vring_base,
drivers/net/virtio/virtio_user/virtio_user_dev.c +8 -39

84 lines not on this page · raw message

drivers/net/virtio/virtio_user_ethdev.c +0 -17
index e822d93690..e2c606a838 100644
@@ -70,7 +70,6 @@ virtio_user_server_reconnect(struct virtio_user_dev *dev)
 	int ret, connectfd, old_status;
 	struct rte_eth_dev *eth_dev = &rte_eth_devices[dev->port_id];
 	struct virtio_hw *hw = &dev->hw;
-	uint64_t protocol_features;
 
 	connectfd = accept(dev->listenfd, NULL, NULL);
 	if (connectfd < 0)
@@ -91,22 +90,6 @@ virtio_user_server_reconnect(struct virtio_user_dev *dev)
 		return -1;
 	}
 
-	if (dev->device_features &
-			(1ULL << VHOST_USER_F_PROTOCOL_FEATURES)) {
-		if (dev->ops->get_protocol_features(dev, &protocol_features))
-			return -1;
-
-		/* Offer VHOST_USER_PROTOCOL_F_STATUS */
-		dev->protocol_features |= (1ULL << VHOST_USER_PROTOCOL_F_STATUS);
-		dev->protocol_features &= protocol_features;
-
-		if (dev->ops->set_protocol_features(dev, dev->protocol_features))
-			return -1;
-
-		if (!(dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_MQ)))
-			dev->unsupported_features |= (1ull << VIRTIO_NET_F_MQ);
-	}
-
 	dev->device_features |= dev->frontend_features;
 
 	/* umask vhost-user unsupported features */
Signature · 1 line
2.29.2
#46 lore raw

PATCH v4 39/44 net/virtio: introduce backend data

In reply to Maxime Coquelin

The goal of this patch is to introduce backend-specific data in order to better isolate what is backend-specific from what is generic to Virtio-user.

For now, only Vhost-user protocol features are moved to Vhost-user backend data.

---
 drivers/net/virtio/virtio_user/vhost.h        |  1 +
 drivers/net/virtio/virtio_user/vhost_kernel.c |  7 +++
 drivers/net/virtio/virtio_user/vhost_user.c   | 62 +++++++++++++++----
 drivers/net/virtio/virtio_user/vhost_vdpa.c   |  7 +++
 .../net/virtio/virtio_user/virtio_user_dev.c  |  2 +
 .../net/virtio/virtio_user/virtio_user_dev.h  |  2 +
 6 files changed, 68 insertions(+), 13 deletions(-)
drivers/net/virtio/virtio_user/vhost.h +1 -0
index dfa2735a20..fc4f059c02 100644
@@ -65,6 +65,7 @@ struct virtio_user_dev;
 
 struct virtio_user_backend_ops {
 	int (*setup)(struct virtio_user_dev *dev);
+	int (*destroy)(struct virtio_user_dev *dev);
 	int (*get_backend_features)(uint64_t *features);
 	int (*set_owner)(struct virtio_user_dev *dev);
 	int (*get_features)(struct virtio_user_dev *dev, uint64_t *features);
drivers/net/virtio/virtio_user/vhost_kernel.c +7 -0
index 2047d41a50..26a71ad07b 100644
@@ -357,6 +357,12 @@ vhost_kernel_setup(struct virtio_user_dev *dev)
 	return 0;
 }
 
+static int
+vhost_kernel_destroy(struct virtio_user_dev *dev __rte_unused)
+{
+	return 0;
+}
+
 static int
 vhost_kernel_set_backend(int vhostfd, int tapfd)
 {
@@ -455,6 +461,7 @@ vhost_kernel_get_backend_features(uint64_t *features)
 
 struct virtio_user_backend_ops virtio_ops_kernel = {
 	.setup = vhost_kernel_setup,
+	.destroy = vhost_kernel_destroy,
 	.get_backend_features = vhost_kernel_get_backend_features,
 	.set_owner = vhost_kernel_set_owner,
 	.get_features = vhost_kernel_get_features,
drivers/net/virtio/virtio_user/vhost_user.c +49 -13

154 lines not on this page · raw message

drivers/net/virtio/virtio_user/vhost_vdpa.c +7 -0
index 8d354b298e..f5a8943993 100644
@@ -432,6 +432,12 @@ vhost_vdpa_setup(struct virtio_user_dev *dev)
 	return 0;
 }
 
+static int
+vhost_vdpa_destroy(struct virtio_user_dev *dev __rte_unused)
+{
+	return 0;
+}
+
 static int
 vhost_vdpa_enable_queue_pair(struct virtio_user_dev *dev,
 			       uint16_t pair_idx,
@@ -467,6 +473,7 @@ vhost_vdpa_get_backend_features(uint64_t *features)
 
 struct virtio_user_backend_ops virtio_ops_vdpa = {
 	.setup = vhost_vdpa_setup,
+	.destroy = vhost_vdpa_destroy,
 	.get_backend_features = vhost_vdpa_get_backend_features,
 	.set_owner = vhost_vdpa_set_owner,
 	.get_features = vhost_vdpa_get_features,
drivers/net/virtio/virtio_user/virtio_user_dev.c +2 -0
index 2614bcb349..215819d46d 100644
@@ -621,6 +621,8 @@ virtio_user_dev_uninit(struct virtio_user_dev *dev)
 
 	if (dev->is_server)
 		unlink(dev->path);
+
+	dev->ops->destroy(dev);
 }
 
 uint8_t
drivers/net/virtio/virtio_user/virtio_user_dev.h +2 -0
index ab62463a5b..7650097b6d 100644
@@ -66,6 +66,8 @@ struct virtio_user_dev {
 	struct virtio_user_backend_ops *ops;
 	pthread_mutex_t	mutex;
 	bool		started;
+
+	void *backend_data;
 };
 
 int virtio_user_dev_set_features(struct virtio_user_dev *dev);
Signature · 1 line
2.29.2
#47 lore raw

PATCH v4 40/44 net/virtio: move Vhost-user specifics to its backend

In reply to Maxime Coquelin

This patch moves all the Vhost-user backend specific logic like Vhost FD, listen FD and interrupt handling to the vhost-user backend implementation.

In order to achieve that, new ops are created to update the link status, disconnect and reconnect the server, and fetch the link state interrupt FD.

---
 drivers/net/virtio/virtio_user/vhost.h        |   4 +
 drivers/net/virtio/virtio_user/vhost_kernel.c |  18 +-
 drivers/net/virtio/virtio_user/vhost_user.c   | 176 ++++++++++++++---
 drivers/net/virtio/virtio_user/vhost_vdpa.c   |  16 ++
 .../net/virtio/virtio_user/virtio_user_dev.c  | 181 +++++++++++++++---
 .../net/virtio/virtio_user/virtio_user_dev.h  |   9 +-
 drivers/net/virtio/virtio_user_ethdev.c       | 179 +----------------
 7 files changed, 350 insertions(+), 233 deletions(-)
drivers/net/virtio/virtio_user/vhost.h +4 -0
index fc4f059c02..c49e88036d 100644
@@ -82,6 +82,10 @@ struct virtio_user_backend_ops {
 	int (*enable_qp)(struct virtio_user_dev *dev, uint16_t pair_idx, int enable);
 	int (*dma_map)(struct virtio_user_dev *dev, void *addr, uint64_t iova, size_t len);
 	int (*dma_unmap)(struct virtio_user_dev *dev, void *addr, uint64_t iova, size_t len);
+	int (*update_link_state)(struct virtio_user_dev *dev);
+	int (*server_disconnect)(struct virtio_user_dev *dev);
+	int (*server_reconnect)(struct virtio_user_dev *dev);
+	int (*get_intr_fd)(struct virtio_user_dev *dev);
 };
 
 extern struct virtio_user_backend_ops virtio_ops_user;
drivers/net/virtio/virtio_user/vhost_kernel.c +17 -1
index 26a71ad07b..0d05e7d339 100644
@@ -459,6 +459,20 @@ vhost_kernel_get_backend_features(uint64_t *features)
 	return 0;
 }
 
+static int
+vhost_kernel_update_link_state(struct virtio_user_dev *dev __rte_unused)
+{
+	/* Nothing to update (Maybe get TAP interface link state?) */
+	return 0;
+}
+
+static int
+vhost_kernel_get_intr_fd(struct virtio_user_dev *dev __rte_unused)
+{
+	/* No link state interrupt with Vhost-kernel */
+	return -1;
+}
+
 struct virtio_user_backend_ops virtio_ops_kernel = {
 	.setup = vhost_kernel_setup,
 	.destroy = vhost_kernel_destroy,
@@ -475,5 +489,7 @@ struct virtio_user_backend_ops virtio_ops_kernel = {
 	.set_vring_addr = vhost_kernel_set_vring_addr,
 	.get_status = vhost_kernel_get_status,
 	.set_status = vhost_kernel_set_status,
-	.enable_qp = vhost_kernel_enable_queue_pair
+	.enable_qp = vhost_kernel_enable_queue_pair,
+	.update_link_state = vhost_kernel_update_link_state,
+	.get_intr_fd = vhost_kernel_get_intr_fd,
 };
drivers/net/virtio/virtio_user/vhost_user.c +149 -27

394 lines not on this page · raw message

drivers/net/virtio/virtio_user/vhost_vdpa.c +16 -0
index f5a8943993..5e3778b682 100644
@@ -471,6 +471,20 @@ vhost_vdpa_get_backend_features(uint64_t *features)
 	return 0;
 }
 
+static int
+vhost_vdpa_update_link_state(struct virtio_user_dev *dev __rte_unused)
+{
+	/* Nothing to update (for now?) */
+	return 0;
+}
+
+static int
+vhost_vdpa_get_intr_fd(struct virtio_user_dev *dev __rte_unused)
+{
+	/* No link state interrupt with Vhost-vDPA */
+	return -1;
+}
+
 struct virtio_user_backend_ops virtio_ops_vdpa = {
 	.setup = vhost_vdpa_setup,
 	.destroy = vhost_vdpa_destroy,
@@ -490,4 +504,6 @@ struct virtio_user_backend_ops virtio_ops_vdpa = {
 	.enable_qp = vhost_vdpa_enable_queue_pair,
 	.dma_map = vhost_vdpa_dma_map_batch,
 	.dma_unmap = vhost_vdpa_dma_unmap_batch,
+	.update_link_state = vhost_vdpa_update_link_state,
+	.get_intr_fd = vhost_vdpa_get_intr_fd,
 };
drivers/net/virtio/virtio_user/virtio_user_dev.c +157 -24

208 lines not on this page · raw message

drivers/net/virtio/virtio_user/virtio_user_dev.h +6 -3
index 7650097b6d..36d2410546 100644
@@ -27,11 +27,11 @@ struct virtio_user_queue {
 struct virtio_user_dev {
 	struct virtio_hw hw;
 	enum virtio_user_backend_type backend_type;
-	/* for vhost_user backend */
-	int		vhostfd;
-	int		listenfd;   /* listening fd */
 	bool		is_server;  /* server or client mode */
 
+	/* for vhost_vdpa backend */
+	int		vhostfd;
+
 	/* for vhost_kernel backend */
 	char		*ifname;
 	int		*vhostfds;
@@ -85,5 +85,8 @@ void virtio_user_handle_cq_packed(struct virtio_user_dev *dev,
 uint8_t virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs);
 int virtio_user_dev_set_status(struct virtio_user_dev *dev, uint8_t status);
 int virtio_user_dev_update_status(struct virtio_user_dev *dev);
+int virtio_user_dev_update_link_state(struct virtio_user_dev *dev);
+void virtio_user_dev_delayed_handler(void *param);
+int virtio_user_dev_server_reconnect(struct virtio_user_dev *dev);
 extern const char * const virtio_user_backend_strings[];
 #endif
drivers/net/virtio/virtio_user_ethdev.c +1 -178

191 lines not on this page · raw message

Signature · 1 line
2.29.2
#48 lore raw

PATCH v4 41/44 net/virtio: move Vhost-kernel data to its backend

In reply to Maxime Coquelin

As done earlier for Vhost-user, this patch moves the Vhost-Kernel specific data to its backend file.

---
 drivers/net/virtio/virtio_user/vhost_kernel.c | 106 +++++++++++++++---
 .../net/virtio/virtio_user/virtio_user_dev.c  |  43 ++-----
 .../net/virtio/virtio_user/virtio_user_dev.h  |   7 +-
 3 files changed, 98 insertions(+), 58 deletions(-)
drivers/net/virtio/virtio_user/vhost_kernel.c +88 -18
index 0d05e7d339..768db55a6c 100644
@@ -14,6 +14,11 @@
 #include "virtio_user_dev.h"
 #include "vhost_kernel_tap.h"
 
+struct vhost_kernel_data {
+	int *vhostfds;
+	int *tapfds;
+};
+
 struct vhost_memory_kernel {
 	uint32_t nregions;
 	uint32_t padding;
@@ -96,7 +101,9 @@ vhost_kernel_ioctl(int fd, uint64_t request, void *arg)
 static int
 vhost_kernel_set_owner(struct virtio_user_dev *dev)
 {
-	return vhost_kernel_ioctl(dev->vhostfds[0], VHOST_SET_OWNER, NULL);
+	struct vhost_kernel_data *data = dev->backend_data;
+
+	return vhost_kernel_ioctl(data->vhostfds[0], VHOST_SET_OWNER, NULL);
 }
 
 static int
@@ -104,8 +111,9 @@ vhost_kernel_get_features(struct virtio_user_dev *dev, uint64_t *features)
 {
 	int ret;
 	unsigned int tap_features;
+	struct vhost_kernel_data *data = dev->backend_data;
 
-	ret = vhost_kernel_ioctl(dev->vhostfds[0], VHOST_GET_FEATURES, features);
+	ret = vhost_kernel_ioctl(data->vhostfds[0], VHOST_GET_FEATURES, features);
 	if (ret < 0) {
 		PMD_DRV_LOG(ERR, "Failed to get features");
 		return -1;
@@ -138,6 +146,8 @@ vhost_kernel_get_features(struct virtio_user_dev *dev, uint64_t *features)
 static int
 vhost_kernel_set_features(struct virtio_user_dev *dev, uint64_t features)
 {
+	struct vhost_kernel_data *data = dev->backend_data;
+
 	/* We don't need memory protection here */
 	features &= ~(1ULL << VIRTIO_F_IOMMU_PLATFORM);
 	/* VHOST kernel does not know about below flags */
@@ -145,7 +155,7 @@ vhost_kernel_set_features(struct virtio_user_dev *dev, uint64_t features)
 	features &= ~VHOST_KERNEL_HOST_OFFLOADS_MASK;
 	features &= ~(1ULL << VIRTIO_NET_F_MQ);
 
-	return vhost_kernel_ioctl(dev->vhostfds[0], VHOST_SET_FEATURES, &features);
+	return vhost_kernel_ioctl(data->vhostfds[0], VHOST_SET_FEATURES, &features);
 }
 
 static int
@@ -185,6 +195,7 @@ add_memseg_list(const struct rte_memseg_list *msl, void *arg)
 static int
 vhost_kernel_set_memory_table(struct virtio_user_dev *dev)
 {
+	struct vhost_kernel_data *data = dev->backend_data;
 	struct vhost_memory_kernel *vm;
 	int ret;
 
@@ -205,7 +216,7 @@ vhost_kernel_set_memory_table(struct virtio_user_dev *dev)
 	if (ret < 0)
 		goto err_free;
 
-	ret = vhost_kernel_ioctl(dev->vhostfds[0], VHOST_SET_MEM_TABLE, vm);
+	ret = vhost_kernel_ioctl(data->vhostfds[0], VHOST_SET_MEM_TABLE, vm);
 	if (ret < 0)
 		goto err_free;
 
@@ -224,9 +235,10 @@ vhost_kernel_set_vring(struct virtio_user_dev *dev, uint64_t req, struct vhost_v
 {
 	int ret, fd;
 	unsigned int index = state->index;
+	struct vhost_kernel_data *data = dev->backend_data;
 
 	/* Convert from queue index to queue-pair & offset */
-	fd = dev->vhostfds[state->index / 2];
+	fd = data->vhostfds[state->index / 2];
 	state->index %= 2;
 
 	ret = vhost_kernel_ioctl(fd, req, state);
@@ -265,9 +277,10 @@ vhost_kernel_set_vring_file(struct virtio_user_dev *dev, uint64_t req,
 {
 	int ret, fd;
 	unsigned int index = file->index;
+	struct vhost_kernel_data *data = dev->backend_data;
 
 	/* Convert from queue index to queue-pair & offset */
-	fd = dev->vhostfds[file->index / 2];
+	fd = data->vhostfds[file->index / 2];
 	file->index %= 2;
 
 	ret = vhost_kernel_ioctl(fd, req, file);
@@ -299,9 +312,10 @@ vhost_kernel_set_vring_addr(struct virtio_user_dev *dev, struct vhost_vring_addr
 {
 	int ret, fd;
 	unsigned int index = addr->index;
+	struct vhost_kernel_data *data = dev->backend_data;
 
 	/* Convert from queue index to queue-pair & offset */
-	fd = dev->vhostfds[addr->index / 2];
+	fd = data->vhostfds[addr->index / 2];
 	addr->index %= 2;
 
 	ret = vhost_kernel_ioctl(fd, VHOST_SET_VRING_ADDR, addr);
@@ -339,27 +353,82 @@ static int
 vhost_kernel_setup(struct virtio_user_dev *dev)
 {
 	int vhostfd;
-	uint32_t i;
+	uint32_t q, i;
+	struct vhost_kernel_data *data;
+
+	data = malloc(sizeof(*data));
+	if (!data) {
+		PMD_INIT_LOG(ERR, "(%s) Failed to allocate Vhost-kernel data", dev->path);
+		return -1;
+	}
+
+	data->vhostfds = malloc(dev->max_queue_pairs * sizeof(int));
+	if (!data->vhostfds) {
+		PMD_INIT_LOG(ERR, "(%s) Failed to allocate Vhost FDs", dev->path);
+		goto err_data;
+	}
+	data->tapfds = malloc(dev->max_queue_pairs * sizeof(int));
+	if (!data->tapfds) {
+		PMD_INIT_LOG(ERR, "(%s) Failed to allocate TAP FDs", dev->path);
+		goto err_vhostfds;
+	}
+
+	for (q = 0; q < dev->max_queue_pairs; ++q) {
+		data->vhostfds[q] = -1;
+		data->tapfds[q] = -1;
+	}
 
 	get_vhost_kernel_max_regions();
 
 	for (i = 0; i < dev->max_queue_pairs; ++i) {
 		vhostfd = open(dev->path, O_RDWR);
 		if (vhostfd < 0) {
-			PMD_DRV_LOG(ERR, "fail to open %s, %s",
-				    dev->path, strerror(errno));
-			return -1;
+			PMD_DRV_LOG(ERR, "fail to open %s, %s", dev->path, strerror(errno));
+			goto err_tapfds;
 		}
 
-		dev->vhostfds[i] = vhostfd;
+		data->vhostfds[i] = vhostfd;
 	}
 
+	dev->backend_data = data;
+
 	return 0;
+
+err_tapfds:
+	for (i = 0; i < dev->max_queue_pairs; i++)
+		if (data->vhostfds[i] >= 0)
+			close(data->vhostfds[i]);
+
+	free(data->tapfds);
+err_vhostfds:
+	free(data->vhostfds);
+err_data:
+	free(data);
+
+	return -1;
 }
 
 static int
-vhost_kernel_destroy(struct virtio_user_dev *dev __rte_unused)
+vhost_kernel_destroy(struct virtio_user_dev *dev)
 {
+	struct vhost_kernel_data *data = dev->backend_data;
+	uint32_t i;
+
+	if (!data)
+		return 0;
+
+	for (i = 0; i < dev->max_queue_pairs; ++i) {
+		if (data->vhostfds[i] >= 0)
+			close(data->vhostfds[i]);
+		if (data->tapfds[i] >= 0)
+			close(data->tapfds[i]);
+	}
+
+	free(data->vhostfds);
+	free(data->tapfds);
+	free(data);
+	dev->backend_data = NULL;
+
 	return 0;
 }
 
@@ -395,14 +464,15 @@ vhost_kernel_enable_queue_pair(struct virtio_user_dev *dev,
 	int vhostfd;
 	int tapfd;
 	int req_mq = (dev->max_queue_pairs > 1);
+	struct vhost_kernel_data *data = dev->backend_data;
 
-	vhostfd = dev->vhostfds[pair_idx];
+	vhostfd = data->vhostfds[pair_idx];
 
 	if (dev->qp_enabled[pair_idx] == enable)
 		return 0;
 
 	if (!enable) {
-		tapfd = dev->tapfds[pair_idx];
+		tapfd = data->tapfds[pair_idx];
 		if (vhost_kernel_set_backend(vhostfd, -1) < 0) {
 			PMD_DRV_LOG(ERR, "fail to set backend for vhost kernel");
 			return -1;
@@ -415,8 +485,8 @@ vhost_kernel_enable_queue_pair(struct virtio_user_dev *dev,
 		return 0;
 	}
 
-	if (dev->tapfds[pair_idx] >= 0) {
-		tapfd = dev->tapfds[pair_idx];
+	if (data->tapfds[pair_idx] >= 0) {
+		tapfd = data->tapfds[pair_idx];
 		if (vhost_kernel_tap_set_offload(tapfd, dev->features) == -1)
 			return -1;
 		if (req_mq && vhost_kernel_tap_set_queue(tapfd, true) < 0) {
@@ -439,7 +509,7 @@ vhost_kernel_enable_queue_pair(struct virtio_user_dev *dev,
 		return -1;
 	}
 
-	dev->tapfds[pair_idx] = tapfd;
+	data->tapfds[pair_idx] = tapfd;
 
 set_backend:
 	if (vhost_kernel_set_backend(vhostfd, tapfd) < 0) {
drivers/net/virtio/virtio_user/virtio_user_dev.c +8 -35

68 lines not on this page · raw message

drivers/net/virtio/virtio_user/virtio_user_dev.h +2 -5
index 36d2410546..36a9cadcad 100644
@@ -32,11 +32,6 @@ struct virtio_user_dev {
 	/* for vhost_vdpa backend */
 	int		vhostfd;
 
-	/* for vhost_kernel backend */
-	char		*ifname;
-	int		*vhostfds;
-	int		*tapfds;
-
 	/* for both vhost_user and vhost_kernel */
 	int		callfds[VIRTIO_MAX_VIRTQUEUES];
 	int		kickfds[VIRTIO_MAX_VIRTQUEUES];
@@ -56,6 +51,8 @@ struct virtio_user_dev {
 	uint16_t	port_id;
 	uint8_t		mac_addr[RTE_ETHER_ADDR_LEN];
 	char		path[PATH_MAX];
+	char		*ifname;
+
 	union {
 		struct vring		vrings[VIRTIO_MAX_VIRTQUEUES];
 		struct vring_packed	packed_vrings[VIRTIO_MAX_VIRTQUEUES];
Signature · 1 line
2.29.2
#49 lore raw

PATCH v4 42/44 net/virtio: move Vhost-vDPA data to its backend

In reply to Maxime Coquelin

As done earlier for Vhost-user and Vhost-kernel, this patch moves the Vhost-vDPA specific data to its backend file.

---
 drivers/net/virtio/virtio_user/vhost_vdpa.c   | 120 +++++++++++++-----
 .../net/virtio/virtio_user/virtio_user_dev.h  |   5 -
 2 files changed, 89 insertions(+), 36 deletions(-)
drivers/net/virtio/virtio_user/vhost_vdpa.c +89 -31
index 5e3778b682..e2d6d3504d 100644
@@ -13,6 +13,11 @@
 #include "vhost.h"
 #include "virtio_user_dev.h"
 
+struct vhost_vdpa_data {
+	int vhostfd;
+	uint64_t protocol_features;
+};
+
 #define VHOST_VDPA_SUPPORTED_BACKEND_FEATURES		\
 	(1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2	|	\
 	1ULL << VHOST_BACKEND_F_IOTLB_BATCH)
@@ -88,27 +93,34 @@ vhost_vdpa_ioctl(int fd, uint64_t request, void *arg)
 static int
 vhost_vdpa_set_owner(struct virtio_user_dev *dev)
 {
-	return vhost_vdpa_ioctl(dev->vhostfd, VHOST_SET_OWNER, NULL);
+	struct vhost_vdpa_data *data = dev->backend_data;
+
+	return vhost_vdpa_ioctl(data->vhostfd, VHOST_SET_OWNER, NULL);
 }
 
 static int
 vhost_vdpa_get_protocol_features(struct virtio_user_dev *dev, uint64_t *features)
 {
-	return vhost_vdpa_ioctl(dev->vhostfd, VHOST_GET_BACKEND_FEATURES, features);
+	struct vhost_vdpa_data *data = dev->backend_data;
+
+	return vhost_vdpa_ioctl(data->vhostfd, VHOST_GET_BACKEND_FEATURES, features);
 }
 
 static int
 vhost_vdpa_set_protocol_features(struct virtio_user_dev *dev, uint64_t features)
 {
-	return vhost_vdpa_ioctl(dev->vhostfd, VHOST_SET_BACKEND_FEATURES, &features);
+	struct vhost_vdpa_data *data = dev->backend_data;
+
+	return vhost_vdpa_ioctl(data->vhostfd, VHOST_SET_BACKEND_FEATURES, &features);
 }
 
 static int
 vhost_vdpa_get_features(struct virtio_user_dev *dev, uint64_t *features)
 {
+	struct vhost_vdpa_data *data = dev->backend_data;
 	int ret;
 
-	ret = vhost_vdpa_ioctl(dev->vhostfd, VHOST_GET_FEATURES, features);
+	ret = vhost_vdpa_ioctl(data->vhostfd, VHOST_GET_FEATURES, features);
 	if (ret) {
 		PMD_DRV_LOG(ERR, "Failed to get features");
 		return -1;
@@ -118,15 +130,15 @@ vhost_vdpa_get_features(struct virtio_user_dev *dev, uint64_t *features)
 	*features &= ~(1ULL << VIRTIO_NET_F_MQ);
 
 	/* Negotiated vDPA backend features */
-	ret = vhost_vdpa_get_protocol_features(dev, &dev->protocol_features);
+	ret = vhost_vdpa_get_protocol_features(dev, &data->protocol_features);
 	if (ret < 0) {
 		PMD_DRV_LOG(ERR, "Failed to get backend features");
 		return -1;
 	}
 
-	dev->protocol_features &= VHOST_VDPA_SUPPORTED_BACKEND_FEATURES;
+	data->protocol_features &= VHOST_VDPA_SUPPORTED_BACKEND_FEATURES;
 
-	ret = vhost_vdpa_set_protocol_features(dev, dev->protocol_features);
+	ret = vhost_vdpa_set_protocol_features(dev, data->protocol_features);
 	if (ret < 0) {
 		PMD_DRV_LOG(ERR, "Failed to set backend features");
 		return -1;
@@ -138,21 +150,24 @@ vhost_vdpa_get_features(struct virtio_user_dev *dev, uint64_t *features)
 static int
 vhost_vdpa_set_features(struct virtio_user_dev *dev, uint64_t features)
 {
+	struct vhost_vdpa_data *data = dev->backend_data;
+
 	/* WORKAROUND */
 	features |= 1ULL << VIRTIO_F_IOMMU_PLATFORM;
 
-	return vhost_vdpa_ioctl(dev->vhostfd, VHOST_SET_FEATURES, &features);
+	return vhost_vdpa_ioctl(data->vhostfd, VHOST_SET_FEATURES, &features);
 }
 
 static int
 vhost_vdpa_iotlb_batch_begin(struct virtio_user_dev *dev)
 {
+	struct vhost_vdpa_data *data = dev->backend_data;
 	struct vhost_msg msg = {};
 
-	if (!(dev->protocol_features & (1ULL << VHOST_BACKEND_F_IOTLB_BATCH)))
+	if (!(data->protocol_features & (1ULL << VHOST_BACKEND_F_IOTLB_BATCH)))
 		return 0;
 
-	if (!(dev->protocol_features & (1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2))) {
+	if (!(data->protocol_features & (1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2))) {
 		PMD_DRV_LOG(ERR, "IOTLB_MSG_V2 not supported by the backend.");
 		return -1;
 	}
@@ -160,7 +175,7 @@ vhost_vdpa_iotlb_batch_begin(struct virtio_user_dev *dev)
 	msg.type = VHOST_IOTLB_MSG_V2;
 	msg.iotlb.type = VHOST_IOTLB_BATCH_BEGIN;
 
-	if (write(dev->vhostfd, &msg, sizeof(msg)) != sizeof(msg)) {
+	if (write(data->vhostfd, &msg, sizeof(msg)) != sizeof(msg)) {
 		PMD_DRV_LOG(ERR, "Failed to send IOTLB batch begin (%s)",
 				strerror(errno));
 		return -1;
@@ -172,12 +187,13 @@ vhost_vdpa_iotlb_batch_begin(struct virtio_user_dev *dev)
 static int
 vhost_vdpa_iotlb_batch_end(struct virtio_user_dev *dev)
 {
+	struct vhost_vdpa_data *data = dev->backend_data;
 	struct vhost_msg msg = {};
 
-	if (!(dev->protocol_features & (1ULL << VHOST_BACKEND_F_IOTLB_BATCH)))
+	if (!(data->protocol_features & (1ULL << VHOST_BACKEND_F_IOTLB_BATCH)))
 		return 0;
 
-	if (!(dev->protocol_features & (1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2))) {
+	if (!(data->protocol_features & (1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2))) {
 		PMD_DRV_LOG(ERR, "IOTLB_MSG_V2 not supported by the backend.");
 		return -1;
 	}
@@ -185,7 +201,7 @@ vhost_vdpa_iotlb_batch_end(struct virtio_user_dev *dev)
 	msg.type = VHOST_IOTLB_MSG_V2;
 	msg.iotlb.type = VHOST_IOTLB_BATCH_END;
 
-	if (write(dev->vhostfd, &msg, sizeof(msg)) != sizeof(msg)) {
+	if (write(data->vhostfd, &msg, sizeof(msg)) != sizeof(msg)) {
 		PMD_DRV_LOG(ERR, "Failed to send IOTLB batch end (%s)",
 				strerror(errno));
 		return -1;
@@ -198,9 +214,10 @@ static int
 vhost_vdpa_dma_map(struct virtio_user_dev *dev, void *addr,
 				  uint64_t iova, size_t len)
 {
+	struct vhost_vdpa_data *data = dev->backend_data;
 	struct vhost_msg msg = {};
 
-	if (!(dev->protocol_features & (1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2))) {
+	if (!(data->protocol_features & (1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2))) {
 		PMD_DRV_LOG(ERR, "IOTLB_MSG_V2 not supported by the backend.");
 		return -1;
 	}
@@ -215,7 +232,7 @@ vhost_vdpa_dma_map(struct virtio_user_dev *dev, void *addr,
 	PMD_DRV_LOG(DEBUG, "%s: iova: 0x%" PRIx64 ", addr: %p, len: 0x%zx",
 			__func__, iova, addr, len);
 
-	if (write(dev->vhostfd, &msg, sizeof(msg)) != sizeof(msg)) {
+	if (write(data->vhostfd, &msg, sizeof(msg)) != sizeof(msg)) {
 		PMD_DRV_LOG(ERR, "Failed to send IOTLB update (%s)",
 				strerror(errno));
 		return -1;
@@ -228,9 +245,10 @@ static int
 vhost_vdpa_dma_unmap(struct virtio_user_dev *dev, __rte_unused void *addr,
 				  uint64_t iova, size_t len)
 {
+	struct vhost_vdpa_data *data = dev->backend_data;
 	struct vhost_msg msg = {};
 
-	if (!(dev->protocol_features & (1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2))) {
+	if (!(data->protocol_features & (1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2))) {
 		PMD_DRV_LOG(ERR, "IOTLB_MSG_V2 not supported by the backend.");
 		return -1;
 	}
@@ -243,7 +261,7 @@ vhost_vdpa_dma_unmap(struct virtio_user_dev *dev, __rte_unused void *addr,
 	PMD_DRV_LOG(DEBUG, "%s: iova: 0x%" PRIx64 ", len: 0x%zx",
 			__func__, iova, len);
 
-	if (write(dev->vhostfd, &msg, sizeof(msg)) != sizeof(msg)) {
+	if (write(data->vhostfd, &msg, sizeof(msg)) != sizeof(msg)) {
 		PMD_DRV_LOG(ERR, "Failed to send IOTLB invalidate (%s)",
 				strerror(errno));
 		return -1;
@@ -353,55 +371,73 @@ vhost_vdpa_set_memory_table(struct virtio_user_dev *dev)
 static int
 vhost_vdpa_set_vring_enable(struct virtio_user_dev *dev, struct vhost_vring_state *state)
 {
-	return vhost_vdpa_ioctl(dev->vhostfd, VHOST_VDPA_SET_VRING_ENABLE, state);
+	struct vhost_vdpa_data *data = dev->backend_data;
+
+	return vhost_vdpa_ioctl(data->vhostfd, VHOST_VDPA_SET_VRING_ENABLE, state);
 }
 
 static int
 vhost_vdpa_set_vring_num(struct virtio_user_dev *dev, struct vhost_vring_state *state)
 {
-	return vhost_vdpa_ioctl(dev->vhostfd, VHOST_SET_VRING_NUM, state);
+	struct vhost_vdpa_data *data = dev->backend_data;
+
+	return vhost_vdpa_ioctl(data->vhostfd, VHOST_SET_VRING_NUM, state);
 }
 
 static int
 vhost_vdpa_set_vring_base(struct virtio_user_dev *dev, struct vhost_vring_state *state)
 {
-	return vhost_vdpa_ioctl(dev->vhostfd, VHOST_SET_VRING_BASE, state);
+	struct vhost_vdpa_data *data = dev->backend_data;
+
+	return vhost_vdpa_ioctl(data->vhostfd, VHOST_SET_VRING_BASE, state);
 }
 
 static int
 vhost_vdpa_get_vring_base(struct virtio_user_dev *dev, struct vhost_vring_state *state)
 {
-	return vhost_vdpa_ioctl(dev->vhostfd, VHOST_GET_VRING_BASE, state);
+	struct vhost_vdpa_data *data = dev->backend_data;
+
+	return vhost_vdpa_ioctl(data->vhostfd, VHOST_GET_VRING_BASE, state);
 }
 
 static int
 vhost_vdpa_set_vring_call(struct virtio_user_dev *dev, struct vhost_vring_file *file)
 {
-	return vhost_vdpa_ioctl(dev->vhostfd, VHOST_SET_VRING_CALL, file);
+	struct vhost_vdpa_data *data = dev->backend_data;
+
+	return vhost_vdpa_ioctl(data->vhostfd, VHOST_SET_VRING_CALL, file);
 }
 
 static int
 vhost_vdpa_set_vring_kick(struct virtio_user_dev *dev, struct vhost_vring_file *file)
 {
-	return vhost_vdpa_ioctl(dev->vhostfd, VHOST_SET_VRING_KICK, file);
+	struct vhost_vdpa_data *data = dev->backend_data;
+
+	return vhost_vdpa_ioctl(data->vhostfd, VHOST_SET_VRING_KICK, file);
 }
 
 static int
 vhost_vdpa_set_vring_addr(struct virtio_user_dev *dev, struct vhost_vring_addr *addr)
 {
-	return vhost_vdpa_ioctl(dev->vhostfd, VHOST_SET_VRING_ADDR, addr);
+	struct vhost_vdpa_data *data = dev->backend_data;
+
+	return vhost_vdpa_ioctl(data->vhostfd, VHOST_SET_VRING_ADDR, addr);
 }
 
 static int
 vhost_vdpa_get_status(struct virtio_user_dev *dev, uint8_t *status)
 {
-	return vhost_vdpa_ioctl(dev->vhostfd, VHOST_VDPA_GET_STATUS, status);
+	struct vhost_vdpa_data *data = dev->backend_data;
+
+	return vhost_vdpa_ioctl(data->vhostfd, VHOST_VDPA_GET_STATUS, status);
 }
 
 static int
 vhost_vdpa_set_status(struct virtio_user_dev *dev, uint8_t status)
 {
-	return vhost_vdpa_ioctl(dev->vhostfd, VHOST_VDPA_SET_STATUS, &status);
+	struct vhost_vdpa_data *data = dev->backend_data;
+
+	return vhost_vdpa_ioctl(data->vhostfd, VHOST_VDPA_SET_STATUS, &status);
 }
 
 /**
@@ -414,27 +450,49 @@ vhost_vdpa_set_status(struct virtio_user_dev *dev, uint8_t status)
 static int
 vhost_vdpa_setup(struct virtio_user_dev *dev)
 {
+	struct vhost_vdpa_data *data;
 	uint32_t did = (uint32_t)-1;
 
-	dev->vhostfd = open(dev->path, O_RDWR);
-	if (dev->vhostfd < 0) {
+	data = malloc(sizeof(*data));
+	if (!data) {
+		PMD_DRV_LOG(ERR, "(%s) Faidle to allocate backend data", dev->path);
+		return -1;
+	}
+
+	data->vhostfd = open(dev->path, O_RDWR);
+	if (data->vhostfd < 0) {
 		PMD_DRV_LOG(ERR, "Failed to open %s: %s\n",
 				dev->path, strerror(errno));
+		free(data);
 		return -1;
 	}
 
-	if (ioctl(dev->vhostfd, VHOST_VDPA_GET_DEVICE_ID, &did) < 0 ||
+	if (ioctl(data->vhostfd, VHOST_VDPA_GET_DEVICE_ID, &did) < 0 ||
 			did != VIRTIO_ID_NETWORK) {
 		PMD_DRV_LOG(ERR, "Invalid vdpa device ID: %u\n", did);
+		close(data->vhostfd);
+		free(data);
 		return -1;
 	}
 
+	dev->backend_data = data;
+
 	return 0;
 }
 
 static int
-vhost_vdpa_destroy(struct virtio_user_dev *dev __rte_unused)
+vhost_vdpa_destroy(struct virtio_user_dev *dev)
 {
+	struct vhost_vdpa_data *data = dev->backend_data;
+
+	if (!data)
+		return 0;
+
+	close(data->vhostfd);
+
+	free(data);
+	dev->backend_data = NULL;
+
 	return 0;
 }
 
drivers/net/virtio/virtio_user/virtio_user_dev.h +0 -5
index 36a9cadcad..8a62f7ea79 100644
@@ -29,10 +29,6 @@ struct virtio_user_dev {
 	enum virtio_user_backend_type backend_type;
 	bool		is_server;  /* server or client mode */
 
-	/* for vhost_vdpa backend */
-	int		vhostfd;
-
-	/* for both vhost_user and vhost_kernel */
 	int		callfds[VIRTIO_MAX_VIRTQUEUES];
 	int		kickfds[VIRTIO_MAX_VIRTQUEUES];
 	int		mac_specified;
@@ -45,7 +41,6 @@ struct virtio_user_dev {
 	uint64_t	device_features; /* supported features by device */
 	uint64_t	frontend_features; /* enabled frontend features */
 	uint64_t	unsupported_features; /* unsupported features mask */
-	uint64_t	protocol_features; /* negotiated protocol features */
 	uint8_t		status;
 	uint16_t	net_status;
 	uint16_t	port_id;
Signature · 1 line
2.29.2
#50 lore raw

PATCH v4 43/44 net/virtio: improve Vhost-user error logging

In reply to Maxime Coquelin

This patch improves error logging in vhost_user_read, especially printing errno when recv() fails.

---
 drivers/net/virtio/virtio_user/vhost_user.c | 31 ++++++++++++---------
 1 file changed, 18 insertions(+), 13 deletions(-)
drivers/net/virtio/virtio_user/vhost_user.c +18 -13
index 088aae3aa3..ec2c53c8fb 100644
@@ -148,38 +148,43 @@ vhost_user_read(int fd, struct vhost_user_msg *msg)
 	int ret, sz_hdr = VHOST_USER_HDR_SIZE, sz_payload;
 
 	ret = recv(fd, (void *)msg, sz_hdr, 0);
-	if (ret < sz_hdr) {
+	if (ret < 0) {
+		PMD_DRV_LOG(ERR, "Failed to recv msg header: %s", strerror(errno));
+		return -1;
+	} else if (ret < sz_hdr) {
 		PMD_DRV_LOG(ERR, "Failed to recv msg hdr: %d instead of %d.",
 			    ret, sz_hdr);
-		goto fail;
+		return -1;
 	}
 
 	/* validate msg flags */
 	if (msg->flags != (valid_flags)) {
-		PMD_DRV_LOG(ERR, "Failed to recv msg: flags %x instead of %x.",
+		PMD_DRV_LOG(ERR, "Failed to recv msg: flags 0x%x instead of 0x%x.",
 			    msg->flags, valid_flags);
-		goto fail;
+		return -1;
 	}
 
 	sz_payload = msg->size;
 
-	if ((size_t)sz_payload > sizeof(msg->payload))
-		goto fail;
+	if ((size_t)sz_payload > sizeof(msg->payload)) {
+		PMD_DRV_LOG(ERR, "Payload size overflow, header says %d but max %zu\n",
+				sz_payload, sizeof(msg->payload));
+		return -1;
+	}
 
 	if (sz_payload) {
 		ret = recv(fd, (void *)((char *)msg + sz_hdr), sz_payload, 0);
-		if (ret < sz_payload) {
-			PMD_DRV_LOG(ERR,
-				"Failed to recv msg payload: %d instead of %d.",
+		if (ret < 0) {
+			PMD_DRV_LOG(ERR, "Failed to recv msg payload: %s", strerror(errno));
+			return -1;
+		} else if (ret < sz_payload) {
+			PMD_DRV_LOG(ERR, "Failed to recv msg payload: %d instead of %u.",
 				ret, msg->size);
-			goto fail;
+			return -1;
 		}
 	}
 
 	return 0;
-
-fail:
-	return -1;
 }
 
 static int
Signature · 1 line
2.29.2
#51 lore raw

PATCH v4 44/44 net/virtio: handle Virtio-user setup failure properly

In reply to Maxime Coquelin

This patch fixes virtio_user_dev_setup() error path, by cleaning all resources it allocates. It introduces virtio_user_dev_uninit_notify() that cleans all open FDs. It implies assigning all FDs to -1 at init time.

With these changes done, virtio_user_dev_init_notify() can be simplified.

---
 .../net/virtio/virtio_user/virtio_user_dev.c  | 70 +++++++++++++------
 1 file changed, 47 insertions(+), 23 deletions(-)
drivers/net/virtio/virtio_user/virtio_user_dev.c +47 -23
index a1e32158bb..2998473622 100644
@@ -283,13 +283,7 @@ virtio_user_dev_init_notify(struct virtio_user_dev *dev)
 	int callfd;
 	int kickfd;
 
-	for (i = 0; i < VIRTIO_MAX_VIRTQUEUES; ++i) {
-		if (i >= dev->max_queue_pairs * 2) {
-			dev->kickfds[i] = -1;
-			dev->callfds[i] = -1;
-			continue;
-		}
-
+	for (i = 0; i < dev->max_queue_pairs * 2; i++) {
 		/* May use invalid flag, but some backend uses kickfd and
 		 * callfd as criteria to judge if dev is alive. so finally we
 		 * use real event_fd.
@@ -297,28 +291,49 @@ virtio_user_dev_init_notify(struct virtio_user_dev *dev)
 		callfd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
 		if (callfd < 0) {
 			PMD_DRV_LOG(ERR, "(%s) callfd error, %s", dev->path, strerror(errno));
-			break;
+			goto err;
 		}
 		kickfd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
 		if (kickfd < 0) {
 			close(callfd);
 			PMD_DRV_LOG(ERR, "(%s) kickfd error, %s", dev->path, strerror(errno));
-			break;
+			goto err;
 		}
 		dev->callfds[i] = callfd;
 		dev->kickfds[i] = kickfd;
 	}
 
-	if (i < VIRTIO_MAX_VIRTQUEUES) {
-		for (j = 0; j < i; ++j) {
-			close(dev->callfds[j]);
+	return 0;
+err:
+	for (j = 0; j < i; j++) {
+		if (dev->kickfds[j] >= 0) {
 			close(dev->kickfds[j]);
+			dev->kickfds[j] = -1;
+		}
+		if (dev->callfds[j] >= 0) {
+			close(dev->callfds[j]);
+			dev->callfds[j] = -1;
 		}
-
-		return -1;
 	}
 
-	return 0;
+	return -1;
+}
+
+static void
+virtio_user_dev_uninit_notify(struct virtio_user_dev *dev)
+{
+	uint32_t i;
+
+	for (i = 0; i < dev->max_queue_pairs; ++i) {
+		if (dev->kickfds[i] >= 0) {
+			close(dev->kickfds[i]);
+			dev->kickfds[i] = -1;
+		}
+		if (dev->callfds[i] >= 0) {
+			close(dev->callfds[i]);
+			dev->callfds[i] = -1;
+		}
+	}
 }
 
 static int
@@ -427,15 +442,22 @@ virtio_user_dev_setup(struct virtio_user_dev *dev)
 
 	if (virtio_user_dev_init_notify(dev) < 0) {
 		PMD_INIT_LOG(ERR, "(%s) Failed to init notifiers\n", dev->path);
-		return -1;
+		goto destroy;
 	}
 
 	if (virtio_user_fill_intr_handle(dev) < 0) {
 		PMD_INIT_LOG(ERR, "(%s) Failed to init interrupt handler\n", dev->path);
-		return -1;
+		goto uninit;
 	}
 
 	return 0;
+
+uninit:
+	virtio_user_dev_uninit_notify(dev);
+destroy:
+	dev->ops->destroy(dev);
+
+	return -1;
 }
 
 /* Use below macro to filter features from vhost backend */
@@ -466,9 +488,16 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
 		     enum virtio_user_backend_type backend_type)
 {
 	uint64_t backend_features;
+	int i;
 
 	pthread_mutex_init(&dev->mutex, NULL);
 	strlcpy(dev->path, path, PATH_MAX);
+
+	for (i = 0; i < VIRTIO_MAX_VIRTQUEUES; i++) {
+		dev->kickfds[i] = -1;
+		dev->callfds[i] = -1;
+	}
+
 	dev->started = 0;
 	dev->max_queue_pairs = queues;
 	dev->queue_pairs = 1; /* mq disabled by default */
@@ -565,16 +594,11 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
 void
 virtio_user_dev_uninit(struct virtio_user_dev *dev)
 {
-	uint32_t i;
-
 	virtio_user_stop_device(dev);
 
 	rte_mem_event_callback_unregister(VIRTIO_USER_MEM_EVENT_CLB_NAME, dev);
 
-	for (i = 0; i < dev->max_queue_pairs * 2; ++i) {
-		close(dev->callfds[i]);
-		close(dev->kickfds[i]);
-	}
+	virtio_user_dev_uninit_notify(dev);
 
 	free(dev->ifname);
 
Signature · 1 line
2.29.2
Reviewed-by on v4 44/44
#52 lore raw

Re: [dpdk-dev] [PATCH v4 44/44] net/virtio: handle Virtio-user setup failure properly

Hi Maxime,

Quoted 81 lines

-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Tuesday, January 26, 2021 6:17 PM
To: [email protected]; Xia, Chenbo <[email protected]>; [email protected]; [email protected]; [email protected]
Cc: Maxime Coquelin <[email protected]>
Subject: [PATCH v4 44/44] net/virtio: handle Virtio-user setup failure properly

This patch fixes virtio_user_dev_setup() error path, by cleaning all resources it allocates. It introduces virtio_user_dev_uninit_notify() that cleans all open FDs. It implies assigning all FDs to -1 at init time.

With these changes done, virtio_user_dev_init_notify() can be simplified.

---
 .../net/virtio/virtio_user/virtio_user_dev.c  | 70 +++++++++++++------
 1 file changed, 47 insertions(+), 23 deletions(-)
drivers/net/virtio/virtio_user/virtio_user_dev.c +12 -14
index a1e32158bb..2998473622 100644
@@ -283,13 +283,7 @@ virtio_user_dev_init_notify(struct virtio_user_dev *dev)
 	int callfd;
 	int kickfd;
 
-	for (i = 0; i < VIRTIO_MAX_VIRTQUEUES; ++i) {
-		if (i >= dev->max_queue_pairs * 2) {
-			dev->kickfds[i] = -1;
-			dev->callfds[i] = -1;
-			continue;
-		}
-
+	for (i = 0; i < dev->max_queue_pairs * 2; i++) {
 		/* May use invalid flag, but some backend uses kickfd and
 		 * callfd as criteria to judge if dev is alive. so finally we
 		 * use real event_fd.
@@ -297,28 +291,49 @@ virtio_user_dev_init_notify(struct virtio_user_dev *dev)
 		callfd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
 		if (callfd < 0) {
 			PMD_DRV_LOG(ERR, "(%s) callfd error, %s", dev->path,
 strerror(errno));
-			break;
+			goto err;
 		}
 		kickfd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
 		if (kickfd < 0) {
 			close(callfd);
 			PMD_DRV_LOG(ERR, "(%s) kickfd error, %s", dev->path,
 strerror(errno));
-			break;
+			goto err;
 		}
 		dev->callfds[i] = callfd;
 		dev->kickfds[i] = kickfd;
 	}
 
-	if (i < VIRTIO_MAX_VIRTQUEUES) {
-		for (j = 0; j < i; ++j) {
-			close(dev->callfds[j]);
+	return 0;
+err:
+	for (j = 0; j < i; j++) {
+		if (dev->kickfds[j] >= 0) {
 			close(dev->kickfds[j]);
+			dev->kickfds[j] = -1;
+		}
+		if (dev->callfds[j] >= 0) {
+			close(dev->callfds[j]);
+			dev->callfds[j] = -1;
 		}
-
-		return -1;
 	}
 

drivers/net/virtio/virtio_user/virtio_user_dev.c virtio_user_dev_init_notify(struct virtio_user_dev *dev) · line 329

Quoted 10 lines
drivers/net/virtio/virtio_user/virtio_user_dev.c +9 -1
-	return 0;
+	return -1;
+}
+
+static void
+virtio_user_dev_uninit_notify(struct virtio_user_dev *dev)
+{
+	uint32_t i;
+
+	for (i = 0; i < dev->max_queue_pairs; ++i) {

Should be 'dev->max_queue_pairs * 2'?

I believe you will fix this in the final version before applying them in the tree.

So with above fixed:

Quoted 77 lines
drivers/net/virtio/virtio_user/virtio_user_dev.c +9 -0
+		if (dev->kickfds[i] >= 0) {
+			close(dev->kickfds[i]);
+			dev->kickfds[i] = -1;
+		}
+		if (dev->callfds[i] >= 0) {
+			close(dev->callfds[i]);
+			dev->callfds[i] = -1;
+		}
+	}
 }

static int

drivers/net/virtio/virtio_user/virtio_user_dev.c +9 -2
@@ -427,15 +442,22 @@ virtio_user_dev_setup(struct virtio_user_dev *dev)
 
 	if (virtio_user_dev_init_notify(dev) < 0) {
 		PMD_INIT_LOG(ERR, "(%s) Failed to init notifiers\n", dev->path);
-		return -1;
+		goto destroy;
 	}
 
 	if (virtio_user_fill_intr_handle(dev) < 0) {
 		PMD_INIT_LOG(ERR, "(%s) Failed to init interrupt handler\n", dev-
 >path);
-		return -1;
+		goto uninit;
 	}
 
 	return 0;
+
+uninit:
+	virtio_user_dev_uninit_notify(dev);
+destroy:
+	dev->ops->destroy(dev);
+
+	return -1;
 }
 

/* Use below macro to filter features from vhost backend */

drivers/net/virtio/virtio_user/virtio_user_dev.c +7 -0
@@ -466,9 +488,16 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char
 *path, int queues,
 		     enum virtio_user_backend_type backend_type)
 {
 	uint64_t backend_features;
+	int i;
 
 	pthread_mutex_init(&dev->mutex, NULL);
 	strlcpy(dev->path, path, PATH_MAX);
+
+	for (i = 0; i < VIRTIO_MAX_VIRTQUEUES; i++) {
+		dev->kickfds[i] = -1;
+		dev->callfds[i] = -1;
+	}
+
 	dev->started = 0;
 	dev->max_queue_pairs = queues;
drivers/net/virtio/virtio_user/virtio_user_dev.c +1 -7
 	dev->queue_pairs = 1; /* mq disabled by default */
@@ -565,16 +594,11 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char
 *path, int queues,
 void
 virtio_user_dev_uninit(struct virtio_user_dev *dev)
 {
-	uint32_t i;
-
 	virtio_user_stop_device(dev);
 
 	rte_mem_event_callback_unregister(VIRTIO_USER_MEM_EVENT_CLB_NAME, dev);
 
-	for (i = 0; i < dev->max_queue_pairs * 2; ++i) {
-		close(dev->callfds[i]);
-		close(dev->kickfds[i]);
-	}
+	virtio_user_dev_uninit_notify(dev);
 
 	free(dev->ifname);
 
--

2.29.2

#53 lore raw

Re: [dpdk-dev] [PATCH v4 44/44] net/virtio: handle Virtio-user setup failure properly

Quoted 83 lines · Chenbo

Hi Maxime,

Quoted 81 lines

-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Tuesday, January 26, 2021 6:17 PM
To: [email protected]; Xia, Chenbo <[email protected]>; [email protected]; [email protected]; [email protected]
Cc: Maxime Coquelin <[email protected]>
Subject: [PATCH v4 44/44] net/virtio: handle Virtio-user setup failure properly

This patch fixes virtio_user_dev_setup() error path, by cleaning all resources it allocates. It introduces virtio_user_dev_uninit_notify() that cleans all open FDs. It implies assigning all FDs to -1 at init time.

With these changes done, virtio_user_dev_init_notify() can be simplified.

---
 .../net/virtio/virtio_user/virtio_user_dev.c  | 70 +++++++++++++------
 1 file changed, 47 insertions(+), 23 deletions(-)
drivers/net/virtio/virtio_user/virtio_user_dev.c +12 -14
index a1e32158bb..2998473622 100644
@@ -283,13 +283,7 @@ virtio_user_dev_init_notify(struct virtio_user_dev *dev)
 	int callfd;
 	int kickfd;
 
-	for (i = 0; i < VIRTIO_MAX_VIRTQUEUES; ++i) {
-		if (i >= dev->max_queue_pairs * 2) {
-			dev->kickfds[i] = -1;
-			dev->callfds[i] = -1;
-			continue;
-		}
-
+	for (i = 0; i < dev->max_queue_pairs * 2; i++) {
 		/* May use invalid flag, but some backend uses kickfd and
 		 * callfd as criteria to judge if dev is alive. so finally we
 		 * use real event_fd.
@@ -297,28 +291,49 @@ virtio_user_dev_init_notify(struct virtio_user_dev *dev)
 		callfd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
 		if (callfd < 0) {
 			PMD_DRV_LOG(ERR, "(%s) callfd error, %s", dev->path,
 strerror(errno));
-			break;
+			goto err;
 		}
 		kickfd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
 		if (kickfd < 0) {
 			close(callfd);
 			PMD_DRV_LOG(ERR, "(%s) kickfd error, %s", dev->path,
 strerror(errno));
-			break;
+			goto err;
 		}
 		dev->callfds[i] = callfd;
 		dev->kickfds[i] = kickfd;
 	}
 
-	if (i < VIRTIO_MAX_VIRTQUEUES) {
-		for (j = 0; j < i; ++j) {
-			close(dev->callfds[j]);
+	return 0;
+err:
+	for (j = 0; j < i; j++) {
+		if (dev->kickfds[j] >= 0) {
 			close(dev->kickfds[j]);
+			dev->kickfds[j] = -1;
+		}
+		if (dev->callfds[j] >= 0) {
+			close(dev->callfds[j]);
+			dev->callfds[j] = -1;
 		}
-
-		return -1;
 	}
 
Quoted 12 lines

drivers/net/virtio/virtio_user/virtio_user_dev.c virtio_user_dev_init_notify(struct virtio_user_dev *dev) · line 327

Quoted 10 lines
drivers/net/virtio/virtio_user/virtio_user_dev.c +9 -1
-	return 0;
+	return -1;
+}
+
+static void
+virtio_user_dev_uninit_notify(struct virtio_user_dev *dev)
+{
+	uint32_t i;
+
+	for (i = 0; i < dev->max_queue_pairs; ++i) {

Should be 'dev->max_queue_pairs * 2'?

Oops, good catch!

Quoted 6 lines

I believe you will fix this in the final version before applying them in the tree.

So with above fixed:

Thanks, I will do the change while applying.

Thanks,
Maxime

Quoted 78 lines
Quoted 77 lines
drivers/net/virtio/virtio_user/virtio_user_dev.c +9 -0
+		if (dev->kickfds[i] >= 0) {
+			close(dev->kickfds[i]);
+			dev->kickfds[i] = -1;
+		}
+		if (dev->callfds[i] >= 0) {
+			close(dev->callfds[i]);
+			dev->callfds[i] = -1;
+		}
+	}
 }

static int

drivers/net/virtio/virtio_user/virtio_user_dev.c +9 -2
@@ -427,15 +442,22 @@ virtio_user_dev_setup(struct virtio_user_dev *dev)
 
 	if (virtio_user_dev_init_notify(dev) < 0) {
 		PMD_INIT_LOG(ERR, "(%s) Failed to init notifiers\n", dev->path);
-		return -1;
+		goto destroy;
 	}
 
 	if (virtio_user_fill_intr_handle(dev) < 0) {
 		PMD_INIT_LOG(ERR, "(%s) Failed to init interrupt handler\n", dev-
 > path);
-		return -1;
+		goto uninit;
 	}
 
 	return 0;
+
+uninit:
+	virtio_user_dev_uninit_notify(dev);
+destroy:
+	dev->ops->destroy(dev);
+
+	return -1;
 }
 

/* Use below macro to filter features from vhost backend */

drivers/net/virtio/virtio_user/virtio_user_dev.c +7 -0
@@ -466,9 +488,16 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char
 *path, int queues,
 		     enum virtio_user_backend_type backend_type)
 {
 	uint64_t backend_features;
+	int i;
 
 	pthread_mutex_init(&dev->mutex, NULL);
 	strlcpy(dev->path, path, PATH_MAX);
+
+	for (i = 0; i < VIRTIO_MAX_VIRTQUEUES; i++) {
+		dev->kickfds[i] = -1;
+		dev->callfds[i] = -1;
+	}
+
 	dev->started = 0;
 	dev->max_queue_pairs = queues;
drivers/net/virtio/virtio_user/virtio_user_dev.c +1 -7
 	dev->queue_pairs = 1; /* mq disabled by default */
@@ -565,16 +594,11 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char
 *path, int queues,
 void
 virtio_user_dev_uninit(struct virtio_user_dev *dev)
 {
-	uint32_t i;
-
 	virtio_user_stop_device(dev);
 
 	rte_mem_event_callback_unregister(VIRTIO_USER_MEM_EVENT_CLB_NAME, dev);
 
-	for (i = 0; i < dev->max_queue_pairs * 2; ++i) {
-		close(dev->callfds[i]);
-		close(dev->kickfds[i]);
-	}
+	virtio_user_dev_uninit_notify(dev);
 
 	free(dev->ifname);
 
--

2.29.2

author Applied
#54 lore raw
In reply to Maxime Coquelin
Quoted 140 lines · Maxime Coquelin

This V3 fixes comments from Chenbo on patch 44 and implements the ABI exception in patch 2.

This series significantly rework Virtio PMD to improve the Virtio-user PMD and its backends integration.

First part of the series removes the dependency of Virtio-user ethdev on Virtio PCI, by creating generic files, adding per-bus meta data, ...

Main (if not single) functionnal change of this first part is to remove the hack for Virtio-user to work in IOVA as PA mode, this hack being very fragile.

Second part of the series reworks Virtio-user internal, by reworking the requests handling so that vDPA and Kernel backends no more hack into being Vhost-user backend. It implies implementing new ops for all the request types. Also, all the backend specific actions are moved from the virtio_user_dev.c and virtio_user_ethdev.c to their backend files.

Only functionnal change in this second part is making the Vhost-user server mode blocking at init time, as long as a client is not connected. The goal of this change is to make the Vhost-user support much more robust, as without blocking, the driver has to assume features that are going to be supported by the client, which is very fragile and error prone. As a side-effect, it also simplifies the logic nin several place of the virtio-user PMD.

Main changes in v4:
- Add ABI exception (David)
- Close FDs only up to max_queue_pairs
- virtio_user_dev_uninit_notify() to return void

Main changes in v3:
- Rename .intr_event to .intr_detect
- Rework last patch, properly clean allocated resources on failure.
- Rebase on top of latest net-next/main
- Minor typo fixes in comments and log improvements

Main changes in v2:
===================
- Introduce vdev driver flag for drivers to require IOVA VA mode
- Rebase on top of -rc1 changes
- Fix regressions introduced in V1 (vhost-kernel broken, vhost-user reconnect...)
- Various minor issues & typos fixed
- Fix status feature issue introduced in v20.11, only reproduceable now that server mode is made blocking
- Improve failure handling in Virtio-user
- Improve logging

Testing coverage (All passed)
=============================
- Virtio-pci PMD
* Virtio PMD in guest with Vhost-user backend in host
* Virtio PMD in guest with Vhost-kernel backend in host
- Virtio-user PMD with Vhost-user backend
* Vhost-user PMD server <-> Virtio-user client PMD IO loopback
* Vhost-user PMD client <-> Virtio-user server PMD IO loopback
* Vhost-user PMD client <-> Virtio-user server PMD reconnect
- Virtio-user PMD with Vhost-kernel backend
* iperf test case
* Txonly testpmd
- Virtio-user PMD with Vhost-vDPA backend
* vdpa-sim (IO loopback)
* CX-6 DX Kernel vDPA (Tx only)

Maxime Coquelin (44):
bus/vdev: add helper to get vdev from ethdev bus/vdev: add driver IOVA VA mode requirement net/virtio: fix getting old status on reconnect net/virtio: introduce Virtio bus type net/virtio: refactor virtio-user device net/virtio: introduce PCI device metadata net/virtio: move PCI device init in dedicated file net/virtio: move PCI specific dev init to PCI ethdev init net/virtio: move MSIX detection to PCI ethdev net/virtio: force IOVA as VA mode for Virtio-user net/virtio: store PCI type in Virtio device metadata net/virtio: add callback for device closing net/virtio: validate features at bus level net/virtio: remove bus type enum
net/virtio: move PCI-specific fields to PCI device net/virtio: pack virtio HW struct
net/virtio: move legacy IO to Virtio PCI net/virtio: introduce generic virtio header net/virtio: move features definition to generic header net/virtio: move virtqueue defines in generic header net/virtio: move config definitions to generic header net/virtio: make interrupt handling more generic net/virtio: move vring alignment to generic header net/virtio: remove last PCI refs in non-PCI code net/virtio: make Vhost-user request sender consistent net/virtio: add Virtio-user ops to set owner net/virtio: add Virtio-user features ops net/virtio: add Virtio-user protocol features ops net/virtio: add Virtio-user memory tables ops net/virtio: add Virtio-user vring setting ops net/virtio: add Virtio-user vring file ops net/virtio: add Virtio-user vring address ops net/virtio: add Virtio-user status ops net/virtio: remove useless request ops net/virtio: improve Virtio-user errors handling net/virtio: move Vhost-user requests to Vhost-user backend net/virtio: make server mode blocking net/virtio: move protocol features to Vhost-user net/virtio: introduce backend data
net/virtio: move Vhost-user specifics to its backend net/virtio: move Vhost-kernel data to its backend net/virtio: move Vhost-vDPA data to its backend net/virtio: improve Vhost-user error logging net/virtio: handle Virtio-user setup failure properly

 devtools/libabigail.abignore                  |   2 +
 drivers/bus/vdev/rte_bus_vdev.h               |   6 +
 drivers/bus/vdev/vdev.c                       |  29 +
 drivers/net/virtio/meson.build                |   6 +-
 drivers/net/virtio/virtio.c                   |  71 ++
 drivers/net/virtio/virtio.h                   | 246 +++++
 drivers/net/virtio/virtio_ethdev.c            | 457 +++------
 drivers/net/virtio/virtio_ethdev.h            |   6 +-
 drivers/net/virtio/virtio_pci.c               | 448 +++++----
 drivers/net/virtio/virtio_pci.h               | 286 +-----
 drivers/net/virtio/virtio_pci_ethdev.c        | 226 +++++
 drivers/net/virtio/virtio_ring.h              |   2 +-
 drivers/net/virtio/virtio_rxtx.c              |  90 +-
 drivers/net/virtio/virtio_rxtx_packed.h       |  10 +-
 drivers/net/virtio/virtio_rxtx_packed_avx.h   |  10 +-
 drivers/net/virtio/virtio_rxtx_packed_neon.h  |  10 +-
 drivers/net/virtio/virtio_rxtx_simple.h       |   3 +-
 drivers/net/virtio/virtio_user/vhost.h        |  79 +-
 drivers/net/virtio/virtio_user/vhost_kernel.c | 461 ++++++---
 .../net/virtio/virtio_user/vhost_kernel_tap.c |  25 +-
 .../net/virtio/virtio_user/vhost_kernel_tap.h |   1 +
 drivers/net/virtio/virtio_user/vhost_user.c   | 898 ++++++++++++++----
 drivers/net/virtio/virtio_user/vhost_vdpa.c   | 323 +++++--
 .../net/virtio/virtio_user/virtio_user_dev.c  | 573 ++++++-----
Quoted 9 lines
 .../net/virtio/virtio_user/virtio_user_dev.h  |  21 +-
 drivers/net/virtio/virtio_user_ethdev.c       | 301 +-----
 drivers/net/virtio/virtqueue.c                |   6 +-
 drivers/net/virtio/virtqueue.h                |  45 +-
 28 files changed, 2742 insertions(+), 1899 deletions(-)
 create mode 100644 drivers/net/virtio/virtio.c
 create mode 100644 drivers/net/virtio/virtio.h
 create mode 100644 drivers/net/virtio/virtio_pci_ethdev.c

Applied to dpdk-next-virtio/main.

Thanks,
Maxime

#55 lore raw
In reply to Maxime Coquelin

Hi Maxime.

We found three virtio issues and bad commit is this patch set. Could you help to take a look?

https://bugs.dpdk.org/show_bug.cgi?id=631
Issue1: vdev_primary_secondary/Virtio_primary_and_secondary_process: start dpdk-symmetric_mp occur core dumped in vm

Issue2: start testpmd occur core dumped in vm when use more than 1 virtio-pmd.

https://bugs.dpdk.org/show_bug.cgi?id=630

issue3: hotplug_mp/attach_detach_virtio_user: The host display is abnormal after dpdk-hotplug_mp exits

BR,
Yinan

Quoted 162 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Maxime Coquelin
Sent: 2021?1?26? 18:16
To: [email protected]; Xia, Chenbo <[email protected]>; [email protected]; [email protected]; [email protected]
Cc: Maxime Coquelin <[email protected]>
Subject: [dpdk-dev] [PATCH v4 00/44] net/virtio: Virtio PMD rework

This V3 fixes comments from Chenbo on patch 44 and implements the ABI exception in patch 2.

This series significantly rework Virtio PMD to improve the Virtio-user PMD and its backends integration.

First part of the series removes the dependency of Virtio-user ethdev on Virtio PCI, by creating generic files, adding per-bus meta data, ...

Main (if not single) functionnal change of this first part is to remove the hack for Virtio-user to work in IOVA as PA mode, this hack being very fragile.

Second part of the series reworks Virtio-user internal, by reworking the requests handling so that vDPA and Kernel backends no more hack into being Vhost-user backend. It implies implementing new ops for all the request types. Also, all the backend specific actions are moved from the virtio_user_dev.c and virtio_user_ethdev.c to their backend files.

Only functionnal change in this second part is making the Vhost-user server mode blocking at init time, as long as a client is not connected. The goal of this change is to make the Vhost-user support much more robust, as without blocking, the driver has to assume features that are going to be supported by the client, which is very fragile and error prone. As a side-effect, it also simplifies the logic nin several place of the virtio-user PMD.

Main changes in v4:
- Add ABI exception (David)
- Close FDs only up to max_queue_pairs
- virtio_user_dev_uninit_notify() to return void

Main changes in v3:
- Rename .intr_event to .intr_detect
- Rework last patch, properly clean allocated resources on failure.
- Rebase on top of latest net-next/main
- Minor typo fixes in comments and log improvements

Main changes in v2:
===================
- Introduce vdev driver flag for drivers to require IOVA VA mode
- Rebase on top of -rc1 changes
- Fix regressions introduced in V1 (vhost-kernel broken, vhost-user reconnect...)
- Various minor issues & typos fixed
- Fix status feature issue introduced in v20.11, only reproduceable now that server
mode is made blocking
- Improve failure handling in Virtio-user
- Improve logging

Testing coverage (All passed)
=============================
- Virtio-pci PMD
* Virtio PMD in guest with Vhost-user backend in host
* Virtio PMD in guest with Vhost-kernel backend in host
- Virtio-user PMD with Vhost-user backend
* Vhost-user PMD server <-> Virtio-user client PMD IO loopback
* Vhost-user PMD client <-> Virtio-user server PMD IO loopback
* Vhost-user PMD client <-> Virtio-user server PMD reconnect
- Virtio-user PMD with Vhost-kernel backend
* iperf test case
* Txonly testpmd
- Virtio-user PMD with Vhost-vDPA backend
* vdpa-sim (IO loopback)
* CX-6 DX Kernel vDPA (Tx only)

Maxime Coquelin (44):
bus/vdev: add helper to get vdev from ethdev bus/vdev: add driver IOVA VA mode requirement net/virtio: fix getting old status on reconnect net/virtio: introduce Virtio bus type net/virtio: refactor virtio-user device net/virtio: introduce PCI device metadata net/virtio: move PCI device init in dedicated file net/virtio: move PCI specific dev init to PCI ethdev init net/virtio: move MSIX detection to PCI ethdev net/virtio: force IOVA as VA mode for Virtio-user net/virtio: store PCI type in Virtio device metadata net/virtio: add callback for device closing net/virtio: validate features at bus level net/virtio: remove bus type enum
net/virtio: move PCI-specific fields to PCI device net/virtio: pack virtio HW struct
net/virtio: move legacy IO to Virtio PCI net/virtio: introduce generic virtio header net/virtio: move features definition to generic header net/virtio: move virtqueue defines in generic header net/virtio: move config definitions to generic header net/virtio: make interrupt handling more generic net/virtio: move vring alignment to generic header net/virtio: remove last PCI refs in non-PCI code net/virtio: make Vhost-user request sender consistent net/virtio: add Virtio-user ops to set owner net/virtio: add Virtio-user features ops net/virtio: add Virtio-user protocol features ops net/virtio: add Virtio-user memory tables ops net/virtio: add Virtio-user vring setting ops net/virtio: add Virtio-user vring file ops net/virtio: add Virtio-user vring address ops net/virtio: add Virtio-user status ops net/virtio: remove useless request ops net/virtio: improve Virtio-user errors handling net/virtio: move Vhost-user requests to Vhost-user backend net/virtio: make server mode blocking net/virtio: move protocol features to Vhost-user net/virtio: introduce backend data
net/virtio: move Vhost-user specifics to its backend net/virtio: move Vhost-kernel data to its backend net/virtio: move Vhost-vDPA data to its backend net/virtio: improve Vhost-user error logging net/virtio: handle Virtio-user setup failure properly

 devtools/libabigail.abignore                  |   2 +
 drivers/bus/vdev/rte_bus_vdev.h               |   6 +
 drivers/bus/vdev/vdev.c                       |  29 +
 drivers/net/virtio/meson.build                |   6 +-
 drivers/net/virtio/virtio.c                   |  71 ++
 drivers/net/virtio/virtio.h                   | 246 +++++
 drivers/net/virtio/virtio_ethdev.c            | 457 +++------
 drivers/net/virtio/virtio_ethdev.h            |   6 +-
 drivers/net/virtio/virtio_pci.c               | 448 +++++----
 drivers/net/virtio/virtio_pci.h               | 286 +-----
 drivers/net/virtio/virtio_pci_ethdev.c        | 226 +++++
 drivers/net/virtio/virtio_ring.h              |   2 +-
 drivers/net/virtio/virtio_rxtx.c              |  90 +-
 drivers/net/virtio/virtio_rxtx_packed.h       |  10 +-
 drivers/net/virtio/virtio_rxtx_packed_avx.h   |  10 +-
 drivers/net/virtio/virtio_rxtx_packed_neon.h  |  10 +-
 drivers/net/virtio/virtio_rxtx_simple.h       |   3 +-
 drivers/net/virtio/virtio_user/vhost.h        |  79 +-
 drivers/net/virtio/virtio_user/vhost_kernel.c | 461 ++++++---
 .../net/virtio/virtio_user/vhost_kernel_tap.c |  25 +-
 .../net/virtio/virtio_user/vhost_kernel_tap.h |   1 +
 drivers/net/virtio/virtio_user/vhost_user.c   | 898 ++++++++++++++----
 drivers/net/virtio/virtio_user/vhost_vdpa.c   | 323 +++++--
 .../net/virtio/virtio_user/virtio_user_dev.c  | 573 ++++++-----
 .../net/virtio/virtio_user/virtio_user_dev.h  |  21 +-
 drivers/net/virtio/virtio_user_ethdev.c       | 301 +-----
 drivers/net/virtio/virtqueue.c                |   6 +-
 drivers/net/virtio/virtqueue.h                |  45 +-
 28 files changed, 2742 insertions(+), 1899 deletions(-)
 create mode 100644 drivers/net/virtio/virtio.c
 create mode 100644 drivers/net/virtio/virtio.h
 create mode 100644 drivers/net/virtio/virtio_pci_ethdev.c

--
2.29.2

#56 lore raw

Hi Yinan,

Quoted 3 lines · Yinan

Hi Maxime.

We found three virtio issues and bad commit is this patch set. Could you help to take a look?

Thanks for the testing and reports.
I'm already working on Bz630, will keep you updated.

Quoted 9 lines

https://bugs.dpdk.org/show_bug.cgi?id=631
Issue1: vdev_primary_secondary/Virtio_primary_and_secondary_process: start dpdk-symmetric_mp occur core dumped in vm

Issue2: start testpmd occur core dumped in vm when use more than 1 virtio-pmd.

https://bugs.dpdk.org/show_bug.cgi?id=630

issue3: hotplug_mp/attach_detach_virtio_user: The host display is abnormal after dpdk-hotplug_mp exits

Thanks,
Maxime

Quoted 165 lines

BR,
Yinan

Quoted 162 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Maxime Coquelin
Sent: 2021?1?26? 18:16
To: [email protected]; Xia, Chenbo <[email protected]>; [email protected]; [email protected]; [email protected]
Cc: Maxime Coquelin <[email protected]>
Subject: [dpdk-dev] [PATCH v4 00/44] net/virtio: Virtio PMD rework

This V3 fixes comments from Chenbo on patch 44 and implements the ABI exception in patch 2.

This series significantly rework Virtio PMD to improve the Virtio-user PMD and its backends integration.

First part of the series removes the dependency of Virtio-user ethdev on Virtio PCI, by creating generic files, adding per-bus meta data, ...

Main (if not single) functionnal change of this first part is to remove the hack for Virtio-user to work in IOVA as PA mode, this hack being very fragile.

Second part of the series reworks Virtio-user internal, by reworking the requests handling so that vDPA and Kernel backends no more hack into being Vhost-user backend. It implies implementing new ops for all the request types. Also, all the backend specific actions are moved from the virtio_user_dev.c and virtio_user_ethdev.c to their backend files.

Only functionnal change in this second part is making the Vhost-user server mode blocking at init time, as long as a client is not connected. The goal of this change is to make the Vhost-user support much more robust, as without blocking, the driver has to assume features that are going to be supported by the client, which is very fragile and error prone. As a side-effect, it also simplifies the logic nin several place of the virtio-user PMD.

Main changes in v4:
- Add ABI exception (David)
- Close FDs only up to max_queue_pairs
- virtio_user_dev_uninit_notify() to return void

Main changes in v3:
- Rename .intr_event to .intr_detect
- Rework last patch, properly clean allocated resources on failure.
- Rebase on top of latest net-next/main
- Minor typo fixes in comments and log improvements

Main changes in v2:
===================
- Introduce vdev driver flag for drivers to require IOVA VA mode
- Rebase on top of -rc1 changes
- Fix regressions introduced in V1 (vhost-kernel broken, vhost-user reconnect...)
- Various minor issues & typos fixed
- Fix status feature issue introduced in v20.11, only reproduceable now that server
mode is made blocking
- Improve failure handling in Virtio-user
- Improve logging

Testing coverage (All passed)
=============================
- Virtio-pci PMD
* Virtio PMD in guest with Vhost-user backend in host
* Virtio PMD in guest with Vhost-kernel backend in host
- Virtio-user PMD with Vhost-user backend
* Vhost-user PMD server <-> Virtio-user client PMD IO loopback
* Vhost-user PMD client <-> Virtio-user server PMD IO loopback
* Vhost-user PMD client <-> Virtio-user server PMD reconnect
- Virtio-user PMD with Vhost-kernel backend
* iperf test case
* Txonly testpmd
- Virtio-user PMD with Vhost-vDPA backend
* vdpa-sim (IO loopback)
* CX-6 DX Kernel vDPA (Tx only)

Maxime Coquelin (44):
bus/vdev: add helper to get vdev from ethdev bus/vdev: add driver IOVA VA mode requirement net/virtio: fix getting old status on reconnect net/virtio: introduce Virtio bus type net/virtio: refactor virtio-user device net/virtio: introduce PCI device metadata net/virtio: move PCI device init in dedicated file net/virtio: move PCI specific dev init to PCI ethdev init net/virtio: move MSIX detection to PCI ethdev net/virtio: force IOVA as VA mode for Virtio-user net/virtio: store PCI type in Virtio device metadata net/virtio: add callback for device closing net/virtio: validate features at bus level net/virtio: remove bus type enum
net/virtio: move PCI-specific fields to PCI device net/virtio: pack virtio HW struct
net/virtio: move legacy IO to Virtio PCI net/virtio: introduce generic virtio header net/virtio: move features definition to generic header net/virtio: move virtqueue defines in generic header net/virtio: move config definitions to generic header net/virtio: make interrupt handling more generic net/virtio: move vring alignment to generic header net/virtio: remove last PCI refs in non-PCI code net/virtio: make Vhost-user request sender consistent net/virtio: add Virtio-user ops to set owner net/virtio: add Virtio-user features ops net/virtio: add Virtio-user protocol features ops net/virtio: add Virtio-user memory tables ops net/virtio: add Virtio-user vring setting ops net/virtio: add Virtio-user vring file ops net/virtio: add Virtio-user vring address ops net/virtio: add Virtio-user status ops net/virtio: remove useless request ops net/virtio: improve Virtio-user errors handling net/virtio: move Vhost-user requests to Vhost-user backend net/virtio: make server mode blocking net/virtio: move protocol features to Vhost-user net/virtio: introduce backend data
net/virtio: move Vhost-user specifics to its backend net/virtio: move Vhost-kernel data to its backend net/virtio: move Vhost-vDPA data to its backend net/virtio: improve Vhost-user error logging net/virtio: handle Virtio-user setup failure properly

 devtools/libabigail.abignore                  |   2 +
 drivers/bus/vdev/rte_bus_vdev.h               |   6 +
 drivers/bus/vdev/vdev.c                       |  29 +
 drivers/net/virtio/meson.build                |   6 +-
 drivers/net/virtio/virtio.c                   |  71 ++
 drivers/net/virtio/virtio.h                   | 246 +++++
 drivers/net/virtio/virtio_ethdev.c            | 457 +++------
 drivers/net/virtio/virtio_ethdev.h            |   6 +-
 drivers/net/virtio/virtio_pci.c               | 448 +++++----
 drivers/net/virtio/virtio_pci.h               | 286 +-----
 drivers/net/virtio/virtio_pci_ethdev.c        | 226 +++++
 drivers/net/virtio/virtio_ring.h              |   2 +-
 drivers/net/virtio/virtio_rxtx.c              |  90 +-
 drivers/net/virtio/virtio_rxtx_packed.h       |  10 +-
 drivers/net/virtio/virtio_rxtx_packed_avx.h   |  10 +-
 drivers/net/virtio/virtio_rxtx_packed_neon.h  |  10 +-
 drivers/net/virtio/virtio_rxtx_simple.h       |   3 +-
 drivers/net/virtio/virtio_user/vhost.h        |  79 +-
 drivers/net/virtio/virtio_user/vhost_kernel.c | 461 ++++++---
 .../net/virtio/virtio_user/vhost_kernel_tap.c |  25 +-
 .../net/virtio/virtio_user/vhost_kernel_tap.h |   1 +
 drivers/net/virtio/virtio_user/vhost_user.c   | 898 ++++++++++++++----
 drivers/net/virtio/virtio_user/vhost_vdpa.c   | 323 +++++--
 .../net/virtio/virtio_user/virtio_user_dev.c  | 573 ++++++-----
 .../net/virtio/virtio_user/virtio_user_dev.h  |  21 +-
 drivers/net/virtio/virtio_user_ethdev.c       | 301 +-----
 drivers/net/virtio/virtqueue.c                |   6 +-
 drivers/net/virtio/virtqueue.h                |  45 +-
 28 files changed, 2742 insertions(+), 1899 deletions(-)
 create mode 100644 drivers/net/virtio/virtio.c
 create mode 100644 drivers/net/virtio/virtio.h
 create mode 100644 drivers/net/virtio/virtio_pci_ethdev.c

--
2.29.2

#57 lore raw
In reply to Maxime Coquelin
Quoted 9 lines · Maxime Coquelin

Only functionnal change in this second part is making the Vhost-user server mode blocking at init time, as long as a client is not connected. The goal of this change is to make the Vhost-user support much more robust, as without blocking, the driver has to assume features that are going to be supported by the client, which is very fragile and error prone. As a side-effect, it also simplifies the logic nin several place of the virtio-user PMD.

Hi, Maxime.

I didn't actually look at the code, but I have a question. Does above text mean that with this change OVS will hang inside driver_register() or similar function until client is connected to dpdkvhostuser (server mode) port?

If so, I think, we will not be able to support server mode in OVS anymore and will have to actually remove it. It's deprecated for a long time now, but I think it might still be in use by some people, especially for virtio-user usecase.

Best regards, Ilya Maximets.

#58 lore raw
CC ovs-dev
Quoted 25 lines · Ilya Maximets
Quoted 9 lines · Maxime Coquelin

Only functionnal change in this second part is making the Vhost-user server mode blocking at init time, as long as a client is not connected. The goal of this change is to make the Vhost-user support much more robust, as without blocking, the driver has to assume features that are going to be supported by the client, which is very fragile and error prone. As a side-effect, it also simplifies the logic nin several place of the virtio-user PMD.

Hi, Maxime.

I didn't actually look at the code, but I have a question. Does above text mean that with this change OVS will hang inside driver_register() or similar function until client is connected to dpdkvhostuser (server mode) port?

If so, I think, we will not be able to support server mode in OVS anymore and will have to actually remove it. It's deprecated for a long time now, but I think it might still be in use by some people, especially for virtio-user usecase.

Best regards, Ilya Maximets.

#59 lore raw

Hi Ilya,

Quoted 25 lines · Ilya Maximets
CC ovs-dev
Quoted 22 lines · Ilya Maximets
Quoted 9 lines · Maxime Coquelin

Only functionnal change in this second part is making the Vhost-user server mode blocking at init time, as long as a client is not connected. The goal of this change is to make the Vhost-user support much more robust, as without blocking, the driver has to assume features that are going to be supported by the client, which is very fragile and error prone. As a side-effect, it also simplifies the logic nin several place of the virtio-user PMD.

Hi, Maxime.

I didn't actually look at the code, but I have a question. Does above text mean that with this change OVS will hang inside driver_register() or similar function until client is connected to dpdkvhostuser (server mode) port?

If so, I think, we will not be able to support server mode in OVS anymore and will have to actually remove it. It's deprecated for a long time now, but I think it might still be in use by some people, especially for virtio-user usecase.

No, there is no impact for OVS. My explanation was maybe a bit confusion, sorry about that.

I meant that Virtio-user PMD, acting as Vhost-user master in server mode, will be blocking waiting for client (OVS dpdkvhostuserclient in your case) connection. This makes the Virtio-user PMD in server mode to behave the same as QEMU Vhost-user port in server mode.

Only noticeable effect on OVS side should be more reliability, as without this change, Virtio-user PMD could assume OVS Vhost-user backend would support features before the connection happens.

Quoted 3 lines
Quoted 2 lines

Best regards, Ilya Maximets.

Regards,
Maxime

#60 lore raw
Quoted 29 lines · Maxime Coquelin

Hi Ilya,

Quoted 25 lines · Ilya Maximets
CC ovs-dev
Quoted 22 lines · Ilya Maximets
Quoted 9 lines · Maxime Coquelin

Only functionnal change in this second part is making the Vhost-user server mode blocking at init time, as long as a client is not connected. The goal of this change is to make the Vhost-user support much more robust, as without blocking, the driver has to assume features that are going to be supported by the client, which is very fragile and error prone. As a side-effect, it also simplifies the logic nin several place of the virtio-user PMD.

Hi, Maxime.

I didn't actually look at the code, but I have a question. Does above text mean that with this change OVS will hang inside driver_register() or similar function until client is connected to dpdkvhostuser (server mode) port?

If so, I think, we will not be able to support server mode in OVS anymore and will have to actually remove it. It's deprecated for a long time now, but I think it might still be in use by some people, especially for virtio-user usecase.

Quoted 7 lines

No, there is no impact for OVS. My explanation was maybe a bit confusion, sorry about that.

I meant that Virtio-user PMD, acting as Vhost-user master in server mode, will be blocking waiting for client (OVS dpdkvhostuserclient in your case) connection. This makes the Virtio-user PMD in server mode to behave the same as QEMU Vhost-user port in server mode.

Oh. OK. So the only affected party is 'net_virtio_user' PMD and vhost library is not affected, right?

And in this case the following command will block OVS:

  ovs-vsctl add-port br0 vu -- set Interface vu type=dpdk \
      options:dpdk-devargs="net_virtio_user,path=vu.sock,server=1"

Is that correct?

(I'm not sure if this works right now, though. I didn't test it.)

Quoted 12 lines

Only noticeable effect on OVS side should be more reliability, as without this change, Virtio-user PMD could assume OVS Vhost-user backend would support features before the connection happens.

Quoted 3 lines
Quoted 2 lines

Best regards, Ilya Maximets.

Regards,
Maxime

#61 lore raw
Quoted 33 lines · Ilya Maximets
Quoted 32 lines · Maxime Coquelin

Hi Ilya,

Quoted 25 lines · Ilya Maximets
CC ovs-dev
Quoted 22 lines · Ilya Maximets
Quoted 9 lines · Maxime Coquelin

Only functionnal change in this second part is making the Vhost-user server mode blocking at init time, as long as a client is not connected. The goal of this change is to make the Vhost-user support much more robust, as without blocking, the driver has to assume features that are going to be supported by the client, which is very fragile and error prone. As a side-effect, it also simplifies the logic nin several place of the virtio-user PMD.

Hi, Maxime.

I didn't actually look at the code, but I have a question. Does above text mean that with this change OVS will hang inside driver_register() or similar function until client is connected to dpdkvhostuser (server mode) port?

If so, I think, we will not be able to support server mode in OVS anymore and will have to actually remove it. It's deprecated for a long time now, but I think it might still be in use by some people, especially for virtio-user usecase.

No, there is no impact for OVS. My explanation was maybe a bit confusion, sorry about that.

Quoted 7 lines
Quoted 4 lines

I meant that Virtio-user PMD, acting as Vhost-user master in server mode, will be blocking waiting for client (OVS dpdkvhostuserclient in your case) connection. This makes the Virtio-user PMD in server mode to behave the same as QEMU Vhost-user port in server mode.

Oh. OK. So the only affected party is 'net_virtio_user' PMD and vhost library is not affected, right?

Right!

Quoted 8 lines

And in this case the following command will block OVS:

  ovs-vsctl add-port br0 vu -- set Interface vu type=dpdk \
      options:dpdk-devargs="net_virtio_user,path=vu.sock,server=1"

Is that correct?

(I'm not sure if this works right now, though. I didn't test it.)

This is correct, even though I don't know a use-case for it (chained OVS-DPDK?).

Thanks,
Maxime

Quoted 14 lines
Quoted 13 lines

Only noticeable effect on OVS side should be more reliability, as without this change, Virtio-user PMD could assume OVS Vhost-user backend would support features before the connection happens.

Quoted 3 lines
Quoted 2 lines

Best regards, Ilya Maximets.

Regards,
Maxime