Skip to content

Commit 1dbce9b

Browse files
AndrewScullgregkh
authored andcommitted
KVM: arm64: Fix nVHE hyp panic host context restore
Commit c4b000c upstream. When panicking from the nVHE hyp and restoring the host context, x29 is expected to hold a pointer to the host context. This wasn't being done so fix it to make sure there's a valid pointer the host context being used. Rather than passing a boolean indicating whether or not the host context should be restored, instead pass the pointer to the host context. NULL is passed to indicate that no context should be restored. Fixes: a2e102e ("KVM: arm64: nVHE: Handle hyp panics") Cc: stable@vger.kernel.org # 5.10.y only Signed-off-by: Andrew Scull <ascull@google.com> Signed-off-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20210219122406.1337626-1-ascull@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent f67e524 commit 1dbce9b

3 files changed

Lines changed: 13 additions & 13 deletions

File tree

‎arch/arm64/include/asm/kvm_hyp.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ u64 __guest_enter(struct kvm_vcpu *vcpu);
9999

100100
void __noreturn hyp_panic(void);
101101
#ifdef __KVM_NVHE_HYPERVISOR__
102-
void __noreturn __hyp_do_panic(bool restore_host, u64 spsr, u64 elr, u64 par);
102+
void __noreturn __hyp_do_panic(struct kvm_cpu_context *host_ctxt, u64 spsr,
103+
u64 elr, u64 par);
103104
#endif
104105

105106
#endif /* __ARM64_KVM_HYP_H__ */

‎arch/arm64/kvm/hyp/nvhe/host.S‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,15 @@ __host_enter_without_restoring:
6464
SYM_FUNC_END(__host_exit)
6565

6666
/*
67-
* void __noreturn __hyp_do_panic(bool restore_host, u64 spsr, u64 elr, u64 par);
67+
* void __noreturn __hyp_do_panic(struct kvm_cpu_context *host_ctxt, u64 spsr,
68+
* u64 elr, u64 par);
6869
*/
6970
SYM_FUNC_START(__hyp_do_panic)
70-
/* Load the format arguments into x1-7 */
71+
mov x29, x0
72+
73+
/* Load the format string into x0 and arguments into x1-7 */
74+
ldr x0, =__hyp_panic_string
75+
7176
mov x6, x3
7277
get_vcpu_ptr x7, x3
7378

@@ -82,13 +87,8 @@ SYM_FUNC_START(__hyp_do_panic)
8287
ldr lr, =panic
8388
msr elr_el2, lr
8489

85-
/*
86-
* Set the panic format string and enter the host, conditionally
87-
* restoring the host context.
88-
*/
89-
cmp x0, xzr
90-
ldr x0, =__hyp_panic_string
91-
b.eq __host_enter_without_restoring
90+
/* Enter the host, conditionally restoring the host context. */
91+
cbz x29, __host_enter_without_restoring
9292
b __host_enter_for_panic
9393
SYM_FUNC_END(__hyp_do_panic)
9494

@@ -144,7 +144,7 @@ SYM_FUNC_END(__hyp_do_panic)
144144

145145
.macro invalid_host_el1_vect
146146
.align 7
147-
mov x0, xzr /* restore_host = false */
147+
mov x0, xzr /* host_ctxt = NULL */
148148
mrs x1, spsr_el2
149149
mrs x2, elr_el2
150150
mrs x3, par_el1

‎arch/arm64/kvm/hyp/nvhe/switch.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ void __noreturn hyp_panic(void)
260260
u64 spsr = read_sysreg_el2(SYS_SPSR);
261261
u64 elr = read_sysreg_el2(SYS_ELR);
262262
u64 par = read_sysreg_par();
263-
bool restore_host = true;
264263
struct kvm_cpu_context *host_ctxt;
265264
struct kvm_vcpu *vcpu;
266265

@@ -274,7 +273,7 @@ void __noreturn hyp_panic(void)
274273
__sysreg_restore_state_nvhe(host_ctxt);
275274
}
276275

277-
__hyp_do_panic(restore_host, spsr, elr, par);
276+
__hyp_do_panic(host_ctxt, spsr, elr, par);
278277
unreachable();
279278
}
280279

0 commit comments

Comments
 (0)