From: David Vrabel <david.vrabel@nutanix.com>
To: David Vrabel <david.vrabel@nutanix.com>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Cc: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
Zhao Liu <zhao1.liu@intel.com>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: [PATCH v2 4/4] hw/pci: Ensure PCIe link speed/width is consistent between both ends
Date: Tue, 8 Sep 2026 15:52:27 +0000 [thread overview]
Message-ID: <20260908155223.164787-5-david.vrabel@nutanix.com> (raw)
In-Reply-To: <20260908155223.164787-1-david.vrabel@nutanix.com>
If an emulated PCIe endpoint has higher link speed or width
capabilities than the upstream port it is connected to, ensure that
the link status on both ends is consistent by using the link status
computed for the upstream port.
If the PCIe endpoint is a passthrough device, the link status
continues to match the real status and consistent values requires the
emulated upstream port to be at least as capable as the endpoint.
Signed-off-by: David Vrabel <david.vrabel@nutanix.com>
---
hw/pci/pcie.c | 26 ++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)
diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
index 4622c75e48..66d778413d 100644
--- a/hw/pci/pcie.c
+++ b/hw/pci/pcie.c
@@ -169,18 +169,36 @@ void pcie_cap_fill_link_ep_usp(PCIDevice *dev, PCIExpLinkWidth width,
PCIExpLinkSpeed speed, bool flitmode)
{
uint8_t *exp_cap = dev->config + dev->exp.exp_cap;
+ PCIDevice *upstream;
/*
- * For an end point or USP need to set the current status as well
- * as the capabilities.
+ * For an endpoint or USP, set Link Status as well as capabilities.
+ * Provisionally use this device's width/speed, then adopt the upstream
+ * port's values so both ends of an emulated link agree. The upstream
+ * LNKSTA is already clamped to the negotiated link capabilities via
+ * pcie_sync_bridge_lnk().
*/
- pci_long_test_and_clear_mask(exp_cap + PCI_EXP_LNKSTA,
+ pci_word_test_and_clear_mask(exp_cap + PCI_EXP_LNKSTA,
PCI_EXP_LNKSTA_CLS | PCI_EXP_LNKSTA_NLW);
- pci_long_test_and_set_mask(exp_cap + PCI_EXP_LNKSTA,
+ pci_word_test_and_set_mask(exp_cap + PCI_EXP_LNKSTA,
QEMU_PCI_EXP_LNKSTA_NLW(width) |
QEMU_PCI_EXP_LNKSTA_CLS(speed));
pcie_cap_fill_lnk(exp_cap, width, speed, flitmode);
+
+ upstream = pci_bridge_get_device(pci_get_bus(dev));
+ if (upstream && pci_is_express_downstream_port(upstream)) {
+ uint8_t *up_exp = upstream->config + upstream->exp.exp_cap;
+ uint16_t lnksta;
+
+ pcie_sync_bridge_lnk(upstream);
+ lnksta = pci_get_word(up_exp + PCI_EXP_LNKSTA);
+ pci_word_test_and_clear_mask(exp_cap + PCI_EXP_LNKSTA,
+ PCI_EXP_LNKSTA_CLS | PCI_EXP_LNKSTA_NLW);
+ pci_word_test_and_set_mask(exp_cap + PCI_EXP_LNKSTA,
+ lnksta & (PCI_EXP_LNKSTA_CLS |
+ PCI_EXP_LNKSTA_NLW));
+ }
}
static void pcie_cap_fill_slot_lnk(PCIDevice *dev)
--
2.43.0
prev parent reply other threads:[~2026-09-08 15:53 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-08 15:52 [PATCH v2 0/4] hw/pci-bridge: Configurable apparent bandwidth for the PCIe topology David Vrabel
2026-09-08 15:52 ` [PATCH v2 1/4] hw/pci-bridge: Add generic PCIe switch upstream and downstream ports David Vrabel
2026-09-08 16:05 ` David Vrabel
2026-09-09 15:14 ` Gerd Hoffmann
2026-09-08 15:52 ` [PATCH v2 2/4] hw/pci-bridge: Make speed and width for PCIe ports non-experimental David Vrabel
2026-09-08 15:52 ` [PATCH v2 3/4] hw/pci-bridge: Default the generic PCIe root port as Gen6 capable David Vrabel
2026-09-08 15:52 ` David Vrabel [this message]
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=20260908155223.164787-5-david.vrabel@nutanix.com \
--to=david.vrabel@nutanix.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=pierrick.bouvier@oss.qualcomm.com \
--cc=qemu-devel@nongnu.org \
--cc=zhao1.liu@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.