* [PATCH 1/2] kvm tools: Add kvm__has_cap() to check whether a cap is available on the host
@ 2011-12-14 6:37 Sasha Levin
2011-12-14 6:37 ` [PATCH 2/2] kvm tools: Don't use ioeventfds if no KVM_CAP_IOEVENTFD Sasha Levin
2011-12-15 4:25 ` [PATCH 1/2] kvm tools: Add kvm__has_cap() to check whether a cap is available on the host Matt Evans
0 siblings, 2 replies; 4+ messages in thread
From: Sasha Levin @ 2011-12-14 6:37 UTC (permalink / raw)
To: penberg; +Cc: mingo, gorcunov, asias.hejun, kvm, matt, Sasha Levin
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
tools/kvm/include/kvm/kvm.h | 2 ++
tools/kvm/kvm.c | 5 +++++
2 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h
index 7159952..d24b70a 100644
--- a/tools/kvm/include/kvm/kvm.h
+++ b/tools/kvm/include/kvm/kvm.h
@@ -79,4 +79,6 @@ static inline void *guest_flat_to_host(struct kvm *kvm, unsigned long offset)
return kvm->ram_start + offset;
}
+bool kvm__has_cap(struct kvm *kvm, u32 cap);
+
#endif /* KVM__KVM_H */
diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index 35ca2c5..a2f7a89 100644
--- a/tools/kvm/kvm.c
+++ b/tools/kvm/kvm.c
@@ -517,3 +517,8 @@ void kvm__notify_paused(void)
mutex_lock(&pause_lock);
mutex_unlock(&pause_lock);
}
+
+bool kvm__has_cap(struct kvm *kvm, u32 cap)
+{
+ return ioctl(kvm->sys_fd, KVM_CHECK_EXTENSION, cap) == 0;
+}
--
1.7.8
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] kvm tools: Don't use ioeventfds if no KVM_CAP_IOEVENTFD
2011-12-14 6:37 [PATCH 1/2] kvm tools: Add kvm__has_cap() to check whether a cap is available on the host Sasha Levin
@ 2011-12-14 6:37 ` Sasha Levin
2011-12-15 0:52 ` Matt Evans
2011-12-15 4:25 ` [PATCH 1/2] kvm tools: Add kvm__has_cap() to check whether a cap is available on the host Matt Evans
1 sibling, 1 reply; 4+ messages in thread
From: Sasha Levin @ 2011-12-14 6:37 UTC (permalink / raw)
To: penberg; +Cc: mingo, gorcunov, asias.hejun, kvm, matt, Sasha Levin
Check KVM_CAP_IOEVENTFD before using ioeventfds.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
tools/kvm/builtin-run.c | 2 +-
tools/kvm/include/kvm/ioeventfd.h | 2 +-
tools/kvm/ioeventfd.c | 16 +++++++++++++++-
3 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 76f1a8c..47e4ea8 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -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);
diff --git a/tools/kvm/include/kvm/ioeventfd.h b/tools/kvm/include/kvm/ioeventfd.h
index df01750..3a95788 100644
--- a/tools/kvm/include/kvm/ioeventfd.h
+++ b/tools/kvm/include/kvm/ioeventfd.h
@@ -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);
diff --git a/tools/kvm/ioeventfd.c b/tools/kvm/ioeventfd.c
index 3a240e4..75dd3f2 100644
--- a/tools/kvm/ioeventfd.c
+++ b/tools/kvm/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");
}
--
1.7.8
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] kvm tools: Don't use ioeventfds if no KVM_CAP_IOEVENTFD
2011-12-14 6:37 ` [PATCH 2/2] kvm tools: Don't use ioeventfds if no KVM_CAP_IOEVENTFD Sasha Levin
@ 2011-12-15 0:52 ` Matt Evans
0 siblings, 0 replies; 4+ messages in thread
From: Matt Evans @ 2011-12-15 0:52 UTC (permalink / raw)
To: Sasha Levin; +Cc: penberg, mingo, gorcunov, asias.hejun, kvm
On 14/12/11 17:37, Sasha Levin wrote:
> Check KVM_CAP_IOEVENTFD before using ioeventfds.
>
> Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
A much nicer solution than my "[PATCH V2 2/2] kvm tools: Make virtio-pci's
ioeventfd__add_event() fall back gracefully if ioeventfds unavailable".
matt.nastyhacks--;
Acked-by: Matt Evans <matt@ozlabs.org>
> ---
> tools/kvm/builtin-run.c | 2 +-
> tools/kvm/include/kvm/ioeventfd.h | 2 +-
> tools/kvm/ioeventfd.c | 16 +++++++++++++++-
> 3 files changed, 17 insertions(+), 3 deletions(-)
>
> diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
> index 76f1a8c..47e4ea8 100644
> --- a/tools/kvm/builtin-run.c
> +++ b/tools/kvm/builtin-run.c
> @@ -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);
> diff --git a/tools/kvm/include/kvm/ioeventfd.h b/tools/kvm/include/kvm/ioeventfd.h
> index df01750..3a95788 100644
> --- a/tools/kvm/include/kvm/ioeventfd.h
> +++ b/tools/kvm/include/kvm/ioeventfd.h
> @@ -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);
> diff --git a/tools/kvm/ioeventfd.c b/tools/kvm/ioeventfd.c
> index 3a240e4..75dd3f2 100644
> --- a/tools/kvm/ioeventfd.c
> +++ b/tools/kvm/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");
> }
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] kvm tools: Add kvm__has_cap() to check whether a cap is available on the host
2011-12-14 6:37 [PATCH 1/2] kvm tools: Add kvm__has_cap() to check whether a cap is available on the host Sasha Levin
2011-12-14 6:37 ` [PATCH 2/2] kvm tools: Don't use ioeventfds if no KVM_CAP_IOEVENTFD Sasha Levin
@ 2011-12-15 4:25 ` Matt Evans
1 sibling, 0 replies; 4+ messages in thread
From: Matt Evans @ 2011-12-15 4:25 UTC (permalink / raw)
To: Sasha Levin; +Cc: penberg, mingo, gorcunov, asias.hejun, kvm
On 14/12/11 17:37, Sasha Levin wrote:
> Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
> ---
> tools/kvm/include/kvm/kvm.h | 2 ++
> tools/kvm/kvm.c | 5 +++++
> 2 files changed, 7 insertions(+), 0 deletions(-)
>
> diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h
> index 7159952..d24b70a 100644
> --- a/tools/kvm/include/kvm/kvm.h
> +++ b/tools/kvm/include/kvm/kvm.h
> @@ -79,4 +79,6 @@ static inline void *guest_flat_to_host(struct kvm *kvm, unsigned long offset)
> return kvm->ram_start + offset;
> }
>
> +bool kvm__has_cap(struct kvm *kvm, u32 cap);
> +
> #endif /* KVM__KVM_H */
> diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
> index 35ca2c5..a2f7a89 100644
> --- a/tools/kvm/kvm.c
> +++ b/tools/kvm/kvm.c
> @@ -517,3 +517,8 @@ void kvm__notify_paused(void)
> mutex_lock(&pause_lock);
> mutex_unlock(&pause_lock);
> }
> +
> +bool kvm__has_cap(struct kvm *kvm, u32 cap)
> +{
> + return ioctl(kvm->sys_fd, KVM_CHECK_EXTENSION, cap) == 0;
> +}
^^^^
D'oh, this needs to be != 0, not == 0.
Cheers,
Matt
---
From: Matt Evans <matt@ozlabs.org>
Date: Thu, 15 Dec 2011 15:19:47 +1100
Subject: [PATCH] kvm tools: Fix inverted logic bug in kvm__has_cap
Commit 42efb1abf4ebebeedd14af34c073e673923e2898 compared KVM_CHECK_EXTENSION's
result wrong, stating 'has cap' true if 0. Invert the comparison.
Signed-off-by: Matt Evans <matt@ozlabs.org>
---
tools/kvm/kvm.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index 9583ab2..25f1419 100644
--- a/tools/kvm/kvm.c
+++ b/tools/kvm/kvm.c
@@ -523,5 +523,5 @@ void kvm__notify_paused(void)
bool kvm__has_cap(struct kvm *kvm, u32 cap)
{
- return ioctl(kvm->sys_fd, KVM_CHECK_EXTENSION, cap) == 0;
+ return ioctl(kvm->sys_fd, KVM_CHECK_EXTENSION, cap) != 0;
}
--
1.7.0.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-12-15 4:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-14 6:37 [PATCH 1/2] kvm tools: Add kvm__has_cap() to check whether a cap is available on the host Sasha Levin
2011-12-14 6:37 ` [PATCH 2/2] kvm tools: Don't use ioeventfds if no KVM_CAP_IOEVENTFD Sasha Levin
2011-12-15 0:52 ` Matt Evans
2011-12-15 4:25 ` [PATCH 1/2] kvm tools: Add kvm__has_cap() to check whether a cap is available on the host Matt Evans
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).