Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@kernel.org>
To: raoxu <raoxu@uniontech.com>, bhelgaas@google.com
Cc: luiz.von.dentz@intel.com, wangruikang@iscas.ac.cn,
	pengpeng@iscas.ac.cn, ligongwei@kylinos.cn,
	maciej.fijalkowski@intel.com, michael.bommarito@gmail.com,
	18255117159@163.com, xiangzao@linux.alibaba.com,
	vidyas@nvidia.com, lihaoxiang@isrc.iscas.ac.cn,
	linux-pci@vger.kernel.org, raoxu@uniontech.com
Subject: Re: [PATCH v3] PCI/MSI: Retry a mismatched MSI-X message once during restore
Date: Wed, 02 Dec 2026 01:53:27 +0100	[thread overview]
Message-ID: <87pkvko648.ffs@fw13> (raw)
In-Reply-To: <3889F27756A28655+20261201123626.1967698-1-raoxu@uniontech.com>

On Tue, Dec 01 2026 at 20:36, raoxu@uniontech.com wrote:
> From: Xu Rao <raoxu@uniontech.com>
>
> The failure was reproduced on Linux 6.6.162. This release includes the

Which failure? You fail to describe the problem. See

  https://docs.kernel.org/process/maintainer-tip.html#changelog

> backport of commit 231c7a57d193 ("PCI/MSI: Enable memory decoding
> before restoring MSI-X messages").

Nobody cares aboyut your private 6.6.162 plus random backports kernel.

The real question is whether this happens on current upstream
(7.4-rc5...) or not.

> The following excerpts show MSI-X entry 0 on two S3 cycles. The
> msg-after trace records the first message readback after the write in
> __pci_restore_msix_state(). The pci-resume trace reads the same entry
> at xHCI resume. Both show address high:low/data, with vector control
> as the last word of v0.
>
>   Normal cycle 16
>   [ 1163.085945] msg-after irq=86
>       want=00000000:36850040/00000000 actual=00000000:36850040/00000000
>   [ 1163.087494] n=16 pci-resume
>       v0=00000000:36850040/00000000/00000000
>
>   Failed cycle 18
>   [ 1285.211630] msg-after irq=86
>       want=00000000:36850040/00000000 actual=ffffffff:ffffffff/ffffffff
>   [ 1285.213401] n=18 pci-resume
>       v0=00000000:00000000/00000000/00000000
>
> On cycle 16 the address matched the cached value at both points. On
> cycle 18 the first readback returned all ones for both address words
> and the data word. The address then read back as zero at xHCI resume.
>
> In a diagnostic run of 500 S3 cycles, nine initial message readbacks
> differed from the cached message. All nine matched after one additional
> write. Subsequent testing with the single retry completed 1000 S3
> cycles without reproducing the failure.
>
> When restoring a non-virtual MSI-X entry with the device in D0 and its
> PCI channel online, read back the message address and data. If either
> differs from the cached value, repeat the write once before restoring
> vector control. Log the table index on retry to help identify affected
> devices.

This whole change log is a debug warrier novel with zero content.

You completely fail to explain the underlying hardware problem and why
this hack actually "fixes" it.

>  void __pci_restore_msix_state(struct pci_dev *dev)
>  {
>  	struct msi_desc *entry;
> +	struct msi_msg actual_msg;
>  	bool write_msg;
>  	u16 cmd;
>
> @@ -894,8 +895,22 @@ void __pci_restore_msix_state(struct pci_dev *dev)
>
>  	scoped_guard (msi_descs_lock, &dev->dev) {
>  		msi_for_each_desc(entry, &dev->dev, MSI_DESC_ALL) {
> -			if (write_msg)
> +			if (write_msg) {
>  				__pci_write_msi_msg(entry, &entry->msg);
> +				if (dev->current_state == PCI_D0 &&
> +				    !pci_channel_offline(dev) &&
> +				    !entry->pci.msi_attrib.is_virtual) {
> +					__pci_read_msi_msg(entry, &actual_msg);
> +					if (actual_msg.address_lo != entry->msg.address_lo ||
> +					    actual_msg.address_hi != entry->msg.address_hi ||
> +					    actual_msg.data != entry->msg.data) {
> +						__pci_write_msi_msg(entry, &entry->msg);
> +						pci_notice_ratelimited(dev,
> +								       "MSI-X entry %u: message mismatch on restore, retried write\n",
> +								       entry->msi_index);
> +					}
> +				}

And TBH, this is incomprehensible garbage. If at all this want's to be
in a seperate static function.

Something like the uncompiled below. The FIXMEs have to be filled in and
they also build the basis for a comprehensible change log.

Thanks,

        tglx
---
--- a/drivers/pci/msi/msi.c
+++ b/drivers/pci/msi/msi.c
@@ -868,6 +868,42 @@ int __pci_enable_msix_range(struct pci_d
 	}
 }
 
+static void pci_restore_msix_msg(struct pci_dev *dev, struct msi_desc *entry)
+{
+	__pci_write_msi_msg(entry, &entry->msg);
+
+	/*
+	 * FIXME: Add a comprehensible technical explanation for this condition
+	 *	  and the actual underlying problem which is solved.
+	 *
+	 *	  Also explain WHY every MSI-X restore has to go through this
+	 *	  non-sensical overhead just because a particular hardware
+	 *	  vendor can't get it's act together and why it does not matter.
+	 */
+	if (dev->current_state != PCI_D0 || pci_channel_offline(dev) ||
+	    entry->pci.msi_attrib.is_virtual)
+		return;
+
+	/*
+	 * FIXME: Add a comprehensible technical explanation
+	 *	  why the message needs to be read back.
+	 */
+	struct msi_msg msg;
+
+	__pci_read_msi_msg(entry, &msg);
+
+	if (memcmp(&msg, &entry->msg, sizeof(msg)))
+		return;
+
+	pci_notice_ratelimited(dev, "MSI-X message restore failed. Trying to recover\n");
+
+	/*
+	 * Write again in the vain attempt to unbreak the broken Inspur
+	 * CE720F2/Phytium D3000 hardware.
+	 */
+	__pci_write_msi_msg(entry, &entry->msg);
+}
+
 void __pci_restore_msix_state(struct pci_dev *dev)
 {
 	struct msi_desc *entry;
@@ -895,7 +931,7 @@ void __pci_restore_msix_state(struct pci
 	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_restore_msix_msg(dev, entry);
 			pci_msix_write_vector_ctrl(entry, entry->pci.msix_ctrl);
 		}
 	}


      parent reply	other threads:[~2026-12-02  0:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 12:36 [PATCH v3] PCI/MSI: Retry a mismatched MSI-X message once during restore raoxu
2026-12-01 12:47 ` sashiko-bot
2026-12-02  0:53 ` Thomas Gleixner [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=87pkvko648.ffs@fw13 \
    --to=tglx@kernel.org \
    --cc=18255117159@163.com \
    --cc=bhelgaas@google.com \
    --cc=ligongwei@kylinos.cn \
    --cc=lihaoxiang@isrc.iscas.ac.cn \
    --cc=linux-pci@vger.kernel.org \
    --cc=luiz.von.dentz@intel.com \
    --cc=maciej.fijalkowski@intel.com \
    --cc=michael.bommarito@gmail.com \
    --cc=pengpeng@iscas.ac.cn \
    --cc=raoxu@uniontech.com \
    --cc=vidyas@nvidia.com \
    --cc=wangruikang@iscas.ac.cn \
    --cc=xiangzao@linux.alibaba.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox