Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1728327rwb; Thu, 8 Dec 2022 14:38:04 -0800 (PST) X-Google-Smtp-Source: AA0mqf5WbPGtxy4EGfpBlX7Jd0qN85RdCzCd8MVbocAG93xYqpZ1JP1Ja0/unXxp5dRlOhTnrkO/ X-Received: by 2002:a17:906:ecb2:b0:7c0:fa2c:fc9b with SMTP id qh18-20020a170906ecb200b007c0fa2cfc9bmr2704553ejb.55.1670539083999; Thu, 08 Dec 2022 14:38:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670539083; cv=none; d=google.com; s=arc-20160816; b=HQV/8Kikj2rJ2LsZK4QehqYgtYRhGNFS2sGcOdOWerXjCkzNhMQyXZKx/T/Z+fcjFX cIjkhMylu86GF+8oV8q1QWRYL87a3EFSfUs1+3/EqJXtrM6bSSbprlcXwSImOoJazanr xlHOv/oY5msoZU5qlCG3IG68T+t4Y+Pm9UlezEyXI5uodaaecKKN+kzNoq1DtL7RaQti 8FBHsdTYbxHOd+QUc9C6WZHJVnwvL5ykU1+4VDXXSpd+b/CnhyycduWO058nfNxpSc8x igauIgZJi/q0lI+HHLZkgATBErs19rlGUazh3dCMczXAVPgrccpqLQ01pIsAuIFRBI0l XkHw== 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=FliWeXV018ru6ANKqxRF6RtAWv58W7FzLHcXM4gsCwg=; b=SMFrkqJSerN95EabdUVj/N0OAfZ3P+vUN+YdpvUCSwpTmbzlwd+K4vOkhQ7OtfO9Z2 1iFO0x9ZKOqg89VjdboxjQ3gh2nUJFWBvMepn46K3sobe1QVNXyTviY5fNPRUmxTvP+Z 8dpO034D+6+u47ZK4n6tRm0vfy1zAOtyFV4UYxFoOYEdduDhnV3TZZVnURUswHG0s5DI uid/1RYRc6qUSUVqubJdbjaXS++nkMpLyqdKk9joVUxWMQh8aTb0JeOdV6PGgp2vm6GB CmdbFcpf7IW2dVMYamNIo+K9CcVyKC6j/otvuW80Rh+F5zwOFMDdULYkKj8l/NULD7Fu loYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="V/7uS/Cm"; 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 t15-20020a1709067c0f00b007aa8a5131a3si14378314ejo.181.2022.12.08.14.37.46; Thu, 08 Dec 2022 14:38:03 -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="V/7uS/Cm"; 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 S230014AbiLHV6G (ORCPT + 74 others); Thu, 8 Dec 2022 16:58:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229751AbiLHV5s (ORCPT ); Thu, 8 Dec 2022 16:57:48 -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 ESMTPS id E60B86B9AB for ; Thu, 8 Dec 2022 13:56:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670536610; 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=FliWeXV018ru6ANKqxRF6RtAWv58W7FzLHcXM4gsCwg=; b=V/7uS/CmdmZA7bX2LBrQ1ar+j6qbk2pJq1D1wboFeRsWpOtT9VqCPJZdNzar7ZVQwEoCiH zpPeFB7TzfJpIFiXQ+KP1GuoB4Ytwe0ZTtC3XVmuq9t8ReErLaLUdJcZNd2QjE6IWFUMC9 D1lxAE85n/XPq6pmEE41koODewoXYgI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-494-mknDyv2_PHaXXflb6fuTUg-1; Thu, 08 Dec 2022 16:56:45 -0500 X-MC-Unique: mknDyv2_PHaXXflb6fuTUg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 96E4E101A52A; Thu, 8 Dec 2022 21:56:44 +0000 (UTC) Received: from starship (unknown [10.35.206.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2E2762166B26; Thu, 8 Dec 2022 21:56:43 +0000 (UTC) Message-ID: <121a948a7089c7b30226efd6d13871432eec43de.camel@redhat.com> Subject: Re: [PATCH v4 15/32] Revert "KVM: SVM: Use target APIC ID to complete x2AVIC IRQs when possible" From: Maxim Levitsky To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Alejandro Jimenez , Suravee Suthikulpanit , Li RongQing Date: Thu, 08 Dec 2022 23:56:42 +0200 In-Reply-To: <20221001005915.2041642-16-seanjc@google.com> References: <20221001005915.2041642-1-seanjc@google.com> <20221001005915.2041642-16-seanjc@google.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 3.1 on 10.11.54.6 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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 Sat, 2022-10-01 at 00:58 +0000, Sean Christopherson wrote: > Due to a likely mismerge of patches, KVM ended up with a superfluous > commit to "enable" AVIC's fast path for x2AVIC mode. Even worse, the > superfluous commit has several bugs and creates a nasty local shadow > variable. > > Rather than fix the bugs piece-by-piece[*] to achieve the same end > result, revert the patch wholesale. > > Opportunistically add a comment documenting the x2AVIC dependencies. > > This reverts commit 8c9e639da435874fb845c4d296ce55664071ea7a. > > [*] https://lore.kernel.org/all/YxEP7ZBRIuFWhnYJ@google.com > > Fixes: 8c9e639da435 ("KVM: SVM: Use target APIC ID to complete x2AVIC IRQs when possible") > Suggested-by: Maxim Levitsky > Signed-off-by: Sean Christopherson > --- > arch/x86/kvm/svm/avic.c | 29 +++++++++++------------------ > 1 file changed, 11 insertions(+), 18 deletions(-) > > diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c > index e35e9363e7ff..605c36569ddf 100644 > --- a/arch/x86/kvm/svm/avic.c > +++ b/arch/x86/kvm/svm/avic.c > @@ -378,7 +378,17 @@ static int avic_kick_target_vcpus_fast(struct kvm *kvm, struct kvm_lapic *source > > logid_index = cluster + __ffs(bitmap); > > - if (!apic_x2apic_mode(source)) { > + if (apic_x2apic_mode(source)) { > + /* > + * For x2APIC, the logical APIC ID is a read-only value > + * that is derived from the x2APIC ID, thus the x2APIC > + * ID can be found by reversing the calculation (done > + * above). Note, bits 31:20 of the x2APIC ID are not > + * propagated to the logical ID, but KVM limits the > + * x2APIC ID limited to KVM_MAX_VCPU_IDS. > + */ > + l1_physical_id = logid_index; > + } else { > u32 *avic_logical_id_table = > page_address(kvm_svm->avic_logical_id_table_page); > > @@ -393,23 +403,6 @@ static int avic_kick_target_vcpus_fast(struct kvm *kvm, struct kvm_lapic *source > > l1_physical_id = logid_entry & > AVIC_LOGICAL_ID_ENTRY_GUEST_PHYSICAL_ID_MASK; > - } else { > - /* > - * For x2APIC logical mode, cannot leverage the index. > - * Instead, calculate physical ID from logical ID in ICRH. > - */ > - int cluster = (icrh & 0xffff0000) >> 16; > - int apic = ffs(icrh & 0xffff) - 1; > - > - /* > - * If the x2APIC logical ID sub-field (i.e. icrh[15:0]) > - * contains anything but a single bit, we cannot use the > - * fast path, because it is limited to a single vCPU. > - */ > - if (apic < 0 || icrh != (1 << apic)) > - return -EINVAL; > - > - l1_physical_id = (cluster << 4) + apic; > } > } > Reviewed-by: Maxim Levitsky Best regards, Maxim Levitsky