From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id AE93574004A for ; Tue, 17 Oct 2023 11:42:21 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=W3hAhHLwwhjlbCD5wwT5LltsfAZo0hssIRzYd/Z1hUA=; c=relaxed/simple; d=groups.io; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From:In-Reply-To:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type:Content-Transfer-Encoding; s=20140610; t=1697542940; v=1; b=wnnkXx/UehU3kDW6Ldym8dmAZXtoeWTNazP8g6ZsGacbfijdH9Kdq4e0e5UF0u+K5nldaXWr HnZYsieLTdPJR+tjHPhNV46D25rR/ZtfGRxobQ/gZjMKdViZppX0n/ZgyjnRHGrwPxTFSnakXce mjjZvUd33hFZYlOZ4ppRWUyo= X-Received: by 127.0.0.2 with SMTP id ChdzYY7687511x8ZTcneeW7N; Tue, 17 Oct 2023 04:42:20 -0700 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.groups.io with SMTP id smtpd.web11.210801.1697542939735285553 for ; Tue, 17 Oct 2023 04:42:19 -0700 X-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-357-R_dJaDNPPoau_XMONJOY-Q-1; Tue, 17 Oct 2023 07:42:12 -0400 X-MC-Unique: R_dJaDNPPoau_XMONJOY-Q-1 X-Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A328285A5BE; Tue, 17 Oct 2023 11:42:11 +0000 (UTC) X-Received: from [10.39.193.132] (unknown [10.39.193.132]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 92C032027045; Tue, 17 Oct 2023 11:42:10 +0000 (UTC) Message-ID: <40508466-1387-51f7-d421-a25b778011b3@redhat.com> Date: Tue, 17 Oct 2023 13:42:09 +0200 MIME-Version: 1.0 Subject: Re: [edk2-devel] [PATCH v2 1/1] UefiCpuPkg/BaseXApicX2ApicLib: fix CPUID_V2_EXTENDED_TOPOLOGY detection To: Gerd Hoffmann , devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Oliver Steffen , Rahul Kumar References: <20231017112807.1244254-1-kraxel@redhat.com> From: "Laszlo Ersek" In-Reply-To: <20231017112807.1244254-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: m7U5Ds9i4L6sbzem5A1FXCEgx7686176AA= Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b="wnnkXx/U"; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=redhat.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io On 10/17/23 13:28, Gerd Hoffmann wrote: > Checking the max cpuid leaf is not enough to figure whenever > CPUID_V2_EXTENDED_TOPOLOGY is supported. Intel SDM says: >=20 > Software must detect the presence of CPUID leaf 1FH by verifying > (a) the highest leaf index supported by CPUID is >=3D 1FH, and > (b) CPUID.1FH:EBX[15:0] reports a non-zero value. >=20 > The same is true for CPUID leaf 0BH. >=20 > This patch adds the EBX check to GetProcessorLocation2ByApicId(). The > patch also fixes the existing check in GetProcessorLocationByApicId() to > be in line with the spec by looking at bits 15:0. The comments are > updated with a quote from the Intel SDM. >=20 > Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=3D2241388 > Signed-off-by: Gerd Hoffmann > --- > .../BaseXApicX2ApicLib/BaseXApicX2ApicLib.c | 21 ++++++++++++++----- > 1 file changed, 16 insertions(+), 5 deletions(-) >=20 > diff --git a/UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c b= /UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c > index aa4eb11181f6..c0a847583330 100644 > --- a/UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c > +++ b/UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c > @@ -1294,11 +1294,12 @@ GetProcessorLocationByApicId ( > NULL > ); > // > - // If CPUID.(EAX=3D0BH, ECX=3D0H):EBX returns zero and maximum input= value for > - // basic CPUID information is greater than 0BH, then CPUID.0BH leaf = is not > - // supported on that processor. > + // Quoting Intel SDM: > + // Software must detect the presence of CPUID leaf 0BH by > + // verifying (a) the highest leaf index supported by CPUID is >=3D > + // 0BH, and (b) CPUID.0BH:EBX[15:0] reports a non-zero value. > // > - if (ExtendedTopologyEbx.Uint32 !=3D 0) { > + if (ExtendedTopologyEbx.Bits.LogicalProcessors !=3D 0) { > TopologyLeafSupported =3D TRUE; > =20 > // > @@ -1424,6 +1425,7 @@ GetProcessorLocation2ByApicId ( > ) > { > CPUID_EXTENDED_TOPOLOGY_EAX ExtendedTopologyEax; > + CPUID_EXTENDED_TOPOLOGY_EBX ExtendedTopologyEbx; > CPUID_EXTENDED_TOPOLOGY_ECX ExtendedTopologyEcx; > UINT32 MaxStandardCpuIdIndex; > UINT32 Index; > @@ -1436,10 +1438,19 @@ GetProcessorLocation2ByApicId ( > } > =20 > // > - // Get max index of CPUID > + // Quoting Intel SDM: > + // Software must detect the presence of CPUID leaf 1FH by verifying > + // (a) the highest leaf index supported by CPUID is >=3D 1FH, and (b) > + // CPUID.1FH:EBX[15:0] reports a non-zero value. > // > AsmCpuid (CPUID_SIGNATURE, &MaxStandardCpuIdIndex, NULL, NULL, NULL); > if (MaxStandardCpuIdIndex < CPUID_V2_EXTENDED_TOPOLOGY) { > + ExtendedTopologyEbx.Bits.LogicalProcessors =3D 0; > + } else { > + AsmCpuidEx (CPUID_V2_EXTENDED_TOPOLOGY, 0, NULL, &ExtendedTopologyEb= x.Uint32, NULL, NULL); > + } > + > + if (ExtendedTopologyEbx.Bits.LogicalProcessors =3D=3D 0) { > if (Die !=3D NULL) { > *Die =3D 0; > } Reviewed-by: Laszlo Ersek Thanks! Laszlo -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#109674): https://edk2.groups.io/g/devel/message/109674 Mute This Topic: https://groups.io/mt/102015439/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/19134562= 12/xyzzy [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-