@@ -524,9 +524,9 @@ static int virtio_pci_mask_vq(PCIDevice *dev, unsigned vector,
VirtQueue *vq, int masked)
{
EventNotifier *notifier = virtio_queue_get_guest_notifier(vq);
- int r = kvm_set_irqfd(dev->msix_cache[vector].kvm_gsi,
- event_notifier_get_fd(notifier),
- !masked);
+ int r = kvm_msi_irqfd_set(&dev->msix_cache[vector],
+ event_notifier_get_fd(notifier),
+ !masked);
if (r < 0) {
return (r == -ENOSYS) ? 0 : r;
}
@@ -208,6 +208,8 @@ int kvm_msi_message_add(MSIMessage *msg, MSIRoutingCache *cache);
int kvm_msi_message_del(MSIRoutingCache *cache);
int kvm_msi_message_update(MSIMessage *msg, MSIRoutingCache *cache);
+int kvm_msi_irqfd_set(MSIRoutingCache *cache, int fd, bool assigned);
+
int kvm_commit_irq_routes(void);
int kvm_irqchip_in_kernel(void);
@@ -352,8 +352,11 @@ int kvm_del_routing_entry(struct kvm_irq_routing_entry *entry)
*e = *p;
cache = s->msi_cache[i];
- if (cache) {
+ if (cache && cache->type != MSI_ROUTE_NONE) {
cache->type = MSI_ROUTE_NONE;
+ if (cache->kvm_irqfd >= 0) {
+ kvm_set_irqfd(cache->kvm_gsi, cache->kvm_irqfd, false);
+ }
}
s->msi_cache[i] = s->msi_cache[s->irq_routes->nr];
@@ -521,6 +524,15 @@ int kvm_msi_message_update(MSIMessage *msg, MSIRoutingCache *cache)
}
+int kvm_msi_irqfd_set(MSIRoutingCache *cache, int fd, bool assigned)
+{
+ if (cache->type == MSI_ROUTE_NONE) {
+ return assigned ? -EINVAL : 0;
+ }
+ cache->kvm_irqfd = assigned ? fd : -1;
+ return kvm_set_irqfd(cache->kvm_gsi, fd, assigned);
+}
+
#ifdef KVM_CAP_DEVICE_MSIX
int kvm_assign_set_msix_nr(KVMState *s, struct kvm_assigned_msix_nr *msix_nr)
{
This makes the KVM core layer aware of the irqfd associated with some MSI cache. kvm_msi_irqfd_set is defined for this purpose, which avoids that virtio needs to peek into the cache for extracting the GSI. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> --- hw/virtio-pci.c | 6 +++--- kvm.h | 2 ++ qemu-kvm.c | 14 +++++++++++++- 3 files changed, 18 insertions(+), 4 deletions(-)