diff options
author | Andre Przywara <andre.przywara@arm.com> | 2019-05-03 18:15:43 +0100 |
---|---|---|
committer | Will Deacon <will.deacon@arm.com> | 2019-05-29 15:54:28 +0100 |
commit | a3704b91cd78626ce79e8f5b163393d3396b1fc0 (patch) | |
tree | 5efeafae656a13fd72215e396fe57487b4cae327 | |
parent | 1ac5dce983fe043ad2d3432cd00a25782a89217b (diff) | |
download | kvmtool-a3704b91cd78626ce79e8f5b163393d3396b1fc0.tar.gz |
vfio: rework vfio_irq_set payload setting
struct vfio_irq_set from the kernel headers contains a variable sized
array to hold a payload. The vfio_irq_eventfd struct puts the "fd"
member right after this, hoping it to automatically fit in the payload slot.
But having a variable sized type not at the end of a struct is a GNU C
extension, so clang will refuse to compile this.
Solve this by somewhat doing the compiler's job and place the payload
manually at the end of the structure.
Reviewed-by: Jean-Philippe Brucker <jean-philippe.brucker@arm.com>
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
-rw-r--r-- | vfio/pci.c | 21 |
1 files changed, 13 insertions, 8 deletions
@@ -9,11 +9,16 @@ #include <sys/time.h> /* Wrapper around UAPI vfio_irq_set */ -struct vfio_irq_eventfd { +union vfio_irq_eventfd { struct vfio_irq_set irq; - int fd; + u8 buffer[sizeof(struct vfio_irq_set) + sizeof(int)]; }; +static void set_vfio_irq_eventd_payload(union vfio_irq_eventfd *evfd, int fd) +{ + memcpy(&evfd->irq.data, &fd, sizeof(fd)); +} + #define msi_is_enabled(state) ((state) & VFIO_PCI_MSI_STATE_ENABLED) #define msi_is_masked(state) ((state) & VFIO_PCI_MSI_STATE_MASKED) #define msi_is_empty(state) ((state) & VFIO_PCI_MSI_STATE_EMPTY) @@ -38,7 +43,7 @@ static int vfio_pci_enable_msis(struct kvm *kvm, struct vfio_device *vdev, int *eventfds; struct vfio_pci_device *pdev = &vdev->pci; struct vfio_pci_msi_common *msis = msix ? &pdev->msix : &pdev->msi; - struct vfio_irq_eventfd single = { + union vfio_irq_eventfd single = { .irq = { .argsz = sizeof(single), .flags = VFIO_IRQ_SET_DATA_EVENTFD | @@ -117,7 +122,7 @@ static int vfio_pci_enable_msis(struct kvm *kvm, struct vfio_device *vdev, continue; single.irq.start = i; - single.fd = fd; + set_vfio_irq_eventd_payload(&single, fd); ret = ioctl(vdev->fd, VFIO_DEVICE_SET_IRQS, &single); if (ret < 0) { @@ -1021,8 +1026,8 @@ static int vfio_pci_enable_intx(struct kvm *kvm, struct vfio_device *vdev) { int ret; int trigger_fd, unmask_fd; - struct vfio_irq_eventfd trigger; - struct vfio_irq_eventfd unmask; + union vfio_irq_eventfd trigger; + union vfio_irq_eventfd unmask; struct vfio_pci_device *pdev = &vdev->pci; int gsi = pdev->intx_gsi; @@ -1058,7 +1063,7 @@ static int vfio_pci_enable_intx(struct kvm *kvm, struct vfio_device *vdev) .start = 0, .count = 1, }; - trigger.fd = trigger_fd; + set_vfio_irq_eventd_payload(&trigger, trigger_fd); ret = ioctl(vdev->fd, VFIO_DEVICE_SET_IRQS, &trigger); if (ret < 0) { @@ -1073,7 +1078,7 @@ static int vfio_pci_enable_intx(struct kvm *kvm, struct vfio_device *vdev) .start = 0, .count = 1, }; - unmask.fd = unmask_fd; + set_vfio_irq_eventd_payload(&unmask, unmask_fd); ret = ioctl(vdev->fd, VFIO_DEVICE_SET_IRQS, &unmask); if (ret < 0) { |