vfio/pci: Expose vfio_pci_core_iowrite/read##size()
authorYishai Hadas <yishaih@nvidia.com>
Tue, 19 Dec 2023 09:32:46 +0000 (11:32 +0200)
committerAlex Williamson <alex.williamson@redhat.com>
Tue, 19 Dec 2023 18:51:33 +0000 (11:51 -0700)
Expose vfio_pci_core_iowrite/read##size() to let it be used by drivers.

This functionality is needed to enable direct access to some physical
BAR of the device with the proper locks/checks in place.

The next patches from this series will use this functionality on a data
path flow when a direct access to the BAR is needed.

Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Signed-off-by: Yishai Hadas <yishaih@nvidia.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Link: https://lore.kernel.org/r/20231219093247.170936-9-yishaih@nvidia.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
drivers/vfio/pci/vfio_pci_rdwr.c
include/linux/vfio_pci_core.h

index a9887fd6de46c81da27049f4ee88997ba50758db..07fea08ea8a21340cacef113b238adea5dc8b59d 100644 (file)
@@ -38,7 +38,7 @@
 #define vfio_iowrite8  iowrite8
 
 #define VFIO_IOWRITE(size) \
-static int vfio_pci_iowrite##size(struct vfio_pci_core_device *vdev,           \
+int vfio_pci_core_iowrite##size(struct vfio_pci_core_device *vdev,     \
                        bool test_mem, u##size val, void __iomem *io)   \
 {                                                                      \
        if (test_mem) {                                                 \
@@ -55,7 +55,8 @@ static int vfio_pci_iowrite##size(struct vfio_pci_core_device *vdev,          \
                up_read(&vdev->memory_lock);                            \
                                                                        \
        return 0;                                                       \
-}
+}                                                                      \
+EXPORT_SYMBOL_GPL(vfio_pci_core_iowrite##size);
 
 VFIO_IOWRITE(8)
 VFIO_IOWRITE(16)
@@ -65,7 +66,7 @@ VFIO_IOWRITE(64)
 #endif
 
 #define VFIO_IOREAD(size) \
-static int vfio_pci_ioread##size(struct vfio_pci_core_device *vdev,            \
+int vfio_pci_core_ioread##size(struct vfio_pci_core_device *vdev,      \
                        bool test_mem, u##size *val, void __iomem *io)  \
 {                                                                      \
        if (test_mem) {                                                 \
@@ -82,7 +83,8 @@ static int vfio_pci_ioread##size(struct vfio_pci_core_device *vdev,           \
                up_read(&vdev->memory_lock);                            \
                                                                        \
        return 0;                                                       \
-}
+}                                                                      \
+EXPORT_SYMBOL_GPL(vfio_pci_core_ioread##size);
 
 VFIO_IOREAD(8)
 VFIO_IOREAD(16)
@@ -119,13 +121,13 @@ static ssize_t do_io_rw(struct vfio_pci_core_device *vdev, bool test_mem,
                                if (copy_from_user(&val, buf, 4))
                                        return -EFAULT;
 
-                               ret = vfio_pci_iowrite32(vdev, test_mem,
-                                                        val, io + off);
+                               ret = vfio_pci_core_iowrite32(vdev, test_mem,
+                                                             val, io + off);
                                if (ret)
                                        return ret;
                        } else {
-                               ret = vfio_pci_ioread32(vdev, test_mem,
-                                                       &val, io + off);
+                               ret = vfio_pci_core_ioread32(vdev, test_mem,
+                                                            &val, io + off);
                                if (ret)
                                        return ret;
 
@@ -141,13 +143,13 @@ static ssize_t do_io_rw(struct vfio_pci_core_device *vdev, bool test_mem,
                                if (copy_from_user(&val, buf, 2))
                                        return -EFAULT;
 
-                               ret = vfio_pci_iowrite16(vdev, test_mem,
-                                                        val, io + off);
+                               ret = vfio_pci_core_iowrite16(vdev, test_mem,
+                                                             val, io + off);
                                if (ret)
                                        return ret;
                        } else {
-                               ret = vfio_pci_ioread16(vdev, test_mem,
-                                                       &val, io + off);
+                               ret = vfio_pci_core_ioread16(vdev, test_mem,
+                                                            &val, io + off);
                                if (ret)
                                        return ret;
 
@@ -163,13 +165,13 @@ static ssize_t do_io_rw(struct vfio_pci_core_device *vdev, bool test_mem,
                                if (copy_from_user(&val, buf, 1))
                                        return -EFAULT;
 
-                               ret = vfio_pci_iowrite8(vdev, test_mem,
-                                                       val, io + off);
+                               ret = vfio_pci_core_iowrite8(vdev, test_mem,
+                                                            val, io + off);
                                if (ret)
                                        return ret;
                        } else {
-                               ret = vfio_pci_ioread8(vdev, test_mem,
-                                                      &val, io + off);
+                               ret = vfio_pci_core_ioread8(vdev, test_mem,
+                                                           &val, io + off);
                                if (ret)
                                        return ret;
 
@@ -364,21 +366,21 @@ static void vfio_pci_ioeventfd_do_write(struct vfio_pci_ioeventfd *ioeventfd,
 {
        switch (ioeventfd->count) {
        case 1:
-               vfio_pci_iowrite8(ioeventfd->vdev, test_mem,
-                                 ioeventfd->data, ioeventfd->addr);
+               vfio_pci_core_iowrite8(ioeventfd->vdev, test_mem,
+                                      ioeventfd->data, ioeventfd->addr);
                break;
        case 2:
-               vfio_pci_iowrite16(ioeventfd->vdev, test_mem,
-                                  ioeventfd->data, ioeventfd->addr);
+               vfio_pci_core_iowrite16(ioeventfd->vdev, test_mem,
+                                       ioeventfd->data, ioeventfd->addr);
                break;
        case 4:
-               vfio_pci_iowrite32(ioeventfd->vdev, test_mem,
-                                  ioeventfd->data, ioeventfd->addr);
+               vfio_pci_core_iowrite32(ioeventfd->vdev, test_mem,
+                                       ioeventfd->data, ioeventfd->addr);
                break;
 #ifdef iowrite64
        case 8:
-               vfio_pci_iowrite64(ioeventfd->vdev, test_mem,
-                                  ioeventfd->data, ioeventfd->addr);
+               vfio_pci_core_iowrite64(ioeventfd->vdev, test_mem,
+                                       ioeventfd->data, ioeventfd->addr);
                break;
 #endif
        }
index 67ac58e20e1da3135c28c22913208fc3238fe490..85e84b92751b67354ad6671d945cd39069afcdcc 100644 (file)
@@ -131,4 +131,23 @@ int vfio_pci_core_setup_barmap(struct vfio_pci_core_device *vdev, int bar);
 pci_ers_result_t vfio_pci_core_aer_err_detected(struct pci_dev *pdev,
                                                pci_channel_state_t state);
 
+#define VFIO_IOWRITE_DECLATION(size) \
+int vfio_pci_core_iowrite##size(struct vfio_pci_core_device *vdev,     \
+                       bool test_mem, u##size val, void __iomem *io);
+
+VFIO_IOWRITE_DECLATION(8)
+VFIO_IOWRITE_DECLATION(16)
+VFIO_IOWRITE_DECLATION(32)
+#ifdef iowrite64
+VFIO_IOWRITE_DECLATION(64)
+#endif
+
+#define VFIO_IOREAD_DECLATION(size) \
+int vfio_pci_core_ioread##size(struct vfio_pci_core_device *vdev,      \
+                       bool test_mem, u##size *val, void __iomem *io);
+
+VFIO_IOREAD_DECLATION(8)
+VFIO_IOREAD_DECLATION(16)
+VFIO_IOREAD_DECLATION(32)
+
 #endif /* VFIO_PCI_CORE_H */