mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
build: Consolidate sev_snp feature usage
Since igvm is a required feature of sev_snp and also sev_snp is x86-64 only the cfg attributes at build time can be consolidated & simplified. Signed-off-by: Rob Bradford <rbradford@meta.com>
This commit is contained in:
@@ -41,12 +41,7 @@ use crate::cpu::CpuManager;
|
||||
use crate::igvm::loader::Loader;
|
||||
use crate::igvm::{BootPageAcceptance, HV_PAGE_SIZE, IgvmLoadedInfo, StartupMemoryType};
|
||||
use crate::memory_manager::{Error as MemoryManagerError, MemoryManager};
|
||||
#[cfg(all(
|
||||
feature = "kvm",
|
||||
feature = "sev_snp",
|
||||
feature = "fw_cfg",
|
||||
target_arch = "x86_64"
|
||||
))]
|
||||
#[cfg(all(feature = "kvm", feature = "sev_snp", feature = "fw_cfg"))]
|
||||
use crate::sev::{MeasuredBootInfo, SEV_HASH_BLOCK_ADDRESS, SEV_HASH_BLOCK_SIZE};
|
||||
|
||||
#[cfg(feature = "sev_snp")]
|
||||
@@ -107,20 +102,10 @@ pub enum Error {
|
||||
MissingIgvm,
|
||||
#[error("Error applying VMSA to vCPU registers: {0}")]
|
||||
SetVmsa(#[source] crate::cpu::Error),
|
||||
#[cfg(all(
|
||||
feature = "kvm",
|
||||
feature = "sev_snp",
|
||||
feature = "fw_cfg",
|
||||
target_arch = "x86_64"
|
||||
))]
|
||||
#[cfg(all(feature = "kvm", feature = "sev_snp", feature = "fw_cfg"))]
|
||||
#[error("Error building SEV-SNP measured boot hash block")]
|
||||
MeasuredBoot(#[source] vmm_sys_util::errno::Error),
|
||||
#[cfg(all(
|
||||
feature = "kvm",
|
||||
feature = "sev_snp",
|
||||
feature = "fw_cfg",
|
||||
target_arch = "x86_64"
|
||||
))]
|
||||
#[cfg(all(feature = "kvm", feature = "sev_snp", feature = "fw_cfg"))]
|
||||
#[error(
|
||||
"igvmfile inserts unmeasured parameter area [0x{region_start:x}, 0x{region_end:x}) over SEV-SNP kernel hashes region [0x{hash_start:x}, 0x{hash_end:x})"
|
||||
)]
|
||||
@@ -279,13 +264,9 @@ pub fn load_igvm(
|
||||
memory_manager: Arc<Mutex<MemoryManager>>,
|
||||
cpu_manager: Arc<Mutex<CpuManager>>,
|
||||
cmdline: &str,
|
||||
#[cfg(all(
|
||||
feature = "kvm",
|
||||
feature = "sev_snp",
|
||||
feature = "fw_cfg",
|
||||
target_arch = "x86_64"
|
||||
))]
|
||||
measured_boot: Option<MeasuredBootInfo>,
|
||||
#[cfg(all(feature = "kvm", feature = "sev_snp", feature = "fw_cfg"))] measured_boot: Option<
|
||||
MeasuredBootInfo,
|
||||
>,
|
||||
#[cfg(feature = "sev_snp")] host_data: &Option<String>,
|
||||
) -> Result<Box<IgvmLoadedInfo>, Error> {
|
||||
let hypervisor_type = cpu_manager.lock().unwrap().hypervisor_type();
|
||||
@@ -338,12 +319,7 @@ pub fn load_igvm(
|
||||
let mut loader = Loader::new(memory);
|
||||
|
||||
let mut parameter_areas: HashMap<u32, ParameterAreaState> = HashMap::new();
|
||||
#[cfg(all(
|
||||
feature = "kvm",
|
||||
feature = "sev_snp",
|
||||
feature = "fw_cfg",
|
||||
target_arch = "x86_64"
|
||||
))]
|
||||
#[cfg(all(feature = "kvm", feature = "sev_snp", feature = "fw_cfg"))]
|
||||
let measured_boot_hash_block = if hypervisor_type == HypervisorType::Kvm {
|
||||
measured_boot
|
||||
.as_ref()
|
||||
@@ -356,26 +332,11 @@ pub fn load_igvm(
|
||||
} else {
|
||||
None
|
||||
};
|
||||
#[cfg(all(
|
||||
feature = "kvm",
|
||||
feature = "sev_snp",
|
||||
feature = "fw_cfg",
|
||||
target_arch = "x86_64"
|
||||
))]
|
||||
#[cfg(all(feature = "kvm", feature = "sev_snp", feature = "fw_cfg"))]
|
||||
let measured_boot_hash_page_base = SEV_HASH_BLOCK_ADDRESS / HV_PAGE_SIZE;
|
||||
#[cfg(all(
|
||||
feature = "kvm",
|
||||
feature = "sev_snp",
|
||||
feature = "fw_cfg",
|
||||
target_arch = "x86_64"
|
||||
))]
|
||||
#[cfg(all(feature = "kvm", feature = "sev_snp", feature = "fw_cfg"))]
|
||||
let measured_boot_hash_offset = (SEV_HASH_BLOCK_ADDRESS % HV_PAGE_SIZE) as usize;
|
||||
#[cfg(all(
|
||||
feature = "kvm",
|
||||
feature = "sev_snp",
|
||||
feature = "fw_cfg",
|
||||
target_arch = "x86_64"
|
||||
))]
|
||||
#[cfg(all(feature = "kvm", feature = "sev_snp", feature = "fw_cfg"))]
|
||||
let mut measured_boot_hash_block_inserted = measured_boot_hash_block.is_none();
|
||||
|
||||
for header in igvm_file.directives() {
|
||||
@@ -529,12 +490,7 @@ pub fn load_igvm(
|
||||
.map_err(Error::Loader)?;
|
||||
imported_page = true;
|
||||
}
|
||||
#[cfg(all(
|
||||
feature = "kvm",
|
||||
feature = "sev_snp",
|
||||
feature = "fw_cfg",
|
||||
target_arch = "x86_64"
|
||||
))]
|
||||
#[cfg(all(feature = "kvm", feature = "sev_snp", feature = "fw_cfg"))]
|
||||
if let Some(hash_block) = measured_boot_hash_block.as_ref().filter(|_| {
|
||||
!imported_page && gpa / HV_PAGE_SIZE == measured_boot_hash_page_base
|
||||
}) {
|
||||
@@ -732,12 +688,7 @@ pub fn load_igvm(
|
||||
};
|
||||
match area {
|
||||
ParameterAreaState::Allocated { data, max_size } => {
|
||||
#[cfg(all(
|
||||
feature = "kvm",
|
||||
feature = "sev_snp",
|
||||
feature = "fw_cfg",
|
||||
target_arch = "x86_64"
|
||||
))]
|
||||
#[cfg(all(feature = "kvm", feature = "sev_snp", feature = "fw_cfg"))]
|
||||
if measured_boot_hash_block.is_some() {
|
||||
let region_end = *gpa + *max_size;
|
||||
let hash_end = SEV_HASH_BLOCK_ADDRESS + SEV_HASH_BLOCK_SIZE as u64;
|
||||
@@ -794,12 +745,7 @@ pub fn load_igvm(
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(
|
||||
feature = "kvm",
|
||||
feature = "sev_snp",
|
||||
feature = "fw_cfg",
|
||||
target_arch = "x86_64"
|
||||
))]
|
||||
#[cfg(all(feature = "kvm", feature = "sev_snp", feature = "fw_cfg"))]
|
||||
if let Some(hash_block) = measured_boot_hash_block.as_ref()
|
||||
&& !measured_boot_hash_block_inserted
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user