mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 18:50:05 +01:00
x86/traps: move pv_inject_event to pv/traps.c
Take the opportunity to rename "v" to "curr". No functional change. Signed-off-by: Wei Liu <wei.liu2@citrix.com> Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
This commit is contained in:
1 parent
b3f9e8bf7f
commit
970c4a2a19
2 files changed
+73
-69
No files matched your search
@@ -20,8 +20,12 @@
|
||||
*/
|
||||
|
||||
#include <xen/hypercall.h>
|
||||
#include <xen/lib.h>
|
||||
#include <xen/trace.h>
|
||||
|
||||
#include <asm/apic.h>
|
||||
#include <asm/shared.h>
|
||||
#include <asm/traps.h>
|
||||
|
||||
void do_entry_int82(struct cpu_user_regs *regs)
|
||||
{
|
||||
@@ -31,6 +35,75 @@ void do_entry_int82(struct cpu_user_regs *regs)
|
||||
pv_hypercall(regs);
|
||||
}
|
||||
|
||||
void pv_inject_event(const struct x86_event *event)
|
||||
{
|
||||
struct vcpu *curr = 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 = &curr->arch.pv_vcpu.trap_bounce;
|
||||
ti = &curr->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 )
|
||||
{
|
||||
curr->arch.pv_vcpu.ctrlreg[2] = event->cr2;
|
||||
arch_set_cr2(curr, event->cr2);
|
||||
|
||||
/* Re-set error_code.user flag appropriately for the guest. */
|
||||
error_code &= ~PFEC_user_mode;
|
||||
if ( !guest_kernel_mode(curr, 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(curr, 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
|
||||
|
||||
@@ -626,75 +626,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.
|
||||
|
||||