From f657d3729a2e82fc97649daeff44c1f146c114f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Sun, 10 May 2026 19:02:20 +0200 Subject: [PATCH] kata-types: add GuestExtensionImage type and field to BootInfo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduce the GuestExtensionImage type to describe extension block-device images (e.g. CoCo guest components) that are cold-plugged into the VM alongside the main rootfs. Each GuestExtensionImage carries a short name (used as the virtio-blk serial and in kernel cmdline verity parameters), a host-side path, and dm-verity parameters (required -- extension images must be integrity- protected). A new guest_extension_images Vec is added to BootInfo so that both the Rust and Go runtimes can iterate the configured extensions when building the VM device list and kernel command line. Signed-off-by: Fabiano FidĂȘncio Assisted-by: Cursor --- .../kata-types/src/config/hypervisor/mod.rs | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/libs/kata-types/src/config/hypervisor/mod.rs b/src/libs/kata-types/src/config/hypervisor/mod.rs index eaab7eb82f..77e95a5996 100644 --- a/src/libs/kata-types/src/config/hypervisor/mod.rs +++ b/src/libs/kata-types/src/config/hypervisor/mod.rs @@ -445,6 +445,25 @@ pub fn validate_block_device_sector_size(size: u32) -> Result<()> { Ok(()) } +/// Extra block device image to attach to the VM (e.g. CoCo extension, GPU extension). +#[derive(Clone, Debug, Default, Deserialize, Serialize)] +pub struct GuestExtensionImage { + /// Short name for this extension (e.g. "coco", "gpu"). Used as the virtio-blk + /// serial so the guest can discover the device via + /// `/dev/disk/by-id/virtio-extension-` and match kernel cmdline verity + /// params `kata.extension..verity_params=...`. + pub name: String, + + /// Path to the extension image file on the host. + #[serde(default)] + pub path: String, + + /// DM-verity parameters for this extension image (root_hash, salt, etc.). + /// Populated at install time from the image build artifacts. + #[serde(default)] + pub verity_params: String, +} + /// Guest kernel boot information. #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct BootInfo { @@ -1732,6 +1751,11 @@ pub struct Hypervisor { #[serde(default, flatten)] pub boot_info: BootInfo, + /// Additional block device images to attach to the VM (e.g. CoCo extension). + /// Each image is cold-plugged as a read-only virtio-blk device. + #[serde(default)] + pub guest_extension_images: Vec, + /// Guest virtual CPU configuration information. #[serde(default, flatten)] pub cpu_info: CpuInfo, @@ -1841,6 +1865,9 @@ impl ConfigOps for Hypervisor { })?; hv.blockdev_info.adjust_config()?; hv.boot_info.adjust_config()?; + for extra in &mut hv.guest_extension_images { + resolve_path!(extra.path, "extra image file {} is invalid: {}")?; + } hv.cpu_info.adjust_config()?; hv.debug_info.adjust_config()?; hv.device_info.adjust_config()?; @@ -1881,6 +1908,35 @@ impl ConfigOps for Hypervisor { let hv = conf.hypervisor.get(hypervisor).unwrap(); hv.blockdev_info.validate()?; hv.boot_info.validate()?; + for extra in &hv.guest_extension_images { + validate_path!(extra.path, "extra image file {} is invalid: {}")?; + if extra.name.is_empty() { + return Err(std::io::Error::other( + "guest_extension_images entry is missing required 'name' field", + )); + } + if !extra + .name + .chars() + .all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_') + { + return Err(std::io::Error::other(format!( + "guest_extension_images '{}' has an invalid name: only ASCII \ + alphanumerics, '-' and '_' are allowed (the name is used in the \ + virtio-blk serial and in the kata.extension..verity_params \ + kernel parameter)", + extra.name + ))); + } + if !extra.verity_params.trim().is_empty() { + parse_kernel_verity_params(&extra.verity_params).map_err(|e| { + std::io::Error::other(format!( + "guest_extension_images '{}' has invalid verity_params: {}", + extra.name, e + )) + })?; + } + } hv.cpu_info.validate()?; hv.debug_info.validate()?; hv.device_info.validate()?;