From: Andrew Cooper Date: Thu, 17 Jan 2019 12:26:17 +0000 (+0000) Subject: x86/altp2m: Rework #VE enable/disable paths X-Git-Tag: 4.12.0-rc4~19 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=e72ecc7615410e5bf1a1c9a4c7772322c16eeb82;p=people%2Fdwmw2%2Fxen.git x86/altp2m: Rework #VE enable/disable paths Split altp2m_vcpu_{enable,disable}_ve() out of the HVMOP_altp2m_vcpu_{enable,disable}_notify marshalling logic. A future change is going to need to call altp2m_vcpu_disable_ve() from the domain_kill() path. While at it, clean up the logic in altp2m_vcpu_{initialise,destroy}(). altp2m_vcpu_reset() has no external callers, so fold it into its two callsites. This in turn allows for altp2m_vcpu_destroy() to reuse altp2m_vcpu_disable_ve() rather than opencoding it. No practical change. Signed-off-by: Andrew Cooper Reviewed-by: Razvan Cojocaru Acked-by: Jan Beulich Release-acked-by: Juergen Gross --- diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 79c7d816e2..a80ddcf50d 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -4568,7 +4568,6 @@ static int do_altp2m_op( case HVMOP_altp2m_vcpu_enable_notify: { struct vcpu *v; - p2m_type_t p2mt; if ( a.u.enable_notify.pad || a.u.enable_notify.vcpu_id >= d->max_vcpus ) @@ -4585,16 +4584,7 @@ static int do_altp2m_op( v = d->vcpu[a.u.enable_notify.vcpu_id]; - if ( !gfn_eq(vcpu_altp2m(v).veinfo_gfn, INVALID_GFN) || - mfn_eq(get_gfn_query_unlocked(v->domain, - a.u.enable_notify.gfn, &p2mt), INVALID_MFN) ) - { - rc = -EINVAL; - break; - } - - vcpu_altp2m(v).veinfo_gfn = _gfn(a.u.enable_notify.gfn); - altp2m_vcpu_update_vmfunc_ve(v); + rc = altp2m_vcpu_enable_ve(v, _gfn(a.u.enable_notify.gfn)); break; } @@ -4616,12 +4606,7 @@ static int do_altp2m_op( v = d->vcpu[a.u.enable_notify.vcpu_id]; - /* Already disabled, nothing to do. */ - if ( gfn_eq(vcpu_altp2m(v).veinfo_gfn, INVALID_GFN) ) - break; - - vcpu_altp2m(v).veinfo_gfn = INVALID_GFN; - altp2m_vcpu_update_vmfunc_ve(v); + altp2m_vcpu_disable_ve(v); break; } diff --git a/xen/arch/x86/mm/altp2m.c b/xen/arch/x86/mm/altp2m.c index 930bdc2669..8bdefb0f7b 100644 --- a/xen/arch/x86/mm/altp2m.c +++ b/xen/arch/x86/mm/altp2m.c @@ -20,23 +20,14 @@ #include #include -void -altp2m_vcpu_reset(struct vcpu *v) -{ - struct altp2mvcpu *av = &vcpu_altp2m(v); - - av->p2midx = INVALID_ALTP2M; - av->veinfo_gfn = INVALID_GFN; -} - void altp2m_vcpu_initialise(struct vcpu *v) { if ( v != current ) vcpu_pause(v); - altp2m_vcpu_reset(v); vcpu_altp2m(v).p2midx = 0; + vcpu_altp2m(v).veinfo_gfn = INVALID_GFN; atomic_inc(&p2m_get_altp2m(v)->active_vcpus); altp2m_vcpu_update_p2m(v); @@ -56,15 +47,39 @@ altp2m_vcpu_destroy(struct vcpu *v) if ( (p2m = p2m_get_altp2m(v)) ) atomic_dec(&p2m->active_vcpus); - altp2m_vcpu_reset(v); + altp2m_vcpu_disable_ve(v); + vcpu_altp2m(v).p2midx = INVALID_ALTP2M; altp2m_vcpu_update_p2m(v); - altp2m_vcpu_update_vmfunc_ve(v); if ( v != current ) vcpu_unpause(v); } +int altp2m_vcpu_enable_ve(struct vcpu *v, gfn_t gfn) +{ + p2m_type_t p2mt; + + if ( !gfn_eq(vcpu_altp2m(v).veinfo_gfn, INVALID_GFN) || + mfn_eq(get_gfn_query_unlocked(v->domain, gfn_x(gfn), &p2mt), + INVALID_MFN) ) + return -EINVAL; + + vcpu_altp2m(v).veinfo_gfn = gfn; + altp2m_vcpu_update_vmfunc_ve(v); + + return 0; +} + +void altp2m_vcpu_disable_ve(struct vcpu *v) +{ + if ( !gfn_eq(vcpu_altp2m(v).veinfo_gfn, INVALID_GFN) ) + { + vcpu_altp2m(v).veinfo_gfn = INVALID_GFN; + altp2m_vcpu_update_vmfunc_ve(v); + } +} + /* * Local variables: * mode: C diff --git a/xen/include/asm-x86/altp2m.h b/xen/include/asm-x86/altp2m.h index 3befcf6d63..8139bf832a 100644 --- a/xen/include/asm-x86/altp2m.h +++ b/xen/include/asm-x86/altp2m.h @@ -33,7 +33,9 @@ static inline bool altp2m_active(const struct domain *d) /* Alternate p2m VCPU */ void altp2m_vcpu_initialise(struct vcpu *v); void altp2m_vcpu_destroy(struct vcpu *v); -void altp2m_vcpu_reset(struct vcpu *v); + +int altp2m_vcpu_enable_ve(struct vcpu *v, gfn_t gfn); +void altp2m_vcpu_disable_ve(struct vcpu *v); static inline uint16_t altp2m_vcpu_idx(const struct vcpu *v) {