[dpdk-dev,v2] virtio: fix crash loading virtio driver when devargs isn't specified

Message ID 1465829588-118146-1-git-send-email-huawei.xie@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Yuanhan Liu
Headers

Commit Message

Huawei Xie June 13, 2016, 2:53 p.m. UTC
  We skip kernel managed virtio devices, if it isn't whitelisted.
Before checking if the virtio device is whitelisted, check if devargs is
specified.

Fixes: ac5e1d838dc1 ("virtio: skip error when probing kernel managed device")

Signed-off-by: Huawei Xie <huawei.xie@intel.com>
Reported-by: Vincent Li <vincent.mc.li@gmail.com>
---
v2: - add reported-by
    - reword subject
    - reword commit message
---
 drivers/net/virtio/virtio_pci.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
  

Comments

Yuanhan Liu June 14, 2016, 1:19 p.m. UTC | #1
On Mon, Jun 13, 2016 at 10:53:08PM +0800, Huawei Xie wrote:
> We skip kernel managed virtio devices, if it isn't whitelisted.
> Before checking if the virtio device is whitelisted, check if devargs is
> specified.
> 
> Fixes: ac5e1d838dc1 ("virtio: skip error when probing kernel managed device")
> 
> Signed-off-by: Huawei Xie <huawei.xie@intel.com>
> Reported-by: Vincent Li <vincent.mc.li@gmail.com>

Applied to dpdk-next-virtio, with above two order changed and summary
shortened.

Thanks.

	--yliu
  

Patch

diff --git a/drivers/net/virtio/virtio_pci.c b/drivers/net/virtio/virtio_pci.c
index d0f2428..60ec4da 100644
--- a/drivers/net/virtio/virtio_pci.c
+++ b/drivers/net/virtio/virtio_pci.c
@@ -626,6 +626,7 @@  next:
  * Return -1:
  *   if there is error mapping with VFIO/UIO.
  *   if port map error when driver type is KDRV_NONE.
+ *   if whitelisted but driver type is KDRV_UNKNOWN.
  * Return 1 if kernel driver is managing the device.
  * Return 0 on success.
  */
@@ -651,7 +652,8 @@  vtpci_init(struct rte_pci_device *dev, struct virtio_hw *hw,
 	PMD_INIT_LOG(INFO, "trying with legacy virtio pci.");
 	if (legacy_virtio_resource_init(dev, hw, dev_flags) < 0) {
 		if (dev->kdrv == RTE_KDRV_UNKNOWN &&
-		    dev->devargs->type != RTE_DEVTYPE_WHITELISTED_PCI) {
+		    (!dev->devargs ||
+		     dev->devargs->type != RTE_DEVTYPE_WHITELISTED_PCI)) {
 			PMD_INIT_LOG(INFO,
 				"skip kernel managed virtio device.");
 			return 1;