Re: [PATCH v2 11/15] svm: Temporary deactivate AVIC during ExtINT handling

From: Suthikulpanit, Suravee
Date: Wed Aug 28 2019 - 11:18:10 EST


Alex,

On 8/19/19 5:35 AM, Alexander Graf wrote:
>
>
> On 15.08.19 18:25, Suthikulpanit, Suravee wrote:
>> AMD AVIC does not support ExtINT. Therefore, AVIC must be temporary
>> deactivated and fall back to using legacy interrupt injection via vINTR
>> and interrupt window.
>>
>> Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@xxxxxxx>
>> ---
>> Â arch/x86/kvm/svm.c | 49
>> +++++++++++++++++++++++++++++++++++++++++++++----
>> Â 1 file changed, 45 insertions(+), 4 deletions(-)
>>
>> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
>> index cfa4b13..4690351 100644
>> --- a/arch/x86/kvm/svm.c
>> +++ b/arch/x86/kvm/svm.c
>> @@ -384,6 +384,7 @@ struct amd_svm_iommu_ir {
>> Â static void svm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0);
>> Â static void svm_flush_tlb(struct kvm_vcpu *vcpu, bool invalidate_gpa);
>> Â static void svm_complete_interrupts(struct vcpu_svm *svm);
>> +static void svm_request_activate_avic(struct kvm_vcpu *vcpu);
>> Â static bool svm_get_enable_apicv(struct kvm *kvm);
>> Â static inline void avic_post_state_restore(struct kvm_vcpu *vcpu);
>> @@ -4494,6 +4495,15 @@ static int interrupt_window_interception(struct
>> vcpu_svm *svm)
>> Â {
>> ÂÂÂÂÂ kvm_make_request(KVM_REQ_EVENT, &svm->vcpu);
>> ÂÂÂÂÂ svm_clear_vintr(svm);
>> +
>> +ÂÂÂ /*
>> +ÂÂÂÂ * For AVIC, the only reason to end up here is ExtINTs.
>> +ÂÂÂÂ * In this case AVIC was temporarily disabled for
>> +ÂÂÂÂ * requesting the IRQ window and we have to re-enable it.
>> +ÂÂÂÂ */
>> +ÂÂÂ if (svm_get_enable_apicv(svm->vcpu.kvm))
>> +ÂÂÂÂÂÂÂ svm_request_activate_avic(&svm->vcpu);
>
> Would it make sense to add a trace point here and to the other call
> sites, so that it becomes obvious in a trace when and why exactly avic
> was active/inactive?
>
> The trace point could add additional information on the why.

Sure, sounds good.

>> ....
>> @@ -5522,9 +5558,6 @@ static void enable_irq_window(struct kvm_vcpu
>> *vcpu)
>> Â {
>> ÂÂÂÂÂ struct vcpu_svm *svm = to_svm(vcpu);
>> -ÂÂÂ if (kvm_vcpu_apicv_active(vcpu))
>> -ÂÂÂÂÂÂÂ return;
>> -
>> ÂÂÂÂÂ /*
>> ÂÂÂÂÂÂ * In case GIF=0 we can't rely on the CPU to tell us when GIF
>> becomes
>>  * 1, because that's a separate STGI/VMRUN intercept. The next
>> time we
>> @@ -5534,6 +5567,14 @@ static void enable_irq_window(struct kvm_vcpu
>> *vcpu)
>> ÂÂÂÂÂÂ * window under the assumption that the hardware will set the GIF.
>> ÂÂÂÂÂÂ */
>> ÂÂÂÂÂ if ((vgif_enabled(svm) || gif_set(svm)) && nested_svm_intr(svm)) {
>> +ÂÂÂÂÂÂÂ /*
>> +ÂÂÂÂÂÂÂÂ * IRQ window is not needed when AVIC is enabled,
>> +ÂÂÂÂÂÂÂÂ * unless we have pending ExtINT since it cannot be injected
>> +ÂÂÂÂÂÂÂÂ * via AVIC. In such case, we need to temporarily disable AVIC,
>> +ÂÂÂÂÂÂÂÂ * and fallback to injecting IRQ via V_IRQ.
>> +ÂÂÂÂÂÂÂÂ */
>> +ÂÂÂÂÂÂÂ if (kvm_vcpu_apicv_active(vcpu))
>> +ÂÂÂÂÂÂÂÂÂÂÂ svm_request_deactivate_avic(&svm->vcpu);
>
> Did you test AVIC with nesting? Did you actually run across this issue
> there?

Currently, we have not claimed that AVIC is supported w/ nested VM.
That's why we have not enabled AVIC by default yet. We will be looking
more into that next.

Suravee