Re: [edk2-devel] Fixing edk2-basetools CI

2024-02-22 Thread Yuwei Chen
Thanks a lot Rebecca~~

Thanks,
Christine

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Michael
> D Kinney
> Sent: Saturday, February 17, 2024 1:24 AM
> To: Rebecca Cran ; Joey Vagedes
> ; Rebecca Cran
> ; devel@edk2.groups.io; Sean
> ; Michael Kubacki
> 
> Cc: Kinney, Michael D 
> Subject: Re: [edk2-devel] Fixing edk2-basetools CI
> 
> Hi Rebecca,
> 
> This approach makes a lot of sense.  Thank you for the updated.  I have
> approved.
> 
> Can we open some new Issues to re-enable flake8/ruf  and codecov so those
> tasks are not forgotten.
> 
> Thanks,
> 
> Mike
> 
> > -Original Message-
> > From: Rebecca Cran 
> > Sent: Thursday, February 15, 2024 11:51 PM
> > To: Joey Vagedes ; Rebecca Cran
> > ; devel@edk2.groups.io; Kinney,
> > Michael D ; Sean ;
> > Michael Kubacki 
> > Subject: Re: [EXTERNAL] Re: [edk2-devel] Fixing edk2-basetools CI
> >
> > I've updated the PR
> > https://github.com/tianocore/edk2-basetools/pull/116/ to include
> > commits from the pyflake8 disable PR and a couple more commits that
> > cause CI to start passing. I realize that disabling both flake8 and
> > codecov isn't good, but my thinking is to get builds working again
> > then we can work on fixing the issues in the background. The
> > edk2-basetools project needs lots of work.
> >
> >
> > Add pyproject.toml and fix setup.py deprecation warnings
> >
> > Disable running Pyflakes in CI since it's blocking releases
> >
> > Fix comments in build-publish-whl-steps.yml
> >
> > Update basic-setup-steps.yml to require Python 3.10
> >
> > Disable codecov to fix CI and due to very low coverage
> >
> >
> > --
> > Rebecca Cran
> >
> >
> > On 2/13/24 12:42, Joey Vagedes wrote:
> > > I agree - there are multiple blocking issues that will require some
> > fixes - One additional thing I noted is that multiple areas still
> > perform relative path imports - i.e. the import starts with `from .`.
> > >
> > > These will all need to be updated to import from edk2basetools as
> > some point soon as importing via relative paths can result in it
> > importing the wrong file if the pypath environment variable is
> > influenced. This open issue actually stems from that:
> > https://github.com/tianocore/edk2-basetools/issues/110 as the end
> > result is that edk2-basetools pip module can unexpectedly end up using
> > the BaseTools/* source code rather than the pip module source code.
> > >
> > > Thanks,
> > > Joey
> > >
> > > -Original Message-
> > > From: Rebecca Cran 
> > > Sent: Tuesday, February 13, 2024 11:28 AM
> > > To: Joey Vagedes ; Rebecca Cran
> > ; devel@edk2.groups.io; Kinney,
> > Michael D ; Sean ;
> > Michael Kubacki 
> > > Subject: Re: [EXTERNAL] Re: [edk2-devel] Fixing edk2-basetools CI
> > >
> > > [You don't often get email from rebe...@bsdio.com. Learn why this is
> > important at https://aka.ms/LearnAboutSenderIdentification ]
> > >
> > > Thanks, I've updated
> > > https://github.com/tianocore/edk2-basetools/pull/116 with the
> > > changes
> > you suggested.
> > >
> > > Unfortunately several of the tools don't work with the
> > projects.scripts section because they don't have Main etc. It turns
> > out even Ecc is currently broken in the edk2-basetools PyPI package
> > because PYTHONPATH doesn't contain the parent directory. I'll plan to
> > fix the issues in the near future, once I've worked through the other PRs.
> > >
> > >
> > > --
> > >
> > > Rebecca Cran
> > >
> > >
> > > On 2/12/24 10:06, Joey Vagedes wrote:
> > >> Hello! Regarding flake8, I see. That will take some time to work
> > through - I completely understand.
> > >>
> > >> When ready to work through that, I suggest switching to ruff. It
> > >> can
> > resolve some errors automatically for you and allows you to customize
> > it more than flake8 (it is also faster).
> > >>
> > >> I just ran ruff on the project, showing about 11k errors. One nice
> > thing is that a large majority of it is regarding importing using *.
> > By fixing those, you can reduce the errors by almost 70% (to 3400
> > errors), so it is not *quite* as bad as it seems (though 3400 is still A 
> > LOT).
> > >>
> > >> ---
> > >> -
> > --
> > >> -
> > >>
> > >> Regarding the setup tools question, the build-backend part of
> > >> pytoml
> > (L3) is the entry point that is invoked - so we are still invoking
> > setuptools. However, it pulls the necessary metadata from
> > pyproject.toml rather than setup.py's setup() function. The main thing
> > that is different is the "get_version" functionality, which we
> > replicate in the pyproject.toml with setuptools-scm[toml] which simply
> > uses the latest tag to set the version.
> > >>
> > >> ---
> > >> -
> > --
> > >> -
> > >>
> > >> Additionally, I wanted to comment on the wrappers that you

回复: [edk2-devel] [PATCH v3 0/2] SMM CPU Optimization

2024-02-22 Thread gaoliming via groups.io
Jiaxin:
  Thanks for your confirmation. Edk2 202402 stable tag will not include
them. 

Thanks
Liming
> -邮件原件-
> 发件人: devel@edk2.groups.io  代表 Wu, Jiaxin
> 发送时间: 2024年2月23日 13:36
> 收件人: gaoliming ; Kinney, Michael D
> ; Zhang, Di ; Li, Fei
> 
> 抄送: devel@edk2.groups.io
> 主题: Re: [edk2-devel] [PATCH v3 0/2] SMM CPU Optimization
> 
> Talked with Di & Liming,
> 
> Those 2 patches don't need to catch this stable tag 202402. Please ignore
the
> request here.
> 
> Thanks,
> Jiaxin
> 
> > -Original Message-
> > From: Wu, Jiaxin
> > Sent: Friday, February 23, 2024 8:47 AM
> > To: gaoliming ; Kinney, Michael D
> > 
> > Cc: devel@edk2.groups.io
> > Subject: RE: [edk2-devel] [PATCH v3 0/2] SMM CPU Optimization
> >
> > Hi Mike,
> >
> > Could you help approval below 2 patches into the stable tag 202402? The
> > patches have been merged.
> >
> > UefiCpuPkg/PiSmmCpuDxeSmm: Avoid BspIndex typecasting
> > UefiCpuPkg/PiSmmCpuDxeSmm: Check BspIndex first before lock cmpxchg
> >
> >
> > Thanks,
> > Jiaxin
> >
> >
> > > -Original Message-
> > > From: gaoliming 
> > > Sent: Thursday, February 22, 2024 10:48 PM
> > > To: Wu, Jiaxin 
> > > Subject: 回复: [edk2-devel] [PATCH v3 0/2] SMM CPU Optimization
> > >
> > > Jiaxin:
> > >   I see you merge this patch set in hard freeze. If you want this
patch set
> > > to catch this stable tag 202402, you need to reply the mail in mail
list and
> > > get the stewards approval. If this patch set is not to catch this
stable
> > > tag, I will not include it in this stable tag.
> > >
> > > Thanks
> > > Liming
> > > > -邮件原件-
> > > > 发件人: devel@edk2.groups.io  代表 Wu,
> Jiaxin
> > > > 发送时间: 2024年2月6日 15:58
> > > > 收件人: devel@edk2.groups.io
> > > > 主题: [edk2-devel] [PATCH v3 0/2] SMM CPU Optimization
> > > >
> > > > In V3 patch set, drop the patch to update the CheckFeatureSupported.
> > > >
> > > > The new patch set only focus on the BspIndex refinement.
> > > >
> > > > Jiaxin Wu (2):
> > > >   UefiCpuPkg/PiSmmCpuDxeSmm: Avoid BspIndex typecasting
> > > >   UefiCpuPkg/PiSmmCpuDxeSmm: Check BspIndex first before lock
> > cmpxchg
> > > >
> > > >  UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 22
> 
> > --
> > > >  1 file changed, 12 insertions(+), 10 deletions(-)
> > > >
> > > > --
> > > > 2.16.2.windows.1
> > > >
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> 
> 
> 
> 
> 





-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115868): https://edk2.groups.io/g/devel/message/115868
Mute This Topic: https://groups.io/mt/104523832/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v3 0/2] SMM CPU Optimization

2024-02-22 Thread Wu, Jiaxin
Talked with Di & Liming, 

Those 2 patches don't need to catch this stable tag 202402. Please ignore the 
request here.

Thanks,
Jiaxin 

> -Original Message-
> From: Wu, Jiaxin
> Sent: Friday, February 23, 2024 8:47 AM
> To: gaoliming ; Kinney, Michael D
> 
> Cc: devel@edk2.groups.io
> Subject: RE: [edk2-devel] [PATCH v3 0/2] SMM CPU Optimization
> 
> Hi Mike,
> 
> Could you help approval below 2 patches into the stable tag 202402? The
> patches have been merged.
> 
> UefiCpuPkg/PiSmmCpuDxeSmm: Avoid BspIndex typecasting
> UefiCpuPkg/PiSmmCpuDxeSmm: Check BspIndex first before lock cmpxchg
> 
> 
> Thanks,
> Jiaxin
> 
> 
> > -Original Message-
> > From: gaoliming 
> > Sent: Thursday, February 22, 2024 10:48 PM
> > To: Wu, Jiaxin 
> > Subject: 回复: [edk2-devel] [PATCH v3 0/2] SMM CPU Optimization
> >
> > Jiaxin:
> >   I see you merge this patch set in hard freeze. If you want this patch set
> > to catch this stable tag 202402, you need to reply the mail in mail list and
> > get the stewards approval. If this patch set is not to catch this stable
> > tag, I will not include it in this stable tag.
> >
> > Thanks
> > Liming
> > > -邮件原件-
> > > 发件人: devel@edk2.groups.io  代表 Wu, Jiaxin
> > > 发送时间: 2024年2月6日 15:58
> > > 收件人: devel@edk2.groups.io
> > > 主题: [edk2-devel] [PATCH v3 0/2] SMM CPU Optimization
> > >
> > > In V3 patch set, drop the patch to update the CheckFeatureSupported.
> > >
> > > The new patch set only focus on the BspIndex refinement.
> > >
> > > Jiaxin Wu (2):
> > >   UefiCpuPkg/PiSmmCpuDxeSmm: Avoid BspIndex typecasting
> > >   UefiCpuPkg/PiSmmCpuDxeSmm: Check BspIndex first before lock
> cmpxchg
> > >
> > >  UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 22 
> --
> > >  1 file changed, 12 insertions(+), 10 deletions(-)
> > >
> > > --
> > > 2.16.2.windows.1
> > >
> > >
> > >
> > > 
> > >
> >
> >



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115867): https://edk2.groups.io/g/devel/message/115867
Mute This Topic: https://groups.io/mt/104194203/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [edk2-platforms][PATCH V3] Silicon/Marvell: Update for UEFI spec v2.9 - mantis #1866

2024-02-22 Thread Gahan
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4689

Bug 4689 - GetInfo() of Adapter Information Protocol
should have a provision for IHV to return no data for
UEFI Spec compliance 2.9 [mantis #1866]

Cc: Marcin Wojtas 
Cc: Leif Lindholm 
Signed-off-by: Gahan Saraiya 
---
 Silicon/Marvell/Drivers/Net/Pp2Dxe/Pp2Dxe.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Silicon/Marvell/Drivers/Net/Pp2Dxe/Pp2Dxe.c 
b/Silicon/Marvell/Drivers/Net/Pp2Dxe/Pp2Dxe.c
index 5e463ac932..517b21940d 100644
--- a/Silicon/Marvell/Drivers/Net/Pp2Dxe/Pp2Dxe.c
+++ b/Silicon/Marvell/Drivers/Net/Pp2Dxe/Pp2Dxe.c
@@ -1394,6 +1394,7 @@ Pp2DxeSnpInstall (

   @retval EFI_SUCCESSThe InformationType information was 
retrieved.
   @retval EFI_UNSUPPORTEDThe InformationType is not known.
+  @retval EFI_NOT_FOUND  Information is not available for the 
requested information type.
   @retval EFI_DEVICE_ERROR   The device reported an error.
   @retval EFI_OUT_OF_RESOURCES   The request could not be completed due to 
a lack of resources.
   @retval EFI_INVALID_PARAMETER  This is NULL.
--
2.39.2.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115866): https://edk2.groups.io/g/devel/message/115866
Mute This Topic: https://groups.io/mt/104523659/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v3 1/6] UefiCpuPkg/MpInitLib: Add support for multiple HOBs to GetMpHandOffHob

2024-02-22 Thread Ni, Ray
> +  @param[in] MpHandOff  Previous HOB body.  Pass NULL to get the
> first HOB.

Can you replace "...HOB Body.  Pass NULL..." with "...HOB Body. Pass NULL..."?
Your current comments contain two spaces.

With that, Reviewed-by: Ray Ni 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115865): https://edk2.groups.io/g/devel/message/115865
Mute This Topic: https://groups.io/mt/104510907/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v3 6/6] UefiCpuPkg/MpInitLib: return early in GetBspNumber()

2024-02-22 Thread Ni, Ray
> +  ASSERT (FALSE);

How about ASSERT (EFI_NOT_FOUND)? Which is more meaningful than FALSE.

No matter you change or not, Reviewed-by: Ray Ni 

> +  return 0;
>  }
> 
>  /**
> --
> 2.43.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115864): https://edk2.groups.io/g/devel/message/115864
Mute This Topic: https://groups.io/mt/104510913/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v3 5/6] UefiCpuPkg/MpInitLib: Add support for multiple HOBs to SaveCpuMpData()

2024-02-22 Thread Ni, Ray



Thanks,
Ray
> -Original Message-
> From: Gerd Hoffmann 
> Sent: Friday, February 23, 2024 12:01 AM
> To: devel@edk2.groups.io
> Cc: Laszlo Ersek ; Ni, Ray ; Kumar,
> Rahul R ; Oliver Steffen ;
> Gerd Hoffmann 
> Subject: [PATCH v3 5/6] UefiCpuPkg/MpInitLib: Add support for multiple
> HOBs to SaveCpuMpData()
> 
> Add support for splitting Hand-Off data into multiple HOBs.
> This is required for VMs with thousands of CPUs.
> 
> Signed-off-by: Gerd Hoffmann 
> ---
>  UefiCpuPkg/Library/MpInitLib/PeiMpLib.c | 44 +++--
>  1 file changed, 27 insertions(+), 17 deletions(-)
> 
> diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c
> b/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c
> index f80e00edcff3..00d48c2ab531 100644
> --- a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c
> +++ b/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c
> @@ -126,35 +126,45 @@ SaveCpuMpData (
>IN CPU_MP_DATA  *CpuMpData
>)
>  {
> +  UINT32   MaxCpusPerHob, CpusInHob;
>UINT64   Data64;
> -  UINTNIndex;
> +  UINT32   Index, HobBase;

Can you please split the local variable declarations in multiple lines?
With that, Reviewed-by: Ray Ni 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115863): https://edk2.groups.io/g/devel/message/115863
Mute This Topic: https://groups.io/mt/104510911/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v3 0/2] SMM CPU Optimization

2024-02-22 Thread Wu, Jiaxin
Hi Mike, 

Could you help approval below 2 patches into the stable tag 202402? The patches 
have been merged.

UefiCpuPkg/PiSmmCpuDxeSmm: Avoid BspIndex typecasting
UefiCpuPkg/PiSmmCpuDxeSmm: Check BspIndex first before lock cmpxchg


Thanks,
Jiaxin 


> -Original Message-
> From: gaoliming 
> Sent: Thursday, February 22, 2024 10:48 PM
> To: Wu, Jiaxin 
> Subject: 回复: [edk2-devel] [PATCH v3 0/2] SMM CPU Optimization
> 
> Jiaxin:
>   I see you merge this patch set in hard freeze. If you want this patch set
> to catch this stable tag 202402, you need to reply the mail in mail list and
> get the stewards approval. If this patch set is not to catch this stable
> tag, I will not include it in this stable tag.
> 
> Thanks
> Liming
> > -邮件原件-
> > 发件人: devel@edk2.groups.io  代表 Wu, Jiaxin
> > 发送时间: 2024年2月6日 15:58
> > 收件人: devel@edk2.groups.io
> > 主题: [edk2-devel] [PATCH v3 0/2] SMM CPU Optimization
> >
> > In V3 patch set, drop the patch to update the CheckFeatureSupported.
> >
> > The new patch set only focus on the BspIndex refinement.
> >
> > Jiaxin Wu (2):
> >   UefiCpuPkg/PiSmmCpuDxeSmm: Avoid BspIndex typecasting
> >   UefiCpuPkg/PiSmmCpuDxeSmm: Check BspIndex first before lock cmpxchg
> >
> >  UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 22 --
> >  1 file changed, 12 insertions(+), 10 deletions(-)
> >
> > --
> > 2.16.2.windows.1
> >
> >
> >
> > 
> >
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115862): https://edk2.groups.io/g/devel/message/115862
Mute This Topic: https://groups.io/mt/104194203/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v2 4/5] UefiCpuPkg/MpInitLib: Add support for multiple HOBs to MpInitLibInitialize

2024-02-22 Thread Ni, Ray
I prefer HOB instead of dynamic PCD.
And let's keep the new singleton HOB structure as an internal interface between
PEI MpInitLib and DXE MpInitLib.


Thanks,
Ray
> -Original Message-
> From: Gerd Hoffmann 
> Sent: Thursday, February 22, 2024 8:29 PM
> To: Laszlo Ersek 
> Cc: devel@edk2.groups.io; Oliver Steffen ; Kumar,
> Rahul R ; Ni, Ray 
> Subject: Re: [edk2-devel] [PATCH v2 4/5] UefiCpuPkg/MpInitLib: Add support
> for multiple HOBs to MpInitLibInitialize
> 
>   Hi,
> 
> > The code looks otherwise OK, but I'm not happy that
> > WaitLoopExecutionMode (and StartupSignalValue) are replicated over all
> > the HOBs, just like in v1. IMO, that will only make it harder for others
> > to understand the code / data structures, and therefore it increases
> > technical debt.
> >
> > I understand that Ray is OK with that, so I won't try to block the
> > patch, but I'm not comfortable giving it an R-b myself, due to the
> > increase in technical debt.
> 
> I can try to address that, but this certainly will be a separate
> patch.
> 
> Given that the HOB structure is defined in locally in the library
> I assume this is considered private and there are no compatibility
> concerns when changing the structs?
> 
> Any preference where the fields should be moved to?  PCD?  Separate
> HOB?  Something else?
> 
> take care,
>   Gerd



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115861): https://edk2.groups.io/g/devel/message/115861
Mute This Topic: https://groups.io/mt/104472311/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v2 02/23] MdePkg: GHCB APIC ID retrieval support definitions

2024-02-22 Thread Ni, Ray


> +//
> +// Get APIC IDs
> +//
> +#define EFI_APIC_IDS_GUID  \
> +  { 0xbc964338, 0xee39, 0x4fc8, { 0xa2, 0x24, 0x10, 0x10, 0x8b, 0x17, 0x80,
> 0x1b }}
> +extern EFI_GUID  gEfiApicIdsGuid;

Since the above GUID is associated with the structure below, how about
rename the GUID from "gEfiApicIdsGuid" which is very general to a specific
name "gGhcbApicIdsGuid"?

+ @Yao, Jiewen, @Xu, Min M  for comments.

> +
> +typedef struct {
> +  UINT32NumEntries;
> +  UINT32ApicIds[];
> +} GHCB_APIC_IDS;
> +
>  //
>  // SEV-ES save area mapping structures used for SEV-SNP AP Creation.
>  // Only the fields required to be set to a non-zero value are defined.
> --
> 2.42.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115860): https://edk2.groups.io/g/devel/message/115860
Mute This Topic: https://groups.io/mt/104512930/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] GuestPhysAddrSize questions

2024-02-22 Thread Paolo Bonzini
On Thu, Feb 22, 2024 at 5:13 PM Paolo Bonzini  wrote:
> Also, to clarify the hardware behavior, if hCR4.LA57=0 and host
> PhysAddrSize==52, then will guest physical addresses above 2^48
>
> 1) cause a reserved #PF in the guest, or
>
> 2) cause a non-present NPF exit in the hypervisor?
>
> I remember that several years ago we had a discussion on hCR4.LA57=0
> reducing the address space compared to MAXPHYADDR, but I cannot find the
> emails and also at the time I didn't notice GuestPhysAddrSize.

Found them! They say that "according to the design document, CPU will
report #NPF if the guest references a PA that is greater than 48 bits
while the hypervisor is in 4-level nested paging mode". That's nice,
because it's the same behavior as the affected Intel processors.

Paolo

> Anyhow, basically we would like GuestPhysAddrSize to be "redefined" as
>
> Maximum usable physical address size in bits.  Physical addresses
> above this size should not be used, but will not produce a "reserved"
> page fault.  When this field is zero, all bits up to PhysAddrSize are
> usable.  This field is expected to be nonzero only on guests where
> the hypervisor is using nested paging.



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115859): https://edk2.groups.io/g/devel/message/115859
Mute This Topic: https://groups.io/mt/104510523/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v2 23/23] OvmfPkg/BaseMemEncryptLib: Check for presence of an SVSM when not at VMPL0

2024-02-22 Thread Lendacky, Thomas via groups.io
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4654

Currently, an SEV-SNP guest will terminate if it is not running at VMPL0.
The requirement for running at VMPL0 is removed if an SVSM is present.

Update the current VMPL0 check to additionally check for the presence of
an SVSM is the guest is not running at VMPL0.

Acked-by: Gerd Hoffmann 
Signed-off-by: Tom Lendacky 
---
 OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecSnpSystemRamValidate.c | 9 
++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecSnpSystemRamValidate.c 
b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecSnpSystemRamValidate.c
index ca279d77274b..f2d9f7cf2fea 100644
--- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecSnpSystemRamValidate.c
+++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecSnpSystemRamValidate.c
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "SnpPageStateChange.h"
 
@@ -74,10 +75,12 @@ MemEncryptSevSnpPreValidateSystemRam (
 
   //
   // The page state change uses the PVALIDATE instruction. The instruction
-  // can be run on VMPL-0 only. If its not VMPL-0 guest then terminate
-  // the boot.
+  // can be run at VMPL-0 only. If its not a VMPL-0 guest, then an SVSM must
+  // be present to perform the operation on behalf of the guest. If the guest
+  // is not running at VMPL-0 and an SVSM is not present, then terminate the
+  // boot.
   //
-  if (!SevSnpIsVmpl0 ()) {
+  if (!SevSnpIsVmpl0 () && !CcSvsmIsSvsmPresent ()) {
 SnpPageStateFailureTerminate ();
   }
 
-- 
2.42.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115858): https://edk2.groups.io/g/devel/message/115858
Mute This Topic: https://groups.io/mt/104512987/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v2 22/23] Ovmfpkg/CcExitLib: Provide SVSM discovery support

2024-02-22 Thread Lendacky, Thomas via groups.io
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4654

The SVSM specification documents an alternative method of discovery for
the SVSM using a reserved CPUID bit and a reserved MSR.

For the CPUID support, the #VC handler of an SEV-SNP guest should modify
the returned value in the EAX register for the 0x801f CPUID function
by setting bit 28 when an SVSM is present.

For the MSR support, new reserved MSR 0xc001f000 has been defined. A #VC
should be generated when accessing this MSR. The #VC handler is expected
to ignore writes to this MSR and return the physical calling area address
(CAA) on reads of this MSR.

Signed-off-by: Tom Lendacky 
---
 OvmfPkg/Library/CcExitLib/CcExitLib.inf |  3 +-
 OvmfPkg/Library/CcExitLib/SecCcExitLib.inf  |  3 +-
 OvmfPkg/Library/CcExitLib/CcExitVcHandler.c | 29 ++--
 3 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/OvmfPkg/Library/CcExitLib/CcExitLib.inf 
b/OvmfPkg/Library/CcExitLib/CcExitLib.inf
index bc75cd5f5a04..692143acd9ad 100644
--- a/OvmfPkg/Library/CcExitLib/CcExitLib.inf
+++ b/OvmfPkg/Library/CcExitLib/CcExitLib.inf
@@ -1,7 +1,7 @@
 ## @file
 #  CcExitLib Library.
 #
-#  Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+#  Copyright (C) 2020 - 2024, Advanced Micro Devices, Inc. All rights 
reserved.
 #  Copyright (C) 2020 - 2022, Intel Corporation. All rights reserved.
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -41,6 +41,7 @@ [LibraryClasses]
   DebugLib
   LocalApicLib
   MemEncryptSevLib
+  CcSvsmLib
 
 [Pcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidBase
diff --git a/OvmfPkg/Library/CcExitLib/SecCcExitLib.inf 
b/OvmfPkg/Library/CcExitLib/SecCcExitLib.inf
index 811269dd2c06..6778c1af6516 100644
--- a/OvmfPkg/Library/CcExitLib/SecCcExitLib.inf
+++ b/OvmfPkg/Library/CcExitLib/SecCcExitLib.inf
@@ -1,7 +1,7 @@
 ## @file
 #  VMGEXIT Support Library.
 #
-#  Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+#  Copyright (C) 2020 - 2024, Advanced Micro Devices, Inc. All rights 
reserved.
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
 ##
@@ -41,6 +41,7 @@ [LibraryClasses]
   LocalApicLib
   MemEncryptSevLib
   PcdLib
+  CcSvsmLib
 
 [FixedPcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBackupBase
diff --git a/OvmfPkg/Library/CcExitLib/CcExitVcHandler.c 
b/OvmfPkg/Library/CcExitLib/CcExitVcHandler.c
index 0fc30f7bc4f6..edb4b57655d4 100644
--- a/OvmfPkg/Library/CcExitLib/CcExitVcHandler.c
+++ b/OvmfPkg/Library/CcExitLib/CcExitVcHandler.c
@@ -1,7 +1,7 @@
 /** @file
   X64 #VC Exception Handler functon.
 
-  Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+  Copyright (C) 2020 - 2024, Advanced Micro Devices, Inc. All rights 
reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -713,10 +714,29 @@ MsrExit (
   IN CC_INSTRUCTION_DATA *InstructionData
   )
 {
-  UINT64  ExitInfo1, Status;
+  MSR_SVSM_CAA_REGISTER  Msr;
+  UINT64 ExitInfo1;
+  UINT64 Status;
 
   ExitInfo1 = 0;
 
+  //
+  // The SVSM CAA MSR is a software implemented MSR and not supported
+  // by the hardware, handle it directly.
+  //
+  if (Regs->Rax == MSR_SVSM_CAA) {
+// Writes to the SVSM CAA MSR are ignored
+if (*(InstructionData->OpCodes + 1) == 0x30) {
+  return 0;
+}
+
+Msr.Uint64 = CcSvsmSnpGetCaa ();
+Regs->Rax  = Msr.Bits.Lower32Bits;
+Regs->Rdx  = Msr.Bits.Upper32Bits;
+
+return 0;
+  }
+
   switch (*(InstructionData->OpCodes + 1)) {
 case 0x30: // WRMSR
   ExitInfo1  = 1;
@@ -1388,6 +1408,11 @@ GetCpuidFw (
 *Ebx = (*Ebx & 0xFF00) | (Ebx2 & 0x00FF);
 /* node ID */
 *Ecx = (*Ecx & 0xFF00) | (Ecx2 & 0x00FF);
+  } else if (EaxIn == 0x801F) {
+/* Set the SVSM feature bit if running under an SVSM */
+if (CcSvsmIsSvsmPresent ()) {
+  *Eax |= BIT28;
+}
   }
 
 Out:
-- 
2.42.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115857): https://edk2.groups.io/g/devel/message/115857
Mute This Topic: https://groups.io/mt/104512981/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v2 21/23] UefiCpuPkg/MpInitLib: AP creation support under an SVSM

2024-02-22 Thread Lendacky, Thomas via groups.io
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4654

When running under an SVSM, the VMPL level of the APs that are started
must match the VMPL level provided by the SVSM. Additionally, each AP
must have a Calling Area for use with the SVSM protocol. Update the AP
creation to properly support running under an SVSM.

Acked-by: Ray Ni 
Acked-by: Gerd Hoffmann 
Signed-off-by: Tom Lendacky 
---
 UefiCpuPkg/Library/MpInitLib/X64/AmdSev.c | 28 +---
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.c 
b/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.c
index bb4a52b25cd2..681a47669a47 100644
--- a/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.c
+++ b/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.c
@@ -44,7 +44,8 @@ SevSnpPerformApAction (
 
   if (Action == SVM_VMGEXIT_SNP_AP_CREATE) {
 //
-// Turn the page into a recognized VMSA page.
+// Turn the page into a recognized VMSA page. When an SVSM is present
+// the page following the VMSA is the Calling Area page.
 //
 VmsaStatus = CcSvsmSnpVmsaRmpAdjust (SaveArea, ApicId, TRUE);
 if (EFI_ERROR (VmsaStatus)) {
@@ -56,6 +57,7 @@ SevSnpPerformApAction (
   }
 
   ExitInfo1  = (UINT64)ApicId << 32;
+  ExitInfo1 |= (UINT64)SaveArea->Vmpl << 16;
   ExitInfo1 |= Action;
   ExitInfo2  = (UINT64)(UINTN)SaveArea;
 
@@ -87,8 +89,9 @@ SevSnpPerformApAction (
 
   if (Action == SVM_VMGEXIT_SNP_AP_DESTROY) {
 //
-// Make the current VMSA not runnable and accessible to be
-// reprogrammed.
+// Make the current VMSA not runnable and accessible to be reprogrammed.
+// When an SVSM is present the page following the VMSA is the Calling Area
+// page.
 //
 VmsaStatus = CcSvsmSnpVmsaRmpAdjust (SaveArea, ApicId, FALSE);
 if (EFI_ERROR (VmsaStatus)) {
@@ -116,6 +119,7 @@ SevSnpCreateSaveArea (
   UINT32  ApicId
   )
 {
+  UINTN PageCount;
   UINT8 *Pages;
   SEV_ES_SAVE_AREA  *SaveArea;
   IA32_CR0  ApCr0;
@@ -125,13 +129,19 @@ SevSnpCreateSaveArea (
   UINTN StartIp;
   UINT8 SipiVector;
 
+  //
+  // When running under an SVSM, a Calling Area page is also needed and is
+  // always the page following the VMSA.
+  //
+  PageCount = CcSvsmIsSvsmPresent () ? 2 : 1;
+
   if (CpuData->SevEsSaveArea == NULL) {
 //
 // Allocate a page for the SEV-ES Save Area and initialize it. Due to AMD
 // erratum #1467 (VMSA cannot be on a 2MB boundary), allocate an extra page
 // to choose from to work around the issue.
 //
-Pages = AllocateReservedPages (2);
+Pages = AllocateReservedPages (PageCount + 1);
 if (!Pages) {
   return;
 }
@@ -140,12 +150,12 @@ SevSnpCreateSaveArea (
 // Since page allocation works by allocating downward in the address space,
 // try to always free the first (lower address) page to limit possible 
holes
 // in the memory map. So, if the address of the second page is 2MB aligned,
-// then use the first page and free the second page. Otherwise, free the
+// then use the first page and free the last page. Otherwise, free the
 // first page and use the second page.
 //
 if (_IS_ALIGNED (Pages + EFI_PAGE_SIZE, SIZE_2MB)) {
   SaveArea = (SEV_ES_SAVE_AREA *)Pages;
-  FreePages (Pages + EFI_PAGE_SIZE, 1);
+  FreePages (Pages + (EFI_PAGE_SIZE * PageCount), 1);
 } else {
   SaveArea = (SEV_ES_SAVE_AREA *)(Pages + EFI_PAGE_SIZE);
   FreePages (Pages, 1);
@@ -163,7 +173,7 @@ SevSnpCreateSaveArea (
 }
   }
 
-  ZeroMem (SaveArea, EFI_PAGE_SIZE);
+  ZeroMem (SaveArea, EFI_PAGE_SIZE * PageCount);
 
   //
   // Propogate the CR0.NW and CR0.CD setting to the AP
@@ -239,10 +249,10 @@ SevSnpCreateSaveArea (
 
   //
   // Set the SEV-SNP specific fields for the save area:
-  //   VMPL - always VMPL0
+  //   VMPL - based on current mode
   //   SEV_FEATURES - equivalent to the SEV_STATUS MSR right shifted 2 bits
   //
-  SaveArea->Vmpl= 0;
+  SaveArea->Vmpl= CcSvsmSnpGetVmpl ();
   SaveArea->SevFeatures = AsmReadMsr64 (MSR_SEV_STATUS) >> 2;
 
   SevSnpPerformApAction (SaveArea, ApicId, SVM_VMGEXIT_SNP_AP_CREATE);
-- 
2.42.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115856): https://edk2.groups.io/g/devel/message/115856
Mute This Topic: https://groups.io/mt/104512980/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v2 20/23] OvmfPkg/CcSvsmLib: Add support for the SVSM create/delete vCPU calls

2024-02-22 Thread Lendacky, Thomas via groups.io
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4654

The RMPADJUST instruction is used to alter the VMSA attribute of a page,
but the VMSA attribute can only be changed when running at VMPL0. When
an SVSM is present, use the SVSM_CORE_CREATE_VCPU and SVSM_CORE_DELTE_VCPU
calls to add or remove the VMSA attribute on a page instead of issuing
the RMPADJUST instruction directly.

Implement the CcSvsmSnpVmsaRmpAdjust() API to perform the proper operation
to update the VMSA attribute.

Signed-off-by: Tom Lendacky 
---
 OvmfPkg/Library/CcSvsmLib/CcSvsmLib.c | 54 +++-
 1 file changed, 53 insertions(+), 1 deletion(-)

diff --git a/OvmfPkg/Library/CcSvsmLib/CcSvsmLib.c 
b/OvmfPkg/Library/CcSvsmLib/CcSvsmLib.c
index 017ca715cee5..97fe09aa7329 100644
--- a/OvmfPkg/Library/CcSvsmLib/CcSvsmLib.c
+++ b/OvmfPkg/Library/CcSvsmLib/CcSvsmLib.c
@@ -377,6 +377,57 @@ CcSvsmSnpPvalidate (
   CcSvsmIsSvsmPresent () ? SvsmPvalidate (Info) : BasePvalidate (Info);
 }
 
+/**
+  Perform an RMPADJUST operation to alter the VMSA setting of a page.
+
+  Add or remove the VMSA attribute for a page.
+
+  @param[in]   Vmsa   Pointer to an SEV-ES save area page
+  @param[in]   ApicId APIC ID associated with the VMSA
+  @param[in]   SetVmsaBoolean indicator as to whether to set or
+  or clear the VMSA setting for the page
+
+  @retval  EFI_SUCCESSRMPADJUST operation successful
+  @retval  EFI_UNSUPPORTEDOperation is not supported
+  @retval  EFI_INVALID_PARAMETER  RMPADJUST operation failed, an invalid
+  parameter was supplied
+
+**/
+STATIC
+EFI_STATUS
+SvsmVmsaRmpAdjust (
+  IN SEV_ES_SAVE_AREA  *Vmsa,
+  IN UINT32ApicId,
+  IN BOOLEAN   SetVmsa
+  )
+{
+  SVSM_CALL_DATA  SvsmCallData;
+  SVSM_FUNCTION   Function;
+  UINTN   Ret;
+
+  SvsmCallData.Caa = (SVSM_CAA *)CcSvsmSnpGetCaa ();
+
+  Function.Id.Protocol = 0;
+
+  if (SetVmsa) {
+Function.Id.CallId = 2;
+
+SvsmCallData.RaxIn = Function.Uint64;
+SvsmCallData.RcxIn = (UINT64)(UINTN)Vmsa;
+SvsmCallData.RdxIn = (UINT64)(UINTN)Vmsa + SIZE_4KB;
+SvsmCallData.R8In  = ApicId;
+  } else {
+Function.Id.CallId = 3;
+
+SvsmCallData.RaxIn = Function.Uint64;
+SvsmCallData.RcxIn = (UINT64)(UINTN)Vmsa;
+  }
+
+  Ret = SvsmMsrProtocol ();
+
+  return (Ret == 0) ? EFI_SUCCESS : EFI_INVALID_PARAMETER;
+}
+
 /**
   Perform a native RMPADJUST operation to alter the VMSA setting of a page.
 
@@ -444,5 +495,6 @@ CcSvsmSnpVmsaRmpAdjust (
   IN BOOLEAN   SetVmsa
   )
 {
-  return BaseVmsaRmpAdjust (Vmsa, SetVmsa);
+  return CcSvsmIsSvsmPresent () ? SvsmVmsaRmpAdjust (Vmsa, ApicId, SetVmsa)
+: BaseVmsaRmpAdjust (Vmsa, SetVmsa);
 }
-- 
2.42.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115855): https://edk2.groups.io/g/devel/message/115855
Mute This Topic: https://groups.io/mt/104512977/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v2 19/23] OvmfPkg/BaseMemEncryptSevLib: Maximize Page State Change efficiency

2024-02-22 Thread Lendacky, Thomas via groups.io
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4654

Similar to the Page State Change optimization added previously, also take
into account the possiblity of using the SVSM for PVALIDATE instructions.
Conditionally adjust the maximum number of entries based on how many
entries the SVSM calling area can support.

Signed-off-by: Tom Lendacky 
---
 OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c | 7 
+++
 1 file changed, 7 insertions(+)

diff --git 
a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c 
b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c
index 4e1225d12797..7060cd61b21c 100644
--- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c
+++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c
@@ -18,6 +18,7 @@
 
 #include 
 #include 
+#include 
 
 #include "SnpPageStateChange.h"
 
@@ -78,6 +79,7 @@ BuildPageStateBuffer (
   UINTN Index;
   UINTN IndexMax;
   UINTN PscIndexMax;
+  UINTN SvsmIndexMax;
 
   // Clear the page state structure
   SetMem (Info, InfoSize, 0);
@@ -96,6 +98,11 @@ BuildPageStateBuffer (
 IndexMax = MIN (IndexMax, PscIndexMax);
   }
 
+  SvsmIndexMax = (IndexMax / SVSM_PVALIDATE_MAX_ENTRY) * 
SVSM_PVALIDATE_MAX_ENTRY;
+  if (SvsmIndexMax > 0) {
+IndexMax = MIN (IndexMax, SvsmIndexMax);
+  }
+
   //
   // Populate the page state entry structure
   //
-- 
2.42.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115854): https://edk2.groups.io/g/devel/message/115854
Mute This Topic: https://groups.io/mt/104512975/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v2 18/23] OvmfPkg/CcSvsmLib: Add support for the SVSM_CORE_PVALIDATE call

2024-02-22 Thread Lendacky, Thomas via groups.io
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4654

The PVALIDATE instruction can only be performed at VMPL0. An SVSM will
be present when running at VMPL1 or higher.

When an SVSM is present, use the SVSM_CORE_PVALIDATE call to perform
memory validation instead of issuing the PVALIDATE instruction directly.

Signed-off-by: Tom Lendacky 
---
 OvmfPkg/Library/CcSvsmLib/CcSvsmLib.c | 183 +++-
 1 file changed, 182 insertions(+), 1 deletion(-)

diff --git a/OvmfPkg/Library/CcSvsmLib/CcSvsmLib.c 
b/OvmfPkg/Library/CcSvsmLib/CcSvsmLib.c
index f45ae472783c..017ca715cee5 100644
--- a/OvmfPkg/Library/CcSvsmLib/CcSvsmLib.c
+++ b/OvmfPkg/Library/CcSvsmLib/CcSvsmLib.c
@@ -8,6 +8,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -43,6 +44,78 @@ SnpTerminate (
   CpuDeadLoop ();
 }
 
+/**
+  Issue an SVSM request.
+
+  Invokes the SVSM to process a request on behalf of the guest.
+
+  @param[in,out]  SvsmCallData  Pointer to the SVSM call data
+
+  @return   Contents of RAX upon return from VMGEXIT
+**/
+STATIC
+UINTN
+SvsmMsrProtocol (
+  IN OUT SVSM_CALL_DATA  *SvsmCallData
+  )
+{
+  MSR_SEV_ES_GHCB_REGISTER  Msr;
+  UINT64CurrentMsr;
+  UINT8 Pending;
+  BOOLEAN   InterruptState;
+  UINTN Ret;
+
+  do {
+//
+// Be sure that an interrupt can't cause a #VC while the GHCB MSR protocol
+// is being used (#VC handler will ASSERT if lower 12-bits are not zero).
+//
+InterruptState = GetInterruptState ();
+if (InterruptState) {
+  DisableInterrupts ();
+}
+
+Pending   = 0;
+SvsmCallData->CallPending = 
+
+CurrentMsr = AsmReadMsr64 (MSR_SEV_ES_GHCB);
+
+Msr.Uint64  = 0;
+Msr.SnpVmplRequest.Function = GHCB_INFO_SNP_VMPL_REQUEST;
+Msr.SnpVmplRequest.Vmpl = 0;
+AsmWriteMsr64 (MSR_SEV_ES_GHCB, Msr.Uint64);
+
+//
+// Guest memory is used for the guest-SVSM communication, so fence the
+// invocation of the VMGEXIT instruction to ensure VMSA accesses are
+// synchronized properly.
+//
+MemoryFence ();
+Ret = AsmVmgExitSvsm (SvsmCallData);
+MemoryFence ();
+
+Msr.Uint64 = AsmReadMsr64 (MSR_SEV_ES_GHCB);
+
+AsmWriteMsr64 (MSR_SEV_ES_GHCB, CurrentMsr);
+
+if (InterruptState) {
+  EnableInterrupts ();
+}
+
+if (Pending != 0) {
+  SnpTerminate ();
+}
+
+if ((Msr.SnpVmplResponse.Function != GHCB_INFO_SNP_VMPL_RESPONSE) ||
+(Msr.SnpVmplResponse.ErrorCode != 0))
+{
+  SnpTerminate ();
+}
+  } while (Ret == SVSM_ERR_INCOMPLETE || Ret == SVSM_ERR_BUSY);
+
+  return Ret;
+}
+
 /**
   Report the presence of an Secure Virtual Services Module (SVSM).
 
@@ -109,6 +182,114 @@ CcSvsmSnpGetCaa (
   return CcSvsmIsSvsmPresent () ? SvsmInfo->SvsmCaa : 0;
 }
 
+/**
+  Issue an SVSM request to perform the PVALIDATE instruction.
+
+  Invokes the SVSM to process the PVALIDATE instruction on behalf of the
+  guest to validate or invalidate the memory range specified.
+
+  @param[in]   Info   Pointer to a page state change structure
+
+**/
+STATIC
+VOID
+SvsmPvalidate (
+  IN SNP_PAGE_STATE_CHANGE_INFO  *Info
+  )
+{
+  SVSM_CALL_DATA  SvsmCallData;
+  SVSM_CAA*Caa;
+  SVSM_PVALIDATE_REQUEST  *Request;
+  SVSM_FUNCTION   Function;
+  BOOLEAN Validate;
+  UINTN   Entry;
+  UINTN   EntryLimit;
+  UINTN   Index;
+  UINTN   EndIndex;
+  UINT64  Gfn;
+  UINT64  GfnEnd;
+  UINTN   Ret;
+
+  Caa = (SVSM_CAA *)CcSvsmSnpGetCaa ();
+  SetMem (Caa->SvsmBuffer, sizeof (Caa->SvsmBuffer), 0);
+
+  Function.Id.Protocol = 0;
+  Function.Id.CallId   = 1;
+
+  Request= (SVSM_PVALIDATE_REQUEST *)Caa->SvsmBuffer;
+  EntryLimit = ((sizeof (Caa->SvsmBuffer) - sizeof (*Request)) /
+sizeof (Request->Entry[0])) - 1;
+
+  SvsmCallData.Caa   = Caa;
+  SvsmCallData.RaxIn = Function.Uint64;
+  SvsmCallData.RcxIn = (UINT64)(UINTN)Request;
+
+  Entry= 0;
+  Index= Info->Header.CurrentEntry;
+  EndIndex = Info->Header.EndEntry;
+
+  while (Index <= EndIndex) {
+Validate = Info->Entry[Index].Operation == SNP_PAGE_STATE_PRIVATE;
+
+Request->Header.Entries++;
+Request->Entry[Entry].Bits.PageSize = Info->Entry[Index].PageSize;
+Request->Entry[Entry].Bits.Action   = (Validate == TRUE) ? 1 : 0;
+Request->Entry[Entry].Bits.IgnoreCf = 0;
+Request->Entry[Entry].Bits.Address  = Info->Entry[Index].GuestFrameNumber;
+
+Entry++;
+if ((Entry > EntryLimit) || (Index == EndIndex)) {
+  Ret = SvsmMsrProtocol ();
+  if ((Ret == SVSM_ERR_PVALIDATE_FAIL_SIZE_MISMATCH) &&
+  (Request->Entry[Request->Header.Next].Bits.PageSize != 0))
+  {
+// Calculate the Index of the entry after the entry that failed
+// before clearing 

[edk2-devel] [PATCH v2 17/23] OvmfPkg: Create a calling area used to communicate with the SVSM

2024-02-22 Thread Lendacky, Thomas via groups.io
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4654

An SVSM requires a calling area page whose address (CAA) is used by the
SVSM to communicate and process the SVSM request.

Add a pre-defined page area to the OvmfPkg and AmdSev packages and define
corresponding PCDs used to communicate the location and size of the area.
Keep the AmdSev package in sync with the OvmfPkg and adjust the AmdSev
launch and hash area memory locations.

Signed-off-by: Tom Lendacky 
---
 OvmfPkg/OvmfPkg.dec |  4 
 OvmfPkg/AmdSev/AmdSevX64.fdf|  9 ++---
 OvmfPkg/OvmfPkgX64.fdf  |  3 +++
 OvmfPkg/PlatformPei/PlatformPei.inf |  2 ++
 OvmfPkg/ResetVector/ResetVector.inf |  2 ++
 OvmfPkg/PlatformPei/AmdSev.c| 11 +++
 OvmfPkg/ResetVector/ResetVector.nasmb   |  6 --
 OvmfPkg/ResetVector/X64/OvmfSevMetadata.asm | 11 ++-
 8 files changed, 42 insertions(+), 6 deletions(-)

diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec
index fbc81e4c8070..2f7bded9260b 100644
--- a/OvmfPkg/OvmfPkg.dec
+++ b/OvmfPkg/OvmfPkg.dec
@@ -338,6 +338,10 @@ [PcdsFixedAtBuild]
   ## Restrict boot to EFI applications in firmware volumes.
   gUefiOvmfPkgTokenSpaceGuid.PcdBootRestrictToFirmware|FALSE|BOOLEAN|0x6c
 
+  ## The base address and size of the initial SVSM Calling Area.
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecSvsmCaaBase|0|UINT32|0x70
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecSvsmCaaSize|0|UINT32|0x71
+
 [PcdsDynamic, PcdsDynamicEx]
   gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent|0|UINT64|2
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable|FALSE|BOOLEAN|0x10
diff --git a/OvmfPkg/AmdSev/AmdSevX64.fdf b/OvmfPkg/AmdSev/AmdSevX64.fdf
index 9dd409596780..dafa5ebacbaf 100644
--- a/OvmfPkg/AmdSev/AmdSevX64.fdf
+++ b/OvmfPkg/AmdSev/AmdSevX64.fdf
@@ -68,13 +68,16 @@ [FD.MEMFD]
 0x00E000|0x001000
 
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidBase|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidSize
 
-0x00F000|0x000C00
+0x00F000|0x001000
+gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecSvsmCaaBase|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecSvsmCaaSize
+
+0x01|0x000C00
 
gUefiOvmfPkgTokenSpaceGuid.PcdSevLaunchSecretBase|gUefiOvmfPkgTokenSpaceGuid.PcdSevLaunchSecretSize
 
-0x00FC00|0x000400
+0x010C00|0x000400
 
gUefiOvmfPkgTokenSpaceGuid.PcdQemuHashTableBase|gUefiOvmfPkgTokenSpaceGuid.PcdQemuHashTableSize
 
-0x01|0x01
+0x011000|0x00F000
 
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize
 
 0x02|0x0E
diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf
index f47ab1727e4c..f12844f674e7 100644
--- a/OvmfPkg/OvmfPkgX64.fdf
+++ b/OvmfPkg/OvmfPkgX64.fdf
@@ -94,6 +94,9 @@ [FD.MEMFD]
 0x00E000|0x001000
 
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidBase|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidSize
 
+0x00F000|0x001000
+gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecSvsmCaaBase|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecSvsmCaaSize
+
 0x01|0x01
 
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize
 
diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf 
b/OvmfPkg/PlatformPei/PlatformPei.inf
index 7de3b4341c2c..126085db0204 100644
--- a/OvmfPkg/PlatformPei/PlatformPei.inf
+++ b/OvmfPkg/PlatformPei/PlatformPei.inf
@@ -128,6 +128,8 @@ [FixedPcd]
   gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBackupBase
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBackupSize
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecSvsmCaaBase
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecSvsmCaaSize
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaSize
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsBase
diff --git a/OvmfPkg/ResetVector/ResetVector.inf 
b/OvmfPkg/ResetVector/ResetVector.inf
index a4154ca90c28..0f5f8fec0b77 100644
--- a/OvmfPkg/ResetVector/ResetVector.inf
+++ b/OvmfPkg/ResetVector/ResetVector.inf
@@ -62,5 +62,7 @@ [FixedPcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdSevLaunchSecretSize
   gUefiOvmfPkgTokenSpaceGuid.PcdQemuHashTableBase
   gUefiOvmfPkgTokenSpaceGuid.PcdQemuHashTableSize
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecSvsmCaaBase
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecSvsmCaaSize
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsBase
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsSize
diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c
index 472cf13f0faa..66f480ee1c5d 100644
--- a/OvmfPkg/PlatformPei/AmdSev.c
+++ b/OvmfPkg/PlatformPei/AmdSev.c
@@ -554,5 +554,16 @@ SevInitializeRam (
   (UINT64)(UINTN)PcdGet32 (PcdOvmfCpuidSize),
   EfiReservedMemoryType
   );
+
+//
+// The calling area memory needs to be protected until the OS can create
+// its own calling area. Mark it as EfiReservedMemoryType so that the
+// guest firmware and OS do not use it as a system memory.
+//
+BuildMemoryAllocationHob (
+  

[edk2-devel] [PATCH v2 16/23] OvmfPkg/BaseMemEncryptSevLib: Use CcSvsmSnpPvalidate() to validate pages

2024-02-22 Thread Lendacky, Thomas via groups.io
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4654

The PVALIDATE instruction is used to change the SNP validation of a page,
but that can only be done when running at VMPL0. To prepare for running at
a less priviledged VMPL, use the CcSvsmLib library API to perform the
PVALIDATE. The CcSvsmLib library will perform the proper operation on
behalf of the caller.

Signed-off-by: Tom Lendacky 
---
 OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf  |  3 +-
 OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf  |  3 +-
 OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf  |  3 +-
 OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c | 74 
+---
 4 files changed, 9 insertions(+), 74 deletions(-)

diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf 
b/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf
index cc24961c9265..7397e5cfb810 100644
--- a/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf
+++ b/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf
@@ -1,7 +1,7 @@
 ## @file
 #  Library provides the helper functions for SEV guest
 #
-# Copyright (c) 2017 - 2020, Advanced Micro Devices. All rights reserved.
+# Copyright (c) 2017 - 2024, Advanced Micro Devices. All rights reserved.
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -52,6 +52,7 @@ [LibraryClasses]
   MemoryAllocationLib
   PcdLib
   CcExitLib
+  CcSvsmLib
 
 [FeaturePcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire
diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf 
b/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf
index 8f56783da55e..55928f9e386c 100644
--- a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf
+++ b/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf
@@ -1,7 +1,7 @@
 ## @file
 #  Library provides the helper functions for SEV guest
 #
-# Copyright (c) 2020 Advanced Micro Devices. All rights reserved.
+# Copyright (c) 2020 - 2024, Advanced Micro Devices. All rights reserved.
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -52,6 +52,7 @@ [LibraryClasses]
   MemoryAllocationLib
   PcdLib
   CcExitLib
+  CcSvsmLib
 
 [FeaturePcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire
diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf 
b/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf
index b6d76e7e630f..e373f9f010ba 100644
--- a/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf
+++ b/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf
@@ -1,7 +1,7 @@
 ## @file
 #  Library provides the helper functions for SEV guest
 #
-# Copyright (c) 2020 Advanced Micro Devices. All rights reserved.
+# Copyright (c) 2020 - 2024, Advanced Micro Devices. All rights reserved.
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -49,6 +49,7 @@ [LibraryClasses]
   DebugLib
   PcdLib
   CcExitLib
+  CcSvsmLib
 
 [FixedPcd]
   gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase
diff --git 
a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c 
b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c
index f1883239a661..4e1225d12797 100644
--- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c
+++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c
@@ -14,14 +14,13 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
 
 #include "SnpPageStateChange.h"
 
-#define PAGES_PER_LARGE_ENTRY  512
-
 STATIC
 UINTN
 MemoryStateToGhcbOp (
@@ -63,73 +62,6 @@ SnpPageStateFailureTerminate (
   CpuDeadLoop ();
 }
 
-/**
- This function issues the PVALIDATE instruction to validate or invalidate the 
memory
- range specified. If PVALIDATE returns size mismatch then it retry validating 
with
- smaller page size.
-
- */
-STATIC
-VOID
-PvalidateRange (
-  IN  SNP_PAGE_STATE_CHANGE_INFO  *Info
-  )
-{
-  UINTN RmpPageSize;
-  UINTN StartIndex;
-  UINTN EndIndex;
-  UINTN Index;
-  UINTN Ret;
-  EFI_PHYSICAL_ADDRESS  Address;
-  BOOLEAN   Validate;
-
-  StartIndex = Info->Header.CurrentEntry;
-  EndIndex   = Info->Header.EndEntry;
-
-  for ( ; StartIndex <= EndIndex; StartIndex++) {
-//
-// Get the address and the page size from the Info.
-//
-Address = 
((EFI_PHYSICAL_ADDRESS)Info->Entry[StartIndex].GuestFrameNumber) << 
EFI_PAGE_SHIFT;
-RmpPageSize = Info->Entry[StartIndex].PageSize;
-Validate= Info->Entry[StartIndex].Operation == SNP_PAGE_STATE_PRIVATE;
-
-Ret = AsmPvalidate (RmpPageSize, Validate, Address);
-
-//
-// If we fail to validate due to size mismatch then try with the
-// smaller page size. This senario will occur if the backing page in
-// the RMP entry is 4K and we are validating it as a 2MB.
-//
-if ((Ret == PVALIDATE_RET_SIZE_MISMATCH) && (RmpPageSize == 

[edk2-devel] [PATCH v2 15/23] UefiCpuPkg/MpInitLib: Use CcSvsmSnpVmsaRmpAdjust() to set/clear VMSA

2024-02-22 Thread Lendacky, Thomas via groups.io
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4654

The RMPADJUST instruction is used to change the VMSA attribute of a page,
but the VMSA attribute can only be changed when running at VMPL0. To
prepare for running at a less priviledged VMPL, use the CcSvsmLib library
API to perform the RMPADJUST. The CcSvsmLib library will perform the
proper operation on behalf of the caller.

Signed-off-by: Tom Lendacky 
---
 UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf |  1 +
 UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf |  1 +
 UefiCpuPkg/Library/MpInitLib/MpLib.h  | 14 -
 UefiCpuPkg/Library/MpInitLib/Ia32/AmdSev.c| 20 
 UefiCpuPkg/Library/MpInitLib/X64/AmdSev.c | 54 +++-
 5 files changed, 9 insertions(+), 81 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf 
b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
index 538a2146ff24..1b6abc4440cb 100644
--- a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
@@ -57,6 +57,7 @@ [LibraryClasses]
   SynchronizationLib
   PcdLib
   CcExitLib
+  CcSvsmLib
   MicrocodeLib
 [LibraryClasses.X64]
   CpuPageTableLib
diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf 
b/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf
index 622baec45e2f..9077114b1e6d 100644
--- a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf
+++ b/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf
@@ -53,6 +53,7 @@ [LibraryClasses]
   PeiServicesLib
   PcdLib
   CcExitLib
+  CcSvsmLib
   MicrocodeLib
 
 [Pcd]
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h 
b/UefiCpuPkg/Library/MpInitLib/MpLib.h
index 617f7401aea8..53a25c4634a1 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
@@ -870,20 +870,6 @@ FillExchangeInfoDataSevEs (
   IN volatile MP_CPU_EXCHANGE_INFO  *ExchangeInfo
   );
 
-/**
-  Issue RMPADJUST to adjust the VMSA attribute of an SEV-SNP page.
-
-  @param[in]  PageAddress
-  @param[in]  VmsaPage
-
-  @return  RMPADJUST return value
-**/
-UINT32
-SevSnpRmpAdjust (
-  IN  EFI_PHYSICAL_ADDRESS  PageAddress,
-  IN  BOOLEAN   VmsaPage
-  );
-
 /**
   Create an SEV-SNP AP save area (VMSA) for use in running the vCPU.
 
diff --git a/UefiCpuPkg/Library/MpInitLib/Ia32/AmdSev.c 
b/UefiCpuPkg/Library/MpInitLib/Ia32/AmdSev.c
index 0478e92317f1..963bd62494b9 100644
--- a/UefiCpuPkg/Library/MpInitLib/Ia32/AmdSev.c
+++ b/UefiCpuPkg/Library/MpInitLib/Ia32/AmdSev.c
@@ -49,26 +49,6 @@ SevSnpCreateAP (
   ASSERT (FALSE);
 }
 
-/**
-  Issue RMPADJUST to adjust the VMSA attribute of an SEV-SNP page.
-
-  @param[in]  PageAddress
-  @param[in]  VmsaPage
-
-  @return  RMPADJUST return value
-**/
-UINT32
-SevSnpRmpAdjust (
-  IN  EFI_PHYSICAL_ADDRESS  PageAddress,
-  IN  BOOLEAN   VmsaPage
-  )
-{
-  //
-  // RMPADJUST is not supported in 32-bit mode
-  //
-  return RETURN_UNSUPPORTED;
-}
-
 /**
   Determine if the SEV-SNP AP Create protocol should be used.
 
diff --git a/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.c 
b/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.c
index 5d92c441adcd..bb4a52b25cd2 100644
--- a/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.c
+++ b/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.c
@@ -10,6 +10,7 @@
 
 #include "MpLib.h"
 #include 
+#include 
 #include 
 #include 
 
@@ -38,20 +39,15 @@ SevSnpPerformApAction (
   BOOLEAN   InterruptState;
   UINT64ExitInfo1;
   UINT64ExitInfo2;
-  UINT32RmpAdjustStatus;
   UINT64VmgExitStatus;
+  EFI_STATUSVmsaStatus;
 
   if (Action == SVM_VMGEXIT_SNP_AP_CREATE) {
 //
-// To turn the page into a recognized VMSA page, issue RMPADJUST:
-//   Target VMPL but numerically higher than current VMPL
-//   Target PermissionMask is not used
+// Turn the page into a recognized VMSA page.
 //
-RmpAdjustStatus = SevSnpRmpAdjust (
-(EFI_PHYSICAL_ADDRESS)(UINTN)SaveArea,
-TRUE
-);
-if (RmpAdjustStatus != 0) {
+VmsaStatus = CcSvsmSnpVmsaRmpAdjust (SaveArea, ApicId, TRUE);
+if (EFI_ERROR (VmsaStatus)) {
   DEBUG ((DEBUG_INFO, "SEV-SNP: RMPADJUST failed for VMSA creation\n"));
   ASSERT (FALSE);
 
@@ -94,11 +90,8 @@ SevSnpPerformApAction (
 // Make the current VMSA not runnable and accessible to be
 // reprogrammed.
 //
-RmpAdjustStatus = SevSnpRmpAdjust (
-(EFI_PHYSICAL_ADDRESS)(UINTN)SaveArea,
-FALSE
-);
-if (RmpAdjustStatus != 0) {
+VmsaStatus = CcSvsmSnpVmsaRmpAdjust (SaveArea, ApicId, FALSE);
+if (EFI_ERROR (VmsaStatus)) {
   DEBUG ((DEBUG_INFO, "SEV-SNP: RMPADJUST failed for VMSA reset\n"));
   ASSERT (FALSE);
 
@@ -328,39 +321,6 @@ SevSnpCreateAP (
   }
 }
 
-/**
-  Issue RMPADJUST to adjust the VMSA attribute of an SEV-SNP page.
-
-  @param[in]  PageAddress
-  @param[in]  VmsaPage

[edk2-devel] [PATCH v2 14/23] Ovmfpkg/CcSvsmLib: Create CcSvsmLib to handle SVSM related services

2024-02-22 Thread Lendacky, Thomas via groups.io
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4654

Add initial support for the new CcSvsmLib library to OvmfPkg. The initial
implementation will fully implement the SVSM presence check API and the
SVSM VMPL API, with later patches fully implementing the other interfaces.

The SVSM presence check, CcSvsmIsSvsmPresent(), determines the presence
of an SVSM by checking if an SVSM has been advertised in the SEV-SNP
Secrets Page. The SVSM VMPL API, CcSvsmSnpGetVmpl(), returns the VMPL
level at which OVMF is currently running.

Signed-off-by: Tom Lendacky 
---
 OvmfPkg/AmdSev/AmdSevX64.dsc|   1 +
 OvmfPkg/Bhyve/BhyveX64.dsc  |   1 +
 OvmfPkg/CloudHv/CloudHvX64.dsc  |   1 +
 OvmfPkg/IntelTdx/IntelTdxX64.dsc|   1 +
 OvmfPkg/Microvm/MicrovmX64.dsc  |   1 +
 OvmfPkg/OvmfPkgIa32.dsc |   1 +
 OvmfPkg/OvmfPkgIa32X64.dsc  |   3 +-
 OvmfPkg/OvmfPkgX64.dsc  |   1 +
 OvmfPkg/OvmfXen.dsc |   1 +
 OvmfPkg/Library/CcSvsmLib/CcSvsmLib.inf |  38 +++
 OvmfPkg/Library/CcSvsmLib/CcSvsmLib.c   | 267 
 11 files changed, 315 insertions(+), 1 deletion(-)

diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc
index a31a89344a60..be0bfe3b017d 100644
--- a/OvmfPkg/AmdSev/AmdSevX64.dsc
+++ b/OvmfPkg/AmdSev/AmdSevX64.dsc
@@ -208,6 +208,7 @@ [LibraryClasses]
 [LibraryClasses.common]
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
   CcExitLib|OvmfPkg/Library/CcExitLib/CcExitLib.inf
+  CcSvsmLib|OvmfPkg/Library/CcSvsmLib/CcSvsmLib.inf
   TdxLib|MdePkg/Library/TdxLib/TdxLib.inf
   TdxMailboxLib|OvmfPkg/Library/TdxMailboxLib/TdxMailboxLibNull.inf
 
diff --git a/OvmfPkg/Bhyve/BhyveX64.dsc b/OvmfPkg/Bhyve/BhyveX64.dsc
index 9689a2f14efa..69e5c33126a3 100644
--- a/OvmfPkg/Bhyve/BhyveX64.dsc
+++ b/OvmfPkg/Bhyve/BhyveX64.dsc
@@ -234,6 +234,7 @@ [LibraryClasses]
 [LibraryClasses.common]
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
   CcExitLib|UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf
+  CcSvsmLib|UefiCpuPkg/Library/CcSvsmLibNull/CcSvsmLibNull.inf
   TdxLib|MdePkg/Library/TdxLib/TdxLib.inf
 
 [LibraryClasses.common.SEC]
diff --git a/OvmfPkg/CloudHv/CloudHvX64.dsc b/OvmfPkg/CloudHv/CloudHvX64.dsc
index b522fa10594d..31d8da0a1a61 100644
--- a/OvmfPkg/CloudHv/CloudHvX64.dsc
+++ b/OvmfPkg/CloudHv/CloudHvX64.dsc
@@ -244,6 +244,7 @@ [LibraryClasses]
 [LibraryClasses.common]
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
   CcExitLib|OvmfPkg/Library/CcExitLib/CcExitLib.inf
+  CcSvsmLib|OvmfPkg/Library/CcSvsmLib/CcSvsmLib.inf
   TdxLib|MdePkg/Library/TdxLib/TdxLib.inf
   TdxMailboxLib|OvmfPkg/Library/TdxMailboxLib/TdxMailboxLibNull.inf
 
diff --git a/OvmfPkg/IntelTdx/IntelTdxX64.dsc b/OvmfPkg/IntelTdx/IntelTdxX64.dsc
index 82e3e41cfc57..6fbe4bb17573 100644
--- a/OvmfPkg/IntelTdx/IntelTdxX64.dsc
+++ b/OvmfPkg/IntelTdx/IntelTdxX64.dsc
@@ -215,6 +215,7 @@ [LibraryClasses]
 [LibraryClasses.common]
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
   CcExitLib|OvmfPkg/Library/CcExitLib/CcExitLib.inf
+  CcSvsmLib|UefiCpuPkg/Library/CcSvsmLibNull/CcSvsmLibNull.inf
   TdxLib|MdePkg/Library/TdxLib/TdxLib.inf
   TdxMailboxLib|OvmfPkg/Library/TdxMailboxLib/TdxMailboxLib.inf
   PlatformInitLib|OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf
diff --git a/OvmfPkg/Microvm/MicrovmX64.dsc b/OvmfPkg/Microvm/MicrovmX64.dsc
index 063324cd0572..7110c4805acf 100644
--- a/OvmfPkg/Microvm/MicrovmX64.dsc
+++ b/OvmfPkg/Microvm/MicrovmX64.dsc
@@ -242,6 +242,7 @@ [LibraryClasses]
 [LibraryClasses.common]
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
   CcExitLib|OvmfPkg/Library/CcExitLib/CcExitLib.inf
+  CcSvsmLib|OvmfPkg/Library/CcSvsmLib/CcSvsmLib.inf
   
SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf
   
PlatformHookLib|MdeModulePkg/Library/BasePlatformHookLibNull/BasePlatformHookLibNull.inf
   FdtLib|EmbeddedPkg/Library/FdtLib/FdtLib.inf
diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc
index 28379961a78e..dc9d7233da15 100644
--- a/OvmfPkg/OvmfPkgIa32.dsc
+++ b/OvmfPkg/OvmfPkgIa32.dsc
@@ -251,6 +251,7 @@ [LibraryClasses]
 [LibraryClasses.common]
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
   CcExitLib|UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf
+  CcSvsmLib|UefiCpuPkg/Library/CcSvsmLibNull/CcSvsmLibNull.inf
   TdxMailboxLib|OvmfPkg/Library/TdxMailboxLib/TdxMailboxLibNull.inf
 
 [LibraryClasses.common.SEC]
diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc
index 5e9eee628aea..afdb33023e85 100644
--- a/OvmfPkg/OvmfPkgIa32X64.dsc
+++ b/OvmfPkg/OvmfPkgIa32X64.dsc
@@ -4,7 +4,7 @@
 #  Copyright (c) 2006 - 2023, Intel Corporation. All rights reserved.
 #  (C) Copyright 2016 Hewlett Packard Enterprise Development LP
 #  Copyright (c) Microsoft Corporation.
-#  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+#  Copyright (C) 

[edk2-devel] [PATCH v2 13/23] UefiPayloadPkg: Prepare UefiPayloadPkg to use the CcSvsmLib library

2024-02-22 Thread Lendacky, Thomas via groups.io
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4654

The MpInitLib library will be updated to use the new CcSvsmLib library.
To prevent any build breakage, update the UefiPayloadPkg DSC file to
include the CcSvsmLib NULL library.

Signed-off-by: Tom Lendacky 
---
 UefiPayloadPkg/UefiPayloadPkg.dsc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc 
b/UefiPayloadPkg/UefiPayloadPkg.dsc
index 0e142bb7c2a2..2d468b43a786 100644
--- a/UefiPayloadPkg/UefiPayloadPkg.dsc
+++ b/UefiPayloadPkg/UefiPayloadPkg.dsc
@@ -331,6 +331,7 @@ [LibraryClasses]
   
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf
   
VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
   CcExitLib|UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf
+  CcSvsmLib|UefiCpuPkg/Library/CcSvsmLibNull/CcSvsmLibNull.inf
   
ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf
   FdtLib|MdePkg/Library/BaseFdtLib/BaseFdtLib.inf
 [LibraryClasses.common]
-- 
2.42.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115848): https://edk2.groups.io/g/devel/message/115848
Mute This Topic: https://groups.io/mt/104512961/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v2 12/23] UefiCpuPkg/CcSvsmLib: Create the CcSvsmLib library to support an SVSM

2024-02-22 Thread Lendacky, Thomas via groups.io
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4654

In order to support an SEV-SNP guest running under an SVSM at VMPL1 or
lower, a new CcSvsmLib library must be created.

This library includes an interface to detect if running under an SVSM, an
interface to return the current VMPL, an interface to perform memory
validation and an interface to set or clear the attribute that allows a
page to be used as a VMSA.

Signed-off-by: Tom Lendacky 
---
 UefiCpuPkg/UefiCpuPkg.dec  |   5 +-
 UefiCpuPkg/UefiCpuPkg.dsc  |   4 +-
 UefiCpuPkg/Library/CcSvsmLibNull/CcSvsmLibNull.inf |  27 +
 UefiCpuPkg/Include/Library/CcSvsmLib.h | 101 ++
 UefiCpuPkg/Library/CcSvsmLibNull/CcSvsmLibNull.c   | 108 
 UefiCpuPkg/Library/CcSvsmLibNull/CcSvsmLibNull.uni |  13 +++
 6 files changed, 256 insertions(+), 2 deletions(-)

diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec
index 571b59b36f0a..4a383c6d1d4d 100644
--- a/UefiCpuPkg/UefiCpuPkg.dec
+++ b/UefiCpuPkg/UefiCpuPkg.dec
@@ -2,7 +2,7 @@
 # This Package provides UEFI compatible CPU modules and libraries.
 #
 # Copyright (c) 2007 - 2023, Intel Corporation. All rights reserved.
-# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+# Copyright (C) 2023 - 2024, Advanced Micro Devices, Inc. All rights 
reserved.
 #
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -52,6 +52,9 @@ [LibraryClasses.IA32, LibraryClasses.X64]
   ##  @libraryclass  Provides function to support CcExit processing.
   CcExitLib|Include/Library/CcExitLib.h
 
+  ##  @libraryclass  Provides function to support CcSvsm processing.
+  CcSvsmLib|Include/Library/CcSvsmLib.h
+
   ##  @libraryclass  Provides function to get CPU cache information.
   CpuCacheInfoLib|Include/Library/CpuCacheInfoLib.h
 
diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc
index 10b33594e586..1ee726e6c6b5 100644
--- a/UefiCpuPkg/UefiCpuPkg.dsc
+++ b/UefiCpuPkg/UefiCpuPkg.dsc
@@ -2,7 +2,7 @@
 #  UefiCpuPkg Package
 #
 #  Copyright (c) 2007 - 2023, Intel Corporation. All rights reserved.
-#  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+#  Copyright (C) 2023 - 2024, Advanced Micro Devices, Inc. All rights 
reserved.
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -61,6 +61,7 @@ [LibraryClasses]
   
PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeCoffExtraActionLibNull.inf
   
TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf
   CcExitLib|UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf
+  CcSvsmLib|UefiCpuPkg/Library/CcSvsmLibNull/CcSvsmLibNull.inf
   MicrocodeLib|UefiCpuPkg/Library/MicrocodeLib/MicrocodeLib.inf
   
SmmCpuRendezvousLib|UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf
   CpuPageTableLib|UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableLib.inf
@@ -159,6 +160,7 @@ [Components.IA32, Components.X64]
   UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf
   UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.inf
   UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf
+  UefiCpuPkg/Library/CcSvsmLibNull/CcSvsmLibNull.inf
   UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationPei.inf
   UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationSmm.inf
   UefiCpuPkg/SecCore/SecCore.inf
diff --git a/UefiCpuPkg/Library/CcSvsmLibNull/CcSvsmLibNull.inf 
b/UefiCpuPkg/Library/CcSvsmLibNull/CcSvsmLibNull.inf
new file mode 100644
index ..b45a75941a8a
--- /dev/null
+++ b/UefiCpuPkg/Library/CcSvsmLibNull/CcSvsmLibNull.inf
@@ -0,0 +1,27 @@
+## @file
+#  CcSvsm Base Support Library.
+#
+#  Copyright (C) 2024, Advanced Micro Devices, Inc. All rights reserved.
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION= 1.29
+  BASE_NAME  = CcSvsmLibNull
+  MODULE_UNI_FILE= CcSvsmLibNull.uni
+  FILE_GUID  = 62b45e0f-c9b4-45ce-a5b3-41762709b3d9
+  MODULE_TYPE= BASE
+  VERSION_STRING = 1.0
+  LIBRARY_CLASS  = CcSvsmLib
+
+[Sources.common]
+  CcSvsmLibNull.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  UefiCpuPkg/UefiCpuPkg.dec
+
+[LibraryClasses]
+  BaseLib
+
diff --git a/UefiCpuPkg/Include/Library/CcSvsmLib.h 
b/UefiCpuPkg/Include/Library/CcSvsmLib.h
new file mode 100644
index ..4715f4db3bd1
--- /dev/null
+++ b/UefiCpuPkg/Include/Library/CcSvsmLib.h
@@ -0,0 +1,101 @@
+/** @file
+  Public header file for the CcSvsmLib.
+
+  This library class defines some routines used for invoking an SVSM when the
+  guest is not running at VMPL0.
+
+  Copyright (C) 2024, Advanced Micro Devices, Inc. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef CC_SVSM_LIB_H_
+#define CC_SVSM_LIB_H_
+
+#include 
+#include 
+
+/**
+  Report the presence of an Secure Virtual Services Module (SVSM).
+
+  Determines the 

[edk2-devel] [PATCH v2 11/23] MdePkg/BaseLib: Add a new VMGEXIT instruction invocation for SVSM

2024-02-22 Thread Lendacky, Thomas via groups.io
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4654

The SVSM specification relies on a specific register calling convention to
hold the parameters that are associated with the SVSM request. The SVSM is
invoked by requesting the hypervisor to run the VMPL0 VMSA of the guest
using the GHCB MSR Protocol or a GHCB NAE event.

Create a new version of the VMGEXIT instruction that will adhere to this
calling convention and load the SVSM function arguments into the proper
register before invoking the VMGEXIT instruction. On return, perform the
atomic exchange on the SVSM call pending value as specified in the SVSM
specification.

Signed-off-by: Tom Lendacky 
---
 MdePkg/Library/BaseLib/BaseLib.inf   |  2 +
 MdePkg/Include/Library/BaseLib.h | 39 
 MdePkg/Library/BaseLib/Ia32/VmgExitSvsm.nasm | 39 
 MdePkg/Library/BaseLib/X64/VmgExitSvsm.nasm  | 94 
 4 files changed, 174 insertions(+)

diff --git a/MdePkg/Library/BaseLib/BaseLib.inf 
b/MdePkg/Library/BaseLib/BaseLib.inf
index 4dbe94be71e1..26e66a8d67cf 100644
--- a/MdePkg/Library/BaseLib/BaseLib.inf
+++ b/MdePkg/Library/BaseLib/BaseLib.inf
@@ -187,6 +187,7 @@ [Sources.Ia32]
   Ia32/XGetBv.nasm
   Ia32/XSetBv.nasm
   Ia32/VmgExit.nasm
+  Ia32/VmgExitSvsm.nasm
 
   Ia32/DivS64x64Remainder.c
   Ia32/InternalSwitchStack.c | MSFT
@@ -328,6 +329,7 @@ [Sources.X64]
   X64/XGetBv.nasm
   X64/XSetBv.nasm
   X64/VmgExit.nasm
+  X64/VmgExitSvsm.nasm
   ChkStkGcc.c  | GCC
 
 [Sources.EBC]
diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/BaseLib.h
index 1fff0fb224f1..95f805599d9d 100644
--- a/MdePkg/Include/Library/BaseLib.h
+++ b/MdePkg/Include/Library/BaseLib.h
@@ -7876,6 +7876,45 @@ AsmVmgExit (
   VOID
   );
 
+///
+/// The structure used to supply and return data to and from the SVSM.
+///
+typedef struct {
+  VOID  *Caa;
+  UINT64RaxIn;
+  UINT64RcxIn;
+  UINT64RdxIn;
+  UINT64R8In;
+  UINT64R9In;
+  UINT64RaxOut;
+  UINT64RcxOut;
+  UINT64RdxOut;
+  UINT64R8Out;
+  UINT64R9Out;
+  UINT8 *CallPending;
+} SVSM_CALL_DATA;
+
+/**
+  Executes a VMGEXIT instruction (VMMCALL with a REP prefix) with arguments
+  and return code
+
+  Executes a VMGEXIT instruction placing the specified arguments in the
+  corresponding registers before invocation. Upon return an XCHG is done to
+  atomically clear and retrieve the SVSM call pending value. The returned RAX
+  register value becomes the function return code. This function is intended
+  for use with an SVSM. This function is only available on IA-32 and x64.
+
+  @param[in,out]  SvsmCallPending  Pointer to the location of the SVSM call 
data
+
+  @return  Value of the RAX register on return
+
+**/
+UINT32
+EFIAPI
+AsmVmgExitSvsm (
+  IN OUT SVSM_CALL_DATA  *SvsmCallData
+  );
+
 /**
   Patch the immediate operand of an IA32 or X64 instruction such that the byte,
   word, dword or qword operand is encoded at the end of the instruction's
diff --git a/MdePkg/Library/BaseLib/Ia32/VmgExitSvsm.nasm 
b/MdePkg/Library/BaseLib/Ia32/VmgExitSvsm.nasm
new file mode 100644
index ..14717bd1af02
--- /dev/null
+++ b/MdePkg/Library/BaseLib/Ia32/VmgExitSvsm.nasm
@@ -0,0 +1,39 @@
+;--
+;
+; Copyright (C) 2024, Advanced Micro Devices, Inc. All rights reserved.
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;
+; Module Name:
+;
+;   VmgExitSvsm.Asm
+;
+; Abstract:
+;
+;   AsmVmgExitSvsm function
+;
+; Notes:
+;
+;--
+
+DEFAULT REL
+SECTION .text
+
+;--
+; UINT32
+; EFIAPI
+; AsmVmgExitSvsm (
+;   SVSM_CALL_DATA *SvsmCallData
+;   );
+;--
+global ASM_PFX(AsmVmgExitSvsm)
+ASM_PFX(AsmVmgExitSvsm):
+;
+; NASM doesn't support the vmmcall instruction in 32-bit mode and NASM versions
+; before 2.12 cannot translate the 64-bit "rep vmmcall" instruction into elf32
+; format. Given that VMGEXIT does not make sense on IA32, provide a stub
+; implementation that is identical to CpuBreakpoint(). In practice,
+; AsmVmgExitSvsm() should never be called on IA32.
+;
+int  3
+ret
+
diff --git a/MdePkg/Library/BaseLib/X64/VmgExitSvsm.nasm 
b/MdePkg/Library/BaseLib/X64/VmgExitSvsm.nasm
new file mode 100644
index ..b8af78890611
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/VmgExitSvsm.nasm
@@ -0,0 +1,94 @@
+;--
+;
+; Copyright (C) 2024, Advanced Micro Devices, Inc. All rights reserved.
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;
+; Module Name:
+;
+;   VmgExitSvsm.Asm
+;
+; Abstract:
+;
+;   AsmVmgExitSvsm function
+;
+; Notes:
+;

[edk2-devel] [PATCH v2 10/23] MdePkg/Register/Amd: Define the SVSM related information

2024-02-22 Thread Lendacky, Thomas via groups.io
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4654

The Secure VM Service Module specification defines the interfaces needed
to allow multi-VMPL level execution of an SEV-SNP guest.

Define the SVSM related structures for the SVSM Calling Area as well as
the SVSM CAA MSR. The SVSM CAA MSR is an MSR register that is reserved for
software use and will not be implemented in hardware.

Acked-by: Gerd Hoffmann 
Signed-off-by: Tom Lendacky 
---
 MdePkg/Include/Register/Amd/Fam17Msr.h |  19 +++-
 MdePkg/Include/Register/Amd/Msr.h  |   3 +-
 MdePkg/Include/Register/Amd/Svsm.h | 101 
 MdePkg/Include/Register/Amd/SvsmMsr.h  |  35 +++
 4 files changed, 156 insertions(+), 2 deletions(-)

diff --git a/MdePkg/Include/Register/Amd/Fam17Msr.h 
b/MdePkg/Include/Register/Amd/Fam17Msr.h
index bb4e143e2456..f2d5ccb39dc7 100644
--- a/MdePkg/Include/Register/Amd/Fam17Msr.h
+++ b/MdePkg/Include/Register/Amd/Fam17Msr.h
@@ -6,7 +6,7 @@
   returned is a single 32-bit or 64-bit value, then a data structure is not
   provided for that MSR.
 
-  Copyright (c) 2017, Advanced Micro Devices. All rights reserved.
+  Copyright (c) 2017 - 2024, Advanced Micro Devices. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
   @par Specification Reference:
@@ -71,9 +71,24 @@ typedef union {
 UINT32ErrorCode;
   } SnpPageStateChangeResponse;
 
+  struct {
+UINT64Function  : 12;
+UINT64Reserved1 : 20;
+UINT64Vmpl  : 8;
+UINT64Reserved2 : 56;
+  } SnpVmplRequest;
+
+  struct {
+UINT32Function : 12;
+UINT32Reserved : 20;
+UINT32ErrorCode;
+  } SnpVmplResponse;
+
   VOID  *Ghcb;
 
   UINT64GhcbPhysicalAddress;
+
+  UINT64Uint64;
 } MSR_SEV_ES_GHCB_REGISTER;
 
 #define GHCB_INFO_SEV_INFO1
@@ -84,6 +99,8 @@ typedef union {
 #define GHCB_INFO_GHCB_GPA_REGISTER_RESPONSE  19
 #define GHCB_INFO_SNP_PAGE_STATE_CHANGE_REQUEST   20
 #define GHCB_INFO_SNP_PAGE_STATE_CHANGE_RESPONSE  21
+#define GHCB_INFO_SNP_VMPL_REQUEST22
+#define GHCB_INFO_SNP_VMPL_RESPONSE   23
 #define GHCB_HYPERVISOR_FEATURES_REQUEST  128
 #define GHCB_HYPERVISOR_FEATURES_RESPONSE 129
 #define GHCB_INFO_TERMINATE_REQUEST   256
diff --git a/MdePkg/Include/Register/Amd/Msr.h 
b/MdePkg/Include/Register/Amd/Msr.h
index 084eb892cdd9..04a3cbeb4315 100644
--- a/MdePkg/Include/Register/Amd/Msr.h
+++ b/MdePkg/Include/Register/Amd/Msr.h
@@ -6,7 +6,7 @@
   returned is a single 32-bit or 64-bit value, then a data structure is not
   provided for that MSR.
 
-  Copyright (c) 2017 - 2019, Advanced Micro Devices. All rights reserved.
+  Copyright (c) 2017 - 2024, Advanced Micro Devices. All rights reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
   @par Specification Reference:
@@ -19,5 +19,6 @@
 
 #include 
 #include 
+#include 
 
 #endif
diff --git a/MdePkg/Include/Register/Amd/Svsm.h 
b/MdePkg/Include/Register/Amd/Svsm.h
new file mode 100644
index ..9a989f803107
--- /dev/null
+++ b/MdePkg/Include/Register/Amd/Svsm.h
@@ -0,0 +1,101 @@
+/** @file
+  Secure VM Service Module (SVSM) Definition.
+
+  Provides data types allowing an SEV-SNP guest to interact with the SVSM.
+
+  Copyright (C) 2024, Advanced Micro Devices, Inc. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+  @par Specification Reference:
+  Secure VM Service Module Specification
+
+**/
+
+#ifndef SVSM_H_
+#define SVSM_H_
+
+#include 
+#include 
+#include 
+
+//
+// The SVSM definitions are part of the SNP Secrets Page:
+//   An SVSM is considered present if the SvsmSize field is non-zero.
+//
+typedef PACKED struct {
+  UINT8 Reserved1[320];
+
+  UINT64SvsmBase;
+  UINT64SvsmSize;
+  UINT64SvsmCaa;
+  UINT32SvsmMaxVersion;
+  UINT8 SvsmGuestVmpl;
+  UINT8 Reserved2[3];
+} SVSM_INFORMATION;
+
+typedef PACKED struct {
+  UINT8SvsmCallPending;
+  UINT8SvsmMemAvailable;
+  UINT8Reserved1[6];
+
+  //
+  // The remainder of the CAA 4KB area can be used for argument
+  // passing to the SVSM.
+  //
+  UINT8SvsmBuffer[SIZE_4KB - 8];
+} SVSM_CAA;
+
+#define SVSM_SUCCESS   0x
+#define SVSM_ERR_INCOMPLETE0x8000
+#define SVSM_ERR_UNSUPPORTED_PROTOCOL  0x8001
+#define SVSM_ERR_UNSUPPORTED_CALL  0x8002
+#define SVSM_ERR_INVALID_ADDRESS   0x8003
+#define SVSM_ERR_INVALID_FORMAT0x8004
+#define SVSM_ERR_INVALID_PARAMETER 0x8005
+#define SVSM_ERR_INVALID_REQUEST   0x8006
+#define SVSM_ERR_BUSY  0x8007
+
+#define SVSM_ERR_PVALIDATE_FAIL_INPUT  0x80001001
+#define SVSM_ERR_PVALIDATE_FAIL_SIZE_MISMATCH  0x80001006
+#define SVSM_ERR_PVALIDATE_FAIL_NO_CHANGE  0x80001010
+
+typedef PACKED struct {
+  UINT16Entries;
+  UINT16Next;
+
+  UINT8 Reserved[4];
+} SVSM_PVALIDATE_HEADER;
+
+typedef union {
+  struct {
+UINT64

[edk2-devel] [PATCH v2 09/23] OvmfPkg/BaseMemEncryptSevLib: Maximize Page State Change efficiency

2024-02-22 Thread Lendacky, Thomas via groups.io
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4654

When building the Page State Change entries for a range of memory, it can
happen that multiple calls to BuildPageStateBuffer() need to be made. If
the size of the input work area passed to BuildPageStateBuffer() exceeds
the number of entries that can be passed to the hypervisor using the GHCB
shared buffer, the Page State Change VMGEXIT support will issue multiple
VMGEXITs to process all entries in the buffer.

However, it could be that the final VMGEXIT for each round of Page State
Changes is only for a small number of entries and subsequent VMGEXITs may
still be issued to handle the full range of memory requested. To maximize
the number of entries processed during the Page State Change VMGEXIT,
limit BuildPageStateBuffer() to not build entries that exceed the maximum
number of entries that can be handled in a single Page State Change
VMGEXIT.

Signed-off-by: Tom Lendacky 
---
 OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c | 11 
+++
 1 file changed, 11 insertions(+)

diff --git 
a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c 
b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c
index bcc0798d6b02..f1883239a661 100644
--- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c
+++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c
@@ -145,6 +145,7 @@ BuildPageStateBuffer (
   UINTN RmpPageSize;
   UINTN Index;
   UINTN IndexMax;
+  UINTN PscIndexMax;
 
   // Clear the page state structure
   SetMem (Info, InfoSize, 0);
@@ -153,6 +154,16 @@ BuildPageStateBuffer (
   IndexMax= (InfoSize - sizeof (Info->Header)) / sizeof (Info->Entry[0]);
   NextAddress = EndAddress;
 
+  //
+  // Make the use of the work area as efficient as possible relative to
+  // exiting from the guest to the hypervisor. Maximize the number of entries
+  // that can be processed per exit.
+  //
+  PscIndexMax = (IndexMax / SNP_PAGE_STATE_MAX_ENTRY) * 
SNP_PAGE_STATE_MAX_ENTRY;
+  if (PscIndexMax > 0) {
+IndexMax = MIN (IndexMax, PscIndexMax);
+  }
+
   //
   // Populate the page state entry structure
   //
-- 
2.42.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115844): https://edk2.groups.io/g/devel/message/115844
Mute This Topic: https://groups.io/mt/104512950/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v2 08/23] OvmfPkg/BaseMemEncryptSevLib: Re-organize page state change support

2024-02-22 Thread Lendacky, Thomas via groups.io
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4654

In preparation for running under an SVSM at VMPL1 or higher (higher
numerically, lower privilege), re-organize the way a page state change
is performed in order to free up the GHCB for use by the SVSM support.

Currently, the page state change logic directly uses the GHCB shared
buffer to build the page state change structures. However, this will be
in conflict with the use of the GHCB should an SVSM call be required.

Instead, use a separate buffer (an area in the workarea during SEC and
an allocated page during PEI/DXE) to hold the page state change request
and only update the GHCB shared buffer as needed.

Since the information is copied to, and operated on, in the GHCB shared
buffer this has the added benefit of not requiring to save the start and
end entries for use when validating the memory during the page state
change sequence.

Signed-off-by: Tom Lendacky 
---
 OvmfPkg/Include/WorkArea.h|   9 +-
 OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChange.h |   6 +-
 OvmfPkg/Library/BaseMemEncryptSevLib/X64/DxeSnpSystemRamValidate.c|  11 +-
 OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c|  27 
-
 OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValidate.c|  22 
+++-
 OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecSnpSystemRamValidate.c|  14 ++-
 OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c | 109 
+---
 7 files changed, 146 insertions(+), 52 deletions(-)

diff --git a/OvmfPkg/Include/WorkArea.h b/OvmfPkg/Include/WorkArea.h
index b1c7045ce18c..e3b415db2caa 100644
--- a/OvmfPkg/Include/WorkArea.h
+++ b/OvmfPkg/Include/WorkArea.h
@@ -2,7 +2,7 @@
 
   Work Area structure definition
 
-  Copyright (c) 2021, AMD Inc.
+  Copyright (c) 2021 - 2024, AMD Inc.
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 **/
@@ -54,6 +54,13 @@ typedef struct _SEC_SEV_ES_WORK_AREA {
   // detection in OvmfPkg/ResetVector/Ia32/AmdSev.c
   //
   UINT8 ReceivedVc;
+  UINT8 Reserved[7];
+
+  // Used by SEC to generate Page State Change requests. This should be
+  // sized less than an equal to the GHCB shared buffer area to allow a
+  // single call to the hypervisor.
+  //
+  UINT8 WorkBuffer[1024];
 } SEC_SEV_ES_WORK_AREA;
 
 //
diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChange.h 
b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChange.h
index 43319cc9ed17..5d23d1828b25 100644
--- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChange.h
+++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChange.h
@@ -2,7 +2,7 @@
 
   SEV-SNP Page Validation functions.
 
-  Copyright (c) 2021 AMD Incorporated. All rights reserved.
+  Copyright (c) 2021 - 2024, AMD Incorporated. All rights reserved.
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -24,7 +24,9 @@ InternalSetPageState (
   IN EFI_PHYSICAL_ADDRESS  BaseAddress,
   IN UINTN NumPages,
   IN SEV_SNP_PAGE_STATEState,
-  IN BOOLEAN   UseLargeEntry
+  IN BOOLEAN   UseLargeEntry,
+  IN VOID  *PscBuffer,
+  IN UINTN PscBufferSize
   );
 
 VOID
diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/DxeSnpSystemRamValidate.c 
b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/DxeSnpSystemRamValidate.c
index cbcdd46f528f..2515425e467a 100644
--- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/DxeSnpSystemRamValidate.c
+++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/DxeSnpSystemRamValidate.c
@@ -2,7 +2,7 @@
 
   SEV-SNP Page Validation functions.
 
-  Copyright (c) 2021 AMD Incorporated. All rights reserved.
+  Copyright (c) 2021 - 2024, AMD Incorporated. All rights reserved.
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -16,6 +16,8 @@
 #include "SnpPageStateChange.h"
 #include "VirtualMemory.h"
 
+STATIC VOID  *mPscBuffer = NULL;
+
 /**
   Pre-validate the system RAM when SEV-SNP is enabled in the guest VM.
 
@@ -52,5 +54,10 @@ MemEncryptSevSnpPreValidateSystemRam (
 }
   }
 
-  InternalSetPageState (BaseAddress, NumPages, SevSnpPagePrivate, TRUE);
+  if (mPscBuffer == NULL) {
+mPscBuffer = AllocateReservedPages (1);
+ASSERT (mPscBuffer != NULL);
+  }
+
+  InternalSetPageState (BaseAddress, NumPages, SevSnpPagePrivate, TRUE, 
mPscBuffer, EFI_PAGE_SIZE);
 }
diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c 
b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c
index dee3fb8914ca..337a7d926b15 100644
--- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c
+++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c
@@ -3,7 +3,7 @@
   Virtual Memory Management Services to set or clear the memory encryption bit
 
   Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
-  Copyright (c) 2017 - 2020, AMD Incorporated. All rights reserved.
+  Copyright (c) 2017 - 2024, AMD Incorporated. All 

[edk2-devel] [PATCH v2 07/23] MdePkg: Avoid hardcoded value for number of Page State Change entries

2024-02-22 Thread Lendacky, Thomas via groups.io
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4654

The SNP_PAGE_STATE_MAX_ENTRY is based on the number of entries that can
fit in the GHCB shared buffer. As a result, the SNP_PAGE_STATE_CHANGE_INFO
structure maps the full GHCB shared buffer based on the shared buffer size
being 2032 bytes.

Instead of using a hardcoded value for SNP_PAGE_STATE_MAX_ENTRY, use a
build calculated value. Since the SNP_PAGE_STATE_CHANGE_INFO is used as a
mapping, eliminate the hardcoded array size so that the structure can be
used based on any size buffer.

Signed-off-by: Tom Lendacky 
---
 MdePkg/Include/Register/Amd/Ghcb.h | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/MdePkg/Include/Register/Amd/Ghcb.h 
b/MdePkg/Include/Register/Amd/Ghcb.h
index 432d67e3e223..0cdc00627472 100644
--- a/MdePkg/Include/Register/Amd/Ghcb.h
+++ b/MdePkg/Include/Register/Amd/Ghcb.h
@@ -197,13 +197,14 @@ typedef struct {
   UINT32Reserved;
 } SNP_PAGE_STATE_HEADER;
 
-#define SNP_PAGE_STATE_MAX_ENTRY  253
-
 typedef struct {
   SNP_PAGE_STATE_HEADERHeader;
-  SNP_PAGE_STATE_ENTRY Entry[SNP_PAGE_STATE_MAX_ENTRY];
+  SNP_PAGE_STATE_ENTRY Entry[];
 } SNP_PAGE_STATE_CHANGE_INFO;
 
+#define SNP_PAGE_STATE_MAX_ENTRY  \
+  ((sizeof (((GHCB *)0)->SharedBuffer) - sizeof (SNP_PAGE_STATE_HEADER)) / 
sizeof (SNP_PAGE_STATE_ENTRY))
+
 //
 // Get APIC IDs
 //
-- 
2.42.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115842): https://edk2.groups.io/g/devel/message/115842
Mute This Topic: https://groups.io/mt/104512946/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v2 06/23] OvmfPkg/BaseMemEncryptSevLib: Calculate memory size for Page State Change

2024-02-22 Thread Lendacky, Thomas via groups.io
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4654

Calculate the amount of memory that can be use to build the Page State
Change data (SNP_PAGE_STATE_CHANGE_INFO) instead of using a hard-coded
size. This allows for changes to the GHCB shared buffer size without
having to make changes to the page state change code.

Signed-off-by: Tom Lendacky 
---
 OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c | 12 

 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git 
a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c 
b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c
index 6a11adb06efb..60b176ab14b8 100644
--- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c
+++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c
@@ -133,23 +133,26 @@ BuildPageStateBuffer (
   IN EFI_PHYSICAL_ADDRESSEndAddress,
   IN SEV_SNP_PAGE_STATE  State,
   IN BOOLEAN UseLargeEntry,
-  IN SNP_PAGE_STATE_CHANGE_INFO  *Info
+  IN SNP_PAGE_STATE_CHANGE_INFO  *Info,
+  IN UINTN   InfoSize
   )
 {
   EFI_PHYSICAL_ADDRESS  NextAddress;
   UINTN RmpPageSize;
   UINTN Index;
+  UINTN IndexMax;
 
   // Clear the page state structure
-  SetMem (Info, sizeof (*Info), 0);
+  SetMem (Info, InfoSize, 0);
 
   Index   = 0;
+  IndexMax= (InfoSize - sizeof (Info->Header)) / sizeof (Info->Entry[0]);
   NextAddress = EndAddress;
 
   //
   // Populate the page state entry structure
   //
-  while ((BaseAddress < EndAddress) && (Index < SNP_PAGE_STATE_MAX_ENTRY)) {
+  while ((BaseAddress < EndAddress) && (Index < IndexMax)) {
 //
 // Is this a 2MB aligned page? Check if we can use the Large RMP entry.
 //
@@ -265,7 +268,8 @@ InternalSetPageState (
 EndAddress,
 State,
 UseLargeEntry,
-Info
+Info,
+sizeof (Ghcb->SharedBuffer)
 );
 
 //
-- 
2.42.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115841): https://edk2.groups.io/g/devel/message/115841
Mute This Topic: https://groups.io/mt/104512944/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v2 05/23] OvmfPkg/BaseMemEncryptSevLib: Fix uncrustify errors

2024-02-22 Thread Lendacky, Thomas via groups.io
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4654

In prep for follow-on patches, fix an area of the code that does not meet
the uncrustify coding standards.

Signed-off-by: Tom Lendacky 
---
 OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c | 27 
+++-
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git 
a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c 
b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c
index 46c6682760d5..6a11adb06efb 100644
--- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c
+++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c
@@ -2,7 +2,7 @@
 
   SEV-SNP Page Validation functions.
 
-  Copyright (c) 2021 AMD Incorporated. All rights reserved.
+  Copyright (c) 2021 - 2024, AMD Incorporated. All rights reserved.
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -78,7 +78,9 @@ PvalidateRange (
   IN  BOOLEAN Validate
   )
 {
-  UINTN RmpPageSize, Ret, i;
+  UINTN RmpPageSize;
+  UINTN Index;
+  UINTN Ret;
   EFI_PHYSICAL_ADDRESS  Address;
 
   for ( ; StartIndex <= EndIndex; StartIndex++) {
@@ -96,7 +98,7 @@ PvalidateRange (
 // the RMP entry is 4K and we are validating it as a 2MB.
 //
 if ((Ret == PVALIDATE_RET_SIZE_MISMATCH) && (RmpPageSize == 
PvalidatePageSize2MB)) {
-  for (i = 0; i < PAGES_PER_LARGE_ENTRY; i++) {
+  for (Index = 0; Index < PAGES_PER_LARGE_ENTRY; Index++) {
 Ret = AsmPvalidate (PvalidatePageSize4K, Validate, Address);
 if (Ret) {
   break;
@@ -135,18 +137,19 @@ BuildPageStateBuffer (
   )
 {
   EFI_PHYSICAL_ADDRESS  NextAddress;
-  UINTN i, RmpPageSize;
+  UINTN RmpPageSize;
+  UINTN Index;
 
   // Clear the page state structure
   SetMem (Info, sizeof (*Info), 0);
 
-  i   = 0;
+  Index   = 0;
   NextAddress = EndAddress;
 
   //
   // Populate the page state entry structure
   //
-  while ((BaseAddress < EndAddress) && (i < SNP_PAGE_STATE_MAX_ENTRY)) {
+  while ((BaseAddress < EndAddress) && (Index < SNP_PAGE_STATE_MAX_ENTRY)) {
 //
 // Is this a 2MB aligned page? Check if we can use the Large RMP entry.
 //
@@ -160,14 +163,14 @@ BuildPageStateBuffer (
   NextAddress = BaseAddress + EFI_PAGE_SIZE;
 }
 
-Info->Entry[i].GuestFrameNumber = BaseAddress >> EFI_PAGE_SHIFT;
-Info->Entry[i].PageSize = RmpPageSize;
-Info->Entry[i].Operation= MemoryStateToGhcbOp (State);
-Info->Entry[i].CurrentPage  = 0;
-Info->Header.EndEntry   = (UINT16)i;
+Info->Entry[Index].GuestFrameNumber = BaseAddress >> EFI_PAGE_SHIFT;
+Info->Entry[Index].PageSize = RmpPageSize;
+Info->Entry[Index].Operation= MemoryStateToGhcbOp (State);
+Info->Entry[Index].CurrentPage  = 0;
+Info->Header.EndEntry   = (UINT16)Index;
 
 BaseAddress = NextAddress;
-i++;
+Index++;
   }
 
   return NextAddress;
-- 
2.42.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115840): https://edk2.groups.io/g/devel/message/115840
Mute This Topic: https://groups.io/mt/104512941/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v2 04/23] UefiCpuPkg/MpInitLib: Always use AP Create if PcdSevSnpApicIds is set

2024-02-22 Thread Lendacky, Thomas via groups.io
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4654

Currently, the first time an AP is started for an SEV-SNP guest, it relies
on the VMSA as set by the hypervisor. If the list of APIC IDs has been
retrieved, this is not necessary. Instead, use the SEV-SNP AP Create
protocol to start the AP for the first time and thereafter using the VMPL
at which the BSP is running.

Signed-off-by: Tom Lendacky 
---
 UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf |  1 +
 UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf |  1 +
 UefiCpuPkg/Library/MpInitLib/MpLib.h  | 15 +++-
 UefiCpuPkg/Library/MpInitLib/Ia32/AmdSev.c| 21 +-
 UefiCpuPkg/Library/MpInitLib/MpLib.c  |  9 ++-
 UefiCpuPkg/Library/MpInitLib/X64/AmdSev.c | 78 ++--
 6 files changed, 112 insertions(+), 13 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf 
b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
index 55e46d4a1fad..538a2146ff24 100644
--- a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
@@ -68,6 +68,7 @@ [Guids]
   gEfiEventExitBootServicesGuid ## CONSUMES  ## Event
   gEfiEventLegacyBootGuid   ## SOMETIMES_CONSUMES  ## Event
   gEdkiiMicrocodePatchHobGuid   ## SOMETIMES_CONSUMES  ## HOB
+  gEfiApicIdsGuid   ## SOMETIMES_CONSUMES  ## HOB
 
 [Pcd]
   gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber## 
CONSUMES
diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf 
b/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf
index bc3d716aa951..622baec45e2f 100644
--- a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf
+++ b/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf
@@ -76,3 +76,4 @@ [Ppis]
 [Guids]
   gEdkiiS3SmmInitDoneGuid
   gEdkiiMicrocodePatchHobGuid
+  gEfiApicIdsGuid## SOMETIMES_CONSUMES
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h 
b/UefiCpuPkg/Library/MpInitLib/MpLib.h
index a96a6389c17d..617f7401aea8 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
@@ -2,7 +2,7 @@
   Common header file for MP Initialize Library.
 
   Copyright (c) 2016 - 2023, Intel Corporation. All rights reserved.
-  Copyright (c) 2020, AMD Inc. All rights reserved.
+  Copyright (c) 2020 - 2024, AMD Inc. All rights reserved.
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -911,6 +911,19 @@ SevSnpCreateAP (
   IN INTN ProcessorNumber
   );
 
+/**
+  Determine if the SEV-SNP AP Create protocol should be used.
+
+  @param[in]  CpuMpData  Pointer to CPU MP Data
+
+  @retval TRUE   Use SEV-SNP AP Create protocol
+  @retval FALSE  Do not use SEV-SNP AP Create protocol
+**/
+BOOLEAN
+CanUseSevSnpCreateAP (
+  IN  CPU_MP_DATA  *CpuMpData
+  );
+
 /**
   Get pointer to CPU MP Data structure from GUIDed HOB.
 
diff --git a/UefiCpuPkg/Library/MpInitLib/Ia32/AmdSev.c 
b/UefiCpuPkg/Library/MpInitLib/Ia32/AmdSev.c
index c83144285b68..0478e92317f1 100644
--- a/UefiCpuPkg/Library/MpInitLib/Ia32/AmdSev.c
+++ b/UefiCpuPkg/Library/MpInitLib/Ia32/AmdSev.c
@@ -2,7 +2,7 @@
 
   AMD SEV helper function.
 
-  Copyright (c) 2021, AMD Incorporated. All rights reserved.
+  Copyright (c) 2021 - 2024, AMD Incorporated. All rights reserved.
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -68,3 +68,22 @@ SevSnpRmpAdjust (
   //
   return RETURN_UNSUPPORTED;
 }
+
+/**
+  Determine if the SEV-SNP AP Create protocol should be used.
+
+  @param[in]  CpuMpData  Pointer to CPU MP Data
+
+  @retval TRUE   Use SEV-SNP AP Create protocol
+  @retval FALSE  Do not use SEV-SNP AP Create protocol
+**/
+BOOLEAN
+CanUseSevSnpCreateAP (
+  IN  CPU_MP_DATA  *CpuMpData
+  )
+{
+  //
+  // SEV-SNP is not supported on 32-bit build.
+  //
+  return FALSE;
+}
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index cdfb570e61a0..dd8d00d54a15 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -2,7 +2,7 @@
   CPU MP Initialize Library common functions.
 
   Copyright (c) 2016 - 2022, Intel Corporation. All rights reserved.
-  Copyright (c) 2020, AMD Inc. All rights reserved.
+  Copyright (c) 2020 - 2024, AMD Inc. All rights reserved.
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -1302,9 +1302,10 @@ WakeUpAP (
   //
   // Wakeup all APs
   //   Must use the INIT-SIPI-SIPI method for initial configuration in
-  //   order to obtain the APIC ID.
+  //   order to obtain the APIC ID if not an SEV-SNP guest and the
+  //   list of APIC IDs is not available.
   //
-  if (CpuMpData->SevSnpIsEnabled && (CpuMpData->InitFlag != ApInitConfig)) 
{
+  if (CanUseSevSnpCreateAP (CpuMpData)) {
 SevSnpCreateAP (CpuMpData, -1);
   } else {
 if ((CpuMpData->InitFlag == ApInitConfig) && FixedPcdGetBool 
(PcdFirstTimeWakeUpAPsBySipi)) {
@@ -1414,7 +1415,7 @@ WakeUpAP (

[edk2-devel] [PATCH v2 03/23] OvmfPkg/PlatformPei: Retrieve APIC IDs from the hypervisor

2024-02-22 Thread Lendacky, Thomas via groups.io
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4654

If the hypervisor supports retrieval of the vCPU APIC IDs, retrieve
them before any APs are actually started. The APIC IDs can be used
to start the APs for any SEV-SNP guest, but is a requirement for an
SEV-SNP guest that is running under an SVSM.

After retrieving the APIC IDs, save the address of the APIC ID data
structure in a GUIDed HOB.

Signed-off-by: Tom Lendacky 
---
 OvmfPkg/PlatformPei/PlatformPei.inf |  1 +
 OvmfPkg/PlatformPei/AmdSev.c| 91 +++-
 2 files changed, 91 insertions(+), 1 deletion(-)

diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf 
b/OvmfPkg/PlatformPei/PlatformPei.inf
index ad52be306560..7de3b4341c2c 100644
--- a/OvmfPkg/PlatformPei/PlatformPei.inf
+++ b/OvmfPkg/PlatformPei/PlatformPei.inf
@@ -45,6 +45,7 @@ [Guids]
   gEfiMemoryTypeInformationGuid
   gFdtHobGuid
   gUefiOvmfPkgPlatformInfoGuid
+  gEfiApicIdsGuid
 
 [LibraryClasses]
   BaseLib
diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c
index e6b602d79a05..472cf13f0faa 100644
--- a/OvmfPkg/PlatformPei/AmdSev.c
+++ b/OvmfPkg/PlatformPei/AmdSev.c
@@ -1,7 +1,7 @@
 /**@file
   Initialize Secure Encrypted Virtualization (SEV) support
 
-  Copyright (c) 2017 - 2020, Advanced Micro Devices. All rights reserved.
+  Copyright (c) 2017 - 2024, Advanced Micro Devices. All rights reserved.
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -31,6 +31,87 @@ GetHypervisorFeature (
   VOID
   );
 
+/**
+  Retrieve APIC IDs from the hypervisor.
+
+**/
+STATIC
+VOID
+AmdSevSnpGetApicIds (
+  VOID
+  )
+{
+  MSR_SEV_ES_GHCB_REGISTER  Msr;
+  GHCB  *Ghcb;
+  BOOLEAN   InterruptState;
+  UINT64VmgExitStatus;
+  UINT64PageCount;
+  BOOLEAN   PageCountValid;
+  VOID  *ApicIds;
+  RETURN_STATUS Status;
+  UINT64GuidData;
+
+  Msr.GhcbPhysicalAddress = AsmReadMsr64 (MSR_SEV_ES_GHCB);
+  Ghcb= Msr.Ghcb;
+
+  PageCount  = 0;
+  PageCountValid = FALSE;
+
+  CcExitVmgInit (Ghcb, );
+  Ghcb->SaveArea.Rax = PageCount;
+  CcExitVmgSetOffsetValid (Ghcb, GhcbRax);
+  VmgExitStatus = CcExitVmgExit (Ghcb, SVM_EXIT_GET_APIC_IDS, 0, 0);
+  if (CcExitVmgIsOffsetValid (Ghcb, GhcbRax)) {
+PageCount  = Ghcb->SaveArea.Rax;
+PageCountValid = TRUE;
+  }
+
+  CcExitVmgDone (Ghcb, InterruptState);
+
+  ASSERT (VmgExitStatus == 0);
+  ASSERT (PageCountValid);
+  if ((VmgExitStatus != 0) || !PageCountValid) {
+return;
+  }
+
+  //
+  // Allocate the memory for the APIC IDs
+  //
+  ApicIds = AllocateReservedPages ((UINTN)PageCount);
+  ASSERT (ApicIds != NULL);
+
+  Status = MemEncryptSevClearPageEncMask (
+ 0,
+ (UINTN)ApicIds,
+ (UINTN)PageCount
+ );
+  ASSERT_RETURN_ERROR (Status);
+
+  ZeroMem (ApicIds, EFI_PAGES_TO_SIZE ((UINTN)PageCount));
+
+  PageCountValid = FALSE;
+
+  CcExitVmgInit (Ghcb, );
+  Ghcb->SaveArea.Rax = PageCount;
+  CcExitVmgSetOffsetValid (Ghcb, GhcbRax);
+  VmgExitStatus = CcExitVmgExit (Ghcb, SVM_EXIT_GET_APIC_IDS, (UINTN)ApicIds, 
0);
+  if (CcExitVmgIsOffsetValid (Ghcb, GhcbRax) && (Ghcb->SaveArea.Rax == 
PageCount)) {
+PageCountValid = TRUE;
+  }
+
+  CcExitVmgDone (Ghcb, InterruptState);
+
+  ASSERT (VmgExitStatus == 0);
+  ASSERT (PageCountValid);
+  if ((VmgExitStatus != 0) || !PageCountValid) {
+FreePages (ApicIds, (UINTN)PageCount);
+return;
+  }
+
+  GuidData = (UINT64)(UINTN)ApicIds;
+  BuildGuidDataHob (, , sizeof (GuidData));
+}
+
 /**
   Initialize SEV-SNP support if running as an SEV-SNP guest.
 
@@ -78,6 +159,14 @@ AmdSevSnpInitialize (
   }
 }
   }
+
+  //
+  // Retrieve the APIC IDs if the hypervisor supports it. These will be used
+  // to always start APs using SNP AP Create.
+  //
+  if ((HvFeatures & GHCB_HV_FEATURES_APIC_ID_LIST) == 
GHCB_HV_FEATURES_APIC_ID_LIST) {
+AmdSevSnpGetApicIds ();
+  }
 }
 
 /**
-- 
2.42.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115838): https://edk2.groups.io/g/devel/message/115838
Mute This Topic: https://groups.io/mt/104512934/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v2 02/23] MdePkg: GHCB APIC ID retrieval support definitions

2024-02-22 Thread Lendacky, Thomas via groups.io
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4654

When an SVSM is present, starting the APs requires knowledge of the APIC
IDs. Create the definitions required to retrieve and hold the APIC ID
information of all the vCPUs present in the guest.

Acked-by: Gerd Hoffmann 
Signed-off-by: Tom Lendacky 
---
 MdePkg/MdePkg.dec  |  5 -
 MdePkg/Include/Register/Amd/Ghcb.h | 16 +++-
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
index 0459418906f8..7d3f54a46f54 100644
--- a/MdePkg/MdePkg.dec
+++ b/MdePkg/MdePkg.dec
@@ -9,7 +9,7 @@
 # (C) Copyright 2016 - 2021 Hewlett Packard Enterprise Development LP
 # Copyright (c) 2022, Loongson Technology Corporation Limited. All rights 
reserved.
 # Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
-# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+# Copyright (C) 2023 - 2024, Advanced Micro Devices, Inc. All rights 
reserved.
 # Copyright (c) 2023, Ampere Computing LLC. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -876,6 +876,9 @@ [Guids]
   ## Include/Protocol/CcMeasurement.h
   gEfiCcFinalEventsTableGuid = { 0xdd4a4648, 0x2de7, 0x4665, { 0x96, 0x4d, 
0x21, 0xd9, 0xef, 0x5f, 0xb4, 0x46 }}
 
+  ## Include/Register/Amd/Ghcb.h
+  gEfiApicIdsGuid= { 0xbc964338, 0xee39, 0x4fc8, { 0xa2, 0x24, 
0x10, 0x10, 0x8b, 0x17, 0x80, 0x1b }}
+
 [Guids.IA32, Guids.X64]
   ## Include/Guid/Cper.h
   gEfiIa32X64ErrorTypeCacheCheckGuid = { 0xA55701F5, 0xE3EF, 0x43de, { 0xAC, 
0x72, 0x24, 0x9B, 0x57, 0x3F, 0xAD, 0x2C }}
diff --git a/MdePkg/Include/Register/Amd/Ghcb.h 
b/MdePkg/Include/Register/Amd/Ghcb.h
index dab396f3ede8..432d67e3e223 100644
--- a/MdePkg/Include/Register/Amd/Ghcb.h
+++ b/MdePkg/Include/Register/Amd/Ghcb.h
@@ -4,7 +4,7 @@
   Provides data types allowing an SEV-ES guest to interact with the hypervisor
   using the GHCB protocol.
 
-  Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+  Copyright (C) 2020 - 2024, Advanced Micro Devices, Inc. All rights 
reserved.
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
   @par Specification Reference:
@@ -56,6 +56,7 @@
 #define SVM_EXIT_AP_JUMP_TABLE  0x8005ULL
 #define SVM_EXIT_SNP_PAGE_STATE_CHANGE  0x8010ULL
 #define SVM_EXIT_SNP_AP_CREATION0x8013ULL
+#define SVM_EXIT_GET_APIC_IDS   0x8017ULL
 #define SVM_EXIT_HYPERVISOR_FEATURES0x8000FFFDULL
 #define SVM_EXIT_UNSUPPORTED0x8000ULL
 
@@ -170,6 +171,7 @@ typedef union {
 #define GHCB_HV_FEATURES_SNP_AP_CREATE   (GHCB_HV_FEATURES_SNP 
| BIT1)
 #define GHCB_HV_FEATURES_SNP_RESTRICTED_INJECTION
(GHCB_HV_FEATURES_SNP_AP_CREATE | BIT2)
 #define GHCB_HV_FEATURES_SNP_RESTRICTED_INJECTION_TIMER  
(GHCB_HV_FEATURES_SNP_RESTRICTED_INJECTION | BIT3)
+#define GHCB_HV_FEATURES_APIC_ID_LISTBIT4
 
 //
 // SNP Page State Change.
@@ -202,6 +204,18 @@ typedef struct {
   SNP_PAGE_STATE_ENTRY Entry[SNP_PAGE_STATE_MAX_ENTRY];
 } SNP_PAGE_STATE_CHANGE_INFO;
 
+//
+// Get APIC IDs
+//
+#define EFI_APIC_IDS_GUID  \
+  { 0xbc964338, 0xee39, 0x4fc8, { 0xa2, 0x24, 0x10, 0x10, 0x8b, 0x17, 0x80, 
0x1b }}
+extern EFI_GUID  gEfiApicIdsGuid;
+
+typedef struct {
+  UINT32NumEntries;
+  UINT32ApicIds[];
+} GHCB_APIC_IDS;
+
 //
 // SEV-ES save area mapping structures used for SEV-SNP AP Creation.
 // Only the fields required to be set to a non-zero value are defined.
-- 
2.42.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115837): https://edk2.groups.io/g/devel/message/115837
Mute This Topic: https://groups.io/mt/104512930/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v2 01/23] OvmfPkg/BaseMemEncryptLib: Fix error check from AsmRmpAdjust()

2024-02-22 Thread Lendacky, Thomas via groups.io
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4654

The AsmRmpAdjust() function returns a UINT32, however in SevSnpIsVmpl0()
the return value is checked with EFI_ERROR() when it should just be
compared to 0. Fix the error check.

Signed-off-by: Tom Lendacky 
---
 OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecSnpSystemRamValidate.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecSnpSystemRamValidate.c 
b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecSnpSystemRamValidate.c
index 7797febb8ac6..be43a44e4e1d 100644
--- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecSnpSystemRamValidate.c
+++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecSnpSystemRamValidate.c
@@ -2,7 +2,7 @@
 
   SEV-SNP Page Validation functions.
 
-  Copyright (c) 2021 AMD Incorporated. All rights reserved.
+  Copyright (c) 2021 - 2024, AMD Incorporated. All rights reserved.
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -31,8 +31,8 @@ SevSnpIsVmpl0 (
   VOID
   )
 {
-  UINT64  Rdx;
-  EFI_STATUS  Status;
+  UINT64  Rdx;
+  UINT32  Status;
 
   //
   // There is no straightforward way to query the current VMPL level.
@@ -44,7 +44,7 @@ SevSnpIsVmpl0 (
   Rdx = 1;
 
   Status = AsmRmpAdjust ((UINT64)gVmpl0Data, 0, Rdx);
-  if (EFI_ERROR (Status)) {
+  if (Status != 0) {
 return FALSE;
   }
 
-- 
2.42.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115836): https://edk2.groups.io/g/devel/message/115836
Mute This Topic: https://groups.io/mt/104512928/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v2 00/23] Provide SEV-SNP support for running under an SVSM

2024-02-22 Thread Lendacky, Thomas via groups.io


BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4654

This series adds SEV-SNP support for running OVMF under an Secure VM
Service Module (SVSM) at a less privileged VM Privilege Level (VMPL).
By running at a less priviledged VMPL, the SVSM can be used to provide
services, e.g. a virtual TPM, for the guest OS within the SEV-SNP
confidential VM (CVM) rather than trust such services from the hypervisor.

Currently, OVMF expects to run at the highest VMPL, VMPL0, and there are
certain SNP related operations that require that VMPL level. Specifically,
the PVALIDATE instruction and the RMPADJUST instruction when setting the
the VMSA attribute of a page (used when starting APs).

If OVMF is to run at a less privileged VMPL, e.g. VMPL2, then it must
use an SVSM (which is running at VMPL0) to perform the operations that
it is no longer able to perform.

When running under an SVSM, OVMF must know the APIC IDs of the vCPUs that
it will be starting. As a result, the GHCB APIC ID retrieval action must
be performed. Since this service can also work with SEV-SNP running at
VMPL0, the patches to make use of this feature are near the beginning of
the series.

How OVMF interacts with and uses the SVSM is documented in the SVSM
specification [1] and the GHCB specification [2].

This support creates a new CcSvsmLib library that is used by MpInitLib.
This requires an update to the edk2-platform DSC files to add the new
library. The edk2-platform change would be needed after patch 12, but
before patch 15.

This series introduces support to run OVMF under an SVSM. It consists
of:
  - Retrieving the list of vCPU APIC IDs and starting up all APs without
performing a broadcast SIPI
  - Reorganizing the page state change support to not directly use the
GHCB buffer since an SVSM will use the calling area buffer, instead
  - Detecting the presence of an SVSM
  - When not running at VMPL0, invoking the SVSM for page validation and
VMSA page creation/deletion
  - Detecting and allowing OVMF to run in a VMPL other than 0 when an
SVSM is present

The series is based off of commit:

  2ca8d5597443 ("UefiCpuPkg/PiSmmCpuDxeSmm: Check BspIndex first before lock 
cmpxchg")

[1] 
https://www.amd.com/content/dam/amd/en/documents/epyc-technical-docs/specifications/58019.pdf
[2] 
https://www.amd.com/content/dam/amd/en/documents/epyc-technical-docs/specifications/56421.pdf

---

Changes in v2:
- Move the APIC IDs retrieval support to the beginning of the patch series
- Use a GUIDed HOB to hold the APIC ID list instead of a PCD
- Split up Page State Change reorganization into multiple patches
- Created CcSvsmLib library instead of extending CcExitLib
- This will require a corresponding update to edk2-platform DSC files
- Removed Ray Ni's Acked-by since it is not a minor change
- Variable name changes and other misc changes

Tom Lendacky (23):
  OvmfPkg/BaseMemEncryptLib: Fix error check from AsmRmpAdjust()
  MdePkg: GHCB APIC ID retrieval support definitions
  OvmfPkg/PlatformPei: Retrieve APIC IDs from the hypervisor
  UefiCpuPkg/MpInitLib: Always use AP Create if PcdSevSnpApicIds is set
  OvmfPkg/BaseMemEncryptSevLib: Fix uncrustify errors
  OvmfPkg/BaseMemEncryptSevLib: Calculate memory size for Page State
Change
  MdePkg: Avoid hardcoded value for number of Page State Change entries
  OvmfPkg/BaseMemEncryptSevLib: Re-organize page state change support
  OvmfPkg/BaseMemEncryptSevLib: Maximize Page State Change efficiency
  MdePkg/Register/Amd: Define the SVSM related information
  MdePkg/BaseLib: Add a new VMGEXIT instruction invocation for SVSM
  UefiCpuPkg/CcSvsmLib: Create the CcSvsmLib library to support an SVSM
  UefiPayloadPkg: Prepare UefiPayloadPkg to use the CcSvsmLib library
  Ovmfpkg/CcSvsmLib: Create CcSvsmLib to handle SVSM related services
  UefiCpuPkg/MpInitLib: Use CcSvsmSnpVmsaRmpAdjust() to set/clear VMSA
  OvmfPkg/BaseMemEncryptSevLib: Use CcSvsmSnpPvalidate() to validate
pages
  OvmfPkg: Create a calling area used to communicate with the SVSM
  OvmfPkg/CcSvsmLib: Add support for the SVSM_CORE_PVALIDATE call
  OvmfPkg/BaseMemEncryptSevLib: Maximize Page State Change efficiency
  OvmfPkg/CcSvsmLib: Add support for the SVSM create/delete vCPU calls
  UefiCpuPkg/MpInitLib: AP creation support under an SVSM
  Ovmfpkg/CcExitLib: Provide SVSM discovery support
  OvmfPkg/BaseMemEncryptLib: Check for presence of an SVSM when not at
VMPL0

 MdePkg/MdePkg.dec |   5 +-
 OvmfPkg/OvmfPkg.dec   |   4 +
 UefiCpuPkg/UefiCpuPkg.dec |   5 +-
 OvmfPkg/AmdSev/AmdSevX64.dsc  |   1 +
 OvmfPkg/Bhyve/BhyveX64.dsc|   1 +
 OvmfPkg/CloudHv/CloudHvX64.dsc|   1 +
 OvmfPkg/IntelTdx/IntelTdxX64.dsc  |   1 +
 

Re: [edk2-devel] [PATCH] MdeModulePkg/PciBusDxe: plug device hierarchy leak upon bridge hot-unplug

2024-02-22 Thread Hsueh, Hong-Chih (Neo) via groups.io
[AMD Official Use Only - General]

Please kindly ignore this mail thread as I have created and sent out [PATCH V2] 
with correct title in another mail thread for review.

Thank you.

Regards,
Neo

From: Hsueh, Hong-Chih (Neo) 
Sent: Tuesday, February 20, 2024 1:48 PM
To: Ding, Feng (Sunnyvale) ; Laszlo Ersek 
; devel@edk2.groups.io 
Cc: He, Jiangang ; Chang, Abner ; 
ray...@intel.com ; gaolim...@byosoft.com.cn 
; Gopal, Pradeep 
Subject: Re: [edk2-devel] [PATCH] MdeModulePkg/PciBusDxe: plug device hierarchy 
leak upon bridge hot-unplug

Hi Feng & Laszlo,

Thank you for the feedback, I have changed the title of this email and the 
title of the commit message of this patch.
The new patch as attached. If this patch looks good to you, could you please 
help to add reviewed-by?

Thanks!

Regards,
Neo


From: Ding, Feng (Sunnyvale) 
Sent: Thursday, February 8, 2024 5:09 PM
To: Laszlo Ersek ; devel@edk2.groups.io 
; Hsueh, Hong-Chih (Neo) 
Cc: He, Jiangang ; Chang, Abner ; 
ray...@intel.com ; gaolim...@byosoft.com.cn 
; Gopal, Pradeep 
Subject: RE: [edk2-devel] [PATCH] MdeModulePkg/PciBusDxe: Fix hotplug 
functionality for USB4 bridge

[AMD Official Use Only - General]

Hi Laszlo,

" MdeModulePkg/PciBusDxe: plug device hierarchy leak upon bridge hot-unplug " 
is perfect description for the issue.
"a root bridge" is "a (PCIe Hotplug) bridge", locating anywhere.

Thanks
feng

-Original Message-
From: Laszlo Ersek 
Sent: Wednesday, February 7, 2024 12:51 PM
To: devel@edk2.groups.io; Hsueh, Hong-Chih (Neo) 
Cc: Ding, Feng (Sunnyvale) ; He, Jiangang 
; Chang, Abner ; ray...@intel.com; 
gaolim...@byosoft.com.cn
Subject: Re: [edk2-devel] [PATCH] MdeModulePkg/PciBusDxe: Fix hotplug 
functionality for USB4 bridge

Caution: This message originated from an External Source. Use proper caution 
when opening attachments, clicking links, or responding.


On 2/6/24 23:34, Hsueh, Hong-Chih (Neo) via groups.io wrote:
> A USB4 or TBT bridge can be plugged or unplugged on USB4 port. The actions 
> require PciHotPlugRequestNotify to add a root bridge or remove a root bridge 
> completely.
> In the plug-unplug-plug scenerio, PciHotPlugRequestNotify will return with 
> no-action on second plug because bridge tree shows configured.
> Destroy Pci Device Tree in function PciHotPlugRequestNotify for unplug event 
> to fix this issue.
>
> Cc: Feng Ding 
> Cc: Jiangang He 
> Signed-off-by: Neo Hsueh 
> ---
>  MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c 
> b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c
> index 3f8c6e6da7..2b7af60e0a 100644
> --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c
> +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c
> @@ -2103,6 +2103,8 @@ PciHotPlugRequestNotify (
>}
>  }
>
> +DestroyPciDeviceTree (Bridge);
> +
>  //
>  // End for
>  //

I think the subject line is too specific. This patch appears to fix a general 
resource leak in the PCI hot-unplug functionality. Writing up the USB4 angle in 
the commit message is welcome in my opinion, but the subject should state 
something like:

MdeModulePkg/PciBusDxe: plug device hierarchy leak upon bridge hot-unplug

(And I think the bridge doesn't even have to be a *root* bridge for the leak to 
occur; is that right?)

Laszlo



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115834): https://edk2.groups.io/g/devel/message/115834
Mute This Topic: https://groups.io/mt/104474693/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v2] MdeModulePkg/PciBusDxe: plug device hierarchy leak upon bridge hot-unplug

2024-02-22 Thread Hsueh, Hong-Chih (Neo) via groups.io
A USB4 or TBT bridge can be plugged or unplugged on USB4 port. The actions 
require PciHotPlugRequestNotify to add a root bridge or remove a root bridge 
completely.
In the plug-unplug-plug scenerio, PciHotPlugRequestNotify will return with 
no-action on second plug because bridge tree shows configured.
Destroy Pci Device Tree in function PciHotPlugRequestNotify for unplug event to 
fix this issue.

Cc: Feng Ding 
Cc: Jiangang He 
Signed-off-by: Neo Hsueh 
---
 MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c 
b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c
index 3f8c6e6da7..2b7af60e0a 100644
--- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c
+++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c
@@ -2103,6 +2103,8 @@ PciHotPlugRequestNotify (
   }
 }
 
+DestroyPciDeviceTree (Bridge);
+
 //
 // End for
 //
-- 
2.40.0.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115833): https://edk2.groups.io/g/devel/message/115833
Mute This Topic: https://groups.io/mt/104511503/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] GuestPhysAddrSize questions

2024-02-22 Thread Paolo Bonzini

On 2/22/24 16:44, Tom Lendacky wrote:

On 2/22/24 05:24, Gerd Hoffmann wrote:

   Hi,


+    if (Cr4.Bits.LA57) {
+  if (PhysBits > 48) {
+    /*
+ * Some Intel CPUs support 5-level paging, have more than 48
+ * phys-bits but support only 4-level EPT, which effectively
+ * limits guest phys-bits to 48.
+ *
+ * AMD Processors have a different but somewhat related
+ * problem: They can handle guest phys-bits larger than 48
+ * only in case the host runs in 5-level paging mode.
+ *
+ * Until we have some way to communicate that kind of
+ * limitations from hypervisor to guest, limit phys-bits
+ * to 48 unconditionally.
+ */


So I'm looking for some communication path.  One option would be to use
some bits in the KVM cpuid leaves.  Another possible candidate is cpuid
leaf 0x8008.

 From the AMD APM (revision 3.35):

   CPUID Fn8000_0008_EAX Long Mode Size Identifiers
   

   The value returned in EAX provides information about the maximum host
   and guest physical and linear address width (in bits) supported by the
   processor.

   Bits   FieldName    Description

   31:24  —    Reserved

   23:16 GuestPhysAddrSize Maximum guest physical address size in bits.
   This number applies only to guests using 
nested

   paging. When this field is zero, refer to the
   PhysAddrSize field for the maximum guest
   physical address size. See “Secure Virtual
   Machine” in APM Volume 2.

   15:8  LinAddrSize   Maximum linear address size in bits.

   7:0   PhysAddrSize  Maximum physical address size in bits. When
   GuestPhysAddrSize is zero, this field also
   indicates the maximum guest physical address
   size.

The description of the GuestPhysAddrSize is somewhat vague.  Is this a
value the hypervisor should use to figure how much address space it can
give to guests?  Or is this a value the hypervisor can set to inform the
guest about the available address space (which would be a solution to
the problem outlined in the comment above)?  Or both?


I believe the main purpose of GuestPhysAddrSize was for software use 
(for nested virtualization) and that the hardware itself has always 
returned zero for that value. So you should be able to use that field. 
Adding @Paolo for his thoughts.


I have already discussed this with Gerd, so I don't really have many 
thoughts to add.


Anyhow, basically we would like GuestPhysAddrSize to be "redefined" as

   Maximum usable physical address size in bits.  Physical addresses
   above this size should not be used, but will not produce a "reserved"
   page fault.  When this field is zero, all bits up to PhysAddrSize are
   usable.  This field is expected to be nonzero only on guests where
   the hypervisor is using nested paging.

Also, to clarify the hardware behavior, if hCR4.LA57=0 and host 
PhysAddrSize==52, then will guest physical addresses above 2^48


1) cause a reserved #PF in the guest, or

2) cause a non-present NPF exit in the hypervisor?

I remember that several years ago we had a discussion on hCR4.LA57=0 
reducing the address space compared to MAXPHYADDR, but I cannot find the 
emails and also at the time I didn't notice GuestPhysAddrSize.


Paolo



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115832): https://edk2.groups.io/g/devel/message/115832
Mute This Topic: https://groups.io/mt/104510523/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3 6/6] UefiCpuPkg/MpInitLib: return early in GetBspNumber()

2024-02-22 Thread Gerd Hoffmann
After finding the BSP Number return the result instead of
continuing to loop over the remaining processors.

Suggested-by: Laszlo Ersek 
Signed-off-by: Gerd Hoffmann 
---
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 11 ---
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index 4b6d6d02b027..2051554207dc 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -1903,15 +1903,13 @@ GetBspNumber (
   )
 {
   UINT32 ApicId;
-  UINT32 BspNumber;
   UINT32 Index;
   CONST MP_HAND_OFF  *MpHandOff;
 
   //
   // Get the processor number for the BSP
   //
-  BspNumber = MAX_UINT32;
-  ApicId= GetInitialApicId ();
+  ApicId = GetInitialApicId ();
 
   for (MpHandOff = FirstMpHandOff;
MpHandOff != NULL;
@@ -1919,14 +1917,13 @@ GetBspNumber (
   {
 for (Index = 0; Index < MpHandOff->CpuCount; Index++) {
   if (MpHandOff->Info[Index].ApicId == ApicId) {
-BspNumber = MpHandOff->ProcessorIndex + Index;
+return MpHandOff->ProcessorIndex + Index;
   }
 }
   }
 
-  ASSERT (BspNumber != MAX_UINT32);
-
-  return BspNumber;
+  ASSERT (FALSE);
+  return 0;
 }
 
 /**
-- 
2.43.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115831): https://edk2.groups.io/g/devel/message/115831
Mute This Topic: https://groups.io/mt/104510913/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3 5/6] UefiCpuPkg/MpInitLib: Add support for multiple HOBs to SaveCpuMpData()

2024-02-22 Thread Gerd Hoffmann
Add support for splitting Hand-Off data into multiple HOBs.
This is required for VMs with thousands of CPUs.

Signed-off-by: Gerd Hoffmann 
---
 UefiCpuPkg/Library/MpInitLib/PeiMpLib.c | 44 +++--
 1 file changed, 27 insertions(+), 17 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c 
b/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c
index f80e00edcff3..00d48c2ab531 100644
--- a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c
@@ -126,35 +126,45 @@ SaveCpuMpData (
   IN CPU_MP_DATA  *CpuMpData
   )
 {
+  UINT32   MaxCpusPerHob, CpusInHob;
   UINT64   Data64;
-  UINTNIndex;
+  UINT32   Index, HobBase;
   CPU_INFO_IN_HOB  *CpuInfoInHob;
   MP_HAND_OFF  *MpHandOff;
   UINTNMpHandOffSize;
 
+  MaxCpusPerHob = (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE) - sizeof (MP_HAND_OFF)) 
/ sizeof (PROCESSOR_HAND_OFF);
+
   //
   // When APs are in a state that can be waken up by a store operation to a 
memory address,
   // report the MP_HAND_OFF data for DXE to use.
   //
-  CpuInfoInHob  = (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob;
-  MpHandOffSize = sizeof (MP_HAND_OFF) + sizeof (PROCESSOR_HAND_OFF) * 
CpuMpData->CpuCount;
-  MpHandOff = (MP_HAND_OFF *)BuildGuidHob (, MpHandOffSize);
-  ASSERT (MpHandOff != NULL);
-  ZeroMem (MpHandOff, MpHandOffSize);
-  MpHandOff->ProcessorIndex = 0;
+  CpuInfoInHob = (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob;
 
-  MpHandOff->CpuCount = CpuMpData->CpuCount;
-  if (CpuMpData->ApLoopMode != ApInHltLoop) {
-MpHandOff->StartupSignalValue= MP_HAND_OFF_SIGNAL;
-MpHandOff->WaitLoopExecutionMode = sizeof (VOID *);
-  }
+  for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
+if (Index % MaxCpusPerHob == 0) {
+  HobBase   = Index;
+  CpusInHob = MIN (CpuMpData->CpuCount - HobBase, MaxCpusPerHob);
 
-  for (Index = 0; Index < MpHandOff->CpuCount; Index++) {
-MpHandOff->Info[Index].ApicId = CpuInfoInHob[Index].ApicId;
-MpHandOff->Info[Index].Health = CpuInfoInHob[Index].Health;
+  MpHandOffSize = sizeof (MP_HAND_OFF) + sizeof (PROCESSOR_HAND_OFF) * 
CpusInHob;
+  MpHandOff = (MP_HAND_OFF *)BuildGuidHob (, 
MpHandOffSize);
+  ASSERT (MpHandOff != NULL);
+  ZeroMem (MpHandOff, MpHandOffSize);
+
+  MpHandOff->ProcessorIndex = HobBase;
+  MpHandOff->CpuCount   = CpusInHob;
+
+  if (CpuMpData->ApLoopMode != ApInHltLoop) {
+MpHandOff->StartupSignalValue= MP_HAND_OFF_SIGNAL;
+MpHandOff->WaitLoopExecutionMode = sizeof (VOID *);
+  }
+}
+
+MpHandOff->Info[Index-HobBase].ApicId = CpuInfoInHob[Index].ApicId;
+MpHandOff->Info[Index-HobBase].Health = CpuInfoInHob[Index].Health;
 if (CpuMpData->ApLoopMode != ApInHltLoop) {
-  MpHandOff->Info[Index].StartupSignalAddress= 
(UINT64)(UINTN)CpuMpData->CpuData[Index].StartupApSignal;
-  MpHandOff->Info[Index].StartupProcedureAddress = 
(UINT64)(UINTN)>CpuData[Index].ApFunction;
+  MpHandOff->Info[Index-HobBase].StartupSignalAddress= 
(UINT64)(UINTN)CpuMpData->CpuData[Index].StartupApSignal;
+  MpHandOff->Info[Index-HobBase].StartupProcedureAddress = 
(UINT64)(UINTN)>CpuData[Index].ApFunction;
 }
   }
 
-- 
2.43.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115830): https://edk2.groups.io/g/devel/message/115830
Mute This Topic: https://groups.io/mt/104510911/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3 1/6] UefiCpuPkg/MpInitLib: Add support for multiple HOBs to GetMpHandOffHob

2024-02-22 Thread Gerd Hoffmann
Rename the function to GetNextMpHandOffHob(), add MP_HAND_OFF parameter.
When called with NULL pointer return the body of the first HOB, otherwise
return the next in the chain.

Also add the function prototype to the MpLib.h header file.

Signed-off-by: Gerd Hoffmann 
---
 UefiCpuPkg/Library/MpInitLib/MpLib.h | 12 
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 26 --
 2 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h 
b/UefiCpuPkg/Library/MpInitLib/MpLib.h
index a96a6389c17d..fab2b2d493ca 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
@@ -485,6 +485,18 @@ SwitchApContext (
   IN MP_HAND_OFF  *MpHandOff
   );
 
+/**
+  Get pointer to next MP_HAND_OFF GUIDed HOB body.
+
+  @param[in] MpHandOff  Previous HOB body.  Pass NULL to get the first HOB.
+
+  @return  The pointer to MP_HAND_OFF structure.
+**/
+MP_HAND_OFF *
+GetNextMpHandOffHob (
+  IN CONST MP_HAND_OFF  *MpHandOff
+  );
+
 /**
   Get available EfiBootServicesCode memory below 4GB by specified size.
 
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index cdfb570e61a0..16fc7dc066fd 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -1961,25 +1961,31 @@ SwitchApContext (
 }
 
 /**
-  Get pointer to MP_HAND_OFF GUIDed HOB.
+  Get pointer to next MP_HAND_OFF GUIDed HOB body.
+
+  @param[in] MpHandOff  Previous HOB body.  Pass NULL to get the first HOB.
 
   @return  The pointer to MP_HAND_OFF structure.
 **/
 MP_HAND_OFF *
-GetMpHandOffHob (
-  VOID
+GetNextMpHandOffHob (
+  IN CONST MP_HAND_OFF  *MpHandOff
   )
 {
   EFI_HOB_GUID_TYPE  *GuidHob;
-  MP_HAND_OFF*MpHandOff;
 
-  MpHandOff = NULL;
-  GuidHob   = GetFirstGuidHob ();
-  if (GuidHob != NULL) {
-MpHandOff = (MP_HAND_OFF *)GET_GUID_HOB_DATA (GuidHob);
+  if (MpHandOff == NULL) {
+GuidHob = GetFirstGuidHob ();
+  } else {
+GuidHob = (VOID *)(((UINT8 *)MpHandOff) - sizeof (EFI_HOB_GUID_TYPE));
+GuidHob = GetNextGuidHob (, GET_NEXT_HOB (GuidHob));
   }
 
-  return MpHandOff;
+  if (GuidHob == NULL) {
+return NULL;
+  }
+
+  return (MP_HAND_OFF *)GET_GUID_HOB_DATA (GuidHob);
 }
 
 /**
@@ -2020,7 +2026,7 @@ MpInitLibInitialize (
   UINTNBackupBufferAddr;
   UINTNApIdtBase;
 
-  MpHandOff = GetMpHandOffHob ();
+  MpHandOff = GetNextMpHandOffHob (NULL);
   if (MpHandOff == NULL) {
 MaxLogicalProcessorNumber = PcdGet32 (PcdCpuMaxLogicalProcessorNumber);
   } else {
-- 
2.43.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115828): https://edk2.groups.io/g/devel/message/115828
Mute This Topic: https://groups.io/mt/104510907/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3 4/6] UefiCpuPkg/MpInitLib: Add support for multiple HOBs to MpInitLibInitialize

2024-02-22 Thread Gerd Hoffmann
Loop over all MP_HAND_OFF HOBs instead of expecting a single HOB
covering all CPUs in the system.

Add a new FirstMpHandOff variable, which caches the first HOB body for
faster lookups.  It is also used to check whenever MP_HAND_OFF HOBs are
present.  Using the MpHandOff pointer for that does not work any more
because the variable will be NULL at the end of HOB loops.

Signed-off-by: Gerd Hoffmann 
Reviewed-by: Ray Ni 
---
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 68 +++-
 1 file changed, 47 insertions(+), 21 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index 8eab8b636d78..4b6d6d02b027 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -2025,6 +2025,7 @@ MpInitLibInitialize (
   VOID
   )
 {
+  MP_HAND_OFF  *FirstMpHandOff;
   MP_HAND_OFF  *MpHandOff;
   CPU_INFO_IN_HOB  *CpuInfoInHob;
   UINT32   MaxLogicalProcessorNumber;
@@ -2038,17 +2039,31 @@ MpInitLibInitialize (
   CPU_MP_DATA  *CpuMpData;
   UINT8ApLoopMode;
   UINT8*MonitorBuffer;
-  UINTNIndex;
+  UINT32   Index, HobIndex;
   UINTNApResetVectorSizeBelow1Mb;
   UINTNApResetVectorSizeAbove1Mb;
   UINTNBackupBufferAddr;
   UINTNApIdtBase;
 
-  MpHandOff = GetNextMpHandOffHob (NULL);
-  if (MpHandOff == NULL) {
+  FirstMpHandOff = GetNextMpHandOffHob (NULL);
+  if (FirstMpHandOff != NULL) {
+MaxLogicalProcessorNumber = 0;
+for (MpHandOff = FirstMpHandOff;
+ MpHandOff != NULL;
+ MpHandOff = GetNextMpHandOffHob (MpHandOff))
+{
+  DEBUG ((
+DEBUG_INFO,
+"%a: ProcessorIndex=%u CpuCount=%u\n",
+__func__,
+MpHandOff->ProcessorIndex,
+MpHandOff->CpuCount
+));
+  ASSERT (MaxLogicalProcessorNumber == MpHandOff->ProcessorIndex);
+  MaxLogicalProcessorNumber += MpHandOff->CpuCount;
+}
+  } else {
 MaxLogicalProcessorNumber = PcdGet32 (PcdCpuMaxLogicalProcessorNumber);
-  } else {
-MaxLogicalProcessorNumber = MpHandOff->CpuCount;
   }
 
   ASSERT (MaxLogicalProcessorNumber != 0);
@@ -2192,7 +2207,7 @@ MpInitLibInitialize (
   //
   ProgramVirtualWireMode ();
 
-  if (MpHandOff == NULL) {
+  if (FirstMpHandOff == NULL) {
 if (MaxLogicalProcessorNumber > 1) {
   //
   // Wakeup all APs and calculate the processor count in system
@@ -2208,21 +2223,32 @@ MpInitLibInitialize (
   AmdSevUpdateCpuMpData (CpuMpData);
 }
 
-CpuMpData->CpuCount  = MpHandOff->CpuCount;
-CpuMpData->BspNumber = GetBspNumber (MpHandOff);
+CpuMpData->CpuCount  = MaxLogicalProcessorNumber;
+CpuMpData->BspNumber = GetBspNumber (FirstMpHandOff);
 CpuInfoInHob = (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob;
-for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
-  InitializeSpinLock (>CpuData[Index].ApLock);
-  CpuMpData->CpuData[Index].CpuHealthy = (MpHandOff->Info[Index].Health == 
0) ? TRUE : FALSE;
-  CpuMpData->CpuData[Index].ApFunction = 0;
-  CpuInfoInHob[Index].InitialApicId= MpHandOff->Info[Index].ApicId;
-  CpuInfoInHob[Index].ApTopOfStack = CpuMpData->Buffer + (Index + 1) * 
CpuMpData->CpuApStackSize;
-  CpuInfoInHob[Index].ApicId   = MpHandOff->Info[Index].ApicId;
-  CpuInfoInHob[Index].Health   = MpHandOff->Info[Index].Health;
+for (MpHandOff = FirstMpHandOff;
+ MpHandOff != NULL;
+ MpHandOff = GetNextMpHandOffHob (MpHandOff))
+{
+  for (HobIndex = 0; HobIndex < MpHandOff->CpuCount; HobIndex++) {
+Index = MpHandOff->ProcessorIndex + HobIndex;
+InitializeSpinLock (>CpuData[Index].ApLock);
+CpuMpData->CpuData[Index].CpuHealthy = 
(MpHandOff->Info[HobIndex].Health == 0) ? TRUE : FALSE;
+CpuMpData->CpuData[Index].ApFunction = 0;
+CpuInfoInHob[Index].InitialApicId= 
MpHandOff->Info[HobIndex].ApicId;
+CpuInfoInHob[Index].ApTopOfStack = CpuMpData->Buffer + (Index + 1) 
* CpuMpData->CpuApStackSize;
+CpuInfoInHob[Index].ApicId   = 
MpHandOff->Info[HobIndex].ApicId;
+CpuInfoInHob[Index].Health   = 
MpHandOff->Info[HobIndex].Health;
+  }
 }
 
-DEBUG ((DEBUG_INFO, "MpHandOff->WaitLoopExecutionMode: %04d, sizeof (VOID 
*): %04d\n", MpHandOff->WaitLoopExecutionMode, sizeof (VOID *)));
-if (MpHandOff->WaitLoopExecutionMode == sizeof (VOID *)) {
+DEBUG ((
+  DEBUG_INFO,
+  "FirstMpHandOff->WaitLoopExecutionMode: %04d, sizeof (VOID *): %04d\n",
+  FirstMpHandOff->WaitLoopExecutionMode,
+  sizeof (VOID *)
+  ));
+if (FirstMpHandOff->WaitLoopExecutionMode == sizeof (VOID *)) {
   ASSERT (CpuMpData->ApLoopMode != ApInHltLoop);
 
   CpuMpData->FinishedCount= 0;
@@ -2238,7 

[edk2-devel] [PATCH v3 3/6] UefiCpuPkg/MpInitLib: Add support for multiple HOBs to SwitchApContext()

2024-02-22 Thread Gerd Hoffmann
Rename the MpHandOff parameter to FirstMpHandOff.  Add loops so the
function inspects all HOBs present in the system.

Signed-off-by: Gerd Hoffmann 
Reviewed-by: Ray Ni 
Reviewed-by: Laszlo Ersek 
---
 UefiCpuPkg/Library/MpInitLib/MpLib.h |  2 +-
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 35 ++--
 2 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h 
b/UefiCpuPkg/Library/MpInitLib/MpLib.h
index fab2b2d493ca..3a7b9896cff4 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
@@ -482,7 +482,7 @@ GetWakeupBuffer (
 **/
 VOID
 SwitchApContext (
-  IN MP_HAND_OFF  *MpHandOff
+  IN CONST MP_HAND_OFF  *FirstMpHandOff
   );
 
 /**
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index 76449f73f4a7..8eab8b636d78 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -1938,31 +1938,42 @@ GetBspNumber (
   This procedure allows the AP to switch to another section of
   memory and continue its loop there.
 
-  @param[in] MpHandOff  Pointer to MP hand-off data structure.
+  @param[in] FirstMpHandOff  Pointer to first MP hand-off HOB body.
 **/
 VOID
 SwitchApContext (
-  IN MP_HAND_OFF  *MpHandOff
+  IN CONST MP_HAND_OFF  *FirstMpHandOff
   )
 {
-  UINTN   Index;
-  UINT32  BspNumber;
+  UINTN  Index;
+  UINT32 BspNumber;
+  CONST MP_HAND_OFF  *MpHandOff;
 
-  BspNumber = GetBspNumber (MpHandOff);
+  BspNumber = GetBspNumber (FirstMpHandOff);
 
-  for (Index = 0; Index < MpHandOff->CpuCount; Index++) {
-if (Index != BspNumber) {
-  *(UINTN *)(UINTN)MpHandOff->Info[Index].StartupProcedureAddress = 
(UINTN)SwitchContextPerAp;
-  *(UINT32 *)(UINTN)MpHandOff->Info[Index].StartupSignalAddress   = 
MpHandOff->StartupSignalValue;
+  for (MpHandOff = FirstMpHandOff;
+   MpHandOff != NULL;
+   MpHandOff = GetNextMpHandOffHob (MpHandOff))
+  {
+for (Index = 0; Index < MpHandOff->CpuCount; Index++) {
+  if (MpHandOff->ProcessorIndex + Index != BspNumber) {
+*(UINTN *)(UINTN)MpHandOff->Info[Index].StartupProcedureAddress = 
(UINTN)SwitchContextPerAp;
+*(UINT32 *)(UINTN)MpHandOff->Info[Index].StartupSignalAddress   = 
MpHandOff->StartupSignalValue;
+  }
 }
   }
 
   //
   // Wait all APs waken up if this is not the 1st broadcast of SIPI
   //
-  for (Index = 0; Index < MpHandOff->CpuCount; Index++) {
-if (Index != BspNumber) {
-  WaitApWakeup ((UINT32 
*)(UINTN)(MpHandOff->Info[Index].StartupSignalAddress));
+  for (MpHandOff = FirstMpHandOff;
+   MpHandOff != NULL;
+   MpHandOff = GetNextMpHandOffHob (MpHandOff))
+  {
+for (Index = 0; Index < MpHandOff->CpuCount; Index++) {
+  if (MpHandOff->ProcessorIndex + Index != BspNumber) {
+WaitApWakeup ((UINT32 
*)(UINTN)(MpHandOff->Info[Index].StartupSignalAddress));
+  }
 }
   }
 }
-- 
2.43.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115827): https://edk2.groups.io/g/devel/message/115827
Mute This Topic: https://groups.io/mt/104510906/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3 0/6] UefiCpuPkg/MpInitLib: Add support for multiple MP_HAND_OFF HOBs

2024-02-22 Thread Gerd Hoffmann
Needed to boot guests with thousands of vcpus.

v3:
 - refine comments and commit messages.
 - fix MaxCpusPerHob calculation.
 - pick up review tags.
 - add patch to speed up GetBspNumber a bit.
v2:
 - rework HOB loops for better performance: O(n) instead of O(n^2).

Gerd Hoffmann (6):
  UefiCpuPkg/MpInitLib: Add support for multiple HOBs to GetMpHandOffHob
  UefiCpuPkg/MpInitLib: Add support for multiple HOBs to GetBspNumber()
  UefiCpuPkg/MpInitLib: Add support for multiple HOBs to
SwitchApContext()
  UefiCpuPkg/MpInitLib: Add support for multiple HOBs to
MpInitLibInitialize
  UefiCpuPkg/MpInitLib: Add support for multiple HOBs to SaveCpuMpData()
  UefiCpuPkg/MpInitLib: return early in GetBspNumber()

 UefiCpuPkg/Library/MpInitLib/MpLib.h|  14 ++-
 UefiCpuPkg/Library/MpInitLib/MpLib.c| 157 +++-
 UefiCpuPkg/Library/MpInitLib/PeiMpLib.c |  44 ---
 3 files changed, 142 insertions(+), 73 deletions(-)

-- 
2.43.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115826): https://edk2.groups.io/g/devel/message/115826
Mute This Topic: https://groups.io/mt/104510905/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3 2/6] UefiCpuPkg/MpInitLib: Add support for multiple HOBs to GetBspNumber()

2024-02-22 Thread Gerd Hoffmann
Rename the MpHandOff parameter to FirstMpHandOff.  Add a loop so the
function inspects all HOBs present in the system.

Signed-off-by: Gerd Hoffmann 
Reviewed-by: Ray Ni 
Reviewed-by: Laszlo Ersek 
---
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 23 +++
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index 16fc7dc066fd..76449f73f4a7 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -1894,26 +1894,33 @@ CheckAllAPs (
 /**
   This function Get BspNumber.
 
-  @param[in] MpHandOffPointer to MpHandOff
+  @param[in] FirstMpHandOff   Pointer to first MpHandOff HOB body.
   @return BspNumber
 **/
 UINT32
 GetBspNumber (
-  IN CONST MP_HAND_OFF  *MpHandOff
+  IN CONST MP_HAND_OFF  *FirstMpHandOff
   )
 {
-  UINT32  ApicId;
-  UINT32  BspNumber;
-  UINT32  Index;
+  UINT32 ApicId;
+  UINT32 BspNumber;
+  UINT32 Index;
+  CONST MP_HAND_OFF  *MpHandOff;
 
   //
   // Get the processor number for the BSP
   //
   BspNumber = MAX_UINT32;
   ApicId= GetInitialApicId ();
-  for (Index = 0; Index < MpHandOff->CpuCount; Index++) {
-if (MpHandOff->Info[Index].ApicId == ApicId) {
-  BspNumber = Index;
+
+  for (MpHandOff = FirstMpHandOff;
+   MpHandOff != NULL;
+   MpHandOff = GetNextMpHandOffHob (MpHandOff))
+  {
+for (Index = 0; Index < MpHandOff->CpuCount; Index++) {
+  if (MpHandOff->Info[Index].ApicId == ApicId) {
+BspNumber = MpHandOff->ProcessorIndex + Index;
+  }
 }
   }
 
-- 
2.43.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115825): https://edk2.groups.io/g/devel/message/115825
Mute This Topic: https://groups.io/mt/104510904/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] GuestPhysAddrSize questions

2024-02-22 Thread Lendacky, Thomas via groups.io

On 2/22/24 05:24, Gerd Hoffmann wrote:

   Hi,


+if (Cr4.Bits.LA57) {
+  if (PhysBits > 48) {
+/*
+ * Some Intel CPUs support 5-level paging, have more than 48
+ * phys-bits but support only 4-level EPT, which effectively
+ * limits guest phys-bits to 48.
+ *
+ * AMD Processors have a different but somewhat related
+ * problem: They can handle guest phys-bits larger than 48
+ * only in case the host runs in 5-level paging mode.
+ *
+ * Until we have some way to communicate that kind of
+ * limitations from hypervisor to guest, limit phys-bits
+ * to 48 unconditionally.
+ */


So I'm looking for some communication path.  One option would be to use
some bits in the KVM cpuid leaves.  Another possible candidate is cpuid
leaf 0x8008.

 From the AMD APM (revision 3.35):

   CPUID Fn8000_0008_EAX Long Mode Size Identifiers
   

   The value returned in EAX provides information about the maximum host
   and guest physical and linear address width (in bits) supported by the
   processor.

   Bits   FieldNameDescription

   31:24  —Reserved

   23:16 GuestPhysAddrSize Maximum guest physical address size in bits.
   This number applies only to guests using nested
   paging. When this field is zero, refer to the
   PhysAddrSize field for the maximum guest
   physical address size. See “Secure Virtual
   Machine” in APM Volume 2.

   15:8  LinAddrSize   Maximum linear address size in bits.

   7:0   PhysAddrSize  Maximum physical address size in bits. When
   GuestPhysAddrSize is zero, this field also
   indicates the maximum guest physical address
   size.

The description of the GuestPhysAddrSize is somewhat vague.  Is this a
value the hypervisor should use to figure how much address space it can
give to guests?  Or is this a value the hypervisor can set to inform the
guest about the available address space (which would be a solution to
the problem outlined in the comment above)?  Or both?


I believe the main purpose of GuestPhysAddrSize was for software use (for 
nested virtualization) and that the hardware itself has always returned 
zero for that value. So you should be able to use that field. Adding 
@Paolo for his thoughts.


Thanks,
Tom



In case GuestPhysAddrSize should not be used this way:  Is it possible
allocate the currently reserved bits 31:24 for that purpose?

Tom?  Michael?

thanks & take care,
   Gerd




-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115824): https://edk2.groups.io/g/devel/message/115824
Mute This Topic: https://groups.io/mt/104510523/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v2 6/6] RedfishPkg/RedfishCrtLib: fix unresolved external symbol issue

2024-02-22 Thread Igor Kulchytskyy via groups.io
Reviewed-by: Igor Kulchytskyy 

-Original Message-
From: Nickle Wang 
Sent: Thursday, February 22, 2024 4:12 AM
To: devel@edk2.groups.io
Cc: Abner Chang ; Igor Kulchytskyy ; Nick 
Ramirez 
Subject: [EXTERNAL] [PATCH v2 6/6] RedfishPkg/RedfishCrtLib: fix unresolved 
external symbol issue


**CAUTION: The e-mail below is from an external source. Please exercise caution 
before opening attachments, clicking links, or following guidance.**

-Fix below compiler error reported in edk2 CI.
ERROR - Linker #2001 from JsonLib.lib(load.obj) : unresolved external
symbol __ftol2
-The file MathFtol.c is copied from IntrinsicLib in CryptoPkg.
-Add MathFtol.c to EccCheck IgnoreFiles.

Signed-off-by: Nickle Wang 
Cc: Abner Chang 
Cc: Igor Kulchytskyy 
Cc: Nick Ramirez 
---
 .../RedfishCrtLib/RedfishCrtLib.inf   |  7 +++-
 .../RedfishCrtLib/Ia32/MathFtol.c | 37 +++
 RedfishPkg/RedfishPkg.ci.yaml |  2 +
 3 files changed, 45 insertions(+), 1 deletion(-)
 create mode 100644 RedfishPkg/PrivateLibrary/RedfishCrtLib/Ia32/MathFtol.c

diff --git a/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf 
b/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf
index 6ff5dba75c..3a5e309d1a 100644
--- a/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf
+++ b/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf
@@ -3,6 +3,7 @@
 #
 # Copyright (c) 2019, Intel Corporation. All rights reserved.
 # (C) Copyright 2020 Hewlett Packard Enterprise Development LP
+# Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 #
 #SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -23,6 +24,9 @@
 [Sources]
   RedfishCrtLib.c

+[Sources.IA32]
+  Ia32/MathFtol.c   | MSFT
+
 [LibraryClasses]
   BaseLib
   SortLib
@@ -35,4 +39,5 @@
   MdeModulePkg/MdeModulePkg.dec
   RedfishPkg/RedfishPkg.dec

-
+[BuildOptions]
+  MSFT:*_*_IA32_CC_FLAGS = /GL-
diff --git a/RedfishPkg/PrivateLibrary/RedfishCrtLib/Ia32/MathFtol.c 
b/RedfishPkg/PrivateLibrary/RedfishCrtLib/Ia32/MathFtol.c
new file mode 100644
index 00..e49f00eaf5
--- /dev/null
+++ b/RedfishPkg/PrivateLibrary/RedfishCrtLib/Ia32/MathFtol.c
@@ -0,0 +1,37 @@
+/** @file This file is copied from 
CryptoPkg/Library/IntrinsicLib/Ia32/MathFtol.c
+  64-bit Math Worker Function.
+  The 32-bit versions of C compiler generate calls to library routines
+  to handle 64-bit math. These functions use non-standard calling conventions.
+
+Copyright (c) 2019, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+/*
+ * Floating point to integer conversion.
+ */
+__declspec(naked) void
+_ftol2 (
+  void
+  )
+{
+  _asm {
+fistp qword ptr [esp-8]
+mov   edx, [esp-4]
+mov   eax, [esp-8]
+ret
+  }
+}
+
+__declspec(naked) void
+_ftol2_sse (
+  void
+  )
+{
+  _asm {
+fistp dword ptr [esp-4]
+mov   eax,[esp-4]
+ret
+  }
+}
diff --git a/RedfishPkg/RedfishPkg.ci.yaml b/RedfishPkg/RedfishPkg.ci.yaml
index 69b6bf39f5..b95e8bfdc7 100644
--- a/RedfishPkg/RedfishPkg.ci.yaml
+++ b/RedfishPkg/RedfishPkg.ci.yaml
@@ -2,6 +2,7 @@
 # CI configuration for NetworkPkg
 #
 # (C) Copyright 2021 Hewlett Packard Enterprise Development LP
+# Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 ##
 {
@@ -38,6 +39,7 @@
 "PrivateInclude/Crt/string.h",
 "PrivateInclude/Crt/time.h",
 "PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c",
+"PrivateLibrary/RedfishCrtLib/Ia32/MathFtol.c",
 "Include/Library/RedfishCrtLib.h",
 ##
 ## For jansson library open source
--
2.34.1

-The information contained in this message may be confidential and proprietary 
to American Megatrends (AMI). This communication is intended to be read only by 
the individual or entity to whom it is addressed or by their designee. If the 
reader of this message is not the intended recipient, you are on notice that 
any distribution of this message, in any form, is strictly prohibited. Please 
promptly notify the sender by reply e-mail or by telephone at 770-246-8600, and 
then delete or destroy all copies of the transmission.


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115823): https://edk2.groups.io/g/devel/message/115823
Mute This Topic: https://groups.io/mt/104505407/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v2 5/6] RedfishPkg/RedfishDebugLib: use RedfishHttpLib

2024-02-22 Thread Igor Kulchytskyy via groups.io
Reviewed-by: Igor Kulchytskyy 

-Original Message-
From: Nickle Wang 
Sent: Thursday, February 22, 2024 4:12 AM
To: devel@edk2.groups.io
Cc: Abner Chang ; Igor Kulchytskyy ; Nick 
Ramirez 
Subject: [EXTERNAL] [PATCH v2 5/6] RedfishPkg/RedfishDebugLib: use 
RedfishHttpLib


**CAUTION: The e-mail below is from an external source. Please exercise caution 
before opening attachments, clicking links, or following guidance.**

Remove RedfishLib and use RedfishHttpLib for debug printing
Redfish response data.

Signed-off-by: Nickle Wang 
Cc: Abner Chang 
Cc: Igor Kulchytskyy 
Cc: Nick Ramirez 
Reviewed-by: Abner Chang 
---
 RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.inf | 4 ++--
 RedfishPkg/Include/Library/RedfishDebugLib.h   | 2 +-
 RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.c   | 1 +
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.inf 
b/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.inf
index 048d27c6dc..d468bb213b 100644
--- a/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.inf
+++ b/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.inf
@@ -1,7 +1,7 @@
 ## @file
 #  INF file for Redfish debug library.
 #
-#  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+#  Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights 
reserved.
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -32,7 +32,7 @@
   DebugLib
   JsonLib
   MemoryAllocationLib
-  RedfishLib
+  RedfishHttpLib
   UefiLib

 [Depex]
diff --git a/RedfishPkg/Include/Library/RedfishDebugLib.h 
b/RedfishPkg/Include/Library/RedfishDebugLib.h
index 3430cf1d14..ad7a697586 100644
--- a/RedfishPkg/Include/Library/RedfishDebugLib.h
+++ b/RedfishPkg/Include/Library/RedfishDebugLib.h
@@ -11,9 +11,9 @@
 #define REDFISH_DEBUG_LIB_H_

 #include 
+#include 
 #include 
 #include 
-#include 

 #include 

diff --git a/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.c 
b/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.c
index 3728f51213..8b0425b8c3 100644
--- a/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.c
+++ b/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 

 #ifndef IS_EMPTY_STRING
--
2.34.1

-The information contained in this message may be confidential and proprietary 
to American Megatrends (AMI). This communication is intended to be read only by 
the individual or entity to whom it is addressed or by their designee. If the 
reader of this message is not the intended recipient, you are on notice that 
any distribution of this message, in any form, is strictly prohibited. Please 
promptly notify the sender by reply e-mail or by telephone at 770-246-8600, and 
then delete or destroy all copies of the transmission.


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115822): https://edk2.groups.io/g/devel/message/115822
Mute This Topic: https://groups.io/mt/104505408/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v2 4/6] RedfishPkg/RedfishLib: include RedfishServiceData.h

2024-02-22 Thread Igor Kulchytskyy via groups.io
Reviewed-by: Igor Kulchytskyy 

-Original Message-
From: Nickle Wang 
Sent: Thursday, February 22, 2024 4:12 AM
To: devel@edk2.groups.io
Cc: Abner Chang ; Igor Kulchytskyy ; Nick 
Ramirez 
Subject: [EXTERNAL] [PATCH v2 4/6] RedfishPkg/RedfishLib: include 
RedfishServiceData.h


**CAUTION: The e-mail below is from an external source. Please exercise caution 
before opening attachments, clicking links, or following guidance.**

Redfish common structures are moved to RedfishServiceData.h. Remove
them from RedfishLib.h

Signed-off-by: Nickle Wang 
Cc: Abner Chang 
Cc: Igor Kulchytskyy 
Cc: Nick Ramirez 
Reviewed-by: Abner Chang 
---
 RedfishPkg/Include/Library/RedfishLib.h | 17 +
 1 file changed, 1 insertion(+), 16 deletions(-)

diff --git a/RedfishPkg/Include/Library/RedfishLib.h 
b/RedfishPkg/Include/Library/RedfishLib.h
index 8309a67c76..fb30ff68f6 100644
--- a/RedfishPkg/Include/Library/RedfishLib.h
+++ b/RedfishPkg/Include/Library/RedfishLib.h
@@ -70,6 +70,7 @@
 #ifndef REDFISH_LIB_H_
 #define REDFISH_LIB_H_

+#include 
 #include 

 #include 
@@ -78,22 +79,6 @@
 #define ODATA_TYPE_NAME_MAX_SIZE  128
 #define ODATA_TYPE_MAX_SIZE   128

-///
-/// Library class public defines
-///
-typedef  VOID  *REDFISH_SERVICE;
-typedef  VOID  *REDFISH_PAYLOAD;
-
-///
-/// Library class public structures/unions
-///
-typedef struct {
-  EFI_HTTP_STATUS_CODE*StatusCode;
-  UINTN   HeaderCount;
-  EFI_HTTP_HEADER *Headers;
-  REDFISH_PAYLOAD Payload;
-} REDFISH_RESPONSE;
-
 ///
 /// Odata type-name mapping structure.
 ///
--
2.34.1

-The information contained in this message may be confidential and proprietary 
to American Megatrends (AMI). This communication is intended to be read only by 
the individual or entity to whom it is addressed or by their designee. If the 
reader of this message is not the intended recipient, you are on notice that 
any distribution of this message, in any form, is strictly prohibited. Please 
promptly notify the sender by reply e-mail or by telephone at 770-246-8600, and 
then delete or destroy all copies of the transmission.


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115821): https://edk2.groups.io/g/devel/message/115821
Mute This Topic: https://groups.io/mt/104505403/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v2 2/6] RedfishPkg: implement Redfish HTTP protocol

2024-02-22 Thread Igor Kulchytskyy via groups.io
Reviewed-by: Igor Kulchytskyy 

-Original Message-
From: Nickle Wang 
Sent: Thursday, February 22, 2024 4:11 AM
To: devel@edk2.groups.io
Cc: Igor Kulchytskyy ; Abner Chang ; Nick 
Ramirez 
Subject: [EXTERNAL] [PATCH v2 2/6] RedfishPkg: implement Redfish HTTP protocol


**CAUTION: The e-mail below is from an external source. Please exercise caution 
before opening attachments, clicking links, or following guidance.**

implement Redfish HTTP protocol driver.

Signed-off-by: Nickle Wang 
Co-authored-by: Igor Kulchytskyy 
Cc: Abner Chang 
Cc: Igor Kulchytskyy 
Cc: Nick Ramirez 
---
 RedfishPkg/RedfishPkg.dec |7 +-
 RedfishPkg/RedfishComponents.dsc.inc  |3 +-
 RedfishPkg/RedfishPkg.dsc |2 +
 RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.inf  |   73 +
 RedfishPkg/RedfishHttpDxe/RedfishHttpData.h   |  256 
 RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.h|   44 +
 .../RedfishHttpDxe/RedfishHttpOperation.h |   76 +
 RedfishPkg/RedfishHttpDxe/RedfishHttpData.c   |  667 
 RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.c| 1344 +
 .../RedfishHttpDxe/RedfishHttpOperation.c |  693 +
 RedfishPkg/Redfish.fdf.inc|3 +-
 11 files changed, 3164 insertions(+), 4 deletions(-)
 create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.inf
 create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpData.h
 create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.h
 create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpOperation.h
 create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpData.c
 create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.c
 create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpOperation.c

diff --git a/RedfishPkg/RedfishPkg.dec b/RedfishPkg/RedfishPkg.dec
index 9b424efdf3..114f8d2ad8 100644
--- a/RedfishPkg/RedfishPkg.dec
+++ b/RedfishPkg/RedfishPkg.dec
@@ -157,8 +157,11 @@
   # set to EFI_REST_EX_PROTOCOL.
   #
   
gEfiRedfishPkgTokenSpaceGuid.PcdRedfishSendReceiveTimeout|5000|UINT32|0x1009
-  ## This is used to enable HTTP content encoding on Redfish communication.
-  
gEfiRedfishPkgTokenSpaceGuid.PcdRedfishServiceContentEncoding|TRUE|BOOLEAN|0x100A
+  #
+  # This PCD string is introduced for platform developer to set the encoding 
method supported by BMC Redfish.
+  # Currently only "None" and "gzip" are supported.
+  #
+  
gEfiRedfishPkgTokenSpaceGuid.PcdRedfishServiceContentEncoding|"None"|VOID*|0x100A
   #
   # Use below PCDs to control Redfhs HTTP protocol.
   #
diff --git a/RedfishPkg/RedfishComponents.dsc.inc 
b/RedfishPkg/RedfishComponents.dsc.inc
index 464ffc8606..d6c5b73d7f 100644
--- a/RedfishPkg/RedfishComponents.dsc.inc
+++ b/RedfishPkg/RedfishComponents.dsc.inc
@@ -7,7 +7,7 @@
 # "RedfishDefines.dsc.inc".
 #
 # (C) Copyright 2020-2021 Hewlett Packard Enterprise Development LP
-# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+# Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights 
reserved.
 #
 #SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -28,4 +28,5 @@
   RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.inf
   RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigDxe.inf
   MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
+  RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.inf
 !endif
diff --git a/RedfishPkg/RedfishPkg.dsc b/RedfishPkg/RedfishPkg.dsc
index 25ed193182..5849e7cf9e 100644
--- a/RedfishPkg/RedfishPkg.dsc
+++ b/RedfishPkg/RedfishPkg.dsc
@@ -45,6 +45,8 @@
   
UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf
   
RedfishPlatformCredentialLib|RedfishPkg/Library/PlatformCredentialLibNull/PlatformCredentialLibNull.inf
   
RedfishContentCodingLib|RedfishPkg/Library/RedfishContentCodingLibNull/RedfishContentCodingLibNull.inf
+  
ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf
+  SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf

   # NULL instance of IPMI related library.
   IpmiLib|MdeModulePkg/Library/BaseIpmiLibNull/BaseIpmiLibNull.inf
diff --git a/RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.inf 
b/RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.inf
new file mode 100644
index 00..c7dfdffacf
--- /dev/null
+++ b/RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.inf
@@ -0,0 +1,73 @@
+## @file
+#  RedfishHttpDxe is the DXE driver which provides
+#  EdkIIRedfishHttpProtocol to EDK2 Redfish Feature
+#  drivers for HTTP operation.
+#
+#  Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights 
reserved.
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION= 0x0001000b
+  BASE_NAME  = RedfishHttpDxe
+  FILE_GUID  = 85ADB2F1-DA93-47D4-AF4F-3D920D9BD2C0
+  MODULE_TYPE= DXE_DRIVER
+  VERSION_STRING = 1.0
+  ENTRY_POINT= 

Re: [edk2-devel] [PATCH v2 3/6] RedfishPkg: introduce RedfishHttpLib

2024-02-22 Thread Igor Kulchytskyy via groups.io
Reviewed-by: Igor Kulchytskyy 

-Original Message-
From: Nickle Wang 
Sent: Thursday, February 22, 2024 4:12 AM
To: devel@edk2.groups.io
Cc: Abner Chang ; Igor Kulchytskyy ; Nick 
Ramirez 
Subject: [EXTERNAL] [PATCH v2 3/6] RedfishPkg: introduce RedfishHttpLib


**CAUTION: The e-mail below is from an external source. Please exercise caution 
before opening attachments, clicking links, or following guidance.**

RedfishHttpLib is a wrapper library for Redfish feature drivers to
call Redfish HTTP Protocol easily.

Signed-off-by: Nickle Wang 
Cc: Abner Chang 
Cc: Igor Kulchytskyy 
Cc: Nick Ramirez 
Reviewed-by: Abner Chang 
---
 RedfishPkg/RedfishPkg.dec |   5 +
 RedfishPkg/RedfishLibs.dsc.inc|   3 +-
 RedfishPkg/RedfishPkg.dsc |   3 +-
 .../Library/RedfishHttpLib/RedfishHttpLib.inf |  43 ++
 RedfishPkg/Include/Library/RedfishHttpLib.h   | 326 ++
 .../Library/RedfishHttpLib/RedfishHttpLib.c   | 585 ++
 6 files changed, 963 insertions(+), 2 deletions(-)
 create mode 100644 RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.inf
 create mode 100644 RedfishPkg/Include/Library/RedfishHttpLib.h
 create mode 100644 RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.c

diff --git a/RedfishPkg/RedfishPkg.dec b/RedfishPkg/RedfishPkg.dec
index 114f8d2ad8..1a9c9ed7bc 100644
--- a/RedfishPkg/RedfishPkg.dec
+++ b/RedfishPkg/RedfishPkg.dec
@@ -69,6 +69,11 @@
   #
   RedfishPlatformConfigLib|Include/Library/RedfishPlatformConfigLib.h

+  ##  @libraryclass  Provides the library functions to access Redfish HTTP
+  #   protocol.
+  #
+  RedfishHttpLib|Include/Library/RedfishHttpLib.h
+
 [LibraryClasses.Common.Private]
   ##  @libraryclass  Provides the private C runtime library functions.
   #   CRT library is currently used by edk2 JsonLib (open source
diff --git a/RedfishPkg/RedfishLibs.dsc.inc b/RedfishPkg/RedfishLibs.dsc.inc
index 5426957da8..55846aaa9d 100644
--- a/RedfishPkg/RedfishLibs.dsc.inc
+++ b/RedfishPkg/RedfishLibs.dsc.inc
@@ -6,7 +6,7 @@
 # of EDKII network library classes.
 #
 # (C) Copyright 2021 Hewlett Packard Enterprise Development LP
-# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+# Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights 
reserved.
 #
 #SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -21,5 +21,6 @@
   
RedfishPlatformCredentialLib|RedfishPkg/Library/RedfishPlatformCredentialIpmiLib/RedfishPlatformCredentialIpmiLib.inf
   HiiUtilityLib|RedfishPkg/Library/HiiUtilityLib/HiiUtilityLib.inf
   
RedfishPlatformConfigLib|RedfishPkg/Library/RedfishPlatformConfigLib/RedfishPlatformConfigLib.inf
+  RedfishHttpLib|RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.inf
 !endif

diff --git a/RedfishPkg/RedfishPkg.dsc b/RedfishPkg/RedfishPkg.dsc
index 5849e7cf9e..b0150043a9 100644
--- a/RedfishPkg/RedfishPkg.dsc
+++ b/RedfishPkg/RedfishPkg.dsc
@@ -4,7 +4,7 @@
 # Copyright (c) 2019 - 2021, Intel Corporation. All rights reserved.
 # (C) Copyright 2021 Hewlett-Packard Enterprise Development LP.
 # Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
-# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+# Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights 
reserved.
 #
 #SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -74,5 +74,6 @@
   RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.inf
   RedfishPkg/Library/HiiUtilityLib/HiiUtilityLib.inf
   RedfishPkg/Library/RedfishPlatformConfigLib/RedfishPlatformConfigLib.inf
+  RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.inf

   !include RedfishPkg/Redfish.dsc.inc
diff --git a/RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.inf 
b/RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.inf
new file mode 100644
index 00..fd53b8c2ed
--- /dev/null
+++ b/RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.inf
@@ -0,0 +1,43 @@
+## @file
+#  Redfish HTTP library is wrapper library for application to call Redfish
+#  HTTP protocol easily.
+#
+#  Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights 
reserved.
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION= 0x00010006
+  BASE_NAME  = RedfishHttpLib
+  FILE_GUID  = 62855D9B-441B-436B-9CA6-B7FEB7ABF54E
+  MODULE_TYPE= DXE_DRIVER
+  VERSION_STRING = 1.0
+  LIBRARY_CLASS  = RedfishHttpLib| DXE_DRIVER UEFI_DRIVER
+  CONSTRUCTOR= RedfishHttpConstructor
+
+#
+#  VALID_ARCHITECTURES   = IA32 X64 EBC
+#
+
+[Sources]
+  RedfishHttpLib.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  RedfishPkg/RedfishPkg.dec
+
+[LibraryClasses]
+  BaseLib
+  DebugLib
+  UefiLib
+  UefiBootServicesTableLib
+
+[Protocols]
+  gEdkIIRedfishHttpProtocolGuid   ## CONSUMES ##
+
+[depex]
+  TRUE
+
diff --git 

Re: [edk2-devel] [PATCH v2 1/6] RedfishPkg: introduce Redfish HTTP protocol

2024-02-22 Thread Igor Kulchytskyy via groups.io
Reviewed-by: Igor Kulchytskyy 

-Original Message-
From: Nickle Wang 
Sent: Thursday, February 22, 2024 4:11 AM
To: devel@edk2.groups.io
Cc: Igor Kulchytskyy ; Abner Chang ; Nick 
Ramirez 
Subject: [EXTERNAL] [PATCH v2 1/6] RedfishPkg: introduce Redfish HTTP protocol


**CAUTION: The e-mail below is from an external source. Please exercise caution 
before opening attachments, clicking links, or following guidance.**

Introduce Redfish HTTP protocol to improve Redfish performance
and communication stability between BIOS and Redfish service.
- Feature drivers often query same Redfish resource multiple
times for different purpose. Implement HTTP cache mechanism to
improve HTTP GET performance. "UseCache" parameter is provided
if application likes to send HTTP GET request to Redfish service
without using cache data.
- This driver will retire stale cache data automatically when
application modify Redfish resource at service side.
- PCD PcdHttpCacheDisabled is used to disable cache mechanism in
this driver for debugging purpose.
- PCD PcdRedfishServiceContentEncoding is used to enable content
encoding while sending data to Redfish service.
- Redfish HTTP protocol also implement retry mechanism to retry
HTTP request when BIOS receive unexpected response from Redfish service.
This function helps BIOS Redfish to finish its job as much as possible.
- PCDs are defined to control how many times BIOS will retry the
request and how many time BIOS will wait between retries.

Signed-off-by: Nickle Wang 
Co-authored-by: Igor Kulchytskyy 
Cc: Abner Chang 
Cc: Igor Kulchytskyy 
Cc: Nick Ramirez 
Reviewed-by: Abner Chang 
---
 RedfishPkg/RedfishPkg.dec |  24 +-
 .../Protocol/EdkIIRedfishHttpProtocol.h   | 308 ++
 RedfishPkg/Include/RedfishServiceData.h   |  43 +++
 3 files changed, 374 insertions(+), 1 deletion(-)
 create mode 100644 RedfishPkg/Include/Protocol/EdkIIRedfishHttpProtocol.h
 create mode 100644 RedfishPkg/Include/RedfishServiceData.h

diff --git a/RedfishPkg/RedfishPkg.dec b/RedfishPkg/RedfishPkg.dec
index 3ea9ff3ef7..9b424efdf3 100644
--- a/RedfishPkg/RedfishPkg.dec
+++ b/RedfishPkg/RedfishPkg.dec
@@ -4,7 +4,7 @@
 # Copyright (c) 2019, Intel Corporation. All rights reserved.
 # (C) Copyright 2021 Hewlett Packard Enterprise Development LP
 # Copyright (c) 2023, American Megatrends International LLC.
-# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+# Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights 
reserved.
 #
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 ##
@@ -93,6 +93,9 @@
   # Redfish Host Interface ready notification protocol
   gEdkIIRedfishHostInterfaceReadyProtocolGuid = { 0xC3F6D062, 0x3D38, 0x4EA4, 
{ 0x92, 0xB1, 0xE8, 0xF8, 0x02, 0x27, 0x63, 0xDF } }

+  ## Include/Protocol/EdkIIRedfishHttpProtocol.h
+  gEdkIIRedfishHttpProtocolGuid = { 0x58a0f47e, 0xf45f, 0x4d44, { 0x89, 0x5b, 
0x2a, 0xfe, 0xb0, 0x80, 0x15, 0xe2 } }
+
 [Guids]
   gEfiRedfishPkgTokenSpaceGuid  = { 0x4fdbccb7, 0xe829, 0x4b4c, { 0x88, 
0x87, 0xb2, 0x3f, 0xd7, 0x25, 0x4b, 0x85 }}

@@ -154,3 +157,22 @@
   # set to EFI_REST_EX_PROTOCOL.
   #
   
gEfiRedfishPkgTokenSpaceGuid.PcdRedfishSendReceiveTimeout|5000|UINT32|0x1009
+  ## This is used to enable HTTP content encoding on Redfish communication.
+  
gEfiRedfishPkgTokenSpaceGuid.PcdRedfishServiceContentEncoding|TRUE|BOOLEAN|0x100A
+  #
+  # Use below PCDs to control Redfhs HTTP protocol.
+  #
+  ## The number of retry when HTTP GET request failed. If the value is 0, 
there is no retry enabled.
+  gEfiRedfishPkgTokenSpaceGuid.PcdHttpGetRetry|0|UINT16|0x100B
+  ## The number of retry when HTTP PUT request failed. If the value is 0, 
there is no retry enabled.
+  gEfiRedfishPkgTokenSpaceGuid.PcdHttpPutRetry|0|UINT16|0x100C
+  ## The number of retry when HTTP PATCH request failed. If the value is 0, 
there is no retry enabled.
+  gEfiRedfishPkgTokenSpaceGuid.PcdHttpPatchRetry|0|UINT16|0x100D
+  ## The number of retry when HTTP POST request failed. If the value is 0, 
there is no retry enabled.
+  gEfiRedfishPkgTokenSpaceGuid.PcdHttpPostRetry|0|UINT16|0x100E
+  ## The number of retry when HTTP DELETE request failed. If the value is 0, 
there is no retry enabled.
+  gEfiRedfishPkgTokenSpaceGuid.PcdHttpDeleteRetry|0|UINT16|0x100F
+  ## The number of second to wait before driver retry HTTP request. If the 
value is 0, there is no wait before next retry.
+  gEfiRedfishPkgTokenSpaceGuid.PcdHttpRetryWaitInSecond|1|UINT16|0x1010
+  ## This is used to disable Redfish HTTP cache function and every request 
will be sent to Redfish service.
+  gEfiRedfishPkgTokenSpaceGuid.PcdHttpCacheDisabled|FALSE|BOOLEAN|0x1011
diff --git a/RedfishPkg/Include/Protocol/EdkIIRedfishHttpProtocol.h 
b/RedfishPkg/Include/Protocol/EdkIIRedfishHttpProtocol.h
new file mode 100644
index 00..fef365730d
--- /dev/null
+++ b/RedfishPkg/Include/Protocol/EdkIIRedfishHttpProtocol.h
@@ 

Re: [edk2-devel] [PATCH v2 0/6] Introduce Redfish http protocol

2024-02-22 Thread Igor Kulchytskyy via groups.io
Reviewed-by: Igor Kulchytskyy 

-Original Message-
From: Nickle Wang 
Sent: Thursday, February 22, 2024 4:11 AM
To: devel@edk2.groups.io
Cc: Abner Chang ; Igor Kulchytskyy ; Nick 
Ramirez 
Subject: [EXTERNAL] [PATCH v2 0/6] Introduce Redfish http protocol


**CAUTION: The e-mail below is from an external source. Please exercise caution 
before opening attachments, clicking links, or following guidance.**

v2: address review comments.
1) add comment to show the source file of MathFtol.c
2) update macro to follow file name in RedfishHttpOperation.h

This patch series introduce Redfish HTTP protocol to RedfishPkg.
This is to improve Redfish performance and communication stability
between BIOS and Redfish service. Two big functions are introduced:
1) HTTP cache mechanism is implemented to reduce the number of
communiocation between BIOS and BMC.
2) HTTP request retry mechanism is implemented to handle communication
failure. With retry mechanism, Redfish feature driver can finish its job
as best as possible.

Several libraries are updated to fix build issues. Pull request is created:
https://github.com/tianocore/edk2/pull/5348

Signed-off-by: Nickle Wang 
Cc: Abner Chang 
Cc: Igor Kulchytskyy 
Cc: Nick Ramirez 

Nickle Wang (6):
  RedfishPkg: introduce Redfish HTTP protocol
  RedfishPkg: implement Redfish HTTP protocol
  RedfishPkg: introduce RedfishHttpLib
  RedfishPkg/RedfishLib: include RedfishServiceData.h
  RedfishPkg/RedfishDebugLib: use RedfishHttpLib
  RedfishPkg/RedfishCrtLib: fix unresolved external symbol issue

 RedfishPkg/RedfishPkg.dec |   32 +-
 RedfishPkg/RedfishComponents.dsc.inc  |3 +-
 RedfishPkg/RedfishLibs.dsc.inc|3 +-
 RedfishPkg/RedfishPkg.dsc |5 +-
 .../RedfishDebugLib/RedfishDebugLib.inf   |4 +-
 .../Library/RedfishHttpLib/RedfishHttpLib.inf |   43 +
 .../RedfishCrtLib/RedfishCrtLib.inf   |7 +-
 RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.inf  |   73 +
 RedfishPkg/Include/Library/RedfishDebugLib.h  |2 +-
 RedfishPkg/Include/Library/RedfishHttpLib.h   |  326 
 RedfishPkg/Include/Library/RedfishLib.h   |   17 +-
 .../Protocol/EdkIIRedfishHttpProtocol.h   |  308 
 RedfishPkg/Include/RedfishServiceData.h   |   43 +
 RedfishPkg/RedfishHttpDxe/RedfishHttpData.h   |  256 
 RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.h|   44 +
 .../RedfishHttpDxe/RedfishHttpOperation.h |   76 +
 .../Library/RedfishDebugLib/RedfishDebugLib.c |1 +
 .../Library/RedfishHttpLib/RedfishHttpLib.c   |  585 +++
 .../RedfishCrtLib/Ia32/MathFtol.c |   37 +
 RedfishPkg/RedfishHttpDxe/RedfishHttpData.c   |  667 
 RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.c| 1344 +
 .../RedfishHttpDxe/RedfishHttpOperation.c |  693 +
 RedfishPkg/Redfish.fdf.inc|3 +-
 RedfishPkg/RedfishPkg.ci.yaml |2 +
 24 files changed, 4549 insertions(+), 25 deletions(-)
 create mode 100644 RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.inf
 create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.inf
 create mode 100644 RedfishPkg/Include/Library/RedfishHttpLib.h
 create mode 100644 RedfishPkg/Include/Protocol/EdkIIRedfishHttpProtocol.h
 create mode 100644 RedfishPkg/Include/RedfishServiceData.h
 create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpData.h
 create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.h
 create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpOperation.h
 create mode 100644 RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.c
 create mode 100644 RedfishPkg/PrivateLibrary/RedfishCrtLib/Ia32/MathFtol.c
 create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpData.c
 create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.c
 create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpOperation.c

--
2.34.1

-The information contained in this message may be confidential and proprietary 
to American Megatrends (AMI). This communication is intended to be read only by 
the individual or entity to whom it is addressed or by their designee. If the 
reader of this message is not the intended recipient, you are on notice that 
any distribution of this message, in any form, is strictly prohibited. Please 
promptly notify the sender by reply e-mail or by telephone at 770-246-8600, and 
then delete or destroy all copies of the transmission.


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115817): https://edk2.groups.io/g/devel/message/115817
Mute This Topic: https://groups.io/mt/104505401/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] Peims are not gettting Dispatched in EagleStream Platform

2024-02-22 Thread memristor2 via groups.io
Thank you. Based on what you told me (memory corruption and and the 
unlikelihood of the stack pointer being NULL) my only suspicion would be the 
microcode I am using, since the only platform dependent parts up until this 
part would be the microcode and the FSP-T and since I am using the FSP for 
EagleStream only the microcode would be left to change. Up until now I was 
using Whitley's microcode (since EagleStream's hadn't been released yet). To be 
honest I still don't have a proper comprehension of the concept of the 
microcode so I thought maybe I could use Whitley's microcode. But now that 
EagleStream's microcode has been released I'll try with that and let you know 
whether it works or not. Yet I am still skeptical about it being a microcode 
issue because my thought is that the microcode is procosser architecture-based 
code rather than it being platform-based code. Please correct me if I am wrong 
on this matter.


On Thursday, February 22nd, 2024 at 3:42 AM, Desimone, Nathaniel L 
 wrote:

> > -Original Message-
> > From: devel@edk2.groups.io devel@edk2.groups.io On Behalf Of Laszlo
> > Ersek
> > Sent: Wednesday, February 21, 2024 3:59 PM
> > To: devel@edk2.groups.io; memrist...@proton.me
> > Subject: Re: [edk2-devel] Peims are not gettting Dispatched in EagleStream
> > Platform
> > 
> > On 2/21/24 07:59, memristor2 via groups.io wrote:
> > 
> > > Hi,
> > > I am trying to build edk2-platforms for EagleStream Platform. The
> > > problem I am facing now is that the Peims are not getting dispatched
> > > when The PeiMain routine calls PeiDispatcher().
> > > After digging deeper into it it seems that the DepexSatisfied()
> > > routine is always returning false. So I also checked this and realized
> > > that the place that is returning false is inside the
> > > PeimDispatchReadiness
> > > function:
> > > ||```
> > > case (EFI_DEP_END): DEBUG ((DEBUG_DISPATCH, " END\n"));
> > > StackPtr--;
> > > //
> > > // Check to make sure EvalStack is balanced. If not, then
> > > there is
> > > // an error in the dependency grammar, so return
> > > EFI_INVALID_PARAMETER.
> > > //
> > > if (StackPtr != [0]) {
> > > 
> > > DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE (Underflow
> > > Error)\n"));
> > > return FALSE;
> > > }
> > > 
> > > DEBUG ((DEBUG_DISPATCH, " RESULT = %a\n", IsPpiInstalled
> > > (PeiServices, StackPtr) ? "TRUE" : "FALSE"));
> > > 
> > > return IsPpiInstalled (PeiServices, StackPtr); ``` It seems
> > > that when entering IsPpiInstalled StackPtr in always NULL.
> > > Any thoughts on this?
> > 
> > StackPtr being NULL seems extremely unlikely; it is supposed to point to
> > elements of the EvalStack local array (or I guess one past the last 
> > element).
> > 
> > Now, I can see two potential problems here:
> > 
> > - your depex is malformed (for whatever reason), and the eval stack is not 
> > torn
> > down entirely before reachig EFI_DEP_END. The code seems to handle that
> > correctly, by returning FALSE.
> > 
> > - your depex is malformed such that it immediately starts with an
> > EFI_DEP_END. The code is actually buggy for that case, because it decrements
> > StackPtr first, before comparing it against [0].
> > That decrement invokes undefined behavior. However, I assume in practice the
> > behavior will be the same as in the previous paragraph.
> > 
> > A NULL StackPtr value I cannot explain at all.
> 
> 
> Agreed with Laszlo here... the only thing that I could think of is memory 
> corruption. Several people at Intel (myself included) as working on getting 
> an EaglestreamOpenBoardPkg posted to edk2-platforms right now. I would 
> recommend you wait for us to release our code as opposed 
> 
> > Laszlo
> > 
> > 


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115816): https://edk2.groups.io/g/devel/message/115816
Mute This Topic: https://groups.io/mt/104498510/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v2 2/6] RedfishPkg: implement Redfish HTTP protocol

2024-02-22 Thread Chang, Abner via groups.io
[AMD Official Use Only - General]

Thanks!

Reviewed-by: Abner Chang 

> -Original Message-
> From: Nickle Wang 
> Sent: Thursday, February 22, 2024 5:11 PM
> To: devel@edk2.groups.io
> Cc: Igor Kulchytskyy ; Chang, Abner
> ; Nick Ramirez 
> Subject: [PATCH v2 2/6] RedfishPkg: implement Redfish HTTP protocol
>
> Caution: This message originated from an External Source. Use proper caution
> when opening attachments, clicking links, or responding.
>
>
> implement Redfish HTTP protocol driver.
>
> Signed-off-by: Nickle Wang 
> Co-authored-by: Igor Kulchytskyy 
> Cc: Abner Chang 
> Cc: Igor Kulchytskyy 
> Cc: Nick Ramirez 
> ---
>  RedfishPkg/RedfishPkg.dec |7 +-
>  RedfishPkg/RedfishComponents.dsc.inc  |3 +-
>  RedfishPkg/RedfishPkg.dsc |2 +
>  RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.inf  |   73 +
>  RedfishPkg/RedfishHttpDxe/RedfishHttpData.h   |  256 
>  RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.h|   44 +
>  .../RedfishHttpDxe/RedfishHttpOperation.h |   76 +
>  RedfishPkg/RedfishHttpDxe/RedfishHttpData.c   |  667 
>  RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.c| 1344
> +
>  .../RedfishHttpDxe/RedfishHttpOperation.c |  693 +
>  RedfishPkg/Redfish.fdf.inc|3 +-
>  11 files changed, 3164 insertions(+), 4 deletions(-)
>  create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.inf
>  create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpData.h
>  create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.h
>  create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpOperation.h
>  create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpData.c
>  create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.c
>  create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpOperation.c
>
> diff --git a/RedfishPkg/RedfishPkg.dec b/RedfishPkg/RedfishPkg.dec
> index 9b424efdf3..114f8d2ad8 100644
> --- a/RedfishPkg/RedfishPkg.dec
> +++ b/RedfishPkg/RedfishPkg.dec
> @@ -157,8 +157,11 @@
># set to EFI_REST_EX_PROTOCOL.
>#
>
> gEfiRedfishPkgTokenSpaceGuid.PcdRedfishSendReceiveTimeout|5000|UINT3
> 2|0x1009
> -  ## This is used to enable HTTP content encoding on Redfish communication.
> -
> gEfiRedfishPkgTokenSpaceGuid.PcdRedfishServiceContentEncoding|TRUE|BO
> OLEAN|0x100A
> +  #
> +  # This PCD string is introduced for platform developer to set the encoding
> method supported by BMC Redfish.
> +  # Currently only "None" and "gzip" are supported.
> +  #
> +
> gEfiRedfishPkgTokenSpaceGuid.PcdRedfishServiceContentEncoding|"None"|V
> OID*|0x100A
>#
># Use below PCDs to control Redfhs HTTP protocol.
>#
> diff --git a/RedfishPkg/RedfishComponents.dsc.inc
> b/RedfishPkg/RedfishComponents.dsc.inc
> index 464ffc8606..d6c5b73d7f 100644
> --- a/RedfishPkg/RedfishComponents.dsc.inc
> +++ b/RedfishPkg/RedfishComponents.dsc.inc
> @@ -7,7 +7,7 @@
>  # "RedfishDefines.dsc.inc".
>  #
>  # (C) Copyright 2020-2021 Hewlett Packard Enterprise Development LP
> -# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights
> reserved.
> +# Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights
> reserved.
>  #
>  #SPDX-License-Identifier: BSD-2-Clause-Patent
>  #
> @@ -28,4 +28,5 @@
>RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.inf
>RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigDxe.inf
>MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
> +  RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.inf
>  !endif
> diff --git a/RedfishPkg/RedfishPkg.dsc b/RedfishPkg/RedfishPkg.dsc
> index 25ed193182..5849e7cf9e 100644
> --- a/RedfishPkg/RedfishPkg.dsc
> +++ b/RedfishPkg/RedfishPkg.dsc
> @@ -45,6 +45,8 @@
>
> UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesL
> ib.inf
>
> RedfishPlatformCredentialLib|RedfishPkg/Library/PlatformCredentialLibNull/
> PlatformCredentialLibNull.inf
>
> RedfishContentCodingLib|RedfishPkg/Library/RedfishContentCodingLibNull/
> RedfishContentCodingLibNull.inf
> +
> ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeR
> eportStatusCodeLib.inf
> +  SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf
>
># NULL instance of IPMI related library.
>IpmiLib|MdeModulePkg/Library/BaseIpmiLibNull/BaseIpmiLibNull.inf
> diff --git a/RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.inf
> b/RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.inf
> new file mode 100644
> index 00..c7dfdffacf
> --- /dev/null
> +++ b/RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.inf
> @@ -0,0 +1,73 @@
> +## @file
> +#  RedfishHttpDxe is the DXE driver which provides
> +#  EdkIIRedfishHttpProtocol to EDK2 Redfish Feature
> +#  drivers for HTTP operation.
> +#
> +#  Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights
> reserved.
> +#
> +#  SPDX-License-Identifier: BSD-2-Clause-Patent
> +#
> +##
> +
> +[Defines]
> +  INF_VERSION= 0x0001000b
> +  BASE_NAME   

Re: [edk2-devel] [PATCH 6/6] RedfishPkg/RedfishCrtLib: fix unresolved external symbol issue

2024-02-22 Thread Chang, Abner via groups.io
[AMD Official Use Only - General]

Thanks!

Reviewed-by: Abner Chang 

> -Original Message-
> From: Nickle Wang 
> Sent: Thursday, February 22, 2024 5:16 PM
> To: Chang, Abner ; devel@edk2.groups.io
> Cc: Igor Kulchytskyy ; Nick Ramirez 
> Subject: RE: [PATCH 6/6] RedfishPkg/RedfishCrtLib: fix unresolved external
> symbol issue
>
> [AMD Official Use Only - General]
>
> Caution: This message originated from an External Source. Use proper caution
> when opening attachments, clicking links, or responding.
>
>
> Hi Abner,
>
> Please check v2 patch. I add the source location of MathFtol.c
>
> Thanks,
> Nickle
>
> > -Original Message-
> > From: Chang, Abner 
> > Sent: Wednesday, February 21, 2024 10:10 AM
> > To: Nickle Wang ; devel@edk2.groups.io
> > Cc: Igor Kulchytskyy ; Nick Ramirez
> 
> > Subject: RE: [PATCH 6/6] RedfishPkg/RedfishCrtLib: fix unresolved external
> > symbol issue
> >
> > External email: Use caution opening links or attachments
> >
> >
> > [AMD Official Use Only - General]
> >
> > > -Original Message-
> > > From: Nickle Wang 
> > > Sent: Tuesday, February 20, 2024 2:42 PM
> > > To: devel@edk2.groups.io
> > > Cc: Chang, Abner ; Igor Kulchytskyy
> > > ; Nick Ramirez 
> > > Subject: [PATCH 6/6] RedfishPkg/RedfishCrtLib: fix unresolved external
> > > symbol issue
> > >
> > > Caution: This message originated from an External Source. Use proper
> > > caution when opening attachments, clicking links, or responding.
> > >
> > >
> > > -Fix below compiler error reported in edk2 CI.
> > > ERROR - Linker #2001 from JsonLib.lib(load.obj) : unresolved external
> > > symbol __ftol2 -The file MathFtol.c is copied from IntrinsicLib in
> > > CryptoPkg.
> > > -Add MathFtol.c to EccCheck IgnoreFiles.
> > >
> > > Signed-off-by: Nickle Wang 
> > > Cc: Abner Chang 
> > > Cc: Igor Kulchytskyy 
> > > Cc: Nick Ramirez 
> > > ---
> > >  .../RedfishCrtLib/RedfishCrtLib.inf   |  7 +++-
> > >  .../RedfishCrtLib/Ia32/MathFtol.c | 37 +++
> > >  RedfishPkg/RedfishPkg.ci.yaml |  2 +
> > >  3 files changed, 45 insertions(+), 1 deletion(-)  create mode 100644
> > > RedfishPkg/PrivateLibrary/RedfishCrtLib/Ia32/MathFtol.c
> > >
> > > diff --git a/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf
> > > b/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf
> > > index 6ff5dba75c..3a5e309d1a 100644
> > > --- a/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf
> > > +++ b/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf
> > > @@ -3,6 +3,7 @@
> > >  #
> > >  # Copyright (c) 2019, Intel Corporation. All rights reserved.  #
> > > (C) Copyright 2020 Hewlett Packard Enterprise Development LP
> > > +# Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights
> > > reserved.
> > >  #
> > >  #SPDX-License-Identifier: BSD-2-Clause-Patent
> > >  #
> > > @@ -23,6 +24,9 @@
> > >  [Sources]
> > >RedfishCrtLib.c
> > >
> > > +[Sources.IA32]
> > > +  Ia32/MathFtol.c   | MSFT
> > > +
> > >  [LibraryClasses]
> > >BaseLib
> > >SortLib
> > > @@ -35,4 +39,5 @@
> > >MdeModulePkg/MdeModulePkg.dec
> > >RedfishPkg/RedfishPkg.dec
> > >
> > > -
> > > +[BuildOptions]
> > > +  MSFT:*_*_IA32_CC_FLAGS = /GL-
> > > diff --git a/RedfishPkg/PrivateLibrary/RedfishCrtLib/Ia32/MathFtol.c
> > > b/RedfishPkg/PrivateLibrary/RedfishCrtLib/Ia32/MathFtol.c
> > > new file mode 100644
> > > index 00..adfe249b1d
> > > --- /dev/null
> > > +++ b/RedfishPkg/PrivateLibrary/RedfishCrtLib/Ia32/MathFtol.c
> > > @@ -0,0 +1,37 @@
> > > +/** @file
> >
> > Hi Nickle,
> > Could you please add the information here after @file about where this file
> or the
> > source code come from, such as the location of original file?
> > Thanks
> > Abner
> >
> >
> > > +  64-bit Math Worker Function.
> > > +  The 32-bit versions of C compiler generate calls to library
> > > + routines  to handle 64-bit math. These functions use non-standard
> > > + calling
> > > conventions.
> > > +
> > > +Copyright (c) 2019, Intel Corporation. All rights reserved.
> > > +SPDX-License-Identifier: BSD-2-Clause-Patent
> > > +
> > > +**/
> > > +
> > > +/*
> > > + * Floating point to integer conversion.
> > > + */
> > > +__declspec(naked) void
> > > +_ftol2 (
> > > +  void
> > > +  )
> > > +{
> > > +  _asm {
> > > +fistp qword ptr [esp-8]
> > > +mov   edx, [esp-4]
> > > +mov   eax, [esp-8]
> > > +ret
> > > +  }
> > > +}
> > > +
> > > +__declspec(naked) void
> > > +_ftol2_sse (
> > > +  void
> > > +  )
> > > +{
> > > +  _asm {
> > > +fistp dword ptr [esp-4]
> > > +mov   eax,[esp-4]
> > > +ret
> > > +  }
> > > +}
> > > diff --git a/RedfishPkg/RedfishPkg.ci.yaml
> > > b/RedfishPkg/RedfishPkg.ci.yaml index 69b6bf39f5..b95e8bfdc7 100644
> > > --- a/RedfishPkg/RedfishPkg.ci.yaml
> > > +++ b/RedfishPkg/RedfishPkg.ci.yaml
> > > @@ -2,6 +2,7 @@
> > >  # CI configuration for NetworkPkg
> > >  #
> > >  # (C) Copyright 2021 Hewlett Packard Enterprise 

Re: [edk2-devel] [PATCH v2 4/5] UefiCpuPkg/MpInitLib: Add support for multiple HOBs to MpInitLibInitialize

2024-02-22 Thread Gerd Hoffmann
  Hi,
 
> The code looks otherwise OK, but I'm not happy that
> WaitLoopExecutionMode (and StartupSignalValue) are replicated over all
> the HOBs, just like in v1. IMO, that will only make it harder for others
> to understand the code / data structures, and therefore it increases
> technical debt.
> 
> I understand that Ray is OK with that, so I won't try to block the
> patch, but I'm not comfortable giving it an R-b myself, due to the
> increase in technical debt.

I can try to address that, but this certainly will be a separate
patch.

Given that the HOB structure is defined in locally in the library
I assume this is considered private and there are no compatibility
concerns when changing the structs?

Any preference where the fields should be moved to?  PCD?  Separate
HOB?  Something else?

take care,
  Gerd



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115813): https://edk2.groups.io/g/devel/message/115813
Mute This Topic: https://groups.io/mt/104472311/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH 10/10] OvmfPkg/ResetVector: wire up 5-level paging for SEV

2024-02-22 Thread Gerd Hoffmann
Removes the GetSevCBitMaskAbove31 OneTimeCall because we need that twice
(for 4-level and 5-level paging).  Open code the single instruction left
in that function instead.

Signed-off-by: Gerd Hoffmann 
---
 OvmfPkg/ResetVector/Ia32/AmdSev.asm   |  8 
 OvmfPkg/ResetVector/Ia32/PageTables64.asm | 14 +-
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/OvmfPkg/ResetVector/Ia32/AmdSev.asm 
b/OvmfPkg/ResetVector/Ia32/AmdSev.asm
index 9063ce1080d3..d1e5e8dfae71 100644
--- a/OvmfPkg/ResetVector/Ia32/AmdSev.asm
+++ b/OvmfPkg/ResetVector/Ia32/AmdSev.asm
@@ -191,14 +191,6 @@ pageTableEntries4kLoop:
 SevClearPageEncMaskForGhcbPageExit:
 OneTimeCallRet SevClearPageEncMaskForGhcbPage
 
-; Get the C-bit mask above 31.
-; Modified: EDX
-;
-; The value is returned in the EDX
-GetSevCBitMaskAbove31:
-mov   edx, dword[SEV_ES_WORK_AREA_ENC_MASK + 4]
-OneTimeCallRet GetSevCBitMaskAbove31
-
 %endif
 
 ; Check if Secure Encrypted Virtualization (SEV) features are enabled.
diff --git a/OvmfPkg/ResetVector/Ia32/PageTables64.asm 
b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
index 6e2063430802..55664fa64f62 100644
--- a/OvmfPkg/ResetVector/Ia32/PageTables64.asm
+++ b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
@@ -243,11 +243,23 @@ SevInit:
 ; SEV workflow
 ;
 ClearOvmfPageTables
+%if PG_5_LEVEL
+Check5LevelPaging Sev4Level
 ; If SEV is enabled, the C-bit position is always above 31.
 ; The mask will be saved in the EDX and applied during the
 ; the page table build below.
-OneTimeCall   GetSevCBitMaskAbove31
+mov edx, dword[SEV_ES_WORK_AREA_ENC_MASK + 4]
+CreatePageTables5Level edx
+Enable5LevelPaging
+jmp SevCommon
+Sev4Level:
+%endif
+; If SEV is enabled, the C-bit position is always above 31.
+; The mask will be saved in the EDX and applied during the
+; the page table build below.
+mov edx, dword[SEV_ES_WORK_AREA_ENC_MASK + 4]
 CreatePageTables4Level edx
+SevCommon:
 ; Clear the C-bit from the GHCB page if the SEV-ES is enabled.
 OneTimeCall   SevClearPageEncMaskForGhcbPage
 OneTimeCall   SevClearVcHandlerAndStack
-- 
2.43.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115812): https://edk2.groups.io/g/devel/message/115812
Mute This Topic: https://groups.io/mt/104506802/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH 09/10] OvmfPkg/ResetVector: leave SEV VC handler installed longer

2024-02-22 Thread Gerd Hoffmann
When running in SEV mode keep the VC handler installed.
Add a function to uninstall it later.

This allows using the cpuid instruction in SetCr3ForPageTables64,
which is needed to check for la57 & 1G page support.

Signed-off-by: Gerd Hoffmann 
---
 OvmfPkg/ResetVector/Ia32/AmdSev.asm   | 12 ++--
 OvmfPkg/ResetVector/Ia32/PageTables64.asm |  1 +
 OvmfPkg/ResetVector/Main.asm  |  4 
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/OvmfPkg/ResetVector/Ia32/AmdSev.asm 
b/OvmfPkg/ResetVector/Ia32/AmdSev.asm
index ed94f1dc668f..9063ce1080d3 100644
--- a/OvmfPkg/ResetVector/Ia32/AmdSev.asm
+++ b/OvmfPkg/ResetVector/Ia32/AmdSev.asm
@@ -320,9 +320,9 @@ NoSevEsVcHlt:
 NoSevPass:
 xor   eax, eax
 
-SevExit:
 ;
-; Clear exception handlers and stack
+; When NOT running in SEV mode: clear exception handlers and stack here.
+; Otherwise: SevClearVcHandlerAndStack must be called later.
 ;
 push  eax
 mov   eax, ADDR_OF(IdtrClear)
@@ -330,8 +330,16 @@ SevExit:
 pop   eax
 mov   esp, 0
 
+SevExit:
 OneTimeCallRet CheckSevFeatures
 
+SevClearVcHandlerAndStack:
+; Clear exception handlers and stack
+mov   eax, ADDR_OF(IdtrClear)
+lidt  [cs:eax]
+mov   esp, 0
+OneTimeCallRet SevClearVcHandlerAndStack
+
 ; Start of #VC exception handling routines
 ;
 
diff --git a/OvmfPkg/ResetVector/Ia32/PageTables64.asm 
b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
index ada3dc0ffbe0..6e2063430802 100644
--- a/OvmfPkg/ResetVector/Ia32/PageTables64.asm
+++ b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
@@ -250,6 +250,7 @@ SevInit:
 CreatePageTables4Level edx
 ; Clear the C-bit from the GHCB page if the SEV-ES is enabled.
 OneTimeCall   SevClearPageEncMaskForGhcbPage
+OneTimeCall   SevClearVcHandlerAndStack
 jmp SetCr3
 
 TdxBspInit:
diff --git a/OvmfPkg/ResetVector/Main.asm b/OvmfPkg/ResetVector/Main.asm
index 46cfa87c4c0a..88b25db3bc9e 100644
--- a/OvmfPkg/ResetVector/Main.asm
+++ b/OvmfPkg/ResetVector/Main.asm
@@ -80,7 +80,11 @@ SearchBfv:
 ; Set the OVMF/SEV work area as appropriate.
 ;
 OneTimeCall CheckSevFeatures
+cmp byte[WORK_AREA_GUEST_TYPE], 1
+jnz NoSevIa32
+OneTimeCall SevClearVcHandlerAndStack
 
+NoSevIa32:
 ;
 ; Restore initial EAX value into the EAX register
 ;
-- 
2.43.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115810): https://edk2.groups.io/g/devel/message/115810
Mute This Topic: https://groups.io/mt/104506799/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH 07/10] OvmfPkg/ResetVector: print post codes for 4/5 level paging

2024-02-22 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann 
---
 OvmfPkg/ResetVector/Ia32/PageTables64.asm | 8 
 1 file changed, 8 insertions(+)

diff --git a/OvmfPkg/ResetVector/Ia32/PageTables64.asm 
b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
index 825589f31193..d736db028277 100644
--- a/OvmfPkg/ResetVector/Ia32/PageTables64.asm
+++ b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
@@ -69,6 +69,10 @@ BITS32
 ; Argument: upper 32 bits of the page table entries
 ;
 %macro CreatePageTables4Level 1
+
+; indicate 4-level paging
+debugShowPostCode 0x41
+
 ;
 ; Top level Page Directory Pointers (1 * 512GB entry)
 ;
@@ -153,6 +157,10 @@ BITS32
 ; level 3 directory.
 ;
 %macro CreatePageTables5Level 1
+
+; indicate 5-level paging
+debugShowPostCode 0x51
+
 ; level 5
 mov dword[PT_ADDR (0)], PT_ADDR (0x1000) + PAGE_PDE_DIRECTORY_ATTR
 mov dword[PT_ADDR (4)], %1
-- 
2.43.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115811): https://edk2.groups.io/g/devel/message/115811
Mute This Topic: https://groups.io/mt/104506801/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH 08/10] OvmfPkg/ResetVector: wire up 5-level paging for TDX

2024-02-22 Thread Gerd Hoffmann
BSP workflow is quite simliar to the non-coco case.

TDX_WORK_AREA_PGTBL_READY is used to record the paging mode:
  1 == 4-level paging
  2 == 5-level paging

APs will look at TDX_WORK_AREA_PGTBL_READY to figure whenever
they should enable 5-level paging or not.

Signed-off-by: Gerd Hoffmann 
---
 OvmfPkg/ResetVector/Ia32/IntelTdx.asm | 13 -
 OvmfPkg/ResetVector/Ia32/PageTables64.asm | 12 
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/OvmfPkg/ResetVector/Ia32/IntelTdx.asm 
b/OvmfPkg/ResetVector/Ia32/IntelTdx.asm
index c6b86019dfb9..7d775591a05b 100644
--- a/OvmfPkg/ResetVector/Ia32/IntelTdx.asm
+++ b/OvmfPkg/ResetVector/Ia32/IntelTdx.asm
@@ -179,7 +179,7 @@ InitTdx:
 ;
 ; Modified:  EAX, EDX
 ;
-; 0-NonTdx, 1-TdxBsp, 2-TdxAps
+; 0-NonTdx, 1-TdxBsp, 2-TdxAps, 3-TdxAps5Level
 ;
 CheckTdxFeaturesBeforeBuildPagetables:
 xor eax, eax
@@ -200,6 +200,17 @@ TdxPostBuildPageTables:
 mov byte[TDX_WORK_AREA_PGTBL_READY], 1
 OneTimeCallRet TdxPostBuildPageTables
 
+%if PG_5_LEVEL
+
+;
+; Set byte[TDX_WORK_AREA_PGTBL_READY] to 2
+;
+TdxPostBuildPageTables5Level:
+mov byte[TDX_WORK_AREA_PGTBL_READY], 2
+OneTimeCallRet TdxPostBuildPageTables5Level
+
+%endif
+
 ;
 ; Check if TDX is enabled
 ;
diff --git a/OvmfPkg/ResetVector/Ia32/PageTables64.asm 
b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
index d736db028277..ada3dc0ffbe0 100644
--- a/OvmfPkg/ResetVector/Ia32/PageTables64.asm
+++ b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
@@ -44,6 +44,7 @@ BITS32
 
 %define TDX_BSP 1
 %define TDX_AP  2
+%define TDX_AP_5_LEVEL  3
 
 ;
 ; For OVMF, build some initial page tables at
@@ -214,6 +215,10 @@ SetCr3ForPageTables64:
 jeTdxBspInit
 cmp   eax, TDX_AP
 jeSetCr3
+%if PG_5_LEVEL
+cmp   eax, TDX_AP_5_LEVEL
+jeSetCr3La57
+%endif
 
 ; Check whether the SEV is active and populate the SevEsWorkArea
 OneTimeCall   CheckSevFeatures
@@ -252,6 +257,13 @@ TdxBspInit:
 ; TDX BSP workflow
 ;
 ClearOvmfPageTables
+%if PG_5_LEVEL
+Check5LevelPaging Tdx4Level
+CreatePageTables5Level 0
+OneTimeCall TdxPostBuildPageTables5Level
+jmp SetCr3La57
+Tdx4Level:
+%endif
 CreatePageTables4Level 0
 OneTimeCall TdxPostBuildPageTables
 jmp SetCr3
-- 
2.43.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115808): https://edk2.groups.io/g/devel/message/115808
Mute This Topic: https://groups.io/mt/104506795/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH 04/10] OvmfPkg/ResetVector: split TDX BSP workflow

2024-02-22 Thread Gerd Hoffmann
Create a separate control flow for TDX BSP.

TdxPostBuildPageTables will now only be called when running in TDX
mode, so the TDX check in that function is not needed any more.

No functional change.

Signed-off-by: Gerd Hoffmann 
---
 OvmfPkg/ResetVector/Ia32/IntelTdx.asm |  4 
 OvmfPkg/ResetVector/Ia32/PageTables64.asm | 15 ++-
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/OvmfPkg/ResetVector/Ia32/IntelTdx.asm 
b/OvmfPkg/ResetVector/Ia32/IntelTdx.asm
index 06794baef81d..c6b86019dfb9 100644
--- a/OvmfPkg/ResetVector/Ia32/IntelTdx.asm
+++ b/OvmfPkg/ResetVector/Ia32/IntelTdx.asm
@@ -197,11 +197,7 @@ NotTdx:
 ; Set byte[TDX_WORK_AREA_PGTBL_READY] to 1
 ;
 TdxPostBuildPageTables:
-cmp byte[WORK_AREA_GUEST_TYPE], VM_GUEST_TDX
-jne ExitTdxPostBuildPageTables
 mov byte[TDX_WORK_AREA_PGTBL_READY], 1
-
-ExitTdxPostBuildPageTables:
 OneTimeCallRet TdxPostBuildPageTables
 
 ;
diff --git a/OvmfPkg/ResetVector/Ia32/PageTables64.asm 
b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
index 14cc2c33aa3d..166e80293c89 100644
--- a/OvmfPkg/ResetVector/Ia32/PageTables64.asm
+++ b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
@@ -112,7 +112,7 @@ SetCr3ForPageTables64:
 ; is set.
 OneTimeCall   CheckTdxFeaturesBeforeBuildPagetables
 cmp   eax, TDX_BSP
-jeClearOvmfPageTables
+jeTdxBspInit
 cmp   eax, TDX_AP
 jeSetCr3
 
@@ -124,16 +124,21 @@ SetCr3ForPageTables64:
 ; the page table build below.
 OneTimeCall   GetSevCBitMaskAbove31
 
-ClearOvmfPageTables:
 ClearOvmfPageTables
 CreatePageTables4Level edx
 
 ; Clear the C-bit from the GHCB page if the SEV-ES is enabled.
 OneTimeCall   SevClearPageEncMaskForGhcbPage
+jmp SetCr3
 
-; TDX will do some PostBuildPages task, such as setting
-; byte[TDX_WORK_AREA_PGTBL_READY].
-OneTimeCall   TdxPostBuildPageTables
+TdxBspInit:
+;
+; TDX BSP workflow
+;
+ClearOvmfPageTables
+CreatePageTables4Level 0
+OneTimeCall TdxPostBuildPageTables
+jmp SetCr3
 
 SetCr3:
 ;
-- 
2.43.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115809): https://edk2.groups.io/g/devel/message/115809
Mute This Topic: https://groups.io/mt/104506797/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH 05/10] OvmfPkg/ResetVector: split SEV and non-CoCo workflows

2024-02-22 Thread Gerd Hoffmann
Use separate control flows for SEV and non-CoCo cases.

SevClearPageEncMaskForGhcbPage and GetSevCBitMaskAbove31 will now only
be called when running in SEV mode, so the SEV check in these functions
is not needed any more.

No functional change.

Signed-off-by: Gerd Hoffmann 
---
 OvmfPkg/ResetVector/Ia32/AmdSev.asm   | 16 ++--
 OvmfPkg/ResetVector/Ia32/PageTables64.asm | 17 ++---
 2 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/OvmfPkg/ResetVector/Ia32/AmdSev.asm 
b/OvmfPkg/ResetVector/Ia32/AmdSev.asm
index 043c88a7abbe..ed94f1dc668f 100644
--- a/OvmfPkg/ResetVector/Ia32/AmdSev.asm
+++ b/OvmfPkg/ResetVector/Ia32/AmdSev.asm
@@ -152,12 +152,8 @@ SevEsUnexpectedRespTerminate:
 
 %ifdef ARCH_X64
 
-; If SEV-ES is enabled then initialize and make the GHCB page shared
+; initialize and make the GHCB page shared
 SevClearPageEncMaskForGhcbPage:
-; Check if SEV is enabled
-cmp   byte[WORK_AREA_GUEST_TYPE], 1
-jnz   SevClearPageEncMaskForGhcbPageExit
-
 ; Check if SEV-ES is enabled
 mov   ecx, 1
 bt[SEV_ES_WORK_AREA_STATUS_MSR], ecx
@@ -195,20 +191,12 @@ pageTableEntries4kLoop:
 SevClearPageEncMaskForGhcbPageExit:
 OneTimeCallRet SevClearPageEncMaskForGhcbPage
 
-; Check if SEV is enabled, and get the C-bit mask above 31.
+; Get the C-bit mask above 31.
 ; Modified: EDX
 ;
 ; The value is returned in the EDX
 GetSevCBitMaskAbove31:
-xor   edx, edx
-
-; Check if SEV is enabled
-cmp   byte[WORK_AREA_GUEST_TYPE], 1
-jnz   GetSevCBitMaskAbove31Exit
-
 mov   edx, dword[SEV_ES_WORK_AREA_ENC_MASK + 4]
-
-GetSevCBitMaskAbove31Exit:
 OneTimeCallRet GetSevCBitMaskAbove31
 
 %endif
diff --git a/OvmfPkg/ResetVector/Ia32/PageTables64.asm 
b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
index 166e80293c89..84a7b4efc019 100644
--- a/OvmfPkg/ResetVector/Ia32/PageTables64.asm
+++ b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
@@ -118,15 +118,26 @@ SetCr3ForPageTables64:
 
 ; Check whether the SEV is active and populate the SevEsWorkArea
 OneTimeCall   CheckSevFeatures
+cmp   byte[WORK_AREA_GUEST_TYPE], 1
+jzSevInit
 
+;
+; normal (non-CoCo) workflow
+;
+ClearOvmfPageTables
+CreatePageTables4Level 0
+jmp SetCr3
+
+SevInit:
+;
+; SEV workflow
+;
+ClearOvmfPageTables
 ; If SEV is enabled, the C-bit position is always above 31.
 ; The mask will be saved in the EDX and applied during the
 ; the page table build below.
 OneTimeCall   GetSevCBitMaskAbove31
-
-ClearOvmfPageTables
 CreatePageTables4Level edx
-
 ; Clear the C-bit from the GHCB page if the SEV-ES is enabled.
 OneTimeCall   SevClearPageEncMaskForGhcbPage
 jmp SetCr3
-- 
2.43.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115807): https://edk2.groups.io/g/devel/message/115807
Mute This Topic: https://groups.io/mt/104506794/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH 06/10] OvmfPkg/ResetVector: add 5-level paging support

2024-02-22 Thread Gerd Hoffmann
Add macros to check for 5-level paging and gigabyte page support.
Enable 5-level paging for the non-confidential-computing case.

Signed-off-by: Gerd Hoffmann 
---
 OvmfPkg/ResetVector/ResetVector.inf   |   1 +
 OvmfPkg/ResetVector/Ia32/PageTables64.asm | 105 ++
 OvmfPkg/ResetVector/ResetVector.nasmb |   1 +
 3 files changed, 107 insertions(+)

diff --git a/OvmfPkg/ResetVector/ResetVector.inf 
b/OvmfPkg/ResetVector/ResetVector.inf
index a4154ca90c28..65f71b05a02e 100644
--- a/OvmfPkg/ResetVector/ResetVector.inf
+++ b/OvmfPkg/ResetVector/ResetVector.inf
@@ -64,3 +64,4 @@ [FixedPcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdQemuHashTableSize
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsBase
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsSize
+  gEfiMdeModulePkgTokenSpaceGuid.PcdUse5LevelPageTable
diff --git a/OvmfPkg/ResetVector/Ia32/PageTables64.asm 
b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
index 84a7b4efc019..825589f31193 100644
--- a/OvmfPkg/ResetVector/Ia32/PageTables64.asm
+++ b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
@@ -101,6 +101,97 @@ BITS32
 loop.pageTableEntriesLoop4Level
 %endmacro
 
+;
+; Check whenever 5-level paging can ca used
+;
+; Argument: jump label for 4-level paging
+;
+%macro Check5LevelPaging 1
+; check for cpuid leaf 0x07
+mov eax, 0x00
+cpuid
+cmp eax, 0x07
+jb  %1
+
+; check for la57 (aka 5-level paging)
+mov eax, 0x07
+mov ecx, 0x00
+cpuid
+bt  ecx, 16
+jnc %1
+
+; check for cpuid leaf 0x8001
+mov eax, 0x8000
+cpuid
+cmp eax, 0x8001
+jb  %1
+
+; check for 1g pages
+mov eax, 0x8001
+cpuid
+bt  edx, 26
+jnc %1
+%endmacro
+
+;
+; Create page tables for 5-level paging with gigabyte pages
+;
+; Argument: upper 32 bits of the page table entries
+;
+; We have 6 pages available for the early page tables,
+; we use four of them:
+;PT_ADDR(0)  - level 5 directory
+;PT_ADDR(0x1000) - level 4 directory
+;PT_ADDR(0x2000) - level 2 directory (0 -> 1GB)
+;PT_ADDR(0x3000) - level 3 directory
+;
+; The level 2 directory for the first gigabyte has the same
+; physical address in both 4-level and 5-level paging mode,
+; SevClearPageEncMaskForGhcbPage depends on this.
+;
+; The 1 GB -> 4 GB range is mapped using 1G pages in the
+; level 3 directory.
+;
+%macro CreatePageTables5Level 1
+; level 5
+mov dword[PT_ADDR (0)], PT_ADDR (0x1000) + PAGE_PDE_DIRECTORY_ATTR
+mov dword[PT_ADDR (4)], %1
+
+; level 4
+mov dword[PT_ADDR (0x1000)], PT_ADDR (0x3000) + PAGE_PDE_DIRECTORY_ATTR
+mov dword[PT_ADDR (0x1004)], %1
+
+; level 3 (1x -> level 2, 3x 1GB)
+mov dword[PT_ADDR (0x3000)], PT_ADDR (0x2000) + PAGE_PDE_DIRECTORY_ATTR
+mov dword[PT_ADDR (0x3004)], %1
+mov dword[PT_ADDR (0x3008)], (1 << 30) + PAGE_PDE_LARGEPAGE_ATTR
+mov dword[PT_ADDR (0x300c)], %1
+mov dword[PT_ADDR (0x3010)], (2 << 30) + PAGE_PDE_LARGEPAGE_ATTR
+mov dword[PT_ADDR (0x3014)], %1
+mov dword[PT_ADDR (0x3018)], (3 << 30) + PAGE_PDE_LARGEPAGE_ATTR
+mov dword[PT_ADDR (0x301c)], %1
+
+;
+; level 2 (512 * 2MB entries => 1GB)
+;
+mov ecx, 0x200
+.pageTableEntriesLoop5Level:
+mov eax, ecx
+dec eax
+shl eax, 21
+add eax, PAGE_PDE_LARGEPAGE_ATTR
+mov dword[ecx * 8 + PT_ADDR (0x2000 - 8)], eax
+mov dword[(ecx * 8 + PT_ADDR (0x2000 - 8)) + 4], %1
+loop.pageTableEntriesLoop5Level
+%endmacro
+
+%macro Enable5LevelPaging 0
+; set la57 bit in cr4
+mov eax, cr4
+bts eax, 12
+mov cr4, eax
+%endmacro
+
 ;
 ; Modified:  EAX, EBX, ECX, EDX
 ;
@@ -125,6 +216,12 @@ SetCr3ForPageTables64:
 ; normal (non-CoCo) workflow
 ;
 ClearOvmfPageTables
+%if PG_5_LEVEL
+Check5LevelPaging Paging4Level
+CreatePageTables5Level 0
+jmp SetCr3La57
+Paging4Level:
+%endif
 CreatePageTables4Level 0
 jmp SetCr3
 
@@ -151,6 +248,14 @@ TdxBspInit:
 OneTimeCall TdxPostBuildPageTables
 jmp SetCr3
 
+;
+; common workflow
+;
+%if PG_5_LEVEL
+SetCr3La57:
+Enable5LevelPaging
+%endif
+
 SetCr3:
 ;
 ; Set CR3 now that the paging structures are available
diff --git a/OvmfPkg/ResetVector/ResetVector.nasmb 
b/OvmfPkg/ResetVector/ResetVector.nasmb
index 366a70fb9992..2bd80149e58b 100644
--- a/OvmfPkg/ResetVector/ResetVector.nasmb
+++ b/OvmfPkg/ResetVector/ResetVector.nasmb
@@ -53,6 +53,7 @@
 
 %define WORK_AREA_GUEST_TYPE  (FixedPcdGet32 (PcdOvmfWorkAreaBase))
 %define PT_ADDR(Offset)   (FixedPcdGet32 
(PcdOvmfSecPageTablesBase) + (Offset))
+%define PG_5_LEVEL(FixedPcdGetBool (PcdUse5LevelPageTable))
 
 %define GHCB_PT_ADDR  (FixedPcdGet32 
(PcdOvmfSecGhcbPageTableBase))
 %define GHCB_BASE (FixedPcdGet32 (PcdOvmfSecGhcbBase))
-- 
2.43.2




[edk2-devel] [PATCH 02/10] OvmfPkg/ResetVector: add ClearOvmfPageTables macro

2024-02-22 Thread Gerd Hoffmann
Move code to clear the page tables to a nasm macro.
No functional change.

Signed-off-by: Gerd Hoffmann 
---
 OvmfPkg/ResetVector/Ia32/PageTables64.asm | 35 ---
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/OvmfPkg/ResetVector/Ia32/PageTables64.asm 
b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
index 6fec6f2beeea..378ba2feeb4f 100644
--- a/OvmfPkg/ResetVector/Ia32/PageTables64.asm
+++ b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
@@ -45,6 +45,24 @@ BITS32
 %define TDX_BSP 1
 %define TDX_AP  2
 
+;
+; For OVMF, build some initial page tables at
+; PcdOvmfSecPageTablesBase - (PcdOvmfSecPageTablesBase + 0x6000).
+;
+; This range should match with PcdOvmfSecPageTablesSize which is
+; declared in the FDF files.
+;
+; At the end of PEI, the pages tables will be rebuilt into a
+; more permanent location by DxeIpl.
+;
+%macro ClearOvmfPageTables 0
+mov ecx, 6 * 0x1000 / 4
+xor eax, eax
+.clearPageTablesMemoryLoop:
+mov dword[ecx * 4 + PT_ADDR (0) - 4], eax
+loop.clearPageTablesMemoryLoop
+%endmacro
+
 ;
 ; Modified:  EAX, EBX, ECX, EDX
 ;
@@ -69,22 +87,7 @@ SetCr3ForPageTables64:
 OneTimeCall   GetSevCBitMaskAbove31
 
 ClearOvmfPageTables:
-;
-; For OVMF, build some initial page tables at
-; PcdOvmfSecPageTablesBase - (PcdOvmfSecPageTablesBase + 0x6000).
-;
-; This range should match with PcdOvmfSecPageTablesSize which is
-; declared in the FDF files.
-;
-; At the end of PEI, the pages tables will be rebuilt into a
-; more permanent location by DxeIpl.
-;
-
-mov ecx, 6 * 0x1000 / 4
-xor eax, eax
-clearPageTablesMemoryLoop:
-mov dword[ecx * 4 + PT_ADDR (0) - 4], eax
-loopclearPageTablesMemoryLoop
+ClearOvmfPageTables
 
 ;
 ; Top level Page Directory Pointers (1 * 512GB entry)
-- 
2.43.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115803): https://edk2.groups.io/g/devel/message/115803
Mute This Topic: https://groups.io/mt/104506789/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH 03/10] OvmfPkg/ResetVector: add CreatePageTables4Level macro

2024-02-22 Thread Gerd Hoffmann
Move code to create 4-level page tables to a nasm macro.
No functional change.

Signed-off-by: Gerd Hoffmann 
---
 OvmfPkg/ResetVector/Ia32/PageTables64.asm | 70 +--
 1 file changed, 39 insertions(+), 31 deletions(-)

diff --git a/OvmfPkg/ResetVector/Ia32/PageTables64.asm 
b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
index 378ba2feeb4f..14cc2c33aa3d 100644
--- a/OvmfPkg/ResetVector/Ia32/PageTables64.asm
+++ b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
@@ -63,6 +63,44 @@ BITS32
 loop.clearPageTablesMemoryLoop
 %endmacro
 
+;
+; Create page tables for 4-level paging
+;
+; Argument: upper 32 bits of the page table entries
+;
+%macro CreatePageTables4Level 1
+;
+; Top level Page Directory Pointers (1 * 512GB entry)
+;
+mov dword[PT_ADDR (0)], PT_ADDR (0x1000) + PAGE_PDE_DIRECTORY_ATTR
+mov dword[PT_ADDR (4)], %1
+
+;
+; Next level Page Directory Pointers (4 * 1GB entries => 4GB)
+;
+mov dword[PT_ADDR (0x1000)], PT_ADDR (0x2000) + PAGE_PDE_DIRECTORY_ATTR
+mov dword[PT_ADDR (0x1004)], %1
+mov dword[PT_ADDR (0x1008)], PT_ADDR (0x3000) + PAGE_PDE_DIRECTORY_ATTR
+mov dword[PT_ADDR (0x100C)], %1
+mov dword[PT_ADDR (0x1010)], PT_ADDR (0x4000) + PAGE_PDE_DIRECTORY_ATTR
+mov dword[PT_ADDR (0x1014)], %1
+mov dword[PT_ADDR (0x1018)], PT_ADDR (0x5000) + PAGE_PDE_DIRECTORY_ATTR
+mov dword[PT_ADDR (0x101C)], %1
+
+;
+; Page Table Entries (2048 * 2MB entries => 4GB)
+;
+mov ecx, 0x800
+.pageTableEntriesLoop4Level:
+mov eax, ecx
+dec eax
+shl eax, 21
+add eax, PAGE_PDE_LARGEPAGE_ATTR
+mov dword[ecx * 8 + PT_ADDR (0x2000 - 8)], eax
+mov dword[(ecx * 8 + PT_ADDR (0x2000 - 8)) + 4], %1
+loop.pageTableEntriesLoop4Level
+%endmacro
+
 ;
 ; Modified:  EAX, EBX, ECX, EDX
 ;
@@ -88,37 +126,7 @@ SetCr3ForPageTables64:
 
 ClearOvmfPageTables:
 ClearOvmfPageTables
-
-;
-; Top level Page Directory Pointers (1 * 512GB entry)
-;
-mov dword[PT_ADDR (0)], PT_ADDR (0x1000) + PAGE_PDE_DIRECTORY_ATTR
-mov dword[PT_ADDR (4)], edx
-
-;
-; Next level Page Directory Pointers (4 * 1GB entries => 4GB)
-;
-mov dword[PT_ADDR (0x1000)], PT_ADDR (0x2000) + PAGE_PDE_DIRECTORY_ATTR
-mov dword[PT_ADDR (0x1004)], edx
-mov dword[PT_ADDR (0x1008)], PT_ADDR (0x3000) + PAGE_PDE_DIRECTORY_ATTR
-mov dword[PT_ADDR (0x100C)], edx
-mov dword[PT_ADDR (0x1010)], PT_ADDR (0x4000) + PAGE_PDE_DIRECTORY_ATTR
-mov dword[PT_ADDR (0x1014)], edx
-mov dword[PT_ADDR (0x1018)], PT_ADDR (0x5000) + PAGE_PDE_DIRECTORY_ATTR
-mov dword[PT_ADDR (0x101C)], edx
-
-;
-; Page Table Entries (2048 * 2MB entries => 4GB)
-;
-mov ecx, 0x800
-pageTableEntriesLoop:
-mov eax, ecx
-dec eax
-shl eax, 21
-add eax, PAGE_PDE_LARGEPAGE_ATTR
-mov [ecx * 8 + PT_ADDR (0x2000 - 8)], eax
-mov [(ecx * 8 + PT_ADDR (0x2000 - 8)) + 4], edx
-looppageTableEntriesLoop
+CreatePageTables4Level edx
 
 ; Clear the C-bit from the GHCB page if the SEV-ES is enabled.
 OneTimeCall   SevClearPageEncMaskForGhcbPage
-- 
2.43.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115805): https://edk2.groups.io/g/devel/message/115805
Mute This Topic: https://groups.io/mt/104506791/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH 01/10] OvmfPkg/ResetVector: improve page table flag names

2024-02-22 Thread Gerd Hoffmann
Add comments, rename some of the PAGE_* flags and combined attributes.
Specifically use "LARGEPAGE" instead of "2M" because that bit is used
for both 2M and 1G large pages.

Signed-off-by: Gerd Hoffmann 
Reviewed-by: Laszlo Ersek 
---
 OvmfPkg/ResetVector/Ia32/PageTables64.asm | 39 +--
 1 file changed, 22 insertions(+), 17 deletions(-)

diff --git a/OvmfPkg/ResetVector/Ia32/PageTables64.asm 
b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
index 317cad430f29..6fec6f2beeea 100644
--- a/OvmfPkg/ResetVector/Ia32/PageTables64.asm
+++ b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
@@ -10,6 +10,7 @@
 
 BITS32
 
+; common for all levels
 %define PAGE_PRESENT0x01
 %define PAGE_READ_WRITE 0x02
 %define PAGE_USER_SUPERVISOR0x04
@@ -17,25 +18,29 @@ BITS32
 %define PAGE_CACHE_DISABLE 0x010
 %define PAGE_ACCESSED  0x020
 %define PAGE_DIRTY 0x040
-%define PAGE_PAT   0x080
 %define PAGE_GLOBAL   0x0100
-%define PAGE_2M_MBO0x080
-%define PAGE_2M_PAT  0x01000
+
+; page table entries (level 1)
+%define PAGE_PTE_PAT   0x080
+
+; page directory entries (level 2+)
+%define PAGE_PDE_LARGEPAGE 0x080
+%define PAGE_PDE_PAT 0x01000
 
 %define PAGE_4K_PDE_ATTR (PAGE_ACCESSED + \
   PAGE_DIRTY + \
   PAGE_READ_WRITE + \
   PAGE_PRESENT)
 
-%define PAGE_2M_PDE_ATTR (PAGE_2M_MBO + \
-  PAGE_ACCESSED + \
-  PAGE_DIRTY + \
-  PAGE_READ_WRITE + \
-  PAGE_PRESENT)
+%define PAGE_PDE_LARGEPAGE_ATTR (PAGE_PDE_LARGEPAGE + \
+ PAGE_ACCESSED + \
+ PAGE_DIRTY + \
+ PAGE_READ_WRITE + \
+ PAGE_PRESENT)
 
-%define PAGE_PDP_ATTR (PAGE_ACCESSED + \
-   PAGE_READ_WRITE + \
-   PAGE_PRESENT)
+%define PAGE_PDE_DIRECTORY_ATTR (PAGE_ACCESSED + \
+ PAGE_READ_WRITE + \
+ PAGE_PRESENT)
 
 %define TDX_BSP 1
 %define TDX_AP  2
@@ -84,19 +89,19 @@ clearPageTablesMemoryLoop:
 ;
 ; Top level Page Directory Pointers (1 * 512GB entry)
 ;
-mov dword[PT_ADDR (0)], PT_ADDR (0x1000) + PAGE_PDP_ATTR
+mov dword[PT_ADDR (0)], PT_ADDR (0x1000) + PAGE_PDE_DIRECTORY_ATTR
 mov dword[PT_ADDR (4)], edx
 
 ;
 ; Next level Page Directory Pointers (4 * 1GB entries => 4GB)
 ;
-mov dword[PT_ADDR (0x1000)], PT_ADDR (0x2000) + PAGE_PDP_ATTR
+mov dword[PT_ADDR (0x1000)], PT_ADDR (0x2000) + PAGE_PDE_DIRECTORY_ATTR
 mov dword[PT_ADDR (0x1004)], edx
-mov dword[PT_ADDR (0x1008)], PT_ADDR (0x3000) + PAGE_PDP_ATTR
+mov dword[PT_ADDR (0x1008)], PT_ADDR (0x3000) + PAGE_PDE_DIRECTORY_ATTR
 mov dword[PT_ADDR (0x100C)], edx
-mov dword[PT_ADDR (0x1010)], PT_ADDR (0x4000) + PAGE_PDP_ATTR
+mov dword[PT_ADDR (0x1010)], PT_ADDR (0x4000) + PAGE_PDE_DIRECTORY_ATTR
 mov dword[PT_ADDR (0x1014)], edx
-mov dword[PT_ADDR (0x1018)], PT_ADDR (0x5000) + PAGE_PDP_ATTR
+mov dword[PT_ADDR (0x1018)], PT_ADDR (0x5000) + PAGE_PDE_DIRECTORY_ATTR
 mov dword[PT_ADDR (0x101C)], edx
 
 ;
@@ -107,7 +112,7 @@ pageTableEntriesLoop:
 mov eax, ecx
 dec eax
 shl eax, 21
-add eax, PAGE_2M_PDE_ATTR
+add eax, PAGE_PDE_LARGEPAGE_ATTR
 mov [ecx * 8 + PT_ADDR (0x2000 - 8)], eax
 mov [(ecx * 8 + PT_ADDR (0x2000 - 8)) + 4], edx
 looppageTableEntriesLoop
-- 
2.43.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115804): https://edk2.groups.io/g/devel/message/115804
Mute This Topic: https://groups.io/mt/104506790/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH 00/10] OvmfPkg/ResetVector: cleanup and add 5-level paging support.

2024-02-22 Thread Gerd Hoffmann
So I ran with the suggestion by Laszlo to move the page table setup into
macros and untangle the non-CoCo / TDX / SEV code paths.  The first five
patches of the series are doing that (without functional changes).

Support for 5-level paging is added by the following five patches.  This
way it is indeed easier to understand.  Additional bonus is that the
patches can be splitted into smaller pieces and 5-level paging for the
three cases (non-CoCo / TDX / SEC) can be enabled independently.

The SEV patches (#9 + #10) are included here for completeness, but it is
probably a good idea to merge them only after 5-level paging support was
added to BaseMemEncryptSevLib.  This way we can turn on 5-level paging
support without breaking SEV.

Gerd Hoffmann (10):
  OvmfPkg/ResetVector: improve page table flag names
  OvmfPkg/ResetVector: add ClearOvmfPageTables macro
  OvmfPkg/ResetVector: add CreatePageTables4Level macro
  OvmfPkg/ResetVector: split TDX BSP workflow
  OvmfPkg/ResetVector: split SEV and non-CoCo workflows
  OvmfPkg/ResetVector: add 5-level paging support
  OvmfPkg/ResetVector: print post codes for 4/5 level paging
  OvmfPkg/ResetVector: wire up 5-level paging for TDX
  OvmfPkg/ResetVector: leave SEV VC handler installed longer
  OvmfPkg/ResetVector: wire up 5-level paging for SEV

 OvmfPkg/ResetVector/ResetVector.inf   |   1 +
 OvmfPkg/ResetVector/Ia32/AmdSev.asm   |  34 +--
 OvmfPkg/ResetVector/Ia32/IntelTdx.asm |  17 +-
 OvmfPkg/ResetVector/Ia32/PageTables64.asm | 300 +-
 OvmfPkg/ResetVector/Main.asm  |   4 +
 OvmfPkg/ResetVector/ResetVector.nasmb |   1 +
 6 files changed, 264 insertions(+), 93 deletions(-)

-- 
2.43.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115802): https://edk2.groups.io/g/devel/message/115802
Mute This Topic: https://groups.io/mt/104506788/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] GuestPhysAddrSize questions (was: Re: [PATCH v4 3/3] OvmfPkg/PlatformInitLib: add 5-level paging) support

2024-02-22 Thread Gerd Hoffmann
  Hi,

> +if (Cr4.Bits.LA57) {
> +  if (PhysBits > 48) {
> +/*
> + * Some Intel CPUs support 5-level paging, have more than 48
> + * phys-bits but support only 4-level EPT, which effectively
> + * limits guest phys-bits to 48.
> + *
> + * AMD Processors have a different but somewhat related
> + * problem: They can handle guest phys-bits larger than 48
> + * only in case the host runs in 5-level paging mode.
> + *
> + * Until we have some way to communicate that kind of
> + * limitations from hypervisor to guest, limit phys-bits
> + * to 48 unconditionally.
> + */

So I'm looking for some communication path.  One option would be to use
some bits in the KVM cpuid leaves.  Another possible candidate is cpuid
leaf 0x8008.

>From the AMD APM (revision 3.35):

  CPUID Fn8000_0008_EAX Long Mode Size Identifiers
  

  The value returned in EAX provides information about the maximum host
  and guest physical and linear address width (in bits) supported by the
  processor.

  Bits   FieldNameDescription

  31:24  —Reserved

  23:16 GuestPhysAddrSize Maximum guest physical address size in bits.
  This number applies only to guests using nested
  paging. When this field is zero, refer to the
  PhysAddrSize field for the maximum guest
  physical address size. See “Secure Virtual
  Machine” in APM Volume 2.

  15:8  LinAddrSize   Maximum linear address size in bits.

  7:0   PhysAddrSize  Maximum physical address size in bits. When
  GuestPhysAddrSize is zero, this field also
  indicates the maximum guest physical address
  size.

The description of the GuestPhysAddrSize is somewhat vague.  Is this a
value the hypervisor should use to figure how much address space it can
give to guests?  Or is this a value the hypervisor can set to inform the
guest about the available address space (which would be a solution to
the problem outlined in the comment above)?  Or both?

In case GuestPhysAddrSize should not be used this way:  Is it possible
allocate the currently reserved bits 31:24 for that purpose?

Tom?  Michael?

thanks & take care,
  Gerd



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115801): https://edk2.groups.io/g/devel/message/115801
Mute This Topic: https://groups.io/mt/104506481/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v4 2/3] MdeModulePkg/DxeIplPeim: rename variable

2024-02-22 Thread Gerd Hoffmann
Rename Page5LevelSupported to Page5LevelEnabled.

The variable is set to true in case 5-paging level is enabled (64-bit
PEI) or will be enabled (32-bit PEI), it does *not* tell whenever the
5-level paging is supported by the CPU.

Signed-off-by: Gerd Hoffmann 
Reviewed-by: Laszlo Ersek 
Acked-by: Ard Biesheuvel 
---
 .../Core/DxeIplPeim/X64/VirtualMemory.c   | 22 +--
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c 
b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c
index 1d240e95966e..df6196a41cd5 100644
--- a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c
+++ b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c
@@ -696,7 +696,7 @@ CreateIdentityMappingPageTables (
   UINTNTotalPagesNum;
   UINTNBigPageAddress;
   VOID *Hob;
-  BOOLEAN  Page5LevelSupport;
+  BOOLEAN  Page5LevelEnabled;
   BOOLEAN  Page1GSupport;
   PAGE_TABLE_1G_ENTRY  *PageDirectory1GEntry;
   UINT64   AddressEncMask;
@@ -744,15 +744,15 @@ CreateIdentityMappingPageTables (
 // If cpu has already run in 64bit long mode PEI, Page table Level in DXE 
must align with previous level.
 //
 Cr4.UintN = AsmReadCr4 ();
-Page5LevelSupport = (Cr4.Bits.LA57 != 0);
-if (Page5LevelSupport) {
+Page5LevelEnabled = (Cr4.Bits.LA57 != 0);
+if (Page5LevelEnabled) {
   ASSERT (PcdGetBool (PcdUse5LevelPageTable));
 }
   } else {
 //
 // If cpu runs in 32bit protected mode PEI, Page table Level in DXE is 
decided by PCD and feature capability.
 //
-Page5LevelSupport = FALSE;
+Page5LevelEnabled = FALSE;
 if (PcdGetBool (PcdUse5LevelPageTable)) {
   AsmCpuidEx (
 CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS,
@@ -763,12 +763,12 @@ CreateIdentityMappingPageTables (
 NULL
 );
   if (EcxFlags.Bits.FiveLevelPage != 0) {
-Page5LevelSupport = TRUE;
+Page5LevelEnabled = TRUE;
   }
 }
   }
 
-  DEBUG ((DEBUG_INFO, "AddressBits=%u 5LevelPaging=%u 1GPage=%u\n", 
PhysicalAddressBits, Page5LevelSupport, Page1GSupport));
+  DEBUG ((DEBUG_INFO, "AddressBits=%u 5LevelPaging=%u 1GPage=%u\n", 
PhysicalAddressBits, Page5LevelEnabled, Page1GSupport));
 
   //
   // IA-32e paging translates 48-bit linear addresses to 52-bit physical 
addresses
@@ -776,7 +776,7 @@ CreateIdentityMappingPageTables (
   //  due to either unsupported by HW, or disabled by PCD.
   //
   ASSERT (PhysicalAddressBits <= 52);
-  if (!Page5LevelSupport && (PhysicalAddressBits > 48)) {
+  if (!Page5LevelEnabled && (PhysicalAddressBits > 48)) {
 PhysicalAddressBits = 48;
   }
 
@@ -811,7 +811,7 @@ CreateIdentityMappingPageTables (
   //
   // Substract the one page occupied by PML5 entries if 5-Level Paging is 
disabled.
   //
-  if (!Page5LevelSupport) {
+  if (!Page5LevelEnabled) {
 TotalPagesNum--;
   }
 
@@ -831,7 +831,7 @@ CreateIdentityMappingPageTables (
   // By architecture only one PageMapLevel4 exists - so lets allocate storage 
for it.
   //
   PageMap = (VOID *)BigPageAddress;
-  if (Page5LevelSupport) {
+  if (Page5LevelEnabled) {
 //
 // By architecture only one PageMapLevel5 exists - so lets allocate 
storage for it.
 //
@@ -853,7 +853,7 @@ CreateIdentityMappingPageTables (
 PageMapLevel4Entry = (VOID *)BigPageAddress;
 BigPageAddress+= SIZE_4KB;
 
-if (Page5LevelSupport) {
+if (Page5LevelEnabled) {
   //
   // Make a PML5 Entry
   //
@@ -947,7 +947,7 @@ CreateIdentityMappingPageTables (
 ZeroMem (PageMapLevel4Entry, (512 - IndexOfPml4Entries) * sizeof 
(PAGE_MAP_AND_DIRECTORY_POINTER));
   }
 
-  if (Page5LevelSupport) {
+  if (Page5LevelEnabled) {
 Cr4.UintN = AsmReadCr4 ();
 Cr4.Bits.LA57 = 1;
 AsmWriteCr4 (Cr4.UintN);
-- 
2.43.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115799): https://edk2.groups.io/g/devel/message/115799
Mute This Topic: https://groups.io/mt/104506113/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v4 1/3] MdeModulePkg/DxeIplPeim: fix PcdUse5LevelPageTable assert

2024-02-22 Thread Gerd Hoffmann
PcdUse5LevelPageTable documentation says:

  Indicates if 5-Level Paging will be enabled in long mode. 5-Level
  Paging will not be enabled when the PCD is TRUE but CPU doesn't support
  5-Level Paging.

So running in 4-level paging mode with PcdUse5LevelPageTable=TRUE is
possible.  The only invalid combination is 5-level paging being active
with PcdUse5LevelPageTable=FALSE.

Fix the ASSERT accordingly.

Signed-off-by: Gerd Hoffmann 
Reviewed-by: Laszlo Ersek 
Acked-by: Ard Biesheuvel 
---
 MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c 
b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c
index 980c2002d4f5..1d240e95966e 100644
--- a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c
+++ b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c
@@ -745,7 +745,9 @@ CreateIdentityMappingPageTables (
 //
 Cr4.UintN = AsmReadCr4 ();
 Page5LevelSupport = (Cr4.Bits.LA57 != 0);
-ASSERT (PcdGetBool (PcdUse5LevelPageTable) == Page5LevelSupport);
+if (Page5LevelSupport) {
+  ASSERT (PcdGetBool (PcdUse5LevelPageTable));
+}
   } else {
 //
 // If cpu runs in 32bit protected mode PEI, Page table Level in DXE is 
decided by PCD and feature capability.
-- 
2.43.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115800): https://edk2.groups.io/g/devel/message/115800
Mute This Topic: https://groups.io/mt/104506114/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v4 3/3] OvmfPkg/PlatformInitLib: add 5-level paging support

2024-02-22 Thread Gerd Hoffmann
Adjust physical address space logic for la57 mode (5-level paging).
With a larger logical address space we can identity-map a larger
physical address space.

Signed-off-by: Gerd Hoffmann 
Reviewed-by: Laszlo Ersek 
Acked-by: Ard Biesheuvel 
---
 OvmfPkg/Library/PlatformInitLib/MemDetect.c | 63 ++---
 1 file changed, 44 insertions(+), 19 deletions(-)

diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c 
b/OvmfPkg/Library/PlatformInitLib/MemDetect.c
index f042517bb64a..7b6e5102ad55 100644
--- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c
+++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c
@@ -628,11 +628,12 @@ PlatformAddressWidthFromCpuid (
   IN BOOLEANQemuQuirk
   )
 {
-  UINT32   RegEax, RegEbx, RegEcx, RegEdx, Max;
-  UINT8PhysBits;
-  CHAR8Signature[13];
-  BOOLEAN  Valid = FALSE;
-  BOOLEAN  Page1GSupport = FALSE;
+  UINT32RegEax, RegEbx, RegEcx, RegEdx, Max;
+  UINT8 PhysBits;
+  CHAR8 Signature[13];
+  IA32_CR4  Cr4;
+  BOOLEAN   Valid = FALSE;
+  BOOLEAN   Page1GSupport = FALSE;
 
   ZeroMem (Signature, sizeof (Signature));
 
@@ -670,30 +671,54 @@ PlatformAddressWidthFromCpuid (
 }
   }
 
+  Cr4.UintN = AsmReadCr4 ();
+
   DEBUG ((
 DEBUG_INFO,
-"%a: Signature: '%a', PhysBits: %d, QemuQuirk: %a, Valid: %a\n",
+"%a: Signature: '%a', PhysBits: %d, QemuQuirk: %a, la57: %a, Valid: %a\n",
 __func__,
 Signature,
 PhysBits,
 QemuQuirk ? "On" : "Off",
+Cr4.Bits.LA57 ? "On" : "Off",
 Valid ? "Yes" : "No"
 ));
 
   if (Valid) {
-if (PhysBits > 46) {
-  /*
-   * Avoid 5-level paging altogether for now, which limits
-   * PhysBits to 48.  Also avoid using address bit 48, due to sign
-   * extension we can't identity-map these addresses (and lots of
-   * places in edk2 assume we have everything identity-mapped).
-   * So the actual limit is 47.
-   *
-   * Also some older linux kernels apparently have problems handling
-   * phys-bits > 46 correctly, so use that as limit.
-   */
-  DEBUG ((DEBUG_INFO, "%a: limit PhysBits to 46 (avoid 5-level paging)\n", 
__func__));
-  PhysBits = 46;
+/*
+ * Due to the sign extension we can use only the lower half of the
+ * virtual address space to identity-map physical address space,
+ * which gives us a 47 bit wide address space with 4 paging levels
+ * and a 56 bit wide address space with 5 paging levels.
+ */
+if (Cr4.Bits.LA57) {
+  if (PhysBits > 48) {
+/*
+ * Some Intel CPUs support 5-level paging, have more than 48
+ * phys-bits but support only 4-level EPT, which effectively
+ * limits guest phys-bits to 48.
+ *
+ * AMD Processors have a different but somewhat related
+ * problem: They can handle guest phys-bits larger than 48
+ * only in case the host runs in 5-level paging mode.
+ *
+ * Until we have some way to communicate that kind of
+ * limitations from hypervisor to guest, limit phys-bits
+ * to 48 unconditionally.
+ */
+DEBUG ((DEBUG_INFO, "%a: limit PhysBits to 48 (5-level paging)\n", 
__func__));
+PhysBits = 48;
+  }
+} else {
+  if (PhysBits > 46) {
+/*
+ * Some older linux kernels apparently have problems handling
+ * phys-bits > 46 correctly, so use that instead of 47 as
+ * limit.
+ */
+DEBUG ((DEBUG_INFO, "%a: limit PhysBits to 46 (4-level paging)\n", 
__func__));
+PhysBits = 46;
+  }
 }
 
 if (!Page1GSupport && (PhysBits > 40)) {
-- 
2.43.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115798): https://edk2.groups.io/g/devel/message/115798
Mute This Topic: https://groups.io/mt/104506111/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v4 0/3] OvmfPkg: Add support for 5-level paging

2024-02-22 Thread Gerd Hoffmann
Patch #1 + #2 fix MdeModulePkg/DxeIplPeim to not assert in case a
5-level enabled build runs in 4-level paging mode.

Patch #3 updates PlatformInitLib for 5-level paging support (update
PhysBits calculation).

v4:
 - drop OvmfPkg/ResetVecor changes, they will be sent as
   separate patch series.
 - add Ard's ack.
v3:
 - add resetvector fixes for sev and tdx
v2 changes:
 - fix sev/tdx handling with 5-level paging.
 - more comments for 5-level page table setup.
 - improve PAGE_* naming (new patch #3).
 - rename Page5LevelSupported to Page5LevelEnabled (new patch #2).
 - pick up some review tags.

Gerd Hoffmann (3):
  MdeModulePkg/DxeIplPeim: fix PcdUse5LevelPageTable assert
  MdeModulePkg/DxeIplPeim: rename variable
  OvmfPkg/PlatformInitLib: add 5-level paging support

 .../Core/DxeIplPeim/X64/VirtualMemory.c   | 24 +++
 OvmfPkg/Library/PlatformInitLib/MemDetect.c   | 63 +--
 2 files changed, 57 insertions(+), 30 deletions(-)

-- 
2.43.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115797): https://edk2.groups.io/g/devel/message/115797
Mute This Topic: https://groups.io/mt/104506109/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH v2 2/5] UefiCpuPkg/MpInitLib: Add support for multiple HOBs to GetBspNumber()

2024-02-22 Thread Ni, Ray
> > +  @param[in] FirstMpHandOff   Pointer to first MpHandOff HOB.
> 
> ... also, it would be more precise to say "first MpHandOff HOB body".
> 
"body" is a very good term that emphasizes it doesn't point to a separate 
storage. 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115796): https://edk2.groups.io/g/devel/message/115796
Mute This Topic: https://groups.io/mt/104472310/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH] UefiCpuPkg: add volatile qualifier to page table related variable

2024-02-22 Thread Ni, Ray
> > I agree with the idea (I think it's a necessary change, or put
> > differently, an improvement, even though I may not be convinced that it
> > is a *sufficient* improvement; but let's not rehash all that here
> > again); however, I think the implementation is not the greatest.
> >
> > Volatile-qualifying the local variables does not seem useful for
> > anything. It's fine -- actually: it's beneficial -- if the compiler
> > optimizes accesses to those locals -- being on the stack -- as heavily
> > as it can. In other words, those parts of the patch look like a small
> > performance regression.

I did experiment using MSVC compiler with below code:
  int main () {
int x;
x = 3;
return 0;
  }

If building the above code in optimized mode, the disassembly does not contain
any reference to local variable x.

But if I changed "int x" to "volatile int x", the compiler does not optimize 
out the
assignment of x.

So, it means the "volatile"  matters even when it applies local variables.


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115795): https://edk2.groups.io/g/devel/message/115795
Mute This Topic: https://groups.io/mt/104483610/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3 12/12] OvmfPkg: only add shell to FV in case secure boot is disabled

2024-02-22 Thread Gerd Hoffmann
The EFI Shell allows to bypass secure boot, do not allow
to include the shell in the firmware images of secure boot
enabled builds.

This prevents misconfigured downstream builds.

Ref: https://bugs.launchpad.net/ubuntu/+source/edk2/+bug/2040137
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=4641
Signed-off-by: Gerd Hoffmann 
Reviewed-by: Laszlo Ersek 
Acked-by: Jiewen Yao 
---
 OvmfPkg/Include/Fdf/ShellDxe.fdf.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/OvmfPkg/Include/Fdf/ShellDxe.fdf.inc 
b/OvmfPkg/Include/Fdf/ShellDxe.fdf.inc
index 3081ac41780a..38f69747b02c 100644
--- a/OvmfPkg/Include/Fdf/ShellDxe.fdf.inc
+++ b/OvmfPkg/Include/Fdf/ShellDxe.fdf.inc
@@ -2,7 +2,7 @@
 #SPDX-License-Identifier: BSD-2-Clause-Patent
 ##
 
-!if $(BUILD_SHELL) == TRUE
+!if $(BUILD_SHELL) == TRUE && $(SECURE_BOOT_ENABLE) == FALSE
 
 !if $(TOOL_CHAIN_TAG) != "XCODE5"
 !if $(NETWORK_ENABLE) == TRUE
-- 
2.43.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115794): https://edk2.groups.io/g/devel/message/115794
Mute This Topic: https://groups.io/mt/104505816/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3 09/12] OvmfPkg: switch IntelTdxX64 to new shell include files

2024-02-22 Thread Gerd Hoffmann
Note that IntelTdxX64 is compiled without network support, so thanks to
the network conditionals in the include files the build result (network
shell commands excluded) should be identical before and after the patch.

Signed-off-by: Gerd Hoffmann 
Acked-by: Laszlo Ersek 
Acked-by: Jiewen Yao 
---
 OvmfPkg/IntelTdx/IntelTdxX64.dsc | 32 +++-
 OvmfPkg/IntelTdx/IntelTdxX64.fdf |  9 ++---
 2 files changed, 5 insertions(+), 36 deletions(-)

diff --git a/OvmfPkg/IntelTdx/IntelTdxX64.dsc b/OvmfPkg/IntelTdx/IntelTdxX64.dsc
index 82e3e41cfc57..7a767324ffda 100644
--- a/OvmfPkg/IntelTdx/IntelTdxX64.dsc
+++ b/OvmfPkg/IntelTdx/IntelTdxX64.dsc
@@ -201,9 +201,6 @@ [LibraryClasses]
   
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf
   
VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
 
-!if $(BUILD_SHELL) == TRUE
-  ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf
-!endif
   ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf
   
S3BootScriptLib|MdeModulePkg/Library/PiDxeS3BootScriptLib/DxeS3BootScriptLib.inf
   SmbusLib|MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf
@@ -212,6 +209,8 @@ [LibraryClasses]
   
Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf
   
TpmMeasurementLib|SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasurementLib.inf
 
+!include OvmfPkg/Include/Dsc/ShellLibs.dsc.inc
+
 [LibraryClasses.common]
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
   CcExitLib|OvmfPkg/Library/CcExitLib/CcExitLib.inf
@@ -717,32 +716,7 @@ [Components]
   MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf
   MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf
 
-!if $(TOOL_CHAIN_TAG) != "XCODE5" && $(BUILD_SHELL) == TRUE
-  OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.inf {
-
-  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
-  }
-!endif
-!if $(BUILD_SHELL) == TRUE
-  ShellPkg/Application/Shell/Shell.inf {
-
-  
ShellCommandLib|ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.inf
-  
NULL|ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellLevel3CommandsLib/UefiShellLevel3CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellInstall1CommandsLib/UefiShellInstall1CommandsLib.inf
-  
HandleParsingLib|ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.inf
-  PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf
-  
BcfgCommandLib|ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.inf
-
-
-  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0xFF
-  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
-  gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|8000
-  }
-!endif
+!include OvmfPkg/Include/Dsc/ShellComponents.dsc.inc
 
 !if $(SECURE_BOOT_ENABLE) == TRUE
   SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf
diff --git a/OvmfPkg/IntelTdx/IntelTdxX64.fdf b/OvmfPkg/IntelTdx/IntelTdxX64.fdf
index e844a0988d68..f3b5126254c6 100644
--- a/OvmfPkg/IntelTdx/IntelTdxX64.fdf
+++ b/OvmfPkg/IntelTdx/IntelTdxX64.fdf
@@ -307,13 +307,6 @@ [FV.NCCFV]
 INF  MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf
 INF  OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf
 
-!if $(BUILD_SHELL) == TRUE && $(TOOL_CHAIN_TAG) != "XCODE5"
-INF  OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.inf
-!endif
-!if $(BUILD_SHELL) == TRUE
-INF  ShellPkg/Application/Shell/Shell.inf
-!endif
-
 INF MdeModulePkg/Logo/LogoDxe.inf
 
 #
@@ -332,6 +325,8 @@ [FV.NCCFV]
 INF  OvmfPkg/VirtioGpuDxe/VirtioGpu.inf
 INF  OvmfPkg/PlatformDxe/Platform.inf
 
+!include OvmfPkg/Include/Fdf/ShellDxe.fdf.inc
+
 

 
 [FV.FVMAIN_COMPACT]
-- 
2.43.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115793): https://edk2.groups.io/g/devel/message/115793
Mute This Topic: https://groups.io/mt/104505815/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3 08/12] OvmfPkg: switch AmdSevX64 to new shell include files

2024-02-22 Thread Gerd Hoffmann
Note that AmdSevX64 is compiled without network support, so thanks to
the network conditionals in the include files the build result (network
shell commands excluded) should be identical before and after the patch.

Signed-off-by: Gerd Hoffmann 
Acked-by: Laszlo Ersek 
Acked-by: Jiewen Yao 
---
 OvmfPkg/AmdSev/AmdSevX64.dsc | 30 ++
 OvmfPkg/AmdSev/AmdSevX64.fdf |  8 ++--
 2 files changed, 4 insertions(+), 34 deletions(-)

diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc
index a31a89344a60..60e916b4fd18 100644
--- a/OvmfPkg/AmdSev/AmdSevX64.dsc
+++ b/OvmfPkg/AmdSev/AmdSevX64.dsc
@@ -194,16 +194,14 @@ [LibraryClasses]
   
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf
   
VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.inf
 
-!if $(BUILD_SHELL) == TRUE
-  ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf
   ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf
-!endif
 
   SmbusLib|MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf
   
OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf
   
S3BootScriptLib|MdeModulePkg/Library/PiDxeS3BootScriptLib/DxeS3BootScriptLib.inf
 
 !include OvmfPkg/Include/Dsc/OvmfTpmLibs.dsc.inc
+!include OvmfPkg/Include/Dsc/ShellLibs.dsc.inc
 
 [LibraryClasses.common]
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
@@ -729,34 +727,10 @@ [Components]
   MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf
   MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf
 
-!if $(TOOL_CHAIN_TAG) != "XCODE5" && $(BUILD_SHELL) == TRUE
-  OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.inf {
-
-  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
-  }
-!endif
   OvmfPkg/AmdSev/SecretDxe/SecretDxe.inf
   OvmfPkg/AmdSev/Grub/Grub.inf
-!if $(BUILD_SHELL) == TRUE
-  ShellPkg/Application/Shell/Shell.inf {
-
-  
ShellCommandLib|ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.inf
-  
NULL|ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellLevel3CommandsLib/UefiShellLevel3CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellInstall1CommandsLib/UefiShellInstall1CommandsLib.inf
-  
HandleParsingLib|ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.inf
-  PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf
-  
BcfgCommandLib|ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.inf
 
-
-  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0xFF
-  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
-  gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|8000
-  }
-!endif
+!include OvmfPkg/Include/Dsc/ShellComponents.dsc.inc
 
   OvmfPkg/PlatformDxe/Platform.inf
   OvmfPkg/AmdSevDxe/AmdSevDxe.inf {
diff --git a/OvmfPkg/AmdSev/AmdSevX64.fdf b/OvmfPkg/AmdSev/AmdSevX64.fdf
index 9dd409596780..b84981e7ba04 100644
--- a/OvmfPkg/AmdSev/AmdSevX64.fdf
+++ b/OvmfPkg/AmdSev/AmdSevX64.fdf
@@ -277,14 +277,8 @@ [FV.DXEFV]
 INF  FatPkg/EnhancedFatDxe/Fat.inf
 INF  MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf
 
-!if $(TOOL_CHAIN_TAG) != "XCODE5" && $(BUILD_SHELL) == TRUE
-INF  OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.inf
-!endif
 INF OvmfPkg/AmdSev/SecretDxe/SecretDxe.inf
 INF  OvmfPkg/AmdSev/Grub/Grub.inf
-!if $(BUILD_SHELL) == TRUE
-INF  ShellPkg/Application/Shell/Shell.inf
-!endif
 
 INF MdeModulePkg/Logo/LogoDxe.inf
 
@@ -320,6 +314,8 @@ [FV.DXEFV]
 #
 !include OvmfPkg/Include/Fdf/OvmfTpmDxe.fdf.inc
 
+!include OvmfPkg/Include/Fdf/ShellDxe.fdf.inc
+
 

 
 [FV.FVMAIN_COMPACT]
-- 
2.43.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115791): https://edk2.groups.io/g/devel/message/115791
Mute This Topic: https://groups.io/mt/104505813/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3 11/12] OvmfPkg/CI: copy shell to virtual drive

2024-02-22 Thread Gerd Hoffmann
Place the EFI shell as EFI/BOOT/BOOT{ARCH}.EFI on the virtual drive.
This allows the "run to shell" CI test case to work even in case the
shell is not included in the firmware image.

This is needed because an followup patch will exclude the shell from
secure boot enabled firmware images.

Signed-off-by: Gerd Hoffmann 
Acked-by: Laszlo Ersek 
Acked-by: Jiewen Yao 
---
 OvmfPkg/PlatformCI/PlatformBuildLib.py | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/OvmfPkg/PlatformCI/PlatformBuildLib.py 
b/OvmfPkg/PlatformCI/PlatformBuildLib.py
index f829738cdda4..00d454954bff 100644
--- a/OvmfPkg/PlatformCI/PlatformBuildLib.py
+++ b/OvmfPkg/PlatformCI/PlatformBuildLib.py
@@ -5,6 +5,7 @@
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 ##
 import os
+import shutil
 import logging
 import io
 
@@ -181,7 +182,8 @@ class PlatformBuilder( UefiBuilder, BuildSettingsManager):
 
 def FlashRomImage(self):
 VirtualDrive = os.path.join(self.env.GetValue("BUILD_OUTPUT_BASE"), 
"VirtualDrive")
-os.makedirs(VirtualDrive, exist_ok=True)
+VirtualDriveBoot = os.path.join(VirtualDrive, "EFI", "BOOT")
+os.makedirs(VirtualDriveBoot, exist_ok=True)
 OutputPath_FV = os.path.join(self.env.GetValue("BUILD_OUTPUT_BASE"), 
"FV")
 
 if (self.env.GetValue("QEMU_SKIP") and
@@ -189,6 +191,14 @@ class PlatformBuilder( UefiBuilder, BuildSettingsManager):
 logging.info("skipping qemu boot test")
 return 0
 
+# copy shell to VirtualDrive
+for arch in self.env.GetValue("TARGET_ARCH").split():
+src = os.path.join(self.env.GetValue("BUILD_OUTPUT_BASE"), arch, 
"Shell.efi")
+dst = os.path.join(VirtualDriveBoot, f'BOOT{arch}.EFI')
+if os.path.exists(src):
+logging.info("copy %s -> %s", src, dst)
+shutil.copyfile(src, dst)
+
 #
 # QEMU must be on the path
 #
-- 
2.43.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115792): https://edk2.groups.io/g/devel/message/115792
Mute This Topic: https://groups.io/mt/104505814/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3 07/12] OvmfPkg: switch OvmfPkgIa32X64 to new shell include files

2024-02-22 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann 
Reviewed-by: Laszlo Ersek 
Acked-by: Jiewen Yao 
---
 OvmfPkg/OvmfPkgIa32X64.dsc | 47 ++
 OvmfPkg/OvmfPkgIa32X64.fdf | 11 ++---
 2 files changed, 4 insertions(+), 54 deletions(-)

diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc
index 5e9eee628aea..90b15dc27097 100644
--- a/OvmfPkg/OvmfPkgIa32X64.dsc
+++ b/OvmfPkg/OvmfPkgIa32X64.dsc
@@ -242,9 +242,6 @@ [LibraryClasses]
   TlsLib|CryptoPkg/Library/TlsLib/TlsLib.inf
 !endif
 
-!if $(BUILD_SHELL) == TRUE
-  ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf
-!endif
   ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf
 
   
S3BootScriptLib|MdeModulePkg/Library/PiDxeS3BootScriptLib/DxeS3BootScriptLib.inf
@@ -252,6 +249,7 @@ [LibraryClasses]
   
OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf
 
 !include OvmfPkg/Include/Dsc/OvmfTpmLibs.dsc.inc
+!include OvmfPkg/Include/Dsc/ShellLibs.dsc.inc
 
 [LibraryClasses.common]
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
@@ -888,48 +886,7 @@ [Components.X64]
   MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf
   MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf
 
-!if $(TOOL_CHAIN_TAG) != "XCODE5" && $(BUILD_SHELL) == TRUE
-  ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf {
-
-  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
-  }
-  ShellPkg/DynamicCommand/HttpDynamicCommand/HttpDynamicCommand.inf {
-
-  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
-  }
-  
ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicyDynamicCommand.inf
 {
-
-  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
-  }
-  OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.inf {
-
-  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
-  }
-!endif
-!if $(BUILD_SHELL) == TRUE
-  ShellPkg/Application/Shell/Shell.inf {
-
-  
ShellCommandLib|ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.inf
-  
NULL|ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellLevel3CommandsLib/UefiShellLevel3CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellInstall1CommandsLib/UefiShellInstall1CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.inf
-!if $(NETWORK_IP6_ENABLE) == TRUE
-  
NULL|ShellPkg/Library/UefiShellNetwork2CommandsLib/UefiShellNetwork2CommandsLib.inf
-!endif
-  
HandleParsingLib|ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.inf
-  PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf
-  
BcfgCommandLib|ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.inf
-
-
-  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0xFF
-  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
-  gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|8000
-  }
-!endif
+!include OvmfPkg/Include/Dsc/ShellComponents.dsc.inc
 
 !if $(SECURE_BOOT_ENABLE) == TRUE
   SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf
diff --git a/OvmfPkg/OvmfPkgIa32X64.fdf b/OvmfPkg/OvmfPkgIa32X64.fdf
index 74cfb58f06cd..ee8068ad55dc 100644
--- a/OvmfPkg/OvmfPkgIa32X64.fdf
+++ b/OvmfPkg/OvmfPkgIa32X64.fdf
@@ -294,15 +294,6 @@ [FV.DXEFV]
 INF  MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf
 INF  OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf
 
-!if $(BUILD_SHELL) == TRUE && $(TOOL_CHAIN_TAG) != "XCODE5"
-INF  ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf
-INF  ShellPkg/DynamicCommand/HttpDynamicCommand/HttpDynamicCommand.inf
-INF  OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.inf
-!endif
-!if $(BUILD_SHELL) == TRUE
-INF  ShellPkg/Application/Shell/Shell.inf
-!endif
-
 INF MdeModulePkg/Logo/LogoDxe.inf
 
 #
@@ -368,6 +359,8 @@ [FV.DXEFV]
 #
 !include OvmfPkg/Include/Fdf/OvmfTpmDxe.fdf.inc
 
+!include OvmfPkg/Include/Fdf/ShellDxe.fdf.inc
+
 

 
 [FV.FVMAIN_COMPACT]
-- 
2.43.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115789): https://edk2.groups.io/g/devel/message/115789
Mute This Topic: https://groups.io/mt/104505811/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3 10/12] OvmfPkg: switch MicrovmX64 to new shell include files

2024-02-22 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann 
Acked-by: Laszlo Ersek 
Acked-by: Jiewen Yao 
---
 OvmfPkg/Microvm/MicrovmX64.dsc | 49 ++
 OvmfPkg/Microvm/MicrovmX64.fdf |  9 ++-
 2 files changed, 10 insertions(+), 48 deletions(-)

diff --git a/OvmfPkg/Microvm/MicrovmX64.dsc b/OvmfPkg/Microvm/MicrovmX64.dsc
index 063324cd0572..2c6bb83beb85 100644
--- a/OvmfPkg/Microvm/MicrovmX64.dsc
+++ b/OvmfPkg/Microvm/MicrovmX64.dsc
@@ -33,6 +33,11 @@ [Defines]
   DEFINE SMM_REQUIRE = FALSE
   DEFINE SOURCE_DEBUG_ENABLE = FALSE
 
+  #
+  # Shell can be useful for debugging but should not be enabled for production
+  #
+  DEFINE BUILD_SHELL = TRUE
+
   #
   # Network definition
   #
@@ -230,7 +235,6 @@ [LibraryClasses]
   TlsLib|CryptoPkg/Library/TlsLib/TlsLib.inf
 !endif
 
-  ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf
   ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf
   
S3BootScriptLib|MdeModulePkg/Library/PiDxeS3BootScriptLib/DxeS3BootScriptLib.inf
   SmbusLib|MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf
@@ -239,6 +243,8 @@ [LibraryClasses]
   
Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf
   
TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf
 
+!include OvmfPkg/Include/Dsc/ShellLibs.dsc.inc
+
 [LibraryClasses.common]
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
   CcExitLib|OvmfPkg/Library/CcExitLib/CcExitLib.inf
@@ -837,46 +843,7 @@ [Components]
   MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf
   MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf
 
-!if $(TOOL_CHAIN_TAG) != "XCODE5"
-  ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf {
-
-  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
-  }
-  ShellPkg/DynamicCommand/HttpDynamicCommand/HttpDynamicCommand.inf {
-
-  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
-  }
-  
ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicyDynamicCommand.inf
 {
-
-  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
-  }
-  OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.inf {
-
-  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
-  }
-!endif
-  ShellPkg/Application/Shell/Shell.inf {
-
-  
ShellCommandLib|ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.inf
-  
NULL|ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellLevel3CommandsLib/UefiShellLevel3CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellInstall1CommandsLib/UefiShellInstall1CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.inf
-!if $(NETWORK_IP6_ENABLE) == TRUE
-  
NULL|ShellPkg/Library/UefiShellNetwork2CommandsLib/UefiShellNetwork2CommandsLib.inf
-!endif
-  
HandleParsingLib|ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.inf
-  PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf
-  
BcfgCommandLib|ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.inf
-
-
-  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0xFF
-  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
-  gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|8000
-  }
+!include OvmfPkg/Include/Dsc/ShellComponents.dsc.inc
 
 !if $(SECURE_BOOT_ENABLE) == TRUE
   SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf
diff --git a/OvmfPkg/Microvm/MicrovmX64.fdf b/OvmfPkg/Microvm/MicrovmX64.fdf
index c877b3f088f9..825bf9f5e41f 100644
--- a/OvmfPkg/Microvm/MicrovmX64.fdf
+++ b/OvmfPkg/Microvm/MicrovmX64.fdf
@@ -257,13 +257,6 @@ [FV.DXEFV]
 INF  EmbeddedPkg/Drivers/FdtClientDxe/FdtClientDxe.inf
 INF  OvmfPkg/Fdt/VirtioFdtDxe/VirtioFdtDxe.inf
 
-!if $(TOOL_CHAIN_TAG) != "XCODE5"
-INF  ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf
-INF  ShellPkg/DynamicCommand/HttpDynamicCommand/HttpDynamicCommand.inf
-INF  OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.inf
-!endif
-INF  ShellPkg/Application/Shell/Shell.inf
-
 INF MdeModulePkg/Logo/LogoDxe.inf
 
 #
@@ -302,6 +295,8 @@ [FV.DXEFV]
 INF  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf
 INF  MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf
 
+!include OvmfPkg/Include/Fdf/ShellDxe.fdf.inc
+
 

 
 [FV.FVMAIN_COMPACT]
-- 
2.43.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115790): 

[edk2-devel] [PATCH v3 05/12] OvmfPkg: ShellDxe.fdf.inc: add VariablePolicyDynamicCommand to FV

2024-02-22 Thread Gerd Hoffmann
Needed to make the new 'varpolicy' EFI shell command
actually available in the OVMF firmware builds.

Fixes: fe6cd1c18721 ("OvmfPkg: Add varpolicy shell command")
Signed-off-by: Gerd Hoffmann 
Reviewed-by: Laszlo Ersek 
Acked-by: Jiewen Yao 
---
 OvmfPkg/Include/Fdf/ShellDxe.fdf.inc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/OvmfPkg/Include/Fdf/ShellDxe.fdf.inc 
b/OvmfPkg/Include/Fdf/ShellDxe.fdf.inc
index 6536c30c5413..3081ac41780a 100644
--- a/OvmfPkg/Include/Fdf/ShellDxe.fdf.inc
+++ b/OvmfPkg/Include/Fdf/ShellDxe.fdf.inc
@@ -9,6 +9,7 @@
 INF  ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf
 INF  ShellPkg/DynamicCommand/HttpDynamicCommand/HttpDynamicCommand.inf
 !endif
+INF  
ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicyDynamicCommand.inf
 INF  OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.inf
 !endif
 
-- 
2.43.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115788): https://edk2.groups.io/g/devel/message/115788
Mute This Topic: https://groups.io/mt/104505810/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3 06/12] OvmfPkg: switch OvmfPkgIa32 to new shell include files

2024-02-22 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann 
Reviewed-by: Laszlo Ersek 
Acked-by: Jiewen Yao 
---
 OvmfPkg/OvmfPkgIa32.dsc | 47 ++---
 OvmfPkg/OvmfPkgIa32.fdf | 11 ++
 2 files changed, 4 insertions(+), 54 deletions(-)

diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc
index 28379961a78e..713f08764b07 100644
--- a/OvmfPkg/OvmfPkgIa32.dsc
+++ b/OvmfPkg/OvmfPkgIa32.dsc
@@ -237,9 +237,6 @@ [LibraryClasses]
   TlsLib|CryptoPkg/Library/TlsLib/TlsLib.inf
 !endif
 
-!if $(BUILD_SHELL) == TRUE
-  ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf
-!endif
   ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf
 
   
S3BootScriptLib|MdeModulePkg/Library/PiDxeS3BootScriptLib/DxeS3BootScriptLib.inf
@@ -247,6 +244,7 @@ [LibraryClasses]
   
OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf
 
 !include OvmfPkg/Include/Dsc/OvmfTpmLibs.dsc.inc
+!include OvmfPkg/Include/Dsc/ShellLibs.dsc.inc
 
 [LibraryClasses.common]
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
@@ -874,48 +872,7 @@ [Components]
   MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf
   MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf
 
-!if $(TOOL_CHAIN_TAG) != "XCODE5" && $(BUILD_SHELL) == TRUE
-  ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf {
-
-  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
-  }
-  ShellPkg/DynamicCommand/HttpDynamicCommand/HttpDynamicCommand.inf {
-
-  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
-  }
-  
ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicyDynamicCommand.inf
 {
-
-  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
-  }
-  OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.inf {
-
-  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
-  }
-!endif
-!if $(BUILD_SHELL) == TRUE
-  ShellPkg/Application/Shell/Shell.inf {
-
-  
ShellCommandLib|ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.inf
-  
NULL|ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellLevel3CommandsLib/UefiShellLevel3CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellInstall1CommandsLib/UefiShellInstall1CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.inf
-!if $(NETWORK_IP6_ENABLE) == TRUE
-  
NULL|ShellPkg/Library/UefiShellNetwork2CommandsLib/UefiShellNetwork2CommandsLib.inf
-!endif
-  
HandleParsingLib|ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.inf
-  PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf
-  
BcfgCommandLib|ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.inf
-
-
-  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0xFF
-  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
-  gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|8000
-  }
-!endif
+!include OvmfPkg/Include/Dsc/ShellComponents.dsc.inc
 
 !if $(SECURE_BOOT_ENABLE) == TRUE
   SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf
diff --git a/OvmfPkg/OvmfPkgIa32.fdf b/OvmfPkg/OvmfPkgIa32.fdf
index 501b4de4695e..6c56c5e53f21 100644
--- a/OvmfPkg/OvmfPkgIa32.fdf
+++ b/OvmfPkg/OvmfPkgIa32.fdf
@@ -293,15 +293,6 @@ [FV.DXEFV]
 INF  MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf
 INF  OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf
 
-!if $(BUILD_SHELL) == TRUE && $(TOOL_CHAIN_TAG) != "XCODE5"
-INF  ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf
-INF  ShellPkg/DynamicCommand/HttpDynamicCommand/HttpDynamicCommand.inf
-INF  OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.inf
-!endif
-!if $(BUILD_SHELL) == TRUE
-INF  ShellPkg/Application/Shell/Shell.inf
-!endif
-
 INF MdeModulePkg/Logo/LogoDxe.inf
 
 #
@@ -361,6 +352,8 @@ [FV.DXEFV]
 #
 !include OvmfPkg/Include/Fdf/OvmfTpmDxe.fdf.inc
 
+!include OvmfPkg/Include/Fdf/ShellDxe.fdf.inc
+
 !if $(LOAD_X64_ON_IA32_ENABLE) == TRUE
 INF  OvmfPkg/CompatImageLoaderDxe/CompatImageLoaderDxe.inf
 !endif
-- 
2.43.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115787): https://edk2.groups.io/g/devel/message/115787
Mute This Topic: https://groups.io/mt/104505809/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3 01/12] OvmfPkg: add ShellComponents.dsc.inc

2024-02-22 Thread Gerd Hoffmann
Move EFI Shell components from OvmfPkgX64.dsc to
the new ShellComponents.dsc.inc include file.

Signed-off-by: Gerd Hoffmann 
Reviewed-by: Laszlo Ersek 
Acked-by: Jiewen Yao 
---
 OvmfPkg/Include/Dsc/ShellComponents.dsc.inc | 49 +
 OvmfPkg/OvmfPkgX64.dsc  | 43 +-
 2 files changed, 50 insertions(+), 42 deletions(-)
 create mode 100644 OvmfPkg/Include/Dsc/ShellComponents.dsc.inc

diff --git a/OvmfPkg/Include/Dsc/ShellComponents.dsc.inc 
b/OvmfPkg/Include/Dsc/ShellComponents.dsc.inc
new file mode 100644
index ..1a3a349a9de5
--- /dev/null
+++ b/OvmfPkg/Include/Dsc/ShellComponents.dsc.inc
@@ -0,0 +1,49 @@
+##
+#SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+!if $(BUILD_SHELL) == TRUE
+
+!if $(TOOL_CHAIN_TAG) != "XCODE5"
+  ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf {
+
+  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
+  }
+  ShellPkg/DynamicCommand/HttpDynamicCommand/HttpDynamicCommand.inf {
+
+  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
+  }
+  
ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicyDynamicCommand.inf
 {
+
+  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
+  }
+  OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.inf {
+
+  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
+  }
+!endif
+
+  ShellPkg/Application/Shell/Shell.inf {
+
+  
ShellCommandLib|ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.inf
+  
NULL|ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.inf
+  
NULL|ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.inf
+  
NULL|ShellPkg/Library/UefiShellLevel3CommandsLib/UefiShellLevel3CommandsLib.inf
+  
NULL|ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.inf
+  
NULL|ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf
+  
NULL|ShellPkg/Library/UefiShellInstall1CommandsLib/UefiShellInstall1CommandsLib.inf
+  
NULL|ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.inf
+!if $(NETWORK_IP6_ENABLE) == TRUE
+  
NULL|ShellPkg/Library/UefiShellNetwork2CommandsLib/UefiShellNetwork2CommandsLib.inf
+!endif
+  
HandleParsingLib|ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.inf
+  PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf
+  
BcfgCommandLib|ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.inf
+
+
+  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0xFF
+  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
+  gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|8000
+  }
+
+!endif
diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index bf4c7906c460..043b0a7a67e0 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -956,48 +956,7 @@ [Components]
   MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf
   MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf
 
-!if $(TOOL_CHAIN_TAG) != "XCODE5" && $(BUILD_SHELL) == TRUE
-  ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf {
-
-  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
-  }
-  ShellPkg/DynamicCommand/HttpDynamicCommand/HttpDynamicCommand.inf {
-
-  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
-  }
-  
ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicyDynamicCommand.inf
 {
-
-  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
-  }
-  OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.inf {
-
-  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
-  }
-!endif
-!if $(BUILD_SHELL) == TRUE
-  ShellPkg/Application/Shell/Shell.inf {
-
-  
ShellCommandLib|ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.inf
-  
NULL|ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellLevel3CommandsLib/UefiShellLevel3CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellInstall1CommandsLib/UefiShellInstall1CommandsLib.inf
-  
NULL|ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.inf
-!if $(NETWORK_IP6_ENABLE) == TRUE
-  
NULL|ShellPkg/Library/UefiShellNetwork2CommandsLib/UefiShellNetwork2CommandsLib.inf
-!endif
-  
HandleParsingLib|ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.inf
-  PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf
-  
BcfgCommandLib|ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.inf
-
-
-  

[edk2-devel] [PATCH v3 04/12] OvmfPkg: Shell*.inc: allow building without network support

2024-02-22 Thread Gerd Hoffmann
Add NETWORK_ENABLE conditionals for the components
which need network support.

Signed-off-by: Gerd Hoffmann 
Reviewed-by: Laszlo Ersek 
Acked-by: Jiewen Yao 
---
 OvmfPkg/Include/Dsc/ShellComponents.dsc.inc | 6 ++
 OvmfPkg/Include/Fdf/ShellDxe.fdf.inc| 2 ++
 2 files changed, 8 insertions(+)

diff --git a/OvmfPkg/Include/Dsc/ShellComponents.dsc.inc 
b/OvmfPkg/Include/Dsc/ShellComponents.dsc.inc
index 1a3a349a9de5..4075688e416d 100644
--- a/OvmfPkg/Include/Dsc/ShellComponents.dsc.inc
+++ b/OvmfPkg/Include/Dsc/ShellComponents.dsc.inc
@@ -5,6 +5,7 @@
 !if $(BUILD_SHELL) == TRUE
 
 !if $(TOOL_CHAIN_TAG) != "XCODE5"
+!if $(NETWORK_ENABLE) == TRUE
   ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf {
 
   gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
@@ -13,6 +14,7 @@
 
   gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
   }
+!endif
   
ShellPkg/DynamicCommand/VariablePolicyDynamicCommand/VariablePolicyDynamicCommand.inf
 {
 
   gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
@@ -32,9 +34,13 @@
   
NULL|ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.inf
   
NULL|ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf
   
NULL|ShellPkg/Library/UefiShellInstall1CommandsLib/UefiShellInstall1CommandsLib.inf
+!if $(NETWORK_ENABLE) == TRUE
+!if $(NETWORK_IP4_ENABLE) == TRUE
   
NULL|ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.inf
+!endif
 !if $(NETWORK_IP6_ENABLE) == TRUE
   
NULL|ShellPkg/Library/UefiShellNetwork2CommandsLib/UefiShellNetwork2CommandsLib.inf
+!endif
 !endif
   
HandleParsingLib|ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.inf
   PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf
diff --git a/OvmfPkg/Include/Fdf/ShellDxe.fdf.inc 
b/OvmfPkg/Include/Fdf/ShellDxe.fdf.inc
index 0935f06fa368..6536c30c5413 100644
--- a/OvmfPkg/Include/Fdf/ShellDxe.fdf.inc
+++ b/OvmfPkg/Include/Fdf/ShellDxe.fdf.inc
@@ -5,8 +5,10 @@
 !if $(BUILD_SHELL) == TRUE
 
 !if $(TOOL_CHAIN_TAG) != "XCODE5"
+!if $(NETWORK_ENABLE) == TRUE
 INF  ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf
 INF  ShellPkg/DynamicCommand/HttpDynamicCommand/HttpDynamicCommand.inf
+!endif
 INF  OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.inf
 !endif
 
-- 
2.43.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115785): https://edk2.groups.io/g/devel/message/115785
Mute This Topic: https://groups.io/mt/104505806/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3 02/12] OvmfPkg: add ShellLibs.dsc.inc

2024-02-22 Thread Gerd Hoffmann
Move EFI Shell libraries from OvmfPkgX64.dsc to
the new ShellComponents.dsc.inc include file.

Signed-off-by: Gerd Hoffmann 
Reviewed-by: Laszlo Ersek 
Acked-by: Jiewen Yao 
---
 OvmfPkg/Include/Dsc/ShellLibs.dsc.inc | 10 ++
 OvmfPkg/OvmfPkgX64.dsc|  4 +---
 2 files changed, 11 insertions(+), 3 deletions(-)
 create mode 100644 OvmfPkg/Include/Dsc/ShellLibs.dsc.inc

diff --git a/OvmfPkg/Include/Dsc/ShellLibs.dsc.inc 
b/OvmfPkg/Include/Dsc/ShellLibs.dsc.inc
new file mode 100644
index ..f4551ec84aeb
--- /dev/null
+++ b/OvmfPkg/Include/Dsc/ShellLibs.dsc.inc
@@ -0,0 +1,10 @@
+##
+#SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+!if $(BUILD_SHELL) == TRUE
+
+[LibraryClasses]
+  ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf
+
+!endif
diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index 043b0a7a67e0..56c920168d25 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -258,9 +258,6 @@ [LibraryClasses]
   TlsLib|CryptoPkg/Library/TlsLib/TlsLib.inf
 !endif
 
-!if $(BUILD_SHELL) == TRUE
-  ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf
-!endif
   ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf
 
   
S3BootScriptLib|MdeModulePkg/Library/PiDxeS3BootScriptLib/DxeS3BootScriptLib.inf
@@ -268,6 +265,7 @@ [LibraryClasses]
   
OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf
 
 !include OvmfPkg/Include/Dsc/OvmfTpmLibs.dsc.inc
+!include OvmfPkg/Include/Dsc/ShellLibs.dsc.inc
 
 [LibraryClasses.common]
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
-- 
2.43.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115784): https://edk2.groups.io/g/devel/message/115784
Mute This Topic: https://groups.io/mt/104505805/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3 03/12] OvmfPkg: add ShellDxe.fdf.inc

2024-02-22 Thread Gerd Hoffmann
Move EFI Shell firmware volume files to
the new ShellDxe.fdf.inc file.

Signed-off-by: Gerd Hoffmann 
Reviewed-by: Laszlo Ersek 
Acked-by: Jiewen Yao 
---
 OvmfPkg/OvmfPkgX64.fdf   | 11 ++-
 OvmfPkg/Include/Fdf/ShellDxe.fdf.inc | 14 ++
 2 files changed, 16 insertions(+), 9 deletions(-)
 create mode 100644 OvmfPkg/Include/Fdf/ShellDxe.fdf.inc

diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf
index f47ab1727e4c..eb3fb90cb8b6 100644
--- a/OvmfPkg/OvmfPkgX64.fdf
+++ b/OvmfPkg/OvmfPkgX64.fdf
@@ -319,15 +319,6 @@ [FV.DXEFV]
 INF  MdeModulePkg/Universal/Disk/UdfDxe/UdfDxe.inf
 INF  OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf
 
-!if $(BUILD_SHELL) == TRUE && $(TOOL_CHAIN_TAG) != "XCODE5"
-INF  ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf
-INF  ShellPkg/DynamicCommand/HttpDynamicCommand/HttpDynamicCommand.inf
-INF  OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.inf
-!endif
-!if $(BUILD_SHELL) == TRUE
-INF  ShellPkg/Application/Shell/Shell.inf
-!endif
-
 INF MdeModulePkg/Logo/LogoDxe.inf
 
 INF OvmfPkg/TdxDxe/TdxDxe.inf
@@ -402,6 +393,8 @@ [FV.DXEFV]
 #
 !include OvmfPkg/Include/Fdf/OvmfTpmDxe.fdf.inc
 
+!include OvmfPkg/Include/Fdf/ShellDxe.fdf.inc
+
 

 
 [FV.FVMAIN_COMPACT]
diff --git a/OvmfPkg/Include/Fdf/ShellDxe.fdf.inc 
b/OvmfPkg/Include/Fdf/ShellDxe.fdf.inc
new file mode 100644
index ..0935f06fa368
--- /dev/null
+++ b/OvmfPkg/Include/Fdf/ShellDxe.fdf.inc
@@ -0,0 +1,14 @@
+##
+#SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+!if $(BUILD_SHELL) == TRUE
+
+!if $(TOOL_CHAIN_TAG) != "XCODE5"
+INF  ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf
+INF  ShellPkg/DynamicCommand/HttpDynamicCommand/HttpDynamicCommand.inf
+INF  OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.inf
+!endif
+
+INF  ShellPkg/Application/Shell/Shell.inf
+!endif
-- 
2.43.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115786): https://edk2.groups.io/g/devel/message/115786
Mute This Topic: https://groups.io/mt/104505807/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v3 00/12] OvmfPkg: tweak shell builds

2024-02-22 Thread Gerd Hoffmann
- Create include files to reduce duplication.
- Fix varpolicy command.
- Little CI tweak.

v3:
 - pick up review and ack tags.
 - no functional changes.
v2:
 - do not move ShellCEntryLib to include file.
 - refine network config conditionals.
 - improve some commit messages.
 - add patch to drop the shell from secure boot builds.

Gerd Hoffmann (12):
  OvmfPkg: add ShellComponents.dsc.inc
  OvmfPkg: add ShellLibs.dsc.inc
  OvmfPkg: add ShellDxe.fdf.inc
  OvmfPkg: Shell*.inc: allow building without network support
  OvmfPkg: ShellDxe.fdf.inc: add VariablePolicyDynamicCommand to FV
  OvmfPkg: switch OvmfPkgIa32 to new shell include files
  OvmfPkg: switch OvmfPkgIa32X64 to new shell include files
  OvmfPkg: switch AmdSevX64 to new shell include files
  OvmfPkg: switch IntelTdxX64 to new shell include files
  OvmfPkg: switch MicrovmX64 to new shell include files
  OvmfPkg/CI: copy shell to virtual drive
  OvmfPkg: only add shell to FV in case secure boot is disabled

 OvmfPkg/Include/Dsc/ShellComponents.dsc.inc | 55 +
 OvmfPkg/Include/Dsc/ShellLibs.dsc.inc   | 10 
 OvmfPkg/AmdSev/AmdSevX64.dsc| 30 +--
 OvmfPkg/IntelTdx/IntelTdxX64.dsc| 32 ++--
 OvmfPkg/Microvm/MicrovmX64.dsc  | 49 +++---
 OvmfPkg/OvmfPkgIa32.dsc | 47 +-
 OvmfPkg/OvmfPkgIa32X64.dsc  | 47 +-
 OvmfPkg/OvmfPkgX64.dsc  | 47 +-
 OvmfPkg/AmdSev/AmdSevX64.fdf|  8 +--
 OvmfPkg/IntelTdx/IntelTdxX64.fdf|  9 +---
 OvmfPkg/Microvm/MicrovmX64.fdf  |  9 +---
 OvmfPkg/OvmfPkgIa32.fdf | 11 +
 OvmfPkg/OvmfPkgIa32X64.fdf  | 11 +
 OvmfPkg/OvmfPkgX64.fdf  | 11 +
 OvmfPkg/Include/Fdf/ShellDxe.fdf.inc| 17 +++
 OvmfPkg/PlatformCI/PlatformBuildLib.py  | 12 -
 16 files changed, 124 insertions(+), 281 deletions(-)
 create mode 100644 OvmfPkg/Include/Dsc/ShellComponents.dsc.inc
 create mode 100644 OvmfPkg/Include/Dsc/ShellLibs.dsc.inc
 create mode 100644 OvmfPkg/Include/Fdf/ShellDxe.fdf.inc

-- 
2.43.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115782): https://edk2.groups.io/g/devel/message/115782
Mute This Topic: https://groups.io/mt/104505803/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




Re: [edk2-devel] [PATCH 2/6] RedfishPkg: implement Redfish HTTP protocol

2024-02-22 Thread Nickle Wang via groups.io
Thanks for catching this typo, Abner. Version 2 patch is sent.

Regards,
Nickle

> -Original Message-
> From: Chang, Abner 
> Sent: Wednesday, February 21, 2024 9:52 AM
> To: Nickle Wang ; devel@edk2.groups.io
> Cc: Igor Kulchytskyy ; Nick Ramirez 
> Subject: RE: [PATCH 2/6] RedfishPkg: implement Redfish HTTP protocol
>
> External email: Use caution opening links or attachments
>
>
> [AMD Official Use Only - General]
>
> One comment below.
>
> > -Original Message-
> > From: Nickle Wang 
> > Sent: Tuesday, February 20, 2024 2:41 PM
> > To: devel@edk2.groups.io
> > Cc: Igor Kulchytskyy ; Chang, Abner
> > ; Nick Ramirez 
> > Subject: [PATCH 2/6] RedfishPkg: implement Redfish HTTP protocol
> >
> > Caution: This message originated from an External Source. Use proper caution
> > when opening attachments, clicking links, or responding.
> >
> >
> > implement Redfish HTTP protocol driver.
> >
> > Signed-off-by: Nickle Wang 
> > Co-authored-by: Igor Kulchytskyy 
> > Cc: Abner Chang 
> > Cc: Igor Kulchytskyy 
> > Cc: Nick Ramirez 
> > ---
> >  RedfishPkg/RedfishPkg.dec |7 +-
> >  RedfishPkg/RedfishComponents.dsc.inc  |3 +-
> >  RedfishPkg/RedfishPkg.dsc |2 +
> >  RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.inf  |   73 +
> >  RedfishPkg/RedfishHttpDxe/RedfishHttpData.h   |  256 
> >  RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.h|   44 +
> >  .../RedfishHttpDxe/RedfishHttpOperation.h |   76 +
> >  RedfishPkg/RedfishHttpDxe/RedfishHttpData.c   |  667 
> >  RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.c| 1344
> > +
> >  .../RedfishHttpDxe/RedfishHttpOperation.c |  693 +
> >  RedfishPkg/Redfish.fdf.inc|3 +-
> >  11 files changed, 3164 insertions(+), 4 deletions(-)
> >  create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.inf
> >  create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpData.h
> >  create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.h
> >  create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpOperation.h
> >  create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpData.c
> >  create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.c
> >  create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpOperation.c
> >
> > diff --git a/RedfishPkg/RedfishPkg.dec b/RedfishPkg/RedfishPkg.dec
> > index 9b424efdf3..114f8d2ad8 100644
> > --- a/RedfishPkg/RedfishPkg.dec
> > +++ b/RedfishPkg/RedfishPkg.dec
> > @@ -157,8 +157,11 @@
> ># set to EFI_REST_EX_PROTOCOL.
> >#
> >
> > gEfiRedfishPkgTokenSpaceGuid.PcdRedfishSendReceiveTimeout|5000|UINT3
> > 2|0x1009
> > -  ## This is used to enable HTTP content encoding on Redfish communication.
> > -
> > gEfiRedfishPkgTokenSpaceGuid.PcdRedfishServiceContentEncoding|TRUE|BO
> > OLEAN|0x100A
> > +  #
> > +  # This PCD string is introduced for platform developer to set the 
> > encoding
> > method supported by BMC Redfish.
> > +  # Currently only "None" and "gzip" are supported.
> > +  #
> > +
> > gEfiRedfishPkgTokenSpaceGuid.PcdRedfishServiceContentEncoding|"None"|V
> > OID*|0x100A
> >#
> ># Use below PCDs to control Redfhs HTTP protocol.
> >#
> > diff --git a/RedfishPkg/RedfishComponents.dsc.inc
> > b/RedfishPkg/RedfishComponents.dsc.inc
> > index 464ffc8606..d6c5b73d7f 100644
> > --- a/RedfishPkg/RedfishComponents.dsc.inc
> > +++ b/RedfishPkg/RedfishComponents.dsc.inc
> > @@ -7,7 +7,7 @@
> >  # "RedfishDefines.dsc.inc".
> >  #
> >  # (C) Copyright 2020-2021 Hewlett Packard Enterprise Development LP
> > -# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights
> > reserved.
> > +# Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights
> > reserved.
> >  #
> >  #SPDX-License-Identifier: BSD-2-Clause-Patent
> >  #
> > @@ -28,4 +28,5 @@
> >RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.inf
> >RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigDxe.inf
> >MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
> > +  RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.inf
> >  !endif
> > diff --git a/RedfishPkg/RedfishPkg.dsc b/RedfishPkg/RedfishPkg.dsc
> > index 25ed193182..5849e7cf9e 100644
> > --- a/RedfishPkg/RedfishPkg.dsc
> > +++ b/RedfishPkg/RedfishPkg.dsc
> > @@ -45,6 +45,8 @@
> >
> > UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesL
> > ib.inf
> >
> > RedfishPlatformCredentialLib|RedfishPkg/Library/PlatformCredentialLibNull/
> > PlatformCredentialLibNull.inf
> >
> > RedfishContentCodingLib|RedfishPkg/Library/RedfishContentCodingLibNull/
> > RedfishContentCodingLibNull.inf
> > +
> > ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeR
> > eportStatusCodeLib.inf
> > +  SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf
> >
> ># NULL instance of IPMI related library.
> >IpmiLib|MdeModulePkg/Library/BaseIpmiLibNull/BaseIpmiLibNull.inf
> > diff --git 

Re: [edk2-devel] [PATCH 6/6] RedfishPkg/RedfishCrtLib: fix unresolved external symbol issue

2024-02-22 Thread Nickle Wang via groups.io
Hi Abner,

Please check v2 patch. I add the source location of MathFtol.c

Thanks,
Nickle

> -Original Message-
> From: Chang, Abner 
> Sent: Wednesday, February 21, 2024 10:10 AM
> To: Nickle Wang ; devel@edk2.groups.io
> Cc: Igor Kulchytskyy ; Nick Ramirez 
> Subject: RE: [PATCH 6/6] RedfishPkg/RedfishCrtLib: fix unresolved external
> symbol issue
> 
> External email: Use caution opening links or attachments
> 
> 
> [AMD Official Use Only - General]
> 
> > -Original Message-
> > From: Nickle Wang 
> > Sent: Tuesday, February 20, 2024 2:42 PM
> > To: devel@edk2.groups.io
> > Cc: Chang, Abner ; Igor Kulchytskyy
> > ; Nick Ramirez 
> > Subject: [PATCH 6/6] RedfishPkg/RedfishCrtLib: fix unresolved external
> > symbol issue
> >
> > Caution: This message originated from an External Source. Use proper
> > caution when opening attachments, clicking links, or responding.
> >
> >
> > -Fix below compiler error reported in edk2 CI.
> > ERROR - Linker #2001 from JsonLib.lib(load.obj) : unresolved external
> > symbol __ftol2 -The file MathFtol.c is copied from IntrinsicLib in
> > CryptoPkg.
> > -Add MathFtol.c to EccCheck IgnoreFiles.
> >
> > Signed-off-by: Nickle Wang 
> > Cc: Abner Chang 
> > Cc: Igor Kulchytskyy 
> > Cc: Nick Ramirez 
> > ---
> >  .../RedfishCrtLib/RedfishCrtLib.inf   |  7 +++-
> >  .../RedfishCrtLib/Ia32/MathFtol.c | 37 +++
> >  RedfishPkg/RedfishPkg.ci.yaml |  2 +
> >  3 files changed, 45 insertions(+), 1 deletion(-)  create mode 100644
> > RedfishPkg/PrivateLibrary/RedfishCrtLib/Ia32/MathFtol.c
> >
> > diff --git a/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf
> > b/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf
> > index 6ff5dba75c..3a5e309d1a 100644
> > --- a/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf
> > +++ b/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf
> > @@ -3,6 +3,7 @@
> >  #
> >  # Copyright (c) 2019, Intel Corporation. All rights reserved.  #
> > (C) Copyright 2020 Hewlett Packard Enterprise Development LP
> > +# Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights
> > reserved.
> >  #
> >  #SPDX-License-Identifier: BSD-2-Clause-Patent
> >  #
> > @@ -23,6 +24,9 @@
> >  [Sources]
> >RedfishCrtLib.c
> >
> > +[Sources.IA32]
> > +  Ia32/MathFtol.c   | MSFT
> > +
> >  [LibraryClasses]
> >BaseLib
> >SortLib
> > @@ -35,4 +39,5 @@
> >MdeModulePkg/MdeModulePkg.dec
> >RedfishPkg/RedfishPkg.dec
> >
> > -
> > +[BuildOptions]
> > +  MSFT:*_*_IA32_CC_FLAGS = /GL-
> > diff --git a/RedfishPkg/PrivateLibrary/RedfishCrtLib/Ia32/MathFtol.c
> > b/RedfishPkg/PrivateLibrary/RedfishCrtLib/Ia32/MathFtol.c
> > new file mode 100644
> > index 00..adfe249b1d
> > --- /dev/null
> > +++ b/RedfishPkg/PrivateLibrary/RedfishCrtLib/Ia32/MathFtol.c
> > @@ -0,0 +1,37 @@
> > +/** @file
> 
> Hi Nickle,
> Could you please add the information here after @file about where this file 
> or the
> source code come from, such as the location of original file?
> Thanks
> Abner
> 
> 
> > +  64-bit Math Worker Function.
> > +  The 32-bit versions of C compiler generate calls to library
> > + routines  to handle 64-bit math. These functions use non-standard
> > + calling
> > conventions.
> > +
> > +Copyright (c) 2019, Intel Corporation. All rights reserved.
> > +SPDX-License-Identifier: BSD-2-Clause-Patent
> > +
> > +**/
> > +
> > +/*
> > + * Floating point to integer conversion.
> > + */
> > +__declspec(naked) void
> > +_ftol2 (
> > +  void
> > +  )
> > +{
> > +  _asm {
> > +fistp qword ptr [esp-8]
> > +mov   edx, [esp-4]
> > +mov   eax, [esp-8]
> > +ret
> > +  }
> > +}
> > +
> > +__declspec(naked) void
> > +_ftol2_sse (
> > +  void
> > +  )
> > +{
> > +  _asm {
> > +fistp dword ptr [esp-4]
> > +mov   eax,[esp-4]
> > +ret
> > +  }
> > +}
> > diff --git a/RedfishPkg/RedfishPkg.ci.yaml
> > b/RedfishPkg/RedfishPkg.ci.yaml index 69b6bf39f5..b95e8bfdc7 100644
> > --- a/RedfishPkg/RedfishPkg.ci.yaml
> > +++ b/RedfishPkg/RedfishPkg.ci.yaml
> > @@ -2,6 +2,7 @@
> >  # CI configuration for NetworkPkg
> >  #
> >  # (C) Copyright 2021 Hewlett Packard Enterprise Development LP
> > +# Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights
> > reserved.
> >  # SPDX-License-Identifier: BSD-2-Clause-Patent  ##  { @@ -38,6 +39,7
> > @@
> >  "PrivateInclude/Crt/string.h",
> >  "PrivateInclude/Crt/time.h",
> >  "PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c",
> > +"PrivateLibrary/RedfishCrtLib/Ia32/MathFtol.c",
> >  "Include/Library/RedfishCrtLib.h",
> >  ##
> >  ## For jansson library open source
> > --
> > 2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115780): https://edk2.groups.io/g/devel/message/115780
Mute This Topic: https://groups.io/mt/104463409/21656
Group Owner: devel+ow...@edk2.groups.io

[edk2-devel] [PATCH v2 5/6] RedfishPkg/RedfishDebugLib: use RedfishHttpLib

2024-02-22 Thread Nickle Wang via groups.io
Remove RedfishLib and use RedfishHttpLib for debug printing
Redfish response data.

Signed-off-by: Nickle Wang 
Cc: Abner Chang 
Cc: Igor Kulchytskyy 
Cc: Nick Ramirez 
Reviewed-by: Abner Chang 
---
 RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.inf | 4 ++--
 RedfishPkg/Include/Library/RedfishDebugLib.h   | 2 +-
 RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.c   | 1 +
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.inf 
b/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.inf
index 048d27c6dc..d468bb213b 100644
--- a/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.inf
+++ b/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.inf
@@ -1,7 +1,7 @@
 ## @file
 #  INF file for Redfish debug library.
 #
-#  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+#  Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights 
reserved.
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -32,7 +32,7 @@
   DebugLib
   JsonLib
   MemoryAllocationLib
-  RedfishLib
+  RedfishHttpLib
   UefiLib
 
 [Depex]
diff --git a/RedfishPkg/Include/Library/RedfishDebugLib.h 
b/RedfishPkg/Include/Library/RedfishDebugLib.h
index 3430cf1d14..ad7a697586 100644
--- a/RedfishPkg/Include/Library/RedfishDebugLib.h
+++ b/RedfishPkg/Include/Library/RedfishDebugLib.h
@@ -11,9 +11,9 @@
 #define REDFISH_DEBUG_LIB_H_
 
 #include 
+#include 
 #include 
 #include 
-#include 
 
 #include 
 
diff --git a/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.c 
b/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.c
index 3728f51213..8b0425b8c3 100644
--- a/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.c
+++ b/RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #ifndef IS_EMPTY_STRING
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115779): https://edk2.groups.io/g/devel/message/115779
Mute This Topic: https://groups.io/mt/104505408/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v2 6/6] RedfishPkg/RedfishCrtLib: fix unresolved external symbol issue

2024-02-22 Thread Nickle Wang via groups.io
-Fix below compiler error reported in edk2 CI.
ERROR - Linker #2001 from JsonLib.lib(load.obj) : unresolved external
symbol __ftol2
-The file MathFtol.c is copied from IntrinsicLib in CryptoPkg.
-Add MathFtol.c to EccCheck IgnoreFiles.

Signed-off-by: Nickle Wang 
Cc: Abner Chang 
Cc: Igor Kulchytskyy 
Cc: Nick Ramirez 
---
 .../RedfishCrtLib/RedfishCrtLib.inf   |  7 +++-
 .../RedfishCrtLib/Ia32/MathFtol.c | 37 +++
 RedfishPkg/RedfishPkg.ci.yaml |  2 +
 3 files changed, 45 insertions(+), 1 deletion(-)
 create mode 100644 RedfishPkg/PrivateLibrary/RedfishCrtLib/Ia32/MathFtol.c

diff --git a/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf 
b/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf
index 6ff5dba75c..3a5e309d1a 100644
--- a/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf
+++ b/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.inf
@@ -3,6 +3,7 @@
 #
 # Copyright (c) 2019, Intel Corporation. All rights reserved.
 # (C) Copyright 2020 Hewlett Packard Enterprise Development LP
+# Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 #
 #SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -23,6 +24,9 @@
 [Sources]
   RedfishCrtLib.c
 
+[Sources.IA32]
+  Ia32/MathFtol.c   | MSFT
+
 [LibraryClasses]
   BaseLib
   SortLib
@@ -35,4 +39,5 @@
   MdeModulePkg/MdeModulePkg.dec
   RedfishPkg/RedfishPkg.dec
 
-
+[BuildOptions]
+  MSFT:*_*_IA32_CC_FLAGS = /GL-
diff --git a/RedfishPkg/PrivateLibrary/RedfishCrtLib/Ia32/MathFtol.c 
b/RedfishPkg/PrivateLibrary/RedfishCrtLib/Ia32/MathFtol.c
new file mode 100644
index 00..e49f00eaf5
--- /dev/null
+++ b/RedfishPkg/PrivateLibrary/RedfishCrtLib/Ia32/MathFtol.c
@@ -0,0 +1,37 @@
+/** @file This file is copied from 
CryptoPkg/Library/IntrinsicLib/Ia32/MathFtol.c
+  64-bit Math Worker Function.
+  The 32-bit versions of C compiler generate calls to library routines
+  to handle 64-bit math. These functions use non-standard calling conventions.
+
+Copyright (c) 2019, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+/*
+ * Floating point to integer conversion.
+ */
+__declspec(naked) void
+_ftol2 (
+  void
+  )
+{
+  _asm {
+fistp qword ptr [esp-8]
+mov   edx, [esp-4]
+mov   eax, [esp-8]
+ret
+  }
+}
+
+__declspec(naked) void
+_ftol2_sse (
+  void
+  )
+{
+  _asm {
+fistp dword ptr [esp-4]
+mov   eax,[esp-4]
+ret
+  }
+}
diff --git a/RedfishPkg/RedfishPkg.ci.yaml b/RedfishPkg/RedfishPkg.ci.yaml
index 69b6bf39f5..b95e8bfdc7 100644
--- a/RedfishPkg/RedfishPkg.ci.yaml
+++ b/RedfishPkg/RedfishPkg.ci.yaml
@@ -2,6 +2,7 @@
 # CI configuration for NetworkPkg
 #
 # (C) Copyright 2021 Hewlett Packard Enterprise Development LP
+# Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 ##
 {
@@ -38,6 +39,7 @@
 "PrivateInclude/Crt/string.h",
 "PrivateInclude/Crt/time.h",
 "PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c",
+"PrivateLibrary/RedfishCrtLib/Ia32/MathFtol.c",
 "Include/Library/RedfishCrtLib.h",
 ##
 ## For jansson library open source
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115778): https://edk2.groups.io/g/devel/message/115778
Mute This Topic: https://groups.io/mt/104505407/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v2 3/6] RedfishPkg: introduce RedfishHttpLib

2024-02-22 Thread Nickle Wang via groups.io
RedfishHttpLib is a wrapper library for Redfish feature drivers to
call Redfish HTTP Protocol easily.

Signed-off-by: Nickle Wang 
Cc: Abner Chang 
Cc: Igor Kulchytskyy 
Cc: Nick Ramirez 
Reviewed-by: Abner Chang 
---
 RedfishPkg/RedfishPkg.dec |   5 +
 RedfishPkg/RedfishLibs.dsc.inc|   3 +-
 RedfishPkg/RedfishPkg.dsc |   3 +-
 .../Library/RedfishHttpLib/RedfishHttpLib.inf |  43 ++
 RedfishPkg/Include/Library/RedfishHttpLib.h   | 326 ++
 .../Library/RedfishHttpLib/RedfishHttpLib.c   | 585 ++
 6 files changed, 963 insertions(+), 2 deletions(-)
 create mode 100644 RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.inf
 create mode 100644 RedfishPkg/Include/Library/RedfishHttpLib.h
 create mode 100644 RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.c

diff --git a/RedfishPkg/RedfishPkg.dec b/RedfishPkg/RedfishPkg.dec
index 114f8d2ad8..1a9c9ed7bc 100644
--- a/RedfishPkg/RedfishPkg.dec
+++ b/RedfishPkg/RedfishPkg.dec
@@ -69,6 +69,11 @@
   #
   RedfishPlatformConfigLib|Include/Library/RedfishPlatformConfigLib.h
 
+  ##  @libraryclass  Provides the library functions to access Redfish HTTP
+  #   protocol.
+  #
+  RedfishHttpLib|Include/Library/RedfishHttpLib.h
+
 [LibraryClasses.Common.Private]
   ##  @libraryclass  Provides the private C runtime library functions.
   #   CRT library is currently used by edk2 JsonLib (open source
diff --git a/RedfishPkg/RedfishLibs.dsc.inc b/RedfishPkg/RedfishLibs.dsc.inc
index 5426957da8..55846aaa9d 100644
--- a/RedfishPkg/RedfishLibs.dsc.inc
+++ b/RedfishPkg/RedfishLibs.dsc.inc
@@ -6,7 +6,7 @@
 # of EDKII network library classes.
 #
 # (C) Copyright 2021 Hewlett Packard Enterprise Development LP
-# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+# Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights 
reserved.
 #
 #SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -21,5 +21,6 @@
   
RedfishPlatformCredentialLib|RedfishPkg/Library/RedfishPlatformCredentialIpmiLib/RedfishPlatformCredentialIpmiLib.inf
   HiiUtilityLib|RedfishPkg/Library/HiiUtilityLib/HiiUtilityLib.inf
   
RedfishPlatformConfigLib|RedfishPkg/Library/RedfishPlatformConfigLib/RedfishPlatformConfigLib.inf
+  RedfishHttpLib|RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.inf
 !endif
 
diff --git a/RedfishPkg/RedfishPkg.dsc b/RedfishPkg/RedfishPkg.dsc
index 5849e7cf9e..b0150043a9 100644
--- a/RedfishPkg/RedfishPkg.dsc
+++ b/RedfishPkg/RedfishPkg.dsc
@@ -4,7 +4,7 @@
 # Copyright (c) 2019 - 2021, Intel Corporation. All rights reserved.
 # (C) Copyright 2021 Hewlett-Packard Enterprise Development LP.
 # Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
-# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+# Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights 
reserved.
 #
 #SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -74,5 +74,6 @@
   RedfishPkg/Library/RedfishDebugLib/RedfishDebugLib.inf
   RedfishPkg/Library/HiiUtilityLib/HiiUtilityLib.inf
   RedfishPkg/Library/RedfishPlatformConfigLib/RedfishPlatformConfigLib.inf
+  RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.inf
 
   !include RedfishPkg/Redfish.dsc.inc
diff --git a/RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.inf 
b/RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.inf
new file mode 100644
index 00..fd53b8c2ed
--- /dev/null
+++ b/RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.inf
@@ -0,0 +1,43 @@
+## @file
+#  Redfish HTTP library is wrapper library for application to call Redfish
+#  HTTP protocol easily.
+#
+#  Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights 
reserved.
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION= 0x00010006
+  BASE_NAME  = RedfishHttpLib
+  FILE_GUID  = 62855D9B-441B-436B-9CA6-B7FEB7ABF54E
+  MODULE_TYPE= DXE_DRIVER
+  VERSION_STRING = 1.0
+  LIBRARY_CLASS  = RedfishHttpLib| DXE_DRIVER UEFI_DRIVER
+  CONSTRUCTOR= RedfishHttpConstructor
+
+#
+#  VALID_ARCHITECTURES   = IA32 X64 EBC
+#
+
+[Sources]
+  RedfishHttpLib.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  RedfishPkg/RedfishPkg.dec
+
+[LibraryClasses]
+  BaseLib
+  DebugLib
+  UefiLib
+  UefiBootServicesTableLib
+
+[Protocols]
+  gEdkIIRedfishHttpProtocolGuid   ## CONSUMES ##
+
+[depex]
+  TRUE
+
diff --git a/RedfishPkg/Include/Library/RedfishHttpLib.h 
b/RedfishPkg/Include/Library/RedfishHttpLib.h
new file mode 100644
index 00..b07a46993b
--- /dev/null
+++ b/RedfishPkg/Include/Library/RedfishHttpLib.h
@@ -0,0 +1,326 @@
+/** @file
+  This file defines the Redfish HTTP library interface.
+
+  Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights 
reserved.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef 

[edk2-devel] [PATCH v2 2/6] RedfishPkg: implement Redfish HTTP protocol

2024-02-22 Thread Nickle Wang via groups.io
implement Redfish HTTP protocol driver.

Signed-off-by: Nickle Wang 
Co-authored-by: Igor Kulchytskyy 
Cc: Abner Chang 
Cc: Igor Kulchytskyy 
Cc: Nick Ramirez 
---
 RedfishPkg/RedfishPkg.dec |7 +-
 RedfishPkg/RedfishComponents.dsc.inc  |3 +-
 RedfishPkg/RedfishPkg.dsc |2 +
 RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.inf  |   73 +
 RedfishPkg/RedfishHttpDxe/RedfishHttpData.h   |  256 
 RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.h|   44 +
 .../RedfishHttpDxe/RedfishHttpOperation.h |   76 +
 RedfishPkg/RedfishHttpDxe/RedfishHttpData.c   |  667 
 RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.c| 1344 +
 .../RedfishHttpDxe/RedfishHttpOperation.c |  693 +
 RedfishPkg/Redfish.fdf.inc|3 +-
 11 files changed, 3164 insertions(+), 4 deletions(-)
 create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.inf
 create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpData.h
 create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.h
 create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpOperation.h
 create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpData.c
 create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.c
 create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpOperation.c

diff --git a/RedfishPkg/RedfishPkg.dec b/RedfishPkg/RedfishPkg.dec
index 9b424efdf3..114f8d2ad8 100644
--- a/RedfishPkg/RedfishPkg.dec
+++ b/RedfishPkg/RedfishPkg.dec
@@ -157,8 +157,11 @@
   # set to EFI_REST_EX_PROTOCOL.
   #
   
gEfiRedfishPkgTokenSpaceGuid.PcdRedfishSendReceiveTimeout|5000|UINT32|0x1009
-  ## This is used to enable HTTP content encoding on Redfish communication.
-  
gEfiRedfishPkgTokenSpaceGuid.PcdRedfishServiceContentEncoding|TRUE|BOOLEAN|0x100A
+  #
+  # This PCD string is introduced for platform developer to set the encoding 
method supported by BMC Redfish.
+  # Currently only "None" and "gzip" are supported.
+  #
+  
gEfiRedfishPkgTokenSpaceGuid.PcdRedfishServiceContentEncoding|"None"|VOID*|0x100A
   #
   # Use below PCDs to control Redfhs HTTP protocol.
   #
diff --git a/RedfishPkg/RedfishComponents.dsc.inc 
b/RedfishPkg/RedfishComponents.dsc.inc
index 464ffc8606..d6c5b73d7f 100644
--- a/RedfishPkg/RedfishComponents.dsc.inc
+++ b/RedfishPkg/RedfishComponents.dsc.inc
@@ -7,7 +7,7 @@
 # "RedfishDefines.dsc.inc".
 #
 # (C) Copyright 2020-2021 Hewlett Packard Enterprise Development LP
-# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+# Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights 
reserved.
 #
 #SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -28,4 +28,5 @@
   RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.inf
   RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigDxe.inf
   MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
+  RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.inf
 !endif
diff --git a/RedfishPkg/RedfishPkg.dsc b/RedfishPkg/RedfishPkg.dsc
index 25ed193182..5849e7cf9e 100644
--- a/RedfishPkg/RedfishPkg.dsc
+++ b/RedfishPkg/RedfishPkg.dsc
@@ -45,6 +45,8 @@
   
UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf
   
RedfishPlatformCredentialLib|RedfishPkg/Library/PlatformCredentialLibNull/PlatformCredentialLibNull.inf
   
RedfishContentCodingLib|RedfishPkg/Library/RedfishContentCodingLibNull/RedfishContentCodingLibNull.inf
+  
ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf
+  SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf
 
   # NULL instance of IPMI related library.
   IpmiLib|MdeModulePkg/Library/BaseIpmiLibNull/BaseIpmiLibNull.inf
diff --git a/RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.inf 
b/RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.inf
new file mode 100644
index 00..c7dfdffacf
--- /dev/null
+++ b/RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.inf
@@ -0,0 +1,73 @@
+## @file
+#  RedfishHttpDxe is the DXE driver which provides
+#  EdkIIRedfishHttpProtocol to EDK2 Redfish Feature
+#  drivers for HTTP operation.
+#
+#  Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights 
reserved.
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION= 0x0001000b
+  BASE_NAME  = RedfishHttpDxe
+  FILE_GUID  = 85ADB2F1-DA93-47D4-AF4F-3D920D9BD2C0
+  MODULE_TYPE= DXE_DRIVER
+  VERSION_STRING = 1.0
+  ENTRY_POINT= RedfishHttpEntryPoint
+  UNLOAD_IMAGE   = RedfishHttpDriverUnload
+
+#
+#  VALID_ARCHITECTURES   = IA32 X64 ARM AARCH64 RISCV64
+#
+
+[Sources]
+  RedfishHttpData.c
+  RedfishHttpData.h
+  RedfishHttpDxe.c
+  RedfishHttpDxe.h
+  RedfishHttpOperation.c
+  RedfishHttpOperation.h
+
+[Packages]
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  NetworkPkg/NetworkPkg.dec
+  RedfishPkg/RedfishPkg.dec
+

[edk2-devel] [PATCH v2 4/6] RedfishPkg/RedfishLib: include RedfishServiceData.h

2024-02-22 Thread Nickle Wang via groups.io
Redfish common structures are moved to RedfishServiceData.h. Remove
them from RedfishLib.h

Signed-off-by: Nickle Wang 
Cc: Abner Chang 
Cc: Igor Kulchytskyy 
Cc: Nick Ramirez 
Reviewed-by: Abner Chang 
---
 RedfishPkg/Include/Library/RedfishLib.h | 17 +
 1 file changed, 1 insertion(+), 16 deletions(-)

diff --git a/RedfishPkg/Include/Library/RedfishLib.h 
b/RedfishPkg/Include/Library/RedfishLib.h
index 8309a67c76..fb30ff68f6 100644
--- a/RedfishPkg/Include/Library/RedfishLib.h
+++ b/RedfishPkg/Include/Library/RedfishLib.h
@@ -70,6 +70,7 @@
 #ifndef REDFISH_LIB_H_
 #define REDFISH_LIB_H_
 
+#include 
 #include 
 
 #include 
@@ -78,22 +79,6 @@
 #define ODATA_TYPE_NAME_MAX_SIZE  128
 #define ODATA_TYPE_MAX_SIZE   128
 
-///
-/// Library class public defines
-///
-typedef  VOID  *REDFISH_SERVICE;
-typedef  VOID  *REDFISH_PAYLOAD;
-
-///
-/// Library class public structures/unions
-///
-typedef struct {
-  EFI_HTTP_STATUS_CODE*StatusCode;
-  UINTN   HeaderCount;
-  EFI_HTTP_HEADER *Headers;
-  REDFISH_PAYLOAD Payload;
-} REDFISH_RESPONSE;
-
 ///
 /// Odata type-name mapping structure.
 ///
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115775): https://edk2.groups.io/g/devel/message/115775
Mute This Topic: https://groups.io/mt/104505403/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-




[edk2-devel] [PATCH v2 1/6] RedfishPkg: introduce Redfish HTTP protocol

2024-02-22 Thread Nickle Wang via groups.io
Introduce Redfish HTTP protocol to improve Redfish performance
and communication stability between BIOS and Redfish service.
- Feature drivers often query same Redfish resource multiple
times for different purpose. Implement HTTP cache mechanism to
improve HTTP GET performance. "UseCache" parameter is provided
if application likes to send HTTP GET request to Redfish service
without using cache data.
- This driver will retire stale cache data automatically when
application modify Redfish resource at service side.
- PCD PcdHttpCacheDisabled is used to disable cache mechanism in
this driver for debugging purpose.
- PCD PcdRedfishServiceContentEncoding is used to enable content
encoding while sending data to Redfish service.
- Redfish HTTP protocol also implement retry mechanism to retry
HTTP request when BIOS receive unexpected response from Redfish service.
This function helps BIOS Redfish to finish its job as much as possible.
- PCDs are defined to control how many times BIOS will retry the
request and how many time BIOS will wait between retries.

Signed-off-by: Nickle Wang 
Co-authored-by: Igor Kulchytskyy 
Cc: Abner Chang 
Cc: Igor Kulchytskyy 
Cc: Nick Ramirez 
Reviewed-by: Abner Chang 
---
 RedfishPkg/RedfishPkg.dec |  24 +-
 .../Protocol/EdkIIRedfishHttpProtocol.h   | 308 ++
 RedfishPkg/Include/RedfishServiceData.h   |  43 +++
 3 files changed, 374 insertions(+), 1 deletion(-)
 create mode 100644 RedfishPkg/Include/Protocol/EdkIIRedfishHttpProtocol.h
 create mode 100644 RedfishPkg/Include/RedfishServiceData.h

diff --git a/RedfishPkg/RedfishPkg.dec b/RedfishPkg/RedfishPkg.dec
index 3ea9ff3ef7..9b424efdf3 100644
--- a/RedfishPkg/RedfishPkg.dec
+++ b/RedfishPkg/RedfishPkg.dec
@@ -4,7 +4,7 @@
 # Copyright (c) 2019, Intel Corporation. All rights reserved.
 # (C) Copyright 2021 Hewlett Packard Enterprise Development LP
 # Copyright (c) 2023, American Megatrends International LLC.
-# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+# Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights 
reserved.
 #
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 ##
@@ -93,6 +93,9 @@
   # Redfish Host Interface ready notification protocol
   gEdkIIRedfishHostInterfaceReadyProtocolGuid = { 0xC3F6D062, 0x3D38, 0x4EA4, 
{ 0x92, 0xB1, 0xE8, 0xF8, 0x02, 0x27, 0x63, 0xDF } }
 
+  ## Include/Protocol/EdkIIRedfishHttpProtocol.h
+  gEdkIIRedfishHttpProtocolGuid = { 0x58a0f47e, 0xf45f, 0x4d44, { 0x89, 0x5b, 
0x2a, 0xfe, 0xb0, 0x80, 0x15, 0xe2 } }
+
 [Guids]
   gEfiRedfishPkgTokenSpaceGuid  = { 0x4fdbccb7, 0xe829, 0x4b4c, { 0x88, 
0x87, 0xb2, 0x3f, 0xd7, 0x25, 0x4b, 0x85 }}
 
@@ -154,3 +157,22 @@
   # set to EFI_REST_EX_PROTOCOL.
   #
   
gEfiRedfishPkgTokenSpaceGuid.PcdRedfishSendReceiveTimeout|5000|UINT32|0x1009
+  ## This is used to enable HTTP content encoding on Redfish communication.
+  
gEfiRedfishPkgTokenSpaceGuid.PcdRedfishServiceContentEncoding|TRUE|BOOLEAN|0x100A
+  #
+  # Use below PCDs to control Redfhs HTTP protocol.
+  #
+  ## The number of retry when HTTP GET request failed. If the value is 0, 
there is no retry enabled.
+  gEfiRedfishPkgTokenSpaceGuid.PcdHttpGetRetry|0|UINT16|0x100B
+  ## The number of retry when HTTP PUT request failed. If the value is 0, 
there is no retry enabled.
+  gEfiRedfishPkgTokenSpaceGuid.PcdHttpPutRetry|0|UINT16|0x100C
+  ## The number of retry when HTTP PATCH request failed. If the value is 0, 
there is no retry enabled.
+  gEfiRedfishPkgTokenSpaceGuid.PcdHttpPatchRetry|0|UINT16|0x100D
+  ## The number of retry when HTTP POST request failed. If the value is 0, 
there is no retry enabled.
+  gEfiRedfishPkgTokenSpaceGuid.PcdHttpPostRetry|0|UINT16|0x100E
+  ## The number of retry when HTTP DELETE request failed. If the value is 0, 
there is no retry enabled.
+  gEfiRedfishPkgTokenSpaceGuid.PcdHttpDeleteRetry|0|UINT16|0x100F
+  ## The number of second to wait before driver retry HTTP request. If the 
value is 0, there is no wait before next retry.
+  gEfiRedfishPkgTokenSpaceGuid.PcdHttpRetryWaitInSecond|1|UINT16|0x1010
+  ## This is used to disable Redfish HTTP cache function and every request 
will be sent to Redfish service.
+  gEfiRedfishPkgTokenSpaceGuid.PcdHttpCacheDisabled|FALSE|BOOLEAN|0x1011
diff --git a/RedfishPkg/Include/Protocol/EdkIIRedfishHttpProtocol.h 
b/RedfishPkg/Include/Protocol/EdkIIRedfishHttpProtocol.h
new file mode 100644
index 00..fef365730d
--- /dev/null
+++ b/RedfishPkg/Include/Protocol/EdkIIRedfishHttpProtocol.h
@@ -0,0 +1,308 @@
+/** @file
+  This file defines the EDKII_REDFISH_HTTP_PROTOCOL interface.
+
+  Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights 
reserved.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef EDKII_REDFISH_HTTP_PROTOCOL_H_
+#define EDKII_REDFISH_HTTP_PROTOCOL_H_
+
+#include 
+#include 
+#include 
+
+typedef struct _EDKII_REDFISH_HTTP_PROTOCOL EDKII_REDFISH_HTTP_PROTOCOL;
+

[edk2-devel] [PATCH v2 0/6] Introduce Redfish http protocol

2024-02-22 Thread Nickle Wang via groups.io
v2: address review comments.
1) add comment to show the source file of MathFtol.c
2) update macro to follow file name in RedfishHttpOperation.h

This patch series introduce Redfish HTTP protocol to RedfishPkg. 
This is to improve Redfish performance and communication stability 
between BIOS and Redfish service. Two big functions are introduced:
1) HTTP cache mechanism is implemented to reduce the number of 
communiocation between BIOS and BMC. 
2) HTTP request retry mechanism is implemented to handle communication 
failure. With retry mechanism, Redfish feature driver can finish its job 
as best as possible.

Several libraries are updated to fix build issues. Pull request is created:
https://github.com/tianocore/edk2/pull/5348

Signed-off-by: Nickle Wang 
Cc: Abner Chang 
Cc: Igor Kulchytskyy 
Cc: Nick Ramirez 

Nickle Wang (6):
  RedfishPkg: introduce Redfish HTTP protocol
  RedfishPkg: implement Redfish HTTP protocol
  RedfishPkg: introduce RedfishHttpLib
  RedfishPkg/RedfishLib: include RedfishServiceData.h
  RedfishPkg/RedfishDebugLib: use RedfishHttpLib
  RedfishPkg/RedfishCrtLib: fix unresolved external symbol issue

 RedfishPkg/RedfishPkg.dec |   32 +-
 RedfishPkg/RedfishComponents.dsc.inc  |3 +-
 RedfishPkg/RedfishLibs.dsc.inc|3 +-
 RedfishPkg/RedfishPkg.dsc |5 +-
 .../RedfishDebugLib/RedfishDebugLib.inf   |4 +-
 .../Library/RedfishHttpLib/RedfishHttpLib.inf |   43 +
 .../RedfishCrtLib/RedfishCrtLib.inf   |7 +-
 RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.inf  |   73 +
 RedfishPkg/Include/Library/RedfishDebugLib.h  |2 +-
 RedfishPkg/Include/Library/RedfishHttpLib.h   |  326 
 RedfishPkg/Include/Library/RedfishLib.h   |   17 +-
 .../Protocol/EdkIIRedfishHttpProtocol.h   |  308 
 RedfishPkg/Include/RedfishServiceData.h   |   43 +
 RedfishPkg/RedfishHttpDxe/RedfishHttpData.h   |  256 
 RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.h|   44 +
 .../RedfishHttpDxe/RedfishHttpOperation.h |   76 +
 .../Library/RedfishDebugLib/RedfishDebugLib.c |1 +
 .../Library/RedfishHttpLib/RedfishHttpLib.c   |  585 +++
 .../RedfishCrtLib/Ia32/MathFtol.c |   37 +
 RedfishPkg/RedfishHttpDxe/RedfishHttpData.c   |  667 
 RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.c| 1344 +
 .../RedfishHttpDxe/RedfishHttpOperation.c |  693 +
 RedfishPkg/Redfish.fdf.inc|3 +-
 RedfishPkg/RedfishPkg.ci.yaml |2 +
 24 files changed, 4549 insertions(+), 25 deletions(-)
 create mode 100644 RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.inf
 create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.inf
 create mode 100644 RedfishPkg/Include/Library/RedfishHttpLib.h
 create mode 100644 RedfishPkg/Include/Protocol/EdkIIRedfishHttpProtocol.h
 create mode 100644 RedfishPkg/Include/RedfishServiceData.h
 create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpData.h
 create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.h
 create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpOperation.h
 create mode 100644 RedfishPkg/Library/RedfishHttpLib/RedfishHttpLib.c
 create mode 100644 RedfishPkg/PrivateLibrary/RedfishCrtLib/Ia32/MathFtol.c
 create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpData.c
 create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpDxe.c
 create mode 100644 RedfishPkg/RedfishHttpDxe/RedfishHttpOperation.c

-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115773): https://edk2.groups.io/g/devel/message/115773
Mute This Topic: https://groups.io/mt/104505401/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-