[edk2-devel] [PATCH v1 2/2] OvmfPkg/BaseMemEncryptLib: Support to issue unencrypted hypercall

Ashish Kalra ashish.kalra at amd.com
Wed Dec 2 21:13:24 UTC 2020


On Wed, Dec 02, 2020 at 08:38:23AM -0600, Tom Lendacky wrote:
> On 12/2/20 1:29 AM, Ashish Kalra wrote:
> > From: Brijesh Singh <brijesh.singh at amd.com>
> > 
> > By default all the SEV guest memory regions are considered encrypted,
> > if a guest changes the encryption attribute of the page (e.g mark a
> > page as decrypted) then notify hypervisor. Hypervisor will need to
> > track the unencrypted pages. The information will be used during
> > guest live migration, guest page migration and guest debugging.
> > 
> > Invoke hypercall via the new hypercall library
> > 
> > This hypercall is used to notify hypervisor when a page is marked as
> > 'decrypted' (i.e C-bit removed).
> 
> This will miss the SEC GHCB page that is mapped as unencrypted in
> OvmfPkg/ResetVector/Ia32/PageTables64.asm. You'll need to remember to mark
> that one specifically. I don't think there are any others.
> 

Ok, thanks Tom, i will add this.

Ashish

> 
> > 
> > Cc: Jordan Justen <jordan.l.justen at intel.com>
> > Cc: Laszlo Ersek <lersek at redhat.com>
> > Cc: Ard Biesheuvel <ard.biesheuvel at arm.com>
> > 
> > Signed-off-by: Brijesh Singh <brijesh.singh at amd.com>
> > Signed-off-by: Ashish Kalra <ashish.kalra at amd.com>
> > ---
> >   OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevLib.inf |  1 +
> >   OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c      | 18 ++++++++++++++++++
> >   2 files changed, 19 insertions(+)
> > 
> > diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevLib.inf b/OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevLib.inf
> > index 7c44d09528..95ee707918 100644
> > --- a/OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevLib.inf
> > +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevLib.inf
> > @@ -46,6 +46,7 @@
> >     DebugLib
> >     MemoryAllocationLib
> >     PcdLib
> > +  MemEncryptHypercallLib
> >   [FeaturePcd]
> >     gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire
> > diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c
> > index 5e110c84ff..1e670b6200 100644
> > --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c
> > +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.c
> > @@ -14,6 +14,7 @@
> >   #include <Library/CpuLib.h>
> >   #include <Register/Amd/Cpuid.h>
> >   #include <Register/Cpuid.h>
> > +#include <Library/MemEncryptHypercallLib.h>
> >   #include "VirtualMemory.h"
> > @@ -589,6 +590,9 @@ SetMemoryEncDec (
> >     UINT64                         AddressEncMask;
> >     BOOLEAN                        IsWpEnabled;
> >     RETURN_STATUS                  Status;
> > +  UINTN                          Size;
> > +  BOOLEAN                        CBitChanged;
> > +  PHYSICAL_ADDRESS               OrigPhysicalAddress;
> >     //
> >     // Set PageMapLevel4Entry to suppress incorrect compiler/analyzer warnings.
> > @@ -640,6 +644,10 @@ SetMemoryEncDec (
> >     Status = EFI_SUCCESS;
> > +  Size = Length;
> > +  CBitChanged = FALSE;
> > +  OrigPhysicalAddress = PhysicalAddress;
> > +
> >     while (Length)
> >     {
> >       //
> > @@ -699,6 +707,7 @@ SetMemoryEncDec (
> >             ));
> >           PhysicalAddress += BIT30;
> >           Length -= BIT30;
> > +        CBitChanged = TRUE;
> >         } else {
> >           //
> >           // We must split the page
> > @@ -753,6 +762,7 @@ SetMemoryEncDec (
> >             SetOrClearCBit (&PageDirectory2MEntry->Uint64, Mode);
> >             PhysicalAddress += BIT21;
> >             Length -= BIT21;
> > +          CBitChanged = TRUE;
> >           } else {
> >             //
> >             // We must split up this page into 4K pages
> > @@ -795,6 +805,7 @@ SetMemoryEncDec (
> >           SetOrClearCBit (&PageTableEntry->Uint64, Mode);
> >           PhysicalAddress += EFI_PAGE_SIZE;
> >           Length -= EFI_PAGE_SIZE;
> > +        CBitChanged = TRUE;
> >         }
> >       }
> >     }
> > @@ -812,6 +823,13 @@ SetMemoryEncDec (
> >     //
> >     CpuFlushTlb();
> > +  //
> > +  // Notify Hypervisor on C-bit status
> > +  //
> > +  if (CBitChanged) {
> > +    SetMemoryEncDecHypercall3 (OrigPhysicalAddress, EFI_SIZE_TO_PAGES(Size), !Mode);
> > +  }
> > +
> >   Done:
> >     //
> >     // Restore page table write protection, if any.
> > 


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#68244): https://edk2.groups.io/g/devel/message/68244
Mute This Topic: https://groups.io/mt/78658199/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-





More information about the edk2-devel-archive mailing list