Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1012082ybe; Wed, 4 Sep 2019 11:07:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqw+p3w/Ie/QEB4RuOCeKfdYb7xVIGLrYaJ6sb2SJnQg/TM6nWENoo0XERDXKxR1NlUoFOAY X-Received: by 2002:a17:902:346:: with SMTP id 64mr42148295pld.151.1567620459265; Wed, 04 Sep 2019 11:07:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567620459; cv=none; d=google.com; s=arc-20160816; b=mH/hYoPA0LijVlvwZTxa6/93VFOEkanQpfLeA5wnmbnHx04OK3wAAx00hoySuhK+TX nC6/1HlI5tQEGbPdNCsGmiNnF28A3l2RDBBygjSaoSqKSQsmiApK1Ed7yi4HwX+1H/WG gYgswwiBaM9iXgZEsNmkY1J2et7Qh4I7HOqAXu+E43JYY0QaeZmbg4lvDF89Qe1+giAy dz2wB+1TL+eVMbJPO+JuEehStCHI9UjnJohMdUSyzxGVJp23e3f+NDVAlaNHNi9UvwA6 RkJxnX2OLKKH4vvlyiNKL0Ye8LcrB8srYsitj+wYZhdhP80qmBt6h7lNJhB0YdR0wF6a FQWw== 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=0+MRvZjmUayPhue7wAy6fV7F2Nl8NUHuo4tMLqUDsZc=; b=TAfjaESnM+K0wm66j+8LZ5QjmrpWHLoCmYR/QsedQBiZiB8isJY0GcomCRyYx7ye1w XQcW4g+yYU+nlDn1H/+Fbih12T+IWJVcWWq99C/wUtlA6txiWMEw1O/rbLFtUl5yjF/d zREQaPIVo47a5EC9d9/QZBQmXCByhhm4ZhwVJLEPxVC7f4hObc1BCUQExpCA1uzPoWEd KFqNYAqfe0pUsS+M3ESReNC83ixGW8/IGPffS+DJFHIMS5s/3D0PX3F/uzFlr8/eJF8n YJDFy85C66iM7TlefGY0GzdAghteU07YgCImdz37pWrCt56HOo3RA/H2PbbaXCK9z1QV a+1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dNXx2xtx; 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 38si11788879pla.249.2019.09.04.11.07.21; Wed, 04 Sep 2019 11:07:39 -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=dNXx2xtx; 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 S2389086AbfIDSE0 (ORCPT + 99 others); Wed, 4 Sep 2019 14:04:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:45412 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389082AbfIDSEX (ORCPT ); Wed, 4 Sep 2019 14:04:23 -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 2C14222CEA; Wed, 4 Sep 2019 18:04:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620262; bh=AHiHjcSpexHCfsm5AxLORu4CiMmROYrp9qEpv3KnMxI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dNXx2xtxG3VG9eJEGLqY7Kna1DIQ3X4fuoHzOmsqlOSoFZig5AvXQk7j7HcRS9lp5 L+mdWNLHkTJn+aUntu8a/E9tXmOzBHFa1tvpCC21MlmHa38CVE/IyXXSjtqIo4iaic dfxriqMWoJgkGgmm3JNYG95JUmYR2zCPm9rDZ75g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andre Przywara , Marc Zyngier , Will Deacon , Sasha Levin Subject: [PATCH 4.14 51/57] KVM: arm/arm64: vgic-v2: Handle SGI bits in GICD_I{S,C}PENDR0 as WI Date: Wed, 4 Sep 2019 19:54:19 +0200 Message-Id: <20190904175306.818216957@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175301.777414715@linuxfoundation.org> References: <20190904175301.777414715@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 [ Upstream commit 82e40f558de566fdee214bec68096bbd5e64a6a4 ] 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: Sasha Levin --- 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(-) diff --git a/virt/kvm/arm/vgic/vgic-mmio.c b/virt/kvm/arm/vgic/vgic-mmio.c index 36194c666814b..63c6b630174fd 100644 --- a/virt/kvm/arm/vgic/vgic-mmio.c +++ b/virt/kvm/arm/vgic/vgic-mmio.c @@ -123,6 +123,12 @@ unsigned long vgic_mmio_read_pending(struct kvm_vcpu *vcpu, return value; } +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) @@ -133,6 +139,12 @@ void vgic_mmio_write_spending(struct kvm_vcpu *vcpu, 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; + } + spin_lock(&irq->irq_lock); irq->pending_latch = true; @@ -151,6 +163,12 @@ void vgic_mmio_write_cpending(struct kvm_vcpu *vcpu, 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; + } + spin_lock(&irq->irq_lock); irq->pending_latch = false; diff --git a/virt/kvm/arm/vgic/vgic-v2.c b/virt/kvm/arm/vgic/vgic-v2.c index a2273a5aaece9..7fe39de1ee334 100644 --- a/virt/kvm/arm/vgic/vgic-v2.c +++ b/virt/kvm/arm/vgic/vgic-v2.c @@ -142,7 +142,10 @@ void vgic_v2_populate_lr(struct kvm_vcpu *vcpu, struct vgic_irq *irq, int lr) 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) diff --git a/virt/kvm/arm/vgic/vgic-v3.c b/virt/kvm/arm/vgic/vgic-v3.c index 094f8ff8f7ba9..084edc9dc553b 100644 --- a/virt/kvm/arm/vgic/vgic-v3.c +++ b/virt/kvm/arm/vgic/vgic-v3.c @@ -124,7 +124,10 @@ void vgic_v3_populate_lr(struct kvm_vcpu *vcpu, struct vgic_irq *irq, int lr) 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) -- 2.20.1