Skip to contentSkip to conversation

xen/arm: Add workaround for Cortex-A53 erratum #845719

PATCH In review Michal Orzel 4 participants 8 messages Dec 8, 2020 – Dec 9, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/arm: Add workaround for Cortex-A53 erratum #845719

When executing in aarch32 state at EL0, a load at EL0 from a virtual address that matches the bottom 32 bits of the virtual address used by a recent load at (aarch64) EL1 might return incorrect data.

The workaround is to insert a write of the contextidr_el1 register on exception return to an aarch32 guest.

---
 docs/misc/arm/silicon-errata.txt |  1 +
 xen/arch/arm/Kconfig             | 19 +++++++++++++++++++
 xen/arch/arm/arm64/entry.S       |  9 +++++++++
 xen/arch/arm/cpuerrata.c         |  8 ++++++++
 xen/include/asm-arm/cpufeature.h |  3 ++-
 5 files changed, 39 insertions(+), 1 deletion(-)
docs/misc/arm/silicon-errata.txt +1 -0
index 27bf957ebf..fa3d9af63d 100644
@@ -45,6 +45,7 @@ stable hypervisors.
 | ARM            | Cortex-A53      | #827319         | ARM64_ERRATUM_827319    |
 | ARM            | Cortex-A53      | #824069         | ARM64_ERRATUM_824069    |
 | ARM            | Cortex-A53      | #819472         | ARM64_ERRATUM_819472    |
+| ARM            | Cortex-A53      | #845719         | ARM64_ERRATUM_845719    |
 | ARM            | Cortex-A55      | #1530923        | N/A                     |
 | ARM            | Cortex-A57      | #852523         | N/A                     |
 | ARM            | Cortex-A57      | #832075         | ARM64_ERRATUM_832075    |
xen/arch/arm/Kconfig +19 -0
index f5b1bcda03..6bea393555 100644
@@ -244,6 +244,25 @@ config ARM_ERRATUM_858921
 
 	  If unsure, say Y.
 
+config ARM64_ERRATUM_845719
+	bool "Cortex-A53: 845719: A load might read incorrect data"
+	default y
+	help
+	  This option adds an alternative code sequence to work around ARM
+	  erratum 845719 on Cortex-A53 parts up to r0p4.
+
+	  When executing in aarch32 state at EL0, a load at EL0 from a
+	  virtual address that matches the bottom 32 bits of the virtual address
+	  used by a recent load at (aarch64) EL1 might return incorrect data.
+
+	  The workaround is to insert a write of the contextidr_el1 register
+	  on exception return to an aarch32 guest.
+	  Please note that this does not necessarily enable the workaround,
+	  as it depends on the alternative framework, which will only patch
+	  the kernel if an affected CPU is detected.
+
+	  If unsure, say Y.
+
 config ARM64_WORKAROUND_REPEAT_TLBI
 	bool
 
xen/arch/arm/arm64/entry.S +9 -0
index 175ea2981e..ef3336f34a 100644
@@ -96,6 +96,15 @@
         msr     SPSR_fiq, x22
         msr     SPSR_irq, x23
 
+#ifdef CONFIG_ARM64_ERRATUM_845719
+alternative_if ARM64_WORKAROUND_845719
+        /* contextidr_el1 is not accessible from aarch32 guest so we can
+         * write xzr to it
+         */
+        msr     contextidr_el1, xzr
+alternative_else_nop_endif
+#endif
+
         add     x21, sp, #UREGS_SPSR_und
         ldp     w22, w23, [x21]
         msr     SPSR_und, x22
xen/arch/arm/cpuerrata.c +8 -0
index b398d480f1..8959d4d4dc 100644
@@ -491,6 +491,14 @@ static const struct arm_cpu_capabilities arm_errata[] = {
         .capability = ARM_WORKAROUND_858921,
         MIDR_ALL_VERSIONS(MIDR_CORTEX_A73),
     },
+#endif
+#ifdef CONFIG_ARM64_ERRATUM_845719
+    {
+        /* Cortex-A53 r0p[01234] */
+        .desc = "ARM erratum 845719",
+        .capability = ARM64_WORKAROUND_845719,
+        MIDR_RANGE(MIDR_CORTEX_A53, 0x00, 0x04),
+    },
 #endif
     {
         /* Neoverse r0p0 - r2p0 */
xen/include/asm-arm/cpufeature.h +2 -1
index c7b5052992..1165a1eb62 100644
@@ -47,8 +47,9 @@
 #define ARM64_WORKAROUND_AT_SPECULATE 9
 #define ARM_WORKAROUND_858921 10
 #define ARM64_WORKAROUND_REPEAT_TLBI 11
+#define ARM64_WORKAROUND_845719 12
 
-#define ARM_NCAPS           12
+#define ARM_NCAPS           13
 
 #ifndef __ASSEMBLY__
 
Signature · 1 line
2.28.0
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 10 lines · Michal Orzel

When executing in aarch32 state at EL0, a load at EL0 from a virtual address that matches the bottom 32 bits of the virtual address used by a recent load at (aarch64) EL1 might return incorrect data.

The workaround is to insert a write of the contextidr_el1 register on exception return to an aarch32 guest.

Thanks
Bertrand

Quoted 107 lines

---

docs/misc/arm/silicon-errata.txt |  1 +
xen/arch/arm/Kconfig             | 19 +++++++++++++++++++
xen/arch/arm/arm64/entry.S       |  9 +++++++++
xen/arch/arm/cpuerrata.c         |  8 ++++++++
xen/include/asm-arm/cpufeature.h |  3 ++-
5 files changed, 39 insertions(+), 1 deletion(-)
docs/misc/arm/silicon-errata.txt +0 -0
index 27bf957ebf..fa3d9af63d 100644
@@ -45,6 +45,7 @@ stable hypervisors.
| ARM            | Cortex-A53      | #827319         | ARM64_ERRATUM_827319    |
| ARM            | Cortex-A53      | #824069         | ARM64_ERRATUM_824069    |
| ARM            | Cortex-A53      | #819472         | ARM64_ERRATUM_819472    |
+| ARM            | Cortex-A53      | #845719         | ARM64_ERRATUM_845719    |
| ARM            | Cortex-A55      | #1530923        | N/A                     |
| ARM            | Cortex-A57      | #852523         | N/A                     |
| ARM            | Cortex-A57      | #832075         | ARM64_ERRATUM_832075    |
xen/arch/arm/Kconfig +19 -0
index f5b1bcda03..6bea393555 100644
@@ -244,6 +244,25 @@ config ARM_ERRATUM_858921
 
 	  If unsure, say Y.
 
+config ARM64_ERRATUM_845719
+	bool "Cortex-A53: 845719: A load might read incorrect data"
+	default y
+	help
+	  This option adds an alternative code sequence to work around ARM
+	  erratum 845719 on Cortex-A53 parts up to r0p4.
+
+	  When executing in aarch32 state at EL0, a load at EL0 from a
+	  virtual address that matches the bottom 32 bits of the virtual address
+	  used by a recent load at (aarch64) EL1 might return incorrect data.
+
+	  The workaround is to insert a write of the contextidr_el1 register
+	  on exception return to an aarch32 guest.
+	  Please note that this does not necessarily enable the workaround,
+	  as it depends on the alternative framework, which will only patch
+	  the kernel if an affected CPU is detected.
+
+	  If unsure, say Y.
+

config ARM64_WORKAROUND_REPEAT_TLBI
bool

xen/arch/arm/arm64/entry.S +9 -0
index 175ea2981e..ef3336f34a 100644
@@ -96,6 +96,15 @@
        msr     SPSR_fiq, x22
        msr     SPSR_irq, x23
 
+#ifdef CONFIG_ARM64_ERRATUM_845719
+alternative_if ARM64_WORKAROUND_845719
+        /* contextidr_el1 is not accessible from aarch32 guest so we can
+         * write xzr to it
+         */
+        msr     contextidr_el1, xzr
+alternative_else_nop_endif
+#endif
+
        add     x21, sp, #UREGS_SPSR_und
        ldp     w22, w23, [x21]
        msr     SPSR_und, x22
xen/arch/arm/cpuerrata.c +8 -0
index b398d480f1..8959d4d4dc 100644
@@ -491,6 +491,14 @@ static const struct arm_cpu_capabilities arm_errata[] = {
        .capability = ARM_WORKAROUND_858921,
        MIDR_ALL_VERSIONS(MIDR_CORTEX_A73),
    },
+#endif
+#ifdef CONFIG_ARM64_ERRATUM_845719
+    {
+        /* Cortex-A53 r0p[01234] */
+        .desc = "ARM erratum 845719",
+        .capability = ARM64_WORKAROUND_845719,
+        MIDR_RANGE(MIDR_CORTEX_A53, 0x00, 0x04),
+    },
 #endif
    {
        /* Neoverse r0p0 - r2p0 */
xen/include/asm-arm/cpufeature.h +2 -1
index c7b5052992..1165a1eb62 100644
@@ -47,8 +47,9 @@
 #define ARM64_WORKAROUND_AT_SPECULATE 9
 #define ARM_WORKAROUND_858921 10
 #define ARM64_WORKAROUND_REPEAT_TLBI 11
+#define ARM64_WORKAROUND_845719 12
 
-#define ARM_NCAPS           12
+#define ARM_NCAPS           13
 
 #ifndef __ASSEMBLY__
 
Signature · 1 line
2.28.0
#2 lore raw
In reply to Michal Orzel

Hi,

Quoted 6 lines · Michal Orzel

When executing in aarch32 state at EL0, a load at EL0 from a virtual address that matches the bottom 32 bits of the virtual address used by a recent load at (aarch64) EL1 might return incorrect data.

The workaround is to insert a write of the contextidr_el1 register on exception return to an aarch32 guest.

I am a bit confused with this comment. In the previous paragraph, you are suggesting that the problem is an interaction between EL1 AArch64 and EL0 AArch32. But here you seem to imply the issue only happen when running a AArch32 guest.

Can you clarify it?

Quoted 57 lines
---
  docs/misc/arm/silicon-errata.txt |  1 +
  xen/arch/arm/Kconfig             | 19 +++++++++++++++++++
  xen/arch/arm/arm64/entry.S       |  9 +++++++++
  xen/arch/arm/cpuerrata.c         |  8 ++++++++
  xen/include/asm-arm/cpufeature.h |  3 ++-
  5 files changed, 39 insertions(+), 1 deletion(-)
docs/misc/arm/silicon-errata.txt +1 -0
index 27bf957ebf..fa3d9af63d 100644
@@ -45,6 +45,7 @@ stable hypervisors.
  | ARM            | Cortex-A53      | #827319         | ARM64_ERRATUM_827319    |
  | ARM            | Cortex-A53      | #824069         | ARM64_ERRATUM_824069    |
  | ARM            | Cortex-A53      | #819472         | ARM64_ERRATUM_819472    |
+| ARM            | Cortex-A53      | #845719         | ARM64_ERRATUM_845719    |
  | ARM            | Cortex-A55      | #1530923        | N/A                     |
  | ARM            | Cortex-A57      | #852523         | N/A                     |
  | ARM            | Cortex-A57      | #832075         | ARM64_ERRATUM_832075    |
xen/arch/arm/Kconfig +19 -0
index f5b1bcda03..6bea393555 100644
@@ -244,6 +244,25 @@ config ARM_ERRATUM_858921
 
  	  If unsure, say Y.
 
+config ARM64_ERRATUM_845719
+	bool "Cortex-A53: 845719: A load might read incorrect data"
+	default y
+	help
+	  This option adds an alternative code sequence to work around ARM
+	  erratum 845719 on Cortex-A53 parts up to r0p4.
+
+	  When executing in aarch32 state at EL0, a load at EL0 from a
+	  virtual address that matches the bottom 32 bits of the virtual address
+	  used by a recent load at (aarch64) EL1 might return incorrect data.
+
+	  The workaround is to insert a write of the contextidr_el1 register
+	  on exception return to an aarch32 guest.
+	  Please note that this does not necessarily enable the workaround,
+	  as it depends on the alternative framework, which will only patch
+	  the kernel if an affected CPU is detected.
+
+	  If unsure, say Y.
+
  config ARM64_WORKAROUND_REPEAT_TLBI
  	bool
 
xen/arch/arm/arm64/entry.S +0 -0
index 175ea2981e..ef3336f34a 100644

xen/arch/arm/arm64/entry.S line 103

Quoted 8 lines
xen/arch/arm/arm64/entry.S +5 -0
@@ -96,6 +96,15 @@
          msr     SPSR_fiq, x22
          msr     SPSR_irq, x23
 
+#ifdef CONFIG_ARM64_ERRATUM_845719
+alternative_if ARM64_WORKAROUND_845719
+        /* contextidr_el1 is not accessible from aarch32 guest so we can
+         * write xzr to it
+         */

This path is also used when the trapping occurs when running in EL0 aarch32. So wouldn't you clobber it if the EL1 AArch64 use it (Linux may store the PID in it)?

Also the coding style for multi-line comment in Xen is:

/*
* Foo
* Bar
*/

xen/arch/arm/arm64/entry.S line 106

Quoted 3 lines
xen/arch/arm/arm64/entry.S +3 -0
+        msr     contextidr_el1, xzr
+alternative_else_nop_endif
+#endif

Cheers,

Signature · 1 line
Julien Grall
#3 lore raw

Hi Julien,

Quoted 11 lines · Julien Grall

Hi,

Quoted 5 lines · Michal Orzel

When executing in aarch32 state at EL0, a load at EL0 from a virtual address that matches the bottom 32 bits of the virtual address used by a recent load at (aarch64) EL1 might return incorrect data. The workaround is to insert a write of the contextidr_el1 register on exception return to an aarch32 guest.

Quoted 3 lines

I am a bit confused with this comment. In the previous paragraph, you are suggesting that the problem is an interaction between EL1 AArch64 and EL0 AArch32. But here you seem to imply the issue only happen when running a AArch32 guest.

Can you clarify it?

This can happen when switching from an aarch64 guest to an aarch32 guest so not only when there is interaction.

Quoted 54 lines
Quoted 54 lines
---
 docs/misc/arm/silicon-errata.txt |  1 +
 xen/arch/arm/Kconfig             | 19 +++++++++++++++++++
 xen/arch/arm/arm64/entry.S       |  9 +++++++++
 xen/arch/arm/cpuerrata.c         |  8 ++++++++
 xen/include/asm-arm/cpufeature.h |  3 ++-
 5 files changed, 39 insertions(+), 1 deletion(-)
docs/misc/arm/silicon-errata.txt +1 -0
index 27bf957ebf..fa3d9af63d 100644
@@ -45,6 +45,7 @@ stable hypervisors.
 | ARM            | Cortex-A53      | #827319         | ARM64_ERRATUM_827319    |
 | ARM            | Cortex-A53      | #824069         | ARM64_ERRATUM_824069    |
 | ARM            | Cortex-A53      | #819472         | ARM64_ERRATUM_819472    |
+| ARM            | Cortex-A53      | #845719         | ARM64_ERRATUM_845719    |
 | ARM            | Cortex-A55      | #1530923        | N/A                     |
 | ARM            | Cortex-A57      | #852523         | N/A                     |
 | ARM            | Cortex-A57      | #832075         | ARM64_ERRATUM_832075    |
xen/arch/arm/Kconfig +18 -0
index f5b1bcda03..6bea393555 100644
@@ -244,6 +244,25 @@ config ARM_ERRATUM_858921
   	  If unsure, say Y.
 +config ARM64_ERRATUM_845719
+	bool "Cortex-A53: 845719: A load might read incorrect data"
+	default y
+	help
+	  This option adds an alternative code sequence to work around ARM
+	  erratum 845719 on Cortex-A53 parts up to r0p4.
+
+	  When executing in aarch32 state at EL0, a load at EL0 from a
+	  virtual address that matches the bottom 32 bits of the virtual address
+	  used by a recent load at (aarch64) EL1 might return incorrect data.
+
+	  The workaround is to insert a write of the contextidr_el1 register
+	  on exception return to an aarch32 guest.
+	  Please note that this does not necessarily enable the workaround,
+	  as it depends on the alternative framework, which will only patch
+	  the kernel if an affected CPU is detected.
+
+	  If unsure, say Y.
+
 config ARM64_WORKAROUND_REPEAT_TLBI
 	bool
 diff --git a/xen/arch/arm/arm64/entry.S b/xen/arch/arm/arm64/entry.S

index 175ea2981e..ef3336f34a 100644

xen/arch/arm/arm64/entry.S +0 -0
@@ -96,6 +96,15 @@
         msr     SPSR_fiq, x22
Quoted 8 lines

xen/arch/arm/arm64/entry.S line 103

Quoted 6 lines
xen/arch/arm/arm64/entry.S +4 -0
         msr     SPSR_irq, x23
 +#ifdef CONFIG_ARM64_ERRATUM_845719
+alternative_if ARM64_WORKAROUND_845719
+        /* contextidr_el1 is not accessible from aarch32 guest so we can
+         * write xzr to it
+         */

This path is also used when the trapping occurs when running in EL0 aarch32. So wouldn't you clobber it if the EL1 AArch64 use it (Linux may store the PID in it)?

Right we missed that.
In this case i would suggest to do something reading and then writting back in contextidr instead so that we do not clobber it.

Regards
Bertrand

Quoted 16 lines

Also the coding style for multi-line comment in Xen is:

/*
* Foo
* Bar
*/

xen/arch/arm/arm64/entry.S line 106

Quoted 3 lines
xen/arch/arm/arm64/entry.S +3 -0
+        msr     contextidr_el1, xzr
+alternative_else_nop_endif
+#endif

Cheers,

Signature · 1 line
Julien Grall
#4 lore raw
Quoted 13 lines · Bertrand Marquis

Hi Julien,

Quoted 11 lines · Julien Grall

Hi,

Quoted 5 lines · Michal Orzel

When executing in aarch32 state at EL0, a load at EL0 from a virtual address that matches the bottom 32 bits of the virtual address used by a recent load at (aarch64) EL1 might return incorrect data. The workaround is to insert a write of the contextidr_el1 register on exception return to an aarch32 guest.

Quoted 5 lines
Quoted 3 lines

I am a bit confused with this comment. In the previous paragraph, you are suggesting that the problem is an interaction between EL1 AArch64 and EL0 AArch32. But here you seem to imply the issue only happen when running a AArch32 guest.

Can you clarify it?

This can happen when switching from an aarch64 guest to an aarch32 guest so not only when there is interaction.

Right, but the context switch will write to CONTEXTIDR_EL1. So this case should already be handled.

Xen will never switch from AArch64 EL1 to AArch32 EL0 without a context switch (the inverse can happen if we inject an exception to the guest).

Reading the Cortex-A53 SDEN, it sounds like this is an OS and not Hypervisor problem. In fact, Linux only seems to workaround it when switching in the OS side rather than the hypervisor.

Therefore, I am not sure to understand why we need to workaroud it in Xen.

Cheers,

Signature · 1 line
Julien Grall
#5 lore raw
Quoted 19 lines · Julien Grall
Quoted 18 lines · Bertrand Marquis

Hi Julien,

Quoted 16 lines · Julien Grall

Hi,

Quoted 5 lines · Michal Orzel

When executing in aarch32 state at EL0, a load at EL0 from a virtual address that matches the bottom 32 bits of the virtual address used by a recent load at (aarch64) EL1 might return incorrect data. The workaround is to insert a write of the contextidr_el1 register on exception return to an aarch32 guest.

I am a bit confused with this comment. In the previous paragraph, you are suggesting that the problem is an interaction between EL1 AArch64 and EL0 AArch32. But here you seem to imply the issue only happen when running a AArch32 guest.

Quoted 4 lines
Quoted 4 lines
Quoted 1 line

Can you clarify it?

This can happen when switching from an aarch64 guest to an aarch32 guest so not only when there is interaction.

Just to confirm: it cannot happen when switching from aarch64 *EL2* to aarch32 EL0/1, right? Because that happens all the time in Xen.

Quoted 11 lines

Right, but the context switch will write to CONTEXTIDR_EL1. So this case should already be handled.

Xen will never switch from AArch64 EL1 to AArch32 EL0 without a context switch (the inverse can happen if we inject an exception to the guest).

Reading the Cortex-A53 SDEN, it sounds like this is an OS and not Hypervisor problem. In fact, Linux only seems to workaround it when switching in the OS side rather than the hypervisor.

Therefore, I am not sure to understand why we need to workaroud it in Xen.

It looks like Julien is right in regards to the "aarch64 EL1 to aarch32 EL0" issue.

#6 lore raw
Quoted 20 lines · Stefano Stabellini
Quoted 19 lines · Julien Grall
Quoted 18 lines · Bertrand Marquis

Hi Julien,

Quoted 16 lines · Julien Grall

Hi,

Quoted 5 lines · Michal Orzel

When executing in aarch32 state at EL0, a load at EL0 from a virtual address that matches the bottom 32 bits of the virtual address used by a recent load at (aarch64) EL1 might return incorrect data. The workaround is to insert a write of the contextidr_el1 register on exception return to an aarch32 guest.

I am a bit confused with this comment. In the previous paragraph, you are suggesting that the problem is an interaction between EL1 AArch64 and EL0 AArch32. But here you seem to imply the issue only happen when running a AArch32 guest.

Quoted 9 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

Can you clarify it?

This can happen when switching from an aarch64 guest to an aarch32 guest so not only when there is interaction.

Just to confirm: it cannot happen when switching from aarch64 *EL2* to aarch32 EL0/1, right? Because that happens all the time in Xen.

No it cannot. It can only happen when switching from aarch64 EL1 to aarch32 EL0.

Quoted 6 lines
Quoted 6 lines

Right, but the context switch will write to CONTEXTIDR_EL1. So this case should already be handled.

Xen will never switch from AArch64 EL1 to AArch32 EL0 without a context switch (the inverse can happen if we inject an exception to the guest).

Quoted 9 lines
Quoted 5 lines

Reading the Cortex-A53 SDEN, it sounds like this is an OS and not Hypervisor problem. In fact, Linux only seems to workaround it when switching in the OS side rather than the hypervisor.

Therefore, I am not sure to understand why we need to workaroud it in Xen.

It looks like Julien is right in regards to the "aarch64 EL1 to aarch32 EL0" issue.

Yes I agree. I missed the fact that there is a write to CONTEXTIDR_EL1 in 'ctxt_switch_to'. Let's abandon this.

Thanks,
Michal

#7 lore raw
Quoted 23 lines · Michal Orzel
Quoted 22 lines · Stefano Stabellini
Quoted 21 lines · Julien Grall
Quoted 20 lines · Bertrand Marquis

Hi Julien,

Quoted 17 lines · Julien Grall

Hi,

Quoted 5 lines · Michal Orzel

When executing in aarch32 state at EL0, a load at EL0 from a virtual address that matches the bottom 32 bits of the virtual address used by a recent load at (aarch64) EL1 might return incorrect data. The workaround is to insert a write of the contextidr_el1 register on exception return to an aarch32 guest.

I am a bit confused with this comment. In the previous paragraph, you are suggesting that the problem is an interaction between EL1 AArch64 and EL0 AArch32. But here you seem to imply the issue only happen when running a AArch32 guest.

Can you clarify it?

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

This can happen when switching from an aarch64 guest to an aarch32 guest so not only when there is interaction.

Just to confirm: it cannot happen when switching from aarch64 *EL2* to aarch32 EL0/1, right? Because that happens all the time in Xen.

No it cannot. It can only happen when switching from aarch64 EL1 to aarch32 EL0.

Excellent, thanks for checking

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

Right, but the context switch will write to CONTEXTIDR_EL1. So this case should already be handled.

Xen will never switch from AArch64 EL1 to AArch32 EL0 without a context switch (the inverse can happen if we inject an exception to the guest).

Reading the Cortex-A53 SDEN, it sounds like this is an OS and not Hypervisor problem. In fact, Linux only seems to workaround it when switching in the OS side rather than the hypervisor.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Therefore, I am not sure to understand why we need to workaroud it in Xen.

It looks like Julien is right in regards to the "aarch64 EL1 to aarch32 EL0" issue.

Yes I agree. I missed the fact that there is a write to CONTEXTIDR_EL1 in 'ctxt_switch_to'. Let's abandon this.

Job done :-)