[PATCH v7 2/2] qemu-kvm: add iofd support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---

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

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

[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux