Skip to content

Commit 6834403

Browse files
vdonnefortMarc Zyngier
authored andcommitted
KVM: arm64: Fix nVHE stacktrace VA bits mask
The hypervisor VA space size depends on both the ID map's (IDMAP_VA_BITS) and the kernel stage-1 (VA_BITS). However, the hypervisor stacktrace decoding is solely relying on VA_BITS. This is especially an issue when VA_BITS < IDMAP_VA_BITS (i.e. VA_BITS is 39-bit): the hypervisor may have addresses bigger than the stacktrace is masking. Align this mask with hyp_va_bits. Signed-off-by: Vincent Donnefort <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Marc Zyngier <[email protected]>
1 parent e8440c1 commit 6834403

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

arch/arm64/include/asm/kvm_mmu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ static __always_inline unsigned long __kern_hyp_va(unsigned long v)
139139

140140
#define kern_hyp_va(v) ((typeof(v))(__kern_hyp_va((unsigned long)(v))))
141141

142+
extern u32 __hyp_va_bits;
143+
142144
/*
143145
* We currently support using a VM-specified IPA size. For backward
144146
* compatibility, the default IPA size is fixed to 40bits.

arch/arm64/kvm/mmu.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ static unsigned long __ro_after_init hyp_idmap_start;
2929
static unsigned long __ro_after_init hyp_idmap_end;
3030
static phys_addr_t __ro_after_init hyp_idmap_vector;
3131

32+
u32 __ro_after_init __hyp_va_bits;
33+
3234
static unsigned long __ro_after_init io_map_base;
3335

3436
static phys_addr_t __stage2_range_addr_end(phys_addr_t addr, phys_addr_t end,
@@ -2056,6 +2058,7 @@ int __init kvm_mmu_init(u32 *hyp_va_bits)
20562058
goto out_destroy_pgtable;
20572059

20582060
io_map_base = hyp_idmap_start;
2061+
__hyp_va_bits = *hyp_va_bits;
20592062
return 0;
20602063

20612064
out_destroy_pgtable:

arch/arm64/kvm/stacktrace.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/kvm.h>
2020
#include <linux/kvm_host.h>
2121

22+
#include <asm/kvm_mmu.h>
2223
#include <asm/stacktrace/nvhe.h>
2324

2425
static struct stack_info stackinfo_get_overflow(void)
@@ -145,7 +146,7 @@ static void unwind(struct unwind_state *state,
145146
*/
146147
static bool kvm_nvhe_dump_backtrace_entry(void *arg, unsigned long where)
147148
{
148-
unsigned long va_mask = GENMASK_ULL(vabits_actual - 1, 0);
149+
unsigned long va_mask = GENMASK_ULL(__hyp_va_bits - 1, 0);
149150
unsigned long hyp_offset = (unsigned long)arg;
150151

151152
/* Mask tags and convert to kern addr */

0 commit comments

Comments
 (0)