target/hexagon: fix the allocframe framekey
PATCH 1/1 target/hexagon: fix the allocframe framekey
The frame that allocframe pushes is {LR, FP}, and what is scrambled is the LR word: FRAMEKEY is XOR'd into the upper 32 bits. The generated code for fFRAME_SCRAMBLE built the key from FRAMEKEY in both halves of a 64-bit value, so it scrambled FP as well. deallocframe and dealloc_return only undo the upper word, so a FP restored from a frame pushed with a non-zero FRAMEKEY was corrupt.
Uncovered by testing some boot images using QuRT.
--- target/hexagon/idef-parser/parser-helpers.c | 2 +- tests/tcg/hexagon/framekey.c | 67 +++++++++++++++++++++ tests/tcg/hexagon/meson.build | 1 + 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/hexagon/framekey.c
target/hexagon/idef-parser/parser-helpers.c +1 -1
@@ -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 +67 -0
67 lines not on this page · raw message
tests/tcg/hexagon/meson.build +1 -0
@@ -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
Quoted 9 lines · Brian Cain
The frame that allocframe pushes is {LR, FP}, and what is scrambled is the LR word: FRAMEKEY is XOR'd into the upper 32 bits. The generated code for
fFRAME_SCRAMBLEbuilt the key from FRAMEKEY in both halves of a 64-bit value, so it scrambled FP as well. deallocframe anddealloc_returnonly undo the upper word, so a FP restored from a frame pushed with a non-zero FRAMEKEY was corrupt.Uncovered by testing some boot images using QuRT.
Quoted 8 lines
Signed-off-by Brian Cain <[email protected]>--- target/hexagon/idef-parser/parser-helpers.c | 2 +- tests/tcg/hexagon/framekey.c | 67 +++++++++++++++++++++ tests/tcg/hexagon/meson.build | 1 + 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/hexagon/framekey.c
Quoted 7 lines · Brian Cain
The frame that allocframe pushes is {LR, FP}, and what is scrambled is the LR word: FRAMEKEY is XOR'd into the upper 32 bits. The generated code for
fFRAME_SCRAMBLEbuilt the key from FRAMEKEY in both halves of a 64-bit value, so it scrambled FP as well. deallocframe anddealloc_returnonly undo the upper word, so a FP restored from a frame pushed with a non-zero FRAMEKEY was corrupt.
I think the commit message is not quite right. AFAICT the error only shows up when idef-parser is used, FRAMEKEY is not 0, and allocframe is followed by dealloc_return.
That also means the test doesn't cover the case that actually breaks, because it pops the frame with deallocframe. allocframe and deallocframe have the same bug, so FP comes back correct either way. Only the first check catches the bug, through the wrong FP word that allocframe stores in memory. The other checks pass with or without the fix.
Quoted 11 lines · Marco Liebel
Quoted 6 lines · Brian Cain
The frame that allocframe pushes is {LR, FP}, and what is scrambled is the LR word: FRAMEKEY is XOR'd into the upper 32 bits. The generated code for
fFRAME_SCRAMBLEbuilt the key from FRAMEKEY in both halves of a 64-bit value, so it scrambled FP as well. deallocframe anddealloc_returnonly undo the upper word, so a FP restored from a frame pushed with a non-zero FRAMEKEY was corrupt.I think the commit message is not quite right. AFAICT the error only shows up when idef-parser is used, FRAMEKEY is not 0, and allocframe is followed by
dealloc_return.
Quoted 6 lines
That also means the test doesn't cover the case that actually breaks, because it pops the frame with deallocframe. allocframe and deallocframe have the same bug, so FP comes back correct either way. Only the first check catches the bug, through the wrong FP word that allocframe stores in memory. The other checks pass with or without the fix.
fixed in v2: https://lore.kernel.org/qemu-devel/[email protected]/