(v)PCI: extended capability handling
v2 cover (v)PCI: extended capability handling
This is a follow-on to 'vPCI: avoid bogus "overlap in extended cap list" warnings', addressing further issues noted there.
v2: New first patch and significantly re-worked 2nd one. See there.
1: PCI: handle PCI->PCIe bridges as well in alloc_pdev() 2: PCI: determine whether a device has extended config space 3: PCI: don't look for ext-caps when there's no extended cfg space 4: vPCI/DomU: really no ext-caps without extended config space
Jan
PATCH v2 1/4 PCI: handle PCI->PCIe bridges as well in alloc_pdev()
It's not clear why the enumerator was omitted, as these clearly shouldn't take the "default" path (issuing a warning). Handle them the same as legacy and PCIe->PCI bridges.
---
v2: New.
xen/drivers/passthrough/pci.c +1 -0
@@ -351,6 +351,7 @@ static struct pci_dev *alloc_pdev(structunsigned long flags;case DEV_TYPE_PCIe2PCI_BRIDGE: +case DEV_TYPE_PCI2PCIe_BRIDGE:case DEV_TYPE_LEGACY_PCI_BRIDGE : sec_bus =pci_conf_read8 (pdev->sbdf,PCI_SECONDARY_BUS ); sub_bus =pci_conf_read8 (pdev->sbdf,PCI_SUBORDINATE_BUS );
Re: [PATCH v2 1/4] PCI: handle PCI->PCIe bridges as well in alloc_pdev()
Quoted 6 lines · Jan Beulich
It's not clear why the enumerator was omitted, as these clearly shouldn't take the "default" path (issuing a warning). Handle them the same as legacy and
PCIe->PCIbridges.Fixes e7e08d86ad2f ("IOMMU/PCI: consolidate pdev_type() and cache its result for a given device")Signed-off-by Jan Beulich <[email protected]>
Re: [PATCH v2 1/4] PCI: handle PCI->PCIe bridges as well in alloc_pdev()
In reply to Jan BeulichQuoted 6 lines · Jan Beulich
It's not clear why the enumerator was omitted, as these clearly shouldn't take the "default" path (issuing a warning). Handle them the same as legacy and
PCIe->PCIbridges.Fixes e7e08d86ad2f ("IOMMU/PCI: consolidate pdev_type() and cache its result for a given device")Signed-off-by Jan Beulich <[email protected]>
Thanks, Roger.
PATCH v2 2/4 PCI: determine whether a device has extended config space
In reply to Jan BeulichLegacy PCI devices don't have any extended config space. Reading any part thereof may return all ones or other arbitrary data, e.g. in some cases base config space contents repeatedly.
Logic follows Linux 6.19-rc's pci_cfg_space_size(), albeit leveraging our determination of device type; in particular some comments are taken verbatim from there.
---
Should we skip re-evaluation when pci_mmcfg_arch_enable() takes its early exit path?
The warning near the bottom of pci_check_extcfg() may be issued multiple times for a single device now. Should we try to avoid that?
Note that no vPCI adjustments are done here, but they're going to be
needed: Whatever requires extended capabilities will need re- evaluating / newly establishing / tearing down in case an invocation of PHYSDEVOP_pci_mmcfg_reserved alters global state.
Linux also has CONFIG_PCI_QUIRKS, allowing to compile out the slightly risky code (as reads may in principle have side effects). Should we gain such, too?
---
v2: Major re-work to also check upon PHYSDEVOP_pci_mmcfg_reserved
invocation.
xen/arch/x86/physdev.c +18 -0
@@ -22,6 +22,8 @@ int physdev_map_pirq(struct domain *d, i struct msi_info *msi);int physdev_unmap_pirq (struct domain *d,int pirq); +int cf_check physdev_check_pci_extcfg(struct pci_dev *pdev, void *arg); +#include "x86_64/mmconfig.h" #ifndef COMPAT
@@ -160,6 +162,17 @@ int physdev_unmap_pirq(struct domain *d,return ret; } + +int cf_check physdev_check_pci_extcfg(struct pci_dev *pdev, void *arg) +{ +const struct physdev_pci_mmcfg_reserved *info = arg; + +ASSERT (pdev->seg == info->segment); +if ( pdev->bus >= info->start_bus && pdev->bus <= info->end_bus ) +pci_check_extcfg (pdev); + +return 0 ; +}#endif /* COMPAT */ ret_t do_physdev_op (int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg)
@@ -511,6 +524,11 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_H ret =pci_mmcfg_reserved (info.address, info.segment, info.start_bus, info.end_bus, info.flags); + +if ( !ret ) + ret =pci_segment_iterate (info.segment, physdev_check_pci_extcfg, + &info); +if ( !ret &&has_vpci (currd) && (info.flags &XEN_PCI_MMCFG_RESERVED ) ) {/*
xen/drivers/passthrough/pci.c +100 -0
124 lines not on this page · raw message
xen/include/xen/pci.h +9 -0
@@ -126,6 +126,9 @@ struct pci_dev {nodeid_t node;/* NUMA node */ +/* Whether the device has (accessible) extended config space. */ +bool ext_cfg; +/* Device to be quarantined, don't automatically re-assign to dom0 */ bool quarantine;
@@ -242,6 +245,11 @@ void pci_check_disable_device(u16 seg, uint pci_iterate_devices (int (*handler)(struct pci_dev *pdev,void *arg),void *arg); +/* Iterate a single PCI segment, with locking but without preemption. */ +int pci_segment_iterate (unsigned int segment, +int (*handler)(struct pci_dev *pdev,void *arg), +void *arg); +uint8_t pci_conf_read8 (pci_sbdf_t sbdf,unsigned int reg);uint16_t pci_conf_read16 (pci_sbdf_t sbdf,unsigned int reg);uint32_t pci_conf_read32 (pci_sbdf_t sbdf,unsigned int reg);
@@ -260,6 +268,7 @@ unsigned int pci_find_next_cap_ttl(pci_s unsigned int *ttl);unsigned int pci_find_next_cap (pci_sbdf_t sbdf,unsigned int pos,unsigned int cap); +void pci_check_extcfg (struct pci_dev *pdev);unsigned int pci_find_ext_capability (const struct pci_dev *pdev,unsigned int cap); unsigned int pci_find_next_ext_capability(const struct pci_dev *pdev,
Re: [PATCH v2 2/4] PCI: determine whether a device has extended config space
Quoted 9 lines · Jan Beulich
Legacy PCI devices don't have any extended config space. Reading any part thereof may return all ones or other arbitrary data, e.g. in some cases base config space contents repeatedly.
Logic follows Linux 6.19-rc's
pci_cfg_space_size(), albeit leveraging our determination of device type; in particular some comments are taken verbatim from there.Signed-off-by Jan Beulich <[email protected]>
Quoted 3 lines
---
Should we skip re-evaluation whenpci_mmcfg_arch_enable()takes its early exit path?
I don't have a strong opinion here, though I'm leaning toward it's OK as is.
Quoted 3 lines
The warning near the bottom of
pci_check_extcfg()may be issued multiple times for a single device now. Should we try to avoid that?
If I'm reading Linux drivers/xen/pci.c correctly, my understanding is that dom0 will only invoke PHYSDEVOP_pci_mmcfg_reserved once per mmcfg segment, so in practice it's unlikely to spam. In other words, I think it's OK as is.
Quoted 5 lines
Note that no vPCI adjustments are done here, but they're going to be
needed: Whatever requires extended capabilities will need re- evaluating / newly establishing / tearing down in case an invocation ofPHYSDEVOP_pci_mmcfg_reservedalters global state.
Agreed. The current patch is prerequisite for this work. Hm, perhaps we could create a gitlab ticket for it?
Re: [PATCH v2 2/4] PCI: determine whether a device has extended config space
Quoted 5 lines · Stewart Hildebrand
Quoted 4 lines · Jan Beulich
Legacy PCI devices don't have any extended config space. Reading any part thereof may return all ones or other arbitrary data, e.g. in some cases base config space contents repeatedly.
Quoted 7 lines
Quoted 5 lines
Logic follows Linux 6.19-rc's
pci_cfg_space_size(), albeit leveraging our determination of device type; in particular some comments are taken verbatim from there.Signed-off-by Jan Beulich <[email protected]>Reviewed-by Stewart Hildebrand <[email protected]>
Thanks, but see below (as that may change your take on it).
Quoted 5 lines
Quoted 3 lines
---
Should we skip re-evaluation whenpci_mmcfg_arch_enable()takes its early exit path?I don't have a strong opinion here, though I'm leaning toward it's OK as is.
Maybe I need to add more context here. Not short-circuiting means that for a brief moment ->ext_cfg for a device can be wrong - between pci_check_extcfg() clearing it and then setting it again once all checks have passed. As long as only Dom0 is executing at that time, and assuming Dom0 actually issues the notification ahead of itself playing with individual devices covered by it, all is going to be fine. With hyperlaunch, however, DomU-s can't be told "not to fiddle" with devices they've been assigned.
With the yet-to-be-written vPCI counterpart changes the window is actually going to get bigger for DomU-s using vPCI.
For hyperlaunch this is going to be interesting anyway, on systems like the one you mentioned. First, without Dom0 / hwdom, how would we even learn we can use MCFG? And even with hwdom, how would we keep DomU-s from accessing the devices they were passed until ->ext_cfg has obtained its final state for them (and vPCI reached proper state, too)?
Quoted 6 lines
Quoted 2 lines
The warning near the bottom of
pci_check_extcfg()may be issued multiple times for a single device now. Should we try to avoid that?If I'm reading Linux
drivers/xen/pci.ccorrectly, my understanding is that dom0 will only invokePHYSDEVOP_pci_mmcfg_reservedonce per mmcfg segment, so in practice it's unlikely to spam. In other words, I think it's OK as is.
Yes, it ought to be no more than twice, but that's still one time more than strictly needed. Hence my (mild) concern.
Quoted 7 lines
Quoted 4 lines
Note that no vPCI adjustments are done here, but they're going to be
needed: Whatever requires extended capabilities will need re- evaluating / newly establishing / tearing down in case an invocation ofPHYSDEVOP_pci_mmcfg_reservedalters global state.Agreed. The current patch is prerequisite for this work. Hm, perhaps we could create a gitlab ticket for it?
Personally I'm not a fan of gitlab tickets, and just in case no-one else gets to it I have this on my todo list already anyway.
Jan
Re: [PATCH v2 2/4] PCI: determine whether a device has extended config space
Quoted 31 lines · Jan Beulich
Quoted 5 lines · Stewart Hildebrand
Quoted 4 lines · Jan Beulich
Legacy PCI devices don't have any extended config space. Reading any part thereof may return all ones or other arbitrary data, e.g. in some cases base config space contents repeatedly.
Quoted 7 lines
Quoted 5 lines
Logic follows Linux 6.19-rc's
pci_cfg_space_size(), albeit leveraging our determination of device type; in particular some comments are taken verbatim from there.Signed-off-by Jan Beulich <[email protected]>Reviewed-by Stewart Hildebrand <[email protected]>Thanks, but see below (as that may change your take on it).
Quoted 5 lines
Quoted 3 lines
---
Should we skip re-evaluation whenpci_mmcfg_arch_enable()takes its early exit path?I don't have a strong opinion here, though I'm leaning toward it's OK as is.
Maybe I need to add more context here. Not short-circuiting means that for a brief moment ->ext_cfg for a device can be wrong - between
pci_check_extcfg()clearing it and then setting it again once all checks have passed. As long as only Dom0 is executing at that time, and assuming Dom0 actually issues the notification ahead of itself playing with individual devices covered by it, all is going to be fine. With hyperlaunch, however, DomU-s can't be told "not to fiddle" with devices they've been assigned.
Quoted 8 lines
With the yet-to-be-written vPCI counterpart changes the window is actually going to get bigger for DomU-s using vPCI.
For hyperlaunch this is going to be interesting anyway, on systems like the one you mentioned. First, without Dom0 / hwdom, how would we even learn we can use MCFG? And even with hwdom, how would we keep DomU-s from accessing the devices they were passed until ->ext_cfg has obtained its final state for them (and vPCI reached proper state, too)?
Ah, I see. Thanks for the additional context.
First of all, to re-answer the original question, it still feels more of a nice-to-have optimization than a necessity since we don't have hyperlaunch PCI passthrough upstream yet. Of course, skipping re-evaluating ext_cfg would be a welcome change if you're up for it. An alternative approach might be to implement pci_check_extcfg() such that it only modifies ->ext_cfg if it needs to be changed, but again, I don't have an issue with it as is.
With that said, what do you think if we took the stance that ->ext_cfg shouldn't be re-evaluated for a pdev while it's assigned to a domU with vPCI? I.e. we would return an error from the pci_mmcfg_reserved hypercall in this case.
If I understand things correctly, conceptually speaking, from a system perspective, setting up mcfg is something that *should* be done at boot, not ad-hoc during runtime. In the hyperlaunch model that I'm envisioning, there will also be hardware/control domain separation, and we will want to limit the hardware domain's ability to interfere with other domains. So I'd consider disabling the mmcfg_reserved hypercall anyway in such a configuration. The assumption with this model is that we would not need rely on dom0 to enable mcfg the system/platform of choice.
Longer term, if we really think we need to support hyperlaunch while relying on a dom0 to initialize mcfg, we could potentially delay assigning pdevs to hyperlaunch domUs until ->ext_cfg has been initialized and is not expected to change. This would imply implementing hotplug for PVH domUs (also needed for "xl pci-attach" with PVH domUs). I wrote some patches in an internal branch to expose an emulated bridge with pcie hotplug capability, laying some of the groundwork to support this, and I'll plan to eventually send this work upstream.
In the scenario without a dom0, I don't have a good answer at the moment for how Xen would learn that mcfg could be used.
Re: [PATCH v2 2/4] PCI: determine whether a device has extended config space
Quoted 40 lines · Stewart Hildebrand
Quoted 31 lines · Jan Beulich
Quoted 5 lines · Stewart Hildebrand
Quoted 4 lines · Jan Beulich
Legacy PCI devices don't have any extended config space. Reading any part thereof may return all ones or other arbitrary data, e.g. in some cases base config space contents repeatedly.
Quoted 7 lines
Quoted 5 lines
Logic follows Linux 6.19-rc's
pci_cfg_space_size(), albeit leveraging our determination of device type; in particular some comments are taken verbatim from there.Signed-off-by Jan Beulich <[email protected]>Reviewed-by Stewart Hildebrand <[email protected]>Thanks, but see below (as that may change your take on it).
Quoted 5 lines
Quoted 3 lines
---
Should we skip re-evaluation whenpci_mmcfg_arch_enable()takes its early exit path?I don't have a strong opinion here, though I'm leaning toward it's OK as is.
Maybe I need to add more context here. Not short-circuiting means that for a brief moment ->ext_cfg for a device can be wrong - between
pci_check_extcfg()clearing it and then setting it again once all checks have passed. As long as only Dom0 is executing at that time, and assuming Dom0 actually issues the notification ahead of itself playing with individual devices covered by it, all is going to be fine. With hyperlaunch, however, DomU-s can't be told "not to fiddle" with devices they've been assigned.Quoted 8 lines
With the yet-to-be-written vPCI counterpart changes the window is actually going to get bigger for DomU-s using vPCI.
For hyperlaunch this is going to be interesting anyway, on systems like the one you mentioned. First, without Dom0 / hwdom, how would we even learn we can use MCFG? And even with hwdom, how would we keep DomU-s from accessing the devices they were passed until ->ext_cfg has obtained its final state for them (and vPCI reached proper state, too)?
Quoted 5 lines
Ah, I see. Thanks for the additional context.
First of all, to re-answer the original question, it still feels more of a nice-to-have optimization than a necessity since we don't have hyperlaunch PCI passthrough upstream yet.
My fear here is that an aspect like this one may easily be forgotten when later doing the actual hyperlaunch work, or when finally making PCI properly supported on Arm64 (where then dom0less would be equally affected, unless Arm has found a way to avoid the dependency on Dom0's ACPI AML parsing).
Quoted 2 lines
Of course, skipping re-evaluating
ext_cfgwould be a welcome change if you're up for it.
We can surely keep this as an incremental change to be made. I guess I want to give Roger a chance to comment before deciding whether to commit the patch here as-is.
Quoted 3 lines
An alternative approach might be to
implementpci_check_extcfg()such that it only modifies ->ext_cfg if it needs to be changed, but again, I don't have an issue with it as is.
That wouldn't help much imo, as there's then still a time window where what the field says is wrong relative to what we already have accounted for in our MCFG handling.
Quoted 3 lines
With that said, what do you think if we took the stance that ->ext_cfg shouldn't be re-evaluated for a pdev while it's assigned to a domU with vPCI? I.e. we would return an error from the
pci_mmcfg_reservedhypercall in this case.
I don't like this idea, as it's functionally limiting (if MCFG becomes available only later) or functionally wrong (if, for whatever reason, MCFG becomes unavailable later).
In no event would I consider returning an error from that hypercall. If anything I'd see us ignore it.
Quoted 3 lines
If I understand things correctly, conceptually speaking, from a system perspective, setting up mcfg is something that *should* be done at boot, not ad-hoc during runtime.
Yes, and that concept simply collides with hyperlaunch's plan to launch more than just Dom0 right at boot. Dom0 booting is part of the system booting, after all.
Quoted 6 lines
In the hyperlaunch model that I'm envisioning, there will
also be hardware/control domain separation, and we will want to limit the hardware domain's ability to interfere with other domains. So I'd consider disabling themmcfg_reservedhypercall anyway in such a configuration. The assumption with this model is that we would not need rely on dom0 to enable mcfg the system/platform of choice.
But you need to work with the hardware you've got. For customized systems it certainly is an option to arrange for firmware to suitably report what Xen needs to be independent of Dom0. But for general purpose systems this won't necessarily fly.
Quoted 7 lines
Longer term, if we really think we need to support hyperlaunch while relying on a dom0 to initialize mcfg, we could potentially delay assigning pdevs to hyperlaunch domUs until ->ext_cfg has been initialized and is not expected to change. This would imply implementing hotplug for PVH domUs (also needed for "xl pci-attach" with PVH domUs). I wrote some patches in an internal branch to expose an emulated bridge with pcie hotplug capability, laying some of the groundwork to support this, and I'll plan to eventually send this work upstream.
Which isn't quite what I understand one of hyperlaunch's goals is (to have all domains be statically configured, and hence be in final, usable shape right when their booting completes).
Jan
Re: [PATCH v2 2/4] PCI: determine whether a device has extended config space
In reply to Jan BeulichQuoted 4 lines · Jan Beulich
Legacy PCI devices don't have any extended config space. Reading any part thereof may return all ones or other arbitrary data, e.g. in some cases base config space contents repeatedly.
Quoted 8 lines
Logic follows Linux 6.19-rc's
pci_cfg_space_size(), albeit leveraging our determination of device type; in particular some comments are taken verbatim from there.Signed-off-by Jan Beulich <[email protected]>---
Should we skip re-evaluation whenpci_mmcfg_arch_enable()takes its early exit path?
Possibly - we expect no change in that case. However it would need to propagate some extra information into the callers. I could see that as a followup optimization.
Quoted 2 lines
The warning near the bottom of
pci_check_extcfg()may be issued multiple times for a single device now. Should we try to avoid that?
Yeah, I've made some comments about that below. Not sure how common those broken bridges are, the comment just mentions two specific models. Adding yet another boolean to track that is cumbersome, and what we would like to do is mark the bridge as broken, instead of every device behind it.
Quoted 4 lines
Note that no vPCI adjustments are done here, but they're going to be
needed: Whatever requires extended capabilities will need re- evaluating / newly establishing / tearing down in case an invocation ofPHYSDEVOP_pci_mmcfg_reservedalters global state.
Hm, you probably want to do something similar to re-scanning the capability list, but avoid tearing down and re-setting the vPCI header logic to prevent unneeded p2m manipulations. We have no easy way to preempt this rescanning from the context of a PHYSDEVOP_pci_mmcfg_reserved call.
Quoted 3 lines
Linux also has
CONFIG_PCI_QUIRKS, allowing to compile out the slightly risky code (as reads may in principle have side effects). Should we gain such, too?
I would be fine with just a command line to disable the newly added behavior in case it causes issues.
xen/arch/x86/physdev.c int physdev_map_pirq(struct domain *d, i · line 25
Quoted 11 lines
---
v2: Major re-work to also check uponPHYSDEVOP_pci_mmcfg_reserved
invocation.xen/arch/x86/physdev.c +1
-0@@ -22,6 +22,8 @@ int physdev_map_pirq(struct domain *d, i struct msi_info *msi);int physdev_unmap_pirq (struct domain *d,int pirq); +int cf_check physdev_check_pci_extcfg(struct pci_dev *pdev, void *arg);
I'm not sure why you need the forward declaration here, the function (in this patch) is just used after it's already defined.
xen/arch/x86/physdev.c int physdev_unmap_pirq(struct domain *d, · line 166
Quoted 10 lines
xen/arch/x86/physdev.c +3
-0+#include "x86_64/mmconfig.h" #ifndef COMPAT @@ -160,6 +162,17 @@ int physdev_unmap_pirq(struct domain *d,return ret; } + +int cf_check physdev_check_pci_extcfg(struct pci_dev *pdev, void *arg)
You can make this static I think?
Quoted 37 lines
xen/arch/x86/physdev.c +14
-0+{ +const struct physdev_pci_mmcfg_reserved *info = arg; + +ASSERT (pdev->seg == info->segment); +if ( pdev->bus >= info->start_bus && pdev->bus <= info->end_bus ) +pci_check_extcfg (pdev); + +return 0 ; +}#endif /* COMPAT */ ret_t do_physdev_op (int cmd,XEN_GUEST_HANDLE_PARAM (void ) arg)@@ -511,6 +524,11 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_H ret =pci_mmcfg_reserved (info.address, info.segment, info.start_bus, info.end_bus, info.flags); + +if ( !ret ) + ret =pci_segment_iterate (info.segment, physdev_check_pci_extcfg, + &info); +if ( !ret &&has_vpci (currd) && (info.flags &XEN_PCI_MMCFG_RESERVED ) ) {/* xen/drivers/passthrough/pci.c +3
-0@@ -422,6 +422,9 @@ static struct pci_dev *alloc_pdev(struct }apply_quirks (pdev); + +pci_check_extcfg (pdev); +check_pdev (pdev);return pdev;
xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 d · line 728
Quoted 8 lines
xen/drivers/passthrough/pci.c +5
-0@@ -718,6 +721,11 @@ int pci_add_device(u16 seg, u8 bus, u8 dlist_add (&pdev->vf_list, &pf_pdev->vf_list); } + +if ( !pdev->ext_cfg ) +printk (XENLOG_WARNING +"%pp: VF without extended config space?\n" , + &pdev->sbdf);
You possibly also want to check that the PF (pf_pdev in this context I think) also has ext_cfg == true.
xen/drivers/passthrough/pci.c enum pdev_type pdev_type(u16 seg, u8 bus · line 1056
Quoted 12 lines
xen/drivers/passthrough/pci.c +5
-0} }@@ -1041,6 +1049,75 @@ enum pdev_type pdev_type(u16 seg, u8 busreturn pos ? DEV_TYPE_PCIe_ENDPOINT :DEV_TYPE_PCI ; } +void pci_check_extcfg (struct pci_dev *pdev) +{ +unsigned int pos, sig; + + pdev->ext_cfg = false;
I think I would prefer if the ext_cfg field is only modified once Xen know the correct value to put there. It would also be nice to detect cases where the device has pdev->ext_cfg == true but a new scan makes it switch to false. Which would signal something has likely gone very wrong, and we should print a warning.
Quoted 48 lines
xen/drivers/passthrough/pci.c +48
-0+ +switch ( pdev->type ) + { +case DEV_TYPE_PCIe_ENDPOINT: +case DEV_TYPE_PCIe_BRIDGE: +case DEV_TYPE_PCI_HOST_BRIDGE : +case DEV_TYPE_PCIe2PCI_BRIDGE: +case DEV_TYPE_PCI2PCIe_BRIDGE: +break ; + +case DEV_TYPE_LEGACY_PCI_BRIDGE : +case DEV_TYPE_PCI : + pos =pci_find_cap_offset (pdev->sbdf,PCI_CAP_ID_PCIX ); +if ( !pos || + !(pci_conf_read32 (pdev->sbdf, pos +PCI_X_STATUS ) & + (PCI_X_STATUS_266MHZ |PCI_X_STATUS_533MHZ )) ) +return ; +break ; + +default : +return ; + } + +/* +* Regular PCI devices have 256 bytes, but PCI-X 2 and PCI Express devices +* have 4096 bytes. Even if the device is capable, that doesn't mean we +* can access it. Maybe we don't have a way to generate extended config +* space accesses, or the device is behind a reverse Express bridge. So +* we try reading the dword at PCI_CFG_SPACE_SIZE which must either be 0 +* or a valid extended capability header. +*/ +if (pci_conf_read32 (pdev->sbdf,PCI_CFG_SPACE_SIZE ) ==0xffffffffU ) +return ; + +/* +* PCI Express to PCI/PCI-X Bridge Specification, rev 1.0, 4.1.4 says that +* when forwarding a type1 configuration request the bridge must check +* that the extended register address field is zero. The bridge is not +* permitted to forward the transactions and must handle it as an +* Unsupported Request. Some bridges do not follow this rule and simply +* drop the extended register bits, resulting in the standard config space +* being aliased, every 256 bytes across the entire configuration space. +* Test for this condition by comparing the first dword of each potential +* alias to the vendor/device ID. +* Known offenders: +* ASM1083/1085 PCIe-to-PCI Reversible Bridge (1b21:1080, rev 01 & 03) +* AMD/ATI SBx00 PCI to PCI Bridge (1002:4384, rev 40) +*/
xen/drivers/passthrough/pci.c enum pdev_type pdev_type(u16 seg, u8 bus · line 1114
Quoted 10 lines
xen/drivers/passthrough/pci.c +10
-0+ sig =pci_conf_read32 (pdev->sbdf,PCI_VENDOR_ID ); +for ( pos =PCI_CFG_SPACE_SIZE ; + pos <PCI_CFG_SPACE_EXP_SIZE ; pos +=PCI_CFG_SPACE_SIZE ) +if (pci_conf_read32 (pdev->sbdf, pos) != sig ) +break ; + +if ( pos >=PCI_CFG_SPACE_EXP_SIZE ) + { +printk (XENLOG_WARNING "%pp: extended config space aliases base one\n" , + &pdev->sbdf);
Hm, I think this shouldn't be very common as it seems limited to a short list of bridges. However every device under such bridge would be affected and repeatedly print the message. I wonder whether we should make this XENLOG_DEBUG instead, there isn't much the user can do to fix it. More a rant than a request though.
Thanks, Roger.
Re: [PATCH v2 2/4] PCI: determine whether a device has extended config space
Quoted 9 lines · Roger Pau Monné
Quoted 8 lines · Jan Beulich
Legacy PCI devices don't have any extended config space. Reading any part thereof may return all ones or other arbitrary data, e.g. in some cases base config space contents repeatedly.
Logic follows Linux 6.19-rc's
pci_cfg_space_size(), albeit leveraging our determination of device type; in particular some comments are taken verbatim from there.
Quoted 8 lines
Quoted 4 lines
Signed-off-by Jan Beulich <[email protected]>---
Should we skip re-evaluation whenpci_mmcfg_arch_enable()takes its early exit path?Possibly - we expect no change in that case. However it would need to propagate some extra information into the callers. I could see that as a followup optimization.
Okay, with Stewart also saying so I'll make this a follow-on then.
Quoted 10 lines
Quoted 4 lines
Note that no vPCI adjustments are done here, but they're going to be
needed: Whatever requires extended capabilities will need re- evaluating / newly establishing / tearing down in case an invocation ofPHYSDEVOP_pci_mmcfg_reservedalters global state.Hm, you probably want to do something similar to re-scanning the capability list, but avoid tearing down and re-setting the vPCI header logic to prevent unneeded p2m manipulations. We have no easy way to preempt this rescanning from the context of a
PHYSDEVOP_pci_mmcfg_reservedcall.
Yes, definitely only re-evaluation of extended capabilities. Note, however, that once we expose more of them, there might be a knock-on effects on the P2M.
Quoted 6 lines
Quoted 3 lines
Linux also has
CONFIG_PCI_QUIRKS, allowing to compile out the slightly risky code (as reads may in principle have side effects). Should we gain such, too?I would be fine with just a command line to disable the newly added behavior in case it causes issues.
Can do. Will need to get creative as to the name of such an option.
Quoted 10 lines
xen/arch/x86/physdev.c int physdev_map_pirq(struct domain *d, i · line 25
Quoted 7 lines
xen/arch/x86/physdev.c +1
-0@@ -22,6 +22,8 @@ int physdev_map_pirq(struct domain *d, i struct msi_info *msi);int physdev_unmap_pirq (struct domain *d,int pirq); +int cf_check physdev_check_pci_extcfg(struct pci_dev *pdev, void *arg);I'm not sure why you need the forward declaration here, the function (in this patch) is just used after it's already defined.
Well, this is needed for the same reason that the two decls just above are:
The file is also used for the COMPAT variant of the hypercall, and hence the declaration needs to be visible there, while ...
Quoted 8 lines
xen/arch/x86/physdev.c int physdev_unmap_pirq(struct domain *d, · line 166
Quoted 6 lines
xen/arch/x86/physdev.c +2
-0@@ -160,6 +162,17 @@ int physdev_unmap_pirq(struct domain *d,return ret; } + +int cf_check physdev_check_pci_extcfg(struct pci_dev *pdev, void *arg)You can make this static I think?
... the definition doesn't need building a 2nd time (which hence also can't be static).
Quoted 12 lines
xen/arch/x86/physdev.c int pci_add_device(u16 seg, u8 bus, u8 d · line 728
Quoted 9 lines
xen/arch/x86/physdev.c +5
-0@@ -718,6 +721,11 @@ int pci_add_device(u16 seg, u8 bus, u8 dlist_add (&pdev->vf_list, &pf_pdev->vf_list); } + +if ( !pdev->ext_cfg ) +printk (XENLOG_WARNING +"%pp: VF without extended config space?\n" , + &pdev->sbdf);You possibly also want to check that the PF (
pf_pdevin this context I think) also hasext_cfg== true.
I don't think so. No extended config space on a PF means no PF in that sense in the first place, for then there not being any SR-IOV capability.
Quoted 4 lines
Quoted 4 lines
xen/arch/x86/physdev.c +0
-0@@ -1041,6 +1049,75 @@ enum pdev_type pdev_type(u16 seg, u8 busreturn pos ? DEV_TYPE_PCIe_ENDPOINT :DEV_TYPE_PCI ; }
Quoted 8 lines
xen/arch/x86/physdev.c enum pdev_type pdev_type(u16 seg, u8 bus · line 1056
Quoted 5 lines
xen/arch/x86/physdev.c +5
-0+void pci_check_extcfg (struct pci_dev *pdev) +{ +unsigned int pos, sig; + + pdev->ext_cfg = false;I think I would prefer if the
ext_cfgfield is only modified once Xen know the correct value to put there.
Well, my main point of doing it this way is that the code ends up being a little easier to follow. Especially without the optimization talked about near the top, there inevitably will be a window in time where what the field says is wrong. With the optimization there'll be two main cases:
- MCFG becoming newly available: The field starts out false in this case, i.e. the write above is a no-op.
- MCFG disappearing (largely hypothetical, I think): The field may start out true in this case, but will go false unless we have another access mechanism for extended config space. It then can as well be set to false as early as possible.
Quoted 4 lines
It would also be nice to detect
cases where the device haspdev->ext_cfg== true but a new scan makes it switch to false. Which would signal something has likely gone very wrong, and we should print a warning.
Why "very wrong"? If Dom0 tells us that MCFG shouldn't be used, there's nothing "very wrong" with that. It's simply what firmware / ACPI are telling us.
Quoted 25 lines
Quoted 14 lines
xen/arch/x86/physdev.c +14
-0+/* +* PCI Express to PCI/PCI-X Bridge Specification, rev 1.0, 4.1.4 says that +* when forwarding a type1 configuration request the bridge must check +* that the extended register address field is zero. The bridge is not +* permitted to forward the transactions and must handle it as an +* Unsupported Request. Some bridges do not follow this rule and simply +* drop the extended register bits, resulting in the standard config space +* being aliased, every 256 bytes across the entire configuration space. +* Test for this condition by comparing the first dword of each potential +* alias to the vendor/device ID. +* Known offenders: +* ASM1083/1085 PCIe-to-PCI Reversible Bridge (1b21:1080, rev 01 & 03) +* AMD/ATI SBx00 PCI to PCI Bridge (1002:4384, rev 40) +*/ xen/arch/x86/physdev.c enum pdev_type pdev_type(u16 seg, u8 bus · line 1080
Quoted 10 lines
xen/arch/x86/physdev.c +10
-0+ sig =pci_conf_read32 (pdev->sbdf,PCI_VENDOR_ID ); +for ( pos =PCI_CFG_SPACE_SIZE ; + pos <PCI_CFG_SPACE_EXP_SIZE ; pos +=PCI_CFG_SPACE_SIZE ) +if (pci_conf_read32 (pdev->sbdf, pos) != sig ) +break ; + +if ( pos >=PCI_CFG_SPACE_EXP_SIZE ) + { +printk (XENLOG_WARNING "%pp: extended config space aliases base one\n" , + &pdev->sbdf);
Quoted 5 lines
Hm, I think this shouldn't be very common as it seems limited to a short list of bridges. However every device under such bridge would be affected and repeatedly print the message. I wonder whether we should make this
XENLOG_DEBUGinstead, there isn't much the user can do to fix it. More a rant than a request though.
XENLOG_DEBUG feels too weak for indicating a potential problem with a device. I also don't see us marking bridges to limit the verbosity here, as the issue may or may not be due to a bridge in between. Imo we can defer thinking about limiting verbosity here until we see reports of this actually getting overly verbose.
Jan
Roger Pau Monné
Acked-byRe: [PATCH v2 2/4] PCI: determine whether a device has extended config space
Quoted 11 lines · Jan Beulich
Quoted 10 lines · Roger Pau Monné
Quoted 9 lines · Jan Beulich
Legacy PCI devices don't have any extended config space. Reading any part thereof may return all ones or other arbitrary data, e.g. in some cases base config space contents repeatedly.
Logic follows Linux 6.19-rc's
pci_cfg_space_size(), albeit leveraging our determination of device type; in particular some comments are taken verbatim from there.Signed-off-by Jan Beulich <[email protected]>
Quoted 21 lines
Quoted 7 lines
Quoted 3 lines
---
Should we skip re-evaluation whenpci_mmcfg_arch_enable()takes its early exit path?Possibly - we expect no change in that case. However it would need to propagate some extra information into the callers. I could see that as a followup optimization.
Okay, with Stewart also saying so I'll make this a follow-on then.
Quoted 10 lines
Quoted 4 lines
Note that no vPCI adjustments are done here, but they're going to be
needed: Whatever requires extended capabilities will need re- evaluating / newly establishing / tearing down in case an invocation ofPHYSDEVOP_pci_mmcfg_reservedalters global state.Hm, you probably want to do something similar to re-scanning the capability list, but avoid tearing down and re-setting the vPCI header logic to prevent unneeded p2m manipulations. We have no easy way to preempt this rescanning from the context of a
PHYSDEVOP_pci_mmcfg_reservedcall.
Quoted 3 lines
Yes, definitely only re-evaluation of extended capabilities. Note, however, that once we expose more of them, there might be a knock-on effects on the P2M.
Preemption in that case will be complicated, as we would have to defer p2m operations from multiple devices in the context of an hypercall. I guess we will cross that bridge when we get there.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Linux also has
CONFIG_PCI_QUIRKS, allowing to compile out the slightly risky code (as reads may in principle have side effects). Should we gain such, too?I would be fine with just a command line to disable the newly added behavior in case it causes issues.
Can do. Will need to get creative as to the name of such an option.
pci=check-ext-cfg=<bool>? Kind of a mouthful.
Quoted 24 lines
Quoted 10 lines
xen/arch/x86/physdev.c int physdev_map_pirq(struct domain *d, i · line 25
Quoted 7 lines
xen/arch/x86/physdev.c +1
-0@@ -22,6 +22,8 @@ int physdev_map_pirq(struct domain *d, i struct msi_info *msi);int physdev_unmap_pirq (struct domain *d,int pirq); +int cf_check physdev_check_pci_extcfg(struct pci_dev *pdev, void *arg);I'm not sure why you need the forward declaration here, the function (in this patch) is just used after it's already defined.
Well, this is needed for the same reason that the two decls just above are:
The file is also used for the COMPAT variant of the hypercall, and hence the declaration needs to be visible there, while ...Quoted 8 lines
xen/arch/x86/physdev.c int physdev_unmap_pirq(struct domain *d, · line 166
Quoted 6 lines
xen/arch/x86/physdev.c +2
-0@@ -160,6 +162,17 @@ int physdev_unmap_pirq(struct domain *d,return ret; } + +int cf_check physdev_check_pci_extcfg(struct pci_dev *pdev, void *arg)You can make this static I think?
Quoted 2 lines
... the definition doesn't need building a 2nd time (which hence also can't be static).
Oh, I see.
Quoted 13 lines
Quoted 12 lines
xen/arch/x86/physdev.c int pci_add_device(u16 seg, u8 bus, u8 d · line 728
Quoted 9 lines
xen/arch/x86/physdev.c +5
-0@@ -718,6 +721,11 @@ int pci_add_device(u16 seg, u8 bus, u8 dlist_add (&pdev->vf_list, &pf_pdev->vf_list); } + +if ( !pdev->ext_cfg ) +printk (XENLOG_WARNING +"%pp: VF without extended config space?\n" , + &pdev->sbdf);You possibly also want to check that the PF (
pf_pdevin this context I think) also hasext_cfg== true.
Quoted 2 lines
I don't think so. No extended config space on a PF means no PF in that sense in the first place, for then there not being any SR-IOV capability.
Right, but won't it be possible for Xen to not be aware of the ECAM region for that device, yet the hardware domain somehow managed to enable SR-IOV it and request to register a VF?
I'm not saying it's common, but it might be a useful sanity check.
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
xen/arch/x86/physdev.c +0
-0@@ -1041,6 +1049,75 @@ enum pdev_type pdev_type(u16 seg, u8 busreturn pos ? DEV_TYPE_PCIe_ENDPOINT :DEV_TYPE_PCI ; }Quoted 8 lines
xen/arch/x86/physdev.c enum pdev_type pdev_type(u16 seg, u8 bus · line 1056
Quoted 5 lines
xen/arch/x86/physdev.c +5
-0+void pci_check_extcfg (struct pci_dev *pdev) +{ +unsigned int pos, sig; + + pdev->ext_cfg = false;I think I would prefer if the
ext_cfgfield is only modified once Xen know the correct value to put there.
Quoted 10 lines
Well, my main point of doing it this way is that the code ends up being a little easier to follow. Especially without the optimization talked about near the top, there inevitably will be a window in time where what the field says is wrong. With the optimization there'll be two main cases:
- MCFG becoming newly available: The field starts out false in this case, i.e. the write above is a no-op.
- MCFG disappearing (largely hypothetical, I think): The field may start out true in this case, but will go false unless we have another access mechanism for extended config space. It then can as well be set to false as early as possible.
Yes, with the optimization to not re-parse existing MMCFGs there's no transient windows where the filed is wrongly set.
I also think the registering of MMCFG ares with Xen should be done ahead of the OS attempting to access the config space, and hence it's not possible for there to be in-flight accesses that could see transient invalid pdev->ext_cfg values.
Quoted 8 lines
Quoted 4 lines
It would also be nice to detect
cases where the device haspdev->ext_cfg== true but a new scan makes it switch to false. Which would signal something has likely gone very wrong, and we should print a warning.Why "very wrong"? If Dom0 tells us that MCFG shouldn't be used, there's nothing "very wrong" with that. It's simply what firmware / ACPI are telling us.
There's also a message printed by pci_mmcfg_arch_disable() when the MMCFG is disabled, so likely we don't need a message printed by each device.
Quoted 31 lines
Quoted 25 lines
Quoted 14 lines
xen/arch/x86/physdev.c +14
-0+/* +* PCI Express to PCI/PCI-X Bridge Specification, rev 1.0, 4.1.4 says that +* when forwarding a type1 configuration request the bridge must check +* that the extended register address field is zero. The bridge is not +* permitted to forward the transactions and must handle it as an +* Unsupported Request. Some bridges do not follow this rule and simply +* drop the extended register bits, resulting in the standard config space +* being aliased, every 256 bytes across the entire configuration space. +* Test for this condition by comparing the first dword of each potential +* alias to the vendor/device ID. +* Known offenders: +* ASM1083/1085 PCIe-to-PCI Reversible Bridge (1b21:1080, rev 01 & 03) +* AMD/ATI SBx00 PCI to PCI Bridge (1002:4384, rev 40) +*/ xen/arch/x86/physdev.c enum pdev_type pdev_type(u16 seg, u8 bus · line 1080
Quoted 10 lines
xen/arch/x86/physdev.c +10
-0+ sig =pci_conf_read32 (pdev->sbdf,PCI_VENDOR_ID ); +for ( pos =PCI_CFG_SPACE_SIZE ; + pos <PCI_CFG_SPACE_EXP_SIZE ; pos +=PCI_CFG_SPACE_SIZE ) +if (pci_conf_read32 (pdev->sbdf, pos) != sig ) +break ; + +if ( pos >=PCI_CFG_SPACE_EXP_SIZE ) + { +printk (XENLOG_WARNING "%pp: extended config space aliases base one\n" , + &pdev->sbdf);Quoted 5 lines
Hm, I think this shouldn't be very common as it seems limited to a short list of bridges. However every device under such bridge would be affected and repeatedly print the message. I wonder whether we should make this
XENLOG_DEBUGinstead, there isn't much the user can do to fix it. More a rant than a request though.
Quoted 5 lines
XENLOG_DEBUGfeels too weak for indicating a potential problem with a device. I also don't see us marking bridges to limit the verbosity here, as the issue may or may not be due to a bridge in between. Imo we can defer thinking about limiting verbosity here until we see reports of this actually getting overly verbose.
OK, let's try with the current level then.
Thanks, Roger.
Re: [PATCH v2 2/4] PCI: determine whether a device has extended config space
Quoted 7 lines · Roger Pau Monné
Quoted 6 lines · Jan Beulich
Quoted 5 lines · Roger Pau Monné
Quoted 4 lines · Jan Beulich
Legacy PCI devices don't have any extended config space. Reading any part thereof may return all ones or other arbitrary data, e.g. in some cases base config space contents repeatedly.
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Logic follows Linux 6.19-rc's
pci_cfg_space_size(), albeit leveraging our determination of device type; in particular some comments are taken verbatim from there.Signed-off-by Jan Beulich <[email protected]>Acked-by Roger Pau Monné <[email protected]>
Thanks. There'll be a v3 though in any event, to add the command line option that you asked for. I'll take the liberty to retain the ack (whereas I've dropped Stewart's R-b).
Quoted 10 lines
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Linux also has
CONFIG_PCI_QUIRKS, allowing to compile out the slightly risky code (as reads may in principle have side effects). Should we gain such, too?I would be fine with just a command line to disable the newly added behavior in case it causes issues.
Can do. Will need to get creative as to the name of such an option.
pci=check-ext-cfg=<bool>? Kind of a mouthful.
As we already have "pci=", I've added a "pci=no-quirks" sub-option there.
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
xen/drivers/passthrough/pci.c int pci_add_device(u16 seg, u8 bus, u8 d · line 728
Quoted 9 lines
xen/drivers/passthrough/pci.c +5
-0@@ -718,6 +721,11 @@ int pci_add_device(u16 seg, u8 bus, u8 dlist_add (&pdev->vf_list, &pf_pdev->vf_list); } + +if ( !pdev->ext_cfg ) +printk (XENLOG_WARNING +"%pp: VF without extended config space?\n" , + &pdev->sbdf);You possibly also want to check that the PF (
pf_pdevin this context I think) also hasext_cfg== true.
Quoted 6 lines
Quoted 2 lines
I don't think so. No extended config space on a PF means no PF in that sense in the first place, for then there not being any SR-IOV capability.
Right, but won't it be possible for Xen to not be aware of the ECAM region for that device, yet the hardware domain somehow managed to enable SR-IOV it and request to register a VF?
Then we're screwed elsewhere, when we try to read the SR-IOV capability ourselves.
Quoted 24 lines
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
xen/drivers/passthrough/pci.c +0
-0@@ -1041,6 +1049,75 @@ enum pdev_type pdev_type(u16 seg, u8 busreturn pos ? DEV_TYPE_PCIe_ENDPOINT :DEV_TYPE_PCI ; }Quoted 8 lines
xen/drivers/passthrough/pci.c enum pdev_type pdev_type(u16 seg, u8 bus · line 1056
Quoted 5 lines
xen/drivers/passthrough/pci.c +5
-0+void pci_check_extcfg (struct pci_dev *pdev) +{ +unsigned int pos, sig; + + pdev->ext_cfg = false;I think I would prefer if the
ext_cfgfield is only modified once Xen know the correct value to put there.Quoted 10 lines
Well, my main point of doing it this way is that the code ends up being a little easier to follow. Especially without the optimization talked about near the top, there inevitably will be a window in time where what the field says is wrong. With the optimization there'll be two main cases:
- MCFG becoming newly available: The field starts out false in this case, i.e. the write above is a no-op.
- MCFG disappearing (largely hypothetical, I think): The field may start out true in this case, but will go false unless we have another access mechanism for extended config space. It then can as well be set to false as early as possible.
Quoted 2 lines
Yes, with the optimization to not re-parse existing MMCFGs there's no transient windows where the filed is wrongly set.
When there's no change. When there is a change, there'll still be such a window. Unavoidably, though.
Quoted 4 lines
I also think the registering of MMCFG ares with Xen should be done ahead of the OS attempting to access the config space, and hence it's not possible for there to be in-flight accesses that could see transient invalid
pdev->ext_cfgvalues.
Yes, for Dom0 alone all should be fine. My worry here is with dom0less and Hyperlaunch.
Jan
PATCH v2 3/4 PCI: don't look for ext-caps when there's no extended cfg space
In reply to Jan BeulichAvoid interpreting as extended capabilities what may be about anything. In doing so, vPCI then also won't mis-interpret data from beyond base config space anymore.
---
Because of the multiple prereq changes, despite the Fixes: tags I'm not quite sure whether to backport this. (I'm leaning towards "no".)
xen/drivers/pci/pci.c +6 -0
@@ -113,6 +113,12 @@ unsigned int pci_find_next_ext_capabilitint ttl =480 ;/* 3840 bytes, minimum 8 bytes per capability */ unsigned int pos =max (start,PCI_CFG_SPACE_SIZE +0U ); +if ( !pdev->ext_cfg ) + { +ASSERT (!start); +return 0 ; + } + header =pci_conf_read32 (pdev->sbdf, pos);/*
Re: [PATCH v2 3/4] PCI: don't look for ext-caps when there's no extended cfg space
Quoted 7 lines · Jan Beulich
Avoid interpreting as extended capabilities what may be about anything. In doing so, vPCI then also won't mis-interpret data from beyond base config space anymore.
Fixes 3b35911d709e ("Enable pci mmcfg and ATS for x86_64")Fixes a845b50c12f3 ("vpci/header: Emulate extended capability list for dom0")Signed-off-by Jan Beulich <[email protected]>
Quoted 3 lines
---
Because of the multiple prereq changes, despite the Fixes: tags I'm not quite sure whether to backport this. (I'm leaning towards "no".)
I'm also leaning towards no, given that the ->ext_cfg change has grown in complexity.
Re: [PATCH v2 3/4] PCI: don't look for ext-caps when there's no extended cfg space
In reply to Jan BeulichQuoted 7 lines · Jan Beulich
Avoid interpreting as extended capabilities what may be about anything. In doing so, vPCI then also won't mis-interpret data from beyond base config space anymore.
Fixes 3b35911d709e ("Enable pci mmcfg and ATS for x86_64")Fixes a845b50c12f3 ("vpci/header: Emulate extended capability list for dom0")Signed-off-by Jan Beulich <[email protected]>
Quoted 3 lines
---
Because of the multiple prereq changes, despite the Fixes: tags I'm not quite sure whether to backport this. (I'm leaning towards "no".)
I won't backport, prereq changes are too intrusive.
Thanks, Roger.
PATCH v2 4/4 vPCI/DomU: really no ext-caps without extended config space
In reply to Jan BeulichWhether to emulate accesses to the first 32 bits of extended config space as read-as-zero or read-as-all-ones depends on whether a device actually has extended config space. If it doesn't, read-as-zero isn't correct; not getting this right may confuse functions like Linux 6.19-rc's pci_ext_cfg_is_aliased().
xen/drivers/vpci/header.c +5 -0
@@ -830,9 +830,14 @@ static int vpci_init_ext_capability_listunsigned int pos =PCI_CFG_SPACE_SIZE ;if ( !is_hardware_domain (pdev->domain) ) + { +if ( !pdev->ext_cfg ) +return 0 ; +/* Extended capabilities read as zero, write ignore for DomU */ return vpci_add_register (pdev->vpci, vpci_read_val,NULL , pos,4 , (void *)0 ); + } do {
Re: [PATCH v2 4/4] vPCI/DomU: really no ext-caps without extended config space
Quoted 8 lines · Jan Beulich
Whether to emulate accesses to the first 32 bits of extended config space as read-as-zero or read-as-all-ones depends on whether a device actually has extended config space. If it doesn't, read-as-zero isn't correct; not getting this right may confuse functions like Linux 6.19-rc's
pci_ext_cfg_is_aliased().Fixes a845b50c12f3 ("vpci/header: Emulate extended capability list for dom0")Signed-off-by Jan Beulich <[email protected]>
Re: [PATCH v2 4/4] vPCI/DomU: really no ext-caps without extended config space
In reply to Jan BeulichQuoted 12 lines · Jan Beulich
Whether to emulate accesses to the first 32 bits of extended config space as read-as-zero or read-as-all-ones depends on whether a device actually has extended config space. If it doesn't, read-as-zero isn't correct; not getting this right may confuse functions like Linux 6.19-rc's
pci_ext_cfg_is_aliased().Fixes a845b50c12f3 ("vpci/header: Emulate extended capability list for dom0")Signed-off-by Jan Beulich <[email protected]>
xen/drivers/vpci/header.c static int vpci_init_ext_capability_list · line 835
Quoted 6 lines
xen/drivers/vpci/header.c +3
-0@@ -830,9 +830,14 @@ static int vpci_init_ext_capability_listunsigned int pos =PCI_CFG_SPACE_SIZE ;if ( !is_hardware_domain (pdev->domain) ) + { +if ( !pdev->ext_cfg ) +return 0 ;
Don't you want to possibly put this as a top-level check, so if there's no extended config space we avoid doing the PCI_CFG_SPACE_SIZE read for dom0 also?
Thanks, Roger.
Re: [PATCH v2 4/4] vPCI/DomU: really no ext-caps without extended config space
Quoted 6 lines · Roger Pau Monné
Quoted 5 lines · Jan Beulich
xen/drivers/vpci/header.c +0
-0@@ -830,9 +830,14 @@ static int vpci_init_ext_capability_listunsigned int pos =PCI_CFG_SPACE_SIZE ;
Quoted 8 lines
xen/drivers/vpci/header.c static int vpci_init_ext_capability_list · line 835
Quoted 4 lines
xen/drivers/vpci/header.c +3
-0if ( !is_hardware_domain (pdev->domain) ) + { +if ( !pdev->ext_cfg ) +return 0 ;Don't you want to possibly put this as a top-level check, so if there's no extended config space we avoid doing the
PCI_CFG_SPACE_SIZEread for dom0 also?
Hmm, yes, didn't think about that. That'll mean dropping the "if ( pos != PCI_CFG_SPACE_SIZE )" from the body of the "if ( header == 0xffffffffU )" then, i.e. the printk() there becoming unconditional. It may also mean dropping "DomU" from the subject.
Jan
Re: [PATCH v2 4/4] vPCI/DomU: really no ext-caps without extended config space
Quoted 16 lines · Jan Beulich
Quoted 6 lines · Roger Pau Monné
Quoted 5 lines · Jan Beulich
xen/drivers/vpci/header.c +0
-0@@ -830,9 +830,14 @@ static int vpci_init_ext_capability_listunsigned int pos =PCI_CFG_SPACE_SIZE ;Quoted 8 lines
xen/drivers/vpci/header.c static int vpci_init_ext_capability_list · line 835
Quoted 4 lines
xen/drivers/vpci/header.c +3
-0if ( !is_hardware_domain (pdev->domain) ) + { +if ( !pdev->ext_cfg ) +return 0 ;Don't you want to possibly put this as a top-level check, so if there's no extended config space we avoid doing the
PCI_CFG_SPACE_SIZEread for dom0 also?
Quoted 4 lines
Hmm, yes, didn't think about that. That'll mean dropping the "if ( pos !=
PCI_CFG_SPACE_SIZE)" from the body of the "if ( header ==0xffffffffU)" then, i.e. theprintk()there becoming unconditional. It may also mean dropping "DomU" from the subject.
I've also wondered whether we want to short-circuit vpci_{read,write} accesses if the device doesn't have extended cfg, for domUs to be on the safe side.
Thanks, Roger.
Re: [PATCH v2 4/4] vPCI/DomU: really no ext-caps without extended config space
Quoted 17 lines · Roger Pau Monné
Quoted 16 lines · Jan Beulich
Quoted 14 lines · Roger Pau Monné
xen/drivers/vpci/header.c static int vpci_init_ext_capability_list · line 835
Quoted 9 lines · Jan Beulich
xen/drivers/vpci/header.c +3
-0@@ -830,9 +830,14 @@ static int vpci_init_ext_capability_listunsigned int pos =PCI_CFG_SPACE_SIZE ;if ( !is_hardware_domain (pdev->domain) ) + { +if ( !pdev->ext_cfg ) +return 0 ;Don't you want to possibly put this as a top-level check, so if there's no extended config space we avoid doing the
PCI_CFG_SPACE_SIZEread for dom0 also?
Quoted 8 lines
Quoted 4 lines
Hmm, yes, didn't think about that. That'll mean dropping the "if ( pos !=
PCI_CFG_SPACE_SIZE)" from the body of the "if ( header ==0xffffffffU)" then, i.e. theprintk()there becoming unconditional. It may also mean dropping "DomU" from the subject.I've also wondered whether we want to short-circuit vpci_{read,write} accesses if the device doesn't have extended cfg, for domUs to be on the safe side.
May make sense, yes. I don't think I'll add anything along these lines to this series, though.
Jan