Zhenzhong Duan <zhenzhong.d...@oracle.com> writes:

> On 2019/10/13 17:02, Vitaly Kuznetsov wrote:
>> Zhenzhong Duan <zhenzhong.d...@oracle.com> writes:
> ...snip
>> diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
>> index ef836d6..6e14bd4 100644
>> --- a/arch/x86/kernel/kvm.c
>> +++ b/arch/x86/kernel/kvm.c
>> @@ -825,18 +825,31 @@ __visible bool __kvm_vcpu_is_preempted(long cpu)
>>    */
>>   void __init kvm_spinlock_init(void)
>>   {
>> -    /* Does host kernel support KVM_FEATURE_PV_UNHALT? */
>> -    if (!kvm_para_has_feature(KVM_FEATURE_PV_UNHALT))
>> +    /*
>> +     * Disable PV qspinlocks if host kernel doesn't support
>> +     * KVM_FEATURE_PV_UNHALT feature or there is only 1 vCPU.
>> +     * virt_spin_lock_key is enabled to avoid lock holder
>> +     * preemption issue.
>> +     */
>> +    if (!kvm_para_has_feature(KVM_FEATURE_PV_UNHALT) ||
>> +        num_possible_cpus() == 1) {
>> +            pr_info("PV spinlocks disabled\n");
>> Why don't we need static_branch_disable(&virt_spin_lock_key) here?
>
> Thanks for review.
>
> I have a brief explanation in above comment area.
>
> Boris also raised the same question in v4 and see my detailed explanation
>
> in https://lkml.org/lkml/2019/10/6/39
>
>>
>> Also, as you're printing the exact reason for PV spinlocks disablement
>> in other cases, I'd suggest separating "no host support" and "single
>> CPU" cases.
>
> Will do after reaching a consensus on your first question.

Oh, sorry I missed v4 discussion. As I'm not the first to ask why we
don't do static_branch_disable(&virt_spin_lock_key) here I suggest we do
the followin:

- Split !kvm_para_has_feature(KVM_FEATURE_PV_UNHALT) and
  num_possible_cpus() == 1 cases
- Do static_branch_disable(&virt_spin_lock_key) for UP case (just for
  consistency).
- Add a comment why we don't do that for
  !kvm_para_has_feature(KVM_FEATURE_PV_UNHALT) case (basically, what you
  replied to Boris)

This will also allow us to print the exact reason.

>
>>
>>>             return;
>>> +   }
>>>   
>>>     if (kvm_para_has_hint(KVM_HINTS_REALTIME)) {
>>> +           pr_info("PV spinlocks disabled with KVM_HINTS_REALTIME 
>>> hints.\n");
>>>             static_branch_disable(&virt_spin_lock_key);
>>>             return;
>>>     }
>>>   
>>> -   /* Don't use the pvqspinlock code if there is only 1 vCPU. */
>>> -   if (num_possible_cpus() == 1)
>>> +   if (nopvspin) {
>>> +           pr_info("PV spinlocks disabled forced by \"nopvspin\" 
>>> parameter.\n");
>> Nit: to make it sound better a comma is missing between 'disabled' and
>> 'forced', or
>>
>> "PV spinlocks forcefully disabled by ..." if you prefer.
>
> Will do.
>
> Zhenzhong
>
>

-- 
Vitaly

Reply via email to