Skip to contentSkip to conversation

vfio/pci: add vfio-pci ATS control property

PATCH Superseded Nathan Chen 4 participants 14 messages Jun 15 – Jun 18

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover vfio/pci: add vfio-pci ATS control property

Hi,

This is a follow-up to the series [0] that adds an ATS control property to vfio-pci and wires iommufd support reporting so vfio-pci can decide whether to expose the ATS PCIe extended capability to the guest.

The new vfio-pci property is:
ats=on|off|auto (default: auto)

Behavior:
- off: always masks ATS from guest view
- on: requires ATS support; fails realize if kernel reports no ATS support via IOMMU_HW_CAP_PCI_ATS_NOT_SUPPORTED
- auto: masks ATS only when kernel reports no ATS support via IOMMU_HW_CAP_PCI_ATS_NOT_SUPPORTED

To preserve machine compatibility for older machine types, this series adds:
{ "vfio-pci", "ats", "on" } to hw_compat_11_0.

Please note that no linux-headers sync patch is included in this series because IOMMU_HW_CAP_PCI_ATS_NOT_SUPPORTED is already present in linux-headers/linux/iommufd.h in the current base.

Testing:
Verified ATS capability visibility changes with vfio-pci ats=off/on/auto on an NVIDIA Grace system:
- ats=on + ATS supported by kernel => propagate ATS extended cap to guest view
- ats=auto + ATS supported by kernel => propagate ATS extended cap to guest view
- ats=on + hiod_iommufd_support_ats modified to return false (mimic kernel-reported unsupported ATS) => realize failure
- ats=auto + hiod_iommufd_support_ats modified to return false (mimic kernel-reported unsupported ATS) => ATS masked
- ats=off => ATS masked
- ats=on + no ATS support in physical device => warning + no ATS ext cap

Changes from v1:
- Set ats_needed to false by default in vfio_pci_ats_requested_and_supported()
- Revise log prefix from "vfio" to "vfio-pci" in vfio_pci_ats_requested_and_supported()
- Squash compat update patch into patch for introducing ats property for bisectibility
- Revise comments and descriptions for support_ats(), vfio_pci_ats_requested_and_supported(), and vfio_pci_class_init() to be more generic, removing references to IOMMU_HW_CAP_PCI_ATS_NOT_SUPPORTED
- Emit a warning when ats=on and no ATS support in physical device

Changes from "Resolve AUTO properties" series:
- Split into separate patches for support_ats() handler introduction and iommufd implementation, "ats" property addition, and compat property fix
- Rebase on vfio-next
- Remove unnecessary includes for hw/vfio/pci.c
- Rename ats_need to ats_needed for vfio_pci_ats_requested_and_supported()
- Move the vfio_pci_ats_requested_and_supported() call to vfio_pci_add_capabilities() so we can propagate the Error **, and then pass ats_needed as a new input arg to vfio_add_ext_cap
- Fix indent error in vfio_add_ext_cap()
- Break and add a pcie_add_capability() call for the PASID case in vfio_add_ext_cap()
- Update comment about return value for support_ats()

Thanks,
Nathan

[0] https://lore.kernel.org/qemu-devel/[email protected]/

Nathan Chen (3):
iommufd: Introduce handler for device ATS support vfio/pci: Add ats property
vfio/pci: Warn when ats=on but host device lacks ATS cap

 hw/vfio/pci.h                      |  1 +
 include/system/host_iommu_device.h |  9 ++++
 backends/iommufd.c                 |  8 +++
 hw/core/machine.c                  |  1 +
 hw/vfio/pci.c                      | 81 ++++++++++++++++++++++++++++--
 5 files changed, 97 insertions(+), 3 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 1/3 iommufd: Introduce handler for device ATS support

From: Nathan Chen <[email protected]>

Introduce a support_ats() handler that returns whether ATS is supported for a device associated with a host IOMMU device, checking if the IOMMU_HW_CAP_PCI_ATS_NOT_SUPPORTED capability bit is set.

Implement this handler in a new function for iommufd.

---
 include/system/host_iommu_device.h | 9 +++++++++
 backends/iommufd.c                 | 8 ++++++++
 2 files changed, 17 insertions(+)
include/system/host_iommu_device.h +9 -0
index f000301583..2cb5365340 100644
@@ -133,6 +133,15 @@ struct HostIOMMUDeviceClass {
      * Returns: true on success, false on failure.
      */
     bool (*get_pasid_info)(HostIOMMUDevice *hiod, PasidInfo *pasid_info);
+    /**
+     *  @support_ats: Returns true if ATS can be used by the device,
+     *  false if the host IOMMU reports it is unavailable.
+     *
+     *  @hiod: handle to the host IOMMU device
+     *
+     *  Returns: true if ATS is supported, false otherwise
+     */
+    bool (*support_ats)(HostIOMMUDevice *hiod);
 };
 
 /*
backends/iommufd.c +8 -0
index 410b044370..7cc6767b4b 100644
@@ -573,6 +573,13 @@ static int hiod_iommufd_get_cap(HostIOMMUDevice *hiod, int cap, Error **errp)
     }
 }
 
+static bool hiod_iommufd_support_ats(HostIOMMUDevice *hiod)
+{
+    HostIOMMUDeviceCaps *caps = &hiod->caps;
+
+    return !(caps->hw_caps & IOMMU_HW_CAP_PCI_ATS_NOT_SUPPORTED);
+}
+
 static bool hiod_iommufd_get_pasid_info(HostIOMMUDevice *hiod,
                                         PasidInfo *pasid_info)
 {
@@ -595,6 +602,7 @@ static void hiod_iommufd_class_init(ObjectClass *oc, const void *data)
 
     hiodc->get_cap = hiod_iommufd_get_cap;
     hiodc->get_pasid_info = hiod_iommufd_get_pasid_info;
+    hiodc->support_ats = hiod_iommufd_support_ats;
 };
 
 static const TypeInfo types[] = {
Signature · 1 line
2.43.0
Reviewed-by on v2 1/3
#2 lore raw

Re: [PATCH v2 1/3] iommufd: Introduce handler for device ATS support

Quoted 54 lines · Nathan Chen

From: Nathan Chen <[email protected]>

Introduce a support_ats() handler that returns whether ATS is supported for a device associated with a host IOMMU device, checking if the IOMMU_HW_CAP_PCI_ATS_NOT_SUPPORTED capability bit is set.

Implement this handler in a new function for iommufd.

---
  include/system/host_iommu_device.h | 9 +++++++++
  backends/iommufd.c                 | 8 ++++++++
  2 files changed, 17 insertions(+)
include/system/host_iommu_device.h +9 -0
index f000301583..2cb5365340 100644
@@ -133,6 +133,15 @@ struct HostIOMMUDeviceClass {
       * Returns: true on success, false on failure.
       */
      bool (*get_pasid_info)(HostIOMMUDevice *hiod, PasidInfo *pasid_info);
+    /**
+     *  @support_ats: Returns true if ATS can be used by the device,
+     *  false if the host IOMMU reports it is unavailable.
+     *
+     *  @hiod: handle to the host IOMMU device
+     *
+     *  Returns: true if ATS is supported, false otherwise
+     */
+    bool (*support_ats)(HostIOMMUDevice *hiod);
  };
 
  /*
backends/iommufd.c +7 -0
index 410b044370..7cc6767b4b 100644
@@ -573,6 +573,13 @@ static int hiod_iommufd_get_cap(HostIOMMUDevice *hiod, int cap, Error **errp)
      }
  }
 
+static bool hiod_iommufd_support_ats(HostIOMMUDevice *hiod)
+{
+    HostIOMMUDeviceCaps *caps = &hiod->caps;
+
+    return !(caps->hw_caps & IOMMU_HW_CAP_PCI_ATS_NOT_SUPPORTED);
+}
+
  static bool hiod_iommufd_get_pasid_info(HostIOMMUDevice *hiod,
                                          PasidInfo *pasid_info)
  {

backends/iommufd.c static void hiod_iommufd_class_init(ObjectClass *oc, const void *data) · line 608

Quoted 7 lines
backends/iommufd.c +1 -0
@@ -595,6 +602,7 @@ static void hiod_iommufd_class_init(ObjectClass *oc, const void *data)
 
      hiodc->get_cap = hiod_iommufd_get_cap;
      hiodc->get_pasid_info = hiod_iommufd_get_pasid_info;
+    hiodc->support_ats = hiod_iommufd_support_ats;
  };
 
  static const TypeInfo types[] = {

Thanks,

C.

Reviewed-by on v2 1/3
#3 lore raw

RE: [PATCH v2 1/3] iommufd: Introduce handler for device ATS support

In reply to Nathan Chen
Quoted 17 lines

-----Original Message-----
From: Nathan Chen <[email protected]>
Sent: 15 June 2026 21:49
To: [email protected]
Cc: Yi Liu <[email protected]>; Eric Auger <[email protected]>; Zhenzhong Duan <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Zhao Liu <[email protected]>; Alex Williamson <[email protected]>; Cédric Le Goater <[email protected]>; Matt Ochs <[email protected]>; Nicolin Chen <[email protected]>; Shameer Kolothum Thodi <[email protected]>; Nathan Chen <[email protected]>
Subject: [PATCH v2 1/3] iommufd: Introduce handler for device ATS support

From: Nathan Chen <[email protected]>

Quoted 8 lines

Introduce a support_ats() handler that returns whether ATS is supported for a device associated with a host IOMMU device, checking if the IOMMU_HW_CAP_PCI_ATS_NOT_SUPPORTED capability bit is set.

Implement this handler in a new function for iommufd.

Thanks,
Shameer

#4 lore raw

PATCH v2 2/3 vfio/pci: Add ats property

In reply to Nathan Chen

From: Nathan Chen <[email protected]>

Add an "ats" OnOffAuto property to vfio-pci. When the device has an ATS extended capability in config space but we should not expose it (ats=off, or ats=auto and kernel reports IOMMU_HW_CAP_PCI_ATS_NOT_SUPPORTED), mask the capability so the guest does not see it.

If ATS is explicitly requested but not supported by the kernel, fail device realize.

This aligns with the kernel's per-device effective ATS reporting and allows vfio-pci to mask ATS when the host kernel reports ATS as unsupported.

Introduce a new compat for the changed default for vfio-pci device ATS property, from "on" to "auto".

---
 hw/vfio/pci.h     |  1 +
 hw/core/machine.c |  1 +
 hw/vfio/pci.c     | 74 +++++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 73 insertions(+), 3 deletions(-)
hw/vfio/pci.h +1 -0
index c3a1f53d35..f2934f2d84 100644
@@ -188,6 +188,7 @@ struct VFIOPCIDevice {
     bool clear_parent_atomics_on_exit;
     bool skip_vsc_check;
     uint16_t vpasid_cap_offset;
+    OnOffAuto ats;
     VFIODisplay *dpy;
     Notifier irqchip_change_notifier;
     VFIOPCICPR cpr;
hw/core/machine.c +1 -0
index 4d8b15d99e..c0cdf7c9da 100644
@@ -43,6 +43,7 @@ GlobalProperty hw_compat_11_0[] = {
     { "chardev-vc", "encoding", "cp437" },
     { "tpm-crb", "cap-chunk", "off" },
     { "tpm-crb", "x-allow-chunk-migration", "off" },
+    { "vfio-pci", "ats", "on" },
 };
 const size_t hw_compat_11_0_len = G_N_ELEMENTS(hw_compat_11_0);
 
hw/vfio/pci.c +71 -3

110 lines not on this page · raw message

Signature · 1 line
2.43.0
#5 lore raw

Re: [PATCH v2 2/3] vfio/pci: Add ats property

Quoted 41 lines · Nathan Chen

From: Nathan Chen <[email protected]>

Add an "ats" OnOffAuto property to vfio-pci. When the device has an ATS extended capability in config space but we should not expose it (ats=off, or ats=auto and kernel reports IOMMU_HW_CAP_PCI_ATS_NOT_SUPPORTED), mask the capability so the guest does not see it.

If ATS is explicitly requested but not supported by the kernel, fail device realize.

This aligns with the kernel's per-device effective ATS reporting and allows vfio-pci to mask ATS when the host kernel reports ATS as unsupported.

Introduce a new compat for the changed default for vfio-pci device ATS property, from "on" to "auto".

---
  hw/vfio/pci.h     |  1 +
  hw/core/machine.c |  1 +
  hw/vfio/pci.c     | 74 +++++++++++++++++++++++++++++++++++++++++++++--
  3 files changed, 73 insertions(+), 3 deletions(-)
hw/vfio/pci.h +1 -0
index c3a1f53d35..f2934f2d84 100644
@@ -188,6 +188,7 @@ struct VFIOPCIDevice {
      bool clear_parent_atomics_on_exit;
      bool skip_vsc_check;
      uint16_t vpasid_cap_offset;
+    OnOffAuto ats;
      VFIODisplay *dpy;
      Notifier irqchip_change_notifier;
      VFIOPCICPR cpr;
hw/core/machine.c +0 -0
index 4d8b15d99e..c0cdf7c9da 100644

hw/core/machine.c GlobalProperty hw_compat_11_0[] = { · line 46

Quoted 4 lines
hw/core/machine.c +1 -0
@@ -43,6 +43,7 @@ GlobalProperty hw_compat_11_0[] = {
      { "chardev-vc", "encoding", "cp437" },
      { "tpm-crb", "cap-chunk", "off" },
      { "tpm-crb", "x-allow-chunk-migration", "off" },
+    { "vfio-pci", "ats", "on" },

This compat "ats=on" for old machine types (11.0 and below) should preserve the old guest-visible behavior : ATS is always advertised regardless of kernel capability.

Now, if the kernel is upgraded and reports IOMMU_HW_CAP_PCI_ATS_NOT_SUPPORTED, the VM will now fail to realize the vfio-pci device, fail to boot and the backward compatibility across machine types is broken ... Tough.

We could argue that the previous behavior was wrong but should be "bug" compatible too.

So, we could :

1. ignore,
2. use a compat "ats=auto", which would hide ATS reported unsupported in new kernels,
3. add a legacy compat "x-ats-strict=off" property to warn but not fail realize, and keep ATS enabled.

In any case, we need a warning at start time.

Ideas ?

Quoted 110 lines
hw/core/machine.c +0 -0
  };
  const size_t hw_compat_11_0_len = G_N_ELEMENTS(hw_compat_11_0);
 
hw/vfio/pci.c +62 -3
index 9c06b25e63..0f592ada89 100644
@@ -2546,7 +2546,49 @@ static bool vfio_pci_synthesize_pasid_cap(VFIOPCIDevice *vdev, Error **errp)
      return true;
  }
 
-static void vfio_add_ext_cap(VFIOPCIDevice *vdev)
+/*
+ * Determine whether ATS capability should be advertised for @vdev, based on
+ * whether it was enabled on the command line and whether it is supported
+ * according to the kernel.
+ *
+ * Store whether ATS capability should be advertised in @ats_needed.
+ *
+ * Returns false only when ats=on is explicitly requested but the kernel
+ * reports it is not supported. Returns true in all other cases.
+ */
+static bool vfio_pci_ats_requested_and_supported(VFIOPCIDevice *vdev,
+                                                 bool *ats_needed, Error **errp)
+{
+    HostIOMMUDevice *hiod = vdev->vbasedev.hiod;
+    HostIOMMUDeviceClass *hiodc;
+    bool ats_supported;
+    *ats_needed = false;
+
+    if (vdev->ats == ON_OFF_AUTO_OFF) {
+        return true;
+    }
+
+    *ats_needed = true;
+    if (!hiod) {
+        return true;
+    }
+    hiodc = HOST_IOMMU_DEVICE_GET_CLASS(hiod);
+    if (!hiodc || !hiodc->support_ats) {
+        return true;
+    }
+
+    ats_supported = hiodc->support_ats(hiod);
+    if (vdev->ats == ON_OFF_AUTO_ON && !ats_supported) {
+        error_setg(errp, "vfio-pci: ATS requested but not supported by kernel");
+        *ats_needed = false;
+        return false;
+    }
+
+    *ats_needed = ats_supported;
+    return true;
+}
+
+static void vfio_add_ext_cap(VFIOPCIDevice *vdev, bool ats_needed)
  {
      PCIDevice *pdev = PCI_DEVICE(vdev);
      bool pasid_cap_added = false;
@@ -2635,7 +2677,18 @@ static void vfio_add_ext_cap(VFIOPCIDevice *vdev)
           */
          case PCI_EXT_CAP_ID_PASID:
              pasid_cap_added = true;
-            /* fallthrough */
+            pcie_add_capability(pdev, cap_id, cap_ver, next, size);
+            break;
+        case PCI_EXT_CAP_ID_ATS:
+            /*
+             * If ATS is requested and supported according to the kernel, add
+             * the ATS capability. If not supported according to the kernel or
+             * disabled on the qemu command line, omit the ATS cap.
+             */
+            if (ats_needed) {
+                pcie_add_capability(pdev, cap_id, cap_ver, next, size);
+            }
+            break;
          default:
              pcie_add_capability(pdev, cap_id, cap_ver, next, size);
          }
@@ -2657,6 +2710,7 @@ static void vfio_add_ext_cap(VFIOPCIDevice *vdev)
  bool vfio_pci_add_capabilities(VFIOPCIDevice *vdev, Error **errp)
  {
      PCIDevice *pdev = PCI_DEVICE(vdev);
+    bool ats_needed = false;
 
      if (!(pdev->config[PCI_STATUS] & PCI_STATUS_CAP_LIST) ||
          !pdev->config[PCI_CAPABILITY_LIST]) {
@@ -2667,7 +2721,11 @@ bool vfio_pci_add_capabilities(VFIOPCIDevice *vdev, Error **errp)
          return false;
      }
 
-    vfio_add_ext_cap(vdev);
+    if (!vfio_pci_ats_requested_and_supported(vdev, &ats_needed, errp)) {
+        return false;
+    }
+
+    vfio_add_ext_cap(vdev, ats_needed);
      return true;
  }
 
@@ -3815,6 +3873,7 @@ static const Property vfio_pci_properties[] = {
      DEFINE_PROP_BOOL("skip-vsc-check", VFIOPCIDevice, skip_vsc_check, true),
      DEFINE_PROP_UINT16("x-vpasid-cap-offset", VFIOPCIDevice,
                         vpasid_cap_offset, 0),
+    DEFINE_PROP_ON_OFF_AUTO("ats", VFIOPCIDevice, ats, ON_OFF_AUTO_AUTO),
  };
 
  static void vfio_pci_set_fd(Object *obj, const char *str, Error **errp)
@@ -3973,6 +4032,15 @@ static void vfio_pci_class_init(ObjectClass *klass, const void *data)
                                            "a vIOMMU. A value of 0 (default) places the capability at the "
                                            "end of the extended configuration space. The offset must be "

hw/vfio/pci.c static void vfio_pci_class_init(ObjectClass *klass, const void *data) · line 4043

Quoted 10 lines
hw/vfio/pci.c +9 -0
                                            "4-byte aligned and within the PCIe extended configuration space");
+   object_class_property_set_description(klass, /* 11.1 */
+                                          "ats",
+                                          "Control guest visibility of the ATS PCIe extended capability. "
+                                          "Valid values are on, off, and auto (default). "
+                                          "'off' always masks ATS. "
+                                          "'on' requires ATS support for the device and fails realize if the "
+                                          "host kernel reports ATS as unavailable for this device. "
+                                          "'auto' masks ATS only when the host kernel reports "
+                                          "ATS as unavailable");

if you resend, could you please fix the alignment of the two object_class_property_set_description block() above.

Thanks,

C.

Quoted 3 lines
hw/vfio/pci.c +0 -0
  }
 
  static const TypeInfo vfio_pci_info = {
#6 lore raw

RE: [PATCH v2 2/3] vfio/pci: Add ats property

Quoted 81 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: 16 June 2026 13:48
To: Nathan Chen <[email protected]>; [email protected]
Cc: Yi Liu <[email protected]>; Eric Auger <[email protected]>; Zhenzhong Duan <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Zhao Liu <[email protected]>; Alex Williamson <[email protected]>; Matt Ochs <[email protected]>; Nicolin Chen <[email protected]>; Shameer Kolothum Thodi <[email protected]>
Subject: Re: [PATCH v2 2/3] vfio/pci: Add ats property

External email: Use caution opening links or attachments

Quoted 5 lines · Nathan Chen

From: Nathan Chen <[email protected]>

Add an "ats" OnOffAuto property to vfio-pci. When the device has an ATS extended capability in config space but we should not expose it (ats=off, or ats=auto and kernel reports

IOMMU_HW_CAP_PCI_ATS_NOT_SUPPORTED), mask

Quoted 11 lines

the capability so the guest does not see it.

If ATS is explicitly requested but not supported by the kernel, fail device realize.

This aligns with the kernel's per-device effective ATS reporting and allows vfio-pci to mask ATS when the host kernel reports ATS as unsupported.

Introduce a new compat for the changed default for vfio-pci device ATS property, from "on" to "auto".

Quoted 6 lines
---
  hw/vfio/pci.h     |  1 +
  hw/core/machine.c |  1 +
  hw/vfio/pci.c     | 74

+++++++++++++++++++++++++++++++++++++++++++++--

Quoted 19 lines
  3 files changed, 73 insertions(+), 3 deletions(-)
hw/vfio/pci.h +1 -0
index c3a1f53d35..f2934f2d84 100644
@@ -188,6 +188,7 @@ struct VFIOPCIDevice {
      bool clear_parent_atomics_on_exit;
      bool skip_vsc_check;
      uint16_t vpasid_cap_offset;
+    OnOffAuto ats;
      VFIODisplay *dpy;
      Notifier irqchip_change_notifier;
      VFIOPCICPR cpr;
hw/core/machine.c +0 -0
index 4d8b15d99e..c0cdf7c9da 100644

hw/core/machine.c GlobalProperty hw_compat_11_0[] = { · line 46

Quoted 4 lines
hw/core/machine.c +1 -0
@@ -43,6 +43,7 @@ GlobalProperty hw_compat_11_0[] = {
      { "chardev-vc", "encoding", "cp437" },
      { "tpm-crb", "cap-chunk", "off" },
      { "tpm-crb", "x-allow-chunk-migration", "off" },
+    { "vfio-pci", "ats", "on" },

This compat "ats=on" for old machine types (11.0 and below) should preserve
the old guest-visible behavior : ATS is always advertised regardless of kernel capability.

Now, if the kernel is upgraded and reports IOMMU_HW_CAP_PCI_ATS_NOT_SUPPORTED,
the VM will now fail to realize the vfio-pci device, fail to boot and the backward compatibility across machine types is broken ... Tough.

We could argue that the previous behavior was wrong but should be "bug" compatible too.

Quoted 7 lines

So, we could :

1. ignore,
2. use a compat "ats=auto", which would hide ATS reported unsupported in new kernels,
3. add a legacy compat "x-ats-strict=off" property to warn but not fail realize, and keep ATS enabled.

I would go with option 2 as failing to boot is too harsh. If host kernel already reports ATS NOT_SUPPORTED, guest use of ATS is already broken(so it doesn't matter even if we hide it after upgrade ).

Thanks,
Shameer

#7 lore raw

Re: [PATCH v2 2/3] vfio/pci: Add ats property

In reply to Cédric Le Goater
Quoted 68 lines · Cédric Le Goater
Quoted 41 lines · Nathan Chen

From: Nathan Chen <[email protected]>

Add an "ats" OnOffAuto property to vfio-pci. When the device has an ATS extended capability in config space but we should not expose it (ats=off, or ats=auto and kernel reports IOMMU_HW_CAP_PCI_ATS_NOT_SUPPORTED), mask the capability so the guest does not see it.

If ATS is explicitly requested but not supported by the kernel, fail device realize.

This aligns with the kernel's per-device effective ATS reporting and allows vfio-pci to mask ATS when the host kernel reports ATS as unsupported.

Introduce a new compat for the changed default for vfio-pci device ATS property, from "on" to "auto".

---
  hw/vfio/pci.h     |  1 +
  hw/core/machine.c |  1 +
  hw/vfio/pci.c     | 74 +++++++++++++++++++++++++++++++++++++++++++++--

  3 files changed, 73 insertions(+), 3 deletions(-)
hw/vfio/pci.h +1 -0
index c3a1f53d35..f2934f2d84 100644
@@ -188,6 +188,7 @@ struct VFIOPCIDevice {
       bool clear_parent_atomics_on_exit;
       bool skip_vsc_check;
       uint16_t vpasid_cap_offset;
+    OnOffAuto ats;
       VFIODisplay *dpy;
       Notifier irqchip_change_notifier;
       VFIOPCICPR cpr;
hw/core/machine.c +0 -0
index 4d8b15d99e..c0cdf7c9da 100644

hw/core/machine.c GlobalProperty hw_compat_11_0[] = { · line 46

Quoted 4 lines
hw/core/machine.c +1 -0
@@ -43,6 +43,7 @@ GlobalProperty hw_compat_11_0[] = {
       { "chardev-vc", "encoding", "cp437" },
       { "tpm-crb", "cap-chunk", "off" },
       { "tpm-crb", "x-allow-chunk-migration", "off" },
+    { "vfio-pci", "ats", "on" },

This compat "ats=on" for old machine types (11.0 and below) should preserve the old guest-visible behavior : ATS is always advertised regardless of kernel capability.

Now, if the kernel is upgraded and reports IOMMU_HW_CAP_PCI_ATS_NOT_SUPPORTED, the VM will now fail to realize the vfio-pci device, fail to boot and the backward compatibility across machine types is broken ... Tough.

We could argue that the previous behavior was wrong but should be "bug" compatible too.

So, we could  :

1. ignore,
2. use a compat "ats=auto", which would hide ATS reported unsupported in new kernels,
3. add a legacy compat "x-ats-strict=off" property to warn but not fail realize, and keep ATS enabled.

Quoted 4 lines

In any case, we need a warning at start time.

Ideas ?

I agree with Shameer on choosing option 2 to avoid the device realize failure. I will use a compat "ats=auto" and emit an additional warning indicating kernel does not support ATS when vdev->ats == ON_OFF_AUTO_AUTO>

Quoted 126 lines
Quoted 126 lines
hw/core/machine.c +0 -0
   };
   const size_t hw_compat_11_0_len = G_N_ELEMENTS(hw_compat_11_0);
hw/vfio/pci.c +2 -1
index 9c06b25e63..0f592ada89 100644
@@ -2546,7 +2546,49 @@ static bool 
 vfio_pci_synthesize_pasid_cap(VFIOPCIDevice *vdev, Error **errp)
       return true;
   }
-static void vfio_add_ext_cap(VFIOPCIDevice *vdev)
+/*
+ * Determine whether ATS capability should be advertised for @vdev, 

based on
+ * whether it was enabled on the command line and whether it is supported
+ * according to the kernel.
+ *
+ * Store whether ATS capability should be advertised in @ats_needed.
+ *
+ * Returns false only when ats=on is explicitly requested but the kernel
+ * reports it is not supported. Returns true in all other cases.
+ */
+static bool vfio_pci_ats_requested_and_supported(VFIOPCIDevice *vdev, +                                                 bool *ats_needed, Error **errp)

hw/vfio/pci.c +22 -0
+{
+    HostIOMMUDevice *hiod = vdev->vbasedev.hiod;
+    HostIOMMUDeviceClass *hiodc;
+    bool ats_supported;
+    *ats_needed = false;
+
+    if (vdev->ats == ON_OFF_AUTO_OFF) {
+        return true;
+    }
+
+    *ats_needed = true;
+    if (!hiod) {
+        return true;
+    }
+    hiodc = HOST_IOMMU_DEVICE_GET_CLASS(hiod);
+    if (!hiodc || !hiodc->support_ats) {
+        return true;
+    }
+
+    ats_supported = hiodc->support_ats(hiod);
+    if (vdev->ats == ON_OFF_AUTO_ON && !ats_supported) {
+        error_setg(errp, "vfio-pci: ATS requested but not supported 

by kernel");
+        *ats_needed = false;
+        return false;
+    }

hw/vfio/pci.c +6 -0
+
+    *ats_needed = ats_supported;
+    return true;
+}
+
+static void vfio_add_ext_cap(VFIOPCIDevice *vdev, bool ats_needed)

  {
      PCIDevice *pdev = PCI_DEVICE(vdev);
      bool pasid_cap_added = false;

hw/vfio/pci.c +0 -0
@@ -2635,7 +2677,18 @@ static void vfio_add_ext_cap(VFIOPCIDevice *vdev)
            */

          case PCI_EXT_CAP_ID_PASID:
              pasid_cap_added = true;
-            /* fallthrough */
+            pcie_add_capability(pdev, cap_id, cap_ver, next, size); +            break;
+        case PCI_EXT_CAP_ID_ATS:
+            /*
+             * If ATS is requested and supported according to the kernel, add
+             * the ATS capability. If not supported according to the kernel or
+             * disabled on the qemu command line, omit the ATS cap. +             */
+            if (ats_needed) {
+                pcie_add_capability(pdev, cap_id, cap_ver, next, size); +            }
+            break;
          default:
              pcie_add_capability(pdev, cap_id, cap_ver, next, size); }

hw/vfio/pci.c +1 -0
@@ -2657,6 +2710,7 @@ static void vfio_add_ext_cap(VFIOPCIDevice *vdev)
   bool vfio_pci_add_capabilities(VFIOPCIDevice *vdev, Error **errp)
   {
       PCIDevice *pdev = PCI_DEVICE(vdev);
+    bool ats_needed = false;

      if (!(pdev->config[PCI_STATUS] & PCI_STATUS_CAP_LIST) || !pdev->config[PCI_CAPABILITY_LIST]) {

hw/vfio/pci.c +6 -1
@@ -2667,7 +2721,11 @@ bool vfio_pci_add_capabilities(VFIOPCIDevice 
 *vdev, Error **errp)
           return false;
       }
-    vfio_add_ext_cap(vdev);
+    if (!vfio_pci_ats_requested_and_supported(vdev, &ats_needed, 
 errp)) {
+        return false;
+    }
+
+    vfio_add_ext_cap(vdev, ats_needed);
       return true;
   }
@@ -3815,6 +3873,7 @@ static const Property vfio_pci_properties[] = {
       DEFINE_PROP_BOOL("skip-vsc-check", VFIOPCIDevice, skip_vsc_check, true),
       DEFINE_PROP_UINT16("x-vpasid-cap-offset", VFIOPCIDevice,
                          vpasid_cap_offset, 0),
+    DEFINE_PROP_ON_OFF_AUTO("ats", VFIOPCIDevice, ats, 
 ON_OFF_AUTO_AUTO),
   };
   static void vfio_pci_set_fd(Object *obj, const char *str, Error **errp)
@@ -3973,6 +4032,15 @@ static void vfio_pci_class_init(ObjectClass 
 *klass, const void *data)

                                            "a vIOMMU. A value of 0 (default) places the capability at the " "end of the extended configuration space. The offset must be " "4-byte aligned and within the PCIe extended configuration space"); +   object_class_property_set_description(klass, /* 11.1 */
+                                          "ats",
+                                          "Control guest visibility
of the ATS PCIe extended capability. "
+                                          "Valid values are on, off,
and auto (default). "
+                                          "'off' always masks ATS. "
+                                          "'on' requires ATS support
for the device and fails realize if the "

Quoted 8 lines
Quoted 5 lines

+                                          "host kernel reports ATS as unavailable for this device. "
+                                          "'auto' masks ATS only when the host kernel reports "
+                                          "ATS as unavailable");

if you resend, could you please fix the alignment of the two object_class_property_set_description block() above.

Yes, I'll fix this in the next refresh.

Thanks,
Nathan

#8 lore raw

Re: [PATCH v2 2/3] vfio/pci: Add ats property

Hello Nathan,

Quoted 71 lines · Nathan Chen
Quoted 68 lines · Cédric Le Goater
Quoted 41 lines · Nathan Chen

From: Nathan Chen <[email protected]>

Add an "ats" OnOffAuto property to vfio-pci. When the device has an ATS extended capability in config space but we should not expose it (ats=off, or ats=auto and kernel reports IOMMU_HW_CAP_PCI_ATS_NOT_SUPPORTED), mask the capability so the guest does not see it.

If ATS is explicitly requested but not supported by the kernel, fail device realize.

This aligns with the kernel's per-device effective ATS reporting and allows vfio-pci to mask ATS when the host kernel reports ATS as unsupported.

Introduce a new compat for the changed default for vfio-pci device ATS property, from "on" to "auto".

---
  hw/vfio/pci.h     |  1 +
  hw/core/machine.c |  1 +
  hw/vfio/pci.c     | 74 +++++++++++++++++++++++++++++++++++++++++++++--

  3 files changed, 73 insertions(+), 3 deletions(-)
hw/vfio/pci.h +1 -0
index c3a1f53d35..f2934f2d84 100644
@@ -188,6 +188,7 @@ struct VFIOPCIDevice {
       bool clear_parent_atomics_on_exit;
       bool skip_vsc_check;
       uint16_t vpasid_cap_offset;
+    OnOffAuto ats;
       VFIODisplay *dpy;
       Notifier irqchip_change_notifier;
       VFIOPCICPR cpr;
hw/core/machine.c +0 -0
index 4d8b15d99e..c0cdf7c9da 100644

hw/core/machine.c GlobalProperty hw_compat_11_0[] = { · line 46

Quoted 4 lines
hw/core/machine.c +1 -0
@@ -43,6 +43,7 @@ GlobalProperty hw_compat_11_0[] = {
       { "chardev-vc", "encoding", "cp437" },
       { "tpm-crb", "cap-chunk", "off" },
       { "tpm-crb", "x-allow-chunk-migration", "off" },
+    { "vfio-pci", "ats", "on" },

This compat "ats=on" for old machine types (11.0 and below) should preserve the old guest-visible behavior : ATS is always advertised regardless of kernel capability.

Now, if the kernel is upgraded and reports IOMMU_HW_CAP_PCI_ATS_NOT_SUPPORTED, the VM will now fail to realize the vfio-pci device, fail to boot and the backward compatibility across machine types is broken ... Tough.

We could argue that the previous behavior was wrong but should be "bug" compatible too.

So, we could  :

1. ignore,
2. use a compat "ats=auto", which would hide ATS reported unsupported in new kernels,
3. add a legacy compat "x-ats-strict=off" property to warn but not fail realize, and keep ATS enabled.

Quoted 5 lines
Quoted 4 lines

In any case, we need a warning at start time.

Ideas ?

I agree with Shameer on choosing option 2 to avoid the device realize failure. I will use a compat "ats=auto" and emit an additional warning indicating kernel does not support ATS when vdev->ats == ON_OFF_AUTO_AUTO

OK. Let's try that.

Quoted 119 lines
Quoted 110 lines
Quoted 110 lines
hw/core/machine.c +0 -0
   };
   const size_t hw_compat_11_0_len = G_N_ELEMENTS(hw_compat_11_0);
hw/vfio/pci.c +43 -1
index 9c06b25e63..0f592ada89 100644
@@ -2546,7 +2546,49 @@ static bool vfio_pci_synthesize_pasid_cap(VFIOPCIDevice *vdev, Error **errp)
       return true;
   }
-static void vfio_add_ext_cap(VFIOPCIDevice *vdev)
+/*
+ * Determine whether ATS capability should be advertised for @vdev, based on
+ * whether it was enabled on the command line and whether it is supported
+ * according to the kernel.
+ *
+ * Store whether ATS capability should be advertised in @ats_needed.
+ *
+ * Returns false only when ats=on is explicitly requested but the kernel
+ * reports it is not supported. Returns true in all other cases.
+ */
+static bool vfio_pci_ats_requested_and_supported(VFIOPCIDevice *vdev,
+                                                 bool *ats_needed, Error **errp)
+{
+    HostIOMMUDevice *hiod = vdev->vbasedev.hiod;
+    HostIOMMUDeviceClass *hiodc;
+    bool ats_supported;
+    *ats_needed = false;
+
+    if (vdev->ats == ON_OFF_AUTO_OFF) {
+        return true;
+    }
+
+    *ats_needed = true;
+    if (!hiod) {
+        return true;
+    }
+    hiodc = HOST_IOMMU_DEVICE_GET_CLASS(hiod);
+    if (!hiodc || !hiodc->support_ats) {
+        return true;
+    }
+
+    ats_supported = hiodc->support_ats(hiod);
+    if (vdev->ats == ON_OFF_AUTO_ON && !ats_supported) {
+        error_setg(errp, "vfio-pci: ATS requested but not supported by kernel");
+        *ats_needed = false;
+        return false;
+    }
+
+    *ats_needed = ats_supported;
+    return true;
+}
+
+static void vfio_add_ext_cap(VFIOPCIDevice *vdev, bool ats_needed)
   {
       PCIDevice *pdev = PCI_DEVICE(vdev);
       bool pasid_cap_added = false;
@@ -2635,7 +2677,18 @@ static void vfio_add_ext_cap(VFIOPCIDevice *vdev)
            */

          case PCI_EXT_CAP_ID_PASID:
              pasid_cap_added = true;
-            /* fallthrough */
+            pcie_add_capability(pdev, cap_id, cap_ver, next, size); +            break;
+        case PCI_EXT_CAP_ID_ATS:
+            /*
+             * If ATS is requested and supported according to the kernel, add +             * the ATS capability. If not supported according to the kernel or +             * disabled on the qemu command line, omit the ATS cap. +             */
+            if (ats_needed) {
+                pcie_add_capability(pdev, cap_id, cap_ver, next, size); +            }
+            break;
          default:
              pcie_add_capability(pdev, cap_id, cap_ver, next, size); }

hw/vfio/pci.c +1 -0
@@ -2657,6 +2710,7 @@ static void vfio_add_ext_cap(VFIOPCIDevice *vdev)
   bool vfio_pci_add_capabilities(VFIOPCIDevice *vdev, Error **errp)
   {
       PCIDevice *pdev = PCI_DEVICE(vdev);
+    bool ats_needed = false;

      if (!(pdev->config[PCI_STATUS] & PCI_STATUS_CAP_LIST) || !pdev->config[PCI_CAPABILITY_LIST]) {

hw/vfio/pci.c +6 -1
@@ -2667,7 +2721,11 @@ bool vfio_pci_add_capabilities(VFIOPCIDevice *vdev, Error **errp)
           return false;
       }
-    vfio_add_ext_cap(vdev);
+    if (!vfio_pci_ats_requested_and_supported(vdev, &ats_needed, errp)) {
+        return false;
+    }
+
+    vfio_add_ext_cap(vdev, ats_needed);
       return true;
   }
@@ -3815,6 +3873,7 @@ static const Property vfio_pci_properties[] = {
       DEFINE_PROP_BOOL("skip-vsc-check", VFIOPCIDevice, skip_vsc_check, true),
       DEFINE_PROP_UINT16("x-vpasid-cap-offset", VFIOPCIDevice,
                          vpasid_cap_offset, 0),
+    DEFINE_PROP_ON_OFF_AUTO("ats", VFIOPCIDevice, ats, ON_OFF_AUTO_AUTO),
   };
   static void vfio_pci_set_fd(Object *obj, const char *str, Error **errp)
@@ -3973,6 +4032,15 @@ static void vfio_pci_class_init(ObjectClass *klass, const void *data)

                                            "a vIOMMU. A value of 0 (default) places the capability at the " "end of the extended configuration space. The offset must be " "4-byte aligned and within the PCIe extended configuration space"); +   object_class_property_set_description(klass, /* 11.1 */
+                                          "ats",
+                                          "Control guest visibility of the ATS PCIe extended capability. " +                                          "Valid values are on, off, and auto (default). "

Quoted 8 lines
Quoted 5 lines

+                                          "'off' always masks ATS. "
+                                          "'on' requires ATS support for the device and fails realize if the " +                                          "host kernel reports ATS as unavailable for this device. " +                                          "'auto' masks ATS only when the host kernel reports " +                                          "ATS as unavailable");

if you resend, could you please fix the alignment of the two object_class_property_set_description block() above.

Quoted 1 line

Yes, I'll fix this in the next refresh.

If you can do that by next week, that'd be nice.

Thanks,

C.

#9 lore raw

PATCH v2 3/3 vfio/pci: Warn when ats=on but host device lacks ATS cap

In reply to Nathan Chen

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.

---
 hw/vfio/pci.c | 7 +++++++
 1 file changed, 7 insertions(+)
hw/vfio/pci.c +7 -0
index 0f592ada89..49ba6813ee 100644
@@ -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);
Signature · 1 line
2.43.0
#10 lore raw

Re: [PATCH v2 3/3] vfio/pci: Warn when ats=on but host device lacks ATS cap

Hi,

Quoted 15 lines · Nathan Chen

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.

---
  hw/vfio/pci.c | 7 +++++++
  1 file changed, 7 insertions(+)
hw/vfio/pci.c +0 -0
index 0f592ada89..49ba6813ee 100644

hw/vfio/pci.c static void vfio_add_ext_cap(VFIOPCIDevice *vdev, bool ats_needed) · line 2596

Quoted 5 lines
hw/vfio/pci.c +1 -0
@@ -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;
        ^^^^^^^^^^

hw/vfio/pci.c static void vfio_add_ext_cap(VFIOPCIDevice *vdev, bool ats_needed) · line 2701

Quoted 12 lines
hw/vfio/pci.c +1 -0
      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);
            ^^^^^^^^^^^^^^^^

hw/vfio/pci.c static void vfio_add_ext_cap(VFIOPCIDevice *vdev, bool ats_needed) · line 2707

Quoted 6 lines
hw/vfio/pci.c +4 -0
      }
 
+    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.

#11 lore raw

Re: [PATCH v2 3/3] vfio/pci: Warn when ats=on but host device lacks ATS cap

Quoted 47 lines · Philippe Mathieu-Daudé

Hi,

Quoted 15 lines · Nathan Chen

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.

---
  hw/vfio/pci.c | 7 +++++++

  1 file changed, 7 insertions(+)
hw/vfio/pci.c +0 -0
index 0f592ada89..49ba6813ee 100644

hw/vfio/pci.c static void vfio_add_ext_cap(VFIOPCIDevice *vdev, bool ats_needed) · line 2596

Quoted 5 lines
hw/vfio/pci.c +1 -0
@@ -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;

        ^^^^^^^^^^

hw/vfio/pci.c static void vfio_add_ext_cap(VFIOPCIDevice *vdev, bool ats_needed) · line 2701

Quoted 12 lines
hw/vfio/pci.c +0 -0
       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

hw/vfio/pci.c +0 -0
@@ -2699,6 +2701,11 @@ static void vfio_add_ext_cap(VFIOPCIDevice *vdev, bool ats_needed)
           error_report_err(err);

            ^^^^^^^^^^^^^^^^

hw/vfio/pci.c static void vfio_add_ext_cap(VFIOPCIDevice *vdev, bool ats_needed) · line 2707

Quoted 5 lines
hw/vfio/pci.c +4 -0
       }
+    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");
+    }
Quoted 5 lines

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.

It would be nice to have and can be done later. It's not strictly part of this series.

Thanks,

C.

Reviewed-by on v2 3/3
#12 lore raw

RE: [PATCH v2 3/3] vfio/pci: Warn when ats=on but host device lacks ATS cap

In reply to Nathan Chen
Quoted 49 lines

-----Original Message-----
From: Nathan Chen <[email protected]>
Sent: 15 June 2026 21:49
To: [email protected]
Cc: Yi Liu <[email protected]>; Eric Auger <[email protected]>; Zhenzhong Duan <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Zhao Liu <[email protected]>; Alex Williamson <[email protected]>; Cédric Le Goater <[email protected]>; Matt Ochs <[email protected]>; Nicolin Chen <[email protected]>; Shameer Kolothum Thodi <[email protected]>; Nathan Chen <[email protected]>
Subject: [PATCH v2 3/3] vfio/pci: Warn when ats=on but host device lacks ATS cap

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.

---
 hw/vfio/pci.c | 7 +++++++
 1 file changed, 7 insertions(+)
hw/vfio/pci.c index 0f592ada89..49ba6813ee renamed from hw/vfio/pci.c +0 -0

100644

hw/vfio/pci.c +2 -0
@@ -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)

Quoted 4 lines
         error_report_err(err);
     }

+ if (vdev->ats == ON_OFF_AUTO_ON && !ats_cap_present) {

Nit: Can we do:
If (ats_needed && !ats_cap_present) here?

hw/vfio/pci.c static void vfio_add_ext_cap(VFIOPCIDevice *vdev, bool ats_needed) · line 2708

Quoted 4 lines
hw/vfio/pci.c +4 -0
+        warn_report("vfio-pci: ats=on requested, but host device has no "
+                    "ATS extended capability");
+    }
+

Also, why this has to be a separate patch? Can't we fold into patch #2?

Besides(if you plan to keep this as separate one):

Thanks,
Shameer

#13 lore raw

Re: [PATCH v2 3/3] vfio/pci: Warn when ats=on but host device lacks ATS cap

Quoted 51 lines · Shameer Kolothum Thodi
Quoted 51 lines

-----Original Message-----
From: Nathan Chen<[email protected]>
Sent: 15 June 2026 21:49
To:[email protected]
Cc: Yi Liu<[email protected]>; Eric Auger<[email protected]>; Zhenzhong Duan<[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Zhao Liu<[email protected]>; Alex Williamson <[email protected]>; Cédric Le Goater<[email protected]>; Matt Ochs <[email protected]>; Nicolin Chen<[email protected]>; Shameer Kolothum Thodi<[email protected]>; Nathan Chen <[email protected]>
Subject: [PATCH v2 3/3] vfio/pci: Warn when ats=on but host device lacks ATS cap

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.

---
  hw/vfio/pci.c | 7 +++++++
  1 file changed, 7 insertions(+)
hw/vfio/pci.c index 0f592ada89..49ba6813ee renamed from hw/vfio/pci.c +0 -0

100644

hw/vfio/pci.c +2 -0
@@ -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);
      }
Quoted 3 lines
Quoted 1 line

+ if (vdev->ats == ON_OFF_AUTO_ON && !ats_cap_present) {

Nit: Can we do:
If (ats_needed && !ats_cap_present) here?

Yes, I'll revise this in the next refresh.>

Quoted 5 lines

hw/vfio/pci.c static void vfio_add_ext_cap(VFIOPCIDevice *vdev, bool ats_needed) · line 2708

Quoted 4 lines
hw/vfio/pci.c +4 -0
+        warn_report("vfio-pci: ats=on requested, but host device has no "
+                    "ATS extended capability");
+    }
+

Also, why this has to be a separate patch? Can't we fold into patch #2?

I'll fold this into patch #2. I had made this separate since it was suggested it could be a follow up change to the original series, but I agree it can fit with the preceding patch's changes to vfio_add_ext_cap()

Thanks,
Nathan