Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1024736ybe; Wed, 4 Sep 2019 11:19:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqxGfdPLKO13W6INhCaTRVBkYnWl73ympv8QnXNqzv/sw5JEfQrzr3DuO4xYVg+IbvZL995u X-Received: by 2002:a65:6795:: with SMTP id e21mr25658519pgr.428.1567621153140; Wed, 04 Sep 2019 11:19:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567621153; cv=none; d=google.com; s=arc-20160816; b=kyoNNO6SsNDQ6i+VhCrjRTXGjPJsxgtXv34TTkq6e84UF3cQapxiaoarqUkbftPnc/ x6A3PDnZzjk2x264gTRxifL4TM+l9QBJHL5tzfw6pc7iSvvO1Fg42CyAxViJztVgx16j q5Q+rwdaPj2Ub/ItsRPenoBJiOVuv20IWbGcKXkogTXqaXY3CQdAh4PQufctoHvjxrgr hiNxsw5QH9rEj/Cs1KWVJkM4/G8Kr5rXiQpK2RheZscLF3FZbevOU7U9SLtp3tgfZOZh ItEPTzNvm/lK68vTWIdaGl/9clt1PsAQXOXrDUyiSPSGxlFVu4PNQXfYrX2OSP9XKVKf dLbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Xep2inEDWvN+e7Lb921ry6mCfOHMOp2uEoG3RFPJRuc=; b=TcFQtfpPBLp5AEz/lFOfFTD2mTI62hwRa5NA+K0E6ofWIwlXFMMVm7nH9VklUNnkRY OAMDdneoUCuGzox3j4qSUDp/OQd61ezmmDxZbdkvECPy5HH7SV+Gb/P2wX4lyoU88K8d wbrHDy6An/+c+OBFEMOcyTJ+gJZs48BBv4T2d9aL6nqog+JuFhjFPwE2ZiGlh2cZ2gD/ +/EUBd7462KiUN/Psi9smhckNQNHMGuPgMHVjAABY1AQZXT6Kt39y7hSXCM2yIgmoueo N2oETEfGS0nk+dr1CeYI9/uJCBzln/blv2JmcaWssh5Da6DFHbqNpP9T9IM4f0clmOQ1 jNUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FNC4yPlH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s18si2796033pjq.43.2019.09.04.11.18.57; Wed, 04 Sep 2019 11:19:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FNC4yPlH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390486AbfIDSR1 (ORCPT + 99 others); Wed, 4 Sep 2019 14:17:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:57564 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389964AbfIDSM6 (ORCPT ); Wed, 4 Sep 2019 14:12:58 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4E25F208E4; Wed, 4 Sep 2019 18:12:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620776; bh=dzkmYbPsikkI1IIQQJOdu4RtdrB3+69Je+S4ujQejnQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FNC4yPlHgyR7qv1E3dq1vadDtx+E74wSKEkOcP7w8/svwSl7Kuo6dCGbeEbjrc+jN Aarw3tSXQobFtmGpOBz25LSx3QYZcARe72dxKggD87QTvVjPk0fXDR5Jm1uewcoQvQ immhjiPYyUnyoF184s3m5RedmYme9c/eNVCL4Ego= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andre Przywara , Marc Zyngier , Will Deacon Subject: [PATCH 5.2 090/143] KVM: arm/arm64: vgic-v2: Handle SGI bits in GICD_I{S,C}PENDR0 as WI Date: Wed, 4 Sep 2019 19:53:53 +0200 Message-Id: <20190904175317.621687275@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175314.206239922@linuxfoundation.org> References: <20190904175314.206239922@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marc Zyngier commit 82e40f558de566fdee214bec68096bbd5e64a6a4 upstream. A guest is not allowed to inject a SGI (or clear its pending state) by writing to GICD_ISPENDR0 (resp. GICD_ICPENDR0), as these bits are defined as WI (as per ARM IHI 0048B 4.3.7 and 4.3.8). Make sure we correctly emulate the architecture. Fixes: 96b298000db4 ("KVM: arm/arm64: vgic-new: Add PENDING registers handlers") Cc: stable@vger.kernel.org # 4.7+ Reported-by: Andre Przywara Signed-off-by: Marc Zyngier Signed-off-by: Will Deacon Signed-off-by: Greg Kroah-Hartman --- virt/kvm/arm/vgic/vgic-mmio.c | 18 ++++++++++++++++++ virt/kvm/arm/vgic/vgic-v2.c | 5 ++++- virt/kvm/arm/vgic/vgic-v3.c | 5 ++++- 3 files changed, 26 insertions(+), 2 deletions(-) --- a/virt/kvm/arm/vgic/vgic-mmio.c +++ b/virt/kvm/arm/vgic/vgic-mmio.c @@ -195,6 +195,12 @@ static void vgic_hw_irq_spending(struct vgic_irq_set_phys_active(irq, true); } +static bool is_vgic_v2_sgi(struct kvm_vcpu *vcpu, struct vgic_irq *irq) +{ + return (vgic_irq_is_sgi(irq->intid) && + vcpu->kvm->arch.vgic.vgic_model == KVM_DEV_TYPE_ARM_VGIC_V2); +} + void vgic_mmio_write_spending(struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len, unsigned long val) @@ -207,6 +213,12 @@ void vgic_mmio_write_spending(struct kvm for_each_set_bit(i, &val, len * 8) { struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, vcpu, intid + i); + /* GICD_ISPENDR0 SGI bits are WI */ + if (is_vgic_v2_sgi(vcpu, irq)) { + vgic_put_irq(vcpu->kvm, irq); + continue; + } + raw_spin_lock_irqsave(&irq->irq_lock, flags); if (irq->hw) vgic_hw_irq_spending(vcpu, irq, is_uaccess); @@ -254,6 +266,12 @@ void vgic_mmio_write_cpending(struct kvm for_each_set_bit(i, &val, len * 8) { struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, vcpu, intid + i); + /* GICD_ICPENDR0 SGI bits are WI */ + if (is_vgic_v2_sgi(vcpu, irq)) { + vgic_put_irq(vcpu->kvm, irq); + continue; + } + raw_spin_lock_irqsave(&irq->irq_lock, flags); if (irq->hw) --- a/virt/kvm/arm/vgic/vgic-v2.c +++ b/virt/kvm/arm/vgic/vgic-v2.c @@ -184,7 +184,10 @@ void vgic_v2_populate_lr(struct kvm_vcpu if (vgic_irq_is_sgi(irq->intid)) { u32 src = ffs(irq->source); - BUG_ON(!src); + if (WARN_RATELIMIT(!src, "No SGI source for INTID %d\n", + irq->intid)) + return; + val |= (src - 1) << GICH_LR_PHYSID_CPUID_SHIFT; irq->source &= ~(1 << (src - 1)); if (irq->source) { --- a/virt/kvm/arm/vgic/vgic-v3.c +++ b/virt/kvm/arm/vgic/vgic-v3.c @@ -167,7 +167,10 @@ void vgic_v3_populate_lr(struct kvm_vcpu model == KVM_DEV_TYPE_ARM_VGIC_V2) { u32 src = ffs(irq->source); - BUG_ON(!src); + if (WARN_RATELIMIT(!src, "No SGI source for INTID %d\n", + irq->intid)) + return; + val |= (src - 1) << GICH_LR_PHYSID_CPUID_SHIFT; irq->source &= ~(1 << (src - 1)); if (irq->source) {