Skip to contentSkip to conversation

panic_PAR refactoring

PATCH In review Michal Orzel 2 participants 6 messages Aug 25 – Aug 27

lore
Share & tools
lore
#0 lore raw

cover panic_PAR refactoring

Michal Orzel (2):
xen/arm: traps: report level 0 faults in panic_PAR() xen/arm: traps: drop unreachable stage 2 decoding from panic_PAR()

 xen/arch/arm/include/asm/processor.h |  3 ++-
 xen/arch/arm/traps.c                 | 25 +++++++++++++++++--------
 2 files changed, 19 insertions(+), 9 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/2 xen/arm: traps: report level 0 faults in panic_PAR()

decode_fsc() derives the fault level from the low two bits of the FSC, so level 0 is a valid output: FSC_FLT_TRANS is 0x04, i.e. "translation fault, level 0".

This is reachable on arm64 because xen_pgtable is the zeroeth-level root, but fsc_level_str() has no case for it and prints " (level invalid)" instead. At the time the function was created Xen used only three levels.

Add the missing case. On arm32 the zeroeth level does not exist, hence guard the case by CONFIG_ARM_64.

While at it, make decode_fsc() decode also address size faults.

---
 xen/arch/arm/include/asm/processor.h | 2 ++
 xen/arch/arm/traps.c                 | 8 ++++++++
 2 files changed, 10 insertions(+)
xen/arch/arm/include/asm/processor.h +2 -0
index a3753c317fff..509040a1cdc0 100644
@@ -521,6 +521,7 @@ extern register_t __cpu_logical_map[];
 /*
  * 543210 BIT
  * 00XXLL -- XX Fault Level LL
+ * ..00LL -- Address Size Fault LL
  * ..01LL -- Translation Fault LL
  * ..10LL -- Access Fault LL
  * ..11LL -- Permission Fault LL
@@ -534,6 +535,7 @@ extern register_t __cpu_logical_map[];
 #define FSC_TYPE_OTH   (_AC(0x02,U)<<4)
 #define FSC_TYPE_IMPL  (_AC(0x03,U)<<4)
 
+#define FSC_FLT_ADDR_SIZE (0x00)
 #define FSC_FLT_TRANS  (0x04)
 #define FSC_FLT_ACCESS (0x08)
 #define FSC_FLT_PERM   (0x0c)
xen/arch/arm/traps.c +8 -0
index 0c01f37ad6b4..dc0ec8a345ed 100644
@@ -307,6 +307,10 @@ static const char *decode_fsc(uint32_t fsc, int *level)
 
     switch ( fsc & 0x3f )
     {
+    case FSC_FLT_ADDR_SIZE ... FSC_FLT_ADDR_SIZE + 3:
+        msg = "Address size fault";
+        *level = fsc & FSC_LL_MASK;
+        break;
     case FSC_FLT_TRANS ... FSC_FLT_TRANS + 3:
         msg = "Translation fault";
         *level = fsc & FSC_LL_MASK;
@@ -363,6 +367,10 @@ static const char *fsc_level_str(int level)
     switch ( level )
     {
     case -1: return "";
+#ifdef CONFIG_ARM_64
+    /* On arm32 the zeroeth level does not exist */
+    case 0:  return " at level 0";
+#endif
     case 1:  return " at level 1";
     case 2:  return " at level 2";
     case 3:  return " at level 3";
Signature · 1 line
2.43.0
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] xen/arm: traps: report level 0 faults in panic_PAR()

On 8/25/26 09:23, Michal Orzel wrote:

Hello Michal

Quoted 8 lines

decode_fsc() derives the fault level from the low two bits of the FSC, so level 0 is a valid output: FSC_FLT_TRANS is 0x04, i.e. "translation fault, level 0".

This is reachable on arm64 because xen_pgtable is the zeroeth-level root, but fsc_level_str() has no case for it and prints " (level invalid)" instead. At the time the function was created Xen used only three levels.

Quoted 6 lines

Add the missing case. On arm32 the zeroeth level does not exist, hence guard the case by CONFIG_ARM_64.

While at it, make decode_fsc() decode also address size faults.

Patch looks ok to me, so:

but I have a comment below:

Quoted 41 lines
---
  xen/arch/arm/include/asm/processor.h | 2 ++
  xen/arch/arm/traps.c                 | 8 ++++++++
  2 files changed, 10 insertions(+)
xen/arch/arm/include/asm/processor.h +2 -0
index a3753c317fff..509040a1cdc0 100644
@@ -521,6 +521,7 @@ extern register_t __cpu_logical_map[];
  /*
   * 543210 BIT
   * 00XXLL -- XX Fault Level LL
+ * ..00LL -- Address Size Fault LL
   * ..01LL -- Translation Fault LL
   * ..10LL -- Access Fault LL
   * ..11LL -- Permission Fault LL
@@ -534,6 +535,7 @@ extern register_t __cpu_logical_map[];
  #define FSC_TYPE_OTH   (_AC(0x02,U)<<4)
  #define FSC_TYPE_IMPL  (_AC(0x03,U)<<4)
 
+#define FSC_FLT_ADDR_SIZE (0x00)
  #define FSC_FLT_TRANS  (0x04)
  #define FSC_FLT_ACCESS (0x08)
  #define FSC_FLT_PERM   (0x0c)
xen/arch/arm/traps.c +4 -0
index 0c01f37ad6b4..dc0ec8a345ed 100644
@@ -307,6 +307,10 @@ static const char *decode_fsc(uint32_t fsc, int *level)
 
      switch ( fsc & 0x3f )
      {
+    case FSC_FLT_ADDR_SIZE ... FSC_FLT_ADDR_SIZE + 3:
+        msg = "Address size fault";
+        *level = fsc & FSC_LL_MASK;
+        break;
      case FSC_FLT_TRANS ... FSC_FLT_TRANS + 3:
          msg = "Translation fault";
          *level = fsc & FSC_LL_MASK;

xen/arch/arm/traps.c static const char *fsc_level_str(int level) · line 373

Quoted 7 lines
xen/arch/arm/traps.c +4 -0
@@ -363,6 +367,10 @@ static const char *fsc_level_str(int level)
      switch ( level )
      {
      case -1: return "";
+#ifdef CONFIG_ARM_64
+    /* On arm32 the zeroeth level does not exist */
+    case 0:  return " at level 0";
+#endif

NIT: Before this patch fsc of 0x00 fell through to default, so it printed "Unknown Failure" and level stayed -1. After the patch Arm32 decodes 0x00 as an address size fault and sets *level = 0, while case 0: in fsc_level_str() is compiled out there, so the print becomes "Address size fault (level invalid)". So I would either drop the #ifdef (to keep the two hunks consistent), or not set the level on Arm32.

That said, I will not insist on the change, my R-b stands either way.

Quoted 3 lines
xen/arch/arm/traps.c +0 -0
      case 1:  return " at level 1";
      case 2:  return " at level 2";
      case 3:  return " at level 3";
#3 lore raw

Re: [PATCH 1/2] xen/arm: traps: report level 0 faults in panic_PAR()

Quoted 78 lines · Oleksandr Tyshchenko

On 8/25/26 09:23, Michal Orzel wrote:

Hello Michal

Quoted 8 lines

decode_fsc() derives the fault level from the low two bits of the FSC, so level 0 is a valid output: FSC_FLT_TRANS is 0x04, i.e. "translation fault, level 0".

This is reachable on arm64 because xen_pgtable is the zeroeth-level root, but fsc_level_str() has no case for it and prints " (level invalid)" instead. At the time the function was created Xen used only three levels.

Quoted 6 lines

Add the missing case. On arm32 the zeroeth level does not exist, hence guard the case by CONFIG_ARM_64.

While at it, make decode_fsc() decode also address size faults.

Patch looks ok to me, so:

but I have a comment below:

Quoted 41 lines
---
  xen/arch/arm/include/asm/processor.h | 2 ++
  xen/arch/arm/traps.c                 | 8 ++++++++
  2 files changed, 10 insertions(+)
xen/arch/arm/include/asm/processor.h +2 -0
index a3753c317fff..509040a1cdc0 100644
@@ -521,6 +521,7 @@ extern register_t __cpu_logical_map[];
  /*
   * 543210 BIT
   * 00XXLL -- XX Fault Level LL
+ * ..00LL -- Address Size Fault LL
   * ..01LL -- Translation Fault LL
   * ..10LL -- Access Fault LL
   * ..11LL -- Permission Fault LL
@@ -534,6 +535,7 @@ extern register_t __cpu_logical_map[];
  #define FSC_TYPE_OTH   (_AC(0x02,U)<<4)
  #define FSC_TYPE_IMPL  (_AC(0x03,U)<<4)
 
+#define FSC_FLT_ADDR_SIZE (0x00)
  #define FSC_FLT_TRANS  (0x04)
  #define FSC_FLT_ACCESS (0x08)
  #define FSC_FLT_PERM   (0x0c)
xen/arch/arm/traps.c +4 -0
index 0c01f37ad6b4..dc0ec8a345ed 100644
@@ -307,6 +307,10 @@ static const char *decode_fsc(uint32_t fsc, int *level)
 
      switch ( fsc & 0x3f )
      {
+    case FSC_FLT_ADDR_SIZE ... FSC_FLT_ADDR_SIZE + 3:
+        msg = "Address size fault";
+        *level = fsc & FSC_LL_MASK;
+        break;
      case FSC_FLT_TRANS ... FSC_FLT_TRANS + 3:
          msg = "Translation fault";
          *level = fsc & FSC_LL_MASK;

xen/arch/arm/traps.c static const char *fsc_level_str(int level) · line 373

Quoted 7 lines
xen/arch/arm/traps.c +4 -0
@@ -363,6 +367,10 @@ static const char *fsc_level_str(int level)
      switch ( level )
      {
      case -1: return "";
+#ifdef CONFIG_ARM_64
+    /* On arm32 the zeroeth level does not exist */
+    case 0:  return " at level 0";
+#endif
Quoted 6 lines

NIT: Before this patch fsc of 0x00 fell through to default, so it printed "Unknown Failure" and level stayed -1. After the patch Arm32 decodes 0x00 as an address size fault and sets *level = 0, while case 0:
in fsc_level_str() is compiled out there, so the print becomes "Address size fault (level invalid)". So I would either drop the #ifdef (to keep the two hunks consistent), or not set the level on Arm32.

Actually, FSC 0 means address size fault at...:
- on AArch64: level 0 OR translation table base register
- on AArch32: translation table base register
so I will say: "at level 0 or TTBR" and drop the #ifdef.

~Michal

#4 lore raw

PATCH 2/2 xen/arm: traps: drop unreachable stage 2 decoding from panic_PAR()

In reply to Michal Orzel

panic_PAR() is only called from va_to_par(), which translates using __va_to_par(), i.e. "at s1e2r" on arm64 and ATS1HR on arm32. Both perform an EL2 stage 1 only translation, so PAR.S (PAR_STAGE2) and PAR.PTW (PAR_STAGE21) can never be set.

This has been the case since commit a14447dbcf171 ("xen: arm: do not panic when failing to translate a guest address"), which made gva_to_par() and gva_to_ipa() return -EFAULT instead of calling panic_PAR() for guest translations.

Print stage 1 unconditionally and keep an ASSERT() to document the invariant. PAR_STAGE21 has no user left, so drop it. While at it, fix the spacing in the decode_fsc() call.

No functional change intended.

---
 xen/arch/arm/include/asm/processor.h |  1 -
 xen/arch/arm/traps.c                 | 17 +++++++++--------
 2 files changed, 9 insertions(+), 9 deletions(-)
xen/arch/arm/include/asm/processor.h +0 -1
index 509040a1cdc0..8ee8f88fb4cb 100644
@@ -507,7 +507,6 @@ extern register_t __cpu_logical_map[];
 /* .... If F == 1 */
 #define PAR_FSC_SHIFT   (1)
 #define PAR_FSC_MASK    (_AC(0x3f,U)<<PAR_FSC_SHIFT)
-#define PAR_STAGE21     (_AC(1,U)<<8)     /* Stage 2 Fault During Stage 1 Walk */
 #define PAR_STAGE2      (_AC(1,U)<<9)     /* Stage 2 Fault */
 
 /* If F == 0 */
xen/arch/arm/traps.c +9 -8
index dc0ec8a345ed..1c2bdb7d02c7 100644
@@ -382,16 +382,17 @@ void panic_PAR(uint64_t par)
 {
     const char *msg;
     int level = -1;
-    int stage = par & PAR_STAGE2 ? 2 : 1;
-    int second_in_first = !!(par & PAR_STAGE21);
 
-    msg = decode_fsc( (par&PAR_FSC_MASK) >> PAR_FSC_SHIFT, &level);
+    /*
+     * The only caller translates using "at s1e2r" (arm64) or ATS1HR
+     * (arm32), i.e. an EL2 stage 1 only translation.
+     */
+    ASSERT(!(par & PAR_STAGE2));
+
+    msg = decode_fsc((par & PAR_FSC_MASK) >> PAR_FSC_SHIFT, &level);
 
-    printk("PAR: %016"PRIx64": %s stage %d%s%s\n",
-           par, msg,
-           stage,
-           second_in_first ? " during second stage lookup" : "",
-           fsc_level_str(level));
+    printk("PAR: %016"PRIx64": %s stage 1%s\n",
+           par, msg, fsc_level_str(level));
 
     panic("Error during Hypervisor-to-physical address translation\n");
 }
Signature · 1 line
2.43.0
Reviewed-by on v1 2/2
#5 lore raw

Re: [PATCH 2/2] xen/arm: traps: drop unreachable stage 2 decoding from panic_PAR()

On 8/25/26 09:23, Michal Orzel wrote:

Hello Michal

Quoted 10 lines

panic_PAR() is only called from va_to_par(), which translates using __va_to_par(), i.e. "at s1e2r" on arm64 and ATS1HR on arm32. Both perform an EL2 stage 1 only translation, so PAR.S (PAR_STAGE2) and PAR.PTW (PAR_STAGE21) can never be set.

This has been the case since commit a14447dbcf171 ("xen: arm: do not panic when failing to translate a guest address"), which made gva_to_par() and gva_to_ipa() return -EFAULT instead of calling panic_PAR() for guest translations.

Quoted 7 lines

Print stage 1 unconditionally and keep an ASSERT() to document the invariant. PAR_STAGE21 has no user left, so drop it. While at it, fix the spacing in the decode_fsc() call.

No functional change intended.

Quoted 47 lines
---
  xen/arch/arm/include/asm/processor.h |  1 -
  xen/arch/arm/traps.c                 | 17 +++++++++--------
  2 files changed, 9 insertions(+), 9 deletions(-)
xen/arch/arm/include/asm/processor.h +0 -1
index 509040a1cdc0..8ee8f88fb4cb 100644
@@ -507,7 +507,6 @@ extern register_t __cpu_logical_map[];
  /* .... If F == 1 */
  #define PAR_FSC_SHIFT   (1)
  #define PAR_FSC_MASK    (_AC(0x3f,U)<<PAR_FSC_SHIFT)
-#define PAR_STAGE21     (_AC(1,U)<<8)     /* Stage 2 Fault During Stage 1 Walk */
  #define PAR_STAGE2      (_AC(1,U)<<9)     /* Stage 2 Fault */
 
  /* If F == 0 */
xen/arch/arm/traps.c +9 -8
index dc0ec8a345ed..1c2bdb7d02c7 100644
@@ -382,16 +382,17 @@ void panic_PAR(uint64_t par)
  {
      const char *msg;
      int level = -1;
-    int stage = par & PAR_STAGE2 ? 2 : 1;
-    int second_in_first = !!(par & PAR_STAGE21);
 
-    msg = decode_fsc( (par&PAR_FSC_MASK) >> PAR_FSC_SHIFT, &level);
+    /*
+     * The only caller translates using "at s1e2r" (arm64) or ATS1HR
+     * (arm32), i.e. an EL2 stage 1 only translation.
+     */
+    ASSERT(!(par & PAR_STAGE2));
+
+    msg = decode_fsc((par & PAR_FSC_MASK) >> PAR_FSC_SHIFT, &level);
 
-    printk("PAR: %016"PRIx64": %s stage %d%s%s\n",
-           par, msg,
-           stage,
-           second_in_first ? " during second stage lookup" : "",
-           fsc_level_str(level));
+    printk("PAR: %016"PRIx64": %s stage 1%s\n",
+           par, msg, fsc_level_str(level));
 
      panic("Error during Hypervisor-to-physical address translation\n");
  }