Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp813850rwe; Wed, 31 Aug 2022 11:27:26 -0700 (PDT) X-Google-Smtp-Source: AA6agR6H8MF9SEy6lfomgIds/Bkz9FRWoWsUrQuUdQCgI99JS8JbTB42jwslcQ9TBtrwX6d3AjPt X-Received: by 2002:a05:6402:d69:b0:448:4c7a:cb6a with SMTP id ec41-20020a0564020d6900b004484c7acb6amr15595656edb.18.1661970445977; Wed, 31 Aug 2022 11:27:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661970445; cv=none; d=google.com; s=arc-20160816; b=1H5mbuogB37CjsODKoVazeBeuNJ72UVtibOSzEz7ATDirn6Gat0CwYYZ24MFNREGSl Hwc+yAkLyweAe0cM168qYPxMBT8NJnHnXVQU7ItHyJMxujNPrr1PV6AKxnnOmL//uYRQ Li+tgHlpR6cq+4ClLszBYTJ3aP2dRhiZT+c58K8aUyP9m4vBIgv8TSNttQbKXAit9m0U HLl27w5mrDMbUtWSVp8hdEXkCJ0FgU05gp1+aLRcJKzFfi3NVQbXcCewqamPc0I91Y5U yIyeLX3MdCXiVw+Bv+qbwCyB8GXUQ6UMIoDg2fTPVyIPf0z9c2WkU0NLy9dF1ORpNhC0 DEmg== 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=abvYViIvguPONv8Ppgd4Bbm0PP4cfU0m1JZK9rzmMe4=; b=Df6TQqsPuwuOWxwX5EYPdrsGccQaJul2BidrGaRdNEDP54rKnjhxnVp8+DwV0RFvxA +5guBl1uZWGj+S55e6uqO/RrN/5YIvM8TXV14GOf1d99dNMP5CEwJPrRg7W/+tPr6lat eFdMozCXrqr+juAx95EbHuV72jIoEgHYcPNwJEFm7DtRFZvMhEKtQ7JIHYvGnwKuBLbD qOs/UqeEtZatjk7idn2t8E5oZr5Qh61DdvWe0HXK/AkNqukdGx1m1BIYq3GozXCCoyho MrpFN7ZbpBwv5E+Oc86YOiUreEZqK592kKUbuVo2EbjuEtWo/vH3M5aI3Ca58izs5Y1d +4tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KyjnEs2Q; 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 d13-20020a170906640d00b007311b45e4bcsi4272052ejm.692.2022.08.31.11.26.59; Wed, 31 Aug 2022 11:27:25 -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=KyjnEs2Q; 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 S230455AbiHaRvc (ORCPT + 99 others); Wed, 31 Aug 2022 13:51:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232007AbiHaRvS (ORCPT ); Wed, 31 Aug 2022 13:51:18 -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 7ABB74A803 for ; Wed, 31 Aug 2022 10:51:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661968276; 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=abvYViIvguPONv8Ppgd4Bbm0PP4cfU0m1JZK9rzmMe4=; b=KyjnEs2QJzowb1aSJDPMsCY1pfLUpovaXoU2ZlNAfvCdroPrYa/I1gQZ9M/c8iBqBnVCfB Po/chVPEDvRYTe8m/hJYw71Xsda2IP1G7PAKPJO6p2WH4Dpkf79EtM+Ns8/+JsOV1CxooI RMmh+ko2+/o0aYXFfzOeJJplTXOyCHw= 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-9-ycFemNoFM7OjuzlH2u3S7A-1; Wed, 31 Aug 2022 13:51:13 -0400 X-MC-Unique: ycFemNoFM7OjuzlH2u3S7A-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A2299800124; Wed, 31 Aug 2022 17:51:12 +0000 (UTC) Received: from starship (unknown [10.40.194.96]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0A6A7492C3B; Wed, 31 Aug 2022 17:51:10 +0000 (UTC) Message-ID: <81ba71741c4098591f77de4275e2df4b558b19c0.camel@redhat.com> Subject: Re: [PATCH 14/19] KVM: x86: Honor architectural behavior for aliased 8-bit APIC IDs From: Maxim Levitsky To: Sean Christopherson Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Suravee Suthikulpanit , Li RongQing Date: Wed, 31 Aug 2022 20:51:04 +0300 In-Reply-To: References: <20220831003506.4117148-1-seanjc@google.com> <20220831003506.4117148-15-seanjc@google.com> <5f6d99bc28fde0c48907991b6f67009430aea243.camel@redhat.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.85 on 10.11.54.10 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 16:41 +0000, Sean Christopherson wrote: > On Wed, Aug 31, 2022, Maxim Levitsky wrote: > > On Wed, 2022-08-31 at 00:35 +0000, Sean Christopherson wrote: > > > - if (!apic_x2apic_mode(apic) && !new->phys_map[xapic_id]) > > > - new->phys_map[xapic_id] = apic; > > > + if (kvm->arch.x2apic_format) { > > > + /* See also kvm_apic_match_physical_addr(). */ > > > + if ((apic_x2apic_mode(apic) || x2apic_id > 0xff) && > > > + x2apic_id <= new->max_apic_id) > > > + new->phys_map[x2apic_id] = apic; > > > + > > > + if (!apic_x2apic_mode(apic) && !new->phys_map[xapic_id]) > > > + new->phys_map[xapic_id] = apic; > > > + } else { > > > + /* > > > + * Disable the optimized map if the physical APIC ID is > > > + * already mapped, i.e. is aliased to multiple vCPUs. > > > + * The optimized map requires a strict 1:1 mapping > > > + * between IDs and vCPUs. > > > + */ > > > + if (apic_x2apic_mode(apic)) > > > + physical_id = x2apic_id; > > > + else > > > + physical_id = xapic_id; > > > + > > > + if (new->phys_map[physical_id]) { > > > + kvfree(new); > > > + new = NULL; > > > + goto out; > > Why not to use the same KVM_APIC_MODE_XAPIC_FLAT | KVM_APIC_MODE_XAPIC_CLUSTER > > hack here? > > The map's "mode" only covers logical mode (the cleanup patch renames "mode" to > "logical_mode" to make this more clear). There is no equivalent for dealing with > the physical IDs. Alternatively, a flag to say "physical map is disabled" could > be added, but KVM already has to cleanly handle a NULL map and in all likelihood > the logical map is also going to be disabled anyways. > > Not to mention that APIC performance is unlikely to be a priority for any guest > that triggers this code :-) > Thanks for the explanation, that makes sense! Best regards, Maxim Levitsky