diff mbox

[8/8] kvm tools: Make virtio-pci's ioeventfd__add_event() fall back gracefully if ioeventfds unavailable

Message ID 4EDD94E1.7040705@ozlabs.org
State New, archived
Headers show

Commit Message

Matt Evans Dec. 6, 2011, 4:06 a.m. UTC
PPC KVM doesn't yet support ioeventfds, so don't bomb out/die.  virtio-pci is
able to function if it instead uses normal IO port notification.

Signed-off-by: Matt Evans <matt@ozlabs.org>
---
 tools/kvm/include/kvm/ioeventfd.h |    3 ++-
 tools/kvm/ioeventfd.c             |   12 +++++++++---
 tools/kvm/virtio/pci.c            |   11 ++++++++++-
 3 files changed, 21 insertions(+), 5 deletions(-)

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

Patch

diff --git a/tools/kvm/include/kvm/ioeventfd.h b/tools/kvm/include/kvm/ioeventfd.h
index df01750..5e458be 100644
--- a/tools/kvm/include/kvm/ioeventfd.h
+++ b/tools/kvm/include/kvm/ioeventfd.h
@@ -4,6 +4,7 @@ 
 #include <linux/types.h>
 #include <linux/list.h>
 #include <sys/eventfd.h>
+#include <stdbool.h>
 
 struct kvm;
 
@@ -21,7 +22,7 @@  struct ioevent {
 
 void ioeventfd__init(void);
 void ioeventfd__start(void);
-void ioeventfd__add_event(struct ioevent *ioevent);
+bool ioeventfd__add_event(struct ioevent *ioevent);
 void ioeventfd__del_event(u64 addr, u64 datamatch);
 
 #endif
diff --git a/tools/kvm/ioeventfd.c b/tools/kvm/ioeventfd.c
index 3a240e4..37f9a63 100644
--- a/tools/kvm/ioeventfd.c
+++ b/tools/kvm/ioeventfd.c
@@ -26,7 +26,7 @@  void ioeventfd__init(void)
 		die("Failed creating epoll fd");
 }
 
-void ioeventfd__add_event(struct ioevent *ioevent)
+bool ioeventfd__add_event(struct ioevent *ioevent)
 {
 	struct kvm_ioeventfd kvm_ioevent;
 	struct epoll_event epoll_event;
@@ -48,8 +48,13 @@  void ioeventfd__add_event(struct ioevent *ioevent)
 		.flags			= KVM_IOEVENTFD_FLAG_PIO | KVM_IOEVENTFD_FLAG_DATAMATCH,
 	};
 
-	if (ioctl(ioevent->fn_kvm->vm_fd, KVM_IOEVENTFD, &kvm_ioevent) != 0)
-		die("Failed creating new ioeventfd");
+	if (ioctl(ioevent->fn_kvm->vm_fd, KVM_IOEVENTFD, &kvm_ioevent) != 0) {
+		/* Not all KVM implementations may support KVM_IOEVENTFD,
+		 * so be graceful.
+		 */
+		free(new_ioevent);
+		return false;
+	}
 
 	epoll_event = (struct epoll_event) {
 		.events			= EPOLLIN,
@@ -60,6 +65,7 @@  void ioeventfd__add_event(struct ioevent *ioevent)
 		die("Failed assigning new event to the epoll fd");
 
 	list_add_tail(&new_ioevent->list, &used_ioevents);
+	return true;
 }
 
 void ioeventfd__del_event(u64 addr, u64 datamatch)
diff --git a/tools/kvm/virtio/pci.c b/tools/kvm/virtio/pci.c
index ffa3768..06d3b79 100644
--- a/tools/kvm/virtio/pci.c
+++ b/tools/kvm/virtio/pci.c
@@ -50,7 +50,16 @@  static int virtio_pci__init_ioeventfd(struct kvm *kvm, struct virtio_trans *vtra
 		.fd		= eventfd(0, 0),
 	};
 
-	ioeventfd__add_event(&ioevent);
+	if (!ioeventfd__add_event(&ioevent)) {
+#ifndef CONFIG_PPC
+		/* PPC64 doesn't have kvm ioevents yet, so we expect this to
+		 * fail -- don't need to be verbose about it!  For virtio-pci,
+		 * this is fine.  It catches the IO accesses anyway, so
+		 * still works (but slower).
+		 */
+		pr_warning("Failed creating new ioeventfd");
+#endif
+	}
 
 	if (vtrans->virtio_ops->notify_vq_eventfd)
 		vtrans->virtio_ops->notify_vq_eventfd(kvm, vpci->dev, vq, ioevent.fd);