Skip to contentSkip to conversation

xen/arm: Correctly support WARN_ON

PATCH Superseded Julien Grall 2 participants 6 messages Jul 1, 2014 – Jul 10, 2014

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/arm: Correctly support WARN_ON

Currently the hypervisor will hang if it hits a WARN_ON.

The implemention uses an undefined instruction, made ourself because ARM doesn't provide one, to implement BUG/ASSERT/WARN_ON, and sets up the different tables (one for each type) which contain useful information.

This is based on the x86 implementation (include/asm-x86/bug.h). Unfortunately the structure can't be shared because many ARM{32,64} gcc versions doesn't correctly support %c. The support of executing a function in an exception handler is also keep unimplemented on ARM.

TODO:
I haven't yet hook the code on ARM64 as I'm not sure how undefined instruction are handled. It looks like there is multiple way to get it via HSR.

---
 xen/arch/arm/arm32/traps.c      |    2 +-
 xen/arch/arm/traps.c            |   96 +++++++++++++++++++++++++++++++++++++++
 xen/arch/arm/xen.lds.S          |    8 ++++
 xen/include/asm-arm/bug.h       |   72 +++++++++++++++++++++++++++--
 xen/include/asm-arm/debugger.h  |    2 +-
 xen/include/asm-arm/processor.h |    2 +
 6 files changed, 177 insertions(+), 5 deletions(-)
xen/arch/arm/arm32/traps.c +1 -1
index ff0b945..f79edcb 100644
@@ -25,7 +25,7 @@
 
 asmlinkage void do_trap_undefined_instruction(struct cpu_user_regs *regs)
 {
-    do_unexpected_trap("Undefined Instruction", regs);
+    do_undefined_instruction(regs);
 }
 
 asmlinkage void do_trap_supervisor_call(struct cpu_user_regs *regs)
xen/arch/arm/traps.c +96 -0

108 lines not on this page · raw message

xen/arch/arm/xen.lds.S +8 -0
index be55dad..c7a47c2 100644
@@ -40,6 +40,14 @@ SECTIONS
   . = ALIGN(PAGE_SIZE);
   .rodata : {
         _srodata = .;          /* Read-only data */
+        /* Bug frames table */
+       __start_bug_frames = .;
+       *(.bug_frames.0)
+       __stop_bug_frames_0 = .;
+       *(.bug_frames.1)
+       __stop_bug_frames_1 = .;
+       *(.bug_frames.2)
+       __stop_bug_frames_2 = .;
        *(.rodata)
        *(.rodata.*)
         _erodata = .;          /* End of read-only data */
xen/include/asm-arm/bug.h +69 -3

79 lines not on this page · raw message

xen/include/asm-arm/debugger.h +1 -1
index 916860b..ac776ef 100644
@@ -1,7 +1,7 @@
 #ifndef __ARM_DEBUGGER_H__
 #define __ARM_DEBUGGER_H__
 
-#define debugger_trap_fatal(v, r) ((void) 0)
+#define debugger_trap_fatal(v, r) (0)
 #define debugger_trap_immediate() ((void) 0)
 
 #endif /* __ARM_DEBUGGER_H__ */
xen/include/asm-arm/processor.h +2 -0
index 3be86f1..ff24ef0 100644
@@ -480,6 +480,8 @@ void show_registers(struct cpu_user_regs *regs);
 
 void do_unexpected_trap(const char *msg, struct cpu_user_regs *regs);
 
+void do_undefined_instruction(struct cpu_user_regs *regs);
+
 void vcpu_regs_hyp_to_user(const struct vcpu *vcpu,
                            struct vcpu_guest_core_regs *regs);
 void vcpu_regs_user_to_hyp(struct vcpu *vcpu,
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 4 lines · Julien Grall

TODO:
I haven't yet hook the code on ARM64 as I'm not sure how undefined instruction are handled. It looks like there is multiple way to get it via HSR.

I think EC==0x00 (the catchall) is where it will end up "The attempted execution of an instruction bit patterns that has no allocated instruction at the current Exception level".

xen/include/asm-arm/bug.h line 30

Quoted 4 lines
xen/include/asm-arm/bug.h +4 -0
+/* ARM doesn't provide any undefined instruction, make our own based on
+ * a combination of bits which is not used by the instruction set
+ */
+#define BUG_INSTR 0xe7f000f0

Linux uses 0xe7f001f2. I'm not sure what the difference is but it seems safer to follow suit.

Ian.

#2 lore raw

Hi Ian,

Quoted 10 lines · Ian Campbell
Quoted 4 lines · Julien Grall

TODO:
I haven't yet hook the code on ARM64 as I'm not sure how undefined instruction are handled. It looks like there is multiple way to get it via HSR.

I think EC==0x00 (the catchall) is where it will end up "The attempted execution of an instruction bit patterns that has no allocated instruction at the current Exception level".

So if EC==0x00 I can safely assume this is a undefined instruction exception, right?

Quoted 7 lines

xen/include/asm-arm/bug.h line 30

Quoted 4 lines
xen/include/asm-arm/bug.h +4 -0
+/* ARM doesn't provide any undefined instruction, make our own based on
+ * a combination of bits which is not used by the instruction set
+ */
+#define BUG_INSTR 0xe7f000f0

Linux uses 0xe7f001f2. I'm not sure what the difference is but it seems safer to follow suit.

Linux uses multiple different undefined opcode (bug, debugger,...). This value is already used in Xen by dump_execution_state (see include/asm-arm/processor.h).

I don't see why we should change it.

Regards,

Signature · 1 line
Julien Grall
#3 lore raw
Quoted 10 lines · Julien Grall

Hi Ian,

Quoted 7 lines · Ian Campbell
Quoted 4 lines · Julien Grall

TODO:
I haven't yet hook the code on ARM64 as I'm not sure how undefined instruction are handled. It looks like there is multiple way to get it via HSR.

Quoted 6 lines
Quoted 3 lines

I think EC==0x00 (the catchall) is where it will end up "The attempted execution of an instruction bit patterns that has no allocated instruction at the current Exception level".

So if EC==0x00 I can safely assume this is a undefined instruction exception, right?

No, EC=0x00 is a catch all thing, I think you would need to work out which reason it was. It might be that having consulted the ARM ARM you decide that an undefined instruction is the only cause which applies to us.

Quoted 9 lines
Quoted 8 lines

xen/include/asm-arm/bug.h line 30

Quoted 5 lines
xen/include/asm-arm/bug.h +4 -0
+/* ARM doesn't provide any undefined instruction, make our own based on
+ * a combination of bits which is not used by the instruction set
+ */
+#define BUG_INSTR 0xe7f000f0

Linux uses 0xe7f001f2. I'm not sure what the difference is but it seems safer to follow suit.

Quoted 5 lines

Linux uses multiple different undefined opcode (bug, debugger,...). This value is already used in Xen by dump_execution_state (see include/asm-arm/processor.h).

I don't see why we should change it.

OK.

#4 lore raw
In reply to Julien Grall
Quoted 11 lines · Julien Grall

Currently the hypervisor will hang if it hits a WARN_ON.

The implemention uses an undefined instruction, made ourself because ARM doesn't provide one, to implement BUG/ASSERT/WARN_ON, and sets up the different tables (one for each type) which contain useful information.

This is based on the x86 implementation (include/asm-x86/bug.h). Unfortunately the structure can't be shared because many ARM{32,64} gcc versions doesn't correctly support %c. The support of executing a function in an exception handler is also keep unimplemented on ARM.

Quoted 5 lines

TODO:
I haven't yet hook the code on ARM64 as I'm not sure how undefined instruction are handled. It looks like there is multiple way to get it via HSR.

Apart from the lack of arm64 support this looks good to me.

Ian.

#5 lore raw
Quoted 12 lines · Ian Campbell
Quoted 11 lines · Julien Grall

Currently the hypervisor will hang if it hits a WARN_ON.

The implemention uses an undefined instruction, made ourself because ARM doesn't provide one, to implement BUG/ASSERT/WARN_ON, and sets up the different tables (one for each type) which contain useful information.

This is based on the x86 implementation (include/asm-x86/bug.h). Unfortunately the structure can't be shared because many ARM{32,64} gcc versions doesn't correctly support %c. The support of executing a function in an exception handler is also keep unimplemented on ARM.

Quoted 7 lines
Quoted 5 lines

TODO:
I haven't yet hook the code on ARM64 as I'm not sure how undefined instruction are handled. It looks like there is multiple way to get it via HSR.

Apart from the lack of arm64 support this looks good to me.

I will try to send a new version with the arm64 support next week.

Regards,

Signature · 1 line
Julien Grall