Skip to content

Commit 73f38ef

Browse files
willdeaconMarc Zyngier
authored andcommitted
KVM: arm64: Maintain a copy of 'kvm_arm_vmid_bits' at EL2
Sharing 'kvm_arm_vmid_bits' between EL1 and EL2 allows the host to modify the variable arbitrarily, potentially leading to all sorts of shenanians as this is used to configure the VTTBR register for the guest stage-2. In preparation for unmapping host sections entirely from EL2, maintain a copy of 'kvm_arm_vmid_bits' in the pKVM hypervisor and initialise it from the host value while it is still trusted. Tested-by: Vincent Donnefort <[email protected]> Signed-off-by: Will Deacon <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent fe41a7f commit 73f38ef

File tree

4 files changed

+6
-3
lines changed

4 files changed

+6
-3
lines changed

arch/arm64/include/asm/kvm_hyp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,6 @@ extern u64 kvm_nvhe_sym(id_aa64mmfr1_el1_sys_val);
124124
extern u64 kvm_nvhe_sym(id_aa64mmfr2_el1_sys_val);
125125

126126
extern unsigned long kvm_nvhe_sym(__icache_flags);
127+
extern unsigned int kvm_nvhe_sym(kvm_arm_vmid_bits);
128+
127129
#endif /* __ARM64_KVM_HYP_H__ */

arch/arm64/kernel/image-vars.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ KVM_NVHE_ALIAS(nvhe_hyp_panic_handler);
7171
/* Vectors installed by hyp-init on reset HVC. */
7272
KVM_NVHE_ALIAS(__hyp_stub_vectors);
7373

74-
/* VMID bits set by the KVM VMID allocator */
75-
KVM_NVHE_ALIAS(kvm_arm_vmid_bits);
76-
7774
/* Static keys which are set if a vGIC trap should be handled in hyp. */
7875
KVM_NVHE_ALIAS(vgic_v2_cpuif_trap);
7976
KVM_NVHE_ALIAS(vgic_v3_cpuif_trap);

arch/arm64/kvm/arm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,6 +1893,7 @@ static void kvm_hyp_init_symbols(void)
18931893
kvm_nvhe_sym(id_aa64mmfr1_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64MMFR1_EL1);
18941894
kvm_nvhe_sym(id_aa64mmfr2_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64MMFR2_EL1);
18951895
kvm_nvhe_sym(__icache_flags) = __icache_flags;
1896+
kvm_nvhe_sym(kvm_arm_vmid_bits) = kvm_arm_vmid_bits;
18961897
}
18971898

18981899
static int kvm_hyp_init_protection(u32 hyp_va_bits)

arch/arm64/kvm/hyp/nvhe/pkvm.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
/* Used by icache_is_vpipt(). */
1616
unsigned long __icache_flags;
1717

18+
/* Used by kvm_get_vttbr(). */
19+
unsigned int kvm_arm_vmid_bits;
20+
1821
/*
1922
* Set trap register values based on features in ID_AA64PFR0.
2023
*/

0 commit comments

Comments
 (0)