vfio: Reset vfio_container in detaching last group #17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If application follows the calling sequence, it fails in getting device fd as the following logs, Assumming that there's only one vfio group and container with a single device attached.
nvme_ctrl_init (e.g., unvme add )
nvme_close (e.g., unvme del )
nvme_ctrl_init
I nvme_pci_init (src/nvme/core.c:510): nvme/core: pci class code is 0x010802
I vfio_get_device_fd (src/iommu/vfio.c:430): iommu/vfio: vfio iommu group is /dev/vfio/5
I vfio_group_set_container (src/iommu/vfio.c:290): iommu/vfio: adding group '/dev/vfio/5' to container
D vfio_get_device_fd (src/iommu/vfio.c:438): iommu/vfio: failed to get device fd
D vfio_pci_open (src/vfio/pci.c:151): vfio/pci: failed to get device fd
This is because kernel removes
container->iommu_driver
by setting it to NULL if this is the last vfio group to be detached from the current container. This will fail in the following vfio kernel code:int vfio_group_use_container(struct vfio_group *group) {
lockdep_assert_held(&group->group_lock);
VFIO_SET_IOMMU ioctl is required to re-initailize
container->iommu
instance. But, currentlibvfn
is skipping vfio_iommu_type1_init in case vfio->iommu_set is set.This patch resets the vfio_container instance when the last vfio group is detached from the current container just like kernel does.