2020-09-14 06:59:27

by Wanpeng Li

[permalink] [raw]
Subject: [PATCH] KVM: SVM: Analyze is_guest_mode() in svm_vcpu_run()

From: Wanpeng Li <[email protected]>

Analyze is_guest_mode() in svm_vcpu_run() instead of svm_exit_handlers_fastpath()
in conformity with VMX version.

Suggested-by: Vitaly Kuznetsov <[email protected]>
Signed-off-by: Wanpeng Li <[email protected]>
---
arch/x86/kvm/svm/svm.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 3da5b2f..009035a 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -3393,8 +3393,7 @@ static void svm_cancel_injection(struct kvm_vcpu *vcpu)

static fastpath_t svm_exit_handlers_fastpath(struct kvm_vcpu *vcpu)
{
- if (!is_guest_mode(vcpu) &&
- to_svm(vcpu)->vmcb->control.exit_code == SVM_EXIT_MSR &&
+ if (to_svm(vcpu)->vmcb->control.exit_code == SVM_EXIT_MSR &&
to_svm(vcpu)->vmcb->control.exit_info_1)
return handle_fastpath_set_msr_irqoff(vcpu);

@@ -3580,6 +3579,10 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu)
svm_handle_mce(svm);

svm_complete_interrupts(svm);
+
+ if (is_guest_mode(vcpu))
+ return EXIT_FASTPATH_NONE;
+
exit_fastpath = svm_exit_handlers_fastpath(vcpu);
return exit_fastpath;
}
--
2.7.4


2020-09-14 20:47:46

by Krish Sadhukhan

[permalink] [raw]
Subject: Re: [PATCH] KVM: SVM: Analyze is_guest_mode() in svm_vcpu_run()


On 9/13/20 11:55 PM, Wanpeng Li wrote:
> From: Wanpeng Li <[email protected]>
>
> Analyze is_guest_mode() in svm_vcpu_run() instead of svm_exit_handlers_fastpath()
> in conformity with VMX version.
>
> Suggested-by: Vitaly Kuznetsov <[email protected]>
> Signed-off-by: Wanpeng Li <[email protected]>
> ---
> arch/x86/kvm/svm/svm.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> index 3da5b2f..009035a 100644
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
> @@ -3393,8 +3393,7 @@ static void svm_cancel_injection(struct kvm_vcpu *vcpu)
>
> static fastpath_t svm_exit_handlers_fastpath(struct kvm_vcpu *vcpu)
> {
> - if (!is_guest_mode(vcpu) &&
> - to_svm(vcpu)->vmcb->control.exit_code == SVM_EXIT_MSR &&
> + if (to_svm(vcpu)->vmcb->control.exit_code == SVM_EXIT_MSR &&
> to_svm(vcpu)->vmcb->control.exit_info_1)
> return handle_fastpath_set_msr_irqoff(vcpu);
>
> @@ -3580,6 +3579,10 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu)
> svm_handle_mce(svm);
>
> svm_complete_interrupts(svm);
> +
> + if (is_guest_mode(vcpu))
> + return EXIT_FASTPATH_NONE;
> +
> exit_fastpath = svm_exit_handlers_fastpath(vcpu);
> return exit_fastpath;

Not related to your changes, but should we get rid of the variable
'exit_fastpath' and just do,

        return svm_exit_handler_fastpath(vcpu);

It seems the variable isn't used anywhere else and svm_vcpu_run()
doesn't return from anywhere else either.

Also, svm_exit_handlers_fastpath() doesn't have any other caller. 
Should we get rid of it as well ?


For your changes,

    Reviewed-by: Krish Sadhukhan <[email protected]>

> }

2020-09-16 00:53:58

by Haiwei Li

[permalink] [raw]
Subject: Re: [PATCH] KVM: SVM: Analyze is_guest_mode() in svm_vcpu_run()



On 20/9/15 04:43, Krish Sadhukhan wrote:
>
> On 9/13/20 11:55 PM, Wanpeng Li wrote:
>> From: Wanpeng Li <[email protected]>
>>
>> Analyze is_guest_mode() in svm_vcpu_run() instead of
>> svm_exit_handlers_fastpath()
>> in conformity with VMX version.
>>
>> Suggested-by: Vitaly Kuznetsov <[email protected]>
>> Signed-off-by: Wanpeng Li <[email protected]>
>> ---
>>   arch/x86/kvm/svm/svm.c | 7 +++++--
>>   1 file changed, 5 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
>> index 3da5b2f..009035a 100644
>> --- a/arch/x86/kvm/svm/svm.c
>> +++ b/arch/x86/kvm/svm/svm.c
>> @@ -3393,8 +3393,7 @@ static void svm_cancel_injection(struct kvm_vcpu
>> *vcpu)
>>   static fastpath_t svm_exit_handlers_fastpath(struct kvm_vcpu *vcpu)
>>   {
>> -    if (!is_guest_mode(vcpu) &&
>> -        to_svm(vcpu)->vmcb->control.exit_code == SVM_EXIT_MSR &&
>> +    if (to_svm(vcpu)->vmcb->control.exit_code == SVM_EXIT_MSR &&
>>           to_svm(vcpu)->vmcb->control.exit_info_1)
>>           return handle_fastpath_set_msr_irqoff(vcpu);
>> @@ -3580,6 +3579,10 @@ static __no_kcsan fastpath_t
>> svm_vcpu_run(struct kvm_vcpu *vcpu)
>>           svm_handle_mce(svm);
>>       svm_complete_interrupts(svm);
>> +
>> +    if (is_guest_mode(vcpu))
>> +        return EXIT_FASTPATH_NONE;
>> +
>>       exit_fastpath = svm_exit_handlers_fastpath(vcpu);
>>       return exit_fastpath;
>
> Not related to your changes, but should we get rid of the variable
> 'exit_fastpath' and just do,
>
>         return svm_exit_handler_fastpath(vcpu);
>
> It seems the variable isn't used anywhere else and svm_vcpu_run()
> doesn't return from anywhere else either.
>
> Also, svm_exit_handlers_fastpath() doesn't have any other caller. Should
> we get rid of it as well ?

I will do this soon, thanks.

2020-09-22 13:47:16

by Paolo Bonzini

[permalink] [raw]
Subject: Re: [PATCH] KVM: SVM: Analyze is_guest_mode() in svm_vcpu_run()

On 14/09/20 22:43, Krish Sadhukhan wrote:
>>
>
> Not related to your changes, but should we get rid of the variable
> 'exit_fastpath' and just do,
>
>         return svm_exit_handler_fastpath(vcpu);
>
> It seems the variable isn't used anywhere else and svm_vcpu_run()
> doesn't return from anywhere else either.

Yes (also because vmx will do the same once we can push
EXIT_FASTPATH_REENTER_GUEST handling up to vcpu_enter_guest)...

> Also, svm_exit_handlers_fastpath() doesn't have any other caller. 
> Should we get rid of it as well ?

... and no, because svm_vcpu_run is a very large function and therefore
it's better to keep its flow streamlined.

Paolo

2020-09-22 14:57:01

by Haiwei Li

[permalink] [raw]
Subject: Re: [PATCH] KVM: SVM: Analyze is_guest_mode() in svm_vcpu_run()

On 20/9/22 21:43, Paolo Bonzini wrote:
> On 14/09/20 22:43, Krish Sadhukhan wrote:
>>>
>>
>> Not related to your changes, but should we get rid of the variable
>> 'exit_fastpath' and just do,
>>
>> return svm_exit_handler_fastpath(vcpu);
>>
>> It seems the variable isn't used anywhere else and svm_vcpu_run()
>> doesn't return from anywhere else either.
>
> Yes (also because vmx will do the same once we can push
> EXIT_FASTPATH_REENTER_GUEST handling up to vcpu_enter_guest)...

Hi, Paolo

I have sent a patch to do this,

https://lore.kernel.org/kvm/[email protected]/

Thanks.

Haiwei

2020-09-22 14:58:29

by Paolo Bonzini

[permalink] [raw]
Subject: Re: [PATCH] KVM: SVM: Analyze is_guest_mode() in svm_vcpu_run()

On 22/09/20 16:54, Haiwei Li wrote:
>> EXIT_FASTPATH_REENTER_GUEST handling up to vcpu_enter_guest)...
> Hi, Paolo
>
> I have sent a patch to do this,
>
> https://lore.kernel.org/kvm/[email protected]/

Cool, thanks. I think I'll just squash it in Wanpeng's if you don't mind.

Paolo

2020-09-22 15:06:55

by Haiwei Li

[permalink] [raw]
Subject: Re: [PATCH] KVM: SVM: Analyze is_guest_mode() in svm_vcpu_run()

On Tue, Sep 22, 2020 at 10:56 PM Paolo Bonzini <[email protected]> wrote:
>
> On 22/09/20 16:54, Haiwei Li wrote:
> >> EXIT_FASTPATH_REENTER_GUEST handling up to vcpu_enter_guest)...
> > Hi, Paolo
> >
> > I have sent a patch to do this,
> >
> > https://lore.kernel.org/kvm/[email protected]/
>
> Cool, thanks. I think I'll just squash it in Wanpeng's if you don't mind.

It's all ok. I don't mind. Thanks.

Haiwei