From patchwork Mon May 11 11:16:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 48259 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DA10C21550 for ; Mon, 11 May 2015 11:20:01 +0000 (UTC) Received: by wgiv13 with SMTP id v13sf38245241wgi.3 for ; Mon, 11 May 2015 04:20:01 -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=8OkfwM9jJckCWb6Oz5fUxXxq2zzjkzinvwk5n2QPxWw=; b=VprXy4O6JCxa52/OZbc8EZrRjuhXzwCfZNMWS0VBK3FOHBP1rxrZ7zFD4Fg+A+ieet wKiWWdKJjRVSFDsX5GYmfa7foXG3QSezYaXxdcFqiCXX8fGmIfCTaYT/g5nrxpyC0ldJ 4Zf2Y62i29ya+I3YUYLQXBQl5Qfqkoz3mVZH0BqOWayM7E2g3pU5tNidpQGIFoIb/oXK at9h9PplGHDEi9AY5xCpjjQ9QuG1xp0R2LArIW5PYs/NPNIXZU7T+p0bQdfhARoZDWMC N4BS3TZ8Pku+9YUU1GiT34X1OuHALnmUz5IQ9f1O3DLwpL4RLNIC36nGjjwP/8jOFM2k KGkA== X-Gm-Message-State: ALoCoQnr7OyuSf6KR+NGOHYryD6mMEUhCfDn2hfzdDDx/ub0PJAs9NM7biKz+ROk2fnVbncTO3eA X-Received: by 10.112.14.101 with SMTP id o5mr7267580lbc.3.1431343201196; Mon, 11 May 2015 04:20:01 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.6.73 with SMTP id y9ls642485lay.1.gmail; Mon, 11 May 2015 04:20:01 -0700 (PDT) X-Received: by 10.152.2.227 with SMTP id 3mr7422074lax.73.1431343201087; Mon, 11 May 2015 04:20:01 -0700 (PDT) Received: from mail-la0-f44.google.com (mail-la0-f44.google.com. [209.85.215.44]) by mx.google.com with ESMTPS id bq3si8172972lbb.128.2015.05.11.04.20.01 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 May 2015 04:20:01 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by laat2 with SMTP id t2so90701875laa.1 for ; Mon, 11 May 2015 04:20:01 -0700 (PDT) X-Received: by 10.112.140.231 with SMTP id rj7mr7513689lbb.76.1431343200991; Mon, 11 May 2015 04:20:00 -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 hn6csp1444700lbb; Mon, 11 May 2015 04:19:59 -0700 (PDT) X-Received: by 10.68.194.6 with SMTP id hs6mr18460031pbc.58.1431343189532; Mon, 11 May 2015 04:19:49 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z11si17550607pas.160.2015.05.11.04.19.48; Mon, 11 May 2015 04:19:49 -0700 (PDT) Received-SPF: none (google.com: stable-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753990AbbEKLTn (ORCPT + 2 others); Mon, 11 May 2015 07:19:43 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:26325 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753986AbbEKLTk (ORCPT ); Mon, 11 May 2015 07:19:40 -0400 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t4BBJc0p003449 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 11 May 2015 11:19:38 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.13.8/8.13.8) with ESMTP id t4BBJckq019454 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Mon, 11 May 2015 11:19:38 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by userv0122.oracle.com (8.13.8/8.13.8) with ESMTP id t4BBJb3s012936; Mon, 11 May 2015 11:19:37 GMT Received: from lappy.hsd1.nh.comcast.net (/10.159.243.153) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 11 May 2015 04:19:37 -0700 From: Sasha Levin To: stable@vger.kernel.org, stable-commits@vger.kernel.org Cc: Christoffer Dall , Shannon Zhao , Sasha Levin Subject: [added to the 3.18 stable tree] arm/arm64: KVM: Initialize the vgic on-demand when injecting IRQs Date: Mon, 11 May 2015 07:16:33 -0400 Message-Id: <1431343152-19437-12-git-send-email-sasha.levin@oracle.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1431343152-19437-1-git-send-email-sasha.levin@oracle.com> References: <1431343152-19437-1-git-send-email-sasha.levin@oracle.com> X-Source-IP: aserv0022.oracle.com [141.146.126.234] 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: patch@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.44 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: Christoffer Dall commit ca7d9c829d419c06e450afa5f785d58198c37caa upstream. Userspace assumes that it can wire up IRQ injections after having created all VCPUs and after having created the VGIC, but potentially before starting the first VCPU. This can currently lead to lost IRQs because the state of that IRQ injection is not stored anywhere and we don't return an error to userspace. We haven't seen this problem manifest itself yet, presumably because guests reset the devices on boot, but this could cause issues with migration and other non-standard startup configurations. Reviewed-by: Marc Zyngier Signed-off-by: Christoffer Dall Signed-off-by: Shannon Zhao Signed-off-by: Sasha Levin --- virt/kvm/arm/vgic.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c index 12c10f2..9a8c183 100644 --- a/virt/kvm/arm/vgic.c +++ b/virt/kvm/arm/vgic.c @@ -1693,16 +1693,26 @@ out: int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int irq_num, bool level) { + int ret = 0; int vcpu_id; - if (likely(vgic_initialized(kvm))) { - vcpu_id = vgic_update_irq_pending(kvm, cpuid, irq_num, level); - if (vcpu_id >= 0) - /* kick the specified vcpu */ - kvm_vcpu_kick(kvm_get_vcpu(kvm, vcpu_id)); + if (unlikely(!vgic_initialized(kvm))) { + mutex_lock(&kvm->lock); + ret = vgic_init(kvm); + mutex_unlock(&kvm->lock); + + if (ret) + goto out; } - return 0; + vcpu_id = vgic_update_irq_pending(kvm, cpuid, irq_num, level); + if (vcpu_id >= 0) { + /* kick the specified vcpu */ + kvm_vcpu_kick(kvm_get_vcpu(kvm, vcpu_id)); + } + +out: + return ret; } static irqreturn_t vgic_maintenance_handler(int irq, void *data)