From 3a81c077b31d079158b9fbeefe33cff270750c14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Cl=C3=A9ment=20Tosi?= Date: Fri, 25 Mar 2022 13:51:31 +0000 Subject: [PATCH] aarch64: fdt: Fix create_psci_node MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Don't format the PSCI compatible string from the version received from KVM as that generates invalid strings for versions other than 0.2 and 1.0. Instead, assume backward compatibility from 0.2 onwards and pass only those that are relevant and supported by the kernel driver or pass the PSCI v0.1 compatible string otherwise. BUG=b:227142928 TEST=tools/dev_container tools/run_tests --target=vm:aarch64 TEST=booted a protected VM from the AOSP fork + checked DT node Change-Id: I3b6a05b487751435b4e0e1c7a6f4643fece02ca7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3560156 Reviewed-by: Daniel Verkamp Tested-by: kokoro Reviewed-by: Andrew Walbran Commit-Queue: Pierre-Clément Tosi --- aarch64/src/fdt.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/aarch64/src/fdt.rs b/aarch64/src/fdt.rs index 5c51d6e4cd..82547f521e 100644 --- a/aarch64/src/fdt.rs +++ b/aarch64/src/fdt.rs @@ -9,7 +9,7 @@ use std::io::Read; use arch::fdt::{Error, FdtWriter, Result}; use arch::SERIAL_ADDR; use devices::{PciAddress, PciInterruptPin}; -use hypervisor::PsciVersion; +use hypervisor::{PsciVersion, PSCI_0_2, PSCI_1_0}; use vm_memory::{GuestAddress, GuestMemory}; // This is the start of DRAM in the physical address space. @@ -224,14 +224,22 @@ fn create_serial_nodes(fdt: &mut FdtWriter) -> Result<()> { } fn create_psci_node(fdt: &mut FdtWriter, version: &PsciVersion) -> Result<()> { - let mut compatible = vec![format!("arm,psci-{}.{}", version.major, version.minor)]; - if version.major == 1 { - // Put `psci-0.2` as well because PSCI 1.0 is compatible with PSCI 0.2. - compatible.push(format!("arm,psci-0.2")) - }; + // The PSCI kernel driver only supports compatible strings for the following + // backward-compatible versions. + let supported = [(PSCI_1_0, "arm,psci-1.0"), (PSCI_0_2, "arm,psci-0.2")]; + + let compatible: Vec<_> = supported + .iter() + .filter(|&(v, _)| *version >= *v) + .map(|&(_, c)| c) + .collect(); + + // The PSCI kernel driver also supports PSCI v0.1, which is NOT forward-compatible. + if compatible.is_empty() { + let compatible = vec!["arm,psci"]; + } let psci_node = fdt.begin_node("psci")?; - let compatible: Vec<_> = compatible.iter().map(String::as_str).collect(); fdt.property_string_list("compatible", &compatible)?; // Only support aarch64 guest fdt.property_string("method", "hvc")?;