Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1689981rwb; Thu, 8 Dec 2022 14:04:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf7KrN9E4guHiN48saAKQnnU+ViVMLPx0eRTyr9GudkZJQ7y7qurWNnzxZyXEfNATDxxkafB X-Received: by 2002:a63:d256:0:b0:478:46b4:4f91 with SMTP id t22-20020a63d256000000b0047846b44f91mr38325631pgi.211.1670537075676; Thu, 08 Dec 2022 14:04:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670537075; cv=none; d=google.com; s=arc-20160816; b=PIVvBHqgrPXNdCJKxH6X3XViOaCCTbqd60vOPrCCDh9Kum/vNxuE/6GT9l7hMr5Z+h WgthE7/jDDFZrRvRn6BbvHTCgrAa+XqsIwJc/TpezN31Os/ZNxFbbpIfCaFqAfmgoBIs eSnO4PWrMbcn+84rUGb3i54C+HhR49wkkotqiP9c6/6DIzdjpzauis13BHwJHUddyJ6y Tj9bE5a5wM/lAnRCEM71Qt+V2dqORjH+GTeRmy1t+Ygd0l/P/FJaReWievDagW9vUpwi x55NdXb8xAhROenE8LJSa9IGgf6+H+b9EeXQZaAAcKFcr2LAK6E0O1wf1gQMb2Pf1FkG HuRQ== 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=ClogqEAHVhvU0Z+VDfOovmr4TOAyX8ejUw7oYGiECZg=; b=W8Qh0MaxPVvolpRSuqC2hwrfyGEAI41cIym69wb2cSpKVHyE7F2YVaTaZu5ctvQmg7 X0KR3pLCuq8QadnzBvhPQnaKsR5KOcgHXup1lFLRVxqSIjkaloqjzG1ByLNvy8xQX5Zb 7Gatt/NHoB6f8M6hcMj5sN/k6ZMHCr9ZY2ExICQGnSl77Yf38MVLXkLR93LPRKlV2NLy cYW+nT4L5UTLMcRZ28xczT+u32ls5baNpKfTeIbPx8Rx92NcXSdVKzhCVXATdc0Ov4j0 VRx6EkIJSAzio6ZSieXSqOTm4iH9R2nCxXS8DEh7d9vEig6R7YjKLjQXsJYI/PpyrdlC OWuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CfnpNv3Y; 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 j7-20020a170903024700b001898d8881d1si22166818plh.598.2022.12.08.14.04.25; Thu, 08 Dec 2022 14:04:35 -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=CfnpNv3Y; 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 S229568AbiLHVyr (ORCPT + 74 others); Thu, 8 Dec 2022 16:54:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229973AbiLHVyg (ORCPT ); Thu, 8 Dec 2022 16:54:36 -0500 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 B801E9492A for ; Thu, 8 Dec 2022 13:53:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670536421; 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=ClogqEAHVhvU0Z+VDfOovmr4TOAyX8ejUw7oYGiECZg=; b=CfnpNv3Y4PIzntwleCHbiZzy3bYbamWCTZPbf0ITFWEadRuoGGvDW/2ya1Tj7IMC6p8qFu f8nuebCK7UqN8hjbefhjZQ0kWbUKbvrmZjKvfvNI5WwAUCI1fXVN72ZdKZYSU59zUptk+u INLCRu+zdCYprmvHm9e02wLVjWfN1qQ= 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-651-SgQoKJ-9NyGKVRrCcNwxEw-1; Thu, 08 Dec 2022 16:53:38 -0500 X-MC-Unique: SgQoKJ-9NyGKVRrCcNwxEw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0A4E086C042; Thu, 8 Dec 2022 21:53:38 +0000 (UTC) Received: from starship (unknown [10.35.206.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9953840C6EC3; Thu, 8 Dec 2022 21:53:36 +0000 (UTC) Message-ID: <17812867e411fbe47b23a942784a9f6cbf251845.camel@redhat.com> Subject: Re: [PATCH v4 07/32] KVM: x86: Don't inhibit APICv/AVIC if xAPIC ID mismatch is due to 32-bit ID 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:53:35 +0200 In-Reply-To: <20221001005915.2041642-8-seanjc@google.com> References: <20221001005915.2041642-1-seanjc@google.com> <20221001005915.2041642-8-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.2 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: > Truncate the vcpu_id, a.k.a. x2APIC ID, to an 8-bit value when comparing > it against the xAPIC ID to avoid false positives (sort of) on systems > with >255 CPUs, i.e. with IDs that don't fit into a u8. The intent of > APIC_ID_MODIFIED is to inhibit APICv/AVIC when the xAPIC is changed from > it's original value, > > The mismatch isn't technically a false positive, as architecturally the > xAPIC IDs do end up being aliased in this scenario, and neither APICv > nor AVIC correctly handles IPI virtualization when there is aliasing. > However, KVM already deliberately does not honor the aliasing behavior > that results when an x2APIC ID gets truncated to an xAPIC ID. I.e. the > resulting APICv/AVIC behavior is aligned with KVM's existing behavior > when KVM's x2APIC hotplug hack is effectively enabled. > > If/when KVM provides a way to disable the hotplug hack, APICv/AVIC can > piggyback whatever logic disables the optimized APIC map (which is what > provides the hotplug hack), i.e. so that KVM's optimized map and APIC > virtualization yield the same behavior. > > For now, fix the immediate problem of APIC virtualization being disabled > for large VMs, which is a much more pressing issue than ensuring KVM > honors architectural behavior for APIC ID aliasing. > > Fixes: 3743c2f02517 ("KVM: x86: inhibit APICv/AVIC on changes to APIC ID or APIC base") > Reported-by: Suravee Suthikulpanit > Cc: Maxim Levitsky > Cc: stable@vger.kernel.org > Signed-off-by: Sean Christopherson > --- > arch/x86/kvm/lapic.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c > index 251856ba0750..2503f162eb95 100644 > --- a/arch/x86/kvm/lapic.c > +++ b/arch/x86/kvm/lapic.c > @@ -2078,7 +2078,12 @@ static void kvm_lapic_xapic_id_updated(struct kvm_lapic *apic) > if (KVM_BUG_ON(apic_x2apic_mode(apic), kvm)) > return; > > - if (kvm_xapic_id(apic) == apic->vcpu->vcpu_id) > + /* > + * Deliberately truncate the vCPU ID when detecting a modified APIC ID > + * to avoid false positives if the vCPU ID, i.e. x2APIC ID, is a 32-bit > + * value. > + */ > + if (kvm_xapic_id(apic) == (u8)apic->vcpu->vcpu_id) > return; > > kvm_set_apicv_inhibit(apic->vcpu->kvm, APICV_INHIBIT_REASON_APIC_ID_MODIFIED); Reviewed-by: Maxim Levitsky Best regards, Maxim Levitsky