[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH for-next v3 07/22] x86/traps: move pv_inject_event to pv/traps.c
No functional change. Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx> --- xen/arch/x86/pv/traps.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++ xen/arch/x86/traps.c | 69 ---------------------------------------------- 2 files changed, 73 insertions(+), 69 deletions(-) diff --git a/xen/arch/x86/pv/traps.c b/xen/arch/x86/pv/traps.c index 350e7a1da4..79304704dd 100644 --- a/xen/arch/x86/pv/traps.c +++ b/xen/arch/x86/pv/traps.c @@ -22,10 +22,14 @@ #include <xen/event.h> #include <xen/guest_access.h> #include <xen/hypercall.h> +#include <xen/lib.h> #include <xen/sched.h> +#include <xen/trace.h> #include <asm/apic.h> #include <asm/debugreg.h> +#include <asm/shared.h> +#include <asm/traps.h> void do_entry_int82(struct cpu_user_regs *regs) { @@ -128,6 +132,75 @@ unsigned long do_get_debugreg(int reg) return -EINVAL; } +void pv_inject_event(const struct x86_event *event) +{ + struct vcpu *v = current; + struct cpu_user_regs *regs = guest_cpu_user_regs(); + struct trap_bounce *tb; + const struct trap_info *ti; + const uint8_t vector = event->vector; + unsigned int error_code = event->error_code; + bool use_error_code; + + ASSERT(vector == event->vector); /* Confirm no truncation. */ + if ( event->type == X86_EVENTTYPE_HW_EXCEPTION ) + { + ASSERT(vector < 32); + use_error_code = TRAP_HAVE_EC & (1u << vector); + } + else + { + ASSERT(event->type == X86_EVENTTYPE_SW_INTERRUPT); + use_error_code = false; + } + if ( use_error_code ) + ASSERT(error_code != X86_EVENT_NO_EC); + else + ASSERT(error_code == X86_EVENT_NO_EC); + + tb = &v->arch.pv_vcpu.trap_bounce; + ti = &v->arch.pv_vcpu.trap_ctxt[vector]; + + tb->flags = TBF_EXCEPTION; + tb->cs = ti->cs; + tb->eip = ti->address; + + if ( event->type == X86_EVENTTYPE_HW_EXCEPTION && + vector == TRAP_page_fault ) + { + v->arch.pv_vcpu.ctrlreg[2] = event->cr2; + arch_set_cr2(v, event->cr2); + + /* Re-set error_code.user flag appropriately for the guest. */ + error_code &= ~PFEC_user_mode; + if ( !guest_kernel_mode(v, regs) ) + error_code |= PFEC_user_mode; + + trace_pv_page_fault(event->cr2, error_code); + } + else + trace_pv_trap(vector, regs->rip, use_error_code, error_code); + + if ( use_error_code ) + { + tb->flags |= TBF_EXCEPTION_ERRCODE; + tb->error_code = error_code; + } + + if ( TI_GET_IF(ti) ) + tb->flags |= TBF_INTERRUPT; + + if ( unlikely(null_trap_bounce(v, tb)) ) + { + gprintk(XENLOG_WARNING, + "Unhandled %s fault/trap [#%d, ec=%04x]\n", + trapstr(vector), vector, error_code); + + if ( vector == TRAP_page_fault ) + show_page_walk(event->cr2); + } +} + /* * Local variables: * mode: C diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index e5a3c9ad1a..96f3ffffd6 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -627,75 +627,6 @@ void fatal_trap(const struct cpu_user_regs *regs, bool_t show_remote) (regs->eflags & X86_EFLAGS_IF) ? "" : ", IN INTERRUPT CONTEXT"); } -void pv_inject_event(const struct x86_event *event) -{ - struct vcpu *v = current; - struct cpu_user_regs *regs = guest_cpu_user_regs(); - struct trap_bounce *tb; - const struct trap_info *ti; - const uint8_t vector = event->vector; - unsigned int error_code = event->error_code; - bool use_error_code; - - ASSERT(vector == event->vector); /* Confirm no truncation. */ - if ( event->type == X86_EVENTTYPE_HW_EXCEPTION ) - { - ASSERT(vector < 32); - use_error_code = TRAP_HAVE_EC & (1u << vector); - } - else - { - ASSERT(event->type == X86_EVENTTYPE_SW_INTERRUPT); - use_error_code = false; - } - if ( use_error_code ) - ASSERT(error_code != X86_EVENT_NO_EC); - else - ASSERT(error_code == X86_EVENT_NO_EC); - - tb = &v->arch.pv_vcpu.trap_bounce; - ti = &v->arch.pv_vcpu.trap_ctxt[vector]; - - tb->flags = TBF_EXCEPTION; - tb->cs = ti->cs; - tb->eip = ti->address; - - if ( event->type == X86_EVENTTYPE_HW_EXCEPTION && - vector == TRAP_page_fault ) - { - v->arch.pv_vcpu.ctrlreg[2] = event->cr2; - arch_set_cr2(v, event->cr2); - - /* Re-set error_code.user flag appropriately for the guest. */ - error_code &= ~PFEC_user_mode; - if ( !guest_kernel_mode(v, regs) ) - error_code |= PFEC_user_mode; - - trace_pv_page_fault(event->cr2, error_code); - } - else - trace_pv_trap(vector, regs->rip, use_error_code, error_code); - - if ( use_error_code ) - { - tb->flags |= TBF_EXCEPTION_ERRCODE; - tb->error_code = error_code; - } - - if ( TI_GET_IF(ti) ) - tb->flags |= TBF_INTERRUPT; - - if ( unlikely(null_trap_bounce(v, tb)) ) - { - gprintk(XENLOG_WARNING, - "Unhandled %s fault/trap [#%d, ec=%04x]\n", - trapstr(vector), vector, error_code); - - if ( vector == TRAP_page_fault ) - show_page_walk(event->cr2); - } -} - /* * Called from asm to set up the MCE trapbounce info. * Returns 0 if no callback is set up, else 1. -- 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |