From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 42B3B81E8C for ; Tue, 22 Nov 2016 21:10:24 -0800 (PST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga102.jf.intel.com with ESMTP; 22 Nov 2016 21:10:23 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,684,1473145200"; d="scan'208";a="789767686" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by FMSMGA003.fm.intel.com with ESMTP; 22 Nov 2016 21:10:23 -0800 Received: from fmsmsx123.amr.corp.intel.com (10.18.125.38) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.248.2; Tue, 22 Nov 2016 21:10:23 -0800 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by fmsmsx123.amr.corp.intel.com (10.18.125.38) with Microsoft SMTP Server (TLS) id 14.3.248.2; Tue, 22 Nov 2016 21:10:23 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.239]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.138]) with mapi id 14.03.0248.002; Wed, 23 Nov 2016 13:10:21 +0800 From: "Fan, Jeff" To: Laszlo Ersek , edk2-devel-01 Thread-Topic: [edk2] [PATCH 2/4] UefiCpuPkg/MpInitLib: fix feature test for Extended Topology CPUID leaf Thread-Index: AQHSRP675R9hkzDuoUCp3xZ5t9Scx6DmBcVw Date: Wed, 23 Nov 2016 05:10:20 +0000 Message-ID: <542CF652F8836A4AB8DBFAAD40ED192A4A2E56C7@shsmsx102.ccr.corp.intel.com> References: <20161122202619.12594-1-lersek@redhat.com> <20161122202619.12594-3-lersek@redhat.com> In-Reply-To: <20161122202619.12594-3-lersek@redhat.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNTlmMmZiNjQtOGIyMy00ZWI3LWJkOWItYTNmMjFmMWRmZWFhIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE1LjkuNi42IiwiVHJ1c3RlZExhYmVsSGFzaCI6Iktxa29zK2I4WHNueGQ4S25Kc1ozVFpweUZcL3VyREFGQUcrT3QrandcL3I0RT0ifQ== x-ctpclassification: CTP_IC x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH 2/4] UefiCpuPkg/MpInitLib: fix feature test for Extended Topology CPUID leaf X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Nov 2016 05:10:24 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Jeff Fan -----Original Message----- From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Lasz= lo Ersek Sent: Wednesday, November 23, 2016 4:26 AM To: edk2-devel-01 Cc: Fan, Jeff Subject: [edk2] [PATCH 2/4] UefiCpuPkg/MpInitLib: fix feature test for Exte= nded Topology CPUID leaf According to the Intel SDM (325462-060US / September 2016), > INPUT EAX =3D 0BH: Returns Extended Topology Information > > [...] 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. [...] The "GetApicId" sections in the Ia32 and X64 "MpFuncs.nasm" files do not pe= rform check (b). This causes an actual bug in the following OVMF setup: - Intel W3550 host processor , - the QEMU/KVM guest's VCPU model is set to "host", that is, "the CPU visible to the guest should be exactly the same as the host CPU". Under "GetApicId", check (a) passes: the CPUID level of the W3550 is exactl= y 11 decimal. However, leaf 11 itself is not supported, therefore EDX is se= t to zero: > If a value entered for CPUID.EAX is less than or equal to the maximum=20 > input value and the leaf is not supported on that processor then 0 is=20 > returned in all the registers. Because we don't check (b), the "GetProcessorNumber" section of the code is= reached with an initial APIC ID of 0 in EDX on all of the APs. Given that = "GetProcessorNumber" searches the "MP_CPU_EXCHANGE_INFO.CpuInfo[*].InitialA= picId" fields for a match, all APs enter ApWakeupFunction() with an identic= al "NumApsExecuting" parameter. This results in unpredictable guest behavior (crashes, reboots, = hangs etc). Reorganize the "GetApicId" section and add the missing check in both assemb= ly files. Cc: Jeff Fan Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek --- UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm | 21 +++++++++++--------- = UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm | 21 +++++++++++--------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm b/UefiCpuPkg/Li= brary/MpInitLib/Ia32/MpFuncs.nasm index 64e51d87ae24..9067f7807098 100644 --- a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm +++ b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm @@ -154,21 +154,24 @@ GetApicId: mov eax, 0 cpuid cmp eax, 0bh - jnb X2Apic + jb NoX2Apic ; CPUID level below CPUID_EXTENDED_TOP= OLOGY + + mov eax, 0bh + xor ecx, ecx + cpuid + test ebx, 0ffffh + jz NoX2Apic ; CPUID.0BH:EBX[15:0] is zero + + ; Processor is x2APIC capable; 32-bit x2APIC ID is already in EDX + jmp GetProcessorNumber + +NoX2Apic: ; Processor is not x2APIC capable, so get 8-bit APIC ID mov eax, 1 cpuid shr ebx, 24 mov edx, ebx - jmp GetProcessorNumber =20 -X2Apic: - ; Processor is x2APIC capable, so get 32-bit x2APIC ID - mov eax, 0bh - xor ecx, ecx - cpuid =20 - ; edx save x2APIC ID - =20 GetProcessorNumber: ; ; Get processor number for this AP diff --git a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm b/UefiCpuPkg/Lib= rary/MpInitLib/X64/MpFuncs.nasm index aaabb50c5468..e7e7d8086dd0 100644 --- a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm +++ b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm @@ -158,21 +158,24 @@ GetApicId: mov eax, 0 cpuid cmp eax, 0bh - jnb X2Apic + jb NoX2Apic ; CPUID level below CPUID_EXTENDED_TOP= OLOGY + + mov eax, 0bh + xor ecx, ecx + cpuid + test ebx, 0ffffh + jz NoX2Apic ; CPUID.0BH:EBX[15:0] is zero + + ; Processor is x2APIC capable; 32-bit x2APIC ID is already in EDX + jmp GetProcessorNumber + +NoX2Apic: ; Processor is not x2APIC capable, so get 8-bit APIC ID mov eax, 1 cpuid shr ebx, 24 mov edx, ebx - jmp GetProcessorNumber =20 -X2Apic: - ; Processor is x2APIC capable, so get 32-bit x2APIC ID - mov eax, 0bh - xor ecx, ecx - cpuid =20 - ; edx save x2APIC ID - =20 GetProcessorNumber: ; ; Get processor number for this AP -- 2.9.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel