From: Gregory Haskins <ghaskins@novell.com>
To: kvm@vger.kernel.org
Cc: avi@redhat.com
Subject: [PATCH v7 2/2] qemu-kvm: add iofd support
Date: Tue, 12 May 2009 14:32:32 -0400 [thread overview]
Message-ID: <20090512183231.26356.81236.stgit@dev.haskins.net> (raw)
In-Reply-To: <20090512183059.26356.94857.stgit@dev.haskins.net>
An iofd allows an eventfd to attach to a specific PIO/MMIO region in the
guest. Any guest-writes to that region will trigger an eventfd signal.
Signed-off-by: Gregory Haskins <ghaskins@novell.com>
---
kvm/libkvm/libkvm.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++
kvm/libkvm/libkvm.h | 31 ++++++++++++++++++++++++++++++
2 files changed, 83 insertions(+), 0 deletions(-)
diff --git a/kvm/libkvm/libkvm.c b/kvm/libkvm/libkvm.c
index 74a21a2..0139abd 100644
--- a/kvm/libkvm/libkvm.c
+++ b/kvm/libkvm/libkvm.c
@@ -1497,6 +1497,45 @@ int kvm_destroy_irqfd(kvm_context_t kvm, int fd, int flags)
return r;
}
+int kvm_assign_iofd(kvm_context_t kvm, unsigned long addr, size_t len,
+ int fd, int type, int flags)
+{
+ int r;
+ struct kvm_iofd data = {
+ .addr = addr,
+ .len = len,
+ .fd = fd,
+ .flags = type ? KVM_IOFD_FLAG_PIO : 0,
+ };
+
+ if (!kvm_check_extension(kvm, KVM_CAP_EVENTFD))
+ return -ENOENT;
+
+ r = ioctl(kvm->vm_fd, KVM_IOFD, &data);
+ if (r == -1)
+ r = -errno;
+ return r;
+}
+
+int kvm_deassign_iofd(kvm_context_t kvm, unsigned long addr, size_t len,
+ int type, int flags)
+{
+ int r;
+ struct kvm_iofd data = {
+ .addr = addr,
+ .len = len,
+ .flags = KVM_IOFD_FLAG_DEASSIGN | (type ? KVM_IOFD_FLAG_PIO : 0),
+ };
+
+ if (!kvm_check_extension(kvm, KVM_CAP_EVENTFD))
+ return -ENOENT;
+
+ r = ioctl(kvm->vm_fd, KVM_IOFD, &data);
+ if (r == -1)
+ r = -errno;
+ return r;
+}
+
#else /* KVM_CAP_EVENTFD */
int kvm_create_irqfd(kvm_context_t kvm, int gsi, int flags)
@@ -1509,4 +1548,17 @@ int kvm_destroy_irqfd(kvm_context_t kvm, int fd, int flags)
return -ENOENT;
}
+int kvm_assign_iofd(kvm_context_t kvm, unsigned long addr, size_t len,
+ int fd, int type, int flags)
+{
+ return -ENOENT;
+}
+
+int kvm_deassign_iofd(kvm_context_t kvm, unsigned long addr, size_t len,
+ int type, int flags)
+{
+ return -ENOENT;
+}
+
#endif /* KVM_CAP_EVENTFD */
+
diff --git a/kvm/libkvm/libkvm.h b/kvm/libkvm/libkvm.h
index 322b4cd..89c558a 100644
--- a/kvm/libkvm/libkvm.h
+++ b/kvm/libkvm/libkvm.h
@@ -881,6 +881,37 @@ int kvm_create_irqfd(kvm_context_t kvm, int gsi, int flags);
*/
int kvm_destroy_irqfd(kvm_context_t kvm, int fd, int flags);
+/*!
+ * \brief Assign an eventfd to an IO port (PIO or MMIO)
+ *
+ * Assigns an eventfd based file-descriptor to a specific PIO or MMIO
+ * address range. Any guest writes to the specified range will generate
+ * an eventfd signal.
+ *
+ * \param kvm Pointer to the current kvm_context
+ * \param addr The IO address
+ * \param len The length of the IO region at the address
+ * \param fd The eventfd file-descriptor
+ * \param type MMIO=0, PIO=1
+ * \param flags reserved, must be zero
+ */
+int kvm_assign_iofd(kvm_context_t kvm, unsigned long addr, size_t len,
+ int fd, int type, int flags);
+
+/*!
+ * \brief Deassign an iofd from a previously registered IO port
+ *
+ * Deassigns an iofd previously registered with kvm_assign_iofd()
+ *
+ * \param kvm Pointer to the current kvm_context
+ * \param addr The IO address
+ * \param len The length of the IO region at the address
+ * \param type MMIO=0, PIO=1
+ * \param flags reserved, must be zero
+ */
+int kvm_deassign_iofd(kvm_context_t kvm, unsigned long addr, size_t len,
+ int type, int flags);
+
#ifdef KVM_CAP_DEVICE_MSIX
int kvm_assign_set_msix_nr(kvm_context_t kvm,
struct kvm_assigned_msix_nr *msix_nr);
prev parent reply other threads:[~2009-05-12 18:32 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-12 18:32 [PATCH v7 0/2] eventfd support for KVM userspace Gregory Haskins
2009-05-12 18:32 ` [PATCH v7 1/2] qemu-kvm: add irqfd support Gregory Haskins
2009-05-31 12:29 ` Avi Kivity
2009-06-02 14:54 ` Gregory Haskins
2009-05-12 18:32 ` Gregory Haskins [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090512183231.26356.81236.stgit@dev.haskins.net \
--to=ghaskins@novell.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox