Skip to contentSkip to conversation

qemu-kvm: add irqfd support

PATCH Superseded Gregory Haskins 1 participant 1 message Apr 27, 2009 KVM

v3 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 qemu-kvm: add irqfd support

(Applies to qemu-kvm.git 8f7a30dbc40a1d4c09275566f9ed9647ed1ee50f)

irqfd lets you create an eventfd based file-desriptor to inject interrupts to a kvm guest. We associate one gsi per fd for fine-grained routing.

---

 kvm/libkvm/libkvm.c |   18 ++++++++++++++++++
 kvm/libkvm/libkvm.h |   14 ++++++++++++++
 2 files changed, 32 insertions(+), 0 deletions(-)
kvm/libkvm/libkvm.c +18 -0
index 0610e3f..dc9a951 100644
@@ -1440,3 +1440,21 @@ int kvm_assign_set_msix_entry(kvm_context_t kvm,
         return ret;
 }
 #endif
+
+int kvm_irqfd(kvm_context_t kvm, int gsi, int flags)
+{
+	int r;
+	struct kvm_irqfd data = {
+		.gsi   = gsi,
+		.flags = flags,
+	};
+
+	if (!kvm_check_extension(kvm, KVM_CAP_IRQFD))
+		return -ENOENT;
+
+	r = ioctl(kvm->vm_fd, KVM_IRQFD, &data);
+	if (r == -1)
+		r = -errno;
+	return r;
+}	
+
kvm/libkvm/libkvm.h +14 -0
index ce6f054..89a8893 100644
@@ -856,6 +856,20 @@ int kvm_commit_irq_routes(kvm_context_t kvm);
  */
 int kvm_get_irq_route_gsi(kvm_context_t kvm);
 
+/*!
+ * \brief Create a file descriptor for injecting interrupts
+ *
+ * Creates an eventfd based file-descriptor that maps to a specific GSI
+ * in the guest.  eventfd compliant signaling (write() from userspace, or
+ * eventfd_signal() from kernelspace) will cause the GSI to inject
+ * itself into the guest at the next available window.
+ *
+ * \param kvm Pointer to the current kvm_context
+ * \param gsi GSI to assign to this fd
+ * \param flags reserved, must be zero
+ */
+int kvm_irqfd(kvm_context_t kvm, int gsi, int flags);
+
 #ifdef KVM_CAP_DEVICE_MSIX
 int kvm_assign_set_msix_nr(kvm_context_t kvm,
 			   struct kvm_assigned_msix_nr *msix_nr);