public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Michael D Kinney" <michael.d.kinney@intel.com>
To: Tom Lendacky <thomas.lendacky@amd.com>,
	"devel@edk2.groups.io" <devel@edk2.groups.io>,
	"Gao, Liming" <liming.gao@intel.com>,
	"Liu, Zhiguang" <zhiguang.liu@intel.com>
Cc: "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>,
	Michael Roth <michael.roth@amd.com>,
	"Kinney, Michael D" <michael.d.kinney@intel.com>
Subject: Re: [edk2-devel] [PATCH 1/2] UefiCpuPkg/MpInitLib: Use AsmCpuidEx() for CPUID_EXTENDED_TOPOLOGY leaf
Date: Tue, 7 Nov 2023 01:19:19 +0000	[thread overview]
Message-ID: <CO1PR11MB49291733FBEE7474DBB4F05DD2A9A@CO1PR11MB4929.namprd11.prod.outlook.com> (raw)
In-Reply-To: <26becea4-2ad8-4773-ab3d-5ad98ff48759@amd.com>

Hi Tom,

It likely would have been better to define AsmCpuid() to
set ECX=0.

However, how would new source code know if the BaseLib they 
linking against has this new behavior or not?

It is probably safer to do what you propose which is to use
AsmCpuidEx() that specifies exactly how ECX is set.

Mike


> -----Original Message-----
> From: Tom Lendacky <thomas.lendacky@amd.com>
> Sent: Monday, November 6, 2023 3:16 PM
> To: devel@edk2.groups.io; Kinney, Michael D
> <michael.d.kinney@intel.com>; Gao, Liming <liming.gao@intel.com>; Liu,
> Zhiguang <zhiguang.liu@intel.com>
> Cc: 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>;
> Michael Roth <michael.roth@amd.com>
> Subject: Re: [edk2-devel] [PATCH 1/2] UefiCpuPkg/MpInitLib: Use
> AsmCpuidEx() for CPUID_EXTENDED_TOPOLOGY leaf
> 
> 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.
> 
> Thanks,
> Tom
> 
> >
> > Fixes: d4d7c9ad5fe5 ("UefiCpuPkg/MpInitLib: use BSP to do extended
> ...")
> > Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
> > ---
> >   UefiCpuPkg/Library/MpInitLib/AmdSev.c | 9 ++++++++-
> >   1 file changed, 8 insertions(+), 1 deletion(-)
> >
> > diff --git a/UefiCpuPkg/Library/MpInitLib/AmdSev.c
> b/UefiCpuPkg/Library/MpInitLib/AmdSev.c
> > index bda4960f6fd3..d34f9513e002 100644
> > --- a/UefiCpuPkg/Library/MpInitLib/AmdSev.c
> > +++ b/UefiCpuPkg/Library/MpInitLib/AmdSev.c
> > @@ -256,7 +256,14 @@ FillExchangeInfoDataSevEs (
> >     if (StdRangeMax >= CPUID_EXTENDED_TOPOLOGY) {
> >       CPUID_EXTENDED_TOPOLOGY_EBX  ExtTopoEbx;
> >
> > -    AsmCpuid (CPUID_EXTENDED_TOPOLOGY, NULL, &ExtTopoEbx.Uint32,
> NULL, NULL);
> > +    AsmCpuidEx (
> > +      CPUID_EXTENDED_TOPOLOGY,
> > +      0,
> > +      NULL,
> > +      &ExtTopoEbx.Uint32,
> > +      NULL,
> > +      NULL
> > +      );
> >       ExchangeInfo->ExtTopoAvail =
> !!ExtTopoEbx.Bits.LogicalProcessors;
> >     }
> >   }


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#110779): https://edk2.groups.io/g/devel/message/110779
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/1913456212/xyzzy [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



  reply	other threads:[~2023-11-07  1:19 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-06 22:45 [edk2-devel] [PATCH 0/2] SEV-SNP guest support fixes Lendacky, Thomas via groups.io
2023-11-06 22:45 ` [edk2-devel] [PATCH 1/2] UefiCpuPkg/MpInitLib: Use AsmCpuidEx() for CPUID_EXTENDED_TOPOLOGY leaf Lendacky, Thomas via groups.io
2023-11-28 10:31   ` Ni, Ray
2023-11-06 22:45 ` [edk2-devel] [PATCH 2/2] UefiCpuPkg/MpInitLib: Copy SEV-ES save area pointer during APIC ID sorting Lendacky, Thomas via groups.io
2023-11-28 10:33   ` Ni, Ray
     [not found] ` <17952A20A9E21541.12603@groups.io>
2023-11-06 23:15   ` [edk2-devel] [PATCH 1/2] UefiCpuPkg/MpInitLib: Use AsmCpuidEx() for CPUID_EXTENDED_TOPOLOGY leaf Lendacky, Thomas via groups.io
2023-11-07  1:19     ` Michael D Kinney [this message]
2023-11-28 14:35     ` Lendacky, Thomas via groups.io
     [not found]     ` <179BD02AA4207037.22216@groups.io>
2024-01-17 21:26       ` Lendacky, Thomas via groups.io
2024-01-18 23:10         ` Michael D Kinney
2024-01-19 10:00           ` Ni, Ray
2024-01-19 23:16             ` Michael D Kinney
2024-01-19 23:48               ` Ni, Ray
2024-01-20  1:49                 ` Michael D Kinney
2024-01-20  6:48                   ` Ni, Ray
2024-01-20 16:03                     ` Lendacky, Thomas via groups.io
2024-01-21  3:00                       ` Ni, Ray
2023-11-07  9:55 ` [edk2-devel] [PATCH 0/2] SEV-SNP guest support fixes Gerd Hoffmann
2023-11-17 21:43   ` Lendacky, Thomas via groups.io
2023-11-27 19:00     ` Lendacky, Thomas via groups.io

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CO1PR11MB49291733FBEE7474DBB4F05DD2A9A@CO1PR11MB4929.namprd11.prod.outlook.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox