Hi,

On 15/6/26 22:48, Nathan Chen wrote:
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");
+    }

At a quick glance vfio_pci_add_capabilities() should pass its @errp
to vfio_add_ext_cap() so the latter can propagate any error instead
of calling error_report_err() or warn_report(). I note this is
pre-existing and could be cleaned later, IMHO the sooner the better
but up to the maintainers.

Regards,

Phil.

Reply via email to