aboutsummaryrefslogtreecommitdiffstats
path: root/ioeventfd.c
diff options
context:
space:
mode:
authorSasha Levin <levinsasha928@gmail.com>2011-12-14 08:37:26 +0200
committerWill Deacon <will.deacon@arm.com>2015-06-01 16:39:49 +0100
commite13377810d2571851908ec190494e0d333107bb6 (patch)
treee4f4a727fbc75acad801876b644bca3846bfd561 /ioeventfd.c
parent6930e42fa2485dc67cd3a5efc75278de45eec6a9 (diff)
downloadkvmtool-e13377810d2571851908ec190494e0d333107bb6.tar.gz
kvm tools: Don't use ioeventfds if no KVM_CAP_IOEVENTFD
Check KVM_CAP_IOEVENTFD before using ioeventfds. Signed-off-by: Sasha Levin <levinsasha928@gmail.com> Signed-off-by: Pekka Enberg <penberg@kernel.org>
Diffstat (limited to 'ioeventfd.c')
-rw-r--r--ioeventfd.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/ioeventfd.c b/ioeventfd.c
index 3a240e4f..75dd3f23 100644
--- a/ioeventfd.c
+++ b/ioeventfd.c
@@ -18,9 +18,14 @@
static struct epoll_event events[IOEVENTFD_MAX_EVENTS];
static int epoll_fd;
static LIST_HEAD(used_ioevents);
+static bool ioeventfd_avail;
-void ioeventfd__init(void)
+void ioeventfd__init(struct kvm *kvm)
{
+ ioeventfd_avail = kvm__has_cap(kvm, KVM_CAP_IOEVENTFD);
+ if (!ioeventfd_avail)
+ return;
+
epoll_fd = epoll_create(IOEVENTFD_MAX_EVENTS);
if (epoll_fd < 0)
die("Failed creating epoll fd");
@@ -33,6 +38,9 @@ void ioeventfd__add_event(struct ioevent *ioevent)
struct ioevent *new_ioevent;
int event;
+ if (!ioeventfd_avail)
+ return;
+
new_ioevent = malloc(sizeof(*new_ioevent));
if (new_ioevent == NULL)
die("Failed allocating memory for new ioevent");
@@ -68,6 +76,9 @@ void ioeventfd__del_event(u64 addr, u64 datamatch)
struct ioevent *ioevent;
u8 found = 0;
+ if (!ioeventfd_avail)
+ return;
+
list_for_each_entry(ioevent, &used_ioevents, list) {
if (ioevent->io_addr == addr) {
found = 1;
@@ -123,6 +134,9 @@ void ioeventfd__start(void)
{
pthread_t thread;
+ if (!ioeventfd_avail)
+ return;
+
if (pthread_create(&thread, NULL, ioeventfd__thread, NULL) != 0)
die("Failed starting ioeventfd thread");
}