x86/domain: Improvements to switch_native() and switch_compat()
PATCH 1/1 x86/domain: Improvements to switch_native() and switch_compat()
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.
To aid the cleanup in switch_compat(), release_compat_l4() is updated to make it safe to call on a vcpu without an existing compat l4.
Finally, switch_compat() is updated to propagate the error from set_compat_l4(), rather than automatically overriding with -ENOMEM.
--- xen/arch/x86/domain.c | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-)
xen/arch/x86/domain.c +13 -23
@@ -349,6 +349,8 @@ static int setup_compat_l4(struct vcpu *v)static void release_compat_l4 (struct vcpu *v) { +if (pagetable_is_null (v->arch.guest_table) ) +return ;free_compat_arg_xlat (v);free_domheap_page (pagetable_get_page (v->arch.guest_table)); v->arch.guest_table =pagetable_null ();
@@ -362,10 +364,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 +373,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 +398,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 +408,10 @@ 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 ) +release_compat_l4 (v); + +return rc; }int vcpu_initialise (struct vcpu *v)
Signature · 1 line
1.7.10.4
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 19.01.15 at 11:44, <[email protected]> wrote:
To aid the cleanup in
switch_compat(),release_compat_l4()is updated to make
it safe to call on a vcpu without an existing compat l4.
For this part of the change:
xen/arch/x86/domain.c static int setup_compat_l4(struct vcpu *v) · line 353
Quoted 8 lines
xen/arch/x86/domain.c +2
-0@@ -349,6 +349,8 @@ static int setup_compat_l4(struct vcpu *v)static void release_compat_l4 (struct vcpu *v) { +if (pagetable_is_null (v->arch.guest_table) ) +return ;
I'd rather see this check be done in the one caller that needs it, since ...
xen/arch/x86/domain.c int switch_native(struct domain *d) · line 377
Quoted 11 lines
xen/arch/x86/domain.c +2
-5@@ -373,21 +373,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);
... this one can't run into that situation (or the old code would have been broken).
Jan