From: Andrew Cooper Date: Sat, 2 Mar 2024 23:01:58 +0000 (+0000) Subject: XTF: Drop exlog X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=216cfe04a0d7db93d6fd5589e66670d1c4bc61cd;p=xtf.git XTF: Drop exlog This was the original exception tracking infrastructure, but exinfo_t/ex_record is far more convenient for tests to use. The selftest already had a non-handler form extable. Update test_NULL_unmapped() to use the handler form, and drop test_exlog(). Signed-off-by: Andrew Cooper --- diff --git a/arch/x86/traps.c b/arch/x86/traps.c index 1ea5dd1..1f82752 100644 --- a/arch/x86/traps.c +++ b/arch/x86/traps.c @@ -1,6 +1,5 @@ #include #include -#include #include #include @@ -25,8 +24,6 @@ void do_exception(struct cpu_regs *regs) const struct extable_entry *ex; bool safe = false; - xtf_exlog_log_exception(regs); - /* Look in the exception table to see if a redirection has been set up. */ if ( !safe && (ex = search_extable(regs->ip)) ) { diff --git a/build/files.mk b/build/files.mk index 97ce795..11624a8 100644 --- a/build/files.mk +++ b/build/files.mk @@ -5,7 +5,6 @@ # obj-$(env) are objects unique to a specific environment obj-perbits += $(ROOT)/common/console.o -obj-perbits += $(ROOT)/common/exlog.o obj-perbits += $(ROOT)/common/extable.o obj-perbits += $(ROOT)/common/grant_table.o obj-perbits += $(ROOT)/common/heapsort.o diff --git a/common/exlog.c b/common/exlog.c deleted file mode 100644 index f9a0735..0000000 --- a/common/exlog.c +++ /dev/null @@ -1,83 +0,0 @@ -#include -#include -#include - -static bool logging = false; -static unsigned int log_entries; - -static exlog_entry_t log[8]; - -void xtf_exlog_start(void) -{ - logging = true; - log_entries = 0; -} - -void xtf_exlog_reset(void) -{ - log_entries = 0; -} - -void xtf_exlog_stop(void) -{ - logging = false; -} - - -unsigned int xtf_exlog_entries(void) -{ - return log_entries; -} - -exlog_entry_t *xtf_exlog_entry(unsigned int idx) -{ - if ( idx < ARRAY_SIZE(log) && idx < log_entries ) - return &log[idx]; - return NULL; -} - -void xtf_exlog_log_exception(struct cpu_regs *regs) -{ - if ( !logging ) - return; - - if ( log_entries < ARRAY_SIZE(log) ) - { - exlog_entry_t *e = &log[log_entries]; - - e->ip = regs->ip; - e->cs = regs->cs; - e->ec = regs->error_code; - e->ev = regs->entry_vector; - } - else - { - printk("Exception log full\n"); - xtf_exlog_dump_log(); - panic("Exception log full\n"); - } - - log_entries++; -} - -void xtf_exlog_dump_log(void) -{ - unsigned int i; - - if ( log_entries == 0 ) - printk("No exception log entries\n"); - else - for ( i = 0; i < ARRAY_SIZE(log) && i < log_entries; ++i ) - printk(" exlog[%02u] %04x:%p vec %u[%04x]\n", - i, log[i].cs, _p(log[i].ip), log[i].ev, log[i].ec); -} - -/* - * Local variables: - * mode: C - * c-file-style: "BSD" - * c-basic-offset: 4 - * tab-width: 4 - * indent-tabs-mode: nil - * End: - */ diff --git a/include/xtf.h b/include/xtf.h index fef08df..292052f 100644 --- a/include/xtf.h +++ b/include/xtf.h @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include diff --git a/include/xtf/exlog.h b/include/xtf/exlog.h deleted file mode 100644 index 8f17e78..0000000 --- a/include/xtf/exlog.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef XTF_EXLOG_H -#define XTF_EXLOG_H - -#include -#include - -void xtf_exlog_start(void); -void xtf_exlog_reset(void); -void xtf_exlog_stop(void); - -typedef struct exlog_entry -{ - unsigned long ip; - uint16_t cs, ec, ev; -} exlog_entry_t; - -unsigned int xtf_exlog_entries(void); -exlog_entry_t *xtf_exlog_entry(unsigned int idx); - -void xtf_exlog_log_exception(struct cpu_regs *regs); - -void xtf_exlog_dump_log(void); - -#endif /* XTF_EXLOG_H */ - -/* - * Local variables: - * mode: C - * c-file-style: "BSD" - * c-basic-offset: 4 - * tab-width: 4 - * indent-tabs-mode: nil - * End: - */ diff --git a/tests/selftest/main.c b/tests/selftest/main.c index 5034613..3a34ea3 100644 --- a/tests/selftest/main.c +++ b/tests/selftest/main.c @@ -49,106 +49,6 @@ static void test_extable(void) _ASM_EXTABLE(1b, 2b)); } -static bool check_nr_entries(unsigned int nr) -{ - unsigned int entries = xtf_exlog_entries(); - - if ( entries != nr ) - { - xtf_failure("Fail: expected %u entries, got %u\n", - nr, entries); - return false; - } - - return true; -} - -static bool check_exlog_entry(unsigned int entry, unsigned int cs, - unsigned long ip, unsigned int ev, - unsigned int ec) -{ - exlog_entry_t *e = xtf_exlog_entry(entry); - - /* Check whether the log entry is available. */ - if ( !e ) - { - xtf_failure("Fail: unable to retrieve log entry %u\n", entry); - return false; - } - - /* Check whether the log entry is correct. */ - if ( (e->ip != ip) || (e->cs != cs) || (e->ec != ec) || (e->ev != ev) ) - { - xtf_failure("Fail: exlog entry:\n" - " Expected: %04x:%p, ec %04x, vec %u\n" - " Got: %04x:%p, ec %04x, vec %u\n", - cs, _p(ip), ec, ev, e->cs, _p(e->ip), e->ec, e->ev); - return false; - } - - return true; -} - -static void test_exlog(void) -{ - extern unsigned long exlog_int3[] asm(".Lexlog_int3"); - extern unsigned long exlog_ud2a[] asm(".Lexlog_ud2a"); - - printk("Test: Exception Logging\n"); - - xtf_exlog_start(); - - /* Check that no entries have been logged thus far. */ - if ( !check_nr_entries(0) ) - goto out; - - asm volatile ("int3; .Lexlog_int3:" - _ASM_TRAP_OK(.Lexlog_int3)); - - /* Check that one entry has now been logged. */ - if ( !check_nr_entries(1) || - !check_exlog_entry(0, __KERN_CS, _u(exlog_int3), X86_EXC_BP, 0) ) - goto out; - - asm volatile (".Lexlog_ud2a: ud2a; 1:" - _ASM_EXTABLE(.Lexlog_ud2a, 1b)); - - /* Check that two entries have now been logged. */ - if ( !check_nr_entries(2) || - !check_exlog_entry(1, __KERN_CS, _u(exlog_ud2a), X86_EXC_UD, 0) ) - goto out; - - xtf_exlog_reset(); - - /* Check that no entries now exist. */ - if ( !check_nr_entries(0) ) - goto out; - - asm volatile ("int3; 1:" - _ASM_TRAP_OK(1b)); - - /* Check that one entry now exists. */ - if ( !check_nr_entries(1) ) - goto out; - - xtf_exlog_stop(); - - /* Check that one entry still exists. */ - if ( !check_nr_entries(1) ) - goto out; - - asm volatile ("int3; 1:" - _ASM_TRAP_OK(1b)); - - /* Check that the previous breakpoint wasn't logged. */ - if ( !check_nr_entries(1) ) - goto out; - - out: - xtf_exlog_reset(); - xtf_exlog_stop(); -} - enum { USER_not_seen, USER_seen, @@ -186,21 +86,19 @@ static void test_exec_user(void) static void test_NULL_unmapped(void) { - extern unsigned long label_test_NULL_unmapped[]; - unsigned long tmp; + unsigned int tmp; + exinfo_t got = 0; printk("Test: NULL unmapped\n"); - xtf_exlog_start(); - - asm volatile ("label_test_NULL_unmapped: mov 0, %0; 2:" - _ASM_EXTABLE(label_test_NULL_unmapped, 2b) - : "=q" (tmp) :: "memory"); - - if ( check_nr_entries(1) ) - check_exlog_entry(0, __KERN_CS, _u(label_test_NULL_unmapped), X86_EXC_PF, 0); + asm volatile ("1: mov 0, %[tmp]; 2:" + _ASM_EXTABLE_HANDLER(1b, 2b, %P[rec]) + : "+a" (got), + [tmp] "=r" (tmp) + : [rec] "p" (ex_record_fault_eax)); - xtf_exlog_stop(); + if ( got != EXINFO_SYM(PF, 0) ) + xtf_failure("Fail: Expected #PF, got %pe\n", _p(got)); } bool do_unhandled_exception(struct cpu_regs *regs) @@ -394,7 +292,6 @@ void test_main(void) } test_extable(); - test_exlog(); test_exec_user(); if ( CONFIG_PAGING_LEVELS > 0 ) test_NULL_unmapped();