* [PATCH] PCI/MSI: Retry a mismatched MSI-X message once during restore
@ 2026-11-26 6:49 raoxu
2026-11-26 7:11 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: raoxu @ 2026-11-26 6:49 UTC (permalink / raw)
To: bhelgaas
Cc: luiz.von.dentz, tglx, pengpeng, brgl, wangruikang, ligongwei,
maciej.fijalkowski, michael.bommarito, 18255117159, xiangzao,
vidyas, lihaoxiang, linux-pci, linux-kernel, raoxu
From: Xu Rao <raoxu@uniontech.com>
Repeated S3 cycles on an Inspur CE720F2 with a Phytium D3000 CPU
leave its Renesas xHCI controller (0000:04:00.0, 1912:0014) without
working interrupts. The keyboard and mouse stop responding, and
newly attached USB devices cannot be used.
The failure was reproduced on UOS 6.6.0-arm64-desktop, revision
d7bafad345e0, build #5.
The affected kernel already includes commit 231c7a57d193
("PCI/MSI: Enable memory decoding before restoring MSI-X messages").
However, inconsistent MSI-X message readbacks still occur after the
restore write on this platform.
Diagnostic excerpts below are wrapped and omit repeated device
prefixes and unrelated fields.
On normal cycle 16, the MSI-X message read back after the PCI
restore write matches the intended message:
[ 1163.085945] xhci-s3 msg-after irq=86 read=1
want=00000000:36850040/00000000
actual=00000000:36850040/00000000
On failing cycle 18, the same readback is all ones. At xHCI resume
entry, the message address is zero:
[ 1285.211630] xhci-s3 msg-after irq=86 read=1
want=00000000:36850040/00000000
actual=ffffffff:ffffffff/ffffffff
[ 1285.213401] xhci-s3 n=18 pci-resume ret=0
read=1 v0=00000000:00000000/00000000/00000000
Here, want is the software-cached target message and actual is the
hardware readback, formatted as address_hi:address_lo/data. The
last field in v0 is vector control. An all-ones read can indicate
an unsuccessful MMIO access; it need not be the stored table value.
The later zero address differs from the expected 0x36850040.
The controller then reports a command timeout:
[ 1295.556532] Command timeout, USBSTS: 0x00000018 EINT PCD
[ 1295.556557] xhci-s3 n=18 timeout cmd=01013c01
dma=0x0000002021506000 irqs=0
[ 1295.556560] xhci-s3 n=18 events scanned=10 limit=0
matched=1 cc=1 last_cmd=0000002021506000
matched=1 and cc=1 identify a successful completion of that Stop
Endpoint command in the event ring. irqs=0 means no xHCI interrupt
was recorded after resume. The command completed, but its completion
was not processed normally.
Read back the message after the existing MSI-X restore write. If
either address field or data differs from the cached message, repeat
the write once. Matching entries receive no additional write.
With the retry, cycle 263 records the incorrect zero address and
then the expected message after the additional write:
[16009.367505] xhci-s3 msix-check irq=86 retry=1 match=1
want=00000000:36850040/00000000
before=00000000:00000000/00000000
after=00000000:36850040/00000000
retry=1 confirms that the mismatch triggered the extra write;
match=1 confirms that the subsequent readback matches the target.
In 500 S3 cycles with temporary diagnostics, 491 comparisons matched
without a retry. Nine mismatches triggered a retry and all nine read
back correctly afterwards. The subsequent xHCI resume snapshots
remained correct, no xHCI command timeout occurred, and a USB storage
device attached after testing enumerated successfully.
Signed-off-by: Xu Rao <raoxu@uniontech.com>
---
drivers/pci/msi/msi.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/pci/msi/msi.c b/drivers/pci/msi/msi.c
index 8a0133a6a286..a3304829258d 100644
--- a/drivers/pci/msi/msi.c
+++ b/drivers/pci/msi/msi.c
@@ -871,6 +871,7 @@ int __pci_enable_msix_range(struct pci_dev *dev, struct msix_entry *entries, int
void __pci_restore_msix_state(struct pci_dev *dev)
{
struct msi_desc *entry;
+ struct msi_msg actual;
bool write_msg;
u16 cmd;
@@ -896,6 +897,15 @@ void __pci_restore_msix_state(struct pci_dev *dev)
msi_for_each_desc(entry, &dev->dev, MSI_DESC_ALL) {
if (write_msg)
__pci_write_msi_msg(entry, &entry->msg);
+ if (write_msg && dev->current_state == PCI_D0 &&
+ !pci_dev_is_disconnected(dev) &&
+ !entry->pci.msi_attrib.is_virtual) {
+ __pci_read_msi_msg(entry, &actual);
+ if (actual.address_lo != entry->msg.address_lo ||
+ actual.address_hi != entry->msg.address_hi ||
+ actual.data != entry->msg.data)
+ __pci_write_msi_msg(entry, &entry->msg);
+ }
pci_msix_write_vector_ctrl(entry, entry->pci.msix_ctrl);
}
}
--
2.50.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] PCI/MSI: Retry a mismatched MSI-X message once during restore
2026-11-26 6:49 [PATCH] PCI/MSI: Retry a mismatched MSI-X message once during restore raoxu
@ 2026-11-26 7:11 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-26 7:11 UTC (permalink / raw)
To: raoxu; +Cc: linux-pci
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] PCI/MSI: __pci_restore_msix_state() reads MSI-X table when
channel is frozen
- [Medium] PCI/MSI: unreliable retry and offline read in
__pci_restore_msix_state()
--
commit a9578a3be66676c84a41222ba8afbb2d8beac990
Author: Xu Rao <raoxu@uniontech.com>
PCI/MSI: Retry a mismatched MSI-X message once during restore
This commit reads back each MSI-X table entry in __pci_restore_msix_state()
after writing it and retries __pci_write_msi_msg() once if the readback
differs from the cached message.
> diff --git a/drivers/pci/msi/msi.c b/drivers/pci/msi/msi.c
> index 4e8ec8d42aa6b..4ab2c670a2d40 100644
> --- a/drivers/pci/msi/msi.c
> +++ b/drivers/pci/msi/msi.c
> @@ -870,6 +870,7 @@ int __pci_enable_msix_range(struct pci_dev *dev, struct msix_entry *entries, int
> void __pci_restore_msix_state(struct pci_dev *dev)
> {
> struct msi_desc *entry;
> + struct msi_msg actual;
> bool write_msg;
> u16 cmd;
>
> @@ -895,6 +896,15 @@ void __pci_restore_msix_state(struct pci_dev *dev)
> msi_for_each_desc(entry, &dev->dev, MSI_DESC_ALL) {
> if (write_msg)
> __pci_write_msi_msg(entry, &entry->msg);
> + if (write_msg && dev->current_state == PCI_D0 &&
> + !pci_dev_is_disconnected(dev) &&
> + !entry->pci.msi_attrib.is_virtual) {
> + __pci_read_msi_msg(entry, &actual);
[Severity: Medium]
Should this guard check !pci_channel_offline(dev) instead of
!pci_dev_is_disconnected(dev)?
Both __pci_write_msi_msg() and pci_msix_write_vector_ctrl() skip MSI-X
table MMIO accesses when pci_channel_offline(dev) is true, as updated in
2e2f69fc8ae2 ("PCI/MSI: Skip MSI/MSI-X programming while the channel is
offline"). pci_dev_is_disconnected() only checks for
pci_channel_io_perm_failure, so if __pci_restore_msix_state() runs while
dev->error_state is pci_channel_io_frozen, __pci_read_msi_msg() still
issues three MMIO reads to the unreachable MSI-X table BAR. When a
Downstream Port link is contained by DPC, those reads complete with
Unsupported Request (returning 0xffffffff), which can trigger an RP PIO
error and secondary Root Port containment on Root Ports with DPC RP
Extensions, as well as a duplicate __pci_write_msi_msg() call.
> + if (actual.address_lo != entry->msg.address_lo ||
> + actual.address_hi != entry->msg.address_hi ||
> + actual.data != entry->msg.data)
> + __pci_write_msi_msg(entry, &entry->msg);
> + }
[Severity: Medium]
Can an immediate single __pci_write_msi_msg() retry still fail when the
device is not yet responding to MSI-X BAR MMIO accesses?
pci_write_msg_msix() already ends with a readl() flush of
PCI_MSIX_ENTRY_DATA, so when __pci_read_msi_msg() reads back all ones (as
in cycle 18 of the changelog), all three readl() calls in
__pci_read_msi_msg() also failed and the device is still not decoding MMIO
at the moment the retry runs. Without waiting for readiness or verifying
the retry, the second write and the following pci_msix_write_vector_ctrl()
can be dropped as well.
In addition, pci_write_config_word(dev, PCI_COMMAND, cmd |
PCI_COMMAND_MEMORY) earlier in __pci_restore_msix_state() is not flushed
with a config read before the MSI-X table MMIO writes begin, and the
unconditional readback adds three synchronous readl() calls per MSI-X
descriptor on every restore across all devices. Retrying via
__pci_write_msi_msg() rather than pci_write_msg_msix() also invokes
entry->write_msi_msg() a second time.
--
Sashiko AI review · https://sashiko.dev/#/patchset/4EDB2ADA2CFC5963+20261126064901.1798104-1-raoxu@uniontech.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-26 7:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 6:49 [PATCH] PCI/MSI: Retry a mismatched MSI-X message once during restore raoxu
2026-11-26 7:11 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox