• Brijesh Singh's avatar
    x86/compressed: Add helper for validating pages in the decompression stage · 4f9c403e
    Brijesh Singh authored
    Many of the integrity guarantees of SEV-SNP are enforced through the
    Reverse Map Table (RMP). Each RMP entry contains the GPA at which a
    particular page of DRAM should be mapped. The VMs can request the
    hypervisor to add pages in the RMP table via the Page State Change
    VMGEXIT defined in the GHCB specification.
    
    Inside each RMP entry is a Validated flag; this flag is automatically
    cleared to 0 by the CPU hardware when a new RMP entry is created for a
    guest. Each VM page can be either validated or invalidated, as indicated
    by the Validated flag in the RMP entry. Memory access to a private page
    that is not validated generates a #VC. A VM must use the PVALIDATE
    instruction to validate a private page before using it.
    
    To maintain the security guarantee of SEV-SNP guests, when transitioning
    pages from private to shared, the guest must invalidate the pages before
    asking the hypervisor to change the page state to shared in the RMP table.
    
    After the pages are mapped private in the page table, the guest must
    issue a page state change VMGEXIT to mark the pages private in the RMP
    table and validate them.
    
    Upon boot, BIOS should have validated the entire system memory.
    During the kernel decompression stage, early_setup_ghcb() uses
    set_page_decrypted() to make the GHCB page shared (i.e. clear encryption
    attribute). And while exiting from the decompression, it calls
    set_page_encrypted() to make the page private.
    
    Add snp_set_page_{private,shared}() helpers that are used by
    set_page_{decrypted,encrypted}() to change the page state in the RMP
    table.
    
      [ bp: Massage commit message and comments. ]
    Signed-off-by: default avatarBrijesh Singh <brijesh.singh@amd.com>
    Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
    Link: https://lore.kernel.org/r/20220307213356.2797205-16-brijesh.singh@amd.com
    4f9c403e
sev-common.h 3.85 KB