Skip to content

Commit a247c82

Browse files
authored
Merge pull request #365 from stefano-garzarella/fix-launch-measurement
igvm tools: fix pre-calculated launch measurement with QEMU/KVM
2 parents 3bf81ca + f61e6da commit a247c82

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

igvmbuilder/src/cmd_options.rs

+17
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ pub struct CmdOptions {
5151
/// Include NATIVE platform target
5252
#[arg(long, default_value_t = false)]
5353
pub native: bool,
54+
55+
/// Enable debug features (e.g. SNP debug_swap)
56+
#[arg(short, long, default_value_t = false)]
57+
pub debug: bool,
58+
59+
/// Extra SEV features to be enabled in the VMSA (multiple values can be provided separated by ',')
60+
#[arg(long, value_delimiter = ',')]
61+
pub sev_features: Vec<SevExtraFeatures>,
5462
}
5563

5664
impl CmdOptions {
@@ -73,3 +81,12 @@ pub enum Hypervisor {
7381
/// Build an IGVM file compatible with Hyper-V
7482
HyperV,
7583
}
84+
85+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Debug)]
86+
pub enum SevExtraFeatures {
87+
ReflectVc,
88+
AlternateInjection,
89+
DebugSwap,
90+
PreventHostIBS,
91+
SNPBTBIsolation,
92+
}

igvmbuilder/src/igvm_builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ impl IgvmBuilder {
347347
self.gpa_map.vmsa.get_start(),
348348
param_block.vtom,
349349
SNP_COMPATIBILITY_MASK,
350+
&self.options.sev_features,
350351
));
351352
}
352353

igvmbuilder/src/vmsa.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use igvm::IgvmDirectiveHeader;
1111
use igvm_defs::IgvmNativeVpContextX64;
1212
use zerocopy::FromZeroes;
1313

14+
use crate::cmd_options::SevExtraFeatures;
1415
use crate::stage2_stack::Stage2Stack;
1516

1617
pub fn construct_start_context() -> Box<IgvmNativeVpContextX64> {
@@ -49,6 +50,7 @@ pub fn construct_vmsa(
4950
gpa_start: u64,
5051
vtom: u64,
5152
compatibility_mask: u32,
53+
extra_features: &Vec<SevExtraFeatures>,
5254
) -> IgvmDirectiveHeader {
5355
let mut vmsa_box = SevVmsa::new_box_zeroed();
5456
let vmsa = vmsa_box.as_mut();
@@ -115,7 +117,17 @@ pub fn construct_vmsa(
115117
vmsa.virtual_tom = vtom;
116118
features.set_vtom(true);
117119
}
118-
features.set_debug_swap(true);
120+
121+
for extra_f in extra_features {
122+
match extra_f {
123+
SevExtraFeatures::ReflectVc => features.set_reflect_vc(true),
124+
SevExtraFeatures::AlternateInjection => features.set_alternate_injection(true),
125+
SevExtraFeatures::DebugSwap => features.set_debug_swap(true),
126+
SevExtraFeatures::PreventHostIBS => features.set_prevent_host_ibs(true),
127+
SevExtraFeatures::SNPBTBIsolation => features.set_snp_btb_isolation(true),
128+
}
129+
}
130+
119131
vmsa.sev_features = features;
120132

121133
IgvmDirectiveHeader::SnpVpContext {

igvmmeasure/src/igvm_measure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ impl IgvmMeasure {
339339
if vmsa.cr0 != 0x31 {
340340
return Err(IgvmMeasureError::InvalidVmsaCr0);
341341
}
342-
if !vmsa.sev_features.debug_swap() {
342+
if vmsa.sev_features.debug_swap() {
343343
return Err(IgvmMeasureError::InvalidDebugSwap);
344344
}
345345
}

0 commit comments

Comments
 (0)