|
|
5d360b |
From dde4b959d6722bc2ebc5cd247b4e21055d2f0abd Mon Sep 17 00:00:00 2001
|
|
|
5d360b |
From: Alex Williamson <alex.williamson@redhat.com>
|
|
|
5d360b |
Date: Fri, 29 Sep 2017 21:44:35 +0200
|
|
|
5d360b |
Subject: [PATCH 05/27] hw/vfio/pci: add type, name and group fields in
|
|
|
5d360b |
VFIODevice
|
|
|
5d360b |
|
|
|
5d360b |
RH-Author: Alex Williamson <alex.williamson@redhat.com>
|
|
|
5d360b |
Message-id: <20170929214435.16765.27045.stgit@gimli.home>
|
|
|
5d360b |
Patchwork-id: 76763
|
|
|
5d360b |
O-Subject: [RHEL-7.5 qemu-kvm PATCH 05/16] hw/vfio/pci: add type, name and group fields in VFIODevice
|
|
|
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: 462037c9e85b27149e71d7f5c7f41375ca6e47d5
|
|
|
5d360b |
|
|
|
5d360b |
Add 3 new fields in the VFIODevice struct. Type is set to
|
|
|
5d360b |
VFIO_DEVICE_TYPE_PCI. The type enum value will later be used
|
|
|
5d360b |
to discriminate between VFIO PCI and platform devices. The name is
|
|
|
5d360b |
set to domain:bus:slot:function. Currently used to test whether
|
|
|
5d360b |
the device already is attached to the group. Later on, the name
|
|
|
5d360b |
will be used to simplify all traces. The group is simply moved
|
|
|
5d360b |
from VFIOPCIDevice to VFIODevice.
|
|
|
5d360b |
|
|
|
5d360b |
Signed-off-by: Eric Auger <eric.auger@linaro.org>
|
|
|
5d360b |
[Fix g_strdup_printf() usage]
|
|
|
5d360b |
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
|
|
|
5d360b |
|
|
|
5d360b |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
5d360b |
---
|
|
|
5d360b |
hw/misc/vfio.c | 27 ++++++++++++++++++---------
|
|
|
5d360b |
1 file changed, 18 insertions(+), 9 deletions(-)
|
|
|
5d360b |
|
|
|
5d360b |
diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c
|
|
|
5d360b |
index 340d967..cc151e2 100644
|
|
|
5d360b |
--- a/hw/misc/vfio.c
|
|
|
5d360b |
+++ b/hw/misc/vfio.c
|
|
|
5d360b |
@@ -55,6 +55,10 @@
|
|
|
5d360b |
#define VFIO_ALLOW_KVM_MSI 1
|
|
|
5d360b |
#define VFIO_ALLOW_KVM_MSIX 1
|
|
|
5d360b |
|
|
|
5d360b |
+enum {
|
|
|
5d360b |
+ VFIO_DEVICE_TYPE_PCI = 0,
|
|
|
5d360b |
+};
|
|
|
5d360b |
+
|
|
|
5d360b |
struct VFIOPCIDevice;
|
|
|
5d360b |
|
|
|
5d360b |
typedef struct VFIOQuirk {
|
|
|
5d360b |
@@ -175,7 +179,10 @@ typedef struct VFIOMSIXInfo {
|
|
|
5d360b |
} VFIOMSIXInfo;
|
|
|
5d360b |
|
|
|
5d360b |
typedef struct VFIODevice {
|
|
|
5d360b |
+ struct VFIOGroup *group;
|
|
|
5d360b |
+ char *name;
|
|
|
5d360b |
int fd;
|
|
|
5d360b |
+ int type;
|
|
|
5d360b |
} VFIODevice;
|
|
|
5d360b |
|
|
|
5d360b |
typedef struct VFIOPCIDevice {
|
|
|
5d360b |
@@ -197,7 +204,6 @@ typedef struct VFIOPCIDevice {
|
|
|
5d360b |
VFIOVGA vga; /* 0xa0000, 0x3b0, 0x3c0 */
|
|
|
5d360b |
PCIHostDeviceAddress host;
|
|
|
5d360b |
QLIST_ENTRY(VFIOPCIDevice) next;
|
|
|
5d360b |
- struct VFIOGroup *group;
|
|
|
5d360b |
EventNotifier err_notifier;
|
|
|
5d360b |
EventNotifier req_notifier;
|
|
|
5d360b |
uint32_t features;
|
|
|
5d360b |
@@ -3526,7 +3532,7 @@ static int vfio_get_device(VFIOGroup *group, const char *name,
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
vdev->vbasedev.fd = ret;
|
|
|
5d360b |
- vdev->group = group;
|
|
|
5d360b |
+ vdev->vbasedev.group = group;
|
|
|
5d360b |
QLIST_INSERT_HEAD(&group->device_list, vdev, next);
|
|
|
5d360b |
|
|
|
5d360b |
/* Sanity check device */
|
|
|
5d360b |
@@ -3658,7 +3664,7 @@ static int vfio_get_device(VFIOGroup *group, const char *name,
|
|
|
5d360b |
error:
|
|
|
5d360b |
if (ret) {
|
|
|
5d360b |
QLIST_REMOVE(vdev, next);
|
|
|
5d360b |
- vdev->group = NULL;
|
|
|
5d360b |
+ vdev->vbasedev.group = NULL;
|
|
|
5d360b |
close(vdev->vbasedev.fd);
|
|
|
5d360b |
}
|
|
|
5d360b |
return ret;
|
|
|
5d360b |
@@ -3667,9 +3673,10 @@ error:
|
|
|
5d360b |
static void vfio_put_device(VFIOPCIDevice *vdev)
|
|
|
5d360b |
{
|
|
|
5d360b |
QLIST_REMOVE(vdev, next);
|
|
|
5d360b |
- vdev->group = NULL;
|
|
|
5d360b |
+ vdev->vbasedev.group = NULL;
|
|
|
5d360b |
DPRINTF("vfio_put_device: close vdev->vbasedev.fd\n");
|
|
|
5d360b |
close(vdev->vbasedev.fd);
|
|
|
5d360b |
+ g_free(vdev->vbasedev.name);
|
|
|
5d360b |
if (vdev->msix) {
|
|
|
5d360b |
g_free(vdev->msix);
|
|
|
5d360b |
vdev->msix = NULL;
|
|
|
5d360b |
@@ -3904,6 +3911,11 @@ static int vfio_initfn(PCIDevice *pdev)
|
|
|
5d360b |
return -errno;
|
|
|
5d360b |
}
|
|
|
5d360b |
|
|
|
5d360b |
+ vdev->vbasedev.type = VFIO_DEVICE_TYPE_PCI;
|
|
|
5d360b |
+ vdev->vbasedev.name = g_strdup_printf("%04x:%02x:%02x.%01x",
|
|
|
5d360b |
+ vdev->host.domain, vdev->host.bus,
|
|
|
5d360b |
+ vdev->host.slot, vdev->host.function);
|
|
|
5d360b |
+
|
|
|
5d360b |
strncat(path, "iommu_group", sizeof(path) - strlen(path) - 1);
|
|
|
5d360b |
|
|
|
5d360b |
len = readlink(path, iommu_group_path, sizeof(path));
|
|
|
5d360b |
@@ -3934,10 +3946,7 @@ static int vfio_initfn(PCIDevice *pdev)
|
|
|
5d360b |
vdev->host.function);
|
|
|
5d360b |
|
|
|
5d360b |
QLIST_FOREACH(pvdev, &group->device_list, next) {
|
|
|
5d360b |
- if (pvdev->host.domain == vdev->host.domain &&
|
|
|
5d360b |
- pvdev->host.bus == vdev->host.bus &&
|
|
|
5d360b |
- pvdev->host.slot == vdev->host.slot &&
|
|
|
5d360b |
- pvdev->host.function == vdev->host.function) {
|
|
|
5d360b |
+ if (strcmp(pvdev->vbasedev.name, vdev->vbasedev.name) == 0) {
|
|
|
5d360b |
|
|
|
5d360b |
error_report("vfio: error: device %s is already attached", path);
|
|
|
5d360b |
vfio_put_group(group);
|
|
|
5d360b |
@@ -4042,7 +4051,7 @@ out_put:
|
|
|
5d360b |
static void vfio_exitfn(PCIDevice *pdev)
|
|
|
5d360b |
{
|
|
|
5d360b |
VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev);
|
|
|
5d360b |
- VFIOGroup *group = vdev->group;
|
|
|
5d360b |
+ VFIOGroup *group = vdev->vbasedev.group;
|
|
|
5d360b |
|
|
|
5d360b |
vfio_unregister_req_notifier(vdev);
|
|
|
5d360b |
vfio_unregister_err_notifier(vdev);
|
|
|
5d360b |
--
|
|
|
5d360b |
1.8.3.1
|
|
|
5d360b |
|