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 01552940503 for ; Sat, 20 Jan 2024 00:01:22 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=HavtAEnDgEkkLZWjW3P/8iVS9e03rQSKt8u4XJJ80Z4=; c=relaxed/simple; d=groups.io; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:From:To:CC:Subject:Thread-Topic:Thread-Index:Date:Message-ID:References:In-Reply-To:Accept-Language:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type; s=20140610; t=1705708881; v=1; b=hexwXY+YNHuN1umVw+TBLCloOIdoXW3CUinLG1AQuO6XqPOy//JW2oknwHf76j3yg0pk78m6 5Jf16ocMuOwGx/JFkXLXpdg4cxSbBcaQDRSU3+ULmZ5zPoSVPrjFi6futQhvJg7Fn3y9yGz6HJ6 GxScqFoKiWQTp8kcEmAj8ttU= X-Received: by 127.0.0.2 with SMTP id 12cVYY7687511xeoY4Bt6Rgz; Fri, 19 Jan 2024 16:01:21 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web11.9199.1705708880524728877 for ; Fri, 19 Jan 2024 16:01:20 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10957"; a="391316934" X-IronPort-AV: E=Sophos;i="6.05,206,1701158400"; d="scan'208,217";a="391316934" X-Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jan 2024 15:48:40 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,206,1701158400"; d="scan'208,217";a="691764" X-Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by fmviesa005.fm.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 19 Jan 2024 15:48:39 -0800 X-Received: from fmsmsx603.amr.corp.intel.com (10.18.126.83) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Fri, 19 Jan 2024 15:48:39 -0800 X-Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35 via Frontend Transport; Fri, 19 Jan 2024 15:48:39 -0800 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.168) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Fri, 19 Jan 2024 15:48:38 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hVqtOxBB8LqNmH2eeyh4gRW4ljQTTA5aNdIdDx3FcCJX9vYfFWSgdJh32ZJE2he8hMQpoyb8JKTby9sNunIsmNKrm2lvtXxXIVr4wNN29AxOSWZhC1vYw7fT/krQs4wROU7ps9AeJ29pt1UbBrXt8/3grYJyzwycIS33oS5q3IRWszPDiX3d+UmyTGTvMp04PJnuoA2MbwtwW3pHbQGcpoMdTku3X/DlhqDICr5Xon2qUveY8Zenp+WgOl/KdVh3kktMv5CWJIaeACUpUktg5/Ih/TEGs2hRL/SsCTUU7DnQ6dlgyALneKBeqbq2IR0TGGorT3eu24eSHGqZzqmVSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=AcduvwfXWuAjAAWKZrKCir3rolUMFNwOBYYDZStE/rQ=; b=k68OkuwZP9yzyeQgkh/Mexpf4UV+gAfARI+QcrtBYLixSVlzD8B2dzoBPz6HTDm7XX+g0muaKhpA92bN/8hdgRVLq0ZnHmSYT4jDFttgSpPT6WBzEuwk5w6ltsmkpjNjXOwR439f0kdFPyhrOpcU/ChMovK9kmz5fnFOS6CBKgTvNt5BzBzRLasbUrPLZaTAuvUr3UK2p0zV6OwuU5DglR79joNbrJll+2rRm/3FK7PHMOQDRS/+7o3uH0ujgiMvoEHNY4GnIr3vYwu7tetwjftD2kLNAIeDXzlawUm0d4MHZXVeo7knrdAVEVN/AeFA/uI9AQe28fs8ne7s2BGOcw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none X-Received: from MN6PR11MB8244.namprd11.prod.outlook.com (2603:10b6:208:470::14) by DS0PR11MB8231.namprd11.prod.outlook.com (2603:10b6:8:15c::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.24; Fri, 19 Jan 2024 23:48:31 +0000 X-Received: from MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::3fea:ca2b:2ef7:e3d4]) by MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::3fea:ca2b:2ef7:e3d4%4]) with mapi id 15.20.7202.024; Fri, 19 Jan 2024 23:48:31 +0000 From: "Ni, Ray" To: "Kinney, Michael D" , Tom Lendacky , "devel@edk2.groups.io" , "Gao, Liming" , "Liu, Zhiguang" , "Dong, Eric" , "Kumar, Rahul R" , Gerd Hoffmann , "Ard Biesheuvel" CC: Michael Roth , "Kinney, Michael D" Subject: Re: [edk2-devel] [PATCH 1/2] UefiCpuPkg/MpInitLib: Use AsmCpuidEx() for CPUID_EXTENDED_TOPOLOGY leaf Thread-Topic: [edk2-devel] [PATCH 1/2] UefiCpuPkg/MpInitLib: Use AsmCpuidEx() for CPUID_EXTENDED_TOPOLOGY leaf Thread-Index: AQHaEQc2QQbjTJ6CsU+Ez2kG5PG30rDe9Z3pgAGvawCAALU6sIAA3q0AgAAH3zo= Date: Fri, 19 Jan 2024 23:48:31 +0000 Message-ID: References: <17952A20A9E21541.12603@groups.io> <26becea4-2ad8-4773-ab3d-5ad98ff48759@amd.com> <179BD02AA4207037.22216@groups.io> In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MN6PR11MB8244:EE_|DS0PR11MB8231:EE_ x-ms-office365-filtering-correlation-id: 1e5163f6-560c-44f5-35bc-08dc1949248e x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam-message-info: vMz/KL8+8tTvl2KcVJlpgSQ7zIJsOzuCoEO8iePM7yd15JvSZeDxoiriTye+jHaqqyGYBPuu+zg0TM1+ZMdk+WJTAgkdd6hBF4f7eiPvwhq3669nXqMwFDfOUl0c9L4Yf2mR4Rk6nysoT7qpZ5s37KMFi94709URXyGA9UOUKN7lV1tpffCQaDoWEcjmHSuLDt+yhraZEldUfY5nnXOdtE/+1zZHa4MWyUvyWSnEUc19CU42CvPTiJqmKpFmfzUKllqsnqzoUmYDoXheRYVMNmH2WqJIL5IZYAZDZvZMI/0CPwk3rgYJvvJz2PQ1TjEy4yk1ZfkEVGyDvIVYkh/6IKUyfrS770tM1D0DGD2lGVQMC6ROboFaZqxzKmP7hfhdS/Gh4sqHM1gMvarClkRjkw977BwZZv8PVdFxDrwFINcsTqLedFa6vrMYwEqKYBeHVw6w1F2qAYnekmI621F+Jc5X4PF9UKQmNdivPSJrLCaxcD40eXtJ/TbQoAvQv7JKl+z2fSBc2Qdg546SUxaFfVfdpCvDrQAUymlOPwuNN7odSQ6V01STVNrEYXThCYsDGIi4tKez3lrW3etLFH7kM9oddULaDFtyJe1DNZSCEYuogsxJsnyr/3+n4C/ZQpNKba4GrK8i2yhqoUVonuj6Rg== x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?Jl1o9Y2zEkgbiAW96/XU3pdugiNGCettS4o+TAiNH+nfKHecAuovkGLzozjo?= =?us-ascii?Q?am4Ae6/biDliddMxIzfp3MnluTwNtzjrj2PSbWHhkIenLpVd5VNKejSDmyt2?= =?us-ascii?Q?MqvmuYgsf7k0vzDRs0bUxAOwsJHzuIHUbRhq9j32qlIA5w8a8+naOHpB7Vzu?= =?us-ascii?Q?mpo+Q76LPEEC4J52hyqAS28DUFicxLXTRU1Tr37gX7R89KdGeqg/rCHawsM/?= =?us-ascii?Q?5WxINg9vmg+ySRXmGfMgfqZe5BvljvFUbFSDq+3yLFp50YwLt1disrGOZEpW?= =?us-ascii?Q?Tid+OGTSdDIg5fOgj+FYUzEfvTWEpD6fHcqj8qFRu9xCOvgYgHFsdK8ncYh8?= =?us-ascii?Q?qZxPcCAEVynXOetwT5H4lk/RlH8roGoYvutOhXm3Oel+Ripgnx4iqEUqSK2m?= =?us-ascii?Q?ilr2wtEfB3tr4kNjzGTowqf8IfzSn8iCcmE78SOnVE3kkH86svp010yw11cJ?= =?us-ascii?Q?T2YqI29DhNhXpmSPkwcsNbv9qLe6Id5qRA4kA7UH5uBbBJIlIlSu2Uee4wYV?= =?us-ascii?Q?vT1VpsSGnUQkt2zF93Tb4NWv5Qp7ArkFkYtrOOUQg5xOtIICGkKO9+jJPOUR?= =?us-ascii?Q?S9l67sRSHnkVVLNs6bRZv7AP8FhK0SR44sqS9QylrESIJ9AuyKwWX3C3Gwm+?= =?us-ascii?Q?TC8i31wCW3ReKQdwnFYCcFtzhRy11+T8zm+/NS/XqN0R9UhN1KPZk7LMtt9L?= =?us-ascii?Q?zr7NxnhGMu1fIJV4VkjlpaLARFn8XrbKRxxIMnuYeGi/jc90/jotK0VR9DeG?= =?us-ascii?Q?JPg1reoEeOs5fNRZMrlGtDWym28APADpxoY9MiNqZ77y22WDaT73wUtwRpHc?= =?us-ascii?Q?nLqPq1uXD0xpuywd4/N0kZN6vs4Y1MxproDHygflGu3bfEBnbL6rOT+O2pai?= =?us-ascii?Q?Q6qoCXELaJSXg+/ElOjQg4K7ZZeq0JjT/u0bm3cqEPoXXj2nTaSZGZMbj/0c?= =?us-ascii?Q?NlFuuqQiJlTpH8coWkg1oPk8UK7AtHIG/ybNw5qg88e3U+8UoybJtOcAfT0p?= =?us-ascii?Q?/L5rHrhylJrBWZksVs/mX8tsyJId5kR38v3tTMehUDmJ+WrUHEV9mw13Rb/u?= =?us-ascii?Q?/6iF5Ed2ixNsOghpro3znIe3HQbk8ZSmTWvo0anqhEOkhp2qAjBh04ZiNjcz?= =?us-ascii?Q?SD/4KRnpzt/W7mBFn1pga3ClP/Bi31xb1I15Qcwi2gsnKnTXxibBKQcbnC/B?= =?us-ascii?Q?b8geVuRyh2dUD6cmXWmtlsJsot7GXd1f2qP2Pd6LUjErj19EEu8r9a5CkGsn?= =?us-ascii?Q?u6DQhSsfUiWFf8wL/YNl+3fAMvnO45gpzyQANxLyJrNwwDlqWtHvge3K16TD?= =?us-ascii?Q?eHCHUQ/mkIxOy4ecFdEOT/4Zpedp0YKmxgY1pGcL62a29HS8y5mNV1FcuRcz?= =?us-ascii?Q?fRtKF4tRBzMpyfb7bV1jMq0htKAifVlRAo7aIMC3GwUYqcjkVLoBkd1hVrK8?= =?us-ascii?Q?SEcJPA/B8VFNYzlfweIm6u07jnqI1/nScglXJ9rN3dyyW1Bk29CRroreMFkY?= =?us-ascii?Q?Is/y1epEXeVCxMxOpbd1/YNgplq5GravpGUJEfriMJgsSCe3vnPJFd+1nncx?= =?us-ascii?Q?ocGqOzU4+4//J40e1iBTuxD/LuA4bXOEzxH7Zu42zH6hpmNoBQ4TU97ZdHbc?= =?us-ascii?Q?wQ=3D=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MN6PR11MB8244.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1e5163f6-560c-44f5-35bc-08dc1949248e X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Jan 2024 23:48:31.5913 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 1hGBbRJml9hxB52R+GwwWQWvd5ZS0x0hm46khV01ckrWPDmmsSoVdVK3lYKT6d4FK4+qnjmsofgwW2YpkhMOmg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR11MB8231 X-OriginatorOrg: 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,ray.ni@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 271hCAi2qy4Z1FUmpFrr7Oo7x7686176AA= Content-Language: en-US Content-Type: multipart/alternative; boundary="_000_MN6PR11MB8244BFB853F79937864A1A138C702MN6PR11MB8244namp_" X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=hexwXY+Y; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.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 --_000_MN6PR11MB8244BFB853F79937864A1A138C702MN6PR11MB8244namp_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Mike, For a certain Cupid leaf that does not have sub leaf, Cupid instruction doe= s not consume ecx and it always fills ecx with a determined value, defined = by sdm. So, I don't see any hurt to deterministic behavior if not zeroing ecx in As= mCpuid. thanks, ray ________________________________ From: Kinney, Michael D Sent: Saturday, January 20, 2024 7:16:14 AM To: Ni, Ray ; Tom Lendacky ; dev= el@edk2.groups.io ; Gao, Liming ; Liu, Zhiguang ; Dong, Eric = ; Kumar, Rahul R ; Gerd Hoffmann ; Ard Biesheuvel Cc: Michael Roth ; Kinney, Michael D Subject: RE: [edk2-devel] [PATCH 1/2] UefiCpuPkg/MpInitLib: Use AsmCpuidEx(= ) for CPUID_EXTENDED_TOPOLOGY leaf Hi Ray, It is about having deterministic behavior if a call if made for a CPUID EAX value that does depend on ECX. If ECX is not zeroed, then it will have a random value that may return different information. The problem statement from Tom is not about zeroing ECX. It is about avoiding code bugs where AsmCpuid() is called for an Index value that is documented to depend on ECX. In this case, we would want an error condition so the developer knows they should use AsmCpuidEx() instead. >From looking at the Intel SDM, there is a small set of Index values that do not look at ECX at all. We could consider adding an ASSERT() condition in AsmCpuid() if Index is a value that depends on ECX. Perhaps in DEBUG_CODE() so it is not always present. Mike > -----Original Message----- > From: Ni, Ray > Sent: Friday, January 19, 2024 2:01 AM > To: Kinney, Michael D ; Tom Lendacky > ; devel@edk2.groups.io; Gao, Liming > ; Liu, Zhiguang ; Dong, > Eric ; Kumar, Rahul R ; > Gerd Hoffmann ; Ard Biesheuvel > > Cc: Michael Roth > Subject: RE: [edk2-devel] [PATCH 1/2] UefiCpuPkg/MpInitLib: Use > AsmCpuidEx() for CPUID_EXTENDED_TOPOLOGY leaf > > Mike, > I agree with your words after "However". > Zeroing ECX in AsmCpuid() is confusing to future code maintainer: If > CPUID instruction does > not consume "ECX", why is it needed to zero "ECX"? > > Thanks, > Ray > > -----Original Message----- > > From: Kinney, Michael D > > Sent: Friday, January 19, 2024 7:11 AM > > To: Tom Lendacky ; devel@edk2.groups.io; > > Gao, Liming ; Liu, Zhiguang > ; > > Dong, Eric ; Ni, Ray ; Kumar, > Rahul R > > ; Gerd Hoffmann ; Ard > > Biesheuvel > > Cc: Michael Roth ; Kinney, Michael D > > > > Subject: RE: [edk2-devel] [PATCH 1/2] UefiCpuPkg/MpInitLib: Use > > AsmCpuidEx() for CPUID_EXTENDED_TOPOLOGY leaf > > > > Hi Tom, > > > > I do not see any harm in zeroing ECX in AsmCpuid(). > > > > If it is not zeroed, then it would have an undefined value. > > > > However, calling AsmCpuid() for any Index that evaluates ECX > > (including a check for 0) should never be done. If ECX is > > evaluated for a given Index, then AsmCpuIdEx() must be used. > > > > Mike > > > > > -----Original Message----- > > > From: Tom Lendacky > > > Sent: Wednesday, January 17, 2024 1:26 PM > > > To: devel@edk2.groups.io; Kinney, Michael D > > > ; Gao, Liming ; > Liu, > > > Zhiguang ; Dong, Eric ; > Ni, > > > Ray ; Kumar, Rahul R ; > Gerd > > > Hoffmann ; Ard Biesheuvel > > > > > Cc: Michael Roth > > > Subject: Re: [edk2-devel] [PATCH 1/2] UefiCpuPkg/MpInitLib: Use > > > AsmCpuidEx() for CPUID_EXTENDED_TOPOLOGY leaf > > > > > > On 11/28/23 08:35, Lendacky, Thomas via groups.io wrote: > > > > On 11/6/23 17:15, Tom Lendacky wrote: > > > >> On 11/6/23 16:45, Lendacky, Thomas via groups.io wrote: > > > >>> The CPUID_EXTENDED_TOPOLOGY CPUID leaf takes a subleaf as input > > when > > > >>> returning CPUID information. However, the AsmCpuid() function > does > > > not > > > >>> zero out ECX before the CPUID instruction, so the input leaf is > used > > > as > > > >>> the sub-leaf for the CPUID request and returns erroneous/invalid > > > CPUID > > > >>> data, since the intent of the request was to get data related to > > > sub-leaf > > > >>> 0. Instead, use AsmCpuidEx() for the CPUID_EXTENDED_TOPOLOGY > leaf. > > > >> > > > >> Alternatively, the AsmCpuid() function could be changed to XOR > ECX > > > >> before invoking the CPUID instruction. This would ensure that the > 0 > > > >> sub-leaf is returned for any CPUID leaves that support sub- > leaves. > > > >> Thoughts? > > > >> > > > >> Adding some additional maintainers for their thoughts, too. > > > > > > > > Any thoughts on this approach (as a separate, unrelated patch) to > > > > eliminate future issues that could pop up? > > > > > > > > Seems like zeroing out ECX before calling CPUID would be an > > > appropriate > > > > thing to do, but I'm not sure if that will have any impact on the > > > existing > > > > code base... it shouldn't, but you never know. > > > > > > Just a re-ping for thoughts on this. > > > > > > Thanks, > > > Tom > > > > > > > > > > > Thanks, > > > > Tom > > > > > > > >> > > > >> Thanks, > > > >> Tom -=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 (#114103): https://edk2.groups.io/g/devel/message/114103 Mute This Topic: https://groups.io/mt/102432782/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- --_000_MN6PR11MB8244BFB853F79937864A1A138C702MN6PR11MB8244namp_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable
Mike,
For a certain Cupid leaf that does not have sub leaf, Cupi= d instruction does not consume ecx and it always fills ecx with a determine= d value, defined by sdm.
So, I don't see any hurt to deterministic behavior if not = zeroing ecx in AsmCpuid.

thanks,
ray

From: Kinney, Michael D <= ;michael.d.kinney@intel.com>
Sent: Saturday, January 20, 2024 7:16:14 AM
To: Ni, Ray <ray.ni@intel.com>; Tom Lendacky <thomas.lendac= ky@amd.com>; devel@edk2.groups.io <devel@edk2.groups.io>; Gao, Lim= ing <liming.gao@intel.com>; Liu, Zhiguang <zhiguang.liu@intel.com&= gt;; Dong, Eric <eric.dong@intel.com>; Kumar, Rahul R <rahul.r.kum= ar@intel.com>; Gerd Hoffmann <kraxel@redhat.com>; Ard Biesheuvel <ardb+tianocore= @kernel.org>
Cc: Michael Roth <michael.roth@amd.com>; Kinney, Michael D <= ;michael.d.kinney@intel.com>
Subject: RE: [edk2-devel] [PATCH 1/2] UefiCpuPkg/MpInitLib: Use AsmC= puidEx() for CPUID_EXTENDED_TOPOLOGY leaf
 
Hi Ray,

It is about having deterministic behavior if a call if made for
a CPUID EAX value that does depend on ECX.  If ECX is not zeroed,
then it will have a random value that may return different
information.

The problem statement from Tom is not about zeroing ECX.  It is
about avoiding code bugs where AsmCpuid() is called for an Index
value that is documented to depend on ECX.  In this case, we would
want an error condition so the developer knows they should use
AsmCpuidEx() instead.

>From looking at the Intel SDM, there is a small set of Index
values that do not look at ECX at all.  We could consider
adding an ASSERT() condition in AsmCpuid() if Index is
a value that depends on ECX.  Perhaps in DEBUG_CODE() so
it is not always present.

Mike

> -----Original Message-----
> From: Ni, Ray <ray.ni@intel.com>
> Sent: Friday, January 19, 2024 2:01 AM
> To: Kinney, Michael D <michael.d.kinney@intel.com>; Tom Lendacky=
> <thomas.lendacky@amd.com>; devel@edk2.groups.io; Gao, Liming
> <liming.gao@intel.com>; Liu, Zhiguang <zhiguang.liu@intel.com= >; Dong,
> Eric <eric.dong@intel.com>; Kumar, Rahul R <rahul.r.kumar@int= el.com>;
> Gerd Hoffmann <kraxel@redhat.com>; Ard Biesheuvel
> <ardb+tianocore@kernel.org>
> Cc: Michael Roth <michael.roth@amd.com>
> Subject: RE: [edk2-devel] [PATCH 1/2] UefiCpuPkg/MpInitLib: Use
> AsmCpuidEx() for CPUID_EXTENDED_TOPOLOGY leaf
>
> Mike,
> I agree with your words after "However".
> Zeroing ECX in AsmCpuid() is confusing to future code maintainer: If > CPUID instruction does
> not consume "ECX", why is it needed to zero "ECX"?=
>
> Thanks,
> Ray
> > -----Original Message-----
> > From: Kinney, Michael D <michael.d.kinney@intel.com>
> > Sent: Friday, January 19, 2024 7:11 AM
> > To: Tom Lendacky <thomas.lendacky@amd.com>; devel@edk2.grou= ps.io;
> > Gao, Liming <liming.gao@intel.com>; Liu, Zhiguang
> <zhiguang.liu@intel.com>;
> > Dong, Eric <eric.dong@intel.com>; Ni, Ray <ray.ni@intel.= com>; Kumar,
> Rahul R
> > <rahul.r.kumar@intel.com>; Gerd Hoffmann <kraxel@redhat.= com>; Ard
> > Biesheuvel <ardb+tianocore@kernel.org>
> > Cc: Michael Roth <michael.roth@amd.com>; Kinney, Michael D<= br> > > <michael.d.kinney@intel.com>
> > Subject: RE: [edk2-devel] [PATCH 1/2] UefiCpuPkg/MpInitLib: Use > > AsmCpuidEx() for CPUID_EXTENDED_TOPOLOGY leaf
> >
> > Hi Tom,
> >
> > I do not see any harm in zeroing ECX in AsmCpuid().
> >
> > If it is not zeroed, then it would have an undefined value.
> >
> > However, calling AsmCpuid() for any Index that evaluates ECX
> > (including a check for 0) should never be done.  If ECX is > > evaluated for a given Index, then AsmCpuIdEx() must be used.
> >
> > Mike
> >
> > > -----Original Message-----
> > > From: Tom Lendacky <thomas.lendacky@amd.com>
> > > Sent: Wednesday, January 17, 2024 1:26 PM
> > > To: devel@edk2.groups.io; Kinney, Michael D
> > > <michael.d.kinney@intel.com>; Gao, Liming <liming.g= ao@intel.com>;
> Liu,
> > > Zhiguang <zhiguang.liu@intel.com>; Dong, Eric <eric= .dong@intel.com>;
> Ni,
> > > Ray <ray.ni@intel.com>; Kumar, Rahul R <rahul.r.kum= ar@intel.com>;
> Gerd
> > > Hoffmann <kraxel@redhat.com>; Ard Biesheuvel
> > <ardb+tianocore@kernel.org>
> > > Cc: Michael Roth <michael.roth@amd.com>
> > > Subject: Re: [edk2-devel] [PATCH 1/2] UefiCpuPkg/MpInitLib: = Use
> > > AsmCpuidEx() for CPUID_EXTENDED_TOPOLOGY leaf
> > >
> > > On 11/28/23 08:35, Lendacky, Thomas via groups.io wrote:
> > > > On 11/6/23 17:15, Tom Lendacky wrote:
> > > >> On 11/6/23 16:45, Lendacky, Thomas via groups.io wr= ote:
> > > >>> The CPUID_EXTENDED_TOPOLOGY CPUID leaf takes a = subleaf as input
> > when
> > > >>> returning CPUID information. However, the AsmCp= uid() function
> does
> > > not
> > > >>> zero out ECX before the CPUID instruction, so t= he input leaf is
> used
> > > as
> > > >>> the sub-leaf for the CPUID request and returns = erroneous/invalid
> > > CPUID
> > > >>> data, since the intent of the request was to ge= t data related to
> > > sub-leaf
> > > >>> 0. Instead, use AsmCpuidEx() for the CPUID_EXTE= NDED_TOPOLOGY
> leaf.
> > > >>
> > > >> Alternatively, the AsmCpuid() function could be cha= nged to XOR
> ECX
> > > >> before invoking the CPUID instruction. This would e= nsure that the
> 0
> > > >> sub-leaf is returned for any CPUID leaves that supp= ort sub-
> leaves.
> > > >> Thoughts?
> > > >>
> > > >> Adding some additional maintainers for their though= ts, too.
> > > >
> > > > Any thoughts on this approach (as a separate, unrelated= patch) to
> > > > eliminate future issues that could pop up?
> > > >
> > > > Seems like zeroing out ECX before calling CPUID would b= e an
> > > appropriate
> > > > thing to do, but I'm not sure if that will have any imp= act on the
> > > existing
> > > > code base... it shouldn't, but you never know.
> > >
> > > Just a re-ping for thoughts on this.
> > >
> > > Thanks,
> > > Tom
> > >
> > > >
> > > > Thanks,
> > > > Tom
> > > >
> > > >>
> > > >> Thanks,
> > > >> Tom
_._,_._,_

Groups.io Links:

=20 You receive all messages sent to this group. =20 =20

View/Reply Online (#114103) | =20 | Mute= This Topic | New Topic
Your Subscriptio= n | Contact Group Owner | Unsubscribe [rebecca@openfw.io]

_._,_._,_
--_000_MN6PR11MB8244BFB853F79937864A1A138C702MN6PR11MB8244namp_--