Hi Jim,

On Thu, Oct 29, 2026 at 03:05:11PM +0000, Jim MacArthur wrote:
> From: Pierrick Bouvier <[email protected]>
> 
> Adds the TEE flag in the legacy config space, and the IDE
> (Integrity & Data Encryption) extended capability. These
> will be present when rme-cap=on is specified for the
> pcie-root-port device.

This commit message needs some enhancement.

First, it ideally should mention the reason/effect for setting the TEE-IO and
advertising the IDE cap, explaining why it's required. For instance, say
that they go together because both are pieces of PCIe TEE-IO, the framework for
assigning a device directly to a confidential VM, and that, accordingly to the
spec, the TEE-IO presence requires IDE, as per ยง11.3.29.3 Securing Interconnects
(I'm looking at spec rev. 7), which reads:

"TEE-I/O capable devices must support Integrity and Data Encryption (IDE) to
protect transactions on the interconnect between the device and the Root
Complex. Devices must support selective IDE streams between the Root Complex and
the device."

Second, I think legacy word should be dropped here and in all other parts of the
patch below because I consider it misleading. The first 256 bytes are still
present in the PCIe spec rev. 7. I'm aware the spec mentions this area as
"available on legacy OSs" so accessible from the CAM mechanism, but from a PCIe
device pov it's simply a the PCI Configuration Space. Moreover, the TEE-IO bit
is in that space and TEE-IO is a quite recent addition to the PCIe spec, hence
it's odd to say a bit related to a new feature like this is being set in a
legacy configuration space.

Also, rme-cap=on is not good, as Jonathan said, because we're in the PCIe
context, so it's not restrict to the Arm arch. I think "tee-io=[on/off]" would
fit better, or even "x-tee-io" if we are experimenting with it and not so sure
how the flag would be called at the end.

ah, and although here it says "rme-cap=on" the prop. being added below is
actually "rme-caps".


> Signed-off-by: Pierrick Bouvier <[email protected]>
> Signed-off-by: Jim MacArthur <Jim [email protected]>

nit: email seems ruined here ------^


> ---
>  hw/pci-bridge/gen_pcie_root_port.c | 21 ++++++++++++++++++++-
>  hw/pci/pcie.c                      | 19 +++++++++++++++++++
>  include/hw/pci/pcie.h              |  3 +++
>  include/hw/pci/pcie_regs.h         |  4 ++++
>  4 files changed, 46 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/pci-bridge/gen_pcie_root_port.c 
> b/hw/pci-bridge/gen_pcie_root_port.c
> index 5434d693d9..ab8087da87 100644
> --- a/hw/pci-bridge/gen_pcie_root_port.c
> +++ b/hw/pci-bridge/gen_pcie_root_port.c
> @@ -26,13 +26,16 @@ OBJECT_DECLARE_SIMPLE_TYPE(GenPCIERootPort, 
> GEN_PCIE_ROOT_PORT)
>  #define GEN_PCIE_ROOT_PORT_AER_OFFSET           0x100
>  #define GEN_PCIE_ROOT_PORT_ACS_OFFSET \
>          (GEN_PCIE_ROOT_PORT_AER_OFFSET + PCI_ERR_SIZEOF)
> -
> +#define GEN_PCIE_ROOT_PORT_ACS_END \
> +        (GEN_PCIE_ROOT_PORT_ACS_OFFSET + PCI_ACS_SIZEOF)
>  #define GEN_PCIE_ROOT_PORT_MSIX_NR_VECTOR       1
>  #define GEN_PCIE_ROOT_DEFAULT_IO_RANGE          4096
>  
>  struct GenPCIERootPort {
>      /*< private >*/
>      PCIESlot parent_obj;
> +    bool     rme_caps;
> +
>      /*< public >*/
>  
>      /* additional resources to reserve */
> @@ -71,6 +74,7 @@ static void gen_rp_realize(DeviceState *dev, Error **errp)
>      GenPCIERootPort *grp = GEN_PCIE_ROOT_PORT(d);
>      PCIERootPortClass *rpc = PCIE_ROOT_PORT_GET_CLASS(d);
>      Error *local_err = NULL;
> +    uint32_t next_cap_offset = GEN_PCIE_ROOT_PORT_ACS_END;
>  
>      rpc->parent_realize(dev, &local_err);
>      if (local_err) {
> @@ -100,6 +104,19 @@ static void gen_rp_realize(DeviceState *dev, Error 
> **errp)
>          d->wmask[PCI_IO_BASE] = 0;
>          d->wmask[PCI_IO_LIMIT] = 0;
>      }
> +
> +    if (grp->rme_caps) {

See my comment on using rme, which is Arm-specific.


> +        pcie_ide_init(d, next_cap_offset);
> +
> +        /* Unused value, but may be useful for the next capability */
> +        next_cap_offset += PCI_IDE_SIZEOF;
> +
> +        /*
> +         * Set up TEE (in the legacy config space, not an extended
> +         * capability)
> +         */
> +        pcie_cap_tee_init(d);
> +    }
>  }
>  
>  static const VMStateDescription vmstate_rp_dev = {
> @@ -133,6 +150,8 @@ static const Property gen_rp_props[] = {
>                                  speed, PCIE_LINK_SPEED_16),
>      DEFINE_PROP_PCIE_LINK_WIDTH("x-width", PCIESlot,
>                                  width, PCIE_LINK_WIDTH_32),
> +    DEFINE_PROP_BOOL("rme-caps", GenPCIERootPort,
> +                     rme_caps, false),
>  };
>  
>  static void gen_rp_dev_class_init(ObjectClass *klass, const void *data)
> diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
> index 42c4997b42..bf2c184cfc 100644
> --- a/hw/pci/pcie.c
> +++ b/hw/pci/pcie.c
> @@ -968,6 +968,16 @@ void pcie_cap_flr_write_config(PCIDevice *dev,
>      }
>  }
>  
> +/*
> + * Set PCI_EXP_DEVCAP_TEE flag in the PCI Express Capability Structure
> + * (in legacy config space) indicating that we support TEE-IO.
> + */
> +void pcie_cap_tee_init(PCIDevice *dev)
> +{
> +    pci_long_test_and_set_mask(dev->config + dev->exp.exp_cap + 
> PCI_EXP_DEVCAP,
> +                               PCI_EXP_DEVCAP_TEE);
> +}
> +
>  /* Alternative Routing-ID Interpretation (ARI)
>   * forwarding support for root and downstream ports
>   */
> @@ -1387,6 +1397,15 @@ uint32_t pcie_pri_get_req_alloc(const PCIDevice *dev)
>      return pci_get_long(dev->config + dev->exp.pri_cap + PCI_PRI_ALLOC_REQ);
>  }
>  
> +/* IDE (Integrity & Data Encryption) */
> +void pcie_ide_init(PCIDevice *dev, uint16_t offset)
> +{
> +    pcie_add_capability(dev, PCI_EXT_CAP_ID_IDE, PCI_IDE_VER,
> +                        offset, PCI_IDE_SIZEOF);
> +    uint32_t cap = PCI_IDE_CAP_SELECTIVE;
> +    pci_set_byte(dev->config + offset + PCI_IDE_CAP, cap);

I would set PCI_IDE_CAP_SELECTIVE directly and avoid 'cap' var here.


Cheers,
Gustavo

> +}
> +
>  bool pcie_pri_enabled(const PCIDevice *dev)
>  {
>      if (!pci_is_express(dev) || !dev->exp.pri_cap) {
> diff --git a/include/hw/pci/pcie.h b/include/hw/pci/pcie.h
> index 86c29f7d8b..6c02c846df 100644
> --- a/include/hw/pci/pcie.h
> +++ b/include/hw/pci/pcie.h
> @@ -123,6 +123,8 @@ void pcie_cap_flr_init(PCIDevice *dev);
>  void pcie_cap_flr_write_config(PCIDevice *dev,
>                             uint32_t addr, uint32_t val, int len);
>  
> +void pcie_cap_tee_init(PCIDevice *dev);
> +
>  /* ARI forwarding capability and control */
>  void pcie_cap_arifwd_init(PCIDevice *dev);
>  void pcie_cap_arifwd_reset(PCIDevice *dev);
> @@ -165,6 +167,7 @@ void pcie_pasid_init(PCIDevice *dev, uint16_t offset, 
> uint8_t pasid_width,
>                       bool exec_perm, bool priv_mod);
>  void pcie_pri_init(PCIDevice *dev, uint16_t offset, uint32_t 
> outstanding_pr_cap,
>                     bool prg_response_pasid_req);
> +void pcie_ide_init(PCIDevice *dev, uint16_t offset);
>  
>  uint32_t pcie_pri_get_req_alloc(const PCIDevice *dev);
>  bool pcie_pri_enabled(const PCIDevice *dev);
> diff --git a/include/hw/pci/pcie_regs.h b/include/hw/pci/pcie_regs.h
> index 33a22229fe..aa21177411 100644
> --- a/include/hw/pci/pcie_regs.h
> +++ b/include/hw/pci/pcie_regs.h
> @@ -182,4 +182,8 @@ typedef enum PCIExpLinkWidth {
>  #define PCI_DOE_VER                     0x1
>  #define PCI_DOE_SIZEOF                  24
>  
> +/* IDE */
> +#define PCI_IDE_VER                     0x1
> +#define PCI_IDE_SIZEOF                  12
> +
>  #endif /* QEMU_PCIE_REGS_H */
> 
> -- 
> 2.43.0
> 
> 


Reply via email to