pvmfw: Print RebootReason on secondary UART
When rebooting due to a business logic error, print the reason as a
formatted string to a dedicated UART, in the same way Microdroid does it
on its /dev/tty1, to provide the host with extra information about the
reason for the pVM rebooting.
Since aosp/2646391, all the pvmfw code runs with the UART properly
initialized, which greatly simplifies printing of the reboot reason as
start() can now assume that the secondary UART is also ready to be used.
This CL was verified through the logs of virtualizationmanager e.g. in
MicrodroidHostTests#protectedVmWithImageSignedWithDifferentKeyRunsPvmfw:
virtmgr : virtualizationmanager::crosvm: VM returned failure reason 'PVM_FIRMWARE_PAYLOAD_VERIFICATION_FAILED'
Note that the host still has to be taught about the new PVM_FIRMWARE_*.
Bug: 300636104
Test: atest MicrodroidHostTestCases
Change-Id: I5d382be9dae02da7e463193400dfa0474ca5e378
diff --git a/pvmfw/src/entry.rs b/pvmfw/src/entry.rs
index 36ead46..0ff7270 100644
--- a/pvmfw/src/entry.rs
+++ b/pvmfw/src/entry.rs
@@ -30,7 +30,7 @@
use log::LevelFilter;
use vmbase::util::RangeExt as _;
use vmbase::{
- configure_heap,
+ configure_heap, console_writeln,
hyp::{get_mem_sharer, get_mmio_guard},
layout::{self, crosvm, UART_PAGE_ADDR},
main,
@@ -59,6 +59,21 @@
SecretDerivationError,
}
+impl RebootReason {
+ pub fn as_avf_reboot_string(&self) -> &'static str {
+ match self {
+ Self::InvalidBcc => "PVM_FIRMWARE_INVALID_BCC",
+ Self::InvalidConfig => "PVM_FIRMWARE_INVALID_CONFIG_DATA",
+ Self::InternalError => "PVM_FIRMWARE_INTERNAL_ERROR",
+ Self::InvalidFdt => "PVM_FIRMWARE_INVALID_FDT",
+ Self::InvalidPayload => "PVM_FIRMWARE_INVALID_PAYLOAD",
+ Self::InvalidRamdisk => "PVM_FIRMWARE_INVALID_RAMDISK",
+ Self::PayloadVerificationError => "PVM_FIRMWARE_PAYLOAD_VERIFICATION_FAILED",
+ Self::SecretDerivationError => "PVM_FIRMWARE_SECRET_DERIVATION_FAILED",
+ }
+ }
+}
+
main!(start);
configure_heap!(SIZE_128KB);
@@ -70,7 +85,11 @@
match main_wrapper(fdt_address as usize, payload_start as usize, payload_size as usize) {
Ok((entry, bcc)) => jump_to_payload(fdt_address, entry.try_into().unwrap(), bcc),
- Err(_) => reboot(), // TODO(b/220071963) propagate the reason back to the host.
+ Err(e) => {
+ const REBOOT_REASON_CONSOLE: usize = 1;
+ console_writeln!(REBOOT_REASON_CONSOLE, "{}", e.as_avf_reboot_string());
+ reboot()
+ }
}
// if we reach this point and return, vmbase::entry::rust_entry() will call power::shutdown().