pcie/acs: configurable ACS capabilities for root and downstream ports
cover pcie/acs: configurable ACS capabilities for root and downstream ports
This series adds an 'acs-ctrl' property to PCIe root ports and downstream ports, letting the hypervisor expose a specific PCIe ACS (Access Control Services) configuration to the guest instead of QEMU always advertising every ACS capability the port structurally supports.
This matters for P2P (peer-to-peer) topologies such as GPUDirect RDMA, where the actual ACS configuration in effect must match what the host side is doing -- otherwise the guest sees a topology/configuration that doesn't reflect reality, which is undefined behavior and can fail either in software or in hardware.
Patch 1 adds the missing ACS capability to xio3130 downstream ports (previously only root ports exposed one), gated behind a new 'x-pcie-acs' property so older machine types can disable it via hw_compat and preserve migration compatibility.
Patch 2 introduces the 'acs-ctrl' property itself on both root and downstream ports, so the configured value -- not just the maximal capability set -- is what gets exposed to the guest.
Patch 3 makes the ACS Control register read-only to the guest once 'acs-ctrl' has been explicitly configured, so a guest OS doing normal PCIe programming can't silently override the host-configured ACS state. An explicitly configured value of 0 is treated the same as any other configured value (locked), distinct from the property never being set at all (which stays guest-writable, unchanged from current behavior).
Tushar Dave (2):
xio3130_downstream: Add ACS support for downstream PCIe ports hw/pci: Make ACS Control read-only to guests
Yishai Hadas (1):
hw/pci: Expose ACS ctrl on Guest as configured by the HYP
hw/core/machine.c | 1 + hw/pci-bridge/pcie_root_port.c | 11 +++++- hw/pci-bridge/xio3130_downstream.c | 14 +++++++ hw/pci/pci.c | 2 + hw/pci/pcie.c | 61 ++++++++++++++++++++++++++++-- include/hw/pci/pci.h | 3 ++ include/hw/pci/pcie.h | 9 +++-- include/hw/pci/pcie_port.h | 2 + 8 files changed, 94 insertions(+), 9 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/3 xio3130_downstream: Add ACS support for downstream PCIe ports
When a PASID-capable device is added behind the PCIe downstream port, for example, an Nvidia GPU, the PCIe downstream ports must expose ACS capability otherwise PASID won't get enabled.
In addition, the other use case is GPUDirect RDMA using Data Direct that must require special ACS controls at the PCIe downstream ports for P2P communication.
Gate it behind a new x-pcie-acs property (default on), following the x-pcie-* compat-bit convention (x-pcie-ext-tag/x-pcie-err-unc-mask/ x-pcie-ari-nextfn-1), so older machine types can disable it via hw_compat to preserve migration compatibility.
--- hw/core/machine.c | 1 + hw/pci-bridge/xio3130_downstream.c | 7 +++++++ hw/pci/pci.c | 2 ++ include/hw/pci/pci.h | 3 +++ 4 files changed, 13 insertions(+)
hw/core/machine.c +1 -0
@@ -43,6 +43,7 @@GlobalProperty hw_compat_11_1[] = { {"sysbus-ehci-usb" ,"x-migrate-fetch-addr-64bit" ,"off" }, {"pci-ehci-usb" ,"x-migrate-fetch-addr-64bit" ,"off" }, + {TYPE_PCI_DEVICE ,"x-pcie-acs" ,"off" },/* Added in 11.2 */ };const size_t hw_compat_11_1_len =G_N_ELEMENTS (hw_compat_11_1);
hw/pci-bridge/xio3130_downstream.c +7 -0
@@ -40,6 +40,8 @@#define XIO3130_SSVID_SSID 0#define XIO3130_EXP_OFFSET 0x90#define XIO3130_AER_OFFSET 0x100 +#define XIO3130_ACS_OFFSET \ + (XIO3130_AER_OFFSET + PCI_ERR_SIZEOF)static void xio3130_downstream_write_config (PCIDevice *d,uint32_t address,uint32_t val,int len)
@@ -60,6 +62,7 @@ static void xio3130_downstream_reset(DeviceState *qdev)pcie_cap_deverr_reset (d);pcie_cap_slot_reset (d);pcie_cap_arifwd_reset (d); +pcie_acs_reset (d);pci_bridge_reset (qdev); }
@@ -111,6 +114,10 @@ static void xio3130_downstream_realize(PCIDevice *d, Error **errp) goto err; } +if (d->cap_present &QEMU_PCIE_CAP_ACS ) { +pcie_acs_init (d,XIO3130_ACS_OFFSET ); + } +return ; err:
hw/pci/pci.c +2 -0
@@ -105,6 +105,8 @@ static const Property pci_props[] = {DEFINE_PROP_STRING ("sriov-pf" , PCIDevice, sriov_pf),DEFINE_PROP_BIT ("x-pcie-ext-tag" , PCIDevice, cap_present,QEMU_PCIE_EXT_TAG_BITNR , true), +DEFINE_PROP_BIT ("x-pcie-acs" , PCIDevice, cap_present, +QEMU_PCIE_ACS_BITNR , true), { .name = "busnr", .info = &prop_pci_busnr }, };
include/hw/pci/pci.h +3 -0
@@ -231,6 +231,9 @@ enum { QEMU_PCI_CAP_PM = (1 << QEMU_PCI_CAP_PM_BITNR),#define QEMU_PCI_SKIP_RESET_ON_CPR_BITNR 15 QEMU_PCI_SKIP_RESET_ON_CPR = (1 << QEMU_PCI_SKIP_RESET_ON_CPR_BITNR), +/* PCIe ACS (Access Control Services) extended capability present */ +#define QEMU_PCIE_ACS_BITNR 16 + QEMU_PCIE_CAP_ACS = (1 << QEMU_PCIE_ACS_BITNR), }; typedef struct PCIINTxRoute {
Signature · 1 line
2.34.1
RE: [PATCH 1/3] xio3130_downstream: Add ACS support for downstream PCIe ports
Quoted 17 lines
-----Original Message-----
From: Tushar Dave <[email protected]>
Sent: 22 September 2026 22:50
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Yishai Hadas <[email protected]>; Alex Williamson <[email protected]>; Jason Gunthorpe <[email protected]>; Shameer Kolothum Thodi <[email protected]>
Subject: [PATCH 1/3]xio3130_downstream: Add ACS support for downstream PCIe portsWhen a PASID-capable device is added behind the PCIe downstream port, for example, an Nvidia GPU, the PCIe downstream ports must expose ACS capability otherwise PASID won't get enabled.
Quoted 5 lines
In addition, the other use case is GPUDirect RDMA using Data Direct that must require special ACS controls at the PCIe downstream ports for P2P communication.
Gate it behind a new x-pcie-acs property (default on), following the
Why default on? It only matters for the use cases above. With it on, a guest with a vIOMMU behind an xio3130 downstream port may see its IOMMU groups change. Is that intended? If so, please mention it in the commit message.
Quoted 65 lines
x-pcie-* compat-bit convention (x-pcie-ext-tag/x-pcie-err-unc-mask/ x-pcie-ari-nextfn-1), so older machine types can disable it via
hw_compatto preserve migration compatibility.Signed-off-by Tushar Dave <[email protected]>--- hw/core/machine.c | 1 + hw/pci-bridge/xio3130_downstream.c | 7 +++++++ hw/pci/pci.c | 2 ++ include/hw/pci/pci.h | 3 +++ 4 files changed, 13 insertions(+)hw/core/machine.c +1
-0@@ -43,6 +43,7 @@GlobalProperty hw_compat_11_1[] = { {"sysbus-ehci-usb" ,"x-migrate-fetch-addr-64bit" ,"off" }, {"pci-ehci-usb" ,"x-migrate-fetch-addr-64bit" ,"off" }, + {TYPE_PCI_DEVICE ,"x-pcie-acs" ,"off" },/* Added in 11.2 */ };const size_t hw_compat_11_1_len =G_N_ELEMENTS (hw_compat_11_1);hw/pci- renamed from hw/pci-bridge/xio3130_downstream.c +0
-0
bridge/xio3130_downstream.c
index0c3fed3053..87ba30eb36100644hw/pci-bridge/xio3130_downstream.c +2
-0@@ -40,6 +40,8 @@#define XIO3130_SSVID_SSID 0#define XIO3130_EXP_OFFSET 0x90#define XIO3130_AER_OFFSET 0x100 +#define XIO3130_ACS_OFFSET \ + (XIO3130_AER_OFFSET + PCI_ERR_SIZEOF) static void xio3130_downstream_write_config(PCIDevice *d, uint32_t address,
uint32_tval, int len)hw/pci-bridge/xio3130_downstream.c +5
-0@@ -60,6 +62,7 @@ static void xio3130_downstream_reset(DeviceState *qdev)pcie_cap_deverr_reset (d);pcie_cap_slot_reset (d);pcie_cap_arifwd_reset (d); +pcie_acs_reset (d);pci_bridge_reset (qdev); }@@ -111,6 +114,10 @@ static void xio3130_downstream_realize(PCIDevice *d, Error **errp) goto err; } +if (d->cap_present &QEMU_PCIE_CAP_ACS ) { +pcie_acs_init (d,XIO3130_ACS_OFFSET ); + } +return ;err:
hw/pci/pci.c +0
-0
hw/pci/pci.c static const Property pci_props[] = { · line 109
Quoted 5 lines
hw/pci/pci.c +2
-0@@ -105,6 +105,8 @@ static const Property pci_props[] = {DEFINE_PROP_STRING ("sriov-pf" , PCIDevice, sriov_pf),DEFINE_PROP_BIT ("x-pcie-ext-tag" , PCIDevice, cap_present,QEMU_PCIE_EXT_TAG_BITNR , true), +DEFINE_PROP_BIT ("x-pcie-acs" , PCIDevice, cap_present, + QEMU_PCIE_ACS_BITNR, true),
This is defined on every PCI device but only xio3130 downstream reads it. I think it is better to limit the scope.
Thanks,
Shameer
Re: [PATCH 1/3] xio3130_downstream: Add ACS support for downstream PCIe ports
Quoted 21 lines · Shameer Kolothum Thodi
Quoted 21 lines
-----Original Message-----
From: Tushar Dave <[email protected]>
Sent: 22 September 2026 22:50
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Yishai Hadas <[email protected]>; Alex Williamson <[email protected]>; Jason Gunthorpe <[email protected]>; Shameer Kolothum Thodi <[email protected]>
Subject: [PATCH 1/3]xio3130_downstream: Add ACS support for downstream PCIe portsWhen a PASID-capable device is added behind the PCIe downstream port, for example, an Nvidia GPU, the PCIe downstream ports must expose ACS capability otherwise PASID won't get enabled.
In addition, the other use case is GPUDirect RDMA using Data Direct that must require special ACS controls at the PCIe downstream ports for P2P communication.
Quoted 6 lines
Quoted 1 line
Gate it behind a new x-pcie-acs property (default on), following the
Why default on? It only matters for the use cases above. With it on, a guest with a vIOMMU behind an xio3130 downstream port may see its IOMMU groups change. Is that intended? If so, please mention it in the commit message.
'x-pcie-acs' exists only for migration compatibility. 'x-pcie-acs' does not control any ACS control bits. It defaults on so that new machine types get the capability without an extra option, and older machine types turn it off through the hw_compat entry, like other properties do today, so migration is unchanged.
Quoted 60 lines
Quoted 60 lines
x-pcie-* compat-bit convention (x-pcie-ext-tag/x-pcie-err-unc-mask/ x-pcie-ari-nextfn-1), so older machine types can disable it via
hw_compatto preserve migration compatibility.Signed-off-by Tushar Dave <[email protected]>--- hw/core/machine.c | 1 + hw/pci-bridge/xio3130_downstream.c | 7 +++++++ hw/pci/pci.c | 2 ++ include/hw/pci/pci.h | 3 +++ 4 files changed, 13 insertions(+)hw/core/machine.c +1
-0@@ -43,6 +43,7 @@GlobalProperty hw_compat_11_1[] = { {"sysbus-ehci-usb" ,"x-migrate-fetch-addr-64bit" ,"off" }, {"pci-ehci-usb" ,"x-migrate-fetch-addr-64bit" ,"off" }, + {TYPE_PCI_DEVICE ,"x-pcie-acs" ,"off" },/* Added in 11.2 */ };const size_t hw_compat_11_1_len =G_N_ELEMENTS (hw_compat_11_1);hw/pci- renamed from hw/pci-bridge/xio3130_downstream.c +0
-0
bridge/xio3130_downstream.c
index0c3fed3053..87ba30eb36100644hw/pci-bridge/xio3130_downstream.c +2
-0@@ -40,6 +40,8 @@#define XIO3130_SSVID_SSID 0#define XIO3130_EXP_OFFSET 0x90#define XIO3130_AER_OFFSET 0x100 +#define XIO3130_ACS_OFFSET \ + (XIO3130_AER_OFFSET + PCI_ERR_SIZEOF) static void xio3130_downstream_write_config(PCIDevice *d, uint32_t address,
uint32_tval, int len)hw/pci-bridge/xio3130_downstream.c +5
-0@@ -60,6 +62,7 @@ static void xio3130_downstream_reset(DeviceState *qdev)pcie_cap_deverr_reset (d);pcie_cap_slot_reset (d);pcie_cap_arifwd_reset (d); +pcie_acs_reset (d);pci_bridge_reset (qdev); }@@ -111,6 +114,10 @@ static void xio3130_downstream_realize(PCIDevice *d, Error **errp) goto err; } +if (d->cap_present &QEMU_PCIE_CAP_ACS ) { +pcie_acs_init (d,XIO3130_ACS_OFFSET ); + } +return ;
Quoted 14 lines
hw/pci/pci.c static const Property pci_props[] = { · line 109
Quoted 11 lines
err:
hw/pci/pci.c +2
-0@@ -105,6 +105,8 @@ static const Property pci_props[] = {DEFINE_PROP_STRING ("sriov-pf" , PCIDevice, sriov_pf),DEFINE_PROP_BIT ("x-pcie-ext-tag" , PCIDevice, cap_present,QEMU_PCIE_EXT_TAG_BITNR , true), +DEFINE_PROP_BIT ("x-pcie-acs" , PCIDevice, cap_present, + QEMU_PCIE_ACS_BITNR, true),This is defined on every PCI device but only xio3130 downstream reads it. I think it is better to limit the scope.
Sure thing.
Quoted 3 lines
Thanks,
Shameer
Thanks.
-Tushar
PATCH 2/3 hw/pci: Expose ACS ctrl on Guest as configured by the HYP
In reply to Tushar DaveFrom: Yishai Hadas <[email protected]>
To support P2P on Guest we must expose to the guest OS the actual PCIe topology and configuration as set by the HYP.
Otherwise, the behavior is considered as un-defined.
It might fail by SW or HW.
Extend both root port and downstream port to get acs ctrl bits that should match the HYP and use them in the guest.
--- hw/pci-bridge/pcie_root_port.c | 10 ++++++++-- hw/pci-bridge/xio3130_downstream.c | 10 ++++++++-- hw/pci/pcie.c | 18 +++++++++++++++--- include/hw/pci/pcie.h | 6 +++--- include/hw/pci/pcie_port.h | 1 + 5 files changed, 35 insertions(+), 10 deletions(-)
hw/pci-bridge/pcie_root_port.c +8 -2
@@ -46,6 +46,7 @@ static void rp_write_config(PCIDevice *d, uint32_t address,static void rp_reset_hold (Object *obj,ResetType type) {PCIDevice *d =PCI_DEVICE (obj); +PCIEPort *p =PCIE_PORT (d);DeviceState *qdev =DEVICE (obj);rp_aer_vector_update (d);
@@ -53,7 +54,7 @@ static void rp_reset_hold(Object *obj, ResetType type)pcie_cap_deverr_reset (d);pcie_cap_slot_reset (d);pcie_cap_arifwd_reset (d); -pcie_acs_reset (d); +pcie_acs_reset (d, p->acs_ctrl);pcie_aer_root_reset (d);pci_bridge_reset (qdev);pci_bridge_disable_base_limit (d);
@@ -118,11 +119,15 @@ static void rp_realize(PCIDevice *d, Error **errp)rp_aer_vector_update (d);if (rpc->acs_offset) { -pcie_acs_init (d, rpc->acs_offset); + rc =pcie_acs_init (d, rpc->acs_offset, p->acs_ctrl, errp); +if (rc <0 ) { + goto err; + } }return ; err: +pcie_aer_exit (d);pcie_chassis_del_slot (s); err_pcie_cap:pcie_cap_exit (d);
@@ -151,6 +156,7 @@ static void rp_exit(PCIDevice *d)static const Property rp_props[] = {DEFINE_PROP_BIT (COMPAT_PROP_PCP , PCIDevice, cap_present,QEMU_PCIE_SLTCAP_PCP_BITNR , true), +DEFINE_PROP_UINT16 ("acs-ctrl" , PCIEPort, acs_ctrl,0 ), };static void rp_instance_post_init (Object *obj)
hw/pci-bridge/xio3130_downstream.c +8 -2
@@ -58,11 +58,12 @@ static void xio3130_downstream_write_config(PCIDevice *d, uint32_t address,static void xio3130_downstream_reset (DeviceState *qdev) {PCIDevice *d =PCI_DEVICE (qdev); +PCIEPort *p =PCIE_PORT (d);pcie_cap_deverr_reset (d);pcie_cap_slot_reset (d);pcie_cap_arifwd_reset (d); -pcie_acs_reset (d); +pcie_acs_reset (d, p->acs_ctrl);pci_bridge_reset (qdev); }
@@ -115,12 +116,16 @@ static void xio3130_downstream_realize(PCIDevice *d, Error **errp) }if (d->cap_present &QEMU_PCIE_CAP_ACS ) { -pcie_acs_init (d,XIO3130_ACS_OFFSET ); + rc =pcie_acs_init (d,XIO3130_ACS_OFFSET , p->acs_ctrl, errp); +if (rc <0 ) { + goto err; + } }return ; err: +pcie_aer_exit (d);pcie_chassis_del_slot (s); err_pcie_cap:pcie_cap_exit (d);
@@ -144,6 +149,7 @@ static void xio3130_downstream_exitfn(PCIDevice *d)static const Property xio3130_downstream_props[] = {DEFINE_PROP_BIT (COMPAT_PROP_PCP , PCIDevice, cap_present,QEMU_PCIE_SLTCAP_PCP_BITNR , true), +DEFINE_PROP_UINT16 ("acs-ctrl" , PCIEPort, acs_ctrl,0 ), };static const VMStateDescription vmstate_xio3130_downstream = {
hw/pci/pcie.c +15 -3
@@ -1260,7 +1260,8 @@ void pcie_ats_init(PCIDevice *dev, uint16_t offset, bool aligned) }/* ACS (Access Control Services) */ -void pcie_acs_init (PCIDevice *dev,uint16_t offset) +int pcie_acs_init (PCIDevice *dev,uint16_t offset,uint16_t ctrl_bits, +Error **errp) {bool is_downstream =pci_is_express_downstream_port (dev);uint16_t cap_bits =0 ;
@@ -1284,16 +1285,27 @@ void pcie_acs_init(PCIDevice *dev, uint16_t offset)*/ cap_bits =PCI_ACS_SV |PCI_ACS_TB |PCI_ACS_RR |PCI_ACS_CR |PCI_ACS_UF |PCI_ACS_DT ; + +if (ctrl_bits & ~cap_bits) { +error_setg (errp, +"Unsupported ACS capabilities 0x%hx were supplied. " +"Supported capabilities are 0x%hx" , + ctrl_bits & ~cap_bits, cap_bits); +return -EINVAL ; + } }pci_set_word (dev->config + offset +PCI_ACS_CAP , cap_bits);pci_set_word (dev->wmask + offset +PCI_ACS_CTRL , cap_bits); +pci_set_word (dev->config + offset +PCI_ACS_CTRL , ctrl_bits); + +return 0 ; } -void pcie_acs_reset (PCIDevice *dev) +void pcie_acs_reset (PCIDevice *dev,uint16_t val) {if (dev->exp.acs_cap) { -pci_set_word (dev->config + dev->exp.acs_cap +PCI_ACS_CTRL ,0 ); +pci_set_word (dev->config + dev->exp.acs_cap +PCI_ACS_CTRL , val); } }
include/hw/pci/pcie.h +3 -3
@@ -137,9 +137,9 @@ bool pcie_insert_capability(PCIDevice *dev, uint16_t cap_id, uint8_t cap_ver, uint16_t offset, uint16_t size);void pcie_sync_bridge_lnk (PCIDevice *dev); -void pcie_acs_init (PCIDevice *dev,uint16_t offset); -void pcie_acs_reset (PCIDevice *dev); - +int pcie_acs_init (PCIDevice *dev,uint16_t offset,uint16_t ctrl_bits, +Error **errp); +void pcie_acs_reset (PCIDevice *dev,uint16_t val);void pcie_ari_init (PCIDevice *dev,uint16_t offset);void pcie_dev_ser_num_init (PCIDevice *dev,uint16_t offset,uint64_t ser_num);void pcie_ats_init (PCIDevice *dev,uint16_t offset,bool aligned);
include/hw/pci/pcie_port.h +1 -0
@@ -36,6 +36,7 @@ struct PCIEPort {/* pci express switch port */ uint8_t port; +uint16_t acs_ctrl; };void pcie_port_init_reg (PCIDevice *d);
Signature · 1 line
2.34.1
RE: [PATCH 2/3] hw/pci: Expose ACS ctrl on Guest as configured by the HYP
Quoted 13 lines
-----Original Message-----
From: Tushar Dave <[email protected]>
Sent: 22 September 2026 22:50
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Yishai Hadas <[email protected]>; Alex Williamson <[email protected]>; Jason Gunthorpe <[email protected]>; Shameer Kolothum Thodi <[email protected]>
Subject: [PATCH 2/3] hw/pci: Expose ACS ctrl on Guest as configured by the HYP
Quoted 4 lines
From: Yishai Hadas <[email protected]>
To support P2P on Guest we must expose to the guest OS the actual PCIe topology and configuration as set by the HYP.
Please use "host" or "hypervisor" instead of HYP
Quoted 4 lines
Otherwise, the behavior is considered as un-defined.
It might fail by SW or HW.
I think this is vague. Please spell out the failure.
Quoted 37 lines
Extend both root port and downstream port to get acs ctrl bits that should match the HYP and use them in the guest.
Signed-off-by Yishai Hadas <[email protected]>Signed-off-by Tushar Dave <[email protected]>--- hw/pci-bridge/pcie_root_port.c | 10 ++++++++-- hw/pci-bridge/xio3130_downstream.c | 10 ++++++++-- hw/pci/pcie.c | 18 +++++++++++++++--- include/hw/pci/pcie.h | 6 +++--- include/hw/pci/pcie_port.h | 1 + 5 files changed, 35 insertions(+), 10 deletions(-)hw/pci-bridge/pcie_root_port.c +1
-0@@ -46,6 +46,7 @@ static void rp_write_config(PCIDevice *d, uint32_t address, static void rp_reset_hold(Object *obj, ResetType type) {PCIDevice *d =PCI_DEVICE (obj); +PCIEPort *p =PCIE_PORT (d);DeviceState *qdev =DEVICE (obj);rp_aer_vector_update(d);hw/pci-bridge/pcie_root_port.c +1
-1@@ -53,7 +54,7 @@ static void rp_reset_hold(Object *obj, ResetType type)pcie_cap_deverr_reset (d);pcie_cap_slot_reset (d);pcie_cap_arifwd_reset (d); -pcie_acs_reset (d); +pcie_acs_reset (d, p->acs_ctrl);pcie_aer_root_reset (d);pci_bridge_reset (qdev);pci_bridge_disable_base_limit (d);
hw/pci-bridge/pcie_root_port.c static void rp_realize(PCIDevice *d, Error **errp) · line 126
Quoted 9 lines
hw/pci-bridge/pcie_root_port.c +4
-1@@ -118,11 +119,15 @@ static void rp_realize(PCIDevice *d, Error **errp)rp_aer_vector_update (d);if (rpc->acs_offset) { -pcie_acs_init (d, rpc->acs_offset); + rc =pcie_acs_init (d, rpc->acs_offset, p->acs_ctrl, errp); +if (rc <0 ) { + goto err; + } }
If acs_offset is 0, there is no ACS capability and acs-ctrl is silently ignored. Please report an error in that case.
Quoted 36 lines
hw/pci-bridge/pcie_root_port.c +2
-0return ; err: +pcie_aer_exit (d);pcie_chassis_del_slot (s); err_pcie_cap:pcie_cap_exit (d);@@ -151,6 +156,7 @@ static void rp_exit(PCIDevice *d)static const Property rp_props[] = {DEFINE_PROP_BIT (COMPAT_PROP_PCP , PCIDevice, cap_present,QEMU_PCIE_SLTCAP_PCP_BITNR , true), +DEFINE_PROP_UINT16 ("acs-ctrl" , PCIEPort, acs_ctrl,0 ), };static void rp_instance_post_init (Object *obj)hw/pci- renamed from hw/pci-bridge/xio3130_downstream.c +0
-0
bridge/xio3130_downstream.c
index87ba30eb36..9829832c39100644hw/pci-bridge/xio3130_downstream.c +2
-1@@ -58,11 +58,12 @@ static void xio3130_downstream_write_config(PCIDevice *d, uint32_t address, static void xio3130_downstream_reset(DeviceState *qdev) {PCIDevice *d =PCI_DEVICE (qdev); +PCIEPort *p =PCIE_PORT (d);pcie_cap_deverr_reset (d);pcie_cap_slot_reset (d);pcie_cap_arifwd_reset (d); -pcie_acs_reset (d); +pcie_acs_reset (d, p->acs_ctrl);pci_bridge_reset (qdev); }
hw/pci-bridge/xio3130_downstream.c static void xio3130_downstream_realize(PCIDevice · line 120
Quoted 6 lines
hw/pci-bridge/xio3130_downstream.c +1
-1@@ -115,12 +116,16 @@ static void xio3130_downstream_realize(PCIDevice *d, Error **errp) }if (d->cap_present &QEMU_PCIE_CAP_ACS ) { -pcie_acs_init (d,XIO3130_ACS_OFFSET ); + rc =pcie_acs_init (d,XIO3130_ACS_OFFSET , p->acs_ctrl, errp);
Same here, with x-pcie-acs=off, acs-ctrl is silently ignored.
Quoted 37 lines
hw/pci-bridge/xio3130_downstream.c +4
-0+if (rc <0 ) { + goto err; + } }return ; err: +pcie_aer_exit (d);pcie_chassis_del_slot (s); err_pcie_cap:pcie_cap_exit(d);hw/pci-bridge/xio3130_downstream.c +1
-0@@ -144,6 +149,7 @@ static void xio3130_downstream_exitfn(PCIDevice *d)static const Property xio3130_downstream_props[] = {DEFINE_PROP_BIT (COMPAT_PROP_PCP , PCIDevice, cap_present,QEMU_PCIE_SLTCAP_PCP_BITNR , true), +DEFINE_PROP_UINT16 ("acs-ctrl" , PCIEPort, acs_ctrl,0 ), };static const VMStateDescription
vmstate_xio3130_downstream= {hw/pci/pcie.c +2
-1@@ -1260,7 +1260,8 @@ void pcie_ats_init(PCIDevice *dev, uint16_t offset, bool aligned) }/* ACS (Access Control Services) */ -void pcie_acs_init (PCIDevice *dev,uint16_t offset) +int pcie_acs_init (PCIDevice *dev,uint16_t offset,uint16_t ctrl_bits, +Error **errp) {bool is_downstream =pci_is_express_downstream_port (dev);uint16_t cap_bits = 0;
hw/pci/pcie.c void pcie_acs_init(PCIDevice *dev, uint16_t · line 1294
Quoted 10 lines
hw/pci/pcie.c +6
-0@@ -1284,16 +1285,27 @@ void pcie_acs_init(PCIDevice *dev, uint16_toffset) */ cap_bits =PCI_ACS_SV |PCI_ACS_TB |PCI_ACS_RR |PCI_ACS_CR |PCI_ACS_UF |PCI_ACS_DT ; + +if (ctrl_bits & ~cap_bits) { +error_setg (errp, +"Unsupported ACS capabilities 0x%hx were supplied. " +"Supported capabilities are 0x%hx" , + ctrl_bits & ~cap_bits, cap_bits);
Nit: maybe "acs-ctrl 0x%hx has bits not supported by this port (supported: 0x%hx)" is clearer.
Thanks,
Shameer
PATCH 3/3 hw/pci: Make ACS Control read-only to guests
In reply to Tushar DaveGPUDirect RDMA using data-direct requires a specific ACS configuration on PCIe Root Ports and Downstream Ports.
While ACS can be configured via QEMU's 'acs-ctrl' property, the guest kernel may overwrite ACS during standard programming.
This change blocks all guest writes to the PCIe ACS Control register and preserves QEMU-provided ACS settings across device resets on PCIe Root Ports and Downstream Ports.
--- hw/pci-bridge/pcie_root_port.c | 3 +- hw/pci-bridge/xio3130_downstream.c | 3 +- hw/pci/pcie.c | 45 ++++++++++++++++++++++++++++-- include/hw/pci/pcie.h | 3 ++ include/hw/pci/pcie_port.h | 1 + 5 files changed, 51 insertions(+), 4 deletions(-)
hw/pci-bridge/pcie_root_port.c +2 -1
@@ -156,7 +156,8 @@ static void rp_exit(PCIDevice *d)static const Property rp_props[] = {DEFINE_PROP_BIT (COMPAT_PROP_PCP , PCIDevice, cap_present,QEMU_PCIE_SLTCAP_PCP_BITNR , true), -DEFINE_PROP_UINT16 ("acs-ctrl" , PCIEPort, acs_ctrl,0 ), +DEFINE_PROP_UNSIGNED_NODEFAULT ("acs-ctrl" , PCIEPort, acs_ctrl, + qdev_prop_acs_ctrl, uint16_t), };static void rp_instance_post_init (Object *obj)
hw/pci-bridge/xio3130_downstream.c +2 -1
@@ -149,7 +149,8 @@ static void xio3130_downstream_exitfn(PCIDevice *d)static const Property xio3130_downstream_props[] = {DEFINE_PROP_BIT (COMPAT_PROP_PCP , PCIDevice, cap_present,QEMU_PCIE_SLTCAP_PCP_BITNR , true), -DEFINE_PROP_UINT16 ("acs-ctrl" , PCIEPort, acs_ctrl,0 ), +DEFINE_PROP_UNSIGNED_NODEFAULT ("acs-ctrl" , PCIEPort, acs_ctrl, + qdev_prop_acs_ctrl, uint16_t), };static const VMStateDescription vmstate_xio3130_downstream = {
hw/pci/pcie.c +43 -2
69 lines not on this page · raw message
include/hw/pci/pcie.h +3 -0
@@ -26,6 +26,7 @@#include "hw/pci/pcie_aer.h" #include "hw/pci/pcie_sriov.h" #include "hw/core/hotplug.h" +#include "hw/core/qdev-properties.h" typedef struct PCIEPort PCIEPort ;typedef struct PCIESlot PCIESlot ;
@@ -86,6 +87,8 @@ struct PCIExpressDevice {#define COMPAT_PROP_PCP "power_controller_present" +extern const PropertyInfo qdev_prop_acs_ctrl; +/* PCI express capability helper functions */ int pcie_cap_init (PCIDevice *dev,uint8_t offset,uint8_t type,uint8_t port,Error **errp);
include/hw/pci/pcie_port.h +1 -0
@@ -37,6 +37,7 @@ struct PCIEPort {/* pci express switch port */ uint8_t port;uint16_t acs_ctrl; +bool acs_ctrl_configured; };void pcie_port_init_reg (PCIDevice *d);
Signature · 1 line
2.34.1
RE: [PATCH 3/3] hw/pci: Make ACS Control read-only to guests
Quoted 67 lines
-----Original Message-----
From: Tushar Dave <[email protected]>
Sent: 22 September 2026 22:50
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; Yishai Hadas <[email protected]>; Alex Williamson <[email protected]>; Jason Gunthorpe <[email protected]>; Shameer Kolothum Thodi <[email protected]>
Subject: [PATCH 3/3] hw/pci: Make ACS Control read-only to guestsGPUDirect RDMA using data-direct requires a specific ACS configuration on PCIe Root Ports and Downstream Ports.
While ACS can be configured via QEMU's 'acs-ctrl' property, the guest kernel may overwrite ACS during standard programming.
This change blocks all guest writes to the PCIe ACS Control register and preserves QEMU-provided ACS settings across device resets on PCIe Root Ports
and Downstream Ports.Signed-off-by Tushar Dave <[email protected]>--- hw/pci-bridge/pcie_root_port.c | 3 +- hw/pci-bridge/xio3130_downstream.c | 3 +- hw/pci/pcie.c | 45 ++++++++++++++++++++++++++++-- include/hw/pci/pcie.h | 3 ++ include/hw/pci/pcie_port.h | 1 + 5 files changed, 51 insertions(+), 4 deletions(-)hw/pci-bridge/pcie_root_port.c +2
-1@@ -156,7 +156,8 @@ static void rp_exit(PCIDevice *d)static const Property rp_props[] = {DEFINE_PROP_BIT (COMPAT_PROP_PCP , PCIDevice, cap_present,QEMU_PCIE_SLTCAP_PCP_BITNR , true), -DEFINE_PROP_UINT16 ("acs-ctrl" , PCIEPort, acs_ctrl,0 ), +DEFINE_PROP_UNSIGNED_NODEFAULT ("acs-ctrl" , PCIEPort, acs_ctrl, + qdev_prop_acs_ctrl, uint16_t), };static void rp_instance_post_init (Object *obj)hw/pci- renamed from hw/pci-bridge/xio3130_downstream.c +0
-0
bridge/xio3130_downstream.c
index9829832c39..e8717be73a100644hw/pci-bridge/xio3130_downstream.c +2
-1@@ -149,7 +149,8 @@ static void xio3130_downstream_exitfn(PCIDevice *d)static const Property xio3130_downstream_props[] = {DEFINE_PROP_BIT (COMPAT_PROP_PCP , PCIDevice, cap_present,QEMU_PCIE_SLTCAP_PCP_BITNR , true), -DEFINE_PROP_UINT16 ("acs-ctrl" , PCIEPort, acs_ctrl,0 ), +DEFINE_PROP_UNSIGNED_NODEFAULT ("acs-ctrl" , PCIEPort, acs_ctrl, + qdev_prop_acs_ctrl, uint16_t), };static const VMStateDescription
vmstate_xio3130_downstream= {hw/pci/pcie.c +0
-0
hw/pci/pcie.c int pcie_acs_init(PCIDevice *dev, uint16_t offset, · line 1269
Quoted 5 lines
hw/pci/pcie.c +1
-0@@ -1265,6 +1265,8 @@ int pcie_acs_init(PCIDevice *dev, uint16_t offset,uint16_t ctrl_bits, { bool is_downstream = pci_is_express_downstream_port(dev);uint16_t cap_bits =0 ; +PCIEPort *p =PCIE_PORT (dev);
This is a common helper. PCIE_PORT() will fail if a non-port dev is passed.
Quoted 53 lines
hw/pci/pcie.c +1
-0+bool configured = p->acs_ctrl_configured;/* For endpoints, only multifunction devs may have an ACS capability: */ assert(is_downstream ||hw/pci/pcie.c +1
-1@@ -1286,7 +1288,7 @@ int pcie_acs_init(PCIDevice *dev, uint16_t offset,uint16_t ctrl_bits, cap_bits =PCI_ACS_SV |PCI_ACS_TB |PCI_ACS_RR |PCI_ACS_CR |PCI_ACS_UF |PCI_ACS_DT ; -if (ctrl_bits & ~cap_bits) { +if (configured && (ctrl_bits & ~cap_bits)) {error_setg (errp, "Unsupported ACS capabilities 0x%hx were supplied. ""Supported capabilities are 0x%hx",hw/pci/pcie.c +11
-1@@ -1296,7 +1298,17 @@ int pcie_acs_init(PCIDevice *dev, uint16_t offset, uint16_t ctrl_bits, }pci_set_word (dev->config + offset +PCI_ACS_CAP , cap_bits); -pci_set_word (dev->wmask + offset +PCI_ACS_CTRL , cap_bits); + +if (is_downstream && configured) { +/* +* Block guest writes to ACS Control entirely to preserve QEMU +* ACS settings +*/ +pci_set_word (dev->wmask + offset +PCI_ACS_CTRL ,0 ); + }else { +pci_set_word (dev->wmask + offset +PCI_ACS_CTRL , cap_bits); + } +pci_set_word (dev->config + offset +PCI_ACS_CTRL , ctrl_bits);return 0;hw/pci/pcie.c +15
-0@@ -1309,6 +1321,35 @@ void pcie_acs_reset(PCIDevice *dev, uint16_t val) } } +static void set_acs_ctrl (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp) +{ +PCIEPort *p =PCIE_PORT (obj); +const Property *prop = opaque; +uint16_t *ptr =object_field_prop_ptr (obj, prop); + +if (!visit_type_uint16 (v, name, ptr, errp)) { +return ; + } + p->acs_ctrl_configured = true; +} + +static void get_acs_ctrl (Object *obj,Visitor *v,const char *name, +void *opaque,Error **errp)
hw/pci/pcie.c void pcie_acs_reset(PCIDevice *dev, uint16_t val) · line 1348
Quoted 10 lines
hw/pci/pcie.c +10
-0+{ +const Property *prop = opaque; +uint16_t *ptr =object_field_prop_ptr (obj, prop); + +visit_type_uint16 (v, name, ptr, errp); +} + +const PropertyInfo qdev_prop_acs_ctrl = { + .type ="uint16" , + .description ="PCIe ACS ctrl configuration (unset = not configured)" ,
Please also say here that setting this, even to 0, makes ACS Control read only to the guest.
Thanks,
Shameer