[RFC] KVM: arm64: Override Microsoft Azure Cobalt 100 MIDR value with ARM Neoverse N2
Message ID | 20240206195819.1146693-1-eahariha@linux.microsoft.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-55576-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1786484dyb; Tue, 6 Feb 2024 12:06:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IFqBrAUd4YR1PV/9V4/cdfd51/58miVfR+rx1+jslkylsOgFfzuRuGi2hg6TlWtXSHxAiyv X-Received: by 2002:a05:6402:31f5:b0:560:cdcb:cdf6 with SMTP id dy21-20020a05640231f500b00560cdcbcdf6mr1678edb.38.1707249982482; Tue, 06 Feb 2024 12:06:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707249982; cv=pass; d=google.com; s=arc-20160816; b=BN2bN3f6Jc1habiE2LEM1XCwRDV6DIJvInpkMBw+MzKMhs9cJuSK5V30GBTMmwEkPE /8hJy4WGr+YGkWMguMeNukWXv08ZNo+QuQjLl3wBpH2rbrri5F2+Xcl4ux7GckpcfurZ RAcbGprKNhDNQ184mBPCbFjxDV8PHbOOELTZw2QygbjZQ4oVGJMEKPew7UivNrTCfrNj Lgq5QP52qEu/+o3pAOK+h+oJdodnEBZ2O3L2j3qzxlulCdtkKMcC92LTxI6/lN4RYYSQ zKKuwZG/2I2dRiMEjCfS7N1LsLHMBwsTx9bUJ2GaIk2hD0COObyNSknM/8D2cvui1oh3 AH3w== 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:to:from :dkim-signature:dkim-filter; bh=YiGmA9Lr1a/CDIgqHElD8PPnAN1LFYjN75PS7RDnPho=; fh=BaU0yMHiMOBu4M7z041dmsIrpFJhBT+DagyVKkZprNE=; b=BtzFseBO9D92+8JEDLlvIN1I0Dk5cEs6WqHR2FKeKmigf/aOA/zNSr23RA/j2Ik06l rX5iaOF9U3IHWQ/hUMWNFDMpL7669a+NR7KqShCm+aUQreVl1HZ7CEHJ06W3S69gRTlI eSwOWQpmahLg+ejQgkqVVs4dng6GWR0rHO1TcgjSpOXhcRnM0yIQC59Rp0PpT7aG9fyt P9GRl0swbaLnG0Qv9EPqqr5Zy4Xl3ao9oTCkG241rROhEgQnjDpJ1Q/gul9MiPIsDmWC 8+Em1Bq3bxug/1S8NBb+R6SGKxHBbADtj17Z9vdYMfhBwJxv/N4iBORrD8KyBQA6Kfeg Ltdw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=QVf5neav; arc=pass (i=1 spf=pass spfdomain=linux.microsoft.com dkim=pass dkdomain=linux.microsoft.com dmarc=pass fromdomain=linux.microsoft.com); spf=pass (google.com: domain of linux-kernel+bounces-55576-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55576-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com X-Forwarded-Encrypted: i=1; AJvYcCU+h9S3dl4QspwRr3Q+0TQBt6udJB48zL4enxivPuWsdrq++ClaP/eDujgigChQyTrJNP/C1sibkE8J3w9Nnis9PMgZ1w== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id g15-20020a0564021ecf00b00560a347aa4csi1413388edg.377.2024.02.06.12.06.22 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 12:06:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55576-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=QVf5neav; arc=pass (i=1 spf=pass spfdomain=linux.microsoft.com dkim=pass dkdomain=linux.microsoft.com dmarc=pass fromdomain=linux.microsoft.com); spf=pass (google.com: domain of linux-kernel+bounces-55576-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55576-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.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 am.mirrors.kernel.org (Postfix) with ESMTPS id 1E0A51F25829 for <ouuuleilei@gmail.com>; Tue, 6 Feb 2024 19:58:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C2B9217BD6; Tue, 6 Feb 2024 19:58:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="QVf5neav" Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9266617745 for <linux-kernel@vger.kernel.org>; Tue, 6 Feb 2024 19:58:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707249516; cv=none; b=uMcooQiSAQ1dO8HfLcGFMTyzU1jEQwwPpG02iwC76dF6e5NFt+ZHSR8PHdOgC5Psif6HEHvl/8Sk01TGnjFdBnUnN/R9KZEqgIcu/oHXPdI6IFEByl12GoS3pP6qWqLMesVlJTYILyGfn8xWivAxsWwRiIElILgsEsmX/ZhDZ4c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707249516; c=relaxed/simple; bh=CSs8R3eAqFpZbozTGGxVMdRi1LPhZmwG0SUML7+4tx4=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=fraxAcukGdWpuc6EbHUVr6rMaSXEbZXtJaUOgKv6cFUAX+NH6UnLL7d8gkvYs6K7ebC1s7NcwP0RDJ3PAYInNXGSG2M2sMfKpiLK7vPkwjLlJTvQRnfFwpqpnmPC+CKoPOih2L754ZE+p/m7igQh8G+LA0dTCn/BEjfnTqtWS1o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=QVf5neav; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Received: from rrs24-12-35.corp.microsoft.com (unknown [131.107.8.19]) by linux.microsoft.com (Postfix) with ESMTPSA id E764F20B2000; Tue, 6 Feb 2024 11:58:33 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com E764F20B2000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1707249514; bh=YiGmA9Lr1a/CDIgqHElD8PPnAN1LFYjN75PS7RDnPho=; h=From:To:Subject:Date:From; b=QVf5neav0galuOadt6P17o8D+jpDq8FW0dD+dOrJecGZiNAcOz3KgLTnX01F6RU9G Kgt5DG9JP3uEkIGH1aTeUYBiD23JfuLOCzEo5q+slprE1w1TSUoWfrvMQVnGpRPk9Q XZXfHj/Uf9P1AOnahuIRFutrj/ftsu+Qlsgbah5Y= From: Easwar Hariharan <eahariha@linux.microsoft.com> To: Catalin Marinas <catalin.marinas@arm.com>, Will Deacon <will@kernel.org>, 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>, Andre Przywara <andre.przywara@arm.com>, Rob Herring <robh@kernel.org>, Fuad Tabba <tabba@google.com>, Joey Gouly <joey.gouly@arm.com>, Kristina Martsenko <kristina.martsenko@arm.com>, linux-arm-kernel@lists.infradead.org (moderated list:ARM64 PORT (AARCH64 ARCHITECTURE)), linux-kernel@vger.kernel.org (open list), kvmarm@lists.linux.dev (open list:KERNEL VIRTUAL MACHINE FOR ARM64 (KVM/arm64)) Subject: [RFC PATCH] KVM: arm64: Override Microsoft Azure Cobalt 100 MIDR value with ARM Neoverse N2 Date: Tue, 6 Feb 2024 19:58:16 +0000 Message-Id: <20240206195819.1146693-1-eahariha@linux.microsoft.com> X-Mailer: git-send-email 2.34.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-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790181358090078250 X-GMAIL-MSGID: 1790181358090078250 |
Series |
[RFC] KVM: arm64: Override Microsoft Azure Cobalt 100 MIDR value with ARM Neoverse N2
|
|
Commit Message
Easwar Hariharan
Feb. 6, 2024, 7:58 p.m. UTC
Several workload optimizations and errata depend on validating that the
optimization or errata are applicable to the particular CPU by checking
the MIDR_EL1 system register value. With the Microsoft implementer ID
for Azure Cobalt 100, the value doesn't match and ~20-25% performance
regression is seen in these workloads. Override the Azure Cobalt 100
value and replace it with the default ARM Neoverse N2 value that Azure
Cobalt 100 is based on.
Signed-off-by: Easwar Hariharan <eahariha@linux.microsoft.com>
---
arch/arm64/include/asm/cputype.h | 3 ++-
arch/arm64/include/asm/el2_setup.h | 5 +++++
arch/arm64/kvm/sys_regs.c | 9 ++++++++-
3 files changed, 15 insertions(+), 2 deletions(-)
Comments
On 2/7/24 01:28, Easwar Hariharan wrote: > Several workload optimizations and errata depend on validating that the > optimization or errata are applicable to the particular CPU by checking > the MIDR_EL1 system register value. With the Microsoft implementer ID Which is how it should be done. > for Azure Cobalt 100, the value doesn't match and ~20-25% performance > regression is seen in these workloads. Override the Azure Cobalt 100 > value and replace it with the default ARM Neoverse N2 value that Azure > Cobalt 100 is based on. Why cannot these MIDR values be classified as required and subscribed to the existing erratas that is affecting such implementations. Hence these work arounds will be triggered as and when applicable. Why then override MIDR value instead ? > > Signed-off-by: Easwar Hariharan <eahariha@linux.microsoft.com> > --- > arch/arm64/include/asm/cputype.h | 3 ++- > arch/arm64/include/asm/el2_setup.h | 5 +++++ > arch/arm64/kvm/sys_regs.c | 9 ++++++++- > 3 files changed, 15 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/include/asm/cputype.h b/arch/arm64/include/asm/cputype.h > index 7c7493cb571f..0450c6c32377 100644 > --- a/arch/arm64/include/asm/cputype.h > +++ b/arch/arm64/include/asm/cputype.h > @@ -262,7 +262,8 @@ is_midr_in_range_list(u32 midr, struct midr_range const *ranges) > */ > static inline u32 __attribute_const__ read_cpuid_id(void) > { > - return read_cpuid(MIDR_EL1); > + return (read_cpuid(MIDR_EL1) == 0x6D0FD490 ? 0x410FD490 : > + read_cpuid(MIDR_EL1)); > } > > static inline u64 __attribute_const__ read_cpuid_mpidr(void) > diff --git a/arch/arm64/include/asm/el2_setup.h b/arch/arm64/include/asm/el2_setup.h > index b7afaa026842..502a14e54a31 100644 > --- a/arch/arm64/include/asm/el2_setup.h > +++ b/arch/arm64/include/asm/el2_setup.h > @@ -138,6 +138,11 @@ > .macro __init_el2_nvhe_idregs > mrs x0, midr_el1 > mrs x1, mpidr_el1 > + ldr x2, =0x6D0FD490 > + cmp x0, x2 > + bne .Loverride_cobalt100_\@ > + ldr x0, =0x410FD490 > +.Loverride_cobalt100_\@: > msr vpidr_el2, x0 > msr vmpidr_el2, x1 > .endm > diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c > index 30253bd19917..8ea9c7fdabdb 100644 > --- a/arch/arm64/kvm/sys_regs.c > +++ b/arch/arm64/kvm/sys_regs.c > @@ -3574,7 +3574,14 @@ id_to_sys_reg_desc(struct kvm_vcpu *vcpu, u64 id, > return ((struct sys_reg_desc *)r)->val; \ > } > > -FUNCTION_INVARIANT(midr_el1) > +static u64 get_midr_el1(struct kvm_vcpu *v, const struct sys_reg_desc *r) > +{ > + ((struct sys_reg_desc *)r)->val = read_sysreg(midr_el1); > + if (((struct sys_reg_desc *)r)->val == 0x6D0FD490) > + ((struct sys_reg_desc *)r)->val == 0x410FD490; > + return ((struct sys_reg_desc *)r)->val; > +} > + > FUNCTION_INVARIANT(revidr_el1) > FUNCTION_INVARIANT(aidr_el1) >
On Tue, Feb 06, 2024 at 07:58:16PM +0000, Easwar Hariharan wrote: > Several workload optimizations and errata depend on validating that the > optimization or errata are applicable to the particular CPU by checking > the MIDR_EL1 system register value. With the Microsoft implementer ID > for Azure Cobalt 100, the value doesn't match and ~20-25% performance > regression is seen in these workloads. Override the Azure Cobalt 100 > value and replace it with the default ARM Neoverse N2 value that Azure > Cobalt 100 is based on. NAK to rewriting the MIDR in the kernel; we do not lie to userspace about the MIDR, and this is not a can of worms we're going to open. If you desire some microarchitectural performance optimizations in particular projects, please submit patches to those projects to understand your MIDR value. Further, if Azure Cobalt 100 is based on ARM Neoverse N2, you presumably suffer from the same errata; can you comment on that at all? e.g. are there any changes in this part that *might* lead to differences in errata and/or workarounds? How do the MIDR_EL1.{Variant,Revision} values compare to that of Neoverse N2? Mark. > Signed-off-by: Easwar Hariharan <eahariha@linux.microsoft.com> > --- > arch/arm64/include/asm/cputype.h | 3 ++- > arch/arm64/include/asm/el2_setup.h | 5 +++++ > arch/arm64/kvm/sys_regs.c | 9 ++++++++- > 3 files changed, 15 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/include/asm/cputype.h b/arch/arm64/include/asm/cputype.h > index 7c7493cb571f..0450c6c32377 100644 > --- a/arch/arm64/include/asm/cputype.h > +++ b/arch/arm64/include/asm/cputype.h > @@ -262,7 +262,8 @@ is_midr_in_range_list(u32 midr, struct midr_range const *ranges) > */ > static inline u32 __attribute_const__ read_cpuid_id(void) > { > - return read_cpuid(MIDR_EL1); > + return (read_cpuid(MIDR_EL1) == 0x6D0FD490 ? 0x410FD490 : > + read_cpuid(MIDR_EL1)); > } > > static inline u64 __attribute_const__ read_cpuid_mpidr(void) > diff --git a/arch/arm64/include/asm/el2_setup.h b/arch/arm64/include/asm/el2_setup.h > index b7afaa026842..502a14e54a31 100644 > --- a/arch/arm64/include/asm/el2_setup.h > +++ b/arch/arm64/include/asm/el2_setup.h > @@ -138,6 +138,11 @@ > .macro __init_el2_nvhe_idregs > mrs x0, midr_el1 > mrs x1, mpidr_el1 > + ldr x2, =0x6D0FD490 > + cmp x0, x2 > + bne .Loverride_cobalt100_\@ > + ldr x0, =0x410FD490 > +.Loverride_cobalt100_\@: > msr vpidr_el2, x0 > msr vmpidr_el2, x1 > .endm > diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c > index 30253bd19917..8ea9c7fdabdb 100644 > --- a/arch/arm64/kvm/sys_regs.c > +++ b/arch/arm64/kvm/sys_regs.c > @@ -3574,7 +3574,14 @@ id_to_sys_reg_desc(struct kvm_vcpu *vcpu, u64 id, > return ((struct sys_reg_desc *)r)->val; \ > } > > -FUNCTION_INVARIANT(midr_el1) > +static u64 get_midr_el1(struct kvm_vcpu *v, const struct sys_reg_desc *r) > +{ > + ((struct sys_reg_desc *)r)->val = read_sysreg(midr_el1); > + if (((struct sys_reg_desc *)r)->val == 0x6D0FD490) > + ((struct sys_reg_desc *)r)->val == 0x410FD490; > + return ((struct sys_reg_desc *)r)->val; > +} > + > FUNCTION_INVARIANT(revidr_el1) > FUNCTION_INVARIANT(aidr_el1) > > -- > 2.34.1 > >
On Tue, 06 Feb 2024 19:58:16 +0000, Easwar Hariharan <eahariha@linux.microsoft.com> wrote: > > Several workload optimizations and errata depend on validating that the > optimization or errata are applicable to the particular CPU by checking > the MIDR_EL1 system register value. With the Microsoft implementer ID > for Azure Cobalt 100, the value doesn't match and ~20-25% performance > regression is seen in these workloads. Override the Azure Cobalt 100 > value and replace it with the default ARM Neoverse N2 value that Azure > Cobalt 100 is based on. Since you don't disclose *why* this particular value should have any impact on the behaviour of the kernel, the answer should be "Thanks, but no, thanks". Whatever the reason is for doing so, you should make it plain what you are working around. Blindly overriding ID registers is not an option, and you should simply add your MIDR value to whatever errata list that actually matches your implementation. > > Signed-off-by: Easwar Hariharan <eahariha@linux.microsoft.com> > --- > arch/arm64/include/asm/cputype.h | 3 ++- > arch/arm64/include/asm/el2_setup.h | 5 +++++ > arch/arm64/kvm/sys_regs.c | 9 ++++++++- > 3 files changed, 15 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/include/asm/cputype.h b/arch/arm64/include/asm/cputype.h > index 7c7493cb571f..0450c6c32377 100644 > --- a/arch/arm64/include/asm/cputype.h > +++ b/arch/arm64/include/asm/cputype.h > @@ -262,7 +262,8 @@ is_midr_in_range_list(u32 midr, struct midr_range const *ranges) > */ > static inline u32 __attribute_const__ read_cpuid_id(void) > { > - return read_cpuid(MIDR_EL1); > + return (read_cpuid(MIDR_EL1) == 0x6D0FD490 ? 0x410FD490 : > + read_cpuid(MIDR_EL1)); > } > > static inline u64 __attribute_const__ read_cpuid_mpidr(void) > diff --git a/arch/arm64/include/asm/el2_setup.h b/arch/arm64/include/asm/el2_setup.h > index b7afaa026842..502a14e54a31 100644 > --- a/arch/arm64/include/asm/el2_setup.h > +++ b/arch/arm64/include/asm/el2_setup.h > @@ -138,6 +138,11 @@ > .macro __init_el2_nvhe_idregs > mrs x0, midr_el1 > mrs x1, mpidr_el1 > + ldr x2, =0x6D0FD490 > + cmp x0, x2 > + bne .Loverride_cobalt100_\@ > + ldr x0, =0x410FD490 > +.Loverride_cobalt100_\@: > msr vpidr_el2, x0 > msr vmpidr_el2, x1 > .endm > diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c > index 30253bd19917..8ea9c7fdabdb 100644 > --- a/arch/arm64/kvm/sys_regs.c > +++ b/arch/arm64/kvm/sys_regs.c > @@ -3574,7 +3574,14 @@ id_to_sys_reg_desc(struct kvm_vcpu *vcpu, u64 id, > return ((struct sys_reg_desc *)r)->val; \ > } > > -FUNCTION_INVARIANT(midr_el1) > +static u64 get_midr_el1(struct kvm_vcpu *v, const struct sys_reg_desc *r) > +{ > + ((struct sys_reg_desc *)r)->val = read_sysreg(midr_el1); > + if (((struct sys_reg_desc *)r)->val == 0x6D0FD490) > + ((struct sys_reg_desc *)r)->val == 0x410FD490; As pointed out to me by Joey, this line is really interesting, and shows that you didn't really test this patch. Thanks, M.
On 2/7/2024 1:50 AM, Marc Zyngier wrote: > On Tue, 06 Feb 2024 19:58:16 +0000, > Easwar Hariharan <eahariha@linux.microsoft.com> wrote: >> >> Several workload optimizations and errata depend on validating that the >> optimization or errata are applicable to the particular CPU by checking >> the MIDR_EL1 system register value. With the Microsoft implementer ID >> for Azure Cobalt 100, the value doesn't match and ~20-25% performance >> regression is seen in these workloads. Override the Azure Cobalt 100 >> value and replace it with the default ARM Neoverse N2 value that Azure >> Cobalt 100 is based on. > > Since you don't disclose *why* this particular value should have any > impact on the behaviour of the kernel, the answer should be "Thanks, > but no, thanks". > The optimizations mentioned in the commit message reside in userspace and depend on the MIDR value exposed to userspace by the kernel. As mentioned in my response to Anshuman, this patch was a proof of concept to have userspace apply the Neoverse N2 optimizations to Azure Cobalt 100 as well. > Whatever the reason is for doing so, you should make it plain what you > are working around. Blindly overriding ID registers is not an option, > and you should simply add your MIDR value to whatever errata list that > actually matches your implementation. > Thank you, I will do that. >> >> Signed-off-by: Easwar Hariharan <eahariha@linux.microsoft.com> >> --- >> arch/arm64/include/asm/cputype.h | 3 ++- >> arch/arm64/include/asm/el2_setup.h | 5 +++++ >> arch/arm64/kvm/sys_regs.c | 9 ++++++++- >> 3 files changed, 15 insertions(+), 2 deletions(-) >> >> diff --git a/arch/arm64/include/asm/cputype.h b/arch/arm64/include/asm/cputype.h >> index 7c7493cb571f..0450c6c32377 100644 >> --- a/arch/arm64/include/asm/cputype.h >> +++ b/arch/arm64/include/asm/cputype.h >> @@ -262,7 +262,8 @@ is_midr_in_range_list(u32 midr, struct midr_range const *ranges) >> */ >> static inline u32 __attribute_const__ read_cpuid_id(void) >> { >> - return read_cpuid(MIDR_EL1); >> + return (read_cpuid(MIDR_EL1) == 0x6D0FD490 ? 0x410FD490 : >> + read_cpuid(MIDR_EL1)); >> } >> >> static inline u64 __attribute_const__ read_cpuid_mpidr(void) >> diff --git a/arch/arm64/include/asm/el2_setup.h b/arch/arm64/include/asm/el2_setup.h >> index b7afaa026842..502a14e54a31 100644 >> --- a/arch/arm64/include/asm/el2_setup.h >> +++ b/arch/arm64/include/asm/el2_setup.h >> @@ -138,6 +138,11 @@ >> .macro __init_el2_nvhe_idregs >> mrs x0, midr_el1 >> mrs x1, mpidr_el1 >> + ldr x2, =0x6D0FD490 >> + cmp x0, x2 >> + bne .Loverride_cobalt100_\@ >> + ldr x0, =0x410FD490 >> +.Loverride_cobalt100_\@: >> msr vpidr_el2, x0 >> msr vmpidr_el2, x1 >> .endm >> diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c >> index 30253bd19917..8ea9c7fdabdb 100644 >> --- a/arch/arm64/kvm/sys_regs.c >> +++ b/arch/arm64/kvm/sys_regs.c >> @@ -3574,7 +3574,14 @@ id_to_sys_reg_desc(struct kvm_vcpu *vcpu, u64 id, >> return ((struct sys_reg_desc *)r)->val; \ >> } >> >> -FUNCTION_INVARIANT(midr_el1) >> +static u64 get_midr_el1(struct kvm_vcpu *v, const struct sys_reg_desc *r) >> +{ >> + ((struct sys_reg_desc *)r)->val = read_sysreg(midr_el1); >> + if (((struct sys_reg_desc *)r)->val == 0x6D0FD490) >> + ((struct sys_reg_desc *)r)->val == 0x410FD490; > > As pointed out to me by Joey, this line is really interesting, and > shows that you didn't really test this patch. > That has clearly escaped my notice, but we did test the patch and validate that the Neoverse N2 MIDR value showed up where we looked. Being new to arch/arm64, it's very possible that I may have modified this hunk without needing to. > Thanks, > > M. >
On 2/7/2024 1:49 AM, Mark Rutland wrote: > On Tue, Feb 06, 2024 at 07:58:16PM +0000, Easwar Hariharan wrote: >> Several workload optimizations and errata depend on validating that the >> optimization or errata are applicable to the particular CPU by checking >> the MIDR_EL1 system register value. With the Microsoft implementer ID >> for Azure Cobalt 100, the value doesn't match and ~20-25% performance >> regression is seen in these workloads. Override the Azure Cobalt 100 >> value and replace it with the default ARM Neoverse N2 value that Azure >> Cobalt 100 is based on. > > NAK to rewriting the MIDR in the kernel; we do not lie to userspace about the > MIDR, and this is not a can of worms we're going to open. > > If you desire some microarchitectural performance optimizations in particular > projects, please submit patches to those projects to understand your MIDR > value. Understood. > > Further, if Azure Cobalt 100 is based on ARM Neoverse N2, you presumably suffer > from the same errata; can you comment on that at all? e.g. are there any > changes in this part that *might* lead to differences in errata and/or > workarounds? How do the MIDR_EL1.{Variant,Revision} values compare to that of > Neoverse N2? > Yes, Azure Cobalt 100 suffers from the same errata as Neoverse N2. We had changes in the implementation, but according to our hardware folks, the Neoverse N2 errata we are affected by so far aren't affected by the changes made for Azure Cobalt 100. > Mark. > >> Signed-off-by: Easwar Hariharan <eahariha@linux.microsoft.com> >> --- >> arch/arm64/include/asm/cputype.h | 3 ++- >> arch/arm64/include/asm/el2_setup.h | 5 +++++ >> arch/arm64/kvm/sys_regs.c | 9 ++++++++- >> 3 files changed, 15 insertions(+), 2 deletions(-) >> >> diff --git a/arch/arm64/include/asm/cputype.h b/arch/arm64/include/asm/cputype.h >> index 7c7493cb571f..0450c6c32377 100644 >> --- a/arch/arm64/include/asm/cputype.h >> +++ b/arch/arm64/include/asm/cputype.h >> @@ -262,7 +262,8 @@ is_midr_in_range_list(u32 midr, struct midr_range const *ranges) >> */ >> static inline u32 __attribute_const__ read_cpuid_id(void) >> { >> - return read_cpuid(MIDR_EL1); >> + return (read_cpuid(MIDR_EL1) == 0x6D0FD490 ? 0x410FD490 : >> + read_cpuid(MIDR_EL1)); >> } >> >> static inline u64 __attribute_const__ read_cpuid_mpidr(void) >> diff --git a/arch/arm64/include/asm/el2_setup.h b/arch/arm64/include/asm/el2_setup.h >> index b7afaa026842..502a14e54a31 100644 >> --- a/arch/arm64/include/asm/el2_setup.h >> +++ b/arch/arm64/include/asm/el2_setup.h >> @@ -138,6 +138,11 @@ >> .macro __init_el2_nvhe_idregs >> mrs x0, midr_el1 >> mrs x1, mpidr_el1 >> + ldr x2, =0x6D0FD490 >> + cmp x0, x2 >> + bne .Loverride_cobalt100_\@ >> + ldr x0, =0x410FD490 >> +.Loverride_cobalt100_\@: >> msr vpidr_el2, x0 >> msr vmpidr_el2, x1 >> .endm >> diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c >> index 30253bd19917..8ea9c7fdabdb 100644 >> --- a/arch/arm64/kvm/sys_regs.c >> +++ b/arch/arm64/kvm/sys_regs.c >> @@ -3574,7 +3574,14 @@ id_to_sys_reg_desc(struct kvm_vcpu *vcpu, u64 id, >> return ((struct sys_reg_desc *)r)->val; \ >> } >> >> -FUNCTION_INVARIANT(midr_el1) >> +static u64 get_midr_el1(struct kvm_vcpu *v, const struct sys_reg_desc *r) >> +{ >> + ((struct sys_reg_desc *)r)->val = read_sysreg(midr_el1); >> + if (((struct sys_reg_desc *)r)->val == 0x6D0FD490) >> + ((struct sys_reg_desc *)r)->val == 0x410FD490; >> + return ((struct sys_reg_desc *)r)->val; >> +} >> + >> FUNCTION_INVARIANT(revidr_el1) >> FUNCTION_INVARIANT(aidr_el1) >> >> -- >> 2.34.1 >> >>
On 2/6/2024 11:54 PM, Anshuman Khandual wrote: > > On 2/7/24 01:28, Easwar Hariharan wrote: >> Several workload optimizations and errata depend on validating that the >> optimization or errata are applicable to the particular CPU by checking >> the MIDR_EL1 system register value. With the Microsoft implementer ID > > Which is how it should be done. > >> for Azure Cobalt 100, the value doesn't match and ~20-25% performance >> regression is seen in these workloads. Override the Azure Cobalt 100 >> value and replace it with the default ARM Neoverse N2 value that Azure >> Cobalt 100 is based on. > > Why cannot these MIDR values be classified as required and subscribed to > the existing erratas that is affecting such implementations. Hence these > work arounds will be triggered as and when applicable. Why then override > MIDR value instead ? > Thanks for the feedback, I will go ahead and add the Azure Cobalt 100 MIDR value to the range of MIDRs affected by the Neoverse N2 errata. This patch was a proof of concept to have userspace apply the Neoverse N2 optimizations to Azure Cobalt 100 as well. As Mark mentioned in a sibling response, this is not an acceptable way to accomplish this. >> >> Signed-off-by: Easwar Hariharan <eahariha@linux.microsoft.com> >> --- >> arch/arm64/include/asm/cputype.h | 3 ++- >> arch/arm64/include/asm/el2_setup.h | 5 +++++ >> arch/arm64/kvm/sys_regs.c | 9 ++++++++- >> 3 files changed, 15 insertions(+), 2 deletions(-) >> >> diff --git a/arch/arm64/include/asm/cputype.h b/arch/arm64/include/asm/cputype.h >> index 7c7493cb571f..0450c6c32377 100644 >> --- a/arch/arm64/include/asm/cputype.h >> +++ b/arch/arm64/include/asm/cputype.h >> @@ -262,7 +262,8 @@ is_midr_in_range_list(u32 midr, struct midr_range const *ranges) >> */ >> static inline u32 __attribute_const__ read_cpuid_id(void) >> { >> - return read_cpuid(MIDR_EL1); >> + return (read_cpuid(MIDR_EL1) == 0x6D0FD490 ? 0x410FD490 : >> + read_cpuid(MIDR_EL1)); >> } >> >> static inline u64 __attribute_const__ read_cpuid_mpidr(void) >> diff --git a/arch/arm64/include/asm/el2_setup.h b/arch/arm64/include/asm/el2_setup.h >> index b7afaa026842..502a14e54a31 100644 >> --- a/arch/arm64/include/asm/el2_setup.h >> +++ b/arch/arm64/include/asm/el2_setup.h >> @@ -138,6 +138,11 @@ >> .macro __init_el2_nvhe_idregs >> mrs x0, midr_el1 >> mrs x1, mpidr_el1 >> + ldr x2, =0x6D0FD490 >> + cmp x0, x2 >> + bne .Loverride_cobalt100_\@ >> + ldr x0, =0x410FD490 >> +.Loverride_cobalt100_\@: >> msr vpidr_el2, x0 >> msr vmpidr_el2, x1 >> .endm >> diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c >> index 30253bd19917..8ea9c7fdabdb 100644 >> --- a/arch/arm64/kvm/sys_regs.c >> +++ b/arch/arm64/kvm/sys_regs.c >> @@ -3574,7 +3574,14 @@ id_to_sys_reg_desc(struct kvm_vcpu *vcpu, u64 id, >> return ((struct sys_reg_desc *)r)->val; \ >> } >> >> -FUNCTION_INVARIANT(midr_el1) >> +static u64 get_midr_el1(struct kvm_vcpu *v, const struct sys_reg_desc *r) >> +{ >> + ((struct sys_reg_desc *)r)->val = read_sysreg(midr_el1); >> + if (((struct sys_reg_desc *)r)->val == 0x6D0FD490) >> + ((struct sys_reg_desc *)r)->val == 0x410FD490; >> + return ((struct sys_reg_desc *)r)->val; >> +} >> + >> FUNCTION_INVARIANT(revidr_el1) >> FUNCTION_INVARIANT(aidr_el1) >>
On Thu, Feb 08, 2024 at 11:16:10AM -0800, Easwar Hariharan wrote: > On 2/7/2024 1:49 AM, Mark Rutland wrote: > > On Tue, Feb 06, 2024 at 07:58:16PM +0000, Easwar Hariharan wrote: > > Further, if Azure Cobalt 100 is based on ARM Neoverse N2, you presumably suffer > > from the same errata; can you comment on that at all? e.g. are there any > > changes in this part that *might* lead to differences in errata and/or > > workarounds? How do the MIDR_EL1.{Variant,Revision} values compare to that of > > Neoverse N2? > > Yes, Azure Cobalt 100 suffers from the same errata as Neoverse N2. We had changes > in the implementation, but according to our hardware folks, the Neoverse N2 errata > we are affected by so far aren't affected by the changes made for Azure Cobalt 100. Ok, so of the currently-known-and-mitigated errata, you'll be affected by: ARM64_ERRATUM_2139208 ARM64_ERRATUM_2067961 ARM64_ERRATUM_2253138 .. and we'll need to extend the midr_range lists for those errata to cover Azure Cobalt 100. From your patch, it looks like the Azure Cobalt 100 MIDR value (0x6D0FD490) is the same as the Arm Neoverse-N2 r0p0 MIDR value (0x410FD490), except the 'Implementer' field is 0x6D ('m' in ASCII) rather than 0x41 ('A' in ASCII). Are you happy to send a patch extending arch/arm64/include/asm/cputype.h with the relevant ARM_CPU_IMP_* and CPU_PART_* definitions, and use those to extend the midr_range lists for those errata? As above, if you could make any comment on how the MIDR_EL1.{Variant,Revision} fields map to that of Arm Neoverse-N2, it would be very helpful. It's not clear to me whether those fields correspond directly (and so this part is based on r0p0), or whether you have a different scheme for revision numbers. That'll matter for correctly matching any future errata and/or future revisions of Azure Cobalt 100. Mark.
On 2/9/2024 3:33 AM, Mark Rutland wrote: > On Thu, Feb 08, 2024 at 11:16:10AM -0800, Easwar Hariharan wrote: >> On 2/7/2024 1:49 AM, Mark Rutland wrote: >>> On Tue, Feb 06, 2024 at 07:58:16PM +0000, Easwar Hariharan wrote: >>> Further, if Azure Cobalt 100 is based on ARM Neoverse N2, you presumably suffer >>> from the same errata; can you comment on that at all? e.g. are there any >>> changes in this part that *might* lead to differences in errata and/or >>> workarounds? How do the MIDR_EL1.{Variant,Revision} values compare to that of >>> Neoverse N2? >> >> Yes, Azure Cobalt 100 suffers from the same errata as Neoverse N2. We had changes >> in the implementation, but according to our hardware folks, the Neoverse N2 errata >> we are affected by so far aren't affected by the changes made for Azure Cobalt 100. > > Ok, so of the currently-known-and-mitigated errata, you'll be affected by: > > ARM64_ERRATUM_2139208 > ARM64_ERRATUM_2067961 > ARM64_ERRATUM_2253138 > > ... and we'll need to extend the midr_range lists for those errata to cover > Azure Cobalt 100. > >>From your patch, it looks like the Azure Cobalt 100 MIDR value (0x6D0FD490) is > the same as the Arm Neoverse-N2 r0p0 MIDR value (0x410FD490), except the > 'Implementer' field is 0x6D ('m' in ASCII) rather than 0x41 ('A' in ASCII). > > Are you happy to send a patch extending arch/arm64/include/asm/cputype.h with > the relevant ARM_CPU_IMP_* and CPU_PART_* definitions, and use those to extend > the midr_range lists for those errata? Yes. > > As above, if you could make any comment on how the MIDR_EL1.{Variant,Revision} > fields map to that of Arm Neoverse-N2, it would be very helpful. It's not clear > to me whether those fields correspond directly (and so this part is based on > r0p0), or whether you have a different scheme for revision numbers. That'll > matter for correctly matching any future errata and/or future revisions of > Azure Cobalt 100. > Thanks for the clarifying detail on your question. Azure Cobalt 100 is indeed based on r0p0 of the Neoverse N-2 and we have not used a different scheme than Neoverse N2 for the Variant and Revision fields. > Mark. > > _______________________________________________ > linux-arm-kernel mailing list > linux-arm-kernel@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
diff --git a/arch/arm64/include/asm/cputype.h b/arch/arm64/include/asm/cputype.h index 7c7493cb571f..0450c6c32377 100644 --- a/arch/arm64/include/asm/cputype.h +++ b/arch/arm64/include/asm/cputype.h @@ -262,7 +262,8 @@ is_midr_in_range_list(u32 midr, struct midr_range const *ranges) */ static inline u32 __attribute_const__ read_cpuid_id(void) { - return read_cpuid(MIDR_EL1); + return (read_cpuid(MIDR_EL1) == 0x6D0FD490 ? 0x410FD490 : + read_cpuid(MIDR_EL1)); } static inline u64 __attribute_const__ read_cpuid_mpidr(void) diff --git a/arch/arm64/include/asm/el2_setup.h b/arch/arm64/include/asm/el2_setup.h index b7afaa026842..502a14e54a31 100644 --- a/arch/arm64/include/asm/el2_setup.h +++ b/arch/arm64/include/asm/el2_setup.h @@ -138,6 +138,11 @@ .macro __init_el2_nvhe_idregs mrs x0, midr_el1 mrs x1, mpidr_el1 + ldr x2, =0x6D0FD490 + cmp x0, x2 + bne .Loverride_cobalt100_\@ + ldr x0, =0x410FD490 +.Loverride_cobalt100_\@: msr vpidr_el2, x0 msr vmpidr_el2, x1 .endm diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 30253bd19917..8ea9c7fdabdb 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -3574,7 +3574,14 @@ id_to_sys_reg_desc(struct kvm_vcpu *vcpu, u64 id, return ((struct sys_reg_desc *)r)->val; \ } -FUNCTION_INVARIANT(midr_el1) +static u64 get_midr_el1(struct kvm_vcpu *v, const struct sys_reg_desc *r) +{ + ((struct sys_reg_desc *)r)->val = read_sysreg(midr_el1); + if (((struct sys_reg_desc *)r)->val == 0x6D0FD490) + ((struct sys_reg_desc *)r)->val == 0x410FD490; + return ((struct sys_reg_desc *)r)->val; +} + FUNCTION_INVARIANT(revidr_el1) FUNCTION_INVARIANT(aidr_el1)