Skip to content

Commit 6c16522

Browse files
willdeaconMarc Zyngier
authored andcommitted
KVM: arm64: Initialise hypervisor copies of host symbols unconditionally
The nVHE object at EL2 maintains its own copies of some host variables so that, when pKVM is enabled, the host cannot directly modify the hypervisor state. When running in normal nVHE mode, however, these variables are still mirrored at EL2 but are not initialised. Initialise the hypervisor symbols from the host copies regardless of pKVM, ensuring that any reference to this data at EL2 with normal nVHE will return a sensibly initialised value. Reviewed-by: Philippe Mathieu-Daudé <[email protected]> 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 aa6948f commit 6c16522

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

arch/arm64/kvm/arm.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,11 +1884,8 @@ static int do_pkvm_init(u32 hyp_va_bits)
18841884
return ret;
18851885
}
18861886

1887-
static int kvm_hyp_init_protection(u32 hyp_va_bits)
1887+
static void kvm_hyp_init_symbols(void)
18881888
{
1889-
void *addr = phys_to_virt(hyp_mem_base);
1890-
int ret;
1891-
18921889
kvm_nvhe_sym(id_aa64pfr0_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64PFR0_EL1);
18931890
kvm_nvhe_sym(id_aa64pfr1_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64PFR1_EL1);
18941891
kvm_nvhe_sym(id_aa64isar0_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64ISAR0_EL1);
@@ -1897,6 +1894,12 @@ static int kvm_hyp_init_protection(u32 hyp_va_bits)
18971894
kvm_nvhe_sym(id_aa64mmfr0_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1);
18981895
kvm_nvhe_sym(id_aa64mmfr1_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64MMFR1_EL1);
18991896
kvm_nvhe_sym(id_aa64mmfr2_el1_sys_val) = read_sanitised_ftr_reg(SYS_ID_AA64MMFR2_EL1);
1897+
}
1898+
1899+
static int kvm_hyp_init_protection(u32 hyp_va_bits)
1900+
{
1901+
void *addr = phys_to_virt(hyp_mem_base);
1902+
int ret;
19001903

19011904
ret = create_hyp_mappings(addr, addr + hyp_mem_size, PAGE_HYP);
19021905
if (ret)
@@ -2071,16 +2074,16 @@ static int init_hyp_mode(void)
20712074
cpu_prepare_hyp_mode(cpu);
20722075
}
20732076

2077+
kvm_hyp_init_symbols();
2078+
20742079
if (is_protected_kvm_enabled()) {
20752080
init_cpu_logical_map();
20762081

20772082
if (!init_psci_relay()) {
20782083
err = -ENODEV;
20792084
goto out_err;
20802085
}
2081-
}
20822086

2083-
if (is_protected_kvm_enabled()) {
20842087
err = kvm_hyp_init_protection(hyp_va_bits);
20852088
if (err) {
20862089
kvm_err("Failed to init hyp memory protection\n");

0 commit comments

Comments
 (0)