ANDROID: KVM: arm64: Fix missing mutex init for hyp trace readers

Prevent the kernel from crashing when using the hypervisor tracing.
While bringing locking for the nVHE hyp tracing readers, init has been
omitted. This resulted in a stack trace with the following signature
when tracing was enabled:

[   85.897294][ T6772] Call trace:
[   85.900420][ T6772]  __list_add_valid+0x78/0xbc
[   85.904937][ T6772]  __mutex_add_waiter+0x54/0x138
[   85.909711][ T6772]  __mutex_lock+0x344/0xdac
[   85.914054][ T6772]  __mutex_lock_slowpath+0x14/0x24
[   85.919003][ T6772]  mutex_lock+0x40/0xec
[   85.922998][ T6772]  hyp_trace_pipe_read+0x37c/0x418
[   85.927948][ T6772]  vfs_read+0x100/0x2c0
[   85.931942][ T6772]  ksys_read+0x78/0xe8
[   85.935850][ T6772]  __arm64_sys_read+0x1c/0x2c
[   85.940367][ T6772]  invoke_syscall+0x58/0x11c
[   85.944794][ T6772]  el0_svc_common+0xb4/0xf4
[   85.949137][ T6772]  do_el0_svc+0x2c/0xb0
[   85.953132][ T6772]  el0_svc+0x2c/0x90
[   85.956865][ T6772]  el0t_64_sync_handler+0x68/0xb4
[   85.961728][ T6772]  el0t_64_sync+0x1a4/0x1a8
[   85.966072][ T6772] Code: d4210000 d0007080 91271c00 9423d9aa

Bug: 229972309
Bug: 380818540
Test: enable hypervisor tracing per-cpu and fetch hyp events
Fixes: 34305ad4b1 ("ANDROID: KVM: arm64: Add host support for the nVHE hyp tracing")
Change-Id: I5269e030f0744bdff8ca8c71260e41c74b20f21b
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
Signed-off-by: Sebastian Ene <sebastianene@google.com>
This commit is contained in:
Vincent Donnefort
2023-06-22 13:54:38 +01:00
committed by Sebastian Ene
parent affd0c0263
commit 0f332d7edc

View File

@@ -979,6 +979,9 @@ int init_hyp_tracefs(void)
if (!is_protected_kvm_enabled()) if (!is_protected_kvm_enabled())
return 0; return 0;
for_each_possible_cpu(cpu)
mutex_init(&per_cpu(hyp_trace_reader_lock, cpu));
root_dir = tracefs_create_dir(TRACEFS_DIR, NULL); root_dir = tracefs_create_dir(TRACEFS_DIR, NULL);
if (!root_dir) { if (!root_dir) {
pr_err("Failed to create tracefs "TRACEFS_DIR"/\n"); pr_err("Failed to create tracefs "TRACEFS_DIR"/\n");