From patchwork Mon Nov 13 09:17:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10055383 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A6CDC60586 for ; Mon, 13 Nov 2017 09:24:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A269728EA4 for ; Mon, 13 Nov 2017 09:24:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 976FE291E6; Mon, 13 Nov 2017 09:24:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1D9E528EA4 for ; Mon, 13 Nov 2017 09:24:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=X6pK/eHGts57iI9XNNaEX2AI0q8eGYdAhOUIijUGVBA=; b=QtAIPgDdwUFTbhl0T0yPTWEZwT S9S0nNLewzhERleFiIF1tF2/Xg5DNtT2tKlFVPPyGNTGiB3pdkPBV17KnZgI4eA2LI2B8Fi7eAf9U 1Cms7I9pKQd/f+pCnmRYGfMPt/AiRv+NT4HWE4zcYXON5uFakLdroDinhebT9VqosuqOgWXNqOoms Ya9Ub2/bP3XTlJJpvLhghDt3YibN3rpU7P9jAtiylu+9plS/t8d5HC7RH46sANPZ1LbcQwSb34VbQ QmoCLPG0VK9+pEsWuGShfNSg4E4yEpqjNVON3copS3ySy5hEQ20kGOAWB+PJ8y06z62YKNlVJcZlW INLOKtQw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eEAyU-0000D5-Dl; Mon, 13 Nov 2017 09:24:14 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eEAtK-0002XV-0P for linux-arm-kernel@lists.infradead.org; Mon, 13 Nov 2017 09:19:00 +0000 Received: by mail-wm0-x243.google.com with SMTP id b189so6525346wmd.5 for ; Mon, 13 Nov 2017 01:18:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Cwf8fTGS5IIQ0Y8CRSDVae1lpWv79YqjdKNuFO7uBwI=; b=NAcpCdeWV/NHuTuRdWllTKYuNPGLViiLXSNidSblGlxIR9uCR2IMhgGuleLfOVRB6v hpju5mrZXkUsjf3l87FeyRI+yWoVH+DcONtLTAhlteZLFVq95bLW9UK/7aakMMKLBSz9 sYR1RAVZqKe1jhNpDhXCPaYCXcPPq9OPMPeSw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Cwf8fTGS5IIQ0Y8CRSDVae1lpWv79YqjdKNuFO7uBwI=; b=EaXDuIQTPahQnM4yaYMOgN7omMJQs4EwkToTBoi4zyEFl/FZkPywdelHNlLdXzSVGR gnfr+NZMG3BGlkUWLyyjSw26p6hrNtWI+D9UWaBHeJ6icGywl+YpEDXz9tsa2knp3Tkv ooMubaCcmZQWQvDoLiHr+Ab2PGUZ62Mas4KvNMPi2CFGi7qRTlAQqW5GERtmYVutNTjO 29ok5KaNh4PTssW9QvmeGtKvolKJ2bDkrGBYqM/sMZmSMGIftzXWOPY1e8npAx/q3FA9 A676zdbjyNWVXgbWwtGYe1wFG3tjSXyh/BtwDENfKJ3wBr1o3Xc+W+TnwzMtC9MzVTuv 2eGA== X-Gm-Message-State: AJaThX7kZHRnXFvinRCjJjd+AwFKHCtACJrIckwMRiPh6KGCXSwrk5xw TsCGGZbVHSTV8Mc/Z0PKpd5UEg== X-Google-Smtp-Source: AGs4zMY7SsV6SMUa7F+vnwWIYvllsM+HiVP7ZL3qC/pP67DXDtrkYRP1vGJagxK4LZGhVY6hh2YWjQ== X-Received: by 10.28.69.8 with SMTP id s8mr5006578wma.65.1510564714742; Mon, 13 Nov 2017 01:18:34 -0800 (PST) Received: from localhost.localdomain (xd93dd96b.cust.hiper.dk. [217.61.217.107]) by smtp.gmail.com with ESMTPSA id x63sm9651399wma.39.2017.11.13.01.18.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 13 Nov 2017 01:18:33 -0800 (PST) From: Christoffer Dall To: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Subject: [PULL 26/27] KVM: arm/arm64: Fix GICv4 ITS initialization issues Date: Mon, 13 Nov 2017 10:17:51 +0100 Message-Id: <20171113091752.10663-27-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171113091752.10663-1-christoffer.dall@linaro.org> References: <20171113091752.10663-1-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171113_011854_590196_49937841 X-CRM114-Status: GOOD ( 15.47 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marc Zyngier , Christoffer Dall , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP We should only try to initialize GICv4 data structures on a GICv4 capable system. Move the vgic_supports_direct_msis() check inito vgic_v4_init() so that any KVM VGIC initialization path does not fail on non-GICv4 systems. Also be slightly more strict in the checking of the return value in vgic_its_create, and only error out on negative return values from the vgic_v4_init() function. This is important because the kvm device code only treats negative values as errors and only cleans up in this case. Errornously treating a positive return value as an error from the vgic_v4_init() function can lead to NULL pointer dereferences, as has recently been observed. Acked-by: Marc Zyngier Signed-off-by: Christoffer Dall --- virt/kvm/arm/vgic/vgic-init.c | 8 +++----- virt/kvm/arm/vgic/vgic-its.c | 2 +- virt/kvm/arm/vgic/vgic-v4.c | 3 +++ 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic-init.c b/virt/kvm/arm/vgic/vgic-init.c index 40be908da238..62310122ee78 100644 --- a/virt/kvm/arm/vgic/vgic-init.c +++ b/virt/kvm/arm/vgic/vgic-init.c @@ -285,11 +285,9 @@ int vgic_init(struct kvm *kvm) if (ret) goto out; - if (vgic_supports_direct_msis(kvm)) { - ret = vgic_v4_init(kvm); - if (ret) - goto out; - } + ret = vgic_v4_init(kvm); + if (ret) + goto out; kvm_for_each_vcpu(i, vcpu, kvm) kvm_vgic_vcpu_enable(vcpu); diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c index b8c1b724ba3e..c93ecd4a903b 100644 --- a/virt/kvm/arm/vgic/vgic-its.c +++ b/virt/kvm/arm/vgic/vgic-its.c @@ -1673,7 +1673,7 @@ static int vgic_its_create(struct kvm_device *dev, u32 type) if (vgic_initialized(dev->kvm)) { int ret = vgic_v4_init(dev->kvm); - if (ret) { + if (ret < 0) { kfree(its); return ret; } diff --git a/virt/kvm/arm/vgic/vgic-v4.c b/virt/kvm/arm/vgic/vgic-v4.c index 915d09dc2638..53c324aa44ef 100644 --- a/virt/kvm/arm/vgic/vgic-v4.c +++ b/virt/kvm/arm/vgic/vgic-v4.c @@ -118,6 +118,9 @@ int vgic_v4_init(struct kvm *kvm) struct kvm_vcpu *vcpu; int i, nr_vcpus, ret; + if (!vgic_supports_direct_msis(kvm)) + return 0; /* Nothing to see here... move along. */ + if (dist->its_vm.vpes) return 0;