public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v8 0/6] SEV Live Migration support for OVMF.
@ 2022-04-05 17:28 Ashish Kalra
  2022-04-05 17:30 ` [PATCH v8 1/6] OvmfPkg/BaseMemEncryptLib: Detect SEV live migration feature Ashish Kalra
                   ` (5 more replies)
  0 siblings, 6 replies; 11+ messages in thread
From: Ashish Kalra @ 2022-04-05 17:28 UTC (permalink / raw)
  To: devel
  Cc: dovmurik, brijesh.singh, tobin, Thomas.Lendacky, jejb, dgilbert,
	lersek, jordan.l.justen, ard.biesheuvel

From: Ashish Kalra <ashish.kalra@amd.com>

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

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.

The patch-set detects if it is running under KVM hypervisor and then
checks for SEV live migration feature support via KVM_FEATURE_CPUID,
if detected setup a new UEFI enviroment variable to indicate OVMF
support for SEV live migration.

This environment variable is created by UEFI but consumed by the
(guest) linux kernel. This is actually part of a 3-way negotiation
of the live migration feature between hypervisor, guest OVMF and
guest kernel. Host indicates support for live migration, which is
detected by OVMF and correspondingly OVMF sets this SetLiveMigrationEnabled
UEFI variable, which is read by the guest kernel and it indicates
to the guest kernel that both host and OVMF support and have
enabled the live migration feature.

A branch containing these patches is available here:
https://github.com/ashkalra/edk2-1/tree/sev_live_migration_v5_23

Changes since v7:
 - Rebase to master

Changes since v6:
 - Move KvmDetectSevLiveMigrationFeature() function in a new header
   file PeiDxeMemEncryptSevLibInternal.h as this function is
   only used internally.
 - Code Style fixes.
 - More descriptive comments for use of SetLiveMigrationEnabled
   UEFI variable.

Changes since v5:
 - Split first patch into three components, one patch for the
   MemEncryptSevLiveMigrationIsEnabled() API, one patch for the
   SetMemoryEncDecHypercall3() API, one patch to make use of the
   SetMemoryEncDecHypercall3() API. 
 - Fix patch subject, in code and patch comments and 
   additionally add relevant comments.
 - Replace SetMemoryEncDecHypercall3() API's Status argument
   with a boolean IsEncrypted argument and corresponding fixes
   to users of this API call.
 - Fix AsciiStrCmp() usage in KVM hypervisor detection code.

Changes since v4:
 - Remove MemEncryptHypercallLib Library and add support to issue
   hypercall in the BaseMemEncryptSevLib library itself.
 - For SEV-ES, make the VC handler hypercall aware by comparing
   the hypercall number and add the additional register values
   in the GHCB.
 - Fix comments in the hypercall API interface.
 - The encryption bit is set/clear on the smallest page size, hence
   use the 4k page size in MAP_GPA_RANGE hypercall.
 - Make the hypercall expect the guest physical address to be
   page-aligned.
 - Add KVM live migration feature flag check in BaseMemEncryptSevLib
   library similar to how BaseMemEncryptSevLib does for the
   MemEncryptSevIsEnabled() and check it before invoking HC. Also
   export the MemEncryptSevLiveMigrationIsEnabled() function as 
   part of the library.
 - Add error handling on hypercall return, on failure, return error
   code to caller which potentially will cause an assert() and
   terminate the boot.
 
Changes since v3:
 - Fix all DSC files under OvmfPkg except X64 to add support for 
   BaseMemEncryptLib and add NULL instance of BaseMemEncryptLib
   for 32 bit platforms.
 - Add the MemEncryptHypercallLib-related files to Maintainers.txt,
   in section "OvmfPkg: Confidential Computing".
 - Add support for the new KVM_HC_MAP_GPA_RANGE hypercall interface.
 - Add patch for SEV live migration support.

Changes since v2:
 - GHCB_BASE setup during reset-vector as decrypted is marked explicitly
   in the hypervisor page encryption bitmap after setting the 
   PcdSevEsIsEnabled PCD.

Changes since v1:
 - Mark GHCB_BASE setup during reset-vector as decrypted explicitly in
   the hypervisor page encryption bitmap.
 - Resending the series with correct shallow threading.

Ashish Kalra (6):
  OvmfPkg/BaseMemEncryptLib: Detect SEV live migration feature.
  OvmfPkg/BaseMemEncryptLib: Hypercall API for page encryption state
    change
  OvmfPkg/BaseMemEncryptLib: Invoke page encryption state change
    hypercall
  OvmfPkg/VmgExitLib: Encryption state change hypercall support in VC
    handler
  OvmfPkg/PlatformPei: Mark SEC GHCB page as unencrypted via hypercall
  OvmfPkg/AmdSevDxe: Add support for SEV live migration.

 OvmfPkg/AmdSevDxe/AmdSevDxe.c                 | 67 +++++++++++++++++++
 OvmfPkg/AmdSevDxe/AmdSevDxe.inf               |  4 ++
 OvmfPkg/Include/Guid/AmdSevMemEncryptLib.h    | 20 ++++++
 OvmfPkg/Include/Library/MemEncryptSevLib.h    | 64 ++++++++++++++++++
 .../DxeMemEncryptSevLib.inf                   |  1 +
 .../DxeMemEncryptSevLibInternal.c             | 49 ++++++++++++--
 .../Ia32/MemEncryptSevLib.c                   | 27 ++++++++
 .../PeiDxeMemEncryptSevLibInternal.c          | 58 ++++++++++++++++
 .../PeiDxeMemEncryptSevLibInternal.h          | 31 +++++++++
 .../PeiMemEncryptSevLib.inf                   |  1 +
 .../PeiMemEncryptSevLibInternal.c             | 42 ++++++++++++
 .../SecMemEncryptSevLibInternal.c             | 38 +++++++++++
 .../X64/AsmHelperStub.nasm                    | 33 +++++++++
 .../X64/MemEncryptSevLib.c                    | 66 ++++++++++++++++++
 .../X64/PeiDxeVirtualMemory.c                 | 16 +++++
 OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 13 ++++
 OvmfPkg/OvmfPkg.dec                           |  1 +
 OvmfPkg/PlatformPei/AmdSev.c                  | 11 +++
 18 files changed, 538 insertions(+), 4 deletions(-)
 create mode 100644 OvmfPkg/Include/Guid/AmdSevMemEncryptLib.h
 create mode 100644 OvmfPkg/Library/BaseMemEncryptSevLib/PeiDxeMemEncryptSevLibInternal.h
 create mode 100644 OvmfPkg/Library/BaseMemEncryptSevLib/X64/AsmHelperStub.nasm

-- 
2.25.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-06-08 13:22 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-05 17:28 [PATCH v8 0/6] SEV Live Migration support for OVMF Ashish Kalra
2022-04-05 17:30 ` [PATCH v8 1/6] OvmfPkg/BaseMemEncryptLib: Detect SEV live migration feature Ashish Kalra
2022-04-05 17:31 ` [PATCH v8 2/6] OvmfPkg/BaseMemEncryptLib: Hypercall API for page encryption state change Ashish Kalra
2022-04-05 17:32 ` [PATCH v8 3/6] OvmfPkg/BaseMemEncryptLib: Invoke page encryption state change hypercall Ashish Kalra
2022-06-07  8:38   ` [edk2-devel] " nikunj
2022-06-07 17:28     ` Ashish Kalra
2022-06-08 13:22       ` nikunj
2022-04-05 17:32 ` [PATCH v8 4/6] OvmfPkg/VmgExitLib: Encryption state change hypercall support in VC handler Ashish Kalra
2022-04-05 17:32 ` [PATCH v8 5/6] OvmfPkg/PlatformPei: Mark SEC GHCB page as unencrypted via hypercall Ashish Kalra
2022-05-31 15:42   ` [edk2-devel] " Nikunj A. Dadhania
2022-04-05 17:33 ` [PATCH v8 6/6] OvmfPkg/AmdSevDxe: Add support for SEV live migration Ashish Kalra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox