Skip to content

Commit f66b07c

Browse files
committed
Merge tag 'vfio-v6.11-rc1' of https://github.com/awilliam/linux-vfio
Pull VFIO updates from Alex Williamson: - Add support for 8-byte accesses when using read/write through the device regions. This fills a gap for userspace drivers that might not be able to use access through mmap to perform native register width accesses (Gerd Bayer) - Add missing MODULE_DESCRIPTION to vfio-mdev sample drivers and replace a non-standard MODULE_INFO usage (Jeff Johnson) * tag 'vfio-v6.11-rc1' of https://github.com/awilliam/linux-vfio: vfio-mdev: add missing MODULE_DESCRIPTION() macros vfio/pci: Fix typo in macro to declare accessors vfio/pci: Support 8-byte PCI loads and stores vfio/pci: Extract duplicated code into macro
2 parents 4305ca0 + 0756bec commit f66b07c

File tree

6 files changed

+78
-70
lines changed

6 files changed

+78
-70
lines changed

drivers/vfio/pci/vfio_pci_rdwr.c

Lines changed: 62 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,47 @@ EXPORT_SYMBOL_GPL(vfio_pci_core_ioread##size);
8989
VFIO_IOREAD(8)
9090
VFIO_IOREAD(16)
9191
VFIO_IOREAD(32)
92+
#ifdef ioread64
93+
VFIO_IOREAD(64)
94+
#endif
95+
96+
#define VFIO_IORDWR(size) \
97+
static int vfio_pci_iordwr##size(struct vfio_pci_core_device *vdev,\
98+
bool iswrite, bool test_mem, \
99+
void __iomem *io, char __user *buf, \
100+
loff_t off, size_t *filled) \
101+
{ \
102+
u##size val; \
103+
int ret; \
104+
\
105+
if (iswrite) { \
106+
if (copy_from_user(&val, buf, sizeof(val))) \
107+
return -EFAULT; \
108+
\
109+
ret = vfio_pci_core_iowrite##size(vdev, test_mem, \
110+
val, io + off); \
111+
if (ret) \
112+
return ret; \
113+
} else { \
114+
ret = vfio_pci_core_ioread##size(vdev, test_mem, \
115+
&val, io + off); \
116+
if (ret) \
117+
return ret; \
118+
\
119+
if (copy_to_user(buf, &val, sizeof(val))) \
120+
return -EFAULT; \
121+
} \
122+
\
123+
*filled = sizeof(val); \
124+
return 0; \
125+
} \
126+
127+
VFIO_IORDWR(8)
128+
VFIO_IORDWR(16)
129+
VFIO_IORDWR(32)
130+
#if defined(ioread64) && defined(iowrite64)
131+
VFIO_IORDWR(64)
132+
#endif
92133

93134
/*
94135
* Read or write from an __iomem region (MMIO or I/O port) with an excluded
@@ -114,72 +155,33 @@ ssize_t vfio_pci_core_do_io_rw(struct vfio_pci_core_device *vdev, bool test_mem,
114155
else
115156
fillable = 0;
116157

158+
#if defined(ioread64) && defined(iowrite64)
159+
if (fillable >= 8 && !(off % 8)) {
160+
ret = vfio_pci_iordwr64(vdev, iswrite, test_mem,
161+
io, buf, off, &filled);
162+
if (ret)
163+
return ret;
164+
165+
} else
166+
#endif
117167
if (fillable >= 4 && !(off % 4)) {
118-
u32 val;
119-
120-
if (iswrite) {
121-
if (copy_from_user(&val, buf, 4))
122-
return -EFAULT;
123-
124-
ret = vfio_pci_core_iowrite32(vdev, test_mem,
125-
val, io + off);
126-
if (ret)
127-
return ret;
128-
} else {
129-
ret = vfio_pci_core_ioread32(vdev, test_mem,
130-
&val, io + off);
131-
if (ret)
132-
return ret;
133-
134-
if (copy_to_user(buf, &val, 4))
135-
return -EFAULT;
136-
}
168+
ret = vfio_pci_iordwr32(vdev, iswrite, test_mem,
169+
io, buf, off, &filled);
170+
if (ret)
171+
return ret;
137172

138-
filled = 4;
139173
} else if (fillable >= 2 && !(off % 2)) {
140-
u16 val;
141-
142-
if (iswrite) {
143-
if (copy_from_user(&val, buf, 2))
144-
return -EFAULT;
145-
146-
ret = vfio_pci_core_iowrite16(vdev, test_mem,
147-
val, io + off);
148-
if (ret)
149-
return ret;
150-
} else {
151-
ret = vfio_pci_core_ioread16(vdev, test_mem,
152-
&val, io + off);
153-
if (ret)
154-
return ret;
155-
156-
if (copy_to_user(buf, &val, 2))
157-
return -EFAULT;
158-
}
174+
ret = vfio_pci_iordwr16(vdev, iswrite, test_mem,
175+
io, buf, off, &filled);
176+
if (ret)
177+
return ret;
159178

160-
filled = 2;
161179
} else if (fillable) {
162-
u8 val;
163-
164-
if (iswrite) {
165-
if (copy_from_user(&val, buf, 1))
166-
return -EFAULT;
167-
168-
ret = vfio_pci_core_iowrite8(vdev, test_mem,
169-
val, io + off);
170-
if (ret)
171-
return ret;
172-
} else {
173-
ret = vfio_pci_core_ioread8(vdev, test_mem,
174-
&val, io + off);
175-
if (ret)
176-
return ret;
177-
178-
if (copy_to_user(buf, &val, 1))
179-
return -EFAULT;
180-
}
180+
ret = vfio_pci_iordwr8(vdev, iswrite, test_mem,
181+
io, buf, off, &filled);
182+
if (ret)
183+
return ret;
181184

182-
filled = 1;
183185
} else {
184186
/* Fill reads with -1, drop writes */
185187
filled = min(count, (size_t)(x_end - off));

include/linux/vfio_pci_core.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,23 +137,26 @@ bool vfio_pci_core_range_intersect_range(loff_t buf_start, size_t buf_cnt,
137137
loff_t *buf_offset,
138138
size_t *intersect_count,
139139
size_t *register_offset);
140-
#define VFIO_IOWRITE_DECLATION(size) \
140+
#define VFIO_IOWRITE_DECLARATION(size) \
141141
int vfio_pci_core_iowrite##size(struct vfio_pci_core_device *vdev, \
142142
bool test_mem, u##size val, void __iomem *io);
143143

144-
VFIO_IOWRITE_DECLATION(8)
145-
VFIO_IOWRITE_DECLATION(16)
146-
VFIO_IOWRITE_DECLATION(32)
144+
VFIO_IOWRITE_DECLARATION(8)
145+
VFIO_IOWRITE_DECLARATION(16)
146+
VFIO_IOWRITE_DECLARATION(32)
147147
#ifdef iowrite64
148-
VFIO_IOWRITE_DECLATION(64)
148+
VFIO_IOWRITE_DECLARATION(64)
149149
#endif
150150

151-
#define VFIO_IOREAD_DECLATION(size) \
151+
#define VFIO_IOREAD_DECLARATION(size) \
152152
int vfio_pci_core_ioread##size(struct vfio_pci_core_device *vdev, \
153153
bool test_mem, u##size *val, void __iomem *io);
154154

155-
VFIO_IOREAD_DECLATION(8)
156-
VFIO_IOREAD_DECLATION(16)
157-
VFIO_IOREAD_DECLATION(32)
155+
VFIO_IOREAD_DECLARATION(8)
156+
VFIO_IOREAD_DECLARATION(16)
157+
VFIO_IOREAD_DECLARATION(32)
158+
#ifdef ioread64
159+
VFIO_IOREAD_DECLARATION(64)
160+
#endif
158161

159162
#endif /* VFIO_PCI_CORE_H */

samples/vfio-mdev/mbochs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
#define STORE_LE32(addr, val) (*(u32 *)addr = val)
8989

9090

91+
MODULE_DESCRIPTION("Mediated virtual PCI display host device driver");
9192
MODULE_LICENSE("GPL v2");
9293

9394
static int max_mbytes = 256;

samples/vfio-mdev/mdpy-fb.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,4 +229,5 @@ static int __init mdpy_fb_init(void)
229229
module_init(mdpy_fb_init);
230230

231231
MODULE_DEVICE_TABLE(pci, mdpy_fb_pci_table);
232+
MODULE_DESCRIPTION("Framebuffer driver for mdpy (mediated virtual pci display device)");
232233
MODULE_LICENSE("GPL v2");

samples/vfio-mdev/mdpy.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#define STORE_LE32(addr, val) (*(u32 *)addr = val)
4141

4242

43+
MODULE_DESCRIPTION("Mediated virtual PCI display host device driver");
4344
MODULE_LICENSE("GPL v2");
4445

4546
#define MDPY_TYPE_1 "vga"

samples/vfio-mdev/mtty.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2058,6 +2058,6 @@ module_init(mtty_dev_init)
20582058
module_exit(mtty_dev_exit)
20592059

20602060
MODULE_LICENSE("GPL v2");
2061-
MODULE_INFO(supported, "Test driver that simulate serial port over PCI");
2061+
MODULE_DESCRIPTION("Test driver that simulate serial port over PCI");
20622062
MODULE_VERSION(VERSION_STRING);
20632063
MODULE_AUTHOR(DRIVER_AUTHOR);

0 commit comments

Comments
 (0)