Skip to contentSkip to conversation

x86: move declaration of the exception_table to C

PATCH Superseded Roger Pau Monne 2 participants 4 messages Jan 26, 2018

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: move declaration of the exception_table to C

This makes the code cleaner because there's no need to declare the exception_table in assembly, and also fixes the following error when using clang's integrated assembler:

entry.S:834:15: error: unexpected token in '.rept' directive

        .rept 32 - ((. - exception_table) / 8)
              ^
entry.S:836:14: error: unmatched '.endr' directive
        .endr
             ^

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>

---
 xen/arch/x86/traps.c            | 19 +++++++++++++++++++
 xen/arch/x86/x86_64/entry.S     | 30 ------------------------------
 xen/include/asm-x86/processor.h |  1 +
 3 files changed, 20 insertions(+), 30 deletions(-)
xen/arch/x86/traps.c +19 -0
index a3e8f0c9b9..be95baafe1 100644
@@ -119,6 +119,25 @@ boolean_param("ler", opt_ler);
 #define stack_words_per_line 4
 #define ESP_BEFORE_EXCEPTION(regs) ((unsigned long *)regs->rsp)
 
+void (* const exception_table[TRAP_nr])(struct cpu_user_regs *regs) = {
+    [TRAP_divide_error] = do_trap,
+    [TRAP_debug] = do_debug,
+    [TRAP_nmi] = (void (*)(struct cpu_user_regs *))do_nmi,
+    [TRAP_int3] = do_int3,
+    [TRAP_overflow ... TRAP_bounds] = do_trap,
+    [TRAP_invalid_op] = do_invalid_op,
+    [TRAP_no_device] = do_device_not_available,
+    [TRAP_double_fault ... TRAP_copro_seg] = do_reserved_trap,
+    [TRAP_invalid_tss ... TRAP_stack_error] = do_trap,
+    [TRAP_gp_fault] = do_general_protection,
+    [TRAP_page_fault] = do_page_fault,
+    [TRAP_spurious_int] = do_reserved_trap,
+    [TRAP_copro_error ... TRAP_alignment_check] = do_trap,
+    [TRAP_machine_check] = (void (*)(struct cpu_user_regs *))do_machine_check,
+    [TRAP_simd_error] = do_trap,
+    [TRAP_virtualisation ... (TRAP_nr - 1)] = do_reserved_trap,
+};
+
 static void show_code(const struct cpu_user_regs *regs)
 {
     unsigned char insns_before[8] = {}, insns_after[16] = {};
xen/arch/x86/x86_64/entry.S +0 -30
index 710c0616ba..af703f6c06 100644
@@ -806,36 +806,6 @@ ENTRY(enable_nmis)
 GLOBAL(trap_nop)
         iretq
 
-
-
-.section .rodata, "a", @progbits
-
-ENTRY(exception_table)
-        .quad do_trap
-        .quad do_debug
-        .quad do_nmi
-        .quad do_int3
-        .quad do_trap
-        .quad do_trap
-        .quad do_invalid_op
-        .quad do_device_not_available
-        .quad do_reserved_trap /* double_fault - has its own entry. */
-        .quad do_reserved_trap /* coproc_seg_overrun - Intel 387 only. */
-        .quad do_trap
-        .quad do_trap
-        .quad do_trap
-        .quad do_general_protection
-        .quad do_page_fault
-        .quad do_reserved_trap /* Default PIC spurious irq - architecturally reserved. */
-        .quad do_trap
-        .quad do_trap
-        .quad do_machine_check
-        .quad do_trap
-        .rept TRAP_nr - ((. - exception_table) / 8)
-        .quad do_reserved_trap /* Architecturally reserved exceptions. */
-        .endr
-        .size exception_table, . - exception_table
-
 /* Table of automatically generated entry points.  One per vector. */
         .section .init.rodata, "a", @progbits
 GLOBAL(autogen_entrypoints)
xen/include/asm-x86/processor.h +1 -0
index e8c2f02e99..472e138f24 100644
@@ -501,6 +501,7 @@ DECLARE_TRAP_HANDLER(entry_int82);
 
 void trap_nop(void);
 void enable_nmis(void);
+void do_trap(struct cpu_user_regs *regs);
 void do_reserved_trap(struct cpu_user_regs *regs);
 
 void sysenter_entry(void);
Signature · 7 lines
2.15.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw
Quoted 4 lines · Roger Pau Monne

This makes the code cleaner because there's no need to declare the exception_table in assembly, and also fixes the following error when using clang's integrated assembler:

Quoted 8 lines

entry.S:834:15: error: unexpected token in '.rept' directive

        .rept 32 - ((. - exception_table) / 8)
              ^
entry.S:836:14: error: unmatched '.endr' directive
        .endr
             ^

Ooh nice.  One less item on my todo list.  However...

Quoted 14 lines

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>

---
 xen/arch/x86/traps.c            | 19 +++++++++++++++++++
 xen/arch/x86/x86_64/entry.S     | 30 ------------------------------
 xen/include/asm-x86/processor.h |  1 +
 3 files changed, 20 insertions(+), 30 deletions(-)
xen/arch/x86/traps.c +0 -0
index a3e8f0c9b9..be95baafe1 100644

xen/arch/x86/traps.c boolean_param("ler", opt_ler); · line 125

Quoted 7 lines
xen/arch/x86/traps.c +4 -0
@@ -119,6 +119,25 @@ boolean_param("ler", opt_ler);
 #define stack_words_per_line 4
 #define ESP_BEFORE_EXCEPTION(regs) ((unsigned long *)regs->rsp)
 
+void (* const exception_table[TRAP_nr])(struct cpu_user_regs *regs) = {
+    [TRAP_divide_error] = do_trap,
+    [TRAP_debug] = do_debug,
+    [TRAP_nmi] = (void (*)(struct cpu_user_regs *))do_nmi,

Cast to (void *) is probably better, and certainly shorter.

xen/arch/x86/traps.c boolean_param("ler", opt_ler); · line 138

Quoted 13 lines
xen/arch/x86/traps.c +13 -0
+    [TRAP_int3] = do_int3,
+    [TRAP_overflow ... TRAP_bounds] = do_trap,
+    [TRAP_invalid_op] = do_invalid_op,
+    [TRAP_no_device] = do_device_not_available,
+    [TRAP_double_fault ... TRAP_copro_seg] = do_reserved_trap,
+    [TRAP_invalid_tss ... TRAP_stack_error] = do_trap,
+    [TRAP_gp_fault] = do_general_protection,
+    [TRAP_page_fault] = do_page_fault,
+    [TRAP_spurious_int] = do_reserved_trap,
+    [TRAP_copro_error ... TRAP_alignment_check] = do_trap,
+    [TRAP_machine_check] = (void (*)(struct cpu_user_regs *))do_machine_check,
+    [TRAP_simd_error] = do_trap,
+    [TRAP_virtualisation ... (TRAP_nr - 1)] = do_reserved_trap,

Can we see about vertically aligning the assignments for neatness?

Also, I'd drop the do_reserve_trap and have the lookup check for a NULL pointer.  This is what we do on the hypercall path and is far less error prone to changes in this table.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
Quoted 30 lines · Andrew Cooper

xen/arch/x86/traps.c boolean_param("ler", opt_ler); · line 125

Quoted 12 lines · Roger Pau Monne
xen/arch/x86/traps.c +4 -0
index a3e8f0c9b9..be95baafe1 100644
@@ -119,6 +119,25 @@ boolean_param("ler", opt_ler);
 #define stack_words_per_line 4
 #define ESP_BEFORE_EXCEPTION(regs) ((unsigned long *)regs->rsp)
 
+void (* const exception_table[TRAP_nr])(struct cpu_user_regs *regs) = {
+    [TRAP_divide_error] = do_trap,
+    [TRAP_debug] = do_debug,
+    [TRAP_nmi] = (void (*)(struct cpu_user_regs *))do_nmi,

Cast to (void *) is probably better, and certainly shorter.

xen/arch/x86/traps.c boolean_param("ler", opt_ler); · line 138

Quoted 13 lines
xen/arch/x86/traps.c +13 -0
+    [TRAP_int3] = do_int3,
+    [TRAP_overflow ... TRAP_bounds] = do_trap,
+    [TRAP_invalid_op] = do_invalid_op,
+    [TRAP_no_device] = do_device_not_available,
+    [TRAP_double_fault ... TRAP_copro_seg] = do_reserved_trap,
+    [TRAP_invalid_tss ... TRAP_stack_error] = do_trap,
+    [TRAP_gp_fault] = do_general_protection,
+    [TRAP_page_fault] = do_page_fault,
+    [TRAP_spurious_int] = do_reserved_trap,
+    [TRAP_copro_error ... TRAP_alignment_check] = do_trap,
+    [TRAP_machine_check] = (void (*)(struct cpu_user_regs *))do_machine_check,
+    [TRAP_simd_error] = do_trap,
+    [TRAP_virtualisation ... (TRAP_nr - 1)] = do_reserved_trap,
Quoted 1 line

Can we see about vertically aligning the assignments for neatness?

Done for both of the above.

Quoted 3 lines

Also, I'd drop the do_reserve_trap and have the lookup check for a NULL pointer.  This is what we do on the hypercall path and is far less error prone to changes in this table.

I would rather do that in a separate change, since this is non-functional. Do you think that's fine?

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
Quoted 29 lines · Roger Pau Monné
Quoted 28 lines · Andrew Cooper

xen/arch/x86/traps.c boolean_param("ler", opt_ler); · line 125

Quoted 12 lines · Roger Pau Monne
xen/arch/x86/traps.c +4 -0
index a3e8f0c9b9..be95baafe1 100644
@@ -119,6 +119,25 @@ boolean_param("ler", opt_ler);
 #define stack_words_per_line 4
 #define ESP_BEFORE_EXCEPTION(regs) ((unsigned long *)regs->rsp)
 
+void (* const exception_table[TRAP_nr])(struct cpu_user_regs *regs) = {
+    [TRAP_divide_error] = do_trap,
+    [TRAP_debug] = do_debug,
+    [TRAP_nmi] = (void (*)(struct cpu_user_regs *))do_nmi,

Cast to (void *) is probably better, and certainly shorter.

Quoted 13 lines
xen/arch/x86/traps.c +13 -0
+    [TRAP_int3] = do_int3,
+    [TRAP_overflow ... TRAP_bounds] = do_trap,
+    [TRAP_invalid_op] = do_invalid_op,
+    [TRAP_no_device] = do_device_not_available,
+    [TRAP_double_fault ... TRAP_copro_seg] = do_reserved_trap,
+    [TRAP_invalid_tss ... TRAP_stack_error] = do_trap,
+    [TRAP_gp_fault] = do_general_protection,
+    [TRAP_page_fault] = do_page_fault,
+    [TRAP_spurious_int] = do_reserved_trap,
+    [TRAP_copro_error ... TRAP_alignment_check] = do_trap,
+    [TRAP_machine_check] = (void (*)(struct cpu_user_regs *))do_machine_check,
+    [TRAP_simd_error] = do_trap,
+    [TRAP_virtualisation ... (TRAP_nr - 1)] = do_reserved_trap,
Quoted 8 lines
Quoted 1 line

Can we see about vertically aligning the assignments for neatness?

Done for both of the above.

Quoted 3 lines

Also, I'd drop the do_reserve_trap and have the lookup check for a NULL pointer.  This is what we do on the hypercall path and is far less error prone to changes in this table.

I would rather do that in a separate change, since this is non-functional. Do you think that's fine?

Hmm ok, so long as the (TRAP_nr - 1) changes to ARRAY_SIZE() - 1 to make one of the failure modes failsafe.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel