From patchwork Thu Mar 30 16:51:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 13194606 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9621DC6FD1D for ; Thu, 30 Mar 2023 16:53:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Dx6Ik5AngRP4QLTvPdAG3VH/+19J722vgJJb7bnT9xA=; b=hsuRjm+bOiKfsJ AMs27vRLkVBySrskZJcgunlbCG0A4403x2m5sKesHnyUWyBTRUG78AtBkOspB3s1TpDBWpdhigPC9 IHYVm91QNXjTLSdqAGEfk2sEeFQw2rRSXE671leGWDQumoZ2/hkDoh0Dplzboyzdo+30C+uFb9M3U Y5C5UZK7VcuLab9RxmPue9GUK+Jk2Ch7nhVb1qALTpFcbUwhycPiE0x4v3e9AbsceMtF1btYtMl/q C1eAlOaFoFPgHtwZuMzk9wVEizUixVrlfy51Xi03yr39ZQcXnk8TbUPGzVR+iuxZZgXSKsovY3VLA 6X8SD0b6ffjrTttIjdPg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1phvWD-004XTS-2f; Thu, 30 Mar 2023 16:52:57 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1phvWA-004XSC-27 for linux-arm-kernel@lists.infradead.org; Thu, 30 Mar 2023 16:52:56 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E56302F4; Thu, 30 Mar 2023 09:53:36 -0700 (PDT) Received: from eglon.cambridge.arm.com (eglon.cambridge.arm.com [10.1.196.177]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id ED3C93F6C4; Thu, 30 Mar 2023 09:52:50 -0700 (PDT) From: James Morse To: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org Cc: Catalin Marinas , Will Deacon , Mark Rutland , Lorenzo Pieralisi , Sudeep Holla , Marc Zyngier , Oliver Upton , James Morse , Rob Herring , Krzysztof Kozlowski , Andre Przywara Subject: [PATCH 1/6] dt-bindings: firmware: Add arm,errata-management Date: Thu, 30 Mar 2023 17:51:23 +0100 Message-Id: <20230330165128.3237939-2-james.morse@arm.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330165128.3237939-1-james.morse@arm.com> References: <20230330165128.3237939-1-james.morse@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230330_095254_791100_1D6F9472 X-CRM114-Status: GOOD ( 22.50 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The Errata Management SMCCC interface allows firmware to advertise whether the OS is affected by an erratum, or if a higher exception level has mitigated the issue. This allows properties of the device that are not discoverable by the OS to be described. e.g. some errata depend on the behaviour of the interconnect, which is not visible to the OS. Deployed devices may find it significantly harder to update EL3 firmware than the device tree. Erratum workarounds typically have to fail safe, and assume the platform is affected putting correctness above performance. Instead of adding a device-tree entry for any CPU errata that is relevant (or not) to the platform, allow the device-tree to describe firmware's responses for the SMCCC interface. This could be used as the data source for the firmware interface, or be parsed by the OS if the firmware interface is missing. Most errata can be detected from CPU id registers. These mechanisms are only needed for the rare cases that external knowledge is needed. Suggested-by: Andre Przywara Signed-off-by: James Morse --- .../devicetree/bindings/arm/cpus.yaml | 5 ++ .../firmware/arm,errata-management.yaml | 77 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 Documentation/devicetree/bindings/firmware/arm,errata-management.yaml diff --git a/Documentation/devicetree/bindings/arm/cpus.yaml b/Documentation/devicetree/bindings/arm/cpus.yaml index c145f6a035ee..47b12761f305 100644 --- a/Documentation/devicetree/bindings/arm/cpus.yaml +++ b/Documentation/devicetree/bindings/arm/cpus.yaml @@ -257,6 +257,11 @@ properties: List of phandles to idle state nodes supported by this cpu (see ./idle-states.yaml). + arm,erratum-list: + $ref: '/schemas/types.yaml#/definitions/phandle' + description: + Specifies the firmware cpu-erratum-list node associated with this CPU. + capacity-dmips-mhz: description: u32 value representing CPU capacity (see ../cpu/cpu-capacity.txt) in diff --git a/Documentation/devicetree/bindings/firmware/arm,errata-management.yaml b/Documentation/devicetree/bindings/firmware/arm,errata-management.yaml new file mode 100644 index 000000000000..9baeb3d35213 --- /dev/null +++ b/Documentation/devicetree/bindings/firmware/arm,errata-management.yaml @@ -0,0 +1,77 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/firmware/arm,errata-management.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Errata Management Firmware Interface + +maintainers: + - James Morse + +description: |+ + The SMC-CC has an erratum discovery interface that allows the OS to discover + whether a particular CPU is affected by a specific erratum when the + configurations affected is only known by firmware. See the specification of + the same title on developer.arm.com, document DEN0100. + Provide the values that should be used by the interface, either to supplement + firmware, or override the values firmware provides. + Most errata can be detected from CPU id registers. These mechanisms are only + needed for the rare cases that external knowledge is needed. + The CPU node should hold a phandle that points to the cpu-erratum-list node. + +properties: + compatible: + items: + - const: arm,cpu-erratum-list + + arm,erratum-affected: + description: Erratum numbers that this CPU is affected by. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 1 + + arm,erratum-not-affected: + description: Erratum numbers that this CPU is not affected by. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 1 + + arm,erratum-higher-el-mitigation: + description: Erratum numbers that have been mitigated by a higher level + of firmware + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 1 + +required: + - compatible +anyOf: + - required: + - 'arm,erratum-affected' + - required: + - 'arm,erratum-not-affected' + - required: + - 'arm,erratum-higher-el-mitigation' + +additionalProperties: false + +examples: + - | + firmware { + CL1_ERRATA: cluster1-errata { + compatible = "arm,cpu-erratum-list"; + arm,erratum-not-affected = <2701952>; + }; + }; + + cpus { + #size-cells = <0>; + #address-cells = <1>; + + cpu@0 { + device_type = "cpu"; + compatible = "arm,cortex-x2"; + reg = <0x0>; + arm,erratum-list = <&CL1_ERRATA>; + }; + }; + +... From patchwork Thu Mar 30 16:51:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 13194610 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9B2ECC77B60 for ; Thu, 30 Mar 2023 16:53:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=c8W1t/15w2boFKmyztkLQaPrXJ8aZPhpQttXoIuTAyw=; b=ijyv4P5WtYCIlU 293vkPwEJuRquzlXtof6LMf2GjQDOiBfFYzjb5x/4kOYXsD4H2Q4OL8KK3KEEewf8hRcpp46lsznk RiIOfQ5HwlEbZpdHaIzS7E/ULP0+T0y94wYR4mz5QJunel7KvtSJlgSvCqLM9W/e79GrreV60Fawc 8RCemy9BvHu96kboVNR4qEk9RBHcWwn7PIS/mn3ECj3PLvXRGcxo2m4p55rCiASCSEZQalTyB/txr iB3J4kdjlYX4MmTQMt7k6OteIx2qhTF2xOITJJtakZ9iD0Ee8jBftcp8dF+45hjZG0zKHMUjhYKi/ aHcXICAOXZREX11eHMfA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1phvWO-004XXc-0Q; Thu, 30 Mar 2023 16:53:08 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1phvWD-004XSv-0r for linux-arm-kernel@lists.infradead.org; Thu, 30 Mar 2023 16:52:59 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A86FA1650; Thu, 30 Mar 2023 09:53:38 -0700 (PDT) Received: from eglon.cambridge.arm.com (eglon.cambridge.arm.com [10.1.196.177]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CC0C43F6C4; Thu, 30 Mar 2023 09:52:52 -0700 (PDT) From: James Morse To: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org Cc: Catalin Marinas , Will Deacon , Mark Rutland , Lorenzo Pieralisi , Sudeep Holla , Marc Zyngier , Oliver Upton , James Morse , Rob Herring , Krzysztof Kozlowski Subject: [PATCH 2/6] firmware: smccc: Add support for erratum discovery API Date: Thu, 30 Mar 2023 17:51:24 +0100 Message-Id: <20230330165128.3237939-3-james.morse@arm.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330165128.3237939-1-james.morse@arm.com> References: <20230330165128.3237939-1-james.morse@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230330_095257_398837_E88151EA X-CRM114-Status: GOOD ( 23.09 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org It is not always possible for the OS to determine if a CPU is affected by a particular erratum. For example, it may depend on an integration choice the chip designer made, or whether firmware has enabled some particular feature. Add support for the SMCCC 'Errata Management Firmware Interface' that lets the OS query firmware for this information. Link: https://developer.arm.com/documentation/den0100/1-0/?lang=en Signed-off-by: James Morse --- arch/arm64/kernel/cpufeature.c | 7 +++ drivers/firmware/smccc/Kconfig | 8 ++++ drivers/firmware/smccc/Makefile | 1 + drivers/firmware/smccc/em.c | 78 +++++++++++++++++++++++++++++++++ include/linux/arm-smccc.h | 28 ++++++++++++ include/linux/arm_smccc_em.h | 11 +++++ 6 files changed, 133 insertions(+) create mode 100644 drivers/firmware/smccc/em.c create mode 100644 include/linux/arm_smccc_em.h diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 2e3e55139777..62f996006783 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -62,6 +62,7 @@ #define pr_fmt(fmt) "CPU features: " fmt +#include #include #include #include @@ -1047,6 +1048,12 @@ void __init init_cpu_features(struct cpuinfo_arm64 *info) */ init_cpu_hwcaps_indirect_list(); + /* + * Early erratum workaround may need to be discovered from firmware. + */ + if (IS_ENABLED(CONFIG_ARM_SMCCC_EM)) + arm_smccc_em_init(); + /* * Detect and enable early CPU capabilities based on the boot CPU, * after we have initialised the CPU feature infrastructure. diff --git a/drivers/firmware/smccc/Kconfig b/drivers/firmware/smccc/Kconfig index 15e7466179a6..a10a150d49bb 100644 --- a/drivers/firmware/smccc/Kconfig +++ b/drivers/firmware/smccc/Kconfig @@ -23,3 +23,11 @@ config ARM_SMCCC_SOC_ID help Include support for the SoC bus on the ARM SMCCC firmware based platforms providing some sysfs information about the SoC variant. + +config ARM_SMCCC_EM + bool "Errata discovery by ARM SMCCC" + depends on HAVE_ARM_SMCCC_DISCOVERY + default y + help + Include support for querying firmware via SMCCC to determine whether + the CPU is affected by a specific erratum. diff --git a/drivers/firmware/smccc/Makefile b/drivers/firmware/smccc/Makefile index 40d19144a860..39ed128b59b5 100644 --- a/drivers/firmware/smccc/Makefile +++ b/drivers/firmware/smccc/Makefile @@ -2,3 +2,4 @@ # obj-$(CONFIG_HAVE_ARM_SMCCC_DISCOVERY) += smccc.o kvm_guest.o obj-$(CONFIG_ARM_SMCCC_SOC_ID) += soc_id.o +obj-$(CONFIG_ARM_SMCCC_EM) += em.o diff --git a/drivers/firmware/smccc/em.c b/drivers/firmware/smccc/em.c new file mode 100644 index 000000000000..2c66240d8707 --- /dev/null +++ b/drivers/firmware/smccc/em.c @@ -0,0 +1,78 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Arm Errata Management firmware interface. + * + * This firmware interface advertises support for firmware mitigations for CPU + * errata. It can also be used to discover erratum where the 'configurations + * affected' depends on the integration. + * + * Copyright (C) 2022 ARM Limited + */ + +#define pr_fmt(fmt) "arm_smccc_em: " fmt + +#include +#include +#include +#include + +#include + +#include + +static u32 supported; + +int arm_smccc_em_cpu_features(u32 erratum_id) +{ + struct arm_smccc_res res; + + if (!READ_ONCE(supported)) + return -EOPNOTSUPP; + + arm_smccc_1_1_invoke(ARM_SMCCC_EM_CPU_ERRATUM_FEATURES, erratum_id, 0, &res); + switch (res.a0) { + case SMCCC_RET_NOT_SUPPORTED: + return -EOPNOTSUPP; + case SMCCC_EM_RET_INVALID_PARAMTER: + return -EINVAL; + case SMCCC_EM_RET_UNKNOWN: + return -ENOENT; + case SMCCC_EM_RET_HIGHER_EL_MITIGATION: + case SMCCC_EM_RET_NOT_AFFECTED: + case SMCCC_EM_RET_AFFECTED: + return res.a0; + }; + + return -EIO; +} + +int __init arm_smccc_em_init(void) +{ + u32 major_ver, minor_ver; + struct arm_smccc_res res; + enum arm_smccc_conduit conduit = arm_smccc_1_1_get_conduit(); + + if (conduit == SMCCC_CONDUIT_NONE) + return -EOPNOTSUPP; + + arm_smccc_1_1_invoke(ARM_SMCCC_EM_VERSION, &res); + if (res.a0 == SMCCC_RET_NOT_SUPPORTED) + return -EOPNOTSUPP; + + major_ver = PSCI_VERSION_MAJOR(res.a0); + minor_ver = PSCI_VERSION_MINOR(res.a0); + if (major_ver != 1) + return -EIO; + + arm_smccc_1_1_invoke(ARM_SMCCC_EM_FEATURES, + ARM_SMCCC_EM_CPU_ERRATUM_FEATURES, &res); + if (res.a0 == SMCCC_RET_NOT_SUPPORTED) + return -EOPNOTSUPP; + + pr_info("SMCCC Errata Management Interface v%d.%d\n", + major_ver, minor_ver); + + WRITE_ONCE(supported, 1); + + return 0; +} diff --git a/include/linux/arm-smccc.h b/include/linux/arm-smccc.h index 220c8c60e021..cc2e38ce8707 100644 --- a/include/linux/arm-smccc.h +++ b/include/linux/arm-smccc.h @@ -182,6 +182,25 @@ ARM_SMCCC_OWNER_STANDARD, \ 0x53) +/* Errata Management calls (defined by ARM DEN0100) */ +#define ARM_SMCCC_EM_VERSION \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_32, \ + ARM_SMCCC_OWNER_STANDARD, \ + 0xF0) + +#define ARM_SMCCC_EM_FEATURES \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_32, \ + ARM_SMCCC_OWNER_STANDARD, \ + 0xF1) + +#define ARM_SMCCC_EM_CPU_ERRATUM_FEATURES \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_32, \ + ARM_SMCCC_OWNER_STANDARD, \ + 0xF2) + /* * Return codes defined in ARM DEN 0070A * ARM DEN 0070A is now merged/consolidated into ARM DEN 0028 C @@ -191,6 +210,15 @@ #define SMCCC_RET_NOT_REQUIRED -2 #define SMCCC_RET_INVALID_PARAMETER -3 +/* + * Return codes defined in ARM DEN 0100 + */ +#define SMCCC_EM_RET_HIGHER_EL_MITIGATION 3 +#define SMCCC_EM_RET_NOT_AFFECTED 2 +#define SMCCC_EM_RET_AFFECTED 1 +#define SMCCC_EM_RET_INVALID_PARAMTER -2 +#define SMCCC_EM_RET_UNKNOWN -3 + #ifndef __ASSEMBLY__ #include diff --git a/include/linux/arm_smccc_em.h b/include/linux/arm_smccc_em.h new file mode 100644 index 000000000000..71293cbbe545 --- /dev/null +++ b/include/linux/arm_smccc_em.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (c) 2023 ARM Limited */ +#ifndef __LINUX_ARM_SMCCC_EM_H +#define __LINUX_ARM_SMCCC_EM_H + +#include + +int arm_smccc_em_init(void); +int arm_smccc_em_cpu_features(u32 erratum_id); + +#endif /* __LINUX_ARM_SMCCC_EM_H */ From patchwork Thu Mar 30 16:51:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 13194607 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B05B2C761A6 for ; Thu, 30 Mar 2023 16:53:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mXv6td47dY//qjb/SojUGh4aqXTzTAF3nV3JrWCdF9s=; b=YIBuVC670PPyim LyewFExQbf2TlpUokTuSQg9addL1VggIsZRWbOmxG73bqzuZy7sTuHpjYqydlvBdNg+Q6RwYXII5a buvJHcHKdlFvlhDaXAAs1Nvgjf7vxyM0idZe9imjWmnPZl7H4O0JtLaRhCOtANR7u1RFkAoSckhsK sS/8UK5XcKBTczO1a+GoE6WHSvR2qbO/K/c70YYV2z0zuJUIrZ9wsgpd0QJuZksjv2dz1JAg2PGyY 9rq9n9fs9RsWlJdgwWPc/aNNuAI0WtYUWW7p3ZCGlf0E087gjDml53byGwcTppO58PLuPeGquJeJU ICVaww+KTlx4YwBhOtCQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1phvWN-004XXC-0S; Thu, 30 Mar 2023 16:53:07 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1phvWC-004XSZ-2a for linux-arm-kernel@lists.infradead.org; Thu, 30 Mar 2023 16:52:58 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6AF3B1682; Thu, 30 Mar 2023 09:53:40 -0700 (PDT) Received: from eglon.cambridge.arm.com (eglon.cambridge.arm.com [10.1.196.177]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8EBF93F6C4; Thu, 30 Mar 2023 09:52:54 -0700 (PDT) From: James Morse To: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org Cc: Catalin Marinas , Will Deacon , Mark Rutland , Lorenzo Pieralisi , Sudeep Holla , Marc Zyngier , Oliver Upton , James Morse , Rob Herring , Krzysztof Kozlowski Subject: [PATCH 3/6] arm64: cputype: Add new part numbers for Cortex-X3, and Neoverse-V2 Date: Thu, 30 Mar 2023 17:51:25 +0100 Message-Id: <20230330165128.3237939-4-james.morse@arm.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330165128.3237939-1-james.morse@arm.com> References: <20230330165128.3237939-1-james.morse@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230330_095256_887870_62198F8E X-CRM114-Status: UNSURE ( 8.26 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org New CPUs have new errata. Add the new partnumbers. Signed-off-by: James Morse --- Cortex-X3: https://developer.arm.com/documentation/101593/0102/?lang=en Neoverse-V2: https://developer.arm.com/documentation/102375/0002/?lang=en --- arch/arm64/include/asm/cputype.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/arm64/include/asm/cputype.h b/arch/arm64/include/asm/cputype.h index 683ca3af4084..1a2c55e172e8 100644 --- a/arch/arm64/include/asm/cputype.h +++ b/arch/arm64/include/asm/cputype.h @@ -84,6 +84,8 @@ #define ARM_CPU_PART_CORTEX_X2 0xD48 #define ARM_CPU_PART_NEOVERSE_N2 0xD49 #define ARM_CPU_PART_CORTEX_A78C 0xD4B +#define ARM_CPU_PART_CORTEX_X3 0xD4E +#define ARM_CPU_PART_NEOVERSE_V2 0xD4F #define APM_CPU_PART_POTENZA 0x000 @@ -149,6 +151,8 @@ #define MIDR_CORTEX_X2 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_X2) #define MIDR_NEOVERSE_N2 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_NEOVERSE_N2) #define MIDR_CORTEX_A78C MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A78C) +#define MIDR_CORTEX_X3 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_X3) +#define MIDR_NEOVERSE_V2 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_NEOVERSE_V2) #define MIDR_THUNDERX MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX) #define MIDR_THUNDERX_81XX MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX_81XX) #define MIDR_THUNDERX_83XX MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX_83XX) From patchwork Thu Mar 30 16:51:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 13194609 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8A2A3C6FD1D for ; Thu, 30 Mar 2023 16:53:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=5GjX8RyoICc3RH64838ELuWtAp/n6OD5h0wukikoGzQ=; b=aH3J5JRdC5jktn stVftNqePlTySseOp+m3SrqMN+fSJLQ8Um4efFzKwZAgSM/RC8iTtX2Df4GUgEPeoiHTjeLGN7D/c d65ksJxEmZioVvcBPhF1pOyR3f+IxUBpnE7bZa3J8JKA/9dzXNa6SNHoEhlgoiFUWE1c689Punyzt uK/EsQoF1BkZq4nDScJdPLRqhuyQT1PlIzNLC1tzUtRxlLb26BXiFcArvIpQyazY50fjNT4MvxNzn Ux571GljIiWJ/ljawMh0dnzM6AEXKIjV//B3cAempyXCoJZ+TQGKEdOBBKwXzYXMi1LILC7vqK/0i u6azLWYth+3dZHO8KY+Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1phvWP-004XY4-0j; Thu, 30 Mar 2023 16:53:09 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1phvWH-004XUk-1c for linux-arm-kernel@lists.infradead.org; Thu, 30 Mar 2023 16:53:03 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4BDB62F4; Thu, 30 Mar 2023 09:53:42 -0700 (PDT) Received: from eglon.cambridge.arm.com (eglon.cambridge.arm.com [10.1.196.177]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 519993F6C4; Thu, 30 Mar 2023 09:52:56 -0700 (PDT) From: James Morse To: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org Cc: Catalin Marinas , Will Deacon , Mark Rutland , Lorenzo Pieralisi , Sudeep Holla , Marc Zyngier , Oliver Upton , James Morse , Rob Herring , Krzysztof Kozlowski Subject: [PATCH 4/6] arm64: errata: Disable FWB on parts with non-ARM interconnects Date: Thu, 30 Mar 2023 17:51:26 +0100 Message-Id: <20230330165128.3237939-5-james.morse@arm.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330165128.3237939-1-james.morse@arm.com> References: <20230330165128.3237939-1-james.morse@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230330_095301_636101_C5464CBA X-CRM114-Status: GOOD ( 29.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Force Write Back (FWB) allows the hypervisor to force non-cacheable accesses made by a guest to be cacheable. This saves the hypervisor from doing cache maintenance on all pages the guest can access, to ensure the guest doesn't see stale (and possibly sensitive) data when making a non-cacheable access. When stage1 translation is disabled, the SCTRL_E1.I bit controls the attributes used for instruction fetch, one of the options results in a non-cacheable access. A whole host of CPUs missed the FWB override in this case, meaning a KVM guest could fetch stale/junk data instead of instructions. The workaround is to always do the cache maintenance. These parts don't have fine-grained-traps, so it isn't feasible to detect the guest disabling the MMU. Instead, disable FWB on the host. While the CPUs are affected, this erratum doesn't occur on parts using Arm's CMN interconnects. Use the Errata Management API to discover whether this CPU is affected. Because guest execution is compromised, the workaround is enabled by default. If the Errata Management API isn't implemented by firmware, the workaround will be enabled. If a target platform is not affected, and it isn't possible to add support for the Errata Management API, the erratum can be disabled in Kconfig. Signed-off-by: James Morse --- This patch causes the additional output: | Stage-2 Force Write-Back disabled due to erratum #2701951 | CPU features: detected: ARM erratum 2701951 --- Documentation/arm64/silicon-errata.rst | 18 ++++++ arch/arm64/Kconfig | 27 ++++++++ arch/arm64/include/asm/cpufeature.h | 1 + arch/arm64/kernel/cpu_errata.c | 86 ++++++++++++++++++++++++++ arch/arm64/kernel/cpufeature.c | 16 ++++- arch/arm64/tools/cpucaps | 1 + 6 files changed, 148 insertions(+), 1 deletion(-) diff --git a/Documentation/arm64/silicon-errata.rst b/Documentation/arm64/silicon-errata.rst index ec5f889d7681..d6ca86ebc7af 100644 --- a/Documentation/arm64/silicon-errata.rst +++ b/Documentation/arm64/silicon-errata.rst @@ -106,6 +106,10 @@ stable kernels. +----------------+-----------------+-----------------+-----------------------------+ | ARM | Cortex-A77 | #1508412 | ARM64_ERRATUM_1508412 | +----------------+-----------------+-----------------+-----------------------------+ +| ARM | Cortex-A78 | #2712571 | ARM64_ERRATUM_2701951 | ++----------------+-----------------+-----------------+-----------------------------+ +| ARM | Cortex-A78C | #2712575,2712572| ARM64_ERRATUM_2701951 | ++----------------+-----------------+-----------------+-----------------------------+ | ARM | Cortex-A510 | #2051678 | ARM64_ERRATUM_2051678 | +----------------+-----------------+-----------------+-----------------------------+ | ARM | Cortex-A510 | #2077057 | ARM64_ERRATUM_2077057 | @@ -120,12 +124,20 @@ stable kernels. +----------------+-----------------+-----------------+-----------------------------+ | ARM | Cortex-A710 | #2224489 | ARM64_ERRATUM_2224489 | +----------------+-----------------+-----------------+-----------------------------+ +| ARM | Cortex-A710 | #2701952 | ARM64_ERRATUM_2701951 | ++----------------+-----------------+-----------------+-----------------------------+ | ARM | Cortex-A715 | #2645198 | ARM64_ERRATUM_2645198 | +----------------+-----------------+-----------------+-----------------------------+ +| ARM | Cortex-X1 | #2712571 | ARM64_ERRATUM_2701951 | ++----------------+-----------------+-----------------+-----------------------------+ | ARM | Cortex-X2 | #2119858 | ARM64_ERRATUM_2119858 | +----------------+-----------------+-----------------+-----------------------------+ | ARM | Cortex-X2 | #2224489 | ARM64_ERRATUM_2224489 | +----------------+-----------------+-----------------+-----------------------------+ +| ARM | Cortex-X2 | #2701952 | ARM64_ERRATUM_2701951 | ++----------------+-----------------+-----------------+-----------------------------+ +| ARM | Cortex-X3 | #2701951 | ARM64_ERRATUM_2701951 | ++----------------+-----------------+-----------------+-----------------------------+ | ARM | Neoverse-N1 | #1188873,1418040| ARM64_ERRATUM_1418040 | +----------------+-----------------+-----------------+-----------------------------+ | ARM | Neoverse-N1 | #1349291 | N/A | @@ -138,6 +150,12 @@ stable kernels. +----------------+-----------------+-----------------+-----------------------------+ | ARM | Neoverse-N2 | #2253138 | ARM64_ERRATUM_2253138 | +----------------+-----------------+-----------------+-----------------------------+ +| ARM | Neoverse-N2 | #2728475 | ARM64_ERRATUM_2701951 | ++----------------+-----------------+-----------------+-----------------------------+ +| ARM | Neoverse-V1 | #2701953 | ARM64_ERRATUM_2701951 | ++----------------+-----------------+-----------------+-----------------------------+ +| ARM | Neoverse-V2 | #2719103 | ARM64_ERRATUM_2701951 | ++----------------+-----------------+-----------------+-----------------------------+ | ARM | MMU-500 | #841119,826419 | N/A | +----------------+-----------------+-----------------+-----------------------------+ +----------------+-----------------+-----------------+-----------------------------+ diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 1023e896d46b..0d07ddd15bfb 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -990,6 +990,33 @@ config ARM64_ERRATUM_2645198 If unsure, say Y. +config ARM64_ERRATUM_2701951 + bool "ARM CPUs: 2701951: disable FWB on affected parts" + select ARM_SMCCC_EM + default y + help + This option adds the workaround for multiple ARM errata titled + "The core might fetch stale instruction from memory when both Stage 1 + Translation and Instruction Cache are Disabled with Stage 2 forced + Write-Back". + This affects Cortex cores: A78, A78C, A710, X1, X2, X3, and Neoverse + cores: V1, V2 and N2. + + Affected cores fail to apply the FWB override to instruction fetch + when stage1 translation is disabled, and SCTLR_EL1.I is clear. This + results in stale data being fetched and executed. Only CPUs that are + connected to a non-Arm interconnect will exhibit symptoms due to this + errata. + + Work around this problem in the driver by disabling FWB on affected + parts. The SMCCC Errata Management API is used to query firmware to + learn if the part is affected. + + If the SMCCC Errata Management API is not implemented on a platform + with an affected core, the workaround will be applied. + + If unsure, say Y. + config CAVIUM_ERRATUM_22375 bool "Cavium erratum 22375, 24313" default y diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 6bf013fb110d..435e5d1b49ab 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h @@ -635,6 +635,7 @@ static inline bool id_aa64pfr1_mte(u64 pfr1) void __init setup_cpu_features(void); void check_local_cpu_capabilities(void); +bool has_stage2_fwb_errata(const struct arm64_cpu_capabilities *entry, int scope); u64 read_sanitised_ftr_reg(u32 id); u64 __read_sysreg_by_encoding(u32 sys_id); diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index 307faa2b4395..55da9e588b9e 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -137,6 +138,81 @@ cpu_clear_bf16_from_user_emulation(const struct arm64_cpu_capabilities *__unused raw_spin_unlock(®_user_mask_modification); } +bool has_stage2_fwb_errata(const struct arm64_cpu_capabilities *ignored, + int scope) +{ + u64 idr; + bool has_feature; + + /* List of CPUs which may have broken FWB support. */ + static const struct midr_range cpus[] = { +#ifdef CONFIG_ARM64_ERRATUM_2701951 + MIDR_ALL_VERSIONS(MIDR_CORTEX_A78), + MIDR_ALL_VERSIONS(MIDR_CORTEX_A78C), + MIDR_ALL_VERSIONS(MIDR_CORTEX_A710), + MIDR_ALL_VERSIONS(MIDR_CORTEX_X1), + MIDR_ALL_VERSIONS(MIDR_CORTEX_X2), + MIDR_RANGE(MIDR_CORTEX_X3, 0, 0, 1, 1), + MIDR_RANGE(MIDR_NEOVERSE_V1, 0, 0, 1, 1), + MIDR_RANGE(MIDR_NEOVERSE_V2, 0, 0, 0, 1), + MIDR_RANGE(MIDR_NEOVERSE_N2, 0, 0, 0, 2), +#endif + { /* sentinel */ }, + }; + + if (scope == ARM64_CPUCAP_SCOPE_SYSTEM) + return cpus_have_cap(ARM64_WORKAROUND_NO_FWB); + + idr = read_cpuid(ID_AA64MMFR2_EL1); + has_feature = FIELD_GET(ID_AA64MMFR2_EL1_FWB, idr); + if (!has_feature) + return false; + + if (is_midr_in_range_list(read_cpuid_id(), cpus)) { + int i; + bool fwb_broken = true; + + /* + * List of erratum numbers for these CPUs. + * It isn't possible to match these to their CPUs, as A78C has + * two erratum numbers. The errata management API will return + * 'UNKNOWN' for an erratum it doesn't recognise. + */ + static const u32 erratum_nums[] = { + 2701951, + 2701952, + 2701953, + 2712571, + 2712572, + 2712575, + 2719103, + 2728475, + }; + + /* + * The CPU is affected, but what about this configuration? + * Only firmware has the answer. Assume the part is affected, + * and query firmware for the set of erratum numbers. If one + * returns not-affected, the workaround isn't needed. + */ + for (i = 0; i < ARRAY_SIZE(erratum_nums); i++) { + int state = arm_smccc_em_cpu_features(erratum_nums[i]); + + if (state == SMCCC_EM_RET_NOT_AFFECTED) { + fwb_broken = false; + break; + } + } + + if (fwb_broken) { + pr_info_once("Stage-2 Force Write-Back disabled due to erratum #2701951\n"); + return true; + } + } + + return false; +} + #define CAP_MIDR_RANGE(model, v_min, r_min, v_max, r_max) \ .matches = is_affected_midr_range, \ .midr_range = MIDR_RANGE(model, v_min, r_min, v_max, r_max) @@ -730,6 +806,16 @@ const struct arm64_cpu_capabilities arm64_errata[] = { .cpu_enable = cpu_clear_bf16_from_user_emulation, }, #endif +#ifdef CONFIG_ARM64_ERRATUM_2701951 + { + .desc = "ARM erratum 2701951", + .capability = ARM64_WORKAROUND_NO_FWB, + .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, + .matches = has_stage2_fwb_errata, + + }, +#endif + { } }; diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 62f996006783..099bf6ad7552 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -1586,6 +1586,20 @@ static bool has_cache_dic(const struct arm64_cpu_capabilities *entry, return ctr & BIT(CTR_EL0_DIC_SHIFT); } +static bool has_stage2_fwb(const struct arm64_cpu_capabilities *entry, + int scope) +{ + bool has_feature = has_cpuid_feature(entry, scope); + + if (!has_feature) + return false; + + if (has_stage2_fwb_errata(NULL, scope)) + return false; + + return has_feature; +} + static bool __maybe_unused has_useable_cnp(const struct arm64_cpu_capabilities *entry, int scope) { @@ -2438,7 +2452,7 @@ static const struct arm64_cpu_capabilities arm64_features[] = { .field_pos = ID_AA64MMFR2_EL1_FWB_SHIFT, .field_width = 4, .min_field_value = 1, - .matches = has_cpuid_feature, + .matches = has_stage2_fwb, }, { .desc = "ARMv8.4 Translation Table Level", diff --git a/arch/arm64/tools/cpucaps b/arch/arm64/tools/cpucaps index 37b1340e9646..2e5f70ec6410 100644 --- a/arch/arm64/tools/cpucaps +++ b/arch/arm64/tools/cpucaps @@ -86,6 +86,7 @@ WORKAROUND_CAVIUM_TX2_219_PRFM WORKAROUND_CAVIUM_TX2_219_TVM WORKAROUND_CLEAN_CACHE WORKAROUND_DEVICE_LOAD_ACQUIRE +WORKAROUND_NO_FWB WORKAROUND_NVIDIA_CARMEL_CNP WORKAROUND_QCOM_FALKOR_E1003 WORKAROUND_REPEAT_TLBI From patchwork Thu Mar 30 16:51:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 13194611 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DCF4AC6FD1D for ; Thu, 30 Mar 2023 16:54:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=KuOBR4P5KxswN3e3RdImwa/f3tHJOJ21NB7JVija1yo=; b=CVplkzDx/8onTo B6SODysctF6Q2V887uhck/7uIEoR91inRHp5/I5AyaJlIY682dG2sdFdQgYHuaB/7MEriGMN0X9jd bODQnhN+/qUWpy6DPFiyJlGLri/+bcyQZpHh6CMlJP+o7HrAwL4RGOZ+JT2IXfPquBgdVznvPm0Ce k3dQO/4nkSygpL++tmhc0JjHV/NZjXIfTCCDvhjxb2QYo/QgyJFZm0HKqxZNLDpe+Be4i53Q8CEia roCSV+/HHtzcC+lAg9UjsO+Nxouh4HoTGyg+b4EasGFsBefshdZCVdDDk/LBPhL05GdUae72J+m2R F3+lgGQaHLf9dR8Zuj4g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1phvWQ-004XYb-1O; Thu, 30 Mar 2023 16:53:10 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1phvWI-004XVF-1i for linux-arm-kernel@lists.infradead.org; Thu, 30 Mar 2023 16:53:04 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0D7DD1650; Thu, 30 Mar 2023 09:53:44 -0700 (PDT) Received: from eglon.cambridge.arm.com (eglon.cambridge.arm.com [10.1.196.177]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3183A3F6C4; Thu, 30 Mar 2023 09:52:58 -0700 (PDT) From: James Morse To: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org Cc: Catalin Marinas , Will Deacon , Mark Rutland , Lorenzo Pieralisi , Sudeep Holla , Marc Zyngier , Oliver Upton , James Morse , Rob Herring , Krzysztof Kozlowski Subject: [PATCH 5/6] firmware: smccc: Allow errata management to be overridden by device tree Date: Thu, 30 Mar 2023 17:51:27 +0100 Message-Id: <20230330165128.3237939-6-james.morse@arm.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330165128.3237939-1-james.morse@arm.com> References: <20230330165128.3237939-1-james.morse@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230330_095302_680191_9EE42ACF X-CRM114-Status: GOOD ( 27.67 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The Errata Management SMCCC interface allows firmware to advertise whether the OS is affected by an erratum, or if a higher exception level has mitigated the issue. This allows properties of the device that are not discoverable by the OS to be described. e.g. some errata depend on the behaviour of the interconnect, which is not visible to the OS. Deployed devices may find it significantly harder to update EL3 firmware than the device tree. Erratum workarounds typically have to fail safe, and assume the platform is affected putting correctness above performance. Instead of adding a device-tree entry for any CPU errata that is relevant (or not) to the platform, allow the device-tree to provide the data firmware should provide via the SMCCC interface. This can be used to provide the value if the firmware is not implemented, or override the firmware response if the value provided is wrong. The vast majority of CPU errata solely depend on the CPU, and can be detected from the CPUs id registers. The number of entries in these tables is expected to be small. Signed-off-by: James Morse --- drivers/firmware/smccc/em.c | 227 ++++++++++++++++++++++++++++++++++-- 1 file changed, 217 insertions(+), 10 deletions(-) diff --git a/drivers/firmware/smccc/em.c b/drivers/firmware/smccc/em.c index 2c66240d8707..62e05e6b2140 100644 --- a/drivers/firmware/smccc/em.c +++ b/drivers/firmware/smccc/em.c @@ -6,14 +6,21 @@ * errata. It can also be used to discover erratum where the 'configurations * affected' depends on the integration. * + * The interfaces's return codes have negative values. These should always be + * converted to linux errno values to avoid confusion. + * * Copyright (C) 2022 ARM Limited */ #define pr_fmt(fmt) "arm_smccc_em: " fmt +#include #include #include #include +#include +#include +#include #include #include @@ -22,52 +29,252 @@ static u32 supported; +/* + * This driver may be called when the boot CPU needs to detect an erratum and + * apply alternatives. This happens before page_alloc_init(), so this driver + * cannot allocate memory using slab. Allocate a page instead, and re-use it + * for CPUs that share a set of errata. + */ +#define MAX_EM_ARRAY_SIZE ((PAGE_SIZE / sizeof(u32) / 3) - 1) + +struct arm_em_dt_supplement_array { + u32 num; + u32 val[MAX_EM_ARRAY_SIZE]; +} __packed; + +struct arm_em_dt_supplement { + struct arm_em_dt_supplement_array affected; + struct arm_em_dt_supplement_array not_affected; + struct arm_em_dt_supplement_array higher_el_mitigated; +} __packed; + +static DEFINE_PER_CPU(struct arm_em_dt_supplement *, em_table); + +static bool arm_smccc_em_search_table(struct arm_em_dt_supplement_array *entry, + u32 erratum_id) +{ + int i; + + for (i = 0; i <= entry->num; i++) { + if (entry->val[i] == erratum_id) + return true; + } + + return false; +} + +static int arm_smccc_em_query_dt(u32 erratum_id) +{ + struct arm_em_dt_supplement *tbl = *this_cpu_ptr(&em_table); + + if (!tbl) + return -ENOENT; + + if (arm_smccc_em_search_table(&tbl->affected, erratum_id)) + return SMCCC_EM_RET_AFFECTED; + if (arm_smccc_em_search_table(&tbl->not_affected, erratum_id)) + return SMCCC_EM_RET_NOT_AFFECTED; + if (arm_smccc_em_search_table(&tbl->higher_el_mitigated, erratum_id)) + return SMCCC_EM_RET_HIGHER_EL_MITIGATION; + + return -ENOENT; +} + +/* Only call when both values >= 0 */ +static int arm_smccc_em_merge_retval(u32 erratum_id, u32 one, u32 two) +{ + if (one == two) + return one; + + pr_warn_once("FW/DT mismatch for errataum #%u", erratum_id); + pr_warn_once("(Any subsequent mismatch warnings are suppressed)\n"); + + if (one == SMCCC_EM_RET_AFFECTED || two == SMCCC_EM_RET_AFFECTED) + return SMCCC_EM_RET_AFFECTED; + + if (one == SMCCC_EM_RET_HIGHER_EL_MITIGATION || + two == SMCCC_EM_RET_HIGHER_EL_MITIGATION) + return SMCCC_EM_RET_HIGHER_EL_MITIGATION; + + return SMCCC_EM_RET_NOT_AFFECTED; +} + int arm_smccc_em_cpu_features(u32 erratum_id) { + int dt_retval; struct arm_smccc_res res; + bool _supported = READ_ONCE(supported); - if (!READ_ONCE(supported)) + dt_retval = arm_smccc_em_query_dt(erratum_id); + if (!_supported && dt_retval <= 0) return -EOPNOTSUPP; - arm_smccc_1_1_invoke(ARM_SMCCC_EM_CPU_ERRATUM_FEATURES, erratum_id, 0, &res); + if (_supported) + arm_smccc_1_1_invoke(ARM_SMCCC_EM_CPU_ERRATUM_FEATURES, + erratum_id, 0, &res); + else + res.a0 = SMCCC_RET_NOT_SUPPORTED; + switch (res.a0) { + /* DT can always override errata firmware doesn't know about */ case SMCCC_RET_NOT_SUPPORTED: - return -EOPNOTSUPP; case SMCCC_EM_RET_INVALID_PARAMTER: - return -EINVAL; case SMCCC_EM_RET_UNKNOWN: - return -ENOENT; + return dt_retval; + + /* + * But if there is a mismatch - print a warning and prefer to enable + * the erratum workaround. + */ case SMCCC_EM_RET_HIGHER_EL_MITIGATION: case SMCCC_EM_RET_NOT_AFFECTED: case SMCCC_EM_RET_AFFECTED: - return res.a0; + if (dt_retval > 0) + return arm_smccc_em_merge_retval(erratum_id, res.a0, + dt_retval); + else + return res.a0; }; return -EIO; } +int arm_smccc_em_dt_alloc_tbl_entry(struct device_node *np, const char *name, + struct arm_em_dt_supplement_array *entry) +{ + int ret = of_property_count_u32_elems(np, name); + + if (ret <= 0) + return 0; + if (ret > ARRAY_SIZE(entry->val)) + return -E2BIG; + + entry->num = ret; + return of_property_read_u32_array(np, name, entry->val, entry->num); +} + +static struct arm_em_dt_supplement *arm_smccc_em_dt_alloc_tbl(struct device_node *np) +{ + struct arm_em_dt_supplement *tbl = memblock_alloc(PAGE_SIZE, PAGE_SIZE); + + BUILD_BUG_ON(sizeof(struct arm_em_dt_supplement) > PAGE_SIZE); + + if (!tbl) + return ERR_PTR(-ENOMEM); + + if (arm_smccc_em_dt_alloc_tbl_entry(np, "arm,erratum-affected", + &tbl->affected)) { + memblock_free(tbl, PAGE_SIZE); + return ERR_PTR(-EIO); + } + if (arm_smccc_em_dt_alloc_tbl_entry(np, "arm,erratum-not-affected", + &tbl->not_affected)) { + memblock_free(tbl, PAGE_SIZE); + return ERR_PTR(-EIO); + } + if (arm_smccc_em_dt_alloc_tbl_entry(np, "arm,erratum-higher-el-mitigated", + &tbl->higher_el_mitigated)) { + memblock_free(tbl, PAGE_SIZE); + return ERR_PTR(-EIO); + } + + return tbl; +} + +static int __init arm_smccc_em_dt_probe(void) +{ + int cpu, cpu2; + bool one_entry_found; + struct arm_em_dt_supplement *tbl; + struct device_node *np, *cpu_np, *np2, *cpu_np2; + + for_each_possible_cpu(cpu) { + /* Pre-populated? */ + if (per_cpu(em_table, cpu)) + continue; + + cpu_np = of_get_cpu_node(cpu, 0); + if (!cpu_np) + continue; + + np = of_parse_phandle(cpu_np, "arm,erratum-list", 0); + if (!np) { + of_node_put(cpu_np); + continue; + } + + tbl = arm_smccc_em_dt_alloc_tbl(np); + if (IS_ERR(tbl)) { + pr_err_once("Failed to allocate memory for DT supplement\n"); + of_node_put(cpu_np); + break; + } + per_cpu(em_table, cpu) = tbl; + + /* Pre-populate all CPUs with the same phandle */ + for_each_possible_cpu(cpu2) { + if (cpu2 == cpu) + continue; + + /* Pre-populated? */ + if (per_cpu(em_table, cpu2)) + continue; + + cpu_np2 = of_get_cpu_node(cpu2, 0); + if (!cpu_np2) + continue; + + np2 = of_parse_phandle(cpu_np2, "arm,erratum-list", 0); + if (!np) { + of_node_put(cpu_np2); + continue; + } + + if (np2 == np) + per_cpu(em_table, cpu2) = tbl; + + of_node_put(cpu_np2); + of_node_put(np2); + } + + of_node_put(cpu_np); + of_node_put(np); + + one_entry_found = true; + } + + if (one_entry_found) + pr_info("Found DT supplements for SMCCC Errata Management Interface\n"); + + return one_entry_found ? 0 : -EOPNOTSUPP; +} + int __init arm_smccc_em_init(void) { + int dt_supported = false; u32 major_ver, minor_ver; struct arm_smccc_res res; enum arm_smccc_conduit conduit = arm_smccc_1_1_get_conduit(); + if (acpi_disabled) + dt_supported = arm_smccc_em_dt_probe(); + if (conduit == SMCCC_CONDUIT_NONE) - return -EOPNOTSUPP; + return dt_supported; arm_smccc_1_1_invoke(ARM_SMCCC_EM_VERSION, &res); if (res.a0 == SMCCC_RET_NOT_SUPPORTED) - return -EOPNOTSUPP; + return dt_supported; major_ver = PSCI_VERSION_MAJOR(res.a0); minor_ver = PSCI_VERSION_MINOR(res.a0); if (major_ver != 1) - return -EIO; + return dt_supported; arm_smccc_1_1_invoke(ARM_SMCCC_EM_FEATURES, ARM_SMCCC_EM_CPU_ERRATUM_FEATURES, &res); if (res.a0 == SMCCC_RET_NOT_SUPPORTED) - return -EOPNOTSUPP; + return dt_supported; pr_info("SMCCC Errata Management Interface v%d.%d\n", major_ver, minor_ver); From patchwork Thu Mar 30 16:51:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 13194608 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 051B4C761A6 for ; Thu, 30 Mar 2023 16:53:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=i9gfrhKYLEVgvW/kXejfg8le4s3zwGL0fy7qaSy2ci0=; b=L+LHqeoI4ocEiJ j2JpFo9b5m0fwHpxlDcR0vNShU+175CxNJYJ7J/yJQzG0RYu71qgZOfHf2/UJ7wKndjzmq7KXWENA wriVStyVGJBPOBvDWgETquJAzQI3SPehhnR9IAynCIV0v/tu1tDXfytnDq85vuU1y3Emm00/uMNBT pNNUQmaubnXVNu0JbLc3eVQVZcke85FdCj2MYpqbLh4yUkfarxt3bkDa2XsLVRohu2CB/eOISphWV BPS83oyAmifE4ahMyN33JQ3+ERV0K8JXvBAiBbj6XrqHLeDU+V864aTzcJ2hUbEFVRL+b/KXZpNdu ThhwearbVnnM3MWNmZjw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1phvWR-004XZA-1g; Thu, 30 Mar 2023 16:53:11 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1phvWJ-004XVf-1H for linux-arm-kernel@lists.infradead.org; Thu, 30 Mar 2023 16:53:05 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C46211682; Thu, 30 Mar 2023 09:53:45 -0700 (PDT) Received: from eglon.cambridge.arm.com (eglon.cambridge.arm.com [10.1.196.177]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E7FCB3F6C4; Thu, 30 Mar 2023 09:52:59 -0700 (PDT) From: James Morse To: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org Cc: Catalin Marinas , Will Deacon , Mark Rutland , Lorenzo Pieralisi , Sudeep Holla , Marc Zyngier , Oliver Upton , James Morse , Rob Herring , Krzysztof Kozlowski Subject: [PATCH 6/6] arm64: errata: Add a commandline option to enable/disable #2701951 Date: Thu, 30 Mar 2023 17:51:28 +0100 Message-Id: <20230330165128.3237939-7-james.morse@arm.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330165128.3237939-1-james.morse@arm.com> References: <20230330165128.3237939-1-james.morse@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230330_095303_531233_C9441D63 X-CRM114-Status: GOOD ( 17.36 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Erratum #2701951 affects the FWB feature in a number of CPUs, but is only going to be visible on parts that don't use an arm interconnect. This is not something the operating system can discover, it has to be described by platform firmware. The firmware discovery API is not deployed on existing systems. Add a commandline option to allow the workaround to override the value from firmware, or provide a value if the firmware is not implemented. The property is named arm64.arm-interconnect, as this is the description in the 'configurations affected' section of the erratum. Signed-off-by: James Morse --- .../admin-guide/kernel-parameters.txt | 4 +++ arch/arm64/kernel/cpu_errata.c | 36 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 6221a1d057dd..5898fde6a9e4 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -391,6 +391,10 @@ arcrimi= [HW,NET] ARCnet - "RIM I" (entirely mem-mapped) cards Format: ,, + arm64.arm-interconnect [ARM64] + Indicates the FWB erratum can be disabled because this + SoC uses an arm interconnect. + arm64.nobti [ARM64] Unconditionally disable Branch Target Identification support diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index 55da9e588b9e..c5570904e8b4 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c @@ -138,6 +138,32 @@ cpu_clear_bf16_from_user_emulation(const struct arm64_cpu_capabilities *__unused raw_spin_unlock(®_user_mask_modification); } +static enum { + FWB_WA_FORCED_ON = 1, + FWB_WA_UNKNOWN = 0, + FWB_WA_FORCED_OFF = -1, +} __fwb_workaround_forced; +#ifdef CONFIG_ARM64_ERRATUM_2701951 +static int __init parse_fwb_workaround_cmdline_override(char *str) +{ + bool arm_interconnect; + int ret = kstrtobool(str, &arm_interconnect); + + if (ret) + return ret; + + /* + * Erratum #2701951's "Configurations Affected" says the erratum can + * only be seen on SoC's "that do not use Arm interconnect IP." + */ + if (arm_interconnect) + __fwb_workaround_forced = FWB_WA_FORCED_OFF; + else + __fwb_workaround_forced = FWB_WA_FORCED_ON; + return 0; +} +early_param("arm64.arm-interconnect", parse_fwb_workaround_cmdline_override); +#endif /* CONFIG_ARM64_ERRATUM_2701951 */ bool has_stage2_fwb_errata(const struct arm64_cpu_capabilities *ignored, int scope) { @@ -205,9 +231,19 @@ bool has_stage2_fwb_errata(const struct arm64_cpu_capabilities *ignored, } if (fwb_broken) { + if (__fwb_workaround_forced == FWB_WA_FORCED_OFF) { + pr_info_once("Workaround for erratum #2701951 disabled by command-line option\n"); + return false; + } pr_info_once("Stage-2 Force Write-Back disabled due to erratum #2701951\n"); return true; } + + /* Allow the commandline to override whatever firmware said */ + if (has_feature && __fwb_workaround_forced == FWB_WA_FORCED_ON) { + pr_info_once("Workaround for erratum #2701951 enabled by command-line option\n"); + return true; + } } return false;