net/virtio: fix crash when configured twice

When first attempt to configure a device with RX interrupt enabled fails
for some reason (e.g. because "Multiple intr vector not supported"),
second attempt to configure the device with RX interrupt disabled and
feature set unchanged will succeed but will leave virtio queues not
allocated. Accessing the queues will cause a segfault.

First attempt:
  - virtio_dev_configure()
    - virtio_init_device() is called to reinit the device because
      "dev->data->dev_conf.intr_conf.rxq" is "1"
      - virtio_configure_intr() fails and returns an error
      - virtio_free_queues() frees previously allocated virtio queues
    - virtio_init_device() fails and returns an error
  - virtio_dev_configure() fails and returns an error

Second attempt:
  - virtio_dev_configure()
    - This time virtio_init_device() is not called, virtio queues
      are not allocated

With this fix, reinit the device during configuration if virtio queues
are not allocated.

Fixes: 2b38151f74 ("net/virtio: fix queue memory leak on error")
Cc: stable@dpdk.org

Signed-off-by: Alexander Chernavin <achernavin@netgate.com>
Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
This commit is contained in:
Alexander Chernavin 2022-09-27 10:15:04 +00:00 committed by Chenbo Xia
parent 5b546fa718
commit 52bd03e969

View File

@ -2617,6 +2617,13 @@ virtio_dev_configure(struct rte_eth_dev *dev)
return ret;
}
/* if queues are not allocated, reinit the device */
if (hw->vqs == NULL) {
ret = virtio_init_device(dev, hw->req_guest_features);
if (ret < 0)
return ret;
}
if ((rxmode->mq_mode & RTE_ETH_MQ_RX_RSS_FLAG) &&
!virtio_with_feature(hw, VIRTIO_NET_F_RSS)) {
PMD_DRV_LOG(ERR, "RSS support requested but not supported by the device");