[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v5 02/13] x86: move the compat callback ops next to the non-compat variant
Take the chance to change v to curr. 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 cbcdeac2da..d811f48110 100644 --- a/xen/arch/x86/pv/callback.c +++ b/xen/arch/x86/pv/callback.c @@ -19,6 +19,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> @@ -172,6 +173,147 @@ 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 *curr = current; + + fixup_guest_code_selector(curr->domain, reg->address.cs); + + switch ( reg->type ) + { + case CALLBACKTYPE_event: + curr->arch.pv_vcpu.event_callback_cs = reg->address.cs; + curr->arch.pv_vcpu.event_callback_eip = reg->address.eip; + break; + + case CALLBACKTYPE_failsafe: + curr->arch.pv_vcpu.failsafe_callback_cs = reg->address.cs; + curr->arch.pv_vcpu.failsafe_callback_eip = reg->address.eip; + if ( reg->flags & CALLBACKF_mask_events ) + set_bit(_VGCF_failsafe_disables_events, + &curr->arch.vgc_flags); + else + clear_bit(_VGCF_failsafe_disables_events, + &curr->arch.vgc_flags); + break; + + case CALLBACKTYPE_syscall32: + curr->arch.pv_vcpu.syscall32_callback_cs = reg->address.cs; + curr->arch.pv_vcpu.syscall32_callback_eip = reg->address.eip; + curr->arch.pv_vcpu.syscall32_disables_events = + (reg->flags & CALLBACKF_mask_events) != 0; + break; + + case CALLBACKTYPE_sysenter: + curr->arch.pv_vcpu.sysenter_callback_cs = reg->address.cs; + curr->arch.pv_vcpu.sysenter_callback_eip = reg->address.eip; + curr->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 diff --git a/xen/arch/x86/x86_64/compat/traps.c b/xen/arch/x86/x86_64/compat/traps.c index 4594a32100..9e1ccba646 100644 --- a/xen/arch/x86/x86_64/compat/traps.c +++ b/xen/arch/x86/x86_64/compat/traps.c @@ -3,149 +3,6 @@ #include <compat/callback.h> #include <compat/arch-x86_32.h> -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; -} - int compat_set_trap_table(XEN_GUEST_HANDLE(trap_info_compat_t) traps) { struct compat_trap_info cur; -- 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 |