ia64/xen-unstable

changeset 9304:796ac2386a24

Clean up HVM relinquish_guest_resources interface and implementation.
Ensure we only unmap the shared I/O page after killing all timers
whose handlers may reference that page.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Thu Mar 16 19:36:28 2006 +0100 (2006-03-16)
parents 58d1ef215706
children 56ec142bdd91
files xen/arch/x86/domain.c xen/arch/x86/hvm/svm/svm.c xen/arch/x86/hvm/vmx/vmx.c xen/include/asm-x86/hvm/hvm.h xen/include/asm-x86/hvm/svm/svm.h xen/include/asm-x86/hvm/vmx/vmcs.h
line diff
     1.1 --- a/xen/arch/x86/domain.c	Thu Mar 16 18:57:54 2006 +0100
     1.2 +++ b/xen/arch/x86/domain.c	Thu Mar 16 19:36:28 2006 +0100
     1.3 @@ -1030,10 +1030,10 @@ void domain_relinquish_resources(struct 
     1.4  
     1.5              v->arch.guest_table_user = mk_pagetable(0);
     1.6          }
     1.7 +    }
     1.8  
     1.9 -        if ( hvm_guest(v) )
    1.10 -            hvm_relinquish_guest_resources(v);
    1.11 -    }
    1.12 +    if ( hvm_guest(d->vcpu[0]) )
    1.13 +        hvm_relinquish_guest_resources(d);
    1.14  
    1.15      shadow_mode_disable(d);
    1.16  
     2.1 --- a/xen/arch/x86/hvm/svm/svm.c	Thu Mar 16 18:57:54 2006 +0100
     2.2 +++ b/xen/arch/x86/hvm/svm/svm.c	Thu Mar 16 19:36:28 2006 +0100
     2.3 @@ -77,6 +77,8 @@ void svm_manual_event_injection32(struct
     2.4          int vector, int has_code);
     2.5  void svm_dump_regs(const char *from, struct cpu_user_regs *regs);
     2.6  
     2.7 +static void svm_relinquish_guest_resources(struct domain *d);
     2.8 +
     2.9  static struct asid_pool ASIDpool[NR_CPUS];
    2.10  
    2.11  /*
    2.12 @@ -198,12 +200,6 @@ int svm_initialize_guest_resources(struc
    2.13      return 1;
    2.14  }
    2.15  
    2.16 -int svm_relinquish_guest_resources(struct vcpu *v)
    2.17 -{
    2.18 -    svm_relinquish_resources(v);
    2.19 -    return 1;
    2.20 -}
    2.21 -
    2.22  void svm_store_cpu_guest_regs(struct vcpu *v, struct cpu_user_regs *regs)
    2.23  {
    2.24      struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb;
    2.25 @@ -722,43 +718,35 @@ void svm_final_setup_guest(struct vcpu *
    2.26  }
    2.27  
    2.28  
    2.29 -void svm_relinquish_resources(struct vcpu *v)
    2.30 +static void svm_relinquish_guest_resources(struct domain *d)
    2.31  {
    2.32 -    struct hvm_virpit *vpit;
    2.33      extern void destroy_vmcb(struct arch_svm_struct *); /* XXX */
    2.34 -
    2.35 -#if 0
    2.36 -    /* 
    2.37 -     * This is not stored at the moment. We need to keep it somewhere and free
    2.38 -     * it Or maybe not, as it's a per-cpu-core item, and I guess we don't
    2.39 -     * normally remove CPU's other than for hot-plug capable systems, where I
    2.40 -     * guess we have to allocate and free host-save area in this case. Let's
    2.41 -     * not worry about it at the moment, as loosing one page per CPU hot-plug
    2.42 -     * event doesn't seem that excessive. But I may be wrong.
    2.43 -     */
    2.44 -    free_host_save_area(v->arch.hvm_svm.host_save_area);
    2.45 -#endif
    2.46 -
    2.47 -    if ( v->vcpu_id == 0 )
    2.48 +    struct vcpu *v;
    2.49 +
    2.50 +    for_each_vcpu ( d, v )
    2.51      {
    2.52 -        /* unmap IO shared page */
    2.53 -        struct domain *d = v->domain;
    2.54 -        if ( d->arch.hvm_domain.shared_page_va )
    2.55 -            unmap_domain_page_global(
    2.56 -                (void *)d->arch.hvm_domain.shared_page_va);
    2.57 -        shadow_direct_map_clean(d);
    2.58 +#if 0
    2.59 +        /* Memory leak by not freeing this. XXXKAF: *Why* is not per core?? */
    2.60 +        free_host_save_area(v->arch.hvm_svm.host_save_area);
    2.61 +#endif
    2.62 +
    2.63 +        destroy_vmcb(&v->arch.hvm_svm);
    2.64 +        free_monitor_pagetable(v);
    2.65 +        kill_timer(&v->arch.hvm_svm.hlt_timer);
    2.66 +        if ( hvm_apic_support(v->domain) && (VLAPIC(v) != NULL) ) 
    2.67 +        {
    2.68 +            kill_timer( &(VLAPIC(v)->vlapic_timer) );
    2.69 +            xfree(VLAPIC(v));
    2.70 +        }
    2.71      }
    2.72  
    2.73 -    destroy_vmcb(&v->arch.hvm_svm);
    2.74 -    free_monitor_pagetable(v);
    2.75 -    vpit = &v->domain->arch.hvm_domain.vpit;
    2.76 -    kill_timer(&vpit->pit_timer);
    2.77 -    kill_timer(&v->arch.hvm_svm.hlt_timer);
    2.78 -    if ( hvm_apic_support(v->domain) && (VLAPIC(v) != NULL) ) 
    2.79 -    {
    2.80 -        kill_timer( &(VLAPIC(v)->vlapic_timer) );
    2.81 -        xfree( VLAPIC(v) );
    2.82 -    }
    2.83 +    kill_timer(&d->arch.hvm_domain.vpit.pit_timer);
    2.84 +
    2.85 +    if ( d->arch.hvm_domain.shared_page_va )
    2.86 +        unmap_domain_page_global(
    2.87 +            (void *)d->arch.hvm_domain.shared_page_va);
    2.88 +
    2.89 +    shadow_direct_map_clean(d);
    2.90  }
    2.91  
    2.92  
     3.1 --- a/xen/arch/x86/hvm/vmx/vmx.c	Thu Mar 16 18:57:54 2006 +0100
     3.2 +++ b/xen/arch/x86/hvm/vmx/vmx.c	Thu Mar 16 19:36:28 2006 +0100
     3.3 @@ -78,30 +78,30 @@ void vmx_final_setup_guest(struct vcpu *
     3.4      }
     3.5  }
     3.6  
     3.7 -void vmx_relinquish_resources(struct vcpu *v)
     3.8 +static void vmx_relinquish_guest_resources(struct domain *d)
     3.9  {
    3.10 -    struct hvm_virpit *vpit;
    3.11 +    struct vcpu *v;
    3.12  
    3.13 -    if (v->vcpu_id == 0) {
    3.14 -        /* unmap IO shared page */
    3.15 -        struct domain *d = v->domain;
    3.16 -        if ( d->arch.hvm_domain.shared_page_va )
    3.17 -            unmap_domain_page_global(
    3.18 -	        (void *)d->arch.hvm_domain.shared_page_va);
    3.19 -        shadow_direct_map_clean(d);
    3.20 +    for_each_vcpu ( d, v )
    3.21 +    {
    3.22 +        vmx_request_clear_vmcs(v);
    3.23 +        destroy_vmcs(&v->arch.hvm_vmx);
    3.24 +        free_monitor_pagetable(v);
    3.25 +        kill_timer(&v->arch.hvm_vmx.hlt_timer);
    3.26 +        if ( hvm_apic_support(v->domain) && (VLAPIC(v) != NULL) )
    3.27 +        {
    3.28 +            kill_timer(&VLAPIC(v)->vlapic_timer);
    3.29 +            xfree(VLAPIC(v));
    3.30 +        }
    3.31      }
    3.32  
    3.33 -    vmx_request_clear_vmcs(v);
    3.34 -    destroy_vmcs(&v->arch.hvm_vmx);
    3.35 -    free_monitor_pagetable(v);
    3.36 -    vpit = &v->domain->arch.hvm_domain.vpit;
    3.37 -    kill_timer(&vpit->pit_timer);
    3.38 -    kill_timer(&v->arch.hvm_vmx.hlt_timer);
    3.39 -    if ( hvm_apic_support(v->domain) && (VLAPIC(v) != NULL) )
    3.40 -    {
    3.41 -        kill_timer(&VLAPIC(v)->vlapic_timer);
    3.42 -        xfree(VLAPIC(v));
    3.43 -    }
    3.44 +    kill_timer(&d->arch.hvm_domain.vpit.pit_timer);
    3.45 +
    3.46 +    if ( d->arch.hvm_domain.shared_page_va )
    3.47 +        unmap_domain_page_global(
    3.48 +	        (void *)d->arch.hvm_domain.shared_page_va);
    3.49 +
    3.50 +    shadow_direct_map_clean(d);
    3.51  }
    3.52  
    3.53  #ifdef __x86_64__
    3.54 @@ -326,12 +326,6 @@ int vmx_initialize_guest_resources(struc
    3.55      return 1;
    3.56  }
    3.57  
    3.58 -int vmx_relinquish_guest_resources(struct vcpu *v)
    3.59 -{
    3.60 -    vmx_relinquish_resources(v);
    3.61 -    return 1;
    3.62 -}
    3.63 -
    3.64  void vmx_migrate_timers(struct vcpu *v)
    3.65  {
    3.66      struct hvm_virpit *vpit = &(v->domain->arch.hvm_domain.vpit);
     4.1 --- a/xen/include/asm-x86/hvm/hvm.h	Thu Mar 16 18:57:54 2006 +0100
     4.2 +++ b/xen/include/asm-x86/hvm/hvm.h	Thu Mar 16 19:36:28 2006 +0100
     4.3 @@ -35,8 +35,8 @@ struct hvm_function_table {
     4.4      /*
     4.5       * Initialize/relinguish HVM guest resources
     4.6       */
     4.7 -    int (*initialize_guest_resources)(struct vcpu *v);
     4.8 -    int (*relinquish_guest_resources)(struct vcpu *v);
     4.9 +    int  (*initialize_guest_resources)(struct vcpu *v);
    4.10 +    void (*relinquish_guest_resources)(struct domain *d);
    4.11  
    4.12      /*
    4.13       * Store and load guest state:
    4.14 @@ -80,24 +80,23 @@ extern struct hvm_function_table hvm_fun
    4.15  static inline void
    4.16  hvm_disable(void)
    4.17  {
    4.18 -    if (hvm_funcs.disable)
    4.19 -	hvm_funcs.disable();
    4.20 +    if ( hvm_funcs.disable )
    4.21 +        hvm_funcs.disable();
    4.22  }
    4.23  
    4.24  static inline int
    4.25  hvm_initialize_guest_resources(struct vcpu *v)
    4.26  {
    4.27 -    if (hvm_funcs.initialize_guest_resources)
    4.28 -	return hvm_funcs.initialize_guest_resources(v);
    4.29 +    if ( hvm_funcs.initialize_guest_resources )
    4.30 +        return hvm_funcs.initialize_guest_resources(v);
    4.31      return 0;
    4.32  }
    4.33  
    4.34 -static inline int
    4.35 -hvm_relinquish_guest_resources(struct vcpu *v)
    4.36 +static inline void
    4.37 +hvm_relinquish_guest_resources(struct domain *d)
    4.38  {
    4.39      if (hvm_funcs.relinquish_guest_resources)
    4.40 -	return hvm_funcs.relinquish_guest_resources(v);
    4.41 -    return 0;
    4.42 +        hvm_funcs.relinquish_guest_resources(d);
    4.43  }
    4.44  
    4.45  static inline void
    4.46 @@ -134,9 +133,9 @@ hvm_restore_msrs(struct vcpu *v)
    4.47          hvm_funcs.restore_msrs(v);
    4.48  }
    4.49  #else
    4.50 -#define	hvm_save_segments(v)	((void)0)
    4.51 -#define	hvm_load_msrs(v)	((void)0)
    4.52 -#define	hvm_restore_msrs(v)	((void)0)
    4.53 +#define hvm_save_segments(v)    ((void)0)
    4.54 +#define hvm_load_msrs(v)        ((void)0)
    4.55 +#define hvm_restore_msrs(v)     ((void)0)
    4.56  #endif /* __x86_64__ */
    4.57  
    4.58  static inline void
     5.1 --- a/xen/include/asm-x86/hvm/svm/svm.h	Thu Mar 16 18:57:54 2006 +0100
     5.2 +++ b/xen/include/asm-x86/hvm/svm/svm.h	Thu Mar 16 19:36:28 2006 +0100
     5.3 @@ -44,7 +44,6 @@ extern void svm_vmread(struct vcpu *v, i
     5.4  extern void svm_vmwrite(struct vcpu *v, int index, unsigned long value);
     5.5  extern void svm_final_setup_guest(struct vcpu *v); 
     5.6  extern int svm_paging_enabled(struct vcpu *v); 
     5.7 -extern void svm_relinquish_resources(struct vcpu *v);
     5.8  extern void svm_dump_vmcb(const char *from, struct vmcb_struct *vmcb);
     5.9  extern void svm_stts(struct vcpu *v); 
    5.10  extern void svm_do_launch(struct vcpu *v);
     6.1 --- a/xen/include/asm-x86/hvm/vmx/vmcs.h	Thu Mar 16 18:57:54 2006 +0100
     6.2 +++ b/xen/include/asm-x86/hvm/vmx/vmcs.h	Thu Mar 16 19:36:28 2006 +0100
     6.3 @@ -28,7 +28,6 @@ extern int start_vmx(void);
     6.4  extern void stop_vmx(void);
     6.5  
     6.6  void vmx_final_setup_guest(struct vcpu *v);
     6.7 -void vmx_relinquish_resources(struct vcpu *v);
     6.8  
     6.9  void vmx_enter_scheduler(void);
    6.10