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 08AA07803CC for ; Tue, 17 Oct 2023 11:28:15 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=eE4bJgGgBFrUozq4oWgF/8PYT8vdt0pdIqAhtBvvsoE=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20140610; t=1697542094; v=1; b=CFvKMCmB2tg7l2/+w+/qfe63xRGSr838A7zvFLzd2R3Nmqasfb+UykpdPEdNhYSu9F/TP7DU NZuVi4UTMceWo07shwq1Tky1k/avTHk1Fcz3kFMxtRQF+7o6nQTahxB3gggmJfEGrbNKMKK8uHQ HSsaEdVaA4tBAyIXhxWxZ/ss= X-Received: by 127.0.0.2 with SMTP id 4Qt1YY7687511xZgxymIaBg8; Tue, 17 Oct 2023 04:28:14 -0700 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.web10.210890.1697542094090241218 for ; Tue, 17 Oct 2023 04:28:14 -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-612-OUdnukTiNk-Asf-b1_JoGQ-1; Tue, 17 Oct 2023 07:28:10 -0400 X-MC-Unique: OUdnukTiNk-Asf-b1_JoGQ-1 X-Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (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 C8E4B185A79B; Tue, 17 Oct 2023 11:28:09 +0000 (UTC) X-Received: from sirius.home.kraxel.org (unknown [10.39.193.174]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7DD51492BFA; Tue, 17 Oct 2023 11:28:09 +0000 (UTC) X-Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id D3DBC1800DFD; Tue, 17 Oct 2023 13:28:07 +0200 (CEST) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Oliver Steffen , Rahul Kumar , =?UTF-8?q?L=C3=A1szl=C3=B3=20=C3=89rsek?= , Gerd Hoffmann Subject: [edk2-devel] [PATCH v2 1/1] UefiCpuPkg/BaseXApicX2ApicLib: fix CPUID_V2_EXTENDED_TOPOLOGY detection Date: Tue, 17 Oct 2023 13:28:07 +0200 Message-ID: <20231017112807.1244254-1-kraxel@redhat.com> MIME-Version: 1.0 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,kraxel@redhat.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: Y2b1WWRXTnKHHWWw0yaif7Zfx7686176AA= Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=CFvKMCmB; 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 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 >= 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. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2241388 Signed-off-by: Gerd Hoffmann --- .../BaseXApicX2ApicLib/BaseXApicX2ApicLib.c | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) 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=0BH, ECX=0H):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 >= + // 0BH, and (b) CPUID.0BH:EBX[15:0] reports a non-zero value. // - if (ExtendedTopologyEbx.Uint32 != 0) { + if (ExtendedTopologyEbx.Bits.LogicalProcessors != 0) { TopologyLeafSupported = TRUE; // @@ -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 ( } // - // 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 >= 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 = 0; + } else { + AsmCpuidEx (CPUID_V2_EXTENDED_TOPOLOGY, 0, NULL, &ExtendedTopologyEbx.Uint32, NULL, NULL); + } + + if (ExtendedTopologyEbx.Bits.LogicalProcessors == 0) { if (Die != NULL) { *Die = 0; } -- 2.41.0 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#109672): https://edk2.groups.io/g/devel/message/109672 Mute This Topic: https://groups.io/mt/102015439/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-