From: Andrew Cooper Subject: [PATCH v2] x86/domain: Improvements to switch_native() and switch_compat() Date: Tue, 20 Jan 2015 14:27:04 +0000 Message-ID: <1421764024-32358-1-git-send-email-andrew.cooper3@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Xen-devel Cc: Andrew Cooper , Keir Fraser , Jan Beulich , Tim Deegan List-Id: xen-devel@lists.xenproject.org Both are called with known-good domains, making the NULL check redundant. Both also have open-coded forms of for_each_vcpu() which are replaced. switch_compat() is updated to propagate the error from set_compat_l4(), rather than automatically overriding with -ENOMEM. Signed-off-by: Andrew Cooper CC: Keir Fraser CC: Jan Beulich CC: Tim Deegan --- v2: No alteration to release_compat_l4(), and the sole takes care of only calling it on an already set up vcpu --- xen/arch/x86/domain.c | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index c8832c6..50b361b 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -362,10 +362,8 @@ static inline int may_switch_mode(struct domain *d) int switch_native(struct domain *d) { - unsigned int vcpuid; + struct vcpu *v; - if ( d == NULL ) - return -EINVAL; if ( !may_switch_mode(d) ) return -EACCES; if ( !is_pv_32on64_domain(d) ) @@ -373,21 +371,16 @@ int switch_native(struct domain *d) d->arch.is_32bit_pv = d->arch.has_32bit_shinfo = 0; - for ( vcpuid = 0; vcpuid < d->max_vcpus; vcpuid++ ) - { - if (d->vcpu[vcpuid]) - release_compat_l4(d->vcpu[vcpuid]); - } + for_each_vcpu( d, v ) + release_compat_l4(v); return 0; } int switch_compat(struct domain *d) { - unsigned int vcpuid; - - if ( d == NULL ) - return -EINVAL; + struct vcpu *v; + int rc; if ( is_pvh_domain(d) ) { @@ -403,12 +396,9 @@ int switch_compat(struct domain *d) d->arch.is_32bit_pv = d->arch.has_32bit_shinfo = 1; - for ( vcpuid = 0; vcpuid < d->max_vcpus; vcpuid++ ) - { - if ( (d->vcpu[vcpuid] != NULL) && - (setup_compat_l4(d->vcpu[vcpuid]) != 0) ) + for_each_vcpu( d, v ) + if ( (rc = setup_compat_l4(v)) ) goto undo_and_fail; - } domain_set_alloc_bitsize(d); @@ -416,12 +406,11 @@ int switch_compat(struct domain *d) undo_and_fail: d->arch.is_32bit_pv = d->arch.has_32bit_shinfo = 0; - while ( vcpuid-- != 0 ) - { - if ( d->vcpu[vcpuid] != NULL ) - release_compat_l4(d->vcpu[vcpuid]); - } - return -ENOMEM; + for_each_vcpu( d, v ) + if ( !pagetable_is_null(v->arch.guest_table) ) + release_compat_l4(v); + + return rc; } int vcpu_initialise(struct vcpu *v) -- 1.7.10.4