Message ID | 20240205184326.78814-1-sauravsc@amazon.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-53247-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1069986dyb; Mon, 5 Feb 2024 10:44:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IEaksVn5KcNTwBp6sWNQGdhuDjkxRkqQFeZHwqyiOWSRBB/qA+7E578lG96FJ0u6hzIbQUQ X-Received: by 2002:a0c:aad4:0:b0:68c:8aaf:3536 with SMTP id g20-20020a0caad4000000b0068c8aaf3536mr286152qvb.6.1707158664171; Mon, 05 Feb 2024 10:44:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707158664; cv=pass; d=google.com; s=arc-20160816; b=VOUdPktl0SGEF1PP0A3Yaau90PaeVGh+vDIHSXzhE3xUp8se1TTsc1uywufsxGd7EE 7D4rCieOsv1x0q/uiN6JPNYQToyLuU14dW/VDcBCKSY1goOqaZ4F7sJc+U/aix5FVckH mF4E0y38o0T+Qij6iYUteqYx3ni09wJURT4csqUYQUB8Q2udIjAHiuSTyFz69MNVFylu UUvwsWNT8Oy7n6Thaw5EwXKzzV0BCsv4UX7o0vHsUHXXoGTHRlQepE8JNFirI91/3UYI e7EwEa5Uzg9FbFebxzQijE7xT4NHxO8zK9YQ8EBK/8ek9X1xlLBep18QcevnleOPDEpk mTXQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=n0UiRQIDwXPhO89gFc7hLFAJlLuRhv/umCxdj84c8o0=; fh=g3WvP7hglbmCEAvYYI5E8KRkj3dL7tLDgTAb52oxYiI=; b=gkt/Fd8XWzbh4cLUdOQLLTQd774osAz/vjqK8rNJQ6ZBMCjXWfYu36w8T6a1jVzZfu lj47wM+2HGErTs7G/1k86L0j3vi8lwbrDJcGEgGj8qHI2V1m35U87y7693ty6QpXzOdh fvbslgz5sz5+xJMEXIh/qcB6zeUem2S4LaBRQr6kAqtanAmLgHfLKM/+UO0Uu4dJsC5/ xoH1uuyJfvU0keDe3vdd/p92olf0RHafZGeN9hpxWXDlydll31TqTFM8TjeYDwj+Ab6W iH+NUdAwXLgNRACgaW4gWl/LiofDff+b07QxW3TgTb4E6VHqMvMiCwaI7q04mmEaFQcp XdkA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=t7vvPXVD; arc=pass (i=1 spf=pass spfdomain=amazon.de dkim=pass dkdomain=amazon.com dmarc=pass fromdomain=amazon.com); spf=pass (google.com: domain of linux-kernel+bounces-53247-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53247-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com X-Forwarded-Encrypted: i=1; AJvYcCUsmhpv/tzvyTJVbdKPDkLBoQUqKYf+s8vxpf4vkIXA4Z+DbidPvcE6wABvmg8IQs2pH+T6lceYyhOeOam3/4P1ezrOCQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id ed10-20020ad44eaa000000b0068caf90f9bdsi197175qvb.116.2024.02.05.10.44.24 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 10:44:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-53247-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=t7vvPXVD; arc=pass (i=1 spf=pass spfdomain=amazon.de dkim=pass dkdomain=amazon.com dmarc=pass fromdomain=amazon.com); spf=pass (google.com: domain of linux-kernel+bounces-53247-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53247-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com 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 EC65B1C221E0 for <ouuuleilei@gmail.com>; Mon, 5 Feb 2024 18:44:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CBA5E482F2; Mon, 5 Feb 2024 18:43:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="t7vvPXVD" Received: from smtp-fw-80008.amazon.com (smtp-fw-80008.amazon.com [99.78.197.219]) (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 93C5B48799 for <linux-kernel@vger.kernel.org>; Mon, 5 Feb 2024 18:43:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=99.78.197.219 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707158623; cv=none; b=jFNUw5iPTgiSTUK3+iGwOtjkPYUGSOK0zfSmqx+S1fhEDw0/W9hRjxUsCt3ZzvLQZqGYBBCui0XdM73EQbyurtQSc0nClXHU6vLhPViWWaiRML8igByeVubDBv8IVs8vSJJCCuQhYKPFv7dD50EIkt+wNIbDKDzQSQ7S63FLhY4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707158623; c=relaxed/simple; bh=nmTgukHgTcZ/pZA80eYQ+M9fO2HDt9ms9ZXkd1+gOI8=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=nXoXyjGj+QG86iv4kBXv5P79lfkX7iAGRv9A0/NNbsS3HrTUGRfVAfJJRIpDUiSnsrdyTEn2B1ENjz1IZV21jkSBTOOu07FpLc4P7Jhmkv0VrDTKbyAdA+m0RJW3s7KraUQckgoskZqYifUdasrDzmVRcmw+6YRVot8tQZumpOs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.de; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=t7vvPXVD; arc=none smtp.client-ip=99.78.197.219 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1707158621; x=1738694621; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=n0UiRQIDwXPhO89gFc7hLFAJlLuRhv/umCxdj84c8o0=; b=t7vvPXVD0XXwX6DX6nZjuNeze+0e1hVjieo69BH8ohs7td2PnFE9dhWv zMfvVi0dKltnxX5tMJagvKd8z6/QhEYPqCVpHW61ZLftc4bCxpDiiYXM2 12HtgDyNubWWonL48stICQX4cIyDf/UHRBILWJx6zSpbjedNcwewi33FP o=; X-IronPort-AV: E=Sophos;i="6.05,245,1701129600"; d="scan'208";a="63862469" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.214]) by smtp-border-fw-80008.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2024 18:43:39 +0000 Received: from EX19MTAEUB001.ant.amazon.com [10.0.43.254:27241] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.8.155:2525] with esmtp (Farcaster) id f9ee6ae2-72b7-46e1-a0c5-bc63b12df20d; Mon, 5 Feb 2024 18:43:38 +0000 (UTC) X-Farcaster-Flow-ID: f9ee6ae2-72b7-46e1-a0c5-bc63b12df20d Received: from EX19D031EUB002.ant.amazon.com (10.252.61.105) by EX19MTAEUB001.ant.amazon.com (10.252.51.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 5 Feb 2024 18:43:38 +0000 Received: from EX19MTAUWA001.ant.amazon.com (10.250.64.204) by EX19D031EUB002.ant.amazon.com (10.252.61.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 5 Feb 2024 18:43:37 +0000 Received: from dev-dsk-sauravsc-1a-8777b848.eu-west-1.amazon.com (172.19.118.34) by mail-relay.amazon.com (10.250.64.204) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40 via Frontend Transport; Mon, 5 Feb 2024 18:43:35 +0000 From: Saurav Sachidanand <sauravsc@amazon.com> To: Marc Zyngier <maz@kernel.org>, Oliver Upton <oliver.upton@linux.dev>, James Morse <james.morse@arm.com>, Suzuki K Poulose <suzuki.poulose@arm.com>, Zenghui Yu <yuzenghui@huawei.com>, Catalin Marinas <catalin.marinas@arm.com>, Will Deacon <will@kernel.org> CC: Saurav Sachidanand <sauravsc@amazon.com>, <linux-arm-kernel@lists.infradead.org>, <kvmarm@lists.linux.dev>, <linux-kernel@vger.kernel.org> Subject: [PATCH] [RFC] KVM: arm64/vgic: Populate GICR_TYPER with Aff3 Date: Mon, 5 Feb 2024 18:43:26 +0000 Message-ID: <20240205184326.78814-1-sauravsc@amazon.com> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790085603220892058 X-GMAIL-MSGID: 1790085603220892058 |
Series |
[RFC] KVM: arm64/vgic: Populate GICR_TYPER with Aff3
|
|
Commit Message
Saurav Sachidanand
Feb. 5, 2024, 6:43 p.m. UTC
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.
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 <sauravsc@amazon.com>
---
arch/arm64/kvm/vgic/vgic-mmio-v3.c | 1 +
1 file changed, 1 insertion(+)
Comments
Hi Saurav, On Mon, Feb 05, 2024 at 06:43:26PM +0000, Saurav Sachidanand wrote: [...] > 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; This looks suspiciously similar to what MPIDR_AFFINITY_LEVEL() accomplishes. I think we can tolerate a few extra lines of code to make the entire thing more self-documenting, like: value = ((u64)MPIDR_AFFINITY_LEVEL(mpidr, 3) << 56 | MPIDR_AFFINITY_LEVEL(mpidr, 2) << 48 | MPIDR_AFFINITY_LEVEL(mpidr, 1) << 40 | MPIDR_AFFINITY_LEVEL(mpidr, 0) << 32);
Hi Saurav, On Mon, 05 Feb 2024 18:43:26 +0000, Saurav Sachidanand <sauravsc@amazon.com> 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 <sauravsc@amazon.com> > --- > 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.
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))