[PATCH v2] KVM: arm64: Skip the KVM pmu initialization when hyp is unavailable

Jia He justin.he at arm.com
Sun Mar 23 19:34:50 PDT 2025


When Hyp mode is unavailable (e.g., the kernel boots from EL1), skip the
unnecessary KVM pmu initialization.

Signed-off-by: Jia He <justin.he at arm.com>
---
v2: 
 - Utilize is_hyp_mode_available() for improved accuracy when detecting the
 guest VM case, as it accounts for scenarios where the kernel boots from EL1.

 arch/arm64/kvm/pmu-emul.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c
index 6c5950b9ceac..81b1a84ee1b3 100644
--- a/arch/arm64/kvm/pmu-emul.c
+++ b/arch/arm64/kvm/pmu-emul.c
@@ -779,6 +779,13 @@ void kvm_host_pmu_init(struct arm_pmu *pmu)
 {
 	struct arm_pmu_entry *entry;
 
+	/*
+	 * When Hyp mode is unavailable (e.g., the kernel boots from EL1),
+	 * skip the unnecessary KVM PMU initialization.
+	 */
+	if (!is_hyp_mode_available())
+		return;
+
 	/*
 	 * Check the sanitised PMU version for the system, as KVM does not
 	 * support implementations where PMUv3 exists on a subset of CPUs.
-- 
2.34.1




More information about the linux-arm-kernel mailing list