From: Nathan Chen <[email protected]>

Emit a warning when ats=on is requested but the physical device does not
advertise ATS, since ATS cannot be exposed to the guest in this case.

Signed-off-by: Nathan Chen <[email protected]>
---
 hw/vfio/pci.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index 0f592ada89..49ba6813ee 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -2592,6 +2592,7 @@ static void vfio_add_ext_cap(VFIOPCIDevice *vdev, bool 
ats_needed)
 {
     PCIDevice *pdev = PCI_DEVICE(vdev);
     bool pasid_cap_added = false;
+    bool ats_cap_present = false;
     Error *err = NULL;
     uint32_t header;
     uint16_t cap_id, next, size;
@@ -2680,6 +2681,7 @@ static void vfio_add_ext_cap(VFIOPCIDevice *vdev, bool 
ats_needed)
             pcie_add_capability(pdev, cap_id, cap_ver, next, size);
             break;
         case PCI_EXT_CAP_ID_ATS:
+            ats_cap_present = true;
             /*
              * If ATS is requested and supported according to the kernel, add
              * the ATS capability. If not supported according to the kernel or
@@ -2699,6 +2701,11 @@ static void vfio_add_ext_cap(VFIOPCIDevice *vdev, bool 
ats_needed)
         error_report_err(err);
     }
 
+    if (vdev->ats == ON_OFF_AUTO_ON && !ats_cap_present) {
+        warn_report("vfio-pci: ats=on requested, but host device has no "
+                    "ATS extended capability");
+    }
+
     /* Cleanup chain head ID if necessary */
     if (pci_get_word(pdev->config + PCI_CONFIG_SPACE_SIZE) == 0xFFFF) {
         pci_set_word(pdev->config + PCI_CONFIG_SPACE_SIZE, 0);
-- 
2.43.0


Reply via email to