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 43DC074003A for ; Sat, 20 Jan 2024 01:49:14 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=fqkFP4yY7MTBwxIZhQy95n1yKJvpLHp9Ac2ZpebXJnE=; 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=1705715352; v=1; b=U6xUnwHurNvrOhO+4KY7zzzyGrh3VVueJNRHgsO49CGabfNyeR4yR0J7TezJPiE69V2lvztt crdzoxQdfpXyRVSzS7I9bnfLECi4kyoQwopIxQrSmHICl3sxOCp9HR7nArYQnN3353pTi94nuSR bU38XYST3bYpQMZ0r5t9C4xw= X-Received: by 127.0.0.2 with SMTP id 2xBpYY7687511xCbp1d5c93C; Fri, 19 Jan 2024 17:49:12 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by mx.groups.io with SMTP id smtpd.web10.12441.1705715351539047563 for ; Fri, 19 Jan 2024 17:49:11 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10957"; a="8269308" X-IronPort-AV: E=Sophos;i="6.05,206,1701158400"; d="scan'208,217";a="8269308" X-Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jan 2024 17:49:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10957"; a="734686455" X-IronPort-AV: E=Sophos;i="6.05,206,1701158400"; d="scan'208,217";a="734686455" X-Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by orsmga003.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 19 Jan 2024 17:49:10 -0800 X-Received: from orsmsx601.amr.corp.intel.com (10.22.229.14) by ORSMSX603.amr.corp.intel.com (10.22.229.16) 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 17:49:09 -0800 X-Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) by orsmsx601.amr.corp.intel.com (10.22.229.14) 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 17:49:09 -0800 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (104.47.66.41) by edgegateway.intel.com (134.134.137.102) 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 17:49:09 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CXobDWhhfmJxCoMsVh1weVQ9+rS7UAN4Ic2/ALzNCIAaTJdhtOz3XulZEJn1LI5PV5DgzSKwbMRpkSzT+sln6sbOOrGFfdhbWUgbqP5xcoxAaPEcs5yLhGf11RQq+fv9uGM4y4BnWPRrTxMll4XlvqZD0SESSPl8cyR2RXZwqQLCfqUuHQp3a3QagHEBW8G03h/FnHxRTf5i1tX63T+eJzQvHlKDbPjOsrg/LxBzdv7j5jpBPlevt9xg8yyuVqv1IZEbMgCEMHJX6p5GyskSvPnAkbGkX6uzBIDmNUiYWua9CNuJdejygFQqhvsh/OCkHtu/ktLwI9aEt0qke/1rXw== 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=kjs2wfGzDm2oIdljgEf15sxa1H5amKC1tKjD5YfpIP4=; b=hyV0axORntADQI/xaO4Sr4wnsENgzhhSvZv/C7IEpZSgwnlWhQwuKv3lICKNXg3hjdbfomrOj+HKIX29M8eE1aAxL6FBqrj6P6eyff8Sy0PzmyVAKwroj3cQIy9eTLVVw7TH5Dvv8AkW4xdGaAERQ9yuxKllV3dTcXj9L5+Vimlo9bVBkw3d5SL+gzQwGGSv94ivRan7Ak7M0mooIBmThMnAqtkpCz4T77bL6zlBZtAMcHreOIEuLlT3+4B3cGZPKF9kjeU7gXsgJ+i/7MBfg/UnR7ulqSSsFuZurD/wQYPNQXj9Kf9AWAKAizhYbWouqe1OhttPY3btEkU1/MPS6Q== 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 CO1PR11MB4929.namprd11.prod.outlook.com (2603:10b6:303:6d::19) by IA0PR11MB8304.namprd11.prod.outlook.com (2603:10b6:208:48b::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.24; Sat, 20 Jan 2024 01:49:02 +0000 X-Received: from CO1PR11MB4929.namprd11.prod.outlook.com ([fe80::4382:5b03:f13:88ff]) by CO1PR11MB4929.namprd11.prod.outlook.com ([fe80::4382:5b03:f13:88ff%4]) with mapi id 15.20.7202.026; Sat, 20 Jan 2024 01:49:02 +0000 From: "Michael D Kinney" To: "Ni, Ray" , 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: AQHaEQc2ooVv+0Hq4UGNbQzkXjxFfLDe9Z1LgAGtYhCAALeogIAA144QgAAPv4CAACEbwA== Date: Sat, 20 Jan 2024 01:49:02 +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: CO1PR11MB4929:EE_|IA0PR11MB8304:EE_ x-ms-office365-filtering-correlation-id: 5094d35f-a0bd-4fb2-81ff-08dc1959fa65 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam-message-info: T+SHeArpocwWnj64tM6rhcBCqmj702a6ye/R7JMG0HbUJXNMcYfxu1aUUlUS+RDd+5V6GP+X7keYAtnsmqPPGectDROcemYZb9yeyoQmRNecd3u4RTg2qjyIkmkZuQ73HE9yeEzoWzRMA7iUTWvNXsNF3bfH1aAtOdEQEnS5v9bEtQx8GYmECBja1qz9TXURy40SUAO0SP9tlFlGOHBrPAckz56n5lvaIMWJY1ehgN+qsMJ7IKC4wDFxrGS0PxQ6XvLG094UL7BsIYujxbkWevgWaUIlNrNdksPGod07Scn6p5+wqe18LGajZ7iAwWL35C0E1w2arZdYqTl+IB+jZHdkvMu7H7gMreORSTFB3NV3Q1831EjiWNpgdHGDaMo6oixA8lqiETIk5fWn3nG2+mfVa/4og4PVipHTeDovEmQEyql3rOBNBPKYqQ91HNhCZF0XJvG2XzsTN9lSk7oE2KgaefJsV3DZ9VVkBgGrUPe4xKDUK9iaxp1kBeuv03CMere9CrRX7L1zoavDMCb9TrwXN4/0sNR4yu4gxFvJQZovWtJblUFLRT9VXeYjLRv+ejRXWs7NOYUqnMgvAzWZNwLme9BDVFGH/JmRTGx0EWjbCnA6m8tK8A6nOEAo1G+FQcTLtY4rzbdOUqVm8PoVxA== x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?XA7W3T7Y+a+e0U5+7z9Hc7NVJsvVTxPGjYiXJECYUM/H41YjNNxhWxUSnlW2?= =?us-ascii?Q?RnFbqzxqlPzpInEhTZOrAPDfW2vJPR1lihC8QwZiUewheau8lNPF/cpNwlOw?= =?us-ascii?Q?UsHTaQuDfKoAvwe1/Af9MMihU6EaHsOkAf7knaBSKUHrVWTXJErwlT6J+kXR?= =?us-ascii?Q?QfTxB+ho7YeHzbODbo3+slTNlkhQTB1R/IhTknQ62tTouSTMKmM/huZhblue?= =?us-ascii?Q?f9idVL+DCnn8euZjcrBznvFnNL0fOBxwQXiIVDpqTJON1MZl1fBZ3knVDFs2?= =?us-ascii?Q?siYP6R0EhRxQijNHWuV5Paj9SSs6GaU2ye5Ma09fxl0J3Yklmlr3FVh15ixv?= =?us-ascii?Q?HSJ3Si65m1Rw7SlpkSVTRQqB5gUimy8Lox/j0w7gVdl1mA6NhFQE92eB/JTo?= =?us-ascii?Q?w40a90GN3LEf6fToCHT/lK8Uj/aexKM8RACfAo8Fty1uevQWjSTtqLVwr9+z?= =?us-ascii?Q?mHt5k+BSG7MmiZPEmelEDkc8JcQFCxzPNJUtf1929btfUtJyO2xE7atJUTIW?= =?us-ascii?Q?hfW+Kg26BIMI6TgN55vR4PyOHNPcZScYdAeNoYPpuf5sH4OUNAHnbYBnrneo?= =?us-ascii?Q?UAtIWj3aLK6ituvllHbMlNs3az+qrjk59S6x3+1fJ621H3c6zeGHv5KcuI/7?= =?us-ascii?Q?PzuXghFgKQ1QaFJlOtpxugwjiVUhKy3Yvt9aYAjDqk07W43ZDy6xLmYSWSH6?= =?us-ascii?Q?1ZINeD37aelMwhmaP9iyNFD6Kh4MWCT2Ium+X9PXpMQKVwu0efXq8v997KBE?= =?us-ascii?Q?eq0E/Wd3I2Z4PBnAoWPBHXp5xg5ndJQIkxqnFXbgubLdbcOTbjc5R6zaV/Gx?= =?us-ascii?Q?hONZqCNnE5w5E5Fi0izVOACbWUTihQC/YYrNc8XZfyvm3avGppfKSjMZ1Xbv?= =?us-ascii?Q?juByiTlFQ/+vtPkzLW69tGK4rYdqxcCYdPfDMLRAyptcD515WEBokLx67SaE?= =?us-ascii?Q?kkboEPO0OIwn3YTPkAMxzG+64sFW9gqYSRYgzoTYoneDIfouRJgMzTHbRO6q?= =?us-ascii?Q?2Gr8RVetzRrO/FmaBUEjkn2uIJd3hlvitggVTdVtMAHlVpuZKDckTIQZ4krO?= =?us-ascii?Q?r7xEt3EQIFfycCgwSJojg3BZkzrvloVVW1ijm9vap5ekYRZBrzTS4FJ1njpj?= =?us-ascii?Q?N9UQvGKxyhqqT+NDi4f7zryFlgizdsc66SUohcn8RYPyWK5Jp4y51QGLbC4i?= =?us-ascii?Q?XYNmmUcLicxF9t2CgCaIkQQvMcBqJ1U4S49nQTOnymWVFf1zIvLjXsmb9QBz?= =?us-ascii?Q?mgP1MoLXzUV0lXolJ+7Tb9I7EOg0GTEFe3eRvGgHbudXdcZYYCZZ+quduT4D?= =?us-ascii?Q?IzAvOrdupYoWOBlQz3lQqog+008EFWeolccrC51981FbJWH5cgqiBRB9vcsA?= =?us-ascii?Q?3yFguBABI98h6XYxRnA1+jCOw6hUlOD0WnxIcnouE8rWEP+ypOn4V+Qx4E3p?= =?us-ascii?Q?oIELM9WcUXM+HUu5FBjy8/OavgjZG/IyWkrgYVRIPwQ+mGNcfDFClxAGl85o?= =?us-ascii?Q?53Bqw24ham/Ijj5dSKgWQKLg/9CE3rmmtA6GrHVpCxKhCS36tnlkLxVOCxWk?= =?us-ascii?Q?8FNPVxXZIRrEcEKp3UYHc8VVYjYYAg2Gg23/MVWJNl4/a610mbqn7z66b6jw?= =?us-ascii?Q?pg=3D=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CO1PR11MB4929.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5094d35f-a0bd-4fb2-81ff-08dc1959fa65 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Jan 2024 01:49:02.3330 (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: fmXUZFpT2T+VTH0WBSY6xCDbC+3UemYjJ0IEcMkOr0Dy3kfbThEsC+/uT5mD9ef93dmP9Eqgt0ym7REDM8N5XawZf/DITx6aP86eVTi/LkQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR11MB8304 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,michael.d.kinney@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: YGxpov0prpX8KWaRnZhv3rc2x7686176AA= Content-Language: en-US Content-Type: multipart/alternative; boundary="_000_CO1PR11MB4929A2106ED63DC316821B43D2772CO1PR11MB4929namp_" X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=U6xUnwHu; 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; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}") --_000_CO1PR11MB4929A2106ED63DC316821B43D2772CO1PR11MB4929namp_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable The issue is if AsmCpuid() is called for an Index value that does depend on= ECX. That would be a bug on the caller's part and would not have determin= istic behavior because ECX on input is not deterministic. That is the cond= ition that would be good to catch. Mike From: Ni, Ray Sent: Friday, January 19, 2024 3:49 PM To: Kinney, Michael D ; Tom Lendacky ; devel@edk2.groups.io; Gao, Liming ; = Liu, Zhiguang ; Dong, Eric ; K= umar, 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 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 >; devel@edk2.groups.io<= mailto:devel@edk2.groups.io> >; Gao, Liming >; Liu= , Zhiguang >; Dong, E= ric >; Kumar, Rahul R >; Gerd Hoffmann >; Ard Biesheuvel > Cc: Michael Roth >; Kinne= y, 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.gro= ups.io; Gao, Liming > >; Liu, Zhiguang >; Dong, > Eric >; Kumar, Rahul R >; > Gerd Hoffmann >; Ard Biesheuv= el > > > 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, Z= higuang > >; > > Dong, Eric >; Ni, Ray <= ray.ni@intel.com>; Kumar, > Rahul R > > >; Gerd Hoffman= n >; Ard > > Biesheuvel = > > > Cc: Michael Roth >; K= inney, 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, Michae= l D > > > >; Gao,= Liming >; > Liu, > > > Zhiguang >; Don= g, Eric >; > Ni, > > > Ray >; Kumar, Rahul R >; > Gerd > > > Hoffmann >; Ard Biesheuve= l > > > > > > 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 (#114105): https://edk2.groups.io/g/devel/message/114105 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_CO1PR11MB4929A2106ED63DC316821B43D2772CO1PR11MB4929namp_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

The issue is if AsmCpuid() is called for an Index va= lue that does depend on ECX.  That would be a bug on the caller’= s part and would not have deterministic behavior because ECX on input is no= t deterministic.  That is the condition that would be good to catch.

 

Mike

 

From: Ni, Ray <ray.ni@intel.com>
Sent: Friday, January 19, 2024 3:49 PM
To: Kinney, Michael D <michael.d.kinney@intel.com>; Tom Lendac= ky <thomas.lendacky@amd.com>; devel@edk2.groups.io; Gao, Liming <l= iming.gao@intel.com>; Liu, Zhiguang <zhiguang.liu@intel.com>; Dong= , Eric <eric.dong@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 <= ;michael.d.kinney@intel.com>
Subject: Re: [edk2-devel] [PATCH 1/2] UefiCpuPkg/MpInitLib: Use AsmC= puidEx() for CPUID_EXTENDED_TOPOLOGY leaf

 

Mike,

For a certain Cupid leaf that does not have sub leaf= , Cupid instruction does not consume ecx and it always fills ecx with a det= ermined value, defined by sdm.

So, I don't see any hurt to deterministic behavior i= f 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 <thoma= s.lendacky@amd.com>; devel@edk2.groups.io <devel@edk2.groups.io>; Gao, Liming= <liming.gao@intel.com>; = Liu, Zhiguang <zhiguang.liu@in= tel.com>; Dong, Eric <eric.dong@intel.com<= /a>>; Kumar, Rahul R <rahu= l.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 <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&g= t;; Liu, Zhiguang <zhiguang.li= u@intel.com>; Dong,
> Eric <eric.dong@intel.com>; Kumar, Rahul R <rahul.= r.kumar@intel.com>;
> Gerd Hoffmann <kraxel@redhat.c= om>; Ard Biesheuvel
> <ardb+tianocore@kernel= .org>
> Cc: Michael Roth <michael.r= oth@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 <t= homas.lendacky@amd.com>; devel@edk2.groups.io;
> > Gao, Liming <liming.ga= o@intel.com>; Liu, Zhiguang
> <zhiguang.liu@intel.com>;
> > Dong, Eric <
eric.dong@i= ntel.com>; Ni, Ray <ray.ni@in= tel.com>; Kumar,
> Rahul R
> > <rahul.r.kumar@inte= l.com>; Gerd Hoffmann <kraxe= l@redhat.com>; Ard
> > Biesheuvel <ardb+= tianocore@kernel.org>
> > Cc: Michael Roth <mich= ael.roth@amd.com>; Kinney, Michael D
> > <michael.d.kinne= y@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.group= s.io; Kinney, Michael D
> > > <michael.d.= kinney@intel.com>; Gao, Liming <liming.gao@intel.com>;
> Liu,
> > > Zhiguang <zhigu= ang.liu@intel.com>; Dong, Eric <eric.dong@intel.com>;
> Ni,
> > > Ray <ray.ni@intel.com= >; Kumar, Rahul R <rah= ul.r.kumar@intel.com>;
> Gerd
> > > Hoffmann <kraxel@red= hat.com>; Ard Biesheuvel
> > <ardb+tianocore@k= ernel.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 (#114105) | =20 | Mute= This Topic | New Topic
Your Subscriptio= n | Contact Group Owner | Unsubscribe [rebecca@openfw.io]

_._,_._,_
--_000_CO1PR11MB4929A2106ED63DC316821B43D2772CO1PR11MB4929namp_--