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>
This commit is contained in:
Sasha Levin
2011-12-14 08:37:26 +02:00
committed by Will Deacon
parent 6930e42fa2
commit e13377810d
3 changed files with 17 additions and 3 deletions
+1 -1
View File
@@ -932,7 +932,7 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
kvm->single_step = single_step;
ioeventfd__init();
ioeventfd__init(kvm);
max_cpus = kvm__max_cpus(kvm);
recommended_cpus = kvm__recommended_cpus(kvm);
+1 -1
View File
@@ -19,7 +19,7 @@ struct ioevent {
struct list_head list;
};
void ioeventfd__init(void);
void ioeventfd__init(struct kvm *kvm);
void ioeventfd__start(void);
void ioeventfd__add_event(struct ioevent *ioevent);
void ioeventfd__del_event(u64 addr, u64 datamatch);
+15 -1
View File
@@ -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");
}