if (cpus_have_final_cap(ARM64_WORKAROUND_SPECULATIVE_AT)) { struct kvm_cpu_context *ctxt = &vcpu->arch.ctxt;
isb(); /* * At this stage, and thanks to the above isb(), S2 is * configured and enabled. We can now restore the guest's S1 * configuration: SCTLR, and only then TCR.
*/
write_sysreg_el1(ctxt_sys_reg(ctxt, SCTLR_EL1), SYS_SCTLR);
isb();
write_sysreg_el1(ctxt_sys_reg(ctxt, TCR_EL1), SYS_TCR);
}
}
if (cpus_have_final_cap(ARM64_WORKAROUND_SPECULATIVE_AT)) {
u64 val;
/* * Set the TCR and SCTLR registers in the exact opposite * sequence as __activate_traps (first prevent walks, * then force the MMU on). A generous sprinkling of isb() * ensure that things happen in this exact order.
*/
val = read_sysreg_el1(SYS_TCR);
write_sysreg_el1(val | TCR_EPD1_MASK | TCR_EPD0_MASK, SYS_TCR);
isb();
val = read_sysreg_el1(SYS_SCTLR);
write_sysreg_el1(val | SCTLR_ELx_M, SYS_SCTLR);
isb();
}
/* Save VGICv3 state on non-VHE systems */ staticvoid __hyp_vgic_save_state(struct kvm_vcpu *vcpu)
{ if (static_branch_unlikely(&kvm_vgic_global_state.gicv3_cpuif)) {
__vgic_v3_save_state(&vcpu->arch.vgic_cpu.vgic_v3);
__vgic_v3_deactivate_traps(&vcpu->arch.vgic_cpu.vgic_v3);
}
}
/* Restore VGICv3 state on non-VHE systems */ staticvoid __hyp_vgic_restore_state(struct kvm_vcpu *vcpu)
{ if (static_branch_unlikely(&kvm_vgic_global_state.gicv3_cpuif)) {
__vgic_v3_activate_traps(&vcpu->arch.vgic_cpu.vgic_v3);
__vgic_v3_restore_state(&vcpu->arch.vgic_cpu.vgic_v3);
}
}
if (pmu->events_guest)
write_sysreg(pmu->events_guest, pmcntenclr_el0);
if (pmu->events_host)
write_sysreg(pmu->events_host, pmcntenset_el0);
} #else #define __pmu_switch_to_guest(v) ({ false; }) #define __pmu_switch_to_host(v) do {} while (0) #endif
/* * Handler for protected VM MSR, MRS or System instruction execution in AArch64. * * Returns true if the hypervisor has handled the exit, and control should go * back to the guest, or false if it hasn't.
*/ staticbool kvm_handle_pvm_sys64(struct kvm_vcpu *vcpu, u64 *exit_code)
{ /* * Make sure we handle the exit for workarounds before the pKVM * handling, as the latter could decide to UNDEF.
*/ return (kvm_hyp_handle_sysreg(vcpu, exit_code) ||
kvm_handle_pvm_sysreg(vcpu, exit_code));
}
/* * Some guests (e.g., protected VMs) are not be allowed to run in * AArch32. The ARMv8 architecture does not give the hypervisor a * mechanism to prevent a guest from dropping to AArch32 EL0 if * implemented by the CPU. If the hypervisor spots a guest in such a * state ensure it is handled, and don't trust the host to spot or fix * it. The check below is based on the one in * kvm_arch_vcpu_ioctl_run().
*/ if (unlikely(vcpu_is_protected(vcpu) && vcpu_mode_is_32bit(vcpu))) { /* * As we have caught the guest red-handed, decide that it isn't * fit for purpose anymore by making the vcpu invalid. The VMM * can try and fix it by re-initializing the vcpu with * KVM_ARM_VCPU_INIT, however, this is likely not possible for * protected VMs.
*/
vcpu_clear_flag(vcpu, VCPU_INITIALIZED);
*exit_code &= BIT(ARM_EXIT_WITH_SERROR_BIT);
*exit_code |= ARM_EXCEPTION_IL;
}
/* Switch to the guest for legacy non-VHE systems */ int __kvm_vcpu_run(struct kvm_vcpu *vcpu)
{ struct kvm_cpu_context *host_ctxt; struct kvm_cpu_context *guest_ctxt; struct kvm_s2_mmu *mmu; bool pmu_switch_needed;
u64 exit_code;
/* * Having IRQs masked via PMR when entering the guest means the GIC * will not signal the CPU of interrupts of lower priority, and the * only way to get out will be via guest exceptions. * Naturally, we want to avoid this.
*/ if (system_uses_irq_prio_masking()) {
gic_write_pmr(GIC_PRIO_IRQON | GIC_PRIO_PSR_I_SET);
pmr_sync();
}
__sysreg_save_state_nvhe(host_ctxt); /* * We must flush and disable the SPE buffer for nVHE, as * the translation regime(EL1&0) is going to be loaded with * that of the guest. And we must do this before we change the * translation regime to EL2 (via MDCR_EL2_E2PB == 0) and * before we load guest Stage1.
*/
__debug_save_host_buffers_nvhe(vcpu);
/* * We're about to restore some new MMU state. Make sure * ongoing page-table walks that have started before we * trapped to EL2 have completed. This also synchronises the * above disabling of BRBE, SPE and TRBE. * * See DDI0487I.a D8.1.5 "Out-of-context translation regimes", * rule R_LFHQG and subsequent information statements.
*/
dsb(nsh);
__kvm_adjust_pc(vcpu);
/* * We must restore the 32-bit state before the sysregs, thanks * to erratum #852523 (Cortex-A57) or #853709 (Cortex-A72). * * Also, and in order to be able to deal with erratum #1319537 (A57) * and #1319367 (A72), we must ensure that all VM-related sysreg are * restored before we enable S2 translation.
*/
__sysreg32_restore_state(vcpu);
__sysreg_restore_state_nvhe(guest_ctxt);
/* * Same thing as before the guest run: we're about to switch * the MMU context, so let's make sure we don't have any * ongoing EL1&0 translations.
*/
dsb(nsh);
__deactivate_traps(vcpu);
__load_host_stage2();
__sysreg_restore_state_nvhe(host_ctxt);
if (guest_owns_fp_regs())
__fpsimd_save_fpexc32(vcpu);
__debug_switch_to_host(vcpu); /* * This must come after restoring the host sysregs, since a non-VHE * system may enable SPE here and make use of the TTBRs.
*/
__debug_restore_host_buffers_nvhe(vcpu);
if (pmu_switch_needed)
__pmu_switch_to_host(vcpu);
/* Returning to host will clear PSR.I, remask PMR if needed */ if (system_uses_irq_prio_masking())
gic_write_pmr(GIC_PRIO_IRQOFF);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.