[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250322035115.118048-1-justin.he@arm.com>
Date: Sat, 22 Mar 2025 03:51:15 +0000
From: Jia He <justin.he@....com>
To: Marc Zyngier <maz@...nel.org>,
Oliver Upton <oliver.upton@...ux.dev>,
linux-arm-kernel@...ts.infradead.org,
kvmarm@...ts.linux.dev
Cc: Joey Gouly <joey.gouly@....com>,
Suzuki K Poulose <suzuki.poulose@....com>,
Zenghui Yu <yuzenghui@...wei.com>,
Catalin Marinas <catalin.marinas@....com>,
Will Deacon <will@...nel.org>,
linux-kernel@...r.kernel.org,
Jia He <justin.he@....com>
Subject: [PATCH] KVM: arm64: pmu: Avoid initializing KVM PMU when KVM is not initialised
Currently, `kvm_host_pmu_init()` does not check if KVM has been
successfully initialized before proceeding. This can lead to unintended
behavior if the function is called in an environment where KVM is not
available, e.g., kernel is landed in EL1.
Signed-off-by: Jia He <justin.he@....com>
---
arch/arm64/kvm/pmu.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/arch/arm64/kvm/pmu.c b/arch/arm64/kvm/pmu.c
index 7169c1a24dd6..e39c48d12b81 100644
--- a/arch/arm64/kvm/pmu.c
+++ b/arch/arm64/kvm/pmu.c
@@ -227,6 +227,13 @@ void kvm_host_pmu_init(struct arm_pmu *pmu)
{
struct arm_pmu_entry *entry;
+ /*
+ * Prevent unintended behavior where KVM is not available or not
+ * successfully initialised, e.g., kernel is landed in EL1.
+ */
+ if (!is_kvm_arm_initialised())
+ 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
Powered by blists - more mailing lists