[dpdk-dev] [PATCH] net/virtio: fix Virtio-PCI ops assignment

Maxime Coquelin maxime.coquelin at redhat.com
Mon Feb 1 16:16:30 CET 2021

VIRTIO_OPS() macro relies on the port ID stored in the
virtio_hw struct. Issue is that it is used before being
assigned at init time. It results in all devices setting
ops on port ID 0, causing crash later when calling ops
for port IDs other than 0.

This patch ensure port ID assignment is done before being

Bugzilla ID: 631
Fixes: 512e27eeb743 ("net/virtio: move PCI specific dev init to PCI ethdev init")

Reported-by: Wei Ling <weix.ling at intel.com>
Signed-off-by: Maxime Coquelin <maxime.coquelin at redhat.com>
 drivers/net/virtio/virtio_pci_ethdev.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/virtio/virtio_pci_ethdev.c b/drivers/net/virtio/virtio_pci_ethdev.c
index 1b818c4565..547cb8ffa0 100644
--- a/drivers/net/virtio/virtio_pci_ethdev.c
+++ b/drivers/net/virtio/virtio_pci_ethdev.c
@@ -76,6 +76,9 @@ 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;
+	/* Required to assign Virtio ops */
+	hw->port_id = eth_dev->data->port_id;
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
 		ret = vtpci_init(RTE_ETH_DEV_TO_PCI(eth_dev), dev);
 		if (ret) {

More information about the dev mailing list