Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

vfio: Don't overreact to DEL_DEVICE

BUS_NOTIFY_DEL_DEVICE triggers IOMMU drivers to remove devices from
their iommu group, but there's really nothing we can do about it at
this point. If the device is in use, then the vfio sub-driver will
block the device_del from completing until it's released. If the
device is not in use or not owned by a vfio sub-driver, then we
really don't care that it's being removed.

The current code can be triggered just by unloading an sr-iov driver
(ex. igb) while the VFs are attached to vfio-pci because it makes an
incorrect assumption about the ordering of driver remove callbacks
vs the DEL_DEVICE notification.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

+7 -22
+7 -22
drivers/vfio/vfio.c
··· 494 494 return 0; 495 495 } 496 496 497 - static int vfio_group_nb_del_dev(struct vfio_group *group, struct device *dev) 498 - { 499 - struct vfio_device *device; 500 - 501 - /* 502 - * Expect to fall out here. If a device was in use, it would 503 - * have been bound to a vfio sub-driver, which would have blocked 504 - * in .remove at vfio_del_group_dev. Sanity check that we no 505 - * longer track the device, so it's safe to remove. 506 - */ 507 - device = vfio_group_get_device(group, dev); 508 - if (likely(!device)) 509 - return 0; 510 - 511 - WARN("Device %s removed from live group %d!\n", dev_name(dev), 512 - iommu_group_id(group->iommu_group)); 513 - 514 - vfio_device_put(device); 515 - return 0; 516 - } 517 - 518 497 static int vfio_group_nb_verify(struct vfio_group *group, struct device *dev) 519 498 { 520 499 /* We don't care what happens when the group isn't in use */ ··· 524 545 vfio_group_nb_add_dev(group, dev); 525 546 break; 526 547 case IOMMU_GROUP_NOTIFY_DEL_DEVICE: 527 - vfio_group_nb_del_dev(group, dev); 548 + /* 549 + * Nothing to do here. If the device is in use, then the 550 + * vfio sub-driver should block the remove callback until 551 + * it is unused. If the device is unused or attached to a 552 + * stub driver, then it should be released and we don't 553 + * care that it will be going away. 554 + */ 528 555 break; 529 556 case IOMMU_GROUP_NOTIFY_BIND_DRIVER: 530 557 pr_debug("%s: Device %s, group %d binding to driver\n",