From 74f9fdb11fc23a5d178d0010eff3163d0b6367de Mon Sep 17 00:00:00 2001 From: Pavel Mores Date: Tue, 4 Mar 2025 14:21:50 +0100 Subject: [PATCH] runtime-rs: remove hardcoding of SEV physical address reduction Previous commit enabled getting the physical address reduction from processor but just stored it for later use. This commit adds handling of the value to ProtectionDevice and enables the QEMU driver to use it. Signed-off-by: Pavel Mores --- .../src/device/driver/protection_device.rs | 1 + .../hypervisor/src/qemu/cmdline_generator.rs | 17 ++++++++++++----- .../crates/hypervisor/src/qemu/inner.rs | 2 ++ .../runtimes/virt_container/src/sandbox.rs | 2 ++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/runtime-rs/crates/hypervisor/src/device/driver/protection_device.rs b/src/runtime-rs/crates/hypervisor/src/device/driver/protection_device.rs index e990cc873c..2d13d0020e 100644 --- a/src/runtime-rs/crates/hypervisor/src/device/driver/protection_device.rs +++ b/src/runtime-rs/crates/hypervisor/src/device/driver/protection_device.rs @@ -21,6 +21,7 @@ pub enum ProtectionDeviceConfig { pub struct SevSnpConfig { pub is_snp: bool, pub cbitpos: u32, + pub phys_addr_reduction: u32, pub firmware: String, pub host_data: Option, } diff --git a/src/runtime-rs/crates/hypervisor/src/qemu/cmdline_generator.rs b/src/runtime-rs/crates/hypervisor/src/qemu/cmdline_generator.rs index 54ed5da2b2..553e2596a8 100644 --- a/src/runtime-rs/crates/hypervisor/src/qemu/cmdline_generator.rs +++ b/src/runtime-rs/crates/hypervisor/src/qemu/cmdline_generator.rs @@ -1875,11 +1875,11 @@ struct ObjectSevSnpGuest { } impl ObjectSevSnpGuest { - fn new(is_snp: bool, cbitpos: u32, host_data: Option) -> Self { + fn new(is_snp: bool, cbitpos: u32, reduced_phys_bits: u32, host_data: Option) -> Self { ObjectSevSnpGuest { id: (if is_snp { "snp" } else { "sev" }).to_owned(), cbitpos, - reduced_phys_bits: 1, + reduced_phys_bits, kernel_hashes: true, host_data, is_snp, @@ -2538,8 +2538,13 @@ impl<'a> QemuCmdLine<'a> { .remove_all_by_key("rootfstype".to_string()); } - pub fn add_sev_protection_device(&mut self, cbitpos: u32, firmware: &str) { - let sev_object = ObjectSevSnpGuest::new(true, cbitpos, None); + pub fn add_sev_protection_device( + &mut self, + cbitpos: u32, + phys_addr_reduction: u32, + firmware: &str, + ) { + let sev_object = ObjectSevSnpGuest::new(false, cbitpos, phys_addr_reduction, None); self.devices.push(Box::new(sev_object)); self.devices.push(Box::new(Bios::new(firmware.to_owned()))); @@ -2552,10 +2557,12 @@ impl<'a> QemuCmdLine<'a> { pub fn add_sev_snp_protection_device( &mut self, cbitpos: u32, + phys_addr_reduction: u32, firmware: &str, host_data: &Option, ) { - let sev_snp_object = ObjectSevSnpGuest::new(true, cbitpos, host_data.clone()); + let sev_snp_object = + ObjectSevSnpGuest::new(true, cbitpos, phys_addr_reduction, host_data.clone()); self.devices.push(Box::new(sev_snp_object)); self.devices.push(Box::new(Bios::new(firmware.to_owned()))); diff --git a/src/runtime-rs/crates/hypervisor/src/qemu/inner.rs b/src/runtime-rs/crates/hypervisor/src/qemu/inner.rs index 63aa260de9..8ab3807bc5 100644 --- a/src/runtime-rs/crates/hypervisor/src/qemu/inner.rs +++ b/src/runtime-rs/crates/hypervisor/src/qemu/inner.rs @@ -163,12 +163,14 @@ impl QemuInner { if sev_snp_cfg.is_snp { cmdline.add_sev_snp_protection_device( sev_snp_cfg.cbitpos, + sev_snp_cfg.phys_addr_reduction, &sev_snp_cfg.firmware, &sev_snp_cfg.host_data, ) } else { cmdline.add_sev_protection_device( sev_snp_cfg.cbitpos, + sev_snp_cfg.phys_addr_reduction, &sev_snp_cfg.firmware, ) } diff --git a/src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs b/src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs index c639be448a..2b793589ab 100644 --- a/src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs +++ b/src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs @@ -423,6 +423,7 @@ impl VirtSandbox { Ok(Some(ProtectionDeviceConfig::SevSnp(SevSnpConfig { is_snp: false, cbitpos: details.cbitpos, + phys_addr_reduction: details.phys_addr_reduction, firmware: hypervisor_config.boot_info.firmware.clone(), host_data: None, }))) @@ -443,6 +444,7 @@ impl VirtSandbox { Ok(Some(ProtectionDeviceConfig::SevSnp(SevSnpConfig { is_snp, cbitpos: details.cbitpos, + phys_addr_reduction: details.phys_addr_reduction, firmware: hypervisor_config.boot_info.firmware.clone(), host_data: init_data, })))