Currently, when mapping a sparse BAR fails, we reset the number of sparse
areas recorded for that BAR. However, BAR records live in memory that
is shared between primary and secondary processes, so when a secondary
process fails to map a BAR, it wipes the record that the primary process
and all other secondary processes rely on.

There is actually no need for the reset to begin with, because when mapping
fails in the primary process, the records are discarded anyway. Fix it
by leaving the record alone.

Fixes: f60abf9757f2 ("bus/pci: add VFIO sparse mmap")
Cc: [email protected]
Cc: [email protected]

Signed-off-by: Anatoly Burakov <[email protected]>
---
 drivers/bus/pci/linux/pci_vfio.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/bus/pci/linux/pci_vfio.c b/drivers/bus/pci/linux/pci_vfio.c
index 4363d7ff2c3..986b0322588 100644
--- a/drivers/bus/pci/linux/pci_vfio.c
+++ b/drivers/bus/pci/linux/pci_vfio.c
@@ -594,21 +594,17 @@ pci_vfio_sparse_mmap_bar(int vfio_dev_fd, struct 
mapped_pci_resource *vfio_res,
                                if (map_addr == NULL) {
                                        munmap(bar_addr, bar->size);
                                        PCI_LOG(ERR, "Failed to map pci BAR%d", 
bar_index);
-                                       goto err_map;
+                                       return -1;
                                }
                        }
                }
        } else {
                PCI_LOG(ERR, "Failed to create inaccessible mapping for BAR%d", 
bar_index);
-               goto err_map;
+               return -1;
        }
 
        bar->addr = bar_addr;
        return 0;
-
-err_map:
-       bar->nr_areas = 0;
-       return -1;
 }
 
 /*
-- 
2.52.0

Reply via email to