From patchwork Mon May 4 01:25:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 47928 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 9B18A20553 for ; Mon, 4 May 2015 01:27:50 +0000 (UTC) Received: by wizk4 with SMTP id k4sf30463010wiz.2 for ; Sun, 03 May 2015 18:27:49 -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=dsZ1PFDwx7CFq8C6dJ530yUTqB95Bk+UFWNkk6aJoR0=; b=cC0UQoGX687aL7q9iVH9i1yEtsWnrwEEICtQ7jGS+5XBOsjcUGVTiQx5uycTqHFM2G 1U79M3uj0LH9Ah3AYTT/8yWbCBM8ZnWqAEzKO1FNhb89JEgnYKI+qwzl6blg7Vk7E85Q 2dz5EarM8/JUPUo0dq3QHP1868m08xp1aZluIZm+hlrchOkAjtIVxoWAprFnQGRjZsfx uIfWTlbx8afgY97FrNjKpztQR6uJ9t1WXRypxSbx22+GUuFGPOUIrILiC+zJLiYWqPQT PFI/BCeKPQyZvsZe5NAcKRVUyd3cp1CvMvl4jcPhCCUh04q/FCOpvjrjiSTeepu8wQhn ymRA== X-Gm-Message-State: ALoCoQlkWZduegy9OWI6wygWi5pcIJLZvhi1SP+HfzpXYQ4lLaV5wPVf1ZfO+PuiqWPeiDjy86HE X-Received: by 10.112.53.102 with SMTP id a6mr16944443lbp.16.1430702869922; Sun, 03 May 2015 18:27:49 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.30.37 with SMTP id p5ls723160lah.9.gmail; Sun, 03 May 2015 18:27:49 -0700 (PDT) X-Received: by 10.152.236.40 with SMTP id ur8mr17653119lac.19.1430702869713; Sun, 03 May 2015 18:27:49 -0700 (PDT) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com. [209.85.217.169]) by mx.google.com with ESMTPS id w5si9061108laa.59.2015.05.03.18.27.49 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 May 2015 18:27:49 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) client-ip=209.85.217.169; Received: by lbbuc2 with SMTP id uc2so95373257lbb.2 for ; Sun, 03 May 2015 18:27:49 -0700 (PDT) X-Received: by 10.112.29.36 with SMTP id g4mr17977525lbh.56.1430702869623; Sun, 03 May 2015 18:27:49 -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.67.65 with SMTP id l1csp1406017lbt; Sun, 3 May 2015 18:27:48 -0700 (PDT) X-Received: by 10.70.38.195 with SMTP id i3mr38466536pdk.82.1430702867189; Sun, 03 May 2015 18:27:47 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id es7si17680936pbd.123.2015.05.03.18.27.45; Sun, 03 May 2015 18:27:47 -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 S1751860AbbEDB1p (ORCPT + 2 others); Sun, 3 May 2015 21:27:45 -0400 Received: from mail-pd0-f180.google.com ([209.85.192.180]:35030 "EHLO mail-pd0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751602AbbEDB1p (ORCPT ); Sun, 3 May 2015 21:27:45 -0400 Received: by pdbqd1 with SMTP id qd1so149640468pdb.2 for ; Sun, 03 May 2015 18:27:44 -0700 (PDT) X-Received: by 10.68.213.135 with SMTP id ns7mr19431013pbc.157.1430702864663; Sun, 03 May 2015 18:27:44 -0700 (PDT) Received: from localhost ([180.150.153.1]) by mx.google.com with ESMTPSA id bc14sm11010814pac.6.2015.05.03.18.27.42 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sun, 03 May 2015 18:27:43 -0700 (PDT) From: shannon.zhao@linaro.org To: stable@vger.kernel.org Cc: sasha.levin@oracle.com, christoffer.dall@linaro.org, shannon.zhao@linaro.org Subject: [PATCH for 3.18.y stable 12/22] arm/arm64: KVM: Initialize the vgic on-demand when injecting IRQs Date: Mon, 4 May 2015 09:25:16 +0800 Message-Id: <1430702726-2056-13-git-send-email-shannon.zhao@linaro.org> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1430702726-2056-1-git-send-email-shannon.zhao@linaro.org> References: <1430702726-2056-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.217.169 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 --- 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)