nested EPT: fix the handling of nested EPT.
PATCH RESEND 1/1 nested EPT: fix the handling of nested EPT.
If the host EPT entry is changed, the nested EPT should be updated. The current code does not do this, and it's wrong.
--- xen/arch/x86/mm/p2m-ept.c | 4 ++++ 1 file changed, 4 insertions(+)
xen/arch/x86/mm/p2m-ept.c +4 -0
@@ -26,6 +26,7 @@#include <asm/p2m.h> #include <asm/hvm/vmx/vmx.h> #include <asm/hvm/vmx/vmcs.h> +#include <asm/hvm/nestedhvm.h> #include <xen/iommu.h> #include <asm/mtrr.h> #include <asm/hvm/cacheattr.h>
@@ -1076,6 +1077,9 @@ void ept_sync_domain(struct p2m_domain *p2m)ASSERT (local_irq_is_enabled ()); +if (nestedhvm_enabled (d) ) +p2m_flush_nestedp2m (d); +/* * Flush active cpus synchronously. Flush others the next time this domain * is scheduled onto them. We accept the race of other CPUs adding to
Signature · 1 line
1.9.1
Quoted 23 lines · Liang Li
If the host EPT entry is changed, the nested EPT should be updated. The current code does not do this, and it's wrong.
Reported-by Tim Deegan <[email protected]>Signed-off-by Liang Li <[email protected]>Signed-off-by Yang Zhang <[email protected]>--- xen/arch/x86/mm/p2m-ept.c | 4 ++++ 1 file changed, 4 insertions(+)xen/arch/x86/mm/p2m-ept.c +1
-0@@ -26,6 +26,7 @@#include <asm/p2m.h> #include <asm/hvm/vmx/vmx.h> #include <asm/hvm/vmx/vmcs.h> +#include <asm/hvm/nestedhvm.h> #include <xen/iommu.h> #include <asm/mtrr.h> #include <asm/hvm/cacheattr.h>
xen/arch/x86/mm/p2m-ept.c void ept_sync_domain(struct p2m_domain *p2m) · line 1081
Quoted 5 lines
xen/arch/x86/mm/p2m-ept.c +2
-0@@ -1076,6 +1077,9 @@ void ept_sync_domain(struct p2m_domain *p2m)ASSERT (local_irq_is_enabled ()); +if (nestedhvm_enabled (d) ) +p2m_flush_nestedp2m (d);
It seems like this should trigger when the nested EPT table itself is being populated, e.g.
hvm_hap_nested_page_fault
--> nestedhvm_hap_nested_page_fault
--> nestedhap_fix_p2m (--> p2m_lock(p2m))
--> p2m_set_entry
--> ept_set_entry
--> ept_sync_domain
--> p2m_flush_nestedp2m
--> p2m_flush_table (--> p2m_lock(p2m))
which would deadlock on the nested table's p2m lock. What have I missed?
Tim.
Quoted 53 lines
-----Original Message-----
From: Tim Deegan [mailto:[email protected]]
Sent: Thursday, June 04, 2015 9:11 PM
To: Li, Liang Z
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Tian, Kevin; Zhang, Yang Z
Subject: Re: [RESEND] nested EPT: fix the handling of nested EPT.Quoted 23 lines · Liang Li
If the host EPT entry is changed, the nested EPT should be updated. The current code does not do this, and it's wrong.
Reported-by Tim Deegan <[email protected]>Signed-off-by Liang Li <[email protected]>Signed-off-by Yang Zhang <[email protected]>--- xen/arch/x86/mm/p2m-ept.c | 4 ++++ 1 file changed, 4 insertions(+)xen/arch/x86/mm/p2m-ept.c +1
-0@@ -26,6 +26,7 @@#include <asm/p2m.h> #include <asm/hvm/vmx/vmx.h> #include <asm/hvm/vmx/vmcs.h> +#include <asm/hvm/nestedhvm.h> #include <xen/iommu.h> #include <asm/mtrr.h> #include <asm/hvm/cacheattr.h> xen/arch/x86/mm/p2m-ept.c void ept_sync_domain(struct p2m_domain *p2m) · line 1081
Quoted 5 lines
xen/arch/x86/mm/p2m-ept.c +2
-0@@ -1076,6 +1077,9 @@ void ept_sync_domain(struct p2m_domain *p2m)ASSERT (local_irq_is_enabled ()); +if (nestedhvm_enabled (d) ) +p2m_flush_nestedp2m (d);It seems like this should trigger when the nested EPT table itself is being populated, e.g.
hvm_hap_nested_page_fault
-->nestedhvm_hap_nested_page_fault
-->nestedhap_fix_p2m(-->p2m_lock(p2m))
-->p2m_set_entry
-->ept_set_entry
-->ept_sync_domain
-->p2m_flush_nestedp2m
-->p2m_flush_table(-->p2m_lock(p2m))
Quoted 1 line
which would deadlock on the nested table's p2m lock. What have I missed?
Yes, you are right.
Maybe we should add another condition checking, just like:
struct vcpu *v = current;
If(nestedhvm_enabled(d) && !nestedhvm_vcpu_in_guestmode(v) )
p2m_flush_nestedp2m(d);
Or add a flag(is_nested_p2m) in the struct p2m_domain to mark a nested EPT, and change the condition to:
If(nestedhvm_enabled(d) && p2m->is_nested_p2m )
to exclude the case of nested EPT, is that enough?
Liang
Quoted 1 line
Tim.
Quoted 53 lines · Liang Z
Quoted 45 lines
-----Original Message-----
From: Tim Deegan [mailto:[email protected]]Quoted 23 lines · Liang Li
If the host EPT entry is changed, the nested EPT should be updated. The current code does not do this, and it's wrong.
Reported-by Tim Deegan <[email protected]>Signed-off-by Liang Li <[email protected]>Signed-off-by Yang Zhang <[email protected]>--- xen/arch/x86/mm/p2m-ept.c | 4 ++++ 1 file changed, 4 insertions(+)xen/arch/x86/mm/p2m-ept.c +1
-0@@ -26,6 +26,7 @@#include <asm/p2m.h> #include <asm/hvm/vmx/vmx.h> #include <asm/hvm/vmx/vmcs.h> +#include <asm/hvm/nestedhvm.h> #include <xen/iommu.h> #include <asm/mtrr.h> #include <asm/hvm/cacheattr.h> xen/arch/x86/mm/p2m-ept.c void ept_sync_domain(struct p2m_domain *p2m) · line 1081
Quoted 5 lines
xen/arch/x86/mm/p2m-ept.c +2
-0@@ -1076,6 +1077,9 @@ void ept_sync_domain(struct p2m_domain *p2m)ASSERT (local_irq_is_enabled ()); +if (nestedhvm_enabled (d) ) +p2m_flush_nestedp2m (d);It seems like this should trigger when the nested EPT table itself is being populated, e.g.
hvm_hap_nested_page_fault
-->nestedhvm_hap_nested_page_fault
-->nestedhap_fix_p2m(-->p2m_lock(p2m))
-->p2m_set_entry
-->ept_set_entry
-->ept_sync_domain
-->p2m_flush_nestedp2m
-->p2m_flush_table(-->p2m_lock(p2m))Quoted 1 line
which would deadlock on the nested table's p2m lock. What have I missed?
Yes, you are right.
Maybe we should add another condition checking, just like:
struct vcpu *v = current;
Quoted 7 lines
If(nestedhvm_enabled(d) && !nestedhvm_vcpu_in_guestmode(v) )p2m_flush_nestedp2m(d);Or add a
flag(is_nested_p2m)in the structp2m_domainto mark a nested EPT, and change the condition to:If(nestedhvm_enabled(d) && p2m->is_nested_p2m )
Yes, I think this is the right check, but you shouldn't need to add any new flags: p2m_is_nestedp2m(p2m) will work.
Also, in the next version of the patch, please describe what testing you've done.
Thanks
Tim.
Quoted 74 lines
-----Original Message-----
From: Tim Deegan [mailto:[email protected]]
Sent: Thursday, June 11, 2015 10:20 PM
To: Li, Liang Z
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Tian, Kevin; Zhang, Yang Z
Subject: Re: [RESEND] nested EPT: fix the handling of nested EPT.Quoted 6 lines · Liang Z
Quoted 6 lines
-----Original Message-----
From: Tim Deegan [mailto:[email protected]] At 05:06 +0800 on 03 JunQuoted 3 lines · Liang Li
If the host EPT entry is changed, the nested EPT should be updated. The current code does not do this, and it's wrong.
Quoted 8 lines
Quoted 8 lines
xen/arch/x86/mm/p2m-
Quoted 8 lines
Reported-by Tim Deegan <[email protected]>Signed-off-by Liang Li <[email protected]>Signed-off-by Yang Zhang <[email protected]>--- xen/arch/x86/mm/p2m-ept.c | 4 ++++ 1 file changed, 4 insertions(+)xen/arch/x86/mm/p2m- renamed from xen/arch/x86/mm/p2m-ept.c +0
-0
ept.cQuoted 4 lines
Quoted 4 lines
Quoted 4 lines
index 5133eb6..26293a0 100644
xen/arch/x86/mm/p2m-ept.c +0
-0@@ -26,6 +26,7 @@Quoted 8 lines
Quoted 8 lines
xen/arch/x86/mm/p2m-ept.c void ept_sync_domain(struct p2m_domain
Quoted 8 lines
xen/arch/x86/mm/p2m-ept.c +1
-0#include <asm/p2m.h> #include <asm/hvm/vmx/vmx.h> #include <asm/hvm/vmx/vmcs.h> +#include <asm/hvm/nestedhvm.h> #include <xen/iommu.h> #include <asm/mtrr.h> #include <asm/hvm/cacheattr.h> @@ -1076,6 +1077,9 @@ void ept_sync_domain(struct p2m_domain*p2m)
Quoted 19 lines
Quoted 19 lines
xen/arch/x86/mm/p2m-ept.c void ept_sync_domain(struct p2m_domain *p2m) · line 1081
Quoted 5 lines
xen/arch/x86/mm/p2m-ept.c +2
-0ASSERT (local_irq_is_enabled ()); +if (nestedhvm_enabled (d) ) +p2m_flush_nestedp2m (d);It seems like this should trigger when the nested EPT table itself is being populated, e.g.
hvm_hap_nested_page_fault
-->nestedhvm_hap_nested_page_fault
-->nestedhap_fix_p2m(-->p2m_lock(p2m))
-->p2m_set_entry
-->ept_set_entry
-->ept_sync_domain
-->p2m_flush_nestedp2m
-->p2m_flush_table(-->p2m_lock(p2m))Quoted 1 line
Quoted 1 line
which would deadlock on the nested table's p2m lock. What have I
missed?
Quoted 7 lines
Yes, you are right.
Maybe we should add another condition checking, just like:
struct vcpu *v = current;
Quoted 7 lines
If(nestedhvm_enabled(d) && !nestedhvm_vcpu_in_guestmode(v) )p2m_flush_nestedp2m(d);Or add a
flag(is_nested_p2m)in the structp2m_domainto mark a nested EPT, and change the condition to:If(nestedhvm_enabled(d) && p2m->is_nested_p2m )
Quoted 5 lines
Yes, I think this is the right check, but you shouldn't need to add any new
flags:p2m_is_nestedp2m(p2m)will work.Also, in the next version of the patch, please describe what testing you've done.
Thanks Tim. I will do test this time ....
Quoted 2 lines
Thanks
Tim.
Quoted 54 lines
Quoted 4 lines
Quoted 4 lines
xen/arch/x86/mm/p2m-
Quoted 4 lines
xen/arch/x86/mm/p2m-ept.c | 4 ++++ 1 file changed, 4 insertions(+)xen/arch/x86/mm/p2m- renamed from xen/arch/x86/mm/p2m-ept.c +0
-0
ept.cQuoted 4 lines
Quoted 4 lines
Quoted 4 lines
index 5133eb6..26293a0 100644
xen/arch/x86/mm/p2m-ept.c +0
-0@@ -26,6 +26,7 @@Quoted 8 lines
Quoted 8 lines
xen/arch/x86/mm/p2m-ept.c void ept_sync_domain(struct p2m_domain
Quoted 8 lines
xen/arch/x86/mm/p2m-ept.c +1
-0#include <asm/p2m.h> #include <asm/hvm/vmx/vmx.h> #include <asm/hvm/vmx/vmcs.h> +#include <asm/hvm/nestedhvm.h> #include <xen/iommu.h> #include <asm/mtrr.h> #include <asm/hvm/cacheattr.h> @@ -1076,6 +1077,9 @@ void ept_sync_domain(struct p2m_domain*p2m)
Quoted 19 lines
Quoted 19 lines
xen/arch/x86/mm/p2m-ept.c void ept_sync_domain(struct p2m_domain *p2m) · line 1081
Quoted 5 lines
xen/arch/x86/mm/p2m-ept.c +2
-0ASSERT (local_irq_is_enabled ()); +if (nestedhvm_enabled (d) ) +p2m_flush_nestedp2m (d);It seems like this should trigger when the nested EPT table itself is being populated, e.g.
hvm_hap_nested_page_fault
-->nestedhvm_hap_nested_page_fault
-->nestedhap_fix_p2m(-->p2m_lock(p2m))
-->p2m_set_entry
-->ept_set_entry
-->ept_sync_domain
-->p2m_flush_nestedp2m
-->p2m_flush_table(-->p2m_lock(p2m))Quoted 1 line
Quoted 1 line
which would deadlock on the nested table's p2m lock. What have I
missed?
Quoted 7 lines
Yes, you are right.
Maybe we should add another condition checking, just like:
struct vcpu *v = current;
Quoted 7 lines
If(nestedhvm_enabled(d) && !nestedhvm_vcpu_in_guestmode(v) )p2m_flush_nestedp2m(d);Or add a
flag(is_nested_p2m)in the structp2m_domainto mark a nested EPT, and change the condition to:If(nestedhvm_enabled(d) && p2m->is_nested_p2m )
Quoted 5 lines
Yes, I think this is the right check, but you shouldn't need to add any new
flags:p2m_is_nestedp2m(p2m)will work.Also, in the next version of the patch, please describe what testing you've done.
Hi Tim,
I can boot the L2 guest successfully with my new patch, and I want to verify that without the fixed patch, there are some issue, but I don't know how to trigger the bug. Which case should the test cover? Could you give some suggestion?
Liang
Quoted 3 lines
Thanks
Tim.
Quoted 57 lines · Liang Z
Quoted 57 lines
Quoted 4 lines
Quoted 4 lines
xen/arch/x86/mm/p2m-
Quoted 4 lines
xen/arch/x86/mm/p2m-ept.c | 4 ++++ 1 file changed, 4 insertions(+)xen/arch/x86/mm/p2m- renamed from xen/arch/x86/mm/p2m-ept.c +0
-0
ept.cQuoted 4 lines
Quoted 4 lines
Quoted 4 lines
index 5133eb6..26293a0 100644
xen/arch/x86/mm/p2m-ept.c +0
-0@@ -26,6 +26,7 @@Quoted 8 lines
Quoted 8 lines
xen/arch/x86/mm/p2m-ept.c void ept_sync_domain(struct p2m_domain
Quoted 8 lines
xen/arch/x86/mm/p2m-ept.c +1
-0#include <asm/p2m.h> #include <asm/hvm/vmx/vmx.h> #include <asm/hvm/vmx/vmcs.h> +#include <asm/hvm/nestedhvm.h> #include <xen/iommu.h> #include <asm/mtrr.h> #include <asm/hvm/cacheattr.h> @@ -1076,6 +1077,9 @@ void ept_sync_domain(struct p2m_domain*p2m)
Quoted 19 lines
Quoted 19 lines
xen/arch/x86/mm/p2m-ept.c void ept_sync_domain(struct p2m_domain *p2m) · line 1081
Quoted 5 lines
xen/arch/x86/mm/p2m-ept.c +2
-0ASSERT (local_irq_is_enabled ()); +if (nestedhvm_enabled (d) ) +p2m_flush_nestedp2m (d);It seems like this should trigger when the nested EPT table itself is being populated, e.g.
hvm_hap_nested_page_fault
-->nestedhvm_hap_nested_page_fault
-->nestedhap_fix_p2m(-->p2m_lock(p2m))
-->p2m_set_entry
-->ept_set_entry
-->ept_sync_domain
-->p2m_flush_nestedp2m
-->p2m_flush_table(-->p2m_lock(p2m))Quoted 1 line
Quoted 1 line
which would deadlock on the nested table's p2m lock. What have I
missed?
Quoted 7 lines
Yes, you are right.
Maybe we should add another condition checking, just like:
struct vcpu *v = current;
Quoted 7 lines
If(nestedhvm_enabled(d) && !nestedhvm_vcpu_in_guestmode(v) )p2m_flush_nestedp2m(d);Or add a
flag(is_nested_p2m)in the structp2m_domainto mark a nested EPT, and change the condition to:If(nestedhvm_enabled(d) && p2m->is_nested_p2m )Yes, I think this is the right check, but you shouldn't need to add any new
flags:p2m_is_nestedp2m(p2m)will work.
Quoted 8 lines
Quoted 2 lines
Also, in the next version of the patch, please describe what testing you've done.
Hi Tim,
I can boot the L2 guest successfully with my new patch, and I want to verify that without the fixed patch, there are some issue, but I don't know how to trigger the bug. Which case should the test cover? Could you give some suggestion?
I'm not sure - I found the bug in the code, and not on a running system. I cn't even think of a way to provoke it without writing a malicious L1 guest.
IMO if it doesn't break existing nested support that'll be enough testing.
Tim.