Skip to contentSkip to conversation

VMX: Eliminate cr3 save/loading exiting when UG enabled

PATCH Superseded Yang Zhang 2 participants 6 messages Dec 18, 2013

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Yang Zhang

author
#0 lore raw

PATCH v2 1/1 VMX: Eliminate cr3 save/loading exiting when UG enabled

From: Yang Zhang <[email protected]>

With the feature of unrestricted guest, there should no vmexit be triggered when guest accesses the cr3 in non-paging mode.

---
changes in v2:
Fix the guest boot failure on non-UG platform.

The previous patch doesn't consider the non-UG platform and will cause guest boot failure on non-ug platform. During developing this patch, i was thinking whether the reading of GUEST_CR3 is necessary on each vmexit. I thought the answer should be no. But current implemention relies the {hw,guest}_cr3 in many places and it hard to do a cleanup.(If anyone interesting, welcome :))

BTW: this patch will improve performance, especially for context switching intensive workload, we saw about 1% improvement. So please backport it to 4.3.

---
 xen/arch/x86/hvm/vmx/vmx.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +5 -4
index dfff628..f6409d6 100644
@@ -1157,7 +1157,7 @@ static void vmx_update_guest_cr(struct vcpu *v, unsigned int cr)
             uint32_t cr3_ctls = (CPU_BASED_CR3_LOAD_EXITING |
                                  CPU_BASED_CR3_STORE_EXITING);
             v->arch.hvm_vmx.exec_control &= ~cr3_ctls;
-            if ( !hvm_paging_enabled(v) )
+            if ( !hvm_paging_enabled(v) && !vmx_unrestricted_guest(v) )
                 v->arch.hvm_vmx.exec_control |= cr3_ctls;
 
             /* Trap CR3 updates if CR3 memory events are enabled. */
@@ -1231,7 +1231,7 @@ static void vmx_update_guest_cr(struct vcpu *v, unsigned int cr)
     case 3:
         if ( paging_mode_hap(v->domain) )
         {
-            if ( !hvm_paging_enabled(v) )
+            if ( !hvm_paging_enabled(v) && !vmx_unrestricted_guest(v) )
                 v->arch.hvm_vcpu.hw_cr[3] =
                     v->domain->arch.hvm_domain.params[HVM_PARAM_IDENT_PT];
             vmx_load_pdptrs(v);
@@ -2487,10 +2487,11 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs)
 
     hvm_invalidate_regs_fields(regs);
 
-    if ( paging_mode_hap(v->domain) && hvm_paging_enabled(v) )
+    if ( paging_mode_hap(v->domain) )
     {
         __vmread(GUEST_CR3, &v->arch.hvm_vcpu.hw_cr[3]);
-        v->arch.hvm_vcpu.guest_cr[3] = v->arch.hvm_vcpu.hw_cr[3];
+        if ( vmx_unrestricted_guest(v) || hvm_paging_enabled(v) )
+            v->arch.hvm_vcpu.guest_cr[3] = v->arch.hvm_vcpu.hw_cr[3];
     }
 
     __vmread(VM_EXIT_REASON, &exit_reason);
Signature · 1 line
1.7.1
#1 lore raw
Quoted 6 lines
Quoted 1 line
Quoted 1 line · Yang Zhang

From: Yang Zhang <[email protected]>

With the feature of unrestricted guest, there should no vmexit be triggered when guest accesses the cr3 in non-paging mode.

Quoted 8 lines

---
changes in v2:
Fix the guest boot failure on non-UG platform.

The previous patch doesn't consider the non-UG platform and will cause guest boot
failure on non-ug platform.

Which "previous patch"? This one being v2, yet there not being a v1 with the same title on the list back until the beginning of October, what you say here is rather confusing. Please be a little more considerate of other people's time and provide more precise information: If a patch needing fixing went in already, name its commit ID and title. If the patch needing fixing didn't go in yet, integrate the fix with that patch (or series) and submit a new version. And if you post a v2 of a patch under a different title than the v1 was posted, please provide enough information to be able to identify that patch.

Jan

Jan

Quoted 55 lines

During developing this patch, i was thinking
whether
the reading of GUEST_CR3 is necessary on each vmexit. I thought the answer should
be no. But current implemention relies the {hw,guest}_cr3 in many places and it
hard to do a cleanup.(If anyone interesting, welcome :))

BTW: this patch will improve performance, especially for context switching intensive
workload, we saw about 1% improvement. So please backport it to 4.3.

---
 xen/arch/x86/hvm/vmx/vmx.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +1 -1
index dfff628..f6409d6 100644
@@ -1157,7 +1157,7 @@ static void vmx_update_guest_cr(struct vcpu *v, 
 unsigned int cr)
             uint32_t cr3_ctls = (CPU_BASED_CR3_LOAD_EXITING |
                                  CPU_BASED_CR3_STORE_EXITING);
             v->arch.hvm_vmx.exec_control &= ~cr3_ctls;
-            if ( !hvm_paging_enabled(v) )
+            if ( !hvm_paging_enabled(v) && !vmx_unrestricted_guest(v) )
                 v->arch.hvm_vmx.exec_control |= cr3_ctls;
 
             /* Trap CR3 updates if CR3 memory events are enabled. */
xen/arch/x86/hvm/vmx/vmx.c +1 -1
@@ -1231,7 +1231,7 @@ static void vmx_update_guest_cr(struct vcpu *v, 
 unsigned int cr)
     case 3:
         if ( paging_mode_hap(v->domain) )
         {
-            if ( !hvm_paging_enabled(v) )
+            if ( !hvm_paging_enabled(v) && !vmx_unrestricted_guest(v) )
                 v->arch.hvm_vcpu.hw_cr[3] =
                     v->domain->arch.hvm_domain.params[HVM_PARAM_IDENT_PT];
             vmx_load_pdptrs(v);
xen/arch/x86/hvm/vmx/vmx.c +3 -2
@@ -2487,10 +2487,11 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs)
 
     hvm_invalidate_regs_fields(regs);
 
-    if ( paging_mode_hap(v->domain) && hvm_paging_enabled(v) )
+    if ( paging_mode_hap(v->domain) )
     {
         __vmread(GUEST_CR3, &v->arch.hvm_vcpu.hw_cr[3]);
-        v->arch.hvm_vcpu.guest_cr[3] = v->arch.hvm_vcpu.hw_cr[3];
+        if ( vmx_unrestricted_guest(v) || hvm_paging_enabled(v) )
+            v->arch.hvm_vcpu.guest_cr[3] = v->arch.hvm_vcpu.hw_cr[3];
     }
 
     __vmread(VM_EXIT_REASON, &exit_reason);
Signature · 1 line
1.7.1
#2 lore raw

Jan Beulich wrote on 2013-12-18:

Quoted 14 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line · Yang Zhang

From: Yang Zhang <[email protected]>

With the feature of unrestricted guest, there should no vmexit be triggered when guest accesses the cr3 in non-paging mode.

Quoted 7 lines

---
changes in v2:
Fix the guest boot failure on non-UG platform.

The previous patch doesn't consider the non-UG platform and will cause guest boot failure on non-ug platform.

Quoted 8 lines

Which "previous patch"? This one being v2, yet there not being a
v1 with the same title on the list back until the beginning of
October, what you say here is rather confusing. Please be a little
more considerate of other people's time and provide more precise
information: If a patch needing fixing went in already, name its
commit ID and title. If the patch needing fixing didn't go in yet, integrate the fix with that patch (or series) and submit a new version. And if you post a v2 of a patch under a different title than the v1
was posted, please provide enough information to be able to identify that patch.

Don't know why you cannot find the first patch:
http://www.gossamer-threads.com/lists/xen/devel/302810

Quoted 58 lines

Jan

Jan

Quoted 17 lines

During developing this patch, i was thinking whether the reading of GUEST_CR3 is necessary on each vmexit. I thought the answer should be no. But current implemention relies the {hw,guest}_cr3 in many places and it hard to do a cleanup.(If anyone interesting, welcome :))

BTW: this patch will improve performance, especially for context switching intensive workload, we saw about 1% improvement. So please backport it to 4.3.

---
 xen/arch/x86/hvm/vmx/vmx.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +0 -0
index dfff628..f6409d6 100644

xen/arch/x86/hvm/vmx/vmx.c static void vmx_update_guest_cr(struct vcpu · line 1158

Quoted 2 lines
xen/arch/x86/hvm/vmx/vmx.c +0 -0
@@ -1157,7 +1157,7 @@ static void vmx_update_guest_cr(struct vcpu
 *v, unsigned int cr)
             uint32_t cr3_ctls = (CPU_BASED_CR3_LOAD_EXITING |

CPU_BASED_CR3_STORE_EXITING);

Quoted 12 lines
xen/arch/x86/hvm/vmx/vmx.c +3 -1
             v->arch.hvm_vmx.exec_control &= ~cr3_ctls;
-            if ( !hvm_paging_enabled(v) )
+            if ( !hvm_paging_enabled(v) &&
+ !vmx_unrestricted_guest(v)
+ )
                 v->arch.hvm_vmx.exec_control |= cr3_ctls;
             /* Trap CR3 updates if CR3 memory events are enabled.

*/ @@ -1231,7 +1231,7 @@ static void vmx_update_guest_cr(struct vcpu *v, unsigned int cr)

     case 3:
         if ( paging_mode_hap(v->domain) )
         {

xen/arch/x86/hvm/vmx/vmx.c

Quoted 5 lines
xen/arch/x86/hvm/vmx/vmx.c +3 -1
-            if ( !hvm_paging_enabled(v) )
+            if ( !hvm_paging_enabled(v) &&
+ !vmx_unrestricted_guest(v)
+ )
                 v->arch.hvm_vcpu.hw_cr[3] =

v->domain->arch.hvm_domain.params[HVM_PARAM_IDENT_PT];

Quoted 15 lines
             vmx_load_pdptrs(v);
xen/arch/x86/hvm/vmx/vmx.c +4 -2
@@ -2487,10 +2487,11 @@ void vmx_vmexit_handler(struct cpu_user_regs
 *regs)
 
     hvm_invalidate_regs_fields(regs);
-    if ( paging_mode_hap(v->domain) && hvm_paging_enabled(v) )
+    if ( paging_mode_hap(v->domain) )
     {
         __vmread(GUEST_CR3, &v->arch.hvm_vcpu.hw_cr[3]);
-        v->arch.hvm_vcpu.guest_cr[3] = v->arch.hvm_vcpu.hw_cr[3];
+        if ( vmx_unrestricted_guest(v) || hvm_paging_enabled(v) )
+            v->arch.hvm_vcpu.guest_cr[3] =
+ v->arch.hvm_vcpu.hw_cr[3];
     }
 
Quoted 5 lines
Quoted 3 lines
     __vmread(VM_EXIT_REASON, &exit_reason);

--
1.7.1

Best regards,
Yang

#3 lore raw
Quoted 22 lines
Quoted 1 line
Quoted 1 line · Yang Z

Jan Beulich wrote on 2013-12-18:

Quoted 14 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line · Yang Zhang

From: Yang Zhang <[email protected]>

With the feature of unrestricted guest, there should no vmexit be triggered when guest accesses the cr3 in non-paging mode.

Quoted 7 lines

---
changes in v2:
Fix the guest boot failure on non-UG platform.

The previous patch doesn't consider the non-UG platform and will cause guest boot failure on non-ug platform.

Quoted 6 lines

Which "previous patch"? This one being v2, yet there not being a v1 with the same title on the list back until the beginning of October, what you say here is rather confusing. Please be a little more considerate of other people's time and provide more precise
information: If a patch needing fixing went in already, name its commit ID and title. If the patch needing fixing didn't go in yet, integrate

Quoted 7 lines

the fix with that patch (or series) and submit a new version.

Quoted 2 lines

And if you post a v2 of a patch under a different title than the v1 was posted, please provide enough information to be able to identify that

patch.

Don't know why you cannot find the first patch:
http://www.gossamer-threads.com/lists/xen/devel/302810

Note the subject difference: "VMX: Eliminate cr3 store/load vmexit when UG enabled" there vs "VMX: Eliminate cr3 save/loading exiting when UG enabled" here. I searched the list archives for "save/loading".

Furthermore, you submitted v2 with the same description as v1, even though a correction was already suggested. You should incorporate such feedback rather than leaving it to the maintainers. I'll be looking forward to see a v3, hopefully within less than almost 2 months (as was the case for v2 compared to v1, not making the tracking of it easier either).

Finally on the earlier thread you suggested that you'd have this go through a full round of testing - nothing in that regard was said here...

Jan

#4 lore raw

Jan Beulich wrote on 2013-12-18:

Quoted 35 lines
Quoted 26 lines
Quoted 1 line
Quoted 1 line · Yang Z

Jan Beulich wrote on 2013-12-18:

Quoted 14 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line · Yang Zhang

From: Yang Zhang <[email protected]>

With the feature of unrestricted guest, there should no vmexit be triggered when guest accesses the cr3 in non-paging mode.

Quoted 7 lines

---
changes in v2:
Fix the guest boot failure on non-UG platform.

The previous patch doesn't consider the non-UG platform and will cause guest boot failure on non-ug platform.

Quoted 10 lines

Which "previous patch"? This one being v2, yet there not being a v1 with the same title on the list back until the beginning of October, what you say here is rather confusing. Please be a little more considerate of other people's time and provide more precise
information: If a patch needing fixing went in already, name its commit ID and title. If the patch needing fixing didn't go in yet, integrate the fix with that patch (or series) and submit a new version. And if you post a v2 of a patch under a different title than the v1 was posted, please provide enough information to be able to identify that

Quoted 4 lines

patch.

Don't know why you cannot find the first patch:
http://www.gossamer-threads.com/lists/xen/devel/302810

Note the subject difference: "VMX: Eliminate cr3 store/load vmexit when UG enabled" there vs "VMX: Eliminate cr3 save/loading exiting when UG enabled" here. I searched the list archives for "save/loading".

Quoted 6 lines

Furthermore, you submitted v2 with the same description as v1, even though a correction was already suggested. You should incorporate such feedback rather than leaving it to the maintainers. I'll be looking forward to see a v3, hopefully within less than almost 2 months (as was the case for v2 compared to v1, not making the tracking of it easier either).

First, you found the regression on 30 Dec. So there is no 2 months until v2. Second, everyone may take vacation or focus on new field and delay a task for long time or never pick it up again. Third, I don't think there are any rule that patch must send out between one or two months.

Quoted 3 lines

Finally on the earlier thread you suggested that you'd have this go through a full round of testing - nothing in that regard was said here...

I said " I will ask our QA to do a full testing against this patch to see whether it introduces any regression" not "we already finished a full round testing and didn't see any regression". And our QA also saw the issue when Xen's automatic testing bot reported the bug. What you want me to said here?

Quoted 1 line

Jan

Best regards,
Yang

#5 lore raw
Quoted 7 lines
Quoted 1 line
Quoted 1 line · Yang Z

Jan Beulich wrote on 2013-12-18:

Quoted 5 lines

Furthermore, you submitted v2 with the same description as v1, even though a correction was already suggested. You should incorporate such feedback rather than leaving it to the maintainers. I'll be looking forward to see a v3, hopefully within less than almost 2 months (as was the case for v2 compared to v1, not making the tracking of it easier

Quoted 7 lines

either).

Quoted 1 line

First, you found the regression on 30 Dec. So there is no 2 months until v2. Second, everyone may take vacation or focus on new field and delay a task for long time or never pick it up again. Third, I don't think there are any rule that patch must send out between one or two months.

That's all correct, and not the point of my complaint. All I'm asking for is that it be made reasonably simple to understand the history of a patch. Which implies that the longer the gap between two revisions, the more extended the reminder on what this is about ought to be.

Quoted 8 lines
Quoted 3 lines

Finally on the earlier thread you suggested that you'd have this go through a full round of testing - nothing in that regard was said here...

I said " I will ask our QA to do a full testing against this patch to see whether it introduces any regression" not "we already finished a full round testing and didn't see any regression". And our QA also saw the issue when Xen's automatic testing bot reported the bug. What you want me to said here?

You could have stated exactly that, or perhaps that the new patch has meanwhile undergone full testing.

Jan