x86/p2m: allocate CPU masks dynamically
PATCH 8/12 x86/p2m: allocate CPU masks dynamically
xen/arch/x86/hvm/nestedhvm.c +2 -2
@@ -114,9 +114,9 @@ nestedhvm_flushtlb_ipi(void *info)void nestedhvm_vmcx_flushtlb (struct p2m_domain *p2m) { -on_selected_cpus (&p2m->p2m_dirty_cpumask, nestedhvm_flushtlb_ipi, +on_selected_cpus (p2m->dirty_cpumask, nestedhvm_flushtlb_ipi, p2m->domain,1 ); -cpumask_clear (&p2m->p2m_dirty_cpumask); +cpumask_clear (p2m->dirty_cpumask); } bool_t
xen/arch/x86/mm/hap/nested_hap.c +1 -1
@@ -88,7 +88,7 @@ nestedp2m_write_p2m_entry(struct p2m_domsafe_write_pte (p, new);if (old_flags & _PAGE_PRESENT) -flush_tlb_mask (&p2m->p2m_dirty_cpumask); +flush_tlb_mask (p2m->dirty_cpumask);paging_unlock (d); }
xen/arch/x86/mm/p2m.c +15 -5
@@ -81,7 +81,6 @@ static void p2m_initialise(struct domain p2m->default_access = p2m_access_rwx; p2m->cr3 =CR3_EADDR ; -cpumask_clear (&p2m->p2m_dirty_cpumask);if (hap_enabled (d) && (boot_cpu_data.x86_vendor ==X86_VENDOR_INTEL ) )ept_p2m_init (p2m);
@@ -102,6 +101,8 @@ p2m_init_nestedp2m(struct domain *d) d->arch.nested_p2m[i] = p2m = xzalloc(struct p2m_domain);if (p2m ==NULL )return -ENOMEM ; +if ( !zalloc_cpumask_var (&p2m->dirty_cpumask) ) +return -ENOMEM ;p2m_initialise (d, p2m); p2m->write_p2m_entry = nestedp2m_write_p2m_entry;list_add (&p2m->np2m_list, &p2m_get_hostp2m (d)->np2m_list);
@@ -117,6 +118,8 @@ int p2m_init(struct domain *d) p2m_get_hostp2m(d) = p2m = xzalloc(struct p2m_domain);if ( p2m ==NULL )return -ENOMEM ; +if ( !zalloc_cpumask_var (&p2m->dirty_cpumask) ) +return -ENOMEM ;p2m_initialise (d, p2m);/* Must initialise nestedp2m unconditionally
@@ -330,6 +333,9 @@ static void p2m_teardown_nestedp2m(strucuint8_t i;for (i =0 ; i <MAX_NESTEDP2M ; i++) { +if ( !d->arch.nested_p2m[i] ) +continue ; +free_cpumask_var (d->arch.nested_p2m[i]->dirty_cpumask);xfree (d->arch.nested_p2m[i]); d->arch.nested_p2m[i] =NULL ; }
@@ -338,8 +344,12 @@ static void p2m_teardown_nestedp2m(strucvoid p2m_final_teardown (struct domain *d) {/* Iterate over all p2m tables per domain */ -xfree (d->arch.p2m); - d->arch.p2m =NULL ; +if ( d->arch.p2m ) + { +free_cpumask_var (d->arch.p2m->dirty_cpumask); +xfree (d->arch.p2m); + d->arch.p2m =NULL ; + }/* We must teardown unconditionally because * we initialise them unconditionally.
@@ -1197,7 +1207,7 @@ p2m_get_nestedp2m(struct vcpu *v, uint64if (p2m->cr3 ==CR3_EADDR )hvm_asid_flush_vcpu (v); p2m->cr3 = cr3; -cpu_set (v->processor, p2m->p2m_dirty_cpumask); +cpumask_set_cpu (v->processor, p2m->dirty_cpumask);p2m_unlock (p2m);nestedp2m_unlock (d);return p2m;
@@ -1214,7 +1224,7 @@ p2m_get_nestedp2m(struct vcpu *v, uint64 p2m->cr3 = cr3; nv->nv_flushp2m =0 ;hvm_asid_flush_vcpu (v); -cpu_set (v->processor, p2m->p2m_dirty_cpumask); +cpumask_set_cpu (v->processor, p2m->dirty_cpumask);p2m_unlock (p2m);nestedp2m_unlock (d);
xen/include/asm-x86/p2m.h +1 -1
@@ -198,7 +198,7 @@ struct p2m_domain {* this p2m and those physical cpus whose vcpu's are in * guestmode. */ -cpumask_t p2m_dirty_cpumask; +cpumask_var_t dirty_cpumask;struct domain *domain;/* back pointer to domain */
x86/p2m: allocate CPU masks dynamically
xen/arch/x86/hvm/nestedhvm.c +2 -2
@@ -114,9 +114,9 @@ nestedhvm_flushtlb_ipi(void *info)void nestedhvm_vmcx_flushtlb (struct p2m_domain *p2m) { -on_selected_cpus (&p2m->p2m_dirty_cpumask, nestedhvm_flushtlb_ipi, +on_selected_cpus (p2m->dirty_cpumask, nestedhvm_flushtlb_ipi, p2m->domain,1 ); -cpumask_clear (&p2m->p2m_dirty_cpumask); +cpumask_clear (p2m->dirty_cpumask); } bool_t
xen/arch/x86/mm/hap/nested_hap.c +1 -1
@@ -88,7 +88,7 @@ nestedp2m_write_p2m_entry(struct p2m_domsafe_write_pte (p, new);if (old_flags & _PAGE_PRESENT) -flush_tlb_mask (&p2m->p2m_dirty_cpumask); +flush_tlb_mask (p2m->dirty_cpumask);paging_unlock (d); }
xen/arch/x86/mm/p2m.c +15 -5
@@ -81,7 +81,6 @@ static void p2m_initialise(struct domain p2m->default_access = p2m_access_rwx; p2m->cr3 =CR3_EADDR ; -cpumask_clear (&p2m->p2m_dirty_cpumask);if (hap_enabled (d) && (boot_cpu_data.x86_vendor ==X86_VENDOR_INTEL ) )ept_p2m_init (p2m);
@@ -102,6 +101,8 @@ p2m_init_nestedp2m(struct domain *d) d->arch.nested_p2m[i] = p2m = xzalloc(struct p2m_domain);if (p2m ==NULL )return -ENOMEM ; +if ( !zalloc_cpumask_var (&p2m->dirty_cpumask) ) +return -ENOMEM ;p2m_initialise (d, p2m); p2m->write_p2m_entry = nestedp2m_write_p2m_entry;list_add (&p2m->np2m_list, &p2m_get_hostp2m (d)->np2m_list);
@@ -117,6 +118,8 @@ int p2m_init(struct domain *d) p2m_get_hostp2m(d) = p2m = xzalloc(struct p2m_domain);if ( p2m ==NULL )return -ENOMEM ; +if ( !zalloc_cpumask_var (&p2m->dirty_cpumask) ) +return -ENOMEM ;p2m_initialise (d, p2m);/* Must initialise nestedp2m unconditionally
@@ -330,6 +333,9 @@ static void p2m_teardown_nestedp2m(strucuint8_t i;for (i =0 ; i <MAX_NESTEDP2M ; i++) { +if ( !d->arch.nested_p2m[i] ) +continue ; +free_cpumask_var (d->arch.nested_p2m[i]->dirty_cpumask);xfree (d->arch.nested_p2m[i]); d->arch.nested_p2m[i] =NULL ; }
@@ -338,8 +344,12 @@ static void p2m_teardown_nestedp2m(strucvoid p2m_final_teardown (struct domain *d) {/* Iterate over all p2m tables per domain */ -xfree (d->arch.p2m); - d->arch.p2m =NULL ; +if ( d->arch.p2m ) + { +free_cpumask_var (d->arch.p2m->dirty_cpumask); +xfree (d->arch.p2m); + d->arch.p2m =NULL ; + }/* We must teardown unconditionally because * we initialise them unconditionally.
@@ -1197,7 +1207,7 @@ p2m_get_nestedp2m(struct vcpu *v, uint64if (p2m->cr3 ==CR3_EADDR )hvm_asid_flush_vcpu (v); p2m->cr3 = cr3; -cpu_set (v->processor, p2m->p2m_dirty_cpumask); +cpumask_set_cpu (v->processor, p2m->dirty_cpumask);p2m_unlock (p2m);nestedp2m_unlock (d);return p2m;
@@ -1214,7 +1224,7 @@ p2m_get_nestedp2m(struct vcpu *v, uint64 p2m->cr3 = cr3; nv->nv_flushp2m =0 ;hvm_asid_flush_vcpu (v); -cpu_set (v->processor, p2m->p2m_dirty_cpumask); +cpumask_set_cpu (v->processor, p2m->dirty_cpumask);p2m_unlock (p2m);nestedp2m_unlock (d);
xen/include/asm-x86/p2m.h +1 -1
@@ -198,7 +198,7 @@ struct p2m_domain {* this p2m and those physical cpus whose vcpu's are in * guestmode. */ -cpumask_t p2m_dirty_cpumask; +cpumask_var_t dirty_cpumask;struct domain *domain;/* back pointer to domain */
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Hi,
Quoted 11 lines · Jan Beulich
xen/arch/x86/mm/p2m.c +0
-1@@ -81,7 +81,6 @@ static void p2m_initialise(struct domain p2m->default_access = p2m_access_rwx; p2m->cr3 =CR3_EADDR ; -cpumask_clear (&p2m->p2m_dirty_cpumask);if (hap_enabled (d) && (boot_cpu_data.x86_vendor ==X86_VENDOR_INTEL ) )ept_p2m_init (p2m);
xen/arch/x86/mm/p2m.c p2m_init_nestedp2m(struct domain *d) · line 105
Quoted 5 lines
xen/arch/x86/mm/p2m.c +2
-0@@ -102,6 +101,8 @@ p2m_init_nestedp2m(struct domain *d) d->arch.nested_p2m[i] = p2m = xzalloc(struct p2m_domain);if (p2m ==NULL )return -ENOMEM ; +if ( !zalloc_cpumask_var (&p2m->dirty_cpumask) ) +return -ENOMEM ;
This leaks 'p2m'.
xen/arch/x86/mm/p2m.c int p2m_init(struct domain *d) · line 122
Quoted 9 lines
xen/arch/x86/mm/p2m.c +2
-0p2m_initialise (d, p2m); p2m->write_p2m_entry = nestedp2m_write_p2m_entry;list_add (&p2m->np2m_list, &p2m_get_hostp2m (d)->np2m_list);@@ -117,6 +118,8 @@ int p2m_init(struct domain *d) p2m_get_hostp2m(d) = p2m = xzalloc(struct p2m_domain);if ( p2m ==NULL )return -ENOMEM ; +if ( !zalloc_cpumask_var (&p2m->dirty_cpumask) ) +return -ENOMEM ;
Likewise.
Apart from that,
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Tim Deegan
Quoted 8 lines · Jan Beulich
xen/arch/x86/mm/p2m.c +0
-1@@ -81,7 +81,6 @@ static void p2m_initialise(struct domain p2m->default_access = p2m_access_rwx; p2m->cr3 =CR3_EADDR ; -cpumask_clear (&p2m->p2m_dirty_cpumask);
Quoted 10 lines
xen/arch/x86/mm/p2m.c p2m_init_nestedp2m(struct domain *d) · line 105
Quoted 8 lines
xen/arch/x86/mm/p2m.c +2
-0if (hap_enabled (d) && (boot_cpu_data.x86_vendor ==X86_VENDOR_INTEL ) )ept_p2m_init (p2m);@@ -102,6 +101,8 @@ p2m_init_nestedp2m(struct domain *d) d->arch.nested_p2m[i] = p2m = xzalloc(struct p2m_domain);if (p2m ==NULL )return -ENOMEM ; +if ( !zalloc_cpumask_var (&p2m->dirty_cpumask) ) +return -ENOMEM ;This leaks 'p2m'.
If that's really true, then there is a leak already without that patch:p2m_init() calls p2m_init_nestedp2m() without recovering from failure in that function. It was my understanding that since failure here ultimately leads to failure of domain construction, which I thought (hoped - didn't verify) would result in p2m_final_teardown() getting called.
Please clarify.
Jan
Quoted 14 lines
xen/arch/x86/mm/p2m.c int p2m_init(struct domain *d) · line 122
Quoted 9 lines
xen/arch/x86/mm/p2m.c +2
-0p2m_initialise (d, p2m); p2m->write_p2m_entry = nestedp2m_write_p2m_entry;list_add (&p2m->np2m_list, &p2m_get_hostp2m (d)->np2m_list);@@ -117,6 +118,8 @@ int p2m_init(struct domain *d) p2m_get_hostp2m(d) = p2m = xzalloc(struct p2m_domain);if ( p2m ==NULL )return -ENOMEM ; +if ( !zalloc_cpumask_var (&p2m->dirty_cpumask) ) +return -ENOMEM ;Likewise.
Apart from that,
Acked-by Tim Deegan <[email protected]>
Quoted 21 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Tim Deegan
Quoted 8 lines · Jan Beulich
xen/arch/x86/mm/p2m.c +0
-1@@ -81,7 +81,6 @@ static void p2m_initialise(struct domain p2m->default_access = p2m_access_rwx; p2m->cr3 =CR3_EADDR ; -cpumask_clear (&p2m->p2m_dirty_cpumask);Quoted 10 lines
xen/arch/x86/mm/p2m.c p2m_init_nestedp2m(struct domain *d) · line 105
Quoted 8 lines
xen/arch/x86/mm/p2m.c +2
-0if (hap_enabled (d) && (boot_cpu_data.x86_vendor ==X86_VENDOR_INTEL ) )ept_p2m_init (p2m);@@ -102,6 +101,8 @@ p2m_init_nestedp2m(struct domain *d) d->arch.nested_p2m[i] = p2m = xzalloc(struct p2m_domain);if (p2m ==NULL )return -ENOMEM ; +if ( !zalloc_cpumask_var (&p2m->dirty_cpumask) ) +return -ENOMEM ;This leaks 'p2m'.
Quoted 6 lines
If that's really true, then there is a leak already without that patch:
p2m_init()callsp2m_init_nestedp2m()without recovering from failure in that function. It was my understanding that since failure here ultimately leads to failure of domain construction, which I thought (hoped - didn't verify) would result inp2m_final_teardown()getting called.
You're quite right; it will all get tidied up by p2m_final_teardown(). Sorry for the noise.
Tim.
Quoted 22 lines · Tim Deegan
Quoted 21 lines · Jan Beulich
Quoted 20 lines
Quoted 1 line
Quoted 1 line · Tim Deegan
Quoted 11 lines · Jan Beulich
xen/arch/x86/mm/p2m.c +0
-1@@ -81,7 +81,6 @@ static void p2m_initialise(struct domain p2m->default_access = p2m_access_rwx; p2m->cr3 =CR3_EADDR ; -cpumask_clear (&p2m->p2m_dirty_cpumask);if (hap_enabled (d) && (boot_cpu_data.x86_vendor ==X86_VENDOR_INTEL ) )ept_p2m_init (p2m);xen/arch/x86/mm/p2m.c p2m_init_nestedp2m(struct domain *d) · line 105
Quoted 5 lines
xen/arch/x86/mm/p2m.c +2
-0@@ -102,6 +101,8 @@ p2m_init_nestedp2m(struct domain *d) d->arch.nested_p2m[i] = p2m = xzalloc(struct p2m_domain);if (p2m ==NULL )return -ENOMEM ; +if ( !zalloc_cpumask_var (&p2m->dirty_cpumask) ) +return -ENOMEM ;This leaks 'p2m'.
Quoted 8 lines
Quoted 6 lines
If that's really true, then there is a leak already without that patch:
p2m_init()callsp2m_init_nestedp2m()without recovering from failure in that function. It was my understanding that since failure here ultimately leads to failure of domain construction, which I thought (hoped - didn't verify) would result inp2m_final_teardown()getting called.You're quite right; it will all get tidied up by
p2m_final_teardown().
Except that arch_domain_create() doesn't actually call paging_final_teardown() if paging_domain_init() fails, so that path probably leaks quite badly -- at least the nested-paging stuff you pointed out, and possibly other things. I'll have a look at it.
Cheers,
Tim.
Quoted 30 lines · Tim Deegan
Quoted 29 lines · Tim Deegan
Quoted 27 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Tim Deegan
Quoted 8 lines · Jan Beulich
xen/arch/x86/mm/p2m.c +0
-1@@ -81,7 +81,6 @@ static void p2m_initialise(struct domain p2m->default_access = p2m_access_rwx; p2m->cr3 =CR3_EADDR ; -cpumask_clear (&p2m->p2m_dirty_cpumask);Quoted 10 lines
xen/arch/x86/mm/p2m.c p2m_init_nestedp2m(struct domain *d) · line 105
Quoted 8 lines
xen/arch/x86/mm/p2m.c +2
-0if (hap_enabled (d) && (boot_cpu_data.x86_vendor ==X86_VENDOR_INTEL ) )ept_p2m_init (p2m);@@ -102,6 +101,8 @@ p2m_init_nestedp2m(struct domain *d) d->arch.nested_p2m[i] = p2m = xzalloc(struct p2m_domain);if (p2m ==NULL )return -ENOMEM ; +if ( !zalloc_cpumask_var (&p2m->dirty_cpumask) ) +return -ENOMEM ;This leaks 'p2m'.
If that's really true, then there is a leak already without that patch:
p2m_init()callsp2m_init_nestedp2m()without recovering from failure in that function. It was my understanding that since failure here ultimately leads to failure of domain construction, which I thought (hoped - didn't verify) would result inp2m_final_teardown()getting called.
Quoted 6 lines
Quoted 1 line
You're quite right; it will all get tidied up by
p2m_final_teardown().Except that
arch_domain_create()doesn't actually callpaging_final_teardown()ifpaging_domain_init()fails, so that path probably leaks quite badly -- at least the nested-paging stuff you pointed out, and possibly other things. I'll have a look at it.
OK, it looks like it was just the nested-p2m state. That should be fixed now, as staging/xen-unstable.hg 23981:6c583d35d76d
Cheers,
Tim