KVM: nVMX: Fix nested_vmx_check_msr_bitmap_controls
PATCH 1/2 KVM: nVMX: Fix nested_vmx_check_msr_bitmap_controls
Allow the L1 guest to specify the last page of addressable guest physical memory for an L2 MSR permission bitmap.
--- arch/x86/kvm/vmx.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
arch/x86/kvm/vmx.c +6 -6
@@ -4624,6 +4624,11 @@ static bool guest_state_valid(struct kvm_vcpu *vcpu)return true; } +static bool page_address_valid (struct kvm_vcpu *vcpu,gpa_t gpa) +{ +return PAGE_ALIGNED (gpa) && !(gpa >>cpuid_maxphyaddr (vcpu)); +} +static int init_rmode_tss (struct kvm *kvm) {gfn_t fn;
@@ -9582,9 +9587,6 @@ static void vmx_start_preemption_timer(struct kvm_vcpu *vcpu)static int nested_vmx_check_msr_bitmap_controls (struct kvm_vcpu *vcpu,struct vmcs12 *vmcs12) { -int maxphyaddr; -u64 addr; -if (!nested_cpu_has (vmcs12,CPU_BASED_USE_MSR_BITMAPS ))return 0 ;
@@ -9592,10 +9594,8 @@ static int nested_vmx_check_msr_bitmap_controls(struct kvm_vcpu *vcpu,WARN_ON (1 );return -EINVAL ; } - maxphyaddr =cpuid_maxphyaddr (vcpu); -if (!PAGE_ALIGNED (vmcs12->msr_bitmap) || - ((addr +PAGE_SIZE ) >> maxphyaddr)) +if (!page_address_valid (vcpu, vmcs12->msr_bitmap))return -EINVAL ;return 0 ;
Signature · 1 line
2.13.0.219.gdb65acc882-goog
PATCH 2/2 KVM: nVMX: Check host support for MSR bitmaps
If the host doesn't support MSR bitmaps, but the L2 guest is configured to use MSR bitmaps, fail the emulated VM-entry.
--- arch/x86/kvm/vmx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/vmx.c +1 -1
@@ -9590,7 +9590,7 @@ static int nested_vmx_check_msr_bitmap_controls(struct kvm_vcpu *vcpu,if (!nested_cpu_has (vmcs12,CPU_BASED_USE_MSR_BITMAPS ))return 0 ; -if (vmcs12_read_any (vcpu,MSR_BITMAP , &addr)) { +if (!cpu_has_vmx_msr_bitmap ()) {WARN_ON (1 );return -EINVAL ; }
Signature · 1 line
2.13.0.219.gdb65acc882-goog
kbuild test robot
build botreproduce:
Hi Jim,
[auto build test ERROR on kvm/linux-next]
[also build test ERROR on v4.12-rc2 next-20170525]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Jim-Mattson/KVM-nVMX-Fix-nested_vmx_check_msr_bitmap_controls/20170526-042341 base: https://git.kernel.org/pub/scm/virt/kvm/kvm.git linux-next config: x86_64-randconfig-x018-201721 (attached as .config) compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce: # save the attached .config to linux build tree make ARCH=x86_64
Note: the linux-review/Jim-Mattson/KVM-nVMX-Fix-nested_vmx_check_msr_bitmap_controls/20170526-042341 HEAD 23051b8d9722709205bf8450e1d1a18a0cd48a05 builds fine.
It only hurts bisectibility.
All errors (new ones prefixed by >>):
arch/x86/kvm/vmx.c: In function 'nested_vmx_check_msr_bitmap_controls':
>> arch/x86/kvm/vmx.c:9593:41: error: 'addr' undeclared (first use in this function)
if (vmcs12_read_any(vcpu, MSR_BITMAP, &addr)) {
^~~~ arch/x86/kvm/vmx.c:9593:41: note: each undeclared identifier is reported only once for each function it appears in
vim +/addr +9593 arch/x86/kvm/vmx.c
3af18d9c Wincy Van 2015-02-03 9587 static int nested_vmx_check_msr_bitmap_controls(struct kvm_vcpu *vcpu,
3af18d9c Wincy Van 2015-02-03 9588 struct vmcs12 *vmcs12)
3af18d9c Wincy Van 2015-02-03 9589 {
3af18d9c Wincy Van 2015-02-03 9590 if (!nested_cpu_has(vmcs12, CPU_BASED_USE_MSR_BITMAPS))
3af18d9c Wincy Van 2015-02-03 9591 return 0;
3af18d9c Wincy Van 2015-02-03 9592
3af18d9c Wincy Van 2015-02-03 @9593 if (vmcs12_read_any(vcpu, MSR_BITMAP, &addr)) {
3af18d9c Wincy Van 2015-02-03 9594 WARN_ON(1);
3af18d9c Wincy Van 2015-02-03 9595 return -EINVAL;
3af18d9c Wincy Van 2015-02-03 9596 }:::::: The code at line 9593 was first introduced by commit
:::::: 3af18d9c5fe95a6b377dca7b9ff9c6d3ab7f0969 KVM: nVMX: Prepare for using hardware MSR bitmap
:::::: TO: Wincy Van <[email protected]>
:::::: CC: Paolo Bonzini <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
PATCH v2 1/2 KVM: nVMX: Fix nested_vmx_check_msr_bitmap_controls
In reply to Jim MattsonAllow the L1 guest to specify the last page of addressable guest physical memory for an L2 MSR permission bitmap.
--- arch/x86/kvm/vmx.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
arch/x86/kvm/vmx.c +6 -4
@@ -4624,6 +4624,11 @@ static bool guest_state_valid(struct kvm_vcpu *vcpu)return true; } +static bool page_address_valid (struct kvm_vcpu *vcpu,gpa_t gpa) +{ +return PAGE_ALIGNED (gpa) && !(gpa >>cpuid_maxphyaddr (vcpu)); +} +static int init_rmode_tss (struct kvm *kvm) {gfn_t fn;
@@ -9582,7 +9587,6 @@ static void vmx_start_preemption_timer(struct kvm_vcpu *vcpu)static int nested_vmx_check_msr_bitmap_controls (struct kvm_vcpu *vcpu,struct vmcs12 *vmcs12) { -int maxphyaddr;u64 addr;if (!nested_cpu_has (vmcs12,CPU_BASED_USE_MSR_BITMAPS ))
@@ -9592,10 +9596,8 @@ static int nested_vmx_check_msr_bitmap_controls(struct kvm_vcpu *vcpu,WARN_ON (1 );return -EINVAL ; } - maxphyaddr =cpuid_maxphyaddr (vcpu); -if (!PAGE_ALIGNED (vmcs12->msr_bitmap) || - ((addr +PAGE_SIZE ) >> maxphyaddr)) +if (!page_address_valid (vcpu, vmcs12->msr_bitmap))return -EINVAL ;return 0 ;
Signature · 1 line
2.13.0.219.gdb65acc882-goog
PATCH v2 2/2 KVM: nVMX: Check host support for MSR bitmaps
In reply to Jim MattsonIf the host doesn't support MSR bitmaps, but the L2 guest is configured to use MSR bitmaps, fail the emulated VM-entry.
--- arch/x86/kvm/vmx.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
arch/x86/kvm/vmx.c +1 -3
@@ -9587,12 +9587,10 @@ static void vmx_start_preemption_timer(struct kvm_vcpu *vcpu)static int nested_vmx_check_msr_bitmap_controls (struct kvm_vcpu *vcpu,struct vmcs12 *vmcs12) { -u64 addr; -if (!nested_cpu_has (vmcs12,CPU_BASED_USE_MSR_BITMAPS ))return 0 ; -if (vmcs12_read_any (vcpu,MSR_BITMAP , &addr)) { +if (!cpu_has_vmx_msr_bitmap ()) {WARN_ON (1 );return -EINVAL ; }
Signature · 1 line
2.13.0.219.gdb65acc882-goog
Re: [PATCH v2 2/2] KVM: nVMX: Check host support for MSR bitmaps
2017-05-25 17:04-0700, Jim Mattson:
Quoted 14 lines
If the host doesn't support MSR bitmaps, but the L2 guest is configured to use MSR bitmaps, fail the emulated VM-entry.
Fixes 3af18d9c5fe95 ("KVM: nVMX: Prepare for using hardware MSR bitmap")Signed-off-by Jim Mattson <[email protected]>--- arch/x86/kvm/vmx.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)arch/x86/kvm/vmx.c +0
-0
arch/x86/kvm/vmx.c static void vmx_start_preemption_timer(struct kvm_vcpu *vcpu) · line 9593
Quoted 10 lines
arch/x86/kvm/vmx.c +1
-3@@ -9587,12 +9587,10 @@ static void vmx_start_preemption_timer(struct kvm_vcpu *vcpu)static int nested_vmx_check_msr_bitmap_controls (struct kvm_vcpu *vcpu,struct vmcs12 *vmcs12) { -u64 addr; -if (!nested_cpu_has (vmcs12,CPU_BASED_USE_MSR_BITMAPS ))return 0 ; -if (vmcs12_read_any (vcpu,MSR_BITMAP , &addr)) { +if (!cpu_has_vmx_msr_bitmap ()) {
VMCS bitmaps are emulated and exposed regardless of CPU features. Doesn't this change break L1 hypervisor on CPUs that don't support MSR bitmaps?
I think the check can just go away and can be merged into the first patch.
Thanks.
Quoted 6 lines
arch/x86/kvm/vmx.c +0
-0WARN_ON (1 );return -EINVAL ; }Signature · 1 line
2.13.0.219.gdb65acc882-goog
PATCH v2 1/1 KVM: nVMX: Fix nested_vmx_check_msr_bitmap_controls
Allow the L1 guest to specify the last page of addressable guest physical memory for an L2 MSR permission bitmap. Also remove the vmcs12_read_any() check that should never fail.
--- arch/x86/kvm/vmx.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)
arch/x86/kvm/vmx.c +6 -11
@@ -4624,6 +4624,11 @@ static bool guest_state_valid(struct kvm_vcpu *vcpu)return true; } +static bool page_address_valid (struct kvm_vcpu *vcpu,gpa_t gpa) +{ +return PAGE_ALIGNED (gpa) && !(gpa >>cpuid_maxphyaddr (vcpu)); +} +static int init_rmode_tss (struct kvm *kvm) {gfn_t fn;
@@ -9559,20 +9564,10 @@ static void vmx_start_preemption_timer(struct kvm_vcpu *vcpu)static int nested_vmx_check_msr_bitmap_controls (struct kvm_vcpu *vcpu,struct vmcs12 *vmcs12) { -int maxphyaddr; -u64 addr; -if (!nested_cpu_has (vmcs12,CPU_BASED_USE_MSR_BITMAPS ))return 0 ; -if (vmcs12_read_any (vcpu,MSR_BITMAP , &addr)) { -WARN_ON (1 ); -return -EINVAL ; - } - maxphyaddr =cpuid_maxphyaddr (vcpu); - -if (!PAGE_ALIGNED (vmcs12->msr_bitmap) || - ((addr +PAGE_SIZE ) >> maxphyaddr)) +if (!page_address_valid (vcpu, vmcs12->msr_bitmap))return -EINVAL ;return 0 ;
Signature · 1 line
2.13.1.518.g3df882009-goog