x86/pci: Comment pci_mmconfig_insert() obscure MCFG dependency
authorBjorn Helgaas <bhelgaas@google.com>
Tue, 21 Nov 2023 18:36:41 +0000 (12:36 -0600)
committerBjorn Helgaas <bhelgaas@google.com>
Tue, 5 Dec 2023 16:56:56 +0000 (10:56 -0600)
In pci_mmconfig_insert(), there's no reference to "addr" between locking
pci_mmcfg_lock and testing "addr", so it *looks* like we should move the
test before the lock.

But 07f9b61c3915 ("x86/PCI: MMCONFIG: Check earlier for MMCONFIG region at
address zero") did that, which broke things by returning -EINVAL when
"addr" is zero instead of -EEXIST.

So 07f9b61c3915 was reverted by 67d470e0e171 ("Revert "x86/PCI: MMCONFIG:
Check earlier for MMCONFIG region at address zero"").

Add a comment about this issue to prevent it from happening again.

Link: https://lore.kernel.org/r/20231121183643.249006-8-helgaas@kernel.org
Tested-by: Tomasz Pala <gotar@polanet.pl>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
arch/x86/pci/mmconfig-shared.c

index b36c10e..459e957 100644 (file)
@@ -786,6 +786,10 @@ int pci_mmconfig_insert(struct device *dev, u16 seg, u8 start, u8 end,
                return -EEXIST;
        }
 
+       /*
+        * Don't move earlier; we must return -EEXIST, not -EINVAL, if
+        * pci_mmconfig_lookup() finds something
+        */
        if (!addr) {
                mutex_unlock(&pci_mmcfg_lock);
                return -EINVAL;