pvmfw: Move DT sanitization to main()
Move it so that it can re-use other inputs e.g. VBMeta capabilities.
This should not compromise the integrity of pvmfw as it still happens
before the DT is used to initialize the PCI bus and swiotlb region.
Move the shared memory setup to main(), so that it only happens when
actually needed i.e. when the instance.img is used, requiring a shared
region for the VirtIO transport.
Bug: 339782511
Bug: 377276983
Test: m pvmfw_bin
Change-Id: I6de6e4607d110c2f8fffd9a3d9527716dca92565
diff --git a/guest/pvmfw/src/memory.rs b/guest/pvmfw/src/memory.rs
index e51a730..d2f63b5 100644
--- a/guest/pvmfw/src/memory.rs
+++ b/guest/pvmfw/src/memory.rs
@@ -15,7 +15,7 @@
//! Low-level allocation and tracking of main memory.
use crate::entry::RebootReason;
-use crate::fdt::{read_initrd_range_from, read_kernel_range_from, sanitize_device_tree};
+use crate::fdt::{read_initrd_range_from, read_kernel_range_from};
use core::num::NonZeroUsize;
use core::slice;
use log::debug;
@@ -24,7 +24,7 @@
use log::warn;
use vmbase::{
layout::crosvm,
- memory::{init_shared_pool, map_data, map_rodata, resize_available_memory},
+ memory::{map_data, map_rodata, resize_available_memory},
};
pub(crate) struct MemorySlices<'a> {
@@ -34,13 +34,7 @@
}
impl<'a> MemorySlices<'a> {
- pub fn new(
- fdt: usize,
- kernel: usize,
- kernel_size: usize,
- vm_dtbo: Option<&mut [u8]>,
- vm_ref_dt: Option<&[u8]>,
- ) -> Result<Self, RebootReason> {
+ pub fn new(fdt: usize, kernel: usize, kernel_size: usize) -> Result<Self, RebootReason> {
let fdt_size = NonZeroUsize::new(crosvm::FDT_MAX_SIZE).unwrap();
// TODO - Only map the FDT as read-only, until we modify it right before jump_to_payload()
// e.g. by generating a DTBO for a template DT in main() and, on return, re-map DT as RW,
@@ -117,15 +111,6 @@
None
};
- let info = sanitize_device_tree(untrusted_fdt, vm_dtbo, vm_ref_dt)?;
- debug!("Fdt passed validation!");
- let fdt = untrusted_fdt;
-
- init_shared_pool(info.swiotlb_info.fixed_range()).map_err(|e| {
- error!("Failed to initialize shared pool: {e}");
- RebootReason::InternalError
- })?;
-
- Ok(Self { fdt, kernel, ramdisk })
+ Ok(Self { fdt: untrusted_fdt, kernel, ramdisk })
}
}