Skip to content

Commit 3503895

Browse files
committed
virtio_pci: move structure to a header
These are guest/host interfaces, so they belong in the header where e.g. qemu will know to find them. Note: we added a new structure as opposed to extending existing one because someone might be relying on the size of the existing structure staying unchanged. Add a warning to avoid using sizeof. Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
1 parent 86f6c22 commit 3503895

3 files changed

Lines changed: 15 additions & 10 deletions

File tree

drivers/virtio/virtio_pci_modern_dev.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,10 @@ int vp_modern_probe(struct virtio_pci_modern_device *mdev)
294294

295295
err = -EINVAL;
296296
mdev->common = vp_modern_map_capability(mdev, common,
297-
sizeof(struct virtio_pci_common_cfg), 4,
298-
0, sizeof(struct virtio_pci_modern_common_cfg),
299-
&mdev->common_len, NULL);
297+
sizeof(struct virtio_pci_common_cfg), 4, 0,
298+
offsetofend(struct virtio_pci_modern_common_cfg,
299+
queue_reset),
300+
&mdev->common_len, NULL);
300301
if (!mdev->common)
301302
goto err_map_common;
302303
mdev->isr = vp_modern_map_capability(mdev, isr, sizeof(u8), 1,

include/linux/virtio_pci_modern.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@
55
#include <linux/pci.h>
66
#include <linux/virtio_pci.h>
77

8-
struct virtio_pci_modern_common_cfg {
9-
struct virtio_pci_common_cfg cfg;
10-
11-
__le16 queue_notify_data; /* read-write */
12-
__le16 queue_reset; /* read-write */
13-
};
14-
158
/**
169
* struct virtio_pci_modern_device - info for modern PCI virtio
1710
* @pci_dev: Ptr to the PCI device struct

include/uapi/linux/virtio_pci.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,17 @@ struct virtio_pci_common_cfg {
166166
__le32 queue_used_hi; /* read-write */
167167
};
168168

169+
/*
170+
* Warning: do not use sizeof on this: use offsetofend for
171+
* specific fields you need.
172+
*/
173+
struct virtio_pci_modern_common_cfg {
174+
struct virtio_pci_common_cfg cfg;
175+
176+
__le16 queue_notify_data; /* read-write */
177+
__le16 queue_reset; /* read-write */
178+
};
179+
169180
/* Fields in VIRTIO_PCI_CAP_PCI_CFG: */
170181
struct virtio_pci_cfg_cap {
171182
struct virtio_pci_cap cap;

0 commit comments

Comments
 (0)