From 7fd1b9a284cac62efdbae6d0bf30740958b0aada Mon Sep 17 00:00:00 2001 From: Jinank Jain Date: Fri, 18 Apr 2025 12:49:55 +0000 Subject: [PATCH] hypervisor: Configure VGIC for MSHV guests As part of this configuration, two things are being done: 1. Setting up the base address of GIC Distributor 2. Setting up the base address of GIC Interrupt Translator Signed-off-by: Jinank Jain --- .typos.toml | 1 + hypervisor/src/mshv/mod.rs | 30 ++++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/.typos.toml b/.typos.toml index 8dd1f8d66..e6e04974f 100644 --- a/.typos.toml +++ b/.typos.toml @@ -15,6 +15,7 @@ EXTINT = "EXTINT" INOUT = "INOUT" liness = "liness" outout = "outout" +TRANSLATER = "TRANSLATER" [default.extend-identifiers] fo = "fo" diff --git a/hypervisor/src/mshv/mod.rs b/hypervisor/src/mshv/mod.rs index ccf5d8ea6..c2eaa79d8 100644 --- a/hypervisor/src/mshv/mod.rs +++ b/hypervisor/src/mshv/mod.rs @@ -43,6 +43,8 @@ use std::os::unix::io::AsRawFd; #[cfg(target_arch = "aarch64")] use std::sync::Mutex; +#[cfg(target_arch = "aarch64")] +use aarch64::gic::MshvGicV2M; #[cfg(target_arch = "aarch64")] pub use aarch64::VcpuMshvState; #[cfg(feature = "sev_snp")] @@ -2204,8 +2206,32 @@ impl vm::Vm for MshvVm { } #[cfg(target_arch = "aarch64")] - fn create_vgic(&self, _config: VgicConfig) -> vm::Result>> { - unimplemented!() + fn create_vgic(&self, config: VgicConfig) -> vm::Result>> { + let gic_device = MshvGicV2M::new(self, config) + .map_err(|e| vm::HypervisorVmError::CreateVgic(anyhow!("Vgic error {:?}", e)))?; + + // Register GICD address with the hypervisor + self.fd + .set_partition_property( + hv_partition_property_code_HV_PARTITION_PROPERTY_GICD_BASE_ADDRESS, + gic_device.dist_addr, + ) + .map_err(|e| { + vm::HypervisorVmError::CreateVgic(anyhow!("Failed to set GICD address: {}", e)) + })?; + + // Register GITS address with the hypervisor + self.fd + .set_partition_property( + // spellchecker:disable-line + hv_partition_property_code_HV_PARTITION_PROPERTY_GITS_TRANSLATER_BASE_ADDRESS, + gic_device.gits_addr, + ) + .map_err(|e| { + vm::HypervisorVmError::CreateVgic(anyhow!("Failed to set GITS address: {}", e)) + })?; + + Ok(Arc::new(Mutex::new(gic_device))) } #[cfg(target_arch = "aarch64")]