Commit e8df1d194c39 for kernel

commit e8df1d194c39b7a5159d570798941851f70a8668
Author: Alexander Gruhlke <gruhlke@mailbox.org>
Date:   Sun Oct 11 21:01:45 2026 +0200

    PCI: Don't treat ~0 as ready in pci_dev_wait() with RRS SV

    With RRS Software Visibility, pci_dev_wait() considers a device ready as
    soon as reading the Vendor ID doesn't return the RRS value.  Devices aren't
    required to respond with RRS while they aren't ready, so the read may
    return ~0 and pci_dev_wait() stops waiting too early.  This was seen with
    Intel [8086:0a54] and Samsung [144d:a80c] NVMe SSDs.

    Also wait while the Vendor ID reads ~0.  A VF's Vendor ID always reads ~0,
    so check its Command register instead, as is done without RRS SV.

    Fixes: d591f6804e7e ("PCI: Wait for device readiness with Configuration RRS")
    Link: https://lore.kernel.org/r/20250611101442.387378-1-hui.wang@canonical.com
    Suggested-by: Lukas Wunner <lukas@wunner.de>
    Assisted-by: Claude:claude-opus-5-5
    Signed-off-by: Alexander Gruhlke <gruhlke@mailbox.org>
    Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
    Reviewed-by: Lukas Wunner <lukas@wunner.de>
    Link: https://patch.msgid.link/20261011190145.23621-3-gruhlke@mailbox.org

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index b2879a6be5f8..d80e52421bf0 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1246,9 +1246,11 @@ static int pci_dev_wait(struct pci_dev *dev, char *reset_type, int timeout)
 	 * initialize.
 	 *
 	 * If the device is below a Root Port with Configuration RRS
-	 * Software Visibility enabled, reading the Vendor ID returns a
+	 * Software Visibility enabled, reading the Vendor ID may return a
 	 * special data value if the device responded with RRS.  Read the
-	 * Vendor ID until we get non-RRS status.
+	 * Vendor ID until we get non-RRS status and something other than
+	 * ~0.  The Vendor ID of VFs reads ~0, so check their Command
+	 * register instead.
 	 *
 	 * If there's no Root Port or Configuration RRS Software Visibility
 	 * is not enabled, the device may still respond with RRS, but
@@ -1268,8 +1270,13 @@ static int pci_dev_wait(struct pci_dev *dev, char *reset_type, int timeout)

 		if (root && root->config_rrs_sv) {
 			pci_read_config_dword(dev, PCI_VENDOR_ID, &id);
-			if (!pci_bus_rrs_vendor_id(id))
-				break;
+			if (!pci_bus_rrs_vendor_id(id)) {
+				if (PCI_POSSIBLE_ERROR(id) && dev->is_virtfn)
+					pci_read_config_dword(dev, PCI_COMMAND,
+							      &id);
+				if (!PCI_POSSIBLE_ERROR(id))
+					break;
+			}
 		} else {
 			pci_read_config_dword(dev, PCI_COMMAND, &id);
 			if (!PCI_POSSIBLE_ERROR(id))