Skip to contentSkip to conversation

target/arm: Set debug in attrs in translate_for_debug()

PATCH In review Peter Maydell 3 participants 4 messages May 15 – May 16

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/arm: Set debug in attrs in translate_for_debug()

The translate_for_debug method is supposed to return attributes that include the debug flag being set. We forgot this when implementing the method for Arm.

Fixes abefca8e7f957 ("target/arm: Implement translate_for_debug")
---
 target/arm/ptw.c | 1 +
 1 file changed, 1 insertion(+)
target/arm/ptw.c +1 -0
index 8706dd59dd..0693d2867e 100644
@@ -3961,6 +3961,7 @@ static bool arm_cpu_get_phys_addr(CPUARMState *env, vaddr addr,
         /* translation succeeded */
         result->physaddr = res.f.phys_addr;
         result->attrs = res.f.attrs;
+        result->attrs.debug = 1;
         result->lg_page_size = res.f.lg_page_size;
     }
     return fault;
Signature · 1 line
2.43.0
#1 lore raw
Quoted 15 lines · Peter Maydell

The translate_for_debug method is supposed to return attributes that include the debug flag being set. We forgot this when implementing the method for Arm.

Fixes abefca8e7f957 ("target/arm: Implement translate_for_debug")
---
  target/arm/ptw.c | 1 +
  1 file changed, 1 insertion(+)
target/arm/ptw.c +0 -0
index 8706dd59dd..0693d2867e 100644

target/arm/ptw.c static bool arm_cpu_get_phys_addr(CPUARMState *env, vaddr addr, · line 3964

Quoted 4 lines
target/arm/ptw.c +1 -0
@@ -3961,6 +3961,7 @@ static bool arm_cpu_get_phys_addr(CPUARMState *env, vaddr addr,
          /* translation succeeded */
          result->physaddr = res.f.phys_addr;
          result->attrs = res.f.attrs;
+        result->attrs.debug = 1;

I missed that because thought we'd set it on success in cpu_translate_for_debug(), but we only do it for the fallback case. Shouldn't it be safer to set it there instead?

Otherwise I'd expect the bit set in arm_cpu_translate_for_debug(). not in arm_cpu_get_phys_addr(). WDYT?

Quoted 3 lines
target/arm/ptw.c +0 -0
          result->lg_page_size = res.f.lg_page_size;
      }
      return fault;
#2 lore raw
Quoted 12 lines · Philippe Mathieu-Daudé
Quoted 10 lines · Peter Maydell

The translate_for_debug method is supposed to return attributes that include the debug flag being set. We forgot this when implementing the method for Arm.

Fixes abefca8e7f957 ("target/arm: Implement translate_for_debug")
---
  target/arm/ptw.c | 1 +
  1 file changed, 1 insertion(+)
Quoted 13 lines

target/arm/ptw.c static bool arm_cpu_get_phys_addr(CPUARMState *env, vaddr addr, · line 3964

Quoted 9 lines
target/arm/ptw.c +1 -0
index 8706dd59dd..0693d2867e 100644
@@ -3961,6 +3961,7 @@ static bool arm_cpu_get_phys_addr(CPUARMState *env, vaddr addr,
          /* translation succeeded */
          result->physaddr = res.f.phys_addr;
          result->attrs = res.f.attrs;
+        result->attrs.debug = 1;

I missed that because thought we'd set it on success in cpu_translate_for_debug(), but we only do it for the fallback case. Shouldn't it be safer to set it there instead?

Mmm. The idea of the method was "the implementation should set the attributes entirely, not set them partially and then have them adjusted by the wrapper function"; also it's a bit confusing if the semantics of the wrapper function aren't the same as the semantics of the method proper. On the other hand, it is a bit of an easy mistake to make, so the API as it stands is a bit bug-prone.

Quoted 2 lines

Otherwise I'd expect the bit set in arm_cpu_translate_for_debug(). not in arm_cpu_get_phys_addr(). WDYT?

I went for arm_cpu_get_phys_addr() because it's this function that sets ".in_debug = true" in the S1Translate struct it uses, so it matches that it also sets the attributes to match that.

The arm_cpu_get_phys_addr() function is a bit misnamed by this point -- it would probably be clearer to name it translate_for_debug_for_mmuidx() or something similar, since it's just a helper function that has the same API as translate_for_debug() but takes the mmuidx to use.

-- PMM

Reviewed-by on v1 1/1
#3 lore raw
In reply to Peter Maydell
Quoted 15 lines · Peter Maydell

The translate_for_debug method is supposed to return attributes that include the debug flag being set. We forgot this when implementing the method for Arm.

Fixes abefca8e7f957 ("target/arm: Implement translate_for_debug")
---
  target/arm/ptw.c | 1 +
  1 file changed, 1 insertion(+)
target/arm/ptw.c +0 -0
index 8706dd59dd..0693d2867e 100644

target/arm/ptw.c static bool arm_cpu_get_phys_addr(CPUARMState *env, vaddr addr, · line 3967

Quoted 7 lines
target/arm/ptw.c +1 -0
@@ -3961,6 +3961,7 @@ static bool arm_cpu_get_phys_addr(CPUARMState *env, vaddr addr,
          /* translation succeeded */
          result->physaddr = res.f.phys_addr;
          result->attrs = res.f.attrs;
+        result->attrs.debug = 1;
          result->lg_page_size = res.f.lg_page_size;
      }
      return fault;

r~