From 688c96f7a86ac5bc0cd6d7b5c2f4e14b91bdab23 Mon Sep 17 00:00:00 2001 From: Kunkun Jiang Date: Sat, 21 Aug 2021 17:00:43 +0800 Subject: [PATCH] vfio/pci: Fix wrong return value when get iommu attribute DOMAIN_ATTR_NESTING virt inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I46K8O CVE: NA ------------------------ Some vendor IOMMU drivers doesn't implement their own domain_get_attr callback or the processing of DOMAIN_ATTR_NESTING. Then iommu_domain_get_attr may return an error. But it shouldn't affect the result of vfio_pci_enable. We print a log to indicate the error and return 0. Signed-off-by: Kunkun Jiang Reviewed-by: Xinle Guo Signed-off-by: Zheng Zengkai --- drivers/vfio/pci/vfio_pci.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index a9d25b339572..42612e193a00 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -502,8 +502,12 @@ static int vfio_pci_dma_fault_init(struct vfio_pci_device *vdev) return 0; ret = iommu_domain_get_attr(domain, DOMAIN_ATTR_NESTING, &nested); - if (ret || !nested) - return ret; + if (ret || !nested) { + if (ret) + pr_warn("%s: Get DOMAIN_ATTR_NESTING failed: %d.\n", + __func__, ret); + return 0; + } mutex_init(&vdev->fault_queue_lock); @@ -592,8 +596,12 @@ static int vfio_pci_dma_fault_response_init(struct vfio_pci_device *vdev) return 0; ret = iommu_domain_get_attr(domain, DOMAIN_ATTR_NESTING, &nested); - if (ret || !nested) - return ret; + if (ret || !nested) { + if (ret) + pr_warn("%s: Get DOMAIN_ATTR_NESTING failed: %d.\n", + __func__, ret); + return 0; + } mutex_init(&vdev->fault_response_queue_lock); -- GitLab