From 5ec1e66e22ad736f1ed0dba5fabd7340fea33de1 Mon Sep 17 00:00:00 2001 From: Oliver Anderson Date: Thu, 4 Dec 2025 12:51:46 +0100 Subject: [PATCH] vmm: Refactor amx tile state component enabling logic We enable AMX tile state components via the hypervisor (as introduced in the previous commit) instead of doing this inline in the body of `CpuManager::new`. Signed-off-by: Oliver Anderson On-behalf-of: SAP oliver.anderson@sap.com --- vmm/src/cpu.rs | 35 +++-------------------------------- 1 file changed, 3 insertions(+), 32 deletions(-) diff --git a/vmm/src/cpu.rs b/vmm/src/cpu.rs index b219265f2..e7c8a699f 100644 --- a/vmm/src/cpu.rs +++ b/vmm/src/cpu.rs @@ -791,38 +791,9 @@ impl CpuManager { #[cfg(target_arch = "x86_64")] if config.features.amx { - const ARCH_GET_XCOMP_GUEST_PERM: usize = 0x1024; - const ARCH_REQ_XCOMP_GUEST_PERM: usize = 0x1025; - const XFEATURE_XTILEDATA: usize = 18; - const XFEATURE_XTILEDATA_MASK: usize = 1 << XFEATURE_XTILEDATA; - - // SAFETY: the syscall is only modifying kernel internal - // data structures that the kernel is itself expected to safeguard. - let amx_tile = unsafe { - libc::syscall( - libc::SYS_arch_prctl, - ARCH_REQ_XCOMP_GUEST_PERM, - XFEATURE_XTILEDATA, - ) - }; - - if amx_tile != 0 { - return Err(Error::AmxEnable(anyhow!("Guest AMX usage not supported"))); - } - let mut mask: usize = 0; - // SAFETY: Syscall with valid parameters. We use a raw mutable pointer to - // the `mask` place in order to ensure that we do not violate Rust's - // aliasing rules. - let result = unsafe { - libc::syscall( - libc::SYS_arch_prctl, - ARCH_GET_XCOMP_GUEST_PERM, - &raw mut mask, - ) - }; - if result != 0 || (mask & XFEATURE_XTILEDATA_MASK) != XFEATURE_XTILEDATA_MASK { - return Err(Error::AmxEnable(anyhow!("Guest AMX usage not supported"))); - } + hypervisor + .enable_amx_state_components() + .map_err(|e| Error::AmxEnable(e.into()))?; } let proximity_domain_per_cpu: BTreeMap = {