[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH V2 11/22] vfio-pci: refactor for cpr
From: |
Steve Sistare |
Subject: |
[PATCH V2 11/22] vfio-pci: refactor for cpr |
Date: |
Tue, 5 Jan 2021 07:41:59 -0800 |
Export vfio_address_spaces and vfio_listener_skipped_section.
Add optional eventfd arg to vfio_add_kvm_msi_virq.
Refactor vector use into a helper vfio_vector_init.
All for use by cpr in a subsequent patch. No functional change.
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
hw/vfio/common.c | 4 ++--
hw/vfio/pci.c | 36 +++++++++++++++++++++++++-----------
include/hw/vfio/vfio-common.h | 3 +++
3 files changed, 30 insertions(+), 13 deletions(-)
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 3335714..7f8768d 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -40,7 +40,7 @@
VFIOGroupList vfio_group_list =
QLIST_HEAD_INITIALIZER(vfio_group_list);
-static QLIST_HEAD(, VFIOAddressSpace) vfio_address_spaces =
+VFIOAddressSpaceList vfio_address_spaces =
QLIST_HEAD_INITIALIZER(vfio_address_spaces);
#ifdef CONFIG_KVM
@@ -393,7 +393,7 @@ static int vfio_host_win_del(VFIOContainer *container,
hwaddr min_iova,
return -1;
}
-static bool vfio_listener_skipped_section(MemoryRegionSection *section)
+bool vfio_listener_skipped_section(MemoryRegionSection *section)
{
return (!memory_region_is_ram(section->mr) &&
!memory_region_is_iommu(section->mr)) ||
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index 2e561c0..9b57ffa 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -412,7 +412,7 @@ static int vfio_enable_vectors(VFIOPCIDevice *vdev, bool
msix)
}
static void vfio_add_kvm_msi_virq(VFIOPCIDevice *vdev, VFIOMSIVector *vector,
- int vector_n, bool msix)
+ int vector_n, bool msix, int eventfd)
{
int virq;
@@ -420,7 +420,9 @@ static void vfio_add_kvm_msi_virq(VFIOPCIDevice *vdev,
VFIOMSIVector *vector,
return;
}
- if (event_notifier_init(&vector->kvm_interrupt, 0)) {
+ if (eventfd >= 0) {
+ event_notifier_init_fd(&vector->kvm_interrupt, eventfd);
+ } else if (event_notifier_init(&vector->kvm_interrupt, 0)) {
return;
}
@@ -456,6 +458,22 @@ static void vfio_update_kvm_msi_virq(VFIOMSIVector
*vector, MSIMessage msg,
kvm_irqchip_commit_routes(kvm_state);
}
+static void vfio_vector_init(VFIOPCIDevice *vdev, int nr, int eventfd)
+{
+ VFIOMSIVector *vector = &vdev->msi_vectors[nr];
+ PCIDevice *pdev = &vdev->pdev;
+
+ vector->vdev = vdev;
+ vector->virq = -1;
+ if (eventfd >= 0) {
+ event_notifier_init_fd(&vector->interrupt, eventfd);
+ } else if (event_notifier_init(&vector->interrupt, 0)) {
+ error_report("vfio: Error: event_notifier_init failed");
+ }
+ vector->use = true;
+ msix_vector_use(pdev, nr);
+}
+
static int vfio_msix_vector_do_use(PCIDevice *pdev, unsigned int nr,
MSIMessage *msg, IOHandler *handler)
{
@@ -467,14 +485,10 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev,
unsigned int nr,
vector = &vdev->msi_vectors[nr];
+ vfio_vector_init(vdev, nr, -1);
+
if (!vector->use) {
- vector->vdev = vdev;
- vector->virq = -1;
- if (event_notifier_init(&vector->interrupt, 0)) {
- error_report("vfio: Error: event_notifier_init failed");
- }
- vector->use = true;
- msix_vector_use(pdev, nr);
+ vfio_vector_init(vdev, nr, -1);
}
qemu_set_fd_handler(event_notifier_get_fd(&vector->interrupt),
@@ -492,7 +506,7 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev,
unsigned int nr,
}
} else {
if (msg) {
- vfio_add_kvm_msi_virq(vdev, vector, nr, true);
+ vfio_add_kvm_msi_virq(vdev, vector, nr, true, -1);
}
}
@@ -628,7 +642,7 @@ retry:
* Attempt to enable route through KVM irqchip,
* default to userspace handling if unavailable.
*/
- vfio_add_kvm_msi_virq(vdev, vector, i, false);
+ vfio_add_kvm_msi_virq(vdev, vector, i, false, -1);
}
/* Set interrupt type prior to possible interrupts */
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index c78f3ff..ab87df4 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -182,6 +182,8 @@ int vfio_get_device(VFIOGroup *group, const char *name,
extern const MemoryRegionOps vfio_region_ops;
typedef QLIST_HEAD(VFIOGroupList, VFIOGroup) VFIOGroupList;
extern VFIOGroupList vfio_group_list;
+typedef QLIST_HEAD(, VFIOAddressSpace) VFIOAddressSpaceList;
+extern VFIOAddressSpaceList vfio_address_spaces;
#ifdef CONFIG_LINUX
int vfio_get_region_info(VFIODevice *vbasedev, int index,
@@ -193,6 +195,7 @@ struct vfio_info_cap_header *
vfio_get_region_info_cap(struct vfio_region_info *info, uint16_t id);
#endif
extern const MemoryListener vfio_prereg_listener;
+bool vfio_listener_skipped_section(MemoryRegionSection *section);
int vfio_spapr_create_window(VFIOContainer *container,
MemoryRegionSection *section,
--
1.8.3.1
- Re: [PATCH V2 18/22] chardev: cpr for sockets, (continued)
- [PATCH V2 19/22] monitor: cpr support, Steve Sistare, 2021/01/05
- [PATCH V2 17/22] chardev: socket accept subroutine, Steve Sistare, 2021/01/05
- [PATCH V2 20/22] cpr: only-cpr-capable option, Steve Sistare, 2021/01/05
- [PATCH V2 22/22] simplify savevm, Steve Sistare, 2021/01/05
- [PATCH V2 14/22] chardev: cpr framework, Steve Sistare, 2021/01/05
- [PATCH V2 21/22] cpr: maintainers, Steve Sistare, 2021/01/05
- [PATCH V2 02/22] qemu_ram_volatile, Steve Sistare, 2021/01/05
- [PATCH V2 13/22] vhost: reset vhost devices upon cprsave, Steve Sistare, 2021/01/05
- [PATCH V2 01/22] as_flat_walk, Steve Sistare, 2021/01/05
- [PATCH V2 11/22] vfio-pci: refactor for cpr,
Steve Sistare <=
- [PATCH V2 15/22] chardev: cpr for simple devices, Steve Sistare, 2021/01/05