Skip to contentSkip to conversation

vvmx: fix ept_sync() for nested p2m

PATCH In review Sergey Dyasli 3 participants 3 messages Jun 28, 2017 – Jun 30, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vvmx: fix ept_sync() for nested p2m

If ept_sync_domain() is called for np2m, the following happens:

1. *np2m*::ept_data::invalidate cpumask is updated
2. IPIs are sent for CPUs in domain_dirty_cpumask forcing vmexits
3. vmx_vmenter_helper() checks *hostp2m*::ept_data::invalidate and does nothing

Which is clearly a bug. Make ept_sync_domain() to update hostp2m's invalidate mask in nested p2m case and make vmx_vmenter_helper() to invalidate EPT translations for all EPTPs if nested virt is enabled.

---
 xen/arch/x86/hvm/vmx/vmx.c | 5 ++++-
 xen/arch/x86/mm/p2m-ept.c  | 9 +++++++--
 2 files changed, 11 insertions(+), 3 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +4 -1
index c53b24955a..a8bb550720 100644
@@ -4278,7 +4278,10 @@ void vmx_vmenter_helper(const struct cpu_user_regs *regs)
         if ( cpumask_test_cpu(cpu, ept->invalidate) )
         {
             cpumask_clear_cpu(cpu, ept->invalidate);
-            __invept(INVEPT_SINGLE_CONTEXT, ept->eptp, 0);
+            if ( nestedhvm_enabled(curr->domain) )
+                __invept(INVEPT_ALL_CONTEXT, 0, 0);
+            else
+                __invept(INVEPT_SINGLE_CONTEXT, ept->eptp, 0);
         }
     }
 
xen/arch/x86/mm/p2m-ept.c +7 -2
index ecab56fbec..8d9da9203c 100644
@@ -1153,8 +1153,13 @@ static void ept_sync_domain_prepare(struct p2m_domain *p2m)
     struct domain *d = p2m->domain;
     struct ept_data *ept = &p2m->ept;
 
-    if ( nestedhvm_enabled(d) && !p2m_is_nestedp2m(p2m) )
-        p2m_flush_nestedp2m(d);
+    if ( nestedhvm_enabled(d) )
+    {
+        if ( p2m_is_nestedp2m(p2m) )
+            ept = &p2m_get_hostp2m(d)->ept;
+        else
+            p2m_flush_nestedp2m(d);
+    }
 
     /*
      * Need to invalidate on all PCPUs because either:
Signature · 7 lines
2.11.0


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

If ept_sync_domain() is called for np2m, the following happens:

1. *np2m*::ept_data::invalidate cpumask is updated
2. IPIs are sent for CPUs in domain_dirty_cpumask forcing vmexits
3. vmx_vmenter_helper() checks *hostp2m*::ept_data::invalidate and does nothing

Quoted 5 lines

Which is clearly a bug. Make ept_sync_domain() to update hostp2m's invalidate mask in nested p2m case and make vmx_vmenter_helper() to invalidate EPT translations for all EPTPs if nested virt is enabled.

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

Acked-by on v1 1/1
#2 lore raw
In reply to Sergey Dyasli
Quoted 10 lines

From: Sergey Dyasli [mailto:[email protected]]
Sent: Wednesday, June 28, 2017 5:36 PM

If ept_sync_domain() is called for np2m, the following happens:

1. *np2m*::ept_data::invalidate cpumask is updated
2. IPIs are sent for CPUs in domain_dirty_cpumask forcing vmexits
3. vmx_vmenter_helper() checks *hostp2m*::ept_data::invalidate and does nothing

Quoted 5 lines

Which is clearly a bug. Make ept_sync_domain() to update hostp2m's invalidate mask in nested p2m case and make vmx_vmenter_helper() to invalidate EPT translations for all EPTPs if nested virt is enabled.

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