Skip to contentSkip to conversation

RDMA/vmw_pvrdma: Correctly set and check device ib_active status

PATCH In review Vishnu Dasa 2 participants 2 messages Sep 18, 2020 – Sep 21, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RDMA/vmw_pvrdma: Correctly set and check device ib_active status

Avoid calling ib_dispatch_event on an inactive device in order to prevent writing to invalid I/O mapped addresses which could cause a guest crash.

Also, set the ib_active status to 'false' in pvrdma_pci_remove and in the failure path of pvrdma_pci_probe.

Fixes 29c8d9eba550 ("IB: Add vmw_pvrdma driver")
---
 drivers/infiniband/hw/vmw_pvrdma/pvrdma_main.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/infiniband/hw/vmw_pvrdma/pvrdma_main.c +12 -0
index 780fd2dfc07e..ff4fd6e078e7 100644
@@ -692,6 +692,16 @@ static void pvrdma_netdevice_event_handle(struct pvrdma_dev *dev,
 	struct pci_dev *pdev_net;
 	unsigned int slot;
 
+	/*
+	 * Do not dispatch events if the device is inactive.  Otherwise
+	 * we'll try to ib_dispatch_event() on an invalid device.
+	 */
+	if (!dev->ib_active) {
+		dev_dbg(&dev->pdev->dev, "ignore netdev event %ld on %s\n",
+			event, dev->ib_dev.name);
+		return;
+	}
+
 	switch (event) {
 	case NETDEV_REBOOT:
 	case NETDEV_DOWN:
@@ -1049,6 +1059,7 @@ static int pvrdma_pci_probe(struct pci_dev *pdev,
 	return 0;
 
 err_unreg_ibdev:
+	dev->ib_active = false;
 	ib_unregister_device(&dev->ib_dev);
 err_disable_intr:
 	pvrdma_disable_intrs(dev);
@@ -1108,6 +1119,7 @@ static void pvrdma_pci_remove(struct pci_dev *pdev)
 	}
 
 	/* Unregister ib device */
+	dev->ib_active = false;
 	ib_unregister_device(&dev->ib_dev);
 
 	mutex_lock(&pvrdma_device_list_lock);
Signature · 1 line
2.18.4
maintainer
#1 lore raw
Quoted 7 lines · Vishnu Dasa

Avoid calling ib_dispatch_event on an inactive device in order to prevent writing to invalid I/O mapped addresses which could cause a guest crash.

Also, set the ib_active status to 'false' in pvrdma_pci_remove and in the failure path of pvrdma_pci_probe.

Quoted 6 lines
Fixes 29c8d9eba550 ("IB: Add vmw_pvrdma driver")
---
 drivers/infiniband/hw/vmw_pvrdma/pvrdma_main.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

To fix this bug you need to change pvrdma_netdevice_event to use ib_device_get_by_netdev() instead of the pvrdma_device_list global

And then use ib_device_put in the pvrdma_netdevice_event_work() once the pointer is no longer needed.

The core code handles all the required locking

Jason