Skip to content

Commit

Permalink
Merge branch 'main' into zc-working
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkur committed Feb 1, 2025
2 parents a243d2b + 495daf6 commit 5160924
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
11 changes: 11 additions & 0 deletions openhcl/host_fdt_parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ pub struct ParsedDeviceTree<
pub device_dma_page_count: Option<u64>,
/// Indicates that Host does support NVMe keep-alive.
pub nvme_keepalive: bool,
/// The physical address of the VTL0 alias mapping, if one is configured.
pub vtl0_alias_map: Option<u64>,
}

/// The memory allocation mode provided by the host. This determines how OpenHCL
Expand Down Expand Up @@ -316,6 +318,7 @@ impl<
entropy: None,
device_dma_page_count: None,
nvme_keepalive: false,
vtl0_alias_map: None,
}
}

Expand Down Expand Up @@ -483,6 +486,13 @@ impl<
}
}

storage.vtl0_alias_map = child
.find_property("vtl0-alias-map")
.map_err(ErrorKind::Prop)?
.map(|p| p.read_u64(0))
.transpose()
.map_err(ErrorKind::Prop)?;

for openhcl_child in child.children() {
let openhcl_child = openhcl_child.map_err(|error| ErrorKind::Node {
parent_name: root.name,
Expand Down Expand Up @@ -727,6 +737,7 @@ impl<
entropy: _,
device_dma_page_count: _,
nvme_keepalive: _,
vtl0_alias_map: _,
} = storage;

*device_tree_size = parser.total_size;
Expand Down
5 changes: 5 additions & 0 deletions openhcl/openhcl_boot/src/host_params/dt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,11 @@ impl PartitionInfo {
storage.vtl2_pool_memory = pool;
}

// If we can trust the host, use the provided alias map
if can_trust_host {
storage.vtl0_alias_map = parsed.vtl0_alias_map;
}

// Set remaining struct fields before returning.
let Self {
vtl2_ram: _,
Expand Down
19 changes: 14 additions & 5 deletions openhcl/openhcl_boot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,14 +611,23 @@ fn shim_main(shim_params_raw_offset: isize) -> ! {
)
.vtl0_alias_map_available()
{
// Disable the alias map on ARM because physical address size is not
// reliably reported. Since the position of the alias map bit is inferred
// from address size, the alias map is broken when the PA size is wrong.
// TODO: is this still true?
if !cfg!(target_arch = "aarch64") {
// If the vtl0 alias map was not provided in the devicetree, attempt to
// derive it from the architectural physical address bits.
//
// The value in the ID_AA64MMFR0_EL1 register used to determine the
// physical address bits can only represent multiples of 4. As a result,
// the Surface Pro X (and systems with similar CPUs) cannot properly
// report their address width of 39 bits. This causes the calculated
// alias map to be incorrect, which results in panics when trying to
// read memory and getting invalid data.
if partition_info.vtl0_alias_map.is_none() {
partition_info.vtl0_alias_map =
Some(1 << (arch::physical_address_bits(p.isolation_type) - 1));
}
} else {
// Ignore any devicetree-provided alias map if the conditions above
// aren't met.
partition_info.vtl0_alias_map = None;
}

if can_trust_host {
Expand Down

0 comments on commit 5160924

Please sign in to comment.