[edk2-devel] [PATCH 4/4] OvmfPkg/CcExitLib: Use documented XSave area base size for SEV-SNP

Roth, Michael via groups.io posted 4 patches 3 years, 1 month ago
There is a newer version of this series
[edk2-devel] [PATCH 4/4] OvmfPkg/CcExitLib: Use documented XSave area base size for SEV-SNP
Posted by Roth, Michael via groups.io 3 years, 1 month ago
Currently OVMF tries to rely on the base size advertised via the CPUID
table entries corresponding to leaf 0xD, sub-leafs 0x0/0x1. This will
generally work for KVM guests, but might not for other SEV-SNP
hypervisor implementations. Make the handling more robust by simply
using the base area size documented by the APM.

Signed-off-by: Michael Roth <michael.roth@amd.com>
---
 OvmfPkg/Library/CcExitLib/CcExitVcHandler.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/OvmfPkg/Library/CcExitLib/CcExitVcHandler.c b/OvmfPkg/Library/CcExitLib/CcExitVcHandler.c
index cd117d5a31..f985dcff8d 100644
--- a/OvmfPkg/Library/CcExitLib/CcExitVcHandler.c
+++ b/OvmfPkg/Library/CcExitLib/CcExitVcHandler.c
@@ -1647,8 +1647,6 @@ SnpEnabled (
 

   @param[in]      XFeaturesEnabled  Bit-mask of enabled XSAVE features/areas as

                                     indicated by XCR0/MSR_IA32_XSS bits

-  @param[in]      XSaveBaseSize     Base/legacy XSAVE area size (e.g. when

-                                    XCR0 is 1)

   @param[in, out] XSaveSize         Pointer to storage for calculated XSAVE area

                                     size

   @param[in]      Compacted         Whether or not the calculation is for the

@@ -1663,7 +1661,6 @@ STATIC
 BOOLEAN

 GetCpuidXSaveSize (

   IN     UINT64   XFeaturesEnabled,

-  IN     UINT32   XSaveBaseSize,

   IN OUT UINT32   *XSaveSize,

   IN     BOOLEAN  Compacted

   )

@@ -1672,7 +1669,10 @@ GetCpuidXSaveSize (
   UINT64              XFeaturesFound = 0;

   UINT32              Idx;

 

-  *XSaveSize = XSaveBaseSize;

+  //

+  // The base/legacy XSave size is documented to be 0x240 in the APM.

+  //

+  *XSaveSize = 0x240;

   CpuidInfo  = (SEV_SNP_CPUID_INFO *)(UINT64)PcdGet32 (PcdOvmfCpuidBase);

 

   for (Idx = 0; Idx < CpuidInfo->Count; Idx++) {

@@ -1888,7 +1888,6 @@ GetCpuidFw (
 

     if (!GetCpuidXSaveSize (

            XCr0 | XssMsr.Uint64,

-           *Ebx,

            &XSaveSize,

            Compacted

            ))

-- 
2.25.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#97705): https://edk2.groups.io/g/devel/message/97705
Mute This Topic: https://groups.io/mt/95815543/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH 4/4] OvmfPkg/CcExitLib: Use documented XSave area base size for SEV-SNP
Posted by Yao, Jiewen 3 years, 1 month ago
Acked-by: Jiewen Yao <jiewen.yao@intel.com>

> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Roth,
> Michael via groups.io
> Sent: Thursday, December 22, 2022 12:07 AM
> To: devel@edk2.groups.io
> Cc: Tom Lendacky <thomas.lendacky@amd.com>; Ni, Ray <ray.ni@intel.com>
> Subject: [edk2-devel] [PATCH 4/4] OvmfPkg/CcExitLib: Use documented
> XSave area base size for SEV-SNP
> 
> Currently OVMF tries to rely on the base size advertised via the CPUID
> table entries corresponding to leaf 0xD, sub-leafs 0x0/0x1. This will
> generally work for KVM guests, but might not for other SEV-SNP
> hypervisor implementations. Make the handling more robust by simply
> using the base area size documented by the APM.
> 
> Signed-off-by: Michael Roth <michael.roth@amd.com>
> ---
>  OvmfPkg/Library/CcExitLib/CcExitVcHandler.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/OvmfPkg/Library/CcExitLib/CcExitVcHandler.c
> b/OvmfPkg/Library/CcExitLib/CcExitVcHandler.c
> index cd117d5a31..f985dcff8d 100644
> --- a/OvmfPkg/Library/CcExitLib/CcExitVcHandler.c
> +++ b/OvmfPkg/Library/CcExitLib/CcExitVcHandler.c
> @@ -1647,8 +1647,6 @@ SnpEnabled (
> 
> 
>    @param[in]      XFeaturesEnabled  Bit-mask of enabled XSAVE
> features/areas as
> 
>                                      indicated by XCR0/MSR_IA32_XSS bits
> 
> -  @param[in]      XSaveBaseSize     Base/legacy XSAVE area size (e.g. when
> 
> -                                    XCR0 is 1)
> 
>    @param[in, out] XSaveSize         Pointer to storage for calculated XSAVE
> area
> 
>                                      size
> 
>    @param[in]      Compacted         Whether or not the calculation is for the
> 
> @@ -1663,7 +1661,6 @@ STATIC
>  BOOLEAN
> 
>  GetCpuidXSaveSize (
> 
>    IN     UINT64   XFeaturesEnabled,
> 
> -  IN     UINT32   XSaveBaseSize,
> 
>    IN OUT UINT32   *XSaveSize,
> 
>    IN     BOOLEAN  Compacted
> 
>    )
> 
> @@ -1672,7 +1669,10 @@ GetCpuidXSaveSize (
>    UINT64              XFeaturesFound = 0;
> 
>    UINT32              Idx;
> 
> 
> 
> -  *XSaveSize = XSaveBaseSize;
> 
> +  //
> 
> +  // The base/legacy XSave size is documented to be 0x240 in the APM.
> 
> +  //
> 
> +  *XSaveSize = 0x240;
> 
>    CpuidInfo  = (SEV_SNP_CPUID_INFO *)(UINT64)PcdGet32
> (PcdOvmfCpuidBase);
> 
> 
> 
>    for (Idx = 0; Idx < CpuidInfo->Count; Idx++) {
> 
> @@ -1888,7 +1888,6 @@ GetCpuidFw (
> 
> 
>      if (!GetCpuidXSaveSize (
> 
>             XCr0 | XssMsr.Uint64,
> 
> -           *Ebx,
> 
>             &XSaveSize,
> 
>             Compacted
> 
>             ))
> 
> --
> 2.25.1
> 
> 
> 
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#98082): https://edk2.groups.io/g/devel/message/98082
Mute This Topic: https://groups.io/mt/95815543/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Re: [edk2-devel] [PATCH 4/4] OvmfPkg/CcExitLib: Use documented XSave area base size for SEV-SNP
Posted by Lendacky, Thomas via groups.io 3 years, 1 month ago
On 12/21/22 10:06, Michael Roth wrote:
> Currently OVMF tries to rely on the base size advertised via the CPUID
> table entries corresponding to leaf 0xD, sub-leafs 0x0/0x1. This will
> generally work for KVM guests, but might not for other SEV-SNP
> hypervisor implementations. Make the handling more robust by simply
> using the base area size documented by the APM.
> 
> Signed-off-by: Michael Roth <michael.roth@amd.com>

Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>

> ---
>   OvmfPkg/Library/CcExitLib/CcExitVcHandler.c | 9 ++++-----
>   1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/OvmfPkg/Library/CcExitLib/CcExitVcHandler.c b/OvmfPkg/Library/CcExitLib/CcExitVcHandler.c
> index cd117d5a31..f985dcff8d 100644
> --- a/OvmfPkg/Library/CcExitLib/CcExitVcHandler.c
> +++ b/OvmfPkg/Library/CcExitLib/CcExitVcHandler.c
> @@ -1647,8 +1647,6 @@ SnpEnabled (
>   
>     @param[in]      XFeaturesEnabled  Bit-mask of enabled XSAVE features/areas as
>                                       indicated by XCR0/MSR_IA32_XSS bits
> -  @param[in]      XSaveBaseSize     Base/legacy XSAVE area size (e.g. when
> -                                    XCR0 is 1)
>     @param[in, out] XSaveSize         Pointer to storage for calculated XSAVE area
>                                       size
>     @param[in]      Compacted         Whether or not the calculation is for the
> @@ -1663,7 +1661,6 @@ STATIC
>   BOOLEAN
>   GetCpuidXSaveSize (
>     IN     UINT64   XFeaturesEnabled,
> -  IN     UINT32   XSaveBaseSize,
>     IN OUT UINT32   *XSaveSize,
>     IN     BOOLEAN  Compacted
>     )
> @@ -1672,7 +1669,10 @@ GetCpuidXSaveSize (
>     UINT64              XFeaturesFound = 0;
>     UINT32              Idx;
>   
> -  *XSaveSize = XSaveBaseSize;
> +  //
> +  // The base/legacy XSave size is documented to be 0x240 in the APM.
> +  //
> +  *XSaveSize = 0x240;
>     CpuidInfo  = (SEV_SNP_CPUID_INFO *)(UINT64)PcdGet32 (PcdOvmfCpuidBase);
>   
>     for (Idx = 0; Idx < CpuidInfo->Count; Idx++) {
> @@ -1888,7 +1888,6 @@ GetCpuidFw (
>   
>       if (!GetCpuidXSaveSize (
>              XCr0 | XssMsr.Uint64,
> -           *Ebx,
>              &XSaveSize,
>              Compacted
>              ))


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#97694): https://edk2.groups.io/g/devel/message/97694
Mute This Topic: https://groups.io/mt/95810062/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-