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@xxxxxxxxxxx> --- hw/virtio-pci.c | 6 +++--- kvm.h | 2 ++ qemu-kvm.c | 14 +++++++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c index 23880e0..ad6a002 100644 --- a/hw/virtio-pci.c +++ b/hw/virtio-pci.c @@ -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; } diff --git a/kvm.h b/kvm.h index 3706fc6..fe2eec5 100644 --- a/kvm.h +++ b/kvm.h @@ -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); diff --git a/qemu-kvm.c b/qemu-kvm.c index 13d4f90..ab7703b 100644 --- a/qemu-kvm.c +++ b/qemu-kvm.c @@ -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) { -- 1.7.3.4 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html