aarch64: fdt: Fix create_psci_node

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 <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Andrew Walbran <qwandor@google.com>
Commit-Queue: Pierre-Clément Tosi <ptosi@google.com>
This commit is contained in:
Pierre-Clément Tosi 2022-03-25 13:51:31 +00:00 committed by Chromeos LUCI
parent 150255a1a8
commit 3a81c077b3

View file

@ -9,7 +9,7 @@ use std::io::Read;
use arch::fdt::{Error, FdtWriter, Result}; use arch::fdt::{Error, FdtWriter, Result};
use arch::SERIAL_ADDR; use arch::SERIAL_ADDR;
use devices::{PciAddress, PciInterruptPin}; use devices::{PciAddress, PciInterruptPin};
use hypervisor::PsciVersion; use hypervisor::{PsciVersion, PSCI_0_2, PSCI_1_0};
use vm_memory::{GuestAddress, GuestMemory}; use vm_memory::{GuestAddress, GuestMemory};
// This is the start of DRAM in the physical address space. // 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<()> { fn create_psci_node(fdt: &mut FdtWriter, version: &PsciVersion) -> Result<()> {
let mut compatible = vec![format!("arm,psci-{}.{}", version.major, version.minor)]; // The PSCI kernel driver only supports compatible strings for the following
if version.major == 1 { // backward-compatible versions.
// Put `psci-0.2` as well because PSCI 1.0 is compatible with PSCI 0.2. let supported = [(PSCI_1_0, "arm,psci-1.0"), (PSCI_0_2, "arm,psci-0.2")];
compatible.push(format!("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 psci_node = fdt.begin_node("psci")?;
let compatible: Vec<_> = compatible.iter().map(String::as_str).collect();
fdt.property_string_list("compatible", &compatible)?; fdt.property_string_list("compatible", &compatible)?;
// Only support aarch64 guest // Only support aarch64 guest
fdt.property_string("method", "hvc")?; fdt.property_string("method", "hvc")?;