|
|
5d360b |
From ec24bb3a66429e7b1d086ab6f3597c550099831d Mon Sep 17 00:00:00 2001
|
|
|
5d360b |
From: Alex Williamson <alex.williamson@redhat.com>
|
|
|
5d360b |
Date: Fri, 29 Sep 2017 21:44:30 +0200
|
|
|
5d360b |
Subject: [PATCH 04/27] hw/vfio/pci: introduce minimalist VFIODevice with fd
|
|
|
5d360b |
|
|
|
5d360b |
RH-Author: Alex Williamson <alex.williamson@redhat.com>
|
|
|
5d360b |
Message-id: <20170929214430.16765.39580.stgit@gimli.home>
|
|
|
5d360b |
Patchwork-id: 76762
|
|
|
5d360b |
O-Subject: [RHEL-7.5 qemu-kvm PATCH 04/16] hw/vfio/pci: introduce minimalist VFIODevice with fd
|
|
|
5d360b |
Bugzilla: 1494181
|
|
|
5d360b |
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
5d360b |
RH-Acked-by: Auger Eric <eric.auger@redhat.com>
|
|
|
5d360b |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
5d360b |
|
|
|
5d360b |
From: Eric Auger <eric.auger@linaro.org>
|
|
|
5d360b |
|
|
|
5d360b |
Upstream: 5546a621a8801351601537b311539486b9b3ee79
|
|
|
5d360b |
RHEL: Include request notifier
|
|
|
5d360b |
|
|
|
5d360b |
Introduce a new base VFIODevice strcut that will be used by both PCI
|
|
|
5d360b |
and Platform VFIO device. Move VFIOPCIDevice fd field there. Obviously
|
|
|
5d360b |
other fields from VFIOPCIDevice will be moved there but this patch
|
|
|
5d360b |
file is introduced to ease the review.
|
|
|
5d360b |
|
|
|
5d360b |
Also vfio_mask_single_irqindex, vfio_unmask_single_irqindex,
|
|
|
5d360b |
vfio_disable_irqindex now take a VFIODevice handle as argument.
|
|
|
5d360b |
|
|
|
5d360b |
Signed-off-by: Eric Auger <eric.auger@linaro.org>
|
|
|
5d360b |
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
|
|
|
5d360b |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
5d360b |
---
|
|
|
5d360b |
hw/misc/vfio.c | 123 +++++++++++++++++++++++++++++++--------------------------
|
|
|
5d360b |
1 file changed, 66 insertions(+), 57 deletions(-)
|
|
|
5d360b |
|
|
|
5d360b |
diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c
|
|
|
5d360b |
index ed9b8c4..340d967 100644
|
|
|
5d360b |
--- a/hw/misc/vfio.c
|
|
|
5d360b |
+++ b/hw/misc/vfio.c
|
|
|
5d360b |
@@ -174,9 +174,13 @@ typedef struct VFIOMSIXInfo {
|
|
|
5d360b |
void *mmap;
|
|
|
5d360b |
} VFIOMSIXInfo;
|
|
|
5d360b |
|
|
|
5d360b |
+typedef struct VFIODevice {
|
|
|
5d360b |
+ int fd;
|
|
|
5d360b |
+} VFIODevice;
|
|
|
5d360b |
+
|
|
|
5d360b |
typedef struct VFIOPCIDevice {
|
|
|
5d360b |
PCIDevice pdev;
|
|
|
5d360b |
- int fd;
|
|
|
5d360b |
+ VFIODevice vbasedev;
|
|
|
5d360b |
VFIOINTx intx;
|
|
|
5d360b |
unsigned int config_size;
|
|
|
5d360b |
uint8_t *emulated_config_bits; /* QEMU emulated bits, little-endian */
|
|
|
5d360b |
@@ -272,7 +276,7 @@ static void vfio_mmap_set_enabled(VFIOPCIDevice *vdev, bool enabled);
|
|
|
5d360b |
/*
|
|
|
5d360b |
* Common VFIO interrupt disable
|
|
|
5d360b |
*/
|
|
|
5d360b |
-static void vfio_disable_irqindex(VFIOPCIDevice *vdev, int index)
|
|
|
5d360b |
+static void vfio_disable_irqindex(VFIODevice *vbasedev, int index)
|
|
|
5d360b |
{
|
|
|
5d360b |
struct vfio_irq_set irq_set = {
|
|
|
5d360b |
.argsz = sizeof(irq_set),
|
|
|
5d360b |
@@ -282,13 +286,13 @@ static void vfio_disable_irqindex(VFIOPCIDevice *vdev, int index)
|
|
|
5d360b |
.count = 0,
|
|
|
5d360b |
};
|
|
|
5d360b |
|
|
|
5d360b |
- ioctl(vdev->fd, VFIO_DEVICE_SET_IRQS, &irq_set);
|
|
|
5d360b |
+ ioctl(vbasedev->fd, VFIO_DEVICE_SET_IRQS, &irq_set);
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
/*
|
|
|
5d360b |
* INTx
|
|
|
5d360b |
*/
|
|
|
5d360b |
-static void vfio_unmask_single_irqindex(VFIOPCIDevice *vdev, int index)
|
|
|
5d360b |
+static void vfio_unmask_single_irqindex(VFIODevice *vbasedev, int index)
|
|
|
5d360b |
{
|
|
|
5d360b |
struct vfio_irq_set irq_set = {
|
|
|
5d360b |
.argsz = sizeof(irq_set),
|
|
|
5d360b |
@@ -298,11 +302,11 @@ static void vfio_unmask_single_irqindex(VFIOPCIDevice *vdev, int index)
|
|
|
5d360b |
.count = 1,
|
|
|
5d360b |
};
|
|
|
5d360b |
|
|
|
5d360b |
- ioctl(vdev->fd, VFIO_DEVICE_SET_IRQS, &irq_set);
|
|
|
5d360b |
+ ioctl(vbasedev->fd, VFIO_DEVICE_SET_IRQS, &irq_set);
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
#ifdef CONFIG_KVM /* Unused outside of CONFIG_KVM code */
|
|
|
5d360b |
-static void vfio_mask_single_irqindex(VFIOPCIDevice *vdev, int index)
|
|
|
5d360b |
+static void vfio_mask_single_irqindex(VFIODevice *vbasedev, int index)
|
|
|
5d360b |
{
|
|
|
5d360b |
struct vfio_irq_set irq_set = {
|
|
|
5d360b |
.argsz = sizeof(irq_set),
|
|
|
5d360b |
@@ -312,7 +316,7 @@ static void vfio_mask_single_irqindex(VFIOPCIDevice *vdev, int index)
|
|
|
5d360b |
.count = 1,
|
|
|
5d360b |
};
|
|
|
5d360b |
|
|
|
5d360b |
- ioctl(vdev->fd, VFIO_DEVICE_SET_IRQS, &irq_set);
|
|
|
5d360b |
+ ioctl(vbasedev->fd, VFIO_DEVICE_SET_IRQS, &irq_set);
|
|
|
5d360b |
}
|
|
|
5d360b |
#endif
|
|
|
5d360b |
|
|
|
5d360b |
@@ -376,7 +380,7 @@ static void vfio_eoi(VFIOPCIDevice *vdev)
|
|
|
5d360b |
|
|
|
5d360b |
vdev->intx.pending = false;
|
|
|
5d360b |
qemu_set_irq(vdev->pdev.irq[vdev->intx.pin], 0);
|
|
|
5d360b |
- vfio_unmask_single_irqindex(vdev, VFIO_PCI_INTX_IRQ_INDEX);
|
|
|
5d360b |
+ vfio_unmask_single_irqindex(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
static void vfio_enable_intx_kvm(VFIOPCIDevice *vdev)
|
|
|
5d360b |
@@ -399,7 +403,7 @@ static void vfio_enable_intx_kvm(VFIOPCIDevice *vdev)
|
|
|
5d360b |
|
|
|
5d360b |
/* Get to a known interrupt state */
|
|
|
5d360b |
qemu_set_fd_handler(irqfd.fd, NULL, NULL, vdev);
|
|
|
5d360b |
- vfio_mask_single_irqindex(vdev, VFIO_PCI_INTX_IRQ_INDEX);
|
|
|
5d360b |
+ vfio_mask_single_irqindex(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
|
|
|
5d360b |
vdev->intx.pending = false;
|
|
|
5d360b |
qemu_set_irq(vdev->pdev.irq[vdev->intx.pin], 0);
|
|
|
5d360b |
|
|
|
5d360b |
@@ -429,7 +433,7 @@ static void vfio_enable_intx_kvm(VFIOPCIDevice *vdev)
|
|
|
5d360b |
|
|
|
5d360b |
*pfd = irqfd.resamplefd;
|
|
|
5d360b |
|
|
|
5d360b |
- ret = ioctl(vdev->fd, VFIO_DEVICE_SET_IRQS, irq_set);
|
|
|
5d360b |
+ ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_SET_IRQS, irq_set);
|
|
|
5d360b |
g_free(irq_set);
|
|
|
5d360b |
if (ret) {
|
|
|
5d360b |
error_report("vfio: Error: Failed to setup INTx unmask fd: %m");
|
|
|
5d360b |
@@ -437,7 +441,7 @@ static void vfio_enable_intx_kvm(VFIOPCIDevice *vdev)
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
/* Let'em rip */
|
|
|
5d360b |
- vfio_unmask_single_irqindex(vdev, VFIO_PCI_INTX_IRQ_INDEX);
|
|
|
5d360b |
+ vfio_unmask_single_irqindex(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
|
|
|
5d360b |
|
|
|
5d360b |
vdev->intx.kvm_accel = true;
|
|
|
5d360b |
|
|
|
5d360b |
@@ -454,7 +458,7 @@ fail_irqfd:
|
|
|
5d360b |
event_notifier_cleanup(&vdev->intx.unmask);
|
|
|
5d360b |
fail:
|
|
|
5d360b |
qemu_set_fd_handler(irqfd.fd, vfio_intx_interrupt, NULL, vdev);
|
|
|
5d360b |
- vfio_unmask_single_irqindex(vdev, VFIO_PCI_INTX_IRQ_INDEX);
|
|
|
5d360b |
+ vfio_unmask_single_irqindex(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
|
|
|
5d360b |
#endif
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
@@ -475,7 +479,7 @@ static void vfio_disable_intx_kvm(VFIOPCIDevice *vdev)
|
|
|
5d360b |
* Get to a known state, hardware masked, QEMU ready to accept new
|
|
|
5d360b |
* interrupts, QEMU IRQ de-asserted.
|
|
|
5d360b |
*/
|
|
|
5d360b |
- vfio_mask_single_irqindex(vdev, VFIO_PCI_INTX_IRQ_INDEX);
|
|
|
5d360b |
+ vfio_mask_single_irqindex(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
|
|
|
5d360b |
vdev->intx.pending = false;
|
|
|
5d360b |
qemu_set_irq(vdev->pdev.irq[vdev->intx.pin], 0);
|
|
|
5d360b |
|
|
|
5d360b |
@@ -493,7 +497,7 @@ static void vfio_disable_intx_kvm(VFIOPCIDevice *vdev)
|
|
|
5d360b |
vdev->intx.kvm_accel = false;
|
|
|
5d360b |
|
|
|
5d360b |
/* If we've missed an event, let it re-fire through QEMU */
|
|
|
5d360b |
- vfio_unmask_single_irqindex(vdev, VFIO_PCI_INTX_IRQ_INDEX);
|
|
|
5d360b |
+ vfio_unmask_single_irqindex(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
|
|
|
5d360b |
|
|
|
5d360b |
DPRINTF("%s(%04x:%02x:%02x.%x) KVM INTx accel disabled\n",
|
|
|
5d360b |
__func__, vdev->host.domain, vdev->host.bus,
|
|
|
5d360b |
@@ -580,7 +584,7 @@ static int vfio_enable_intx(VFIOPCIDevice *vdev)
|
|
|
5d360b |
*pfd = event_notifier_get_fd(&vdev->intx.interrupt);
|
|
|
5d360b |
qemu_set_fd_handler(*pfd, vfio_intx_interrupt, NULL, vdev);
|
|
|
5d360b |
|
|
|
5d360b |
- ret = ioctl(vdev->fd, VFIO_DEVICE_SET_IRQS, irq_set);
|
|
|
5d360b |
+ ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_SET_IRQS, irq_set);
|
|
|
5d360b |
g_free(irq_set);
|
|
|
5d360b |
if (ret) {
|
|
|
5d360b |
error_report("vfio: Error: Failed to setup INTx fd: %m");
|
|
|
5d360b |
@@ -605,7 +609,7 @@ static void vfio_disable_intx(VFIOPCIDevice *vdev)
|
|
|
5d360b |
|
|
|
5d360b |
qemu_del_timer(vdev->intx.mmap_timer);
|
|
|
5d360b |
vfio_disable_intx_kvm(vdev);
|
|
|
5d360b |
- vfio_disable_irqindex(vdev, VFIO_PCI_INTX_IRQ_INDEX);
|
|
|
5d360b |
+ vfio_disable_irqindex(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX);
|
|
|
5d360b |
vdev->intx.pending = false;
|
|
|
5d360b |
qemu_set_irq(vdev->pdev.irq[vdev->intx.pin], 0);
|
|
|
5d360b |
vfio_mmap_set_enabled(vdev, true);
|
|
|
5d360b |
@@ -695,7 +699,7 @@ static int vfio_enable_vectors(VFIOPCIDevice *vdev, bool msix)
|
|
|
5d360b |
fds[i] = fd;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
- ret = ioctl(vdev->fd, VFIO_DEVICE_SET_IRQS, irq_set);
|
|
|
5d360b |
+ ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_SET_IRQS, irq_set);
|
|
|
5d360b |
|
|
|
5d360b |
g_free(irq_set);
|
|
|
5d360b |
|
|
|
5d360b |
@@ -792,7 +796,7 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, unsigned int nr,
|
|
|
5d360b |
* increase them as needed.
|
|
|
5d360b |
*/
|
|
|
5d360b |
if (vdev->nr_vectors < nr + 1) {
|
|
|
5d360b |
- vfio_disable_irqindex(vdev, VFIO_PCI_MSIX_IRQ_INDEX);
|
|
|
5d360b |
+ vfio_disable_irqindex(&vdev->vbasedev, VFIO_PCI_MSIX_IRQ_INDEX);
|
|
|
5d360b |
vdev->nr_vectors = nr + 1;
|
|
|
5d360b |
ret = vfio_enable_vectors(vdev, true);
|
|
|
5d360b |
if (ret) {
|
|
|
5d360b |
@@ -820,7 +824,7 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, unsigned int nr,
|
|
|
5d360b |
*pfd = event_notifier_get_fd(&vector->interrupt);
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
- ret = ioctl(vdev->fd, VFIO_DEVICE_SET_IRQS, irq_set);
|
|
|
5d360b |
+ ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_SET_IRQS, irq_set);
|
|
|
5d360b |
g_free(irq_set);
|
|
|
5d360b |
if (ret) {
|
|
|
5d360b |
error_report("vfio: failed to modify vector, %d", ret);
|
|
|
5d360b |
@@ -871,7 +875,7 @@ static void vfio_msix_vector_release(PCIDevice *pdev, unsigned int nr)
|
|
|
5d360b |
|
|
|
5d360b |
*pfd = event_notifier_get_fd(&vector->interrupt);
|
|
|
5d360b |
|
|
|
5d360b |
- ioctl(vdev->fd, VFIO_DEVICE_SET_IRQS, irq_set);
|
|
|
5d360b |
+ ioctl(vdev->vbasedev.fd, VFIO_DEVICE_SET_IRQS, irq_set);
|
|
|
5d360b |
|
|
|
5d360b |
g_free(irq_set);
|
|
|
5d360b |
}
|
|
|
5d360b |
@@ -1030,7 +1034,7 @@ static void vfio_disable_msix(VFIOPCIDevice *vdev)
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
if (vdev->nr_vectors) {
|
|
|
5d360b |
- vfio_disable_irqindex(vdev, VFIO_PCI_MSIX_IRQ_INDEX);
|
|
|
5d360b |
+ vfio_disable_irqindex(&vdev->vbasedev, VFIO_PCI_MSIX_IRQ_INDEX);
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
vfio_disable_msi_common(vdev);
|
|
|
5d360b |
@@ -1041,7 +1045,7 @@ static void vfio_disable_msix(VFIOPCIDevice *vdev)
|
|
|
5d360b |
|
|
|
5d360b |
static void vfio_disable_msi(VFIOPCIDevice *vdev)
|
|
|
5d360b |
{
|
|
|
5d360b |
- vfio_disable_irqindex(vdev, VFIO_PCI_MSI_IRQ_INDEX);
|
|
|
5d360b |
+ vfio_disable_irqindex(&vdev->vbasedev, VFIO_PCI_MSI_IRQ_INDEX);
|
|
|
5d360b |
vfio_disable_msi_common(vdev);
|
|
|
5d360b |
|
|
|
5d360b |
DPRINTF("%s(%04x:%02x:%02x.%x)\n", __func__, vdev->host.domain,
|
|
|
5d360b |
@@ -1187,7 +1191,7 @@ static void vfio_pci_load_rom(VFIOPCIDevice *vdev)
|
|
|
5d360b |
off_t off = 0;
|
|
|
5d360b |
size_t bytes;
|
|
|
5d360b |
|
|
|
5d360b |
- if (ioctl(vdev->fd, VFIO_DEVICE_GET_REGION_INFO, ®_info)) {
|
|
|
5d360b |
+ if (ioctl(vdev->vbasedev.fd, VFIO_DEVICE_GET_REGION_INFO, ®_info)) {
|
|
|
5d360b |
error_report("vfio: Error getting ROM info: %m");
|
|
|
5d360b |
return;
|
|
|
5d360b |
}
|
|
|
5d360b |
@@ -1217,7 +1221,8 @@ static void vfio_pci_load_rom(VFIOPCIDevice *vdev)
|
|
|
5d360b |
memset(vdev->rom, 0xff, size);
|
|
|
5d360b |
|
|
|
5d360b |
while (size) {
|
|
|
5d360b |
- bytes = pread(vdev->fd, vdev->rom + off, size, vdev->rom_offset + off);
|
|
|
5d360b |
+ bytes = pread(vdev->vbasedev.fd, vdev->rom + off,
|
|
|
5d360b |
+ size, vdev->rom_offset + off);
|
|
|
5d360b |
if (bytes == 0) {
|
|
|
5d360b |
break;
|
|
|
5d360b |
} else if (bytes > 0) {
|
|
|
5d360b |
@@ -1290,6 +1295,7 @@ static void vfio_pci_size_rom(VFIOPCIDevice *vdev)
|
|
|
5d360b |
off_t offset = vdev->config_offset + PCI_ROM_ADDRESS;
|
|
|
5d360b |
DeviceState *dev = DEVICE(vdev);
|
|
|
5d360b |
char name[32];
|
|
|
5d360b |
+ int fd = vdev->vbasedev.fd;
|
|
|
5d360b |
|
|
|
5d360b |
if (vdev->pdev.romfile || !vdev->pdev.rom_bar) {
|
|
|
5d360b |
/* Since pci handles romfile, just print a message and return */
|
|
|
5d360b |
@@ -1308,10 +1314,10 @@ static void vfio_pci_size_rom(VFIOPCIDevice *vdev)
|
|
|
5d360b |
* Use the same size ROM BAR as the physical device. The contents
|
|
|
5d360b |
* will get filled in later when the guest tries to read it.
|
|
|
5d360b |
*/
|
|
|
5d360b |
- if (pread(vdev->fd, &orig, 4, offset) != 4 ||
|
|
|
5d360b |
- pwrite(vdev->fd, &size, 4, offset) != 4 ||
|
|
|
5d360b |
- pread(vdev->fd, &size, 4, offset) != 4 ||
|
|
|
5d360b |
- pwrite(vdev->fd, &orig, 4, offset) != 4) {
|
|
|
5d360b |
+ if (pread(fd, &orig, 4, offset) != 4 ||
|
|
|
5d360b |
+ pwrite(fd, &size, 4, offset) != 4 ||
|
|
|
5d360b |
+ pread(fd, &size, 4, offset) != 4 ||
|
|
|
5d360b |
+ pwrite(fd, &orig, 4, offset) != 4) {
|
|
|
5d360b |
error_report("%s(%04x:%02x:%02x.%x) failed: %m",
|
|
|
5d360b |
__func__, vdev->host.domain, vdev->host.bus,
|
|
|
5d360b |
vdev->host.slot, vdev->host.function);
|
|
|
5d360b |
@@ -2123,7 +2129,8 @@ static uint32_t vfio_pci_read_config(PCIDevice *pdev, uint32_t addr, int len)
|
|
|
5d360b |
if (~emu_bits & (0xffffffffU >> (32 - len * 8))) {
|
|
|
5d360b |
ssize_t ret;
|
|
|
5d360b |
|
|
|
5d360b |
- ret = pread(vdev->fd, &phys_val, len, vdev->config_offset + addr);
|
|
|
5d360b |
+ ret = pread(vdev->vbasedev.fd, &phys_val, len,
|
|
|
5d360b |
+ vdev->config_offset + addr);
|
|
|
5d360b |
if (ret != len) {
|
|
|
5d360b |
error_report("%s(%04x:%02x:%02x.%x, 0x%x, 0x%x) failed: %m",
|
|
|
5d360b |
__func__, vdev->host.domain, vdev->host.bus,
|
|
|
5d360b |
@@ -2153,7 +2160,8 @@ static void vfio_pci_write_config(PCIDevice *pdev, uint32_t addr,
|
|
|
5d360b |
vdev->host.function, addr, val, len);
|
|
|
5d360b |
|
|
|
5d360b |
/* Write everything to VFIO, let it filter out what we can't write */
|
|
|
5d360b |
- if (pwrite(vdev->fd, &val_le, len, vdev->config_offset + addr) != len) {
|
|
|
5d360b |
+ if (pwrite(vdev->vbasedev.fd, &val_le, len, vdev->config_offset + addr)
|
|
|
5d360b |
+ != len) {
|
|
|
5d360b |
error_report("%s(%04x:%02x:%02x.%x, 0x%x, 0x%x, 0x%x) failed: %m",
|
|
|
5d360b |
__func__, vdev->host.domain, vdev->host.bus,
|
|
|
5d360b |
vdev->host.slot, vdev->host.function, addr, val, len);
|
|
|
5d360b |
@@ -2389,7 +2397,7 @@ static int vfio_setup_msi(VFIOPCIDevice *vdev, int pos)
|
|
|
5d360b |
bool msi_64bit, msi_maskbit;
|
|
|
5d360b |
int ret, entries;
|
|
|
5d360b |
|
|
|
5d360b |
- if (pread(vdev->fd, &ctrl, sizeof(ctrl),
|
|
|
5d360b |
+ if (pread(vdev->vbasedev.fd, &ctrl, sizeof(ctrl),
|
|
|
5d360b |
vdev->config_offset + pos + PCI_CAP_FLAGS) != sizeof(ctrl)) {
|
|
|
5d360b |
return -errno;
|
|
|
5d360b |
}
|
|
|
5d360b |
@@ -2428,23 +2436,24 @@ static int vfio_early_setup_msix(VFIOPCIDevice *vdev)
|
|
|
5d360b |
uint8_t pos;
|
|
|
5d360b |
uint16_t ctrl;
|
|
|
5d360b |
uint32_t table, pba;
|
|
|
5d360b |
+ int fd = vdev->vbasedev.fd;
|
|
|
5d360b |
|
|
|
5d360b |
pos = pci_find_capability(&vdev->pdev, PCI_CAP_ID_MSIX);
|
|
|
5d360b |
if (!pos) {
|
|
|
5d360b |
return 0;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
- if (pread(vdev->fd, &ctrl, sizeof(ctrl),
|
|
|
5d360b |
+ if (pread(fd, &ctrl, sizeof(ctrl),
|
|
|
5d360b |
vdev->config_offset + pos + PCI_CAP_FLAGS) != sizeof(ctrl)) {
|
|
|
5d360b |
return -errno;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
- if (pread(vdev->fd, &table, sizeof(table),
|
|
|
5d360b |
+ if (pread(fd, &table, sizeof(table),
|
|
|
5d360b |
vdev->config_offset + pos + PCI_MSIX_TABLE) != sizeof(table)) {
|
|
|
5d360b |
return -errno;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
- if (pread(vdev->fd, &pba, sizeof(pba),
|
|
|
5d360b |
+ if (pread(fd, &pba, sizeof(pba),
|
|
|
5d360b |
vdev->config_offset + pos + PCI_MSIX_PBA) != sizeof(pba)) {
|
|
|
5d360b |
return -errno;
|
|
|
5d360b |
}
|
|
|
5d360b |
@@ -2628,7 +2637,7 @@ static void vfio_map_bar(VFIOPCIDevice *vdev, int nr)
|
|
|
5d360b |
vdev->host.function, nr);
|
|
|
5d360b |
|
|
|
5d360b |
/* Determine what type of BAR this is for registration */
|
|
|
5d360b |
- ret = pread(vdev->fd, &pci_bar, sizeof(pci_bar),
|
|
|
5d360b |
+ ret = pread(vdev->vbasedev.fd, &pci_bar, sizeof(pci_bar),
|
|
|
5d360b |
vdev->config_offset + PCI_BASE_ADDRESS_0 + (4 * nr));
|
|
|
5d360b |
if (ret != sizeof(pci_bar)) {
|
|
|
5d360b |
error_report("vfio: Failed to read BAR %d (%m)", nr);
|
|
|
5d360b |
@@ -3054,7 +3063,7 @@ static int vfio_pci_hot_reset(VFIOPCIDevice *vdev, bool single)
|
|
|
5d360b |
info = g_malloc0(sizeof(*info));
|
|
|
5d360b |
info->argsz = sizeof(*info);
|
|
|
5d360b |
|
|
|
5d360b |
- ret = ioctl(vdev->fd, VFIO_DEVICE_GET_PCI_HOT_RESET_INFO, info);
|
|
|
5d360b |
+ ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_GET_PCI_HOT_RESET_INFO, info);
|
|
|
5d360b |
if (ret && errno != ENOSPC) {
|
|
|
5d360b |
ret = -errno;
|
|
|
5d360b |
if (!vdev->has_pm_reset) {
|
|
|
5d360b |
@@ -3070,7 +3079,7 @@ static int vfio_pci_hot_reset(VFIOPCIDevice *vdev, bool single)
|
|
|
5d360b |
info->argsz = sizeof(*info) + (count * sizeof(*devices));
|
|
|
5d360b |
devices = &info->devices[0];
|
|
|
5d360b |
|
|
|
5d360b |
- ret = ioctl(vdev->fd, VFIO_DEVICE_GET_PCI_HOT_RESET_INFO, info);
|
|
|
5d360b |
+ ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_GET_PCI_HOT_RESET_INFO, info);
|
|
|
5d360b |
if (ret) {
|
|
|
5d360b |
ret = -errno;
|
|
|
5d360b |
error_report("vfio: hot reset info failed: %m");
|
|
|
5d360b |
@@ -3165,7 +3174,7 @@ static int vfio_pci_hot_reset(VFIOPCIDevice *vdev, bool single)
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
/* Bus reset! */
|
|
|
5d360b |
- ret = ioctl(vdev->fd, VFIO_DEVICE_PCI_HOT_RESET, reset);
|
|
|
5d360b |
+ ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_PCI_HOT_RESET, reset);
|
|
|
5d360b |
g_free(reset);
|
|
|
5d360b |
|
|
|
5d360b |
DPRINTF("%04x:%02x:%02x.%x hot reset: %s\n", vdev->host.domain,
|
|
|
5d360b |
@@ -3516,12 +3525,12 @@ static int vfio_get_device(VFIOGroup *group, const char *name,
|
|
|
5d360b |
return ret;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
- vdev->fd = ret;
|
|
|
5d360b |
+ vdev->vbasedev.fd = ret;
|
|
|
5d360b |
vdev->group = group;
|
|
|
5d360b |
QLIST_INSERT_HEAD(&group->device_list, vdev, next);
|
|
|
5d360b |
|
|
|
5d360b |
/* Sanity check device */
|
|
|
5d360b |
- ret = ioctl(vdev->fd, VFIO_DEVICE_GET_INFO, &dev_info);
|
|
|
5d360b |
+ ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_GET_INFO, &dev_info);
|
|
|
5d360b |
if (ret) {
|
|
|
5d360b |
error_report("vfio: error getting device info: %m");
|
|
|
5d360b |
goto error;
|
|
|
5d360b |
@@ -3551,7 +3560,7 @@ static int vfio_get_device(VFIOGroup *group, const char *name,
|
|
|
5d360b |
for (i = VFIO_PCI_BAR0_REGION_INDEX; i < VFIO_PCI_ROM_REGION_INDEX; i++) {
|
|
|
5d360b |
reg_info.index = i;
|
|
|
5d360b |
|
|
|
5d360b |
- ret = ioctl(vdev->fd, VFIO_DEVICE_GET_REGION_INFO, ®_info);
|
|
|
5d360b |
+ ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_GET_REGION_INFO, ®_info);
|
|
|
5d360b |
if (ret) {
|
|
|
5d360b |
error_report("vfio: Error getting region %d info: %m", i);
|
|
|
5d360b |
goto error;
|
|
|
5d360b |
@@ -3565,14 +3574,14 @@ static int vfio_get_device(VFIOGroup *group, const char *name,
|
|
|
5d360b |
vdev->bars[i].flags = reg_info.flags;
|
|
|
5d360b |
vdev->bars[i].size = reg_info.size;
|
|
|
5d360b |
vdev->bars[i].fd_offset = reg_info.offset;
|
|
|
5d360b |
- vdev->bars[i].fd = vdev->fd;
|
|
|
5d360b |
+ vdev->bars[i].fd = vdev->vbasedev.fd;
|
|
|
5d360b |
vdev->bars[i].nr = i;
|
|
|
5d360b |
QLIST_INIT(&vdev->bars[i].quirks);
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
reg_info.index = VFIO_PCI_CONFIG_REGION_INDEX;
|
|
|
5d360b |
|
|
|
5d360b |
- ret = ioctl(vdev->fd, VFIO_DEVICE_GET_REGION_INFO, ®_info);
|
|
|
5d360b |
+ ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_GET_REGION_INFO, ®_info);
|
|
|
5d360b |
if (ret) {
|
|
|
5d360b |
error_report("vfio: Error getting config info: %m");
|
|
|
5d360b |
goto error;
|
|
|
5d360b |
@@ -3596,7 +3605,7 @@ static int vfio_get_device(VFIOGroup *group, const char *name,
|
|
|
5d360b |
.index = VFIO_PCI_VGA_REGION_INDEX,
|
|
|
5d360b |
};
|
|
|
5d360b |
|
|
|
5d360b |
- ret = ioctl(vdev->fd, VFIO_DEVICE_GET_REGION_INFO, &vga_info);
|
|
|
5d360b |
+ ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_GET_REGION_INFO, &vga_info);
|
|
|
5d360b |
if (ret) {
|
|
|
5d360b |
error_report(
|
|
|
5d360b |
"vfio: Device does not support requested feature x-vga");
|
|
|
5d360b |
@@ -3613,7 +3622,7 @@ static int vfio_get_device(VFIOGroup *group, const char *name,
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
vdev->vga.fd_offset = vga_info.offset;
|
|
|
5d360b |
- vdev->vga.fd = vdev->fd;
|
|
|
5d360b |
+ vdev->vga.fd = vdev->vbasedev.fd;
|
|
|
5d360b |
|
|
|
5d360b |
vdev->vga.region[QEMU_PCI_VGA_MEM].offset = QEMU_PCI_VGA_MEM_BASE;
|
|
|
5d360b |
vdev->vga.region[QEMU_PCI_VGA_MEM].nr = QEMU_PCI_VGA_MEM;
|
|
|
5d360b |
@@ -3632,7 +3641,7 @@ static int vfio_get_device(VFIOGroup *group, const char *name,
|
|
|
5d360b |
|
|
|
5d360b |
irq_info.index = VFIO_PCI_ERR_IRQ_INDEX;
|
|
|
5d360b |
|
|
|
5d360b |
- ret = ioctl(vdev->fd, VFIO_DEVICE_GET_IRQ_INFO, &irq_info);
|
|
|
5d360b |
+ ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_GET_IRQ_INFO, &irq_info);
|
|
|
5d360b |
if (ret) {
|
|
|
5d360b |
/* This can fail for an old kernel or legacy PCI dev */
|
|
|
5d360b |
DPRINTF("VFIO_DEVICE_GET_IRQ_INFO failure: %m\n");
|
|
|
5d360b |
@@ -3650,7 +3659,7 @@ error:
|
|
|
5d360b |
if (ret) {
|
|
|
5d360b |
QLIST_REMOVE(vdev, next);
|
|
|
5d360b |
vdev->group = NULL;
|
|
|
5d360b |
- close(vdev->fd);
|
|
|
5d360b |
+ close(vdev->vbasedev.fd);
|
|
|
5d360b |
}
|
|
|
5d360b |
return ret;
|
|
|
5d360b |
}
|
|
|
5d360b |
@@ -3659,8 +3668,8 @@ static void vfio_put_device(VFIOPCIDevice *vdev)
|
|
|
5d360b |
{
|
|
|
5d360b |
QLIST_REMOVE(vdev, next);
|
|
|
5d360b |
vdev->group = NULL;
|
|
|
5d360b |
- DPRINTF("vfio_put_device: close vdev->fd\n");
|
|
|
5d360b |
- close(vdev->fd);
|
|
|
5d360b |
+ DPRINTF("vfio_put_device: close vdev->vbasedev.fd\n");
|
|
|
5d360b |
+ close(vdev->vbasedev.fd);
|
|
|
5d360b |
if (vdev->msix) {
|
|
|
5d360b |
g_free(vdev->msix);
|
|
|
5d360b |
vdev->msix = NULL;
|
|
|
5d360b |
@@ -3729,7 +3738,7 @@ static void vfio_register_err_notifier(VFIOPCIDevice *vdev)
|
|
|
5d360b |
*pfd = event_notifier_get_fd(&vdev->err_notifier);
|
|
|
5d360b |
qemu_set_fd_handler(*pfd, vfio_err_notifier_handler, NULL, vdev);
|
|
|
5d360b |
|
|
|
5d360b |
- ret = ioctl(vdev->fd, VFIO_DEVICE_SET_IRQS, irq_set);
|
|
|
5d360b |
+ ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_SET_IRQS, irq_set);
|
|
|
5d360b |
if (ret) {
|
|
|
5d360b |
error_report("vfio: Failed to set up error notification");
|
|
|
5d360b |
qemu_set_fd_handler(*pfd, NULL, NULL, vdev);
|
|
|
5d360b |
@@ -3762,7 +3771,7 @@ static void vfio_unregister_err_notifier(VFIOPCIDevice *vdev)
|
|
|
5d360b |
pfd = (int32_t *)&irq_set->data;
|
|
|
5d360b |
*pfd = -1;
|
|
|
5d360b |
|
|
|
5d360b |
- ret = ioctl(vdev->fd, VFIO_DEVICE_SET_IRQS, irq_set);
|
|
|
5d360b |
+ ret = ioctl(vdev->vbasedev.fd, VFIO_DEVICE_SET_IRQS, irq_set);
|
|
|
5d360b |
if (ret) {
|
|
|
5d360b |
error_report("vfio: Failed to de-assign error fd: %m");
|
|
|
5d360b |
}
|
|
|
5d360b |
@@ -3795,7 +3804,7 @@ static void vfio_register_req_notifier(VFIOPCIDevice *vdev)
|
|
|
5d360b |
return;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
- if (ioctl(vdev->fd,
|
|
|
5d360b |
+ if (ioctl(vdev->vbasedev.fd,
|
|
|
5d360b |
VFIO_DEVICE_GET_IRQ_INFO, &irq_info) < 0 || irq_info.count < 1) {
|
|
|
5d360b |
return;
|
|
|
5d360b |
}
|
|
|
5d360b |
@@ -3819,7 +3828,7 @@ static void vfio_register_req_notifier(VFIOPCIDevice *vdev)
|
|
|
5d360b |
*pfd = event_notifier_get_fd(&vdev->req_notifier);
|
|
|
5d360b |
qemu_set_fd_handler(*pfd, vfio_req_notifier_handler, NULL, vdev);
|
|
|
5d360b |
|
|
|
5d360b |
- if (ioctl(vdev->fd, VFIO_DEVICE_SET_IRQS, irq_set)) {
|
|
|
5d360b |
+ if (ioctl(vdev->vbasedev.fd, VFIO_DEVICE_SET_IRQS, irq_set)) {
|
|
|
5d360b |
error_report("vfio: Failed to set up device request notification");
|
|
|
5d360b |
qemu_set_fd_handler(*pfd, NULL, NULL, vdev);
|
|
|
5d360b |
event_notifier_cleanup(&vdev->req_notifier);
|
|
|
5d360b |
@@ -3852,7 +3861,7 @@ static void vfio_unregister_req_notifier(VFIOPCIDevice *vdev)
|
|
|
5d360b |
pfd = (int32_t *)&irq_set->data;
|
|
|
5d360b |
*pfd = -1;
|
|
|
5d360b |
|
|
|
5d360b |
- if (ioctl(vdev->fd, VFIO_DEVICE_SET_IRQS, irq_set)) {
|
|
|
5d360b |
+ if (ioctl(vdev->vbasedev.fd, VFIO_DEVICE_SET_IRQS, irq_set)) {
|
|
|
5d360b |
error_report("vfio: Failed to de-assign device request fd: %m");
|
|
|
5d360b |
}
|
|
|
5d360b |
g_free(irq_set);
|
|
|
5d360b |
@@ -3944,7 +3953,7 @@ static int vfio_initfn(PCIDevice *pdev)
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
/* Get a copy of config space */
|
|
|
5d360b |
- ret = pread(vdev->fd, vdev->pdev.config,
|
|
|
5d360b |
+ ret = pread(vdev->vbasedev.fd, vdev->pdev.config,
|
|
|
5d360b |
MIN(pci_config_size(&vdev->pdev), vdev->config_size),
|
|
|
5d360b |
vdev->config_offset);
|
|
|
5d360b |
if (ret < (int)MIN(pci_config_size(&vdev->pdev), vdev->config_size)) {
|
|
|
5d360b |
@@ -4061,7 +4070,7 @@ static void vfio_pci_reset(DeviceState *dev)
|
|
|
5d360b |
vfio_pci_pre_reset(vdev);
|
|
|
5d360b |
|
|
|
5d360b |
if (vdev->reset_works && (vdev->has_flr || !vdev->has_pm_reset) &&
|
|
|
5d360b |
- !ioctl(vdev->fd, VFIO_DEVICE_RESET)) {
|
|
|
5d360b |
+ !ioctl(vdev->vbasedev.fd, VFIO_DEVICE_RESET)) {
|
|
|
5d360b |
DPRINTF("%04x:%02x:%02x.%x FLR/VFIO_DEVICE_RESET\n", vdev->host.domain,
|
|
|
5d360b |
vdev->host.bus, vdev->host.slot, vdev->host.function);
|
|
|
5d360b |
goto post_reset;
|
|
|
5d360b |
@@ -4074,7 +4083,7 @@ static void vfio_pci_reset(DeviceState *dev)
|
|
|
5d360b |
|
|
|
5d360b |
/* If nothing else works and the device supports PM reset, use it */
|
|
|
5d360b |
if (vdev->reset_works && vdev->has_pm_reset &&
|
|
|
5d360b |
- !ioctl(vdev->fd, VFIO_DEVICE_RESET)) {
|
|
|
5d360b |
+ !ioctl(vdev->vbasedev.fd, VFIO_DEVICE_RESET)) {
|
|
|
5d360b |
DPRINTF("%04x:%02x:%02x.%x PCI PM Reset\n", vdev->host.domain,
|
|
|
5d360b |
vdev->host.bus, vdev->host.slot, vdev->host.function);
|
|
|
5d360b |
goto post_reset;
|
|
|
5d360b |
--
|
|
|
5d360b |
1.8.3.1
|
|
|
5d360b |
|