x86/pv: Trivial improvements to callback handling
cover x86/pv: Trivial improvements to callback handling
Andrew Cooper (3):
x86/pv: Avoid locked bit manipulation in register_guest_callback() x86/pv: Fold {compat_}unregister_guest_callback() into its non-compat counterpart x86/pv: Minor tweaks to {,compat_}register_guest_callback()
xen/arch/x86/pv/callback.c | 103 +++++++++++++++------------------------------ 1 file changed, 34 insertions(+), 69 deletions(-)
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 1/3 x86/pv: Avoid locked bit manipulation in register_guest_callback()
Changes to arch.vgc_flags are made to current in syncrhonous context only, and don't need to be locked. (The only other changes are via arch_set_info_guest(), which operates on descheduled vcpus only).
Replace the {set,clear}_bit() calls with compiler-visible bitwise operations.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
--- xen/arch/x86/pv/callback.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
xen/arch/x86/pv/callback.c +6 -12
@@ -88,21 +88,17 @@ static long register_guest_callback(struct callback_register *reg)case CALLBACKTYPE_failsafe: curr->arch.pv_vcpu.failsafe_callback_eip = reg->address;if ( reg->flags & CALLBACKF_mask_events ) -set_bit (_VGCF_failsafe_disables_events, - &curr->arch.vgc_flags); + curr->arch.vgc_flags |= VGCF_failsafe_disables_events;else -clear_bit (_VGCF_failsafe_disables_events, - &curr->arch.vgc_flags); + curr->arch.vgc_flags &= ~VGCF_failsafe_disables_events;break ;case CALLBACKTYPE_syscall: curr->arch.pv_vcpu.syscall_callback_eip = reg->address;if ( reg->flags & CALLBACKF_mask_events ) -set_bit (_VGCF_syscall_disables_events, - &curr->arch.vgc_flags); + curr->arch.vgc_flags |= VGCF_syscall_disables_events;else -clear_bit (_VGCF_syscall_disables_events, - &curr->arch.vgc_flags); + curr->arch.vgc_flags &= ~VGCF_syscall_disables_events;break ;case CALLBACKTYPE_syscall32:
@@ -236,11 +232,9 @@ static long compat_register_guest_callback(struct compat_callback_register *reg) 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); + curr->arch.vgc_flags |= VGCF_failsafe_disables_events;else -clear_bit (_VGCF_failsafe_disables_events, - &curr->arch.vgc_flags); + curr->arch.vgc_flags &= ~VGCF_failsafe_disables_events;break ;case CALLBACKTYPE_syscall32:
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 1/3] x86/pv: Avoid locked bit manipulation in register_guest_callback()
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 15.03.18 at 12:58, <[email protected]> wrote:
Changes to arch.vgc_flags are made to current in syncrhonous context only, and don't need to be locked. (The only other changes are via
arch_set_info_guest(), which operates on descheduled vcpus only).Replace the {set,clear}_bit() calls with compiler-visible bitwise operations.
Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 1/3] x86/pv: Avoid locked bit manipulation in register_guest_callback()
In reply to Andrew CooperQuoted 7 lines · Andrew Cooper
Changes to arch.vgc_flags are made to current in syncrhonous context only, and don't need to be locked. (The only other changes are via
arch_set_info_guest(), which operates on descheduled vcpus only).Replace the {set,clear}_bit() calls with compiler-visible bitwise operations.
Signed-off-by Andrew Cooper <[email protected]>
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 2/3 x86/pv: Fold {compat_}unregister_guest_callback() into its non-compat counterpart
In reply to Andrew CooperThese functions are almost identical. They differ only in the error emitted for the use of CALLBACKTYPE_syscall (which is inconsequential to guests), and the type of their argument.
Have the callers pass the unreg.type parameter directly, avoiding the need for differently typed parameters.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
--- xen/arch/x86/pv/callback.c | 37 +++++-------------------------------- 1 file changed, 5 insertions(+), 32 deletions(-)
xen/arch/x86/pv/callback.c +5 -32
@@ -125,11 +125,11 @@ static long register_guest_callback(struct callback_register *reg)return ret; } -static long unregister_guest_callback (struct callback_unregister *unreg) +static int unregister_guest_callback (unsigned int type) { -long ret; +int ret; -switch ( unreg->type ) +switch ( type ) {case CALLBACKTYPE_event:case CALLBACKTYPE_failsafe:
@@ -178,7 +178,7 @@ long do_callback_op(int cmd, XEN_GUEST_HANDLE_PARAM(const_void) arg)if (copy_from_guest (&unreg, arg,1 ) )break ; - ret =unregister_guest_callback (&unreg); + ret =unregister_guest_callback (unreg.type); }break ;
@@ -263,33 +263,6 @@ static long compat_register_guest_callback(struct compat_callback_register *reg)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: -unregister_guest_nmi_callback (); - ret =0 ; -break ; - -default : - ret = -ENOSYS ; -break ; - } - -return ret; -} -long compat_callback_op (int cmd,XEN_GUEST_HANDLE (void ) arg) {long ret;
@@ -316,7 +289,7 @@ long compat_callback_op(int cmd, XEN_GUEST_HANDLE(void) arg)if (copy_from_guest (&unreg, arg,1 ) )break ; - ret =compat_unregister_guest_callback (&unreg); + ret =unregister_guest_callback (unreg.type); }break ;
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 2/3] x86/pv: Fold {compat_}unregister_guest_callback() into its non-compat counterpart
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 15.03.18 at 12:58, <[email protected]> wrote:
These functions are almost identical. They differ only in the error emitted for the use of
CALLBACKTYPE_syscall(which is inconsequential to guests),
I'm not entirely convinced - so far there's been a match here between map and unmap, i.e. with the change it may be advisable for compat_register_guest_callback() to also return -EINVAL for CALLBACKTYPE_syscall. However, I don't feel strongly about this, so either way ...
Quoted 7 lines
and
the type of their argument.Have the callers pass the unreg.type parameter directly, avoiding the need for differently typed parameters.
Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 2/3] x86/pv: Fold {compat_}unregister_guest_callback() into its non-compat counterpart
In reply to Andrew CooperQuoted 8 lines · Andrew Cooper
These functions are almost identical. They differ only in the error emitted for the use of
CALLBACKTYPE_syscall(which is inconsequential to guests), and the type of their argument.Have the callers pass the unreg.type parameter directly, avoiding the need for differently typed parameters.
Signed-off-by Andrew Cooper <[email protected]>
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 3/3 x86/pv: Minor tweaks to {, compat_}register_guest_callback()
In reply to Andrew Cooper * Being internal functions, use int rather than long for the return value
* Factor out pv_vcpu into a local variable. Reduces code volume, and removes some split lines.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
--- xen/arch/x86/pv/callback.c | 48 ++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 25 deletions(-)
xen/arch/x86/pv/callback.c +23 -25
@@ -71,10 +71,11 @@ static void unregister_guest_nmi_callback(void)memset (t,0 ,sizeof (*t)); } -static long register_guest_callback (struct callback_register *reg) +static int register_guest_callback (struct callback_register *reg) { -long ret =0 ;struct vcpu *curr = current; +struct pv_vcpu *pv = &curr->arch.pv_vcpu; +int ret =0 ;if ( !is_canonical_address (reg->address) )return -EINVAL ;
@@ -82,11 +83,11 @@ static long register_guest_callback(struct callback_register *reg)switch ( reg->type ) {case CALLBACKTYPE_event: - curr->arch.pv_vcpu.event_callback_eip = reg->address; + pv->event_callback_eip = reg->address;break ;case CALLBACKTYPE_failsafe: - curr->arch.pv_vcpu.failsafe_callback_eip = reg->address; + pv->failsafe_callback_eip = reg->address;if ( reg->flags & CALLBACKF_mask_events ) curr->arch.vgc_flags |= VGCF_failsafe_disables_events;else
@@ -94,7 +95,7 @@ static long register_guest_callback(struct callback_register *reg)break ;case CALLBACKTYPE_syscall: - curr->arch.pv_vcpu.syscall_callback_eip = reg->address; + pv->syscall_callback_eip = reg->address;if ( reg->flags & CALLBACKF_mask_events ) curr->arch.vgc_flags |= VGCF_syscall_disables_events;else
@@ -102,15 +103,13 @@ static long register_guest_callback(struct callback_register *reg)break ;case CALLBACKTYPE_syscall32: - curr->arch.pv_vcpu.syscall32_callback_eip = reg->address; - curr->arch.pv_vcpu.syscall32_disables_events = - !!(reg->flags & CALLBACKF_mask_events); + pv->syscall32_callback_eip = reg->address; + pv->syscall32_disables_events = reg->flags & CALLBACKF_mask_events;break ;case CALLBACKTYPE_sysenter: - curr->arch.pv_vcpu.sysenter_callback_eip = reg->address; - curr->arch.pv_vcpu.sysenter_disables_events = - !!(reg->flags & CALLBACKF_mask_events); + pv->sysenter_callback_eip = reg->address; + pv->sysenter_disables_events = reg->flags & CALLBACKF_mask_events;break ;case CALLBACKTYPE_nmi:
@@ -214,23 +213,24 @@ long do_set_callbacks(unsigned long event_address,return 0 ; } -static long compat_register_guest_callback (struct compat_callback_register *reg) +static int compat_register_guest_callback (struct compat_callback_register *reg) { -long ret =0 ;struct vcpu *curr = current; +struct pv_vcpu *pv = &curr->arch.pv_vcpu; +int ret =0 ;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; + pv->event_callback_cs = reg->address.cs; + pv->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; + pv->failsafe_callback_cs = reg->address.cs; + pv->failsafe_callback_eip = reg->address.eip;if ( reg->flags & CALLBACKF_mask_events ) curr->arch.vgc_flags |= VGCF_failsafe_disables_events;else
@@ -238,17 +238,15 @@ static long compat_register_guest_callback(struct compat_callback_register *reg)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 ; + pv->syscall32_callback_cs = reg->address.cs; + pv->syscall32_callback_eip = reg->address.eip; + pv->syscall32_disables_events = reg->flags & CALLBACKF_mask_events;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 ; + pv->sysenter_callback_cs = reg->address.cs; + pv->sysenter_callback_eip = reg->address.eip; + pv->sysenter_disables_events = reg->flags & CALLBACKF_mask_events;break ;case CALLBACKTYPE_nmi:
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 3/3] x86/pv: Minor tweaks to {, compat_}register_guest_callback()
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 15.03.18 at 12:58, <[email protected]> wrote:
xen/arch/x86/pv/callback.c static void unregister_guest_nmi_callback(void) · line 78
Quoted 10 lines
xen/arch/x86/pv/callback.c +3
-2@@ -71,10 +71,11 @@ static void unregister_guest_nmi_callback(void)memset (t,0 ,sizeof (*t)); } -static long register_guest_callback (struct callback_register *reg) +static int register_guest_callback (struct callback_register *reg) { -long ret =0 ;struct vcpu *curr = current; +struct pv_vcpu *pv = &curr->arch.pv_vcpu; +int ret =0 ;
Instead of altering ret's type, why don't you drop it altogether? Same actually for the unregister function in patch 2. Preferably with that done
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH 3/3] x86/pv: Minor tweaks to {, compat_}register_guest_callback()
In reply to Andrew CooperQuoted 5 lines · Andrew Cooper
* Being internal functions, use int rather than long for the return value
* Factor outpv_vcpuinto a local variable. Reduces code volume, and removes some split lines.Signed-off-by Andrew Cooper <[email protected]>
register_guest_callback and compat_register_guest_callback are fairly similar, I wonder if we could translate compat_callback_register into callback_register and pass an extra compat parameter to register_guest_callback in order to get rid of compat_register_guest_callback.
Thanks, Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel