Re: [edk2-devel] [PATCH] uefi-sct/SctPkg: Remove gEfiFormBrowserExProtocolGuid

2020-07-14 Thread Irene Park
Hello Edhay,

There has been no response from Eric since June 22.
Do you have any concerns with this change?
It’s very straight forward as indicated in REF: 
https://bugzilla.tianocore.org/show_bug.cgi?id=2145.

Thank you,
Irene

From: Irene Park
Sent: Monday, July 6, 2020 12:48 PM
To: Jin, Eric ; devel@edk2.groups.io
Cc: G Edhaya Chandran 
Subject: RE: [edk2-devel] [PATCH] uefi-sct/SctPkg: Remove 
gEfiFormBrowserExProtocolGuid

Hello Eric,
Would you please kindly review this change?
Thank you,
Irene

From: G Edhaya Chandran 
mailto:edhaya.chand...@arm.com>>
Sent: Monday, June 22, 2020 3:06 PM
To: Jin, Eric mailto:eric@intel.com>>
Cc: Irene Park mailto:ip...@nvidia.com>>
Subject: RE: [edk2-devel] [PATCH] uefi-sct/SctPkg: Remove 
gEfiFormBrowserExProtocolGuid

External email: Use caution opening links or attachments

Hello Eric,

   Could you please review this change too.
Once complete, I will mainline it.

With Warm Regards,
Edhay


From: Irene Park mailto:ip...@nvidia.com>>
Sent: 23 June 2020 00:00
To: devel@edk2.groups.io; G Edhaya Chandran 
mailto:edhaya.chand...@arm.com>>
Subject: RE: [edk2-devel] [PATCH] uefi-sct/SctPkg: Remove 
gEfiFormBrowserExProtocolGuid

Hi Edhaya,
Thank you for the review.
By the way, I don’t see it got mainlined yet.
Do you mind to share when you’re going to pick it up ?
Thank you,
Irene

From: devel@edk2.groups.io 
mailto:devel@edk2.groups.io>> On Behalf Of G Edhaya 
Chandran
Sent: Friday, June 5, 2020 4:12 AM
To: Irene Park mailto:ip...@nvidia.com>>; 
devel@edk2.groups.io
Subject: Re: [edk2-devel] [PATCH] uefi-sct/SctPkg: Remove 
gEfiFormBrowserExProtocolGuid

External email: Use caution opening links or attachments


Reviewed-by: G Edhaya 
Chandranmailto:edhaya.chand...@arm.com>>

IMPORTANT NOTICE: The contents of this email and any attachments are 
confidential and may also be privileged. If you are not the intended recipient, 
please notify the sender immediately and do not disclose the contents to any 
other person, use it for any purpose, or store or copy the information in any 
medium. Thank you.

-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62594): https://edk2.groups.io/g/devel/message/62594
Mute This Topic: https://groups.io/mt/74529350/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH v10 45/46] UefiCpuPkg/MpInitLib: Prepare SEV-ES guest APs for OS use

2020-07-14 Thread Dong, Eric
Reviewed-by: Eric Dong 

> -Original Message-
> From: Tom Lendacky 
> Sent: Tuesday, July 14, 2020 10:38 PM
> To: devel@edk2.groups.io
> Cc: Brijesh Singh ; Ard Biesheuvel
> ; Dong, Eric ; Justen,
> Jordan L ; Laszlo Ersek ;
> Gao, Liming ; Kinney, Michael D
> ; Ni, Ray 
> Subject: [PATCH v10 45/46] UefiCpuPkg/MpInitLib: Prepare SEV-ES guest APs
> for OS use
> 
> From: Tom Lendacky 
> 
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198
> 
> Before UEFI transfers control to the OS, it must park the AP. This is done
> using the AsmRelocateApLoop function to transition into 32-bit non-paging
> mode. For an SEV-ES guest, a few additional things must be
> done:
>   - AsmRelocateApLoop must be updated to support SEV-ES. This means
> performing a VMGEXIT AP Reset Hold instead of an MWAIT or HLT loop.
>   - Since the AP must transition to real mode, a small routine is copied
> to the WakeupBuffer area. Since the WakeupBuffer will be used by
> the AP during OS booting, it must be placed in reserved memory.
> Additionally, the AP stack must be located where it can be accessed
> in real mode.
>   - Once the AP is in real mode it will transfer control to the
> destination specified by the OS in the SEV-ES AP Jump Table. The
> SEV-ES AP Jump Table address is saved by the hypervisor for the OS
> using the GHCB VMGEXIT AP Jump Table exit code.
> 
> Cc: Eric Dong 
> Cc: Ray Ni 
> Cc: Laszlo Ersek 
> Signed-off-by: Tom Lendacky 
> ---
>  UefiCpuPkg/Library/MpInitLib/MpLib.h  |   8 +-
>  UefiCpuPkg/Library/MpInitLib/DxeMpLib.c   |  54 +++-
>  UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm | 131
> --
>  3 files changed, 175 insertions(+), 18 deletions(-)
> 
> diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h
> b/UefiCpuPkg/Library/MpInitLib/MpLib.h
> index b1a9d99cb3eb..267aa5201c50 100644
> --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
> +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
> @@ -293,7 +293,8 @@ struct _CPU_MP_DATA {
>UINT64 GhcbBase;
>  };
> 
> -#define AP_RESET_STACK_SIZE 64
> +#define AP_SAFE_STACK_SIZE  128
> +#define AP_RESET_STACK_SIZE AP_SAFE_STACK_SIZE
> 
>  #pragma pack(1)
> 
> @@ -349,8 +350,11 @@ VOID
>IN BOOLEAN MwaitSupport,
>IN UINTN   ApTargetCState,
>IN UINTN   PmCodeSegment,
> +  IN UINTN   Pm16CodeSegment,
>IN UINTN   TopOfApStack,
> -  IN UINTN   NumberToFinish
> +  IN UINTN   NumberToFinish,
> +  IN UINTN   SevEsAPJumpTable,
> +  IN UINTN   WakeupBuffer
>);
> 
>  /**
> diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
> b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
> index 9115ff9e3e30..7165bcf3124a 100644
> --- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
> +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
> @@ -12,6 +12,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
> 
> @@ -85,6 +86,13 @@ GetWakeupBuffer (
>  {
>EFI_STATUS  Status;
>EFI_PHYSICAL_ADDRESSStartAddress;
> +  EFI_MEMORY_TYPE MemoryType;
> +
> +  if (PcdGetBool (PcdSevEsIsEnabled)) {
> +MemoryType = EfiReservedMemoryType;  } else {
> +MemoryType = EfiBootServicesData;
> +  }
> 
>//
>// Try to allocate buffer below 1M for waking vector.
> @@ -97,7 +105,7 @@ GetWakeupBuffer (
>StartAddress = 0x88000;
>Status = gBS->AllocatePages (
>AllocateMaxAddress,
> -  EfiBootServicesData,
> +  MemoryType,
>EFI_SIZE_TO_PAGES (WakeupBufferSize),
>
>);
> @@ -159,8 +167,10 @@ GetSevEsAPMemory (
>VOID
>)
>  {
> -  EFI_STATUSStatus;
> -  EFI_PHYSICAL_ADDRESS  StartAddress;
> +  EFI_STATUSStatus;
> +  EFI_PHYSICAL_ADDRESS  StartAddress;
> +  MSR_SEV_ES_GHCB_REGISTER  Msr;
> +  GHCB  *Ghcb;
> 
>//
>// Allocate 1 page for AP jump table page @@ -176,6 +186,16 @@
> GetSevEsAPMemory (
> 
>DEBUG ((DEBUG_INFO, "Dxe: SevEsAPMemory = %lx\n", (UINTN)
> StartAddress));
> 
> +  //
> +  // Save the SevEsAPMemory as the AP jump table.
> +  //
> +  Msr.GhcbPhysicalAddress = AsmReadMsr64 (MSR_SEV_ES_GHCB);  Ghcb
> =
> + Msr.Ghcb;
> +
> +  VmgInit (Ghcb);
> +  VmgExit (Ghcb, SVM_EXIT_AP_JUMP_TABLE, 0, (UINT64) (UINTN)
> + StartAddress);  VmgDone (Ghcb);
> +
>return (UINTN) StartAddress;
>  }
> 
> @@ -330,17 +350,26 @@ RelocateApLoop (
>BOOLEANMwaitSupport;
>ASM_RELOCATE_AP_LOOP   AsmRelocateApLoopFunc;
>UINTN  ProcessorNumber;
> +  UINTN  StackStart;
> 
>MpInitLibWhoAmI ();
>CpuMpData= GetCpuMpData ();
>MwaitSupport = IsMwaitSupport ();
> +  if (CpuMpData->SevEsIsEnabled) {
> +StackStart = CpuMpData->SevEsAPResetStackStart;
> +  } else {
> +StackStart = 

Re: [edk2-devel] [PATCH 1/6] SecurityPkg/TcgPpi: Add TcgPpi header file.

2020-07-14 Thread Bret Barkelew via groups.io
Since we’re working on early boot TCG interfaces, is this a good time to 
discuss a standard way to init the log with measurements made by the HW root of 
trust prior to Tcg2Pei? We were using a NULL lib and a registration pattern on 
the PEIM, but I’m open to other ideas, too. Thoughts?

- Bret

From: devel@edk2.groups.io  on behalf of Yao, Jiewen via 
groups.io 
Sent: Tuesday, July 14, 2020 10:08:30 PM
To: Zhang, Qi1 ; devel@edk2.groups.io 

Cc: Wang, Jian J 
Subject: [EXTERNAL] Re: [edk2-devel] [PATCH 1/6] SecurityPkg/TcgPpi: Add TcgPpi 
header file.

Thanks Qi.

I just thought one use case that a PEIM may already have a calculated hash  
(https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ftianocore%2Fedk2%2Fblob%2Fmaster%2FSecurityPkg%2FTcg%2FTcg2Pei%2FTcg2Pei.c%23L652data=02%7C01%7CBret.Barkelew%40microsoft.com%7Cbe2bb9ca3e0c4dd95a0a08d8287d21ec%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637303865193113145sdata=V3ofX%2Fvs6Pp%2Bc79cQx4iSB6K324Lyptqrj7FtvmDwsc%3Dreserved=0)
We may need add a flag to support this pre-hash use case. Such as:

> +(EFIAPI *EDKII_TCG_HASH_LOG_EXTEND_EVENT)(
>
> +  IN  EDKII_TCG_PPI *This,
>
> +  IN  UINT64   Flags,  // new field. BIT0 = 0 means 
> HashData is the data to be hashed; BIT0 = 1 means HashData is the pre-hash 
> digest.
>
> +  IN  UINT8 *HashData,
>
> +  IN  UINTN HashDataLen,
>
> +  IN  TCG_PCR_EVENT_HDR *NewEventHdr,
>
> +  IN  UINT8 *NewEventData
>
> +  );

> -Original Message-
> From: Zhang, Qi1 
> Sent: Tuesday, July 14, 2020 2:49 PM
> To: devel@edk2.groups.io
> Cc: Yao, Jiewen ; Wang, Jian J ;
> Zhang, Chao B 
> Subject: [PATCH 1/6] SecurityPkg/TcgPpi: Add TcgPpi header file.
>
> From: Jiewen Yao 
>
> REF: 
> https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2841data=02%7C01%7CBret.Barkelew%40microsoft.com%7Cbe2bb9ca3e0c4dd95a0a08d8287d21ec%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637303865193113145sdata=VgWc2LNPqJRlBisa%2Bvuqq2THVK62f66uzzqh4cle4Rs%3Dreserved=0
>
> Cc: Jiewen Yao 
> Cc: Jian J Wang 
> Cc: Chao Zhang 
> Signed-off-by: Jiewen Yao 
> ---
>  SecurityPkg/Include/Ppi/Tcg.h | 50 +++
>  1 file changed, 50 insertions(+)
>  create mode 100644 SecurityPkg/Include/Ppi/Tcg.h
>
> diff --git a/SecurityPkg/Include/Ppi/Tcg.h b/SecurityPkg/Include/Ppi/Tcg.h
> new file mode 100644
> index 00..4eacd57166
> --- /dev/null
> +++ b/SecurityPkg/Include/Ppi/Tcg.h
> @@ -0,0 +1,50 @@
> +/** @file
>
> +  TCG PPI services.
>
> +
>
> +Copyright (c) 2020, Intel Corporation. All rights reserved.
>
> +SPDX-License-Identifier: BSD-2-Clause-Patent
>
> +
>
> +**/
>
> +
>
> +#ifndef _TCG_PPI_H_
>
> +#define _TCG_PPI_H_
>
> +
>
> +#include 
>
> +
>
> +typedef struct _EDKII_TCG_PPI EDKII_TCG_PPI;
>
> +
>
> +/**
>
> +  Tpm measure and log data, and extend the measurement result into a specific
> PCR.
>
> +
>
> +  @param[in]  This  Indicates the calling context
>
> +  @param[in]  HashData  Physical address of the start of the data 
> buffer
>
> +to be hashed, extended, and logged.
>
> +  @param[in]  HashDataLen   The length, in bytes, of the buffer 
> referenced by
> HashData.
>
> +  @param[in]  NewEventHdr   Pointer to a TCG_PCR_EVENT_HDR data
> structure.
>
> +  @param[in]  NewEventData  Pointer to the new event data.
>
> +
>
> +  @retval EFI_SUCCESS   Operation completed successfully.
>
> +  @retval EFI_UNSUPPORTED   TPM device not available.
>
> +  @retval EFI_OUT_OF_RESOURCES  Out of memory.
>
> +  @retval EFI_DEVICE_ERROR  The operation was unsuccessful.
>
> +**/
>
> +typedef
>
> +EFI_STATUS
>
> +(EFIAPI *EDKII_TCG_HASH_LOG_EXTEND_EVENT)(
>
> +  IN  EDKII_TCG_PPI *This,
>
> +  IN  UINT8 *HashData,
>
> +  IN  UINTN HashDataLen,
>
> +  IN  TCG_PCR_EVENT_HDR *NewEventHdr,
>
> +  IN  UINT8 *NewEventData
>
> +  );
>
> +
>
> +///
>
> +/// The EFI_TCG Protocol abstracts TCG activity.
>
> +///
>
> +struct _EDKII_TCG_PPI {
>
> +  EDKII_TCG_HASH_LOG_EXTEND_EVENT HashLogExtendEvent;
>
> +};
>
> +
>
> +extern EFI_GUID gEdkiiTcgPpiGuid;
>
> +
>
> +#endif
>
> --
> 2.26.2.windows.1





-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62592): https://edk2.groups.io/g/devel/message/62592
Mute This Topic: https://groups.io/mt/75496422/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH v10 42/46] UefiCpuPkg: Allow AP booting under SEV-ES

2020-07-14 Thread Dong, Eric
Reviewed-by: Eric Dong 

> -Original Message-
> From: Tom Lendacky 
> Sent: Tuesday, July 14, 2020 10:38 PM
> To: devel@edk2.groups.io
> Cc: Brijesh Singh ; Ard Biesheuvel
> ; Dong, Eric ; Justen,
> Jordan L ; Laszlo Ersek ;
> Gao, Liming ; Kinney, Michael D
> ; Ni, Ray 
> Subject: [PATCH v10 42/46] UefiCpuPkg: Allow AP booting under SEV-ES
> 
> From: Tom Lendacky 
> 
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198
> 
> Typically, an AP is booted using the INIT-SIPI-SIPI sequence. This sequence is
> intercepted by the hypervisor, which sets the AP's registers to the values
> requested by the sequence. At that point, the hypervisor can start the AP,
> which will then begin execution at the appropriate location.
> 
> Under SEV-ES, AP booting presents some challenges since the hypervisor is
> not allowed to alter the AP's register state. In this situation, we have to
> distinguish between the AP's first boot and AP's subsequent boots.
> 
> First boot:
>  Once the AP's register state has been defined (which is before the guest  is
> first booted) it cannot be altered. Should the hypervisor attempt to  alter 
> the
> register state, the change would be detected by the hardware  and the
> VMRUN instruction would fail. Given this, the first boot for the  AP is
> required to begin execution with this initial register state, which  is 
> typically
> the reset vector. This prevents the BSP from directing the  AP startup
> location through the INIT-SIPI-SIPI sequence.
> 
>  To work around this, the firmware will provide a build time reserved area
> that can be used as the initial IP value. The hypervisor can extract this
> location value by checking for the SEV-ES reset block GUID that must be
> located 48-bytes from the end of the firmware. The format of the SEV-ES
> reset block area is:
> 
>0x00 - 0x01 - SEV-ES Reset IP
>0x02 - 0x03 - SEV-ES Reset CS Segment Base[31:16]
>0x04 - 0x05 - Size of the SEV-ES reset block
>0x06 - 0x15 - SEV-ES Reset Block GUID
>(00f771de-1a7e-4fcb-890e-68c77e2fb44e)
> 
>The total size is 22 bytes. Any expansion to this block must be done
>by adding new values before existing values.
> 
>  The hypervisor will use the IP and CS values obtained from the SEV-ES  reset
> block to set as the AP's initial values. The CS Segment Base  represents the
> upper 16 bits of the CS segment base and must be left  shifted by 16 bits to
> form the complete CS segment base value.
> 
>  Before booting the AP for the first time, the BSP must initialize the  SEV-ES
> reset area. This consists of programming a FAR JMP instruction  to the
> contents of a memory location that is also located in the SEV-ES  reset area.
> The BSP must program the IP and CS values for the FAR JMP  based on values
> drived from the INIT-SIPI-SIPI sequence.
> 
> Subsequent boots:
>  Again, the hypervisor cannot alter the AP register state, so a method is
> required to take the AP out of halt state and redirect it to the desired  IP
> location. If it is determined that the AP is running in an SEV-ES  guest, then
> instead of calling CpuSleep(), a VMGEXIT is issued with the  AP Reset Hold
> exit code (0x8004). The hypervisor will put the AP in  a halt state, 
> waiting
> for an INIT-SIPI-SIPI sequence. Once the sequence  is recognized, the
> hypervisor will resume the AP. At this point the AP  must transition from the
> current 64-bit long mode down to 16-bit real  mode and begin executing at
> the derived location from the INIT-SIPI-SIPI  sequence.
> 
>  Another change is around the area of obtaining the (x2)APIC ID during AP
> startup. During AP startup, the AP can't take a #VC exception before the  AP
> has established a stack. However, the AP stack is set by using the  (x2)APIC 
> ID,
> which is obtained through CPUID instructions. A CPUID  instruction will cause
> a #VC, so a different method must be used. The  GHCB protocol supports a
> method to obtain CPUID information from the  hypervisor through the GHCB
> MSR. This method does not require a stack,  so it is used to obtain the
> necessary CPUID information to determine the  (x2)APIC ID.
> 
> The new 16-bit protected mode GDT entry is used in order to transition from
> 64-bit long mode down to 16-bit real mode.
> 
> A new assembler routine is created that takes the AP from 64-bit long mode
> to 16-bit real mode.  This is located under 1MB in memory and transitions
> from 64-bit long mode to 32-bit compatibility mode to 16-bit protected mode
> and finally 16-bit real mode.
> 
> Cc: Eric Dong 
> Cc: Ray Ni 
> Cc: Laszlo Ersek 
> Signed-off-by: Tom Lendacky 
> ---
>  UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf |   3 +
>  UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf |   3 +
>  UefiCpuPkg/Library/MpInitLib/MpLib.h  |  60 
>  UefiCpuPkg/Library/MpInitLib/DxeMpLib.c   |  70 +++-
>  UefiCpuPkg/Library/MpInitLib/MpLib.c  | 336 +-
>  UefiCpuPkg/Library/MpInitLib/PeiMpLib.c   

Re: [edk2-devel] [PATCH 1/6] SecurityPkg/TcgPpi: Add TcgPpi header file.

2020-07-14 Thread Yao, Jiewen
Thanks Qi.

I just thought one use case that a PEIM may already have a calculated hash  
(https://github.com/tianocore/edk2/blob/master/SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c#L652)
We may need add a flag to support this pre-hash use case. Such as:

> +(EFIAPI *EDKII_TCG_HASH_LOG_EXTEND_EVENT)(
> 
> +  IN  EDKII_TCG_PPI *This,
> 
> +  IN  UINT64   Flags,  // new field. BIT0 = 0 means 
> HashData is the data to be hashed; BIT0 = 1 means HashData is the pre-hash 
> digest.
> 
> +  IN  UINT8 *HashData,
> 
> +  IN  UINTN HashDataLen,
> 
> +  IN  TCG_PCR_EVENT_HDR *NewEventHdr,
> 
> +  IN  UINT8 *NewEventData
> 
> +  );

> -Original Message-
> From: Zhang, Qi1 
> Sent: Tuesday, July 14, 2020 2:49 PM
> To: devel@edk2.groups.io
> Cc: Yao, Jiewen ; Wang, Jian J ;
> Zhang, Chao B 
> Subject: [PATCH 1/6] SecurityPkg/TcgPpi: Add TcgPpi header file.
> 
> From: Jiewen Yao 
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2841
> 
> Cc: Jiewen Yao 
> Cc: Jian J Wang 
> Cc: Chao Zhang 
> Signed-off-by: Jiewen Yao 
> ---
>  SecurityPkg/Include/Ppi/Tcg.h | 50 +++
>  1 file changed, 50 insertions(+)
>  create mode 100644 SecurityPkg/Include/Ppi/Tcg.h
> 
> diff --git a/SecurityPkg/Include/Ppi/Tcg.h b/SecurityPkg/Include/Ppi/Tcg.h
> new file mode 100644
> index 00..4eacd57166
> --- /dev/null
> +++ b/SecurityPkg/Include/Ppi/Tcg.h
> @@ -0,0 +1,50 @@
> +/** @file
> 
> +  TCG PPI services.
> 
> +
> 
> +Copyright (c) 2020, Intel Corporation. All rights reserved.
> 
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +
> 
> +**/
> 
> +
> 
> +#ifndef _TCG_PPI_H_
> 
> +#define _TCG_PPI_H_
> 
> +
> 
> +#include 
> 
> +
> 
> +typedef struct _EDKII_TCG_PPI EDKII_TCG_PPI;
> 
> +
> 
> +/**
> 
> +  Tpm measure and log data, and extend the measurement result into a specific
> PCR.
> 
> +
> 
> +  @param[in]  This  Indicates the calling context
> 
> +  @param[in]  HashData  Physical address of the start of the data 
> buffer
> 
> +to be hashed, extended, and logged.
> 
> +  @param[in]  HashDataLen   The length, in bytes, of the buffer 
> referenced by
> HashData.
> 
> +  @param[in]  NewEventHdr   Pointer to a TCG_PCR_EVENT_HDR data
> structure.
> 
> +  @param[in]  NewEventData  Pointer to the new event data.
> 
> +
> 
> +  @retval EFI_SUCCESS   Operation completed successfully.
> 
> +  @retval EFI_UNSUPPORTED   TPM device not available.
> 
> +  @retval EFI_OUT_OF_RESOURCES  Out of memory.
> 
> +  @retval EFI_DEVICE_ERROR  The operation was unsuccessful.
> 
> +**/
> 
> +typedef
> 
> +EFI_STATUS
> 
> +(EFIAPI *EDKII_TCG_HASH_LOG_EXTEND_EVENT)(
> 
> +  IN  EDKII_TCG_PPI *This,
> 
> +  IN  UINT8 *HashData,
> 
> +  IN  UINTN HashDataLen,
> 
> +  IN  TCG_PCR_EVENT_HDR *NewEventHdr,
> 
> +  IN  UINT8 *NewEventData
> 
> +  );
> 
> +
> 
> +///
> 
> +/// The EFI_TCG Protocol abstracts TCG activity.
> 
> +///
> 
> +struct _EDKII_TCG_PPI {
> 
> +  EDKII_TCG_HASH_LOG_EXTEND_EVENT HashLogExtendEvent;
> 
> +};
> 
> +
> 
> +extern EFI_GUID gEdkiiTcgPpiGuid;
> 
> +
> 
> +#endif
> 
> --
> 2.26.2.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62590): https://edk2.groups.io/g/devel/message/62590
Mute This Topic: https://groups.io/mt/75496422/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH V1 1/2] MdePkg-IndustryStandard: CXL 1.1 Specification registers

2020-07-14 Thread Javeed, Ashraf
HI Mike,
My response inline.
Thanks for reviewing.

Ashraf

> -Original Message-
> From: Kinney, Michael D 
> Sent: Wednesday, July 15, 2020 9:14 AM
> To: devel@edk2.groups.io; Javeed, Ashraf ; Kinney,
> Michael D 
> Cc: Gao, Liming 
> Subject: RE: [edk2-devel] [PATCH V1 1/2] MdePkg-IndustryStandard: CXL 1.1
> Specification registers
> 
> Hi Arshaf,
> 
> 1) Pci.h - Copyright should be updated to 2020
Missed it, will change this.

> 2) Why is define for CXL_DVSEC_VENDOR_ID listed on its own
>in Cxl.h?  Was this added to the standard after the CXL 1.1
>specs?
Yes, it was added after the CXL1.1 specs was published. This is made backward 
compatible for the CXL1.1 DVSEC Vendor IDs, and also applicable for CXL 2.0 in 
future; hence I added this in the Cxl.h.
 
> 3) There are a few minor formatting issues with the field
>indentations for some of the bitfield structs.  One example:
> 
> typedef union {
>   struct {
>   UINT16 CacheEnable: 1; // bit 0
>   UINT16 IoEnable   : 1; // bit 1
>   UINT16 MemEnable  : 1; // bit 2
>   UINT16 CxlSyncBypassEnable: 1; // bit 3
>   UINT16 DriftBufferEnable  : 1; // bit 4
>   UINT16 Reserved   : 3; // bit 
> 5..7
>   UINT16 CxlCorrectableProtocolIdFramingError   : 1; // bit 8
>   UINT16 CxlUncorrectableProtocolIdFramingError : 1; // bit 9
>   UINT16 CxlUnexpectedProtocolIdDropped : 1; // bit 10
>   UINT16 Reserved2  : 5; // bit 
> 11..15
>   }Bits;
>   UINT16Uint16;
> } CXL_1_1_DVSEC_FLEX_BUS_PORT_STATUS;
> 
> Should be:
> 
> typedef union {
>   struct {
> UINT16 CacheEnable  : 1; // bit 0
> UINT16 IoEnable : 1; // bit 1
> UINT16 MemEnable: 1; // bit 2
> UINT16 CxlSyncBypassEnable  : 1; // bit 3
> UINT16 DriftBufferEnable: 1; // bit 4
> UINT16 Reserved : 3; // bit 
> 5..7
> UINT16 CxlCorrectableProtocolIdFramingError : 1; // bit 8
> UINT16 CxlUncorrectableProtocolIdFramingError   : 1; // bit 9
> UINT16 CxlUnexpectedProtocolIdDropped   : 1; // bit 10
> UINT16 Reserved2: 5; // bit 
> 11..15
>   }Bits;
>   UINT16Uint16;
> } CXL_1_1_DVSEC_FLEX_BUS_PORT_STATUS;
> 
Good catch, will fix, I used a Python script to generate these structures and 
happen to miss the indentation for the second level.

> 4) The following structure that provides a log looks a little odd
>because code that access the log array would have to use
>HeaderLog.HeaderLog[Index].
> 
> typedef struct {
>   CXL_1_1_UNCORRECTABLE_ERROR_STATUSHeaderLog[16];
> } CXL_HEADER_LOG;
> 
> typedef struct {
>   CXL_1_1_UNCORRECTABLE_ERROR_STATUS
> UncorrectableErrorStatus; // offset 0
>   CXL_1_1_UNCORRECTABLE_ERROR_MASK
> UncorrectableErrorMask;   // offset 4
>   CXL_1_1_UNCORRECTABLE_ERROR_SEVERITY
> UncorrectableErrorSeverity;   // offset 8
>   CXL_CORRECTABLE_ERROR_STATUS  
> CorrectableErrorStatus;
> // offset 12
>   CXL_CORRECTABLE_ERROR_MASK
> CorrectableErrorMask;
> // offset 16
>   CXL_ERROR_CAPABILITIES_AND_CONTROL
> ErrorCapabilitiesAndControl;  // offset 20
>   CXL_HEADER_LOGHeaderLog;
> // offset 24
> } CXL_1_1_RAS_CAPABILITY_STRUCTURE;
> 
> If this was changed to the following, it may be easier to use and understand:
> 
> typedef struct {
>   CXL_1_1_UNCORRECTABLE_ERROR_STATUS
> UncorrectableErrorStatus; // offset 0
>   CXL_1_1_UNCORRECTABLE_ERROR_MASK
> UncorrectableErrorMask;   // offset 4
>   CXL_1_1_UNCORRECTABLE_ERROR_SEVERITY
> UncorrectableErrorSeverity;   // offset 8
>   CXL_CORRECTABLE_ERROR_STATUS  
> CorrectableErrorStatus;
> // offset 12
>   CXL_CORRECTABLE_ERROR_MASK
> CorrectableErrorMask;
> // offset 16
>   CXL_ERROR_CAPABILITIES_AND_CONTROL
> ErrorCapabilitiesAndControl;  // offset 20
>   CXL_1_1_UNCORRECTABLE_ERROR_STATUSHeaderLog[16];
> // offset 24
> } CXL_1_1_RAS_CAPABILITY_STRUCTURE;
> 
Agree. Will change this appropriately.

> Thanks,
> 
> Mike
> 
> > -Original Message-
> > From: devel@edk2.groups.io  On Behalf Of Javeed,
> > Ashraf
> > Sent: Saturday, July 11, 2020 

Re: [edk2-devel] [PATCH] Using LLVM compiler set to build BaseTools in Linux

2020-07-14 Thread Yuwei Chen
Reviewed-by: Yuwei Chen

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of
> Zhiguang Liu
> Sent: Monday, July 6, 2020 2:38 PM
> To: devel@edk2.groups.io
> Cc: Feng, Bob C ; Gao, Liming 
> Subject: [edk2-devel] [PATCH] Using LLVM compiler set to build BaseTools in
> Linux
> 
> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2842
> 
> To use LLVM to build BaseTools, first set the CLANG_BIN environment value,
> and add "CXX=llvm" to choose LLVM compiler set when using make
> command.
> 
> Cc: Bob Feng 
> Cc: Liming Gao 
> 
> Signed-off-by: Zhiguang Liu 
> ---
>  BaseTools/Source/C/Makefiles/header.makefile   | 22
> --
>  BaseTools/Source/C/VfrCompile/GNUmakefile  |  6 --
>  BaseTools/Source/C/VfrCompile/Pccts/antlr/makefile |  4 
>  BaseTools/Source/C/VfrCompile/Pccts/dlg/makefile   |  4 
>  4 files changed, 32 insertions(+), 4 deletions(-)
> 
> diff --git a/BaseTools/Source/C/Makefiles/header.makefile
> b/BaseTools/Source/C/Makefiles/header.makefile
> index 4e9b36d98b..1c105ee7d4 100644
> --- a/BaseTools/Source/C/Makefiles/header.makefile
> +++ b/BaseTools/Source/C/Makefiles/header.makefile
> @@ -38,12 +38,19 @@ endif
>  CYGWIN:=$(findstring CYGWIN, $(shell uname -s)) LINUX:=$(findstring Linux,
> $(shell uname -s)) DARWIN:=$(findstring Darwin, $(shell uname -s))-+ifeq
> ($(CXX), llvm)+BUILD_CC ?= $(CLANG_BIN)clang+BUILD_CXX ?=
> $(CLANG_BIN)clang+++BUILD_AS ?= $(CLANG_BIN)clang+BUILD_AR ?=
> $(CLANG_BIN)llvm-ar+BUILD_LD ?= $(CLANG_BIN)llvm-ld+else BUILD_CC ?=
> gcc BUILD_CXX ?= g++ BUILD_AS ?= gcc BUILD_AR ?= ar BUILD_LD ?=
> ld+endif LINKER ?= $(BUILD_CC) ifeq ($(HOST_ARCH), IA32) ARCH_INCLUDE
> = -I $(MAKEROOT)/Include/Ia32/@@ -72,14 +79,25 @@ ifeq
> ($(DARWIN),Darwin)  BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing
> -Wall -Werror \ -Wno-deprecated-declarations -Wno-self-assign -Wno-
> unused-result -nostdlib -g else+ifeq ($(CXX), llvm)+BUILD_CFLAGS = -MD -
> fshort-wchar -fno-strict-aliasing -fwrapv \+-fno-delete-null-pointer-checks -
> Wall -Werror \+-Wno-deprecated-declarations -Wno-self-assign \+-Wno-
> unused-result -nostdlib -g+else BUILD_CFLAGS = -MD -fshort-wchar -fno-
> strict-aliasing -fwrapv \ -fno-delete-null-pointer-checks -Wall -Werror \ -
> Wno-deprecated-declarations -Wno-stringop-truncation -Wno-restrict \ -
> Wno-unused-result -nostdlib -g endif+endif+ifeq ($(CXX),
> llvm)+BUILD_LFLAGS =+BUILD_CXXFLAGS = -Wno-deprecated-register -
> Wno-unused-result+else BUILD_LFLAGS = BUILD_CXXFLAGS = -Wno-
> unused-result-+endif ifeq ($(HOST_ARCH), IA32) # # Snow Leopard  is a 32-
> bit and 64-bit environment. uname -m returns i386, but gcc defaultsdiff --git
> a/BaseTools/Source/C/VfrCompile/GNUmakefile
> b/BaseTools/Source/C/VfrCompile/GNUmakefile
> index 42e3d7da02..fc329944b9 100644
> --- a/BaseTools/Source/C/VfrCompile/GNUmakefile
> +++ b/BaseTools/Source/C/VfrCompile/GNUmakefile
> @@ -16,9 +16,11 @@ TOOL_INCLUDE = -I Pccts/h
>  #OBJECTS = VfrSyntax.o VfrServices.o DLGLexer.o EfiVfrParser.o
> ATokenBuffer.o DLexerBase.o AParser.o OBJECTS = AParser.o DLexerBase.o
> ATokenBuffer.o EfiVfrParser.o VfrLexer.o VfrSyntax.o \   VfrFormPkg.o
> VfrError.o VfrUtilityLib.o VfrCompiler.o-+ifeq ($(CXX), llvm)+VFR_CPPFLAGS
> = -Wno-deprecated-register -DPCCTS_USE_NAMESPACE_STD
> $(BUILD_CPPFLAGS)+else VFR_CPPFLAGS = -
> DPCCTS_USE_NAMESPACE_STD $(BUILD_CPPFLAGS)-+endif # keep
> BUILD_OPTFLAGS last VFR_CXXFLAGS = $(BUILD_OPTFLAGS) diff --git
> a/BaseTools/Source/C/VfrCompile/Pccts/antlr/makefile
> b/BaseTools/Source/C/VfrCompile/Pccts/antlr/makefile
> index 8f2cc78c59..559b1c99f1 100644
> --- a/BaseTools/Source/C/VfrCompile/Pccts/antlr/makefile
> +++ b/BaseTools/Source/C/VfrCompile/Pccts/antlr/makefile
> @@ -164,7 +164,11 @@ PCCTS_H=../h
>  # #   UNIX  (default) #+ifeq ($(CXX),
> llvm)+BUILD_CC?=$(CLANG_BIN)clang+else BUILD_CC?=gcc+endif COPT=-O
> ANTLR=${BIN_DIR}/antlr DLG=${BIN_DIR}/dlgdiff --git
> a/BaseTools/Source/C/VfrCompile/Pccts/dlg/makefile
> b/BaseTools/Source/C/VfrCompile/Pccts/dlg/makefile
> index b3a34d3b46..5a3561edec 100644
> --- a/BaseTools/Source/C/VfrCompile/Pccts/dlg/makefile
> +++ b/BaseTools/Source/C/VfrCompile/Pccts/dlg/makefile
> @@ -114,7 +114,11 @@ PCCTS_H=../h
>  # #   UNIX #+ifeq ($(CXX), llvm)+BUILD_CC?=$(CLANG_BIN)clang+else
> BUILD_CC?=cc+endif COPT=-O ANTLR=${BIN_DIR}/antlr
> DLG=${BIN_DIR}/dlg--
> 2.25.1.windows.1
> 
> 
> -=-=-=-=-=-=
> Groups.io Links: You receive all messages sent to this group.
> 
> View/Reply Online (#62063): https://edk2.groups.io/g/devel/message/62063
> Mute This Topic: https://groups.io/mt/75328235/4546272
> Group Owner: devel+ow...@edk2.groups.io
> Unsubscribe: https://edk2.groups.io/g/devel/unsub
> [yuwei.c...@intel.com] -=-=-=-=-=-=


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62588): https://edk2.groups.io/g/devel/message/62588
Mute This Topic: https://groups.io/mt/75328235/21656
Group Owner: 

Re: [EXTERNAL] [edk2-devel] [Patch v3 00/16] UnitTestFrameworkPkg: Enhancements and bug fixes

2020-07-14 Thread Bret Barkelew via groups.io
Can’t tell if I got them all. Just let me know if you’re missing any. Thanks!

- Bret

From: Michael D Kinney via 
groups.io
Sent: Friday, July 10, 2020 7:09 PM
To: devel@edk2.groups.io
Subject: [EXTERNAL] [edk2-devel] [Patch v3 00/16] UnitTestFrameworkPkg: 
Enhancements and bug fixes

Changes in V3
==
* Add UnitTestHostBaseLib class for the global variable that allows
  host based unit tests to hook and emulate some BaseLib services

Changes in V2
==
* Add UnitTestExpectAssertFailure() to UnitTestLib to simplify the macro
  UT_EXPECT_ASSERT_FAILURE() and provide better log messages.
* Expand UnitTestFrameworkPkg sample unit tests to cover test cases for the new
  UT_EXPECT_ASSERT_FAILURE() macro and all other UnitTestLib macros.
* Add failure type FAILURETYPE_EXPECTASSERT when the macro
  UT_EXPECT_ASSERT_FAILURE() does not detect an ASSERT().
* Move print of log messages to end of cleanup function to support log
  messages generated in a cleanup function.
* Update running of target-based tests to use SetJump()/LongJump()
  around prereq, cleanup, and unit test functions to match the behavior
  of host based tests using cmocka. This also requires all UnitTestLib
  Assert functions to generate error log message first and then call
  UnitTestFailure() where the LongJump() is made to make sure all log
  messages are added before the LongJump().

REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2797data=02%7C01%7Cbret.barkelew%40microsoft.com%7C85c2633c67ce49ad912208d8253f684a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637300301547515364sdata=uuTtY%2BtdCZvv4r6cCeBlydCmqftVVBuTwkg8TXtVqco%3Dreserved=0
REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2798data=02%7C01%7Cbret.barkelew%40microsoft.com%7C85c2633c67ce49ad912208d8253f684a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637300301547515364sdata=OZqCcWPq6GJ3QO3YQcAPV7r04u2xzJCwjDzg2QbW7Uc%3Dreserved=0
REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2799data=02%7C01%7Cbret.barkelew%40microsoft.com%7C85c2633c67ce49ad912208d8253f684a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637300301547515364sdata=%2BkvS3Ar5kX65TKkNy46hsNcGihYBHebpYguFJEXjVEg%3Dreserved=0
REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2800data=02%7C01%7Cbret.barkelew%40microsoft.com%7C85c2633c67ce49ad912208d8253f684a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637300301547515364sdata=Vxdm4iRHixD9FzJjGpIPAwZKgo6OKct1nxGfiU6ycv4%3Dreserved=0
REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2801data=02%7C01%7Cbret.barkelew%40microsoft.com%7C85c2633c67ce49ad912208d8253f684a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637300301547515364sdata=PkSMoe6u7y1yLFY%2BsvXVI0DRLvfWnCWRmPRN1L0G8wY%3Dreserved=0
REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2803data=02%7C01%7Cbret.barkelew%40microsoft.com%7C85c2633c67ce49ad912208d8253f684a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637300301547515364sdata=rRq%2ByS4%2FnUaA4hV8Rwfks16P3IGgePwDS1MuMYbaPXg%3Dreserved=0
REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2804data=02%7C01%7Cbret.barkelew%40microsoft.com%7C85c2633c67ce49ad912208d8253f684a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637300301547515364sdata=AQBJfetimL0OhXoNmLGOrlDmkz01RC0onv5OUR4Jl8k%3Dreserved=0
REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2805data=02%7C01%7Cbret.barkelew%40microsoft.com%7C85c2633c67ce49ad912208d8253f684a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637300301547515364sdata=%2B07i4x%2BTRHGq3SlQsDndfVJvuhqcno9EOWHD%2Ba36WVE%3Dreserved=0
REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2806data=02%7C01%7Cbret.barkelew%40microsoft.com%7C85c2633c67ce49ad912208d8253f684a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637300301547515364sdata=rrb2NdSxAxUHvUjS0D2Gh%2B0dbgQdU2JlPqtIfMvgTDE%3Dreserved=0

* Add Null base libraries for host based unit tests
* Add host based test version of BaseLib with hooks for services that use
  privileged instructions.
* Add new UT_EXPECT_ASSERT_FAILURE() macro to UnitTestLib class
* Enable source level debug of unit tests
* Increase stack size to 256KB for host based tests on Windows
* Update BaseTools to support NULL libs for HOST_APPLICATION modules
* Guarantee print log works even if unit test generates an exception
* Use filename instead of function name in target mode logs

Cc: Liming Gao liming@intel.com
Cc: Bob Feng 

Re: [EXTERNAL] [edk2-devel] [Patch v3 00/16] UnitTestFrameworkPkg: Enhancements and bug fixes

2020-07-14 Thread Bret Barkelew via groups.io
Reviewed-by: Bret Barkelew 


- Bret

From: Michael D Kinney via 
groups.io
Sent: Friday, July 10, 2020 7:09 PM
To: devel@edk2.groups.io
Subject: [EXTERNAL] [edk2-devel] [Patch v3 00/16] UnitTestFrameworkPkg: 
Enhancements and bug fixes

Changes in V3
==
* Add UnitTestHostBaseLib class for the global variable that allows
  host based unit tests to hook and emulate some BaseLib services

Changes in V2
==
* Add UnitTestExpectAssertFailure() to UnitTestLib to simplify the macro
  UT_EXPECT_ASSERT_FAILURE() and provide better log messages.
* Expand UnitTestFrameworkPkg sample unit tests to cover test cases for the new
  UT_EXPECT_ASSERT_FAILURE() macro and all other UnitTestLib macros.
* Add failure type FAILURETYPE_EXPECTASSERT when the macro
  UT_EXPECT_ASSERT_FAILURE() does not detect an ASSERT().
* Move print of log messages to end of cleanup function to support log
  messages generated in a cleanup function.
* Update running of target-based tests to use SetJump()/LongJump()
  around prereq, cleanup, and unit test functions to match the behavior
  of host based tests using cmocka. This also requires all UnitTestLib
  Assert functions to generate error log message first and then call
  UnitTestFailure() where the LongJump() is made to make sure all log
  messages are added before the LongJump().

REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2797data=02%7C01%7Cbret.barkelew%40microsoft.com%7C85c2633c67ce49ad912208d8253f684a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637300301547515364sdata=uuTtY%2BtdCZvv4r6cCeBlydCmqftVVBuTwkg8TXtVqco%3Dreserved=0
REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2798data=02%7C01%7Cbret.barkelew%40microsoft.com%7C85c2633c67ce49ad912208d8253f684a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637300301547515364sdata=OZqCcWPq6GJ3QO3YQcAPV7r04u2xzJCwjDzg2QbW7Uc%3Dreserved=0
REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2799data=02%7C01%7Cbret.barkelew%40microsoft.com%7C85c2633c67ce49ad912208d8253f684a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637300301547515364sdata=%2BkvS3Ar5kX65TKkNy46hsNcGihYBHebpYguFJEXjVEg%3Dreserved=0
REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2800data=02%7C01%7Cbret.barkelew%40microsoft.com%7C85c2633c67ce49ad912208d8253f684a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637300301547515364sdata=Vxdm4iRHixD9FzJjGpIPAwZKgo6OKct1nxGfiU6ycv4%3Dreserved=0
REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2801data=02%7C01%7Cbret.barkelew%40microsoft.com%7C85c2633c67ce49ad912208d8253f684a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637300301547515364sdata=PkSMoe6u7y1yLFY%2BsvXVI0DRLvfWnCWRmPRN1L0G8wY%3Dreserved=0
REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2803data=02%7C01%7Cbret.barkelew%40microsoft.com%7C85c2633c67ce49ad912208d8253f684a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637300301547515364sdata=rRq%2ByS4%2FnUaA4hV8Rwfks16P3IGgePwDS1MuMYbaPXg%3Dreserved=0
REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2804data=02%7C01%7Cbret.barkelew%40microsoft.com%7C85c2633c67ce49ad912208d8253f684a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637300301547515364sdata=AQBJfetimL0OhXoNmLGOrlDmkz01RC0onv5OUR4Jl8k%3Dreserved=0
REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2805data=02%7C01%7Cbret.barkelew%40microsoft.com%7C85c2633c67ce49ad912208d8253f684a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637300301547515364sdata=%2B07i4x%2BTRHGq3SlQsDndfVJvuhqcno9EOWHD%2Ba36WVE%3Dreserved=0
REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2806data=02%7C01%7Cbret.barkelew%40microsoft.com%7C85c2633c67ce49ad912208d8253f684a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637300301547515364sdata=rrb2NdSxAxUHvUjS0D2Gh%2B0dbgQdU2JlPqtIfMvgTDE%3Dreserved=0

* Add Null base libraries for host based unit tests
* Add host based test version of BaseLib with hooks for services that use
  privileged instructions.
* Add new UT_EXPECT_ASSERT_FAILURE() macro to UnitTestLib class
* Enable source level debug of unit tests
* Increase stack size to 256KB for host based tests on Windows
* Update BaseTools to support NULL libs for HOST_APPLICATION modules
* Guarantee print log works even if unit test generates an exception
* Use filename instead of function name in target mode logs

Cc: Liming Gao liming@intel.com
Cc: Bob Feng bob.c.f...@intel.com
Cc: Sean Brogan 

Re: [edk2-devel] [Patch v3 12/16] UnitTestFrameworkPkg/UnitTestLib: Add checks for ASSERT()

2020-07-14 Thread Bret Barkelew via groups.io
Reviewed-by: Bret Barkelew 


- Bret

From: Michael D Kinney via 
groups.io
Sent: Tuesday, July 14, 2020 9:26 AM
To: liming.gao; 
devel@edk2.groups.io; Kinney, Michael 
D
Cc: Sean Brogan; Bret 
Barkelew; Yao, 
Jiewen
Subject: [EXTERNAL] Re: [edk2-devel] [Patch v3 12/16] 
UnitTestFrameworkPkg/UnitTestLib: Add checks for ASSERT()

Liming,

I will fix that one issue in the INF comment block
when I push the commits.

Thanks,

Mike

> -Original Message-
> From: Gao, Liming 
> Sent: Monday, July 13, 2020 11:57 PM
> To: devel@edk2.groups.io; Kinney, Michael D
> 
> Cc: Sean Brogan ; Bret
> Barkelew ; Yao, Jiewen
> 
> Subject: RE: [edk2-devel] [Patch v3 12/16]
> UnitTestFrameworkPkg/UnitTestLib: Add checks for
> ASSERT()
>
> Mike:
>
> -Original Message-
> From: devel@edk2.groups.io  On
> Behalf Of Michael D Kinney
> Sent: 2020年7月11日 10:09
> To: devel@edk2.groups.io
> Cc: Sean Brogan ; Bret
> Barkelew ; Yao, Jiewen
> 
> Subject: [edk2-devel] [Patch v3 12/16]
> UnitTestFrameworkPkg/UnitTestLib: Add checks for
> ASSERT()
>
> REF: REF:
> https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2801data=02%7C01%7Cbret.barkelew%40microsoft.com%7C3b85c7dd72af42d6295508d82812a84a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637303407889843281sdata=5fA35uRcosAAp0%2B1RVFoCLsGzAaqvc92dmxSVrwDJsY%3Dreserved=0
>
> Add UnitTestDebugAssertLib that provides the
> UnitTestDebugAssert() service and the
> gUnitTestExpectAssertFailureJumpBuffer global variable.
> This NULL library is linked against all host and target
> unit test builds.  This guarantees that the
> UnitTestDebugAssert() service is available to link
> against all libraries and modules that use the DebugLib
> class.
>
> EDKII_UNIT_TEST_FRAMEWORK_ENABLED must always be defined
> when building unit tests so the behavior of the DebugLib
> ASSERT() macros can be adjusted to allow the unit test
> framework to catch an ASSERT() if it is triggered by a
> function under test.
>
> Cc: Sean Brogan 
> Cc: Bret Barkelew 
> Cc: Jiewen Yao 
> Signed-off-by: Michael D Kinney
> 
> ---
>  .../UnitTestDebugAssertLib.c  |  49
> +
>  .../UnitTestDebugAssertLib.inf|  31 +++
>  .../UnitTestDebugAssertLib.uni|  11 +
>  .../Library/UnitTestLib/Assert.c  | 203
> --
>  .../Library/UnitTestLib/AssertCmocka.c|  68
> ++
>  .../Library/UnitTestLib/RunTests.c|  23 +-
>  .../UnitTestResultReportLib.c |   3 +-
>  .../PrivateInclude/UnitTestFrameworkTypes.h   |   1 +
>  .../Test/UnitTestFrameworkPkgHostTest.dsc |   2 +-
>  UnitTestFrameworkPkg/UnitTestFrameworkPkg.dsc |   1 +
>  .../UnitTestFrameworkPkgTarget.dsc.inc|   6 +-
>  11 files changed, 328 insertions(+), 70 deletions(-)
> create mode 100644
> UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/Unit
> TestDebugAssertLib.c
>  create mode 100644
> UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/Unit
> TestDebugAssertLib.inf
>  create mode 100644
> UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/Unit
> TestDebugAssertLib.uni
>
> diff --git
> a/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/Un
> itTestDebugAssertLib.c
> b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/Un
> itTestDebugAssertLib.c
> new file mode 100644
> index 00..0a4001e182
> --- /dev/null
> +++
> b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/Un
> itTestDebugA
> +++ ssertLib.c
> @@ -0,0 +1,49 @@
> +/** @file
> +  Unit Test Debug Assert Library
> +
> +  Copyright (c) 2020, Intel Corporation. All rights
> reserved.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include 
> +#include 
> +#include 
> +
> +///
> +/// Point to jump buffer used with SetJump()/LongJump()
> to test if a
> +function /// under test generates an expected ASSERT()
> condition.
> +///
> +BASE_LIBRARY_JUMP_BUFFER
> *gUnitTestExpectAssertFailureJumpBuffer =
> +NULL;
> +
> +/**
> +  Unit test library replacement for DebugAssert() in
> DebugLib.
> +
> +  If FileName is NULL, then a  string of
> "(NULL) Filename" is printed.
> +  If Description is NULL, then a  string
> of "(NULL) Description" is printed.
> +
> +  @param  FileName The pointer to the name of the
> source file that generated the assert condition.
> +  @param  LineNumber   The line number in the source
> file that generated the assert condition
> +  @param  Description  The pointer to the description
> of the assert condition.
> +
> +**/
> +VOID
> +EFIAPI
> +UnitTestDebugAssert (
> +  IN CONST CHAR8  *FileName,
> +  IN UINTNLineNumber,
> +  IN CONST CHAR8  *Description
> +  )
> +{
> +  CHAR8  Message[256];
> +
> +  if 

Re: [edk2-devel] [EXTERNAL] [Patch v3 07/16] UnitTestFrameworkPkg: Enable source level debug for host tests

2020-07-14 Thread Bret Barkelew via groups.io
Reviewed-by: Bret Barkelew 


- Bret


From: Michael D Kinney 
Sent: Friday, July 10, 2020 7:08:55 PM
To: devel@edk2.groups.io 
Cc: Sean Brogan ; Bret Barkelew 
; Yao, Jiewen 
Subject: [EXTERNAL] [Patch v3 07/16] UnitTestFrameworkPkg: Enable source level 
debug for host tests

REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2804data=02%7C01%7CBret.Barkelew%40microsoft.com%7Cd31f0dcf6e6d4f80bd3008d8253f689e%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637300301550028840sdata=oNgc2S2JjPYyf0Hh%2FjS7EqunqyH4%2BB7nfWWZBDDGWIE%3Dreserved=0

Optionally enable a feature to support source level debug of a
host based unit test.  By default, this feature is disabled.
Exceptions are caught by the unit test framework and are
interpreted as a test failure.

When a unit test is under development, bugs may generate
exceptions or a unit test developer may want to trace the
execution of unit tests to debug some unexpected behavior.
Defining UNIT_TESTING_DEBUG in the DSC file or from the build
command line allows exceptions to be caught by the host OS
and allows the developer to debug their unit test under
development or debug the Unit Test Framework itself.

Cc: Sean Brogan 
Cc: Bret Barkelew 
Cc: Jiewen Yao 
Signed-off-by: Michael D Kinney 
---
 UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc | 5 +
 1 file changed, 5 insertions(+)

diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc 
b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc
index c22085fae1..c4e6e0e0a6 100644
--- a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc
+++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc
@@ -20,6 +20,11 @@ [LibraryClasses.common.HOST_APPLICATION]

 [BuildOptions]
   GCC:*_*_*_CC_FLAGS = -fno-pie
+!ifdef $(UNIT_TESTING_DEBUG)
+  MSFT:*_*_*_CC_FLAGS  = -D UNIT_TESTING_DEBUG=1
+  GCC:*_*_*_CC_FLAGS   = -D UNIT_TESTING_DEBUG=1
+  XCODE:*_*_*_CC_FLAGS = -D UNIT_TESTING_DEBUG=1
+!endif

 [BuildOptions.common.EDKII.HOST_APPLICATION]
   #
--
2.21.0.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62583): https://edk2.groups.io/g/devel/message/62583
Mute This Topic: https://groups.io/mt/75514383/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [EXTERNAL] [Patch v3 06/16] UnitTestFrameworkPkg: Use host libraries from MdePkg

2020-07-14 Thread Bret Barkelew via groups.io
Reviewed-by: Bret Barkelew 


- Bret


From: Michael D Kinney 
Sent: Friday, July 10, 2020 7:08:54 PM
To: devel@edk2.groups.io 
Cc: Sean Brogan ; Bret Barkelew 
; Yao, Jiewen 
Subject: [EXTERNAL] [Patch v3 06/16] UnitTestFrameworkPkg: Use host libraries 
from MdePkg

REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2800data=02%7C01%7CBret.Barkelew%40microsoft.com%7C12c2ebe65a74457d0b0508d8253f675b%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637300301533729524sdata=Ru4QTYif83gqk%2BWkzmCxTXm0N4Uyh3T%2BPrTh3vr0cCE%3Dreserved=0
REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2799data=02%7C01%7CBret.Barkelew%40microsoft.com%7C12c2ebe65a74457d0b0508d8253f675b%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637300301533729524sdata=eZtAdXCBsixYVZ6CrZ66vDEmDgZ2Dpuh4NwN1jGjgQI%3Dreserved=0
REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2798data=02%7C01%7CBret.Barkelew%40microsoft.com%7C12c2ebe65a74457d0b0508d8253f675b%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637300301533729524sdata=48f8BlgozfDlnYBiR1G2ng610xRQhsMjHdH4VZs3njs%3Dreserved=0

Update the default unit test library mappings to use the
library instances from the MdePkg that are safe for host
based unit tests.

Cc: Sean Brogan 
Cc: Bret Barkelew 
Cc: Jiewen Yao 
Signed-off-by: Michael D Kinney 
---
 UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc | 4 
 1 file changed, 4 insertions(+)

diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc 
b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc
index e954968efc..c22085fae1 100644
--- a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc
+++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc
@@ -9,6 +9,10 @@
 !include UnitTestFrameworkPkg/UnitTestFrameworkPkgTarget.dsc.inc

 [LibraryClasses.common.HOST_APPLICATION]
+  BaseLib|MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf
+  UnitTestHostBaseLib|MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf
+  CpuLib|MdePkg/Library/BaseCpuLibNull/BaseCpuLibNull.inf
+  
CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLibNull/BaseCacheMaintenanceLibNull.inf
   CmockaLib|UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf
   UnitTestLib|UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLibCmocka.inf
   DebugLib|UnitTestFrameworkPkg/Library/Posix/DebugLibPosix/DebugLibPosix.inf
--
2.21.0.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62586): https://edk2.groups.io/g/devel/message/62586
Mute This Topic: https://groups.io/mt/75514389/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [EXTERNAL] [Patch v3 10/16] UnitTestFrameworkPkg/UnitTestLib: Move print log into cleanup

2020-07-14 Thread Bret Barkelew via groups.io
Reviewed-by: Bret Barkelew 


- Bret

From: Michael D Kinney
Sent: Friday, July 10, 2020 7:09 PM
To: devel@edk2.groups.io
Cc: Sean Brogan; Bret 
Barkelew; Yao, 
Jiewen
Subject: [EXTERNAL] [Patch v3 10/16] UnitTestFrameworkPkg/UnitTestLib: Move 
print log into cleanup

REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2805data=02%7C01%7CBret.Barkelew%40microsoft.com%7C0e54105ccc5b453f790508d8253f690e%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637300301563150384sdata=OY4xwl9Ecv%2F0SJyzzqBUGNxTi1E%2F8Ax70I6jF2dA6cA%3Dreserved=0

If a unit test fails with an exception or an assert, then the
CmockaUnitTestFunctionRunner() is terminated and the logic
that follows the invocation of the unit test is skipped.  This
currently skips the logic that prints log messages.

Move the print of log messages to the end of the function
CmockaUnitTestTeardownFunctionRunner() that is guaranteed to
be executed when a unit test completes normally or is
terminated with an exception or an assert.

Cc: Sean Brogan 
Cc: Bret Barkelew 
Cc: Jiewen Yao 
Signed-off-by: Michael D Kinney 
---
 .../Library/UnitTestLib/RunTestsCmocka.c  | 33 +--
 1 file changed, 16 insertions(+), 17 deletions(-)

diff --git a/UnitTestFrameworkPkg/Library/UnitTestLib/RunTestsCmocka.c 
b/UnitTestFrameworkPkg/Library/UnitTestLib/RunTestsCmocka.c
index fb81cc9658..96aa4d9b13 100644
--- a/UnitTestFrameworkPkg/Library/UnitTestLib/RunTestsCmocka.c
+++ b/UnitTestFrameworkPkg/Library/UnitTestLib/RunTestsCmocka.c
@@ -53,21 +53,9 @@ CmockaUnitTestFunctionRunner (
 UnitTest->Result = UNIT_TEST_SKIPPED;
   } else {
 UnitTest->Result = UNIT_TEST_RUNNING;
-
 Framework->CurrentTest = UnitTest;
 UnitTest->Result = UnitTest->RunTest (UnitTest->Context);
 Framework->CurrentTest = NULL;
-
-// Print out the log messages - This is a partial solution as it
-// does not get the log into the XML.  Need cmocka changes to support
-// stdout and stderr in their xml format
-//
-if (UnitTest->Log != NULL) {
-  print_message("UnitTest: %s - %s\n", UnitTest->Name, 
UnitTest->Description);
-  print_message("Log Output Start\n");
-  print_message("%s", UnitTest->Log);
-  print_message("Log Output End\n");
-}
   }
 }

@@ -112,13 +100,24 @@ CmockaUnitTestTeardownFunctionRunner (
   Suite = (UNIT_TEST_SUITE *)(UnitTest->ParentSuite);
   Framework = (UNIT_TEST_FRAMEWORK *)(Suite->ParentFramework);

-  if (UnitTest->CleanUp == NULL) {
-return 0;
+  if (UnitTest->CleanUp != NULL) {
+Framework->CurrentTest = UnitTest;
+UnitTest->CleanUp (UnitTest->Context);
+Framework->CurrentTest = NULL;
+  }
+
+  //
+  // Print out the log messages - This is a partial solution as it
+  // does not get the log into the XML.  Need cmocka changes to support
+  // stdout and stderr in their xml format
+  //
+  if (UnitTest->Log != NULL) {
+print_message("UnitTest: %s - %s\n", UnitTest->Name, 
UnitTest->Description);
+print_message("Log Output Start\n");
+print_message("%s", UnitTest->Log);
+print_message("Log Output End\n");
   }

-  Framework->CurrentTest = UnitTest;
-  UnitTest->CleanUp (UnitTest->Context);
-  Framework->CurrentTest = NULL;
   //
   // Return 0 for success.  Non-zero for error.
   //
--
2.21.0.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62584): https://edk2.groups.io/g/devel/message/62584
Mute This Topic: https://groups.io/mt/75514386/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [EXTERNAL] [Patch v3 09/16] UnitTestFrameworkPkg: Change target mode DebugLib mapping

2020-07-14 Thread Bret Barkelew via groups.io
Reviewed-by: Bret Barkelew 


- Bret


From: Michael D Kinney 
Sent: Friday, July 10, 2020 7:08:57 PM
To: devel@edk2.groups.io 
Cc: Sean Brogan ; Bret Barkelew 
; Yao, Jiewen 
Subject: [EXTERNAL] [Patch v3 09/16] UnitTestFrameworkPkg: Change target mode 
DebugLib mapping

REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2801data=02%7C01%7CBret.Barkelew%40microsoft.com%7C51f924d3b7144be85fc608d8253f6879%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637300301550295393sdata=mOv%2FyMpj14WmxCmpAdtexIJRxcyL9nkWJMrAxmqTV70%3Dreserved=0

The default DebugLib for target mode was DebugLibNull.  This
library instance disables all ASSERT() and DEBUG() macros
which removes the ability to write unit tests that check for
ASSERT() behaviors.

The DebugLib is changed to PeiDxeDebugLibReportStatusCode.inf
that guarantees that DEBUG() and ASSERT() macros are active.  The
default ReportStatusCodeLib is set to BaseReportStatusCodeLibNull.inf
so no messages are sent to any devices preserving the DebugLibNull
behavior.

A platform specific unit test can always override these mappings
with a platform specific DebugLib.

Cc: Sean Brogan 
Cc: Bret Barkelew 
Cc: Jiewen Yao 
Signed-off-by: Michael D Kinney 
---
 UnitTestFrameworkPkg/UnitTestFrameworkPkgTarget.dsc.inc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkgTarget.dsc.inc 
b/UnitTestFrameworkPkg/UnitTestFrameworkPkgTarget.dsc.inc
index c29b056fca..0881278ab0 100644
--- a/UnitTestFrameworkPkg/UnitTestFrameworkPkgTarget.dsc.inc
+++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkgTarget.dsc.inc
@@ -16,7 +16,9 @@ [LibraryClasses]

   BaseLib|MdePkg/Library/BaseLib/BaseLib.inf
   BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
-  DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf
+  
DebugLib|MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf
+  
ReportStatusCodeLib|MdePkg/Library/BaseReportStatusCodeLibNull/BaseReportStatusCodeLibNull.inf
+  
DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf
   
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
   PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
   PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf
--
2.21.0.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62579): https://edk2.groups.io/g/devel/message/62579
Mute This Topic: https://groups.io/mt/75514379/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 00/16] UnitTestFrameworkPkg: Enhancements and bug fixes

2020-07-14 Thread Bret Barkelew via groups.io
Reviewed-by: Bret Barkelew 


- Bret


From: devel@edk2.groups.io  on behalf of Liming Gao via 
groups.io 
Sent: Monday, July 13, 2020 11:54:53 PM
To: devel@edk2.groups.io ; Kinney, Michael D 

Subject: [EXTERNAL] Re: [edk2-devel] [Patch v3 00/16] UnitTestFrameworkPkg: 
Enhancements and bug fixes

Mike:
 Thanks for your update. This patch set is good to me. Reviewed-by: Liming Gao 


Thanks
Liming
-Original Message-
From: devel@edk2.groups.io  On Behalf Of Michael D Kinney
Sent: 2020年7月11日 10:09
To: devel@edk2.groups.io
Subject: [edk2-devel] [Patch v3 00/16] UnitTestFrameworkPkg: Enhancements and 
bug fixes

Changes in V3
==
* Add UnitTestHostBaseLib class for the global variable that allows
  host based unit tests to hook and emulate some BaseLib services

Changes in V2
==
* Add UnitTestExpectAssertFailure() to UnitTestLib to simplify the macro
  UT_EXPECT_ASSERT_FAILURE() and provide better log messages.
* Expand UnitTestFrameworkPkg sample unit tests to cover test cases for the new
  UT_EXPECT_ASSERT_FAILURE() macro and all other UnitTestLib macros.
* Add failure type FAILURETYPE_EXPECTASSERT when the macro
  UT_EXPECT_ASSERT_FAILURE() does not detect an ASSERT().
* Move print of log messages to end of cleanup function to support log
  messages generated in a cleanup function.
* Update running of target-based tests to use SetJump()/LongJump()
  around prereq, cleanup, and unit test functions to match the behavior
  of host based tests using cmocka. This also requires all UnitTestLib
  Assert functions to generate error log message first and then call
  UnitTestFailure() where the LongJump() is made to make sure all log
  messages are added before the LongJump().

REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2797data=02%7C01%7CBret.Barkelew%40microsoft.com%7Cdb2bad178b6044d37e1208d827c2d38e%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637303065010616592sdata=Cvs4rSfp%2FUl15lR331i0WOqsz0X0XGYc9nPu%2FFu5Ce0%3Dreserved=0
REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2798data=02%7C01%7CBret.Barkelew%40microsoft.com%7Cdb2bad178b6044d37e1208d827c2d38e%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637303065010616592sdata=gKBdHVSP%2F3QmwmX%2FAhCjQcIC6BMU%2F8yx6BM03VYaugo%3Dreserved=0
REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2799data=02%7C01%7CBret.Barkelew%40microsoft.com%7Cdb2bad178b6044d37e1208d827c2d38e%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637303065010616592sdata=eBVwmQgDnQLCOKhIybCJ8nn9CU43aO3shuTlUSxzC%2BM%3Dreserved=0
REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2800data=02%7C01%7CBret.Barkelew%40microsoft.com%7Cdb2bad178b6044d37e1208d827c2d38e%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637303065010616592sdata=7sFBxWZvhxXfiLAyCgaExGqAW%2F8yfIU0p2hlMLK4XUg%3Dreserved=0
REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2801data=02%7C01%7CBret.Barkelew%40microsoft.com%7Cdb2bad178b6044d37e1208d827c2d38e%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637303065010616592sdata=jYoltIH%2BvS43A1b5koMYdK0bnmPt8Pa4tz6QkbezYc4%3Dreserved=0
REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2803data=02%7C01%7CBret.Barkelew%40microsoft.com%7Cdb2bad178b6044d37e1208d827c2d38e%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637303065010616592sdata=Neyrn2INlcMtlJ%2BbS456GPRWVxb5ALL%2B9BcLMGqX69Q%3Dreserved=0
REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2804data=02%7C01%7CBret.Barkelew%40microsoft.com%7Cdb2bad178b6044d37e1208d827c2d38e%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637303065010616592sdata=hkyOv8qhQ3iC%2FwvqnayiBeot6AYwfRho%2FUmhfcVd0qo%3Dreserved=0
REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2805data=02%7C01%7CBret.Barkelew%40microsoft.com%7Cdb2bad178b6044d37e1208d827c2d38e%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637303065010616592sdata=TLvx%2FUylNXEyMOBlikWOfnQHnbqyR1JiCm9uIod859Q%3Dreserved=0
REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2806data=02%7C01%7CBret.Barkelew%40microsoft.com%7Cdb2bad178b6044d37e1208d827c2d38e%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637303065010616592sdata=Wh7uoily48Be5EFItwd7o6whBtQZy82jh0cIDE%2FDrCY%3Dreserved=0

* Add Null base libraries for host based unit tests
* Add host based test version of BaseLib with hooks for services that use
  privileged instructions.
* Add new UT_EXPECT_ASSERT_FAILURE() macro to UnitTestLib class
* Enable source level debug of unit tests
* 

Re: [edk2-devel] [EXTERNAL] [Patch v3 12/16] UnitTestFrameworkPkg/UnitTestLib: Add checks for ASSERT()

2020-07-14 Thread Bret Barkelew via groups.io
Reviewed-by: Bret Barkelew 


- Bret

From: Michael D Kinney
Sent: Friday, July 10, 2020 7:09 PM
To: devel@edk2.groups.io
Cc: Sean Brogan; Bret 
Barkelew; Yao, 
Jiewen
Subject: [EXTERNAL] [Patch v3 12/16] UnitTestFrameworkPkg/UnitTestLib: Add 
checks for ASSERT()

REF: REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2801data=02%7C01%7CBret.Barkelew%40microsoft.com%7C5764407d5dc9445fec9808d8253f699c%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637300301574194018sdata=4UQXMIDPbI9xRP%2BKcPorH1PpbFb1%2BjZR%2BlpsnCP5lAM%3Dreserved=0

Add UnitTestDebugAssertLib that provides the UnitTestDebugAssert()
service and the gUnitTestExpectAssertFailureJumpBuffer global
variable.  This NULL library is linked against all host and target
unit test builds.  This guarantees that the UnitTestDebugAssert()
service is available to link against all libraries and modules that
use the DebugLib class.

EDKII_UNIT_TEST_FRAMEWORK_ENABLED must always be defined when
building unit tests so the behavior of the DebugLib ASSERT()
macros can be adjusted to allow the unit test framework to
catch an ASSERT() if it is triggered by a function under test.

Cc: Sean Brogan 
Cc: Bret Barkelew 
Cc: Jiewen Yao 
Signed-off-by: Michael D Kinney 
---
 .../UnitTestDebugAssertLib.c  |  49 +
 .../UnitTestDebugAssertLib.inf|  31 +++
 .../UnitTestDebugAssertLib.uni|  11 +
 .../Library/UnitTestLib/Assert.c  | 203 --
 .../Library/UnitTestLib/AssertCmocka.c|  68 ++
 .../Library/UnitTestLib/RunTests.c|  23 +-
 .../UnitTestResultReportLib.c |   3 +-
 .../PrivateInclude/UnitTestFrameworkTypes.h   |   1 +
 .../Test/UnitTestFrameworkPkgHostTest.dsc |   2 +-
 UnitTestFrameworkPkg/UnitTestFrameworkPkg.dsc |   1 +
 .../UnitTestFrameworkPkgTarget.dsc.inc|   6 +-
 11 files changed, 328 insertions(+), 70 deletions(-)
 create mode 100644 
UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.c
 create mode 100644 
UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.inf
 create mode 100644 
UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.uni

diff --git 
a/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.c 
b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.c
new file mode 100644
index 00..0a4001e182
--- /dev/null
+++ 
b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.c
@@ -0,0 +1,49 @@
+/** @file
+  Unit Test Debug Assert Library
+
+  Copyright (c) 2020, Intel Corporation. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include 
+#include 
+#include 
+
+///
+/// Point to jump buffer used with SetJump()/LongJump() to test if a function
+/// under test generates an expected ASSERT() condition.
+///
+BASE_LIBRARY_JUMP_BUFFER  *gUnitTestExpectAssertFailureJumpBuffer = NULL;
+
+/**
+  Unit test library replacement for DebugAssert() in DebugLib.
+
+  If FileName is NULL, then a  string of "(NULL) Filename" is 
printed.
+  If Description is NULL, then a  string of "(NULL) Description" 
is printed.
+
+  @param  FileName The pointer to the name of the source file that 
generated the assert condition.
+  @param  LineNumber   The line number in the source file that generated the 
assert condition
+  @param  Description  The pointer to the description of the assert condition.
+
+**/
+VOID
+EFIAPI
+UnitTestDebugAssert (
+  IN CONST CHAR8  *FileName,
+  IN UINTNLineNumber,
+  IN CONST CHAR8  *Description
+  )
+{
+  CHAR8  Message[256];
+
+  if (gUnitTestExpectAssertFailureJumpBuffer != NULL) {
+UT_LOG_INFO ("Detected expected ASSERT: %a(%d): %a\n", FileName, 
LineNumber, Description);
+LongJump (gUnitTestExpectAssertFailureJumpBuffer, 1);
+  } else {
+AsciiStrCpyS (Message, sizeof(Message), "Detected unexpected ASSERT(");
+AsciiStrCatS (Message, sizeof(Message), Description);
+AsciiStrCatS (Message, sizeof(Message), ")");
+UnitTestAssertTrue (FALSE, "", LineNumber, FileName, Message);
+  }
+}
diff --git 
a/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.inf
 
b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.inf
new file mode 100644
index 00..e6ccab0dd9
--- /dev/null
+++ 
b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.inf
@@ -0,0 +1,31 @@
+## @file
+#  Unit Test Debug Assert Library
+#
+#  Copyright (c) 2020, Intel Corporation. All rights reserved.
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION= 0x00010005
+  BASE_NAME  = 

Re: [edk2-devel] [EXTERNAL] [Patch v3 11/16] UnitTestFrameworkPkg/UnitTestLib: Fix target mode log messages

2020-07-14 Thread Bret Barkelew via groups.io
Reviewed-by: Bret Barkelew 


- Bret


From: Michael D Kinney 
Sent: Friday, July 10, 2020 7:08:59 PM
To: devel@edk2.groups.io 
Cc: Sean Brogan ; Bret Barkelew 
; Yao, Jiewen 
Subject: [EXTERNAL] [Patch v3 11/16] UnitTestFrameworkPkg/UnitTestLib: Fix 
target mode log messages

REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2806data=02%7C01%7CBret.Barkelew%40microsoft.com%7C37f4c773c1684ce41aea08d8253f692e%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637300301580380663sdata=xRivgP78PSA7wfjoPw8LZL9U9Fnh5x7LClkYmnVGL4M%3Dreserved=0

Update the log messages generated in target mode to use
FileName instead of FunctionName.  FunctionName is an empty
string so the log messages generated do not provide enough
information to know the source of a unit test failure.

Using FileName combined with LineNumber provides the
right information to identify the location of a unit test
failure.

Cc: Sean Brogan 
Cc: Bret Barkelew 
Cc: Jiewen Yao 
Signed-off-by: Michael D Kinney 
---
 .../Library/UnitTestLib/Assert.c  | 64 +--
 1 file changed, 32 insertions(+), 32 deletions(-)

diff --git a/UnitTestFrameworkPkg/Library/UnitTestLib/Assert.c 
b/UnitTestFrameworkPkg/Library/UnitTestLib/Assert.c
index c327ba88f1..8a131fab2b 100644
--- a/UnitTestFrameworkPkg/Library/UnitTestLib/Assert.c
+++ b/UnitTestFrameworkPkg/Library/UnitTestLib/Assert.c
@@ -105,14 +105,14 @@ UnitTestAssertTrue (
   if (!Expression) {
 UnitTestLogFailure (
   FAILURETYPE_ASSERTTRUE,
-  "%a::%d Expression (%a) is not TRUE!\n",
-  FunctionName,
+  "%a:%d: Expression (%a) is not TRUE!\n",
+  FileName,
   LineNumber,
   Description
   );
 UT_LOG_ERROR (
-  "[ASSERT FAIL] %a::%d Expression (%a) is not TRUE!\n",
-  FunctionName,
+  "[ASSERT FAIL] %a:%d: Expression (%a) is not TRUE!\n",
+  FileName,
   LineNumber,
   Description
   );
@@ -151,14 +151,14 @@ UnitTestAssertFalse (
   if (Expression) {
 UnitTestLogFailure (
   FAILURETYPE_ASSERTFALSE,
-  "%a::%d Expression(%a) is not FALSE!\n",
-  FunctionName,
+  "%a:%d: Expression(%a) is not FALSE!\n",
+  FileName,
   LineNumber,
   Description
   );
 UT_LOG_ERROR (
-  "[ASSERT FAIL] %a::%d Expression (%a) is not FALSE!\n",
-  FunctionName,
+  "[ASSERT FAIL] %a:%d: Expression (%a) is not FALSE!\n",
+  FileName,
   LineNumber,
   Description
   );
@@ -197,15 +197,15 @@ UnitTestAssertNotEfiError (
   if (EFI_ERROR (Status)) {
 UnitTestLogFailure (
   FAILURETYPE_ASSERTNOTEFIERROR,
-  "%a::%d Status '%a' is EFI_ERROR (%r)!\n",
-  FunctionName,
+  "%a:%d: Status '%a' is EFI_ERROR (%r)!\n",
+  FileName,
   LineNumber,
   Description,
   Status
   );
 UT_LOG_ERROR (
-  "[ASSERT FAIL] %a::%d Status '%a' is EFI_ERROR (%r)!\n",
-  FunctionName,
+  "[ASSERT FAIL] %a:%d: Status '%a' is EFI_ERROR (%r)!\n",
+  FileName,
   LineNumber,
   Description,
   Status
@@ -250,8 +250,8 @@ UnitTestAssertEqual (
   if (ValueA != ValueB) {
 UnitTestLogFailure (
   FAILURETYPE_ASSERTEQUAL,
-  "%a::%d Value %a != %a (%d != %d)!\n",
-  FunctionName,
+  "%a:%d: Value %a != %a (%d != %d)!\n",
+  FileName,
   LineNumber,
   DescriptionA,
   DescriptionB,
@@ -259,8 +259,8 @@ UnitTestAssertEqual (
   ValueB
   );
 UT_LOG_ERROR (
-  "[ASSERT FAIL] %a::%d Value %a != %a (%d != %d)!\n",
-  FunctionName,
+  "[ASSERT FAIL] %a:%d: Value %a != %a (%d != %d)!\n",
+  FileName,
   LineNumber,
   DescriptionA,
   DescriptionB,
@@ -312,16 +312,16 @@ UnitTestAssertMemEqual (
   if (CompareMem(BufferA, BufferB, Length) != 0) {
 UnitTestLogFailure (
   FAILURETYPE_ASSERTEQUAL,
-  "%a::%d Memory at %a != %a for length %d bytes!\n",
-  FunctionName,
+  "%a:%d: Memory at %a != %a for length %d bytes!\n",
+  FileName,
   LineNumber,
   DescriptionA,
   DescriptionB,
   Length
   );
 UT_LOG_ERROR (
-  "[ASSERT FAIL] %a::%d Value %a != %a for length %d bytes!\n",
-  FunctionName,
+  "[ASSERT FAIL] %a:%d: Value %a != %a for length %d bytes!\n",
+  FileName,
   LineNumber,
   DescriptionA,
   DescriptionB,
@@ -368,8 +368,8 @@ UnitTestAssertNotEqual (
   if (ValueA == ValueB) {
 UnitTestLogFailure (
   FAILURETYPE_ASSERTNOTEQUAL,
-  "%a::%d Value %a == %a (%d == %d)!\n",
-  FunctionName,
+  "%a:%d: Value %a == %a (%d == %d)!\n",
+  FileName,
   LineNumber,
   DescriptionA,
   DescriptionB,
@@ -377,8 +377,8 @@ UnitTestAssertNotEqual (
   ValueB
   );
 UT_LOG_ERROR (
-  "[ASSERT FAIL] %a::%d Value %a == %a (%d == %d)!\n",
-  FunctionName,
+  "[ASSERT FAIL] %a:%d: Value %a == %a (%d == %d)!\n",
+  FileName,
   LineNumber,
   

Re: [edk2-devel] [EXTERNAL] [Patch v3 08/16] UnitTestFrameworkPkg: Set host application stack size to 256KB

2020-07-14 Thread Bret Barkelew via groups.io
Reviewed-by: Bret Barkelew 

- Bret

From: Michael D Kinney
Sent: Friday, July 10, 2020 7:09 PM
To: devel@edk2.groups.io
Cc: Sean Brogan; Bret 
Barkelew; Yao, 
Jiewen
Subject: [EXTERNAL] [Patch v3 08/16] UnitTestFrameworkPkg: Set host application 
stack size to 256KB

REF: 
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2803data=02%7C01%7CBret.Barkelew%40microsoft.com%7C6d34207455e9401311c408d8253f6805%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637300301542442718sdata=IhFDMIx%2FIz4DQAMJjDmGZo%2FBBZfUFzeYvCbAxbnNTzo%3Dreserved=0

The UEFI Specification defines the minimum stack size before
ExitBootServices() to be 128KB.  When running a host based unit
test, there may be additional stack overhead from the host
application environment and cmocka.

Update the build flags to set the size of the stack to 256KB
which is double the UEFI Specification requirement.

Cc: Sean Brogan 
Cc: Bret Barkelew 
Cc: Jiewen Yao 
Signed-off-by: Michael D Kinney 
---
 UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc 
b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc
index c4e6e0e0a6..4dd8d4ac67 100644
--- a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc
+++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc
@@ -30,7 +30,7 @@ [BuildOptions.common.EDKII.HOST_APPLICATION]
   #
   # MSFT
   #
-  MSFT:*_*_*_DLINK_FLAGS== /out:"$(BIN_DIR)\$(BASE_NAME).exe" 
/pdb:"$(BIN_DIR)\$(BASE_NAME).pdb" /IGNORE:4001 /NOLOGO /SUBSYSTEM:CONSOLE 
/DEBUG /NODEFAULTLIB:libcmt.lib libcmtd.lib
+  MSFT:*_*_*_DLINK_FLAGS== /out:"$(BIN_DIR)\$(BASE_NAME).exe" 
/pdb:"$(BIN_DIR)\$(BASE_NAME).pdb" /IGNORE:4001 /NOLOGO /SUBSYSTEM:CONSOLE 
/DEBUG /STACK:0x4,0x4 /NODEFAULTLIB:libcmt.lib libcmtd.lib
   MSFT:*_*_IA32_DLINK_FLAGS = /MACHINE:I386
   MSFT:*_*_X64_DLINK_FLAGS  = /MACHINE:AMD64

--
2.21.0.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62577): https://edk2.groups.io/g/devel/message/62577
Mute This Topic: https://groups.io/mt/75514372/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH V1 1/2] MdePkg-IndustryStandard: CXL 1.1 Specification registers

2020-07-14 Thread Michael D Kinney
Hi Arshaf,

1) Pci.h - Copyright should be updated to 2020
2) Why is define for CXL_DVSEC_VENDOR_ID listed on its own
   in Cxl.h?  Was this added to the standard after the CXL 1.1
   specs?
3) There are a few minor formatting issues with the field 
   indentations for some of the bitfield structs.  One example:

typedef union {
  struct {
  UINT16 CacheEnable: 1; // bit 0
  UINT16 IoEnable   : 1; // bit 1
  UINT16 MemEnable  : 1; // bit 2
  UINT16 CxlSyncBypassEnable: 1; // bit 3
  UINT16 DriftBufferEnable  : 1; // bit 4
  UINT16 Reserved   : 3; // bit 5..7
  UINT16 CxlCorrectableProtocolIdFramingError   : 1; // bit 8
  UINT16 CxlUncorrectableProtocolIdFramingError : 1; // bit 9
  UINT16 CxlUnexpectedProtocolIdDropped : 1; // bit 10
  UINT16 Reserved2  : 5; // bit 
11..15
  }Bits;
  UINT16Uint16;
} CXL_1_1_DVSEC_FLEX_BUS_PORT_STATUS;

Should be:

typedef union {
  struct {
UINT16 CacheEnable  : 1; // bit 0
UINT16 IoEnable : 1; // bit 1
UINT16 MemEnable: 1; // bit 2
UINT16 CxlSyncBypassEnable  : 1; // bit 3
UINT16 DriftBufferEnable: 1; // bit 4
UINT16 Reserved : 3; // bit 5..7
UINT16 CxlCorrectableProtocolIdFramingError : 1; // bit 8
UINT16 CxlUncorrectableProtocolIdFramingError   : 1; // bit 9
UINT16 CxlUnexpectedProtocolIdDropped   : 1; // bit 10
UINT16 Reserved2: 5; // bit 
11..15
  }Bits;
  UINT16Uint16;
} CXL_1_1_DVSEC_FLEX_BUS_PORT_STATUS;

4) The following structure that provides a log looks a little odd
   because code that access the log array would have to use
   HeaderLog.HeaderLog[Index].

typedef struct {
  CXL_1_1_UNCORRECTABLE_ERROR_STATUSHeaderLog[16];
} CXL_HEADER_LOG;

typedef struct {
  CXL_1_1_UNCORRECTABLE_ERROR_STATUS
UncorrectableErrorStatus; // offset 0
  CXL_1_1_UNCORRECTABLE_ERROR_MASK  
UncorrectableErrorMask;   // offset 4
  CXL_1_1_UNCORRECTABLE_ERROR_SEVERITY  
UncorrectableErrorSeverity;   // offset 8
  CXL_CORRECTABLE_ERROR_STATUS  
CorrectableErrorStatus;   // offset 12
  CXL_CORRECTABLE_ERROR_MASK
CorrectableErrorMask; // offset 16
  CXL_ERROR_CAPABILITIES_AND_CONTROL
ErrorCapabilitiesAndControl;  // offset 20
  CXL_HEADER_LOGHeaderLog;  
  // offset 24
} CXL_1_1_RAS_CAPABILITY_STRUCTURE;

If this was changed to the following, it may be easier
to use and understand:

typedef struct {
  CXL_1_1_UNCORRECTABLE_ERROR_STATUS
UncorrectableErrorStatus; // offset 0
  CXL_1_1_UNCORRECTABLE_ERROR_MASK  
UncorrectableErrorMask;   // offset 4
  CXL_1_1_UNCORRECTABLE_ERROR_SEVERITY  
UncorrectableErrorSeverity;   // offset 8
  CXL_CORRECTABLE_ERROR_STATUS  
CorrectableErrorStatus;   // offset 12
  CXL_CORRECTABLE_ERROR_MASK
CorrectableErrorMask; // offset 16
  CXL_ERROR_CAPABILITIES_AND_CONTROL
ErrorCapabilitiesAndControl;  // offset 20
  CXL_1_1_UNCORRECTABLE_ERROR_STATUSHeaderLog[16];  
  // offset 24
} CXL_1_1_RAS_CAPABILITY_STRUCTURE;

Thanks,

Mike

> -Original Message-
> From: devel@edk2.groups.io  On
> Behalf Of Javeed, Ashraf
> Sent: Saturday, July 11, 2020 3:40 AM
> To: devel@edk2.groups.io
> Cc: Kinney, Michael D ; Gao,
> Liming 
> Subject: [edk2-devel] [PATCH V1 1/2] MdePkg-
> IndustryStandard: CXL 1.1 Specification registers
> 
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2611
> 
> Register definitions from chapter 7 of Compute Express
> Link Specification
> Revision 1.1 are ported into the new Cxl11.h.
> The CXL Flex Bus registers are based on the PCIe
> Extended Capability
> DVSEC structure header, led to the inclusion of upgraded
> Pci.h.
> 
> Signed-off-by: Ashraf Javeed 
> Cc: Michael D Kinney 
> Cc: Liming Gao 
> ---
>  MdePkg/Include/IndustryStandard/Cxl11.h | 573
> 

Re: [edk2-devel] [PATCH v3 3/3] AzurePipelines : Pr Gate: Turn on HBUT for CryptoPkg

2020-07-14 Thread Michael D Kinney
Matt,

Reviewed-by: Michael D Kinney  

Mike

> -Original Message-
> From: matthewfcarl...@gmail.com
> 
> Sent: Tuesday, July 14, 2020 11:23 AM
> To: devel@edk2.groups.io
> Cc: Sean Brogan ; Bret
> Barkelew ; Kinney, Michael
> D ; Gao, Liming
> 
> Subject: [PATCH v3 3/3] AzurePipelines : Pr Gate: Turn
> on HBUT for CryptoPkg
> 
> From: Matthew Carlson 
> 
> Turns on Host Based Unit Tests for CryptoPkg by enabling
> the target
> NOOPT in the CI pipeline.
> 
> Cc: Sean Brogan 
> Cc: Bret Barkelew 
> Cc: Michael D Kinney 
> Cc: Liming Gao 
> 
> Signed-off-by: Matthew Carlson
> 
> ---
>  .azurepipelines/templates/pr-gate-build-job.yml | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/.azurepipelines/templates/pr-gate-build-
> job.yml b/.azurepipelines/templates/pr-gate-build-
> job.yml
> index a9f89aa68451..e84ba80030b1 100644
> --- a/.azurepipelines/templates/pr-gate-build-job.yml
> +++ b/.azurepipelines/templates/pr-gate-build-job.yml
> @@ -40,7 +40,7 @@ jobs:
>  Build.Targets: 'DEBUG,RELEASE,NO-TARGET,NOOPT'
> 
>TARGET_CRYPTO:
> 
>  Build.Pkgs: 'CryptoPkg'
> 
> -Build.Targets: 'DEBUG,RELEASE,NO-TARGET'
> 
> +Build.Targets: 'DEBUG,RELEASE,NO-TARGET,NOOPT'
> 
>TARGET_SECURITY:
> 
>  Build.Pkgs: 'SecurityPkg'
> 
>  Build.Targets: 'DEBUG,RELEASE,NO-TARGET'
> 
> --
> 2.27.0.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62574): https://edk2.groups.io/g/devel/message/62574
Mute This Topic: https://groups.io/mt/75505001/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/3] UnitTestFrameworkPkg : BaseTimerLibPosix: Adds a host-based timer Lib

2020-07-14 Thread Michael D Kinney
Matt,

Reviewed-by: Michael D Kinney  

Mike

> -Original Message-
> From: matthewfcarl...@gmail.com
> 
> Sent: Tuesday, July 14, 2020 11:23 AM
> To: devel@edk2.groups.io
> Cc: Kinney, Michael D ; Sean
> Brogan ; Bret Barkelew
> 
> Subject: [PATCH v3 1/3] UnitTestFrameworkPkg :
> BaseTimerLibPosix: Adds a host-based timer Lib
> 
> From: Matthew Carlson 
> 
> This adds a host based BaseTimerLib that won't assert.
> 
> Cc: Michael D Kinney 
> Cc: Sean Brogan 
> Cc: Bret Barkelew 
> Signed-off-by: Matthew Carlson
> 
> ---
> 
> UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/Tim
> erLibPosix.c   | 132 
> 
> UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/Bas
> eTimerLibPosix.inf |  33 +
> 
> UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/Bas
> eTimerLibPosix.uni |  14 +++
> 
> UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.d
> sc |   1 +
>  UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc
> |   1 +
>  5 files changed, 181 insertions(+)
> 
> diff --git
> a/UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/T
> imerLibPosix.c
> b/UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/T
> imerLibPosix.c
> new file mode 100644
> index ..3c1394e3b21b
> --- /dev/null
> +++
> b/UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/T
> imerLibPosix.c
> @@ -0,0 +1,132 @@
> +/** @file
> 
> +  A semi-functional instance of the Timer Library.
> 
> +
> 
> +  Copyright (c) Microsoft Corporation.
> 
> +
> 
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +
> 
> +**/
> 
> +
> 
> +#include 
> 
> +#include 
> 
> +#include 
> 
> +#include 
> 
> +#include 
> 
> +#include 
> 
> +
> 
> +/**
> 
> +  Stalls the CPU for at least the given number of
> microseconds.
> 
> +
> 
> +  @param  MicroSeconds  The minimum number of
> microseconds to delay.
> 
> +  @return The value of MicroSeconds inputted.
> 
> +
> 
> +**/
> 
> +UINTN
> 
> +EFIAPI
> 
> +MicroSecondDelay (
> 
> +  IN  UINTN MicroSeconds
> 
> +  )
> 
> +{
> 
> +  // Since this is a host based test, we don't actually
> want to stall
> 
> +  return MicroSeconds;
> 
> +}
> 
> +
> 
> +/**
> 
> +  Stalls the CPU for at least the given number of
> nanoseconds.
> 
> +
> 
> +  @param  NanoSeconds The minimum number of nanoseconds
> to delay.
> 
> +  @return The value of NanoSeconds inputted.
> 
> +
> 
> +**/
> 
> +UINTN
> 
> +EFIAPI
> 
> +NanoSecondDelay (
> 
> +  IN  UINTN NanoSeconds
> 
> +  )
> 
> +{
> 
> +  // Since this is a host based test, we don't actually
> want to stall
> 
> +  return NanoSeconds;
> 
> +}
> 
> +
> 
> +/**
> 
> +  Retrieves the current value of a 64-bit free running
> performance counter.
> 
> +
> 
> +  The counter can either count up by 1 or count down by
> 1. If the physical
> 
> +  performance counter counts by a larger increment,
> then the counter values
> 
> +  must be translated. The properties of the counter can
> be retrieved from
> 
> +  GetPerformanceCounterProperties().
> 
> +
> 
> +  @return The current value of the free running
> performance counter.
> 
> +
> 
> +**/
> 
> +UINT64
> 
> +EFIAPI
> 
> +GetPerformanceCounter (
> 
> +  VOID
> 
> +  )
> 
> +{
> 
> +  struct timespec ts;
> 
> +  timespec_get(, TIME_UTC);
> 
> +  // Return the current number of nanoseconds on the
> clock
> 
> +  return ts.tv_nsec;
> 
> +}
> 
> +
> 
> +/**
> 
> +  Retrieves the 64-bit frequency in Hz and the range of
> performance counter
> 
> +  values.
> 
> +
> 
> +  If StartValue is not NULL, then the value that the
> performance counter starts
> 
> +  with immediately after is it rolls over is returned
> in StartValue. If
> 
> +  EndValue is not NULL, then the value that the
> performance counter end with
> 
> +  immediately before it rolls over is returned in
> EndValue. The 64-bit
> 
> +  frequency of the performance counter in Hz is always
> returned. If StartValue
> 
> +  is less than EndValue, then the performance counter
> counts up. If StartValue
> 
> +  is greater than EndValue, then the performance
> counter counts down. For
> 
> +  example, a 64-bit free running counter that counts up
> would have a StartValue
> 
> +  of 0 and an EndValue of 0x. A 24-bit
> free running counter
> 
> +  that counts down would have a StartValue of 0xFF
> and an EndValue of 0.
> 
> +
> 
> +  @param  StartValue  The value the performance counter
> starts with when it
> 
> +  rolls over.
> 
> +  @param  EndValueThe value that the performance
> counter ends with before
> 
> +  it rolls over.
> 
> +
> 
> +  @return The frequency in Hz.
> 
> +
> 
> +**/
> 
> +UINT64
> 
> +EFIAPI
> 
> +GetPerformanceCounterProperties (
> 
> +  OUT  UINT64*StartValue,
> OPTIONAL
> 
> +  OUT  UINT64*EndValue
> OPTIONAL
> 
> +  )
> 
> +{
> 
> +  if ( EndValue != NULL ) {
> 
> +*EndValue = MAX_UINT64;
> 
> +  }
> 
> +  if ( StartValue != NULL ) {
> 

[edk2-devel] [edk2-non-osi] Platform/Qemu/Sbssa: Add TF-A binaries

2020-07-14 Thread Tanmay Jagdale
Add fip.bin and bl1.bin binaries for the Qemu Sbsa model

Signed-off-by: Tanmay Jagdale 
---
 Platform/Qemu/Sbsa/License.txt |  25 +
 Platform/Qemu/Sbsa/Readme.md   |  29 +
 Platform/Qemu/Sbsa/bl1.bin | Bin 0 -> 19301 bytes
 Platform/Qemu/Sbsa/fip.bin | Bin 0 -> 53973 bytes
 4 files changed, 54 insertions(+)
 create mode 100644 Platform/Qemu/Sbsa/License.txt
 create mode 100644 Platform/Qemu/Sbsa/Readme.md
 create mode 100755 Platform/Qemu/Sbsa/bl1.bin
 create mode 100644 Platform/Qemu/Sbsa/fip.bin

diff --git a/Platform/Qemu/Sbsa/License.txt b/Platform/Qemu/Sbsa/License.txt
new file mode 100644
index 000..da40d30
--- /dev/null
+++ b/Platform/Qemu/Sbsa/License.txt
@@ -0,0 +1,25 @@
+Copyright (c) 2020, Linaro Ltd. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+* Redistributions of source code must retain the above copyright
+  notice, this list of conditions and the following disclaimer.
+* Redistributions in binary form must reproduce the above copyright
+  notice, this list of conditions and the following disclaimer in
+  the documentation and/or other materials provided with the
+  distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
diff --git a/Platform/Qemu/Sbsa/Readme.md b/Platform/Qemu/Sbsa/Readme.md
new file mode 100644
index 000..3831094
--- /dev/null
+++ b/Platform/Qemu/Sbsa/Readme.md
@@ -0,0 +1,29 @@
+Qemu SBSA TF-A binaries
+---
+
+These binaries have been created from the mainline TF-A
+code checked out at the following commit ID:
+
+commit 99c447f4406c8ae66b6cab2341ef0c8e8d9751d2
+Merge: 331723509 8e570b71d
+Author: André Przywara 
+Date:   Tue Jul 7 22:06:31 2020 +
+
+Merge "drivers: arm: gicv3: auto-detect presence of GIC600-AE" into 
integration
+
+
+This ensures that the following fix for qemu_sbsa platform is
+merged upstream and is included in the build:
+
+commit d7f5be8ec2fc5254fc581af52156b5fde5deb822
+Author: Masahisa Kojima 
+Date:   Tue May 19 19:49:36 2020 +0900
+
+qemu/qemu_sbsa: increase size to handle fdt
+
+
+NOTE: No modifications to the source code have been done.
+  The binaries have been generated for the AARCH64 platform
+  with the following command:
+
+   make PLAT=qemu_sbsa all fip
diff --git a/Platform/Qemu/Sbsa/bl1.bin b/Platform/Qemu/Sbsa/bl1.bin
new file mode 100755
index 
..bd0b2de1dfcb23eb3901f3001ab01edd9f15cb52
GIT binary patch
literal 19301
zcmeHu3vg8DmFBtkwjKx>gd{)+6@6O*2ikzeTi_U7wZtpN7=*@VY;V-92M>c0sD&*X
zY_7z^BywC_SuqawxEnBzx;Ithk-^#CnF#_MJF_G^qM_N^%+%1540bFh0|MJ>jL?4P
zJ|yw*W^1c5RPCbV^56SE=@%=RdE%P4RVMf5v;=lrk=IK3|H=PNXJ<=m?ShoV;B~
zp;n{+P4pKC^=uI4tf3eKtPZTVU`+#@
zDE0g@3OH`8Wje16Rbtk9hJC%SZ*=e0Uk%Wt!x4f{Vr?td-n{OFj(1?)u|PX$xAr{b
z);)u6rZbAYSvVYtN{C2_UD5G~!EV9e)9)Z#cl=-)Z^dQMXsn~4#s4uxO)B)jkRfRv
z=8?WfV?AVg$webI0s2%_>*?u~1gD*BU4Gzm*htGyq00q*eI-mM>rLsZoF4hz#UZlM
z3i;i{&^7Rf`(^*)kUfz$H?t1fXoT!f#6AqUy9G7%2Ih526y&`!Ps*{!OOOYN_H!cM
zU0F)34Cmt##<08ghVwCKtas}_=yG8_xdPa%-(Ni?25g}3o3Rx0CDZ1`
zaa6Jz{a*v_$Ji&+0NCMQ*SdQ;Byt{>a3--_pK1I+x0djw0+qN@Xura0?c^s#iB;(9Z931aaZAs1zG9vu!_qYhIs`f*oBQBBy#U(uJq*$pracBaRa3Tv
z{S$CO-}LjtG%^m>3D*05eQX`2380zfD8#GbsjwT{@1W1UTmL=)9n{YZ%e4k@ym;yl
zj?z5!qqMKmC^k~(x#Voa*@zO?@(UW3K
zA!=7*FJoL5%)Q~e5#RlLgg#li#B0TrsxQQK>#N8+P607qpH`Vyvun
zw06)(TwvBoE1G{Yyx!QPk_&|)OEm=W77%94?N+$ep4<5TI1*_^QDJ*1wO$p
zYZkAVM~S>=8_kO5C^425^C^$}M4B}Rbi9#G+Bet6YCPVVBS5C3f?}K+`$}*KQ
zU~|xq^@Y$m<_-8Tvt1h9-~TZBqrH8ze8VWF>k{D2W;~Wo@%b$;1kVk<@`6u%26*l_
zXno-85$JL^-dXSYOyswTF@DcKYqZ(mA)mQY61wW3SL_P~(8T;%pFmCed0}4>8x
zkeQ#@FUtcusmsMWyVjXv-Vx;EztOi(wQRg9+-BpIemL;S@c;6lvufd}0IVI9p{cYm
zMBp22VDT=B4~@4efr{%C@FY{L5VB@^EPI}Bqs<3^^}4xE3cm+if78*t_aX)wIqN?WO^bmm9;e8YdkPF*g_P_DH@
z4t`N>WZrRW_;|zL^!rIOc8NBKf%ZeNi|}DlJ7fyDHGt{CH{f;Q9G48i1G$}Y>$XD;
ze+hY7xMY#_*R*-x0n-ndrGUxn70`YwO%|<|PV4*_{4*}*2
zpCk4S?6X0sn%y`HrOEceeM$(h`n*fQww23
z)UY12`7^X%0Jb}`Fs6S;GxQja=fB7O;uvi!x7o%xp9_~fM(f>rqM2d*O)uN$|JrY#
z!7nG%s=PHo|%Us
z)|K_o_Yf(uR=oG~(X^j2*wx;xAM5A)dC{(K^ZnZDvY(
z1IuZbImZn<9eq%V{dauxT*h+*#0)nqfbTTmw0Qp7#jo7pXoh(!1T_L@5?6

Re: [edk2-devel] [PATCH v3 1/1] MdeModulePkg/UsbBusDxe: Rebuild the description table after Reset Device

2020-07-14 Thread Guomin Jiang
Hi Jeremy,

We test many different device and found some device haven't reproduced the 
issue.

We need to figure out the root cause rather than work around.

Best Regards
Guomin
> -Original Message-
> From: Jeremy Linton 
> Sent: Wednesday, July 15, 2020 8:19 AM
> To: Jiang, Guomin ; devel@edk2.groups.io
> Cc: Wang, Jian J ; Wu, Hao A
> ; Ni, Ray 
> Subject: Re: [PATCH v3 1/1] MdeModulePkg/UsbBusDxe: Rebuild the
> description table after Reset Device
> 
> Hi,
> 
> On 5/9/20 3:26 AM, Guomin Jiang wrote:
> > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2694
> >
> > When the USB fail and then Reset Device, it should rebuild description.
> 
> 
> I pulled the latest edk2 a few hours ago and I'm still seeing the assert 
> TrsRing
> != 0 messages on a real XHCI controller with the jmicron JBOD I mentioned
> earlier.
> 
> Is there a newer version of this patch?
> 
> Thanks,
> 
> 
> 
> >
> > Signed-off-by: Guomin Jiang 
> > Cc: Jian J Wang 
> > Cc: Hao A Wu 
> > Cc: Ray Ni 
> > ---
> >   MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c  |   7 ++
> >   MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c | 152
> +++
> >   MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.h |  14 +++
> >   3 files changed, 173 insertions(+)
> >
> > diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
> > b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
> > index 4b4915c019ad..7bb9373a6adf 100644
> > --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
> > +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
> > @@ -874,6 +874,13 @@ UsbIoPortReset (
> > // is in CONFIGURED state.
> > //
> > if (Dev->ActiveConfig != NULL) {
> > +Status = UsbRebuildDescTable (Dev);
> > +
> > +if (EFI_ERROR (Status)) {
> > +  DEBUG (( DEBUG_ERROR, "UsbIoPortReset: failed to rebuild desc table
> - %r\n", Status));
> > +  goto ON_EXIT;
> > +}
> > +
> >   Status = UsbSetConfig (Dev,
> > Dev->ActiveConfig->Desc.ConfigurationValue);
> >
> >   if (EFI_ERROR (Status)) {
> > diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c
> > b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c
> > index b08188b1bc78..d8e5e50b7c5a 100644
> > --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c
> > +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c
> > @@ -900,6 +900,158 @@ UsbBuildDescTable (
> > return EFI_SUCCESS;
> >   }
> >
> > +/**
> > +  Copy the interface descriptor
> > +
> > +  @param[out]  DescBuf   The buffer of raw descriptor.
> > +  @param[in]   SrcBufThe buffer of raw descriptor
> > +**/
> > +VOID
> > +UsbCopyInterfaceDesc (
> > +  OUT USB_INTERFACE_DESC  *DescBuf,
> > +  IN  USB_INTERFACE_DESC  *SrcBuf
> > +  )
> > +{
> > +  UINTN   Index, IndexI;
> > +
> > +  ASSERT ((DescBuf != NULL) && (SrcBuf != NULL));
> > +
> > +  if (DescBuf->NumOfSetting == SrcBuf->NumOfSetting) {
> > +DescBuf->ActiveIndex = SrcBuf->ActiveIndex;
> > +
> > +for (Index = 0; Index < DescBuf->NumOfSetting; Index++) {
> > +  CopyMem (>Settings[Index]->Desc,
> > +>Settings[Index]->Desc,
> > +sizeof(EFI_USB_INTERFACE_DESCRIPTOR));
> > +
> > +  if (DescBuf->Settings[Index]->Desc.NumEndpoints ==
> > +   SrcBuf->Settings[Index]->Desc.NumEndpoints) {
> > +
> > +for (IndexI = 0; IndexI < DescBuf->Settings[Index]-
> >Desc.NumEndpoints;
> > +  IndexI++) {
> > +  CopyMem (DescBuf->Settings[Index]->Endpoints[IndexI],
> > +SrcBuf->Settings[Index]->Endpoints[IndexI],
> > +sizeof(USB_ENDPOINT_DESC));
> > +}
> > +  }
> > +}
> > +  }
> > +}
> > +
> > +/**
> > +  Copy the configuration descriptor and its interfaces.
> > +
> > +  @param[out]  DescBuf   The buffer of raw descriptor.
> > +  @param[in]   SrcBufThe buffer of raw descriptor
> > +**/
> > +VOID
> > +UsbCopyConfigDesc (
> > +  OUT USB_CONFIG_DESC   *DescBuf,
> > +  IN  USB_CONFIG_DESC   *SrcBuf
> > +  )
> > +{
> > +  UINTN   Index;
> > +
> > +  ASSERT ((DescBuf != NULL) && (SrcBuf != NULL));
> > +
> > +  if (DescBuf->Desc.NumInterfaces == SrcBuf->Desc.NumInterfaces) {
> > +CopyMem (>Desc, >Desc,
> > + sizeof(EFI_USB_CONFIG_DESCRIPTOR));
> > +
> > +for (Index = 0; Index < DescBuf->Desc.NumInterfaces; Index++) {
> > +  UsbCopyInterfaceDesc (DescBuf->Interfaces[Index], SrcBuf-
> >Interfaces[Index]);
> > +}
> > +  }
> > +}
> > +
> > +/**
> > +  Rebuild the whole array of descriptors.
> > +
> > +  @param[in]  UsbDevThe Usb device.
> > +
> > +  @retval EFI_SUCCESS   The descriptor table is build.
> > +  @retval EFI_DEVICE_ERROR  Invalid config
> > +  @retval OthersCommand error when get descriptor.
> > +**/
> > +EFI_STATUS
> > +UsbRebuildDescTable (
> > +  IN USB_DEVICE   *UsbDev
> > +  )
> > +{
> > +  EFI_USB_CONFIG_DESCRIPTOR *Config;
> > +  USB_CONFIG_DESC   *ConfigDesc;
> > +  UINT8 NumConfig;
> > +  EFI_STATUS

Re: [edk2-devel] [Patch v4] BaseTools: Add Guid name support in GenFfs.

2020-07-14 Thread Bob Feng
Reviewed-by: Bob Feng 

-Original Message-
From: devel@edk2.groups.io  On Behalf Of Yuwei Chen
Sent: Tuesday, July 14, 2020 1:31 PM
To: devel@edk2.groups.io
Subject: [edk2-devel] [Patch v4] BaseTools: Add Guid name support in GenFfs.

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2762

The Fv Section in the FDF files use hard coding Guid values which is 
inconvenient to manage. This patch adds Guid name support in GenFfs to solve 
this problem.

Signed-off-by: Yuwei Chen 
---
 .../Source/Python/AutoGen/WorkspaceAutoGen.py | 24 +++  
BaseTools/Source/Python/Common/GlobalData.py  |  1 +
 BaseTools/Source/Python/GenFds/FdfParser.py   | 14 ++-
 3 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/BaseTools/Source/Python/AutoGen/WorkspaceAutoGen.py 
b/BaseTools/Source/Python/AutoGen/WorkspaceAutoGen.py
index 668126aaac..f86c749c08 100644
--- a/BaseTools/Source/Python/AutoGen/WorkspaceAutoGen.py
+++ b/BaseTools/Source/Python/AutoGen/WorkspaceAutoGen.py
@@ -108,6 +108,10 @@ class WorkspaceAutoGen(AutoGen):
 #
 # Mark now build in AutoGen Phase
 #
+#
+# Collect Platform Guids to support Guid name in Fdfparser.
+#
+self.CollectPlatformGuids()
 GlobalData.gAutoGenPhase = True
 self.ProcessModuleFromPdf()
 self.ProcessPcdType()
@@ -153,6 +157,26 @@ class WorkspaceAutoGen(AutoGen):
 EdkLogger.error("build", PARAMETER_INVALID,
 ExtraData="Build target [%s] is not supported by 
the platform. [Valid target: %s]"
   % (self.BuildTarget, " 
".join(self.Platform.BuildTargets)))
+
+def CollectPlatformGuids(self):
+oriInfList = []
+oriPkgSet = set()
+PlatformPkg = set()
+for Arch in self.ArchList:
+Platform = self.BuildDatabase[self.MetaFile, Arch, 
self.BuildTarget, self.ToolChain]
+oriInfList = Platform.Modules
+for ModuleFile in oriInfList:
+ModuleData = self.BuildDatabase[ModuleFile, Platform._Arch, 
Platform._Target, Platform._Toolchain]
+oriPkgSet.update(ModuleData.Packages)
+for Pkg in oriPkgSet:
+Guids = Pkg.Guids
+GlobalData.gGuidDict.update(Guids)
+if Platform.Packages:
+PlatformPkg.update(Platform.Packages)
+for Pkg in PlatformPkg:
+Guids = Pkg.Guids
+GlobalData.gGuidDict.update(Guids)
+
 @cached_property
 def FdfProfile(self):
 if not self.FdfFile:
diff --git a/BaseTools/Source/Python/Common/GlobalData.py 
b/BaseTools/Source/Python/Common/GlobalData.py
index 8ac29eb7a6..61ab3f7e24 100755
--- a/BaseTools/Source/Python/Common/GlobalData.py
+++ b/BaseTools/Source/Python/Common/GlobalData.py
@@ -29,6 +29,7 @@ gProcessingFile = ''
 gBuildingModule = ''
 gSkuids = []
 gDefaultStores = []
+gGuidDict = {}
 
 # definition for a MACRO name.  used to create regular expressions below.
 _MacroNamePattern = "[A-Z][A-Z0-9_]*"
diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py 
b/BaseTools/Source/Python/GenFds/FdfParser.py
index 9b04a76af8..ea2401b0e4 100644
--- a/BaseTools/Source/Python/GenFds/FdfParser.py
+++ b/BaseTools/Source/Python/GenFds/FdfParser.py
@@ -18,7 +18,7 @@ from uuid import UUID
 
 from Common.BuildToolError import *
 from Common import EdkLogger
-from Common.Misc import PathClass, tdict, ProcessDuplicatedInf
+from Common.Misc import PathClass, tdict, ProcessDuplicatedInf, 
+GuidStructureStringToGuidString
 from Common.StringUtils import NormPath, ReplaceMacro  from Common import 
GlobalData  from Common.Expression import * @@ -1087,6 +1087,8 @@ class 
FdfParser:
 return False
 if GlobalData.gGuidPattern.match(self._Token) is not None:
 return True
+elif self._Token in GlobalData.gGuidDict:
+return True
 else:
 self._UndoToken()
 return False
@@ -2248,6 +2250,8 @@ class FdfParser:
 
 if not self._GetNextGuid():
 raise Warning.Expected("GUID value", self.FileName, 
self.CurrentLineNumber)
+if self._Token in GlobalData.gGuidDict:
+self._Token = 
+ GuidStructureStringToGuidString(GlobalData.gGuidDict[self._Token]).upp
+ er()
 
 FvObj.FvNameGuid = self._Token
 
@@ -2459,6 +2463,8 @@ class FdfParser:
 raise Warning.ExpectedEquals(self.FileName, 
self.CurrentLineNumber)
 if not self._GetNextGuid():
 raise Warning.Expected("GUID value", self.FileName, 
self.CurrentLineNumber)
+if self._Token in GlobalData.gGuidDict:
+self._Token = 
+ GuidStructureStringToGuidString(GlobalData.gGuidDict[self._Token]).upp
+ er()
 FfsInfObj.OverrideGuid = self._Token
 
 if self._IsKeyword("RuleOverride"):
@@ -2550,6 +2556,8 @@ class FdfParser:
   

Re: [edk2-devel] [PATCH v3 1/1] MdeModulePkg/UsbBusDxe: Rebuild the description table after Reset Device

2020-07-14 Thread Jeremy Linton

Hi,

On 5/9/20 3:26 AM, Guomin Jiang wrote:

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2694

When the USB fail and then Reset Device, it should rebuild description.



I pulled the latest edk2 a few hours ago and I'm still seeing the assert 
TrsRing != 0 messages on a real XHCI controller with the jmicron JBOD I 
mentioned earlier.


Is there a newer version of this patch?

Thanks,





Signed-off-by: Guomin Jiang 
Cc: Jian J Wang 
Cc: Hao A Wu 
Cc: Ray Ni 
---
  MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c  |   7 ++
  MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c | 152 +++
  MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.h |  14 +++
  3 files changed, 173 insertions(+)

diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c 
b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
index 4b4915c019ad..7bb9373a6adf 100644
--- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
+++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c
@@ -874,6 +874,13 @@ UsbIoPortReset (
// is in CONFIGURED state.
//
if (Dev->ActiveConfig != NULL) {
+Status = UsbRebuildDescTable (Dev);
+
+if (EFI_ERROR (Status)) {
+  DEBUG (( DEBUG_ERROR, "UsbIoPortReset: failed to rebuild desc table - 
%r\n", Status));
+  goto ON_EXIT;
+}
+
  Status = UsbSetConfig (Dev, Dev->ActiveConfig->Desc.ConfigurationValue);
  
  if (EFI_ERROR (Status)) {

diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c 
b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c
index b08188b1bc78..d8e5e50b7c5a 100644
--- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c
+++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbDesc.c
@@ -900,6 +900,158 @@ UsbBuildDescTable (
return EFI_SUCCESS;
  }
  
+/**

+  Copy the interface descriptor
+
+  @param[out]  DescBuf   The buffer of raw descriptor.
+  @param[in]   SrcBufThe buffer of raw descriptor
+**/
+VOID
+UsbCopyInterfaceDesc (
+  OUT USB_INTERFACE_DESC  *DescBuf,
+  IN  USB_INTERFACE_DESC  *SrcBuf
+  )
+{
+  UINTN   Index, IndexI;
+
+  ASSERT ((DescBuf != NULL) && (SrcBuf != NULL));
+
+  if (DescBuf->NumOfSetting == SrcBuf->NumOfSetting) {
+DescBuf->ActiveIndex = SrcBuf->ActiveIndex;
+
+for (Index = 0; Index < DescBuf->NumOfSetting; Index++) {
+  CopyMem (>Settings[Index]->Desc,
+>Settings[Index]->Desc,
+sizeof(EFI_USB_INTERFACE_DESCRIPTOR));
+
+  if (DescBuf->Settings[Index]->Desc.NumEndpoints ==
+   SrcBuf->Settings[Index]->Desc.NumEndpoints) {
+
+for (IndexI = 0; IndexI < DescBuf->Settings[Index]->Desc.NumEndpoints;
+  IndexI++) {
+  CopyMem (DescBuf->Settings[Index]->Endpoints[IndexI],
+SrcBuf->Settings[Index]->Endpoints[IndexI],
+sizeof(USB_ENDPOINT_DESC));
+}
+  }
+}
+  }
+}
+
+/**
+  Copy the configuration descriptor and its interfaces.
+
+  @param[out]  DescBuf   The buffer of raw descriptor.
+  @param[in]   SrcBufThe buffer of raw descriptor
+**/
+VOID
+UsbCopyConfigDesc (
+  OUT USB_CONFIG_DESC   *DescBuf,
+  IN  USB_CONFIG_DESC   *SrcBuf
+  )
+{
+  UINTN   Index;
+
+  ASSERT ((DescBuf != NULL) && (SrcBuf != NULL));
+
+  if (DescBuf->Desc.NumInterfaces == SrcBuf->Desc.NumInterfaces) {
+CopyMem (>Desc, >Desc, sizeof(EFI_USB_CONFIG_DESCRIPTOR));
+
+for (Index = 0; Index < DescBuf->Desc.NumInterfaces; Index++) {
+  UsbCopyInterfaceDesc (DescBuf->Interfaces[Index], 
SrcBuf->Interfaces[Index]);
+}
+  }
+}
+
+/**
+  Rebuild the whole array of descriptors.
+
+  @param[in]  UsbDevThe Usb device.
+
+  @retval EFI_SUCCESS   The descriptor table is build.
+  @retval EFI_DEVICE_ERROR  Invalid config
+  @retval OthersCommand error when get descriptor.
+**/
+EFI_STATUS
+UsbRebuildDescTable (
+  IN USB_DEVICE   *UsbDev
+  )
+{
+  EFI_USB_CONFIG_DESCRIPTOR *Config;
+  USB_CONFIG_DESC   *ConfigDesc;
+  UINT8 NumConfig;
+  EFI_STATUSStatus;
+  UINT8 Index;
+
+  //
+  // Override the device descriptor, Current device fail but the original
+  // descriptor pointer array is still exist.
+  //
+  Status  = UsbCtrlGetDesc (
+  UsbDev,
+  USB_DESC_TYPE_DEVICE,
+  0,
+  0,
+  UsbDev->DevDesc,
+  sizeof (EFI_USB_DEVICE_DESCRIPTOR)
+  );
+
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, "UsbRebuildDescTable: failed to override device descriptor 
- %r\n", Status));
+return Status;
+  }
+
+  NumConfig = UsbDev->DevDesc->Desc.NumConfigurations;
+  if (NumConfig == 0) {
+return EFI_DEVICE_ERROR;
+  }
+
+  DEBUG ((DEBUG_INFO, "UsbReuildDescTable: device has %d configures\n", 
NumConfig));
+
+  //
+  // Read each configurations, then parse them
+  //
+  for (Index = 0; Index < NumConfig; Index++) {
+Config = UsbGetOneConfig (UsbDev, Index);
+
+if (Config == NULL) {
+  DEBUG ((DEBUG_INFO, 

[edk2-devel] [PATCH v10 46/46] Maintainers.txt: Add reviewers for the OvmfPkg SEV-related files

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

Register reviewers for the SEV-related files in OvmfPkg.

Cc: Andrew Fish 
Cc: Laszlo Ersek 
Cc: Leif Lindholm 
Cc: Michael D Kinney 
Cc: Brijesh Singh 
Acked-by: Brijesh Singh 
Reviewed-by: Laszlo Ersek 
Signed-off-by: Tom Lendacky 
---
 Maintainers.txt | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/Maintainers.txt b/Maintainers.txt
index 32c9003a6209..cd10dc5e95fd 100644
--- a/Maintainers.txt
+++ b/Maintainers.txt
@@ -406,6 +406,16 @@ F: OvmfPkg/PvScsiDxe/
 R: Liran Alon 
 R: Nikita Leshenko 
 
+OvmfPkg: SEV-related modules
+F: OvmfPkg/AmdSevDxe/
+F: OvmfPkg/Include/Library/MemEncryptSevLib.h
+F: OvmfPkg/IoMmuDxe/AmdSevIoMmu.*
+F: OvmfPkg/Library/BaseMemEncryptSevLib/
+F: OvmfPkg/Library/VmgExitLib/
+F: OvmfPkg/PlatformPei/AmdSev.c
+R: Tom Lendacky 
+R: Brijesh Singh 
+
 OvmfPkg: TCG- and TPM2-related modules
 F: OvmfPkg/Include/IndustryStandard/QemuTpm.h
 F: OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
-- 
2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62568): https://edk2.groups.io/g/devel/message/62568
Mute This Topic: https://groups.io/mt/75506919/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v10 45/46] UefiCpuPkg/MpInitLib: Prepare SEV-ES guest APs for OS use

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

Before UEFI transfers control to the OS, it must park the AP. This is
done using the AsmRelocateApLoop function to transition into 32-bit
non-paging mode. For an SEV-ES guest, a few additional things must be
done:
  - AsmRelocateApLoop must be updated to support SEV-ES. This means
performing a VMGEXIT AP Reset Hold instead of an MWAIT or HLT loop.
  - Since the AP must transition to real mode, a small routine is copied
to the WakeupBuffer area. Since the WakeupBuffer will be used by
the AP during OS booting, it must be placed in reserved memory.
Additionally, the AP stack must be located where it can be accessed
in real mode.
  - Once the AP is in real mode it will transfer control to the
destination specified by the OS in the SEV-ES AP Jump Table. The
SEV-ES AP Jump Table address is saved by the hypervisor for the OS
using the GHCB VMGEXIT AP Jump Table exit code.

Cc: Eric Dong 
Cc: Ray Ni 
Cc: Laszlo Ersek 
Signed-off-by: Tom Lendacky 
---
 UefiCpuPkg/Library/MpInitLib/MpLib.h  |   8 +-
 UefiCpuPkg/Library/MpInitLib/DxeMpLib.c   |  54 +++-
 UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm | 131 --
 3 files changed, 175 insertions(+), 18 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h 
b/UefiCpuPkg/Library/MpInitLib/MpLib.h
index b1a9d99cb3eb..267aa5201c50 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
@@ -293,7 +293,8 @@ struct _CPU_MP_DATA {
   UINT64 GhcbBase;
 };
 
-#define AP_RESET_STACK_SIZE 64
+#define AP_SAFE_STACK_SIZE  128
+#define AP_RESET_STACK_SIZE AP_SAFE_STACK_SIZE
 
 #pragma pack(1)
 
@@ -349,8 +350,11 @@ VOID
   IN BOOLEAN MwaitSupport,
   IN UINTN   ApTargetCState,
   IN UINTN   PmCodeSegment,
+  IN UINTN   Pm16CodeSegment,
   IN UINTN   TopOfApStack,
-  IN UINTN   NumberToFinish
+  IN UINTN   NumberToFinish,
+  IN UINTN   SevEsAPJumpTable,
+  IN UINTN   WakeupBuffer
   );
 
 /**
diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c 
b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
index 9115ff9e3e30..7165bcf3124a 100644
--- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -85,6 +86,13 @@ GetWakeupBuffer (
 {
   EFI_STATUS  Status;
   EFI_PHYSICAL_ADDRESSStartAddress;
+  EFI_MEMORY_TYPE MemoryType;
+
+  if (PcdGetBool (PcdSevEsIsEnabled)) {
+MemoryType = EfiReservedMemoryType;
+  } else {
+MemoryType = EfiBootServicesData;
+  }
 
   //
   // Try to allocate buffer below 1M for waking vector.
@@ -97,7 +105,7 @@ GetWakeupBuffer (
   StartAddress = 0x88000;
   Status = gBS->AllocatePages (
   AllocateMaxAddress,
-  EfiBootServicesData,
+  MemoryType,
   EFI_SIZE_TO_PAGES (WakeupBufferSize),
   
   );
@@ -159,8 +167,10 @@ GetSevEsAPMemory (
   VOID
   )
 {
-  EFI_STATUSStatus;
-  EFI_PHYSICAL_ADDRESS  StartAddress;
+  EFI_STATUSStatus;
+  EFI_PHYSICAL_ADDRESS  StartAddress;
+  MSR_SEV_ES_GHCB_REGISTER  Msr;
+  GHCB  *Ghcb;
 
   //
   // Allocate 1 page for AP jump table page
@@ -176,6 +186,16 @@ GetSevEsAPMemory (
 
   DEBUG ((DEBUG_INFO, "Dxe: SevEsAPMemory = %lx\n", (UINTN) StartAddress));
 
+  //
+  // Save the SevEsAPMemory as the AP jump table.
+  //
+  Msr.GhcbPhysicalAddress = AsmReadMsr64 (MSR_SEV_ES_GHCB);
+  Ghcb = Msr.Ghcb;
+
+  VmgInit (Ghcb);
+  VmgExit (Ghcb, SVM_EXIT_AP_JUMP_TABLE, 0, (UINT64) (UINTN) StartAddress);
+  VmgDone (Ghcb);
+
   return (UINTN) StartAddress;
 }
 
@@ -330,17 +350,26 @@ RelocateApLoop (
   BOOLEANMwaitSupport;
   ASM_RELOCATE_AP_LOOP   AsmRelocateApLoopFunc;
   UINTN  ProcessorNumber;
+  UINTN  StackStart;
 
   MpInitLibWhoAmI ();
   CpuMpData= GetCpuMpData ();
   MwaitSupport = IsMwaitSupport ();
+  if (CpuMpData->SevEsIsEnabled) {
+StackStart = CpuMpData->SevEsAPResetStackStart;
+  } else {
+StackStart = mReservedTopOfApStack;
+  }
   AsmRelocateApLoopFunc = (ASM_RELOCATE_AP_LOOP) (UINTN) mReservedApLoopFunc;
   AsmRelocateApLoopFunc (
 MwaitSupport,
 CpuMpData->ApTargetCState,
 CpuMpData->PmCodeSegment,
-mReservedTopOfApStack - ProcessorNumber * AP_SAFE_STACK_SIZE,
-(UINTN) 
+CpuMpData->Pm16CodeSegment,
+StackStart - ProcessorNumber * AP_SAFE_STACK_SIZE,
+(UINTN) ,
+CpuMpData->SevEsAPBuffer,
+CpuMpData->WakeupBuffer
 );
   //
   // It should never reach here
@@ -374,6 +403,21 @@ MpInitChangeApLoopCallback (
   while (mNumberToFinish > 0) {
 CpuPause ();
   }
+
+  if 

[edk2-devel] [PATCH v10 40/46] UefiCpuPkg: Add a 16-bit protected mode code segment descriptor

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

A hypervisor is not allowed to update an SEV-ES guests register state,
so when booting an SEV-ES guest AP, the hypervisor is not allowed to
set the RIP to the guest requested value. Instead, an SEV-ES AP must be
transition from 64-bit long mode to 16-bit real mode in response to an
INIT-SIPI-SIPI sequence. This requires a 16-bit code segment descriptor.
For PEI, create this descriptor in the reset vector GDT table. For DXE,
create this descriptor from the newly reserved entry at location 0x28.

Cc: Eric Dong 
Cc: Ray Ni 
Cc: Laszlo Ersek 
Reviewed-by: Eric Dong 
Signed-off-by: Tom Lendacky 
---
 UefiCpuPkg/CpuDxe/CpuGdt.h  | 4 ++--
 UefiCpuPkg/CpuDxe/CpuGdt.c  | 8 
 UefiCpuPkg/ResetVector/Vtf0/Ia16/Real16ToFlat32.asm | 9 +
 3 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/UefiCpuPkg/CpuDxe/CpuGdt.h b/UefiCpuPkg/CpuDxe/CpuGdt.h
index 3a0210b2f172..1c94487cbee8 100644
--- a/UefiCpuPkg/CpuDxe/CpuGdt.h
+++ b/UefiCpuPkg/CpuDxe/CpuGdt.h
@@ -36,7 +36,7 @@ struct _GDT_ENTRIES {
   GDT_ENTRY LinearCode;
   GDT_ENTRY SysData;
   GDT_ENTRY SysCode;
-  GDT_ENTRY Spare4;
+  GDT_ENTRY SysCode16;
   GDT_ENTRY LinearData64;
   GDT_ENTRY LinearCode64;
   GDT_ENTRY Spare5;
@@ -49,7 +49,7 @@ struct _GDT_ENTRIES {
 #define LINEAR_CODE_SEL   OFFSET_OF (GDT_ENTRIES, LinearCode)
 #define SYS_DATA_SEL  OFFSET_OF (GDT_ENTRIES, SysData)
 #define SYS_CODE_SEL  OFFSET_OF (GDT_ENTRIES, SysCode)
-#define SPARE4_SELOFFSET_OF (GDT_ENTRIES, Spare4)
+#define SYS_CODE16_SELOFFSET_OF (GDT_ENTRIES, SysCode16)
 #define LINEAR_DATA64_SEL OFFSET_OF (GDT_ENTRIES, LinearData64)
 #define LINEAR_CODE64_SEL OFFSET_OF (GDT_ENTRIES, LinearCode64)
 #define SPARE5_SELOFFSET_OF (GDT_ENTRIES, Spare5)
diff --git a/UefiCpuPkg/CpuDxe/CpuGdt.c b/UefiCpuPkg/CpuDxe/CpuGdt.c
index 64efadeba601..a1ab543f2da5 100644
--- a/UefiCpuPkg/CpuDxe/CpuGdt.c
+++ b/UefiCpuPkg/CpuDxe/CpuGdt.c
@@ -70,14 +70,14 @@ STATIC GDT_ENTRIES GdtTemplate = {
 0x0,
   },
   //
-  // SPARE4_SEL
+  // SYS_CODE16_SEL
   //
   {
-0x0,// limit 15:0
+0x0,// limit 15:0
 0x0,// base 15:0
 0x0,// base 23:16
-0x0,// type
-0x0,// limit 19:16, flags
+0x09A,  // present, ring 0, code, execute/read
+0x08F,  // page-granular, 16-bit
 0x0,// base 31:24
   },
   //
diff --git a/UefiCpuPkg/ResetVector/Vtf0/Ia16/Real16ToFlat32.asm 
b/UefiCpuPkg/ResetVector/Vtf0/Ia16/Real16ToFlat32.asm
index ce4ebfffb688..0e79a3984b16 100644
--- a/UefiCpuPkg/ResetVector/Vtf0/Ia16/Real16ToFlat32.asm
+++ b/UefiCpuPkg/ResetVector/Vtf0/Ia16/Real16ToFlat32.asm
@@ -129,5 +129,14 @@ LINEAR_CODE64_SEL   equ $-GDT_BASE
 DB  0; base 31:24
 %endif
 
+; linear code segment descriptor
+LINEAR_CODE16_SEL equ $-GDT_BASE
+DW  0x   ; limit 15:0
+DW  0; base 15:0
+DB  0; base 23:16
+DB  PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(CODE32_TYPE)
+DB  
GRANULARITY_FLAG(1)|DEFAULT_SIZE32(0)|CODE64_FLAG(0)|UPPER_LIMIT(0xf)
+DB  0; base 31:24
+
 GDT_END:
 
-- 
2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62562): https://edk2.groups.io/g/devel/message/62562
Mute This Topic: https://groups.io/mt/75506899/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v10 44/46] OvmfPkg: Move the GHCB allocations into reserved memory

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

After having transitioned from UEFI to the OS, the OS will need to boot
the APs. For an SEV-ES guest, the APs will have been parked by UEFI using
GHCB pages allocated by UEFI. The hypervisor will write to the GHCB
SW_EXITINFO2 field of the GHCB when the AP is booted. As a result, the
GHCB pages must be marked reserved so that the OS does not attempt to use
them and experience memory corruption because of the hypervisor write.

Change the GHCB allocation from the default boot services memory to
reserved memory.

Cc: Jordan Justen 
Cc: Laszlo Ersek 
Cc: Ard Biesheuvel 
Reviewed-by: Laszlo Ersek 
Signed-off-by: Tom Lendacky 
---
 OvmfPkg/PlatformPei/AmdSev.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c
index a2b38c591236..4a515a484720 100644
--- a/OvmfPkg/PlatformPei/AmdSev.c
+++ b/OvmfPkg/PlatformPei/AmdSev.c
@@ -51,9 +51,11 @@ AmdSevEsInitialize (
 
   //
   // Allocate GHCB and per-CPU variable pages.
+  //   Since the pages must survive across the UEFI to OS transition
+  //   make them reserved.
   //
   GhcbPageCount = mMaxCpuCount * 2;
-  GhcbBase = AllocatePages (GhcbPageCount);
+  GhcbBase = AllocateReservedPages (GhcbPageCount);
   ASSERT (GhcbBase != NULL);
 
   GhcbBasePa = (PHYSICAL_ADDRESS)(UINTN) GhcbBase;
-- 
2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62566): https://edk2.groups.io/g/devel/message/62566
Mute This Topic: https://groups.io/mt/75506912/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v10 42/46] UefiCpuPkg: Allow AP booting under SEV-ES

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

Typically, an AP is booted using the INIT-SIPI-SIPI sequence. This
sequence is intercepted by the hypervisor, which sets the AP's registers
to the values requested by the sequence. At that point, the hypervisor can
start the AP, which will then begin execution at the appropriate location.

Under SEV-ES, AP booting presents some challenges since the hypervisor is
not allowed to alter the AP's register state. In this situation, we have
to distinguish between the AP's first boot and AP's subsequent boots.

First boot:
 Once the AP's register state has been defined (which is before the guest
 is first booted) it cannot be altered. Should the hypervisor attempt to
 alter the register state, the change would be detected by the hardware
 and the VMRUN instruction would fail. Given this, the first boot for the
 AP is required to begin execution with this initial register state, which
 is typically the reset vector. This prevents the BSP from directing the
 AP startup location through the INIT-SIPI-SIPI sequence.

 To work around this, the firmware will provide a build time reserved area
 that can be used as the initial IP value. The hypervisor can extract this
 location value by checking for the SEV-ES reset block GUID that must be
 located 48-bytes from the end of the firmware. The format of the SEV-ES
 reset block area is:

   0x00 - 0x01 - SEV-ES Reset IP
   0x02 - 0x03 - SEV-ES Reset CS Segment Base[31:16]
   0x04 - 0x05 - Size of the SEV-ES reset block
   0x06 - 0x15 - SEV-ES Reset Block GUID
   (00f771de-1a7e-4fcb-890e-68c77e2fb44e)

   The total size is 22 bytes. Any expansion to this block must be done
   by adding new values before existing values.

 The hypervisor will use the IP and CS values obtained from the SEV-ES
 reset block to set as the AP's initial values. The CS Segment Base
 represents the upper 16 bits of the CS segment base and must be left
 shifted by 16 bits to form the complete CS segment base value.

 Before booting the AP for the first time, the BSP must initialize the
 SEV-ES reset area. This consists of programming a FAR JMP instruction
 to the contents of a memory location that is also located in the SEV-ES
 reset area. The BSP must program the IP and CS values for the FAR JMP
 based on values drived from the INIT-SIPI-SIPI sequence.

Subsequent boots:
 Again, the hypervisor cannot alter the AP register state, so a method is
 required to take the AP out of halt state and redirect it to the desired
 IP location. If it is determined that the AP is running in an SEV-ES
 guest, then instead of calling CpuSleep(), a VMGEXIT is issued with the
 AP Reset Hold exit code (0x8004). The hypervisor will put the AP in
 a halt state, waiting for an INIT-SIPI-SIPI sequence. Once the sequence
 is recognized, the hypervisor will resume the AP. At this point the AP
 must transition from the current 64-bit long mode down to 16-bit real
 mode and begin executing at the derived location from the INIT-SIPI-SIPI
 sequence.

 Another change is around the area of obtaining the (x2)APIC ID during AP
 startup. During AP startup, the AP can't take a #VC exception before the
 AP has established a stack. However, the AP stack is set by using the
 (x2)APIC ID, which is obtained through CPUID instructions. A CPUID
 instruction will cause a #VC, so a different method must be used. The
 GHCB protocol supports a method to obtain CPUID information from the
 hypervisor through the GHCB MSR. This method does not require a stack,
 so it is used to obtain the necessary CPUID information to determine the
 (x2)APIC ID.

The new 16-bit protected mode GDT entry is used in order to transition
from 64-bit long mode down to 16-bit real mode.

A new assembler routine is created that takes the AP from 64-bit long mode
to 16-bit real mode.  This is located under 1MB in memory and transitions
from 64-bit long mode to 32-bit compatibility mode to 16-bit protected
mode and finally 16-bit real mode.

Cc: Eric Dong 
Cc: Ray Ni 
Cc: Laszlo Ersek 
Signed-off-by: Tom Lendacky 
---
 UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf |   3 +
 UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf |   3 +
 UefiCpuPkg/Library/MpInitLib/MpLib.h  |  60 
 UefiCpuPkg/Library/MpInitLib/DxeMpLib.c   |  70 +++-
 UefiCpuPkg/Library/MpInitLib/MpLib.c  | 336 +-
 UefiCpuPkg/Library/MpInitLib/PeiMpLib.c   |  19 +
 UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmFuncsArch.c  |   2 +-
 UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc   |   2 +-
 .../Library/MpInitLib/Ia32/MpFuncs.nasm   |  15 +
 UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc|   4 +-
 UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm | 239 +
 11 files changed, 738 insertions(+), 15 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf 
b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
index 583276595619..1771575c69c1 100644
--- 

[edk2-devel] [PATCH v10 41/46] UefiCpuPkg/MpInitLib: Add CPU MP data flag to indicate if SEV-ES is enabled

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

When starting APs in an SMP configuration, the AP needs to know if it is
running as an SEV-ES guest in order to assign a GHCB page.

Add a field to the CPU_MP_DATA structure that will indicate if SEV-ES is
enabled. This new field is set during MP library initialization with the
PCD value PcdSevEsIsEnabled. This flag can then be used to determine if
SEV-ES is enabled.

Cc: Eric Dong 
Cc: Ray Ni 
Cc: Laszlo Ersek 
Reviewed-by: Eric Dong 
Signed-off-by: Tom Lendacky 
---
 UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf | 1 +
 UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf | 1 +
 UefiCpuPkg/Library/MpInitLib/MpLib.h  | 2 ++
 UefiCpuPkg/Library/MpInitLib/MpLib.c  | 1 +
 4 files changed, 5 insertions(+)

diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf 
b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
index 9907f4157b09..583276595619 100644
--- a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
@@ -71,4 +71,5 @@ [Pcd]
   gUefiCpuPkgTokenSpaceGuid.PcdCpuApLoopMode   ## 
CONSUMES
   gUefiCpuPkgTokenSpaceGuid.PcdCpuApTargetCstate   ## 
SOMETIMES_CONSUMES
   gUefiCpuPkgTokenSpaceGuid.PcdCpuApStatusCheckIntervalInMicroSeconds  ## 
CONSUMES
+  gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled  ## 
CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard  ## 
CONSUMES
diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf 
b/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf
index 89ee9a79d8c5..4b3d39fbf36c 100644
--- a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf
+++ b/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf
@@ -61,6 +61,7 @@ [Pcd]
   gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchRegionSize ## CONSUMES
   gUefiCpuPkgTokenSpaceGuid.PcdCpuApLoopMode   ## CONSUMES
   gUefiCpuPkgTokenSpaceGuid.PcdCpuApTargetCstate   ## 
SOMETIMES_CONSUMES
+  gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled  ## CONSUMES
 
 [Ppis]
   gEdkiiPeiShadowMicrocodePpiGuid## SOMETIMES_CONSUMES
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h 
b/UefiCpuPkg/Library/MpInitLib/MpLib.h
index a8ca03efb8e3..5b46c295b6b2 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
@@ -276,6 +276,8 @@ struct _CPU_MP_DATA {
   // driver.
   //
   BOOLEANWakeUpByInitSipiSipi;
+
+  BOOLEANSevEsIsEnabled;
 };
 
 extern EFI_GUID mCpuInitMpLibHobGuid;
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c 
b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index 9b0660a5d4ea..2a3fbeef35f7 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -1704,6 +1704,7 @@ MpInitLibInitialize (
   CpuMpData->CpuData  = (CPU_AP_DATA *) (CpuMpData + 1);
   CpuMpData->CpuInfoInHob = (UINT64) (UINTN) (CpuMpData->CpuData + 
MaxLogicalProcessorNumber);
   InitializeSpinLock(>MpLock);
+  CpuMpData->SevEsIsEnabled = PcdGetBool (PcdSevEsIsEnabled);
 
   //
   // Make sure no memory usage outside of the allocated buffer.
-- 
2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62563): https://edk2.groups.io/g/devel/message/62563
Mute This Topic: https://groups.io/mt/75506902/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v10 43/46] OvmfPkg: Use the SEV-ES work area for the SEV-ES AP reset vector

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

A hypervisor is not allowed to update an SEV-ES guest's register state,
so when booting an SEV-ES guest AP, the hypervisor is not allowed to
set the RIP to the guest requested value. Instead an SEV-ES AP must be
re-directed from within the guest to the actual requested staring location
as specified in the INIT-SIPI-SIPI sequence.

Use the SEV-ES work area for the reset vector code that contains support
to jump to the desired RIP location after having been started. This is
required for only the very first AP reset.

This new OVMF source file, ResetVectorVtf0.asm, is used in place of the
original file through the use of the include path order set in
OvmfPkg/ResetVector/ResetVector.inf under "[BuildOptions]".

Cc: Jordan Justen 
Cc: Laszlo Ersek 
Cc: Ard Biesheuvel 
Reviewed-by: Laszlo Ersek 
Signed-off-by: Tom Lendacky 
---
 OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm | 100 +++
 OvmfPkg/ResetVector/ResetVector.nasmb|   1 +
 2 files changed, 101 insertions(+)
 create mode 100644 OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm

diff --git a/OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm 
b/OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm
new file mode 100644
index ..980e0138e7fe
--- /dev/null
+++ b/OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm
@@ -0,0 +1,100 @@
+;--
+; @file
+; First code executed by processor after resetting.
+; Derived from UefiCpuPkg/ResetVector/Vtf0/Ia16/ResetVectorVtf0.asm
+;
+; Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;
+;--
+
+BITS16
+
+ALIGN   16
+
+;
+; Pad the image size to 4k when page tables are in VTF0
+;
+; If the VTF0 image has page tables built in, then we need to make
+; sure the end of VTF0 is 4k above where the page tables end.
+;
+; This is required so the page tables will be 4k aligned when VTF0 is
+; located just below 0x1 (4GB) in the firmware device.
+;
+%ifdef ALIGN_TOP_TO_4K_FOR_PAGING
+TIMES (0x1000 - ($ - EndOfPageTables) - 0x20) DB 0
+%endif
+
+;
+; SEV-ES Processor Reset support
+;
+; sevEsResetBlock:
+;   For the initial boot of an AP under SEV-ES, the "reset" RIP must be
+;   programmed to the RAM area defined by SEV_ES_AP_RESET_IP. A known offset
+;   and GUID will be used to locate this block in the firmware and extract
+;   the build time RIP value. The GUID must always be 48 bytes from the
+;   end of the firmware.
+;
+;   0xffca (-0x36) - IP value
+;   0xffcc (-0x34) - CS segment base [31:16]
+;   0xffce (-0x32) - Size of the SEV-ES reset block
+;   0xffd0 (-0x30) - SEV-ES reset block GUID
+;(00f771de-1a7e-4fcb-890e-68c77e2fb44e)
+;
+;   A hypervisor reads the CS segement base and IP value. The CS segment base
+;   value represents the high order 16-bits of the CS segment base, so the
+;   hypervisor must left shift the value of the CS segement base by 16 bits to
+;   form the full CS segment base for the CS segment register. It would then
+;   program the EIP register with the IP value as read.
+;
+
+TIMES (32 - (sevEsResetBlockEnd - sevEsResetBlockStart)) DB 0
+
+sevEsResetBlockStart:
+DD  SEV_ES_AP_RESET_IP
+DW  sevEsResetBlockEnd - sevEsResetBlockStart
+DB  0xDE, 0x71, 0xF7, 0x00, 0x7E, 0x1A, 0xCB, 0x4F
+DB  0x89, 0x0E, 0x68, 0xC7, 0x7E, 0x2F, 0xB4, 0x4E
+sevEsResetBlockEnd:
+
+ALIGN   16
+
+applicationProcessorEntryPoint:
+;
+; Application Processors entry point
+;
+; GenFv generates code aligned on a 4k boundary which will jump to this
+; location.  (0xffe0)  This allows the Local APIC Startup IPI to be
+; used to wake up the application processors.
+;
+jmp EarlyApInitReal16
+
+ALIGN   8
+
+DD  0
+
+;
+; The VTF signature
+;
+; VTF-0 means that the VTF (Volume Top File) code does not require
+; any fixups.
+;
+vtfSignature:
+DB  'V', 'T', 'F', 0
+
+ALIGN   16
+
+resetVector:
+;
+; Reset Vector
+;
+; This is where the processor will begin execution
+;
+nop
+nop
+jmp EarlyBspInitReal16
+
+ALIGN   16
+
+fourGigabytes:
+
diff --git a/OvmfPkg/ResetVector/ResetVector.nasmb 
b/OvmfPkg/ResetVector/ResetVector.nasmb
index 762661115d50..4913b379a993 100644
--- a/OvmfPkg/ResetVector/ResetVector.nasmb
+++ b/OvmfPkg/ResetVector/ResetVector.nasmb
@@ -82,5 +82,6 @@
 
 %include "Main.asm"
 
+  %define SEV_ES_AP_RESET_IP  FixedPcdGet32 (PcdSevEsWorkAreaBase)
 %include "Ia16/ResetVectorVtf0.asm"
 
-- 
2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62565): https://edk2.groups.io/g/devel/message/62565
Mute This Topic: https://groups.io/mt/75506909/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  

[edk2-devel] [PATCH] OvmfPkg/SmmControl2Dxe: negotiate ICH9_LPC_SMI_F_CPU_HOTPLUG

2020-07-14 Thread Laszlo Ersek
The ICH9_LPC_SMI_F_BROADCAST and ICH9_LPC_SMI_F_CPU_HOTPLUG feature flags
cause QEMU to behave as follows:

  BROADCAST  CPU_HOTPLUG  use case / behavior
  -  ---  
  clear  clearOVMF built without SMM_REQUIRE; or very old OVMF
  (from before commit a316d7ac91d3 / 2017-02-07).
  QEMU permits CPU hotplug operations, and does
  not cause the OS to inject an SMI upon hotplug.
  Firmware is not expected to be aware of hotplug
  events.

  clear  set  Invalid feature set; QEMU rejects the feature
  negotiation.

  setclearOVMF after a316d7ac91d3 / 2017-02-07, built with
  SMM_REQUIRE, but no support for CPU hotplug.
  QEMU gracefully refuses hotplug operations.

  setset  OVMF after a316d7ac91d3 / 2017-02-07, built with
  SMM_REQUIRE, and supporting CPU hotplug. QEMU
  permits CPU hotplug operations, and causes the
  OS to inject an SMI upon hotplug. Firmware is
  expected to deal with hotplug events.

Negotiate ICH9_LPC_SMI_F_CPU_HOTPLUG -- but only if SEV is disabled, as
OvmfPkg/CpuHotplugSmm can't deal with SEV yet.

Cc: Ard Biesheuvel 
Cc: Boris Ostrovsky 
Cc: Igor Mammedov 
Cc: Jordan Justen 
Cc: Liran Alon 
Cc: Philippe Mathieu-Daudé 
Signed-off-by: Laszlo Ersek 
---

Notes:
This is the OVMF counterpart to Igor's QEMU series:

- [RFC 0/3] x86: fix cpu hotplug with secure boot
  https://lists.gnu.org/archive/html/qemu-devel/2020-07/msg03746.html
  message-id: <20200710161704.309824-1-imamm...@redhat.com>

Repo:   https://pagure.io/lersek/edk2.git
Branch: negotiate_cpuhp_with_smi_rhbz1849177

 OvmfPkg/SmmControl2Dxe/SmmControl2Dxe.inf |  1 +
 OvmfPkg/SmmControl2Dxe/SmiFeatures.c  | 26 ++--
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/OvmfPkg/SmmControl2Dxe/SmmControl2Dxe.inf 
b/OvmfPkg/SmmControl2Dxe/SmmControl2Dxe.inf
index 3abed141e644..b8fdea8deb84 100644
--- a/OvmfPkg/SmmControl2Dxe/SmmControl2Dxe.inf
+++ b/OvmfPkg/SmmControl2Dxe/SmmControl2Dxe.inf
@@ -46,6 +46,7 @@ [LibraryClasses]
   BaseLib
   DebugLib
   IoLib
+  MemEncryptSevLib
   MemoryAllocationLib
   PcdLib
   PciLib
diff --git a/OvmfPkg/SmmControl2Dxe/SmiFeatures.c 
b/OvmfPkg/SmmControl2Dxe/SmiFeatures.c
index 6210b7515e3e..c9d875543205 100644
--- a/OvmfPkg/SmmControl2Dxe/SmiFeatures.c
+++ b/OvmfPkg/SmmControl2Dxe/SmiFeatures.c
@@ -9,6 +9,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -21,6 +22,12 @@
 // "etc/smi/supported-features" and "etc/smi/requested-features" fw_cfg files.
 //
 #define ICH9_LPC_SMI_F_BROADCAST BIT0
+//
+// The following bit value stands for "enable CPU hotplug, and inject an SMI
+// with control value ICH9_APM_CNT_CPU_HOTPLUG upon hotplug", in the
+// "etc/smi/supported-features" and "etc/smi/requested-features" fw_cfg files.
+//
+#define ICH9_LPC_SMI_F_CPU_HOTPLUG BIT1
 
 //
 // Provides a scratch buffer (allocated in EfiReservedMemoryType type memory)
@@ -67,6 +74,7 @@ NegotiateSmiFeatures (
   UINTNSupportedFeaturesSize;
   UINTNRequestedFeaturesSize;
   UINTNFeaturesOkSize;
+  UINT64   RequestedFeaturesMask;
 
   //
   // Look up the fw_cfg files used for feature negotiation. The selector keys
@@ -104,9 +112,16 @@ NegotiateSmiFeatures (
   QemuFwCfgReadBytes (sizeof mSmiFeatures, );
 
   //
-  // We want broadcast SMI and nothing else.
+  // We want broadcast SMI, SMI on CPU hotplug, and nothing else.
   //
-  mSmiFeatures &= ICH9_LPC_SMI_F_BROADCAST;
+  RequestedFeaturesMask = ICH9_LPC_SMI_F_BROADCAST;
+  if (!MemEncryptSevIsEnabled ()) {
+//
+// For now, we only support hotplug with SEV disabled.
+//
+RequestedFeaturesMask |= ICH9_LPC_SMI_F_CPU_HOTPLUG;
+  }
+  mSmiFeatures &= RequestedFeaturesMask;
   QemuFwCfgSelectItem (mRequestedFeaturesItem);
   QemuFwCfgWriteBytes (sizeof mSmiFeatures, );
 
@@ -144,6 +159,13 @@ NegotiateSmiFeatures (
 DEBUG ((DEBUG_INFO, "%a: using SMI broadcast\n", __FUNCTION__));
   }
 
+  if ((mSmiFeatures & ICH9_LPC_SMI_F_CPU_HOTPLUG) == 0) {
+DEBUG ((DEBUG_INFO, "%a: CPU hotplug not negotiated\n", __FUNCTION__));
+  } else {
+DEBUG ((DEBUG_INFO, "%a: CPU hotplug with SMI negotiated\n",
+  __FUNCTION__));
+  }
+
   //
   // Negotiation successful (although we may not have gotten the optimal
   // feature set).
-- 
2.19.1.3.g30247aa5d201


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62561): https://edk2.groups.io/g/devel/message/62561
Mute This Topic: https://groups.io/mt/75505395/21656
Group Owner: devel+ow...@edk2.groups.io

[edk2-devel] [PATCH v3 3/3] AzurePipelines : Pr Gate: Turn on HBUT for CryptoPkg

2020-07-14 Thread matthewfcarlson
From: Matthew Carlson 

Turns on Host Based Unit Tests for CryptoPkg by enabling the target
NOOPT in the CI pipeline.

Cc: Sean Brogan 
Cc: Bret Barkelew 
Cc: Michael D Kinney 
Cc: Liming Gao 

Signed-off-by: Matthew Carlson 
---
 .azurepipelines/templates/pr-gate-build-job.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.azurepipelines/templates/pr-gate-build-job.yml 
b/.azurepipelines/templates/pr-gate-build-job.yml
index a9f89aa68451..e84ba80030b1 100644
--- a/.azurepipelines/templates/pr-gate-build-job.yml
+++ b/.azurepipelines/templates/pr-gate-build-job.yml
@@ -40,7 +40,7 @@ jobs:
 Build.Targets: 'DEBUG,RELEASE,NO-TARGET,NOOPT'
   TARGET_CRYPTO:
 Build.Pkgs: 'CryptoPkg'
-Build.Targets: 'DEBUG,RELEASE,NO-TARGET'
+Build.Targets: 'DEBUG,RELEASE,NO-TARGET,NOOPT'
   TARGET_SECURITY:
 Build.Pkgs: 'SecurityPkg'
 Build.Targets: 'DEBUG,RELEASE,NO-TARGET'
-- 
2.27.0.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62559): https://edk2.groups.io/g/devel/message/62559
Mute This Topic: https://groups.io/mt/75505001/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/3] UnitTestFrameworkPkg : BaseTimerLibPosix: Adds a host-based timer Lib

2020-07-14 Thread matthewfcarlson
From: Matthew Carlson 

This adds a host based BaseTimerLib that won't assert.

Cc: Michael D Kinney 
Cc: Sean Brogan 
Cc: Bret Barkelew 
Signed-off-by: Matthew Carlson 
---
 UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/TimerLibPosix.c   | 
132 
 UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/BaseTimerLibPosix.inf |  
33 +
 UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/BaseTimerLibPosix.uni |  
14 +++
 UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc |   
1 +
 UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc  |   
1 +
 5 files changed, 181 insertions(+)

diff --git 
a/UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/TimerLibPosix.c 
b/UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/TimerLibPosix.c
new file mode 100644
index ..3c1394e3b21b
--- /dev/null
+++ b/UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/TimerLibPosix.c
@@ -0,0 +1,132 @@
+/** @file
+  A semi-functional instance of the Timer Library.
+
+  Copyright (c) Microsoft Corporation.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/**
+  Stalls the CPU for at least the given number of microseconds.
+
+  @param  MicroSeconds  The minimum number of microseconds to delay.
+  @return The value of MicroSeconds inputted.
+
+**/
+UINTN
+EFIAPI
+MicroSecondDelay (
+  IN  UINTN MicroSeconds
+  )
+{
+  // Since this is a host based test, we don't actually want to stall
+  return MicroSeconds;
+}
+
+/**
+  Stalls the CPU for at least the given number of nanoseconds.
+
+  @param  NanoSeconds The minimum number of nanoseconds to delay.
+  @return The value of NanoSeconds inputted.
+
+**/
+UINTN
+EFIAPI
+NanoSecondDelay (
+  IN  UINTN NanoSeconds
+  )
+{
+  // Since this is a host based test, we don't actually want to stall
+  return NanoSeconds;
+}
+
+/**
+  Retrieves the current value of a 64-bit free running performance counter.
+
+  The counter can either count up by 1 or count down by 1. If the physical
+  performance counter counts by a larger increment, then the counter values
+  must be translated. The properties of the counter can be retrieved from
+  GetPerformanceCounterProperties().
+
+  @return The current value of the free running performance counter.
+
+**/
+UINT64
+EFIAPI
+GetPerformanceCounter (
+  VOID
+  )
+{
+  struct timespec ts;
+  timespec_get(, TIME_UTC);
+  // Return the current number of nanoseconds on the clock
+  return ts.tv_nsec;
+}
+
+/**
+  Retrieves the 64-bit frequency in Hz and the range of performance counter
+  values.
+
+  If StartValue is not NULL, then the value that the performance counter starts
+  with immediately after is it rolls over is returned in StartValue. If
+  EndValue is not NULL, then the value that the performance counter end with
+  immediately before it rolls over is returned in EndValue. The 64-bit
+  frequency of the performance counter in Hz is always returned. If StartValue
+  is less than EndValue, then the performance counter counts up. If StartValue
+  is greater than EndValue, then the performance counter counts down. For
+  example, a 64-bit free running counter that counts up would have a StartValue
+  of 0 and an EndValue of 0x. A 24-bit free running counter
+  that counts down would have a StartValue of 0xFF and an EndValue of 0.
+
+  @param  StartValue  The value the performance counter starts with when it
+  rolls over.
+  @param  EndValueThe value that the performance counter ends with before
+  it rolls over.
+
+  @return The frequency in Hz.
+
+**/
+UINT64
+EFIAPI
+GetPerformanceCounterProperties (
+  OUT  UINT64*StartValue,  OPTIONAL
+  OUT  UINT64*EndValue OPTIONAL
+  )
+{
+  if ( EndValue != NULL ) {
+*EndValue = MAX_UINT64;
+  }
+  if ( StartValue != NULL ) {
+*StartValue = 0;
+  }
+  // Return the number of nanoseconds in a second
+  return 10;
+}
+
+/**
+  Converts elapsed ticks of performance counter to time in nanoseconds.
+
+  This function converts the elapsed ticks of running performance counter to
+  time value in unit of nanoseconds.
+
+  @param  Ticks The number of elapsed ticks of running performance counter.
+
+  @return The elapsed time in nanoseconds.
+
+**/
+UINT64
+EFIAPI
+GetTimeInNanoSecond (
+  IN  UINT64 Ticks
+  )
+{
+  return Ticks;
+}
diff --git 
a/UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/BaseTimerLibPosix.inf 
b/UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/BaseTimerLibPosix.inf
new file mode 100644
index ..797f04bb125b
--- /dev/null
+++ b/UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/BaseTimerLibPosix.inf
@@ -0,0 +1,33 @@
+## @file
+#  An instance of Timer Library for posix compliant hosts.
+#
+#  A semi-functional 

[edk2-devel] [PATCH v3 0/3] Add Unit Tests for BaseCryptLib to CryptoPkg

2020-07-14 Thread matthewfcarlson
From: Matthew Carlson 

This turns on Host Based Unit Tests for CryptoPkg, adds the unit test itself, 
and 
adds a POSIX BaseTimerLib for unit tests.

Matthew Carlson (3):
  UnitTestFrameworkPkg : BaseTimerLibPosix: Adds a host-based timer Lib
  CryptoPkg: BaseCryptLib: Add unit tests (Host and Shell based)
  AzurePipelines : Pr Gate: Turn on HBUT for CryptoPkg

 CryptoPkg/Library/BaseCryptLib/SysCall/UnitTestHostCrtWrapper.c
|   93 ++
 CryptoPkg/Test/UnitTest/Library/BaseCryptLib/AuthenticodeTests.c   
| 1002 
 CryptoPkg/Test/UnitTest/Library/BaseCryptLib/BaseCryptLibUnitTests.c   
|   66 ++
 CryptoPkg/Test/UnitTest/Library/BaseCryptLib/BlockCipherTests.c
|  293 ++
 CryptoPkg/Test/UnitTest/Library/BaseCryptLib/DhTests.c 
|  106 +++
 CryptoPkg/Test/UnitTest/Library/BaseCryptLib/HashTests.c   
|  197 
 CryptoPkg/Test/UnitTest/Library/BaseCryptLib/HmacTests.c   
|  184 
 CryptoPkg/Test/UnitTest/Library/BaseCryptLib/OaepEncryptTests.c
|  308 ++
 CryptoPkg/Test/UnitTest/Library/BaseCryptLib/Pkcs5Pbkdf2Tests.c
|   71 ++
 CryptoPkg/Test/UnitTest/Library/BaseCryptLib/Pkcs7EkuTests.c   
|  524 ++
 CryptoPkg/Test/UnitTest/Library/BaseCryptLib/RandTests.c   
|   51 +
 CryptoPkg/Test/UnitTest/Library/BaseCryptLib/RsaPkcs7Tests.c   
|  415 
 CryptoPkg/Test/UnitTest/Library/BaseCryptLib/RsaTests.c
|  310 ++
 CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TSTests.c 
|  335 +++
 CryptoPkg/Test/UnitTest/Library/BaseCryptLib/UnitTestMain.c
|   81 ++
 CryptoPkg/Test/UnitTest/Library/BaseCryptLib/UnitTestMainBCOP.c
|   58 ++
 UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/TimerLibPosix.c   
|  132 +++
 .azurepipelines/templates/pr-gate-build-job.yml
|2 +-
 CryptoPkg/CryptoPkg.ci.yaml
|4 +
 CryptoPkg/CryptoPkg.dsc
|   26 +
 CryptoPkg/Library/BaseCryptLib/UnitTestHostBaseCryptLib.inf
|   90 ++
 CryptoPkg/Test/UnitTest/CryptoPkgHostUnitTest.dsc  
|   35 +
 CryptoPkg/Test/UnitTest/Library/BaseCryptLib/Pkcs7EkuTestSignatures.h  
|  789 +++
 CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLib.h
|  121 +++
 CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost.inf  
|   46 +
 CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibUefiShell.inf 
|   49 +
 
CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestEKUCerts/ChainCreationInstructions.txt
|   92 ++
 CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestEKUCerts/CreateTestCerts.cmd  
|   11 +
 
CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestEKUCerts/SignFirmwareWithEKUs.cmd
 |   76 ++
 
CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestEKUCerts/TestEKUParsingIssuingCA.ini
  |   45 +
 
CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestEKUCerts/TestEKUParsingLeafSigner.ini
 |   25 +
 
CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestEKUCerts/TestEKUParsingLeafSignerPid1.ini
 |   24 +
 
CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestEKUCerts/TestEKUParsingLeafSignerPid12345.ini
 |   27 +
 
CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestEKUCerts/TestEKUParsingNoEKUsInSigner.ini
 |   16 +
 
CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestEKUCerts/TestEKUParsingPolicyCA.ini
   |   28 +
 
CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestEKUCerts/TestEKUParsingRoot.ini
   |   28 +
 UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/BaseTimerLibPosix.inf 
|   33 +
 UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/BaseTimerLibPosix.uni 
|   14 +
 UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc 
|1 +
 UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc  
|1 +
 40 files changed, 5808 insertions(+), 1 deletion(-)
 create mode 100644 
CryptoPkg/Library/BaseCryptLib/SysCall/UnitTestHostCrtWrapper.c
 create mode 100644 
CryptoPkg/Test/UnitTest/Library/BaseCryptLib/AuthenticodeTests.c
 create mode 100644 

[edk2-devel] [PATCH v3 8/8] ShellPkg/AcpiView: Refactor table parsers

2020-07-14 Thread Tomas Pilar (tpilar)
The tests for checking specific constraints and checking
for buffer overflows have been simplified to use a standard
set of templates defined in the logging facility.

This regularises some of the error handling and makes
it easier to write more tests like this in the future.

Cc: Ray Ni 
Cc: Zhichao Gao 
Signed-off-by: Tomas Pilar 
---
 .../UefiShellAcpiViewCommandLib/AcpiParser.c  |  25 ---
 .../UefiShellAcpiViewCommandLib/AcpiParser.h  |  18 --
 .../Arm/SbbrValidator.c   |  65 +++---
 .../Parsers/Dbg2/Dbg2Parser.c | 119 ---
 .../Parsers/Fadt/FadtParser.c |  54 ++---
 .../Parsers/Gtdt/GtdtParser.c |  80 ++-
 .../Parsers/Iort/IortParser.c | 197 +++---
 .../Parsers/Madt/MadtParser.c | 101 +++--
 .../Parsers/Mcfg/McfgParser.c |  11 +-
 .../Parsers/Pptt/PpttParser.c | 165 ---
 .../Parsers/Rsdp/RsdpParser.c |  38 +---
 .../Parsers/Slit/SlitParser.c | 124 +--
 .../Parsers/Spcr/SpcrParser.c |  23 +-
 .../Parsers/Srat/SratParser.c | 188 +
 .../Parsers/Xsdt/XsdtParser.c |  96 +++--
 15 files changed, 390 insertions(+), 914 deletions(-)

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
index 16b8d1f80bc2..1c8664910515 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
@@ -25,31 +25,6 @@ STATIC CONST ACPI_PARSER AcpiHeaderParser[] = {
   PARSE_ACPI_HEADER ()
 };
 
-/**
-  This function increments the ACPI table error counter.
-**/
-VOID
-EFIAPI
-IncrementErrorCount (
-  VOID
-  )
-{
-  mTableErrorCount++;
-}
-
-/**
-  This function increments the ACPI table warning counter.
-**/
-VOID
-EFIAPI
-IncrementWarningCount (
-  VOID
-  )
-{
-  mTableWarningCount++;
-}
-
-
 /**
   This function verifies the ACPI table checksum.
 
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
index bd3cdb774fb5..cdae433fef3b 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
@@ -18,24 +18,6 @@
 /// that allows us to process the log options.
 #define RSDP_TABLE_INFO  SIGNATURE_32('R', 'S', 'D', 'P')
 
-/**
-  This function increments the ACPI table error counter.
-**/
-VOID
-EFIAPI
-IncrementErrorCount (
-  VOID
-  );
-
-/**
-  This function increments the ACPI table warning counter.
-**/
-VOID
-EFIAPI
-IncrementWarningCount (
-  VOID
-  );
-
 /**
   This function verifies the ACPI table checksum.
 
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Arm/SbbrValidator.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Arm/SbbrValidator.c
index d3284417fa5f..ba80a5ab3b40 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/Arm/SbbrValidator.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/Arm/SbbrValidator.c
@@ -18,15 +18,16 @@
 #include 
 #include 
 #include "AcpiParser.h"
+#include "AcpiViewLog.h"
 #include "Arm/SbbrValidator.h"
 
 /**
   SBBR specification version strings
 **/
-STATIC CONST CHAR8* ArmSbbrVersions[ArmSbbrVersionMax] = {
-  "1.0", // ArmSbbrVersion_1_0
-  "1.1", // ArmSbbrVersion_1_1
-  "1.2"  // ArmSbbrVersion_1_2
+STATIC CONST CHAR16* ArmSbbrVersions[ArmSbbrVersionMax] = {
+  L"SBBR-v1.0", // ArmSbbrVersion_1_0
+  L"SBBR-v1.1", // ArmSbbrVersion_1_1
+  L"SBBR-v1.2"  // ArmSbbrVersion_1_2
 };
 
 /**
@@ -96,6 +97,16 @@ STATIC ACPI_TABLE_COUNTER ArmSbbrTableCounts[] = {
   {EFI_ACPI_6_3_PROCESSOR_PROPERTIES_TOPOLOGY_TABLE_STRUCTURE_SIGNATURE, 0}
 };
 
+STATIC_ASSERT (
+  ARRAY_SIZE (ArmSbbr10Mandatory) <= ARRAY_SIZE (ArmSbbrTableCounts),
+  "Incompatible mandatory array tables");
+STATIC_ASSERT (
+  ARRAY_SIZE (ArmSbbr11Mandatory) <= ARRAY_SIZE (ArmSbbrTableCounts),
+  "Incompatible mandatory array tables");
+STATIC_ASSERT (
+  ARRAY_SIZE (ArmSbbr12Mandatory) <= ARRAY_SIZE (ArmSbbrTableCounts),
+  "Incompatible mandatory array tables");
+
 /**
   Reset the platform ACPI table instance count for all SBBR-mandatory tables.
 **/
@@ -160,7 +171,6 @@ ArmSbbrReqsValidate (
   UINT32Table;
   UINT32Index;
   UINT32MandatoryTable;
-  CONST UINT8*  SignaturePtr;
   BOOLEAN   IsArmSbbrViolated;
 
   if (Version >= ArmSbbrVersionMax) {
@@ -172,51 +182,30 @@ ArmSbbrReqsValidate (
   // Go through the list of mandatory tables for the input SBBR version
   for (Table = 0; Table < ArmSbbrReqs[Version].TableCount; Table++) {
 MandatoryTable = ArmSbbrReqs[Version].Tables[Table];
-SignaturePtr = (CONST UINT8*)(UINTN)
 
 // Locate the instance count for the table with the given signature
-Index = 0;
-while ((Index < ARRAY_SIZE (ArmSbbrTableCounts)) &&
-   

[edk2-devel] [PATCH v3 4/8] ShellPkg/AcpiView: Create a logging facility

2020-07-14 Thread Tomas Pilar (tpilar)
Extract error and warning logging into separate methods. Fold
highlighting and other output properties into the logging methods.

Cc: Ray Ni 
Cc: Zhichao Gao 
Signed-off-by: Tomas Pilar 
---
 .../UefiShellAcpiViewCommandLib/AcpiParser.c  |   5 +-
 .../UefiShellAcpiViewCommandLib/AcpiViewLog.c | 338 ++
 .../UefiShellAcpiViewCommandLib/AcpiViewLog.h | 192 ++
 .../UefiShellAcpiViewCommandLib.inf   |   2 +
 4 files changed, 533 insertions(+), 4 deletions(-)
 create mode 100644 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLog.c
 create mode 100644 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLog.h

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
index 7017fa93efae..b88594cf3865 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
@@ -11,13 +11,10 @@
 #include "AcpiParser.h"
 #include "AcpiView.h"
 #include "AcpiViewConfig.h"
+#include "AcpiViewLog.h"
 
 STATIC UINT32   gIndent;
 
-// Publicly accessible error and warning counters.
-UINT32   mTableErrorCount;
-UINT32   mTableWarningCount;
-
 STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
 
 /**
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLog.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLog.c
new file mode 100644
index ..7ec276ac7528
--- /dev/null
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLog.c
@@ -0,0 +1,338 @@
+/** @file
+  'acpiview' logging and output facility
+
+  Copyright (c) 2020, ARM Limited. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include "AcpiViewLog.h"
+#include "AcpiViewConfig.h"
+#include "AcpiParser.h"
+#include 
+#include 
+
+static CHAR16 mOutputBuffer [MAX_OUTPUT_SIZE] = { 0 };
+
+// String descriptions of error types
+static const CHAR16* mErrorTypeDesc [ACPI_ERROR_MAX] = {
+  L"Not an error",///< ACPI_ERROR_NONE
+  L"Generic", ///< ACPI_ERROR_GENERIC
+  L"Checksum",///< ACPI_ERROR_CSUM
+  L"Parsing", ///< ACPI_ERROR_PARSE
+  L"Length",  ///< ACPI_ERROR_LENGTH
+  L"Value",   ///< ACPI_ERROR_VALUE
+  L"Cross-check", ///< ACPI_ERROR_CROSS
+};
+
+// Publicly accessible error and warning counters.
+UINT32   mTableErrorCount;
+UINT32   mTableWarningCount;
+
+/**
+  Change the attributes of the standard output console
+  to change the colour of the text according to the given
+  severity of a log message.
+
+  @param[in] Severity  The severity of the log message that is being
+   annotated with changed colour text.
+  @param[in] OriginalAttribute The current attributes of ConOut that will
+   be modified.
+**/
+static
+VOID
+EFIAPI
+ApplyColor (
+  IN ACPI_LOG_SEVERITY Severity,
+  IN UINTN OriginalAttribute
+  )
+{
+  if (!mConfig.ColourHighlighting) {
+return;
+  }
+
+  // Strip the foreground colour
+  UINTN NewAttribute = OriginalAttribute & 0xF0;
+
+  // Add specific foreground colour based on severity
+  switch (Severity) {
+  case ACPI_DEBUG:
+NewAttribute |= EFI_DARKGRAY;
+break;
+  case ACPI_HIGHLIGHT:
+NewAttribute |= EFI_LIGHTBLUE;
+break;
+  case ACPI_GOOD:
+NewAttribute |= EFI_GREEN;
+break;
+  case ACPI_ITEM:
+  case ACPI_WARN:
+NewAttribute |= EFI_YELLOW;
+break;
+  case ACPI_BAD:
+  case ACPI_ERROR:
+  case ACPI_FATAL:
+NewAttribute |= EFI_RED;
+break;
+  case ACPI_INFO:
+  default:
+NewAttribute |= OriginalAttribute;
+break;
+  }
+
+  gST->ConOut->SetAttribute (gST->ConOut, NewAttribute);
+}
+
+/**
+  Restore ConOut text attributes.
+
+  @param[in] OriginalAttribute The attribute set that will be restored.
+**/
+static
+VOID
+EFIAPI
+RestoreColor(
+  IN UINTN OriginalAttribute
+  )
+{
+  gST->ConOut->SetAttribute (gST->ConOut, OriginalAttribute);
+}
+
+/**
+  Formats and prints an ascii string to screen.
+
+  @param[in] Format String that will be formatted and printed.
+  @param[in] Marker The marker for variable parameters to be formatted.
+**/
+static
+VOID
+EFIAPI
+AcpiViewVSOutput (
+  IN const CHAR16  *Format,
+  IN VA_LIST   Marker
+  )
+{
+  UnicodeVSPrint (mOutputBuffer, sizeof(mOutputBuffer), Format, Marker);
+  gST->ConOut->OutputString (gST->ConOut, mOutputBuffer);
+}
+
+/**
+  Formats and prints and ascii string to screen.
+
+  @param[in] Format String that will be formatted and printed.
+  @param[in] ...A variable number of parameters that will be formatted.
+**/
+VOID
+EFIAPI
+AcpiViewOutput (
+  IN const CHAR16 *Format,
+  IN ...
+  )
+{
+  VA_LIST Marker;
+  VA_START (Marker, Format);
+
+  AcpiViewVSOutput (Format, Marker);
+
+  VA_END (Marker);
+}
+
+
+/**
+  Prints the base file name given a full file path.
+
+  @param[in] FullName Fully qualified file path
+**/
+VOID
+EFIAPI
+PrintFileName (
+  

[edk2-devel] [PATCH v3 7/8] ShellPkg/AcpiView: Refactor AcpiView

2020-07-14 Thread Tomas Pilar (tpilar)
Refactor logging using the AcpiViewLog facility.
Trim some of the source to more elegant state.

Cc: Ray Ni 
Cc: Zhichao Gao 
Signed-off-by: Tomas Pilar 
---
 .../UefiShellAcpiViewCommandLib/AcpiParser.c  | 225 --
 .../UefiShellAcpiViewCommandLib/AcpiParser.h  |   6 +-
 .../AcpiTableParser.c |  52 ++--
 .../AcpiTableParser.h |   2 +-
 .../UefiShellAcpiViewCommandLib/AcpiView.c| 187 +--
 .../FieldFormatHelper.h   | 106 +
 6 files changed, 188 insertions(+), 390 deletions(-)

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
index 65108e25ff96..16b8d1f80bc2 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
@@ -8,6 +8,9 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 #include "AcpiParser.h"
 #include "AcpiView.h"
 #include "AcpiViewConfig.h"
@@ -46,6 +49,7 @@ IncrementWarningCount (
   mTableWarningCount++;
 }
 
+
 /**
   This function verifies the ACPI table checksum.
 
@@ -69,12 +73,7 @@ VerifyChecksum (
 {
   UINTN ByteCount;
   UINT8 Checksum;
-  UINTN OriginalAttribute;
 
-  //
-  // set local variables to suppress incorrect compiler/analyzer warnings
-  //
-  OriginalAttribute = 0;
   ByteCount = 0;
   Checksum = 0;
 
@@ -84,29 +83,10 @@ VerifyChecksum (
   }
 
   if (Log) {
-OriginalAttribute = gST->ConOut->Mode->Attribute;
 if (Checksum == 0) {
-  if (mConfig.ColourHighlighting) {
-gST->ConOut->SetAttribute (
-   gST->ConOut,
-   EFI_TEXT_ATTR (EFI_GREEN,
- ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4))
-   );
-  }
-  Print (L"Table Checksum : OK\n\n");
+  AcpiLog (ACPI_GOOD, L"Table Checksum : OK\n");
 } else {
-  IncrementErrorCount ();
-  if (mConfig.ColourHighlighting) {
-gST->ConOut->SetAttribute (
-   gST->ConOut,
-   EFI_TEXT_ATTR (EFI_RED,
- ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4))
-   );
-  }
-  Print (L"Table Checksum : FAILED (0x%X)\n\n", Checksum);
-}
-if (mConfig.ColourHighlighting) {
-  gST->ConOut->SetAttribute (gST->ConOut, OriginalAttribute);
+  AcpiError (ACPI_ERROR_CSUM, L"Table Checksum (0x%X != 0)\n", Checksum);
 }
   }
 
@@ -127,53 +107,101 @@ DumpRaw (
   )
 {
   UINTN ByteCount;
-  UINTN PartLineChars;
-  UINTN AsciiBufferIndex;
   CHAR8 AsciiBuffer[17];
+  CHAR8 HexBuffer[128];
+  CHAR8 *HexCursor;
 
   ByteCount = 0;
-  AsciiBufferIndex = 0;
 
-  Print (L"Address  : 0x%p\n", Ptr);
-  Print (L"Length   : %d\n", Length);
+  AcpiInfo (L"Address  : 0x%p", Ptr);
+  AcpiInfo (L"Length   : %d\n", Length);
 
   while (ByteCount < Length) {
-if ((ByteCount & 0x0F) == 0) {
-  AsciiBuffer[AsciiBufferIndex] = '\0';
-  Print (L"  %a\n%08X : ", AsciiBuffer, ByteCount);
-  AsciiBufferIndex = 0;
-} else if ((ByteCount & 0x07) == 0) {
-  Print (L"- ");
+
+// Reset ascii and hex strings
+if (ByteCount % 16 == 0) {
+  HexCursor = HexBuffer;
+  ZeroMem (AsciiBuffer, sizeof(AsciiBuffer));
+  ZeroMem (HexBuffer, sizeof(HexBuffer));
+} else if (ByteCount % 8 == 0) {
+  HexCursor += AsciiSPrint (HexCursor, sizeof(HexBuffer), "- ");
 }
 
+// Add hex couplet to hex buffer
+HexCursor += AsciiSPrint (HexCursor, sizeof(HexBuffer), "%02X ", *Ptr);
+
+// Add ascii letter to the ascii buffer
+AsciiBuffer[ByteCount & 0xF] = '.';
 if ((*Ptr >= ' ') && (*Ptr < 0x7F)) {
-  AsciiBuffer[AsciiBufferIndex++] = *Ptr;
-} else {
-  AsciiBuffer[AsciiBufferIndex++] = '.';
+  AsciiBuffer[ByteCount & 0xF] = *Ptr;
 }
 
-Print (L"%02X ", *Ptr++);
+// Print line with fixed width hex part
+if (ByteCount % 16 == 15) {
+  AcpiInfo (L"%08X : %-.*a %a", ByteCount + 1, 46, HexBuffer, AsciiBuffer);
+}
 
 ByteCount++;
+Ptr++;
   }
 
-  // Justify the final line using spaces before printing
-  // the ASCII data.
-  PartLineChars = (Length & 0x0F);
-  if (PartLineChars != 0) {
-PartLineChars = 48 - (PartLineChars * 3);
-if ((Length & 0x0F) <= 8) {
-  PartLineChars += 2;
-}
-while (PartLineChars > 0) {
-  Print (L" ");
-  PartLineChars--;
+// Print the last line
+if (ByteCount % 16 != 15) {
+  AcpiInfo (
+L"%08X : %-*a %.*a",
+(ByteCount + 16) & ~0xF,
+46,
+HexBuffer,
+ByteCount & 0xF,
+AsciiBuffer);
 }
+}
+
+/**
+  Prints an arbitrary variable to screen using a given parser.
+  Also calls the internal validator if it exists.
+
+  @param[in] Parser The parser to use to print to screen
+  @param[in] PrtPointer to variable that should be printed
+**/
+STATIC
+VOID
+EFIAPI

[edk2-devel] [PATCH v3 2/8] ShellPkg/AcpiView: Declutter error counters

2020-07-14 Thread Tomas Pilar (tpilar)
Remove superfluous accessor methods for error and warning
counters.

Cc: Ray Ni 
Cc: Zhichao Gao 
Signed-off-by: Tomas Pilar 
---
 .../UefiShellAcpiViewCommandLib/AcpiParser.c  | 54 ++-
 .../UefiShellAcpiViewCommandLib/AcpiParser.h  |  4 ++
 .../UefiShellAcpiViewCommandLib/AcpiView.c| 12 ++---
 .../UefiShellAcpiViewCommandLib/AcpiView.h| 36 -
 4 files changed, 14 insertions(+), 92 deletions(-)

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
index 3a029b01cc20..7017fa93efae 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
@@ -13,8 +13,10 @@
 #include "AcpiViewConfig.h"
 
 STATIC UINT32   gIndent;
-STATIC UINT32   mTableErrorCount;
-STATIC UINT32   mTableWarningCount;
+
+// Publicly accessible error and warning counters.
+UINT32   mTableErrorCount;
+UINT32   mTableWarningCount;
 
 STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
 
@@ -25,54 +27,6 @@ STATIC CONST ACPI_PARSER AcpiHeaderParser[] = {
   PARSE_ACPI_HEADER ()
 };
 
-/**
-  This function resets the ACPI table error counter to Zero.
-**/
-VOID
-ResetErrorCount (
-  VOID
-  )
-{
-  mTableErrorCount = 0;
-}
-
-/**
-  This function returns the ACPI table error count.
-
-  @retval Returns the count of errors detected in the ACPI tables.
-**/
-UINT32
-GetErrorCount (
-  VOID
-  )
-{
-  return mTableErrorCount;
-}
-
-/**
-  This function resets the ACPI table warning counter to Zero.
-**/
-VOID
-ResetWarningCount (
-  VOID
-  )
-{
-  mTableWarningCount = 0;
-}
-
-/**
-  This function returns the ACPI table warning count.
-
-  @retval Returns the count of warning detected in the ACPI tables.
-**/
-UINT32
-GetWarningCount (
-  VOID
-  )
-{
-  return mTableWarningCount;
-}
-
 /**
   This function increments the ACPI table error counter.
 **/
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
index f81ccac7e118..84eae61c8889 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
@@ -16,6 +16,10 @@
 /// that allows us to process the log options.
 #define RSDP_TABLE_INFO  SIGNATURE_32('R', 'S', 'D', 'P')
 
+// Publicly accessible error and warning counters.
+extern UINT32   mTableErrorCount;
+extern UINT32   mTableWarningCount;
+
 /**
   This function increments the ACPI table error counter.
 **/
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c
index d0a0edc45f3b..16f498b8c328 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c
@@ -197,8 +197,8 @@ AcpiView (
   mBinTableCount = 0;
 
   // Reset The error/warning counters
-  ResetErrorCount ();
-  ResetWarningCount ();
+  mTableErrorCount = 0;
+  mTableWarningCount = 0;
 
   // Search the table for an entry that matches the ACPI Table Guid
   FoundAcpiTable = FALSE;
@@ -276,7 +276,7 @@ AcpiView (
   Print (L"\nTable Statistics:\n");
 
   if (mConfig.ColourHighlighting) {
-PrintAttribute = (GetErrorCount () > 0) ?
+PrintAttribute = ((mTableErrorCount) > 0) ?
 EFI_TEXT_ATTR (
   EFI_RED,
   ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)
@@ -284,10 +284,10 @@ AcpiView (
 OriginalAttribute;
 gST->ConOut->SetAttribute (gST->ConOut, PrintAttribute);
   }
-  Print (L"\t%d Error(s)\n", GetErrorCount ());
+  Print (L"\t%d Error(s)\n", mTableErrorCount);
 
   if (mConfig.ColourHighlighting) {
-PrintAttribute = (GetWarningCount () > 0) ?
+PrintAttribute = (mTableWarningCount > 0) ?
 EFI_TEXT_ATTR (
   EFI_RED,
   ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)
@@ -296,7 +296,7 @@ AcpiView (
 
 gST->ConOut->SetAttribute (gST->ConOut, PrintAttribute);
   }
-  Print (L"\t%d Warning(s)\n", GetWarningCount ());
+  Print (L"\t%d Warning(s)\n", mTableWarningCount);
 
   if (mConfig.ColourHighlighting) {
 gST->ConOut->SetAttribute (gST->ConOut, OriginalAttribute);
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.h 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.h
index d5b95f5ee707..6fefe98a4463 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.h
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.h
@@ -23,42 +23,6 @@
 **/
 #define RSDP_LENGTH_OFFSET   20
 
-/**
-  This function resets the ACPI table error counter to Zero.
-**/
-VOID
-ResetErrorCount (
-  VOID
-  );
-
-/**
-  This function returns the ACPI table error count.
-
-  @retval Returns the count of errors detected in the ACPI 

[edk2-devel] [PATCH v3 5/8] ShellPkg/AcpiView: Refactor PrintFieldName

2020-07-14 Thread Tomas Pilar (tpilar)
The AcpiView core method is refactored to take format
and parameters rather than a fully formatted string. This
allows for far more flexible parser writing.

Cc: Ray Ni 
Cc: Zhichao Gao 
Signed-off-by: Tomas Pilar 
---
 .../UefiShellAcpiViewCommandLib/AcpiParser.c  | 30 ---
 .../UefiShellAcpiViewCommandLib/AcpiParser.h  | 19 --
 .../UefiShellAcpiViewCommandLib/AcpiViewLog.c | 38 +++
 .../UefiShellAcpiViewCommandLib/AcpiViewLog.h | 21 ++
 .../Parsers/Dbg2/Dbg2Parser.c |  1 +
 .../Parsers/Fadt/FadtParser.c |  1 +
 .../Parsers/Iort/IortParser.c |  1 +
 .../Parsers/Pptt/PpttParser.c |  1 +
 .../Parsers/Slit/SlitParser.c |  1 +
 .../Parsers/Srat/SratParser.c |  1 +
 .../Parsers/Xsdt/XsdtParser.c |  1 +
 11 files changed, 66 insertions(+), 49 deletions(-)

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
index b88594cf3865..54d87e2768e1 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
@@ -13,8 +13,6 @@
 #include "AcpiViewConfig.h"
 #include "AcpiViewLog.h"
 
-STATIC UINT32   gIndent;
-
 STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
 
 /**
@@ -390,34 +388,6 @@ Dump12Chars (
 );
 }
 
-/**
-  This function indents and prints the ACPI table Field Name.
-
-  @param [in] Indent  Number of spaces to add to the global table indent.
-  The global table indent is 0 by default; however
-  this value is updated on entry to the ParseAcpi()
-  by adding the indent value provided to ParseAcpi()
-  and restored back on exit.
-  Therefore the total indent in the output is
-  dependent on from where this function is called.
-  @param [in] FieldName   Pointer to the Field Name.
-**/
-VOID
-EFIAPI
-PrintFieldName (
-  IN UINT32 Indent,
-  IN CONST CHAR16*  FieldName
-)
-{
-  Print (
-L"%*a%-*s : ",
-gIndent + Indent,
-"",
-(OUTPUT_FIELD_COLUMN_WIDTH - gIndent - Indent),
-FieldName
-);
-}
-
 /**
   This function is used to parse an ACPI table buffer.
 
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
index 84eae61c8889..eb0c74eef144 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.h
@@ -204,25 +204,6 @@ Dump12Chars (
   IN   UINT8*  Ptr
   );
 
-/**
-  This function indents and prints the ACPI table Field Name.
-
-  @param [in] Indent  Number of spaces to add to the global table
-  indent. The global table indent is 0 by default;
-  however this value is updated on entry to the
-  ParseAcpi() by adding the indent value provided to
-  ParseAcpi() and restored back on exit. Therefore
-  the total indent in the output is dependent on from
-  where this function is called.
-  @param [in] FieldName   Pointer to the Field Name.
-**/
-VOID
-EFIAPI
-PrintFieldName (
-  IN UINT32 Indent,
-  IN CONST CHAR16*  FieldName
-  );
-
 /**
   This function pointer is the template for customizing the trace output
 
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLog.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLog.c
index 7ec276ac7528..18bbf67eef0a 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLog.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLog.c
@@ -27,6 +27,7 @@ static const CHAR16* mErrorTypeDesc [ACPI_ERROR_MAX] = {
 // Publicly accessible error and warning counters.
 UINT32   mTableErrorCount;
 UINT32   mTableWarningCount;
+UINT32   gIndent;
 
 /**
   Change the attributes of the standard output console
@@ -336,3 +337,40 @@ CheckConstraintInternal (
   // Return TRUE if constraint was violated
   return !Constraint;
 }
+
+/**
+  This function indents and prints the ACPI table Field Name.
+
+  @param [in] Indent  Number of spaces to add to the global table indent.
+  The global table indent is 0 by default; however
+  this value is updated on entry to the ParseAcpi()
+  by adding the indent value provided to ParseAcpi()
+  and restored back on exit.
+  Therefore the total indent in the output is
+  dependent on from where this function is called.
+  @param [in] FieldName   Pointer to the format string for field name.
+  @param [in] ... Variable List parameters to format.
+**/
+VOID
+EFIAPI

[edk2-devel] [PATCH v3 3/8] ShellPkg/AcpiView: Modify error message

2020-07-14 Thread Tomas Pilar (tpilar)
Modify the DumpFile error message to be more in line
with the rest of the error messages in the same file.

Cc: Ray Ni 
Cc: Zhichao Gao 
Signed-off-by: Tomas Pilar 
---
 .../UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git 
a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c
index 9613c16f5703..11e97afabc52 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c
@@ -147,10 +147,8 @@ ShellDumpBufferToFile (
  );
 
   if (EFI_ERROR (Status)) {
-Print (L"ERROR: Failed to write binary file.\n");
+Print (L"acpiview: Failed to write binary file.\n");
 TransferBytes = 0;
-  } else {
-Print (L"DONE.\n");
   }
 
   ShellCloseFile ();
-- 
2.24.1.windows.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62552): https://edk2.groups.io/g/devel/message/62552
Mute This Topic: https://groups.io/mt/75504253/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/8] ShellPkg/AcpiView: Extract configuration struct

2020-07-14 Thread Tomas Pilar (tpilar)
Remove accessor method bloat by creating a configuration
struct that is linked using an extern symbol in the config header
file. Directly reference the config struct for all read
and write accesses in the entire module.

Rationalise the remaining methods in the config header and source.

Cc: Ray Ni 
Cc: Zhichao Gao 
Signed-off-by: Tomas Pilar 
---
 .../UefiShellAcpiViewCommandLib/AcpiParser.c  |  18 +-
 .../AcpiTableParser.c |   4 +-
 .../UefiShellAcpiViewCommandLib/AcpiView.c|  67 +++
 .../AcpiViewConfig.c  | 180 ++
 .../AcpiViewConfig.h  | 138 ++
 .../UefiShellAcpiViewCommandLib.c |  18 +-
 6 files changed, 70 insertions(+), 355 deletions(-)

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
index 02f6d771c7e1..3a029b01cc20 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
@@ -137,7 +137,7 @@ VerifyChecksum (
   if (Log) {
 OriginalAttribute = gST->ConOut->Mode->Attribute;
 if (Checksum == 0) {
-  if (GetColourHighlighting ()) {
+  if (mConfig.ColourHighlighting) {
 gST->ConOut->SetAttribute (
gST->ConOut,
EFI_TEXT_ATTR (EFI_GREEN,
@@ -147,7 +147,7 @@ VerifyChecksum (
   Print (L"Table Checksum : OK\n\n");
 } else {
   IncrementErrorCount ();
-  if (GetColourHighlighting ()) {
+  if (mConfig.ColourHighlighting) {
 gST->ConOut->SetAttribute (
gST->ConOut,
EFI_TEXT_ATTR (EFI_RED,
@@ -156,7 +156,7 @@ VerifyChecksum (
   }
   Print (L"Table Checksum : FAILED (0x%X)\n\n", Checksum);
 }
-if (GetColourHighlighting ()) {
+if (mConfig.ColourHighlighting) {
   gST->ConOut->SetAttribute (gST->ConOut, OriginalAttribute);
 }
   }
@@ -507,7 +507,6 @@ ParseAcpi (
 {
   UINT32  Index;
   UINT32  Offset;
-  BOOLEAN HighLight;
   UINTN   OriginalAttribute;
 
   //
@@ -520,9 +519,8 @@ ParseAcpi (
   gIndent += Indent;
 
   if (Trace && (AsciiName != NULL)){
-HighLight = GetColourHighlighting ();
 
-if (HighLight) {
+if (mConfig.ColourHighlighting) {
   OriginalAttribute = gST->ConOut->Mode->Attribute;
   gST->ConOut->SetAttribute (
  gST->ConOut,
@@ -537,7 +535,7 @@ ParseAcpi (
   (OUTPUT_FIELD_COLUMN_WIDTH - gIndent),
   AsciiName
   );
-if (HighLight) {
+if (mConfig.ColourHighlighting) {
   gST->ConOut->SetAttribute (gST->ConOut, OriginalAttribute);
 }
   }
@@ -555,8 +553,7 @@ ParseAcpi (
   continue;
 }
 
-if (GetConsistencyChecking () &&
-(Offset != Parser[Index].Offset)) {
+if (mConfig.ConsistencyCheck && (Offset != Parser[Index].Offset)) {
   IncrementErrorCount ();
   Print (
 L"\nERROR: %a: Offset Mismatch for %s\n"
@@ -599,8 +596,7 @@ ParseAcpi (
 
 // Validating only makes sense if we are tracing
 // the parsed table entries, to report by table name.
-if (GetConsistencyChecking () &&
-(Parser[Index].FieldValidator != NULL)) {
+if (mConfig.ConsistencyCheck && (Parser[Index].FieldValidator != 
NULL)) {
   Parser[Index].FieldValidator (Ptr, Parser[Index].Context);
 }
   }
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.c
index 4b618f131eac..526cb8cb7cad 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.c
@@ -222,13 +222,13 @@ ProcessAcpiTable (
   return;
 }
 
-if (GetConsistencyChecking ()) {
+if (mConfig.ConsistencyCheck) {
   VerifyChecksum (TRUE, Ptr, *AcpiTableLength);
 }
   }
 
 #if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
-  if (GetMandatoryTableValidate ()) {
+  if (mConfig.MandatoryTableValidate) {
 ArmSbbrIncrementTableCount (*AcpiTableSignature);
   }
 #endif
diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c
index 9a5b013fb234..d0a0edc45f3b 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiView.c
@@ -48,15 +48,12 @@ DumpAcpiTableToFile (
 {
   CHAR16  FileNameBuffer[MAX_FILE_NAME_LEN];
   UINTN   TransferBytes;
-  SELECTED_ACPI_TABLE *SelectedTable;
-
-  GetSelectedAcpiTable ();
 
   UnicodeSPrint (
 FileNameBuffer,
 sizeof (FileNameBuffer),
 L".\\%s%04d.bin",
-SelectedTable->Name,
+mSelectedAcpiTable.Name,
 mBinTableCount++
 );
 
@@ -82,11 +79,9 @@ ProcessTableReportOptions (
   IN CONST UINT32  Length
   )
 {
-  UINTNOriginalAttribute;
-  UINT8   

[edk2-devel] [PATCH v3 6/8] ShellPkg/AcpiView: Refactor dump helpers

2020-07-14 Thread Tomas Pilar (tpilar)
The dump variable helper functions are refactored into
a separate header file as inline functions to declutter code.

Cc: Ray Ni 
Cc: Zhichao Gao 
Signed-off-by: Tomas Pilar 
---
 .../UefiShellAcpiViewCommandLib/AcpiParser.c  | 212 ---
 .../UefiShellAcpiViewCommandLib/AcpiParser.h  | 134 +-
 .../FieldFormatHelper.h   | 244 ++
 .../UefiShellAcpiViewCommandLib.inf   |   1 +
 4 files changed, 247 insertions(+), 344 deletions(-)
 create mode 100644 
ShellPkg/Library/UefiShellAcpiViewCommandLib/FieldFormatHelper.h

diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c 
b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
index 54d87e2768e1..65108e25ff96 100644
--- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
+++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c
@@ -176,218 +176,6 @@ DumpRaw (
   Print (L"  %a\n\n", AsciiBuffer);
 }
 
-/**
-  This function traces 1 byte of data as specified in the format string.
-
-  @param [in] Format  The format string for tracing the data.
-  @param [in] Ptr Pointer to the start of the buffer.
-**/
-VOID
-EFIAPI
-DumpUint8 (
-  IN CONST CHAR16* Format,
-  IN UINT8*Ptr
-  )
-{
-  Print (Format, *Ptr);
-}
-
-/**
-  This function traces 2 bytes of data as specified in the format string.
-
-  @param [in] Format  The format string for tracing the data.
-  @param [in] Ptr Pointer to the start of the buffer.
-**/
-VOID
-EFIAPI
-DumpUint16 (
-  IN CONST CHAR16* Format,
-  IN UINT8*Ptr
-  )
-{
-  Print (Format, *(UINT16*)Ptr);
-}
-
-/**
-  This function traces 4 bytes of data as specified in the format string.
-
-  @param [in] Format  The format string for tracing the data.
-  @param [in] Ptr Pointer to the start of the buffer.
-**/
-VOID
-EFIAPI
-DumpUint32 (
-  IN CONST CHAR16* Format,
-  IN UINT8*Ptr
-  )
-{
-  Print (Format, *(UINT32*)Ptr);
-}
-
-/**
-  This function traces 8 bytes of data as specified by the format string.
-
-  @param [in] Format  The format string for tracing the data.
-  @param [in] Ptr Pointer to the start of the buffer.
-**/
-VOID
-EFIAPI
-DumpUint64 (
-  IN CONST CHAR16* Format,
-  IN UINT8*Ptr
-  )
-{
-  // Some fields are not aligned and this causes alignment faults
-  // on ARM platforms if the compiler generates LDRD instructions.
-  // Perform word access so that LDRD instructions are not generated.
-  UINT64 Val;
-
-  Val = *(UINT32*)(Ptr + sizeof (UINT32));
-
-  Val = LShiftU64(Val,32);
-  Val |= (UINT64)*(UINT32*)Ptr;
-
-  Print (Format, Val);
-}
-
-/**
-  This function traces 3 characters which can be optionally
-  formated using the format string if specified.
-
-  If no format string is specified the Format must be NULL.
-
-  @param [in] Format  Optional format string for tracing the data.
-  @param [in] Ptr Pointer to the start of the buffer.
-**/
-VOID
-EFIAPI
-Dump3Chars (
-  IN CONST CHAR16* Format OPTIONAL,
-  IN UINT8*Ptr
-  )
-{
-  Print (
-(Format != NULL) ? Format : L"%c%c%c",
-Ptr[0],
-Ptr[1],
-Ptr[2]
-);
-}
-
-/**
-  This function traces 4 characters which can be optionally
-  formated using the format string if specified.
-
-  If no format string is specified the Format must be NULL.
-
-  @param [in] Format  Optional format string for tracing the data.
-  @param [in] Ptr Pointer to the start of the buffer.
-**/
-VOID
-EFIAPI
-Dump4Chars (
-  IN CONST CHAR16* Format OPTIONAL,
-  IN UINT8*Ptr
-  )
-{
-  Print (
-(Format != NULL) ? Format : L"%c%c%c%c",
-Ptr[0],
-Ptr[1],
-Ptr[2],
-Ptr[3]
-);
-}
-
-/**
-  This function traces 6 characters which can be optionally
-  formated using the format string if specified.
-
-  If no format string is specified the Format must be NULL.
-
-  @param [in] Format  Optional format string for tracing the data.
-  @param [in] Ptr Pointer to the start of the buffer.
-**/
-VOID
-EFIAPI
-Dump6Chars (
-  IN CONST CHAR16* Format OPTIONAL,
-  IN UINT8*Ptr
-  )
-{
-  Print (
-(Format != NULL) ? Format : L"%c%c%c%c%c%c",
-Ptr[0],
-Ptr[1],
-Ptr[2],
-Ptr[3],
-Ptr[4],
-Ptr[5]
-);
-}
-
-/**
-  This function traces 8 characters which can be optionally
-  formated using the format string if specified.
-
-  If no format string is specified the Format must be NULL.
-
-  @param [in] Format  Optional format string for tracing the data.
-  @param [in] Ptr Pointer to the start of the buffer.
-**/
-VOID
-EFIAPI
-Dump8Chars (
-  IN CONST CHAR16* Format OPTIONAL,
-  IN UINT8*Ptr
-  )
-{
-  Print (
-(Format != NULL) ? Format : L"%c%c%c%c%c%c%c%c",
-Ptr[0],
-Ptr[1],
-Ptr[2],
-Ptr[3],
-Ptr[4],
-Ptr[5],
-Ptr[6],
-Ptr[7]
-);
-}
-
-/**
-  This function traces 12 characters which can be optionally
-  formated using the format string if specified.
-
-  If no format string is specified the Format must be NULL.
-
-  

[edk2-devel] [PATCH v3 0/8] ShellPkg/AcpiView: Refactor Error Logging

2020-07-14 Thread Tomas Pilar (tpilar)
This patch series refactors the error logging in the AcpiView
functionality to a newly created logging facility.

The new error logging facility in AcpiViewLog.[ch] contains
helper functions to log messages of various types and severities,
enumerations of known error types as well as common abstractions
for outputting the log.

This allows for modularity when determining how the output
should be delivered to the user as well as significantly reduced
code footprint of the logging mechanism in the core AcpiView code.

---
Can be seen also on github:
https://github.com/tpilar/edk2/tree/acpiview-error-logging-v3

v3: Tidy formatting. Fix off-by-one-errors in asserts.
v2: Tidy formatting. Remove inline functions.
Remove assignments in local variable declarations.
Return macro to access 2D array items.

 .../UefiShellAcpiViewCommandLib/AcpiParser.c  | 531 --
 .../UefiShellAcpiViewCommandLib/AcpiParser.h  | 173 +-
 .../AcpiTableParser.c |  56 +-
 .../AcpiTableParser.h |   2 +-
 .../UefiShellAcpiViewCommandLib/AcpiView.c| 226 +++-
 .../UefiShellAcpiViewCommandLib/AcpiView.h|  36 --
 .../AcpiViewConfig.c  | 180 +-
 .../AcpiViewConfig.h  | 138 +
 .../UefiShellAcpiViewCommandLib/AcpiViewLog.c | 376 +
 .../UefiShellAcpiViewCommandLib/AcpiViewLog.h | 213 +++
 .../Arm/SbbrValidator.c   |  65 +--
 .../FieldFormatHelper.h   | 164 ++
 .../Parsers/Dbg2/Dbg2Parser.c | 120 ++--
 .../Parsers/Fadt/FadtParser.c |  55 +-
 .../Parsers/Gtdt/GtdtParser.c |  80 +--
 .../Parsers/Iort/IortParser.c | 198 +++
 .../Parsers/Madt/MadtParser.c | 101 ++--
 .../Parsers/Mcfg/McfgParser.c |  11 +-
 .../Parsers/Pptt/PpttParser.c | 166 ++
 .../Parsers/Rsdp/RsdpParser.c |  38 +-
 .../Parsers/Slit/SlitParser.c | 125 ++---
 .../Parsers/Spcr/SpcrParser.c |  23 +-
 .../Parsers/Srat/SratParser.c | 189 ++-
 .../Parsers/Xsdt/XsdtParser.c |  97 +---
 .../UefiShellAcpiViewCommandLib.c |  22 +-
 .../UefiShellAcpiViewCommandLib.inf   |   3 +
 26 files changed, 1373 insertions(+), 2015 deletions(-)
 create mode 100644 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLog.c
 create mode 100644 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLog.h
 create mode 100644 
ShellPkg/Library/UefiShellAcpiViewCommandLib/FieldFormatHelper.h

-- 
2.24.1.windows.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62548): https://edk2.groups.io/g/devel/message/62548
Mute This Topic: https://groups.io/mt/75504248/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 12/16] UnitTestFrameworkPkg/UnitTestLib: Add checks for ASSERT()

2020-07-14 Thread Michael D Kinney
Liming,

I will fix that one issue in the INF comment block
when I push the commits.

Thanks,

Mike

> -Original Message-
> From: Gao, Liming 
> Sent: Monday, July 13, 2020 11:57 PM
> To: devel@edk2.groups.io; Kinney, Michael D
> 
> Cc: Sean Brogan ; Bret
> Barkelew ; Yao, Jiewen
> 
> Subject: RE: [edk2-devel] [Patch v3 12/16]
> UnitTestFrameworkPkg/UnitTestLib: Add checks for
> ASSERT()
> 
> Mike:
> 
> -Original Message-
> From: devel@edk2.groups.io  On
> Behalf Of Michael D Kinney
> Sent: 2020年7月11日 10:09
> To: devel@edk2.groups.io
> Cc: Sean Brogan ; Bret
> Barkelew ; Yao, Jiewen
> 
> Subject: [edk2-devel] [Patch v3 12/16]
> UnitTestFrameworkPkg/UnitTestLib: Add checks for
> ASSERT()
> 
> REF: REF:
> https://bugzilla.tianocore.org/show_bug.cgi?id=2801
> 
> Add UnitTestDebugAssertLib that provides the
> UnitTestDebugAssert() service and the
> gUnitTestExpectAssertFailureJumpBuffer global variable.
> This NULL library is linked against all host and target
> unit test builds.  This guarantees that the
> UnitTestDebugAssert() service is available to link
> against all libraries and modules that use the DebugLib
> class.
> 
> EDKII_UNIT_TEST_FRAMEWORK_ENABLED must always be defined
> when building unit tests so the behavior of the DebugLib
> ASSERT() macros can be adjusted to allow the unit test
> framework to catch an ASSERT() if it is triggered by a
> function under test.
> 
> Cc: Sean Brogan 
> Cc: Bret Barkelew 
> Cc: Jiewen Yao 
> Signed-off-by: Michael D Kinney
> 
> ---
>  .../UnitTestDebugAssertLib.c  |  49
> +
>  .../UnitTestDebugAssertLib.inf|  31 +++
>  .../UnitTestDebugAssertLib.uni|  11 +
>  .../Library/UnitTestLib/Assert.c  | 203
> --
>  .../Library/UnitTestLib/AssertCmocka.c|  68
> ++
>  .../Library/UnitTestLib/RunTests.c|  23 +-
>  .../UnitTestResultReportLib.c |   3 +-
>  .../PrivateInclude/UnitTestFrameworkTypes.h   |   1 +
>  .../Test/UnitTestFrameworkPkgHostTest.dsc |   2 +-
>  UnitTestFrameworkPkg/UnitTestFrameworkPkg.dsc |   1 +
>  .../UnitTestFrameworkPkgTarget.dsc.inc|   6 +-
>  11 files changed, 328 insertions(+), 70 deletions(-)
> create mode 100644
> UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/Unit
> TestDebugAssertLib.c
>  create mode 100644
> UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/Unit
> TestDebugAssertLib.inf
>  create mode 100644
> UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/Unit
> TestDebugAssertLib.uni
> 
> diff --git
> a/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/Un
> itTestDebugAssertLib.c
> b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/Un
> itTestDebugAssertLib.c
> new file mode 100644
> index 00..0a4001e182
> --- /dev/null
> +++
> b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/Un
> itTestDebugA
> +++ ssertLib.c
> @@ -0,0 +1,49 @@
> +/** @file
> +  Unit Test Debug Assert Library
> +
> +  Copyright (c) 2020, Intel Corporation. All rights
> reserved.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include 
> +#include 
> +#include 
> +
> +///
> +/// Point to jump buffer used with SetJump()/LongJump()
> to test if a
> +function /// under test generates an expected ASSERT()
> condition.
> +///
> +BASE_LIBRARY_JUMP_BUFFER
> *gUnitTestExpectAssertFailureJumpBuffer =
> +NULL;
> +
> +/**
> +  Unit test library replacement for DebugAssert() in
> DebugLib.
> +
> +  If FileName is NULL, then a  string of
> "(NULL) Filename" is printed.
> +  If Description is NULL, then a  string
> of "(NULL) Description" is printed.
> +
> +  @param  FileName The pointer to the name of the
> source file that generated the assert condition.
> +  @param  LineNumber   The line number in the source
> file that generated the assert condition
> +  @param  Description  The pointer to the description
> of the assert condition.
> +
> +**/
> +VOID
> +EFIAPI
> +UnitTestDebugAssert (
> +  IN CONST CHAR8  *FileName,
> +  IN UINTNLineNumber,
> +  IN CONST CHAR8  *Description
> +  )
> +{
> +  CHAR8  Message[256];
> +
> +  if (gUnitTestExpectAssertFailureJumpBuffer != NULL) {
> +UT_LOG_INFO ("Detected expected ASSERT: %a(%d):
> %a\n", FileName, LineNumber, Description);
> +LongJump (gUnitTestExpectAssertFailureJumpBuffer,
> 1);
> +  } else {
> +AsciiStrCpyS (Message, sizeof(Message), "Detected
> unexpected ASSERT(");
> +AsciiStrCatS (Message, sizeof(Message),
> Description);
> +AsciiStrCatS (Message, sizeof(Message), ")");
> +UnitTestAssertTrue (FALSE, "", LineNumber,
> FileName, Message);
> +  }
> +}
> diff --git
> a/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/Un
> itTestDebugAssertLib.inf
> b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/Un
> itTestDebugAssertLib.inf
> new file mode 100644
> index 00..e6ccab0dd9
> --- /dev/null
> +++
> b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/Un
> itTestDebugA
> +++ ssertLib.inf
> @@ 

[edk2-devel] Cancelled Event: TianoCore Bug Triage - APAC / NAMO - Tuesday, 14 July 2020 #cal-cancelled

2020-07-14 Thread devel@edk2.groups.io Calendar
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Groups.io Inc//Groups.io Calendar//EN
METHOD:CANCELLED
CALSCALE:GREGORIAN
BEGIN:VEVENT
UID:mlda.1580078539586725120.r...@groups.io
DTSTAMP:20200714T161452Z
ORGANIZER;CN=Brian Richardson:mailto:brian.richard...@intel.com
DTSTART:20200715T013000Z
DTEND:20200715T023000Z
SUMMARY:TianoCore Bug Triage - APAC / NAMO
DESCRIPTION:https //www.tianocore.org/bug-triage\n\nMeeting URL\n\nhttps 
 //bluejeans.com/889357567?src=join_info\n\nMeeting ID\n\n889 357 567\n\nW
 ant to dial in from a phone?\n\nDial one of the following numbers \n\n+1.
 408.740.7256 (US (San Jose))\n\n+1.408.317.9253 (US (Primary\, San Jose))
 \n\n(see all numbers - https //www.bluejeans.com/numbers)\n\nEnter the me
 eting ID and passcode followed by #
LOCATION:https://bluejeans.com/889357567?src=join_info
SEQUENCE:999
STATUS:CANCELLED
END:VEVENT
END:VCALENDAR


invite.ics
Description: application/ics


Re: [edk2-devel] TianoCore Bug Triage - APAC / NAMO - Tue, 07/14/2020 6:30pm-7:30pm #cal-reminder

2020-07-14 Thread Liming Gao
There are only 5 unconfirmed issues this week to be discussed. So, this week 
Bug Triage will be cancelled.

2850
EDK2
Tools
unassig...@tianocore.org
UNCO
---
Generate compile_commands.json file needed by clangd VS Code 
plugin
02:10:16
2848
EDK2
Code
abner.ch...@hpe.com
UNCO
---
"OpensslLib.inf" and "OpensslLibCrypto.inf" use different 
RISCV64_CC_FLAGS
Mon 14:06
2846
EDK2
Tools
unassig...@tianocore.org
UNCO
---
Error while execute command 'nmake all' in direcotry 
C:\Users\jguo5\Downloads\edk2-master\BaseTools\Source\C\BrotliCompress
Sat 15:21
2845
EDK2
Code
unassig...@tianocore.org
UNCO
---
To enable X2Apic by default
Thu 23:04
2504
Tianocor
Code
maciej.rab...@intel.com
UNCO
---
UEFI HTTPS Boot Support for HTTP Client Authentication (Basic or 
Digest)
Wed 21:21

Thanks
Liming
From: devel@edk2.groups.io 
Sent: Tuesday, July 14, 2020 9:30 AM
To: devel@edk2.groups.io
Subject: [edk2-devel] TianoCore Bug Triage - APAC / NAMO - Tue, 07/14/2020 
6:30pm-7:30pm #cal-reminder


Reminder: TianoCore Bug Triage - APAC / NAMO

When: Tuesday, 14 July 2020, 6:30pm to 7:30pm, (GMT-07:00) America/Los Angeles

Where:https://bluejeans.com/889357567?src=join_info

View Event

Organizer: Brian Richardson 
brian.richard...@intel.com

Description:
https://www.tianocore.org/bug-triage

Meeting URL
https://bluejeans.com/889357567?src=join_info

Meeting ID
889 357 567

Want to dial in from a phone?
Dial one of the following numbers:
+1.408.740.7256 (US (San Jose))
+1.408.317.9253 (US (Primary, San Jose))

(see all numbers - https://www.bluejeans.com/numbers)
Enter the meeting ID and passcode followed by #


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62545): https://edk2.groups.io/g/devel/message/62545
Mute This Topic: https://groups.io/mt/75490724/21656
Mute #cal-reminder: https://groups.io/g/edk2/mutehashtag/cal-reminder
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [edk2][PATCH 1/1] BcmGenetDxe: don't consume RX buffer until it's actually copied

2020-07-14 Thread Leif Lindholm
On Tue, Jul 14, 2020 at 14:51:46 +0100, Pete Batard wrote:
> On 2020.07.14 14:36, Leif Lindholm wrote:
> > On Mon, Jul 13, 2020 at 12:25:18 +0100, Pete Batard wrote:
> > > One very minor formatting issue inline (that can be sorted during
> > > integration):
> > 
> > I would also like to prepend "Silicon/" to the subject line.
> 
> Please do. It should have been there in the first place.

Thanks. With those minor tweaks:
Reviewed-by: Leif Lindholm 
Pushed as 2242b990248c.

> Regards,
> 
> /Pete
> 
> > If I can do those two things:
> > Reviewed-by: Leif Lindholm 
> > 
> > > On 2020.07.12 05:28, Andrei Warkentin wrote:
> > > > This was originally a bit sloppy, and could hypothetically under heavy
> > > > load result in a buffer being overwritten by hardware before the 
> > > > received
> > > > buffer is copied.
> > > > 
> > > > Signed-off-by: Andrei Warkentin 
> > > > ---
> > > >Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h   | 15 +
> > > >Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c | 59 
> > > > +++-
> > > >Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c | 26 
> > > > ++---
> > > >3 files changed, 77 insertions(+), 23 deletions(-)
> > > > 
> > > > diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h 
> > > > b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h
> > > > index 1a117b25..b39a1326 100644
> > > > --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h
> > > > +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h
> > > > @@ -358,6 +358,16 @@ GenetTxIntr (
> > > >  OUT VOID  **TxBuf
> > > >  );
> > > > +UINT32
> > > > +GenetRxPending (
> > > > +  IN  GENET_PRIVATE_DATA *Genet
> > > > +  );
> > > > +
> > > > +UINT32
> > > > +GenetTxPending (
> > > > +  IN  GENET_PRIVATE_DATA *Genet
> > > > +  );
> > > > +
> > > >EFI_STATUS
> > > >GenetRxIntr (
> > > >  IN GENET_PRIVATE_DATA *Genet,
> > > > @@ -365,4 +375,9 @@ GenetRxIntr (
> > > >  OUT UINTN *FrameLength
> > > >  );
> > > > +VOID
> > > > +GenetRxComplete (
> > > > +  IN GENET_PRIVATE_DATA *Genet
> > > > +  );
> > > > +
> > > >#endif /* GENET_UTIL_H__ */
> > > > diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c 
> > > > b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c
> > > > index 1c4c8527..a0097b0d 100644
> > > > --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c
> > > > +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c
> > > > @@ -661,6 +661,7 @@ GenetDmaMapRxDescriptor (
> > > >Genet->RxBufferMap[DescIndex].PhysAddress & 0x);
> > > >  GenetMmioWrite (Genet, GENET_RX_DESC_ADDRESS_HI (DescIndex),
> > > >(Genet->RxBufferMap[DescIndex].PhysAddress >> 32) & 0x);
> > > > +  GenetMmioWrite (Genet, GENET_RX_DESC_STATUS (DescIndex), 0);
> > > >  return EFI_SUCCESS;
> > > >}
> > > > @@ -753,12 +754,9 @@ GenetTxIntr (
> > > >  OUT VOID   **TxBuf
> > > >  )
> > > >{
> > > > -  UINT32  ConsIndex, Total;
> > > > +  UINT32 Total;
> > > > -  ConsIndex = GenetMmioRead (Genet,
> > > > -GENET_TX_DMA_CONS_INDEX (GENET_DMA_DEFAULT_QUEUE)) & 
> > > > 0x;
> > > > -
> > > > -  Total = (ConsIndex - Genet->TxConsIndex) & 0x;
> > > > +  Total = GenetTxPending (Genet);
> > > >  if (Genet->TxQueued > 0 && Total > 0) {
> > > >DmaUnmap (Genet->TxBufferMap[Genet->TxNext]);
> > > >*TxBuf = Genet->TxBuffer[Genet->TxNext];
> > > > @@ -770,6 +768,46 @@ GenetTxIntr (
> > > >  }
> > > >}
> > > > +UINT32
> > > > +GenetRxPending (
> > > > +  IN  GENET_PRIVATE_DATA *Genet
> > > > +  )
> > > > +{
> > > > +  UINT32 ProdIndex;
> > > > +  UINT32 ConsIndex;
> > > > +
> > > > +  ConsIndex = GenetMmioRead (Genet,
> > > > +GENET_RX_DMA_CONS_INDEX (GENET_DMA_DEFAULT_QUEUE)) & 
> > > > 0x;
> > > > +  ASSERT (ConsIndex == Genet->RxConsIndex);
> > > > +
> > > > +  ProdIndex = GenetMmioRead (Genet,
> > > > +GENET_RX_DMA_PROD_INDEX (GENET_DMA_DEFAULT_QUEUE)) & 
> > > > 0x;
> > > > +  return (ProdIndex - Genet->RxConsIndex) & 0x;
> > > > +}
> > > > +
> > > > +UINT32
> > > > +GenetTxPending (
> > > > +  IN  GENET_PRIVATE_DATA *Genet
> > > > +  )
> > > > +{
> > > > +  UINT32 ConsIndex;
> > > > +
> > > > +  ConsIndex = GenetMmioRead (Genet,
> > > > + GENET_TX_DMA_CONS_INDEX (GENET_DMA_DEFAULT_QUEUE)) & 0x;
> > > 
> > > If we want to be pedantic about EDK2 formatting, this should be indented 
> > > to
> > > start after the "Ge" of GenetMmioRead above, like the previous calls.
> > > 
> > > > +
> > > > +  return (ConsIndex - Genet->TxConsIndex) & 0x;
> > > > +}
> > > > +
> > > > +VOID
> > > > +GenetRxComplete (
> > > > +  IN GENET_PRIVATE_DATA *Genet
> > > > +  )
> > > > +{
> > > > +  Genet->RxConsIndex = (Genet->RxConsIndex + 1) & 0x;
> > > > +  GenetMmioWrite (Genet, GENET_RX_DMA_CONS_INDEX 
> > > > (GENET_DMA_DEFAULT_QUEUE),
> > > > + 

Re: [edk2-devel] [edk2-platforms][PATCH v3 1/1] Platform/RaspberryPi/Drivers: Add SD/(e)MMC card detection

2020-07-14 Thread Leif Lindholm
On Tue, Jul 14, 2020 at 14:49:21 +0100, Pete Batard wrote:
> On 2020.07.14 14:25, Leif Lindholm wrote:
> > On Mon, Jul 13, 2020 at 12:16:20 +0100, Pete Batard wrote:
> > > The Raspberry Pi 3 and Pi 4 platforms (with latest EEPROM) can boot
> > > straight from USB, without the need for an SD card being present.
> > > However, the IsCardPresent () calls from the ArasanMmcHost and SdHost
> > > drivers are currently hardwired to return TRUE, which results in
> > > straight to USB boot failing due to the SD drivers looping on
> > > errors while trying to poke at a non-existent card...
> > > 
> > > Ideally, we would use the Card Detect signal from the uSD slot, to
> > > report on the presence or absence of a card, but the Raspberry Pi
> > > Foundation did not wire those signals in the Pi 2 and subsequent
> > > models, leaving us with only potentially interfering SD commands
> > > as means to perform card detection.
> > > 
> > > As a result of this, we are left with no other choice but limit
> > > detection to occurring only once, prior to formal SD card init,
> > > and then return the detected value for subsequent calls. This,
> > > however, is more than good enough for the intended purpose, which
> > > is to allow straight to USB boot. The sequence is a simplified
> > > variant of the identification code in MmcDxe.
> > > 
> > > Tested on Raspberry Pi 2B, 3B and CM3 (for both SD controllers)
> > > and Pi 4 (for Arasan, as that's the only controller available today)
> > > 
> > > Addresses pftf/RPi3#13, pftf/RPi3#14, pftf/RPi4#37.
> > > 
> > > Co-authored-by: Andrei Warkentin 
> > > Signed-off-by: Pete Batard 
> > 
> > Some minor style comments below, I'm happy to fix them before pushing
> > if you're OK with these:
> 
> I agree with the proposed changes. Thanks for volunteering to fix these.
> 
> I just tested your diff with a Pi 4, for good measure, and everything looks
> good.

Thanks! With that
Reviewed-by: Leif Lindholm 
Pushed as 225426271bb0.

> Regards,
> 
> /Pete
> 
> > 
> > > ---
> > >   Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.c | 86 
> > > ++--
> > >   Platform/RaspberryPi/Drivers/SdHostDxe/SdHostDxe.c   | 75 
> > > +++--
> > >   Platform/RaspberryPi/Include/Protocol/RpiMmcHost.h   |  6 ++
> > >   3 files changed, 150 insertions(+), 17 deletions(-)
> > > 
> > > diff --git 
> > > a/Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.c 
> > > b/Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.c
> > > index 6d706af6f276..d2a8ffddbb66 100644
> > > --- a/Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.c
> > > +++ b/Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.c
> > > @@ -11,7 +11,8 @@
> > >   #define DEBUG_MMCHOST_SD DEBUG_VERBOSE
> > > -BOOLEAN PreviousIsCardPresent = FALSE;
> > > +BOOLEAN CardIsPresent = FALSE;
> > > +CARD_DETECT_STATE CardDetectState = CardDetectRequired;
> > 
> > Global variables, so add 'm' prefix?
> > Also, add STATIC (which also matches SdHostDxe version)?
> > 
> > >   UINT32 LastExecutedCommand = (UINT32) -1;
> > >   STATIC RASPBERRY_PI_FIRMWARE_PROTOCOL *mFwProtocol;
> > > @@ -239,14 +240,6 @@ CalculateClockFrequencyDivisor (
> > > return EFI_SUCCESS;
> > >   }
> > > -BOOLEAN
> > > -MMCIsCardPresent (
> > > -  IN EFI_MMC_HOST_PROTOCOL *This
> > > -)
> > > -{
> > > -  return TRUE;
> > > -}
> > > -
> > >   BOOLEAN
> > >   MMCIsReadOnly (
> > > IN EFI_MMC_HOST_PROTOCOL *This
> > > @@ -418,6 +411,10 @@ MMCNotifyState (
> > > DEBUG ((DEBUG_MMCHOST_SD, "ArasanMMCHost: MMCNotifyState(State: 
> > > %d)\n", State));
> > > +  // Stall all operations except init until card detection has occurred.
> > > +  if (State != MmcHwInitializationState && CardDetectState != 
> > > CardDetectCompleted)
> > > +return EFI_NOT_READY;
> > > +
> > 
> > Add {}?
> > 
> > > switch (State) {
> > > case MmcHwInitializationState:
> > >   {
> > > @@ -489,6 +486,77 @@ MMCNotifyState (
> > > return EFI_SUCCESS;
> > >   }
> > > +BOOLEAN
> > > +MMCIsCardPresent (
> > > +  IN EFI_MMC_HOST_PROTOCOL *This
> > > +)
> > > +{
> > > +  EFI_STATUS Status;
> > > +
> > > +  //
> > > +  // If we are already in progress (we may get concurrent calls)
> > > +  // or completed the detection, just return the current value.
> > > +  //
> > > +  if (CardDetectState != CardDetectRequired)
> > > +return CardIsPresent;
> > 
> > Add {}?
> > 
> > > +
> > > +  CardDetectState = CardDetectInProgress;
> > > +  CardIsPresent = FALSE;
> > > +
> > > +  //
> > > +  // The two following commands should succeed even if no card is 
> > > present.
> > > +  //
> > > +  Status = MMCNotifyState (This, MmcHwInitializationState);
> > > +  if (EFI_ERROR (Status)) {
> > > +DEBUG ((DEBUG_ERROR, "MMCIsCardPresent: Error 
> > > MmcHwInitializationState, Status=%r.\n", Status));
> > > +// If we failed init, go back to requiring card detection
> > > +CardDetectState = 

[edk2-devel] [PATCH v10 31/46] OvmfPkg: Create GHCB pages for use during Pei and Dxe phase

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

Allocate memory for the GHCB pages and the per-CPU variable pages during
SEV initialization for use during Pei and Dxe phases. The GHCB page(s)
must be shared pages, so clear the encryption mask from the current page
table entries. Upon successful allocation, set the GHCB PCDs (PcdGhcbBase
and PcdGhcbSize).

The per-CPU variable page needs to be unique per AP. Using the page after
the GHCB ensures that it is unique per AP. Only the GHCB page is marked as
shared, keeping the per-CPU variable page encyrpted. The same logic is
used in DXE using CreateIdentityMappingPageTables() before switching to
the DXE pagetables.

The GHCB pages (one per vCPU) will be used by the PEI and DXE #VC
exception handlers. The #VC exception handler will fill in the necessary
fields of the GHCB and exit to the hypervisor using the VMGEXIT
instruction. The hypervisor then accesses the GHCB associated with the
vCPU in order to perform the requested function.

Cc: Jordan Justen 
Cc: Laszlo Ersek 
Cc: Ard Biesheuvel 
Reviewed-by: Laszlo Ersek 
Signed-off-by: Tom Lendacky 
---
 OvmfPkg/OvmfPkgIa32.dsc |  2 ++
 OvmfPkg/OvmfPkgIa32X64.dsc  |  2 ++
 OvmfPkg/OvmfPkgX64.dsc  |  2 ++
 OvmfPkg/PlatformPei/PlatformPei.inf |  2 ++
 OvmfPkg/PlatformPei/AmdSev.c| 45 -
 5 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc
index 494b67c5c073..0090cc10ab01 100644
--- a/OvmfPkg/OvmfPkgIa32.dsc
+++ b/OvmfPkg/OvmfPkgIa32.dsc
@@ -607,6 +607,8 @@ [PcdsDynamicDefault]
   gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask|0x0
 
   # Set SEV-ES defaults
+  gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase|0
+  gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbSize|0
   gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled|0
 
 !if $(SMM_REQUIRE) == TRUE
diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc
index 14ecfb24912d..84d91e2ccb91 100644
--- a/OvmfPkg/OvmfPkgIa32X64.dsc
+++ b/OvmfPkg/OvmfPkgIa32X64.dsc
@@ -619,6 +619,8 @@ [PcdsDynamicDefault]
   gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask|0x0
 
   # Set SEV-ES defaults
+  gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase|0
+  gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbSize|0
   gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled|0
 
 !if $(SMM_REQUIRE) == TRUE
diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index ec11ec914556..da37f767fc47 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -617,6 +617,8 @@ [PcdsDynamicDefault]
   gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask|0x0
 
   # Set SEV-ES defaults
+  gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase|0
+  gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbSize|0
   gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled|0
 
 !if $(SMM_REQUIRE) == TRUE
diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf 
b/OvmfPkg/PlatformPei/PlatformPei.inf
index a54d10ba90d5..4742e1bdf42b 100644
--- a/OvmfPkg/PlatformPei/PlatformPei.inf
+++ b/OvmfPkg/PlatformPei/PlatformPei.inf
@@ -102,6 +102,8 @@ [Pcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack
   gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiS3Enable
   gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask
+  gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase
+  gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbSize
   gEfiSecurityPkgTokenSpaceGuid.PcdOptionRomImageVerificationPolicy
   gUefiCpuPkgTokenSpaceGuid.PcdCpuLocalApicBaseAddress
   gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber
diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c
index 4dc5340caa7a..4fd4534cabea 100644
--- a/OvmfPkg/PlatformPei/AmdSev.c
+++ b/OvmfPkg/PlatformPei/AmdSev.c
@@ -10,12 +10,15 @@
 // The package level header files this module uses
 //
 #include 
+#include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -32,7 +35,10 @@ AmdSevEsInitialize (
   VOID
   )
 {
-  RETURN_STATUS PcdStatus;
+  VOID  *GhcbBase;
+  PHYSICAL_ADDRESS  GhcbBasePa;
+  UINTN GhcbPageCount, PageCount;
+  RETURN_STATUS PcdStatus, DecryptStatus;
 
   if (!MemEncryptSevEsIsEnabled ()) {
 return;
@@ -40,6 +46,43 @@ AmdSevEsInitialize (
 
   PcdStatus = PcdSetBoolS (PcdSevEsIsEnabled, TRUE);
   ASSERT_RETURN_ERROR (PcdStatus);
+
+  //
+  // Allocate GHCB and per-CPU variable pages.
+  //
+  GhcbPageCount = mMaxCpuCount * 2;
+  GhcbBase = AllocatePages (GhcbPageCount);
+  ASSERT (GhcbBase != NULL);
+
+  GhcbBasePa = (PHYSICAL_ADDRESS)(UINTN) GhcbBase;
+
+  //
+  // Each vCPU gets two consecutive pages, the first is the GHCB and the
+  // second is the per-CPU variable page. Loop through the allocation and
+  // only clear the encryption mask for the GHCB pages.
+  //
+  for (PageCount = 0; PageCount < GhcbPageCount; PageCount += 2) {
+DecryptStatus = MemEncryptSevClearPageEncMask (
+  0,
+  

[edk2-devel] [PATCH v10 38/46] OvmfPkg/Sec: Enable cache early to speed up booting

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

Currently, the OVMF code relies on the hypervisor to enable the cache
support on the processor in order to improve the boot speed. However,
with SEV-ES, the hypervisor is not allowed to change the CR0 register
to enable caching.

Update the OVMF Sec support to enable caching in order to improve the
boot speed when running as an SEV-ES guest.

Cc: Jordan Justen 
Cc: Laszlo Ersek 
Cc: Ard Biesheuvel 
Reviewed-by: Laszlo Ersek 
Signed-off-by: Tom Lendacky 
---
 OvmfPkg/Sec/SecMain.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/OvmfPkg/Sec/SecMain.c b/OvmfPkg/Sec/SecMain.c
index c2a35463dce4..271a06348ed8 100644
--- a/OvmfPkg/Sec/SecMain.c
+++ b/OvmfPkg/Sec/SecMain.c
@@ -905,6 +905,13 @@ SecCoreStartupWithStack (
 // For non SEV-ES guests, just load the IDTR.
 //
 AsmWriteIdtr ();
+  } else {
+//
+// Under SEV-ES, the hypervisor can't modify CR0 and so can't enable
+// caching in order to speed up the boot. Enable caching early for
+// an SEV-ES guest.
+//
+AsmEnableCache ();
   }
 
   DEBUG ((DEBUG_INFO,
-- 
2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62541): https://edk2.groups.io/g/devel/message/62541
Mute This Topic: https://groups.io/mt/75500021/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v10 32/46] OvmfPkg/PlatformPei: Move early GDT into ram when SEV-ES is enabled

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

The SEV support will clear the C-bit from non-RAM areas.  The early GDT
lives in a non-RAM area, so when an exception occurs (like a #VC) the GDT
will be read as un-encrypted even though it is encrypted. This will result
in a failure to be able to handle the exception.

Move the GDT into RAM so it can be accessed without error when running as
an SEV-ES guest.

Cc: Jordan Justen 
Cc: Laszlo Ersek 
Cc: Ard Biesheuvel 
Reviewed-by: Laszlo Ersek 
Signed-off-by: Tom Lendacky 
---
 OvmfPkg/PlatformPei/AmdSev.c | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c
index 4fd4534cabea..a2b38c591236 100644
--- a/OvmfPkg/PlatformPei/AmdSev.c
+++ b/OvmfPkg/PlatformPei/AmdSev.c
@@ -39,6 +39,8 @@ AmdSevEsInitialize (
   PHYSICAL_ADDRESS  GhcbBasePa;
   UINTN GhcbPageCount, PageCount;
   RETURN_STATUS PcdStatus, DecryptStatus;
+  IA32_DESCRIPTOR   Gdtr;
+  VOID  *Gdt;
 
   if (!MemEncryptSevEsIsEnabled ()) {
 return;
@@ -83,6 +85,22 @@ AmdSevEsInitialize (
 (UINT64)GhcbPageCount, GhcbBase));
 
   AsmWriteMsr64 (MSR_SEV_ES_GHCB, GhcbBasePa);
+
+  //
+  // The SEV support will clear the C-bit from non-RAM areas.  The early GDT
+  // lives in a non-RAM area, so when an exception occurs (like a #VC) the GDT
+  // will be read as un-encrypted even though it was created before the C-bit
+  // was cleared (encrypted). This will result in a failure to be able to
+  // handle the exception.
+  //
+  AsmReadGdtr ();
+
+  Gdt = AllocatePages (EFI_SIZE_TO_PAGES ((UINTN) Gdtr.Limit + 1));
+  ASSERT (Gdt != NULL);
+
+  CopyMem (Gdt, (VOID *) Gdtr.Base, Gdtr.Limit + 1);
+  Gdtr.Base = (UINTN) Gdt;
+  AsmWriteGdtr ();
 }
 
 /**
-- 
2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62535): https://edk2.groups.io/g/devel/message/62535
Mute This Topic: https://groups.io/mt/75500015/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v10 39/46] OvmfPkg/QemuFlashFvbServicesRuntimeDxe: Bypass flash detection with SEV-ES

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

The flash detection routine will attempt to determine how the flash
device behaves (e.g. ROM, RAM, Flash). But when SEV-ES is enabled and
the flash device behaves as a ROM device (meaning it is marked read-only
by the hypervisor), this check may result in an infinite nested page fault
because of the attempted write. Since the instruction cannot be emulated
when SEV-ES is enabled, the RIP is never advanced, resulting in repeated
nested page faults.

When SEV-ES is enabled, exit the flash detection early and assume that
the FD behaves as Flash. This will result in QemuFlashWrite() being called
to store EFI variables, which will also result in an infinite nested page
fault when the write is performed. In this case, update QemuFlashWrite()
to use the VMGEXIT MMIO write support to have the hypervisor perform the
write without having to emulate the instruction.

Cc: Jordan Justen 
Cc: Laszlo Ersek 
Cc: Ard Biesheuvel 
Reviewed-by: Laszlo Ersek 
Signed-off-by: Tom Lendacky 
---
 .../FvbServicesRuntimeDxe.inf |  2 +
 .../QemuFlash.h   | 13 ++
 .../QemuFlash.c   | 23 +--
 .../QemuFlashDxe.c| 40 +++
 .../QemuFlashSmm.c| 16 
 5 files changed, 91 insertions(+), 3 deletions(-)

diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf 
b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
index 72cabba4357d..8bb2325157ea 100644
--- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
+++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
@@ -38,6 +38,7 @@ [Sources]
 [Packages]
   MdePkg/MdePkg.dec
   MdeModulePkg/MdeModulePkg.dec
+  UefiCpuPkg/UefiCpuPkg.dec
   OvmfPkg/OvmfPkg.dec
 
 [LibraryClasses]
@@ -52,6 +53,7 @@ [LibraryClasses]
   UefiBootServicesTableLib
   UefiDriverEntryPoint
   UefiRuntimeLib
+  VmgExitLib
 
 [Guids]
   gEfiEventVirtualAddressChangeGuid   # ALWAYS_CONSUMED
diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.h 
b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.h
index f1afabcbe6ae..219d0d6e83cf 100644
--- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.h
+++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.h
@@ -89,5 +89,18 @@ QemuFlashBeforeProbe (
   IN  UINTN   FdBlockCount
   );
 
+/**
+  Write to QEMU Flash
+
+  @param[in] PtrPointer to the location to write.
+  @param[in] Value  The value to write.
+
+**/
+VOID
+QemuFlashPtrWrite (
+  INvolatile UINT8*Ptr,
+  INUINT8 Value
+  );
+
 #endif
 
diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c 
b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c
index 1b0d6c053f1a..0d29bf701aca 100644
--- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c
+++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c
@@ -9,6 +9,7 @@
 
 #include 
 #include 
+#include 
 #include 
 
 #include "QemuFlash.h"
@@ -80,6 +81,21 @@ QemuFlashDetected (
 
   DEBUG ((DEBUG_INFO, "QEMU Flash: Attempting flash detection at %p\n", Ptr));
 
+  if (MemEncryptSevEsIsEnabled ()) {
+//
+// When SEV-ES is enabled, the check below can result in an infinite
+// loop with respect to a nested page fault. When the memslot is mapped
+// read-only, the nested page table entry is read-only. The check below
+// will cause a nested page fault that cannot be emulated, causing
+// the instruction to retried over and over. For SEV-ES, acknowledge that
+// the FD appears as ROM and not as FLASH, but report FLASH anyway because
+// FLASH behavior can be simulated using VMGEXIT.
+//
+DEBUG ((DEBUG_INFO,
+  "QEMU Flash: SEV-ES enabled, assuming FD behaves as FLASH\n"));
+return TRUE;
+  }
+
   OriginalUint8 = *Ptr;
   *Ptr = CLEAR_STATUS_CMD;
   ProbeUint8 = *Ptr;
@@ -181,8 +197,9 @@ QemuFlashWrite (
   //
   Ptr = QemuFlashPtr (Lba, Offset);
   for (Loop = 0; Loop < *NumBytes; Loop++) {
-*Ptr = WRITE_BYTE_CMD;
-*Ptr = Buffer[Loop];
+QemuFlashPtrWrite (Ptr, WRITE_BYTE_CMD);
+QemuFlashPtrWrite (Ptr, Buffer[Loop]);
+
 Ptr++;
   }
 
@@ -190,7 +207,7 @@ QemuFlashWrite (
   // Restore flash to read mode
   //
   if (*NumBytes > 0) {
-*(Ptr - 1) = READ_ARRAY_CMD;
+QemuFlashPtrWrite (Ptr - 1, READ_ARRAY_CMD);
   }
 
   return EFI_SUCCESS;
diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashDxe.c 
b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashDxe.c
index 5aabe9d7b59c..565383ee26d2 100644
--- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashDxe.c
+++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashDxe.c
@@ -10,6 +10,9 @@
 **/
 
 #include 
+#include 
+#include 
+#include 
 
 #include "QemuFlash.h"
 
@@ -32,3 +35,40 @@ QemuFlashBeforeProbe (
   // Do nothing
   //
 }
+
+/**
+  Write to QEMU Flash
+
+  @param[in] PtrPointer to the 

[edk2-devel] [PATCH v10 30/46] OvmfPkg/PlatformPei: Reserve GHCB-related areas if S3 is supported

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

Protect the memory used by an SEV-ES guest when S3 is supported. This
includes the page table used to break down the 2MB page that contains
the GHCB so that it can be marked un-encrypted, as well as the GHCB
area.

Regarding the lifecycle of the GHCB-related memory areas:
  PcdOvmfSecGhcbPageTableBase
  PcdOvmfSecGhcbBase

(a) when and how it is initialized after first boot of the VM

  If SEV-ES is enabled, the GHCB-related areas are initialized during
  the SEC phase [OvmfPkg/ResetVector/Ia32/PageTables64.asm].

(b) how it is protected from memory allocations during DXE

  If S3 and SEV-ES are enabled, then InitializeRamRegions()
  [OvmfPkg/PlatformPei/MemDetect.c] protects the ranges with an AcpiNVS
  memory allocation HOB, in PEI.

  If S3 is disabled, then these ranges are not protected. DXE's own page
  tables are first built while still in PEI (see HandOffToDxeCore()
  [MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c]). Those tables are
  located in permanent PEI memory. After CR3 is switched over to them
  (which occurs before jumping to the DXE core entry point), we don't have
  to preserve PcdOvmfSecGhcbPageTableBase. PEI switches to GHCB pages in
  permanent PEI memory and DXE will use these PEI GHCB pages, so we don't
  have to preserve PcdOvmfSecGhcbBase.

(c) how it is protected from the OS

  If S3 is enabled, then (b) reserves it from the OS too.

  If S3 is disabled, then the range needs no protection.

(d) how it is accessed on the S3 resume path

  It is rewritten same as in (a), which is fine because (b) reserved it.

(e) how it is accessed on the warm reset path

  It is rewritten same as in (a).

Cc: Jordan Justen 
Cc: Laszlo Ersek 
Cc: Ard Biesheuvel 
Cc: Anthony Perard 
Cc: Julien Grall 
Reviewed-by: Laszlo Ersek 
Signed-off-by: Tom Lendacky 
---
 OvmfPkg/PlatformPei/PlatformPei.inf |  4 
 OvmfPkg/PlatformPei/MemDetect.c | 23 +++
 2 files changed, 27 insertions(+)

diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf 
b/OvmfPkg/PlatformPei/PlatformPei.inf
index 00feb96c9308..a54d10ba90d5 100644
--- a/OvmfPkg/PlatformPei/PlatformPei.inf
+++ b/OvmfPkg/PlatformPei/PlatformPei.inf
@@ -75,6 +75,10 @@ [Pcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesSize
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableBase
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableSize
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbSize
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageBase
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageSize
   gUefiOvmfPkgTokenSpaceGuid.PcdGuidedExtractHandlerTableSize
diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetect.c
index 3b46ea431ade..6b5fee166b5d 100644
--- a/OvmfPkg/PlatformPei/MemDetect.c
+++ b/OvmfPkg/PlatformPei/MemDetect.c
@@ -27,6 +27,7 @@ Module Name:
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -866,6 +867,28 @@ InitializeRamRegions (
   (UINT64)(UINTN) PcdGet32 (PcdOvmfSecPageTablesSize),
   EfiACPIMemoryNVS
   );
+
+if (MemEncryptSevEsIsEnabled ()) {
+  //
+  // If SEV-ES is enabled, reserve the GHCB-related memory area. This
+  // includes the extra page table used to break down the 2MB page
+  // mapping into 4KB page entries where the GHCB resides and the
+  // GHCB area itself.
+  //
+  // Since this memory range will be used by the Reset Vector on S3
+  // resume, it must be reserved as ACPI NVS.
+  //
+  BuildMemoryAllocationHob (
+(EFI_PHYSICAL_ADDRESS)(UINTN) PcdGet32 (PcdOvmfSecGhcbPageTableBase),
+(UINT64)(UINTN) PcdGet32 (PcdOvmfSecGhcbPageTableSize),
+EfiACPIMemoryNVS
+);
+  BuildMemoryAllocationHob (
+(EFI_PHYSICAL_ADDRESS)(UINTN) PcdGet32 (PcdOvmfSecGhcbBase),
+(UINT64)(UINTN) PcdGet32 (PcdOvmfSecGhcbSize),
+EfiACPIMemoryNVS
+);
+}
 #endif
   }
 
-- 
2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62533): https://edk2.groups.io/g/devel/message/62533
Mute This Topic: https://groups.io/mt/75500011/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v10 34/46] OvmfPkg: Reserve a page in memory for the SEV-ES usage

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

Reserve a fixed area of memory for SEV-ES use and set a fixed PCD,
PcdSevEsWorkAreaBase, to this value.

This area will be used by SEV-ES support for two purposes:
  1. Communicating the SEV-ES status during BSP boot to SEC:
 Using a byte of memory from the page, the BSP reset vector code can
 communicate the SEV-ES status to SEC for use before exception
 handling can be enabled in SEC. After SEC, this field is no longer
 valid and the standard way of determine if SEV-ES is active should
 be used.

  2. Establishing an area of memory for AP boot support:
 A hypervisor is not allowed to update an SEV-ES guest's register
 state, so when booting an SEV-ES guest AP, the hypervisor is not
 allowed to set the RIP to the guest requested value. Instead an
 SEV-ES AP must be re-directed from within the guest to the actual
 requested staring location as specified in the INIT-SIPI-SIPI
 sequence.

 Use this memory for reset vector code that can be programmed to have
 the AP jump to the desired RIP location after starting the AP. This
 is required for only the very first AP reset.

Cc: Jordan Justen 
Cc: Laszlo Ersek 
Cc: Ard Biesheuvel 
Reviewed-by: Laszlo Ersek 
Signed-off-by: Tom Lendacky 
---
 OvmfPkg/OvmfPkgX64.fdf | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf
index 88b1e880e603..8836b30a0cef 100644
--- a/OvmfPkg/OvmfPkgX64.fdf
+++ b/OvmfPkg/OvmfPkgX64.fdf
@@ -82,6 +82,9 @@ [FD.MEMFD]
 0x009000|0x002000
 
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbSize
 
+0x00B000|0x001000
+gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase|gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaSize
+
 0x01|0x01
 
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize
 
-- 
2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62537): https://edk2.groups.io/g/devel/message/62537
Mute This Topic: https://groups.io/mt/75500017/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v10 33/46] UefiCpuPkg: Create an SEV-ES workarea PCD

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

Create an SEV-ES workarea PCD. This PCD will be used for BSP communication
during SEC and for AP startup during PEI and DXE phases, the latter is the
reason for creating it in the UefiCpuPkg.

Cc: Eric Dong 
Cc: Ray Ni 
Cc: Laszlo Ersek 
Reviewed-by: Eric Dong 
Signed-off-by: Tom Lendacky 
---
 UefiCpuPkg/UefiCpuPkg.dec | 8 
 UefiCpuPkg/UefiCpuPkg.uni | 8 
 2 files changed, 16 insertions(+)

diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec
index cb92f34b6f55..8c614f9b42bd 100644
--- a/UefiCpuPkg/UefiCpuPkg.dec
+++ b/UefiCpuPkg/UefiCpuPkg.dec
@@ -161,6 +161,14 @@ [PcdsFixedAtBuild]
   # @Prompt Specify the count of pre allocated SMM MP tokens per chunk.
   gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmMpTokenCountPerChunk|64|UINT32|0x30002002
 
+  ## Area of memory where the SEV-ES work area block lives.
+  # @Prompt Configure the SEV-ES work area base
+  gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase|0x0|UINT32|0x30002005
+
+  ## Size of teh area of memory where the SEV-ES work area block lives.
+  # @Prompt Configure the SEV-ES work area base
+  gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaSize|0x0|UINT32|0x30002006
+
 [PcdsFixedAtBuild, PcdsPatchableInModule]
   ## This value is the CPU Local APIC base address, which aligns the address 
on a 4-KByte boundary.
   # @Prompt Configure base address of CPU Local APIC
diff --git a/UefiCpuPkg/UefiCpuPkg.uni b/UefiCpuPkg/UefiCpuPkg.uni
index f4a0c72f6293..219c1963bf08 100644
--- a/UefiCpuPkg/UefiCpuPkg.uni
+++ b/UefiCpuPkg/UefiCpuPkg.uni
@@ -281,3 +281,11 @@
 
 #string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsIsEnabled_PROMPT  #language 
en-US "Specifies whether SEV-ES is enabled"
 #string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsIsEnabled_HELP#language 
en-US "Set to TRUE when running as an SEV-ES guest, FALSE otherwise."
+
+#string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsWorkAreaBase_PROMPT  #language 
en-US "Specify the address of the SEV-ES work area"
+
+#string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsWorkAreaBase_HELP#language 
en-US "Specifies the address of the work area used by an SEV-ES guest."
+
+#string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsWorkAreaSize_PROMPT  #language 
en-US "Specify the size of the SEV-ES work area"
+
+#string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsWorkAreaSize_HELP#language 
en-US "Specifies the size of the work area used by an SEV-ES guest."
-- 
2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62536): https://edk2.groups.io/g/devel/message/62536
Mute This Topic: https://groups.io/mt/75500016/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v10 35/46] OvmfPkg/PlatformPei: Reserve SEV-ES work area if S3 is supported

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

Protect the SEV-ES work area memory used by an SEV-ES guest.

Regarding the lifecycle of the SEV-ES memory area:
  PcdSevEsWorkArea

(a) when and how it is initialized after first boot of the VM

  If SEV-ES is enabled, the SEV-ES area is initialized during
  the SEC phase [OvmfPkg/ResetVector/Ia32/PageTables64.asm].

(b) how it is protected from memory allocations during DXE

  If SEV-ES is enabled, then InitializeRamRegions()
  [OvmfPkg/PlatformPei/MemDetect.c] protects the ranges with either
  an AcpiNVS (S3 enabled) or BootServicesData (S3 disabled) memory
  allocation HOB, in PEI.

(c) how it is protected from the OS

  If S3 is enabled, then (b) reserves it from the OS too.

  If S3 is disabled, then the range needs no protection.

(d) how it is accessed on the S3 resume path

  It is rewritten same as in (a), which is fine because (b) reserved it.

(e) how it is accessed on the warm reset path

  It is rewritten same as in (a).

Cc: Jordan Justen 
Cc: Laszlo Ersek 
Cc: Ard Biesheuvel 
Cc: Anthony Perard 
Cc: Julien Grall 
Reviewed-by: Laszlo Ersek 
Signed-off-by: Tom Lendacky 
---
 OvmfPkg/PlatformPei/PlatformPei.inf |  2 ++
 OvmfPkg/PlatformPei/MemDetect.c | 20 
 2 files changed, 22 insertions(+)

diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf 
b/OvmfPkg/PlatformPei/PlatformPei.inf
index 4742e1bdf42b..c53be2f4925c 100644
--- a/OvmfPkg/PlatformPei/PlatformPei.inf
+++ b/OvmfPkg/PlatformPei/PlatformPei.inf
@@ -118,6 +118,8 @@ [FixedPcd]
   gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType
   gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode
   gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData
+  gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase
+  gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaSize
 
 [FeaturePcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdCsmEnable
diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetect.c
index 6b5fee166b5d..ffbbef891a11 100644
--- a/OvmfPkg/PlatformPei/MemDetect.c
+++ b/OvmfPkg/PlatformPei/MemDetect.c
@@ -940,5 +940,25 @@ InitializeRamRegions (
   );
   }
 }
+
+#ifdef MDE_CPU_X64
+if (MemEncryptSevEsIsEnabled ()) {
+  //
+  // If SEV-ES is enabled, reserve the SEV-ES work area.
+  //
+  // Since this memory range will be used by the Reset Vector on S3
+  // resume, it must be reserved as ACPI NVS.
+  //
+  // If S3 is unsupported, then various drivers might still write to the
+  // work area. We ought to prevent DXE from serving allocation requests
+  // such that they would overlap the work area.
+  //
+  BuildMemoryAllocationHob (
+(EFI_PHYSICAL_ADDRESS)(UINTN) FixedPcdGet32 (PcdSevEsWorkAreaBase),
+(UINT64)(UINTN) FixedPcdGet32 (PcdSevEsWorkAreaSize),
+mS3Supported ? EfiACPIMemoryNVS : EfiBootServicesData
+);
+}
+#endif
   }
 }
-- 
2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62538): https://edk2.groups.io/g/devel/message/62538
Mute This Topic: https://groups.io/mt/75500018/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v10 36/46] OvmfPkg/ResetVector: Add support for a 32-bit SEV check

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

During BSP startup, the reset vector code will issue a CPUID instruction
while in 32-bit mode. When running as an SEV-ES guest, this will trigger
a #VC exception.

Add exception handling support to the early reset vector code to catch
these exceptions.  Also, since the guest is in 32-bit mode at this point,
writes to the GHCB will be encrypted and thus not able to be read by the
hypervisor, so use the GHCB CPUID request/response protocol to obtain the
requested CPUID function values and provide these to the guest.

The exception handling support is active during the SEV check and uses the
OVMF temporary RAM space for a stack. After the SEV check is complete, the
exception handling support is removed and the stack pointer cleared.

Cc: Jordan Justen 
Cc: Laszlo Ersek 
Cc: Ard Biesheuvel 
Reviewed-by: Laszlo Ersek 
Signed-off-by: Tom Lendacky 
---
 OvmfPkg/ResetVector/ResetVector.inf   |   3 +
 OvmfPkg/ResetVector/Ia32/PageTables64.asm | 275 +-
 OvmfPkg/ResetVector/ResetVector.nasmb |   2 +
 3 files changed, 277 insertions(+), 3 deletions(-)

diff --git a/OvmfPkg/ResetVector/ResetVector.inf 
b/OvmfPkg/ResetVector/ResetVector.inf
index 483fd90fe785..a53ae6c194ae 100644
--- a/OvmfPkg/ResetVector/ResetVector.inf
+++ b/OvmfPkg/ResetVector/ResetVector.inf
@@ -34,9 +34,12 @@ [BuildOptions]
*_*_X64_NASMB_FLAGS = -I$(WORKSPACE)/UefiCpuPkg/ResetVector/Vtf0/
 
 [Pcd]
+  gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbSize
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableBase
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableSize
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesSize
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize
diff --git a/OvmfPkg/ResetVector/Ia32/PageTables64.asm 
b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
index 9f86ddf6f08f..7c72128a84d6 100644
--- a/OvmfPkg/ResetVector/Ia32/PageTables64.asm
+++ b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
@@ -36,13 +36,58 @@ BITS32
PAGE_READ_WRITE + \
PAGE_PRESENT)
 
+;
+; SEV-ES #VC exception handler support
+;
+; #VC handler local variable locations
+;
+%define VC_CPUID_RESULT_EAX 0
+%define VC_CPUID_RESULT_EBX 4
+%define VC_CPUID_RESULT_ECX 8
+%define VC_CPUID_RESULT_EDX12
+%define VC_GHCB_MSR_EDX16
+%define VC_GHCB_MSR_EAX20
+%define VC_CPUID_REQUEST_REGISTER  24
+%define VC_CPUID_FUNCTION  28
+
+; #VC handler total local variable size
+;
+%define VC_VARIABLE_SIZE   32
+
+; #VC handler GHCB CPUID request/response protocol values
+;
+%define GHCB_CPUID_REQUEST  4
+%define GHCB_CPUID_RESPONSE 5
+%define GHCB_CPUID_REGISTER_SHIFT  30
+%define CPUID_INSN_LEN  2
+
+
 ; Check if Secure Encrypted Virtualization (SEV) feature is enabled
 ;
-; If SEV is enabled then EAX will be at least 32
+; Modified:  EAX, EBX, ECX, EDX, ESP
+;
+; If SEV is enabled then EAX will be at least 32.
 ; If SEV is disabled then EAX will be zero.
 ;
 CheckSevFeature:
+; Set the first byte of the workarea to zero to communicate to the SEC
+; phase that SEV-ES is not enabled. If SEV-ES is enabled, the CPUID
+; instruction will trigger a #VC exception where the first byte of the
+; workarea will be set to one.
+mov byte[SEV_ES_WORK_AREA], 0
+
+;
+; Set up exception handlers to check for SEV-ES
+;   Load temporary RAM stack based on PCDs (see SevEsIdtVmmComm for
+;   stack usage)
+;   Establish exception handlers
+;
+mov   esp, SEV_ES_VC_TOP_OF_STACK
+mov   eax, ADDR_OF(Idtr)
+lidt  [cs:eax]
+
 ; Check if we have a valid (0x8000_001F) CPUID leaf
+;   CPUID raises a #VC exception if running as an SEV-ES guest
 mov   eax, 0x8000
 cpuid
 
@@ -53,8 +98,8 @@ CheckSevFeature:
 jlNoSev
 
 ; Check for memory encryption feature:
-;  CPUID  Fn8000_001F[EAX] - Bit 1
-;
+; CPUID  Fn8000_001F[EAX] - Bit 1
+;   CPUID raises a #VC exception if running as an SEV-ES guest
 mov   eax,  0x801f
 cpuid
 bteax, 1
@@ -78,6 +123,15 @@ NoSev:
 xor   eax, eax
 
 SevExit:
+;
+; Clear exception handlers and stack
+;
+push  eax
+mov   eax, ADDR_OF(IdtrClear)
+lidt  [cs:eax]
+pop   eax
+mov   esp, 0
+
 OneTimeCallRet CheckSevFeature
 
 ; Check if Secure Encrypted Virtualization - Encrypted State (SEV-ES) feature
@@ -222,3 +276,218 @@ SetCr3:
 mov cr3, eax
 
 OneTimeCallRet SetCr3ForPageTables64
+
+;
+; Start of #VC exception handling routines
+;
+
+SevEsIdtNotCpuid:
+;
+; Use VMGEXIT to request termination.
+;   1 

[edk2-devel] [PATCH v10 37/46] OvmfPkg/Sec: Add #VC exception handling for Sec phase

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

An SEV-ES guest will generate a #VC exception when it encounters a
non-automatic exit (NAE) event. It is expected that the #VC exception
handler will communicate with the hypervisor using the GHCB to handle
the NAE event.

NAE events can occur during the Sec phase, so initialize exception
handling early in the OVMF Sec support.

Before establishing the exception handling, validate that the supported
version of the SEV-ES protocol in OVMF is supported by the hypervisor.

Cc: Jordan Justen 
Cc: Laszlo Ersek 
Cc: Ard Biesheuvel 
Reviewed-by: Laszlo Ersek 
Signed-off-by: Tom Lendacky 
---
 OvmfPkg/Sec/SecMain.inf |   4 +
 OvmfPkg/Sec/SecMain.c   | 181 +---
 2 files changed, 172 insertions(+), 13 deletions(-)

diff --git a/OvmfPkg/Sec/SecMain.inf b/OvmfPkg/Sec/SecMain.inf
index 63ba4cb555fb..7f78dcee2772 100644
--- a/OvmfPkg/Sec/SecMain.inf
+++ b/OvmfPkg/Sec/SecMain.inf
@@ -50,15 +50,19 @@ [LibraryClasses]
   PeCoffExtraActionLib
   ExtractGuidedSectionLib
   LocalApicLib
+  CpuExceptionHandlerLib
 
 [Ppis]
   gEfiTemporaryRamSupportPpiGuid# PPI ALWAYS_PRODUCED
 
 [Pcd]
+  gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvSize
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvBase
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvSize
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbSize
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize
diff --git a/OvmfPkg/Sec/SecMain.c b/OvmfPkg/Sec/SecMain.c
index 6dea6e771a29..c2a35463dce4 100644
--- a/OvmfPkg/Sec/SecMain.c
+++ b/OvmfPkg/Sec/SecMain.c
@@ -24,6 +24,9 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 #include 
 
@@ -34,6 +37,10 @@ typedef struct _SEC_IDT_TABLE {
   IA32_IDT_GATE_DESCRIPTOR  IdtTable[SEC_IDT_ENTRY_COUNT];
 } SEC_IDT_TABLE;
 
+typedef struct _SEC_SEV_ES_WORK_AREA {
+  UINT8  SevEsEnabled;
+} SEC_SEV_ES_WORK_AREA;
+
 VOID
 EFIAPI
 SecStartupPhase2 (
@@ -712,6 +719,120 @@ FindAndReportEntryPoints (
   return;
 }
 
+/**
+  Handle an SEV-ES/GHCB protocol check failure.
+
+  Notify the hypervisor using the VMGEXIT instruction that the SEV-ES guest
+  wishes to be terminated.
+
+  @param[in] ReasonCode  Reason code to provide to the hypervisor for the
+ termination request.
+
+**/
+STATIC
+VOID
+SevEsProtocolFailure (
+  IN UINT8  ReasonCode
+  )
+{
+  MSR_SEV_ES_GHCB_REGISTER  Msr;
+
+  //
+  // Use the GHCB MSR Protocol to request termination by the hypervisor
+  //
+  Msr.GhcbPhysicalAddress = 0;
+  Msr.GhcbTerminate.Function = GHCB_INFO_TERMINATE_REQUEST;
+  Msr.GhcbTerminate.ReasonCodeSet = GHCB_TERMINATE_GHCB;
+  Msr.GhcbTerminate.ReasonCode = ReasonCode;
+  AsmWriteMsr64 (MSR_SEV_ES_GHCB, Msr.GhcbPhysicalAddress);
+
+  AsmVmgExit ();
+
+  ASSERT (FALSE);
+  CpuDeadLoop ();
+}
+
+/**
+  Validate the SEV-ES/GHCB protocol level.
+
+  Verify that the level of SEV-ES/GHCB protocol supported by the hypervisor
+  and the guest intersect. If they don't intersect, request termination.
+
+**/
+STATIC
+VOID
+SevEsProtocolCheck (
+  VOID
+  )
+{
+  MSR_SEV_ES_GHCB_REGISTER  Msr;
+  GHCB  *Ghcb;
+
+  //
+  // Use the GHCB MSR Protocol to obtain the GHCB SEV-ES Information for
+  // protocol checking
+  //
+  Msr.GhcbPhysicalAddress = 0;
+  Msr.GhcbInfo.Function = GHCB_INFO_SEV_INFO_GET;
+  AsmWriteMsr64 (MSR_SEV_ES_GHCB, Msr.GhcbPhysicalAddress);
+
+  AsmVmgExit ();
+
+  Msr.GhcbPhysicalAddress = AsmReadMsr64 (MSR_SEV_ES_GHCB);
+
+  if (Msr.GhcbInfo.Function != GHCB_INFO_SEV_INFO) {
+SevEsProtocolFailure (GHCB_TERMINATE_GHCB_GENERAL);
+  }
+
+  if (Msr.GhcbProtocol.SevEsProtocolMin > Msr.GhcbProtocol.SevEsProtocolMax) {
+SevEsProtocolFailure (GHCB_TERMINATE_GHCB_PROTOCOL);
+  }
+
+  if ((Msr.GhcbProtocol.SevEsProtocolMin > GHCB_VERSION_MAX) ||
+  (Msr.GhcbProtocol.SevEsProtocolMax < GHCB_VERSION_MIN)) {
+SevEsProtocolFailure (GHCB_TERMINATE_GHCB_PROTOCOL);
+  }
+
+  //
+  // SEV-ES protocol checking succeeded, set the initial GHCB address
+  //
+  Msr.GhcbPhysicalAddress = FixedPcdGet32 (PcdOvmfSecGhcbBase);
+  AsmWriteMsr64 (MSR_SEV_ES_GHCB, Msr.GhcbPhysicalAddress);
+
+  Ghcb = Msr.Ghcb;
+  SetMem (Ghcb, sizeof (*Ghcb), 0);
+
+  //
+  // Set the version to the maximum that can be supported
+  //
+  Ghcb->ProtocolVersion = MIN (Msr.GhcbProtocol.SevEsProtocolMax, 
GHCB_VERSION_MAX);
+  Ghcb->GhcbUsage = GHCB_STANDARD_USAGE;
+}
+
+/**
+  Determine if SEV-ES is active.
+
+  During early booting, SEV-ES support code will set a flag to indicate that
+  SEV-ES is enabled. Return the value of this flag as an indicator that SEV-ES
+  is enabled.
+
+  @retval TRUE   SEV-ES is enabled
+  @retval FALSE  SEV-ES is not 

[edk2-devel] [PATCH v10 29/46] OvmfPkg: Create a GHCB page for use during Sec phase

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

A GHCB page is needed during the Sec phase, so this new page must be
created. Since the #VC exception handler routines assume that a per-CPU
variable area is immediately after the GHCB, this per-CPU variable area
must also be created. Since the GHCB must be marked as an un-encrypted,
or shared, page, an additional pagetable page is required to break down
the 2MB region where the GHCB page lives into 4K pagetable entries.

Create a new entry in the OVMF memory layout for the new page table
page and for the SEC GHCB and per-CPU variable pages. After breaking down
the 2MB page, update the GHCB page table entry to remove the encryption
mask.

The GHCB page will be used by the SEC #VC exception handler. The #VC
exception handler will fill in the necessary fields of the GHCB and exit
to the hypervisor using the VMGEXIT instruction. The hypervisor then
accesses the GHCB in order to perform the requested function.

Four new fixed PCDs are needed to support the SEC GHCB page:
  - PcdOvmfSecGhcbBase  UINT32 value that is the base address of the
GHCB used during the SEC phase.
  - PcdOvmfSecGhcbSize  UINT32 value that is the size, in bytes, of the
GHCB area used during the SEC phase.

  - PcdOvmfSecGhcbPageTableBase  UINT32 value that is address of a page
table page used to break down the 2MB page into
512 4K pages.
  - PcdOvmfSecGhcbPageTableSize  UINT32 value that is the size, in bytes,
of the page table page.

Cc: Jordan Justen 
Cc: Laszlo Ersek 
Cc: Ard Biesheuvel 
Reviewed-by: Laszlo Ersek 
Signed-off-by: Tom Lendacky 
---
 OvmfPkg/OvmfPkg.dec   |  9 +++
 OvmfPkg/OvmfPkgX64.fdf|  6 ++
 OvmfPkg/ResetVector/ResetVector.inf   |  5 ++
 OvmfPkg/ResetVector/Ia32/PageTables64.asm | 76 +++
 OvmfPkg/ResetVector/ResetVector.nasmb | 17 +
 5 files changed, 113 insertions(+)

diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec
index 65bb2bb0eb4c..02ad62ed9f43 100644
--- a/OvmfPkg/OvmfPkg.dec
+++ b/OvmfPkg/OvmfPkg.dec
@@ -281,6 +281,15 @@ [PcdsFixedAtBuild]
   ## Number of page frames to use for storing grant table entries.
   gUefiOvmfPkgTokenSpaceGuid.PcdXenGrantFrames|4|UINT32|0x33
 
+  ## Specify the extra page table needed to mark the GHCB as unencrypted.
+  #  The value should be a multiple of 4KB for each.
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableBase|0x0|UINT32|0x3a
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableSize|0x0|UINT32|0x3b
+
+  ## The base address of the SEC GHCB page used by SEV-ES.
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase|0|UINT32|0x3c
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbSize|0|UINT32|0x3d
+
 [PcdsDynamic, PcdsDynamicEx]
   gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent|0|UINT64|2
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable|FALSE|BOOLEAN|0x10
diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf
index bfca1eff9e83..88b1e880e603 100644
--- a/OvmfPkg/OvmfPkgX64.fdf
+++ b/OvmfPkg/OvmfPkgX64.fdf
@@ -76,6 +76,12 @@ [FD.MEMFD]
 0x007000|0x001000
 
gEfiMdePkgTokenSpaceGuid.PcdGuidedExtractHandlerTableAddress|gUefiOvmfPkgTokenSpaceGuid.PcdGuidedExtractHandlerTableSize
 
+0x008000|0x001000
+gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableBase|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableSize
+
+0x009000|0x002000
+gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbSize
+
 0x01|0x01
 
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize
 
diff --git a/OvmfPkg/ResetVector/ResetVector.inf 
b/OvmfPkg/ResetVector/ResetVector.inf
index b0ddfa5832a2..483fd90fe785 100644
--- a/OvmfPkg/ResetVector/ResetVector.inf
+++ b/OvmfPkg/ResetVector/ResetVector.inf
@@ -26,6 +26,7 @@ [Sources]
 [Packages]
   OvmfPkg/OvmfPkg.dec
   MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
   UefiCpuPkg/UefiCpuPkg.dec
 
 [BuildOptions]
@@ -33,5 +34,9 @@ [BuildOptions]
*_*_X64_NASMB_FLAGS = -I$(WORKSPACE)/UefiCpuPkg/ResetVector/Vtf0/
 
 [Pcd]
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbSize
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableBase
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableSize
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesSize
diff --git a/OvmfPkg/ResetVector/Ia32/PageTables64.asm 
b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
index abad009f20f5..9f86ddf6f08f 100644
--- a/OvmfPkg/ResetVector/Ia32/PageTables64.asm
+++ b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
@@ -21,6 +21,11 @@ BITS32
 %define PAGE_2M_MBO0x080
 %define PAGE_2M_PAT  0x01000
 
+%define PAGE_4K_PDE_ATTR (PAGE_ACCESSED + \
+  PAGE_DIRTY + \
+  

[edk2-devel] [PATCH v10 28/46] OvmfPkg: Add support to perform SEV-ES initialization

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

When SEV-ES is enabled, then SEV is also enabled. Add support to the SEV
initialization function to also check for SEV-ES being enabled, and if
enabled, set the SEV-ES enabled PCD (PcdSevEsIsEnabled).

Cc: Jordan Justen 
Cc: Laszlo Ersek 
Cc: Ard Biesheuvel 
Reviewed-by: Laszlo Ersek 
Signed-off-by: Tom Lendacky 
---
 OvmfPkg/OvmfPkgIa32.dsc |  3 +++
 OvmfPkg/OvmfPkgIa32X64.dsc  |  3 +++
 OvmfPkg/OvmfPkgX64.dsc  |  3 +++
 OvmfPkg/PlatformPei/PlatformPei.inf |  1 +
 OvmfPkg/PlatformPei/AmdSev.c| 26 ++
 5 files changed, 36 insertions(+)

diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc
index b6f98af8183c..494b67c5c073 100644
--- a/OvmfPkg/OvmfPkgIa32.dsc
+++ b/OvmfPkg/OvmfPkgIa32.dsc
@@ -606,6 +606,9 @@ [PcdsDynamicDefault]
   # Set memory encryption mask
   gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask|0x0
 
+  # Set SEV-ES defaults
+  gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled|0
+
 !if $(SMM_REQUIRE) == TRUE
   gUefiOvmfPkgTokenSpaceGuid.PcdQ35TsegMbytes|8
   gUefiOvmfPkgTokenSpaceGuid.PcdQ35SmramAtDefaultSmbase|FALSE
diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc
index d147aca168be..14ecfb24912d 100644
--- a/OvmfPkg/OvmfPkgIa32X64.dsc
+++ b/OvmfPkg/OvmfPkgIa32X64.dsc
@@ -618,6 +618,9 @@ [PcdsDynamicDefault]
   # Set memory encryption mask
   gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask|0x0
 
+  # Set SEV-ES defaults
+  gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled|0
+
 !if $(SMM_REQUIRE) == TRUE
   gUefiOvmfPkgTokenSpaceGuid.PcdQ35TsegMbytes|8
   gUefiOvmfPkgTokenSpaceGuid.PcdQ35SmramAtDefaultSmbase|FALSE
diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index 6db1f0b51c7c..ec11ec914556 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -616,6 +616,9 @@ [PcdsDynamicDefault]
   # Set memory encryption mask
   gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask|0x0
 
+  # Set SEV-ES defaults
+  gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled|0
+
 !if $(SMM_REQUIRE) == TRUE
   gUefiOvmfPkgTokenSpaceGuid.PcdQ35TsegMbytes|8
   gUefiOvmfPkgTokenSpaceGuid.PcdQ35SmramAtDefaultSmbase|FALSE
diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf 
b/OvmfPkg/PlatformPei/PlatformPei.inf
index ff397b3ee9d7..00feb96c9308 100644
--- a/OvmfPkg/PlatformPei/PlatformPei.inf
+++ b/OvmfPkg/PlatformPei/PlatformPei.inf
@@ -103,6 +103,7 @@ [Pcd]
   gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber
   gUefiCpuPkgTokenSpaceGuid.PcdCpuBootLogicalProcessorNumber
   gUefiCpuPkgTokenSpaceGuid.PcdCpuApStackSize
+  gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled
 
 [FixedPcd]
   gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress
diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c
index e484f4b311fe..4dc5340caa7a 100644
--- a/OvmfPkg/PlatformPei/AmdSev.c
+++ b/OvmfPkg/PlatformPei/AmdSev.c
@@ -21,6 +21,27 @@
 
 #include "Platform.h"
 
+/**
+
+  Initialize SEV-ES support if running as an SEV-ES guest.
+
+  **/
+STATIC
+VOID
+AmdSevEsInitialize (
+  VOID
+  )
+{
+  RETURN_STATUS PcdStatus;
+
+  if (!MemEncryptSevEsIsEnabled ()) {
+return;
+  }
+
+  PcdStatus = PcdSetBoolS (PcdSevEsIsEnabled, TRUE);
+  ASSERT_RETURN_ERROR (PcdStatus);
+}
+
 /**
 
   Function checks if SEV support is available, if present then it sets
@@ -103,4 +124,9 @@ AmdSevInitialize (
 );
 }
   }
+
+  //
+  // Check and perform SEV-ES initialization if required.
+  //
+  AmdSevEsInitialize ();
 }
-- 
2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62531): https://edk2.groups.io/g/devel/message/62531
Mute This Topic: https://groups.io/mt/7559/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v10 26/46] OvmfPkg/VmgExitLib: Add support for DR7 Read/Write NAE events

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

Under SEV-ES, a DR7 read or write intercept generates a #VC exception.
The #VC handler must provide special support to the guest for this. On
a DR7 write, the #VC handler must cache the value and issue a VMGEXIT
to notify the hypervisor of the write. However, the #VC handler must
not actually set the value of the DR7 register. On a DR7 read, the #VC
handler must return the cached value of the DR7 register to the guest.
VMGEXIT is not invoked for a DR7 register read.

The caching of the DR7 values will make use of the per-CPU data pages
that are allocated along with the GHCB pages. The per-CPU page for a
vCPU is the page that immediately follows the vCPU's GHCB page. Since
each GHCB page is unique for a vCPU, the page that follows becomes
unique for that vCPU. The SEC phase will reserves an area of memory for
a single GHCB and per-CPU page for use by the BSP. After transitioning
to the PEI phase, new GHCB and per-CPU pages are allocated for the BSP
and all APs.

Cc: Jordan Justen 
Cc: Laszlo Ersek 
Cc: Ard Biesheuvel 
Acked-by: Laszlo Ersek 
Signed-off-by: Tom Lendacky 
---
 OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 114 ++
 1 file changed, 114 insertions(+)

diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c 
b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
index e70e0ef82f68..c57c8c4ba203 100644
--- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
+++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
@@ -126,6 +126,14 @@ UINT64
   SEV_ES_INSTRUCTION_DATA  *InstructionData
   );
 
+//
+// Per-CPU data mapping structure
+//
+typedef struct {
+  BOOLEAN  Dr7Cached;
+  UINT64   Dr7;
+} SEV_ES_PER_CPU_DATA;
+
 
 /**
   Checks the GHCB to determine if the specified register has been marked valid.
@@ -1480,6 +1488,104 @@ RdtscExit (
   return 0;
 }
 
+/**
+  Handle a DR7 register write event.
+
+  Use the VMGEXIT instruction to handle a DR7 write event.
+
+  @param[in, out] Ghcb Pointer to the Guest-Hypervisor 
Communication
+   Block
+  @param[in, out] Regs x64 processor context
+  @param[in]  InstructionData  Instruction parsing context
+
+  @retval 0Event handled successfully
+  @return  New exception value to propagate
+
+**/
+STATIC
+UINT64
+Dr7WriteExit (
+  IN OUT GHCB *Ghcb,
+  IN OUT EFI_SYSTEM_CONTEXT_X64   *Regs,
+  IN SEV_ES_INSTRUCTION_DATA  *InstructionData
+  )
+{
+  SEV_ES_INSTRUCTION_OPCODE_EXT  *Ext;
+  SEV_ES_PER_CPU_DATA*SevEsData;
+  UINT64 *Register;
+  UINT64 Status;
+
+  Ext = >Ext;
+  SevEsData = (SEV_ES_PER_CPU_DATA *) (Ghcb + 1);
+
+  DecodeModRm (Regs, InstructionData);
+
+  //
+  // MOV DRn always treats MOD == 3 no matter how encoded
+  //
+  Register = GetRegisterPointer (Regs, Ext->ModRm.Rm);
+
+  //
+  // Using a value of 0 for ExitInfo1 means RAX holds the value
+  //
+  Ghcb->SaveArea.Rax = *Register;
+  GhcbSetRegValid (Ghcb, GhcbRax);
+
+  Status = VmgExit (Ghcb, SVM_EXIT_DR7_WRITE, 0, 0);
+  if (Status != 0) {
+return Status;
+  }
+
+  SevEsData->Dr7 = *Register;
+  SevEsData->Dr7Cached = TRUE;
+
+  return 0;
+}
+
+/**
+  Handle a DR7 register read event.
+
+  Use the VMGEXIT instruction to handle a DR7 read event.
+
+  @param[in, out] Ghcb Pointer to the Guest-Hypervisor 
Communication
+   Block
+  @param[in, out] Regs x64 processor context
+  @param[in]  InstructionData  Instruction parsing context
+
+  @retval 0Event handled successfully
+
+**/
+STATIC
+UINT64
+Dr7ReadExit (
+  IN OUT GHCB *Ghcb,
+  IN OUT EFI_SYSTEM_CONTEXT_X64   *Regs,
+  IN SEV_ES_INSTRUCTION_DATA  *InstructionData
+  )
+{
+  SEV_ES_INSTRUCTION_OPCODE_EXT  *Ext;
+  SEV_ES_PER_CPU_DATA*SevEsData;
+  UINT64 *Register;
+
+  Ext = >Ext;
+  SevEsData = (SEV_ES_PER_CPU_DATA *) (Ghcb + 1);
+
+  DecodeModRm (Regs, InstructionData);
+
+  //
+  // MOV DRn always treats MOD == 3 no matter how encoded
+  //
+  Register = GetRegisterPointer (Regs, Ext->ModRm.Rm);
+
+  //
+  // If there is a cached valued for DR7, return that. Otherwise return the
+  // DR7 standard reset value of 0x400 (no debug breakpoints set).
+  //
+  *Register = (SevEsData->Dr7Cached) ? SevEsData->Dr7 : 0x400;
+
+  return 0;
+}
+
 /**
   Handle a #VC exception.
 
@@ -1524,6 +1630,14 @@ VmgExitHandleVc (
 
   ExitCode = Regs->ExceptionData;
   switch (ExitCode) {
+  case SVM_EXIT_DR7_READ:
+NaeExit = Dr7ReadExit;
+break;
+
+  case SVM_EXIT_DR7_WRITE:
+NaeExit = Dr7WriteExit;
+break;
+
   case SVM_EXIT_RDTSC:
 NaeExit = RdtscExit;
 break;
-- 
2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62529): 

[edk2-devel] [PATCH v10 25/46] OvmfPkg/VmgExitLib: Add support for MWAIT/MWAITX NAE events

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

Under SEV-ES, a MWAIT/MWAITX intercept generates a #VC exception.
VMGEXIT must be used to allow the hypervisor to handle this intercept.

Cc: Jordan Justen 
Cc: Laszlo Ersek 
Cc: Ard Biesheuvel 
Acked-by: Laszlo Ersek 
Signed-off-by: Tom Lendacky 
---
 OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 36 +++
 1 file changed, 36 insertions(+)

diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c 
b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
index fe08b1e0ff49..e70e0ef82f68 100644
--- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
+++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
@@ -856,6 +856,38 @@ MmioExit (
   return Status;
 }
 
+/**
+  Handle a MWAIT event.
+
+  Use the VMGEXIT instruction to handle a MWAIT event.
+
+  @param[in, out] Ghcb Pointer to the Guest-Hypervisor 
Communication
+   Block
+  @param[in, out] Regs x64 processor context
+  @param[in]  InstructionData  Instruction parsing context
+
+  @retval 0Event handled successfully
+  @return  New exception value to propagate
+
+**/
+STATIC
+UINT64
+MwaitExit (
+  IN OUT GHCB *Ghcb,
+  IN OUT EFI_SYSTEM_CONTEXT_X64   *Regs,
+  IN SEV_ES_INSTRUCTION_DATA  *InstructionData
+  )
+{
+  DecodeModRm (Regs, InstructionData);
+
+  Ghcb->SaveArea.Rax = Regs->Rax;
+  GhcbSetRegValid (Ghcb, GhcbRax);
+  Ghcb->SaveArea.Rcx = Regs->Rcx;
+  GhcbSetRegValid (Ghcb, GhcbRcx);
+
+  return VmgExit (Ghcb, SVM_EXIT_MWAIT, 0, 0);
+}
+
 /**
   Handle a MONITOR event.
 
@@ -1532,6 +1564,10 @@ VmgExitHandleVc (
 NaeExit = MonitorExit;
 break;
 
+  case SVM_EXIT_MWAIT:
+NaeExit = MwaitExit;
+break;
+
   case SVM_EXIT_NPF:
 NaeExit = MmioExit;
 break;
-- 
2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62528): https://edk2.groups.io/g/devel/message/62528
Mute This Topic: https://groups.io/mt/7556/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v10 27/46] OvmfPkg/MemEncryptSevLib: Add an SEV-ES guest indicator function

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

Create a function that can be used to determine if the VM is running
as an SEV-ES guest.

Cc: Jordan Justen 
Cc: Laszlo Ersek 
Cc: Ard Biesheuvel 
Reviewed-by: Laszlo Ersek 
Signed-off-by: Tom Lendacky 
---
 OvmfPkg/Include/Library/MemEncryptSevLib.h| 12 +++
 .../MemEncryptSevLibInternal.c| 75 ---
 2 files changed, 60 insertions(+), 27 deletions(-)

diff --git a/OvmfPkg/Include/Library/MemEncryptSevLib.h 
b/OvmfPkg/Include/Library/MemEncryptSevLib.h
index 64dd6977b0f8..a50a0de9c870 100644
--- a/OvmfPkg/Include/Library/MemEncryptSevLib.h
+++ b/OvmfPkg/Include/Library/MemEncryptSevLib.h
@@ -13,6 +13,18 @@
 
 #include 
 
+/**
+  Returns a boolean to indicate whether SEV-ES is enabled
+
+  @retval TRUE   SEV-ES is enabled
+  @retval FALSE  SEV-ES is not enabled
+**/
+BOOLEAN
+EFIAPI
+MemEncryptSevEsIsEnabled (
+  VOID
+  );
+
 /**
   Returns a boolean to indicate whether SEV is enabled
 
diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c 
b/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c
index 96a66e373f11..3301c5c2862f 100644
--- a/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c
+++ b/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c
@@ -20,19 +20,17 @@
 #include 
 
 STATIC BOOLEAN mSevStatus = FALSE;
+STATIC BOOLEAN mSevEsStatus = FALSE;
 STATIC BOOLEAN mSevStatusChecked = FALSE;
 
 /**
+  Reads and sets the status of SEV features
 
-  Returns a boolean to indicate whether SEV is enabled
-
-  @retval TRUE   SEV is enabled
-  @retval FALSE  SEV is not enabled
   **/
 STATIC
-BOOLEAN
+VOID
 EFIAPI
-InternalMemEncryptSevIsEnabled (
+InternalMemEncryptSevStatus (
   VOID
   )
 {
@@ -56,32 +54,55 @@ InternalMemEncryptSevIsEnabled (
   //
   Msr.Uint32 = AsmReadMsr32 (MSR_SEV_STATUS);
   if (Msr.Bits.SevBit) {
-return TRUE;
+mSevStatus = TRUE;
+  }
+
+  //
+  // Check MSR_0xC0010131 Bit 1 (Sev-Es Enabled)
+  //
+  if (Msr.Bits.SevEsBit) {
+mSevEsStatus = TRUE;
   }
 }
   }
 
-  return FALSE;
-}
-
-/**
-  Returns a boolean to indicate whether SEV is enabled
-
-  @retval TRUE   SEV is enabled
-  @retval FALSE  SEV is not enabled
-**/
-BOOLEAN
-EFIAPI
-MemEncryptSevIsEnabled (
-  VOID
-  )
-{
-  if (mSevStatusChecked) {
-return mSevStatus;
-  }
-
-  mSevStatus = InternalMemEncryptSevIsEnabled();
   mSevStatusChecked = TRUE;
+}
+
+/**
+  Returns a boolean to indicate whether SEV-ES is enabled
+
+  @retval TRUE   SEV-ES is enabled
+  @retval FALSE  SEV-ES is not enabled
+**/
+BOOLEAN
+EFIAPI
+MemEncryptSevEsIsEnabled (
+  VOID
+  )
+{
+  if (!mSevStatusChecked) {
+InternalMemEncryptSevStatus ();
+  }
+
+  return mSevEsStatus;
+}
+
+/**
+  Returns a boolean to indicate whether SEV is enabled
+
+  @retval TRUE   SEV is enabled
+  @retval FALSE  SEV is not enabled
+**/
+BOOLEAN
+EFIAPI
+MemEncryptSevIsEnabled (
+  VOID
+  )
+{
+  if (!mSevStatusChecked) {
+InternalMemEncryptSevStatus ();
+  }
 
   return mSevStatus;
 }
-- 
2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62530): https://edk2.groups.io/g/devel/message/62530
Mute This Topic: https://groups.io/mt/7558/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v10 22/46] OvmfPkg/VmgExitLib: Add support for VMMCALL NAE events

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

Under SEV-ES, a VMMCALL intercept generates a #VC exception. VMGEXIT must
be used to allow the hypervisor to handle this intercept.

Cc: Jordan Justen 
Cc: Laszlo Ersek 
Cc: Ard Biesheuvel 
Acked-by: Laszlo Ersek 
Signed-off-by: Tom Lendacky 
---
 OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 48 +++
 1 file changed, 48 insertions(+)

diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c 
b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
index af5264095b98..54134f37e614 100644
--- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
+++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
@@ -881,6 +881,50 @@ WbinvdExit (
   return VmgExit (Ghcb, SVM_EXIT_WBINVD, 0, 0);
 }
 
+/**
+  Handle a VMMCALL event.
+
+  Use the VMGEXIT instruction to handle a VMMCALL event.
+
+  @param[in, out] Ghcb Pointer to the Guest-Hypervisor 
Communication
+   Block
+  @param[in, out] Regs x64 processor context
+  @param[in]  InstructionData  Instruction parsing context
+
+  @retval 0Event handled successfully
+  @return  New exception value to propagate
+
+**/
+STATIC
+UINT64
+VmmCallExit (
+  IN OUT GHCB *Ghcb,
+  IN OUT EFI_SYSTEM_CONTEXT_X64   *Regs,
+  IN SEV_ES_INSTRUCTION_DATA  *InstructionData
+  )
+{
+  UINT64  Status;
+
+  DecodeModRm (Regs, InstructionData);
+
+  Ghcb->SaveArea.Rax = Regs->Rax;
+  GhcbSetRegValid (Ghcb, GhcbRax);
+  Ghcb->SaveArea.Cpl = (UINT8) (Regs->Cs & 0x3);
+  GhcbSetRegValid (Ghcb, GhcbCpl);
+
+  Status = VmgExit (Ghcb, SVM_EXIT_VMMCALL, 0, 0);
+  if (Status != 0) {
+return Status;
+  }
+
+  if (!GhcbIsRegValid (Ghcb, GhcbRax)) {
+return UnsupportedExit (Ghcb, Regs, InstructionData);
+  }
+  Regs->Rax = Ghcb->SaveArea.Rax;
+
+  return 0;
+}
+
 /**
   Handle an MSR event.
 
@@ -1395,6 +1439,10 @@ VmgExitHandleVc (
 NaeExit = MsrExit;
 break;
 
+  case SVM_EXIT_VMMCALL:
+NaeExit = VmmCallExit;
+break;
+
   case SVM_EXIT_WBINVD:
 NaeExit = WbinvdExit;
 break;
-- 
2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62525): https://edk2.groups.io/g/devel/message/62525
Mute This Topic: https://groups.io/mt/75499877/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v10 23/46] OvmfPkg/VmgExitLib: Add support for RDTSCP NAE events

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

Under SEV-ES, a RDTSCP intercept generates a #VC exception. VMGEXIT must be
used to allow the hypervisor to handle this intercept.

Cc: Jordan Justen 
Cc: Laszlo Ersek 
Cc: Ard Biesheuvel 
Acked-by: Laszlo Ersek 
Signed-off-by: Tom Lendacky 
---
 OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 47 +++
 1 file changed, 47 insertions(+)

diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c 
b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
index 54134f37e614..a1cf792d4d0b 100644
--- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
+++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
@@ -881,6 +881,49 @@ WbinvdExit (
   return VmgExit (Ghcb, SVM_EXIT_WBINVD, 0, 0);
 }
 
+/**
+  Handle a RDTSCP event.
+
+  Use the VMGEXIT instruction to handle a RDTSCP event.
+
+  @param[in, out] Ghcb Pointer to the Guest-Hypervisor 
Communication
+   Block
+  @param[in, out] Regs x64 processor context
+  @param[in]  InstructionData  Instruction parsing context
+
+  @retval 0Event handled successfully
+  @return  New exception value to propagate
+
+**/
+STATIC
+UINT64
+RdtscpExit (
+  IN OUT GHCB *Ghcb,
+  IN OUT EFI_SYSTEM_CONTEXT_X64   *Regs,
+  IN SEV_ES_INSTRUCTION_DATA  *InstructionData
+  )
+{
+  UINT64  Status;
+
+  DecodeModRm (Regs, InstructionData);
+
+  Status = VmgExit (Ghcb, SVM_EXIT_RDTSCP, 0, 0);
+  if (Status != 0) {
+return Status;
+  }
+
+  if (!GhcbIsRegValid (Ghcb, GhcbRax) ||
+  !GhcbIsRegValid (Ghcb, GhcbRcx) ||
+  !GhcbIsRegValid (Ghcb, GhcbRdx)) {
+return UnsupportedExit (Ghcb, Regs, InstructionData);
+  }
+  Regs->Rax = Ghcb->SaveArea.Rax;
+  Regs->Rcx = Ghcb->SaveArea.Rcx;
+  Regs->Rdx = Ghcb->SaveArea.Rdx;
+
+  return 0;
+}
+
 /**
   Handle a VMMCALL event.
 
@@ -1443,6 +1486,10 @@ VmgExitHandleVc (
 NaeExit = VmmCallExit;
 break;
 
+  case SVM_EXIT_RDTSCP:
+NaeExit = RdtscpExit;
+break;
+
   case SVM_EXIT_WBINVD:
 NaeExit = WbinvdExit;
 break;
-- 
2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62526): https://edk2.groups.io/g/devel/message/62526
Mute This Topic: https://groups.io/mt/75499881/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v10 24/46] OvmfPkg/VmgExitLib: Add support for MONITOR/MONITORX NAE events

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

Under SEV-ES, a MONITOR/MONITORX intercept generates a #VC exception.
VMGEXIT must be used to allow the hypervisor to handle this intercept.

Cc: Jordan Justen 
Cc: Laszlo Ersek 
Cc: Ard Biesheuvel 
Acked-by: Laszlo Ersek 
Signed-off-by: Tom Lendacky 
---
 OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 38 +++
 1 file changed, 38 insertions(+)

diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c 
b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
index a1cf792d4d0b..fe08b1e0ff49 100644
--- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
+++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
@@ -856,6 +856,40 @@ MmioExit (
   return Status;
 }
 
+/**
+  Handle a MONITOR event.
+
+  Use the VMGEXIT instruction to handle a MONITOR event.
+
+  @param[in, out] Ghcb Pointer to the Guest-Hypervisor 
Communication
+   Block
+  @param[in, out] Regs x64 processor context
+  @param[in]  InstructionData  Instruction parsing context
+
+  @retval 0Event handled successfully
+  @return  New exception value to propagate
+
+**/
+STATIC
+UINT64
+MonitorExit (
+  IN OUT GHCB *Ghcb,
+  IN OUT EFI_SYSTEM_CONTEXT_X64   *Regs,
+  IN SEV_ES_INSTRUCTION_DATA  *InstructionData
+  )
+{
+  DecodeModRm (Regs, InstructionData);
+
+  Ghcb->SaveArea.Rax = Regs->Rax;  // Identity mapped, so VA = PA
+  GhcbSetRegValid (Ghcb, GhcbRax);
+  Ghcb->SaveArea.Rcx = Regs->Rcx;
+  GhcbSetRegValid (Ghcb, GhcbRcx);
+  Ghcb->SaveArea.Rdx = Regs->Rdx;
+  GhcbSetRegValid (Ghcb, GhcbRdx);
+
+  return VmgExit (Ghcb, SVM_EXIT_MONITOR, 0, 0);
+}
+
 /**
   Handle a WBINVD event.
 
@@ -1494,6 +1528,10 @@ VmgExitHandleVc (
 NaeExit = WbinvdExit;
 break;
 
+  case SVM_EXIT_MONITOR:
+NaeExit = MonitorExit;
+break;
+
   case SVM_EXIT_NPF:
 NaeExit = MmioExit;
 break;
-- 
2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62527): https://edk2.groups.io/g/devel/message/62527
Mute This Topic: https://groups.io/mt/75499885/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v10 19/46] OvmfPkg/VmgExitLib: Add support for RDTSC NAE events

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

Under SEV-ES, a RDTSC intercept generates a #VC exception. VMGEXIT must be
used to allow the hypervisor to handle this intercept.

Cc: Jordan Justen 
Cc: Laszlo Ersek 
Cc: Ard Biesheuvel 
Acked-by: Laszlo Ersek 
Signed-off-by: Tom Lendacky 
---
 OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 43 +++
 1 file changed, 43 insertions(+)

diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c 
b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
index bf07f960e380..65af57046063 100644
--- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
+++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
@@ -1221,6 +1221,45 @@ CpuidExit (
   return 0;
 }
 
+/**
+  Handle a RDTSC event.
+
+  Use the VMGEXIT instruction to handle a RDTSC event.
+
+  @param[in, out] Ghcb Pointer to the Guest-Hypervisor 
Communication
+   Block
+  @param[in, out] Regs x64 processor context
+  @param[in]  InstructionData  Instruction parsing context
+
+  @retval 0Event handled successfully
+  @return  New exception value to propagate
+
+**/
+STATIC
+UINT64
+RdtscExit (
+  IN OUT GHCB *Ghcb,
+  IN OUT EFI_SYSTEM_CONTEXT_X64   *Regs,
+  IN SEV_ES_INSTRUCTION_DATA  *InstructionData
+  )
+{
+  UINT64  Status;
+
+  Status = VmgExit (Ghcb, SVM_EXIT_RDTSC, 0, 0);
+  if (Status != 0) {
+return Status;
+  }
+
+  if (!GhcbIsRegValid (Ghcb, GhcbRax) ||
+  !GhcbIsRegValid (Ghcb, GhcbRdx)) {
+return UnsupportedExit (Ghcb, Regs, InstructionData);
+  }
+  Regs->Rax = Ghcb->SaveArea.Rax;
+  Regs->Rdx = Ghcb->SaveArea.Rdx;
+
+  return 0;
+}
+
 /**
   Handle a #VC exception.
 
@@ -1265,6 +1304,10 @@ VmgExitHandleVc (
 
   ExitCode = Regs->ExceptionData;
   switch (ExitCode) {
+  case SVM_EXIT_RDTSC:
+NaeExit = RdtscExit;
+break;
+
   case SVM_EXIT_CPUID:
 NaeExit = CpuidExit;
 break;
-- 
2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62522): https://edk2.groups.io/g/devel/message/62522
Mute This Topic: https://groups.io/mt/75499861/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v10 20/46] OvmfPkg/VmgExitLib: Add support for RDPMC NAE events

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

Under SEV-ES, a RDPMC intercept generates a #VC exception. VMGEXIT must be
used to allow the hypervisor to handle this intercept.

Cc: Jordan Justen 
Cc: Laszlo Ersek 
Cc: Ard Biesheuvel 
Acked-by: Laszlo Ersek 
Signed-off-by: Tom Lendacky 
---
 OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 46 +++
 1 file changed, 46 insertions(+)

diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c 
b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
index 65af57046063..b19bd3ee8906 100644
--- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
+++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
@@ -1221,6 +1221,48 @@ CpuidExit (
   return 0;
 }
 
+/**
+  Handle a RDPMC event.
+
+  Use the VMGEXIT instruction to handle a RDPMC event.
+
+  @param[in, out] Ghcb Pointer to the Guest-Hypervisor 
Communication
+   Block
+  @param[in, out] Regs x64 processor context
+  @param[in]  InstructionData  Instruction parsing context
+
+  @retval 0Event handled successfully
+  @return  New exception value to propagate
+
+**/
+STATIC
+UINT64
+RdpmcExit (
+  IN OUT GHCB *Ghcb,
+  IN OUT EFI_SYSTEM_CONTEXT_X64   *Regs,
+  IN SEV_ES_INSTRUCTION_DATA  *InstructionData
+  )
+{
+  UINT64  Status;
+
+  Ghcb->SaveArea.Rcx = Regs->Rcx;
+  GhcbSetRegValid (Ghcb, GhcbRcx);
+
+  Status = VmgExit (Ghcb, SVM_EXIT_RDPMC, 0, 0);
+  if (Status != 0) {
+return Status;
+  }
+
+  if (!GhcbIsRegValid (Ghcb, GhcbRax) ||
+  !GhcbIsRegValid (Ghcb, GhcbRdx)) {
+return UnsupportedExit (Ghcb, Regs, InstructionData);
+  }
+  Regs->Rax = Ghcb->SaveArea.Rax;
+  Regs->Rdx = Ghcb->SaveArea.Rdx;
+
+  return 0;
+}
+
 /**
   Handle a RDTSC event.
 
@@ -1308,6 +1350,10 @@ VmgExitHandleVc (
 NaeExit = RdtscExit;
 break;
 
+  case SVM_EXIT_RDPMC:
+NaeExit = RdpmcExit;
+break;
+
   case SVM_EXIT_CPUID:
 NaeExit = CpuidExit;
 break;
-- 
2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62523): https://edk2.groups.io/g/devel/message/62523
Mute This Topic: https://groups.io/mt/75499864/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v10 21/46] OvmfPkg/VmgExitLib: Add support for INVD NAE events

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

Under SEV-ES, a INVD intercept generates a #VC exception. VMGEXIT must be
used to allow the hypervisor to handle this intercept.

Cc: Jordan Justen 
Cc: Laszlo Ersek 
Cc: Ard Biesheuvel 
Acked-by: Laszlo Ersek 
Signed-off-by: Tom Lendacky 
---
 OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 29 +++
 1 file changed, 29 insertions(+)

diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c 
b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
index b19bd3ee8906..af5264095b98 100644
--- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
+++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
@@ -1166,6 +1166,31 @@ IoioExit (
   return 0;
 }
 
+/**
+  Handle a INVD event.
+
+  Use the VMGEXIT instruction to handle a INVD event.
+
+  @param[in, out] Ghcb Pointer to the Guest-Hypervisor 
Communication
+   Block
+  @param[in, out] Regs x64 processor context
+  @param[in]  InstructionData  Instruction parsing context
+
+  @retval 0Event handled successfully
+  @return  New exception value to propagate
+
+**/
+STATIC
+UINT64
+InvdExit (
+  IN OUT GHCB *Ghcb,
+  IN OUT EFI_SYSTEM_CONTEXT_X64   *Regs,
+  IN SEV_ES_INSTRUCTION_DATA  *InstructionData
+  )
+{
+  return VmgExit (Ghcb, SVM_EXIT_INVD, 0, 0);
+}
+
 /**
   Handle a CPUID event.
 
@@ -1358,6 +1383,10 @@ VmgExitHandleVc (
 NaeExit = CpuidExit;
 break;
 
+  case SVM_EXIT_INVD:
+NaeExit = InvdExit;
+break;
+
   case SVM_EXIT_IOIO_PROT:
 NaeExit = IoioExit;
 break;
-- 
2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62524): https://edk2.groups.io/g/devel/message/62524
Mute This Topic: https://groups.io/mt/75499869/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v10 18/46] OvmfPkg/VmgExitLib: Add support for WBINVD NAE events

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

Under SEV-ES, a WBINVD intercept generates a #VC exception. VMGEXIT must be
used to allow the hypervisor to handle this intercept.

Cc: Jordan Justen 
Cc: Laszlo Ersek 
Cc: Ard Biesheuvel 
Acked-by: Laszlo Ersek 
Signed-off-by: Tom Lendacky 
---
 OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 29 +++
 1 file changed, 29 insertions(+)

diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c 
b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
index 0e502ac14819..bf07f960e380 100644
--- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
+++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
@@ -856,6 +856,31 @@ MmioExit (
   return Status;
 }
 
+/**
+  Handle a WBINVD event.
+
+  Use the VMGEXIT instruction to handle a WBINVD event.
+
+  @param[in, out] Ghcb Pointer to the Guest-Hypervisor 
Communication
+   Block
+  @param[in, out] Regs x64 processor context
+  @param[in]  InstructionData  Instruction parsing context
+
+  @retval 0Event handled successfully
+  @return  New exception value to propagate
+
+**/
+STATIC
+UINT64
+WbinvdExit (
+  IN OUT GHCB *Ghcb,
+  IN OUT EFI_SYSTEM_CONTEXT_X64   *Regs,
+  IN SEV_ES_INSTRUCTION_DATA  *InstructionData
+  )
+{
+  return VmgExit (Ghcb, SVM_EXIT_WBINVD, 0, 0);
+}
+
 /**
   Handle an MSR event.
 
@@ -1252,6 +1277,10 @@ VmgExitHandleVc (
 NaeExit = MsrExit;
 break;
 
+  case SVM_EXIT_WBINVD:
+NaeExit = WbinvdExit;
+break;
+
   case SVM_EXIT_NPF:
 NaeExit = MmioExit;
 break;
-- 
2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62521): https://edk2.groups.io/g/devel/message/62521
Mute This Topic: https://groups.io/mt/75499846/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v10 15/46] OvmfPkg/VmgExitLib: Add support for CPUID NAE events

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

Under SEV-ES, a CPUID intercept generates a #VC exception. VMGEXIT must be
used to allow the hypervisor to handle this intercept.

Add support to construct the required GHCB values to support a CPUID NAE
event. Additionally, CPUID 0x_000d (CPUID_EXTENDED_STATE) requires
XCR0 to be supplied in the GHCB, so add support to issue the XGETBV
instruction.

Cc: Jordan Justen 
Cc: Laszlo Ersek 
Cc: Ard Biesheuvel 
Acked-by: Laszlo Ersek 
Signed-off-by: Tom Lendacky 
---
 OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 60 +++
 1 file changed, 60 insertions(+)

diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c 
b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
index b6ac3552894f..1c9c272a250e 100644
--- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
+++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 //
@@ -597,6 +598,61 @@ IoioExit (
   return 0;
 }
 
+/**
+  Handle a CPUID event.
+
+  Use the VMGEXIT instruction to handle a CPUID event.
+
+  @param[in, out] Ghcb Pointer to the Guest-Hypervisor 
Communication
+   Block
+  @param[in, out] Regs x64 processor context
+  @param[in]  InstructionData  Instruction parsing context
+
+  @retval 0Event handled successfully
+  @return  New exception value to propagate
+
+**/
+STATIC
+UINT64
+CpuidExit (
+  IN OUT GHCB *Ghcb,
+  IN OUT EFI_SYSTEM_CONTEXT_X64   *Regs,
+  IN SEV_ES_INSTRUCTION_DATA  *InstructionData
+  )
+{
+  UINT64  Status;
+
+  Ghcb->SaveArea.Rax = Regs->Rax;
+  GhcbSetRegValid (Ghcb, GhcbRax);
+  Ghcb->SaveArea.Rcx = Regs->Rcx;
+  GhcbSetRegValid (Ghcb, GhcbRcx);
+  if (Regs->Rax == CPUID_EXTENDED_STATE) {
+IA32_CR4  Cr4;
+
+Cr4.UintN = AsmReadCr4 ();
+Ghcb->SaveArea.XCr0 = (Cr4.Bits.OSXSAVE == 1) ? AsmXGetBv (0) : 1;
+GhcbSetRegValid (Ghcb, GhcbXCr0);
+  }
+
+  Status = VmgExit (Ghcb, SVM_EXIT_CPUID, 0, 0);
+  if (Status != 0) {
+return Status;
+  }
+
+  if (!GhcbIsRegValid (Ghcb, GhcbRax) ||
+  !GhcbIsRegValid (Ghcb, GhcbRbx) ||
+  !GhcbIsRegValid (Ghcb, GhcbRcx) ||
+  !GhcbIsRegValid (Ghcb, GhcbRdx)) {
+return UnsupportedExit (Ghcb, Regs, InstructionData);
+  }
+  Regs->Rax = Ghcb->SaveArea.Rax;
+  Regs->Rbx = Ghcb->SaveArea.Rbx;
+  Regs->Rcx = Ghcb->SaveArea.Rcx;
+  Regs->Rdx = Ghcb->SaveArea.Rdx;
+
+  return 0;
+}
+
 /**
   Handle a #VC exception.
 
@@ -641,6 +697,10 @@ VmgExitHandleVc (
 
   ExitCode = Regs->ExceptionData;
   switch (ExitCode) {
+  case SVM_EXIT_CPUID:
+NaeExit = CpuidExit;
+break;
+
   case SVM_EXIT_IOIO_PROT:
 NaeExit = IoioExit;
 break;
-- 
2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62518): https://edk2.groups.io/g/devel/message/62518
Mute This Topic: https://groups.io/mt/75499834/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v10 16/46] OvmfPkg/VmgExitLib: Add support for MSR_PROT NAE events

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

Under SEV-ES, a MSR_PROT intercept generates a #VC exception. VMGEXIT must
be used to allow the hypervisor to handle this intercept.

Add support to construct the required GHCB values to support an MSR_PROT
NAE event. Parse the instruction that generated the #VC exception to
determine whether it is RDMSR or WRMSR, setting the required register
register values in the GHCB and creating the proper SW_EXIT_INFO1 value in
the GHCB.

Cc: Jordan Justen 
Cc: Laszlo Ersek 
Cc: Ard Biesheuvel 
Acked-by: Laszlo Ersek 
Signed-off-by: Tom Lendacky 
---
 OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 65 +++
 1 file changed, 65 insertions(+)

diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c 
b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
index 1c9c272a250e..dbedd4e9f95d 100644
--- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
+++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
@@ -374,6 +374,67 @@ UnsupportedExit (
   return Status;
 }
 
+/**
+  Handle an MSR event.
+
+  Use the VMGEXIT instruction to handle either a RDMSR or WRMSR event.
+
+  @param[in, out] Ghcb Pointer to the Guest-Hypervisor 
Communication
+   Block
+  @param[in, out] Regs x64 processor context
+  @param[in]  InstructionData  Instruction parsing context
+
+  @retval 0Event handled successfully
+  @return  New exception value to propagate
+
+**/
+STATIC
+UINT64
+MsrExit (
+  IN OUT GHCB *Ghcb,
+  IN OUT EFI_SYSTEM_CONTEXT_X64   *Regs,
+  IN SEV_ES_INSTRUCTION_DATA  *InstructionData
+  )
+{
+  UINT64  ExitInfo1, Status;
+
+  ExitInfo1 = 0;
+
+  switch (*(InstructionData->OpCodes + 1)) {
+  case 0x30: // WRMSR
+ExitInfo1 = 1;
+Ghcb->SaveArea.Rax = Regs->Rax;
+GhcbSetRegValid (Ghcb, GhcbRax);
+Ghcb->SaveArea.Rdx = Regs->Rdx;
+GhcbSetRegValid (Ghcb, GhcbRdx);
+//
+// fall through
+//
+  case 0x32: // RDMSR
+Ghcb->SaveArea.Rcx = Regs->Rcx;
+GhcbSetRegValid (Ghcb, GhcbRcx);
+break;
+  default:
+return UnsupportedExit (Ghcb, Regs, InstructionData);
+  }
+
+  Status = VmgExit (Ghcb, SVM_EXIT_MSR, ExitInfo1, 0);
+  if (Status != 0) {
+return Status;
+  }
+
+  if (ExitInfo1 == 0) {
+if (!GhcbIsRegValid (Ghcb, GhcbRax) ||
+!GhcbIsRegValid (Ghcb, GhcbRdx)) {
+  return UnsupportedExit (Ghcb, Regs, InstructionData);
+}
+Regs->Rax = Ghcb->SaveArea.Rax;
+Regs->Rdx = Ghcb->SaveArea.Rdx;
+  }
+
+  return 0;
+}
+
 /**
   Build the IOIO event information.
 
@@ -705,6 +766,10 @@ VmgExitHandleVc (
 NaeExit = IoioExit;
 break;
 
+  case SVM_EXIT_MSR:
+NaeExit = MsrExit;
+break;
+
   default:
 NaeExit = UnsupportedExit;
   }
-- 
2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62519): https://edk2.groups.io/g/devel/message/62519
Mute This Topic: https://groups.io/mt/75499840/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v10 17/46] OvmfPkg/VmgExitLib: Add support for NPF NAE events (MMIO)

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

Under SEV-ES, a NPF intercept for an NPT entry with a reserved bit set
generates a #VC exception. This condition is assumed to be an MMIO access.
VMGEXIT must be used to allow the hypervisor to handle this intercept.

Add support to construct the required GHCB values to support a NPF NAE
event for MMIO.  Parse the instruction that generated the #VC exception,
setting the required register values in the GHCB and creating the proper
SW_EXIT_INFO1, SW_EXITINFO2 and SW_SCRATCH values in the GHCB.

Cc: Jordan Justen 
Cc: Laszlo Ersek 
Cc: Ard Biesheuvel 
Acked-by: Laszlo Ersek 
Signed-off-by: Tom Lendacky 
---
 OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 486 ++
 1 file changed, 486 insertions(+)

diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c 
b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
index dbedd4e9f95d..0e502ac14819 100644
--- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
+++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
@@ -183,6 +183,281 @@ GhcbSetRegValid (
   Ghcb->SaveArea.ValidBitmap[RegIndex] |= (1 << RegBit);
 }
 
+/**
+  Return a pointer to the contents of the specified register.
+
+  Based upon the input register, return a pointer to the registers contents
+  in the x86 processor context.
+
+  @param[in] Regs  x64 processor context
+  @param[in] Register  Register to obtain pointer for
+
+  @return  Pointer to the contents of the requested register
+
+**/
+STATIC
+UINT64 *
+GetRegisterPointer (
+  IN EFI_SYSTEM_CONTEXT_X64   *Regs,
+  IN UINT8Register
+  )
+{
+  UINT64 *Reg;
+
+  switch (Register) {
+  case 0:
+Reg = >Rax;
+break;
+  case 1:
+Reg = >Rcx;
+break;
+  case 2:
+Reg = >Rdx;
+break;
+  case 3:
+Reg = >Rbx;
+break;
+  case 4:
+Reg = >Rsp;
+break;
+  case 5:
+Reg = >Rbp;
+break;
+  case 6:
+Reg = >Rsi;
+break;
+  case 7:
+Reg = >Rdi;
+break;
+  case 8:
+Reg = >R8;
+break;
+  case 9:
+Reg = >R9;
+break;
+  case 10:
+Reg = >R10;
+break;
+  case 11:
+Reg = >R11;
+break;
+  case 12:
+Reg = >R12;
+break;
+  case 13:
+Reg = >R13;
+break;
+  case 14:
+Reg = >R14;
+break;
+  case 15:
+Reg = >R15;
+break;
+  default:
+Reg = NULL;
+  }
+  ASSERT (Reg != NULL);
+
+  return Reg;
+}
+
+/**
+  Update the instruction parsing context for displacement bytes.
+
+  @param[in, out] InstructionData  Instruction parsing context
+  @param[in]  Size The instruction displacement size
+
+**/
+STATIC
+VOID
+UpdateForDisplacement (
+  IN OUT SEV_ES_INSTRUCTION_DATA  *InstructionData,
+  IN UINTNSize
+  )
+{
+  InstructionData->DisplacementSize = Size;
+  InstructionData->Immediate += Size;
+  InstructionData->End += Size;
+}
+
+/**
+  Determine if an instruction address if RIP relative.
+
+  Examine the instruction parsing context to determine if the address offset
+  is relative to the instruction pointer.
+
+  @param[in] InstructionData  Instruction parsing context
+
+  @retval TRUEInstruction addressing is RIP relative
+  @retval FALSE   Instruction addressing is not RIP relative
+
+**/
+STATIC
+BOOLEAN
+IsRipRelative (
+  IN SEV_ES_INSTRUCTION_DATA  *InstructionData
+  )
+{
+  SEV_ES_INSTRUCTION_OPCODE_EXT  *Ext;
+
+  Ext = >Ext;
+
+  return ((InstructionData->Mode == LongMode64Bit) &&
+  (Ext->ModRm.Mod == 0) &&
+  (Ext->ModRm.Rm == 5)  &&
+  (InstructionData->SibPresent == FALSE));
+}
+
+/**
+  Return the effective address of a memory operand.
+
+  Examine the instruction parsing context to obtain the effective memory
+  address of a memory operand.
+
+  @param[in] Regs x64 processor context
+  @param[in] InstructionData  Instruction parsing context
+
+  @return The memory operand effective address
+
+**/
+STATIC
+UINT64
+GetEffectiveMemoryAddress (
+  IN EFI_SYSTEM_CONTEXT_X64   *Regs,
+  IN SEV_ES_INSTRUCTION_DATA  *InstructionData
+  )
+{
+  SEV_ES_INSTRUCTION_OPCODE_EXT  *Ext;
+  UINT64 EffectiveAddress;
+
+  Ext = >Ext;
+  EffectiveAddress = 0;
+
+  if (IsRipRelative (InstructionData)) {
+//
+// RIP-relative displacement is a 32-bit signed value
+//
+INT32 RipRelative;
+
+RipRelative = *(INT32 *) InstructionData->Displacement;
+
+UpdateForDisplacement (InstructionData, 4);
+
+//
+// Negative displacement is handled by standard UINT64 wrap-around.
+//
+return Regs->Rip + (UINT64) RipRelative;
+  }
+
+  switch (Ext->ModRm.Mod) {
+  case 1:
+UpdateForDisplacement (InstructionData, 1);
+EffectiveAddress += (UINT64) (*(INT8 *) (InstructionData->Displacement));
+break;
+  case 2:
+switch (InstructionData->AddrSize) {
+case Size16Bits:
+  UpdateForDisplacement (InstructionData, 2);
+  EffectiveAddress += (UINT64) 

[edk2-devel] [PATCH v10 14/46] OvmfPkg/VmgExitLib: Support string IO for IOIO_PROT NAE events

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

Add support to the #VC exception handler to handle string IO. This
requires expanding the IO instruction parsing to recognize string based
IO instructions as well as preparing an un-encrypted buffer to be used
to transfer (either to or from the guest) the string contents for the IO
operation. The SW_EXITINFO2 and SW_SCRATCH fields of the GHCB are set
appropriately for the operation. Multiple VMGEXIT invocations may be
needed to complete the string IO operation.

Cc: Jordan Justen 
Cc: Laszlo Ersek 
Cc: Ard Biesheuvel 
Acked-by: Laszlo Ersek 
Signed-off-by: Tom Lendacky 
---
 OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 90 ---
 1 file changed, 76 insertions(+), 14 deletions(-)

diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c 
b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
index 04e8b8aebf7d..b6ac3552894f 100644
--- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
+++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
@@ -397,6 +397,26 @@ IoioExitInfo (
   ExitInfo = 0;
 
   switch (*(InstructionData->OpCodes)) {
+  //
+  // INS opcodes
+  //
+  case 0x6C:
+  case 0x6D:
+ExitInfo |= IOIO_TYPE_INS;
+ExitInfo |= IOIO_SEG_ES;
+ExitInfo |= ((Regs->Rdx & 0x) << 16);
+break;
+
+  //
+  // OUTS opcodes
+  //
+  case 0x6E:
+  case 0x6F:
+ExitInfo |= IOIO_TYPE_OUTS;
+ExitInfo |= IOIO_SEG_DS;
+ExitInfo |= ((Regs->Rdx & 0x) << 16);
+break;
+
   //
   // IN immediate opcodes
   //
@@ -445,6 +465,8 @@ IoioExitInfo (
   //
   // Single-byte opcodes
   //
+  case 0x6C:
+  case 0x6E:
   case 0xE4:
   case 0xE6:
   case 0xEC:
@@ -506,30 +528,70 @@ IoioExit (
   IN SEV_ES_INSTRUCTION_DATA  *InstructionData
   )
 {
-  UINT64  ExitInfo1, Status;
+  UINT64   ExitInfo1, ExitInfo2, Status;
+  BOOLEAN  IsString;
 
   ExitInfo1 = IoioExitInfo (Regs, InstructionData);
   if (ExitInfo1 == 0) {
 return UnsupportedExit (Ghcb, Regs, InstructionData);
   }
 
-  if ((ExitInfo1 & IOIO_TYPE_IN) != 0) {
-Ghcb->SaveArea.Rax = 0;
+  IsString = ((ExitInfo1 & IOIO_TYPE_STR) != 0) ? TRUE : FALSE;
+  if (IsString) {
+UINTN  IoBytes, VmgExitBytes;
+UINTN  GhcbCount, OpCount;
+
+Status = 0;
+
+IoBytes = IOIO_DATA_BYTES (ExitInfo1);
+GhcbCount = sizeof (Ghcb->SharedBuffer) / IoBytes;
+
+OpCount = ((ExitInfo1 & IOIO_REP) != 0) ? Regs->Rcx : 1;
+while (OpCount) {
+  ExitInfo2 = MIN (OpCount, GhcbCount);
+  VmgExitBytes = ExitInfo2 * IoBytes;
+
+  if ((ExitInfo1 & IOIO_TYPE_IN) == 0) {
+CopyMem (Ghcb->SharedBuffer, (VOID *) Regs->Rsi, VmgExitBytes);
+Regs->Rsi += VmgExitBytes;
+  }
+
+  Ghcb->SaveArea.SwScratch = (UINT64) Ghcb->SharedBuffer;
+  Status = VmgExit (Ghcb, SVM_EXIT_IOIO_PROT, ExitInfo1, ExitInfo2);
+  if (Status != 0) {
+return Status;
+  }
+
+  if ((ExitInfo1 & IOIO_TYPE_IN) != 0) {
+CopyMem ((VOID *) Regs->Rdi, Ghcb->SharedBuffer, VmgExitBytes);
+Regs->Rdi += VmgExitBytes;
+  }
+
+  if ((ExitInfo1 & IOIO_REP) != 0) {
+Regs->Rcx -= ExitInfo2;
+  }
+
+  OpCount -= ExitInfo2;
+}
   } else {
-CopyMem (>SaveArea.Rax, >Rax, IOIO_DATA_BYTES (ExitInfo1));
-  }
-  GhcbSetRegValid (Ghcb, GhcbRax);
+if ((ExitInfo1 & IOIO_TYPE_IN) != 0) {
+  Ghcb->SaveArea.Rax = 0;
+} else {
+  CopyMem (>SaveArea.Rax, >Rax, IOIO_DATA_BYTES (ExitInfo1));
+}
+GhcbSetRegValid (Ghcb, GhcbRax);
 
-  Status = VmgExit (Ghcb, SVM_EXIT_IOIO_PROT, ExitInfo1, 0);
-  if (Status != 0) {
-return Status;
-  }
+Status = VmgExit (Ghcb, SVM_EXIT_IOIO_PROT, ExitInfo1, 0);
+if (Status != 0) {
+  return Status;
+}
 
-  if ((ExitInfo1 & IOIO_TYPE_IN) != 0) {
-if (!GhcbIsRegValid (Ghcb, GhcbRax)) {
-  return UnsupportedExit (Ghcb, Regs, InstructionData);
+if ((ExitInfo1 & IOIO_TYPE_IN) != 0) {
+  if (!GhcbIsRegValid (Ghcb, GhcbRax)) {
+return UnsupportedExit (Ghcb, Regs, InstructionData);
+  }
+  CopyMem (>Rax, >SaveArea.Rax, IOIO_DATA_BYTES (ExitInfo1));
 }
-CopyMem (>Rax, >SaveArea.Rax, IOIO_DATA_BYTES (ExitInfo1));
   }
 
   return 0;
-- 
2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62517): https://edk2.groups.io/g/devel/message/62517
Mute This Topic: https://groups.io/mt/75499827/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v10 13/46] OvmfPkg/VmgExitLib: Add support for IOIO_PROT NAE events

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

Under SEV-ES, a IOIO_PROT intercept generates a #VC exception. VMGEXIT
must be used to allow the hypervisor to handle this intercept.

Add support to construct the required GHCB values to support a IOIO_PROT
NAE event.  Parse the instruction that generated the #VC exception,
setting the required register values in the GHCB and creating the proper
SW_EXITINFO1 value in the GHCB.

Cc: Jordan Justen 
Cc: Laszlo Ersek 
Cc: Ard Biesheuvel 
Acked-by: Laszlo Ersek 
Signed-off-by: Tom Lendacky 
---
 .../IndustryStandard/InstructionParsing.h |  83 +++
 OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 560 +-
 2 files changed, 629 insertions(+), 14 deletions(-)
 create mode 100644 OvmfPkg/Include/IndustryStandard/InstructionParsing.h

diff --git a/OvmfPkg/Include/IndustryStandard/InstructionParsing.h 
b/OvmfPkg/Include/IndustryStandard/InstructionParsing.h
new file mode 100644
index ..149ff328e06c
--- /dev/null
+++ b/OvmfPkg/Include/IndustryStandard/InstructionParsing.h
@@ -0,0 +1,83 @@
+/** @file
+  Instruction parsing support definitions.
+
+  Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef __INSTRUCTION_PARSING_H__
+#define __INSTRUCTION_PARSING_H__
+
+#include 
+#include 
+
+//
+// Instruction REX prefix definition
+//
+typedef union {
+  struct {
+UINT8  BitB:1;
+UINT8  BitX:1;
+UINT8  BitR:1;
+UINT8  BitW:1;
+UINT8  Rex:4;
+  } Bits;
+
+  UINT8  Uint8;
+} INSTRUCTION_REX_PREFIX;
+
+//
+// Instruction ModRM definition
+//
+typedef union {
+  struct {
+UINT8  Rm:3;
+UINT8  Reg:3;
+UINT8  Mod:2;
+  } Bits;
+
+  UINT8  Uint8;
+} INSTRUCTION_MODRM;
+
+//
+// Instruction SIB definition
+//
+typedef union {
+  struct {
+UINT8  Base:3;
+UINT8  Index:3;
+UINT8  Scale:2;
+  } Bits;
+
+  UINT8  Uint8;
+} INSTRUCTION_SIB;
+
+//
+// Legacy Instruction Prefixes
+//
+#define OVERRIDE_SEGMENT_CS  0x2E
+#define OVERRIDE_SEGMENT_DS  0x3E
+#define OVERRIDE_SEGMENT_ES  0x26
+#define OVERRIDE_SEGMENT_SS  0x36
+#define OVERRIDE_SEGMENT_FS  0x64
+#define OVERRIDE_SEGMENT_GS  0x65
+#define OVERRIDE_OPERAND_SIZE0x66
+#define OVERRIDE_ADDRESS_SIZE0x67
+#define LOCK_PREFIX  0xF0
+#define REPNZ_PREFIX 0xF2
+#define REPZ_PREFIX  0xF3
+
+//
+// REX Prefixes
+//
+#define REX_PREFIX_START 0x40
+#define REX_PREFIX_STOP  0x4F
+#define REX_64BIT_OPERAND_SIZE_MASK  0x08
+
+//
+// Two-byte Opcode Flag
+//
+#define TWO_BYTE_OPCODE_ESCAPE   0x0F
+
+#endif
diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c 
b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
index b6a955ed8088..04e8b8aebf7d 100644
--- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
+++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c
@@ -11,6 +11,529 @@
 #include 
 #include 
 #include 
+#include 
+
+//
+// Instruction execution mode definition
+//
+typedef enum {
+  LongMode64Bit= 0,
+  LongModeCompat32Bit,
+  LongModeCompat16Bit,
+} SEV_ES_INSTRUCTION_MODE;
+
+//
+// Instruction size definition (for operand and address)
+//
+typedef enum {
+  Size8Bits= 0,
+  Size16Bits,
+  Size32Bits,
+  Size64Bits,
+} SEV_ES_INSTRUCTION_SIZE;
+
+//
+// Intruction segment definition
+//
+typedef enum {
+  SegmentEs= 0,
+  SegmentCs,
+  SegmentSs,
+  SegmentDs,
+  SegmentFs,
+  SegmentGs,
+} SEV_ES_INSTRUCTION_SEGMENT;
+
+//
+// Instruction rep function definition
+//
+typedef enum {
+  RepNone  = 0,
+  RepZ,
+  RepNZ,
+} SEV_ES_INSTRUCTION_REP;
+
+typedef struct {
+  UINT8  Rm;
+  UINT8  Reg;
+  UINT8  Mod;
+} SEV_ES_INSTRUCTION_MODRM_EXT;
+
+typedef struct {
+  UINT8  Base;
+  UINT8  Index;
+  UINT8  Scale;
+} SEV_ES_INSTRUCTION_SIB_EXT;
+
+//
+// Instruction opcode definition
+//
+typedef struct {
+  SEV_ES_INSTRUCTION_MODRM_EXT  ModRm;
+
+  SEV_ES_INSTRUCTION_SIB_EXTSib;
+
+  UINTN RegData;
+  UINTN RmData;
+} SEV_ES_INSTRUCTION_OPCODE_EXT;
+
+//
+// Instruction parsing context definition
+//
+typedef struct {
+  GHCB   *Ghcb;
+
+  SEV_ES_INSTRUCTION_MODEMode;
+  SEV_ES_INSTRUCTION_SIZEDataSize;
+  SEV_ES_INSTRUCTION_SIZEAddrSize;
+  BOOLEANSegmentSpecified;
+  SEV_ES_INSTRUCTION_SEGMENT Segment;
+  SEV_ES_INSTRUCTION_REP RepMode;
+
+  UINT8  *Begin;
+  UINT8  *End;
+
+  UINT8  *Prefixes;
+  UINT8  *OpCodes;
+  UINT8  *Displacement;
+  UINT8  *Immediate;
+
+  INSTRUCTION_REX_PREFIX RexPrefix;
+
+  BOOLEANModRmPresent;
+  INSTRUCTION_MODRM  ModRm;
+
+  

[edk2-devel] [PATCH v10 12/46] OvmfPkg/VmgExitLib: Implement library support for VmgExitLib in OVMF

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

The base VmgExitLib library provides a default limited interface. As it
does not provide full support, create an OVMF version of this library to
begin the process of providing full support of SEV-ES within OVMF.

SEV-ES support is only provided for X64 builds, so only OvmfPkgX64.dsc is
updated to make use of the OvmfPkg version of the library.

Cc: Jordan Justen 
Cc: Laszlo Ersek 
Cc: Ard Biesheuvel 
Acked-by: Laszlo Ersek 
Signed-off-by: Tom Lendacky 
---
 OvmfPkg/OvmfPkgX64.dsc|   2 +-
 OvmfPkg/Library/VmgExitLib/VmgExitLib.inf |  36 
 OvmfPkg/Library/VmgExitLib/VmgExitLib.c   | 159 ++
 OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c |  81 +
 4 files changed, 277 insertions(+), 1 deletion(-)
 create mode 100644 OvmfPkg/Library/VmgExitLib/VmgExitLib.inf
 create mode 100644 OvmfPkg/Library/VmgExitLib/VmgExitLib.c
 create mode 100644 OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c

diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index 269b6d973188..6db1f0b51c7c 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -232,7 +232,7 @@ [LibraryClasses]
 
 [LibraryClasses.common]
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
-  VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
+  VmgExitLib|OvmfPkg/Library/VmgExitLib/VmgExitLib.inf
 
 [LibraryClasses.common.SEC]
   TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf
diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitLib.inf 
b/OvmfPkg/Library/VmgExitLib/VmgExitLib.inf
new file mode 100644
index ..d003ac63173e
--- /dev/null
+++ b/OvmfPkg/Library/VmgExitLib/VmgExitLib.inf
@@ -0,0 +1,36 @@
+## @file
+#  VMGEXIT Support Library.
+#
+#  Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION= 0x00010005
+  BASE_NAME  = VmgExitLib
+  FILE_GUID  = 0e923c25-13cd-430b-8714-ffe85652a97b
+  MODULE_TYPE= BASE
+  VERSION_STRING = 1.0
+  LIBRARY_CLASS  = VmgExitLib
+
+#
+# The following information is for reference only and not required by the 
build tools.
+#
+#  VALID_ARCHITECTURES   = X64
+#
+
+[Sources.common]
+  VmgExitLib.c
+  VmgExitVcHandler.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  OvmfPkg/OvmfPkg.dec
+  UefiCpuPkg/UefiCpuPkg.dec
+
+[LibraryClasses]
+  BaseLib
+  BaseMemoryLib
+  DebugLib
+
diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitLib.c 
b/OvmfPkg/Library/VmgExitLib/VmgExitLib.c
new file mode 100644
index ..53040cc6f649
--- /dev/null
+++ b/OvmfPkg/Library/VmgExitLib/VmgExitLib.c
@@ -0,0 +1,159 @@
+/** @file
+  VMGEXIT Support Library.
+
+  Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/**
+  Check for VMGEXIT error
+
+  Check if the hypervisor has returned an error after completion of the VMGEXIT
+  by examining the SwExitInfo1 field of the GHCB.
+
+  @param[in]  Ghcb   A pointer to the GHCB
+
+  @retval  0 VMGEXIT succeeded.
+  @returnException number to be propagated, VMGEXIT processing
+ did not succeed.
+
+**/
+STATIC
+UINT64
+VmgExitErrorCheck (
+  IN GHCB*Ghcb
+  )
+{
+  GHCB_EVENT_INJECTION  Event;
+  GHCB_EXIT_INFOExitInfo;
+  UINT64Status;
+
+  ExitInfo.Uint64 = Ghcb->SaveArea.SwExitInfo1;
+  ASSERT ((ExitInfo.Elements.Lower32Bits == 0) ||
+  (ExitInfo.Elements.Lower32Bits == 1));
+
+  Status = 0;
+  if (ExitInfo.Elements.Lower32Bits == 0) {
+return Status;
+  }
+
+  if (ExitInfo.Elements.Lower32Bits == 1) {
+ASSERT (Ghcb->SaveArea.SwExitInfo2 != 0);
+
+//
+// Check that the return event is valid
+//
+Event.Uint64 = Ghcb->SaveArea.SwExitInfo2;
+if (Event.Elements.Valid &&
+Event.Elements.Type == GHCB_EVENT_INJECTION_TYPE_EXCEPTION) {
+  switch (Event.Elements.Vector) {
+  case GP_EXCEPTION:
+  case UD_EXCEPTION:
+//
+// Use returned event as return code
+//
+Status = Event.Uint64;
+  }
+}
+  }
+
+  if (Status == 0) {
+GHCB_EVENT_INJECTION  GpEvent;
+
+GpEvent.Uint64 = 0;
+GpEvent.Elements.Vector = GP_EXCEPTION;
+GpEvent.Elements.Type   = GHCB_EVENT_INJECTION_TYPE_EXCEPTION;
+GpEvent.Elements.Valid  = 1;
+
+Status = GpEvent.Uint64;
+  }
+
+  return Status;
+}
+
+/**
+  Perform VMGEXIT.
+
+  Sets the necessary fields of the GHCB, invokes the VMGEXIT instruction and
+  then handles the return actions.
+
+  @param[in, out]  Ghcb   A pointer to the GHCB
+  @param[in]   ExitCode   VMGEXIT code to be assigned to the SwExitCode
+  field of the GHCB.
+  @param[in]   ExitInfo1  VMGEXIT information to 

[edk2-devel] [PATCH v10 11/46] UefiCpuPkg/CpuExceptionHandler: Add base support for the #VC exception

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

Add base support to handle #VC exceptions. Update the common exception
handlers to invoke the VmgExitHandleVc () function of the VmgExitLib
library when a #VC is encountered. A non-zero return code will propagate
to the targeted exception handler.

Under SEV-ES, a DR7 read or write intercept generates a #VC exception.
To avoid exception recursion, a #VC exception will not try to read and
push the actual debug registers into the EFI_SYSTEM_CONTEXT_X64 struct
and instead push zeroes. The #VC exception handler does not make use of
the debug registers from the saved context and the exception processing
exit code does not attempt to restore the debug register values.

Cc: Eric Dong 
Cc: Ray Ni 
Cc: Laszlo Ersek 
Reviewed-by: Eric Dong 
Signed-off-by: Tom Lendacky 
---
 .../DxeCpuExceptionHandlerLib.inf |  1 +
 .../PeiCpuExceptionHandlerLib.inf |  1 +
 .../SecPeiCpuExceptionHandlerLib.inf  |  1 +
 .../SmmCpuExceptionHandlerLib.inf |  1 +
 .../Xcode5SecPeiCpuExceptionHandlerLib.inf|  1 +
 .../CpuExceptionCommon.c  | 10 +-
 .../PeiDxeSmmCpuException.c   | 20 ++-
 .../SecPeiCpuException.c  | 19 ++
 .../X64/ExceptionHandlerAsm.nasm  | 17 
 .../X64/Xcode5ExceptionHandlerAsm.nasm| 17 
 10 files changed, 86 insertions(+), 2 deletions(-)

diff --git 
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf
index 61e2ec30b089..07b34c92a892 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf
@@ -57,3 +57,4 @@ [LibraryClasses]
   PeCoffGetEntryPointLib
   MemoryAllocationLib
   DebugLib
+  VmgExitLib
diff --git 
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf
index 093374944df6..feae7b3e06de 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf
@@ -52,6 +52,7 @@ [LibraryClasses]
   HobLib
   MemoryAllocationLib
   SynchronizationLib
+  VmgExitLib
 
 [Pcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard# CONSUMES
diff --git 
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf
index 6d25cafe2ca3..967cb61ba6d9 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf
@@ -48,3 +48,4 @@ [LibraryClasses]
   PrintLib
   LocalApicLib
   PeCoffGetEntryPointLib
+  VmgExitLib
diff --git 
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf
index 2ffbbccc302f..4cdb11c04ea0 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf
@@ -51,4 +51,5 @@ [LibraryClasses]
   LocalApicLib
   PeCoffGetEntryPointLib
   DebugLib
+  VmgExitLib
 
diff --git 
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHandlerLib.inf
 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHandlerLib.inf
index 7e21beaab6f2..743c2aa76684 100644
--- 
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHandlerLib.inf
+++ 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHandlerLib.inf
@@ -53,3 +53,4 @@ [LibraryClasses]
   PrintLib
   LocalApicLib
   PeCoffGetEntryPointLib
+  VmgExitLib
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c
index 8adbd43fefb4..c9003b10e552 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c
@@ -14,7 +14,7 @@
 //
 // 1 means an error code will be pushed, otherwise 0
 //
-CONST UINT32 mErrorCodeFlag = 0x00227d00;
+CONST UINT32 mErrorCodeFlag = 0x20227d00;
 
 //
 // Define the maximum message length
@@ -45,6 +45,14 @@ CONST CHAR8 *mExceptionNameStr[] = {
   "#XM - SIMD floating-point",
   "#VE - Virtualization",
   "#CP - Control Protection"
+  "Reserved",
+  "Reserved",
+  "Reserved",
+  "Reserved",
+  "Reserved",
+  "Reserved",
+  "Reserved",
+  "#VC - VMM Communication",
 };
 
 #define EXCEPTION_KNOWN_NAME_NUM  (sizeof (mExceptionNameStr) / sizeof (CHAR8 
*))
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c 

[edk2-devel] [PATCH v10 10/46] UefiPayloadPkg: Prepare UefiPayloadPkg to use the VmgExitLib library

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

Various CpuExceptionHandlerLib libraries will updated to use the new
VmgExitLib library. To prevent any build breakage, update the
UefiPayloadPkg DSC files that use a form of the CpuExceptionHandlerLib
library to include the VmgExitLib library.

Cc: Maurice Ma 
Cc: Guo Dong 
Cc: Benjamin You 
Reviewed-by: Guo Dong 
Signed-off-by: Tom Lendacky 
---
 UefiPayloadPkg/UefiPayloadPkgIa32.dsc| 2 ++
 UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/UefiPayloadPkg/UefiPayloadPkgIa32.dsc 
b/UefiPayloadPkg/UefiPayloadPkgIa32.dsc
index 9a9ca3060e47..460da1c504dc 100644
--- a/UefiPayloadPkg/UefiPayloadPkgIa32.dsc
+++ b/UefiPayloadPkg/UefiPayloadPkgIa32.dsc
@@ -237,6 +237,7 @@ [LibraryClasses.common.DXE_CORE]
   DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf
 !endif
   
CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf
+  VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
 
 [LibraryClasses.common.DXE_DRIVER]
   PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
@@ -249,6 +250,7 @@ [LibraryClasses.common.DXE_DRIVER]
 !endif
   
CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf
   MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
+  VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
 
 [LibraryClasses.common.DXE_RUNTIME_DRIVER]
   PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
diff --git a/UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc 
b/UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc
index a768a8702c66..942bc9076634 100644
--- a/UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc
+++ b/UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc
@@ -238,6 +238,7 @@ [LibraryClasses.common.DXE_CORE]
   DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf
 !endif
   
CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf
+  VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
 
 [LibraryClasses.common.DXE_DRIVER]
   PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
@@ -250,6 +251,7 @@ [LibraryClasses.common.DXE_DRIVER]
 !endif
   
CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf
   MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
+  VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
 
 [LibraryClasses.common.DXE_RUNTIME_DRIVER]
   PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
-- 
2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62513): https://edk2.groups.io/g/devel/message/62513
Mute This Topic: https://groups.io/mt/75499809/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v10 05/46] MdeModulePkg/DxeIplPeim: Support GHCB pages when creating page tables

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

GHCB pages must be mapped as shared pages, so modify the process of
creating identity mapped pagetable entries so that GHCB entries are
created without the encryption bit set. The GHCB range consists of
two pages per CPU, the first being the GHCB and the second being a
per-CPU variable page. Only the GHCB page is mapped as shared.

Cc: Jian J Wang 
Cc: Hao A Wu 
Cc: Dandan Bi 
Cc: Liming Gao 
Signed-off-by: Tom Lendacky 
---
 MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf   |  2 +
 .../Core/DxeIplPeim/X64/VirtualMemory.h   | 12 +++-
 .../Core/DxeIplPeim/Ia32/DxeLoadFunc.c|  4 +-
 .../Core/DxeIplPeim/X64/DxeLoadFunc.c | 11 +++-
 .../Core/DxeIplPeim/X64/VirtualMemory.c   | 57 +++
 5 files changed, 70 insertions(+), 16 deletions(-)

diff --git a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf 
b/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf
index 3f1702854660..19b8a4c8aefa 100644
--- a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf
+++ b/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf
@@ -115,6 +115,8 @@ [Pcd.IA32,Pcd.X64]
   gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPropertyMask   ## 
CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard   ## 
CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdUse5LevelPageTable  ## 
SOMETIMES_CONSUMES
+  gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase## 
CONSUMES
+  gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbSize## 
CONSUMES
 
 [Pcd.IA32,Pcd.X64,Pcd.ARM,Pcd.AARCH64]
   gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack   ## 
SOMETIMES_CONSUMES
diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.h 
b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.h
index 2d0493f109e8..6b7c38a441d6 100644
--- a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.h
+++ b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.h
@@ -201,6 +201,8 @@ EnableExecuteDisableBit (
   @param[in, out] PageEntry2M   Pointer to 2M page entry.
   @param[in]  StackBase Stack base address.
   @param[in]  StackSize Stack size.
+  @param[in]  GhcbBase  GHCB page area base address.
+  @param[in]  GhcbSize  GHCB page area size.
 
 **/
 VOID
@@ -208,7 +210,9 @@ Split2MPageTo4K (
   IN EFI_PHYSICAL_ADDRESS   PhysicalAddress,
   IN OUT UINT64 *PageEntry2M,
   IN EFI_PHYSICAL_ADDRESS   StackBase,
-  IN UINTN  StackSize
+  IN UINTN  StackSize,
+  IN EFI_PHYSICAL_ADDRESS   GhcbBase,
+  IN UINTN  GhcbSize
   );
 
 /**
@@ -217,6 +221,8 @@ Split2MPageTo4K (
 
   @param[in] StackBase  Stack base address.
   @param[in] StackSize  Stack size.
+  @param[in] GhcbBase   GHCB page area base address.
+  @param[in] GhcbSize   GHCB page area size.
 
   @return The address of 4 level page map.
 
@@ -224,7 +230,9 @@ Split2MPageTo4K (
 UINTN
 CreateIdentityMappingPageTables (
   IN EFI_PHYSICAL_ADDRESS   StackBase,
-  IN UINTN  StackSize
+  IN UINTN  StackSize,
+  IN EFI_PHYSICAL_ADDRESS   GhcbBase,
+  IN UINTN  GhcbkSize
   );
 
 
diff --git a/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c 
b/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c
index 6e8ca824d469..284b34818ca7 100644
--- a/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c
+++ b/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c
@@ -123,7 +123,7 @@ Create4GPageTablesIa32Pae (
 //
 // Need to split this 2M page that covers stack range.
 //
-Split2MPageTo4K (PhysicalAddress, (UINT64 *) PageDirectoryEntry, 
StackBase, StackSize);
+Split2MPageTo4K (PhysicalAddress, (UINT64 *) PageDirectoryEntry, 
StackBase, StackSize, 0, 0);
   } else {
 //
 // Fill in the Page Directory entries
@@ -282,7 +282,7 @@ HandOffToDxeCore (
 //
 // Create page table and save PageMapLevel4 to CR3
 //
-PageTables = CreateIdentityMappingPageTables (BaseOfStack, STACK_SIZE);
+PageTables = CreateIdentityMappingPageTables (BaseOfStack, STACK_SIZE, 0, 
0);
 
 //
 // End of PEI phase signal
diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c 
b/MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c
index f465eb1d8ac4..156a477d8467 100644
--- a/MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c
+++ b/MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c
@@ -35,6 +35,8 @@ HandOffToDxeCore (
   UINT32  Index;
   EFI_VECTOR_HANDOFF_INFO *VectorInfo;
   EFI_PEI_VECTOR_HANDOFF_INFO_PPI *VectorHandoffInfoPpi;
+  VOID*GhcbBase;
+  UINTN   GhcbSize;
 
   //
   // Clear page 0 and mark it as allocated if NULL pointer detection is 
enabled.
@@ -81,12 +83,19 @@ HandOffToDxeCore (
   TopOfStack = (VOID *) ((UINTN) 

[edk2-devel] [PATCH v10 06/46] MdePkg/BaseLib: Add support for the XGETBV instruction

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

Under SEV-ES, a CPUID instruction requires the current value of the XCR0
register. In order to retrieve that value, the XGETBV instruction needs
to be executed.

Provide the necessary support to execute the XGETBV instruction.

Cc: Michael D Kinney 
Cc: Liming Gao 
Signed-off-by: Tom Lendacky 
---
 MdePkg/Library/BaseLib/BaseLib.inf  |  2 ++
 MdePkg/Include/Library/BaseLib.h| 17 +
 MdePkg/Library/BaseLib/Ia32/GccInline.c | 28 
 MdePkg/Library/BaseLib/X64/GccInline.c  | 30 ++
 MdePkg/Library/BaseLib/Ia32/XGetBv.nasm | 31 ++
 MdePkg/Library/BaseLib/X64/XGetBv.nasm  | 34 +
 6 files changed, 142 insertions(+)
 create mode 100644 MdePkg/Library/BaseLib/Ia32/XGetBv.nasm
 create mode 100644 MdePkg/Library/BaseLib/X64/XGetBv.nasm

diff --git a/MdePkg/Library/BaseLib/BaseLib.inf 
b/MdePkg/Library/BaseLib/BaseLib.inf
index a57ae2da31f3..da6bc22a3e2b 100644
--- a/MdePkg/Library/BaseLib/BaseLib.inf
+++ b/MdePkg/Library/BaseLib/BaseLib.inf
@@ -153,6 +153,7 @@ [Sources.Ia32]
   Ia32/ARShiftU64.c | MSFT
   Ia32/EnableCache.c | MSFT
   Ia32/DisableCache.c | MSFT
+  Ia32/XGetBv.nasm | MSFT
 
 
   Ia32/GccInline.c | GCC
@@ -287,6 +288,7 @@ [Sources.X64]
   X64/ReadCr2.nasm| MSFT
   X64/ReadCr0.nasm| MSFT
   X64/ReadEflags.nasm| MSFT
+  X64/XGetBv.nasm | MSFT
 
 
   X64/Non-existing.c
diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/BaseLib.h
index 8e7b87cbda4e..7edf0051a0a0 100644
--- a/MdePkg/Include/Library/BaseLib.h
+++ b/MdePkg/Include/Library/BaseLib.h
@@ -7831,6 +7831,23 @@ AsmLfence (
   VOID
   );
 
+/**
+  Executes a XGETBV instruction
+
+  Executes a XGETBV instruction. This function is only available on IA-32 and
+  x64.
+
+  @param[in] IndexExtended control register index
+
+  @return The current value of the extended control register
+**/
+UINT64
+EFIAPI
+AsmXGetBv (
+  IN UINT32  Index
+  );
+
+
 /**
   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/GccInline.c 
b/MdePkg/Library/BaseLib/Ia32/GccInline.c
index 5287200f8754..c962bcfa4617 100644
--- a/MdePkg/Library/BaseLib/Ia32/GccInline.c
+++ b/MdePkg/Library/BaseLib/Ia32/GccInline.c
@@ -1763,3 +1763,31 @@ AsmFlushCacheLine (
 }
 
 
+/**
+  Executes a XGETBV instruction
+
+  Executes a XGETBV instruction. This function is only available on IA-32 and
+  x64.
+
+  @param[in] IndexExtended control register index
+
+  @return The current value of the extended control register
+**/
+UINT64
+EFIAPI
+AsmXGetBv (
+  IN UINT32 Index
+  )
+{
+  UINT64 Data;
+
+  __asm__ __volatile__ (
+"xgetbv"
+: "=A" (Data)
+: "c"  (Index)
+);
+
+  return Data;
+}
+
+
diff --git a/MdePkg/Library/BaseLib/X64/GccInline.c 
b/MdePkg/Library/BaseLib/X64/GccInline.c
index 154ce1f57e92..91198f9f 100644
--- a/MdePkg/Library/BaseLib/X64/GccInline.c
+++ b/MdePkg/Library/BaseLib/X64/GccInline.c
@@ -1798,3 +1798,33 @@ AsmFlushCacheLine (
 }
 
 
+/**
+  Executes a XGETBV instruction
+
+  Executes a XGETBV instruction. This function is only available on IA-32 and
+  x64.
+
+  @param[in] IndexExtended control register index
+
+  @return The current value of the extended control register
+**/
+UINT64
+EFIAPI
+AsmXGetBv (
+  IN UINT32 Index
+  )
+{
+  UINT32 LowData;
+  UINT32 HighData;
+
+  __asm__ __volatile__ (
+"xgetbv"
+: "=a" (LowData),
+  "=d" (HighData)
+: "c"  (Index)
+);
+
+  return (((UINT64)HighData) << 32) | LowData;
+}
+
+
diff --git a/MdePkg/Library/BaseLib/Ia32/XGetBv.nasm 
b/MdePkg/Library/BaseLib/Ia32/XGetBv.nasm
new file mode 100644
index ..9f7b03bbff35
--- /dev/null
+++ b/MdePkg/Library/BaseLib/Ia32/XGetBv.nasm
@@ -0,0 +1,31 @@
+;--
+;
+; Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;
+; Module Name:
+;
+;   XGetBv.Asm
+;
+; Abstract:
+;
+;   AsmXgetBv function
+;
+; Notes:
+;
+;--
+
+SECTION .text
+
+;--
+; UINT64
+; EFIAPI
+; AsmXGetBv (
+;   IN UINT32  Index
+;   );
+;--
+global ASM_PFX(AsmXGetBv)
+ASM_PFX(AsmXGetBv):
+mov ecx, [esp + 4]
+xgetbv
+ret
diff --git a/MdePkg/Library/BaseLib/X64/XGetBv.nasm 
b/MdePkg/Library/BaseLib/X64/XGetBv.nasm
new file mode 100644
index ..09f3be8ae0a8
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/XGetBv.nasm
@@ -0,0 +1,34 @@

[edk2-devel] [PATCH v10 08/46] UefiCpuPkg: Implement library support for VMGEXIT

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

To support handling #VC exceptions and issuing VMGEXIT instructions,
create a library with functions that can be used to perform these
#VC/VMGEXIT related operations. This includes functions for:
  - Handling #VC exceptions
  - Preparing for and issuing a VMGEXIT
  - Performing MMIO-related write operations to support flash emulation
  - Performing AP related boot opeations

The base functions in this driver will not do anything and will return
an error if a return value is required. It is expected that other packages
(like OvmfPkg) will create a version of the library to fully support an
SEV-ES guest.

Cc: Eric Dong 
Cc: Ray Ni 
Cc: Laszlo Ersek 
Reviewed-by: Eric Dong 
Signed-off-by: Tom Lendacky 
---
 UefiCpuPkg/UefiCpuPkg.dec |   3 +
 UefiCpuPkg/UefiCpuPkg.dsc |   2 +
 .../Library/VmgExitLibNull/VmgExitLibNull.inf |  27 
 UefiCpuPkg/Include/Library/VmgExitLib.h   | 103 +++
 .../Library/VmgExitLibNull/VmgExitLibNull.c   | 121 ++
 .../Library/VmgExitLibNull/VmgExitLibNull.uni |  15 +++
 6 files changed, 271 insertions(+)
 create mode 100644 UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
 create mode 100644 UefiCpuPkg/Include/Library/VmgExitLib.h
 create mode 100644 UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c
 create mode 100644 UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni

diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec
index df5d02bae6b4..cb92f34b6f55 100644
--- a/UefiCpuPkg/UefiCpuPkg.dec
+++ b/UefiCpuPkg/UefiCpuPkg.dec
@@ -53,6 +53,9 @@ [LibraryClasses.IA32, LibraryClasses.X64]
   ##
   MpInitLib|Include/Library/MpInitLib.h
 
+  ##  @libraryclass  Provides function to support VMGEXIT processing.
+  VmgExitLib|Include/Library/VmgExitLib.h
+
 [Guids]
   gUefiCpuPkgTokenSpaceGuid  = { 0xac05bf33, 0x995a, 0x4ed4, { 0xaa, 0xb8, 
0xef, 0x7a, 0xe8, 0xf, 0x5c, 0xb0 }}
   gMsegSmramGuid = { 0x5802bce4, 0x, 0x4e33, { 0xa1, 0x30, 
0xeb, 0xad, 0x27, 0xf0, 0xe4, 0x39 }}
diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc
index afa304128221..f0e58b90ff0a 100644
--- a/UefiCpuPkg/UefiCpuPkg.dsc
+++ b/UefiCpuPkg/UefiCpuPkg.dsc
@@ -56,6 +56,7 @@ [LibraryClasses]
   
PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf
   
PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeCoffExtraActionLibNull.inf
   
TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf
+  VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
 
 [LibraryClasses.common.SEC]
   PlatformSecLib|UefiCpuPkg/Library/PlatformSecLibNull/PlatformSecLibNull.inf
@@ -143,6 +144,7 @@ [Components.IA32, Components.X64]
   UefiCpuPkg/Library/SmmCpuPlatformHookLibNull/SmmCpuPlatformHookLibNull.inf
   UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
   UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf
+  UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
   UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationPei.inf
   UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationSmm.inf
   UefiCpuPkg/SecCore/SecCore.inf
diff --git a/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf 
b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
new file mode 100644
index ..d8770a21c355
--- /dev/null
+++ b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
@@ -0,0 +1,27 @@
+## @file
+#  VMGEXIT Support Library.
+#
+#  Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION= 0x00010005
+  BASE_NAME  = VmgExitLibNull
+  MODULE_UNI_FILE= VmgExitLibNull.uni
+  FILE_GUID  = 3cd7368f-ef9b-4a9b-9571-2ed93813677e
+  MODULE_TYPE= BASE
+  VERSION_STRING = 1.0
+  LIBRARY_CLASS  = VmgExitLib
+
+[Sources.common]
+  VmgExitLibNull.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  UefiCpuPkg/UefiCpuPkg.dec
+
+[LibraryClasses]
+  BaseLib
+
diff --git a/UefiCpuPkg/Include/Library/VmgExitLib.h 
b/UefiCpuPkg/Include/Library/VmgExitLib.h
new file mode 100644
index ..45fc27d35e29
--- /dev/null
+++ b/UefiCpuPkg/Include/Library/VmgExitLib.h
@@ -0,0 +1,103 @@
+/** @file
+  Public header file for the VMGEXIT Support library class.
+
+  This library class defines some routines used when invoking the VMGEXIT
+  instruction in support of SEV-ES and to handle #VC exceptions.
+
+  Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef __VMG_EXIT_LIB_H__
+#define __VMG_EXIT_LIB_H__
+
+#include 
+#include 
+
+
+/**
+  Perform VMGEXIT.
+
+  Sets the necessary fields of the GHCB, invokes the VMGEXIT instruction and
+  then handles the return actions.

[edk2-devel] [PATCH v10 09/46] OvmfPkg: Prepare OvmfPkg to use the VmgExitLib library

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

Various CpuExceptionHandlerLib libraries will updated to use the new
VmgExitLib library. To prevent any build breakage, update the OvmfPkg
DSC files that use a form of the CpuExceptionHandlerLib library to
include the VmgExitLib library.

Cc: Jordan Justen 
Cc: Laszlo Ersek 
Cc: Ard Biesheuvel 
Cc: Anthony Perard 
Cc: Julien Grall 
Reviewed-by: Laszlo Ersek 
Signed-off-by: Tom Lendacky 
---
 OvmfPkg/OvmfPkgIa32.dsc| 1 +
 OvmfPkg/OvmfPkgIa32X64.dsc | 1 +
 OvmfPkg/OvmfPkgX64.dsc | 1 +
 OvmfPkg/OvmfXen.dsc| 1 +
 4 files changed, 4 insertions(+)

diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc
index b4ee7376791b..b6f98af8183c 100644
--- a/OvmfPkg/OvmfPkgIa32.dsc
+++ b/OvmfPkg/OvmfPkgIa32.dsc
@@ -228,6 +228,7 @@ [LibraryClasses]
 
 [LibraryClasses.common]
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
+  VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
 
 [LibraryClasses.common.SEC]
   TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf
diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc
index ed68b080f2a2..d147aca168be 100644
--- a/OvmfPkg/OvmfPkgIa32X64.dsc
+++ b/OvmfPkg/OvmfPkgIa32X64.dsc
@@ -232,6 +232,7 @@ [LibraryClasses]
 
 [LibraryClasses.common]
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
+  VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
 
 [LibraryClasses.common.SEC]
   TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf
diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index cb7e8068a3d8..269b6d973188 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -232,6 +232,7 @@ [LibraryClasses]
 
 [LibraryClasses.common]
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
+  VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
 
 [LibraryClasses.common.SEC]
   TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf
diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc
index 782803cb2787..37b63a874067 100644
--- a/OvmfPkg/OvmfXen.dsc
+++ b/OvmfPkg/OvmfXen.dsc
@@ -213,6 +213,7 @@ [LibraryClasses]
 
 [LibraryClasses.common]
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
+  VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
 
 [LibraryClasses.common.SEC]
   QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSecLib.inf
-- 
2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62512): https://edk2.groups.io/g/devel/message/62512
Mute This Topic: https://groups.io/mt/75499796/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v10 07/46] MdePkg/BaseLib: Add support for the VMGEXIT instruction

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

VMGEXIT is a new instruction used for Hypervisor/Guest communication when
running as an SEV-ES guest. A VMGEXIT will cause an automatic exit (AE)
to occur, resulting in a #VMEXIT with an exit code value of 0x403.

Provide the necessary support to execute the VMGEXIT instruction, which
is "rep; vmmcall".

Cc: Michael D Kinney 
Cc: Liming Gao 
Signed-off-by: Tom Lendacky 
---
 MdePkg/Library/BaseLib/BaseLib.inf   |  2 ++
 MdePkg/Include/Library/BaseLib.h | 14 +
 MdePkg/Library/BaseLib/Ia32/GccInline.c  | 17 +++
 MdePkg/Library/BaseLib/X64/GccInline.c   | 17 +++
 MdePkg/Library/BaseLib/Ia32/VmgExit.nasm | 37 
 MdePkg/Library/BaseLib/X64/VmgExit.nasm  | 32 
 6 files changed, 119 insertions(+)
 create mode 100644 MdePkg/Library/BaseLib/Ia32/VmgExit.nasm
 create mode 100644 MdePkg/Library/BaseLib/X64/VmgExit.nasm

diff --git a/MdePkg/Library/BaseLib/BaseLib.inf 
b/MdePkg/Library/BaseLib/BaseLib.inf
index da6bc22a3e2b..7cf6467fa77b 100644
--- a/MdePkg/Library/BaseLib/BaseLib.inf
+++ b/MdePkg/Library/BaseLib/BaseLib.inf
@@ -154,6 +154,7 @@ [Sources.Ia32]
   Ia32/EnableCache.c | MSFT
   Ia32/DisableCache.c | MSFT
   Ia32/XGetBv.nasm | MSFT
+  Ia32/VmgExit.nasm | MSFT
 
 
   Ia32/GccInline.c | GCC
@@ -289,6 +290,7 @@ [Sources.X64]
   X64/ReadCr0.nasm| MSFT
   X64/ReadEflags.nasm| MSFT
   X64/XGetBv.nasm | MSFT
+  X64/VmgExit.nasm | MSFT
 
 
   X64/Non-existing.c
diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/BaseLib.h
index 7edf0051a0a0..04fb329eaabb 100644
--- a/MdePkg/Include/Library/BaseLib.h
+++ b/MdePkg/Include/Library/BaseLib.h
@@ -7848,6 +7848,20 @@ AsmXGetBv (
   );
 
 
+/**
+  Executes a VMGEXIT instruction (VMMCALL with a REP prefix)
+
+  Executes a VMGEXIT instruction. This function is only available on IA-32 and
+  x64.
+
+**/
+VOID
+EFIAPI
+AsmVmgExit (
+  VOID
+  );
+
+
 /**
   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/GccInline.c 
b/MdePkg/Library/BaseLib/Ia32/GccInline.c
index c962bcfa4617..d6a7581b36f6 100644
--- a/MdePkg/Library/BaseLib/Ia32/GccInline.c
+++ b/MdePkg/Library/BaseLib/Ia32/GccInline.c
@@ -1791,3 +1791,20 @@ AsmXGetBv (
 }
 
 
+/**
+  Executes a VMGEXIT instruction.
+
+  Executes a VMGEXIT instruction. This function is only available on IA-32 and
+  X64.
+
+**/
+VOID
+EFIAPI
+AsmVmgExit (
+  VOID
+  )
+{
+  __asm__ __volatile__ ("rep; vmmcall":::"memory");
+}
+
+
diff --git a/MdePkg/Library/BaseLib/X64/GccInline.c 
b/MdePkg/Library/BaseLib/X64/GccInline.c
index 91198f9f..0685337bbb56 100644
--- a/MdePkg/Library/BaseLib/X64/GccInline.c
+++ b/MdePkg/Library/BaseLib/X64/GccInline.c
@@ -1828,3 +1828,20 @@ AsmXGetBv (
 }
 
 
+/**
+  Executes a VMGEXIT instruction.
+
+  Executes a VMGEXIT instruction. This function is only available on IA-32 and
+  X64.
+
+**/
+VOID
+EFIAPI
+AsmVmgExit (
+  VOID
+  )
+{
+  __asm__ __volatile__ ("rep; vmmcall":::"memory");
+}
+
+
diff --git a/MdePkg/Library/BaseLib/Ia32/VmgExit.nasm 
b/MdePkg/Library/BaseLib/Ia32/VmgExit.nasm
new file mode 100644
index ..a4b37385cc7a
--- /dev/null
+++ b/MdePkg/Library/BaseLib/Ia32/VmgExit.nasm
@@ -0,0 +1,37 @@
+;--
+;
+; Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;
+; Module Name:
+;
+;   VmgExit.Asm
+;
+; Abstract:
+;
+;   AsmVmgExit function
+;
+; Notes:
+;
+;--
+
+SECTION .text
+
+;--
+; VOID
+; EFIAPI
+; AsmVmgExit (
+;   VOID
+;   );
+;--
+global ASM_PFX(AsmVmgExit)
+ASM_PFX(AsmVmgExit):
+;
+; NASM doesn't support the vmmcall instruction in 32-bit mode, so work around
+; this by temporarily switching to 64-bit mode.
+;
+BITS64
+rep vmmcall
+BITS32
+ret
+
diff --git a/MdePkg/Library/BaseLib/X64/VmgExit.nasm 
b/MdePkg/Library/BaseLib/X64/VmgExit.nasm
new file mode 100644
index ..26f034593c67
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/VmgExit.nasm
@@ -0,0 +1,32 @@
+;--
+;
+; Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;
+; Module Name:
+;
+;   VmgExit.Asm
+;
+; Abstract:
+;
+;   AsmVmgExit function
+;
+; Notes:
+;
+;--
+
+DEFAULT REL
+SECTION .text
+
+;--
+; VOID

[edk2-devel] [PATCH v10 01/46] MdeModulePkg: Create PCDs to be used in support of SEV-ES

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

Two new dynamic MdeModulePkg PCDs are needed to support SEV-ES under OVMF:
  - PcdGhcbBase:   UINT64 value that is the base address of the GHCB
   allocation.
  - PcdGhcbSize:   UINT64 value that is the size, in bytes, of the
   GHCB allocation (size is dependent on the number of
   APs).

Cc: Jian J Wang 
Cc: Hao A Wu 
Signed-off-by: Tom Lendacky 
---
 MdeModulePkg/MdeModulePkg.dec | 9 +
 MdeModulePkg/MdeModulePkg.uni | 8 
 2 files changed, 17 insertions(+)

diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index 843e963ad34b..f8cd9239b4ce 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -2051,6 +2051,15 @@ [PcdsDynamic, PcdsDynamicEx]
   # @Prompt If there is any test key used by the platform.
   gEfiMdeModulePkgTokenSpaceGuid.PcdTestKeyUsed|FALSE|BOOLEAN|0x00030003
 
+  ## This dynamic PCD holds the base address of the GHCB pool allocation.
+  # @Prompt GHCB Pool Base Address
+  gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase|0|UINT64|0x00030007
+
+  ## This dynamic PCD holds the total size of the GHCB pool allocation.
+  #  The amount of memory allocated for GHCBs is dependent on the number of 
APs.
+  # @Prompt GHCB Pool Size
+  gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbSize|0|UINT64|0x00030008
+
 [PcdsDynamicEx]
   ## This dynamic PCD enables the default variable setting.
   #  Its value is the default store ID value. The default value is zero as 
Standard default.
diff --git a/MdeModulePkg/MdeModulePkg.uni b/MdeModulePkg/MdeModulePkg.uni
index 2007e0596c4f..2f8cca03e527 100644
--- a/MdeModulePkg/MdeModulePkg.uni
+++ b/MdeModulePkg/MdeModulePkg.uni
@@ -1297,3 +1297,11 @@
 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTcgPfpMeasurementRevision_PROMPT 
#language en-US "TCG Platform Firmware Profile revision"
 
 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTcgPfpMeasurementRevision_HELP 
#language en-US "Indicates which TCG Platform Firmware Profile revision the 
EDKII firmware follows."
+
+#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdGhcbBase_PROMPT #language en-US 
"GHCB Pool Base Address"
+
+#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdGhcbBase_HELP #language en-US 
"Used with SEV-ES support to identify an address range that is not to be 
encrypted."
+
+#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdGhcbSize_PROMPT #language en-US 
"GHCB Pool Base Size"
+
+#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdGhcbSize_HELP #language en-US 
"Used with SEV-ES support to identify the size of the address range that is not 
to be encrypted."
-- 
2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62504): https://edk2.groups.io/g/devel/message/62504
Mute This Topic: https://groups.io/mt/75499722/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v10 03/46] MdePkg: Add the MSR definition for the GHCB register

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

For SEV-ES, the GHCB page address is stored in the GHCB MSR register
(0xc0010130). Define the register and the format used for register
during GHCB protocol negotiation.

Cc: Michael D Kinney 
Cc: Liming Gao 
Signed-off-by: Tom Lendacky 
---
 MdePkg/Include/Register/Amd/Fam17Msr.h | 46 ++
 1 file changed, 46 insertions(+)

diff --git a/MdePkg/Include/Register/Amd/Fam17Msr.h 
b/MdePkg/Include/Register/Amd/Fam17Msr.h
index 6ef45a9b21d3..e4db09c5184c 100644
--- a/MdePkg/Include/Register/Amd/Fam17Msr.h
+++ b/MdePkg/Include/Register/Amd/Fam17Msr.h
@@ -17,6 +17,52 @@
 #ifndef __FAM17_MSR_H__
 #define __FAM17_MSR_H__
 
+/**
+  Secure Encrypted Virtualization - Encrypted State (SEV-ES) GHCB register
+
+**/
+#define MSR_SEV_ES_GHCB0xc0010130
+
+/**
+  MSR information returned for #MSR_SEV_ES_GHCB
+**/
+typedef union {
+  struct {
+UINT32  Function:12;
+UINT32  Reserved1:20;
+UINT32  Reserved2:32;
+  } GhcbInfo;
+
+  struct {
+UINT8   Reserved[3];
+UINT8   SevEncryptionBitPos;
+UINT16  SevEsProtocolMin;
+UINT16  SevEsProtocolMax;
+  } GhcbProtocol;
+
+  struct {
+UINT32  Function:12;
+UINT32  ReasonCodeSet:4;
+UINT32  ReasonCode:8;
+UINT32  Reserved1:8;
+UINT32  Reserved2:32;
+  } GhcbTerminate;
+
+  VOID*Ghcb;
+
+  UINT64  GhcbPhysicalAddress;
+} MSR_SEV_ES_GHCB_REGISTER;
+
+#define GHCB_INFO_SEV_INFO 1
+#define GHCB_INFO_SEV_INFO_GET 2
+#define GHCB_INFO_CPUID_REQUEST4
+#define GHCB_INFO_CPUID_RESPONSE   5
+#define GHCB_INFO_TERMINATE_REQUEST256
+
+#define GHCB_TERMINATE_GHCB0
+#define GHCB_TERMINATE_GHCB_GENERAL0
+#define GHCB_TERMINATE_GHCB_PROTOCOL   1
+
 /**
   Secure Encrypted Virtualization (SEV) status register
 
-- 
2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62506): https://edk2.groups.io/g/devel/message/62506
Mute This Topic: https://groups.io/mt/75499744/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v10 04/46] MdePkg: Add a structure definition for the GHCB

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

The GHCB is used by an SEV-ES guest for communicating between the guest
and the hypervisor. Create the GHCB definition as defined by the GHCB
protocol definition.

Cc: Michael D Kinney 
Cc: Liming Gao 
Signed-off-by: Tom Lendacky 
---
 MdePkg/Include/Register/Amd/Ghcb.h | 166 +
 1 file changed, 166 insertions(+)
 create mode 100644 MdePkg/Include/Register/Amd/Ghcb.h

diff --git a/MdePkg/Include/Register/Amd/Ghcb.h 
b/MdePkg/Include/Register/Amd/Ghcb.h
new file mode 100644
index ..54a80da0f6d7
--- /dev/null
+++ b/MdePkg/Include/Register/Amd/Ghcb.h
@@ -0,0 +1,166 @@
+/** @file
+  Guest-Hypervisor Communication Block (GHCB) Definition.
+
+  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.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+  @par Specification Reference:
+  SEV-ES Guest-Hypervisor Communication Block Standardization
+
+**/
+
+#ifndef __GHCB_H__
+#define __GHCB_H__
+
+#include 
+#include 
+#include 
+
+#define UD_EXCEPTION  6
+#define GP_EXCEPTION 13
+#define VC_EXCEPTION 29
+
+#define GHCB_VERSION_MIN 1
+#define GHCB_VERSION_MAX 1
+
+#define GHCB_STANDARD_USAGE  0
+
+//
+// SVM Exit Codes
+//
+#define SVM_EXIT_DR7_READ   0x27ULL
+#define SVM_EXIT_DR7_WRITE  0x37ULL
+#define SVM_EXIT_RDTSC  0x6EULL
+#define SVM_EXIT_RDPMC  0x6FULL
+#define SVM_EXIT_CPUID  0x72ULL
+#define SVM_EXIT_INVD   0x76ULL
+#define SVM_EXIT_IOIO_PROT  0x7BULL
+#define SVM_EXIT_MSR0x7CULL
+#define SVM_EXIT_VMMCALL0x81ULL
+#define SVM_EXIT_RDTSCP 0x87ULL
+#define SVM_EXIT_WBINVD 0x89ULL
+#define SVM_EXIT_MONITOR0x8AULL
+#define SVM_EXIT_MWAIT  0x8BULL
+#define SVM_EXIT_NPF0x400ULL
+
+//
+// VMG Special Exit Codes
+//
+#define SVM_EXIT_MMIO_READ  0x8001ULL
+#define SVM_EXIT_MMIO_WRITE 0x8002ULL
+#define SVM_EXIT_NMI_COMPLETE   0x8003ULL
+#define SVM_EXIT_AP_RESET_HOLD  0x8004ULL
+#define SVM_EXIT_AP_JUMP_TABLE  0x8005ULL
+#define SVM_EXIT_UNSUPPORTED0x8000ULL
+
+//
+// IOIO Exit Information
+//
+#define IOIO_TYPE_STR   BIT2
+#define IOIO_TYPE_IN1
+#define IOIO_TYPE_INS   (IOIO_TYPE_IN | IOIO_TYPE_STR)
+#define IOIO_TYPE_OUT   0
+#define IOIO_TYPE_OUTS  (IOIO_TYPE_OUT | IOIO_TYPE_STR)
+
+#define IOIO_REPBIT3
+
+#define IOIO_ADDR_64BIT9
+#define IOIO_ADDR_32BIT8
+#define IOIO_ADDR_16BIT7
+
+#define IOIO_DATA_32BIT6
+#define IOIO_DATA_16BIT5
+#define IOIO_DATA_8 BIT4
+#define IOIO_DATA_MASK  (BIT6 | BIT5 | BIT4)
+#define IOIO_DATA_OFFSET4
+#define IOIO_DATA_BYTES(x)  (((x) & IOIO_DATA_MASK) >> IOIO_DATA_OFFSET)
+
+#define IOIO_SEG_ES 0
+#define IOIO_SEG_DS (BIT11 | BIT10)
+
+
+typedef enum {
+  GhcbCpl  = 25,
+  GhcbRflags   = 46,
+  GhcbRip,
+  GhcbRsp  = 59,
+  GhcbRax  = 63,
+  GhcbRcx  = 97,
+  GhcbRdx,
+  GhcbRbx,
+  GhcbRbp  = 101,
+  GhcbRsi,
+  GhcbRdi,
+  GhcbR8,
+  GhcbR9,
+  GhcbR10,
+  GhcbR11,
+  GhcbR12,
+  GhcbR13,
+  GhcbR14,
+  GhcbR15,
+  GhcbXCr0 = 125,
+} GHCB_REGISTER;
+
+typedef PACKED struct {
+  UINT8  Reserved1[203];
+  UINT8  Cpl;
+  UINT8  Reserved2[148];
+  UINT64 Dr7;
+  UINT8  Reserved3[144];
+  UINT64 Rax;
+  UINT8  Reserved4[264];
+  UINT64 Rcx;
+  UINT64 Rdx;
+  UINT64 Rbx;
+  UINT8  Reserved5[112];
+  UINT64 SwExitCode;
+  UINT64 SwExitInfo1;
+  UINT64 SwExitInfo2;
+  UINT64 SwScratch;
+  UINT8  Reserved6[56];
+  UINT64 XCr0;
+  UINT8  ValidBitmap[16];
+  UINT64 X87StateGpa;
+  UINT8  Reserved7[1016];
+} GHCB_SAVE_AREA;
+
+typedef PACKED struct {
+  GHCB_SAVE_AREA SaveArea;
+  UINT8  SharedBuffer[2032];
+  UINT8  Reserved1[10];
+  UINT16 ProtocolVersion;
+  UINT32 GhcbUsage;
+} GHCB;
+
+typedef union {
+  struct {
+UINT32  Lower32Bits;
+UINT32  Upper32Bits;
+  } Elements;
+
+  UINT64Uint64;
+} GHCB_EXIT_INFO;
+
+typedef union {
+  struct {
+UINT32  Vector:8;
+UINT32  Type:3;
+UINT32  ErrorCodeValid:1;
+UINT32  Rsvd:19;
+UINT32  Valid:1;
+UINT32  ErrorCode;
+  } Elements;
+
+  UINT64Uint64;
+} GHCB_EVENT_INJECTION;
+
+#define GHCB_EVENT_INJECTION_TYPE_INT0
+#define GHCB_EVENT_INJECTION_TYPE_NMI2
+#define GHCB_EVENT_INJECTION_TYPE_EXCEPTION  3
+#define 

[edk2-devel] [PATCH v10 02/46] UefiCpuPkg: Create PCD to be used in support of SEV-ES

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

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

A new dynamic UefiCpuPkg PCD is needed to support SEV-ES under OVMF:
  - PcdSevEsIsEnabled: BOOLEAN value used to indicate if SEV-ES is enabled

Cc: Eric Dong 
Cc: Ray Ni 
Cc: Laszlo Ersek 
Reviewed-by: Eric Dong 
Signed-off-by: Tom Lendacky 
---
 UefiCpuPkg/UefiCpuPkg.dec | 6 ++
 UefiCpuPkg/UefiCpuPkg.uni | 3 +++
 2 files changed, 9 insertions(+)

diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec
index 762badf5d239..df5d02bae6b4 100644
--- a/UefiCpuPkg/UefiCpuPkg.dec
+++ b/UefiCpuPkg/UefiCpuPkg.dec
@@ -370,5 +370,11 @@ [PcdsDynamic, PcdsDynamicEx]
   # @ValidRange  0x8001 | 0 - 1
   gUefiCpuPkgTokenSpaceGuid.PcdCpuProcTraceOutputScheme|0x0|UINT8|0x6015
 
+  ## This dynamic PCD indicates whether SEV-ES is enabled
+  #   TRUE  - SEV-ES is enabled
+  #   FALSE - SEV-ES is not enabled
+  # @Prompt SEV-ES Status
+  gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled|FALSE|BOOLEAN|0x6016
+
 [UserExtensions.TianoCore."ExtraFiles"]
   UefiCpuPkgExtra.uni
diff --git a/UefiCpuPkg/UefiCpuPkg.uni b/UefiCpuPkg/UefiCpuPkg.uni
index 1780dfdc126d..f4a0c72f6293 100644
--- a/UefiCpuPkg/UefiCpuPkg.uni
+++ b/UefiCpuPkg/UefiCpuPkg.uni
@@ -278,3 +278,6 @@
 
 #string 
STR_gUefiCpuPkgTokenSpaceGuid_PcdCpuApStatusCheckIntervalInMicroSeconds_PROMPT  
#language en-US "Periodic interval value in microseconds for AP status check in 
DXE.\n"
 #string 
STR_gUefiCpuPkgTokenSpaceGuid_PcdCpuApStatusCheckIntervalInMicroSeconds_HELP
#language en-US "Periodic interval value in microseconds for the status check 
of APs for StartupAllAPs() and StartupThisAP() executed in non-blocking mode in 
DXE phase.\n"
+
+#string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsIsEnabled_PROMPT  #language 
en-US "Specifies whether SEV-ES is enabled"
+#string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsIsEnabled_HELP#language 
en-US "Set to TRUE when running as an SEV-ES guest, FALSE otherwise."
-- 
2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62505): https://edk2.groups.io/g/devel/message/62505
Mute This Topic: https://groups.io/mt/75499738/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH v10 00/46] SEV-ES guest support

2020-07-14 Thread Lendacky, Thomas
From: Tom Lendacky 

This patch series provides support for running EDK2/OVMF under SEV-ES.

Secure Encrypted Virtualization - Encrypted State (SEV-ES) expands on the
SEV support to protect the guest register state from the hypervisor. See
"AMD64 Architecture Programmer's Manual Volume 2: System Programming",
section "15.35 Encrypted State (SEV-ES)" [1].

In order to allow a hypervisor to perform functions on behalf of a guest,
there is architectural support for notifying a guest's operating system
when certain types of VMEXITs are about to occur. This allows the guest to
selectively share information with the hypervisor to satisfy the requested
function. The notification is performed using a new exception, the VMM
Communication exception (#VC). The information is shared through the
Guest-Hypervisor Communication Block (GHCB) using the VMGEXIT instruction.
The GHCB format and the protocol for using it is documented in "SEV-ES
Guest-Hypervisor Communication Block Standardization" [2].

The main areas of the EDK2 code that are updated to support SEV-ES are
around the exception handling support and the AP boot support.

Exception support is required starting in Sec, continuing through Pei
and into Dxe in order to handle #VC exceptions that are generated.  Each
AP requires it's own GHCB page as well as a page to hold values specific
to that AP.

AP booting poses some interesting challenges. The INIT-SIPI-SIPI sequence
is typically used to boot the APs. However, the hypervisor is not allowed
to update the guest registers. The GHCB document [2] talks about how SMP
booting under SEV-ES is performed.

Since the GHCB page must be a shared (unencrypted) page, the processor
must be running in long mode in order for the guest and hypervisor to
communicate with each other. As a result, SEV-ES is only supported under
the X64 architecture.

[1] https://www.amd.com/system/files/TechDocs/24593.pdf
[2] https://developer.amd.com/wp-content/resources/56421.pdf

---

These patches are based on commit:
9c6f3545aee0 ("UefiCpuPkg/MtrrLib: Remove unnecessary API MtrrSetFixedMtrr()")

A version of the tree can be found at:
https://github.com/AMDESE/ovmf/tree/sev-es-v18

Cc: Andrew Fish 
Cc: Anthony Perard 
Cc: Ard Biesheuvel 
Cc: Benjamin You 
Cc: Dandan Bi 
Cc: Eric Dong 
Cc: Guo Dong 
Cc: Hao A Wu 
Cc: Jian J Wang 
Cc: Jordan Justen 
Cc: Julien Grall 
Cc: Laszlo Ersek 
Cc: Leif Lindholm 
Cc: Liming Gao 
Cc: Maurice Ma 
Cc: Michael D Kinney 
Cc: Ray Ni 

Changes since v9:
- Fixed bit field declarations in the GHCB structure to use UINT32
  and not UINT64.
- Fixed a warning produced by VS2019 in the instruction parsing code
  by expliciting casting a bit shift to an INT64.
- Sorted section entries in the OVMF VmgExitLib INF file.
- Moved the new Maintainers.txt entry so entries remain sorted.
- Documentation style fixes for return values.
- Miscellaneous code style fixes.

Changes since v8:
- Move IOIO exit info definitions into Ghcb.h file
  - Add a macro for calculating IO instruction bytes (IOIO_DATA_BYTES)
- Exception handler support for debug registers
  - Moved the DRx register saving changes into the UefiCpuPkg patch for
base #VC support in CpuExceptionHandlerLib.
- OvmfPkg VmgExitLib
  - Remove the .uni file
  - Update .inf file:
- New file location for VmgExitVcHandler.c
- Add additional Packages and LibraryClasses
- Introduce a header file to hold the #VC instruction parsing related
  definitions
  - Include additional #defines for instruction decoding to replace
hard coded values for things like instruction prefixes and escapes.
- Replace hardcoded CPUID values with values from existing header files
  and use existing CR4 definition for accessing CR4 data.
- Change the type used for obtaining data addresses in the instruction
  parsing
  - Switch from INTN to UINT64 and use compiler conversions and casting
to perform the correct address calculation
- ResetVector code:
  - Revert some inadvertant changes introduced in v7 for reserving the
SEV-ES work area memory and for checking the status of SEV-ES.
- AP Booting
  - Provide support for non-broadcast INIT-SIPI-SIPI AP boot (minimize
code duplication by creating a function to set the AP jump table
vector address).
- Fix file/directory entry in maintainer changes.
- Various coding style fixes
  - Commenting, if statements, etc.
- Various documentation style fixes

Changes since v7:
- Reserve the SEV-ES workarea when S3 is enabled
- Fix warnings issued by the Visual Studio compiler
- Create a NULL VmgExitLib instance that is used for VMGEXIT
  related operations as well as #VC handling. Then create the full
  VmgExitLib support only in OvmfPkg - where it will be used. This
  removes a bunch of implementation code from platforms that will
  not be using the functionality.
- Remove single use interfaces from the VmgExitLib (VmgMmioWrite
  and VmgSetApJumpTable)

Changes since v6:
- Add function comments to all functions, including local 

Re: [edk2-devel] [edk2][PATCH 1/1] BcmGenetDxe: don't consume RX buffer until it's actually copied

2020-07-14 Thread Pete Batard

On 2020.07.14 14:36, Leif Lindholm wrote:

On Mon, Jul 13, 2020 at 12:25:18 +0100, Pete Batard wrote:

One very minor formatting issue inline (that can be sorted during
integration):


I would also like to prepend "Silicon/" to the subject line.


Please do. It should have been there in the first place.

Regards,

/Pete


If I can do those two things:
Reviewed-by: Leif Lindholm 


On 2020.07.12 05:28, Andrei Warkentin wrote:

This was originally a bit sloppy, and could hypothetically under heavy
load result in a buffer being overwritten by hardware before the received
buffer is copied.

Signed-off-by: Andrei Warkentin 
---
   Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h   | 15 +
   Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c | 59 
+++-
   Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c | 26 ++---
   3 files changed, 77 insertions(+), 23 deletions(-)

diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h 
b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h
index 1a117b25..b39a1326 100644
--- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h
+++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h
@@ -358,6 +358,16 @@ GenetTxIntr (
 OUT VOID  **TxBuf
 );
+UINT32
+GenetRxPending (
+  IN  GENET_PRIVATE_DATA *Genet
+  );
+
+UINT32
+GenetTxPending (
+  IN  GENET_PRIVATE_DATA *Genet
+  );
+
   EFI_STATUS
   GenetRxIntr (
 IN GENET_PRIVATE_DATA *Genet,
@@ -365,4 +375,9 @@ GenetRxIntr (
 OUT UINTN *FrameLength
 );
+VOID
+GenetRxComplete (
+  IN GENET_PRIVATE_DATA *Genet
+  );
+
   #endif /* GENET_UTIL_H__ */
diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c 
b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c
index 1c4c8527..a0097b0d 100644
--- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c
+++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c
@@ -661,6 +661,7 @@ GenetDmaMapRxDescriptor (
   Genet->RxBufferMap[DescIndex].PhysAddress & 0x);
 GenetMmioWrite (Genet, GENET_RX_DESC_ADDRESS_HI (DescIndex),
   (Genet->RxBufferMap[DescIndex].PhysAddress >> 32) & 0x);
+  GenetMmioWrite (Genet, GENET_RX_DESC_STATUS (DescIndex), 0);
 return EFI_SUCCESS;
   }
@@ -753,12 +754,9 @@ GenetTxIntr (
 OUT VOID   **TxBuf
 )
   {
-  UINT32  ConsIndex, Total;
+  UINT32 Total;
-  ConsIndex = GenetMmioRead (Genet,
-GENET_TX_DMA_CONS_INDEX (GENET_DMA_DEFAULT_QUEUE)) & 0x;
-
-  Total = (ConsIndex - Genet->TxConsIndex) & 0x;
+  Total = GenetTxPending (Genet);
 if (Genet->TxQueued > 0 && Total > 0) {
   DmaUnmap (Genet->TxBufferMap[Genet->TxNext]);
   *TxBuf = Genet->TxBuffer[Genet->TxNext];
@@ -770,6 +768,46 @@ GenetTxIntr (
 }
   }
+UINT32
+GenetRxPending (
+  IN  GENET_PRIVATE_DATA *Genet
+  )
+{
+  UINT32 ProdIndex;
+  UINT32 ConsIndex;
+
+  ConsIndex = GenetMmioRead (Genet,
+GENET_RX_DMA_CONS_INDEX (GENET_DMA_DEFAULT_QUEUE)) & 0x;
+  ASSERT (ConsIndex == Genet->RxConsIndex);
+
+  ProdIndex = GenetMmioRead (Genet,
+GENET_RX_DMA_PROD_INDEX (GENET_DMA_DEFAULT_QUEUE)) & 0x;
+  return (ProdIndex - Genet->RxConsIndex) & 0x;
+}
+
+UINT32
+GenetTxPending (
+  IN  GENET_PRIVATE_DATA *Genet
+  )
+{
+  UINT32 ConsIndex;
+
+  ConsIndex = GenetMmioRead (Genet,
+ GENET_TX_DMA_CONS_INDEX (GENET_DMA_DEFAULT_QUEUE)) & 0x;


If we want to be pedantic about EDK2 formatting, this should be indented to
start after the "Ge" of GenetMmioRead above, like the previous calls.


+
+  return (ConsIndex - Genet->TxConsIndex) & 0x;
+}
+
+VOID
+GenetRxComplete (
+  IN GENET_PRIVATE_DATA *Genet
+  )
+{
+  Genet->RxConsIndex = (Genet->RxConsIndex + 1) & 0x;
+  GenetMmioWrite (Genet, GENET_RX_DMA_CONS_INDEX (GENET_DMA_DEFAULT_QUEUE),
+  Genet->RxConsIndex);
+}
+
   /**
 Simulate an "RX interrupt", returning the index of a completed RX buffer 
and
 corresponding frame length.
@@ -790,21 +828,14 @@ GenetRxIntr (
 )
   {
 EFI_STATUSStatus;
-  UINT32ProdIndex, Total;
+  UINT32Total;
 UINT32DescStatus;
-  ProdIndex = GenetMmioRead (Genet,
-GENET_RX_DMA_PROD_INDEX (GENET_DMA_DEFAULT_QUEUE)) & 0x;
-
-  Total = (ProdIndex - Genet->RxConsIndex) & 0x;
+  Total = GenetRxPending (Genet);
 if (Total > 0) {
   *DescIndex = Genet->RxConsIndex % GENET_DMA_DESC_COUNT;
   DescStatus = GenetMmioRead (Genet, GENET_RX_DESC_STATUS (*DescIndex));
   *FrameLength = SHIFTOUT (DescStatus, GENET_RX_DESC_STATUS_BUFLEN);
-
-Genet->RxConsIndex = (Genet->RxConsIndex + 1) & 0x;
-GenetMmioWrite (Genet, GENET_RX_DMA_CONS_INDEX (GENET_DMA_DEFAULT_QUEUE),
-  Genet->RxConsIndex);
   Status = EFI_SUCCESS;
 } else {
   Status = EFI_NOT_READY;
diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c 
b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c

Re: [edk2-devel] [edk2-platforms][PATCH v3 1/1] Platform/RaspberryPi/Drivers: Add SD/(e)MMC card detection

2020-07-14 Thread Pete Batard

On 2020.07.14 14:25, Leif Lindholm wrote:

On Mon, Jul 13, 2020 at 12:16:20 +0100, Pete Batard wrote:

The Raspberry Pi 3 and Pi 4 platforms (with latest EEPROM) can boot
straight from USB, without the need for an SD card being present.
However, the IsCardPresent () calls from the ArasanMmcHost and SdHost
drivers are currently hardwired to return TRUE, which results in
straight to USB boot failing due to the SD drivers looping on
errors while trying to poke at a non-existent card...

Ideally, we would use the Card Detect signal from the uSD slot, to
report on the presence or absence of a card, but the Raspberry Pi
Foundation did not wire those signals in the Pi 2 and subsequent
models, leaving us with only potentially interfering SD commands
as means to perform card detection.

As a result of this, we are left with no other choice but limit
detection to occurring only once, prior to formal SD card init,
and then return the detected value for subsequent calls. This,
however, is more than good enough for the intended purpose, which
is to allow straight to USB boot. The sequence is a simplified
variant of the identification code in MmcDxe.

Tested on Raspberry Pi 2B, 3B and CM3 (for both SD controllers)
and Pi 4 (for Arasan, as that's the only controller available today)

Addresses pftf/RPi3#13, pftf/RPi3#14, pftf/RPi4#37.

Co-authored-by: Andrei Warkentin 
Signed-off-by: Pete Batard 


Some minor style comments below, I'm happy to fix them before pushing
if you're OK with these:


I agree with the proposed changes. Thanks for volunteering to fix these.

I just tested your diff with a Pi 4, for good measure, and everything 
looks good.


Regards,

/Pete




---
  Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.c | 86 
++--
  Platform/RaspberryPi/Drivers/SdHostDxe/SdHostDxe.c   | 75 
+++--
  Platform/RaspberryPi/Include/Protocol/RpiMmcHost.h   |  6 ++
  3 files changed, 150 insertions(+), 17 deletions(-)

diff --git a/Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.c 
b/Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.c
index 6d706af6f276..d2a8ffddbb66 100644
--- a/Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.c
+++ b/Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.c
@@ -11,7 +11,8 @@
  
  #define DEBUG_MMCHOST_SD DEBUG_VERBOSE
  
-BOOLEAN PreviousIsCardPresent = FALSE;

+BOOLEAN CardIsPresent = FALSE;
+CARD_DETECT_STATE CardDetectState = CardDetectRequired;


Global variables, so add 'm' prefix?
Also, add STATIC (which also matches SdHostDxe version)?


  UINT32 LastExecutedCommand = (UINT32) -1;
  
  STATIC RASPBERRY_PI_FIRMWARE_PROTOCOL *mFwProtocol;

@@ -239,14 +240,6 @@ CalculateClockFrequencyDivisor (
return EFI_SUCCESS;
  }
  
-BOOLEAN

-MMCIsCardPresent (
-  IN EFI_MMC_HOST_PROTOCOL *This
-)
-{
-  return TRUE;
-}
-
  BOOLEAN
  MMCIsReadOnly (
IN EFI_MMC_HOST_PROTOCOL *This
@@ -418,6 +411,10 @@ MMCNotifyState (
  
DEBUG ((DEBUG_MMCHOST_SD, "ArasanMMCHost: MMCNotifyState(State: %d)\n", State));
  
+  // Stall all operations except init until card detection has occurred.

+  if (State != MmcHwInitializationState && CardDetectState != 
CardDetectCompleted)
+return EFI_NOT_READY;
+


Add {}?


switch (State) {
case MmcHwInitializationState:
  {
@@ -489,6 +486,77 @@ MMCNotifyState (
return EFI_SUCCESS;
  }
  
+BOOLEAN

+MMCIsCardPresent (
+  IN EFI_MMC_HOST_PROTOCOL *This
+)
+{
+  EFI_STATUS Status;
+
+  //
+  // If we are already in progress (we may get concurrent calls)
+  // or completed the detection, just return the current value.
+  //
+  if (CardDetectState != CardDetectRequired)
+return CardIsPresent;


Add {}?


+
+  CardDetectState = CardDetectInProgress;
+  CardIsPresent = FALSE;
+
+  //
+  // The two following commands should succeed even if no card is present.
+  //
+  Status = MMCNotifyState (This, MmcHwInitializationState);
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, "MMCIsCardPresent: Error MmcHwInitializationState, 
Status=%r.\n", Status));
+// If we failed init, go back to requiring card detection
+CardDetectState = CardDetectRequired;
+return FALSE;
+  }
+
+  Status = MMCSendCommand (This, MMC_CMD0, 0);
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, "MMCIsCardPresent: CMD0 Error, Status=%r.\n", 
Status));
+goto out;
+  }
+
+  //
+  // CMD8 should tell us if an SD card is present.
+  //
+  Status = MMCSendCommand (This, MMC_CMD8, CMD8_SD_ARG);
+  if (!EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_INFO, "MMCIsCardPresent: Maybe SD card detected.\n"));
+ CardIsPresent = TRUE;
+ goto out;
+  }
+
+  //
+  // MMC/eMMC won't accept CMD8, but we can try CMD1.
+  //
+  Status = MMCSendCommand (This, MMC_CMD1, 
EMMC_CMD1_CAPACITY_GREATER_THAN_2GB);
+  if (!EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_INFO, "MMCIsCardPresent: Maybe MMC card detected.\n"));
+ CardIsPresent = TRUE;
+ goto out;
+  

Re: [edk2-devel] [edk2][PATCH 1/1] BcmGenetDxe: don't consume RX buffer until it's actually copied

2020-07-14 Thread Leif Lindholm
On Mon, Jul 13, 2020 at 12:25:18 +0100, Pete Batard wrote:
> One very minor formatting issue inline (that can be sorted during
> integration):

I would also like to prepend "Silicon/" to the subject line.
If I can do those two things:
Reviewed-by: Leif Lindholm 

> On 2020.07.12 05:28, Andrei Warkentin wrote:
> > This was originally a bit sloppy, and could hypothetically under heavy
> > load result in a buffer being overwritten by hardware before the received
> > buffer is copied.
> > 
> > Signed-off-by: Andrei Warkentin 
> > ---
> >   Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h   | 15 +
> >   Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c | 59 
> > +++-
> >   Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c | 26 ++---
> >   3 files changed, 77 insertions(+), 23 deletions(-)
> > 
> > diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h 
> > b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h
> > index 1a117b25..b39a1326 100644
> > --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h
> > +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h
> > @@ -358,6 +358,16 @@ GenetTxIntr (
> > OUT VOID  **TxBuf
> > );
> > +UINT32
> > +GenetRxPending (
> > +  IN  GENET_PRIVATE_DATA *Genet
> > +  );
> > +
> > +UINT32
> > +GenetTxPending (
> > +  IN  GENET_PRIVATE_DATA *Genet
> > +  );
> > +
> >   EFI_STATUS
> >   GenetRxIntr (
> > IN GENET_PRIVATE_DATA *Genet,
> > @@ -365,4 +375,9 @@ GenetRxIntr (
> > OUT UINTN *FrameLength
> > );
> > +VOID
> > +GenetRxComplete (
> > +  IN GENET_PRIVATE_DATA *Genet
> > +  );
> > +
> >   #endif /* GENET_UTIL_H__ */
> > diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c 
> > b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c
> > index 1c4c8527..a0097b0d 100644
> > --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c
> > +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c
> > @@ -661,6 +661,7 @@ GenetDmaMapRxDescriptor (
> >   Genet->RxBufferMap[DescIndex].PhysAddress & 0x);
> > GenetMmioWrite (Genet, GENET_RX_DESC_ADDRESS_HI (DescIndex),
> >   (Genet->RxBufferMap[DescIndex].PhysAddress >> 32) & 0x);
> > +  GenetMmioWrite (Genet, GENET_RX_DESC_STATUS (DescIndex), 0);
> > return EFI_SUCCESS;
> >   }
> > @@ -753,12 +754,9 @@ GenetTxIntr (
> > OUT VOID   **TxBuf
> > )
> >   {
> > -  UINT32  ConsIndex, Total;
> > +  UINT32 Total;
> > -  ConsIndex = GenetMmioRead (Genet,
> > -GENET_TX_DMA_CONS_INDEX (GENET_DMA_DEFAULT_QUEUE)) & 
> > 0x;
> > -
> > -  Total = (ConsIndex - Genet->TxConsIndex) & 0x;
> > +  Total = GenetTxPending (Genet);
> > if (Genet->TxQueued > 0 && Total > 0) {
> >   DmaUnmap (Genet->TxBufferMap[Genet->TxNext]);
> >   *TxBuf = Genet->TxBuffer[Genet->TxNext];
> > @@ -770,6 +768,46 @@ GenetTxIntr (
> > }
> >   }
> > +UINT32
> > +GenetRxPending (
> > +  IN  GENET_PRIVATE_DATA *Genet
> > +  )
> > +{
> > +  UINT32 ProdIndex;
> > +  UINT32 ConsIndex;
> > +
> > +  ConsIndex = GenetMmioRead (Genet,
> > +GENET_RX_DMA_CONS_INDEX (GENET_DMA_DEFAULT_QUEUE)) & 
> > 0x;
> > +  ASSERT (ConsIndex == Genet->RxConsIndex);
> > +
> > +  ProdIndex = GenetMmioRead (Genet,
> > +GENET_RX_DMA_PROD_INDEX (GENET_DMA_DEFAULT_QUEUE)) & 
> > 0x;
> > +  return (ProdIndex - Genet->RxConsIndex) & 0x;
> > +}
> > +
> > +UINT32
> > +GenetTxPending (
> > +  IN  GENET_PRIVATE_DATA *Genet
> > +  )
> > +{
> > +  UINT32 ConsIndex;
> > +
> > +  ConsIndex = GenetMmioRead (Genet,
> > + GENET_TX_DMA_CONS_INDEX (GENET_DMA_DEFAULT_QUEUE)) & 0x;
> 
> If we want to be pedantic about EDK2 formatting, this should be indented to
> start after the "Ge" of GenetMmioRead above, like the previous calls.
> 
> > +
> > +  return (ConsIndex - Genet->TxConsIndex) & 0x;
> > +}
> > +
> > +VOID
> > +GenetRxComplete (
> > +  IN GENET_PRIVATE_DATA *Genet
> > +  )
> > +{
> > +  Genet->RxConsIndex = (Genet->RxConsIndex + 1) & 0x;
> > +  GenetMmioWrite (Genet, GENET_RX_DMA_CONS_INDEX (GENET_DMA_DEFAULT_QUEUE),
> > +  Genet->RxConsIndex);
> > +}
> > +
> >   /**
> > Simulate an "RX interrupt", returning the index of a completed RX 
> > buffer and
> > corresponding frame length.
> > @@ -790,21 +828,14 @@ GenetRxIntr (
> > )
> >   {
> > EFI_STATUSStatus;
> > -  UINT32ProdIndex, Total;
> > +  UINT32Total;
> > UINT32DescStatus;
> > -  ProdIndex = GenetMmioRead (Genet,
> > -GENET_RX_DMA_PROD_INDEX (GENET_DMA_DEFAULT_QUEUE)) & 
> > 0x;
> > -
> > -  Total = (ProdIndex - Genet->RxConsIndex) & 0x;
> > +  Total = GenetRxPending (Genet);
> > if (Total > 0) {
> >   *DescIndex = Genet->RxConsIndex % GENET_DMA_DESC_COUNT;
> >   DescStatus = GenetMmioRead (Genet, GENET_RX_DESC_STATUS (*DescIndex));
> >   *FrameLength = SHIFTOUT (DescStatus, 

Re: [edk2-devel] [edk2-platforms][PATCH v3 1/1] Platform/RaspberryPi/Drivers: Add SD/(e)MMC card detection

2020-07-14 Thread Leif Lindholm
On Mon, Jul 13, 2020 at 12:16:20 +0100, Pete Batard wrote:
> The Raspberry Pi 3 and Pi 4 platforms (with latest EEPROM) can boot
> straight from USB, without the need for an SD card being present.
> However, the IsCardPresent () calls from the ArasanMmcHost and SdHost
> drivers are currently hardwired to return TRUE, which results in
> straight to USB boot failing due to the SD drivers looping on
> errors while trying to poke at a non-existent card...
> 
> Ideally, we would use the Card Detect signal from the uSD slot, to
> report on the presence or absence of a card, but the Raspberry Pi
> Foundation did not wire those signals in the Pi 2 and subsequent
> models, leaving us with only potentially interfering SD commands
> as means to perform card detection.
> 
> As a result of this, we are left with no other choice but limit
> detection to occurring only once, prior to formal SD card init,
> and then return the detected value for subsequent calls. This,
> however, is more than good enough for the intended purpose, which
> is to allow straight to USB boot. The sequence is a simplified
> variant of the identification code in MmcDxe.
> 
> Tested on Raspberry Pi 2B, 3B and CM3 (for both SD controllers)
> and Pi 4 (for Arasan, as that's the only controller available today)
> 
> Addresses pftf/RPi3#13, pftf/RPi3#14, pftf/RPi4#37.
> 
> Co-authored-by: Andrei Warkentin 
> Signed-off-by: Pete Batard 

Some minor style comments below, I'm happy to fix them before pushing
if you're OK with these:

> ---
>  Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.c | 86 
> ++--
>  Platform/RaspberryPi/Drivers/SdHostDxe/SdHostDxe.c   | 75 
> +++--
>  Platform/RaspberryPi/Include/Protocol/RpiMmcHost.h   |  6 ++
>  3 files changed, 150 insertions(+), 17 deletions(-)
> 
> diff --git a/Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.c 
> b/Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.c
> index 6d706af6f276..d2a8ffddbb66 100644
> --- a/Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.c
> +++ b/Platform/RaspberryPi/Drivers/ArasanMmcHostDxe/ArasanMmcHostDxe.c
> @@ -11,7 +11,8 @@
>  
>  #define DEBUG_MMCHOST_SD DEBUG_VERBOSE
>  
> -BOOLEAN PreviousIsCardPresent = FALSE;
> +BOOLEAN CardIsPresent = FALSE;
> +CARD_DETECT_STATE CardDetectState = CardDetectRequired;

Global variables, so add 'm' prefix?
Also, add STATIC (which also matches SdHostDxe version)?

>  UINT32 LastExecutedCommand = (UINT32) -1;
>  
>  STATIC RASPBERRY_PI_FIRMWARE_PROTOCOL *mFwProtocol;
> @@ -239,14 +240,6 @@ CalculateClockFrequencyDivisor (
>return EFI_SUCCESS;
>  }
>  
> -BOOLEAN
> -MMCIsCardPresent (
> -  IN EFI_MMC_HOST_PROTOCOL *This
> -)
> -{
> -  return TRUE;
> -}
> -
>  BOOLEAN
>  MMCIsReadOnly (
>IN EFI_MMC_HOST_PROTOCOL *This
> @@ -418,6 +411,10 @@ MMCNotifyState (
>  
>DEBUG ((DEBUG_MMCHOST_SD, "ArasanMMCHost: MMCNotifyState(State: %d)\n", 
> State));
>  
> +  // Stall all operations except init until card detection has occurred.
> +  if (State != MmcHwInitializationState && CardDetectState != 
> CardDetectCompleted)
> +return EFI_NOT_READY;
> +

Add {}?

>switch (State) {
>case MmcHwInitializationState:
>  {
> @@ -489,6 +486,77 @@ MMCNotifyState (
>return EFI_SUCCESS;
>  }
>  
> +BOOLEAN
> +MMCIsCardPresent (
> +  IN EFI_MMC_HOST_PROTOCOL *This
> +)
> +{
> +  EFI_STATUS Status;
> +
> +  //
> +  // If we are already in progress (we may get concurrent calls)
> +  // or completed the detection, just return the current value.
> +  //
> +  if (CardDetectState != CardDetectRequired)
> +return CardIsPresent;

Add {}?

> +
> +  CardDetectState = CardDetectInProgress;
> +  CardIsPresent = FALSE;
> +
> +  //
> +  // The two following commands should succeed even if no card is present.
> +  //
> +  Status = MMCNotifyState (This, MmcHwInitializationState);
> +  if (EFI_ERROR (Status)) {
> +DEBUG ((DEBUG_ERROR, "MMCIsCardPresent: Error MmcHwInitializationState, 
> Status=%r.\n", Status));
> +// If we failed init, go back to requiring card detection
> +CardDetectState = CardDetectRequired;
> +return FALSE;
> +  }
> +
> +  Status = MMCSendCommand (This, MMC_CMD0, 0);
> +  if (EFI_ERROR (Status)) {
> +DEBUG ((DEBUG_ERROR, "MMCIsCardPresent: CMD0 Error, Status=%r.\n", 
> Status));
> +goto out;
> +  }
> +
> +  //
> +  // CMD8 should tell us if an SD card is present.
> +  //
> +  Status = MMCSendCommand (This, MMC_CMD8, CMD8_SD_ARG);
> +  if (!EFI_ERROR (Status)) {
> + DEBUG ((DEBUG_INFO, "MMCIsCardPresent: Maybe SD card detected.\n"));
> + CardIsPresent = TRUE;
> + goto out;
> +  }
> +
> +  //
> +  // MMC/eMMC won't accept CMD8, but we can try CMD1.
> +  //
> +  Status = MMCSendCommand (This, MMC_CMD1, 
> EMMC_CMD1_CAPACITY_GREATER_THAN_2GB);
> +  if (!EFI_ERROR (Status)) {
> + DEBUG ((DEBUG_INFO, "MMCIsCardPresent: Maybe MMC card detected.\n"));
> + CardIsPresent = TRUE;
> + 

Re: [edk2-devel] [PATCH edk2-platforms 1/1] Platform/RaspberryPi: remove unused variable GpuIndex from PlatformLib

2020-07-14 Thread Leif Lindholm
On Tue, Jul 14, 2020 at 13:58:11 +0100, Pete Batard wrote:
> Good call.
> 
> On 2020.07.14 13:45, Leif Lindholm wrote:
> > Commit 678f6bff3c46 ("RPi4: reserve/map memory above 4GB when present")
> > removed the only user of the GpuIndex variable in
> > ArmPlatformGetVirtualMemoryMap, which causes a build error of NOOPT
> > profile with gcc 8.3. Delete the variable, and its initialization.
> > 
> > Cc: Andrei Warkentin 
> > Cc: Pete Batard 
> > Signed-off-by: Leif Lindholm 
> > ---
> >   Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c | 2 --
> >   1 file changed, 2 deletions(-)
> > 
> > diff --git a/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c 
> > b/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
> > index 60a7b43af993..c395e0c75df7 100644
> > --- a/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
> > +++ b/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
> > @@ -57,7 +57,6 @@ ArmPlatformGetVirtualMemoryMap (
> > )
> >   {
> > UINTN Index = 0;
> > -  UINTN GpuIndex;
> > INT64 TotalMemorySize;
> > INT64 MemorySizeBelow3GB;
> > INT64 MemorySizeBelow4GB;
> > @@ -162,7 +161,6 @@ ArmPlatformGetVirtualMemoryMap (
> > VirtualMemoryInfo[Index++].Name   = L"System RAM < 1GB";
> > // GPU Reserved
> > -  GpuIndex = Index;
> > VirtualMemoryTable[Index].PhysicalBase= mVideoCoreBase;
> > VirtualMemoryTable[Index].VirtualBase = 
> > VirtualMemoryTable[Index].PhysicalBase;
> > VirtualMemoryTable[Index].Length  = mVideoCoreSize;
> > 
> 
> Reviewed-by: Pete Batard 

Thanks!
Pushed as 5d2d48eb8f26.

/
Leif

-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62498): https://edk2.groups.io/g/devel/message/62498
Mute This Topic: https://groups.io/mt/75497638/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [PATCH edk2-platforms 1/1] Platform/RaspberryPi: remove unused variable GpuIndex from PlatformLib

2020-07-14 Thread Pete Batard

Good call.

On 2020.07.14 13:45, Leif Lindholm wrote:

Commit 678f6bff3c46 ("RPi4: reserve/map memory above 4GB when present")
removed the only user of the GpuIndex variable in
ArmPlatformGetVirtualMemoryMap, which causes a build error of NOOPT
profile with gcc 8.3. Delete the variable, and its initialization.

Cc: Andrei Warkentin 
Cc: Pete Batard 
Signed-off-by: Leif Lindholm 
---
  Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c | 2 --
  1 file changed, 2 deletions(-)

diff --git a/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c 
b/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
index 60a7b43af993..c395e0c75df7 100644
--- a/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
+++ b/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
@@ -57,7 +57,6 @@ ArmPlatformGetVirtualMemoryMap (
)
  {
UINTN Index = 0;
-  UINTN GpuIndex;
INT64 TotalMemorySize;
INT64 MemorySizeBelow3GB;
INT64 MemorySizeBelow4GB;
@@ -162,7 +161,6 @@ ArmPlatformGetVirtualMemoryMap (
VirtualMemoryInfo[Index++].Name   = L"System RAM < 1GB";
  
// GPU Reserved

-  GpuIndex = Index;
VirtualMemoryTable[Index].PhysicalBase= mVideoCoreBase;
VirtualMemoryTable[Index].VirtualBase = 
VirtualMemoryTable[Index].PhysicalBase;
VirtualMemoryTable[Index].Length  = mVideoCoreSize;



Reviewed-by: Pete Batard 

-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62497): https://edk2.groups.io/g/devel/message/62497
Mute This Topic: https://groups.io/mt/75497638/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



[edk2-devel] [PATCH edk2-platforms 1/1] Platform/RaspberryPi: remove unused variable GpuIndex from PlatformLib

2020-07-14 Thread Leif Lindholm
Commit 678f6bff3c46 ("RPi4: reserve/map memory above 4GB when present")
removed the only user of the GpuIndex variable in
ArmPlatformGetVirtualMemoryMap, which causes a build error of NOOPT
profile with gcc 8.3. Delete the variable, and its initialization.

Cc: Andrei Warkentin 
Cc: Pete Batard 
Signed-off-by: Leif Lindholm 
---
 Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c 
b/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
index 60a7b43af993..c395e0c75df7 100644
--- a/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
+++ b/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c
@@ -57,7 +57,6 @@ ArmPlatformGetVirtualMemoryMap (
   )
 {
   UINTN Index = 0;
-  UINTN GpuIndex;
   INT64 TotalMemorySize;
   INT64 MemorySizeBelow3GB;
   INT64 MemorySizeBelow4GB;
@@ -162,7 +161,6 @@ ArmPlatformGetVirtualMemoryMap (
   VirtualMemoryInfo[Index++].Name   = L"System RAM < 1GB";
 
   // GPU Reserved
-  GpuIndex = Index;
   VirtualMemoryTable[Index].PhysicalBase= mVideoCoreBase;
   VirtualMemoryTable[Index].VirtualBase = 
VirtualMemoryTable[Index].PhysicalBase;
   VirtualMemoryTable[Index].Length  = mVideoCoreSize;
-- 
2.20.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62496): https://edk2.groups.io/g/devel/message/62496
Mute This Topic: https://groups.io/mt/75497638/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



Re: [edk2-devel] [edk2][PATCH 1/1] BcmGenetDxe: don't consume RX buffer until it's actually copied

2020-07-14 Thread Leif Lindholm
On Mon, Jul 13, 2020 at 12:25:18 +0100, Pete Batard wrote:
> One very minor formatting issue inline (that can be sorted during
> integration):

Will do, thanks for highlighting (and review).

/
Leif

> On 2020.07.12 05:28, Andrei Warkentin wrote:
> > This was originally a bit sloppy, and could hypothetically under heavy
> > load result in a buffer being overwritten by hardware before the received
> > buffer is copied.
> > 
> > Signed-off-by: Andrei Warkentin 
> > ---
> >   Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h   | 15 +
> >   Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c | 59 
> > +++-
> >   Silicon/Broadcom/Drivers/Net/BcmGenetDxe/SimpleNetwork.c | 26 ++---
> >   3 files changed, 77 insertions(+), 23 deletions(-)
> > 
> > diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h 
> > b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h
> > index 1a117b25..b39a1326 100644
> > --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h
> > +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/BcmGenetDxe.h
> > @@ -358,6 +358,16 @@ GenetTxIntr (
> > OUT VOID  **TxBuf
> > );
> > +UINT32
> > +GenetRxPending (
> > +  IN  GENET_PRIVATE_DATA *Genet
> > +  );
> > +
> > +UINT32
> > +GenetTxPending (
> > +  IN  GENET_PRIVATE_DATA *Genet
> > +  );
> > +
> >   EFI_STATUS
> >   GenetRxIntr (
> > IN GENET_PRIVATE_DATA *Genet,
> > @@ -365,4 +375,9 @@ GenetRxIntr (
> > OUT UINTN *FrameLength
> > );
> > +VOID
> > +GenetRxComplete (
> > +  IN GENET_PRIVATE_DATA *Genet
> > +  );
> > +
> >   #endif /* GENET_UTIL_H__ */
> > diff --git a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c 
> > b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c
> > index 1c4c8527..a0097b0d 100644
> > --- a/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c
> > +++ b/Silicon/Broadcom/Drivers/Net/BcmGenetDxe/GenetUtil.c
> > @@ -661,6 +661,7 @@ GenetDmaMapRxDescriptor (
> >   Genet->RxBufferMap[DescIndex].PhysAddress & 0x);
> > GenetMmioWrite (Genet, GENET_RX_DESC_ADDRESS_HI (DescIndex),
> >   (Genet->RxBufferMap[DescIndex].PhysAddress >> 32) & 0x);
> > +  GenetMmioWrite (Genet, GENET_RX_DESC_STATUS (DescIndex), 0);
> > return EFI_SUCCESS;
> >   }
> > @@ -753,12 +754,9 @@ GenetTxIntr (
> > OUT VOID   **TxBuf
> > )
> >   {
> > -  UINT32  ConsIndex, Total;
> > +  UINT32 Total;
> > -  ConsIndex = GenetMmioRead (Genet,
> > -GENET_TX_DMA_CONS_INDEX (GENET_DMA_DEFAULT_QUEUE)) & 
> > 0x;
> > -
> > -  Total = (ConsIndex - Genet->TxConsIndex) & 0x;
> > +  Total = GenetTxPending (Genet);
> > if (Genet->TxQueued > 0 && Total > 0) {
> >   DmaUnmap (Genet->TxBufferMap[Genet->TxNext]);
> >   *TxBuf = Genet->TxBuffer[Genet->TxNext];
> > @@ -770,6 +768,46 @@ GenetTxIntr (
> > }
> >   }
> > +UINT32
> > +GenetRxPending (
> > +  IN  GENET_PRIVATE_DATA *Genet
> > +  )
> > +{
> > +  UINT32 ProdIndex;
> > +  UINT32 ConsIndex;
> > +
> > +  ConsIndex = GenetMmioRead (Genet,
> > +GENET_RX_DMA_CONS_INDEX (GENET_DMA_DEFAULT_QUEUE)) & 
> > 0x;
> > +  ASSERT (ConsIndex == Genet->RxConsIndex);
> > +
> > +  ProdIndex = GenetMmioRead (Genet,
> > +GENET_RX_DMA_PROD_INDEX (GENET_DMA_DEFAULT_QUEUE)) & 
> > 0x;
> > +  return (ProdIndex - Genet->RxConsIndex) & 0x;
> > +}
> > +
> > +UINT32
> > +GenetTxPending (
> > +  IN  GENET_PRIVATE_DATA *Genet
> > +  )
> > +{
> > +  UINT32 ConsIndex;
> > +
> > +  ConsIndex = GenetMmioRead (Genet,
> > + GENET_TX_DMA_CONS_INDEX (GENET_DMA_DEFAULT_QUEUE)) & 0x;
> 
> If we want to be pedantic about EDK2 formatting, this should be indented to
> start after the "Ge" of GenetMmioRead above, like the previous calls.
> 
> > +
> > +  return (ConsIndex - Genet->TxConsIndex) & 0x;
> > +}
> > +
> > +VOID
> > +GenetRxComplete (
> > +  IN GENET_PRIVATE_DATA *Genet
> > +  )
> > +{
> > +  Genet->RxConsIndex = (Genet->RxConsIndex + 1) & 0x;
> > +  GenetMmioWrite (Genet, GENET_RX_DMA_CONS_INDEX (GENET_DMA_DEFAULT_QUEUE),
> > +  Genet->RxConsIndex);
> > +}
> > +
> >   /**
> > Simulate an "RX interrupt", returning the index of a completed RX 
> > buffer and
> > corresponding frame length.
> > @@ -790,21 +828,14 @@ GenetRxIntr (
> > )
> >   {
> > EFI_STATUSStatus;
> > -  UINT32ProdIndex, Total;
> > +  UINT32Total;
> > UINT32DescStatus;
> > -  ProdIndex = GenetMmioRead (Genet,
> > -GENET_RX_DMA_PROD_INDEX (GENET_DMA_DEFAULT_QUEUE)) & 
> > 0x;
> > -
> > -  Total = (ProdIndex - Genet->RxConsIndex) & 0x;
> > +  Total = GenetRxPending (Genet);
> > if (Total > 0) {
> >   *DescIndex = Genet->RxConsIndex % GENET_DMA_DESC_COUNT;
> >   DescStatus = GenetMmioRead (Genet, GENET_RX_DESC_STATUS (*DescIndex));
> >   *FrameLength = SHIFTOUT (DescStatus, GENET_RX_DESC_STATUS_BUFLEN);
> > -
> > -Genet->RxConsIndex = 

Re: [edk2-devel] [PATCH 1/2] Revert "BaseTools/PatchCheck.py: Add LicenseCheck"

2020-07-14 Thread Leif Lindholm
Hi Liming,

Thanks, this solves my concern.

/
Leif

On Tue, Jul 14, 2020 at 02:28:59 +, Gao, Liming wrote:
> Leif:
>   Shenglei is working on new patch to add license checker as open CI
>   plug-in (BZ 2833). This way allows to add the exception. So, the
>   autogen file can be handled. Based on current statement, only
>   BSD-2-Clause-Patent license will be allowed. Other license can be
>   added as the exception case if necessary. With new license checker
>   in open CI, I agree to revert this checker in
>   BaseTools/PatchCheck.py.
> 
> Thanks
> Liming
> -Original Message-
> From: Leif Lindholm  
> Sent: 2020年7月7日 23:57
> To: devel@edk2.groups.io; ler...@redhat.com
> Cc: Andrew Fish ; Kinney, Michael D 
> ; Zhang, Shenglei ; 
> Chen, Yuwei ; Gao, Liming 
> Subject: Re: [edk2-devel] [PATCH 1/2] Revert "BaseTools/PatchCheck.py: Add 
> LicenseCheck"
> 
> On Fri, Jul 03, 2020 at 18:20:26 +0200, Laszlo Ersek wrote:
> > On 07/02/20 13:24, Leif Lindholm wrote:
> > > This reverts commit a4cfb842fca9693a330cb5435284c1ee8bfbbace.
> > > This commit suggests inclusion of non-edk2+license content without
> > 
> > The expression "non-edk2+license" is a typo.
> > 
> > I think you meant "non-BSD-2-Clause-Patent".
> 
> Err, yes. Sorry.
> 
> > > a contribution agreement is something the community has made a 
> > > decision on, which is incorrect.
> > 
> > I'm OK with commit a4cfb842fca9 being reverted, as this solves the 
> > practical problem of adding generated files.
> > 
> > Acked-by: Laszlo Ersek 
> > 
> > That said, I *still* don't grasp the more general problem you refer to.
> > 
> > Can we express it as follows (using commits 6b621f958123 and 
> > 6f21d772aa6b as reference):
> > 
> > (1) Content under OvmfPkg/Include/IndustryStandard/Xen was introduced 
> > under the MIT license in commit 6b621f958123. That commit was marked with:
> > 
> > > License: This patch adds many files under the MIT licence.
> > > Contributed-under: TianoCore Contribution Agreement 1.0
> > 
> > and the header files also contained open-coded instances of the MIT 
> > license. (These would later be replaced with SPDX identifiers in 
> > commit
> > 6f21d772aa6b.)
> > 
> > As a result, these files effectively granted use and distribution 
> > rights under the MIT license, *plus* a patent grant (per TCA).
> 
> Correct.
> 
> > (2) If we did the same today (that is, add new MIT-licensed files, but 
> > no "Contributed-under: TCA" line on the commit message), then that 
> > would grant use and distribution rights under the "MIT license", and 
> > *no* patent grant.
> > 
> > Is this the issue you're thinking of?
> 
> Yes.
> 
> > So are we basically looking to replace (for example):
> > 
> >   SPDX-License-Identifier: MIT
> > 
> > with *something* like:
> > 
> >   SPDX-License-Identifier: MIT-Patent
> > 
> > ? (Assuming the latter exists -- which it doesn't, at the moment?)
> 
> It doesn't.
> 
> For BSD3/BSD4, we can do what the BSD distros do and use (for example)
> SPDX-License-Identifier: BSD-3-Clause AND BSD-2-Clause-Patent
> 
> It is not clear to me if (for example) "MIT AND BSD-2-Clause-Patent"
> is a valid expression. But what about "public domain"? Do we figure out a 
> jurisdiction in which public domain content can clearly have arbitrary 
> licenses applied to it and ask someone there to relicense it to something we 
> can accept?
> 
> If we decide the explicit patent grant isn't important, why did we add it in 
> the first place? If we decide it is important, we need to actively make a 
> decision on whether we can ever sidestep it, and if so under what 
> circumstances. (e.g.: "we permit it for tools" - but then the code generation 
> aspect also needs to be covered)
> 
> Regards,
> 
> Leif
> 
> > Thanks
> > Laszlo
> > 
> > > 
> > > Cc: Shenglei Zhang 
> > > Cc: Yuwei Chen 
> > > Cc: Liming Gao 
> > > Signed-off-by: Leif Lindholm 
> > > ---
> > >  BaseTools/Scripts/PatchCheck.py | 50 
> > > -
> > >  1 file changed, 50 deletions(-)
> > > 
> > > diff --git a/BaseTools/Scripts/PatchCheck.py 
> > > b/BaseTools/Scripts/PatchCheck.py index e38cf61f93da..6372f71592d3 
> > > 100755
> > > --- a/BaseTools/Scripts/PatchCheck.py
> > > +++ b/BaseTools/Scripts/PatchCheck.py
> > > @@ -305,49 +305,12 @@ class GitDiffCheck:
> > >  self.line_num = 0
> > >  self.state = START
> > >  self.new_bin = []
> > > -self.LicenseCheck(self.lines, self.count)
> > >  while self.line_num < self.count and self.format_ok:
> > >  line_num = self.line_num
> > >  self.run()
> > >  assert(self.line_num > line_num)
> > >  self.report_message_result()
> > >  
> > > -def LicenseCheck(self, lines, count):
> > > -self.ok = True
> > > -self.startcheck = False
> > > -self.license = True
> > > -line_index = 0
> > > -for line in lines:
> > > -if line.startswith('--- /dev/null'):
> > > -   

[edk2-devel] [PATCH] SignedCapsulePkg: Address NULL pointer dereference case.

2020-07-14 Thread Vin Xue
Original code GetFmpImageDescriptors for OriginalFmpImageInfoBuf
pointer, if failed, return a NULL pointer. The OriginalFmpImageInfoBuf
should not be NULL and the NULL pointer dereference case
should be false positive.

Signed-off-by: Vin Xue 
---
 .../SystemFirmwareUpdateDxe.c | 39 ++-
 1 file changed, 21 insertions(+), 18 deletions(-)

diff --git 
a/SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareUpdateDxe.c 
b/SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareUpdateDxe.c
index bdb70bdb32..ea795cd7db 100644
--- a/SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareUpdateDxe.c
+++ b/SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareUpdateDxe.c
@@ -681,32 +681,35 @@ FindMatchingFmpHandles (
 //

 // Loop through the set of EFI_FIRMWARE_IMAGE_DESCRIPTORs.

 //

-FmpImageInfoBuf = OriginalFmpImageInfoBuf;

 MatchFound = FALSE;

-for (Index2 = 0; Index2 < FmpImageInfoCount; Index2++) {

-  for (Index3 = 0; Index3 < mSystemFmpPrivate->DescriptorCount; Index3++) {

-MatchFound = CompareGuid (

-   >ImageTypeId,

-   >ImageDescriptor[Index3].ImageTypeId

-   );

+if (OriginalFmpImageInfoBuf != NULL) {

+  FmpImageInfoBuf = OriginalFmpImageInfoBuf;

+

+  for (Index2 = 0; Index2 < FmpImageInfoCount; Index2++) {

+for (Index3 = 0; Index3 < mSystemFmpPrivate->DescriptorCount; 
Index3++) {

+  MatchFound = CompareGuid (

+>ImageTypeId,

+>ImageDescriptor[Index3].ImageTypeId

+);

+  if (MatchFound) {

+break;

+  }

+}

 if (MatchFound) {

   break;

 }

+//

+// Increment the buffer pointer ahead by the size of the descriptor

+//

+FmpImageInfoBuf = (EFI_FIRMWARE_IMAGE_DESCRIPTOR *)(((UINT8 
*)FmpImageInfoBuf) + DescriptorSize);

   }

   if (MatchFound) {

-break;

+HandleBuffer[*HandleCount] = HandleBuffer[Index];

+(*HandleCount)++;

   }

-  //

-  // Increment the buffer pointer ahead by the size of the descriptor

-  //

-  FmpImageInfoBuf = (EFI_FIRMWARE_IMAGE_DESCRIPTOR *)(((UINT8 
*)FmpImageInfoBuf) + DescriptorSize);

-}

-if (MatchFound) {

-  HandleBuffer[*HandleCount] = HandleBuffer[Index];

-  (*HandleCount)++;

-}

 

-FreePool (OriginalFmpImageInfoBuf);

+  FreePool (OriginalFmpImageInfoBuf);

+}

   }

 

   if ((*HandleCount) == 0) {

-- 
2.27.0.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#62488): https://edk2.groups.io/g/devel/message/62488
Mute This Topic: https://groups.io/mt/75474501/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-



  1   2   >