This source file includes following definitions.
- kvm_arch_vcpu_run_map_fp
- kvm_arch_vcpu_load_fp
- kvm_arch_vcpu_ctxsync_fp
- kvm_arch_vcpu_put_fp
1
2
3
4
5
6
7
8 #include <linux/irqflags.h>
9 #include <linux/sched.h>
10 #include <linux/thread_info.h>
11 #include <linux/kvm_host.h>
12 #include <asm/fpsimd.h>
13 #include <asm/kvm_asm.h>
14 #include <asm/kvm_host.h>
15 #include <asm/kvm_mmu.h>
16 #include <asm/sysreg.h>
17
18
19
20
21
22
23
24
25
26
27 int kvm_arch_vcpu_run_map_fp(struct kvm_vcpu *vcpu)
28 {
29 int ret;
30
31 struct thread_info *ti = ¤t->thread_info;
32 struct user_fpsimd_state *fpsimd = ¤t->thread.uw.fpsimd_state;
33
34
35
36
37
38 ret = create_hyp_mappings(ti, ti + 1, PAGE_HYP);
39 if (ret)
40 goto error;
41
42 ret = create_hyp_mappings(fpsimd, fpsimd + 1, PAGE_HYP);
43 if (ret)
44 goto error;
45
46 vcpu->arch.host_thread_info = kern_hyp_va(ti);
47 vcpu->arch.host_fpsimd_state = kern_hyp_va(fpsimd);
48 error:
49 return ret;
50 }
51
52
53
54
55
56
57
58
59
60
61
62 void kvm_arch_vcpu_load_fp(struct kvm_vcpu *vcpu)
63 {
64 BUG_ON(!current->mm);
65
66 vcpu->arch.flags &= ~(KVM_ARM64_FP_ENABLED |
67 KVM_ARM64_HOST_SVE_IN_USE |
68 KVM_ARM64_HOST_SVE_ENABLED);
69 vcpu->arch.flags |= KVM_ARM64_FP_HOST;
70
71 if (test_thread_flag(TIF_SVE))
72 vcpu->arch.flags |= KVM_ARM64_HOST_SVE_IN_USE;
73
74 if (read_sysreg(cpacr_el1) & CPACR_EL1_ZEN_EL0EN)
75 vcpu->arch.flags |= KVM_ARM64_HOST_SVE_ENABLED;
76 }
77
78
79
80
81
82
83
84 void kvm_arch_vcpu_ctxsync_fp(struct kvm_vcpu *vcpu)
85 {
86 WARN_ON_ONCE(!irqs_disabled());
87
88 if (vcpu->arch.flags & KVM_ARM64_FP_ENABLED) {
89 fpsimd_bind_state_to_cpu(&vcpu->arch.ctxt.gp_regs.fp_regs,
90 vcpu->arch.sve_state,
91 vcpu->arch.sve_max_vl);
92
93 clear_thread_flag(TIF_FOREIGN_FPSTATE);
94 update_thread_flag(TIF_SVE, vcpu_has_sve(vcpu));
95 }
96 }
97
98
99
100
101
102
103
104 void kvm_arch_vcpu_put_fp(struct kvm_vcpu *vcpu)
105 {
106 unsigned long flags;
107 bool host_has_sve = system_supports_sve();
108 bool guest_has_sve = vcpu_has_sve(vcpu);
109
110 local_irq_save(flags);
111
112 if (vcpu->arch.flags & KVM_ARM64_FP_ENABLED) {
113 u64 *guest_zcr = &vcpu->arch.ctxt.sys_regs[ZCR_EL1];
114
115 fpsimd_save_and_flush_cpu_state();
116
117 if (guest_has_sve)
118 *guest_zcr = read_sysreg_s(SYS_ZCR_EL12);
119 } else if (host_has_sve) {
120
121
122
123
124
125
126
127 if (vcpu->arch.flags & KVM_ARM64_HOST_SVE_ENABLED)
128 sysreg_clear_set(CPACR_EL1, 0, CPACR_EL1_ZEN_EL0EN);
129 else
130 sysreg_clear_set(CPACR_EL1, CPACR_EL1_ZEN_EL0EN, 0);
131 }
132
133 update_thread_flag(TIF_SVE,
134 vcpu->arch.flags & KVM_ARM64_HOST_SVE_IN_USE);
135
136 local_irq_restore(flags);
137 }