Skip to content

Commit 27d2b47

Browse files
Yingchao DengMarc Zyngier
authored andcommitted
KVM: arm64: Return early from trace helpers when KVM isn't available
When Linux is booted at EL1, host_data_ptr() resolves to the nVHE hypervisor's copy of host data. When hyp mode isn't available for KVM the nVHE percpu bases remain uninitialized. Consequently, any usage of host_data_ptr() will result in a NULL dereference which has been observed in KVM's trace filtering helpers. Add an early return to the trace filtering helpers if KVM isn't initialized, avoiding the NULL dereference. Take this opportunity to move the TRBE-skipping checks to a common helper. Fixes: 054b883 ("KVM: arm64: Support trace filtering for guests") Signed-off-by: Yingchao Deng <yingchao.deng@oss.qualcomm.com> Reviewed-by: James Clark <james.clark@linaro.org> [maz: repainted the helpers to be readable, and the commit message with Oliver's suggestion] Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent 2ba972b commit 27d2b47

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

arch/arm64/kvm/debug.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -230,29 +230,29 @@ void kvm_debug_handle_oslar(struct kvm_vcpu *vcpu, u64 val)
230230
preempt_enable();
231231
}
232232

233-
void kvm_enable_trbe(void)
233+
static bool skip_trbe_access(bool skip_condition)
234234
{
235-
if (has_vhe() || is_protected_kvm_enabled() ||
236-
WARN_ON_ONCE(preemptible()))
237-
return;
235+
return (WARN_ON_ONCE(preemptible()) || skip_condition ||
236+
is_protected_kvm_enabled() || !is_kvm_arm_initialised());
237+
}
238238

239-
host_data_set_flag(TRBE_ENABLED);
239+
void kvm_enable_trbe(void)
240+
{
241+
if (!skip_trbe_access(has_vhe()))
242+
host_data_set_flag(TRBE_ENABLED);
240243
}
241244
EXPORT_SYMBOL_GPL(kvm_enable_trbe);
242245

243246
void kvm_disable_trbe(void)
244247
{
245-
if (has_vhe() || is_protected_kvm_enabled() ||
246-
WARN_ON_ONCE(preemptible()))
247-
return;
248-
249-
host_data_clear_flag(TRBE_ENABLED);
248+
if (!skip_trbe_access(has_vhe()))
249+
host_data_clear_flag(TRBE_ENABLED);
250250
}
251251
EXPORT_SYMBOL_GPL(kvm_disable_trbe);
252252

253253
void kvm_tracing_set_el1_configuration(u64 trfcr_while_in_guest)
254254
{
255-
if (is_protected_kvm_enabled() || WARN_ON_ONCE(preemptible()))
255+
if (skip_trbe_access(false))
256256
return;
257257

258258
if (has_vhe()) {

0 commit comments

Comments
 (0)