1
2
3
4
5
6
7
8
9
10
11
12
13#include <linux/kvm_host.h>
14#include <asm/kvm_emulate.h>
15#include <asm/esr.h>
16
17static void inject_abt64(struct kvm_vcpu *vcpu, bool is_iabt, unsigned long addr)
18{
19 unsigned long cpsr = *vcpu_cpsr(vcpu);
20 bool is_aarch32 = vcpu_mode_is_32bit(vcpu);
21 u32 esr = 0;
22
23 vcpu->arch.flags |= (KVM_ARM64_EXCEPT_AA64_EL1 |
24 KVM_ARM64_EXCEPT_AA64_ELx_SYNC |
25 KVM_ARM64_PENDING_EXCEPTION);
26
27 vcpu_write_sys_reg(vcpu, addr, FAR_EL1);
28
29
30
31
32
33 if (kvm_vcpu_trap_il_is32bit(vcpu))
34 esr |= ESR_ELx_IL;
35
36
37
38
39
40 if (is_aarch32 || (cpsr & PSR_MODE_MASK) == PSR_MODE_EL0t)
41 esr |= (ESR_ELx_EC_IABT_LOW << ESR_ELx_EC_SHIFT);
42 else
43 esr |= (ESR_ELx_EC_IABT_CUR << ESR_ELx_EC_SHIFT);
44
45 if (!is_iabt)
46 esr |= ESR_ELx_EC_DABT_LOW << ESR_ELx_EC_SHIFT;
47
48 vcpu_write_sys_reg(vcpu, esr | ESR_ELx_FSC_EXTABT, ESR_EL1);
49}
50
51static void inject_undef64(struct kvm_vcpu *vcpu)
52{
53 u32 esr = (ESR_ELx_EC_UNKNOWN << ESR_ELx_EC_SHIFT);
54
55 vcpu->arch.flags |= (KVM_ARM64_EXCEPT_AA64_EL1 |
56 KVM_ARM64_EXCEPT_AA64_ELx_SYNC |
57 KVM_ARM64_PENDING_EXCEPTION);
58
59
60
61
62
63 if (kvm_vcpu_trap_il_is32bit(vcpu))
64 esr |= ESR_ELx_IL;
65
66 vcpu_write_sys_reg(vcpu, esr, ESR_EL1);
67}
68
69#define DFSR_FSC_EXTABT_LPAE 0x10
70#define DFSR_FSC_EXTABT_nLPAE 0x08
71#define DFSR_LPAE BIT(9)
72#define TTBCR_EAE BIT(31)
73
74static void inject_undef32(struct kvm_vcpu *vcpu)
75{
76 vcpu->arch.flags |= (KVM_ARM64_EXCEPT_AA32_UND |
77 KVM_ARM64_PENDING_EXCEPTION);
78}
79
80
81
82
83
84static void inject_abt32(struct kvm_vcpu *vcpu, bool is_pabt, u32 addr)
85{
86 u64 far;
87 u32 fsr;
88
89
90 if (vcpu_read_sys_reg(vcpu, TCR_EL1) & TTBCR_EAE) {
91 fsr = DFSR_LPAE | DFSR_FSC_EXTABT_LPAE;
92 } else {
93
94 fsr = DFSR_FSC_EXTABT_nLPAE;
95 }
96
97 far = vcpu_read_sys_reg(vcpu, FAR_EL1);
98
99 if (is_pabt) {
100 vcpu->arch.flags |= (KVM_ARM64_EXCEPT_AA32_IABT |
101 KVM_ARM64_PENDING_EXCEPTION);
102 far &= GENMASK(31, 0);
103 far |= (u64)addr << 32;
104 vcpu_write_sys_reg(vcpu, fsr, IFSR32_EL2);
105 } else {
106 vcpu->arch.flags |= (KVM_ARM64_EXCEPT_AA32_DABT |
107 KVM_ARM64_PENDING_EXCEPTION);
108 far &= GENMASK(63, 32);
109 far |= addr;
110 vcpu_write_sys_reg(vcpu, fsr, ESR_EL1);
111 }
112
113 vcpu_write_sys_reg(vcpu, far, FAR_EL1);
114}
115
116
117
118
119
120
121
122
123
124void kvm_inject_dabt(struct kvm_vcpu *vcpu, unsigned long addr)
125{
126 if (vcpu_el1_is_32bit(vcpu))
127 inject_abt32(vcpu, false, addr);
128 else
129 inject_abt64(vcpu, false, addr);
130}
131
132
133
134
135
136
137
138
139
140void kvm_inject_pabt(struct kvm_vcpu *vcpu, unsigned long addr)
141{
142 if (vcpu_el1_is_32bit(vcpu))
143 inject_abt32(vcpu, true, addr);
144 else
145 inject_abt64(vcpu, true, addr);
146}
147
148
149
150
151
152
153
154
155void kvm_inject_undefined(struct kvm_vcpu *vcpu)
156{
157 if (vcpu_el1_is_32bit(vcpu))
158 inject_undef32(vcpu);
159 else
160 inject_undef64(vcpu);
161}
162
163void kvm_set_sei_esr(struct kvm_vcpu *vcpu, u64 esr)
164{
165 vcpu_set_vsesr(vcpu, esr & ESR_ELx_ISS_MASK);
166 *vcpu_hcr(vcpu) |= HCR_VSE;
167}
168
169
170
171
172
173
174
175
176
177
178
179
180
181void kvm_inject_vabt(struct kvm_vcpu *vcpu)
182{
183 kvm_set_sei_esr(vcpu, ESR_ELx_ISV);
184}
185