From 11620ab958c21a5f2a8c55939cc8ad0d3fcbe30a Mon Sep 17 00:00:00 2001 From: Lokesh Vutla Date: Mon, 20 Jan 2025 10:29:34 +0000 Subject: [PATCH] FROMGIT: KVM: arm64: Flush hyp bss section after initialization of variables in bss To determine CPU features during initialization, the nVHE hypervisor utilizes sanitized values of the host's CPU features registers. These values, stored in u64 idaa64*_el1_sys_val variables are updated by the kvm_hyp_init_symbols() function at EL1. To ensure EL2 visibility with the MMU off, the data cache needs to be flushed after these updates. However, individually flushing each variable using kvm_flush_dcache_to_poc() is inefficient. These cpu feature variables would be part of the bss section of the hypervisor. Hence, flush the entire bss section of hypervisor once the initialization is complete. Fixes: 6c30bfb18d0b ("KVM: arm64: Add handlers for protected VM System Registers") Bug: b/386889513 Bug: 357781595 Change-Id: Ib988dbc23ea401e0af1cd6e5445151af868c844c Link: https://lore.kernel.org/all/20250121044016.2219256-1-lokeshvutla@google.com/ (cherry picked from commit 9bcbb6104a344d3526e185ee1e7b985509914e90 https://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git/ fixes) Suggested-by: Fuad Tabba Signed-off-by: Lokesh Vutla Signed-off-by: Fuad Tabba --- arch/arm64/kvm/arm.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index e21e2bcdd99c..915100a97191 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -2084,6 +2084,12 @@ static void kvm_hyp_init_symbols(void) kvm_nvhe_sym(kvm_arm_vmid_bits) = kvm_arm_vmid_bits; kvm_nvhe_sym(smccc_trng_available) = smccc_trng_available; kvm_nvhe_sym(kvm_host_sve_max_vl) = kvm_host_sve_max_vl; + + /* + * Flush entire BSS since part of its data is read while the MMU is off. + */ + kvm_flush_dcache_to_poc(kvm_ksym_ref(__hyp_bss_start), + kvm_ksym_ref(__hyp_bss_end) - kvm_ksym_ref(__hyp_bss_start)); } int kvm_hyp_init_events(void);