From patchwork Fri Aug 23 16:35:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 11112063 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 963421399 for ; Fri, 23 Aug 2019 16:35:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6B39B2082F for ; Fri, 23 Aug 2019 16:35:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566578137; bh=9/Ga/gY/4DodONFOysFXqlnV2abLZqyyzG+7T1oXTQs=; h=From:To:Cc:Subject:Date:List-ID:From; b=YcdSvWCuv79zfLwFO4Ze7VZGMbddQ3cWSl22Ds7I421OB8XrEZEJ5bs+82JxFbox3 Ked/BAa/nEEDwIW2u6exrcHl0ztKWGy7vxMaPHsoisrEaJ+VlXhrj3NOKd3W2oqbQn FWa5G83WWoKd9i/917hbAa3bDWEW0SmaRE5C+cyw= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436731AbfHWQfg (ORCPT ); Fri, 23 Aug 2019 12:35:36 -0400 Received: from foss.arm.com ([217.140.110.172]:36998 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389827AbfHWQfg (ORCPT ); Fri, 23 Aug 2019 12:35:36 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 769F328; Fri, 23 Aug 2019 09:35:35 -0700 (PDT) Received: from filthy-habits.cambridge.arm.com (filthy-habits.cambridge.arm.com [10.1.197.61]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C53193F246; Fri, 23 Aug 2019 09:35:33 -0700 (PDT) From: Marc Zyngier To: Paolo Bonzini , =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= Cc: Andre Przywara , Andrew Jones , Dave Martin , Julien Grall , Mark Rutland , Julien Thierry , James Morse , Suzuki K Poulose , linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu Subject: [GIT PULL] KVM/arm updates for 5.3-rc6 Date: Fri, 23 Aug 2019 17:35:14 +0100 Message-Id: <20190823163516.179768-1-maz@kernel.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Paolo, Radim, One (hopefully last) set of fixes for KVM/arm for 5.3: an embarassing MMIO emulation regression, and a UBSAN splat. Oh well... Please pull, M. The following changes since commit 16e604a437c89751dc626c9e90cf88ba93c5be64: KVM: arm/arm64: vgic: Reevaluate level sensitive interrupts on enable (2019-08-09 08:07:26 +0100) are available in the Git repository at: git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git tags/kvmarm-fixes-for-5.3-3 for you to fetch changes up to 2e16f3e926ed48373c98edea85c6ad0ef69425d1: KVM: arm/arm64: VGIC: Properly initialise private IRQ affinity (2019-08-23 17:23:01 +0100) ---------------------------------------------------------------- KVM/arm fixes for 5.3, take #3 - Don't overskip instructions on MMIO emulation - Fix UBSAN splat when initializing PPI priorities ---------------------------------------------------------------- Andre Przywara (1): KVM: arm/arm64: VGIC: Properly initialise private IRQ affinity Andrew Jones (1): KVM: arm/arm64: Only skip MMIO insn once virt/kvm/arm/mmio.c | 7 +++++++ virt/kvm/arm/vgic/vgic-init.c | 30 ++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 10 deletions(-) From patchwork Fri Aug 23 16:35:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 11112069 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DBA9A1709 for ; Fri, 23 Aug 2019 16:35:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BAF2221726 for ; Fri, 23 Aug 2019 16:35:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566578141; bh=Q6JaWtZbUkVEAtSydl7bb5cp6lWS6Y3PwQCQXZzN95s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=X4tslAmXE17SDTNI5R/IxpZOJL9oqYG5TVgw2XJq9BNwzrB5ZNxsnJM/wVnLaR0t3 mgqYodBCLVb0/DRW1GOsexrl0k8ct1t5lMYqK1P+OzLIzcA08YA6rPdy2aGrU1zYQ8 8wUieYn1Brci/Z7lUM6qs95BjFNUhAgveFjyEt4o= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436777AbfHWQfk (ORCPT ); Fri, 23 Aug 2019 12:35:40 -0400 Received: from foss.arm.com ([217.140.110.172]:37024 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436778AbfHWQfj (ORCPT ); Fri, 23 Aug 2019 12:35:39 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 454FA1570; Fri, 23 Aug 2019 09:35:39 -0700 (PDT) Received: from filthy-habits.cambridge.arm.com (filthy-habits.cambridge.arm.com [10.1.197.61]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 94A4B3F246; Fri, 23 Aug 2019 09:35:37 -0700 (PDT) From: Marc Zyngier To: Paolo Bonzini , =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= Cc: Andre Przywara , Andrew Jones , Dave Martin , Julien Grall , Mark Rutland , Julien Thierry , James Morse , Suzuki K Poulose , linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu Subject: [PATCH 2/2] KVM: arm/arm64: VGIC: Properly initialise private IRQ affinity Date: Fri, 23 Aug 2019 17:35:16 +0100 Message-Id: <20190823163516.179768-3-maz@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190823163516.179768-1-maz@kernel.org> References: <20190823163516.179768-1-maz@kernel.org> MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Andre Przywara At the moment we initialise the target *mask* of a virtual IRQ to the VCPU it belongs to, even though this mask is only defined for GICv2 and quickly runs out of bits for many GICv3 guests. This behaviour triggers an UBSAN complaint for more than 32 VCPUs: ------ [ 5659.462377] UBSAN: Undefined behaviour in virt/kvm/arm/vgic/vgic-init.c:223:21 [ 5659.471689] shift exponent 32 is too large for 32-bit type 'unsigned int' ------ Also for GICv3 guests the reporting of TARGET in the "vgic-state" debugfs dump is wrong, due to this very same problem. Because there is no requirement to create the VGIC device before the VCPUs (and QEMU actually does it the other way round), we can't safely initialise mpidr or targets in kvm_vgic_vcpu_init(). But since we touch every private IRQ for each VCPU anyway later (in vgic_init()), we can just move the initialisation of those fields into there, where we definitely know the VGIC type. On the way make sure we really have either a VGICv2 or a VGICv3 device, since the existing code is just checking for "VGICv3 or not", silently ignoring the uninitialised case. Signed-off-by: Andre Przywara Reported-by: Dave Martin Tested-by: Julien Grall Signed-off-by: Marc Zyngier --- virt/kvm/arm/vgic/vgic-init.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic-init.c b/virt/kvm/arm/vgic/vgic-init.c index bdbc297d06fb..e621b5d45b27 100644 --- a/virt/kvm/arm/vgic/vgic-init.c +++ b/virt/kvm/arm/vgic/vgic-init.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "vgic.h" @@ -164,12 +165,18 @@ static int kvm_vgic_dist_init(struct kvm *kvm, unsigned int nr_spis) irq->vcpu = NULL; irq->target_vcpu = vcpu0; kref_init(&irq->refcount); - if (dist->vgic_model == KVM_DEV_TYPE_ARM_VGIC_V2) { + switch (dist->vgic_model) { + case KVM_DEV_TYPE_ARM_VGIC_V2: irq->targets = 0; irq->group = 0; - } else { + break; + case KVM_DEV_TYPE_ARM_VGIC_V3: irq->mpidr = 0; irq->group = 1; + break; + default: + kfree(dist->spis); + return -EINVAL; } } return 0; @@ -209,7 +216,6 @@ int kvm_vgic_vcpu_init(struct kvm_vcpu *vcpu) irq->intid = i; irq->vcpu = NULL; irq->target_vcpu = vcpu; - irq->targets = 1U << vcpu->vcpu_id; kref_init(&irq->refcount); if (vgic_irq_is_sgi(i)) { /* SGIs */ @@ -219,11 +225,6 @@ int kvm_vgic_vcpu_init(struct kvm_vcpu *vcpu) /* PPIs */ irq->config = VGIC_CONFIG_LEVEL; } - - if (dist->vgic_model == KVM_DEV_TYPE_ARM_VGIC_V3) - irq->group = 1; - else - irq->group = 0; } if (!irqchip_in_kernel(vcpu->kvm)) @@ -286,10 +287,19 @@ int vgic_init(struct kvm *kvm) for (i = 0; i < VGIC_NR_PRIVATE_IRQS; i++) { struct vgic_irq *irq = &vgic_cpu->private_irqs[i]; - if (dist->vgic_model == KVM_DEV_TYPE_ARM_VGIC_V3) + switch (dist->vgic_model) { + case KVM_DEV_TYPE_ARM_VGIC_V3: irq->group = 1; - else + irq->mpidr = kvm_vcpu_get_mpidr_aff(vcpu); + break; + case KVM_DEV_TYPE_ARM_VGIC_V2: irq->group = 0; + irq->targets = 1U << idx; + break; + default: + ret = -EINVAL; + goto out; + } } }