Skip to contentSkip to conversation

net/virtio: fix Virtio-PCI ops assignment

PATCH Superseded Maxime Coquelin 2 participants 3 messages Feb 1, 2021 Network drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/virtio: fix Virtio-PCI ops assignment

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 used.

Bugzilla ID: 631

Fixes 512e27eeb743 ("net/virtio: move PCI specific dev init to PCI ethdev init")
---
 drivers/net/virtio/virtio_pci_ethdev.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/virtio/virtio_pci_ethdev.c +3 -0
index 1b818c4565..547cb8ffa0 100644
@@ -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) {
Signature · 1 line
2.29.2
#1 lore raw
Quoted 24 lines · Maxime Coquelin

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 used.

Bugzilla ID: 631

Fixes 512e27eeb743 ("net/virtio: move PCI specific dev init to PCI ethdev init")
---
 drivers/net/virtio/virtio_pci_ethdev.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/virtio/virtio_pci_ethdev.c +0 -0
index 1b818c4565..547cb8ffa0 100644

drivers/net/virtio/virtio_pci_ethdev.c eth_virtio_pci_init(struct rte_eth_dev *eth_dev) · line 84

Quoted 9 lines
drivers/net/virtio/virtio_pci_ethdev.c +3 -0
@@ -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) {

We probably don't need to set hw->port-id in eth_virtio_dev_init anymore. And I would only set it in the primary process context, letting the secondary pick what has been chosen by the primary?

Signature · 1 line
David Marchand
#2 lore raw
Quoted 29 lines · David Marchand
Quoted 27 lines · Maxime Coquelin

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 used.

Bugzilla ID: 631

Fixes 512e27eeb743 ("net/virtio: move PCI specific dev init to PCI ethdev init")
---
 drivers/net/virtio/virtio_pci_ethdev.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/virtio/virtio_pci_ethdev.c +0 -0
index 1b818c4565..547cb8ffa0 100644
@@ -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;
 
Quoted 12 lines

drivers/net/virtio/virtio_pci_ethdev.c eth_virtio_pci_init(struct rte_eth_dev *eth_dev) · line 84

Quoted 6 lines
drivers/net/virtio/virtio_pci_ethdev.c +3 -0
+       /* 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) {

We probably don't need to set hw->port-id in eth_virtio_dev_init anymore. And I would only set it in the primary process context, letting the secondary pick what has been chosen by the primary?

I agree, I will remove the second assignment and also move this one only for primary process.

Thanks,
Maxime