[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v4 23/27] x86: move the compat callback ops next to the non-compat variant
Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx> --- xen/arch/x86/pv/callback.c | 142 ++++++++++++++++++++++++++++++++++++ xen/arch/x86/x86_64/compat/traps.c | 143 ------------------------------------- 2 files changed, 142 insertions(+), 143 deletions(-) diff --git a/xen/arch/x86/pv/callback.c b/xen/arch/x86/pv/callback.c index dbd602c89d..00981d0f47 100644 --- a/xen/arch/x86/pv/callback.c +++ b/xen/arch/x86/pv/callback.c @@ -1,6 +1,7 @@ #include <xen/guest_access.h> #include <xen/lib.h> #include <xen/sched.h> +#include <compat/callback.h> #include <asm/current.h> #include <asm/nmi.h> @@ -155,3 +156,144 @@ long do_set_callbacks(unsigned long event_address, return 0; } +static long compat_register_guest_callback(struct compat_callback_register *reg) +{ + long ret = 0; + struct vcpu *v = current; + + fixup_guest_code_selector(v->domain, reg->address.cs); + + switch ( reg->type ) + { + case CALLBACKTYPE_event: + v->arch.pv_vcpu.event_callback_cs = reg->address.cs; + v->arch.pv_vcpu.event_callback_eip = reg->address.eip; + break; + + case CALLBACKTYPE_failsafe: + v->arch.pv_vcpu.failsafe_callback_cs = reg->address.cs; + v->arch.pv_vcpu.failsafe_callback_eip = reg->address.eip; + if ( reg->flags & CALLBACKF_mask_events ) + set_bit(_VGCF_failsafe_disables_events, + &v->arch.vgc_flags); + else + clear_bit(_VGCF_failsafe_disables_events, + &v->arch.vgc_flags); + break; + + case CALLBACKTYPE_syscall32: + v->arch.pv_vcpu.syscall32_callback_cs = reg->address.cs; + v->arch.pv_vcpu.syscall32_callback_eip = reg->address.eip; + v->arch.pv_vcpu.syscall32_disables_events = + (reg->flags & CALLBACKF_mask_events) != 0; + break; + + case CALLBACKTYPE_sysenter: + v->arch.pv_vcpu.sysenter_callback_cs = reg->address.cs; + v->arch.pv_vcpu.sysenter_callback_eip = reg->address.eip; + v->arch.pv_vcpu.sysenter_disables_events = + (reg->flags & CALLBACKF_mask_events) != 0; + break; + + case CALLBACKTYPE_nmi: + ret = register_guest_nmi_callback(reg->address.eip); + break; + + default: + ret = -ENOSYS; + break; + } + + return ret; +} + +static long compat_unregister_guest_callback( + struct compat_callback_unregister *unreg) +{ + long ret; + + switch ( unreg->type ) + { + case CALLBACKTYPE_event: + case CALLBACKTYPE_failsafe: + case CALLBACKTYPE_syscall32: + case CALLBACKTYPE_sysenter: + ret = -EINVAL; + break; + + case CALLBACKTYPE_nmi: + ret = unregister_guest_nmi_callback(); + break; + + default: + ret = -ENOSYS; + break; + } + + return ret; +} + + +long compat_callback_op(int cmd, XEN_GUEST_HANDLE(void) arg) +{ + long ret; + + switch ( cmd ) + { + case CALLBACKOP_register: + { + struct compat_callback_register reg; + + ret = -EFAULT; + if ( copy_from_guest(®, arg, 1) ) + break; + + ret = compat_register_guest_callback(®); + } + break; + + case CALLBACKOP_unregister: + { + struct compat_callback_unregister unreg; + + ret = -EFAULT; + if ( copy_from_guest(&unreg, arg, 1) ) + break; + + ret = compat_unregister_guest_callback(&unreg); + } + break; + + default: + ret = -EINVAL; + break; + } + + return ret; +} + +long compat_set_callbacks(unsigned long event_selector, + unsigned long event_address, + unsigned long failsafe_selector, + unsigned long failsafe_address) +{ + struct compat_callback_register event = { + .type = CALLBACKTYPE_event, + .address = { + .cs = event_selector, + .eip = event_address + } + }; + struct compat_callback_register failsafe = { + .type = CALLBACKTYPE_failsafe, + .address = { + .cs = failsafe_selector, + .eip = failsafe_address + } + }; + + compat_register_guest_callback(&event); + compat_register_guest_callback(&failsafe); + + return 0; +} diff --git a/xen/arch/x86/x86_64/compat/traps.c b/xen/arch/x86/x86_64/compat/traps.c index df691f0ae3..6e146a62a7 100644 --- a/xen/arch/x86/x86_64/compat/traps.c +++ b/xen/arch/x86/x86_64/compat/traps.c @@ -66,149 +66,6 @@ void compat_show_guest_stack(struct vcpu *v, const struct cpu_user_regs *regs, printk("\n"); } -static long compat_register_guest_callback( - struct compat_callback_register *reg) -{ - long ret = 0; - struct vcpu *v = current; - - fixup_guest_code_selector(v->domain, reg->address.cs); - - switch ( reg->type ) - { - case CALLBACKTYPE_event: - v->arch.pv_vcpu.event_callback_cs = reg->address.cs; - v->arch.pv_vcpu.event_callback_eip = reg->address.eip; - break; - - case CALLBACKTYPE_failsafe: - v->arch.pv_vcpu.failsafe_callback_cs = reg->address.cs; - v->arch.pv_vcpu.failsafe_callback_eip = reg->address.eip; - if ( reg->flags & CALLBACKF_mask_events ) - set_bit(_VGCF_failsafe_disables_events, - &v->arch.vgc_flags); - else - clear_bit(_VGCF_failsafe_disables_events, - &v->arch.vgc_flags); - break; - - case CALLBACKTYPE_syscall32: - v->arch.pv_vcpu.syscall32_callback_cs = reg->address.cs; - v->arch.pv_vcpu.syscall32_callback_eip = reg->address.eip; - v->arch.pv_vcpu.syscall32_disables_events = - (reg->flags & CALLBACKF_mask_events) != 0; - break; - - case CALLBACKTYPE_sysenter: - v->arch.pv_vcpu.sysenter_callback_cs = reg->address.cs; - v->arch.pv_vcpu.sysenter_callback_eip = reg->address.eip; - v->arch.pv_vcpu.sysenter_disables_events = - (reg->flags & CALLBACKF_mask_events) != 0; - break; - - case CALLBACKTYPE_nmi: - ret = register_guest_nmi_callback(reg->address.eip); - break; - - default: - ret = -ENOSYS; - break; - } - - return ret; -} - -static long compat_unregister_guest_callback( - struct compat_callback_unregister *unreg) -{ - long ret; - - switch ( unreg->type ) - { - case CALLBACKTYPE_event: - case CALLBACKTYPE_failsafe: - case CALLBACKTYPE_syscall32: - case CALLBACKTYPE_sysenter: - ret = -EINVAL; - break; - - case CALLBACKTYPE_nmi: - ret = unregister_guest_nmi_callback(); - break; - - default: - ret = -ENOSYS; - break; - } - - return ret; -} - - -long compat_callback_op(int cmd, XEN_GUEST_HANDLE(void) arg) -{ - long ret; - - switch ( cmd ) - { - case CALLBACKOP_register: - { - struct compat_callback_register reg; - - ret = -EFAULT; - if ( copy_from_guest(®, arg, 1) ) - break; - - ret = compat_register_guest_callback(®); - } - break; - - case CALLBACKOP_unregister: - { - struct compat_callback_unregister unreg; - - ret = -EFAULT; - if ( copy_from_guest(&unreg, arg, 1) ) - break; - - ret = compat_unregister_guest_callback(&unreg); - } - break; - - default: - ret = -EINVAL; - break; - } - - return ret; -} - -long compat_set_callbacks(unsigned long event_selector, - unsigned long event_address, - unsigned long failsafe_selector, - unsigned long failsafe_address) -{ - struct compat_callback_register event = { - .type = CALLBACKTYPE_event, - .address = { - .cs = event_selector, - .eip = event_address - } - }; - struct compat_callback_register failsafe = { - .type = CALLBACKTYPE_failsafe, - .address = { - .cs = failsafe_selector, - .eip = failsafe_address - } - }; - - compat_register_guest_callback(&event); - compat_register_guest_callback(&failsafe); - - return 0; -} - /* * Local variables: * mode: C -- 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 |