arch/arm64/kvm/hyp/include/hyp/switch.h
Source file repositories/reference/linux-study-clean/arch/arm64/kvm/hyp/include/hyp/switch.h
File Facts
- System
- Linux kernel
- Corpus path
arch/arm64/kvm/hyp/include/hyp/switch.h- Extension
.h- Size
- 27030 bytes
- Lines
- 989
- Domain
- Architecture Layer
- Bucket
- arch/arm64
- Inferred role
- Architecture Layer: implementation source
- Status
- source implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
hyp/adjust_pc.hhyp/fault.hlinux/arm-smccc.hlinux/kvm_host.hlinux/types.hlinux/jump_label.huapi/linux/psci.hkvm/arm_psci.hasm/barrier.hasm/cpufeature.hasm/extable.hasm/kprobes.hasm/kvm_asm.hasm/kvm_emulate.hasm/kvm_hyp.hasm/kvm_mmu.hasm/kvm_nested.hasm/fpsimd.hasm/debug-monitors.hasm/processor.hasm/traps.h
Detected Declarations
struct kvm_exception_table_entryfunction __fpsimd_save_fpexc32function __activate_traps_fpsimd32function __activate_cptr_traps_nvhefunction __activate_cptr_traps_vhefunction __activate_cptr_trapsfunction __deactivate_cptr_traps_nvhefunction __deactivate_cptr_traps_vhefunction __deactivate_cptr_trapsfunction cpu_has_amufunction __activate_traps_hfgxtrfunction __activate_traps_ich_hfgxtrfunction __deactivate_traps_hfgxtrfunction __deactivate_traps_ich_hfgxtrfunction __activate_traps_mpamfunction __deactivate_traps_mpamfunction __activate_traps_commonfunction __deactivate_traps_commonfunction ___activate_trapsfunction ___deactivate_trapsfunction __populate_fault_infofunction kvm_hyp_handle_mopsfunction __hyp_sve_restore_guestfunction __hyp_sve_save_hostfunction fpsimd_lazy_switch_to_guestfunction fpsimd_lazy_switch_to_hostfunction __activate_cptr_trapsfunction kvm_hyp_save_fpsimd_hostfunction kvm_hyp_handle_fpsimdfunction handle_tx2_tvmfunction hyp_timer_get_offsetfunction compute_counter_valuefunction kvm_handle_cntxctfunction handle_ampere1_tcrfunction kvm_hyp_handle_sysregfunction kvm_hyp_handle_cp15_32function kvm_hyp_handle_memory_faultfunction kvm_hyp_handle_dabt_lowfunction kvm_hyp_handle_exitfunction synchronize_vcpu_pstatefunction __fixup_guest_exitfunction __kvm_unexpected_el2_exception
Annotated Snippet
struct kvm_exception_table_entry {
int insn, fixup;
};
extern struct kvm_exception_table_entry __start___kvm_ex_table;
extern struct kvm_exception_table_entry __stop___kvm_ex_table;
/* Save the 32-bit only FPSIMD system register state */
static inline void __fpsimd_save_fpexc32(struct kvm_vcpu *vcpu)
{
if (!vcpu_el1_is_32bit(vcpu))
return;
__vcpu_assign_sys_reg(vcpu, FPEXC32_EL2, read_sysreg(fpexc32_el2));
}
static inline void __activate_traps_fpsimd32(struct kvm_vcpu *vcpu)
{
/*
* We are about to set CPTR_EL2.TFP to trap all floating point
* register accesses to EL2, however, the ARM ARM clearly states that
* traps are only taken to EL2 if the operation would not otherwise
* trap to EL1. Therefore, always make sure that for 32-bit guests,
* we set FPEXC.EN to prevent traps to EL1, when setting the TFP bit.
* If FP/ASIMD is not implemented, FPEXC is UNDEFINED and any access to
* it will cause an exception.
*/
if (vcpu_el1_is_32bit(vcpu) && system_supports_fpsimd())
write_sysreg(1 << 30, fpexc32_el2);
}
static inline void __activate_cptr_traps_nvhe(struct kvm_vcpu *vcpu)
{
u64 val = CPTR_NVHE_EL2_RES1 | CPTR_EL2_TAM | CPTR_EL2_TTA;
/*
* Always trap SME since it's not supported in KVM.
* TSM is RES1 if SME isn't implemented.
*/
val |= CPTR_EL2_TSM;
if (!vcpu_has_sve(vcpu) || !guest_owns_fp_regs())
val |= CPTR_EL2_TZ;
if (!guest_owns_fp_regs())
val |= CPTR_EL2_TFP;
write_sysreg(val, cptr_el2);
}
static inline void __activate_cptr_traps_vhe(struct kvm_vcpu *vcpu)
{
/*
* With VHE (HCR.E2H == 1), accesses to CPACR_EL1 are routed to
* CPTR_EL2. In general, CPACR_EL1 has the same layout as CPTR_EL2,
* except for some missing controls, such as TAM.
* In this case, CPTR_EL2.TAM has the same position with or without
* VHE (HCR.E2H == 1) which allows us to use here the CPTR_EL2.TAM
* shift value for trapping the AMU accesses.
*/
u64 val = CPTR_EL2_TAM | CPACR_EL1_TTA;
u64 cptr;
if (guest_owns_fp_regs()) {
val |= CPACR_EL1_FPEN;
if (vcpu_has_sve(vcpu))
val |= CPACR_EL1_ZEN;
}
if (!vcpu_has_nv(vcpu))
goto write;
/*
* The architecture is a bit crap (what a surprise): an EL2 guest
* writing to CPTR_EL2 via CPACR_EL1 can't set any of TCPAC or TTA,
* as they are RES0 in the guest's view. To work around it, trap the
* sucker using the very same bit it can't set...
*/
if (vcpu_el2_e2h_is_set(vcpu) && is_hyp_ctxt(vcpu))
val |= CPTR_EL2_TCPAC;
/*
* Layer the guest hypervisor's trap configuration on top of our own if
* we're in a nested context.
*/
if (is_hyp_ctxt(vcpu))
goto write;
cptr = vcpu_sanitised_cptr_el2(vcpu);
Annotation
- Immediate include surface: `hyp/adjust_pc.h`, `hyp/fault.h`, `linux/arm-smccc.h`, `linux/kvm_host.h`, `linux/types.h`, `linux/jump_label.h`, `uapi/linux/psci.h`, `kvm/arm_psci.h`.
- Detected declarations: `struct kvm_exception_table_entry`, `function __fpsimd_save_fpexc32`, `function __activate_traps_fpsimd32`, `function __activate_cptr_traps_nvhe`, `function __activate_cptr_traps_vhe`, `function __activate_cptr_traps`, `function __deactivate_cptr_traps_nvhe`, `function __deactivate_cptr_traps_vhe`, `function __deactivate_cptr_traps`, `function cpu_has_amu`.
- Atlas domain: Architecture Layer / arch/arm64.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.