From nobody Mon Feb 9 16:18:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+111257+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+111257+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700046961; cv=none; d=zohomail.com; s=zohoarc; b=cd4SNfCBg9OEeZGMjGj1ZMz0ZMTluqasvtDxRc6a8ky7Heu+OKJgewtiIxsXRYa6VHrW4gS1JtWTJJcd6Nh96EbBs5kgYKKAeX0CXhqvgln8aZxTNpNe443l6uZsSFY1w2GLgYVGYV9cMah0iWojDeSfxeeZhesNjb1/YmwE2P4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700046961; h=Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=KVeFspvakPXNNSb2HpqRW3SjH9ScrAA7lyjV3ZIbH7I=; b=TzUL805EOe54i4XYVvM4sknRXRMZogUhc2Bz/jIRM1034GCc1orHtLFlmjunBM67DHzqQEAGLwf7stmEZu1C6dS/jqyimOt0yhHzUc9QzfoRq1bbD7+So/WmNROCJ0Dd83THo/MmiJioxfi6Tjdb8CDkAfgeI2NZvPUdoGUM3KI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+111257+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1700046961531656.898488075413; Wed, 15 Nov 2023 03:16:01 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=nbndrrZs86RSkWawWNCrhWWYulcc6UUAZAdTX7Twnwo=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe; s=20140610; t=1700046961; v=1; b=ihBp2Ppwr1ztt+Fss/c+oMHEAAySV/V/Vm6FRu1bvYw+1mIapCJooCEBKy0z/M7S3oqeXnQQ uf+m4R3EBZIDYQZA+tIHU7shSX4Yrf8XIU3xT1jeAD18TzilskUjZaU2uiJnZ5Q+GTXYF+tL48o zZHEW3p8IlggExU2Lv0Baov8= X-Received: by 127.0.0.2 with SMTP id fdtqYY1788612xda2to2mY8Z; Wed, 15 Nov 2023 03:16:01 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web11.10782.1700046959669687038 for ; Wed, 15 Nov 2023 03:16:00 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10894"; a="455148438" X-IronPort-AV: E=Sophos;i="6.03,304,1694761200"; d="scan'208";a="455148438" X-Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Nov 2023 03:16:00 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10894"; a="1096420851" X-IronPort-AV: E=Sophos;i="6.03,304,1694761200"; d="scan'208";a="1096420851" X-Received: from sh1gapp1009.ccr.corp.intel.com ([10.239.189.219]) by fmsmga005.fm.intel.com with ESMTP; 15 Nov 2023 03:15:58 -0800 From: "Wu, Jiaxin" To: devel@edk2.groups.io Cc: Laszlo Ersek , Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann , Star Zeng Subject: [edk2-devel] [PATCH v2 1/3] UefiCpuPkg/BaseXApicLib: Fix CPUID_V2_EXTENDED_TOPOLOGY detection Date: Wed, 15 Nov 2023 19:15:51 +0800 Message-Id: <20231115111553.6592-2-jiaxin.wu@intel.com> In-Reply-To: <20231115111553.6592-1-jiaxin.wu@intel.com> References: <20231115111553.6592-1-jiaxin.wu@intel.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,jiaxin.wu@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: eycGaRUCM2pTlYTi5KNkq4vpx1787277AA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1700046963368100008 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch is to complete 170d4ce8, sync the change to BaseXApicLib. Checking the max cpuid leaf is not enough to figure whenever CPUID_V2_EXTENDED_TOPOLOGY is supported. Intel SDM says: 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. The same is true for CPUID leaf 0BH. 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. 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 Reviewed-by: Laszlo Ersek Reviewed-by: Ray Ni --- UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.c b/UefiCpuPkg/Li= brary/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 v= alue 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 paramet= ers 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_TYPE_= 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, &ExtendedTopologyEbx.= Uint32, NULL, NULL); + } + + if (ExtendedTopologyEbx.Bits.LogicalProcessors =3D=3D 0) { if (Die !=3D NULL) { *Die =3D 0; } =20 if (Tile !=3D NULL) { --=20 2.16.2.windows.1 -=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 (#111257): https://edk2.groups.io/g/devel/message/111257 Mute This Topic: https://groups.io/mt/102602851/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-