x86: Perform mem_sharing teardown before paging teardown
PATCH v2 1/1 x86: Perform mem_sharing teardown before paging teardown
An assert failure has been observed in p2m_teardown when performing vm forking and then destroying the forked VM (p2m-basic.c:173). The assert checks whether the domain's shared pages counter is 0. According to the patch that originally added the assert (7bedbbb5c31) the p2m_teardown should only happen after mem_sharing already relinquished all shared pages.
In this patch we flip the order in which relinquish ops are called to avoid tripping the assert.
---
v2: comsetic fixes
--- xen/arch/x86/domain.c | 56 ++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 27 deletions(-)
xen/arch/x86/domain.c +29 -27
@@ -2289,9 +2289,9 @@ int domain_relinquish_resources(struct domain *d)enum { PROG_iommu_pagetables =1 , + PROG_shared, PROG_paging, PROG_vcpu_pagetables, - PROG_shared, PROG_xen, PROG_l4, PROG_l3,
@@ -2310,6 +2310,34 @@ int domain_relinquish_resources(struct domain *d)if ( ret )return ret; +#ifdef CONFIG_MEM_SHARING + PROGRESS(shared): + + if ( is_hvm_domain(d) ) + { +/* +* If the domain has shared pages, relinquish them allowing +* for preemption. +*/ + ret =relinquish_shared_pages (d); +if ( ret ) +return ret; + +/* +* If the domain is forked, decrement the parent's pause count +* and release the domain. +*/ +if (mem_sharing_is_fork (d) ) + { +struct domain *parent = d->parent; + + d->parent =NULL ; +domain_unpause (parent); +put_domain (parent); + } + } +#endif + PROGRESS(paging):/* Tear down paging-assistance stuff. */
@@ -2350,32 +2378,6 @@ int domain_relinquish_resources(struct domain *d) d->arch.auto_unmask =0 ; } -#ifdef CONFIG_MEM_SHARING - PROGRESS(shared): - - if ( is_hvm_domain(d) ) - { -/* If the domain has shared pages, relinquish them allowing -* for preemption. */ - ret =relinquish_shared_pages (d); -if ( ret ) -return ret; - -/* -* If the domain is forked, decrement the parent's pause count -* and release the domain. -*/ -if (mem_sharing_is_fork (d) ) - { -struct domain *parent = d->parent; - - d->parent =NULL ; -domain_unpause (parent); -put_domain (parent); - } - } -#endif -spin_lock (&d->page_alloc_lock);page_list_splice (&d->arch.relmem_list, &d->page_list);INIT_PAGE_LIST_HEAD (&d->arch.relmem_list);
Signature · 1 line
2.34.1
Quoted 11 lines · Tamas K Lengyel
An assert failure has been observed in
p2m_teardownwhen performing vm forking and then destroying the forked VM (p2m-basic.c:173). The assert checks whether the domain's shared pages counter is 0. According to the patch that originally added the assert (7bedbbb5c31) thep2m_teardownshould only happen aftermem_sharingalready relinquished all shared pages.In this patch we flip the order in which relinquish ops are called to avoid tripping the assert.
Signed-off-by Tamas K Lengyel <[email protected]>Fixes e7aa55c0aab3 ("x86/p2m: free the paging memory pool preemptively")
Especially considering the backporting requirement I'm disappointed to find that you haven't extended the description to explain why this heavier code churn is to be preferred over an adjustment to the offending assertion. As said in reply to v1 - I'm willing to accept arguments towards this being better, but I need to know those arguments.
Jan
Quoted 7 lines · Jan Beulich
Quoted 5 lines · Tamas K Lengyel
An assert failure has been observed in
p2m_teardownwhen performing vm forking and then destroying the forked VM (p2m-basic.c:173). The assert checks whether the domain's shared pages counter is 0. According to the patch that originally added the assert (7bedbbb5c31) thep2m_teardownshould only happen aftermem_sharingalready relinquished all shared
pages.
Quoted 2 lines
Quoted 2 lines
In this patch we flip the order in which relinquish ops are called to
avoid
Quoted 4 lines
Quoted 4 lines
tripping the assert.
Signed-off-by Tamas K Lengyel <[email protected]>Fixes e7aa55c0aab3 ("x86/p2m: free the paging memory pool
preemptively")
Quoted 6 lines
Especially considering the backporting requirement I'm disappointed to find that you haven't extended the description to explain why this heavier code churn is to be preferred over an adjustment to the offending assertion. As said in reply to v1 - I'm willing to accept arguments towards this being better, but I need to know those arguments.
The assert change as you proposed is hard to understand and will be thus harder to maintain. Conceptually sharing being torn down makes sense to happen before paging is torn down. Considering that's how it has been before the unfortunate regression I'm fixing here I don't think more justification is needed. The code-churn is minimal anyway.
Tamas
Quoted 24 lines · Tamas K Lengyel
Quoted 7 lines · Jan Beulich
Quoted 5 lines · Tamas K Lengyel
An assert failure has been observed in
p2m_teardownwhen performing vm forking and then destroying the forked VM (p2m-basic.c:173). The assert checks whether the domain's shared pages counter is 0. According to the patch that originally added the assert (7bedbbb5c31) thep2m_teardownshould only happen aftermem_sharingalready relinquished all sharedpages.
Quoted 2 lines
Quoted 2 lines
In this patch we flip the order in which relinquish ops are called to
avoid
Quoted 4 lines
Quoted 4 lines
tripping the assert.
Signed-off-by Tamas K Lengyel <[email protected]>Fixes e7aa55c0aab3 ("x86/p2m: free the paging memory poolpreemptively")
Quoted 6 lines
Especially considering the backporting requirement I'm disappointed to find that you haven't extended the description to explain why this heavier code churn is to be preferred over an adjustment to the offending assertion. As said in reply to v1 - I'm willing to accept arguments towards this being better, but I need to know those arguments.
Quoted 3 lines
The assert change as you proposed is hard to understand and will be thus harder to maintain. Conceptually sharing being torn down makes sense to happen before paging is torn down.
This is (perhaps) the crucial thing to say. Whereas ...
Quoted 3 lines
Considering that's how it has been
before the unfortunate regression I'm fixing here I don't think more justification is needed.
... I disagree here - that's _not_ how it has been before: paging_teardown() has always been called first. The regression was with how much of teardown is performed from there vs at the final stage of domain cleanup.
I'd be fine adding the "Conceptually ..." sentence to the description when committing, of course provided you agree.
Quoted 1 line
The code-churn is minimal anyway.
Perspectives here may vary. Plus, as said, being the one to backport this eventually, the larger the code change (even if pure movement), the larger the chance of there being a conflict somewhere.
Jan
Quoted 7 lines · Jan Beulich
Quoted 5 lines · Tamas K Lengyel
Quoted 4 lines · Jan Beulich
Quoted 2 lines · Tamas K Lengyel
An assert failure has been observed in
p2m_teardownwhen performing vm forking and then destroying the forked VM (p2m-basic.c:173). The
assert
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
checks whether the domain's shared pages counter is 0. According to
the
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
patch that originally added the assert (
7bedbbb5c31) thep2m_teardownshould only happen aftermem_sharingalready relinquished all sharedpages.
Quoted 2 lines
Quoted 2 lines
In this patch we flip the order in which relinquish ops are called to
avoid
Quoted 2 lines
Quoted 2 lines
tripping the assert.
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Signed-off-by Tamas K Lengyel <[email protected]>Fixes e7aa55c0aab3 ("x86/p2m: free the paging memory poolpreemptively")
Quoted 4 lines
Especially considering the backporting requirement I'm disappointed to find that you haven't extended the description to explain why this heavier code churn is to be preferred over an adjustment to the
offending
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
assertion. As said in reply to v1 - I'm willing to accept arguments towards this being better, but I need to know those arguments.
The assert change as you proposed is hard to understand and will be thus harder to maintain. Conceptually sharing being torn down makes sense to happen before paging is torn down.
Quoted 7 lines
This is (perhaps) the crucial thing to say. Whereas ...
Quoted 3 lines
Considering that's how it has been
before the unfortunate regression I'm fixing here I don't think more justification is needed.... I disagree here - that's _not_ how it has been before:
paging_teardown()
Quoted 5 lines
has always been called first. The regression was with how much of teardown is performed from there vs at the final stage of domain cleanup.
I'd be fine adding the "Conceptually ..." sentence to the description when committing, of course provided you agree.
Perfectly fine by me.
Thanks,
Tamas