Skip to content

Commit

Permalink
Define a new variable header type for environment information (#18)
Browse files Browse the repository at this point in the history
The IGVM_VHT_ENVIRONMENT_INFO_PARAMETER defines a bitfield that permits
the hosting environment to describe certain behaviors so the VM can
conform. The only currently defined behavior indicates whether the
default state of memory is assigned (private) or unassigned (shared) so
the VM knows whether it must request page state changes before using any
memory. Other behaviors will be defined in the future.
  • Loading branch information
msft-jlange authored Dec 13, 2023
1 parent 4977f88 commit 2a6e996
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 16 deletions.
35 changes: 33 additions & 2 deletions igvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ pub enum IgvmDirectiveHeader {
initial_data: Vec<u8>,
},
VpCount(IGVM_VHS_PARAMETER),
EnvironmentInfo(IGVM_VHS_PARAMETER),
Srat(IGVM_VHS_PARAMETER),
Madt(IGVM_VHS_PARAMETER),
Slit(IGVM_VHS_PARAMETER),
Expand Down Expand Up @@ -815,6 +816,7 @@ impl IgvmDirectiveHeader {
IgvmDirectiveHeader::PageData { .. } => size_of::<IGVM_VHS_PAGE_DATA>(),
IgvmDirectiveHeader::ParameterArea { .. } => size_of::<IGVM_VHS_PARAMETER_AREA>(),
IgvmDirectiveHeader::VpCount(param) => size_of_val(param),
IgvmDirectiveHeader::EnvironmentInfo(param) => size_of_val(param),
IgvmDirectiveHeader::Srat(param) => size_of_val(param),
IgvmDirectiveHeader::Madt(param) => size_of_val(param),
IgvmDirectiveHeader::Slit(param) => size_of_val(param),
Expand Down Expand Up @@ -931,6 +933,13 @@ impl IgvmDirectiveHeader {
variable_headers,
);
}
IgvmDirectiveHeader::EnvironmentInfo(param) => {
append_header(
param,
IgvmVariableHeaderType::IGVM_VHT_ENVIRONMENT_INFO_PARAMETER,
variable_headers,
);
}
IgvmDirectiveHeader::Srat(param) => {
append_header(
param,
Expand Down Expand Up @@ -1175,6 +1184,7 @@ impl IgvmDirectiveHeader {
} => Some(*compatibility_mask),
ParameterArea { .. } => None,
VpCount(_) => None,
EnvironmentInfo(_) => None,
Srat(_) => None,
Madt(_) => None,
Slit(_) => None,
Expand Down Expand Up @@ -1219,6 +1229,7 @@ impl IgvmDirectiveHeader {
} => Some(compatibility_mask),
ParameterArea { .. } => None,
VpCount(_) => None,
EnvironmentInfo(_) => None,
Srat(_) => None,
Madt(_) => None,
Slit(_) => None,
Expand Down Expand Up @@ -1347,6 +1358,7 @@ impl IgvmDirectiveHeader {
// Parameter usage is validated by the IgvmFile functions, as more
// info is needed than just this header.
IgvmDirectiveHeader::VpCount(_)
| IgvmDirectiveHeader::EnvironmentInfo(_)
| IgvmDirectiveHeader::Srat(_)
| IgvmDirectiveHeader::Madt(_)
| IgvmDirectiveHeader::Slit(_)
Expand Down Expand Up @@ -1637,6 +1649,11 @@ impl IgvmDirectiveHeader {
{
IgvmDirectiveHeader::VpCount(read_header(&mut variable_headers)?)
}
IgvmVariableHeaderType::IGVM_VHT_ENVIRONMENT_INFO_PARAMETER
if length == size_of::<IGVM_VHS_PARAMETER>() =>
{
IgvmDirectiveHeader::EnvironmentInfo(read_header(&mut variable_headers)?)
}
IgvmVariableHeaderType::IGVM_VHT_SRAT if length == size_of::<IGVM_VHS_PARAMETER>() => {
IgvmDirectiveHeader::Srat(read_header(&mut variable_headers)?)
}
Expand Down Expand Up @@ -2248,6 +2265,7 @@ impl IgvmFile {
}
}
IgvmDirectiveHeader::VpCount(info)
| IgvmDirectiveHeader::EnvironmentInfo(info)
| IgvmDirectiveHeader::Srat(info)
| IgvmDirectiveHeader::Madt(info)
| IgvmDirectiveHeader::Slit(info)
Expand Down Expand Up @@ -3002,8 +3020,16 @@ impl IgvmFile {
}
}
}
VpCount(info) | Srat(info) | Madt(info) | Slit(info) | Pptt(info)
| MmioRanges(info) | MemoryMap(info) | CommandLine(info) | DeviceTree(info) => {
VpCount(info)
| EnvironmentInfo(info)
| Srat(info)
| Madt(info)
| Slit(info)
| Pptt(info)
| MmioRanges(info)
| MemoryMap(info)
| CommandLine(info)
| DeviceTree(info) => {
fixup_parameter_index(
&mut info.parameter_area_index,
&fixup_parameter_index_map,
Expand Down Expand Up @@ -3911,6 +3937,11 @@ mod tests {
IgvmVariableHeaderType::IGVM_VHT_VP_COUNT_PARAMETER
));

test_igvm_parameter!(test_environment_info(
IgvmDirectiveHeader::EnvironmentInfo,
IgvmVariableHeaderType::IGVM_VHT_ENVIRONMENT_INFO_PARAMETER
));

test_igvm_parameter!(test_srat(
IgvmDirectiveHeader::Srat,
IgvmVariableHeaderType::IGVM_VHT_SRAT
Expand Down
29 changes: 15 additions & 14 deletions igvm_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,13 @@ pub enum IgvmVariableHeaderType {
///
/// IGVM specific extensions can be found in the [`dt`] module.
IGVM_VHT_DEVICE_TREE = 0x312,
/// A parameter which holds a 4-byte u32 value defining the default state
/// of memory in the memory map. The value is defined by the
/// IgvmMemoryState enumeration. The loader will write the state to the
/// specified offset of the specified parameter area. The parameter
/// location information is specified by a structure of type
/// [`IGVM_VHS_PARAMETER`].
IGVM_VHT_MEMORY_STATE_PARAMETER = 0x313,
/// A parameter which holds a u32 bitfield value defining environmental
/// state of the VM. The bitfield is defined by the `IgvmEnvironmentInfo`
/// structure. The loader will write the state to the specified offset of
/// the specified parameter area. The parameter location information is
/// specified by a structure of type [`IGVM_VHS_PARAMETER`].
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
IGVM_VHT_ENVIRONMENT_INFO_PARAMETER = 0x313,
}

/// The range of header types for platform structures.
Expand Down Expand Up @@ -637,14 +637,15 @@ pub struct IGVM_VHS_PARAMETER_AREA {

/// Default memory state described by the IGVM_VHT_MEMORY_STATE_PARAMETER
/// parameter.
#[open_enum]
#[derive(AsBytes, FromBytes, FromZeroes, Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)]
pub enum IgvmMemoryState {
/// Default state of memory is assigned to the guest (private)
ASSIGNED = 0x0,
#[cfg(feature = "unstable")]
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
#[bitfield(u32)]
#[derive(AsBytes, FromBytes, FromZeroes, PartialEq, Eq)]
pub struct IgvmEnvironmentInfo {
/// Default state of memory is not assigned to the guest (shared)
UNASSIGNED = 0x1,
pub memory_is_shared: bool,
#[bits(31)]
pub reserved: u32,
}

/// Page data types that describe the type of import for
Expand Down

0 comments on commit 2a6e996

Please sign in to comment.