Skip to contentSkip to conversation

irqchip/gic-v3: Workaround Marvell erratum 38545 when reading IAR

PATCH Superseded Linu Cherian 2 participants 4 messages Mar 4, 2022

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 irqchip/gic-v3: Workaround Marvell erratum 38545 when reading IAR

When a IAR register read races with a GIC interrupt RELEASE event, GIC-CPU interface could wrongly return a valid INTID to the CPU for an interrupt that is already released(non activated) instead of 0x3ff.

As a side effect, an interrupt handler could run twice, once with interrupt priority and then with idle priority.

As a workaround, gic_read_iar is updated so that it will return a valid interrupt ID only if there is a change in the active priority list after the IAR read on all the affected Silicons.

Since there are silicon variants where both 23154 and 38545 are applicable, workaround for erratum 23154 has been extended to address both of them.

---
Changes since V2:
- IIDR based quirk management done for 23154 has been reverted
- Extended existing 23154 errata to address 38545 as well, so that existing static keys are reused.
- Added MIDR based support macros to cover all the affected parts
- Changed the unlikely construct to likely construct in the workaround function.

 Documentation/arm64/silicon-errata.rst |  2 +-
 arch/arm64/Kconfig                     |  8 ++++++--
 arch/arm64/include/asm/arch_gicv3.h    | 22 ++++++++++++++++++++--
 arch/arm64/include/asm/cputype.h       |  2 ++
 arch/arm64/kernel/cpu_errata.c         | 25 ++++++++++++++++++++++---
 5 files changed, 51 insertions(+), 8 deletions(-)
Documentation/arm64/silicon-errata.rst +1 -1
index ea281dd75517..466cb9e89047 100644
@@ -136,7 +136,7 @@ stable kernels.
 +----------------+-----------------+-----------------+-----------------------------+
 | Cavium         | ThunderX ITS    | #23144          | CAVIUM_ERRATUM_23144        |
 +----------------+-----------------+-----------------+-----------------------------+
-| Cavium         | ThunderX GICv3  | #23154          | CAVIUM_ERRATUM_23154        |
+| Cavium         | ThunderX GICv3  | #23154,38545    | CAVIUM_ERRATUM_23154        |
 +----------------+-----------------+-----------------+-----------------------------+
 | Cavium         | ThunderX GICv3  | #38539          | N/A                         |
 +----------------+-----------------+-----------------+-----------------------------+
arch/arm64/Kconfig +6 -2
index 09b885cc4db5..778cc2e22c21 100644
@@ -891,13 +891,17 @@ config CAVIUM_ERRATUM_23144
 	  If unsure, say Y.
 
 config CAVIUM_ERRATUM_23154
-	bool "Cavium erratum 23154: Access to ICC_IAR1_EL1 is not sync'ed"
+	bool "Cavium errata 23154 and 38545: GICv3 lacks HW synchronisation"
 	default y
 	help
-	  The gicv3 of ThunderX requires a modified version for
+	  The ThunderX GICv3 implementation requires a modified version for
 	  reading the IAR status to ensure data synchronization
 	  (access to icc_iar1_el1 is not sync'ed before and after).
 
+	  It also suffers from erratum 38545 (also present on Marvell's
+	  OcteonTX and OcteonTX2), resulting in deactivated interrupts being
+	  spuriously presented to the CPU interface.
+
 	  If unsure, say Y.
 
 config CAVIUM_ERRATUM_27456
arch/arm64/include/asm/arch_gicv3.h +20 -2
index 4ad22c3135db..b8fd7b1f9944 100644
@@ -53,17 +53,35 @@ static inline u64 gic_read_iar_common(void)
  * The gicv3 of ThunderX requires a modified version for reading the
  * IAR status to ensure data synchronization (access to icc_iar1_el1
  * is not sync'ed before and after).
+ *
+ * Erratum 38545
+ *
+ * When a IAR register read races with a GIC interrupt RELEASE event,
+ * GIC-CPU interface could wrongly return a valid INTID to the CPU
+ * for an interrupt that is already released(non activated) instead of 0x3ff.
+ *
+ * To workaround this, return a valid interrupt ID only if there is a change
+ * in the active priority list after the IAR read.
+ *
+ * Common function used for both the workarounds since,
+ * 1. On Thunderx 88xx 1.x both erratas are applicable.
+ * 2. Having extra nops doesn't add any side effects for Silicons where
+ *    erratum 23154 is not applicable.
  */
 static inline u64 gic_read_iar_cavium_thunderx(void)
 {
-	u64 irqstat;
+	u64 irqstat, apr;
 
+	apr = read_sysreg_s(SYS_ICC_AP1R0_EL1);
 	nops(8);
 	irqstat = read_sysreg_s(SYS_ICC_IAR1_EL1);
 	nops(4);
 	mb();
 
-	return irqstat;
+	if (likely(apr != read_sysreg_s(SYS_ICC_AP1R0_EL1)))
+		return irqstat;
+
+	return 0x3ff;
 }
 
 static inline void gic_write_ctlr(u32 val)
arch/arm64/include/asm/cputype.h +2 -0
index 999b9149f856..9407c5074a4f 100644
@@ -80,6 +80,7 @@
 
 #define APM_CPU_PART_POTENZA		0x000
 
+#define CAVIUM_CPU_PART_THUNDERX_OTX_GEN 0x0A0
 #define CAVIUM_CPU_PART_THUNDERX	0x0A1
 #define CAVIUM_CPU_PART_THUNDERX_81XX	0x0A2
 #define CAVIUM_CPU_PART_THUNDERX_83XX	0x0A3
@@ -121,6 +122,7 @@
 #define MIDR_CORTEX_A710 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A710)
 #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_THUNDERX_OTX_GEN MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX_OTX_GEN)
 #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)
arch/arm64/kernel/cpu_errata.c +22 -3
index b217941713a8..82ed09b363d6 100644
@@ -41,6 +41,25 @@ is_affected_midr_range_list(const struct arm64_cpu_capabilities *entry,
 	return is_midr_in_range_list(read_cpuid_id(), entry->midr_range_list);
 }
 
+static bool __maybe_unused
+is_marvell_thunderx_otx_family(const struct arm64_cpu_capabilities *entry,
+			       int scope)
+{
+	u32 model;
+
+	WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible());
+
+	model = read_cpuid_id();
+	/* 0xe8 mask will cover  0xA1 - 0xA3 and 0xB1 - 0xB6 series with
+	 * 0xAF and 0xB8 as exceptions
+	 */
+	model &= MIDR_IMPLEMENTOR_MASK | (0x0e8 << MIDR_PARTNUM_SHIFT) |
+		 MIDR_ARCHITECTURE_MASK;
+
+	/* This includes Thunderx, OcteonTx, OcteonTx2 family of processors */
+	return model == MIDR_THUNDERX_OTX_GEN;
+}
+
 static bool __maybe_unused
 is_kryo_midr(const struct arm64_cpu_capabilities *entry, int scope)
 {
@@ -425,10 +444,10 @@ const struct arm64_cpu_capabilities arm64_errata[] = {
 #endif
 #ifdef CONFIG_CAVIUM_ERRATUM_23154
 	{
-	/* Cavium ThunderX, pass 1.x */
-		.desc = "Cavium erratum 23154",
+		.desc = "Cavium errata 23154 and 38545",
 		.capability = ARM64_WORKAROUND_CAVIUM_23154,
-		ERRATA_MIDR_REV_RANGE(MIDR_THUNDERX, 0, 0, 1),
+		.type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM,
+		.matches = is_marvell_thunderx_otx_family,
 	},
 #endif
 #ifdef CONFIG_CAVIUM_ERRATUM_27456
Signature · 1 line
2.31.1
maintainer
#1 lore raw
Quoted 90 lines · Linu Cherian

When a IAR register read races with a GIC interrupt RELEASE event, GIC-CPU interface could wrongly return a valid INTID to the CPU for an interrupt that is already released(non activated) instead of 0x3ff.

As a side effect, an interrupt handler could run twice, once with interrupt priority and then with idle priority.

As a workaround, gic_read_iar is updated so that it will return a valid interrupt ID only if there is a change in the active priority list after the IAR read on all the affected Silicons.

Since there are silicon variants where both 23154 and 38545 are applicable, workaround for erratum 23154 has been extended to address both of them.

---
Changes since V2:
- IIDR based quirk management done for 23154 has been reverted
- Extended existing 23154 errata to address 38545 as well, so that existing static keys are reused.
- Added MIDR based support macros to cover all the affected parts
- Changed the unlikely construct to likely construct in the workaround function.

 Documentation/arm64/silicon-errata.rst |  2 +-
 arch/arm64/Kconfig                     |  8 ++++++--
 arch/arm64/include/asm/arch_gicv3.h    | 22 ++++++++++++++++++++--
 arch/arm64/include/asm/cputype.h       |  2 ++
 arch/arm64/kernel/cpu_errata.c         | 25 ++++++++++++++++++++++---
 5 files changed, 51 insertions(+), 8 deletions(-)
Documentation/arm64/silicon-errata.rst +1 -1
index ea281dd75517..466cb9e89047 100644
@@ -136,7 +136,7 @@ stable kernels.
 +----------------+-----------------+-----------------+-----------------------------+
 | Cavium         | ThunderX ITS    | #23144          | CAVIUM_ERRATUM_23144        |
 +----------------+-----------------+-----------------+-----------------------------+
-| Cavium         | ThunderX GICv3  | #23154          | CAVIUM_ERRATUM_23154        |
+| Cavium         | ThunderX GICv3  | #23154,38545    | CAVIUM_ERRATUM_23154        |
 +----------------+-----------------+-----------------+-----------------------------+
 | Cavium         | ThunderX GICv3  | #38539          | N/A                         |
 +----------------+-----------------+-----------------+-----------------------------+
arch/arm64/Kconfig +6 -2
index 09b885cc4db5..778cc2e22c21 100644
@@ -891,13 +891,17 @@ config CAVIUM_ERRATUM_23144
 	  If unsure, say Y.
 
 config CAVIUM_ERRATUM_23154
-	bool "Cavium erratum 23154: Access to ICC_IAR1_EL1 is not sync'ed"
+	bool "Cavium errata 23154 and 38545: GICv3 lacks HW synchronisation"
 	default y
 	help
-	  The gicv3 of ThunderX requires a modified version for
+	  The ThunderX GICv3 implementation requires a modified version for
 	  reading the IAR status to ensure data synchronization
 	  (access to icc_iar1_el1 is not sync'ed before and after).
 
+	  It also suffers from erratum 38545 (also present on Marvell's
+	  OcteonTX and OcteonTX2), resulting in deactivated interrupts being
+	  spuriously presented to the CPU interface.
+
 	  If unsure, say Y.
 
 config CAVIUM_ERRATUM_27456
arch/arm64/include/asm/arch_gicv3.h +11 -0
index 4ad22c3135db..b8fd7b1f9944 100644
@@ -53,17 +53,35 @@ static inline u64 gic_read_iar_common(void)
  * The gicv3 of ThunderX requires a modified version for reading the
  * IAR status to ensure data synchronization (access to icc_iar1_el1
  * is not sync'ed before and after).
+ *
+ * Erratum 38545
+ *
+ * When a IAR register read races with a GIC interrupt RELEASE event,
+ * GIC-CPU interface could wrongly return a valid INTID to the CPU
+ * for an interrupt that is already released(non activated) instead of 0x3ff.
+ *
+ * To workaround this, return a valid interrupt ID only if there is a change
+ * in the active priority list after the IAR read.
+ *
+ * Common function used for both the workarounds since,

arch/arm64/include/asm/arch_gicv3.h static inline u64 gic_read_iar_common(void) · line 75

Quoted 10 lines
arch/arm64/include/asm/arch_gicv3.h +5 -1
+ * 1. On Thunderx 88xx 1.x both erratas are applicable.
+ * 2. Having extra nops doesn't add any side effects for Silicons where
+ *    erratum 23154 is not applicable.
  */
 static inline u64 gic_read_iar_cavium_thunderx(void)
 {
-	u64 irqstat;
+	u64 irqstat, apr;
 
+	apr = read_sysreg_s(SYS_ICC_AP1R0_EL1);

Why only AP1R0? Does the HW only support 5 bits of priority? If it supports more, you need to check all the registers that may contain an active priority (0xa0 for a standard interrupt, 0x20 for a pNMI).

arch/arm64/include/asm/arch_gicv3.h static inline u64 gic_read_iar_common(void) · line 84

Quoted 10 lines
arch/arm64/include/asm/arch_gicv3.h +4 -1
 	nops(8);
 	irqstat = read_sysreg_s(SYS_ICC_IAR1_EL1);
 	nops(4);
 	mb();
 
-	return irqstat;
+	if (likely(apr != read_sysreg_s(SYS_ICC_AP1R0_EL1)))
+		return irqstat;
+
+	return 0x3ff;

This should be ICC_IAR1_EL1_SPURIOUS.

arch/arm64/include/asm/cputype.h line 83

Quoted 12 lines
arch/arm64/include/asm/arch_gicv3.h +0 -0
 }
 
 static inline void gic_write_ctlr(u32 val)
arch/arm64/include/asm/cputype.h +1 -0
index 999b9149f856..9407c5074a4f 100644
@@ -80,6 +80,7 @@
 
 #define APM_CPU_PART_POTENZA		0x000
 
+#define CAVIUM_CPU_PART_THUNDERX_OTX_GEN 0x0A0

Is this an actual part number? What does 'GEN' stand for?

Quoted 28 lines
arch/arm64/include/asm/cputype.h +1 -0
 #define CAVIUM_CPU_PART_THUNDERX	0x0A1
 #define CAVIUM_CPU_PART_THUNDERX_81XX	0x0A2
 #define CAVIUM_CPU_PART_THUNDERX_83XX	0x0A3
@@ -121,6 +122,7 @@
 #define MIDR_CORTEX_A710 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A710)
 #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_THUNDERX_OTX_GEN MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX_OTX_GEN)
 #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)
arch/arm64/kernel/cpu_errata.c +9 -0
index b217941713a8..82ed09b363d6 100644
@@ -41,6 +41,25 @@ is_affected_midr_range_list(const struct arm64_cpu_capabilities *entry,
 	return is_midr_in_range_list(read_cpuid_id(), entry->midr_range_list);
 }
 
+static bool __maybe_unused
+is_marvell_thunderx_otx_family(const struct arm64_cpu_capabilities *entry,
+			       int scope)
+{
+	u32 model;
+
+	WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible());
+
+	model = read_cpuid_id();

arch/arm64/kernel/cpu_errata.c is_affected_midr_range_list(const struct arm64_cpu_capabilities *entry, · line 62

Quoted 10 lines
arch/arm64/kernel/cpu_errata.c +10 -0
+	/* 0xe8 mask will cover  0xA1 - 0xA3 and 0xB1 - 0xB6 series with
+	 * 0xAF and 0xB8 as exceptions
+	 */
+	model &= MIDR_IMPLEMENTOR_MASK | (0x0e8 << MIDR_PARTNUM_SHIFT) |
+		 MIDR_ARCHITECTURE_MASK;
+
+	/* This includes Thunderx, OcteonTx, OcteonTx2 family of processors */
+	return model == MIDR_THUNDERX_OTX_GEN;
+}
+

No, please. This is a version of the Kryo hack, only worse. We *really* want to see an actual list of models and revisions, not an obfuscated mask that covers HW that may or may not exist. All the infrastructure is there to describe these constraints as data, just make use of it.

Quoted 7 lines
arch/arm64/kernel/cpu_errata.c +0 -0
 static bool __maybe_unused
 is_kryo_midr(const struct arm64_cpu_capabilities *entry, int scope)
 {
@@ -425,10 +444,10 @@ const struct arm64_cpu_capabilities arm64_errata[] = {
 #endif
 #ifdef CONFIG_CAVIUM_ERRATUM_23154
 	{

arch/arm64/kernel/cpu_errata.c const struct arm64_cpu_capabilities arm64_errata[] = { · line 453

Quoted 10 lines
arch/arm64/kernel/cpu_errata.c +3 -3
-	/* Cavium ThunderX, pass 1.x */
-		.desc = "Cavium erratum 23154",
+		.desc = "Cavium errata 23154 and 38545",
 		.capability = ARM64_WORKAROUND_CAVIUM_23154,
-		ERRATA_MIDR_REV_RANGE(MIDR_THUNDERX, 0, 0, 1),
+		.type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM,
+		.matches = is_marvell_thunderx_otx_family,
 	},
 #endif
 #ifdef CONFIG_CAVIUM_ERRATUM_27456

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
#2 lore raw

Hi Marc,

Quoted 125 lines

-----Original Message-----
From: Marc Zyngier <[email protected]>
Sent: Friday, March 4, 2022 1:13 PM
To: Linu Cherian <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: [EXT] Re: [PATCH V2] irqchip/gic-v3: Workaround Marvell erratum 38545 when reading IAR

External Email

----------------------------------------------------------------------

Quoted 8 lines · Linu Cherian

When a IAR register read races with a GIC interrupt RELEASE event, GIC-CPU interface could wrongly return a valid INTID to the CPU for an interrupt that is already released(non activated) instead of 0x3ff.

As a side effect, an interrupt handler could run twice, once with interrupt priority and then with idle priority.

Quoted 6 lines

As a workaround, gic_read_iar is updated so that it will return a valid interrupt ID only if there is a change in the active priority list after the IAR read on all the affected Silicons.

Since there are silicon variants where both 23154 and 38545 are applicable, workaround for erratum 23154 has been extended to address

both of them.

Quoted 26 lines

---
Changes since V2:
- IIDR based quirk management done for 23154 has been reverted
- Extended existing 23154 errata to address 38545 as well, so that existing static keys are reused.
- Added MIDR based support macros to cover all the affected parts
- Changed the unlikely construct to likely construct in the workaround function.

 Documentation/arm64/silicon-errata.rst |  2 +-
 arch/arm64/Kconfig                     |  8 ++++++--
 arch/arm64/include/asm/arch_gicv3.h    | 22 ++++++++++++++++++++--
 arch/arm64/include/asm/cputype.h       |  2 ++
 arch/arm64/kernel/cpu_errata.c         | 25 ++++++++++++++++++++++---
 5 files changed, 51 insertions(+), 8 deletions(-)
Documentation/arm64/silicon-errata.rst +0 -0
index ea281dd75517..466cb9e89047 100644

Documentation/arm64/silicon-errata.rst stable kernels. · line 137

Quoted 2 lines
Documentation/arm64/silicon-errata.rst +0 -0
@@ -136,7 +136,7 @@ stable kernels.
 +----------------+-----------------+-----------------+-----------------------------+
 | Cavium         | ThunderX ITS    | #23144          | CAVIUM_ERRATUM_23144

|

Documentation/arm64/silicon-errata.rst stable kernels. · line 139

Quoted 4 lines
Documentation/arm64/silicon-errata.rst +1 -2
+----------------+-----------------+-----------------+----------------
-------------+
-| Cavium         | ThunderX GICv3  | #23154          |

CAVIUM_ERRATUM_23154 |

Documentation/arm64/silicon-errata.rst stable kernels. · line 139

Quoted 1 line
Documentation/arm64/silicon-errata.rst +1 -0
+| Cavium         | ThunderX GICv3  | #23154,38545    |

CAVIUM_ERRATUM_23154 |

Quoted 9 lines
Documentation/arm64/silicon-errata.rst +1 -1
 +----------------+-----------------+-----------------+-----------------------------+
 | Cavium         | ThunderX GICv3  | #38539          | N/A                         |
 
+----------------+-----------------+-----------------+----------------
-------------+ diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig

index 09b885cc4db5..778cc2e22c21 100644

arch/arm64/Kconfig config CAVIUM_ERRATUM_23144 · line 894

Quoted 5 lines
arch/arm64/Kconfig +1 -1
@@ -891,13 +891,17 @@ config CAVIUM_ERRATUM_23144
 	  If unsure, say Y.
 
 config CAVIUM_ERRATUM_23154
-	bool "Cavium erratum 23154: Access to ICC_IAR1_EL1 is not sync'ed"
+	bool "Cavium errata 23154 and 38545: GICv3 lacks HW

synchronisation"

Quoted 44 lines
arch/arm64/Kconfig +5 -1
 	default y
 	help
-	  The gicv3 of ThunderX requires a modified version for
+	  The ThunderX GICv3 implementation requires a modified version for
 	  reading the IAR status to ensure data synchronization
 	  (access to icc_iar1_el1 is not sync'ed before and after).
 
+	  It also suffers from erratum 38545 (also present on Marvell's
+	  OcteonTX and OcteonTX2), resulting in deactivated interrupts being
+	  spuriously presented to the CPU interface.
+
 	  If unsure, say Y.
 
 config CAVIUM_ERRATUM_27456
arch/arm64/include/asm/arch_gicv3.h +16 -1
index 4ad22c3135db..b8fd7b1f9944 100644
@@ -53,17 +53,35 @@ static inline u64 gic_read_iar_common(void)
  * The gicv3 of ThunderX requires a modified version for reading the
  * IAR status to ensure data synchronization (access to icc_iar1_el1
  * is not sync'ed before and after).
+ *
+ * Erratum 38545
+ *
+ * When a IAR register read races with a GIC interrupt RELEASE event,
+ * GIC-CPU interface could wrongly return a valid INTID to the CPU
+ * for an interrupt that is already released(non activated) instead of 0x3ff.
+ *
+ * To workaround this, return a valid interrupt ID only if there is a
+ change
+ * in the active priority list after the IAR read.
+ *
+ * Common function used for both the workarounds since,
+ * 1. On Thunderx 88xx 1.x both erratas are applicable.
+ * 2. Having extra nops doesn't add any side effects for Silicons where
+ *    erratum 23154 is not applicable.
  */
 static inline u64 gic_read_iar_cavium_thunderx(void)
 {
-	u64 irqstat;
+	u64 irqstat, apr;
 
Quoted 6 lines

arch/arm64/include/asm/arch_gicv3.h static inline u64 gic_read_iar_common(void) · line 76

Quoted 1 line
arch/arm64/include/asm/arch_gicv3.h +1 -0
+	apr = read_sysreg_s(SYS_ICC_AP1R0_EL1);

Why only AP1R0? Does the HW only support 5 bits of priority? If it supports more, you need to check all the registers that may contain an active priority (0xa0 for a standard interrupt, 0x20 for a pNMI).

Yes correct. HW supports only 5 bits of priority groups. Will note this in the comment.

Quoted 5 lines
Quoted 5 lines
arch/arm64/include/asm/arch_gicv3.h +0 -0
 	nops(8);
 	irqstat = read_sysreg_s(SYS_ICC_IAR1_EL1);
 	nops(4);
 	mb();
 
Quoted 7 lines

arch/arm64/include/asm/arch_gicv3.h static inline u64 gic_read_iar_common(void) · line 85

Quoted 5 lines
arch/arm64/include/asm/arch_gicv3.h +4 -1
-	return irqstat;
+	if (likely(apr != read_sysreg_s(SYS_ICC_AP1R0_EL1)))
+		return irqstat;
+
+	return 0x3ff;

This should be ICC_IAR1_EL1_SPURIOUS.

Looks like we need fixes like below in couple of files to make use of this macro.

arch/arm64/include/asm/kvm_host.h +1 -1
index 5bc01e62c08a..d02b7339d21a 100644
@@ -18,7 +18,7 @@
 #include <linux/kvm_types.h>
 #include <linux/percpu.h>
 #include <linux/psci.h>
-#include <asm/arch_gicv3.h>
+#include <linux/irqchip/arm-gic-v3.h>
 

Should I consider fixing these ?
At least its builds fine for me with similar header fixes.

Quoted 11 lines
Quoted 5 lines
arch/arm64/include/asm/arch_gicv3.h +0 -0
 }
 
 static inline void gic_write_ctlr(u32 val) diff --git

a/arch/arm64/include/asm/cputype.h

b/arch/arm64/include/asm/cputype.h

Quoted 5 lines

index 999b9149f856..9407c5074a4f 100644

arch/arm64/include/asm/cputype.h +0 -0
@@ -80,6 +80,7 @@
 
Quoted 6 lines

arch/arm64/include/asm/cputype.h line 83

Quoted 3 lines
arch/arm64/include/asm/cputype.h +1 -0
 #define APM_CPU_PART_POTENZA		0x000
 
+#define CAVIUM_CPU_PART_THUNDERX_OTX_GEN 0x0A0

Is this an actual part number? What does 'GEN' stand for?

No, this is not an actual part number. GEN was meant to be generic to cover a group of part numbers.

Quoted 49 lines
Quoted 7 lines
arch/arm64/include/asm/cputype.h +0 -0
 #define CAVIUM_CPU_PART_THUNDERX	0x0A1
 #define CAVIUM_CPU_PART_THUNDERX_81XX	0x0A2
 #define CAVIUM_CPU_PART_THUNDERX_83XX	0x0A3
@@ -121,6 +122,7 @@
 #define MIDR_CORTEX_A710 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM,

ARM_CPU_PART_CORTEX_A710) #define MIDR_CORTEX_X2 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_X2)

#define

Quoted 3 lines

MIDR_NEOVERSE_N2 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM,
ARM_CPU_PART_NEOVERSE_N2)
+#define MIDR_THUNDERX_OTX_GEN

MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM,

Quoted 2 lines

+CAVIUM_CPU_PART_THUNDERX_OTX_GEN)
#define MIDR_THUNDERX MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM,

CAVIUM_CPU_PART_THUNDERX)

Quoted 1 line

#define MIDR_THUNDERX_81XX

MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM,

Quoted 2 lines

CAVIUM_CPU_PART_THUNDERX_81XX) #define MIDR_THUNDERX_83XX MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM,

CAVIUM_CPU_PART_THUNDERX_83XX) diff

arch/arm64/kernel/cpu_errata.c is_affected_midr_range_list(const struct

Quoted 6 lines

--git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index b217941713a8..82ed09b363d6 100644

arch/arm64/kernel/cpu_errata.c +0 -0
@@ -41,6 +41,25 @@ is_affected_midr_range_list(const struct

arm64_cpu_capabilities *entry,

arch/arm64/kernel/cpu_errata.c is_affected_midr_range_list(const struct · line 45

Quoted 5 lines
arch/arm64/kernel/cpu_errata.c +2 -0
 	return is_midr_in_range_list(read_cpuid_id(),
 entry->midr_range_list);  }
 
+static bool __maybe_unused
+is_marvell_thunderx_otx_family(const struct arm64_cpu_capabilities

*entry,

arch/arm64/kernel/cpu_errata.c is_affected_midr_range_list(const struct · line 56

Quoted 11 lines
arch/arm64/kernel/cpu_errata.c +11 -0
+			       int scope)
+{
+	u32 model;
+
+	WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible());
+
+	model = read_cpuid_id();
+	/* 0xe8 mask will cover  0xA1 - 0xA3 and 0xB1 - 0xB6 series with
+	 * 0xAF and 0xB8 as exceptions
+	 */
+	model &= MIDR_IMPLEMENTOR_MASK | (0x0e8 <<

MIDR_PARTNUM_SHIFT) |

arch/arm64/kernel/cpu_errata.c is_affected_midr_range_list(const struct · line 59

Quoted 3 lines
arch/arm64/kernel/cpu_errata.c +3 -0
+		 MIDR_ARCHITECTURE_MASK;
+
+	/* This includes Thunderx, OcteonTx, OcteonTx2 family of processors

*/

Quoted 8 lines

arch/arm64/kernel/cpu_errata.c is_affected_midr_range_list(const struct · line 61

Quoted 2 lines
arch/arm64/kernel/cpu_errata.c +2 -0
+	return model == MIDR_THUNDERX_OTX_GEN; }
+

No, please. This is a version of the Kryo hack, only worse. We *really* want to see an actual list of models and revisions, not an obfuscated mask that covers HW that may or may not exist. All the infrastructure is there to describe these constraints as data, just make use of it.

Ack. Will change this to actual part numbers.

Quoted 22 lines
Quoted 5 lines
arch/arm64/kernel/cpu_errata.c +0 -0
 static bool __maybe_unused
 is_kryo_midr(const struct arm64_cpu_capabilities *entry, int scope)

{ @@ -425,10 +444,10 @@ const struct arm64_cpu_capabilities arm64_errata[] = { #endif #ifdef CONFIG_CAVIUM_ERRATUM_23154

arch/arm64/kernel/cpu_errata.c +0 -0
 	{

arch/arm64/kernel/cpu_errata.c

Quoted 10 lines
arch/arm64/kernel/cpu_errata.c +3 -3
-	/* Cavium ThunderX, pass 1.x */
-		.desc = "Cavium erratum 23154",
+		.desc = "Cavium errata 23154 and 38545",
 		.capability = ARM64_WORKAROUND_CAVIUM_23154,
-		ERRATA_MIDR_REV_RANGE(MIDR_THUNDERX, 0, 0, 1),
+		.type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM,
+		.matches = is_marvell_thunderx_otx_family,
 	},
 #endif
 #ifdef CONFIG_CAVIUM_ERRATUM_27456

Thanks,

	M.

--
Without deviation from the norm, progress is not possible.

maintainer
#3 lore raw

Hi Linu,

Quoted 15 lines · Linu Cherian

Hi Marc,

Quoted 11 lines

Review

Quoted 6 lines

static inline u64 gic_read_iar_cavium_thunderx(void) {

(quoted diff) +2 -1
-	u64 irqstat;
+	u64 irqstat, apr;
 
+	apr = read_sysreg_s(SYS_ICC_AP1R0_EL1);

Why only AP1R0? Does the HW only support 5 bits of priority? If it supports more, you need to check all the registers that may contain an active priority (0xa0 for a standard interrupt, 0x20 for a pNMI).

Quoted 2 lines

Yes correct. HW supports only 5 bits of priority groups. Will note this in the comment.

Thanks.

Quoted 28 lines
Quoted 6 lines
Quoted 6 lines
(quoted diff) +0 -0
 	nops(8);
 	irqstat = read_sysreg_s(SYS_ICC_IAR1_EL1);
 	nops(4);
 	mb();
Quoted 7 lines

Review

Quoted 5 lines
(quoted diff) +4 -1
-	return irqstat;
+	if (likely(apr != read_sysreg_s(SYS_ICC_AP1R0_EL1)))
+		return irqstat;
+
+	return 0x3ff;

This should be ICC_IAR1_EL1_SPURIOUS.

Looks like we need fixes like below in couple of files to make use of this macro.

arch/arm64/include/asm/kvm_host.h +1 -1
index 5bc01e62c08a..d02b7339d21a 100644
@@ -18,7 +18,7 @@
 #include <linux/kvm_types.h>
 #include <linux/percpu.h>
 #include <linux/psci.h>
-#include <asm/arch_gicv3.h>
+#include <linux/irqchip/arm-gic-v3.h>
 
Quoted 2 lines

Should I consider fixing these ?
At least its builds fine for me with similar header fixes.

Ah, crap. I'd like to avoid dragging too much of the linux/*.h into asm/*.h, as this eventually leads to a pretty terrible mess. Never mind then. I'll look into fixing it independently, and we'll live with the 0x3ff for now.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

+#define CAVIUM_CPU_PART_THUNDERX_OTX_GEN 0x0A0

Is this an actual part number? What does 'GEN' stand for?

No, this is not an actual part number. GEN was meant to be generic to cover a group of part numbers.

The problem with that is that it eventually clashes with part numbers that are allocated later, and your old kernel tries to apply a workaround on the new HW... Sticking to the actual parts is a lot safer.

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.