xref: /cloud-hypervisor/vmm/src/igvm/mod.rs (revision 1968805ba291ae08e07abf0ef8c0ade4cf11ab68)
1 // SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause
2 //
3 // Copyright © 2023, Microsoft Corporation
4 //
5 /*
6  *  The IGVM(Independent Guest Virtual Machine) file format
7  *  is designed to encapsulate all information required to
8  *  launch a virtual machine on any given virtualization stack,
9  *  with support for different isolation technologies such as
10  *  AMD SEV-SNP and Intel TDX.
11  *  At a conceptual level, this file format is a set of commands created
12  *  by the tool that generated the file, used by the loader to construct
13  *  the initial guest state. The file format also contains measurement
14  *  information that the underlying platform will use to confirm that
15  *  the file was loaded correctly and signed by the appropriate authorities.
16  *
17  *  The IGVM file is generated by the tool:
18  *  https://github.com/microsoft/igvm-tooling
19  *
20  *  The IGVM file is parsed by the following crates:
21  *  https://github.com/microsoft/igvm
22  *
23  *  This module takes the IGVM file, parses it, and loads it to the
24  *  guest memory. Currently igvm only supported on Microsoft Hypervisor, as
25  *  booting a legacy VM, as well as SNP based isolated VM.
26  */
27 
28 pub mod igvm_loader;
29 mod loader;
30 use igvm::snp_defs::SevVmsa;
31 use igvm_defs::IGVM_VHS_SNP_ID_BLOCK;
32 use zerocopy::FromZeros;
33 
34 #[derive(Debug, Clone)]
35 pub struct IgvmLoadedInfo {
36     pub gpas: Vec<u64>,
37     pub vmsa_gpa: u64,
38     pub snp_id_block: IGVM_VHS_SNP_ID_BLOCK,
39     pub vmsa: SevVmsa,
40 }
41 
42 impl Default for IgvmLoadedInfo {
43     fn default() -> Self {
44         IgvmLoadedInfo {
45             gpas: Vec::new(),
46             vmsa_gpa: 0,
47             snp_id_block: IGVM_VHS_SNP_ID_BLOCK::new_zeroed(),
48             vmsa: SevVmsa::new_zeroed(),
49         }
50     }
51 }
52 
53 pub const HV_PAGE_SIZE: u64 = 4096;
54 
55 /// The page acceptance used for importing pages into the initial launch context of the guest.
56 #[derive(Debug, PartialEq, Eq, Clone, Copy)]
57 pub enum BootPageAcceptance {
58     /// The page is accepted exclusive (no host visibility) and the page data is measured.
59     Exclusive,
60     /// The page is accepted exclusive (no host visibility) and the page data is unmeasured.
61     ExclusiveUnmeasured,
62     /// The page contains hardware-specific VP context information.
63     VpContext,
64     /// This page communicates error information to the host.
65     ErrorPage,
66     /// This page communicates hardware-specific secret information and the page data is unmeasured.
67     SecretsPage,
68     /// This page includes guest-specified CPUID information.
69     CpuidPage,
70     /// This page should include the enumeration of extended state CPUID leaves.
71     CpuidExtendedStatePage,
72 }
73 
74 /// The startup memory type used to notify a well behaved host that memory should be present before attempting to
75 /// start the guest.
76 #[allow(dead_code)]
77 #[derive(Debug, PartialEq, Eq)]
78 pub enum StartupMemoryType {
79     /// The range is normal memory.
80     Ram,
81 }
82