hypervisor: Introduce an enable AMX tile state components method

Currently when the user configures AMX the corresponding state
components get dynamically enabled directly inside the function body of
vmm::cpu::CpuManager::new.

With our ongoing work on CPU templates/profiles, there will (likely) be
one more binary crate for producing CPU profiles that also needs to do
this (without creating a CpuManager) and it may also be the case that
we will need to call this function prior to `CpuManager::new` during
live migrations.

We thus add a method for enabling the AMX tile state components on the
hypervisor trait that may be called wherever necessary. We argue that
this is beneficial for code clarity independently of the upcoming CPU
templates/profiles PR that we are working on.

The astute reader will notice that the logic introduced here is not 100%
the same as what is done inside the vmm::cpu::Cpumanager::new method. We
claim that our approach is more in-line with the official documentation.

Signed-off-by: Oliver Anderson <oliver.anderson@cyberus-technology.de>
On-behalf-of: SAP oliver.anderson@sap.com
This commit is contained in:
Oliver Anderson
2025-12-04 11:35:45 +01:00
committed by Rob Bradford
parent 5fb50edb55
commit 01383538f3
2 changed files with 104 additions and 0 deletions

View File

@@ -89,6 +89,13 @@ pub enum HypervisorError {
///
#[error("Unsupported VmType")]
UnsupportedVmType(),
///
/// The attempt to enable AMX tile state components failed
///
#[cfg(target_arch = "x86_64")]
#[error("Failed to enable AMX tile state components")]
CouldNotEnableAmxStateComponents(#[source] crate::arch::x86::AmxGuestSupportError),
}
///
@@ -166,4 +173,19 @@ pub trait Hypervisor: Send + Sync {
}
}
}
/// This function enables the AMX related TILECFG and TILEDATA state components for guests.
///
/// # Background
/// AMX uses a concept of tiles which are small 2D blocks of data stored in registers on the CPU,
/// where the TILECFG state component defines the shape and size of each tile (rows and columns),
/// and the TILEDATA state component holds the actual elements of these tiles used by matrix operations.
#[cfg(target_arch = "x86_64")]
fn enable_amx_state_components(&self) -> Result<()> {
let cpu_vendor = self.get_cpu_vendor();
crate::arch::x86::amx_supported(cpu_vendor)
.map_err(HypervisorError::CouldNotEnableAmxStateComponents)?;
crate::arch::x86::request_guest_amx_support()
.map_err(HypervisorError::CouldNotEnableAmxStateComponents)
}
}