Skip to contentSkip to conversation

x86/p2m: Stop other vcpus using a nested p2m before clearing it

PATCH In review Andrew Cooper 4 participants 6 messages Feb 7, 2017 – Feb 8, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/p2m: Stop other vcpus using a nested p2m before clearing it

Until the IPI has completed, other processors might be running on this nested p2m object. clear_domain_page() does not guarantee to make 8-byte atomic updates, which means that a pagewalk on a remote processor might encounter a partial update.

This is currently safe as other issues prevents a nested p2m ever being shared between two cpus (although this is contrary to the original plan).

Setting p2m->np2m_base to P2M_BASE_EADDR before the IPI ensures that the IPI'd processors won't continue to use the flushed mappings.

While modifying this function, remove all the trailing whitespace and tweak style in the affected areas.

---
CC: Jan Beulich <[email protected]>
CC: Tim Deegan <[email protected]>
CC: George Dunlap <[email protected]>

---
 xen/arch/x86/mm/p2m.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
xen/arch/x86/mm/p2m.c +11 -7
index 7675e9c..c5b1642 100644
@@ -1618,8 +1618,10 @@ p2m_flush_table(struct p2m_domain *p2m)
 
     p2m_lock(p2m);
 
-    /* "Host" p2m tables can have shared entries &c that need a bit more 
-     * care when discarding them */
+    /*
+     * "Host" p2m tables can have shared entries &c that need a bit more care
+     * when discarding them.
+     */
     ASSERT(!p2m_is_hostp2m(p2m));
     /* Nested p2m's do not do pod, hence the asserts (and no pod lock)*/
     ASSERT(page_list_empty(&p2m->pod.super));
@@ -1633,19 +1635,21 @@ p2m_flush_table(struct p2m_domain *p2m)
 
     /* This is no longer a valid nested p2m for any address space */
     p2m->np2m_base = P2M_BASE_EADDR;
-    
-    /* Zap the top level of the trie */
-    mfn = pagetable_get_mfn(p2m_get_pagetable(p2m));
-    clear_domain_page(mfn);
 
     /* Make sure nobody else is using this p2m table */
     nestedhvm_vmcx_flushtlb(p2m);
 
+    /* Zap the top level of the trie */
+    mfn = pagetable_get_mfn(p2m_get_pagetable(p2m));
+    clear_domain_page(mfn);
+
     /* Free the rest of the trie pages back to the paging pool */
     top = mfn_to_page(mfn);
     while ( (pg = page_list_remove_head(&p2m->pages)) )
-        if ( pg != top ) 
+    {
+        if ( pg != top )
             d->arch.paging.free_page(d, pg);
+    }
     page_list_add(top, &p2m->pages);
 
     p2m_unlock(p2m);
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Andrew Cooper

Until the IPI has completed, other processors might be running on this nested p2m object. clear_domain_page() does not guarantee to make 8-byte atomic updates, which means that a pagewalk on a remote processor might encounter a partial update.

This is currently safe as other issues prevents a nested p2m ever being shared between two cpus (although this is contrary to the original plan).

Quoted 7 lines

Setting p2m->np2m_base to P2M_BASE_EADDR before the IPI ensures that the IPI'd processors won't continue to use the flushed mappings.

While modifying this function, remove all the trailing whitespace and tweak style in the affected areas.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by on v1 1/1
#2 lore raw
In reply to Andrew Cooper
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 07.02.17 at 19:48, <[email protected]> wrote:

Until the IPI has completed, other processors might be running on this nested p2m object. clear_domain_page() does not guarantee to make 8-byte atomic updates, which means that a pagewalk on a remote processor might encounter a partial update.

This is currently safe as other issues prevents a nested p2m ever being shared between two cpus (although this is contrary to the original plan).

Quoted 7 lines

Setting p2m->np2m_base to P2M_BASE_EADDR before the IPI ensures that the IPI'd processors won't continue to use the flushed mappings.

While modifying this function, remove all the trailing whitespace and tweak style in the affected areas.

but ...

xen/arch/x86/mm/p2m.c p2m_flush_table(struct p2m_domain *p2m) · line 1642

Quoted 13 lines
xen/arch/x86/mm/p2m.c +1 -4
@@ -1633,19 +1635,21 @@ p2m_flush_table(struct p2m_domain *p2m)
 
     /* This is no longer a valid nested p2m for any address space */
     p2m->np2m_base = P2M_BASE_EADDR;
-    
-    /* Zap the top level of the trie */
-    mfn = pagetable_get_mfn(p2m_get_pagetable(p2m));
-    clear_domain_page(mfn);
 
     /* Make sure nobody else is using this p2m table */
     nestedhvm_vmcx_flushtlb(p2m);
 
+    /* Zap the top level of the trie */

s/trie/tree/ here, as you touch it anyway?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw
Quoted 28 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 07.02.17 at 19:48, <[email protected]> wrote:

Until the IPI has completed, other processors might be running on this nested p2m object. clear_domain_page() does not guarantee to make 8-byte atomic updates, which means that a pagewalk on a remote processor might encounter a partial update.

This is currently safe as other issues prevents a nested p2m ever being shared between two cpus (although this is contrary to the original plan).

Quoted 7 lines

Setting p2m->np2m_base to P2M_BASE_EADDR before the IPI ensures that the IPI'd processors won't continue to use the flushed mappings.

While modifying this function, remove all the trailing whitespace and tweak style in the affected areas.

but ...

Quoted 9 lines
xen/arch/x86/mm/p2m.c +0 -4
@@ -1633,19 +1635,21 @@ p2m_flush_table(struct p2m_domain *p2m)
 
     /* This is no longer a valid nested p2m for any address space */
     p2m->np2m_base = P2M_BASE_EADDR;
-    
-    /* Zap the top level of the trie */
-    mfn = pagetable_get_mfn(p2m_get_pagetable(p2m));
-    clear_domain_page(mfn);
 
Quoted 5 lines

xen/arch/x86/mm/p2m.c p2m_flush_table(struct p2m_domain *p2m) · line 1642

Quoted 4 lines
xen/arch/x86/mm/p2m.c +1 -0
     /* Make sure nobody else is using this p2m table */
     nestedhvm_vmcx_flushtlb(p2m);
 
+    /* Zap the top level of the trie */

s/trie/tree/ here, as you touch it anyway?

Trie here refers to the datastructure https://en.wikipedia.org/wiki/Trie
which is the structure implemented by processor pagetables. It is more specific than just calling them trees.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by
#4 lore raw
Quoted 32 lines · Andrew Cooper
Quoted 31 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 07.02.17 at 19:48, <[email protected]> wrote:

Until the IPI has completed, other processors might be running on this nested p2m object. clear_domain_page() does not guarantee to make 8-byte atomic updates, which means that a pagewalk on a remote processor might encounter a partial update.

This is currently safe as other issues prevents a nested p2m ever being shared between two cpus (although this is contrary to the original plan).

Quoted 7 lines

Setting p2m->np2m_base to P2M_BASE_EADDR before the IPI ensures that the IPI'd processors won't continue to use the flushed mappings.

While modifying this function, remove all the trailing whitespace and tweak style in the affected areas.

but ...

Quoted 12 lines
xen/arch/x86/mm/p2m.c +0 -4
@@ -1633,19 +1635,21 @@ p2m_flush_table(struct p2m_domain *p2m)
 
     /* This is no longer a valid nested p2m for any address space */
     p2m->np2m_base = P2M_BASE_EADDR;
-    
-    /* Zap the top level of the trie */
-    mfn = pagetable_get_mfn(p2m_get_pagetable(p2m));
-    clear_domain_page(mfn);
 
     /* Make sure nobody else is using this p2m table */
     nestedhvm_vmcx_flushtlb(p2m);
 
Quoted 6 lines
Quoted 2 lines

xen/arch/x86/mm/p2m.c p2m_flush_table(struct p2m_domain *p2m) · line 1642

Quoted 1 line
xen/arch/x86/mm/p2m.c +1 -0
+    /* Zap the top level of the trie */

s/trie/tree/ here, as you touch it anyway?

Trie here refers to the datastructure https://en.wikipedia.org/wiki/Trie
which is the structure implemented by processor pagetables. It is more specific than just calling them trees.

Never heard that before, but we seem to already have at least six instances in the hypervisor (and an ocaml file called 'trie.mli'), so I guess there's precedent. :-)

I'll check this one in.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#5 lore raw
Quoted 40 lines · George Dunlap
Quoted 32 lines · Andrew Cooper
Quoted 31 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 07.02.17 at 19:48, <[email protected]> wrote:

Until the IPI has completed, other processors might be running on this nested p2m object. clear_domain_page() does not guarantee to make 8-byte atomic updates, which means that a pagewalk on a remote processor might encounter a partial update.

This is currently safe as other issues prevents a nested p2m ever being shared between two cpus (although this is contrary to the original plan).

Quoted 7 lines

Setting p2m->np2m_base to P2M_BASE_EADDR before the IPI ensures that the IPI'd processors won't continue to use the flushed mappings.

While modifying this function, remove all the trailing whitespace and tweak style in the affected areas.

but ...

Quoted 12 lines
xen/arch/x86/mm/p2m.c +0 -4
@@ -1633,19 +1635,21 @@ p2m_flush_table(struct p2m_domain *p2m)
 
     /* This is no longer a valid nested p2m for any address space */
     p2m->np2m_base = P2M_BASE_EADDR;
-    
-    /* Zap the top level of the trie */
-    mfn = pagetable_get_mfn(p2m_get_pagetable(p2m));
-    clear_domain_page(mfn);
 
     /* Make sure nobody else is using this p2m table */
     nestedhvm_vmcx_flushtlb(p2m);
 
Quoted 6 lines
Quoted 2 lines

xen/arch/x86/mm/p2m.c p2m_flush_table(struct p2m_domain *p2m) · line 1642

Quoted 1 line
xen/arch/x86/mm/p2m.c +1 -0
+    /* Zap the top level of the trie */

s/trie/tree/ here, as you touch it anyway?

Trie here refers to the datastructure https://en.wikipedia.org/wiki/Trie
which is the structure implemented by processor pagetables. It is more specific than just calling them trees.

Quoted 7 lines

Never heard that before, but we seem to already have at least six instances in the hypervisor (and an ocaml file called 'trie.mli'), so I guess there's precedent. :-)

I'll check this one in.

Or maybe I won't. :-)

-George

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel