Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1978878pxm; Thu, 24 Feb 2022 13:28:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJz4Eq44Rp7T2numABQAM10VkQy9p0epis+AqbCOsz5do/F/DkkbnE7uloZo6XMqFT+ZidCB X-Received: by 2002:a17:907:7053:b0:6a6:b835:dbd3 with SMTP id ws19-20020a170907705300b006a6b835dbd3mr3715857ejb.190.1645738127925; Thu, 24 Feb 2022 13:28:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645738127; cv=none; d=google.com; s=arc-20160816; b=QU8nPPpqtC88bwuUZRbIG02Bah7ugwBk7VvYfm9sbIzY5OWXw7IRclt5p0B4oG2tQA h9rdwfk3qltRf9qh/bl0bmAyGpCCK8pzaLQ842mABXErnbutXVfJ7sNK5E1K3CmCSqPK stUJNeQM1kr1TkuMFW4ztuHxQhAZcmfSOLSubOSh7n8Zss427CR2AZ6MTtyN3QwkDTat XUT1k9Wtu7nTdxMfdg+uN6xMDqxnomShT6MZ95pWcP74qRBycqHOmYmhr/zmwSHnkSS/ szjy+yx0LdGZn7GVbc7rMnYJILS9AzcYJVQ/TA7Ur3zY0s2OJum1aeDyzhEFGaiszpFt AGcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=g0B+WO5LiFSrbCtPwzNlhDkRjWZYlmhLiJlV8EM915Y=; b=N2Pbk7u/kJ/wC7YlrYznFn9H1ip1WkshJ6Ask5ohNdnhFvQz5cxPlcAwMAppRzQz/f ct2fD7iIciCPi2+BZgCeprH/adwU3Esj+Wo80XVZRmLbbkGt0RurGpsT2UQoD//ov4aU mARkdCE7LOy6YEDzzA6AXhhew6IQ5TM9lnAK0QCBN253j8mMtWTJRr3OIzmyHCOCxT5e S/KyZzbPYdLm/GzavZgWwQYQCmEPWoi8kIcrY7YW2yX82mBer1rpU28nw1GEaYPUKlkT qd+L60bNfwWK7k6kvLbXmrvPeIY5/wVCPsg49IQH2Cx90Sqy1WLJDejRlC4r3d3fKVT6 3DBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NPuI0xh8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i4-20020a170906698400b006d03abb9255si338562ejr.767.2022.02.24.13.28.24; Thu, 24 Feb 2022 13:28:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NPuI0xh8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234204AbiBXUHR (ORCPT + 99 others); Thu, 24 Feb 2022 15:07:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233578AbiBXUHP (ORCPT ); Thu, 24 Feb 2022 15:07:15 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 33A2342EF6 for ; Thu, 24 Feb 2022 12:06:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1645733203; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=g0B+WO5LiFSrbCtPwzNlhDkRjWZYlmhLiJlV8EM915Y=; b=NPuI0xh8+tjV5P0gHeUJS7OO1sCjqz/i6OvHf7L7HG0mj+a7adYgjA8hn2LB/SvHNgby/s BMBnJuK0J/qscUKxSBuJiyT7LbRWDy02LiL+EhXuGOKC6bun/WA5BwT5c11gxEO+9uXr8X 5oG5y7QekWlAACdjlj+CZ2cZqs+dQMw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-634-GPMiioRsN1epimur1G8LOA-1; Thu, 24 Feb 2022 15:06:40 -0500 X-MC-Unique: GPMiioRsN1epimur1G8LOA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AF2201854E21; Thu, 24 Feb 2022 20:06:38 +0000 (UTC) Received: from starship (unknown [10.40.195.190]) by smtp.corp.redhat.com (Postfix) with ESMTP id 77C9B2D1F7; Thu, 24 Feb 2022 20:06:35 +0000 (UTC) Message-ID: Subject: Re: [RFC PATCH 12/13] KVM: SVM: Remove APICv inhibit reasone due to x2APIC From: Maxim Levitsky To: Suravee Suthikulpanit , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: pbonzini@redhat.com, seanjc@google.com, joro@8bytes.org, jon.grimm@amd.com, wei.huang2@amd.com, terry.bowman@amd.com Date: Thu, 24 Feb 2022 22:06:34 +0200 In-Reply-To: <20220221021922.733373-13-suravee.suthikulpanit@amd.com> References: <20220221021922.733373-1-suravee.suthikulpanit@amd.com> <20220221021922.733373-13-suravee.suthikulpanit@amd.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 2022-02-20 at 20:19 -0600, Suravee Suthikulpanit wrote: > Currently, AVIC is inactive when booting a VM w/ x2APIC support. > With x2AVIC support, the APICV_INHIBIT_REASON_X2APIC can be removed. The commit title is a bit misleading - the inhibit reason is not removed, but rather AVIC is not inhibited when x2avic is present. > > Signed-off-by: Suravee Suthikulpanit > --- > arch/x86/kvm/svm/avic.c | 21 +++++++++++++++++++++ > arch/x86/kvm/svm/svm.c | 18 ++---------------- > arch/x86/kvm/svm/svm.h | 1 + > 3 files changed, 24 insertions(+), 16 deletions(-) > > diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c > index 3306b74f1d8b..874c89f8fd47 100644 > --- a/arch/x86/kvm/svm/avic.c > +++ b/arch/x86/kvm/svm/avic.c > @@ -21,6 +21,7 @@ > > #include > > +#include "cpuid.h" > #include "trace.h" > #include "lapic.h" > #include "x86.h" > @@ -176,6 +177,26 @@ void avic_vm_destroy(struct kvm *kvm) > spin_unlock_irqrestore(&svm_vm_data_hash_lock, flags); > } > > +void avic_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu, int nested) > +{ > + /* > + * If the X2APIC feature is exposed to the guest, > + * disable AVIC unless X2AVIC mode is enabled. > + */ > + if (avic_mode == AVIC_MODE_X1 && > + guest_cpuid_has(vcpu, X86_FEATURE_X2APIC)) > + kvm_request_apicv_update(vcpu->kvm, false, > + APICV_INHIBIT_REASON_X2APIC); > + > + /* > + * Currently, AVIC does not work with nested virtualization. > + * So, we disable AVIC when cpuid for SVM is set in the L1 guest. > + */ > + if (nested && guest_cpuid_has(vcpu, X86_FEATURE_SVM)) > + kvm_request_apicv_update(vcpu->kvm, false, > + APICV_INHIBIT_REASON_NESTED); BTW, now that I am thinking about it, it would be nice to be able to force the AVIC_MODE_X1 even if x2avic is present, for debug purposes from a module param. Just a suggestion. > +} > + > int avic_vm_init(struct kvm *kvm) > { > unsigned long flags; > diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c > index afca26aa1f40..b7bc6cd74aba 100644 > --- a/arch/x86/kvm/svm/svm.c > +++ b/arch/x86/kvm/svm/svm.c > @@ -3992,23 +3992,9 @@ static void svm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) > vcpu->arch.reserved_gpa_bits &= ~(1UL << (best->ebx & 0x3f)); > } > > - if (kvm_vcpu_apicv_active(vcpu)) { > - /* > - * AVIC does not work with an x2APIC mode guest. If the X2APIC feature > - * is exposed to the guest, disable AVIC. > - */ > - if (guest_cpuid_has(vcpu, X86_FEATURE_X2APIC)) > - kvm_request_apicv_update(vcpu->kvm, false, > - APICV_INHIBIT_REASON_X2APIC); > + if (kvm_vcpu_apicv_active(vcpu)) > + avic_vcpu_after_set_cpuid(vcpu, nested); > > - /* > - * Currently, AVIC does not work with nested virtualization. > - * So, we disable AVIC when cpuid for SVM is set in the L1 guest. > - */ > - if (nested && guest_cpuid_has(vcpu, X86_FEATURE_SVM)) > - kvm_request_apicv_update(vcpu->kvm, false, > - APICV_INHIBIT_REASON_NESTED); > - } > init_vmcb_after_set_cpuid(vcpu); > } > > diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h > index 41514df5107e..aea80abe9186 100644 > --- a/arch/x86/kvm/svm/svm.h > +++ b/arch/x86/kvm/svm/svm.h > @@ -578,6 +578,7 @@ void avic_update_vapic_bar(struct vcpu_svm *svm, u64 data); > void avic_vcpu_load(struct kvm_vcpu *vcpu, int cpu); > void avic_vcpu_put(struct kvm_vcpu *vcpu); > void avic_post_state_restore(struct kvm_vcpu *vcpu); > +void avic_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu, int nested); > void svm_set_virtual_apic_mode(struct kvm_vcpu *vcpu); > void svm_refresh_apicv_exec_ctrl(struct kvm_vcpu *vcpu); > bool svm_check_apicv_inhibit_reasons(ulong bit); Reviewed-by: Maxim Levitsky Best regards, Maxim Levitsky