diff mbox

[RFC,19/45] qemu-kvm: Factor out kvm_msi_irqfd_set

Message ID 869b269736f714cb82498954df06f6759d97c60f.1318843693.git.jan.kiszka@siemens.com
State New
Headers show

Commit Message

Jan Kiszka Oct. 17, 2011, 9:27 a.m. UTC
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(-)
diff mbox

Patch

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)
 {