Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2943996rdb; Tue, 6 Feb 2024 02:29:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IGrnO5EJZa7swpSveQUf967rvOVxrAE0ge0ArOwv3gzEQL/OJOj3HTvjzEVkj4Nh/NkWYW2 X-Received: by 2002:a05:6214:260e:b0:68c:4ab9:4620 with SMTP id gu14-20020a056214260e00b0068c4ab94620mr2701787qvb.42.1707215398016; Tue, 06 Feb 2024 02:29:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707215398; cv=pass; d=google.com; s=arc-20160816; b=mrBtZzjXIq2UMQEKSu6k0hZuyoqOcxYNmIMN9nBJhMQivsZ997z+OYO8HWPjc4xWbS 8dkpanZcmyLVb+cmwZWAMFnChXkBBlE5G1a0WhVIqhHDUF4jIe6ibHSAkyZ9Z8kWRctR ilnPsoTyFg0bkNLv9U08Ky5kn2ymLnujyJQWUipnjxRHtDOaX1qfUKATTCG/tdZS+pRG gCP55Rkn650qoOB43qW+yfrHcRHwhBYTAZsoJ9Af9TMvxpKuBPGnR+gp3hbfna8d2nPn SixGcww99tE0qKLUbI8a6CUPR9QG7SG4sJP0UlPgRZwDU5LJ3NzqrfEYNNYUgunlTHL6 cVLQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:references:in-reply-to:subject:cc:to:from:message-id :date:dkim-signature; bh=SU4tn7zB8t1YsSesI0q62VFjQfIQv1c/BHCu1NbjIOs=; fh=fbmRRmGyfTR7FAaUwHrJqP+kxyL8nFH+qt19fa6BGU0=; b=KE2XUm6BWr2GiQ19RCXU3FdAS7b7dRvx7/pUxNuSS3Tfu3rr2j0W9WlgKjN2gUBfK6 IQOC9a5JN9Nyu/8wL9fl/b7j7xu1XVqAP2HNM4/IYeHhYXsDyxwVre19hcg+Ks2hbIuQ OfYUqjiUT7WdQ0psQXWVTCEx0lv4QmzQXAgqXoCxvK72ASI/SJKIaIdKX5jUCXPGe/d0 mTsuAqmJ2pzLDFWGvMLeMWCFwGMurX6NFoRIvjr0E4kw3xPm0YXtKc9ydP/M3c62AHI3 yBMavJJ629eRD/eDxy4w7bxRYWqjtrf+MTVW5OJYZGgse6uxY7T3oPCzJb/6BcQQv1bv zwIw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="WbKK//aI"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-54689-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54689-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCXHY8R0WFn5CuTzYG7Ef18/GFOLmkf+lARqGHUfX5fC2j7aKT1ruox/FhbQwrGBjTEUSB2F3C4IR8LYaj9ZMGL4kjG2bv31Xv5ZySPKuA== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id jo19-20020a056214501300b0068cafc7c1bdsi1851371qvb.237.2024.02.06.02.29.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 02:29:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54689-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="WbKK//aI"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-54689-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54689-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 872381C23A40 for ; Tue, 6 Feb 2024 10:29:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D45DD12EBDF; Tue, 6 Feb 2024 10:29:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WbKK//aI" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 02F1312EBCA; Tue, 6 Feb 2024 10:29:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707215367; cv=none; b=MlxtzpLiopVKFvSz8e2L8sh9HzAZRkRP7EU9O6LyFkBkEraVqDMAlj0Cn5tLpLscdi0zDadhKz4pERR9I2agcRwuY4HFVuR6uo1yq7z6b8rqS90wMptfa+RpXmCiw8UkwFQHK7dTvIB4O3fGKnHlU9/Kh8vDdqSrY3LQ43nKnxU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707215367; c=relaxed/simple; bh=yQWyXDnKngD/mW309FyivfmArIxnKAMYY8kh8S/6+VI=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=LhSYZLXFdUXGN2n0u5OZp3xKaOsgEgIhJwRpzzjNWLfIiLKhj2diy13WGjoFfKsIJbLWl0hsHReoegIegaxPA00cSw5V4L0USohlqdhEWj1n/ylsMYs1mydgAOxfqsak+kngpIC/aZhSwJiDdyFga4FOiFh8uPOgBXF8kHGHR8o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WbKK//aI; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6250AC433F1; Tue, 6 Feb 2024 10:29:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707215366; bh=yQWyXDnKngD/mW309FyivfmArIxnKAMYY8kh8S/6+VI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=WbKK//aI6LbFbaL6CNf9KRaD0f70vHAyf/CF4LqcDnLb7IIiAzF4HCGEPTwjx/jaF YJBo+W6bZyOltfXDXJbyRHgYTZon/v9oszDQXZ00GSw7qtVHyocEvvUeAiw2ynuRqV EGWVMFYmS8qEmZ9Ynaq/ZVrbJsKy1dmOqoOQu9PMpL6OGKzwhwEYS/EPED00QzRNa/ FYCgqsWWAc7QndDh7l017QY949uz0Tw0AgaM+9zzs2KjYcOEbiYuNwB9J+9IAFjM/e xsF6GkadbDD7QNzlq8TnT7cGJzcF3yTDcXNuzNPi+gDMxH+uOhMbu4zpw3TuUHlLYN XMgCNVALA0Ijg== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rXIhf-000m2E-Hz; Tue, 06 Feb 2024 10:29:23 +0000 Date: Tue, 06 Feb 2024 10:29:22 +0000 Message-ID: <86y1bx6g3h.wl-maz@kernel.org> From: Marc Zyngier To: Saurav Sachidanand Cc: Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , , , Subject: Re: [PATCH] [RFC] KVM: arm64/vgic: Populate GICR_TYPER with Aff3 In-Reply-To: <20240205184326.78814-1-sauravsc@amazon.com> References: <20240205184326.78814-1-sauravsc@amazon.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/29.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: sauravsc@amazon.com, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Hi Saurav, On Mon, 05 Feb 2024 18:43:26 +0000, Saurav Sachidanand wrote: > > According to spec, bits [63:56] of the GICR_TYPER register are supposed > to contain Affinity level 3 (Aff3) bits of the Processing Element (PE) > associated with its GIC redistributor. Linux guests on boot match PEs > with their redistributor using all four Affinity level bits from this > register. If you read the spec carefully, you will notice that Aff3 support is *optional*, and that it is on purpose that we don't support Aff3: this cannot work for 32bit guests. The other thing is that there is no guarantee that the HW actually supports that either: ICH_VTR_EL2.A3V tells you whether the CPU interface actually supports it. > > Currently, vGIC populates GICR_TYPER with just the first three Affinity > levels of a vCPU's MPIDR. This works fine for a Linux guest that boots > with KVM's default vCPU MPIDR assignment, which also only populates till > the first three Affinity levels. > > However, a hypervisor can override KVM's default MPIDR assignment by > writing directly to a vCPU's MPIDR_EL1 register. If such a hypervisor > were to populate Aff3 bits for a VM, a Linux guest booting there would > fail to match vCPUs with their vGIC redistributors, since their virtual > GICR_TYPER registers would be missing the respective Aff3 bits. > > To change that, let's populate GICR_TYPER using Aff3 bits [39:32] from > the vCPU's MPIDR. > > Signed-off-by: Saurav Sachidanand > --- > arch/arm64/kvm/vgic/vgic-mmio-v3.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/arch/arm64/kvm/vgic/vgic-mmio-v3.c b/arch/arm64/kvm/vgic/vgic-mmio-v3.c > index c15ee1df036a..26bc838ce14c 100644 > --- a/arch/arm64/kvm/vgic/vgic-mmio-v3.c > +++ b/arch/arm64/kvm/vgic/vgic-mmio-v3.c > @@ -324,6 +324,7 @@ static unsigned long vgic_mmio_read_v3r_typer(struct kvm_vcpu *vcpu, > u64 value; > > value = (u64)(mpidr & GENMASK(23, 0)) << 32; > + value |= (u64)((mpidr >> 32) & GENMASK(7, 0)) << 56; > value |= ((target_vcpu_id & 0xffff) << 8); > > if (vgic_has_its(vcpu->kvm)) So if you consider the above remarks, this is neither sufficient nor guaranteed to work. I'm not opposed to having full Aff3 support (most of it is already there), but this needs to be done in a consistent way, and consider both the case of 32bit guests (which are not going away) and the capabilities of the HW (the current code being rather inconsistent in this regard). If you are willing to work on this, I'll happily review a more complete series of patches. Thanks, M. -- Without deviation from the norm, progress is not possible.