ethdev: fix secondary process crash on unused virtio
authorJianfeng Tan <jianfeng.tan@intel.com>
Mon, 3 Jul 2017 06:37:31 +0000 (06:37 +0000)
committerThomas Monjalon <thomas@monjalon.net>
Wed, 5 Jul 2017 10:10:40 +0000 (12:10 +0200)
commita33c81e38cebfe3fdbefb218c921f11ea1e7c8ad
treed1b055b08f9defe064938a4d90d6ba6cab9851be
parentad10c178210e11bfa468f7f5ecca597644d2eb34
ethdev: fix secondary process crash on unused virtio

Suppose we have 2 virtio devices for a VM, with only the first one,
virtio0, binding to igb_uio. Start a primary DPDK process, driving
only virtio0. Then start a secondary DPDK process, it encounters
segfault at eth_virtio_dev_init() because hw is NULL, when trying
to initialize the 2nd virtio devices.
    1539                    if (!hw->virtio_user_dev) {

We could add a precheck to return error when hw is NULL. But the
root cause is that virtio devices which are not driven by the primary
process are not exluded by secondary eal probe function.

To support legacy virtio devices bound to none kernel driver, we
removed RTE_PCI_DRV_NEED_MAPPING in
commit 962cf902e6eb ("pci: export device mapping functions").
At the boot of primary process, ether dev is allocated in rte_eth_devices
array, rte_eth_dev_data is also allocated in rte_eth_dev_data array; then
probe function fails; and ether dev is released. However, the entry in
rte_eth_dev_data array is not cleared. Then we start secondary process,
and try to attach the virtio device that not used in primary process,
the field, dev_private (or hw), in rte_eth_dev_data, is NULL.

To fail the dev attach, we need to clear the field, name, when we
release any ether devices in primary, so that below loop in
rte_eth_dev_attach_secondary() will not find any matched names.
        for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
                if (strcmp(rte_eth_dev_data[i].name, name) == 0)
                        break;
        }

Fixes: 6d890f8ab512 ("net/virtio: fix multiple process support")
Cc: stable@dpdk.org
Reported-by: Reshma Pattan <reshma.pattan@intel.com>
Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
lib/librte_ether/rte_ethdev_pci.h