From nobody Sun Feb 8 12:18:40 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA0A6C3DA7A for ; Fri, 6 Jan 2023 01:14:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232270AbjAFBOm (ORCPT ); Thu, 5 Jan 2023 20:14:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236843AbjAFBNk (ORCPT ); Thu, 5 Jan 2023 20:13:40 -0500 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5728A71FF6 for ; Thu, 5 Jan 2023 17:13:38 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id a11-20020a17090a8c0b00b00226cdbf8bbcso1917799pjo.5 for ; Thu, 05 Jan 2023 17:13:38 -0800 (PST) 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:message-id:reply-to; bh=dY73TyImmD0wCqNL26nvzhCHfX8vBgtKvyMOXbN+v1I=; b=B861zubBIjRS4M7hrE2P/lP1yiAP6O9QSDe8ztqdzZ75i+UmjMLuMJpNqdL1Elk8v/ RAAfOXEHLS8mwZoF3qdVZsbOy4/D5cBa1NaNov3OMq4WhgX+YWKDc18ZxIck79I1eX76 1S9Dd/6XPyWvlMNYGUn+0Bxbfx7NM3Bb8F2MkBes6HJ441yQNZ9yJnSAr6SZrWwUMgF0 F6fMSah5f8GauF6VTpl4lM81mhmTu8PAsbyUeUc8I9prYkJWnHInHrRzbBeahfU3Lci8 NUNUa/xmwowTdGQxAb69BtM7JoxrsfzEZIYUinrzK/gKYn1gTY4gK8xbr8v0C/Ggak2O zMHQ== 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:message-id :reply-to; bh=dY73TyImmD0wCqNL26nvzhCHfX8vBgtKvyMOXbN+v1I=; b=XJLGe8j0VLA7j+luMlBPMxbVvHGNFfJMrkhGOhr6c//QGf7j5kk5DiPD3e9rVnqbR3 FJjGEh0XNqvfSO/ClHW3e08PJKlp9WPYSEA55JwgTCEJjCgbuUmTUS+aDR6bx/BNLZMs rPeHnkDV2WzF/N9PkLn/SRoTaky0dZwbxlc99zY4XFLYMFleydeXyjCrhvWNU/F108AD QtRrx8GcfWM6HRma5ZJysflvSyDPjRK/gLt+9nGUbmhTo5uhDyi8aCSOSTlWJXneajuk F4XHOWkFuYRzkKMSYQy2jWONwQJ3qk12dIBbOY4AlHh0U39iQWXvUH9l28e5kYw+7afC eYpg== X-Gm-Message-State: AFqh2kpy2mg463Sl/dVFC8mAoXBiJ0dWxAbE7zW0GrexUaNXjLzWVxT3 lY8xhl2sb0MIvNKd52QBn1xNLCOx2tw= X-Google-Smtp-Source: AMrXdXvXUwoPtx1VGD8IrsXsf3RNGjmLaGKsP+ZxpWSG6SVLX4nROauFHzf5Vp7o4I738ZRKSXgckNPWa9E= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:aa7:999c:0:b0:582:74a2:1e4e with SMTP id k28-20020aa7999c000000b0058274a21e4emr1235081pfh.26.1672967617919; Thu, 05 Jan 2023 17:13:37 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 6 Jan 2023 01:12:47 +0000 In-Reply-To: <20230106011306.85230-1-seanjc@google.com> Mime-Version: 1.0 References: <20230106011306.85230-1-seanjc@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20230106011306.85230-15-seanjc@google.com> Subject: [PATCH v5 14/33] 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, Alejandro Jimenez , Maxim Levitsky , Suravee Suthikulpanit , Li RongQing , Greg Edwards Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 0f67fd34ef99..e4b5f8b14882 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 =20 logid_index =3D cluster + __ffs(bitmap); =20 - 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 =3D logid_index; + } else { u32 *avic_logical_id_table =3D page_address(kvm_svm->avic_logical_id_table_page); =20 @@ -393,23 +403,6 @@ static int avic_kick_target_vcpus_fast(struct kvm *kvm= , struct kvm_lapic *source =20 l1_physical_id =3D 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 =3D (icrh & 0xffff0000) >> 16; - int apic =3D 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 !=3D (1 << apic)) - return -EINVAL; - - l1_physical_id =3D (cluster << 4) + apic; } } =20 --=20 2.39.0.314.g84b9a713c41-goog