Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

KVM: arm64: Add PKVM_DISABLE_STAGE2_ON_PANIC

On NVHE_EL2_DEBUG, when using pKVM, the host stage-2 is relaxed to grant
the kernel access to the stacktrace, hypervisor bug table and text to
symbolize addresses. This is unsafe for production. In preparation for
adding more debug options to NVHE_EL2_DEBUG, decouple the stage-2
relaxation into a separate option.

While at it, rename PROTECTED_NVHE_STACKTRACE into PKVM_STACKTRACE,
following the same naming scheme as PKVM_DISABLE_STAGE2_ON_PANIC.

Reviewed-by: Kalesh Singh <kaleshsingh@google.com>
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
Link: https://patch.msgid.link/20260309162516.2623589-20-vdonnefort@google.com
Signed-off-by: Marc Zyngier <maz@kernel.org>

authored by

Vincent Donnefort and committed by
Marc Zyngier
9019e82c a717943d

+48 -32
+39 -23
arch/arm64/kvm/Kconfig
··· 42 42 43 43 If unsure, say N. 44 44 45 - config NVHE_EL2_DEBUG 46 - bool "Debug mode for non-VHE EL2 object" 47 - depends on KVM 48 - help 49 - Say Y here to enable the debug mode for the non-VHE KVM EL2 object. 50 - Failure reports will BUG() in the hypervisor. This is intended for 51 - local EL2 hypervisor development. 52 - 53 - If unsure, say N. 54 - 55 - config PROTECTED_NVHE_STACKTRACE 56 - bool "Protected KVM hypervisor stacktraces" 57 - depends on NVHE_EL2_DEBUG 58 - default n 59 - help 60 - Say Y here to enable pKVM hypervisor stacktraces on hyp_panic() 61 - 62 - If using protected nVHE mode, but cannot afford the associated 63 - memory cost (less than 0.75 page per CPU) of pKVM stacktraces, 64 - say N. 65 - 66 - If unsure, or not using protected nVHE (pKVM), say N. 45 + if KVM 67 46 68 47 config PTDUMP_STAGE2_DEBUGFS 69 48 bool "Present the stage-2 pagetables to debugfs" 70 - depends on KVM 71 49 depends on DEBUG_KERNEL 72 50 depends on DEBUG_FS 73 51 depends on ARCH_HAS_PTDUMP ··· 60 82 61 83 If in doubt, say N. 62 84 85 + config NVHE_EL2_DEBUG 86 + bool "Debug mode for non-VHE EL2 object" 87 + default n 88 + help 89 + Say Y here to enable the debug mode for the non-VHE KVM EL2 object. 90 + Failure reports will BUG() in the hypervisor. This is intended for 91 + local EL2 hypervisor development. 92 + 93 + If unsure, say N. 94 + 95 + if NVHE_EL2_DEBUG 96 + 97 + config PKVM_DISABLE_STAGE2_ON_PANIC 98 + bool "Disable the host stage-2 on panic" 99 + default n 100 + help 101 + Relax the host stage-2 on hypervisor panic to allow the kernel to 102 + unwind and symbolize the hypervisor stacktrace. This however tampers 103 + the system security. This is intended for local EL2 hypervisor 104 + development. 105 + 106 + If unsure, say N. 107 + 108 + config PKVM_STACKTRACE 109 + bool "Protected KVM hypervisor stacktraces" 110 + depends on PKVM_DISABLE_STAGE2_ON_PANIC 111 + default y 112 + help 113 + Say Y here to enable pKVM hypervisor stacktraces on hyp_panic() 114 + 115 + If using protected nVHE mode, but cannot afford the associated 116 + memory cost (less than 0.75 page per CPU) of pKVM stacktraces, 117 + say N. 118 + 119 + If unsure, or not using protected nVHE (pKVM), say N. 120 + 121 + endif # NVHE_EL2_DEBUG 122 + endif # KVM 63 123 endif # VIRTUALIZATION
+1 -1
arch/arm64/kvm/handle_exit.c
··· 539 539 540 540 /* All hyp bugs, including warnings, are treated as fatal. */ 541 541 if (!is_protected_kvm_enabled() || 542 - IS_ENABLED(CONFIG_NVHE_EL2_DEBUG)) { 542 + IS_ENABLED(CONFIG_PKVM_DISABLE_STAGE2_ON_PANIC)) { 543 543 struct bug_entry *bug = find_bug(elr_in_kimg); 544 544 545 545 if (bug)
+1 -1
arch/arm64/kvm/hyp/nvhe/host.S
··· 120 120 121 121 mov x29, x0 122 122 123 - #ifdef CONFIG_NVHE_EL2_DEBUG 123 + #ifdef PKVM_DISABLE_STAGE2_ON_PANIC 124 124 /* Ensure host stage-2 is disabled */ 125 125 mrs x0, hcr_el2 126 126 bic x0, x0, #HCR_VM
+3 -3
arch/arm64/kvm/hyp/nvhe/stacktrace.c
··· 34 34 stacktrace_info->pc = pc; 35 35 } 36 36 37 - #ifdef CONFIG_PROTECTED_NVHE_STACKTRACE 37 + #ifdef CONFIG_PKVM_STACKTRACE 38 38 #include <asm/stacktrace/nvhe.h> 39 39 40 40 DEFINE_PER_CPU(unsigned long [NVHE_STACKTRACE_SIZE/sizeof(long)], pkvm_stacktrace); ··· 134 134 135 135 unwind(&state, pkvm_save_backtrace_entry, &idx); 136 136 } 137 - #else /* !CONFIG_PROTECTED_NVHE_STACKTRACE */ 137 + #else /* !CONFIG_PKVM_STACKTRACE */ 138 138 static void pkvm_save_backtrace(unsigned long fp, unsigned long pc) 139 139 { 140 140 } 141 - #endif /* CONFIG_PROTECTED_NVHE_STACKTRACE */ 141 + #endif /* CONFIG_PKVM_STACKTRACE */ 142 142 143 143 /* 144 144 * kvm_nvhe_prepare_backtrace - prepare to dump the nVHE backtrace
+4 -4
arch/arm64/kvm/stacktrace.c
··· 197 197 kvm_nvhe_dump_backtrace_end(); 198 198 } 199 199 200 - #ifdef CONFIG_PROTECTED_NVHE_STACKTRACE 200 + #ifdef CONFIG_PKVM_STACKTRACE 201 201 DECLARE_KVM_NVHE_PER_CPU(unsigned long [NVHE_STACKTRACE_SIZE/sizeof(long)], 202 202 pkvm_stacktrace); 203 203 ··· 225 225 kvm_nvhe_dump_backtrace_entry((void *)hyp_offset, stacktrace[i]); 226 226 kvm_nvhe_dump_backtrace_end(); 227 227 } 228 - #else /* !CONFIG_PROTECTED_NVHE_STACKTRACE */ 228 + #else /* !CONFIG_PKVM_STACKTRACE */ 229 229 static void pkvm_dump_backtrace(unsigned long hyp_offset) 230 230 { 231 - kvm_err("Cannot dump pKVM nVHE stacktrace: !CONFIG_PROTECTED_NVHE_STACKTRACE\n"); 231 + kvm_err("Cannot dump pKVM nVHE stacktrace: !CONFIG_PKVM_STACKTRACE\n"); 232 232 } 233 - #endif /* CONFIG_PROTECTED_NVHE_STACKTRACE */ 233 + #endif /* CONFIG_PKVM_STACKTRACE */ 234 234 235 235 /* 236 236 * kvm_nvhe_dump_backtrace - Dump KVM nVHE hypervisor backtrace.