From: Yi Liu <yi.l.liu@intel.com>
To: Shameer Kolothum <skolothumtho@nvidia.com>,
"qemu-arm@nongnu.org" <qemu-arm@nongnu.org>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Cc: "eric.auger@redhat.com" <eric.auger@redhat.com>,
"peter.maydell@linaro.org" <peter.maydell@linaro.org>,
Jason Gunthorpe <jgg@nvidia.com>,
Nicolin Chen <nicolinc@nvidia.com>,
"ddutile@redhat.com" <ddutile@redhat.com>,
"berrange@redhat.com" <berrange@redhat.com>,
"clg@redhat.com" <clg@redhat.com>,
"alex@shazbot.org" <alex@shazbot.org>,
Nathan Chen <nathanc@nvidia.com>, Matt Ochs <mochs@nvidia.com>,
"smostafa@google.com" <smostafa@google.com>,
"wangzhou1@hisilicon.com" <wangzhou1@hisilicon.com>,
"jiangkunkun@huawei.com" <jiangkunkun@huawei.com>,
"jonathan.cameron@huawei.com" <jonathan.cameron@huawei.com>,
"zhangfei.gao@linaro.org" <zhangfei.gao@linaro.org>,
"zhenzhong.duan@intel.com" <zhenzhong.duan@intel.com>,
Krishnakant Jaju <kjaju@nvidia.com>,
"Michael S . Tsirkin" <mst@redhat.com>
Subject: Re: [PATCH v9 34/37] hw/pci: Add helper to insert PCIe extended capability at a fixed offset
Date: Tue, 27 Jan 2026 11:03:03 +0800 [thread overview]
Message-ID: <b520ea7e-3a41-4193-ba8c-4df73a67dce8@intel.com> (raw)
In-Reply-To: <CH3PR12MB75481EF03A19B7DAFD9EA25FAB93A@CH3PR12MB7548.namprd12.prod.outlook.com>
On 2026/1/26 22:17, Shameer Kolothum wrote:
> Hi Yi,
>
>>> +/*
>>> + * Insert a PCIe extended capability at a given offset.
>>> + *
>>> + * This helper only validates that the insertion does not overwrite an
>>> + * existing PCIe extended capability header, as corrupting a header would
>>> + * break the extended capability linked list.
>>> + *
>>> + * The caller must ensure that (offset, size) does not overlap with other
>>> + * registers or capability-specific register blocks. Overlaps with
>>> + * capability-specific registers are not checked and are considered a
>>> + * user-controlled override.
>>> + *
>>> + * Note: Best effort helper. The PCIe spec does not require extended
>>> + * capabilities to be ordered, but most devices use a forward-linked list.
>>> + * Devices that do not consistently use a forward-linked list may cause
>>> + * insertion to fail.
>>> + */
>>> +bool pcie_insert_capability(PCIDevice *dev, uint16_t cap_id, uint8_t
>> cap_ver,
>>> + uint16_t offset, uint16_t size)
>>> +{
>>> + uint16_t pos = PCI_CONFIG_SPACE_SIZE, prev = 0;
>>> + uint32_t header;
>>> +
>>> + assert(pci_is_express(dev));
>>> +
>>> + if (!QEMU_IS_ALIGNED(offset, PCI_EXT_CAP_ALIGN) ||
>>> + size < 8 ||
>>> + offset < PCI_CONFIG_SPACE_SIZE ||
>>> + offset >= PCIE_CONFIG_SPACE_SIZE ||
>>> + offset + size > PCIE_CONFIG_SPACE_SIZE) {
>>> + return false;
>>> + }
>>> +
>>> + header = pci_get_long(dev->config + pos);
>>> + if (!header) {
>>> + /* No extended capability present, insertion must be at the ECAP head
>> */
>>> + if (offset != pos) {
>>> + return false;
>>> + }
>>> + pci_set_long(dev->config + pos, PCI_EXT_CAP(cap_id, cap_ver, 0));
>>> + goto out;
>>> + }
>>> +
>>> + while (header && pos && offset >= pos) {
>>> + uint16_t next = PCI_EXT_CAP_NEXT(header);
>>> +
>>> + /* Reject insertion inside an existing ECAP header (4 bytes) */
>>> + if (offset < pos + PCI_EXT_CAP_ALIGN) {
>>> + return false;
>>> + }
>>
>> TBH. I was expecting to see a table that is similar with
>> pci_ext_cap_length[][1], and a helper to walk the ext cap list
>> to figure out the spared pos. But it might be over-enginering as
>> we rely more on user to give an offset that is for sure no conflict
>> with existing ecaps nor hidden registers. Could you also add a comment
>> in the code to note it?
>>
>> [1]
>> https://github.com/torvalds/linux/blob/63804fed149a6750ffd28610c5c1c9
>> 8cce6bd377/drivers/vfio/pci/vfio_pci_config.c#L71
>>
>> With the above nit, LGTM.
>>
>> Reviewed-by: Yi Liu <yi.l.liu@intel.com>
>
> Thanks.
>
> Yes, the helper depends on the caller to provide a suitable offset, since
> it's not generally possible to validate this due to hidden registers and
> device specific capability layouts, and this is already noted in the commit
> log and function comment.
>
> If you had a specific wording in mind that would make this clearer, please
> let me know and I can incorporate it if this requires a respin.
no respin needed. Just noticed the comment in the function header is
enough. :)
next prev parent reply other threads:[~2026-01-27 2:56 UTC|newest]
Thread overview: 68+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-26 10:42 [PATCH v9 00/37] hw/arm/virt: Add support for user-creatable accelerated SMMUv3 Shameer Kolothum
2026-01-26 10:42 ` [PATCH v9 01/37] backends/iommufd: Introduce iommufd_backend_alloc_viommu Shameer Kolothum
2026-01-26 12:06 ` Yi Liu
2026-01-26 10:42 ` [PATCH v9 02/37] backends/iommufd: Introduce iommufd_backend_alloc_vdev Shameer Kolothum
2026-01-26 12:06 ` Yi Liu
2026-01-26 10:43 ` [PATCH v9 03/37] hw/arm/smmu-common: Factor out common helper functions and export Shameer Kolothum
2026-01-26 10:43 ` [PATCH v9 04/37] hw/arm/smmu-common: Make iommu ops part of SMMUState Shameer Kolothum
2026-01-26 10:43 ` [PATCH v9 05/37] hw/arm/smmuv3-accel: Introduce smmuv3 accel device Shameer Kolothum
2026-01-26 10:43 ` [PATCH v9 06/37] hw/arm/smmuv3-accel: Initialize shared system address space Shameer Kolothum
2026-01-26 10:43 ` [PATCH v9 07/37] hw/pci/pci: Move pci_init_bus_master() after adding device to bus Shameer Kolothum
2026-01-26 12:06 ` Yi Liu
2026-01-26 10:43 ` [PATCH v9 08/37] hw/pci/pci: Add optional supports_address_space() callback Shameer Kolothum
2026-01-26 12:06 ` Yi Liu
2026-01-26 10:43 ` [PATCH v9 09/37] hw/pci-bridge/pci_expander_bridge: Move TYPE_PXB_PCIE_DEV to header Shameer Kolothum
2026-01-26 12:06 ` Yi Liu
2026-01-26 10:43 ` [PATCH v9 10/37] hw/arm/smmuv3-accel: Restrict accelerated SMMUv3 to vfio-pci endpoints with iommufd Shameer Kolothum
2026-01-26 10:43 ` [PATCH v9 11/37] hw/arm/smmuv3: Implement get_viommu_cap() callback Shameer Kolothum
2026-01-26 10:43 ` [PATCH v9 12/37] hw/arm/smmuv3-accel: Add set/unset_iommu_device callback Shameer Kolothum
2026-04-15 13:02 ` Anton Kuchin
2026-04-15 14:59 ` Shameer Kolothum Thodi
2026-04-15 16:18 ` Anton Kuchin
2026-04-15 17:49 ` Shameer Kolothum Thodi
2026-01-26 10:43 ` [PATCH v9 13/37] hw/arm/smmuv3: propagate smmuv3_cmdq_consume() errors to caller Shameer Kolothum
2026-01-26 10:43 ` [PATCH v9 14/37] hw/arm/smmuv3-accel: Add nested vSTE install/uninstall support Shameer Kolothum
2026-01-26 10:43 ` [PATCH v9 15/37] hw/arm/smmuv3-accel: Install SMMUv3 GBPA based hwpt Shameer Kolothum
2026-01-26 10:43 ` [PATCH v9 16/37] hw/pci/pci: Introduce a callback to retrieve the MSI doorbell GPA directly Shameer Kolothum
2026-01-26 10:43 ` [PATCH v9 17/37] hw/arm/smmuv3-accel: Implement get_msi_direct_gpa callback Shameer Kolothum
2026-01-26 10:43 ` [PATCH v9 18/37] hw/arm/virt: Set msi-gpa property Shameer Kolothum
2026-01-26 10:43 ` [PATCH v9 19/37] hw/arm/smmuv3-accel: Add support to issue invalidation cmd to host Shameer Kolothum
2026-01-26 10:43 ` [PATCH v9 20/37] hw/arm/smmuv3: Initialize ID registers early during realize() Shameer Kolothum
2026-01-26 10:43 ` [PATCH v9 21/37] hw/arm/smmuv3-accel: Get host SMMUv3 hw info and validate Shameer Kolothum
2026-01-26 10:43 ` [PATCH v9 22/37] hw/pci-host/gpex: Allow to generate preserve boot config DSM #5 Shameer Kolothum
2026-01-26 10:43 ` [PATCH v9 23/37] hw/arm/virt: Set PCI preserve_config for accel SMMUv3 Shameer Kolothum
2026-01-26 10:43 ` [PATCH v9 24/37] tests/qtest/bios-tables-test: Prepare for IORT revison upgrade Shameer Kolothum
2026-01-26 10:43 ` [PATCH v9 25/37] hw/arm/virt-acpi-build: Add IORT RMR regions to handle MSI nested binding Shameer Kolothum
2026-01-26 10:43 ` [PATCH v9 26/37] tests/qtest/bios-tables-test: Update IORT blobs after revision upgrade Shameer Kolothum
2026-01-26 10:43 ` [PATCH v9 27/37] hw/arm/smmuv3: Block migration when accel is enabled Shameer Kolothum
2026-01-26 10:43 ` [PATCH v9 28/37] hw/arm/smmuv3: Add accel property for SMMUv3 device Shameer Kolothum
2026-01-26 10:43 ` [PATCH v9 29/37] hw/arm/smmuv3-accel: Add a property to specify RIL support Shameer Kolothum
2026-01-26 10:43 ` [PATCH v9 30/37] hw/arm/smmuv3-accel: Add support for ATS Shameer Kolothum
2026-01-26 10:43 ` [PATCH v9 31/37] hw/arm/smmuv3-accel: Add property to specify OAS bits Shameer Kolothum
2026-02-02 14:39 ` Eric Auger
2026-02-02 15:11 ` Shameer Kolothum Thodi
2026-02-02 15:19 ` Jason Gunthorpe
2026-02-02 15:38 ` Shameer Kolothum Thodi
2026-02-02 16:00 ` Jason Gunthorpe
2026-02-02 16:03 ` Shameer Kolothum Thodi
2026-02-10 15:12 ` Shameer Kolothum Thodi
2026-02-10 16:01 ` Eric Auger
2026-02-10 16:08 ` Shameer Kolothum Thodi
2026-03-04 7:47 ` Eric Auger
2026-03-04 8:26 ` Shameer Kolothum Thodi
2026-03-04 16:37 ` Eric Auger
2026-02-02 15:29 ` Eric Auger
2026-01-26 10:43 ` [PATCH v9 32/37] backends/iommufd: Retrieve PASID width from iommufd_backend_get_device_info() Shameer Kolothum
2026-01-26 12:06 ` Yi Liu
2026-01-26 10:43 ` [PATCH v9 33/37] backends/iommufd: Add get_pasid_info() callback Shameer Kolothum
2026-01-26 12:06 ` Yi Liu
2026-01-26 10:43 ` [PATCH v9 34/37] hw/pci: Add helper to insert PCIe extended capability at a fixed offset Shameer Kolothum
2026-01-26 12:07 ` Yi Liu
2026-01-26 14:17 ` Shameer Kolothum
2026-01-27 3:03 ` Yi Liu [this message]
2026-01-26 10:43 ` [PATCH v9 35/37] hw/pci: Factor out common PASID capability initialization Shameer Kolothum
2026-01-26 12:07 ` Yi Liu
2026-01-26 10:43 ` [PATCH v9 36/37] hw/vfio/pci: Synthesize PASID capability for vfio-pci devices Shameer Kolothum
2026-01-26 12:07 ` Yi Liu
2026-01-26 10:43 ` [PATCH v9 37/37] hw/arm/smmuv3-accel: Make SubstreamID support configurable Shameer Kolothum
2026-01-26 14:56 ` [PATCH v9 00/37] hw/arm/virt: Add support for user-creatable accelerated SMMUv3 Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b520ea7e-3a41-4193-ba8c-4df73a67dce8@intel.com \
--to=yi.l.liu@intel.com \
--cc=alex@shazbot.org \
--cc=berrange@redhat.com \
--cc=clg@redhat.com \
--cc=ddutile@redhat.com \
--cc=eric.auger@redhat.com \
--cc=jgg@nvidia.com \
--cc=jiangkunkun@huawei.com \
--cc=jonathan.cameron@huawei.com \
--cc=kjaju@nvidia.com \
--cc=mochs@nvidia.com \
--cc=mst@redhat.com \
--cc=nathanc@nvidia.com \
--cc=nicolinc@nvidia.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=skolothumtho@nvidia.com \
--cc=smostafa@google.com \
--cc=wangzhou1@hisilicon.com \
--cc=zhangfei.gao@linaro.org \
--cc=zhenzhong.duan@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.