Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp404369pxu; Tue, 1 Dec 2020 14:24:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJwKTRVVohPCw3wkQBXabnDC0smezijTsXBtlr4fEIhionkc209qspF3/eiMsnX2t859u3FC X-Received: by 2002:a17:906:87c3:: with SMTP id zb3mr5031431ejb.47.1606861485500; Tue, 01 Dec 2020 14:24:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606861485; cv=none; d=google.com; s=arc-20160816; b=Am1dw7O8McTngeYAp2bWS3ZAUhpMOowL70GsplJ3ZTGakSXN40Qvy7P43M80jfbMxu JnhsA8xTKWD4ExIfAaLoT29vcALB3ETH9e2cr2MXNg1bOLGGb2fwSd2HuU7tH2HfuJWK 30GiGNiUQK50VvufzPDqQHAHRoM1MRd1p+5PDe19tj/S9Ywy4c8XxRXmbni1U697WKHE ox+RHIbpXLRy7okFmZA5iBBpq+JlopV7AstR2Iblh6ykEiDXmRCVBWo4MQhwlB4oJIBE vr2Lum2yg88fsh0ubTDBJTJhtkD6gsicMwOba2sGwalmXsu1gj4UqQmsHUz4ZJA6LTzo 9nZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=M6oVQEB13EuoWcq6NJrtmXeiHzL5NMqQL+7qMHd3E5Y=; b=QdeHRV5NPSkhLo393QN+i5GI0xZ0j6Lw0dzK66tIYf2AKEiQNxv7GctuSLZ9WVMeGU naLdwKd/hglJJguau4jwZVdUytBbJZqAvXTHir5HD6XBStfPiM4+mWcVWjwAOh5sOhOU Nf2e50bMG8f91heOFDTNTXAcv2UPELR5tFflA9uM8IYaQ7+QTq2AqzMTCKJt9Nlvo0rc 6myU7d8gck9o2awDGYY5EFYcu+QuelVItfh8vdcB5kEaS6O0LnCbzI1AozWGDUNtIM43 1dCPH6DhbckH2swvKERmkhXZylEaTqqOyyl9FT2kwy1cTs+WzC9ry6/G9VZW++avSCc5 LQ7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KSZi3euR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m19si804292edb.315.2020.12.01.14.24.22; Tue, 01 Dec 2020 14:24:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KSZi3euR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389466AbgLAJJ3 (ORCPT + 99 others); Tue, 1 Dec 2020 04:09:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:45100 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389181AbgLAJIR (ORCPT ); Tue, 1 Dec 2020 04:08:17 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 B12782067D; Tue, 1 Dec 2020 09:08:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606813681; bh=0ZKrzedkeNaQQav56syj/ZPxW7yKpfWqhJQGXPQPkac=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KSZi3euRtWOSS6IRz+Ps9oKFYNtzWgmPZITQXxjrF3fbJ3FUp4S/fJn2jtOof7nXK Je6yaStEMLDgLUPD6ywk2IINso8akPXeOMN0QWdFter7/S5OrcwlEv0sBYmPJ/qcML WhlFFqabtk4pDWTx+ohiQEFDiWV38S1Pyunt2CKA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Keqian Zhu , Zenghui Yu , Marc Zyngier , Eric Auger Subject: [PATCH 5.9 023/152] KVM: arm64: vgic-v3: Drop the reporting of GICR_TYPER.Last for userspace Date: Tue, 1 Dec 2020 09:52:18 +0100 Message-Id: <20201201084714.917455697@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201201084711.707195422@linuxfoundation.org> References: <20201201084711.707195422@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zenghui Yu commit 23bde34771f1ea92fb5e6682c0d8c04304d34b3b upstream. It was recently reported that if GICR_TYPER is accessed before the RD base address is set, we'll suffer from the unset @rdreg dereferencing. Oops... gpa_t last_rdist_typer = rdreg->base + GICR_TYPER + (rdreg->free_index - 1) * KVM_VGIC_V3_REDIST_SIZE; It's "expected" that users will access registers in the redistributor if the RD has been properly configured (e.g., the RD base address is set). But it hasn't yet been covered by the existing documentation. Per discussion on the list [1], the reporting of the GICR_TYPER.Last bit for userspace never actually worked. And it's difficult for us to emulate it correctly given that userspace has the flexibility to access it any time. Let's just drop the reporting of the Last bit for userspace for now (userspace should have full knowledge about it anyway) and it at least prevents kernel from panic ;-) [1] https://lore.kernel.org/kvmarm/c20865a267e44d1e2c0d52ce4e012263@kernel.org/ Fixes: ba7b3f1275fd ("KVM: arm/arm64: Revisit Redistributor TYPER last bit computation") Reported-by: Keqian Zhu Signed-off-by: Zenghui Yu Signed-off-by: Marc Zyngier Reviewed-by: Eric Auger Link: https://lore.kernel.org/r/20201117151629.1738-1-yuzenghui@huawei.com Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- arch/arm64/kvm/vgic/vgic-mmio-v3.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) --- a/arch/arm64/kvm/vgic/vgic-mmio-v3.c +++ b/arch/arm64/kvm/vgic/vgic-mmio-v3.c @@ -273,6 +273,23 @@ static unsigned long vgic_mmio_read_v3r_ return extract_bytes(value, addr & 7, len); } +static unsigned long vgic_uaccess_read_v3r_typer(struct kvm_vcpu *vcpu, + gpa_t addr, unsigned int len) +{ + unsigned long mpidr = kvm_vcpu_get_mpidr_aff(vcpu); + int target_vcpu_id = vcpu->vcpu_id; + u64 value; + + value = (u64)(mpidr & GENMASK(23, 0)) << 32; + value |= ((target_vcpu_id & 0xffff) << 8); + + if (vgic_has_its(vcpu->kvm)) + value |= GICR_TYPER_PLPIS; + + /* reporting of the Last bit is not supported for userspace */ + return extract_bytes(value, addr & 7, len); +} + static unsigned long vgic_mmio_read_v3r_iidr(struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len) { @@ -593,8 +610,9 @@ static const struct vgic_register_region REGISTER_DESC_WITH_LENGTH(GICR_IIDR, vgic_mmio_read_v3r_iidr, vgic_mmio_write_wi, 4, VGIC_ACCESS_32bit), - REGISTER_DESC_WITH_LENGTH(GICR_TYPER, - vgic_mmio_read_v3r_typer, vgic_mmio_write_wi, 8, + REGISTER_DESC_WITH_LENGTH_UACCESS(GICR_TYPER, + vgic_mmio_read_v3r_typer, vgic_mmio_write_wi, + vgic_uaccess_read_v3r_typer, vgic_mmio_uaccess_write_wi, 8, VGIC_ACCESS_64bit | VGIC_ACCESS_32bit), REGISTER_DESC_WITH_LENGTH(GICR_WAKER, vgic_mmio_read_raz, vgic_mmio_write_wi, 4,