* [PATCH v1 1/2] KVM: nVMX: single function for switching between vmcs
@ 2017-03-15 15:01 David Hildenbrand
2017-03-16 9:10 ` David Hildenbrand
0 siblings, 1 reply; 4+ messages in thread
From: David Hildenbrand @ 2017-03-15 15:01 UTC (permalink / raw)
To: kvm; +Cc: Paolo Bonzini, rkrcmar, jmattson, david
Let's combine it in a single function vmx_switch_vmcs().
Signed-off-by: David Hildenbrand <david@redhat.com>
---
arch/x86/kvm/vmx.c | 22 ++++++++--------------
1 file changed, 8 insertions(+), 14 deletions(-)
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index bbbfe12..dc2d8f0 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -9120,16 +9120,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
vmx_complete_interrupts(vmx);
}
-static void vmx_load_vmcs01(struct kvm_vcpu *vcpu)
+static void vmx_switch_vmcs(struct kvm_vcpu *vcpu, struct loaded_vmcs *vmcs)
{
struct vcpu_vmx *vmx = to_vmx(vcpu);
int cpu;
- if (vmx->loaded_vmcs == &vmx->vmcs01)
+ if (vmx->loaded_vmcs == vmcs)
return;
cpu = get_cpu();
- vmx->loaded_vmcs = &vmx->vmcs01;
+ vmx->loaded_vmcs = vmcs;
vmx_vcpu_put(vcpu);
vmx_vcpu_load(vcpu, cpu);
vcpu->cpu = cpu;
@@ -9147,7 +9147,7 @@ static void vmx_free_vcpu_nested(struct kvm_vcpu *vcpu)
r = vcpu_load(vcpu);
BUG_ON(r);
- vmx_load_vmcs01(vcpu);
+ vmx_switch_vmcs(vcpu, &vmx->vmcs01);
free_nested(vmx);
vcpu_put(vcpu);
}
@@ -10412,18 +10412,12 @@ static int enter_vmx_non_root_mode(struct kvm_vcpu *vcpu, bool from_vmentry)
if (!(vmcs12->vm_entry_controls & VM_ENTRY_LOAD_DEBUG_CONTROLS))
vmx->nested.vmcs01_debugctl = vmcs_read64(GUEST_IA32_DEBUGCTL);
- cpu = get_cpu();
- vmx->loaded_vmcs = vmcs02;
- vmx_vcpu_put(vcpu);
- vmx_vcpu_load(vcpu, cpu);
- vcpu->cpu = cpu;
- put_cpu();
-
+ vmx_switch_vmcs(vcpu, vmcs02);
vmx_segment_cache_clear(vmx);
if (prepare_vmcs02(vcpu, vmcs12, from_vmentry, &exit_qual)) {
leave_guest_mode(vcpu);
- vmx_load_vmcs01(vcpu);
+ vmx_switch_vmcs(vcpu, &vmx->vmcs01);
nested_vmx_entry_failure(vcpu, vmcs12,
EXIT_REASON_INVALID_STATE, exit_qual);
return 1;
@@ -10436,7 +10430,7 @@ static int enter_vmx_non_root_mode(struct kvm_vcpu *vcpu, bool from_vmentry)
vmcs12->vm_entry_msr_load_count);
if (msr_entry_idx) {
leave_guest_mode(vcpu);
- vmx_load_vmcs01(vcpu);
+ vmx_switch_vmcs(vcpu, &vmx->vmcs01);
nested_vmx_entry_failure(vcpu, vmcs12,
EXIT_REASON_MSR_LOAD_FAIL, msr_entry_idx);
return 1;
@@ -11004,7 +10998,7 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason,
if (unlikely(vmx->fail))
vm_inst_error = vmcs_read32(VM_INSTRUCTION_ERROR);
- vmx_load_vmcs01(vcpu);
+ vmx_switch_vmcs(vcpu, &vmx->vmcs01);
if ((exit_reason == EXIT_REASON_EXTERNAL_INTERRUPT)
&& nested_exit_intr_ack_set(vcpu)) {
--
2.9.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v1 1/2] KVM: nVMX: single function for switching between vmcs
2017-03-15 15:01 [PATCH v1 1/2] KVM: nVMX: single function for switching between vmcs David Hildenbrand
@ 2017-03-16 9:10 ` David Hildenbrand
2017-03-16 9:12 ` Paolo Bonzini
0 siblings, 1 reply; 4+ messages in thread
From: David Hildenbrand @ 2017-03-16 9:10 UTC (permalink / raw)
To: kvm; +Cc: Paolo Bonzini, rkrcmar, jmattson
On 15.03.2017 16:01, David Hildenbrand wrote:
This is actually just a single patch. Decided to hold back the second
patch for now but missed to fixup the subject when sending it out. So
don't get confused by the 1/2.
> Let's combine it in a single function vmx_switch_vmcs().
>
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
> arch/x86/kvm/vmx.c | 22 ++++++++--------------
> 1 file changed, 8 insertions(+), 14 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index bbbfe12..dc2d8f0 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -9120,16 +9120,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
> vmx_complete_interrupts(vmx);
> }
>
> -static void vmx_load_vmcs01(struct kvm_vcpu *vcpu)
> +static void vmx_switch_vmcs(struct kvm_vcpu *vcpu, struct loaded_vmcs *vmcs)
> {
> struct vcpu_vmx *vmx = to_vmx(vcpu);
> int cpu;
>
> - if (vmx->loaded_vmcs == &vmx->vmcs01)
> + if (vmx->loaded_vmcs == vmcs)
> return;
>
> cpu = get_cpu();
> - vmx->loaded_vmcs = &vmx->vmcs01;
> + vmx->loaded_vmcs = vmcs;
> vmx_vcpu_put(vcpu);
> vmx_vcpu_load(vcpu, cpu);
> vcpu->cpu = cpu;
> @@ -9147,7 +9147,7 @@ static void vmx_free_vcpu_nested(struct kvm_vcpu *vcpu)
>
> r = vcpu_load(vcpu);
> BUG_ON(r);
> - vmx_load_vmcs01(vcpu);
> + vmx_switch_vmcs(vcpu, &vmx->vmcs01);
> free_nested(vmx);
> vcpu_put(vcpu);
> }
> @@ -10412,18 +10412,12 @@ static int enter_vmx_non_root_mode(struct kvm_vcpu *vcpu, bool from_vmentry)
> if (!(vmcs12->vm_entry_controls & VM_ENTRY_LOAD_DEBUG_CONTROLS))
> vmx->nested.vmcs01_debugctl = vmcs_read64(GUEST_IA32_DEBUGCTL);
>
> - cpu = get_cpu();
> - vmx->loaded_vmcs = vmcs02;
> - vmx_vcpu_put(vcpu);
> - vmx_vcpu_load(vcpu, cpu);
> - vcpu->cpu = cpu;
> - put_cpu();
> -
> + vmx_switch_vmcs(vcpu, vmcs02);
> vmx_segment_cache_clear(vmx);
>
> if (prepare_vmcs02(vcpu, vmcs12, from_vmentry, &exit_qual)) {
> leave_guest_mode(vcpu);
> - vmx_load_vmcs01(vcpu);
> + vmx_switch_vmcs(vcpu, &vmx->vmcs01);
> nested_vmx_entry_failure(vcpu, vmcs12,
> EXIT_REASON_INVALID_STATE, exit_qual);
> return 1;
> @@ -10436,7 +10430,7 @@ static int enter_vmx_non_root_mode(struct kvm_vcpu *vcpu, bool from_vmentry)
> vmcs12->vm_entry_msr_load_count);
> if (msr_entry_idx) {
> leave_guest_mode(vcpu);
> - vmx_load_vmcs01(vcpu);
> + vmx_switch_vmcs(vcpu, &vmx->vmcs01);
> nested_vmx_entry_failure(vcpu, vmcs12,
> EXIT_REASON_MSR_LOAD_FAIL, msr_entry_idx);
> return 1;
> @@ -11004,7 +10998,7 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason,
> if (unlikely(vmx->fail))
> vm_inst_error = vmcs_read32(VM_INSTRUCTION_ERROR);
>
> - vmx_load_vmcs01(vcpu);
> + vmx_switch_vmcs(vcpu, &vmx->vmcs01);
>
> if ((exit_reason == EXIT_REASON_EXTERNAL_INTERRUPT)
> && nested_exit_intr_ack_set(vcpu)) {
>
--
Thanks,
David
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1 1/2] KVM: nVMX: single function for switching between vmcs
2017-03-16 9:10 ` David Hildenbrand
@ 2017-03-16 9:12 ` Paolo Bonzini
2017-03-16 11:40 ` David Hildenbrand
0 siblings, 1 reply; 4+ messages in thread
From: Paolo Bonzini @ 2017-03-16 9:12 UTC (permalink / raw)
To: David Hildenbrand, kvm; +Cc: rkrcmar, jmattson
On 16/03/2017 10:10, David Hildenbrand wrote:
> On 15.03.2017 16:01, David Hildenbrand wrote:
>
> This is actually just a single patch. Decided to hold back the second
> patch for now but missed to fixup the subject when sending it out. So
> don't get confused by the 1/2.
>
>> Let's combine it in a single function vmx_switch_vmcs().
>>
>> Signed-off-by: David Hildenbrand <david@redhat.com>
>> ---
>> arch/x86/kvm/vmx.c | 22 ++++++++--------------
>> 1 file changed, 8 insertions(+), 14 deletions(-)
>>
>> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
>> index bbbfe12..dc2d8f0 100644
>> --- a/arch/x86/kvm/vmx.c
>> +++ b/arch/x86/kvm/vmx.c
>> @@ -9120,16 +9120,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
>> vmx_complete_interrupts(vmx);
>> }
>>
>> -static void vmx_load_vmcs01(struct kvm_vcpu *vcpu)
>> +static void vmx_switch_vmcs(struct kvm_vcpu *vcpu, struct loaded_vmcs *vmcs)
>> {
>> struct vcpu_vmx *vmx = to_vmx(vcpu);
>> int cpu;
>>
>> - if (vmx->loaded_vmcs == &vmx->vmcs01)
>> + if (vmx->loaded_vmcs == vmcs)
>> return;
>>
>> cpu = get_cpu();
>> - vmx->loaded_vmcs = &vmx->vmcs01;
>> + vmx->loaded_vmcs = vmcs;
>> vmx_vcpu_put(vcpu);
>> vmx_vcpu_load(vcpu, cpu);
>> vcpu->cpu = cpu;
>> @@ -9147,7 +9147,7 @@ static void vmx_free_vcpu_nested(struct kvm_vcpu *vcpu)
>>
>> r = vcpu_load(vcpu);
>> BUG_ON(r);
>> - vmx_load_vmcs01(vcpu);
>> + vmx_switch_vmcs(vcpu, &vmx->vmcs01);
>> free_nested(vmx);
>> vcpu_put(vcpu);
>> }
>> @@ -10412,18 +10412,12 @@ static int enter_vmx_non_root_mode(struct kvm_vcpu *vcpu, bool from_vmentry)
>> if (!(vmcs12->vm_entry_controls & VM_ENTRY_LOAD_DEBUG_CONTROLS))
>> vmx->nested.vmcs01_debugctl = vmcs_read64(GUEST_IA32_DEBUGCTL);
>>
>> - cpu = get_cpu();
>> - vmx->loaded_vmcs = vmcs02;
>> - vmx_vcpu_put(vcpu);
>> - vmx_vcpu_load(vcpu, cpu);
>> - vcpu->cpu = cpu;
>> - put_cpu();
>> -
>> + vmx_switch_vmcs(vcpu, vmcs02);
>> vmx_segment_cache_clear(vmx);
>>
>> if (prepare_vmcs02(vcpu, vmcs12, from_vmentry, &exit_qual)) {
>> leave_guest_mode(vcpu);
>> - vmx_load_vmcs01(vcpu);
>> + vmx_switch_vmcs(vcpu, &vmx->vmcs01);
>> nested_vmx_entry_failure(vcpu, vmcs12,
>> EXIT_REASON_INVALID_STATE, exit_qual);
>> return 1;
>> @@ -10436,7 +10430,7 @@ static int enter_vmx_non_root_mode(struct kvm_vcpu *vcpu, bool from_vmentry)
>> vmcs12->vm_entry_msr_load_count);
>> if (msr_entry_idx) {
>> leave_guest_mode(vcpu);
>> - vmx_load_vmcs01(vcpu);
>> + vmx_switch_vmcs(vcpu, &vmx->vmcs01);
>> nested_vmx_entry_failure(vcpu, vmcs12,
>> EXIT_REASON_MSR_LOAD_FAIL, msr_entry_idx);
>> return 1;
>> @@ -11004,7 +10998,7 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason,
>> if (unlikely(vmx->fail))
>> vm_inst_error = vmcs_read32(VM_INSTRUCTION_ERROR);
>>
>> - vmx_load_vmcs01(vcpu);
>> + vmx_switch_vmcs(vcpu, &vmx->vmcs01);
>>
>> if ((exit_reason == EXIT_REASON_EXTERNAL_INTERRUPT)
>> && nested_exit_intr_ack_set(vcpu)) {
>>
>
>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1 1/2] KVM: nVMX: single function for switching between vmcs
2017-03-16 9:12 ` Paolo Bonzini
@ 2017-03-16 11:40 ` David Hildenbrand
0 siblings, 0 replies; 4+ messages in thread
From: David Hildenbrand @ 2017-03-16 11:40 UTC (permalink / raw)
To: Paolo Bonzini, kvm; +Cc: rkrcmar, jmattson
>>> - cpu = get_cpu();
>>> - vmx->loaded_vmcs = vmcs02;
>>> - vmx_vcpu_put(vcpu);
>>> - vmx_vcpu_load(vcpu, cpu);
>>> - vcpu->cpu = cpu;
>>> - put_cpu();
>>> -
>>> + vmx_switch_vmcs(vcpu, vmcs02);
>>> vmx_segment_cache_clear(vmx);
>>>
>>> if (prepare_vmcs02(vcpu, vmcs12, from_vmentry, &exit_qual)) {
>>> leave_guest_mode(vcpu);
>>> - vmx_load_vmcs01(vcpu);
>>> + vmx_switch_vmcs(vcpu, &vmx->vmcs01);
>>> nested_vmx_entry_failure(vcpu, vmcs12,
>>> EXIT_REASON_INVALID_STATE, exit_qual);
>>> return 1;
>>> @@ -10436,7 +10430,7 @@ static int enter_vmx_non_root_mode(struct kvm_vcpu *vcpu, bool from_vmentry)
>>> vmcs12->vm_entry_msr_load_count);
>>> if (msr_entry_idx) {
>>> leave_guest_mode(vcpu);
>>> - vmx_load_vmcs01(vcpu);
>>> + vmx_switch_vmcs(vcpu, &vmx->vmcs01);
>>> nested_vmx_entry_failure(vcpu, vmcs12,
>>> EXIT_REASON_MSR_LOAD_FAIL, msr_entry_idx);
>>> return 1;
>>> @@ -11004,7 +10998,7 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason,
>>> if (unlikely(vmx->fail))
>>> vm_inst_error = vmcs_read32(VM_INSTRUCTION_ERROR);
>>>
>>> - vmx_load_vmcs01(vcpu);
>>> + vmx_switch_vmcs(vcpu, &vmx->vmcs01);
>>>
>>> if ((exit_reason == EXIT_REASON_EXTERNAL_INTERRUPT)
>>> && nested_exit_intr_ack_set(vcpu)) {
>>>
>>
>>
>
> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
>
Thanks, just noticed a minor thing is missing:
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index dc2d8f0..71b14d9 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -10399,7 +10399,6 @@ static int enter_vmx_non_root_mode(struct
kvm_vcpu *vcpu, bool from_vmentry)
struct vcpu_vmx *vmx = to_vmx(vcpu);
struct vmcs12 *vmcs12 = get_vmcs12(vcpu);
struct loaded_vmcs *vmcs02;
- int cpu;
u32 msr_entry_idx;
u32 exit_qual;
So I will add it to this patch.
--
Thanks,
David
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-03-16 11:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-15 15:01 [PATCH v1 1/2] KVM: nVMX: single function for switching between vmcs David Hildenbrand
2017-03-16 9:10 ` David Hildenbrand
2017-03-16 9:12 ` Paolo Bonzini
2017-03-16 11:40 ` David Hildenbrand
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.