Skip to contentSkip to conversation

target/arm: Generate UNDEF for 32-bit Thumb2 insns

PATCH In review Peter Maydell 4 participants 7 messages Dec 11, 2017 – Dec 12, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/arm: Generate UNDEF for 32-bit Thumb2 insns

The refactoring of commit 296e5a0a6c3935 has a nasty bug:
it accidentally dropped the generation of code to raise the UNDEF exception when disas_thumb2_insn() returns nonzero. This means that 32-bit Thumb2 instruction patterns that ought to UNDEF just act like nops instead. This is likely to break any number of things, including the kernel's "disable the FPU and use the UNDEF exception to identify when to turn it back on again" trick.

---
This is the smallest possible fix that will correct the bug, for possible inclusion in 2.11; for 2.12 we should fix the asymmetry where disas_thumb() generates its own exception-raising code but disas_thumb2() wants the caller to do it. (This asymmetry is why we didn't notice the problem in code review.)

I'm not sure whether this should go into 2.11 or not -- this time last week it would have been an easy "yes".

---
 target/arm/translate.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
target/arm/translate.c +4 -1
index 4afb0c8..f120932 100644
@@ -12245,7 +12245,10 @@ static void thumb_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)
     if (is_16bit) {
         disas_thumb_insn(dc, insn);
     } else {
-        disas_thumb2_insn(dc, insn);
+        if (disas_thumb2_insn(dc, insn)) {
+            gen_exception_insn(dc, 4, EXCP_UDEF, syn_uncategorized(),
+                               default_exception_el(dc));
+        }
     }
 
     /* Advance the Thumb condexec condition.  */
Signature · 1 line
2.7.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 18 lines · Peter Maydell

The refactoring of commit 296e5a0a6c3935 has a nasty bug:
it accidentally dropped the generation of code to raise the UNDEF exception when disas_thumb2_insn() returns nonzero. This means that 32-bit Thumb2 instruction patterns that ought to UNDEF just act like nops instead. This is likely to break any number of things, including the kernel's "disable the FPU and use the UNDEF exception to identify when to turn it back on again" trick.

---
This is the smallest possible fix that will correct the bug, for possible inclusion in 2.11; for 2.12 we should fix the asymmetry where disas_thumb() generates its own exception-raising code but disas_thumb2() wants the caller to do it. (This asymmetry is why we didn't notice the problem in code review.)

Quoted 2 lines

I'm not sure whether this should go into 2.11 or not -- this time last week it would have been an easy "yes".

r~

#2 lore raw
Quoted 19 lines · Richard Henderson
Quoted 18 lines · Peter Maydell

The refactoring of commit 296e5a0a6c3935 has a nasty bug:
it accidentally dropped the generation of code to raise the UNDEF exception when disas_thumb2_insn() returns nonzero. This means that 32-bit Thumb2 instruction patterns that ought to UNDEF just act like nops instead. This is likely to break any number of things, including the kernel's "disable the FPU and use the UNDEF exception to identify when to turn it back on again" trick.

---
This is the smallest possible fix that will correct the bug, for possible inclusion in 2.11; for 2.12 we should fix the asymmetry where disas_thumb() generates its own exception-raising code but disas_thumb2() wants the caller to do it. (This asymmetry is why we didn't notice the problem in code review.)

Quoted 4 lines
Quoted 2 lines

I'm not sure whether this should go into 2.11 or not -- this time last week it would have been an easy "yes".

Thanks. I think I have come down on the side of putting this into 2.11, so rolling an rc5 today, and delaying the final release a day to Wednesday.

thanks
-- PMM

#3 lore raw
Quoted 3 lines · Peter Maydell

Thanks. I think I have come down on the side of putting this into 2.11, so rolling an rc5 today, and delaying the final release a day to Wednesday.

Glad to see it's in -rc5 -- thanks for fixing this so quickly!

Again, apologies for not having caught this earlier ;-(

Emilio

#4 lore raw
Quoted 8 lines · Emilio G. Cota
Quoted 3 lines · Peter Maydell

Thanks. I think I have come down on the side of putting this into 2.11, so rolling an rc5 today, and delaying the final release a day to Wednesday.

Glad to see it's in -rc5 -- thanks for fixing this so quickly!

Again, apologies for not having caught this earlier ;-(

It's my own fault really -- my extremely ad-hoc approach to testing for Arm guests was bound to come back and bite me sooner or later.

thanks
-- PMM

#5 lore raw
Quoted 6 lines · Peter Maydell
Quoted 5 lines · Emilio G. Cota
Quoted 3 lines · Peter Maydell

Thanks. I think I have come down on the side of putting this into 2.11, so rolling an rc5 today, and delaying the final release a day to Wednesday.

Quoted 7 lines
Quoted 3 lines

Glad to see it's in -rc5 -- thanks for fixing this so quickly!

Again, apologies for not having caught this earlier ;-(

It's my own fault really -- my extremely ad-hoc approach to testing for Arm guests was bound to come back and bite me sooner or later.

Should we include the vfio fix in too for rc5?

http://patchwork.ozlabs.org/patch/844940/

I see that the tag is there already, not sure whether it means it missed the chance again... Thanks,

Signature · 1 line
Peter Xu
#6 lore raw
Quoted 15 lines · Peter Xu
Quoted 6 lines · Peter Maydell
Quoted 5 lines · Emilio G. Cota
Quoted 3 lines · Peter Maydell

Thanks. I think I have come down on the side of putting this into 2.11, so rolling an rc5 today, and delaying the final release a day to Wednesday.

Quoted 7 lines
Quoted 3 lines

Glad to see it's in -rc5 -- thanks for fixing this so quickly!

Again, apologies for not having caught this earlier ;-(

It's my own fault really -- my extremely ad-hoc approach to testing for Arm guests was bound to come back and bite me sooner or later.

Quoted 6 lines

Should we include the vfio fix in too for rc5?

http://patchwork.ozlabs.org/patch/844940/

I see that the tag is there already, not sure whether it means it missed the chance again... Thanks,

It did miss the chance, but in any case that vfio fix is not a regression from 2.10, so it doesn't meet the criteria to go in now.

thanks
-- PMM