Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp509150rwe; Wed, 31 Aug 2022 06:36:14 -0700 (PDT) X-Google-Smtp-Source: AA6agR4+HDdeBAxlx9LUMEmIXjUuRwUIAlaDN3z9C4EzMqtxF6sVKxKu4YNgNcNfS6mh0YG8i6tF X-Received: by 2002:a17:907:3e81:b0:726:9615:d14d with SMTP id hs1-20020a1709073e8100b007269615d14dmr19786556ejc.517.1661952963907; Wed, 31 Aug 2022 06:36:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661952963; cv=none; d=google.com; s=arc-20160816; b=cekkSL+TNv22TVBh870sc7zPGIwsdqFjGE3j3TH4UBLwEZL/aHQkDZapGlU2Ol5t7B CotRRuuxunUFNp17fTEXJZhfdPZgo+S1lGXGBMDbcccRMxebMybNfJZoohnrNVztMvX+ 98P2MPITc5KBLkBynclevT2YFXcEl+Jua5w+nJEa+MlVlpl7IlacGC12QrO2kgT2XuNn tBOnk+2P+t4ydugE8rTLIxYSLuJKxlFUTXcqWdEdx3P52mGbAXkUJ93OKBGFveAyrGLo wcIugxNBpL+LjAOtihbayoboSCAf+edxCuFmJ6Ep0VGNcqHXwp/OGxaXUB8JxFaTlInY wsDw== 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=ZECxeq+VOxz3+YhbPEZAiDDllz5WtJE1F6cO2w5XPV0=; b=H5m53idEJF5CIAi85u0vAztAwH2VlJbU93qtoGKVL88sQRrF2O+XmiSrG2pKECX8qX zW3dburGXnXuuBcWbIPlEirZZKz/rapjXASyuFYBpNOzHDLHM4SHbg5c+6X6zSLdsGsL qkKtwTERn4p/AhuAHH3D6RHVthpiP76nrLMA3p/bIvXb/aYkpqsVNSu4H5W01BsXkI0H gSbs/jFN6reiirbArTJ3JIHzLShldbIWqeEFE+Vn/IIAjp4IV1ZIxe0du0+xcS5VL0jE 5sMpInVc/hOpsRP1/mugvvBcH44KSu26+KjOLyk+Cnfw9lYTAuaXPlU62V/vN21b77kT Tj0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SBXRsQuJ; 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 m6-20020a1709061ec600b00706b9787b43si9577649ejj.319.2022.08.31.06.35.37; Wed, 31 Aug 2022 06:36:03 -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=@redhat.com header.s=mimecast20190719 header.b=SBXRsQuJ; 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 S231793AbiHaNXw (ORCPT + 99 others); Wed, 31 Aug 2022 09:23:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231886AbiHaNXj (ORCPT ); Wed, 31 Aug 2022 09:23:39 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B2B3CB5CC for ; Wed, 31 Aug 2022 06:23:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661952217; 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=ZECxeq+VOxz3+YhbPEZAiDDllz5WtJE1F6cO2w5XPV0=; b=SBXRsQuJ9uJQOGeYQ5lbZymEha0hM0i2NZMOOzsrkPNVJK4UTwoARNQd4LECpDj8HGSgAG UvX42MXT89J7cZeQM8Sr+k9b+fzYlRIDet4d5rDcdueXqm9Nk0jcUtJPEabHt5o0oYndYX o+uKbzrASq8l8nTtJUEG+bVF36xvNQs= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-173-GNYk6GstMAu40G4z40UUqQ-1; Wed, 31 Aug 2022 09:23:36 -0400 X-MC-Unique: GNYk6GstMAu40G4z40UUqQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ADB051C07589; Wed, 31 Aug 2022 13:23:35 +0000 (UTC) Received: from starship (unknown [10.40.194.96]) by smtp.corp.redhat.com (Postfix) with ESMTP id 186201121320; Wed, 31 Aug 2022 13:23:33 +0000 (UTC) Message-ID: Subject: Re: [PATCH 12/19] KVM: x86: Disable APIC logical map if logical ID covers multiple MDAs From: Maxim Levitsky To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Suravee Suthikulpanit , Li RongQing Date: Wed, 31 Aug 2022 16:23:32 +0300 In-Reply-To: <20220831003506.4117148-13-seanjc@google.com> References: <20220831003506.4117148-1-seanjc@google.com> <20220831003506.4117148-13-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 2.78 on 10.11.54.3 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, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 On Wed, 2022-08-31 at 00:34 +0000, Sean Christopherson wrote: > Disable the optimized APIC logical map if a logical ID covers multiple > MDAs, i.e. if a vCPU has multiple bits set in its ID. In logical mode, > events match if "ID & MDA != 0", i.e. creating an entry for only the > first bit can cause interrupts to be missed. > > Note, creating an entry for every bit is also wrong as KVM would generate > IPIs for every matching bit. It would be possible to teach KVM to play > nice with this edge case, but it is very much an edge case and probably > not used in any real world OS, i.e. it's not worth optimizing. > > Use an impossible value for the "mode" to effectively designate that it's > disabled. Don't bother adding a dedicated "invalid" value, the mode > handling will be cleaned up in the future and it would take just as much > effort to explain what value is "safe" at this time. > > Fixes: 1e08ec4a130e ("KVM: optimize apic interrupt delivery") > Signed-off-by: Sean Christopherson > --- > arch/x86/kvm/lapic.c | 11 +++++++++-- > 1 file changed, 9 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c > index 9dda989a1cf0..82278acae95b 100644 > --- a/arch/x86/kvm/lapic.c > +++ b/arch/x86/kvm/lapic.c > @@ -300,8 +300,15 @@ void kvm_recalculate_apic_map(struct kvm *kvm) > if (!kvm_apic_map_get_logical_dest(new, ldr, &cluster, &mask)) > continue; > > - if (mask) > - cluster[ffs(mask) - 1] = apic; > + if (!mask) > + continue; > + > + if (!is_power_of_2(mask)) { > + new->mode = KVM_APIC_MODE_XAPIC_FLAT | > + KVM_APIC_MODE_XAPIC_CLUSTER; > + continue; > + } > + cluster[ffs(mask) - 1] = apic; > } > out: > old = rcu_dereference_protected(kvm->arch.apic_map, I was about to complain about the abuse of the invalid mode, but I see that this is fixed in later patch as it is said in the commit description, so no complains. Reviewed-by: Maxim Levitsky Best regards, Maxim Levitsky