Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1159742yba; Thu, 4 Apr 2019 05:33:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqxKAn99HV3ZxqjHipJ4OqyIWMK9DfDmFDxK0xdF1naT+wmFf/WEKGvT21nI1Hz4sO4RxeMm X-Received: by 2002:a17:902:3e3:: with SMTP id d90mr6104884pld.271.1554381208080; Thu, 04 Apr 2019 05:33:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554381208; cv=none; d=google.com; s=arc-20160816; b=DfhSkssaHg7+fT2VRV2VOKY3diauDmOmvseYeV268hB35qpyALgBbmbwIxjVY7fMP4 O+93TRlfdgfTVnZ2atCqhnZU13ZuNb8t01gaXtMMrfsi8WFtkWaYF1Nx1vNBbHgKOtGL yrmkHmaQXlM5bJ1eXeWVcsnquEX+5tIlma+GPmJna1CgULPVrqnl20+4hzWVe3MAMToK QWi5FadBVggAadrwdf/5E0uDzV1sCrUoyMdS2P9XSjx3nvgH1sPU4ELZOMAej9+Qi7fG M6AlHQAiUiYjG0aH/vPGqHPUoP/XNflx5sLIPVoysPiNMYbJjY7MBJFIFsvPfYIMaQyg A5BQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=DTQNpOgaHAFxwYBxDT6yMNKtHKpxPOJwVoc/1TaOFAM=; b=RmCddP1OhTJFyy0nDSM6DtuLyrO3+V1KGPoMh7tpc9Z77TsvmynHJolvAMYOu9X8H9 bR/jSWBpzbjwdnOVaCv5wOvM+Nrow6+WgyxrxzjhJ+xcibfo0S34W8kVhwXH7JilbtJN o8eyypkEHPiIyiKQUivWZ8F39f3i6bDmmActWy1zkhCx7iKcx/1n6GLHyQIYqmxshKaP VTP60SsaemO90LPbQaILtEpuhY+O1MK6AfOH9tLlv5EYitZDwTSpnMjeF1bkePKt3xPo /71foQ3CcRq7Ai3k95hNiY+yw0stJK/qCCcWDCWmoDvNcMaMHYizod5+Dj+bj4mj6XPo qOVA== ARC-Authentication-Results: i=1; mx.google.com; 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 207si1206837pgc.266.2019.04.04.05.33.12; Thu, 04 Apr 2019 05:33:28 -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; 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 S1729581AbfDDMbG (ORCPT + 99 others); Thu, 4 Apr 2019 08:31:06 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:5665 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726790AbfDDMbG (ORCPT ); Thu, 4 Apr 2019 08:31:06 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 269E9F4AF30746A93AA2; Thu, 4 Apr 2019 20:31:04 +0800 (CST) Received: from HGHY2Y004646261.china.huawei.com (10.184.12.158) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.408.0; Thu, 4 Apr 2019 20:30:53 +0800 From: Zenghui Yu To: , CC: , , , , , , , , , Zenghui Yu Subject: [PATCH] KVM: arm/arm64: vgic: Restrict setting irq->targets only in GICv2 Date: Thu, 4 Apr 2019 12:30:15 +0000 Message-ID: <1554381015-13056-1-git-send-email-yuzenghui@huawei.com> X-Mailer: git-send-email 2.6.4.windows.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.184.12.158] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit ad275b8bb1e6 ("KVM: arm/arm64: vgic-new: vgic_init: implement vgic_init") had set irq->targets in kvm_vgic_vcpu_init(), regardless of the GIC architecture (v2 or v3). When the number of vcpu reaches 32 (in v3), UBSAN will complain about it. ================================================================================ UBSAN: Undefined behaviour in arch/arm64/kvm/../../../virt/kvm/arm/vgic/vgic-init.c:223:21 shift exponent 32 is too large for 32-bit type 'unsigned int' CPU: 13 PID: 833 Comm: CPU 32/KVM Kdump: loaded Not tainted 5.1.0-rc1+ #16 Hardware name: Huawei TaiShan 2280 /BC11SPCD, BIOS 1.58 10/24/2018 Call trace: dump_backtrace+0x0/0x190 show_stack+0x24/0x30 dump_stack+0xc8/0x114 ubsan_epilogue+0x14/0x50 __ubsan_handle_shift_out_of_bounds+0x118/0x188 kvm_vgic_vcpu_init+0x1d4/0x200 kvm_arch_vcpu_init+0x3c/0x48 kvm_vcpu_init+0xa8/0x100 kvm_arch_vcpu_create+0x94/0x120 kvm_vm_ioctl+0x57c/0xe58 do_vfs_ioctl+0xc4/0x7f0 ksys_ioctl+0x8c/0xa0 __arm64_sys_ioctl+0x28/0x38 el0_svc_common+0xa0/0x190 el0_svc_handler+0x38/0x78 el0_svc+0x8/0xc ================================================================================ This patch Restricts setting irq->targets in GICv2, which only supports a maximum of eight PEs, to keep UBSAN quiet. And since irq->mpidr will only be used by SPI in GICv3, we decided to set mpidr to 0 for SGI and PPI. Like commit ab2d5eb03dbb ("KVM: arm/arm64: vgic: Always initialize the group of private IRQs"), we should also take the creating order of the VGIC and VCPUs into consideration. Cc: Eric Auger Cc: Marc Zyngier Cc: Andre Przywara Cc: Christoffer Dall Signed-off-by: Zenghui Yu --- virt/kvm/arm/vgic/vgic-init.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic-init.c b/virt/kvm/arm/vgic/vgic-init.c index 3bdb31e..0cba92e 100644 --- a/virt/kvm/arm/vgic/vgic-init.c +++ b/virt/kvm/arm/vgic/vgic-init.c @@ -220,7 +220,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 */ @@ -231,10 +230,14 @@ int kvm_vgic_vcpu_init(struct kvm_vcpu *vcpu) irq->config = VGIC_CONFIG_LEVEL; } - if (dist->vgic_model == KVM_DEV_TYPE_ARM_VGIC_V3) + if (dist->vgic_model == KVM_DEV_TYPE_ARM_VGIC_V3) { irq->group = 1; - else + irq->mpidr = 0; + } else { irq->group = 0; + if (vcpu->vcpu_id < VGIC_V2_MAX_CPUS) + irq->targets = 1U << vcpu->vcpu_id; + } } if (!irqchip_in_kernel(vcpu->kvm)) @@ -297,10 +300,13 @@ 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) + if (dist->vgic_model == KVM_DEV_TYPE_ARM_VGIC_V3) { irq->group = 1; - else + irq->mpidr = 0; + } else { irq->group = 0; + irq->targets = 1U << vcpu->vcpu_id; + } } } -- 1.8.3.1