x86/mm: Make {hap, shadow}_teardown() preemptible
PATCH 1/1 x86/mm: Make {hap, shadow}_teardown() preemptible
From: Anshul Makkar <[email protected]>
A domain with sufficient shadow allocation can cause a watchdog timeout during domain destruction. Expand the existing -ERESTART logic in paging_teardown() to allow {hap/sh}_set_allocation() to become restartable during the DOMCTL_destroydomain hypercall.
---
CC: Tim Deegan <[email protected]>
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
Wei: Currently, Xen can't actually run 1TB guests without suffering a watchdog timeout when destroying the domain. Therefore this is fairly important for 4.6 (and backport), or we will have to retroactively drop the currently-stated supported limits on the wiki.
The patch has had extensive testing in XenServer, although has been forward ported from 4.5.
--- xen/arch/x86/mm/hap/hap.c | 9 ++++++--- xen/arch/x86/mm/paging.c | 8 +++++--- xen/arch/x86/mm/shadow/common.c | 9 ++++++--- xen/include/asm-x86/hap.h | 2 +- xen/include/asm-x86/shadow.h | 4 ++-- 5 files changed, 20 insertions(+), 12 deletions(-)
xen/arch/x86/mm/hap/hap.c +6 -3
@@ -551,7 +551,7 @@ void hap_final_teardown(struct domain *d) }if ( d->arch.paging.hap.total_pages !=0 ) -hap_teardown (d); +hap_teardown (d,NULL );p2m_teardown (p2m_get_hostp2m (d));/* Free any memory that the p2m teardown released */
@@ -561,7 +561,7 @@ void hap_final_teardown(struct domain *d)paging_unlock (d); } -void hap_teardown (struct domain *d) +void hap_teardown (struct domain *d,int *preempted) {struct vcpu *v;mfn_t mfn;
@@ -595,7 +595,9 @@ void hap_teardown(struct domain *d) d->arch.paging.hap.total_pages, d->arch.paging.hap.free_pages, d->arch.paging.hap.p2m_pages); -hap_set_allocation (d,0 ,NULL ); +hap_set_allocation (d,0 , preempted); +if ( preempted && *preempted ) + goto out; HAP_PRINTK("teardown done." " pages total = %u, free = %u, p2m=%u\n", d->arch.paging.hap.total_pages,
@@ -609,6 +611,7 @@ void hap_teardown(struct domain *d)xfree (d->arch.hvm_domain.dirty_vram); d->arch.hvm_domain.dirty_vram =NULL ; +out:paging_unlock (d); }
xen/arch/x86/mm/paging.c +5 -3
@@ -799,12 +799,14 @@ long paging_domctl_continuation(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)/* Call when destroying a domain */ int paging_teardown (struct domain *d) { -int rc; +int rc, preempted =0 ;if (hap_enabled (d) ) -hap_teardown (d); +hap_teardown (d, &preempted);else -shadow_teardown (d); +shadow_teardown (d, &preempted); +if ( preempted ) +return -ERESTART ;/* clean up log dirty resources. */ rc =paging_free_log_dirty_bitmap (d,0 );
xen/arch/x86/mm/shadow/common.c +6 -3
@@ -3071,7 +3071,7 @@ int shadow_enable(struct domain *d, u32 mode)return rv; } -void shadow_teardown (struct domain *d) +void shadow_teardown (struct domain *d,int *preempted)/* Destroy the shadow pagetables of this domain and free its shadow memory. * Should only be called for dying domains. */ {
@@ -3139,7 +3139,9 @@ void shadow_teardown(struct domain *d) d->arch.paging.shadow.free_pages, d->arch.paging.shadow.p2m_pages);/* Destroy all the shadows and release memory to domheap */ -sh_set_allocation (d,0 ,NULL ); +sh_set_allocation (d,0 , preempted); +if ( preempted && *preempted ) + goto out;/* Release the hash table back to xenheap */ if (d->arch.paging.shadow.hash_table)shadow_hash_teardown (d);
@@ -3177,6 +3179,7 @@ void shadow_teardown(struct domain *d) d->arch.hvm_domain.dirty_vram =NULL ; } +out:paging_unlock (d);/* Must be called outside the lock */
@@ -3198,7 +3201,7 @@ void shadow_final_teardown(struct domain *d)* It is possible for a domain that never got domain_kill()ed * to get here with its shadow allocation intact. */ if ( d->arch.paging.shadow.total_pages !=0 ) -shadow_teardown (d); +shadow_teardown (d,NULL );/* It is now safe to pull down the p2m map. */ p2m_teardown (p2m_get_hostp2m (d));
xen/include/asm-x86/hap.h +1 -1
@@ -38,7 +38,7 @@ int hap_domctl(struct domain *d, xen_domctl_shadow_op_t *sc, XEN_GUEST_HANDLE_PARAM(void) u_domctl);int hap_enable (struct domain *d,u32 mode);void hap_final_teardown (struct domain *d); -void hap_teardown (struct domain *d); +void hap_teardown (struct domain *d,int *preempted);void hap_vcpu_init (struct vcpu *v); int hap_track_dirty_vram(struct domain *d, unsigned long begin_pfn,
xen/include/asm-x86/shadow.h +2 -2
@@ -73,7 +73,7 @@ int shadow_domctl(struct domain *d, XEN_GUEST_HANDLE_PARAM(void) u_domctl);/* Call when destroying a domain */ -void shadow_teardown (struct domain *d); +void shadow_teardown (struct domain *d,int *preempted);/* Call once all of the references to the domain have gone away */ void shadow_final_teardown (struct domain *d);
@@ -85,7 +85,7 @@ int shadow_domctl(struct domain *d,#else /* !CONFIG_SHADOW_PAGING */ -#define shadow_teardown (d) ASSERT(is_pv_domain(d)) +#define shadow_teardown (d, p) ASSERT(is_pv_domain(d))#define shadow_final_teardown (d) ASSERT(is_pv_domain(d))#define shadow_enable (d, mode) \ ({ ASSERT(is_pv_domain(d)); -EOPNOTSUPP; })
Signature · 1 line
1.7.10.4
Hi,
Quoted 9 lines · Andrew Cooper
From: Anshul Makkar <[email protected]>
A domain with sufficient shadow allocation can cause a watchdog timeout during domain destruction. Expand the existing
-ERESTARTlogic inpaging_teardown()to allow {hap/sh}_set_allocation() to become restartable during theDOMCTL_destroydomainhypercall.Signed-off-by Anshul Makkar <[email protected]>Signed-off-by Andrew Cooper <[email protected]>
Good catch, thanks.
xen/arch/x86/mm/shadow/common.c void shadow_teardown(struct domain *d) · line 3147
Quoted 11 lines
xen/arch/x86/mm/shadow/common.c +3
-1@@ -3139,7 +3139,9 @@ void shadow_teardown(struct domain *d) d->arch.paging.shadow.free_pages, d->arch.paging.shadow.p2m_pages);/* Destroy all the shadows and release memory to domheap */ -sh_set_allocation (d,0 ,NULL ); +sh_set_allocation (d,0 , preempted); +if ( preempted && *preempted ) + goto out;/* Release the hash table back to xenheap */ if (d->arch.paging.shadow.hash_table)shadow_hash_teardown (d);
If the debug printout just above this is ever enabled, it will get very loud since the printout will make preemption likely. Please just delete the SHADOW_PRINTK above; you can also delete the one below if you like. The HAP side looks like it needs the same adjustment.
With that done, Reviewed-by: Tim Deegan <[email protected]>
Cheers,
Tim.