diff mbox

[v7,1/2] qemu-kvm: add irqfd support

Message ID 20090512183226.26356.46296.stgit@dev.haskins.net (mailing list archive)
State New, archived
Headers show

Commit Message

Gregory Haskins May 12, 2009, 6:32 p.m. UTC
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.

Signed-off-by: Gregory Haskins <ghaskins@novell.com>
---

 kvm/libkvm/libkvm.c |   66 +++++++++++++++++++++++++++++++++++++++++++++++++++
 kvm/libkvm/libkvm.h |   25 +++++++++++++++++++
 2 files changed, 91 insertions(+), 0 deletions(-)


--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Avi Kivity May 31, 2009, 12:29 p.m. UTC | #1
Gregory Haskins wrote:
> 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.
>
>   

Sorry, getting to userspace a little late in the game.

> @@ -34,6 +34,7 @@
>  #include <string.h>
>  #include <errno.h>
>  #include <sys/ioctl.h>
> +#include <sys/eventfd.h>
>   

This only made it in 2.6.22.  So it needs a ./configure -time check for 
existence.

> +int kvm_create_irqfd(kvm_context_t kvm, int gsi, int flags)
> +{
> +	return -ENOENT;
> +}
> +
> +int kvm_destroy_irqfd(kvm_context_t kvm, int fd, int flags)
> +{
> +	return -ENOENT;
> +}
>   

-ENOSYS is more traditional.
Gregory Haskins June 2, 2009, 2:54 p.m. UTC | #2
Avi Kivity wrote:
> Gregory Haskins wrote:
>> 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.
>>
>>   
>
> Sorry, getting to userspace a little late in the game.
Np.. I need to re-work this for the POLLHUP patch I am about to push anyway.

>
>> @@ -34,6 +34,7 @@
>>  #include <string.h>
>>  #include <errno.h>
>>  #include <sys/ioctl.h>
>> +#include <sys/eventfd.h>
>>   
>
> This only made it in 2.6.22.  So it needs a ./configure -time check
> for existence.

I could also just put this within the #ifdef KVM_CAP_IRQFD?


>
>> +int kvm_create_irqfd(kvm_context_t kvm, int gsi, int flags)
>> +{
>> +    return -ENOENT;
>> +}
>> +
>> +int kvm_destroy_irqfd(kvm_context_t kvm, int fd, int flags)
>> +{
>> +    return -ENOENT;
>> +}
>>   
>
> -ENOSYS is more traditional.
>
Ack.

-Greg
diff mbox

Patch

diff --git a/kvm/libkvm/libkvm.c b/kvm/libkvm/libkvm.c
index ba0a5d1..74a21a2 100644
--- a/kvm/libkvm/libkvm.c
+++ b/kvm/libkvm/libkvm.c
@@ -34,6 +34,7 @@ 
 #include <string.h>
 #include <errno.h>
 #include <sys/ioctl.h>
+#include <sys/eventfd.h>
 #include <inttypes.h>
 #include "libkvm.h"
 
@@ -1444,3 +1445,68 @@  int kvm_assign_set_msix_entry(kvm_context_t kvm,
         return ret;
 }
 #endif
+
+#ifdef KVM_CAP_EVENTFD
+static int _assign_irqfd(kvm_context_t kvm, int fd, int gsi, int flags)
+{
+	int r;
+	struct kvm_irqfd data = {
+		.fd    = fd,
+		.gsi   = gsi,
+		.flags = flags,
+	};
+
+	r = ioctl(kvm->vm_fd, KVM_ASSIGN_IRQFD, &data);
+	if (r == -1)
+		r = -errno;
+	return r;
+}
+
+int kvm_create_irqfd(kvm_context_t kvm, int gsi, int flags)
+{
+	int r;
+	int fd;
+
+	if (!kvm_check_extension(kvm, KVM_CAP_EVENTFD))
+		return -ENOENT;
+
+	fd = eventfd(0, 0);
+	if (fd < 0)
+		return -errno;
+
+	r = _assign_irqfd(kvm, fd, gsi, flags);
+	if (r < 0) {
+		close(fd);
+		return -errno;
+	}
+
+	return fd;
+}
+
+int kvm_destroy_irqfd(kvm_context_t kvm, int fd, int flags)
+{
+	int r;
+	__u32 data = fd;
+
+	r = ioctl(kvm->vm_fd, KVM_DEASSIGN_IRQFD, &data);
+	if (r == -1)
+		r = -errno;
+
+	close(fd);
+
+	return r;
+}
+
+#else /* KVM_CAP_EVENTFD */
+
+int kvm_create_irqfd(kvm_context_t kvm, int gsi, int flags)
+{
+	return -ENOENT;
+}
+
+int kvm_destroy_irqfd(kvm_context_t kvm, int fd, int flags)
+{
+	return -ENOENT;
+}
+
+#endif /* KVM_CAP_EVENTFD */
diff --git a/kvm/libkvm/libkvm.h b/kvm/libkvm/libkvm.h
index 4821a1e..322b4cd 100644
--- a/kvm/libkvm/libkvm.h
+++ b/kvm/libkvm/libkvm.h
@@ -856,6 +856,31 @@  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_create_irqfd(kvm_context_t kvm, int gsi, int flags);
+
+/*!
+ * \brief Destroy an irqfd file descriptor
+ *
+ * Destroys a file descriptor previously opened with kvm_create_irqfd()
+ *
+ * \param kvm Pointer to the current kvm_context
+ * \param fd fd to close
+ * \param flags reserved, must be zero
+ */
+int kvm_destroy_irqfd(kvm_context_t kvm, int fd, int flags);
+
 #ifdef KVM_CAP_DEVICE_MSIX
 int kvm_assign_set_msix_nr(kvm_context_t kvm,
 			   struct kvm_assigned_msix_nr *msix_nr);