From patchwork Thu Jul 26 14:35:14 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 10278 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id D08B924048 for ; Thu, 26 Jul 2012 14:35:23 +0000 (UTC) Received: from mail-gh0-f180.google.com (mail-gh0-f180.google.com [209.85.160.180]) by fiordland.canonical.com (Postfix) with ESMTP id A1462A18F40 for ; Thu, 26 Jul 2012 14:35:23 +0000 (UTC) Received: by mail-gh0-f180.google.com with SMTP id z12so2031191ghb.11 for ; Thu, 26 Jul 2012 07:35:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=Si8wrYWrHh8jyhe3KbnbjNEkq2Tzpj7piytb7f7rRJg=; b=m4py394m1eNPXtuCAp1vBvYu4BkTCz1sAADSwfIeMyeY8Q/BgxTGMJUHvQa7QT94A/ HT8mMNK1kG0vyvzRxHrAO1jfk96L/An8XGioCAgB78zC522b+UfbHQ6LhTGKEKvOXW47 k0M19gVVai1faStYT8ulAx2diGkZPS4WX3eBk2g28t50gCF3i/cmjIP+uZSYE37D2fmV 3Hek10Y4qRgmn+C2ucscktIBEO7fTwGk5YXqF7JsX55zi7+WbWvP9714SyCmm+BbLs36 SsoYdyRk4Dt0xJxrkL77l+DKVTVOfzCIt/dR+NsloYA4QahTX1AFoHV7Y9N44MkIJXZN nl/g== Received: by 10.42.22.206 with SMTP id p14mr28493152icb.23.1343313323301; Thu, 26 Jul 2012 07:35:23 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.43.93.3 with SMTP id bs3csp142935icc; Thu, 26 Jul 2012 07:35:22 -0700 (PDT) Received: by 10.14.173.71 with SMTP id u47mr4371776eel.22.1343313321237; Thu, 26 Jul 2012 07:35:21 -0700 (PDT) Received: from mnementh.archaic.org.uk (1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.1.0.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id h44si1978563eem.71.2012.07.26.07.35.20 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 26 Jul 2012 07:35:21 -0700 (PDT) Received-SPF: neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) client-ip=2001:8b0:1d0::1; Authentication-Results: mx.google.com; spf=neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) smtp.mail=pm215@archaic.org.uk Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1SuP9q-00073S-4f; Thu, 26 Jul 2012 15:35:18 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Avi Kivity , Marcelo Tosatti , Jan Kiszka , Alexander Graf Subject: [PATCH v2 4/7] kvm: Decouple 'irqfds usable' from 'kernel irqchip' Date: Thu, 26 Jul 2012 15:35:14 +0100 Message-Id: <1343313317-27087-5-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1343313317-27087-1-git-send-email-peter.maydell@linaro.org> References: <1343313317-27087-1-git-send-email-peter.maydell@linaro.org> X-Gm-Message-State: ALoCoQmPJEwsxKRF30a8hdH1/nMN8U1B1nWufqbSWylPVGFyqRc0wSODy2vIaGupu3OFAmdj9o6e 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; }