[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH v4 11/11] nested vmx: check host ability when intercept MSR read
>>> On 06.12.12 at 14:01, Dongxiao Xu <dongxiao.xu@xxxxxxxxx> wrote: > When guest hypervisor tries to read MSR value, we intercept this behavior > and return certain emulated values. Besides that, we also need to ensure > that those emulated values must compatible with host ability. > > Signed-off-by: Dongxiao Xu <dongxiao.xu@xxxxxxxxx> > --- > xen/arch/x86/hvm/vmx/vvmx.c | 16 +++++++++++++--- > 1 files changed, 13 insertions(+), 3 deletions(-) > > diff --git a/xen/arch/x86/hvm/vmx/vvmx.c b/xen/arch/x86/hvm/vmx/vvmx.c > index 178adbc..cacbee4 100644 > --- a/xen/arch/x86/hvm/vmx/vvmx.c > +++ b/xen/arch/x86/hvm/vmx/vvmx.c > @@ -1314,24 +1314,29 @@ int nvmx_handle_vmwrite(struct cpu_user_regs *regs) > return X86EMUL_OKAY; > } > > +#define combine_host_cap(data, host_data) \ > + (((data & host_data) & (~0ul << 32)) | \ > + ((uint32_t)(data | host_data))) > + > /* > * Capability reporting > */ > int nvmx_msr_read_intercept(unsigned int msr, u64 *msr_content) > { > - u64 data = 0, tmp = 0; > + u64 data = 0, host_data = 0, tmp = 0; > int r = 1; > > if ( !nestedhvm_enabled(current->domain) ) > return 0; > > + rdmsrl(msr, host_data); > + > /* > * Remove unsupport features from n1 guest capability MSR > */ > switch (msr) { > case MSR_IA32_VMX_BASIC: > - data = VVMCS_REVISION | ((u64)PAGE_SIZE) << 32 | > - ((u64)MTRR_TYPE_WRBACK) << 50 | VMX_BASIC_DEFAULT1_ZERO; > + data = (host_data & (~0ul << 32)) | VVMCS_REVISION; > break; > case MSR_IA32_VMX_PINBASED_CTLS: > case MSR_IA32_VMX_TRUE_PINBASED_CTLS: > @@ -1341,6 +1346,7 @@ int nvmx_msr_read_intercept(unsigned int msr, u64 > *msr_content) > PIN_BASED_PREEMPT_TIMER; > tmp = VMX_PINBASED_CTLS_DEFAULT1; > data = ((data | tmp) << 32) | (tmp); > + data = combine_host_cap(data, host_data); Honestly, I had hoped/expected to get the folding in of "tmp" into the macro-ization as well (with zero getting passed where needed). Quite likely the code would become even more readable if you removed the extra assignments to "tmp" and rather passed the literals directly (where they have a single, fixed value). Jan > break; > case MSR_IA32_VMX_PROCBASED_CTLS: > case MSR_IA32_VMX_TRUE_PROCBASED_CTLS: > @@ -1368,6 +1374,7 @@ int nvmx_msr_read_intercept(unsigned int msr, u64 > *msr_content) > tmp = VMX_PROCBASED_CTLS_DEFAULT1; > /* 0-settings */ > data = ((data | tmp) << 32) | (tmp); > + data = combine_host_cap(data, host_data); > break; > case MSR_IA32_VMX_PROCBASED_CTLS2: > /* 1-seetings */ > @@ -1376,6 +1383,7 @@ int nvmx_msr_read_intercept(unsigned int msr, u64 > *msr_content) > /* 0-settings */ > tmp = 0; > data = (data << 32) | tmp; > + data = combine_host_cap(data, host_data); > break; > case MSR_IA32_VMX_EXIT_CTLS: > case MSR_IA32_VMX_TRUE_EXIT_CTLS: > @@ -1391,6 +1399,7 @@ int nvmx_msr_read_intercept(unsigned int msr, u64 > *msr_content) > VM_EXIT_LOAD_PERF_GLOBAL_CTRL; > /* 0-settings */ > data = ((data | tmp) << 32) | tmp; > + data = combine_host_cap(data, host_data); > break; > case MSR_IA32_VMX_ENTRY_CTLS: > case MSR_IA32_VMX_TRUE_ENTRY_CTLS: > @@ -1401,6 +1410,7 @@ int nvmx_msr_read_intercept(unsigned int msr, u64 > *msr_content) > VM_ENTRY_LOAD_PERF_GLOBAL_CTRL | > VM_ENTRY_IA32E_MODE; > data = ((data | tmp) << 32) | tmp; > + data = combine_host_cap(data, host_data); > break; > > case IA32_FEATURE_CONTROL_MSR: > -- > 1.7.1 > > > _______________________________________________ > Xen-devel mailing list > Xen-devel@xxxxxxxxxxxxx > http://lists.xen.org/xen-devel _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |