Skip to contentSkip to conversation

target/hexagon: fix allocframe FRAMEKEY scrambling

PATCH In review Brian Cain 2 participants 2 messages Oct 20 Arm/Amlogic Meson SoC support

lore
Share & tools
lore

Brian Cain

author
#0 lore raw

PATCH v2 1/1 target/hexagon: fix allocframe FRAMEKEY scrambling

The architecture scrambles only the LR word of the {FP, LR} frame that allocframe stores. With the idef parser enabled, fFRAME_SCRAMBLE built the XOR key with FRAMEKEY in both halves of the 64-bit value, so the stored FP was scrambled as well.

deallocframe is also parser-generated and applies the same incorrect transform a second time, which masks the error. dealloc_return uses the hand-written TCG implementation that correctly descrambles only LR, so it leaves FP corrupt when returning from a frame allocated by the parser.

Add a regression test that sets a nonzero FRAMEKEY, allocates a frame, and returns through dealloc_return to validate the restored FP.

Uncovered by testing some boot images using QuRT.

---
 target/hexagon/idef-parser/parser-helpers.c |  2 +-
 tests/tcg/hexagon/framekey.c                | 54 +++++++++++++++++++++
 tests/tcg/hexagon/meson.build               |  1 +
 3 files changed, 56 insertions(+), 1 deletion(-)
 create mode 100644 tests/tcg/hexagon/framekey.c
target/hexagon/idef-parser/parser-helpers.c +1 -1
index 49cc11fddd8..14840d98737 100644
@@ -1989,7 +1989,7 @@ HexValue gen_rvalue_fscr(Context *c, YYLTYPE *locp, HexValue *value)
     *value = gen_rvalue_extend(c, locp, value);
     OUT(c, locp, "gen_read_reg(", &frame_key, ", HEX_REG_FRAMEKEY);\n");
     OUT(c, locp, "tcg_gen_concat_i32_i64(",
-        &key, ", ", &frame_key, ", ", &frame_key, ");\n");
+        &key, ", tcg_constant_tl(0), ", &frame_key, ");\n");
     OUT(c, locp, "tcg_gen_xor_i64(", &res, ", ", value, ", ", &key, ");\n");
     return res;
 }
tests/tcg/hexagon/framekey.c new file +54 -0

54 lines not on this page · raw message

tests/tcg/hexagon/meson.build +1 -0
index a6ace4c77c2..0fd62ce7e4c 100644
@@ -68,6 +68,7 @@ tests += {
   'overflow.c': {'cflags': cflags, 'exe_name': 'hex-overflow'},
   'preg_alias.c': {'cflags': cflags},
   'dual_stores.c': {'cflags': cflags},
+  'framekey.c': {'cflags': cflags},
   'multi_result.c': {'cflags': cflags},
   'mem_noshuf.c': {'cflags': cflags},
   'mem_noshuf_exception.c': {'cflags': cflags},
Signature · 1 line
2.34.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 16 lines · Brian Cain

The architecture scrambles only the LR word of the {FP, LR} frame that allocframe stores. With the idef parser enabled, fFRAME_SCRAMBLE built the XOR key with FRAMEKEY in both halves of the 64-bit value, so the stored FP was scrambled as well.

deallocframe is also parser-generated and applies the same incorrect transform a second time, which masks the error. dealloc_return uses the hand-written TCG implementation that correctly descrambles only LR, so it leaves FP corrupt when returning from a frame allocated by the parser.

Add a regression test that sets a nonzero FRAMEKEY, allocates a frame, and returns through dealloc_return to validate the restored FP.

Uncovered by testing some boot images using QuRT.

Quoted 8 lines
---
 target/hexagon/idef-parser/parser-helpers.c |  2 +-
 tests/tcg/hexagon/framekey.c                | 54 +++++++++++++++++++++
 tests/tcg/hexagon/meson.build               |  1 +
 3 files changed, 56 insertions(+), 1 deletion(-)
 create mode 100644 tests/tcg/hexagon/framekey.c