From a890ea3be71eb6f52588217bd50685072ef818a8 Mon Sep 17 00:00:00 2001 From: Jan Beulich Date: Wed, 31 Jan 2018 12:35:52 +0100 Subject: [PATCH] x86: re-organize toggle_guest_*() toggle_guest_mode() is only ever being called for 64-bit PV vCPU-s - replace the 32-bit PV conditional by an ASSERT(). Introduce a local helper without 32-bit PV conditional, to be used by both pre-existing functions. Signed-off-by: Jan Beulich Reviewed-by: Andrew Cooper --- xen/arch/x86/pv/domain.c | 44 +++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/xen/arch/x86/pv/domain.c b/xen/arch/x86/pv/domain.c index 74e9e667d2..2c784fb3cc 100644 --- a/xen/arch/x86/pv/domain.c +++ b/xen/arch/x86/pv/domain.c @@ -220,28 +220,8 @@ int pv_domain_initialise(struct domain *d, unsigned int domcr_flags, return rc; } -void toggle_guest_mode(struct vcpu *v) +static void _toggle_guest_pt(struct vcpu *v) { - if ( is_pv_32bit_vcpu(v) ) - return; - - if ( cpu_has_fsgsbase ) - { - if ( v->arch.flags & TF_kernel_mode ) - v->arch.pv_vcpu.gs_base_kernel = __rdgsbase(); - else - v->arch.pv_vcpu.gs_base_user = __rdgsbase(); - } - asm volatile ( "swapgs" ); - - toggle_guest_pt(v); -} - -void toggle_guest_pt(struct vcpu *v) -{ - if ( is_pv_32bit_vcpu(v) ) - return; - v->arch.flags ^= TF_kernel_mode; update_cr3(v); /* Don't flush user global mappings from the TLB. Don't tick TLB clock. */ @@ -260,6 +240,28 @@ void toggle_guest_pt(struct vcpu *v) v->arch.pv_vcpu.pending_system_time.version = 0; } +void toggle_guest_mode(struct vcpu *v) +{ + ASSERT(!is_pv_32bit_vcpu(v)); + + if ( cpu_has_fsgsbase ) + { + if ( v->arch.flags & TF_kernel_mode ) + v->arch.pv_vcpu.gs_base_kernel = __rdgsbase(); + else + v->arch.pv_vcpu.gs_base_user = __rdgsbase(); + } + asm volatile ( "swapgs" ); + + _toggle_guest_pt(v); +} + +void toggle_guest_pt(struct vcpu *v) +{ + if ( !is_pv_32bit_vcpu(v) ) + _toggle_guest_pt(v); +} + /* * Local variables: * mode: C -- 2.39.5