From: sashiko-bot@kernel.org
To: "Farhan Ali" <alifm@linux.ibm.com>
Cc: linux-s390@vger.kernel.org,
"Alexander Gordeev" <agordeev@linux.ibm.com>,
"Vasily Gorbik" <gor@linux.ibm.com>,
linux-pci@vger.kernel.org, "Heiko Carstens" <hca@linux.ibm.com>
Subject: Re: [PATCH v19 4/4] PCI/MSI: Enable memory decoding before restoring MSI-X messages
Date: Mon, 15 Jun 2026 18:48:49 +0000 [thread overview]
Message-ID: <20260615184849.918991F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260615183524.2880-5-alifm@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
New issues:
- [High] Unvalidated PCI_COMMAND read can result in writing 0xFFFF back to the device, enabling fatal error reporting.
- [High] Blind restoration of PCI_COMMAND register clobbers concurrent modifications across the locked section (TOCTOU race).
Pre-existing issues:
- [High] Conditional enablement of PCI_COMMAND_MEMORY leaves pci_msix_write_vector_ctrl() exposed to Unsupported Request (UR) faults.
--
commit 9bf79a22431c8153c5aed81ed2a19f276bfd3940
Author: Farhan Ali <alifm@linux.ibm.com>
PCI/MSI: Enable memory decoding before restoring MSI-X messages
This commit attempts to fix Unsupported Request (UR) faults during MSI-X
restoration by temporarily enabling the Memory bit in the Command register
when writing MSI-X messages. The bit is enabled prior to restoration and
restored to its previous state afterwards.
> diff --git a/drivers/pci/msi/msi.c b/drivers/pci/msi/msi.c
> index 81d24a270a795..d8d3c8a911ac0 100644
> --- a/drivers/pci/msi/msi.c
> +++ b/drivers/pci/msi/msi.c
> @@ -874,6 +874,7 @@ void __pci_restore_msix_state(struct pci_dev *dev)
> {
> struct msi_desc *entry;
> bool write_msg;
> + u16 cmd;
>
> if (!dev->msix_enabled)
> return;
[ ... ]
> @@ -884,6 +885,11 @@ void __pci_restore_msix_state(struct pci_dev *dev)
> PCI_MSIX_FLAGS_ENABLE | PCI_MSIX_FLAGS_MASKALL);
>
> write_msg = arch_restore_msi_irqs(dev);
> + if (write_msg) {
> + pci_read_config_word(dev, PCI_COMMAND, &cmd);
> + pci_write_config_word(dev, PCI_COMMAND,
> + cmd | PCI_COMMAND_MEMORY);
> + }
[Severity: High]
Does pci_read_config_word() need its return value checked here?
If the read fails (e.g., due to a transient bus error or recovery state), the
PCI subsystem populates cmd with 0xFFFF (PCI_ERROR_RESPONSE). Computing
cmd | PCI_COMMAND_MEMORY would then write 0xFFFF back to the Command Register,
enabling all writable capabilities at once (including SERR# Enable), which
could trigger a fatal NMI or system panic.
> scoped_guard (msi_descs_lock, &dev->dev) {
> msi_for_each_desc(entry, &dev->dev, MSI_DESC_ALL) {
> if (write_msg)
> __pci_write_msi_msg(entry, &entry->msg);
> pci_msix_write_vector_ctrl(entry, entry->pci.msix_ctrl);
[Severity: High]
This is a pre-existing issue, but does this code leave the MSI-X table
exposed to the very Unsupported Request (UR) faults this patch tries to fix?
Since pci_msix_write_vector_ctrl() performs an MMIO write to the MSI-X
Vector Control register unconditionally for every MSI descriptor, what
happens if write_msg is false? The memory decoding bit won't be enabled
above, meaning this unconditional MMIO access could still trigger a UR fault.
> }
> }
>
> + if (write_msg)
> + pci_write_config_word(dev, PCI_COMMAND, cmd);
> +
[Severity: High]
Can this blindly overwrite the PCI_COMMAND register with a stale snapshot?
The cmd value was read before the scoped_guard() block. If concurrent
operations modify PCI_COMMAND (such as changing PCI_COMMAND_MASTER or
PCI_COMMAND_INTX_DISABLE via sysfs or other subsystem operations) while
the lock is held, rewriting the old cmd value here would wipe out those
concurrent changes.
Should we re-read the register here, mask out PCI_COMMAND_MEMORY if we
enabled it, and only restore that specific bit?
> pci_msix_clear_and_set_ctrl(dev, PCI_MSIX_FLAGS_MASKALL, 0);
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260615183524.2880-1-alifm@linux.ibm.com?part=4
next prev parent reply other threads:[~2026-06-15 18:48 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-15 18:35 [PATCH v19 0/4] [PCI] Error recovery for vfio-pci devices on s390x Farhan Ali
2026-06-15 18:35 ` [PATCH v19 1/4] PCI: Allow per function PCI slots to fix slot reset on s390 Farhan Ali
2026-06-15 18:50 ` sashiko-bot
2026-06-15 18:35 ` [PATCH v19 2/4] PCI: Avoid saving config space state if inaccessible Farhan Ali
2026-06-15 18:49 ` sashiko-bot
2026-06-15 18:35 ` [PATCH v19 3/4] PCI: Fail FLR when config space is inaccessible Farhan Ali
2026-06-15 18:43 ` sashiko-bot
2026-06-15 18:35 ` [PATCH v19 4/4] PCI/MSI: Enable memory decoding before restoring MSI-X messages Farhan Ali
2026-06-15 18:48 ` sashiko-bot [this message]
2026-06-15 18:59 ` Niklas Schnelle
2026-06-15 22:17 ` Farhan Ali
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=20260615184849.918991F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=alifm@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=linux-pci@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox