From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
Kevin Tian <kevin.tian@intel.com>,
Jun Nakajima <jun.nakajima@intel.com>,
Jan Beulich <JBeulich@suse.com>
Subject: [PATCH 2/3] x86/vmx: Don't self-recurse in vmx_update_guest_cr()
Date: Fri, 29 Sep 2017 19:31:02 +0100 [thread overview]
Message-ID: <1506709863-12291-3-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1506709863-12291-1-git-send-email-andrew.cooper3@citrix.com>
An update to CR4 following a CR0 update can be done easily by falling
through into the CR4 case. This avoids unnecessary passes through
vmx_vmcs_{enter,exit}() and unnecessary stack usage (as the compiler
cannot optimise this use to a tailcall).
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Jun Nakajima <jun.nakajima@intel.com>
CC: Kevin Tian <kevin.tian@intel.com>
---
xen/arch/x86/hvm/vmx/vmx.c | 40 ++++++++++++++++++----------------------
1 file changed, 18 insertions(+), 22 deletions(-)
diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index 61047e0..5b943d4 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -1627,29 +1627,8 @@ static void vmx_update_guest_cr(struct vcpu *v, unsigned int cr)
v->arch.hvm_vcpu.hw_cr[0] =
v->arch.hvm_vcpu.guest_cr[0] | hw_cr0_mask;
__vmwrite(GUEST_CR0, v->arch.hvm_vcpu.hw_cr[0]);
-
- /* Changing CR0 can change some bits in real CR4. */
- vmx_update_guest_cr(v, 4);
- break;
}
-
- case 2:
- /* CR2 is updated in exit stub. */
- break;
-
- case 3:
- if ( paging_mode_hap(v->domain) )
- {
- 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);
- }
-
- __vmwrite(GUEST_CR3, v->arch.hvm_vcpu.hw_cr[3]);
- hvm_asid_flush_vcpu(v);
- break;
-
+ /* Fallthrough: Changing CR0 can change some bits in real CR4. */
case 4:
v->arch.hvm_vcpu.hw_cr[4] = HVM_CR4_HOST_MASK;
if ( paging_mode_hap(v->domain) )
@@ -1681,6 +1660,23 @@ static void vmx_update_guest_cr(struct vcpu *v, unsigned int cr)
__vmwrite(GUEST_CR4, v->arch.hvm_vcpu.hw_cr[4]);
break;
+ case 2:
+ /* CR2 is updated in exit stub. */
+ break;
+
+ case 3:
+ if ( paging_mode_hap(v->domain) )
+ {
+ 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);
+ }
+
+ __vmwrite(GUEST_CR3, v->arch.hvm_vcpu.hw_cr[3]);
+ hvm_asid_flush_vcpu(v);
+ break;
+
default:
BUG();
}
--
2.1.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-09-29 18:31 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-29 18:31 [PATCH 0/3] x86/vmx: Minor improvements to vmx_update_guest_cr() Andrew Cooper
2017-09-29 18:31 ` [PATCH 1/3] x86/vmx: Misc cleanup " Andrew Cooper
2017-10-03 11:53 ` Roger Pau Monné
2017-10-10 5:25 ` Tian, Kevin
2017-09-29 18:31 ` Andrew Cooper [this message]
2017-10-03 12:01 ` [PATCH 2/3] x86/vmx: Don't self-recurse in vmx_update_guest_cr() Roger Pau Monné
2017-10-10 5:26 ` Tian, Kevin
2017-09-29 18:31 ` [PATCH 3/3] x86/vmx: Better description of CR4 settings outside of paged mode Andrew Cooper
2017-10-03 14:04 ` Roger Pau Monné
2017-10-03 14:12 ` Andrew Cooper
2017-10-03 15:12 ` Roger Pau Monné
2017-10-10 5:31 ` Tian, Kevin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1506709863-12291-3-git-send-email-andrew.cooper3@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=JBeulich@suse.com \
--cc=jun.nakajima@intel.com \
--cc=kevin.tian@intel.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).