KVM
Classes | Macros | Typedefs | Functions | Variables
switch.h File Reference
#include <hyp/adjust_pc.h>
#include <hyp/fault.h>
#include <linux/arm-smccc.h>
#include <linux/kvm_host.h>
#include <linux/types.h>
#include <linux/jump_label.h>
#include <uapi/linux/psci.h>
#include <kvm/arm_psci.h>
#include <asm/barrier.h>
#include <asm/cpufeature.h>
#include <asm/extable.h>
#include <asm/kprobes.h>
#include <asm/kvm_asm.h>
#include <asm/kvm_emulate.h>
#include <asm/kvm_hyp.h>
#include <asm/kvm_mmu.h>
#include <asm/kvm_nested.h>
#include <asm/fpsimd.h>
#include <asm/debug-monitors.h>
#include <asm/processor.h>
#include <asm/traps.h>
Include dependency graph for switch.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  kvm_exception_table_entry
 

Macros

#define compute_clr_set(vcpu, reg, clr, set)
 
#define update_fgt_traps_cs(vcpu, reg, clr, set)
 
#define update_fgt_traps(vcpu, reg)    update_fgt_traps_cs(vcpu, reg, 0, 0)
 
#define CHECK_FGT_MASKS(reg)
 
#define __ptrauth_save_key(ctxt, key)
 

Typedefs

typedef bool(* exit_handler_fn) (struct kvm_vcpu *, u64 *)
 

Functions

static bool guest_owns_fp_regs (struct kvm_vcpu *vcpu)
 
static void __fpsimd_save_fpexc32 (struct kvm_vcpu *vcpu)
 
static void __activate_traps_fpsimd32 (struct kvm_vcpu *vcpu)
 
static bool cpu_has_amu (void)
 
static void __activate_traps_hfgxtr (struct kvm_vcpu *vcpu)
 
static void __deactivate_traps_hfgxtr (struct kvm_vcpu *vcpu)
 
static void __activate_traps_common (struct kvm_vcpu *vcpu)
 
static void __deactivate_traps_common (struct kvm_vcpu *vcpu)
 
static void ___activate_traps (struct kvm_vcpu *vcpu)
 
static void ___deactivate_traps (struct kvm_vcpu *vcpu)
 
static bool __populate_fault_info (struct kvm_vcpu *vcpu)
 
static bool kvm_hyp_handle_mops (struct kvm_vcpu *vcpu, u64 *exit_code)
 
static void __hyp_sve_restore_guest (struct kvm_vcpu *vcpu)
 
static bool kvm_hyp_handle_fpsimd (struct kvm_vcpu *vcpu, u64 *exit_code)
 
static bool handle_tx2_tvm (struct kvm_vcpu *vcpu)
 
static bool esr_is_ptrauth_trap (u64 esr)
 
 DECLARE_PER_CPU (struct kvm_cpu_context, kvm_hyp_ctxt)
 
static bool kvm_hyp_handle_ptrauth (struct kvm_vcpu *vcpu, u64 *exit_code)
 
static bool kvm_hyp_handle_cntpct (struct kvm_vcpu *vcpu)
 
static bool handle_ampere1_tcr (struct kvm_vcpu *vcpu)
 
static bool kvm_hyp_handle_sysreg (struct kvm_vcpu *vcpu, u64 *exit_code)
 
static bool kvm_hyp_handle_cp15_32 (struct kvm_vcpu *vcpu, u64 *exit_code)
 
static bool kvm_hyp_handle_memory_fault (struct kvm_vcpu *vcpu, u64 *exit_code)
 
static bool kvm_hyp_handle_iabt_low (struct kvm_vcpu *vcpu, u64 *exit_code) __alias(kvm_hyp_handle_memory_fault)
 
static bool kvm_hyp_handle_watchpt_low (struct kvm_vcpu *vcpu, u64 *exit_code) __alias(kvm_hyp_handle_memory_fault)
 
static bool kvm_hyp_handle_dabt_low (struct kvm_vcpu *vcpu, u64 *exit_code)
 
static const exit_handler_fnkvm_get_exit_handler_array (struct kvm_vcpu *vcpu)
 
static void early_exit_filter (struct kvm_vcpu *vcpu, u64 *exit_code)
 
static bool kvm_hyp_handle_exit (struct kvm_vcpu *vcpu, u64 *exit_code)
 
static void synchronize_vcpu_pstate (struct kvm_vcpu *vcpu, u64 *exit_code)
 
static bool fixup_guest_exit (struct kvm_vcpu *vcpu, u64 *exit_code)
 
static void __kvm_unexpected_el2_exception (void)
 

Variables

struct kvm_exception_table_entry __start___kvm_ex_table
 
struct kvm_exception_table_entry __stop___kvm_ex_table
 

Macro Definition Documentation

◆ __ptrauth_save_key

#define __ptrauth_save_key (   ctxt,
  key 
)
Value:
do { \
u64 __val; \
__val = read_sysreg_s(SYS_ ## key ## KEYLO_EL1); \
ctxt_sys_reg(ctxt, key ## KEYLO_EL1) = __val; \
__val = read_sysreg_s(SYS_ ## key ## KEYHI_EL1); \
ctxt_sys_reg(ctxt, key ## KEYHI_EL1) = __val; \
} while(0)

Definition at line 465 of file switch.h.

◆ CHECK_FGT_MASKS

#define CHECK_FGT_MASKS (   reg)
Value:
do { \
BUILD_BUG_ON((__ ## reg ## _MASK) & (__ ## reg ## _nMASK)); \
BUILD_BUG_ON(~((__ ## reg ## _RES0) ^ (__ ## reg ## _MASK) ^ \
(__ ## reg ## _nMASK))); \
} while(0)

Definition at line 107 of file switch.h.

◆ compute_clr_set

#define compute_clr_set (   vcpu,
  reg,
  clr,
  set 
)
Value:
do { \
u64 hfg; \
hfg = __vcpu_sys_reg(vcpu, reg) & ~__ ## reg ## _RES0; \
set |= hfg & __ ## reg ## _MASK; \
clr |= ~hfg & __ ## reg ## _nMASK; \
} while(0)

Definition at line 74 of file switch.h.

◆ update_fgt_traps

#define update_fgt_traps (   vcpu,
  reg 
)     update_fgt_traps_cs(vcpu, reg, 0, 0)

Definition at line 100 of file switch.h.

◆ update_fgt_traps_cs

#define update_fgt_traps_cs (   vcpu,
  reg,
  clr,
  set 
)
Value:
do { \
struct kvm_cpu_context *hctxt = \
&this_cpu_ptr(&kvm_host_data)->host_ctxt; \
u64 c = 0, s = 0; \
\
ctxt_sys_reg(hctxt, reg) = read_sysreg_s(SYS_ ## reg); \
compute_clr_set(vcpu, reg, c, s); \
s |= set; \
c |= clr; \
if (c || s) { \
u64 val = __ ## reg ## _nMASK; \
val |= s; \
val &= ~c; \
write_sysreg_s(val, SYS_ ## reg); \
} \
} while(0)

Definition at line 82 of file switch.h.

Typedef Documentation

◆ exit_handler_fn

typedef bool(* exit_handler_fn) (struct kvm_vcpu *, u64 *)

Definition at line 645 of file switch.h.

Function Documentation

◆ ___activate_traps()

static void ___activate_traps ( struct kvm_vcpu *  vcpu)
inlinestatic

Definition at line 268 of file switch.h.

269 {
270  u64 hcr = vcpu->arch.hcr_el2;
271 
272  if (cpus_have_final_cap(ARM64_WORKAROUND_CAVIUM_TX2_219_TVM))
273  hcr |= HCR_TVM;
274 
275  write_sysreg(hcr, hcr_el2);
276 
277  if (cpus_have_final_cap(ARM64_HAS_RAS_EXTN) && (hcr & HCR_VSE))
278  write_sysreg_s(vcpu->arch.vsesr_el2, SYS_VSESR_EL2);
279 }
Here is the caller graph for this function:

◆ ___deactivate_traps()

static void ___deactivate_traps ( struct kvm_vcpu *  vcpu)
inlinestatic

Definition at line 281 of file switch.h.

282 {
283  /*
284  * If we pended a virtual abort, preserve it until it gets
285  * cleared. See D1.14.3 (Virtual Interrupts) for details, but
286  * the crucial bit is "On taking a vSError interrupt,
287  * HCR_EL2.VSE is cleared to 0."
288  */
289  if (vcpu->arch.hcr_el2 & HCR_VSE) {
290  vcpu->arch.hcr_el2 &= ~HCR_VSE;
291  vcpu->arch.hcr_el2 |= read_sysreg(hcr_el2) & HCR_VSE;
292  }
293 }
Here is the caller graph for this function:

◆ __activate_traps_common()

static void __activate_traps_common ( struct kvm_vcpu *  vcpu)
inlinestatic

Definition at line 207 of file switch.h.

208 {
209  /* Trap on AArch32 cp15 c15 (impdef sysregs) accesses (EL1 or EL0) */
210  write_sysreg(1 << 15, hstr_el2);
211 
212  /*
213  * Make sure we trap PMU access from EL0 to EL2. Also sanitize
214  * PMSELR_EL0 to make sure it never contains the cycle
215  * counter, which could make a PMXEVCNTR_EL0 access UNDEF at
216  * EL1 instead of being trapped to EL2.
217  */
218  if (kvm_arm_support_pmu_v3()) {
219  struct kvm_cpu_context *hctxt;
220 
221  write_sysreg(0, pmselr_el0);
222 
223  hctxt = &this_cpu_ptr(&kvm_host_data)->host_ctxt;
224  ctxt_sys_reg(hctxt, PMUSERENR_EL0) = read_sysreg(pmuserenr_el0);
225  write_sysreg(ARMV8_PMU_USERENR_MASK, pmuserenr_el0);
226  vcpu_set_flag(vcpu, PMUSERENR_ON_CPU);
227  }
228 
229  vcpu->arch.mdcr_el2_host = read_sysreg(mdcr_el2);
230  write_sysreg(vcpu->arch.mdcr_el2, mdcr_el2);
231 
232  if (cpus_have_final_cap(ARM64_HAS_HCX)) {
233  u64 hcrx = HCRX_GUEST_FLAGS;
234  if (vcpu_has_nv(vcpu) && !is_hyp_ctxt(vcpu)) {
235  u64 clr = 0, set = 0;
236 
237  compute_clr_set(vcpu, HCRX_EL2, clr, set);
238 
239  hcrx |= set;
240  hcrx &= ~clr;
241  }
242 
243  write_sysreg_s(hcrx, SYS_HCRX_EL2);
244  }
245 
247 }
static bool kvm_arm_support_pmu_v3(void)
Definition: arm_pmu.h:113
#define compute_clr_set(vcpu, reg, clr, set)
Definition: switch.h:74
static void __activate_traps_hfgxtr(struct kvm_vcpu *vcpu)
Definition: switch.h:122
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __activate_traps_fpsimd32()

static void __activate_traps_fpsimd32 ( struct kvm_vcpu *  vcpu)
inlinestatic

Definition at line 57 of file switch.h.

58 {
59  /*
60  * We are about to set CPTR_EL2.TFP to trap all floating point
61  * register accesses to EL2, however, the ARM ARM clearly states that
62  * traps are only taken to EL2 if the operation would not otherwise
63  * trap to EL1. Therefore, always make sure that for 32-bit guests,
64  * we set FPEXC.EN to prevent traps to EL1, when setting the TFP bit.
65  * If FP/ASIMD is not implemented, FPEXC is UNDEFINED and any access to
66  * it will cause an exception.
67  */
68  if (vcpu_el1_is_32bit(vcpu) && system_supports_fpsimd()) {
69  write_sysreg(1 << 30, fpexc32_el2);
70  isb();
71  }
72 }
Here is the caller graph for this function:

◆ __activate_traps_hfgxtr()

static void __activate_traps_hfgxtr ( struct kvm_vcpu *  vcpu)
inlinestatic

Definition at line 122 of file switch.h.

123 {
124  struct kvm_cpu_context *hctxt = &this_cpu_ptr(&kvm_host_data)->host_ctxt;
125  u64 r_clr = 0, w_clr = 0, r_set = 0, w_set = 0, tmp;
126  u64 r_val, w_val;
127 
128  CHECK_FGT_MASKS(HFGRTR_EL2);
129  CHECK_FGT_MASKS(HFGWTR_EL2);
130  CHECK_FGT_MASKS(HFGITR_EL2);
131  CHECK_FGT_MASKS(HDFGRTR_EL2);
132  CHECK_FGT_MASKS(HDFGWTR_EL2);
133  CHECK_FGT_MASKS(HAFGRTR_EL2);
134  CHECK_FGT_MASKS(HCRX_EL2);
135 
136  if (!cpus_have_final_cap(ARM64_HAS_FGT))
137  return;
138 
139  ctxt_sys_reg(hctxt, HFGRTR_EL2) = read_sysreg_s(SYS_HFGRTR_EL2);
140  ctxt_sys_reg(hctxt, HFGWTR_EL2) = read_sysreg_s(SYS_HFGWTR_EL2);
141 
142  if (cpus_have_final_cap(ARM64_SME)) {
143  tmp = HFGxTR_EL2_nSMPRI_EL1_MASK | HFGxTR_EL2_nTPIDR2_EL0_MASK;
144 
145  r_clr |= tmp;
146  w_clr |= tmp;
147  }
148 
149  /*
150  * Trap guest writes to TCR_EL1 to prevent it from enabling HA or HD.
151  */
152  if (cpus_have_final_cap(ARM64_WORKAROUND_AMPERE_AC03_CPU_38))
153  w_set |= HFGxTR_EL2_TCR_EL1_MASK;
154 
155  if (vcpu_has_nv(vcpu) && !is_hyp_ctxt(vcpu)) {
156  compute_clr_set(vcpu, HFGRTR_EL2, r_clr, r_set);
157  compute_clr_set(vcpu, HFGWTR_EL2, w_clr, w_set);
158  }
159 
160  /* The default to trap everything not handled or supported in KVM. */
161  tmp = HFGxTR_EL2_nAMAIR2_EL1 | HFGxTR_EL2_nMAIR2_EL1 | HFGxTR_EL2_nS2POR_EL1 |
162  HFGxTR_EL2_nPOR_EL1 | HFGxTR_EL2_nPOR_EL0 | HFGxTR_EL2_nACCDATA_EL1;
163 
164  r_val = __HFGRTR_EL2_nMASK & ~tmp;
165  r_val |= r_set;
166  r_val &= ~r_clr;
167 
168  w_val = __HFGWTR_EL2_nMASK & ~tmp;
169  w_val |= w_set;
170  w_val &= ~w_clr;
171 
172  write_sysreg_s(r_val, SYS_HFGRTR_EL2);
173  write_sysreg_s(w_val, SYS_HFGWTR_EL2);
174 
175  if (!vcpu_has_nv(vcpu) || is_hyp_ctxt(vcpu))
176  return;
177 
178  update_fgt_traps(vcpu, HFGITR_EL2);
179  update_fgt_traps(vcpu, HDFGRTR_EL2);
180  update_fgt_traps(vcpu, HDFGWTR_EL2);
181 
182  if (cpu_has_amu())
183  update_fgt_traps(vcpu, HAFGRTR_EL2);
184 }
#define CHECK_FGT_MASKS(reg)
Definition: switch.h:107
static bool cpu_has_amu(void)
Definition: switch.h:114
#define update_fgt_traps(vcpu, reg)
Definition: switch.h:100
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __deactivate_traps_common()

static void __deactivate_traps_common ( struct kvm_vcpu *  vcpu)
inlinestatic

Definition at line 249 of file switch.h.

250 {
251  write_sysreg(vcpu->arch.mdcr_el2_host, mdcr_el2);
252 
253  write_sysreg(0, hstr_el2);
254  if (kvm_arm_support_pmu_v3()) {
255  struct kvm_cpu_context *hctxt;
256 
257  hctxt = &this_cpu_ptr(&kvm_host_data)->host_ctxt;
258  write_sysreg(ctxt_sys_reg(hctxt, PMUSERENR_EL0), pmuserenr_el0);
259  vcpu_clear_flag(vcpu, PMUSERENR_ON_CPU);
260  }
261 
262  if (cpus_have_final_cap(ARM64_HAS_HCX))
263  write_sysreg_s(HCRX_HOST_FLAGS, SYS_HCRX_EL2);
264 
266 }
static void __deactivate_traps_hfgxtr(struct kvm_vcpu *vcpu)
Definition: switch.h:186
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __deactivate_traps_hfgxtr()

static void __deactivate_traps_hfgxtr ( struct kvm_vcpu *  vcpu)
inlinestatic

Definition at line 186 of file switch.h.

187 {
188  struct kvm_cpu_context *hctxt = &this_cpu_ptr(&kvm_host_data)->host_ctxt;
189 
190  if (!cpus_have_final_cap(ARM64_HAS_FGT))
191  return;
192 
193  write_sysreg_s(ctxt_sys_reg(hctxt, HFGRTR_EL2), SYS_HFGRTR_EL2);
194  write_sysreg_s(ctxt_sys_reg(hctxt, HFGWTR_EL2), SYS_HFGWTR_EL2);
195 
196  if (!vcpu_has_nv(vcpu) || is_hyp_ctxt(vcpu))
197  return;
198 
199  write_sysreg_s(ctxt_sys_reg(hctxt, HFGITR_EL2), SYS_HFGITR_EL2);
200  write_sysreg_s(ctxt_sys_reg(hctxt, HDFGRTR_EL2), SYS_HDFGRTR_EL2);
201  write_sysreg_s(ctxt_sys_reg(hctxt, HDFGWTR_EL2), SYS_HDFGWTR_EL2);
202 
203  if (cpu_has_amu())
204  write_sysreg_s(ctxt_sys_reg(hctxt, HAFGRTR_EL2), SYS_HAFGRTR_EL2);
205 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ __fpsimd_save_fpexc32()

static void __fpsimd_save_fpexc32 ( struct kvm_vcpu *  vcpu)
inlinestatic

Definition at line 49 of file switch.h.

50 {
51  if (!vcpu_el1_is_32bit(vcpu))
52  return;
53 
54  __vcpu_sys_reg(vcpu, FPEXC32_EL2) = read_sysreg(fpexc32_el2);
55 }
Here is the caller graph for this function:

◆ __hyp_sve_restore_guest()

static void __hyp_sve_restore_guest ( struct kvm_vcpu *  vcpu)
inlinestatic

Definition at line 316 of file switch.h.

317 {
318  sve_cond_update_zcr_vq(vcpu_sve_max_vq(vcpu) - 1, SYS_ZCR_EL2);
319  __sve_restore_state(vcpu_sve_pffr(vcpu),
320  &vcpu->arch.ctxt.fp_regs.fpsr);
321  write_sysreg_el1(__vcpu_sys_reg(vcpu, ZCR_EL1), SYS_ZCR);
322 }
Here is the caller graph for this function:

◆ __kvm_unexpected_el2_exception()

static void __kvm_unexpected_el2_exception ( void  )
inlinestatic

Definition at line 748 of file switch.h.

749 {
750  extern char __guest_exit_panic[];
751  unsigned long addr, fixup;
752  struct kvm_exception_table_entry *entry, *end;
753  unsigned long elr_el2 = read_sysreg(elr_el2);
754 
755  entry = &__start___kvm_ex_table;
757 
758  while (entry < end) {
759  addr = (unsigned long)&entry->insn + entry->insn;
760  fixup = (unsigned long)&entry->fixup + entry->fixup;
761 
762  if (addr != elr_el2) {
763  entry++;
764  continue;
765  }
766 
767  write_sysreg(fixup, elr_el2);
768  return;
769  }
770 
771  /* Trigger a panic after restoring the hyp context. */
772  write_sysreg(__guest_exit_panic, elr_el2);
773 }
static unsigned long end
Definition: early_alloc.c:16
Definition: switch.h:35
int insn
Definition: switch.h:36
int fixup
Definition: switch.h:36
struct kvm_exception_table_entry __stop___kvm_ex_table
struct kvm_exception_table_entry __start___kvm_ex_table
Here is the caller graph for this function:

◆ __populate_fault_info()

static bool __populate_fault_info ( struct kvm_vcpu *  vcpu)
inlinestatic

Definition at line 295 of file switch.h.

296 {
297  return __get_fault_info(vcpu->arch.fault.esr_el2, &vcpu->arch.fault);
298 }
static bool __get_fault_info(u64 esr, struct kvm_vcpu_fault_info *fault)
Definition: fault.h:44
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cpu_has_amu()

static bool cpu_has_amu ( void  )
inlinestatic

Definition at line 114 of file switch.h.

115 {
116  u64 pfr0 = read_sysreg_s(SYS_ID_AA64PFR0_EL1);
117 
118  return cpuid_feature_extract_unsigned_field(pfr0,
119  ID_AA64PFR0_EL1_AMU_SHIFT);
120 }
Here is the caller graph for this function:

◆ DECLARE_PER_CPU()

DECLARE_PER_CPU ( struct kvm_cpu_context  ,
kvm_hyp_ctxt   
)

◆ early_exit_filter()

static void early_exit_filter ( struct kvm_vcpu *  vcpu,
u64 *  exit_code 
)
static
Here is the caller graph for this function:

◆ esr_is_ptrauth_trap()

static bool esr_is_ptrauth_trap ( u64  esr)
inlinestatic

Definition at line 446 of file switch.h.

447 {
448  switch (esr_sys64_to_sysreg(esr)) {
449  case SYS_APIAKEYLO_EL1:
450  case SYS_APIAKEYHI_EL1:
451  case SYS_APIBKEYLO_EL1:
452  case SYS_APIBKEYHI_EL1:
453  case SYS_APDAKEYLO_EL1:
454  case SYS_APDAKEYHI_EL1:
455  case SYS_APDBKEYLO_EL1:
456  case SYS_APDBKEYHI_EL1:
457  case SYS_APGAKEYLO_EL1:
458  case SYS_APGAKEYHI_EL1:
459  return true;
460  }
461 
462  return false;
463 }
Here is the caller graph for this function:

◆ fixup_guest_exit()

static bool fixup_guest_exit ( struct kvm_vcpu *  vcpu,
u64 *  exit_code 
)
inlinestatic

Definition at line 693 of file switch.h.

694 {
695  /*
696  * Save PSTATE early so that we can evaluate the vcpu mode
697  * early on.
698  */
699  synchronize_vcpu_pstate(vcpu, exit_code);
700 
701  /*
702  * Check whether we want to repaint the state one way or
703  * another.
704  */
705  early_exit_filter(vcpu, exit_code);
706 
707  if (ARM_EXCEPTION_CODE(*exit_code) != ARM_EXCEPTION_IRQ)
708  vcpu->arch.fault.esr_el2 = read_sysreg_el2(SYS_ESR);
709 
710  if (ARM_SERROR_PENDING(*exit_code) &&
711  ARM_EXCEPTION_CODE(*exit_code) != ARM_EXCEPTION_IRQ) {
712  u8 esr_ec = kvm_vcpu_trap_get_class(vcpu);
713 
714  /*
715  * HVC already have an adjusted PC, which we need to
716  * correct in order to return to after having injected
717  * the SError.
718  *
719  * SMC, on the other hand, is *trapped*, meaning its
720  * preferred return address is the SMC itself.
721  */
722  if (esr_ec == ESR_ELx_EC_HVC32 || esr_ec == ESR_ELx_EC_HVC64)
723  write_sysreg_el2(read_sysreg_el2(SYS_ELR) - 4, SYS_ELR);
724  }
725 
726  /*
727  * We're using the raw exception code in order to only process
728  * the trap if no SError is pending. We will come back to the
729  * same PC once the SError has been injected, and replay the
730  * trapping instruction.
731  */
732  if (*exit_code != ARM_EXCEPTION_TRAP)
733  goto exit;
734 
735  /* Check if there's an exit handler and allow it to handle the exit. */
736  if (kvm_hyp_handle_exit(vcpu, exit_code))
737  goto guest;
738 exit:
739  /* Return to the host kernel and handle the exit */
740  return false;
741 
742 guest:
743  /* Re-enter the guest */
744  asm(ALTERNATIVE("nop", "dmb sy", ARM64_WORKAROUND_1508412));
745  return true;
746 }
static bool kvm_hyp_handle_exit(struct kvm_vcpu *vcpu, u64 *exit_code)
Definition: switch.h:657
static void synchronize_vcpu_pstate(struct kvm_vcpu *vcpu, u64 *exit_code)
Definition: switch.h:670
static void early_exit_filter(struct kvm_vcpu *vcpu, u64 *exit_code)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ guest_owns_fp_regs()

static bool guest_owns_fp_regs ( struct kvm_vcpu *  vcpu)
inlinestatic

Definition at line 43 of file switch.h.

44 {
45  return vcpu->arch.fp_state == FP_STATE_GUEST_OWNED;
46 }
Here is the caller graph for this function:

◆ handle_ampere1_tcr()

static bool handle_ampere1_tcr ( struct kvm_vcpu *  vcpu)
static

Definition at line 549 of file switch.h.

550 {
551  u32 sysreg = esr_sys64_to_sysreg(kvm_vcpu_get_esr(vcpu));
552  int rt = kvm_vcpu_sys_get_rt(vcpu);
553  u64 val = vcpu_get_reg(vcpu, rt);
554 
555  if (sysreg != SYS_TCR_EL1)
556  return false;
557 
558  /*
559  * Affected parts do not advertise support for hardware Access Flag /
560  * Dirty state management in ID_AA64MMFR1_EL1.HAFDBS, but the underlying
561  * control bits are still functional. The architecture requires these be
562  * RES0 on systems that do not implement FEAT_HAFDBS.
563  *
564  * Uphold the requirements of the architecture by masking guest writes
565  * to TCR_EL1.{HA,HD} here.
566  */
567  val &= ~(TCR_HD | TCR_HA);
568  write_sysreg_el1(val, SYS_TCR);
569  __kvm_skip_instr(vcpu);
570  return true;
571 }
static void __kvm_skip_instr(struct kvm_vcpu *vcpu)
Definition: adjust_pc.h:33
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_tx2_tvm()

static bool handle_tx2_tvm ( struct kvm_vcpu *  vcpu)
inlinestatic

Definition at line 391 of file switch.h.

392 {
393  u32 sysreg = esr_sys64_to_sysreg(kvm_vcpu_get_esr(vcpu));
394  int rt = kvm_vcpu_sys_get_rt(vcpu);
395  u64 val = vcpu_get_reg(vcpu, rt);
396 
397  /*
398  * The normal sysreg handling code expects to see the traps,
399  * let's not do anything here.
400  */
401  if (vcpu->arch.hcr_el2 & HCR_TVM)
402  return false;
403 
404  switch (sysreg) {
405  case SYS_SCTLR_EL1:
406  write_sysreg_el1(val, SYS_SCTLR);
407  break;
408  case SYS_TTBR0_EL1:
409  write_sysreg_el1(val, SYS_TTBR0);
410  break;
411  case SYS_TTBR1_EL1:
412  write_sysreg_el1(val, SYS_TTBR1);
413  break;
414  case SYS_TCR_EL1:
415  write_sysreg_el1(val, SYS_TCR);
416  break;
417  case SYS_ESR_EL1:
418  write_sysreg_el1(val, SYS_ESR);
419  break;
420  case SYS_FAR_EL1:
421  write_sysreg_el1(val, SYS_FAR);
422  break;
423  case SYS_AFSR0_EL1:
424  write_sysreg_el1(val, SYS_AFSR0);
425  break;
426  case SYS_AFSR1_EL1:
427  write_sysreg_el1(val, SYS_AFSR1);
428  break;
429  case SYS_MAIR_EL1:
430  write_sysreg_el1(val, SYS_MAIR);
431  break;
432  case SYS_AMAIR_EL1:
433  write_sysreg_el1(val, SYS_AMAIR);
434  break;
435  case SYS_CONTEXTIDR_EL1:
436  write_sysreg_el1(val, SYS_CONTEXTIDR);
437  break;
438  default:
439  return false;
440  }
441 
442  __kvm_skip_instr(vcpu);
443  return true;
444 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_get_exit_handler_array()

static const exit_handler_fn* kvm_get_exit_handler_array ( struct kvm_vcpu *  vcpu)
static
Here is the caller graph for this function:

◆ kvm_hyp_handle_cntpct()

static bool kvm_hyp_handle_cntpct ( struct kvm_vcpu *  vcpu)
static

Definition at line 500 of file switch.h.

501 {
502  struct arch_timer_context *ctxt;
503  u32 sysreg;
504  u64 val;
505 
506  /*
507  * We only get here for 64bit guests, 32bit guests will hit
508  * the long and winding road all the way to the standard
509  * handling. Yes, it sucks to be irrelevant.
510  */
511  sysreg = esr_sys64_to_sysreg(kvm_vcpu_get_esr(vcpu));
512 
513  switch (sysreg) {
514  case SYS_CNTPCT_EL0:
515  case SYS_CNTPCTSS_EL0:
516  if (vcpu_has_nv(vcpu)) {
517  if (is_hyp_ctxt(vcpu)) {
518  ctxt = vcpu_hptimer(vcpu);
519  break;
520  }
521 
522  /* Check for guest hypervisor trapping */
523  val = __vcpu_sys_reg(vcpu, CNTHCTL_EL2);
524  if (!vcpu_el2_e2h_is_set(vcpu))
525  val = (val & CNTHCTL_EL1PCTEN) << 10;
526 
527  if (!(val & (CNTHCTL_EL1PCTEN << 10)))
528  return false;
529  }
530 
531  ctxt = vcpu_ptimer(vcpu);
532  break;
533  default:
534  return false;
535  }
536 
537  val = arch_timer_read_cntpct_el0();
538 
539  if (ctxt->offset.vm_offset)
540  val -= *kern_hyp_va(ctxt->offset.vm_offset);
541  if (ctxt->offset.vcpu_offset)
542  val -= *kern_hyp_va(ctxt->offset.vcpu_offset);
543 
544  vcpu_set_reg(vcpu, kvm_vcpu_sys_get_rt(vcpu), val);
546  return true;
547 }
#define vcpu_ptimer(v)
#define vcpu_hptimer(v)
struct kvm_vcpu * vcpu
struct arch_timer_offset offset
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_hyp_handle_cp15_32()

static bool kvm_hyp_handle_cp15_32 ( struct kvm_vcpu *  vcpu,
u64 *  exit_code 
)
static

Definition at line 596 of file switch.h.

597 {
598  if (static_branch_unlikely(&vgic_v3_cpuif_trap) &&
600  return true;
601 
602  return false;
603 }
struct static_key_false vgic_v3_cpuif_trap
int __vgic_v3_perform_cpuif_access(struct kvm_vcpu *vcpu)
Definition: vgic-v3-sr.c:1016
Here is the call graph for this function:

◆ kvm_hyp_handle_dabt_low()

static bool kvm_hyp_handle_dabt_low ( struct kvm_vcpu *  vcpu,
u64 *  exit_code 
)
static

Definition at line 617 of file switch.h.

618 {
619  if (kvm_hyp_handle_memory_fault(vcpu, exit_code))
620  return true;
621 
622  if (static_branch_unlikely(&vgic_v2_cpuif_trap)) {
623  bool valid;
624 
625  valid = kvm_vcpu_trap_is_translation_fault(vcpu) &&
626  kvm_vcpu_dabt_isvalid(vcpu) &&
627  !kvm_vcpu_abt_issea(vcpu) &&
628  !kvm_vcpu_abt_iss1tw(vcpu);
629 
630  if (valid) {
631  int ret = __vgic_v2_perform_cpuif_access(vcpu);
632 
633  if (ret == 1)
634  return true;
635 
636  /* Promote an illegal access to an SError.*/
637  if (ret == -1)
638  *exit_code = ARM_EXCEPTION_EL1_SERROR;
639  }
640  }
641 
642  return false;
643 }
struct static_key_false vgic_v2_cpuif_trap
static bool kvm_hyp_handle_memory_fault(struct kvm_vcpu *vcpu, u64 *exit_code)
Definition: switch.h:605
int __vgic_v2_perform_cpuif_access(struct kvm_vcpu *vcpu)
Here is the call graph for this function:

◆ kvm_hyp_handle_exit()

static bool kvm_hyp_handle_exit ( struct kvm_vcpu *  vcpu,
u64 *  exit_code 
)
inlinestatic

Definition at line 657 of file switch.h.

658 {
659  const exit_handler_fn *handlers = kvm_get_exit_handler_array(vcpu);
660  exit_handler_fn fn;
661 
662  fn = handlers[kvm_vcpu_trap_get_class(vcpu)];
663 
664  if (fn)
665  return fn(vcpu, exit_code);
666 
667  return false;
668 }
bool(* exit_handler_fn)(struct kvm_vcpu *, u64 *)
Definition: switch.h:645
static const exit_handler_fn * kvm_get_exit_handler_array(struct kvm_vcpu *vcpu)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_hyp_handle_fpsimd()

static bool kvm_hyp_handle_fpsimd ( struct kvm_vcpu *  vcpu,
u64 *  exit_code 
)
static

Definition at line 330 of file switch.h.

331 {
332  bool sve_guest;
333  u8 esr_ec;
334  u64 reg;
335 
336  if (!system_supports_fpsimd())
337  return false;
338 
339  sve_guest = vcpu_has_sve(vcpu);
340  esr_ec = kvm_vcpu_trap_get_class(vcpu);
341 
342  /* Only handle traps the vCPU can support here: */
343  switch (esr_ec) {
344  case ESR_ELx_EC_FP_ASIMD:
345  break;
346  case ESR_ELx_EC_SVE:
347  if (!sve_guest)
348  return false;
349  break;
350  default:
351  return false;
352  }
353 
354  /* Valid trap. Switch the context: */
355 
356  /* First disable enough traps to allow us to update the registers */
357  if (has_vhe() || has_hvhe()) {
358  reg = CPACR_EL1_FPEN_EL0EN | CPACR_EL1_FPEN_EL1EN;
359  if (sve_guest)
360  reg |= CPACR_EL1_ZEN_EL0EN | CPACR_EL1_ZEN_EL1EN;
361 
362  sysreg_clear_set(cpacr_el1, 0, reg);
363  } else {
364  reg = CPTR_EL2_TFP;
365  if (sve_guest)
366  reg |= CPTR_EL2_TZ;
367 
368  sysreg_clear_set(cptr_el2, reg, 0);
369  }
370  isb();
371 
372  /* Write out the host state if it's in the registers */
373  if (vcpu->arch.fp_state == FP_STATE_HOST_OWNED)
374  __fpsimd_save_state(vcpu->arch.host_fpsimd_state);
375 
376  /* Restore the guest state */
377  if (sve_guest)
379  else
380  __fpsimd_restore_state(&vcpu->arch.ctxt.fp_regs);
381 
382  /* Skip restoring fpexc32 for AArch64 guests */
383  if (!(read_sysreg(hcr_el2) & HCR_RW))
384  write_sysreg(__vcpu_sys_reg(vcpu, FPEXC32_EL2), fpexc32_el2);
385 
386  vcpu->arch.fp_state = FP_STATE_GUEST_OWNED;
387 
388  return true;
389 }
static void __hyp_sve_restore_guest(struct kvm_vcpu *vcpu)
Definition: switch.h:316
Here is the call graph for this function:

◆ kvm_hyp_handle_iabt_low()

static bool kvm_hyp_handle_iabt_low ( struct kvm_vcpu *  vcpu,
u64 *  exit_code 
)
static

◆ kvm_hyp_handle_memory_fault()

static bool kvm_hyp_handle_memory_fault ( struct kvm_vcpu *  vcpu,
u64 *  exit_code 
)
static

Definition at line 605 of file switch.h.

606 {
607  if (!__populate_fault_info(vcpu))
608  return true;
609 
610  return false;
611 }
static bool __populate_fault_info(struct kvm_vcpu *vcpu)
Definition: switch.h:295
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_hyp_handle_mops()

static bool kvm_hyp_handle_mops ( struct kvm_vcpu *  vcpu,
u64 *  exit_code 
)
static

Definition at line 300 of file switch.h.

301 {
302  *vcpu_pc(vcpu) = read_sysreg_el2(SYS_ELR);
303  arm64_mops_reset_regs(vcpu_gp_regs(vcpu), vcpu->arch.fault.esr_el2);
304  write_sysreg_el2(*vcpu_pc(vcpu), SYS_ELR);
305 
306  /*
307  * Finish potential single step before executing the prologue
308  * instruction.
309  */
310  *vcpu_cpsr(vcpu) &= ~DBG_SPSR_SS;
311  write_sysreg_el2(*vcpu_cpsr(vcpu), SYS_SPSR);
312 
313  return true;
314 }

◆ kvm_hyp_handle_ptrauth()

static bool kvm_hyp_handle_ptrauth ( struct kvm_vcpu *  vcpu,
u64 *  exit_code 
)
static

Definition at line 476 of file switch.h.

477 {
478  struct kvm_cpu_context *ctxt;
479  u64 val;
480 
481  if (!vcpu_has_ptrauth(vcpu))
482  return false;
483 
484  ctxt = this_cpu_ptr(&kvm_hyp_ctxt);
485  __ptrauth_save_key(ctxt, APIA);
486  __ptrauth_save_key(ctxt, APIB);
487  __ptrauth_save_key(ctxt, APDA);
488  __ptrauth_save_key(ctxt, APDB);
489  __ptrauth_save_key(ctxt, APGA);
490 
491  vcpu_ptrauth_enable(vcpu);
492 
493  val = read_sysreg(hcr_el2);
494  val |= (HCR_API | HCR_APK);
495  write_sysreg(val, hcr_el2);
496 
497  return true;
498 }
#define __ptrauth_save_key(ctxt, key)
Definition: switch.h:465
Here is the caller graph for this function:

◆ kvm_hyp_handle_sysreg()

static bool kvm_hyp_handle_sysreg ( struct kvm_vcpu *  vcpu,
u64 *  exit_code 
)
static

Definition at line 573 of file switch.h.

574 {
575  if (cpus_have_final_cap(ARM64_WORKAROUND_CAVIUM_TX2_219_TVM) &&
576  handle_tx2_tvm(vcpu))
577  return true;
578 
579  if (cpus_have_final_cap(ARM64_WORKAROUND_AMPERE_AC03_CPU_38) &&
580  handle_ampere1_tcr(vcpu))
581  return true;
582 
583  if (static_branch_unlikely(&vgic_v3_cpuif_trap) &&
585  return true;
586 
587  if (esr_is_ptrauth_trap(kvm_vcpu_get_esr(vcpu)))
588  return kvm_hyp_handle_ptrauth(vcpu, exit_code);
589 
590  if (kvm_hyp_handle_cntpct(vcpu))
591  return true;
592 
593  return false;
594 }
static bool kvm_hyp_handle_ptrauth(struct kvm_vcpu *vcpu, u64 *exit_code)
Definition: switch.h:476
static bool esr_is_ptrauth_trap(u64 esr)
Definition: switch.h:446
static bool handle_ampere1_tcr(struct kvm_vcpu *vcpu)
Definition: switch.h:549
static bool kvm_hyp_handle_cntpct(struct kvm_vcpu *vcpu)
Definition: switch.h:500
static bool handle_tx2_tvm(struct kvm_vcpu *vcpu)
Definition: switch.h:391
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_hyp_handle_watchpt_low()

static bool kvm_hyp_handle_watchpt_low ( struct kvm_vcpu *  vcpu,
u64 *  exit_code 
)
static

◆ synchronize_vcpu_pstate()

static void synchronize_vcpu_pstate ( struct kvm_vcpu *  vcpu,
u64 *  exit_code 
)
inlinestatic

Definition at line 670 of file switch.h.

671 {
672  /*
673  * Check for the conditions of Cortex-A510's #2077057. When these occur
674  * SPSR_EL2 can't be trusted, but isn't needed either as it is
675  * unchanged from the value in vcpu_gp_regs(vcpu)->pstate.
676  * Are we single-stepping the guest, and took a PAC exception from the
677  * active-not-pending state?
678  */
679  if (cpus_have_final_cap(ARM64_WORKAROUND_2077057) &&
680  vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP &&
681  *vcpu_cpsr(vcpu) & DBG_SPSR_SS &&
682  ESR_ELx_EC(read_sysreg_el2(SYS_ESR)) == ESR_ELx_EC_PAC)
683  write_sysreg_el2(*vcpu_cpsr(vcpu), SYS_SPSR);
684 
685  vcpu->arch.ctxt.regs.pstate = read_sysreg_el2(SYS_SPSR);
686 }
Here is the caller graph for this function:

Variable Documentation

◆ __start___kvm_ex_table

struct kvm_exception_table_entry __start___kvm_ex_table
extern

◆ __stop___kvm_ex_table

struct kvm_exception_table_entry __stop___kvm_ex_table
extern