From patchwork Tue Jun 30 10:48:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 50450 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 16D9C229DF for ; Tue, 30 Jun 2015 10:50:00 +0000 (UTC) Received: by widjy10 with SMTP id jy10sf5180226wid.3 for ; Tue, 30 Jun 2015 03:49:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=lzYLZX8mWvqrmQ5AjOPeU3CQo8a92bqS8zVB7gup+g0=; b=P87Pa/PIlGlk+e/ob1HGrBDvX953rNyrXm4ZEJACFxGalRGVZ9LMlSvoVS4lrd39Ph bJBZvMEGFLXrXNQ+Sl4itA6TIUsT2xsPo6coLR00iL7KZeNBKE8OrqyEQ/URjBhc08rJ aC5XcA02gZwK9bzxXFng3CXZXTJSP2n1eDHE+rySqhqpq9nqcLc7IrhtVDO/sEngE+IB Iem+hm3KFuMRLR9F96+nnVPmO5MkA5x/Sc1MSFNGG7cL5ufb1xOjnonVwHcEFa+eU+rH WX01DpwYSjySyUEMzRD7nq5iOnDbH7DoOfDPnlbPxHhHfkcqErJ8EGVEHR/voCgjXVQt EGMw== X-Gm-Message-State: ALoCoQl1uXgHPQyhZcpnmHrjoN81BDP3cDhhn319em9otWsye0phrQs01yXSvTCL996RTIVpOH8J X-Received: by 10.152.88.70 with SMTP id be6mr13702540lab.9.1435661399298; Tue, 30 Jun 2015 03:49:59 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.2.202 with SMTP id 10ls26876law.79.gmail; Tue, 30 Jun 2015 03:49:58 -0700 (PDT) X-Received: by 10.152.170.165 with SMTP id an5mr19155453lac.100.1435661398829; Tue, 30 Jun 2015 03:49:58 -0700 (PDT) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com. [209.85.215.48]) by mx.google.com with ESMTPS id da7si37763526lad.99.2015.06.30.03.49.58 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Jun 2015 03:49:58 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by lagh6 with SMTP id h6so8079688lag.2 for ; Tue, 30 Jun 2015 03:49:58 -0700 (PDT) X-Received: by 10.112.160.165 with SMTP id xl5mr18918866lbb.36.1435661398684; Tue, 30 Jun 2015 03:49:58 -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.112.108.230 with SMTP id hn6csp2352415lbb; Tue, 30 Jun 2015 03:49:57 -0700 (PDT) X-Received: by 10.68.69.70 with SMTP id c6mr34005601pbu.40.1435661396556; Tue, 30 Jun 2015 03:49:56 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y5si66313267par.87.2015.06.30.03.49.55; Tue, 30 Jun 2015 03:49:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752560AbbF3Ktz (ORCPT + 2 others); Tue, 30 Jun 2015 06:49:55 -0400 Received: from mail-pa0-f45.google.com ([209.85.220.45]:34520 "EHLO mail-pa0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750973AbbF3Kty (ORCPT ); Tue, 30 Jun 2015 06:49:54 -0400 Received: by pabvl15 with SMTP id vl15so3844771pab.1 for ; Tue, 30 Jun 2015 03:49:54 -0700 (PDT) X-Received: by 10.66.157.167 with SMTP id wn7mr42241432pab.119.1435661394107; Tue, 30 Jun 2015 03:49:54 -0700 (PDT) Received: from localhost ([120.136.36.232]) by mx.google.com with ESMTPSA id do16sm903985pac.15.2015.06.30.03.49.52 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 30 Jun 2015 03:49:53 -0700 (PDT) From: shannon.zhao@linaro.org To: stable@vger.kernel.org Cc: gregkh@linuxfoundation.org, christoffer.dall@linaro.org, shannon.zhao@linaro.org, Marc Zyngier Subject: [PATCH for 3.14.y stable 02/22] KVM: ARM: vgic: plug irq injection race Date: Tue, 30 Jun 2015 18:48:50 +0800 Message-Id: <1435661350-8060-3-git-send-email-shannon.zhao@linaro.org> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1435661350-8060-1-git-send-email-shannon.zhao@linaro.org> References: <1435661350-8060-1-git-send-email-shannon.zhao@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: stable@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: shannon.zhao@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 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 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Marc Zyngier Since we don't backport commit 227844f (arm/arm64: KVM: Rename irq_state to irq_pending) for linux-3.14.y, here we still use vgic_update_irq_state instead of vgic_update_irq_pending. commit 71afaba4a2e98bb7bdeba5078370ab43d46e67a1 upstream. 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 Signed-off-by: Shannon Zhao --- 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 1316e55..2187318 100644 --- a/virt/kvm/arm/vgic.c +++ b/virt/kvm/arm/vgic.c @@ -1387,7 +1387,8 @@ out: int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int irq_num, bool level) { - if (vgic_update_irq_state(kvm, cpuid, irq_num, level)) + if (likely(vgic_initialized(kvm)) && + vgic_update_irq_state(kvm, cpuid, irq_num, level)) vgic_kick_vcpus(kvm); return 0;