KVM
Functions
arm_hypercalls.h File Reference
#include <asm/kvm_emulate.h>
Include dependency graph for arm_hypercalls.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int kvm_smccc_call_handler (struct kvm_vcpu *vcpu)
 
static u32 smccc_get_function (struct kvm_vcpu *vcpu)
 
static unsigned long smccc_get_arg1 (struct kvm_vcpu *vcpu)
 
static unsigned long smccc_get_arg2 (struct kvm_vcpu *vcpu)
 
static unsigned long smccc_get_arg3 (struct kvm_vcpu *vcpu)
 
static void smccc_set_retval (struct kvm_vcpu *vcpu, unsigned long a0, unsigned long a1, unsigned long a2, unsigned long a3)
 
void kvm_arm_init_hypercalls (struct kvm *kvm)
 
void kvm_arm_teardown_hypercalls (struct kvm *kvm)
 
int kvm_arm_get_fw_num_regs (struct kvm_vcpu *vcpu)
 
int kvm_arm_copy_fw_reg_indices (struct kvm_vcpu *vcpu, u64 __user *uindices)
 
int kvm_arm_get_fw_reg (struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
 
int kvm_arm_set_fw_reg (struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
 
int kvm_vm_smccc_has_attr (struct kvm *kvm, struct kvm_device_attr *attr)
 
int kvm_vm_smccc_set_attr (struct kvm *kvm, struct kvm_device_attr *attr)
 

Function Documentation

◆ kvm_arm_copy_fw_reg_indices()

int kvm_arm_copy_fw_reg_indices ( struct kvm_vcpu *  vcpu,
u64 __user *  uindices 
)

Definition at line 413 of file hypercalls.c.

414 {
415  int i;
416 
417  for (i = 0; i < ARRAY_SIZE(kvm_arm_fw_reg_ids); i++) {
418  if (put_user(kvm_arm_fw_reg_ids[i], uindices++))
419  return -EFAULT;
420  }
421 
422  return 0;
423 }
static const u64 kvm_arm_fw_reg_ids[]
Definition: hypercalls.c:382
Here is the caller graph for this function:

◆ kvm_arm_get_fw_num_regs()

int kvm_arm_get_fw_num_regs ( struct kvm_vcpu *  vcpu)

Definition at line 408 of file hypercalls.c.

409 {
410  return ARRAY_SIZE(kvm_arm_fw_reg_ids);
411 }
Here is the caller graph for this function:

◆ kvm_arm_get_fw_reg()

int kvm_arm_get_fw_reg ( struct kvm_vcpu *  vcpu,
const struct kvm_one_reg *  reg 
)

Definition at line 476 of file hypercalls.c.

477 {
478  struct kvm_smccc_features *smccc_feat = &vcpu->kvm->arch.smccc_feat;
479  void __user *uaddr = (void __user *)(long)reg->addr;
480  u64 val;
481 
482  switch (reg->id) {
483  case KVM_REG_ARM_PSCI_VERSION:
484  val = kvm_psci_version(vcpu);
485  break;
486  case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1:
487  case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2:
488  case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_3:
490  break;
491  case KVM_REG_ARM_STD_BMAP:
492  val = READ_ONCE(smccc_feat->std_bmap);
493  break;
494  case KVM_REG_ARM_STD_HYP_BMAP:
495  val = READ_ONCE(smccc_feat->std_hyp_bmap);
496  break;
497  case KVM_REG_ARM_VENDOR_HYP_BMAP:
498  val = READ_ONCE(smccc_feat->vendor_hyp_bmap);
499  break;
500  default:
501  return -ENOENT;
502  }
503 
504  if (copy_to_user(uaddr, &val, KVM_REG_SIZE(reg->id)))
505  return -EFAULT;
506 
507  return 0;
508 }
static int kvm_psci_version(struct kvm_vcpu *vcpu)
Definition: arm_psci.h:20
static int get_kernel_wa_level(u64 regid)
Definition: hypercalls.c:431
#define KVM_REG_FEATURE_LEVEL_MASK
Definition: hypercalls.c:425
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_arm_init_hypercalls()

void kvm_arm_init_hypercalls ( struct kvm *  kvm)

Definition at line 392 of file hypercalls.c.

393 {
394  struct kvm_smccc_features *smccc_feat = &kvm->arch.smccc_feat;
395 
396  smccc_feat->std_bmap = KVM_ARM_SMCCC_STD_FEATURES;
397  smccc_feat->std_hyp_bmap = KVM_ARM_SMCCC_STD_HYP_FEATURES;
398  smccc_feat->vendor_hyp_bmap = KVM_ARM_SMCCC_VENDOR_HYP_FEATURES;
399 
400  mt_init(&kvm->arch.smccc_filter);
401 }
#define KVM_ARM_SMCCC_STD_HYP_FEATURES
Definition: hypercalls.c:14
#define KVM_ARM_SMCCC_VENDOR_HYP_FEATURES
Definition: hypercalls.c:16
#define KVM_ARM_SMCCC_STD_FEATURES
Definition: hypercalls.c:12
Here is the caller graph for this function:

◆ kvm_arm_set_fw_reg()

int kvm_arm_set_fw_reg ( struct kvm_vcpu *  vcpu,
const struct kvm_one_reg *  reg 
)

Definition at line 551 of file hypercalls.c.

552 {
553  void __user *uaddr = (void __user *)(long)reg->addr;
554  u64 val;
555  int wa_level;
556 
557  if (KVM_REG_SIZE(reg->id) != sizeof(val))
558  return -ENOENT;
559  if (copy_from_user(&val, uaddr, KVM_REG_SIZE(reg->id)))
560  return -EFAULT;
561 
562  switch (reg->id) {
563  case KVM_REG_ARM_PSCI_VERSION:
564  {
565  bool wants_02;
566 
567  wants_02 = vcpu_has_feature(vcpu, KVM_ARM_VCPU_PSCI_0_2);
568 
569  switch (val) {
570  case KVM_ARM_PSCI_0_1:
571  if (wants_02)
572  return -EINVAL;
573  vcpu->kvm->arch.psci_version = val;
574  return 0;
575  case KVM_ARM_PSCI_0_2:
576  case KVM_ARM_PSCI_1_0:
577  case KVM_ARM_PSCI_1_1:
578  if (!wants_02)
579  return -EINVAL;
580  vcpu->kvm->arch.psci_version = val;
581  return 0;
582  }
583  break;
584  }
585 
586  case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1:
587  case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_3:
588  if (val & ~KVM_REG_FEATURE_LEVEL_MASK)
589  return -EINVAL;
590 
591  if (get_kernel_wa_level(reg->id) < val)
592  return -EINVAL;
593 
594  return 0;
595 
596  case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2:
597  if (val & ~(KVM_REG_FEATURE_LEVEL_MASK |
598  KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_ENABLED))
599  return -EINVAL;
600 
601  /* The enabled bit must not be set unless the level is AVAIL. */
602  if ((val & KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_ENABLED) &&
603  (val & KVM_REG_FEATURE_LEVEL_MASK) != KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_AVAIL)
604  return -EINVAL;
605 
606  /*
607  * Map all the possible incoming states to the only two we
608  * really want to deal with.
609  */
610  switch (val & KVM_REG_FEATURE_LEVEL_MASK) {
611  case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_AVAIL:
612  case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_UNKNOWN:
613  wa_level = KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_AVAIL;
614  break;
615  case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_AVAIL:
616  case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_REQUIRED:
617  wa_level = KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_REQUIRED;
618  break;
619  default:
620  return -EINVAL;
621  }
622 
623  /*
624  * We can deal with NOT_AVAIL on NOT_REQUIRED, but not the
625  * other way around.
626  */
627  if (get_kernel_wa_level(reg->id) < wa_level)
628  return -EINVAL;
629 
630  return 0;
631  case KVM_REG_ARM_STD_BMAP:
632  case KVM_REG_ARM_STD_HYP_BMAP:
633  case KVM_REG_ARM_VENDOR_HYP_BMAP:
634  return kvm_arm_set_fw_reg_bmap(vcpu, reg->id, val);
635  default:
636  return -ENOENT;
637  }
638 
639  return -EINVAL;
640 }
#define KVM_ARM_PSCI_1_0
Definition: arm_psci.h:15
#define KVM_ARM_PSCI_0_1
Definition: arm_psci.h:13
#define KVM_ARM_PSCI_0_2
Definition: arm_psci.h:14
#define KVM_ARM_PSCI_1_1
Definition: arm_psci.h:16
static int kvm_arm_set_fw_reg_bmap(struct kvm_vcpu *vcpu, u64 reg_id, u64 val)
Definition: hypercalls.c:510
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_arm_teardown_hypercalls()

void kvm_arm_teardown_hypercalls ( struct kvm *  kvm)

Definition at line 403 of file hypercalls.c.

404 {
405  mtree_destroy(&kvm->arch.smccc_filter);
406 }
Here is the caller graph for this function:

◆ kvm_smccc_call_handler()

int kvm_smccc_call_handler ( struct kvm_vcpu *  vcpu)

Definition at line 263 of file hypercalls.c.

264 {
265  struct kvm_smccc_features *smccc_feat = &vcpu->kvm->arch.smccc_feat;
266  u32 func_id = smccc_get_function(vcpu);
267  u64 val[4] = {SMCCC_RET_NOT_SUPPORTED};
268  u32 feature;
269  u8 action;
270  gpa_t gpa;
271 
272  action = kvm_smccc_get_action(vcpu, func_id);
273  switch (action) {
274  case KVM_SMCCC_FILTER_HANDLE:
275  break;
276  case KVM_SMCCC_FILTER_DENY:
277  goto out;
278  case KVM_SMCCC_FILTER_FWD_TO_USER:
279  kvm_prepare_hypercall_exit(vcpu, func_id);
280  return 0;
281  default:
282  WARN_RATELIMIT(1, "Unhandled SMCCC filter action: %d\n", action);
283  goto out;
284  }
285 
286  switch (func_id) {
287  case ARM_SMCCC_VERSION_FUNC_ID:
288  val[0] = ARM_SMCCC_VERSION_1_1;
289  break;
290  case ARM_SMCCC_ARCH_FEATURES_FUNC_ID:
291  feature = smccc_get_arg1(vcpu);
292  switch (feature) {
293  case ARM_SMCCC_ARCH_WORKAROUND_1:
294  switch (arm64_get_spectre_v2_state()) {
295  case SPECTRE_VULNERABLE:
296  break;
297  case SPECTRE_MITIGATED:
298  val[0] = SMCCC_RET_SUCCESS;
299  break;
300  case SPECTRE_UNAFFECTED:
301  val[0] = SMCCC_ARCH_WORKAROUND_RET_UNAFFECTED;
302  break;
303  }
304  break;
305  case ARM_SMCCC_ARCH_WORKAROUND_2:
306  switch (arm64_get_spectre_v4_state()) {
307  case SPECTRE_VULNERABLE:
308  break;
309  case SPECTRE_MITIGATED:
310  /*
311  * SSBS everywhere: Indicate no firmware
312  * support, as the SSBS support will be
313  * indicated to the guest and the default is
314  * safe.
315  *
316  * Otherwise, expose a permanent mitigation
317  * to the guest, and hide SSBS so that the
318  * guest stays protected.
319  */
320  if (cpus_have_final_cap(ARM64_SSBS))
321  break;
322  fallthrough;
323  case SPECTRE_UNAFFECTED:
324  val[0] = SMCCC_RET_NOT_REQUIRED;
325  break;
326  }
327  break;
328  case ARM_SMCCC_ARCH_WORKAROUND_3:
329  switch (arm64_get_spectre_bhb_state()) {
330  case SPECTRE_VULNERABLE:
331  break;
332  case SPECTRE_MITIGATED:
333  val[0] = SMCCC_RET_SUCCESS;
334  break;
335  case SPECTRE_UNAFFECTED:
336  val[0] = SMCCC_ARCH_WORKAROUND_RET_UNAFFECTED;
337  break;
338  }
339  break;
340  case ARM_SMCCC_HV_PV_TIME_FEATURES:
341  if (test_bit(KVM_REG_ARM_STD_HYP_BIT_PV_TIME,
342  &smccc_feat->std_hyp_bmap))
343  val[0] = SMCCC_RET_SUCCESS;
344  break;
345  }
346  break;
347  case ARM_SMCCC_HV_PV_TIME_FEATURES:
348  val[0] = kvm_hypercall_pv_features(vcpu);
349  break;
350  case ARM_SMCCC_HV_PV_TIME_ST:
351  gpa = kvm_init_stolen_time(vcpu);
352  if (gpa != INVALID_GPA)
353  val[0] = gpa;
354  break;
355  case ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID:
356  val[0] = ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_0;
357  val[1] = ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_1;
358  val[2] = ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_2;
359  val[3] = ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_3;
360  break;
361  case ARM_SMCCC_VENDOR_HYP_KVM_FEATURES_FUNC_ID:
362  val[0] = smccc_feat->vendor_hyp_bmap;
363  break;
364  case ARM_SMCCC_VENDOR_HYP_KVM_PTP_FUNC_ID:
365  kvm_ptp_get_time(vcpu, val);
366  break;
367  case ARM_SMCCC_TRNG_VERSION:
368  case ARM_SMCCC_TRNG_FEATURES:
369  case ARM_SMCCC_TRNG_GET_UUID:
370  case ARM_SMCCC_TRNG_RND32:
371  case ARM_SMCCC_TRNG_RND64:
372  return kvm_trng_call(vcpu);
373  default:
374  return kvm_psci_call(vcpu);
375  }
376 
377 out:
378  smccc_set_retval(vcpu, val[0], val[1], val[2], val[3]);
379  return 1;
380 }
static u32 smccc_get_function(struct kvm_vcpu *vcpu)
static unsigned long smccc_get_arg1(struct kvm_vcpu *vcpu)
static void smccc_set_retval(struct kvm_vcpu *vcpu, unsigned long a0, unsigned long a1, unsigned long a2, unsigned long a3)
static u8 kvm_smccc_get_action(struct kvm_vcpu *vcpu, u32 func_id)
Definition: hypercalls.c:227
static void kvm_ptp_get_time(struct kvm_vcpu *vcpu, u64 *val)
Definition: hypercalls.c:19
static void kvm_prepare_hypercall_exit(struct kvm_vcpu *vcpu, u32 func_id)
Definition: hypercalls.c:244
int kvm_psci_call(struct kvm_vcpu *vcpu)
Definition: psci.c:439
long kvm_hypercall_pv_features(struct kvm_vcpu *vcpu)
Definition: pvtime.c:35
gpa_t kvm_init_stolen_time(struct kvm_vcpu *vcpu)
Definition: pvtime.c:51
int kvm_trng_call(struct kvm_vcpu *vcpu)
Definition: trng.c:51
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_vm_smccc_has_attr()

int kvm_vm_smccc_has_attr ( struct kvm *  kvm,
struct kvm_device_attr *  attr 
)

Definition at line 642 of file hypercalls.c.

643 {
644  switch (attr->attr) {
645  case KVM_ARM_VM_SMCCC_FILTER:
646  return 0;
647  default:
648  return -ENXIO;
649  }
650 }
Here is the caller graph for this function:

◆ kvm_vm_smccc_set_attr()

int kvm_vm_smccc_set_attr ( struct kvm *  kvm,
struct kvm_device_attr *  attr 
)

Definition at line 652 of file hypercalls.c.

653 {
654  void __user *uaddr = (void __user *)attr->addr;
655 
656  switch (attr->attr) {
657  case KVM_ARM_VM_SMCCC_FILTER:
658  return kvm_smccc_set_filter(kvm, uaddr);
659  default:
660  return -ENXIO;
661  }
662 }
static int kvm_smccc_set_filter(struct kvm *kvm, struct kvm_smccc_filter __user *uaddr)
Definition: hypercalls.c:170
Here is the call graph for this function:
Here is the caller graph for this function:

◆ smccc_get_arg1()

static unsigned long smccc_get_arg1 ( struct kvm_vcpu *  vcpu)
inlinestatic

Definition at line 16 of file arm_hypercalls.h.

17 {
18  return vcpu_get_reg(vcpu, 1);
19 }
Here is the caller graph for this function:

◆ smccc_get_arg2()

static unsigned long smccc_get_arg2 ( struct kvm_vcpu *  vcpu)
inlinestatic

Definition at line 21 of file arm_hypercalls.h.

22 {
23  return vcpu_get_reg(vcpu, 2);
24 }
Here is the caller graph for this function:

◆ smccc_get_arg3()

static unsigned long smccc_get_arg3 ( struct kvm_vcpu *  vcpu)
inlinestatic

Definition at line 26 of file arm_hypercalls.h.

27 {
28  return vcpu_get_reg(vcpu, 3);
29 }
Here is the caller graph for this function:

◆ smccc_get_function()

static u32 smccc_get_function ( struct kvm_vcpu *  vcpu)
inlinestatic

Definition at line 11 of file arm_hypercalls.h.

12 {
13  return vcpu_get_reg(vcpu, 0);
14 }
Here is the caller graph for this function:

◆ smccc_set_retval()

static void smccc_set_retval ( struct kvm_vcpu *  vcpu,
unsigned long  a0,
unsigned long  a1,
unsigned long  a2,
unsigned long  a3 
)
inlinestatic

Definition at line 31 of file arm_hypercalls.h.

36 {
37  vcpu_set_reg(vcpu, 0, a0);
38  vcpu_set_reg(vcpu, 1, a1);
39  vcpu_set_reg(vcpu, 2, a2);
40  vcpu_set_reg(vcpu, 3, a3);
41 }
Here is the caller graph for this function: