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 4/6] x86/vvmx: Switch nested MSR intercept handling to use struct vmx_msr_bitmap
Date: Wed, 19 Jul 2017 12:57:55 +0100 [thread overview]
Message-ID: <1500465477-23793-5-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1500465477-23793-1-git-send-email-andrew.cooper3@citrix.com>
Rename vmx_check_msr_bitmap() to vmx_msr_is_intercepted() in order to more
clearly identify what the boolean return value means. Change the int
access_type to bool is_write.
The NULL pointer check is moved out, as it doesn't pertain to whether the MSR
is intercepted or not. The check is moved into nvmx_n2_vmexit_handler(),
where it becomes a hard error in the case that ACTIVATE_MSR_BITMAP is set.
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/vmcs.c | 31 +++++++++----------------------
xen/arch/x86/hvm/vmx/vvmx.c | 23 ++++++++++++-----------
xen/include/asm-x86/hvm/vmx/vmcs.h | 3 ++-
3 files changed, 23 insertions(+), 34 deletions(-)
diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c
index 0e1a142..f1427f8 100644
--- a/xen/arch/x86/hvm/vmx/vmcs.c
+++ b/xen/arch/x86/hvm/vmx/vmcs.c
@@ -862,31 +862,18 @@ void vmx_set_msr_intercept(struct vcpu *v, unsigned int msr,
ASSERT(!"MSR out of range for interception\n");
}
-/*
- * access_type: read == 0, write == 1
- */
-int vmx_check_msr_bitmap(unsigned long *msr_bitmap, u32 msr, int access_type)
+bool vmx_msr_is_intercepted(struct vmx_msr_bitmap *msr_bitmap,
+ unsigned int msr, bool is_write)
{
- int ret = 1;
- if ( !msr_bitmap )
- return 1;
-
if ( msr <= 0x1fff )
- {
- if ( access_type == 0 )
- ret = test_bit(msr, msr_bitmap + 0x000/BYTES_PER_LONG); /* read-low */
- else if ( access_type == 1 )
- ret = test_bit(msr, msr_bitmap + 0x800/BYTES_PER_LONG); /* write-low */
- }
+ return test_bit(msr, is_write ? msr_bitmap->write_low
+ : msr_bitmap->read_low);
else if ( (msr >= 0xc0000000) && (msr <= 0xc0001fff) )
- {
- msr &= 0x1fff;
- if ( access_type == 0 )
- ret = test_bit(msr, msr_bitmap + 0x400/BYTES_PER_LONG); /* read-high */
- else if ( access_type == 1 )
- ret = test_bit(msr, msr_bitmap + 0xc00/BYTES_PER_LONG); /* write-high */
- }
- return ret;
+ return test_bit(msr & 0x1fff, is_write ? msr_bitmap->write_high
+ : msr_bitmap->read_high);
+ else
+ /* MSRs outside the bitmap ranges are always intercepted. */
+ return true;
}
diff --git a/xen/arch/x86/hvm/vmx/vvmx.c b/xen/arch/x86/hvm/vmx/vvmx.c
index 2c8cf63..0d08789 100644
--- a/xen/arch/x86/hvm/vmx/vvmx.c
+++ b/xen/arch/x86/hvm/vmx/vvmx.c
@@ -2284,22 +2284,23 @@ int nvmx_n2_vmexit_handler(struct cpu_user_regs *regs,
/* inject to L1 */
nvcpu->nv_vmexit_pending = 1;
break;
+
case EXIT_REASON_MSR_READ:
case EXIT_REASON_MSR_WRITE:
- {
- int status;
ctrl = __n2_exec_control(v);
- if ( ctrl & CPU_BASED_ACTIVATE_MSR_BITMAP )
- {
- status = vmx_check_msr_bitmap(nvmx->msrbitmap, regs->ecx,
- !!(exit_reason == EXIT_REASON_MSR_WRITE));
- if ( status )
- nvcpu->nv_vmexit_pending = 1;
- }
- else
+
+ /* Without ACTIVATE_MSR_BITMAP, all MSRs are intercepted. */
+ if ( !(ctrl & CPU_BASED_ACTIVATE_MSR_BITMAP) )
nvcpu->nv_vmexit_pending = 1;
+ else if ( !nvmx->msrbitmap )
+ /* ACTIVATE_MSR_BITMAP set, but L2 bitmap not mapped??? */
+ domain_crash(v->domain);
+ else
+ nvcpu->nv_vmexit_pending =
+ vmx_msr_is_intercepted(nvmx->msrbitmap, regs->ecx,
+ exit_reason == EXIT_REASON_MSR_WRITE);
break;
- }
+
case EXIT_REASON_IO_INSTRUCTION:
ctrl = __n2_exec_control(v);
if ( ctrl & CPU_BASED_ACTIVATE_IO_BITMAP )
diff --git a/xen/include/asm-x86/hvm/vmx/vmcs.h b/xen/include/asm-x86/hvm/vmx/vmcs.h
index 926e792..32a6732 100644
--- a/xen/include/asm-x86/hvm/vmx/vmcs.h
+++ b/xen/include/asm-x86/hvm/vmx/vmcs.h
@@ -543,7 +543,8 @@ int vmx_add_msr(u32 msr, int type);
void vmx_vmcs_switch(paddr_t from, paddr_t to);
void vmx_set_eoi_exit_bitmap(struct vcpu *v, u8 vector);
void vmx_clear_eoi_exit_bitmap(struct vcpu *v, u8 vector);
-int vmx_check_msr_bitmap(unsigned long *msr_bitmap, u32 msr, int access_type);
+bool vmx_msr_is_intercepted(struct vmx_msr_bitmap *msr_bitmap,
+ unsigned int msr, bool is_write) __nonnull(1);
void virtual_vmcs_enter(const struct vcpu *);
void virtual_vmcs_exit(const struct vcpu *);
u64 virtual_vmcs_vmread(const struct vcpu *, u32 encoding);
--
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-07-19 11:57 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-19 11:57 [PATCH 0/6] x86/vvmx: Fixes to MSR_BITMAP interception handling Andrew Cooper
2017-07-19 11:57 ` [PATCH 1/6] x86/vmx: Improvements to vmx_{dis, en}able_intercept_for_msr() Andrew Cooper
2017-07-27 5:43 ` Tian, Kevin
2017-07-19 11:57 ` [PATCH 2/6] x86/vpmu: Use vmx_{clear, set}_msr_intercept() rather than opencoding them Andrew Cooper
2017-07-19 12:17 ` Andrew Cooper
2017-07-27 5:46 ` Tian, Kevin
2017-07-19 13:33 ` Boris Ostrovsky
2017-07-19 11:57 ` [PATCH 3/6] x86/vmx: Introduce and use struct vmx_msr_bitmap Andrew Cooper
2017-07-27 6:02 ` Tian, Kevin
2017-07-27 8:30 ` Andrew Cooper
2017-07-27 9:01 ` Tian, Kevin
2017-07-19 11:57 ` Andrew Cooper [this message]
2017-07-27 6:09 ` [PATCH 4/6] x86/vvmx: Switch nested MSR intercept handling to " Tian, Kevin
2017-07-19 11:57 ` [PATCH 5/6] x86/vvmx: Fix handing of the MSR_BITMAP field with VMCS shadowing Andrew Cooper
2017-07-26 8:50 ` Sergey Dyasli
2017-07-27 6:11 ` Tian, Kevin
2017-07-19 11:57 ` [PATCH 6/6] x86/vvmx: Fix auditing of MSR_BITMAP parameter Andrew Cooper
2017-07-27 6:13 ` 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=1500465477-23793-5-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).