* [PATCH v2] KVM: vmx: Set msr bitmap correctly if vcpu is in guest mode
@ 2015-03-04 6:31 Wincy Van
2015-03-04 15:58 ` Bandan Das
2015-03-13 12:25 ` Marcelo Tosatti
0 siblings, 2 replies; 4+ messages in thread
From: Wincy Van @ 2015-03-04 6:31 UTC (permalink / raw)
To: bsd, mtosatti, pbonzini, gleb, yang.z.zhang, fanwenyi0529
Cc: wanpeng.li, kvm, linux-kernel, jan.kiszka, yong.y.wang
In commit 3af18d9c5fe9 ("KVM: nVMX: Prepare for using hardware MSR bitmap"),
we are setting MSR_BITMAP in prepare_vmcs02 if we should use hardware. This
is not enough since the field will be modified by following vmx_set_efer.
Fix this by setting vmx_msr_bitmap_nested in vmx_set_msr_bitmap if vcpu is
in guest mode.
Signed-off-by: Wincy Van <fanwenyi0529@gmail.com>
---
arch/x86/kvm/vmx.c | 11 +++++++----
1 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index f7b20b4..10a481b 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -2168,7 +2168,10 @@ static void vmx_set_msr_bitmap(struct kvm_vcpu *vcpu)
{
unsigned long *msr_bitmap;
- if (irqchip_in_kernel(vcpu->kvm) && apic_x2apic_mode(vcpu->arch.apic)) {
+ if (is_guest_mode(vcpu))
+ msr_bitmap = vmx_msr_bitmap_nested;
+ else if (irqchip_in_kernel(vcpu->kvm) &&
+ apic_x2apic_mode(vcpu->arch.apic)) {
if (is_long_mode(vcpu))
msr_bitmap = vmx_msr_bitmap_longmode_x2apic;
else
@@ -9218,9 +9221,9 @@ static void prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12)
}
if (cpu_has_vmx_msr_bitmap() &&
- exec_control & CPU_BASED_USE_MSR_BITMAPS &&
- nested_vmx_merge_msr_bitmap(vcpu, vmcs12)) {
- vmcs_write64(MSR_BITMAP, __pa(vmx_msr_bitmap_nested));
+ exec_control & CPU_BASED_USE_MSR_BITMAPS) {
+ nested_vmx_merge_msr_bitmap(vcpu, vmcs12);
+ /* MSR_BITMAP will be set by following vmx_set_efer. */
} else
exec_control &= ~CPU_BASED_USE_MSR_BITMAPS;
--
1.7.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] KVM: vmx: Set msr bitmap correctly if vcpu is in guest mode
2015-03-04 6:31 [PATCH v2] KVM: vmx: Set msr bitmap correctly if vcpu is in guest mode Wincy Van
@ 2015-03-04 15:58 ` Bandan Das
2015-03-05 2:53 ` Wincy Van
2015-03-13 12:25 ` Marcelo Tosatti
1 sibling, 1 reply; 4+ messages in thread
From: Bandan Das @ 2015-03-04 15:58 UTC (permalink / raw)
To: Wincy Van
Cc: mtosatti, pbonzini, gleb, yang.z.zhang, wanpeng.li, kvm,
linux-kernel, jan.kiszka, yong.y.wang
Hi Wincy,
Wincy Van <fanwenyi0529@gmail.com> writes:
> In commit 3af18d9c5fe9 ("KVM: nVMX: Prepare for using hardware MSR bitmap"),
> we are setting MSR_BITMAP in prepare_vmcs02 if we should use hardware. This
> is not enough since the field will be modified by following vmx_set_efer.
>
> Fix this by setting vmx_msr_bitmap_nested in vmx_set_msr_bitmap if vcpu is
> in guest mode.
>
> Signed-off-by: Wincy Van <fanwenyi0529@gmail.com>
> ---
> arch/x86/kvm/vmx.c | 11 +++++++----
> 1 files changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index f7b20b4..10a481b 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -2168,7 +2168,10 @@ static void vmx_set_msr_bitmap(struct kvm_vcpu *vcpu)
> {
> unsigned long *msr_bitmap;
>
> - if (irqchip_in_kernel(vcpu->kvm) && apic_x2apic_mode(vcpu->arch.apic)) {
> + if (is_guest_mode(vcpu))
> + msr_bitmap = vmx_msr_bitmap_nested;
Do you think this should be (is_guest_mode(vcpu) &
(exec_control & CPU_BASED_USE_MSR_BITMAPS)) ?
> + else if (irqchip_in_kernel(vcpu->kvm) &&
> + apic_x2apic_mode(vcpu->arch.apic)) {
> if (is_long_mode(vcpu))
> msr_bitmap = vmx_msr_bitmap_longmode_x2apic;
> else
> @@ -9218,9 +9221,9 @@ static void prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12)
> }
>
> if (cpu_has_vmx_msr_bitmap() &&
> - exec_control & CPU_BASED_USE_MSR_BITMAPS &&
> - nested_vmx_merge_msr_bitmap(vcpu, vmcs12)) {
> - vmcs_write64(MSR_BITMAP, __pa(vmx_msr_bitmap_nested));
> + exec_control & CPU_BASED_USE_MSR_BITMAPS) {
> + nested_vmx_merge_msr_bitmap(vcpu, vmcs12);
> + /* MSR_BITMAP will be set by following vmx_set_efer. */
> } else
> exec_control &= ~CPU_BASED_USE_MSR_BITMAPS;
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] KVM: vmx: Set msr bitmap correctly if vcpu is in guest mode
2015-03-04 15:58 ` Bandan Das
@ 2015-03-05 2:53 ` Wincy Van
0 siblings, 0 replies; 4+ messages in thread
From: Wincy Van @ 2015-03-05 2:53 UTC (permalink / raw)
To: Bandan Das
Cc: mtosatti, Paolo Bonzini, gleb, Zhang, Yang Z, Wanpeng Li, kvm,
linux-kernel, Jan Kiszka, Yong Wang
On Wed, Mar 4, 2015 at 11:58 PM, Bandan Das <bsd@redhat.com> wrote:
> Hi Wincy,
>
> Wincy Van <fanwenyi0529@gmail.com> writes:
>
>> In commit 3af18d9c5fe9 ("KVM: nVMX: Prepare for using hardware MSR bitmap"),
>> we are setting MSR_BITMAP in prepare_vmcs02 if we should use hardware. This
>> is not enough since the field will be modified by following vmx_set_efer.
>>
>> Fix this by setting vmx_msr_bitmap_nested in vmx_set_msr_bitmap if vcpu is
>> in guest mode.
>>
>> Signed-off-by: Wincy Van <fanwenyi0529@gmail.com>
>> ---
>> arch/x86/kvm/vmx.c | 11 +++++++----
>> 1 files changed, 7 insertions(+), 4 deletions(-)
>>
>> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
>> index f7b20b4..10a481b 100644
>> --- a/arch/x86/kvm/vmx.c
>> +++ b/arch/x86/kvm/vmx.c
>> @@ -2168,7 +2168,10 @@ static void vmx_set_msr_bitmap(struct kvm_vcpu *vcpu)
>> {
>> unsigned long *msr_bitmap;
>>
>> - if (irqchip_in_kernel(vcpu->kvm) && apic_x2apic_mode(vcpu->arch.apic)) {
>> + if (is_guest_mode(vcpu))
>> + msr_bitmap = vmx_msr_bitmap_nested;
> Do you think this should be (is_guest_mode(vcpu) &
> (exec_control & CPU_BASED_USE_MSR_BITMAPS)) ?
>
We don't need to do that, because if we don't use the hardware, we will disable
hardware msr bitmap:
if (cpu_has_vmx_msr_bitmap() &&
exec_control & CPU_BASED_USE_MSR_BITMAPS) {
nested_vmx_merge_msr_bitmap(vcpu, vmcs12);
/* MSR_BITMAP will be set by following vmx_set_efer. */
} else
exec_control &= ~CPU_BASED_USE_MSR_BITMAPS;
Then, the hardware will ignore MSR_BITMAP.
Setting MSR_BITMAP without enabling it may be unnecessary, but it is no
harm, and we can reduce the code complexity of vmx_set_msr_bitmap.
Thanks,
Wincy
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] KVM: vmx: Set msr bitmap correctly if vcpu is in guest mode
2015-03-04 6:31 [PATCH v2] KVM: vmx: Set msr bitmap correctly if vcpu is in guest mode Wincy Van
2015-03-04 15:58 ` Bandan Das
@ 2015-03-13 12:25 ` Marcelo Tosatti
1 sibling, 0 replies; 4+ messages in thread
From: Marcelo Tosatti @ 2015-03-13 12:25 UTC (permalink / raw)
To: Wincy Van
Cc: bsd, pbonzini, gleb, yang.z.zhang, wanpeng.li, kvm, linux-kernel,
jan.kiszka, yong.y.wang
On Wed, Mar 04, 2015 at 02:31:56PM +0800, Wincy Van wrote:
> In commit 3af18d9c5fe9 ("KVM: nVMX: Prepare for using hardware MSR bitmap"),
> we are setting MSR_BITMAP in prepare_vmcs02 if we should use hardware. This
> is not enough since the field will be modified by following vmx_set_efer.
>
> Fix this by setting vmx_msr_bitmap_nested in vmx_set_msr_bitmap if vcpu is
> in guest mode.
>
> Signed-off-by: Wincy Van <fanwenyi0529@gmail.com>
Applied, thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-03-13 14:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-04 6:31 [PATCH v2] KVM: vmx: Set msr bitmap correctly if vcpu is in guest mode Wincy Van
2015-03-04 15:58 ` Bandan Das
2015-03-05 2:53 ` Wincy Van
2015-03-13 12:25 ` Marcelo Tosatti
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).