Since "vfio/pci: Set up barmap in vfio_pci_core_enable()", the BAR
mapping and resource acquisition are done at setup time, and most uses
of vfio_pci_core_setup_barmap() are now unnecessary.  Remove the
callers, and the function.

Some callers used it to also test if a mapping is present before a
direct access, and these places now do a simple test of
vdev->barmap[].

Signed-off-by: Matt Evans <[email protected]>
---
 drivers/vfio/pci/nvgrace-gpu/main.c | 11 +++++------
 drivers/vfio/pci/vfio_pci_core.c    |  8 --------
 drivers/vfio/pci/vfio_pci_rdwr.c    | 22 ++++------------------
 drivers/vfio/pci/virtio/legacy_io.c |  5 ++---
 4 files changed, 11 insertions(+), 35 deletions(-)

diff --git a/drivers/vfio/pci/nvgrace-gpu/main.c 
b/drivers/vfio/pci/nvgrace-gpu/main.c
index fa056b69f899..3712f6b54d46 100644
--- a/drivers/vfio/pci/nvgrace-gpu/main.c
+++ b/drivers/vfio/pci/nvgrace-gpu/main.c
@@ -184,14 +184,13 @@ static int nvgrace_gpu_open_device(struct vfio_device 
*core_vdev)
 
        /*
         * GPU readiness is checked by reading the BAR0 registers.
-        *
-        * ioremap BAR0 to ensure that the BAR0 mapping is present before
-        * register reads on first fault before establishing any GPU
-        * memory mapping.
+        * BARs should have been mapped at device enable, but it's
+        * good to assert they're present before the access:
         */
-       ret = vfio_pci_core_setup_barmap(vdev, 0);
-       if (ret)
+       if (!vdev->barmap[0]) {
+               ret = -EINVAL;
                goto error_exit;
+       }
 
        if (nvdev->resmem.memlength) {
                ret = nvgrace_gpu_vfio_pci_register_pfn_range(core_vdev, 
&nvdev->resmem);
diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
index 4a314213f3ae..228d92ce61d1 100644
--- a/drivers/vfio/pci/vfio_pci_core.c
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -1805,14 +1805,6 @@ int vfio_pci_core_mmap(struct vfio_device *core_vdev, 
struct vm_area_struct *vma
        if (req_start + req_len > phys_len)
                return -EINVAL;
 
-       /*
-        * Even though we don't make use of the barmap for the mmap,
-        * we need to request the region and the barmap tracks that.
-        */
-       ret = vfio_pci_core_setup_barmap(vdev, index);
-       if (ret)
-               return ret;
-
        vma->vm_private_data = vdev;
        vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
        vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot);
diff --git a/drivers/vfio/pci/vfio_pci_rdwr.c b/drivers/vfio/pci/vfio_pci_rdwr.c
index d1386a31a3a3..21e19ed48bf5 100644
--- a/drivers/vfio/pci/vfio_pci_rdwr.c
+++ b/drivers/vfio/pci/vfio_pci_rdwr.c
@@ -198,18 +198,6 @@ ssize_t vfio_pci_core_do_io_rw(struct vfio_pci_core_device 
*vdev, bool test_mem,
 }
 EXPORT_SYMBOL_GPL(vfio_pci_core_do_io_rw);
 
-int vfio_pci_core_setup_barmap(struct vfio_pci_core_device *vdev, int bar)
-{
-       /*
-        * The barmap is now always set up in vfio_pci_core_enable().
-        * Some legacy callers use this function to check if the BAR
-        * is legitimate, so maintain that:
-        */
-
-       return vdev->barmap[bar] ? 0 : -EBUSY;
-}
-EXPORT_SYMBOL_GPL(vfio_pci_core_setup_barmap);
-
 ssize_t vfio_pci_bar_rw(struct vfio_pci_core_device *vdev, char __user *buf,
                        size_t count, loff_t *ppos, bool iswrite)
 {
@@ -261,9 +249,8 @@ ssize_t vfio_pci_bar_rw(struct vfio_pci_core_device *vdev, 
char __user *buf,
                 */
                max_width = VFIO_PCI_IO_WIDTH_4;
        } else {
-               int ret = vfio_pci_core_setup_barmap(vdev, bar);
-               if (ret) {
-                       done = ret;
+               if (!vdev->barmap[bar]) {
+                       done = -EINVAL;
                        goto out;
                }
 
@@ -439,9 +426,8 @@ int vfio_pci_ioeventfd(struct vfio_pci_core_device *vdev, 
loff_t offset,
        if (count == 8)
                return -EINVAL;
 
-       ret = vfio_pci_core_setup_barmap(vdev, bar);
-       if (ret)
-               return ret;
+       if (!vdev->barmap[bar])
+               return -EINVAL;
 
        mutex_lock(&vdev->ioeventfds_lock);
 
diff --git a/drivers/vfio/pci/virtio/legacy_io.c 
b/drivers/vfio/pci/virtio/legacy_io.c
index 1ed349a55629..67f93b96c099 100644
--- a/drivers/vfio/pci/virtio/legacy_io.c
+++ b/drivers/vfio/pci/virtio/legacy_io.c
@@ -305,9 +305,8 @@ static int virtiovf_set_notify_addr(struct 
virtiovf_pci_core_device *virtvdev)
         * Setup the BAR where the 'notify' exists to be used by vfio as well
         * This will let us mmap it only once and use it when needed.
         */
-       ret = vfio_pci_core_setup_barmap(core_device,
-                                        virtvdev->notify_bar);
-       if (ret)
+       if (virtvdev->notify_bar >= PCI_STD_NUM_BARS ||
+           !core_device->barmap[virtvdev->notify_bar])
                return ret;
 
        virtvdev->notify_addr = core_device->barmap[virtvdev->notify_bar] +
-- 
2.47.3


Reply via email to