Change the condition for preparing for ramdump on the crosvm side
Preparing for ramdump on the crosvm side means two activities:
* creating an empty file for storing the ramdump (and making it as the
backing file for the /dev/hvc1 virtio console)
* adding `crashkernel=xxM` parameter
For protected VMs: ramdump is prepared if debug policy (accessed by
reading the device tree) says ramdump is enabled. Note that we can do
this unconditionally for protected VMs because pvmfw will anyway kick in
and remove the parameter if ramdump is enabled. We do this conditionally
on the host just because we don't want to create the ramdump file
unnecessarily.
For non-protected VMs: ramdump is prepared if debug policy says so OR
the debugLevel is full. This allows developers to do the ramdump even on
a device where debug policy is not provisioed.
Bug: 270657304
Test: test ramdump on the following combinations:
* dp provisioned + pVM + debugLevel=none: ramdump enabled
* dp provisioned + pVM + debugLevel=full: ramdump enabled
* dp provisioned + non-pVM + debugLevel=none: ramdump enabled
* dp provisioned + non-pVM + debugLevel=full: ramdump enabled
* dp empty + pVM + debugLevel=none: ramdump disabled
* dp empty + pVM + debugLevel=full: ramdump disabled [note]
* dp empty + non-pVM + debugLevel=none: ramdump disabled
* dp empty + non-pVM + debugLevel=full: ramdump enabled
[note] `crashkernel=xx` is sent from the host. However, pvmfw
unconditionally removes the parameter from the cmdline because dp is not
provisioned. It could have checked the debug level by looking into the
bootconfig in the initrd, but it's too dirty.
Change-Id: I52ce34e0f9ef6404e482abec728c8108341a9fd6
diff --git a/virtualizationmanager/src/crosvm.rs b/virtualizationmanager/src/crosvm.rs
index 1b52507..6ac1658 100644
--- a/virtualizationmanager/src/crosvm.rs
+++ b/virtualizationmanager/src/crosvm.rs
@@ -667,16 +667,6 @@
}
}
-fn ramdump_enabled() -> bool {
- if let Ok(mut file) = File::open("/proc/device-tree/avf/guest/common/ramdump") {
- let mut ramdump: [u8; 4] = Default::default();
- file.read_exact(&mut ramdump).map_err(|_| false).unwrap();
- // DT spec uses big endian although Android is always little endian.
- return u32::from_be_bytes(ramdump) == 1;
- }
- false
-}
-
/// Starts an instance of `crosvm` to manage a new VM.
fn run_vm(
config: CrosvmConfig,
@@ -723,12 +713,14 @@
// Context in b/238324526.
command.arg("--unmap-guest-memory-on-fork");
- // Protected VM needs to reserve memory for ramdump here. pvmfw will drop This
- // if ramdump should be disabled (via debug policy). Note that we reserve more
- // memory for the restricted dma pool.
- let ramdump_reserve = RAMDUMP_RESERVED_MIB + swiotlb_size_mib;
- command.arg("--params").arg(format!("crashkernel={ramdump_reserve}M"));
- } else if ramdump_enabled() {
+ if config.ramdump.is_some() {
+ // Protected VM needs to reserve memory for ramdump here. pvmfw will drop This
+ // if ramdump should be disabled (via debug policy). Note that we reserve more
+ // memory for the restricted dma pool.
+ let ramdump_reserve = RAMDUMP_RESERVED_MIB + swiotlb_size_mib;
+ command.arg("--params").arg(format!("crashkernel={ramdump_reserve}M"));
+ }
+ } else if config.ramdump.is_some() {
command.arg("--params").arg(format!("crashkernel={RAMDUMP_RESERVED_MIB}M"));
}