Skip to content

Commit 8486ae1

Browse files
yishaihAlex Williamson
authored andcommitted
vfio/pci: Expose vfio_pci_core_iowrite/read##size()
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>
1 parent 8bccc5b commit 8486ae1

2 files changed

Lines changed: 45 additions & 24 deletions

File tree

drivers/vfio/pci/vfio_pci_rdwr.c

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#define vfio_iowrite8 iowrite8
3939

4040
#define VFIO_IOWRITE(size) \
41-
static int vfio_pci_iowrite##size(struct vfio_pci_core_device *vdev, \
41+
int vfio_pci_core_iowrite##size(struct vfio_pci_core_device *vdev, \
4242
bool test_mem, u##size val, void __iomem *io) \
4343
{ \
4444
if (test_mem) { \
@@ -55,7 +55,8 @@ static int vfio_pci_iowrite##size(struct vfio_pci_core_device *vdev, \
5555
up_read(&vdev->memory_lock); \
5656
\
5757
return 0; \
58-
}
58+
} \
59+
EXPORT_SYMBOL_GPL(vfio_pci_core_iowrite##size);
5960

6061
VFIO_IOWRITE(8)
6162
VFIO_IOWRITE(16)
@@ -65,7 +66,7 @@ VFIO_IOWRITE(64)
6566
#endif
6667

6768
#define VFIO_IOREAD(size) \
68-
static int vfio_pci_ioread##size(struct vfio_pci_core_device *vdev, \
69+
int vfio_pci_core_ioread##size(struct vfio_pci_core_device *vdev, \
6970
bool test_mem, u##size *val, void __iomem *io) \
7071
{ \
7172
if (test_mem) { \
@@ -82,7 +83,8 @@ static int vfio_pci_ioread##size(struct vfio_pci_core_device *vdev, \
8283
up_read(&vdev->memory_lock); \
8384
\
8485
return 0; \
85-
}
86+
} \
87+
EXPORT_SYMBOL_GPL(vfio_pci_core_ioread##size);
8688

8789
VFIO_IOREAD(8)
8890
VFIO_IOREAD(16)
@@ -119,13 +121,13 @@ static ssize_t do_io_rw(struct vfio_pci_core_device *vdev, bool test_mem,
119121
if (copy_from_user(&val, buf, 4))
120122
return -EFAULT;
121123

122-
ret = vfio_pci_iowrite32(vdev, test_mem,
123-
val, io + off);
124+
ret = vfio_pci_core_iowrite32(vdev, test_mem,
125+
val, io + off);
124126
if (ret)
125127
return ret;
126128
} else {
127-
ret = vfio_pci_ioread32(vdev, test_mem,
128-
&val, io + off);
129+
ret = vfio_pci_core_ioread32(vdev, test_mem,
130+
&val, io + off);
129131
if (ret)
130132
return ret;
131133

@@ -141,13 +143,13 @@ static ssize_t do_io_rw(struct vfio_pci_core_device *vdev, bool test_mem,
141143
if (copy_from_user(&val, buf, 2))
142144
return -EFAULT;
143145

144-
ret = vfio_pci_iowrite16(vdev, test_mem,
145-
val, io + off);
146+
ret = vfio_pci_core_iowrite16(vdev, test_mem,
147+
val, io + off);
146148
if (ret)
147149
return ret;
148150
} else {
149-
ret = vfio_pci_ioread16(vdev, test_mem,
150-
&val, io + off);
151+
ret = vfio_pci_core_ioread16(vdev, test_mem,
152+
&val, io + off);
151153
if (ret)
152154
return ret;
153155

@@ -163,13 +165,13 @@ static ssize_t do_io_rw(struct vfio_pci_core_device *vdev, bool test_mem,
163165
if (copy_from_user(&val, buf, 1))
164166
return -EFAULT;
165167

166-
ret = vfio_pci_iowrite8(vdev, test_mem,
167-
val, io + off);
168+
ret = vfio_pci_core_iowrite8(vdev, test_mem,
169+
val, io + off);
168170
if (ret)
169171
return ret;
170172
} else {
171-
ret = vfio_pci_ioread8(vdev, test_mem,
172-
&val, io + off);
173+
ret = vfio_pci_core_ioread8(vdev, test_mem,
174+
&val, io + off);
173175
if (ret)
174176
return ret;
175177

@@ -364,21 +366,21 @@ static void vfio_pci_ioeventfd_do_write(struct vfio_pci_ioeventfd *ioeventfd,
364366
{
365367
switch (ioeventfd->count) {
366368
case 1:
367-
vfio_pci_iowrite8(ioeventfd->vdev, test_mem,
368-
ioeventfd->data, ioeventfd->addr);
369+
vfio_pci_core_iowrite8(ioeventfd->vdev, test_mem,
370+
ioeventfd->data, ioeventfd->addr);
369371
break;
370372
case 2:
371-
vfio_pci_iowrite16(ioeventfd->vdev, test_mem,
372-
ioeventfd->data, ioeventfd->addr);
373+
vfio_pci_core_iowrite16(ioeventfd->vdev, test_mem,
374+
ioeventfd->data, ioeventfd->addr);
373375
break;
374376
case 4:
375-
vfio_pci_iowrite32(ioeventfd->vdev, test_mem,
376-
ioeventfd->data, ioeventfd->addr);
377+
vfio_pci_core_iowrite32(ioeventfd->vdev, test_mem,
378+
ioeventfd->data, ioeventfd->addr);
377379
break;
378380
#ifdef iowrite64
379381
case 8:
380-
vfio_pci_iowrite64(ioeventfd->vdev, test_mem,
381-
ioeventfd->data, ioeventfd->addr);
382+
vfio_pci_core_iowrite64(ioeventfd->vdev, test_mem,
383+
ioeventfd->data, ioeventfd->addr);
382384
break;
383385
#endif
384386
}

include/linux/vfio_pci_core.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,23 @@ int vfio_pci_core_setup_barmap(struct vfio_pci_core_device *vdev, int bar);
131131
pci_ers_result_t vfio_pci_core_aer_err_detected(struct pci_dev *pdev,
132132
pci_channel_state_t state);
133133

134+
#define VFIO_IOWRITE_DECLATION(size) \
135+
int vfio_pci_core_iowrite##size(struct vfio_pci_core_device *vdev, \
136+
bool test_mem, u##size val, void __iomem *io);
137+
138+
VFIO_IOWRITE_DECLATION(8)
139+
VFIO_IOWRITE_DECLATION(16)
140+
VFIO_IOWRITE_DECLATION(32)
141+
#ifdef iowrite64
142+
VFIO_IOWRITE_DECLATION(64)
143+
#endif
144+
145+
#define VFIO_IOREAD_DECLATION(size) \
146+
int vfio_pci_core_ioread##size(struct vfio_pci_core_device *vdev, \
147+
bool test_mem, u##size *val, void __iomem *io);
148+
149+
VFIO_IOREAD_DECLATION(8)
150+
VFIO_IOREAD_DECLATION(16)
151+
VFIO_IOREAD_DECLATION(32)
152+
134153
#endif /* VFIO_PCI_CORE_H */

0 commit comments

Comments
 (0)