vfio/spapr/nvlink2: Skip unpinning pages on error exit
Subsystems (2)
PATCH 1/1 vfio/spapr/nvlink2: Skip unpinning pages on error exit
The nvlink2 subdriver for IBM Witherspoon machines preregisters GPU memory in the IOMMI API so KVM TCE code can map this memory for DMA as well. This is done by mm_iommu_newdev() called from vfio_pci_nvgpu_regops::mmap.
In an unlikely event of failure the data->mem remains NULL and since mm_iommu_put() (which unregisters the region and unpins memory if that was regular memory) does not expect mem=NULL, it should not be called.
This adds a check to only call mm_iommu_put() for a valid data->mem.
--- drivers/vfio/pci/vfio_pci_nvlink2.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/vfio/pci/vfio_pci_nvlink2.c +4 -2
@@ -97,8 +97,10 @@ static void vfio_pci_nvgpu_release(struct vfio_pci_device *vdev,/* If there were any mappings at all... */ if (data->mm) { - ret =mm_iommu_put (data->mm, data->mem); -WARN_ON (ret); +if (data->mem) { + ret =mm_iommu_put (data->mm, data->mem); +WARN_ON (ret); + }mmdrop (data->mm); }
Signature · 1 line
2.17.1
Alex Williamson
AppliedQuoted 25 lines · On Mon, 23 Dec 2019 12:09:27 +1100 Alexey Kardashevskiy <[email protected]> wrote:
The nvlink2 subdriver for IBM Witherspoon machines preregisters GPU memory in the IOMMI API so KVM TCE code can map this memory for DMA as well. This is done by
mm_iommu_newdev()called fromvfio_pci_nvgpu_regops::mmap.In an unlikely event of failure the
data->memremains NULL and sincemm_iommu_put()(which unregisters the region and unpins memory if that was regular memory) does not expect mem=NULL, it should not be called.This adds a check to only call
mm_iommu_put()for a validdata->mem.Fixes 7f92891778df ("vfio_pci: Add NVIDIA GV100GL [Tesla V100 SXM2] subdriver")Signed-off-by Alexey Kardashevskiy <[email protected]>--- drivers/vfio/pci/vfio_pci_nvlink2.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/vfio/pci/vfio_pci_nvlink2.c +0
-0@@ -97,8 +97,10 @@ static void vfio_pci_nvgpu_release(struct vfio_pci_device *vdev,/* If there were any mappings at all... */
drivers/vfio/pci/vfio_pci_nvlink2.c static void vfio_pci_nvgpu_release(struct vfio_pci_device *vdev, · line 106
Quoted 10 lines
drivers/vfio/pci/vfio_pci_nvlink2.c +4
-2if (data->mm) { - ret =mm_iommu_put (data->mm, data->mem); -WARN_ON (ret); +if (data->mem) { + ret =mm_iommu_put (data->mm, data->mem); +WARN_ON (ret); + }mmdrop (data->mm); }
Applied to vfio next branch for v5.6. Thanks,
Alex