From patchwork Thu Sep 11 11:09:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 37235 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f71.google.com (mail-oa0-f71.google.com [209.85.219.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 501AE20491 for ; Thu, 11 Sep 2014 11:12:04 +0000 (UTC) Received: by mail-oa0-f71.google.com with SMTP id jd19sf10262533oac.2 for ; Thu, 11 Sep 2014 04:12:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=Xt36ixHH1h12BJ4B3JMIUZIWzqXR8BnEGMQi3Tsuymg=; b=QHV3eQbQ5dxG+VI1tp0AAgjh1ph+Um9JS4WeI5QUG4C+YIU3bAxSXfEJ84k/KaHHAv RE2Q+7drpB05rOc28Xjg7M7CCfgDvq4alWmf6C6+CaKnAm1gg5COwpC8AtaxzSCcb5kk lNkwb3E3btkdS0k7Rbk6FRvfyLksQ/SCdKyMQ6iukBnEEUgvR9BQx8jtGXO0CnLmacUn JlHit0ejxG2q+do8j8nRtqk+kh7lzmzaC6UjD0aS40Z8CVneC3RgGeQ1M8mJ7ZzvakPz 1ADwKFMUbKe0cJBMBWXUUUgt9nAqgi43Xl+VB+vUAIhm0xP49zCSLeWB7NxIBIC8iRf2 /3vg== X-Gm-Message-State: ALoCoQnY0cRECxCd/9xYA6qMkUzd5wYvT5Loe5m+9ArBFCeGST2/KsUS7Wox5puwxBWUV/4mt3+P X-Received: by 10.182.95.40 with SMTP id dh8mr98996obb.11.1410433923931; Thu, 11 Sep 2014 04:12:03 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.19.108 with SMTP id 99ls127100qgg.29.gmail; Thu, 11 Sep 2014 04:12:03 -0700 (PDT) X-Received: by 10.52.138.210 with SMTP id qs18mr134849vdb.18.1410433923764; Thu, 11 Sep 2014 04:12:03 -0700 (PDT) Received: from mail-vc0-f182.google.com (mail-vc0-f182.google.com [209.85.220.182]) by mx.google.com with ESMTPS id qh2si160291vcb.81.2014.09.11.04.12.03 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 11 Sep 2014 04:12:03 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.182 as permitted sender) client-ip=209.85.220.182; Received: by mail-vc0-f182.google.com with SMTP id le20so5826887vcb.41 for ; Thu, 11 Sep 2014 04:12:03 -0700 (PDT) X-Received: by 10.221.26.70 with SMTP id rl6mr170686vcb.0.1410433923665; Thu, 11 Sep 2014 04:12:03 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp573123vcb; Thu, 11 Sep 2014 04:12:03 -0700 (PDT) X-Received: by 10.67.4.230 with SMTP id ch6mr178406pad.109.1410433922573; Thu, 11 Sep 2014 04:12:02 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id bd1si1065258pad.15.2014.09.11.04.12.02 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Sep 2014 04:12:02 -0700 (PDT) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XS2Gt-0006wP-I0; Thu, 11 Sep 2014 11:10:39 +0000 Received: from foss-mx-na.foss.arm.com ([217.140.108.86]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XS2GS-0005Jc-7v for linux-arm-kernel@lists.infradead.org; Thu, 11 Sep 2014 11:10:12 +0000 Received: from foss-smtp-na-1.foss.arm.com (unknown [10.80.61.8]) by foss-mx-na.foss.arm.com (Postfix) with ESMTP id 3D1FF462; Thu, 11 Sep 2014 06:09:25 -0500 (CDT) Received: from collaborate-mta1.arm.com (highbank-bc01-b06.austin.arm.com [10.112.81.134]) by foss-smtp-na-1.foss.arm.com (Postfix) with ESMTP id C21B25FAD1; Thu, 11 Sep 2014 06:09:17 -0500 (CDT) Received: from e102391-lin.cambridge.arm.com (e102391-lin.cambridge.arm.com [10.1.209.143]) by collaborate-mta1.arm.com (Postfix) with ESMTP id E30DB13F813; Thu, 11 Sep 2014 06:09:16 -0500 (CDT) From: Marc Zyngier To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org Subject: [PATCH v4 1/8] KVM: ARM: vgic: plug irq injection race Date: Thu, 11 Sep 2014 12:09:08 +0100 Message-Id: <1410433755-3612-2-git-send-email-marc.zyngier@arm.com> X-Mailer: git-send-email 2.0.4 In-Reply-To: <1410433755-3612-1-git-send-email-marc.zyngier@arm.com> References: <1410433755-3612-1-git-send-email-marc.zyngier@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140911_041012_295787_C6697ED9 X-CRM114-Status: UNSURE ( 8.57 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -2.5 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain Cc: Andre Przywara , Christoffer Dall X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: marc.zyngier@arm.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.182 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 As it stands, nothing prevents userspace from injecting an interrupt before the guest's GIC is actually initialized. This goes unnoticed so far (as everything is pretty much statically allocated), but ends up exploding in a spectacular way once we switch to a more dynamic allocation (the GIC data structure isn't there yet). The fix is to test for the "ready" flag in the VGIC distributor before trying to inject the interrupt. Note that in order to avoid breaking userspace, we have to ignore what is essentially an error. Signed-off-by: Marc Zyngier Acked-by: Christoffer Dall --- virt/kvm/arm/vgic.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c index f7ab1ca..d3299d4 100644 --- a/virt/kvm/arm/vgic.c +++ b/virt/kvm/arm/vgic.c @@ -1584,7 +1584,8 @@ out: int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int irq_num, bool level) { - if (vgic_update_irq_pending(kvm, cpuid, irq_num, level)) + if (likely(vgic_initialized(kvm)) && + vgic_update_irq_pending(kvm, cpuid, irq_num, level)) vgic_kick_vcpus(kvm); return 0;