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 DEB37D8114F for ; Wed, 15 Nov 2023 14:45:03 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=lnz6E6v2J/PWU6VVcDLY5HCCTyBLr8nsTvymltc6MkA=; 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=1700059502; v=1; b=JuNaktVr3GOiSSAUQajfE8UxDz03TXtmYMAEGDSV7eDClIwwf6SwflxWzI6ZIyzwQn4k+nTN s0MU326/SHihBR4HtmQVwKfCPOrx6IzSyz/UrqWfOA+FXAsdw+DPsp1TOy9dzoqOYeamx8e33ut 31G00WPlEEZySUPrz/8mVhPU= X-Received: by 127.0.0.2 with SMTP id wv3bYY7687511xhWciwDhdQS; Wed, 15 Nov 2023 06:45:02 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web11.14865.1700059501717000051 for ; Wed, 15 Nov 2023 06:45:01 -0800 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.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-638-KQO-DIW_PdW9LHi4k6IdZw-1; Wed, 15 Nov 2023 09:44:56 -0500 X-MC-Unique: KQO-DIW_PdW9LHi4k6IdZw-1 X-Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 39AE481D8A1; Wed, 15 Nov 2023 14:44:56 +0000 (UTC) X-Received: from [10.39.192.211] (unknown [10.39.192.211]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1322A492BFD; Wed, 15 Nov 2023 14:44:54 +0000 (UTC) Message-ID: <23d2fc10-6731-6aab-a2c1-83944091eeb9@redhat.com> Date: Wed, 15 Nov 2023 15:44:53 +0100 MIME-Version: 1.0 Subject: Re: [edk2-devel] [PATCH v2 1/3] UefiCpuPkg/BaseXApicLib: Fix CPUID_V2_EXTENDED_TOPOLOGY detection To: Jiaxin Wu , devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann , Star Zeng References: <20231115111553.6592-1-jiaxin.wu@intel.com> <20231115111553.6592-2-jiaxin.wu@intel.com> From: "Laszlo Ersek" In-Reply-To: <20231115111553.6592-2-jiaxin.wu@intel.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 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: cDjpMarTwzDUlsNpDfGVeHXYx7686176AA= 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=JuNaktVr; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=redhat.com (policy=none) On 11/15/23 12:15, Jiaxin Wu wrote: > This patch is to complete 170d4ce8, sync the change to BaseXApicLib. >=20 > 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 > Cc: Laszlo Ersek > Cc: Eric Dong > Cc: Ray Ni > Cc: Rahul Kumar > Cc: Gerd Hoffmann > Cc: Star Zeng > Signed-off-by: Gerd Hoffmann > Signed-off-by: Jiaxin Wu > --- > UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.c | 21 ++++++++++++++++----= - > 1 file changed, 16 insertions(+), 5 deletions(-) >=20 > diff --git a/UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.c b/UefiCpuPkg/= Library/BaseXApicLib/BaseXApicLib.c > index d56c6275cc..efb9d71ca1 100644 > --- a/UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.c > +++ b/UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.c > @@ -1053,15 +1053,16 @@ GetProcessorLocationByApicId ( > &ExtendedTopologyEbx.Uint32, > &ExtendedTopologyEcx.Uint32, > 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 > // > // Sub-leaf index 0 (ECX=3D 0 as input) provides enumeration param= eters to extract > // the SMT sub-field of x2APIC ID. > @@ -1183,10 +1184,11 @@ GetProcessorLocation2ByApicId ( > OUT UINT32 *Core OPTIONAL, > OUT UINT32 *Thread OPTIONAL > ) > { > CPUID_EXTENDED_TOPOLOGY_EAX ExtendedTopologyEax; > + CPUID_EXTENDED_TOPOLOGY_EBX ExtendedTopologyEbx; > CPUID_EXTENDED_TOPOLOGY_ECX ExtendedTopologyEcx; > UINT32 MaxStandardCpuIdIndex; > UINT32 Index; > UINTN LevelType; > UINT32 Bits[CPUID_V2_EXTENDED_TOPOLOGY_LEVEL_TYP= E_DIE + 2]; > @@ -1195,14 +1197,23 @@ GetProcessorLocation2ByApicId ( > for (LevelType =3D 0; LevelType < ARRAY_SIZE (Bits); LevelType++) { > Bits[LevelType] =3D 0; > } > =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; > } > =20 > if (Tile !=3D NULL) { This synchronizes the GetProcessorLocationByApicId() and GetProcessorLocation2ByApicId() functions in BaseXApicLib with those in BaseXApicX2ApicLib. Reviewed-by: Laszlo Ersek -=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 (#111278): https://edk2.groups.io/g/devel/message/111278 Mute This Topic: https://groups.io/mt/102602851/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-