Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp448504rwb; Fri, 2 Sep 2022 17:41:53 -0700 (PDT) X-Google-Smtp-Source: AA6agR7GjH/JiMXtQvKmIRPMXWwoOFwgCL7/Bpv11kdD0REaImhsLLQ2tRpAxg1AfxSgF3g3ksul X-Received: by 2002:a05:6402:428c:b0:440:8259:7a2b with SMTP id g12-20020a056402428c00b0044082597a2bmr33883174edc.329.1662165713122; Fri, 02 Sep 2022 17:41:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662165713; cv=none; d=google.com; s=arc-20160816; b=XiQmF8FyQKaG4ney1fPZAjA80XZhlPmObvf+T8xgVhWIniTrEdRs8CYjiA3DCdfnP+ Vh5BXi2wkCj79SZt/xBnUzDHZfOQsRVBzOqLM8FyKwh9EXBq5ar67I1/UrpXV/apniLA kbwWZMBfaH+t/lVD0fkRS9eknBTDxhtdIBzyjk6CBiBaEUZzbCsAakgH0eBc/Op8Sw1F nLIcfhw4tkNw6voQINiuptpkJu6yJauHADZ95C9zcqzJUwgDFG56DjI0cysH3XaiyqI3 yjci+HtgXTcADBAciYDpqAl6vw/Pk7vwL2Ut1zioBuQsp17sLmJRlVJ/1WQ3KJqf6hGS kD+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=gdqi7/sisgOJWdb3UjZLC+OFglcO8pjrSzcL6Yf8oaE=; b=qsQ3KwsSzkMtcHEzm+1EQd761ODelSZnqUk1rAPt5k1nbbn1LBzNtOzeKAE/LwBzLh xXc1maI0mxn8Rwcu6Os/eanLbOXNCUA5WG2ZPUhWHXCfQwUx7bgvYL2BcJJO+JEVx4oH YpSPi2w4Ji5zdR2VqiT4oaa2ZZwvcbRLnHTPVzI3B+xSVCNv2t3YdCazVS2hV2Wm4o1a 2TV5ZqJRG0oZX5qBLSIki3j2socsi73WwP9cV4M7wyLfNxPCRbcb0tfAEE8mnRNXDfdl BpJ3O+MwGxKsm7UfySWaDBSu7QJbhzoANKPuN03dYbA5U/wuataYIq3gyrlkiKwBvLW4 osww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=qdZ1uwpy; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hb34-20020a170907162200b0073d84169079si3417173ejc.571.2022.09.02.17.41.28; Fri, 02 Sep 2022 17:41:53 -0700 (PDT) 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=@google.com header.s=20210112 header.b=qdZ1uwpy; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231481AbiICAXp (ORCPT + 99 others); Fri, 2 Sep 2022 20:23:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231388AbiICAXR (ORCPT ); Fri, 2 Sep 2022 20:23:17 -0400 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6ACEF63DE for ; Fri, 2 Sep 2022 17:23:14 -0700 (PDT) Received: by mail-pf1-x449.google.com with SMTP id c135-20020a624e8d000000b0053617082770so1719772pfb.8 for ; Fri, 02 Sep 2022 17:23:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date; bh=gdqi7/sisgOJWdb3UjZLC+OFglcO8pjrSzcL6Yf8oaE=; b=qdZ1uwpywN2x8XHJ4BBaMqpMM/TLq88CuwaWUgF7yRNgkIc2u3iavToNk3hjy/g1M1 g38i6uQLHl/N/phr+D80midzVaIBr2r5vezSxLvVEM1lKptWwnyLluSqYep03gNZURsu wWDHbjf241306jJL9GO7WJf34Cbu5X75AdfwLc3eHznK7iRuheBqg0S6Yk+q/gCL+rsh b6Kf6ZyDhrzdfl2V8FXG90fVgQNcMZ4NnLz586ri74P17Un2luWxvVBcuGGwNTwv1N9K mC0CpD9RqNMBMZtS55NVq3lsGeL23Z4jt/5q26+840w2d3v1S0Su1pE7CkXaidk3r7Pr 1qbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date; bh=gdqi7/sisgOJWdb3UjZLC+OFglcO8pjrSzcL6Yf8oaE=; b=JLnYnOUzkLR1OmdVMIWZiq0BqReNnd541HukBKErrsELryES1es2A2NS+Qm1hf1b2+ Kb0NBRyanwTIT/yruezB+0l63llC3UFupRzd93EYWwb8eLwtLJ7RsPTECCND5KdSrSau nFaE7FhRTAzfPFk0MTsdA6vX58E7/7NZRvNWW1Ac79pCXMyP0FzKDBIToJnxhvcgYddV WPz34tcFBW8uXg9I6IRFO08y+H/0rGYwqCno9hj36vuc5uxqyCLUej+R+pl/U7IXE2R5 UNkVg+o7yx2DRM1gP3IeDZmIZMw3U/2n3+ZqOSj7ZLIXU2KCRaTSgmViE2lbh1nx+lP3 jfiA== X-Gm-Message-State: ACgBeo0Z8DssLFBppbIyF/9XOfxgBTl6QnrbAB2FSRFVERKdjT1jp1Tq T+89uuUkDAL00DH3qbSTeW3XhpA2UvU= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:da86:b0:174:cbcf:5f98 with SMTP id j6-20020a170902da8600b00174cbcf5f98mr26500000plx.49.1662164594392; Fri, 02 Sep 2022 17:23:14 -0700 (PDT) Reply-To: Sean Christopherson Date: Sat, 3 Sep 2022 00:22:40 +0000 In-Reply-To: <20220903002254.2411750-1-seanjc@google.com> Mime-Version: 1.0 References: <20220903002254.2411750-1-seanjc@google.com> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Message-ID: <20220903002254.2411750-10-seanjc@google.com> Subject: [PATCH v2 09/23] Revert "KVM: SVM: Use target APIC ID to complete x2AVIC IRQs when possible" From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Suravee Suthikulpanit , Maxim Levitsky , Li RongQing Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham 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 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 163edc42f979..8259a64c99d6 100644 --- a/arch/x86/kvm/svm/avic.c +++ b/arch/x86/kvm/svm/avic.c @@ -405,7 +405,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); @@ -420,23 +430,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; } } -- 2.37.2.789.g6183377224-goog