* [PATCH v8] qemu-kvm: add irqfd support
@ 2009-06-02 15:45 Gregory Haskins
2009-06-02 15:48 ` Gregory Haskins
2009-06-04 10:06 ` Avi Kivity
0 siblings, 2 replies; 4+ messages in thread
From: Gregory Haskins @ 2009-06-02 15:45 UTC (permalink / raw)
To: kvm; +Cc: avi
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.
[note: this is meant to work in conjunction with the POLLHUP version of
irqfd, which has not yet been accepted into kvm.git]
[ Changelog:
v8:
*) removed deassign() verb in favor of POLLHUP support on close()
*) only include sys/eventfd.h if CAP_IRQFD is defined to properly
support older kernels
*) s/ENOENT/ENOSYS
]
Signed-off-by: Gregory Haskins <ghaskins@novell.com>
---
kvm/libkvm/libkvm.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
kvm/libkvm/libkvm.h | 14 ++++++++++++++
2 files changed, 63 insertions(+), 0 deletions(-)
diff --git a/kvm/libkvm/libkvm.c b/kvm/libkvm/libkvm.c
index ba0a5d1..10cb2ac 100644
--- a/kvm/libkvm/libkvm.c
+++ b/kvm/libkvm/libkvm.c
@@ -1444,3 +1444,52 @@ int kvm_assign_set_msix_entry(kvm_context_t kvm,
return ret;
}
#endif
+
+#ifdef KVM_CAP_IRQFD
+
+#include <sys/eventfd.h>
+
+static int _kvm_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_IRQFD, &data);
+ if (r == -1)
+ r = -errno;
+ return r;
+}
+
+int kvm_irqfd(kvm_context_t kvm, int gsi, int flags)
+{
+ int r;
+ int fd;
+
+ if (!kvm_check_extension(kvm, KVM_CAP_IRQFD))
+ return -ENOENT;
+
+ fd = eventfd(0, 0);
+ if (fd < 0)
+ return -errno;
+
+ r = _kvm_irqfd(kvm, fd, gsi, 0);
+ if (r < 0) {
+ close(fd);
+ return -errno;
+ }
+
+ return fd;
+}
+
+#else /* KVM_CAP_IRQFD */
+
+int kvm_irqfd(kvm_context_t kvm, int gsi, int flags)
+{
+ return -ENOSYS;
+}
+
+#endif /* KVM_CAP_IRQFD */
diff --git a/kvm/libkvm/libkvm.h b/kvm/libkvm/libkvm.h
index 4821a1e..aca8ed6 100644
--- a/kvm/libkvm/libkvm.h
+++ b/kvm/libkvm/libkvm.h
@@ -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);
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH v8] qemu-kvm: add irqfd support
2009-06-02 15:45 [PATCH v8] qemu-kvm: add irqfd support Gregory Haskins
@ 2009-06-02 15:48 ` Gregory Haskins
2009-06-04 10:06 ` Avi Kivity
1 sibling, 0 replies; 4+ messages in thread
From: Gregory Haskins @ 2009-06-02 15:48 UTC (permalink / raw)
Cc: kvm, avi
[-- Attachment #1: Type: text/plain, Size: 3333 bytes --]
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.
>
> [note: this is meant to work in conjunction with the POLLHUP version of
> irqfd, which has not yet been accepted into kvm.git]
>
> [ Changelog:
>
> v8:
> *) removed deassign() verb in favor of POLLHUP support on close()
> *) only include sys/eventfd.h if CAP_IRQFD is defined to properly
> support older kernels
> *) s/ENOENT/ENOSYS
> ]
>
Hmm..it would appear I already released a 'v8' in the past. :(
In any case, this is the latest version to consider
-Greg
> Signed-off-by: Gregory Haskins <ghaskins@novell.com>
> ---
>
> kvm/libkvm/libkvm.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
> kvm/libkvm/libkvm.h | 14 ++++++++++++++
> 2 files changed, 63 insertions(+), 0 deletions(-)
>
> diff --git a/kvm/libkvm/libkvm.c b/kvm/libkvm/libkvm.c
> index ba0a5d1..10cb2ac 100644
> --- a/kvm/libkvm/libkvm.c
> +++ b/kvm/libkvm/libkvm.c
> @@ -1444,3 +1444,52 @@ int kvm_assign_set_msix_entry(kvm_context_t kvm,
> return ret;
> }
> #endif
> +
> +#ifdef KVM_CAP_IRQFD
> +
> +#include <sys/eventfd.h>
> +
> +static int _kvm_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_IRQFD, &data);
> + if (r == -1)
> + r = -errno;
> + return r;
> +}
> +
> +int kvm_irqfd(kvm_context_t kvm, int gsi, int flags)
> +{
> + int r;
> + int fd;
> +
> + if (!kvm_check_extension(kvm, KVM_CAP_IRQFD))
> + return -ENOENT;
> +
> + fd = eventfd(0, 0);
> + if (fd < 0)
> + return -errno;
> +
> + r = _kvm_irqfd(kvm, fd, gsi, 0);
> + if (r < 0) {
> + close(fd);
> + return -errno;
> + }
> +
> + return fd;
> +}
> +
> +#else /* KVM_CAP_IRQFD */
> +
> +int kvm_irqfd(kvm_context_t kvm, int gsi, int flags)
> +{
> + return -ENOSYS;
> +}
> +
> +#endif /* KVM_CAP_IRQFD */
> diff --git a/kvm/libkvm/libkvm.h b/kvm/libkvm/libkvm.h
> index 4821a1e..aca8ed6 100644
> --- a/kvm/libkvm/libkvm.h
> +++ b/kvm/libkvm/libkvm.h
> @@ -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);
>
> --
> 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
>
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 266 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v8] qemu-kvm: add irqfd support
2009-06-02 15:45 [PATCH v8] qemu-kvm: add irqfd support Gregory Haskins
2009-06-02 15:48 ` Gregory Haskins
@ 2009-06-04 10:06 ` Avi Kivity
1 sibling, 0 replies; 4+ messages in thread
From: Avi Kivity @ 2009-06-04 10:06 UTC (permalink / raw)
To: Gregory Haskins; +Cc: kvm
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.
>
> [note: this is meant to work in conjunction with the POLLHUP version of
> irqfd, which has not yet been accepted into kvm.git]
>
Applied with two changes: added a dependency on CONFIG_eventfd (with the
kvm external module, you can have irqfd support without eventfd
support), and adjusted for the new libkvm location (libkvm-all.[ch]).
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v8] qemu-kvm: add irqfd support
@ 2009-05-14 17:02 Gregory Haskins
0 siblings, 0 replies; 4+ messages in thread
From: Gregory Haskins @ 2009-05-14 17:02 UTC (permalink / raw)
To: kvm; +Cc: avi
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 | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++
kvm/libkvm/libkvm.h | 26 +++++++++++++++++++++++
2 files changed, 83 insertions(+), 0 deletions(-)
diff --git a/kvm/libkvm/libkvm.c b/kvm/libkvm/libkvm.c
index ba0a5d1..ccab985 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,59 @@ int kvm_assign_set_msix_entry(kvm_context_t kvm,
return ret;
}
#endif
+
+#ifdef KVM_CAP_IRQFD
+static int _kvm_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_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_IRQFD))
+ return -ENOENT;
+
+ fd = eventfd(0, 0);
+ if (fd < 0)
+ return -errno;
+
+ r = _kvm_irqfd(kvm, fd, gsi, 0);
+ if (r < 0) {
+ close(fd);
+ return -errno;
+ }
+
+ return fd;
+}
+
+int kvm_destroy_irqfd(kvm_context_t kvm, int fd, int gsi, int flags)
+{
+ return _kvm_irqfd(kvm, fd, gsi, KVM_IRQFD_FLAG_DEASSIGN);
+}
+
+#else /* 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 gsi, int flags)
+{
+ return -ENOENT;
+}
+
+#endif /* KVM_CAP_IRQFD */
diff --git a/kvm/libkvm/libkvm.h b/kvm/libkvm/libkvm.h
index 4821a1e..3ccbe3d 100644
--- a/kvm/libkvm/libkvm.h
+++ b/kvm/libkvm/libkvm.h
@@ -856,6 +856,32 @@ 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 gsi GSI to close
+ * \param flags reserved, must be zero
+ */
+int kvm_destroy_irqfd(kvm_context_t kvm, int fd, 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);
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-06-04 10:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-06-02 15:45 [PATCH v8] qemu-kvm: add irqfd support Gregory Haskins
2009-06-02 15:48 ` Gregory Haskins
2009-06-04 10:06 ` Avi Kivity
-- strict thread matches above, loose matches on Subject: below --
2009-05-14 17:02 Gregory Haskins
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox