0001
0002
0003
0004
0005
0006
0007 #include <hyp/sysreg-sr.h>
0008
0009 #include <linux/compiler.h>
0010 #include <linux/kvm_host.h>
0011
0012 #include <asm/kprobes.h>
0013 #include <asm/kvm_asm.h>
0014 #include <asm/kvm_emulate.h>
0015 #include <asm/kvm_hyp.h>
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027 void sysreg_save_host_state_vhe(struct kvm_cpu_context *ctxt)
0028 {
0029 __sysreg_save_common_state(ctxt);
0030 }
0031 NOKPROBE_SYMBOL(sysreg_save_host_state_vhe);
0032
0033 void sysreg_save_guest_state_vhe(struct kvm_cpu_context *ctxt)
0034 {
0035 __sysreg_save_common_state(ctxt);
0036 __sysreg_save_el2_return_state(ctxt);
0037 }
0038 NOKPROBE_SYMBOL(sysreg_save_guest_state_vhe);
0039
0040 void sysreg_restore_host_state_vhe(struct kvm_cpu_context *ctxt)
0041 {
0042 __sysreg_restore_common_state(ctxt);
0043 }
0044 NOKPROBE_SYMBOL(sysreg_restore_host_state_vhe);
0045
0046 void sysreg_restore_guest_state_vhe(struct kvm_cpu_context *ctxt)
0047 {
0048 __sysreg_restore_common_state(ctxt);
0049 __sysreg_restore_el2_return_state(ctxt);
0050 }
0051 NOKPROBE_SYMBOL(sysreg_restore_guest_state_vhe);
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064 void kvm_vcpu_load_sysregs_vhe(struct kvm_vcpu *vcpu)
0065 {
0066 struct kvm_cpu_context *guest_ctxt = &vcpu->arch.ctxt;
0067 struct kvm_cpu_context *host_ctxt;
0068
0069 host_ctxt = &this_cpu_ptr(&kvm_host_data)->host_ctxt;
0070 __sysreg_save_user_state(host_ctxt);
0071
0072
0073
0074
0075
0076
0077
0078 __sysreg32_restore_state(vcpu);
0079 __sysreg_restore_user_state(guest_ctxt);
0080 __sysreg_restore_el1_state(guest_ctxt);
0081
0082 vcpu_set_flag(vcpu, SYSREGS_ON_CPU);
0083
0084 activate_traps_vhe_load(vcpu);
0085 }
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098 void kvm_vcpu_put_sysregs_vhe(struct kvm_vcpu *vcpu)
0099 {
0100 struct kvm_cpu_context *guest_ctxt = &vcpu->arch.ctxt;
0101 struct kvm_cpu_context *host_ctxt;
0102
0103 host_ctxt = &this_cpu_ptr(&kvm_host_data)->host_ctxt;
0104 deactivate_traps_vhe_put(vcpu);
0105
0106 __sysreg_save_el1_state(guest_ctxt);
0107 __sysreg_save_user_state(guest_ctxt);
0108 __sysreg32_save_state(vcpu);
0109
0110
0111 __sysreg_restore_user_state(host_ctxt);
0112
0113 vcpu_clear_flag(vcpu, SYSREGS_ON_CPU);
0114 }