Skip to content

Commit

Permalink
fix(fdt): Support FDT setup for CPU caches with high number of sets
Browse files Browse the repository at this point in the history
Change the type of `CacheEntry`'s `number_of_sets` field from `u16` to
`u32`, to allow correctly parsing CPU cache information from sysfs and
successfully setting up the FDT on hosts with CPU caches with a number
of sets that is higher than `u16::MAX`.

This also makes a couple of `u16`->`u32` conversions redundant, which
we therefore remove.

Signed-off-by: Christos Katsakioris <[email protected]>
Signed-off-by: Filippos Tofalos <[email protected]>
  • Loading branch information
ckatsak authored and roypat committed Oct 24, 2024
1 parent 7b4adcd commit 0b9cf39
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/vmm/src/arch/aarch64/cache_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub(crate) struct CacheEntry {
// Type of cache: Unified, Data, Instruction.
pub type_: CacheType,
pub size_: Option<u32>,
pub number_of_sets: Option<u16>,
pub number_of_sets: Option<u32>,
pub line_size: Option<u16>,
// How many CPUS share this cache.
pub cpus_per_unit: u16,
Expand Down Expand Up @@ -114,7 +114,7 @@ impl CacheEntry {
}

if let Ok(number_of_sets) = store.get_by_key(index, "number_of_sets") {
cache.number_of_sets = Some(number_of_sets.parse::<u16>().map_err(|err| {
cache.number_of_sets = Some(number_of_sets.parse::<u32>().map_err(|err| {
CacheInfoError::InvalidCacheAttr("number_of_sets".to_string(), err.to_string())
})?);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/vmm/src/arch/aarch64/fdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ fn create_cpu_nodes(fdt: &mut FdtWriter, vcpu_mpidr: &[u64]) -> Result<(), FdtEr
fdt.property_u32(cache.type_.of_cache_line_size(), u32::from(line_size))?;
}
if let Some(number_of_sets) = cache.number_of_sets {
fdt.property_u32(cache.type_.of_cache_sets(), u32::from(number_of_sets))?;
fdt.property_u32(cache.type_.of_cache_sets(), number_of_sets)?;
}
}

Expand Down Expand Up @@ -197,7 +197,7 @@ fn create_cpu_nodes(fdt: &mut FdtWriter, vcpu_mpidr: &[u64]) -> Result<(), FdtEr
fdt.property_u32(cache.type_.of_cache_line_size(), u32::from(line_size))?;
}
if let Some(number_of_sets) = cache.number_of_sets {
fdt.property_u32(cache.type_.of_cache_sets(), u32::from(number_of_sets))?;
fdt.property_u32(cache.type_.of_cache_sets(), number_of_sets)?;
}
if let Some(cache_type) = cache.type_.of_cache_type() {
fdt.property_null(cache_type)?;
Expand Down

0 comments on commit 0b9cf39

Please sign in to comment.