Skip to content

AMD Secure Nested Paging (SEV-SNP) Guest Support

John Allen requested to merge johnalle/centos-stream-9:2081424 into main
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2081424 
Upstream Status: linux.git 
Tested: Set up host system with the kernel, qemu, and ovmf that support SNP
from the scripts found here:
https://github.com/AMDESE/AMDSEV/tree/sev-snp-devel
Install guest VM with the kernel built from this patchset and boot with
-object sev-snp-guest,id=sev0,cbitpos=51,reduced-phys-bits=1
Guest should boot with the following message in the dmesg logs:
AMD Memory Encryption Features active: SEV SEV-ES SEV-SNP

This part of Secure Encrypted Paging (SEV-SNP) series focuses on the changes
required in a guest OS for SEV-SNP support.

SEV-SNP builds upon existing SEV and SEV-ES functionality while adding
new hardware-based memory protections. SEV-SNP adds strong memory integrity
protection to help prevent malicious hypervisor-based attacks like data
replay, memory re-mapping and more in order to create an isolated memory
encryption environment.
 
This series provides the basic building blocks to support booting the SEV-SNP
VMs, it does not cover all the security enhancement introduced by the SEV-SNP
such as interrupt protection.

Many of the integrity guarantees of SEV-SNP are enforced through a new
structure called the Reverse Map Table (RMP). Adding a new page to SEV-SNP
VM requires a 2-step process. First, the hypervisor assigns a page to the
guest using the new RMPUPDATE instruction. This transitions the page to
guest-invalid. Second, the guest validates the page using the new PVALIDATE
instruction. The SEV-SNP VMs can use the new "Page State Change Request NAE"
defined in the GHCB specification to ask hypervisor to add or remove page
from the RMP table.

Each page assigned to the SEV-SNP VM can either be validated or unvalidated,
as indicated by the Validated flag in the page's RMP entry. There are two
approaches that can be taken for the page validation: Pre-validation and
Lazy Validation.

Under pre-validation, the pages are validated prior to first use. And under
lazy validation, pages are validated when first accessed. An access to a
unvalidated page results in a #VC exception, at which time the exception
handler may validate the page. Lazy validation requires careful tracking of
the validated pages to avoid validating the same GPA more than once. The
recently introduced "Unaccepted" memory type can be used to communicate the
unvalidated memory ranges to the Guest OS.

At this time we only support the pre-validation, the OVMF guest BIOS
validates the entire RAM before the control is handed over to the guest kernel.
The early_set_memory_{encrypted,decrypted} and set_memory_{encrypted,decrypted} are
enlightened to perform the page validation or invalidation while setting or
clearing the encryption attribute from the page table.

This series does not provide support for the Interrupt security yet which will
be added after the base support.


Signed-off-by: Bandan Das <bsd@redhat.com>
Signed-off-by: John Allen <johnalle@redhat.com>
Edited by John Allen

Merge request reports