From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:58084) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SuPA8-0000oq-A1 for qemu-devel@nongnu.org; Thu, 26 Jul 2012 10:35:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SuPA2-0005Fp-0k for qemu-devel@nongnu.org; Thu, 26 Jul 2012 10:35:36 -0400 Received: from mnementh.archaic.org.uk ([81.2.115.146]:35648) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SuPA1-0005EA-OW for qemu-devel@nongnu.org; Thu, 26 Jul 2012 10:35:29 -0400 From: Peter Maydell Date: Thu, 26 Jul 2012 15:35:14 +0100 Message-Id: <1343313317-27087-5-git-send-email-peter.maydell@linaro.org> In-Reply-To: <1343313317-27087-1-git-send-email-peter.maydell@linaro.org> References: <1343313317-27087-1-git-send-email-peter.maydell@linaro.org> Subject: [Qemu-devel] [PATCH v2 4/7] kvm: Decouple 'irqfds usable' from 'kernel irqchip' List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Alexander Graf , Marcelo Tosatti , Jan Kiszka , Avi Kivity , patches@linaro.org Instead of assuming that we can use irqfds if and only if kvm_irqchip_in_kernel(), add a bool to the KVMState which indicates this, and is set only on x86 and only if the irqchip is in the kernel. The kernel documentation implies that the only thing you need to use KVM_IRQFD is that KVM_CAP_IRQFD is advertised, but this seems to be untrue. In particular the kernel does not (alas) return a sensible error if you try to set up an irqfd when you haven't created an irqchip. If it did we could remove all this nonsense and let the kernel return the error code. Signed-off-by: Peter Maydell Acked-by: Jan Kiszka --- kvm-all.c | 3 ++- kvm-stub.c | 1 + kvm.h | 11 +++++++++++ target-i386/kvm.c | 4 ++++ 4 files changed, 18 insertions(+), 1 deletions(-) diff --git a/kvm-all.c b/kvm-all.c index 9a34090..3a69e53 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -101,6 +101,7 @@ struct KVMState KVMState *kvm_state; bool kvm_kernel_irqchip; bool kvm_async_interrupts_allowed; +bool kvm_irqfds_allowed; static const KVMCapabilityInfo kvm_required_capabilites[] = { KVM_CAP_INFO(USER_MEMORY), @@ -1126,7 +1127,7 @@ static int kvm_irqchip_assign_irqfd(KVMState *s, int fd, int virq, bool assign) .flags = assign ? 0 : KVM_IRQFD_FLAG_DEASSIGN, }; - if (!kvm_irqchip_in_kernel()) { + if (!kvm_irqfds_enabled()) { return -ENOSYS; } diff --git a/kvm-stub.c b/kvm-stub.c index f2b0c61..02e7fe0 100644 --- a/kvm-stub.c +++ b/kvm-stub.c @@ -20,6 +20,7 @@ KVMState *kvm_state; bool kvm_kernel_irqchip; bool kvm_async_interrupts_allowed; +bool kvm_irqfds_allowed; int kvm_init_vcpu(CPUArchState *env) { diff --git a/kvm.h b/kvm.h index 47bf5ba..21436ef 100644 --- a/kvm.h +++ b/kvm.h @@ -25,6 +25,7 @@ extern int kvm_allowed; extern bool kvm_kernel_irqchip; extern bool kvm_async_interrupts_allowed; +extern bool kvm_irqfds_allowed; #if defined CONFIG_KVM || !defined NEED_CPU_H #define kvm_enabled() (kvm_allowed) @@ -40,10 +41,20 @@ extern bool kvm_async_interrupts_allowed; */ #define kvm_async_interrupts_enabled() (kvm_async_interrupts_allowed) +/** + * kvm_irqfds_enabled: + * + * Returns: true if we can use irqfds to inject interrupts into + * a KVM CPU (ie the kernel supports irqfds and we are running + * with a configuration where it is meaningful to use them). + */ +#define kvm_irqfds_enabled() (kvm_irqfds_allowed) + #else #define kvm_enabled() (0) #define kvm_irqchip_in_kernel() (false) #define kvm_async_interrupts_enabled() (false) +#define kvm_irqfds_enabled() (false) #endif struct kvm_run; diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 7e5f51e..5cb33a2 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -2045,4 +2045,8 @@ void kvm_arch_init_irq_routing(KVMState *s) */ no_hpet = 1; } + /* We know at this point that we're using the in-kernel + * irqchip, so we can use irqfds. + */ + kvm_irqfds_allowed = true; } -- 1.7.5.4