VMX: Eliminate cr3 save/loading exiting when UG enabled
PATCH v3 1/1 VMX: Eliminate cr3 save/loading exiting when UG enabled
From: Yang Zhang <[email protected]>
With the feature of unrestricted guest, there should be no vmexit be triggered when guest accesses the cr3 in non-paging mode. This patch will clear the cr3 save/loading bit in vmcs control filed to eliminate cr3 access vmexit on UG avaliable hardware.
The previous patch (commit c9efe34c119418a5ac776e5d91aeefcce4576518) did the same thing compare to this one. But it will cause guest fail to boot up on non-UG hardware which is repoted by Jan and it has been reverted (commit 1e2bf05ec37cf04b0e01585eae524509179f165e).
This patch incorporate the fixing and guest are working well both in UG and non-UG platform with this patch.
---
changes in v3:
Revise the patch description according Jan's suggestion
changes in v2:
Fix the guest boot failure on non-UG platform.
There are some discussions around the first patch, please see the following link:
http://www.gossamer-threads.com/lists/xen/devel/302810
--- xen/arch/x86/hvm/vmx/vmx.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-)
xen/arch/x86/hvm/vmx/vmx.c +5 -4
@@ -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
Zhang, Yang Z wrote on 2013-12-19:
Quoted 7 lines
From: Yang Zhang <[email protected]>
With the feature of unrestricted guest, there should be no vmexit be triggered when guest accesses the cr3 in non-paging mode. This patch will clear the cr3 save/loading bit in vmcs control filed to eliminate cr3 access vmexit on UG avaliable hardware.
Quoted 8 lines
The previous patch (commit
c9efe34c119418a5ac776e5d91aeefcce4576518) did the same thing compare to this one. But it will cause guest fail to boot up on non-UG hardware which is repoted by Jan and it has been reverted (commit1e2bf05ec37cf04b0e01585eae524509179f165e).This patch incorporate the fixing and guest are working well both in UG and non-UG platform with this patch.
Hi, Jun and Andrew,
Please help to review this one which is different from the first one.
The main difference is that on non-UG hardware, guest may write cr3 before enabling paging. So we should not set guest_cr3 to the value of hw_cr3 which contain the EPT identify mapping address on non-paging mode .
Quoted 42 lines
Reported-by Jan Beulich <[email protected]>Signed-off-by Yang Zhang <[email protected]>---
changes in v3:
Revise the patch description according Jan's suggestionchanges in v2:
Fix the guest boot failure on non-UG platform.There are some discussions around the first patch, please see the following link: http://www.gossamer-threads.com/lists/xen/devel/302810
--- xen/arch/x86/hvm/vmx/vmx.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-)xen/arch/x86/hvm/vmx/vmx.c +0
-0
b/xen/arch/x86/hvm/vmx/vmx.c@@ -1157,7 +1157,7 @@ static voidvmx_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;xen/arch/x86/hvm/vmx/vmx.c +4
-2-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);xen/arch/x86/hvm/vmx/vmx.c +0
-0@@ -2487,10 +2487,11 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs)hvm_invalidate_regs_fields (regs);
xen/arch/x86/hvm/vmx/vmx.c void vmx_vmexit_handler(struct cpu_user_regs · line 2497
Quoted 10 lines
xen/arch/x86/hvm/vmx/vmx.c +3
-2-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);
Best regards,
Yang
Quoted 10 lines · Yang Zhang
From: Yang Zhang <[email protected]>
With the feature of unrestricted guest, there should be no vmexit be triggered when guest accesses the cr3 in non-paging mode. This patch will clear the cr3 save/loading bit in vmcs control filed to eliminate cr3 access vmexit on UG avaliable hardware.
The previous patch (commit
c9efe34c119418a5ac776e5d91aeefcce4576518) did the same thing compare to this one. But it will cause guest fail to boot up on non-UG hardware which is repoted by Jan and it has been
"reported by"
Quoted 7 lines
reverted (commit
1e2bf05ec37cf04b0e01585eae524509179f165e).This patch incorporate the fixing and guest are working well both in UG and non-UG platform with this patch.
Reported-by Jan Beulich <[email protected]>Signed-off-by Yang Zhang <[email protected]>
Looks plausible.
Quoted 50 lines
---
changes in v3:
Revise the patch description according Jan's suggestionchanges in v2:
Fix the guest boot failure on non-UG platform.There are some discussions around the first patch, please see the following link:
http://www.gossamer-threads.com/lists/xen/devel/302810--- xen/arch/x86/hvm/vmx/vmx.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-)xen/arch/x86/hvm/vmx/vmx.c +5
-4@@ -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);
Zhang, Yang Z wrote on 2013-12-19:
Quoted 7 lines
From: Yang Zhang <[email protected]>
With the feature of unrestricted guest, there should be no vmexit be triggered when guest accesses the cr3 in non-paging mode. This patch will clear the cr3 save/loading bit in vmcs control filed to eliminate cr3 access vmexit on UG avaliable hardware.
Quoted 5 lines
The previous patch (commit
c9efe34c119418a5ac776e5d91aeefcce4576518) did the same thing compare to this one. But it will cause guest fail to boot up on non-UG hardware which is repoted by Jan and it has been reverted (commit1e2bf05ec37cf04b0e01585eae524509179f165e).
Hi, Jun.
Can you help to review this patch?
Quoted 45 lines
This patch incorporate the fixing and guest are working well both in UG and non-UG platform with this patch.
Reported-by Jan Beulich <[email protected]>Signed-off-by Yang Zhang <[email protected]>---
changes in v3:
Revise the patch description according Jan's suggestionchanges in v2:
Fix the guest boot failure on non-UG platform.There are some discussions around the first patch, please see the following link: http://www.gossamer-threads.com/lists/xen/devel/302810
--- xen/arch/x86/hvm/vmx/vmx.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-)xen/arch/x86/hvm/vmx/vmx.c +0
-0
b/xen/arch/x86/hvm/vmx/vmx.c@@ -1157,7 +1157,7 @@ static voidvmx_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;xen/arch/x86/hvm/vmx/vmx.c +4
-2-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);xen/arch/x86/hvm/vmx/vmx.c +0
-0@@ -2487,10 +2487,11 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs)hvm_invalidate_regs_fields (regs);
xen/arch/x86/hvm/vmx/vmx.c void vmx_vmexit_handler(struct cpu_user_regs · line 2497
Quoted 10 lines
xen/arch/x86/hvm/vmx/vmx.c +3
-2-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);
Best regards,
Yang
Quoted 8 lines · Yang Z
Zhang, Yang Z wrote on 2013-12-19:
Quoted 7 lines
From: Yang Zhang <[email protected]>
With the feature of unrestricted guest, there should be no vmexit be triggered when guest accesses the cr3 in non-paging mode. This patch will clear the cr3 save/loading bit in vmcs control filed to eliminate cr3 access vmexit on UG avaliable hardware.
Quoted 8 lines
Quoted 5 lines
The previous patch (commit
c9efe34c119418a5ac776e5d91aeefcce4576518) did the same thing compare to this one. But it will cause guest fail to boot up on non-UG hardware which is repoted by Jan and it has been reverted (commit1e2bf05ec37cf04b0e01585eae524509179f165e).Hi, Jun.
Can you help to review this patch?
This got committed earlier today
http://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=f4fed540e78ac8a2bd3b1dee53a5206dde25f613)
as you are a maintainer, and I (as an independent party as far as the patch goes) reviewed it.
Quoted 61 lines
Quoted 46 lines
This patch incorporate the fixing and guest are working well both in UG and non-UG platform with this patch.
Reported-by Jan Beulich <[email protected]>Signed-off-by Yang Zhang <[email protected]>---
changes in v3:
Revise the patch description according Jan's suggestionchanges in v2:
Fix the guest boot failure on non-UG platform.There are some discussions around the first patch, please see the following link: http://www.gossamer-threads.com/lists/xen/devel/302810
--- xen/arch/x86/hvm/vmx/vmx.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-)xen/arch/x86/hvm/vmx/vmx.c +0
-0
b/xen/arch/x86/hvm/vmx/vmx.c@@ -1157,7 +1157,7 @@ static voidvmx_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;xen/arch/x86/hvm/vmx/vmx.c +4
-2-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);xen/arch/x86/hvm/vmx/vmx.c +0
-0@@ -2487,10 +2487,11 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs)hvm_invalidate_regs_fields (regs);xen/arch/x86/hvm/vmx/vmx.c void vmx_vmexit_handler(struct cpu_user_regs · line 2497
Quoted 10 lines
xen/arch/x86/hvm/vmx/vmx.c +3
-2-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);Best regards,
Yang
Andrew Cooper wrote on 2014-01-08:
Quoted 15 lines · Yang Z
Quoted 14 lines
Zhang, Yang Z wrote on 2013-12-19:
Quoted 13 lines
From: Yang Zhang <[email protected]>
With the feature of unrestricted guest, there should be no vmexit be triggered when guest accesses the cr3 in non-paging mode. This patch will clear the cr3 save/loading bit in vmcs control filed to eliminate
cr3 access vmexit on UG avaliable hardware.The previous patch (commit
c9efe34c119418a5ac776e5d91aeefcce4576518) did the same thing compare to this one. But it will cause guest fail to boot up on non-UG hardware which is repoted by Jan and it has been reverted (commit1e2bf05ec37cf04b0e01585eae524509179f165e).
Quoted 8 lines
Quoted 3 lines
Hi, Jun.
Can you help to review this patch?
This got committed earlier today
http://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=f4fed540e78ac8
a2bd3b1dee53a5206dde25f613) as you are a maintainer, and I (as an independent party as far as the patch goes) reviewed it.
I remember in old day, after a patch got committed, the maintainer will reply the mail to tell the author it is applied. Or else, it's hard for author to know it in time. Should we still follow this rule?
BTW: KVM always follow this rule.
Quoted 26 lines
Quoted 18 lines
Quoted 18 lines
This patch incorporate the fixing and guest are working well both in UG and non-UG platform with this patch.
Reported-by Jan Beulich <[email protected]>Signed-off-by Yang Zhang <[email protected]>---
changes in v3:
Revise the patch description according Jan's suggestionchanges in v2:
Fix the guest boot failure on non-UG platform.There are some discussions around the first patch, please see the following link:
http://www.gossamer-threads.com/lists/xen/devel/302810Quoted 8 lines
Quoted 8 lines
--- xen/arch/x86/hvm/vmx/vmx.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-) diff --git
a/xen/arch/x86/hvm/vmx/vmx.cb/xen/arch/x86/hvm/vmx/vmx.cindex dfff628..f6409d6 100644 ---a/xen/arch/x86/hvm/vmx/vmx.c+++b/xen/arch/x86/hvm/vmx/vmx.c@@ -1157,7 +1157,7 @@ static voidvmx_update_guest_cr(struct vcpu *v, unsigned int cr)uint32_t cr3_ctls = (CPU_BASED_CR3_LOAD_EXITING |
Quoted 40 lines
CPU_BASED_CR3_STORE_EXITING);Quoted 39 lines
Quoted 24 lines
v->arch.hvm_vmx.exec_control &= ~cr3_ctls;(quoted diff) +3
-1- 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) ) {(quoted diff) +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]; vmx_load_pdptrs(v);xen/arch/x86/hvm/vmx/vmx.c +0
-1@@ -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) )xen/arch/x86/hvm/vmx/vmx.c void vmx_vmexit_handler(struct cpu_user_regs · line 2497
Quoted 10 lines
xen/arch/x86/hvm/vmx/vmx.c +4
-1+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);Best regards,
Yang
Best regards,
Yang
Quoted 5 lines
Quoted 1 line
Quoted 1 line · Yang Z
Andrew Cooper wrote on 2014-01-08:
Quoted 3 lines · Yang Z
Quoted 1 line
Can you help to review this patch?
Quoted 8 lines
Quoted 4 lines
This got committed earlier today
http://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=f4fed540e78ac8
a2bd3b1dee53a5206dde25f613) as you are a maintainer, and I (as an independent party as far as the patch goes) reviewed it.I remember in old day, after a patch got committed, the maintainer will reply the mail to tell the author it is applied. Or else, it's hard for author to know it in time. Should we still follow this rule?
As it requires extra work, and it's easy to check the tree (there aren't that many commits during a day), and there are generally no intermediate trees (i.e. just a single canonical one to look at), I never reply with commit notifications. If anything like that is being wanted, then this should be via an automatic commit notification mechanism (and ISTR that there is a respective list you could subscribe to).
Jan
Jan Beulich wrote on 2014-01-08:
Quoted 15 lines
Quoted 11 lines
Quoted 1 line
Quoted 1 line · Yang Z
Andrew Cooper wrote on 2014-01-08:
Quoted 8 lines · Yang Z
Quoted 1 line
Can you help to review this patch?
This got committed earlier today
http://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=f4fed540e78
ac
8 a2bd3b1dee53a5206dde25f613) as you are a maintainer, and I (as an independent party as far as the patch goes) reviewed it.Quoted 3 lines
I remember in old day, after a patch got committed, the maintainer will reply the mail to tell the author it is applied. Or else, it's hard for author to know it in time. Should we still follow this rule?
Quoted 7 lines
As it requires extra work, and it's easy to check the tree (there
aren't that many commits during a day), and there are generally no intermediate trees (i.e. just a single canonical one to look at), I never reply with commit notifications. If anything like that is being wanted, then this should
be via an automatic commit notification mechanism (and ISTR that there
is a respective list you could subscribe to).
Yes, I should subscribe Xen change log list to track the committed patch. It can solve my concern.
Quoted 1 line
Jan
Best regards,
Yang