Skip to content

Commit

Permalink
net/vhost: fix deadlock on vring state change
Browse files Browse the repository at this point in the history
[ upstream commit 193edd75a94fe8d0d633d1702109779fd7b7d6a0 ]

If vring state changes after pmd starts working, the locked vring
notifies pmd, thus calling update_queuing_status(), the latter
will wait for pmd to finish accessing vring, while pmd is also
waiting for vring to be unlocked, thus causing deadlock.

Actually, update_queuing_status() only needs to wait while
destroy/stopping the device, but not in other cases.

This patch adds a flag for whether or not to wait to fix this issue.

Fixes: 1ce3c7f ("net/vhost: emulate device start/stop behavior")

Signed-off-by: Yuan Wang <yuanx.wang@intel.com>
Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
  • Loading branch information
yuanx-wang authored and cpaelzer committed Jul 7, 2022
1 parent 288097d commit 48e451f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions drivers/net/vhost/rte_eth_vhost.c
Expand Up @@ -652,7 +652,7 @@ eth_vhost_install_intr(struct rte_eth_dev *dev)
}

static void
update_queuing_status(struct rte_eth_dev *dev)
update_queuing_status(struct rte_eth_dev *dev, bool wait_queuing)
{
struct pmd_internal *internal = dev->data->dev_private;
struct vhost_queue *vq;
Expand All @@ -678,7 +678,7 @@ update_queuing_status(struct rte_eth_dev *dev)
rte_atomic32_set(&vq->allow_queuing, 1);
else
rte_atomic32_set(&vq->allow_queuing, 0);
while (rte_atomic32_read(&vq->while_queuing))
while (wait_queuing && rte_atomic32_read(&vq->while_queuing))
rte_pause();
}

Expand All @@ -690,7 +690,7 @@ update_queuing_status(struct rte_eth_dev *dev)
rte_atomic32_set(&vq->allow_queuing, 1);
else
rte_atomic32_set(&vq->allow_queuing, 0);
while (rte_atomic32_read(&vq->while_queuing))
while (wait_queuing && rte_atomic32_read(&vq->while_queuing))
rte_pause();
}
}
Expand Down Expand Up @@ -772,7 +772,7 @@ new_device(int vid)
eth_dev->data->dev_link.link_status = ETH_LINK_UP;

rte_atomic32_set(&internal->dev_attached, 1);
update_queuing_status(eth_dev);
update_queuing_status(eth_dev, false);

VHOST_LOG(INFO, "Vhost device %d created\n", vid);

Expand Down Expand Up @@ -802,7 +802,7 @@ destroy_device(int vid)
internal = eth_dev->data->dev_private;

rte_atomic32_set(&internal->dev_attached, 0);
update_queuing_status(eth_dev);
update_queuing_status(eth_dev, true);

eth_dev->data->dev_link.link_status = ETH_LINK_DOWN;

Expand Down Expand Up @@ -863,7 +863,7 @@ vring_state_changed(int vid, uint16_t vring, int enable)
state->max_vring = RTE_MAX(vring, state->max_vring);
rte_spinlock_unlock(&state->lock);

update_queuing_status(eth_dev);
update_queuing_status(eth_dev, false);

VHOST_LOG(INFO, "vring%u is %s\n",
vring, enable ? "enabled" : "disabled");
Expand Down Expand Up @@ -1050,7 +1050,7 @@ eth_dev_start(struct rte_eth_dev *eth_dev)
}

rte_atomic32_set(&internal->started, 1);
update_queuing_status(eth_dev);
update_queuing_status(eth_dev, false);

return 0;
}
Expand All @@ -1061,7 +1061,7 @@ eth_dev_stop(struct rte_eth_dev *dev)
struct pmd_internal *internal = dev->data->dev_private;

rte_atomic32_set(&internal->started, 0);
update_queuing_status(dev);
update_queuing_status(dev, true);
}

static void
Expand Down

0 comments on commit 48e451f

Please sign in to comment.