Skip to contentSkip to conversation

kvm: Create an eventfd mechanism for EOIs to get to userspace

PATCH New Alex Williamson 1 participant 1 message Oct 29, 2010 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kvm: Create an eventfd mechanism for EOIs to get to userspace

To support VFIO based device assignment, we need to be able to get an EOI out of the KVM irqchip. This introduces a mechanism to do that by registering an eventfd to be signaled when the IRQ is ACKed.

---

 include/linux/kvm.h      |   13 ++++++
 include/linux/kvm_host.h |    6 +++
 virt/kvm/eventfd.c       |   95 ++++++++++++++++++++++++++++++++++++++++++++++
 virt/kvm/kvm_main.c      |    8 ++++
 4 files changed, 122 insertions(+), 0 deletions(-)
include/linux/kvm.h +13 -0
index ea2dc1a..92d5b27 100644
@@ -541,6 +541,7 @@ struct kvm_ppc_pvinfo {
 #define KVM_CAP_PPC_GET_PVINFO 57
 #define KVM_CAP_PPC_IRQ_LEVEL 58
 #define KVM_CAP_ASYNC_PF 59
+#define KVM_CAP_EOI_EVENTFD 60
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
@@ -620,6 +621,16 @@ struct kvm_clock_data {
 	__u32 pad[9];
 };
 
+#define KVM_EOI_EVENTFD_FLAG_DEASSIGN (1 << 0)
+#define KVM_EOI_EVENTFD_FLAG_DEASSERT (1 << 1)
+
+struct kvm_eoi {
+	__u32 fd;
+	__u32 gsi;
+	__u32 flags;
+	__u8  pad[20];
+};
+
 /*
  * ioctls for VM fds
  */
@@ -677,6 +688,8 @@ struct kvm_clock_data {
 #define KVM_SET_PIT2              _IOW(KVMIO,  0xa0, struct kvm_pit_state2)
 /* Available with KVM_CAP_PPC_GET_PVINFO */
 #define KVM_PPC_GET_PVINFO	  _IOW(KVMIO,  0xa1, struct kvm_ppc_pvinfo)
+/* Available with KVM_CAP_EOI_EVENTFD */
+#define KVM_EOI_EVENTFD           _IOW(KVMIO,  0xa2, struct kvm_eoi)
 
 /*
  * ioctls for vcpu fds
include/linux/kvm_host.h +6 -0
index ee4314e..5d50a7e 100644
@@ -227,6 +227,7 @@ struct kvm {
 		struct list_head  items;
 	} irqfds;
 	struct list_head ioeventfds;
+	struct list_head eoi_eventfds;
 #endif
 	struct kvm_vm_stat stat;
 	struct kvm_arch arch;
@@ -643,6 +644,7 @@ void kvm_eventfd_init(struct kvm *kvm);
 int kvm_irqfd(struct kvm *kvm, int fd, int gsi, int flags);
 void kvm_irqfd_release(struct kvm *kvm);
 int kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args);
+int kvm_eoi_eventfd(struct kvm *kvm, struct kvm_eoi *eoi);
 
 #else
 
@@ -658,6 +660,10 @@ static inline int kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args)
 	return -ENOSYS;
 }
 
+static inline int kvm_eoi_eventfd(struct kvm *kvm, struct kvm_eoi *eoi)
+{
+	return -ENOSYS;
+}
 #endif /* CONFIG_HAVE_KVM_EVENTFD */
 
 #ifdef CONFIG_KVM_APIC_ARCHITECTURE
virt/kvm/eventfd.c +95 -0

104 lines not on this page · raw message

virt/kvm/kvm_main.c +8 -0
index 88d869e..7ca6f13 100644
@@ -1807,6 +1807,14 @@ static long kvm_vm_ioctl(struct file *filp,
 		mutex_unlock(&kvm->lock);
 		break;
 #endif
+	case KVM_EOI_EVENTFD: {
+		struct kvm_eoi eoi;
+		r = -EFAULT;
+		if (copy_from_user(&eoi, argp, sizeof eoi))
+			goto out;
+		r = kvm_eoi_eventfd(kvm, &eoi);
+		break;
+	}
 	default:
 		r = kvm_arch_vm_ioctl(filp, ioctl, arg);
 		if (r == -ENOTTY)