[edk2-devel] [PATCH v2 08/11] OvmfPkg/AmdSev/SecretPei: build hob for full page

Dov Murik posted 11 patches 4 years, 7 months ago
There is a newer version of this series
[edk2-devel] [PATCH v2 08/11] OvmfPkg/AmdSev/SecretPei: build hob for full page
Posted by Dov Murik 4 years, 7 months ago
Round up the size of the SEV launch secret area to a whole page, as
required by BuildMemoryAllocationHob.  This will allow the secret
area defined in the MEMFD to take less than a whole 4KB page.

Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Ashish Kalra <ashish.kalra@amd.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Erdem Aktas <erdemaktas@google.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Min Xu <min.m.xu@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3457
Signed-off-by: Dov Murik <dovmurik@linux.ibm.com>
---
 OvmfPkg/AmdSev/SecretPei/SecretPei.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/OvmfPkg/AmdSev/SecretPei/SecretPei.c b/OvmfPkg/AmdSev/SecretPei/SecretPei.c
index ad491515dd5d..db4267428e5a 100644
--- a/OvmfPkg/AmdSev/SecretPei/SecretPei.c
+++ b/OvmfPkg/AmdSev/SecretPei/SecretPei.c
@@ -15,9 +15,16 @@ InitializeSecretPei (
   IN CONST EFI_PEI_SERVICES     **PeiServices
   )
 {
+  UINT64 RoundedSize;
+
+  RoundedSize = PcdGet32 (PcdSevLaunchSecretSize);
+  if (RoundedSize % EFI_PAGE_SIZE != 0) {
+    RoundedSize = (RoundedSize / EFI_PAGE_SIZE + 1) * EFI_PAGE_SIZE;
+  }
+
   BuildMemoryAllocationHob (
     PcdGet32 (PcdSevLaunchSecretBase),
-    PcdGet32 (PcdSevLaunchSecretSize),
+    RoundedSize,
     EfiBootServicesData
     );
 
-- 
2.25.1



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


Re: [edk2-devel] [PATCH v2 08/11] OvmfPkg/AmdSev/SecretPei: build hob for full page
Posted by Lendacky, Thomas via groups.io 4 years, 6 months ago
On 7/6/21 3:54 AM, Dov Murik wrote:
> Round up the size of the SEV launch secret area to a whole page, as
> required by BuildMemoryAllocationHob.  This will allow the secret
> area defined in the MEMFD to take less than a whole 4KB page.
> 
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
> Cc: Jordan Justen <jordan.l.justen@intel.com>
> Cc: Ashish Kalra <ashish.kalra@amd.com>
> Cc: Brijesh Singh <brijesh.singh@amd.com>
> Cc: Erdem Aktas <erdemaktas@google.com>
> Cc: James Bottomley <jejb@linux.ibm.com>
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Min Xu <min.m.xu@intel.com>
> Cc: Tom Lendacky <thomas.lendacky@amd.com>
> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3457
> Signed-off-by: Dov Murik <dovmurik@linux.ibm.com>
> ---
>  OvmfPkg/AmdSev/SecretPei/SecretPei.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/OvmfPkg/AmdSev/SecretPei/SecretPei.c b/OvmfPkg/AmdSev/SecretPei/SecretPei.c
> index ad491515dd5d..db4267428e5a 100644
> --- a/OvmfPkg/AmdSev/SecretPei/SecretPei.c
> +++ b/OvmfPkg/AmdSev/SecretPei/SecretPei.c
> @@ -15,9 +15,16 @@ InitializeSecretPei (
>    IN CONST EFI_PEI_SERVICES     **PeiServices
>    )
>  {
> +  UINT64 RoundedSize;
> +
> +  RoundedSize = PcdGet32 (PcdSevLaunchSecretSize);

Can you just unconditionally perform:

  RoundedSize = ALIGN_VALUE (RoundedSize, EFI_PAGE_SIZE);

Or use ALIGN_VALUE () in the if statement if you don't want to do it
unconditionally?

Or even use ALIGN_VALUE on size value in the BuildMemoryAllocationHob()
call below.

Thanks,
Tom

> +  if (RoundedSize % EFI_PAGE_SIZE != 0) {
> +    RoundedSize = (RoundedSize / EFI_PAGE_SIZE + 1) * EFI_PAGE_SIZE;
> +  }
> +
>    BuildMemoryAllocationHob (
>      PcdGet32 (PcdSevLaunchSecretBase),
> -    PcdGet32 (PcdSevLaunchSecretSize),
> +    RoundedSize,
>      EfiBootServicesData
>      );
>  
> 


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


Re: [edk2-devel] [PATCH v2 08/11] OvmfPkg/AmdSev/SecretPei: build hob for full page
Posted by Dov Murik 4 years, 6 months ago

On 19/07/2021 19:19, Tom Lendacky wrote:
> On 7/6/21 3:54 AM, Dov Murik wrote:
>> Round up the size of the SEV launch secret area to a whole page, as
>> required by BuildMemoryAllocationHob.  This will allow the secret
>> area defined in the MEMFD to take less than a whole 4KB page.
>>
>> Cc: Laszlo Ersek <lersek@redhat.com>
>> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
>> Cc: Jordan Justen <jordan.l.justen@intel.com>
>> Cc: Ashish Kalra <ashish.kalra@amd.com>
>> Cc: Brijesh Singh <brijesh.singh@amd.com>
>> Cc: Erdem Aktas <erdemaktas@google.com>
>> Cc: James Bottomley <jejb@linux.ibm.com>
>> Cc: Jiewen Yao <jiewen.yao@intel.com>
>> Cc: Min Xu <min.m.xu@intel.com>
>> Cc: Tom Lendacky <thomas.lendacky@amd.com>
>> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3457
>> Signed-off-by: Dov Murik <dovmurik@linux.ibm.com>
>> ---
>>  OvmfPkg/AmdSev/SecretPei/SecretPei.c | 9 ++++++++-
>>  1 file changed, 8 insertions(+), 1 deletion(-)
>>
>> diff --git a/OvmfPkg/AmdSev/SecretPei/SecretPei.c b/OvmfPkg/AmdSev/SecretPei/SecretPei.c
>> index ad491515dd5d..db4267428e5a 100644
>> --- a/OvmfPkg/AmdSev/SecretPei/SecretPei.c
>> +++ b/OvmfPkg/AmdSev/SecretPei/SecretPei.c
>> @@ -15,9 +15,16 @@ InitializeSecretPei (
>>    IN CONST EFI_PEI_SERVICES     **PeiServices
>>    )
>>  {
>> +  UINT64 RoundedSize;
>> +
>> +  RoundedSize = PcdGet32 (PcdSevLaunchSecretSize);
> 
> Can you just unconditionally perform:
> 
>   RoundedSize = ALIGN_VALUE (RoundedSize, EFI_PAGE_SIZE);
> 
> Or use ALIGN_VALUE () in the if statement if you don't want to do it
> unconditionally?
> 
> Or even use ALIGN_VALUE on size value in the BuildMemoryAllocationHob()
> call below.

Yes, that's much better.  Thanks for introducing me to this macro.

-Dov


> 
> Thanks,
> Tom
> 
>> +  if (RoundedSize % EFI_PAGE_SIZE != 0) {
>> +    RoundedSize = (RoundedSize / EFI_PAGE_SIZE + 1) * EFI_PAGE_SIZE;
>> +  }
>> +
>>    BuildMemoryAllocationHob (
>>      PcdGet32 (PcdSevLaunchSecretBase),
>> -    PcdGet32 (PcdSevLaunchSecretSize),
>> +    RoundedSize,
>>      EfiBootServicesData
>>      );
>>  
>>


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