]> git.ipfire.org Git - people/arne_f/kernel.git/commitdiff
s390/pci: recognize name clashes with uids
authorSebastian Ott <sebott@linux.vnet.ibm.com>
Wed, 21 Jun 2017 08:20:35 +0000 (10:20 +0200)
committerMartin Schwidefsky <schwidefsky@de.ibm.com>
Wed, 28 Jun 2017 05:32:14 +0000 (07:32 +0200)
When uid checking is enabled firmware guarantees uniqueness of the uids
and we use them for device enumeration. Tests have shown that uid checking
can be toggled at runtime. This is unfortunate since it can lead to name
clashes.

Recognize these name clashes by allocating bits in zpci_domain even for
firmware provided ids.

Signed-off-by: Sebastian Ott <sebott@linux.vnet.ibm.com>
Reviewed-by: Pierre Morel <pmorel@linux.vnet.ibm.com>
Reviewed-by: Gerald Schaefer <gerald.schaefer@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
arch/s390/pci/pci.c

index d5c7444a0c05faff72cbcc42b01f2e14be50ccff..7b30af5da222a947cceb1cf226945884e0682847 100644 (file)
@@ -736,6 +736,16 @@ static int zpci_alloc_domain(struct zpci_dev *zdev)
 {
        if (zpci_unique_uid) {
                zdev->domain = (u16) zdev->uid;
+               if (zdev->domain >= ZPCI_NR_DEVICES)
+                       return 0;
+
+               spin_lock(&zpci_domain_lock);
+               if (test_bit(zdev->domain, zpci_domain)) {
+                       spin_unlock(&zpci_domain_lock);
+                       return -EEXIST;
+               }
+               set_bit(zdev->domain, zpci_domain);
+               spin_unlock(&zpci_domain_lock);
                return 0;
        }
 
@@ -752,7 +762,7 @@ static int zpci_alloc_domain(struct zpci_dev *zdev)
 
 static void zpci_free_domain(struct zpci_dev *zdev)
 {
-       if (zpci_unique_uid)
+       if (zdev->domain >= ZPCI_NR_DEVICES)
                return;
 
        spin_lock(&zpci_domain_lock);