KVM
Classes | Macros | Enumerations | Functions | Variables
arm_vgic.h File Reference
#include <linux/bits.h>
#include <linux/kvm.h>
#include <linux/irqreturn.h>
#include <linux/kref.h>
#include <linux/mutex.h>
#include <linux/spinlock.h>
#include <linux/static_key.h>
#include <linux/types.h>
#include <kvm/iodev.h>
#include <linux/list.h>
#include <linux/jump_label.h>
#include <linux/irqchip/arm-gic-v4.h>
Include dependency graph for arm_vgic.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  vgic_global
 
struct  irq_ops
 
struct  vgic_irq
 
struct  vgic_io_device
 
struct  vgic_its
 
struct  vgic_redist_region
 
struct  vgic_dist
 
struct  vgic_v2_cpu_if
 
struct  vgic_v3_cpu_if
 
struct  vgic_cpu
 

Macros

#define VGIC_V3_MAX_CPUS   512
 
#define VGIC_V2_MAX_CPUS   8
 
#define VGIC_NR_IRQS_LEGACY   256
 
#define VGIC_NR_SGIS   16
 
#define VGIC_NR_PPIS   16
 
#define VGIC_NR_PRIVATE_IRQS   (VGIC_NR_SGIS + VGIC_NR_PPIS)
 
#define VGIC_MAX_PRIVATE   (VGIC_NR_PRIVATE_IRQS - 1)
 
#define VGIC_MAX_SPI   1019
 
#define VGIC_MAX_RESERVED   1023
 
#define VGIC_MIN_LPI   8192
 
#define KVM_IRQCHIP_NUM_PINS   (1020 - 32)
 
#define irq_is_ppi(irq)   ((irq) >= VGIC_NR_SGIS && (irq) < VGIC_NR_PRIVATE_IRQS)
 
#define irq_is_spi(irq)
 
#define VGIC_V2_MAX_LRS   (1 << 6)
 
#define VGIC_V3_MAX_LRS   16
 
#define VGIC_V3_LR_INDEX(lr)   (VGIC_V3_MAX_LRS - 1 - lr)
 
#define VGIC_IRQ_SW_RESAMPLE   BIT(0) /* Clear the active state for resampling */
 
#define KVM_VGIC_IMP_REV_2   2 /* GICv2 restorable groups */
 
#define KVM_VGIC_IMP_REV_3   3 /* GICv3 GICR_CTLR.{IW,CES,RWP} */
 
#define KVM_VGIC_IMP_REV_LATEST   KVM_VGIC_IMP_REV_3
 
#define irqchip_in_kernel(k)   (!!((k)->arch.vgic.in_kernel))
 
#define vgic_initialized(k)   ((k)->arch.vgic.initialized)
 
#define vgic_ready(k)   ((k)->arch.vgic.ready)
 
#define vgic_valid_spi(k, i)
 

Enumerations

enum  vgic_type { VGIC_V2 , VGIC_V3 }
 
enum  vgic_irq_config { VGIC_CONFIG_EDGE = 0 , VGIC_CONFIG_LEVEL }
 
enum  iodev_type { IODEV_CPUIF , IODEV_DIST , IODEV_REDIST , IODEV_ITS }
 

Functions

static bool vgic_irq_needs_resampling (struct vgic_irq *irq)
 
int kvm_set_legacy_vgic_v2_addr (struct kvm *kvm, struct kvm_arm_device_addr *dev_addr)
 
void kvm_vgic_early_init (struct kvm *kvm)
 
int kvm_vgic_vcpu_init (struct kvm_vcpu *vcpu)
 
int kvm_vgic_create (struct kvm *kvm, u32 type)
 
void kvm_vgic_destroy (struct kvm *kvm)
 
void kvm_vgic_vcpu_destroy (struct kvm_vcpu *vcpu)
 
int kvm_vgic_map_resources (struct kvm *kvm)
 
int kvm_vgic_hyp_init (void)
 
void kvm_vgic_init_cpu_hardware (void)
 
int kvm_vgic_inject_irq (struct kvm *kvm, struct kvm_vcpu *vcpu, unsigned int intid, bool level, void *owner)
 
int kvm_vgic_map_phys_irq (struct kvm_vcpu *vcpu, unsigned int host_irq, u32 vintid, struct irq_ops *ops)
 
int kvm_vgic_unmap_phys_irq (struct kvm_vcpu *vcpu, unsigned int vintid)
 
int kvm_vgic_get_map (struct kvm_vcpu *vcpu, unsigned int vintid)
 
bool kvm_vgic_map_is_active (struct kvm_vcpu *vcpu, unsigned int vintid)
 
int kvm_vgic_vcpu_pending_irq (struct kvm_vcpu *vcpu)
 
void kvm_vgic_load (struct kvm_vcpu *vcpu)
 
void kvm_vgic_put (struct kvm_vcpu *vcpu)
 
void kvm_vgic_vmcr_sync (struct kvm_vcpu *vcpu)
 
bool kvm_vcpu_has_pending_irqs (struct kvm_vcpu *vcpu)
 
void kvm_vgic_sync_hwstate (struct kvm_vcpu *vcpu)
 
void kvm_vgic_flush_hwstate (struct kvm_vcpu *vcpu)
 
void kvm_vgic_reset_mapped_irq (struct kvm_vcpu *vcpu, u32 vintid)
 
void vgic_v3_dispatch_sgi (struct kvm_vcpu *vcpu, u64 reg, bool allow_group1)
 
static int kvm_vgic_get_max_vcpus (void)
 
int kvm_vgic_setup_default_irq_routing (struct kvm *kvm)
 
int kvm_vgic_set_owner (struct kvm_vcpu *vcpu, unsigned int intid, void *owner)
 
int kvm_vgic_v4_set_forwarding (struct kvm *kvm, int irq, struct kvm_kernel_irq_routing_entry *irq_entry)
 
int kvm_vgic_v4_unset_forwarding (struct kvm *kvm, int irq, struct kvm_kernel_irq_routing_entry *irq_entry)
 
int vgic_v4_load (struct kvm_vcpu *vcpu)
 
void vgic_v4_commit (struct kvm_vcpu *vcpu)
 
int vgic_v4_put (struct kvm_vcpu *vcpu)
 
void kvm_vgic_cpu_up (void)
 
void kvm_vgic_cpu_down (void)
 

Variables

struct vgic_global kvm_vgic_global_state
 
struct static_key_false vgic_v2_cpuif_trap
 
struct static_key_false vgic_v3_cpuif_trap
 

Macro Definition Documentation

◆ irq_is_ppi

#define irq_is_ppi (   irq)    ((irq) >= VGIC_NR_SGIS && (irq) < VGIC_NR_PRIVATE_IRQS)

Definition at line 34 of file arm_vgic.h.

◆ irq_is_spi

#define irq_is_spi (   irq)
Value:
((irq) >= VGIC_NR_PRIVATE_IRQS && \
(irq) <= VGIC_MAX_SPI)
#define VGIC_MAX_SPI
Definition: arm_vgic.h:29
#define VGIC_NR_PRIVATE_IRQS
Definition: arm_vgic.h:27

Definition at line 35 of file arm_vgic.h.

◆ irqchip_in_kernel

#define irqchip_in_kernel (   k)    (!!((k)->arch.vgic.in_kernel))

Definition at line 392 of file arm_vgic.h.

◆ KVM_IRQCHIP_NUM_PINS

#define KVM_IRQCHIP_NUM_PINS   (1020 - 32)

Definition at line 32 of file arm_vgic.h.

◆ KVM_VGIC_IMP_REV_2

#define KVM_VGIC_IMP_REV_2   2 /* GICv2 restorable groups */

Definition at line 234 of file arm_vgic.h.

◆ KVM_VGIC_IMP_REV_3

#define KVM_VGIC_IMP_REV_3   3 /* GICv3 GICR_CTLR.{IW,CES,RWP} */

Definition at line 235 of file arm_vgic.h.

◆ KVM_VGIC_IMP_REV_LATEST

#define KVM_VGIC_IMP_REV_LATEST   KVM_VGIC_IMP_REV_3

Definition at line 236 of file arm_vgic.h.

◆ vgic_initialized

#define vgic_initialized (   k)    ((k)->arch.vgic.initialized)

Definition at line 393 of file arm_vgic.h.

◆ VGIC_IRQ_SW_RESAMPLE

#define VGIC_IRQ_SW_RESAMPLE   BIT(0) /* Clear the active state for resampling */

Definition at line 107 of file arm_vgic.h.

◆ VGIC_MAX_PRIVATE

#define VGIC_MAX_PRIVATE   (VGIC_NR_PRIVATE_IRQS - 1)

Definition at line 28 of file arm_vgic.h.

◆ VGIC_MAX_RESERVED

#define VGIC_MAX_RESERVED   1023

Definition at line 30 of file arm_vgic.h.

◆ VGIC_MAX_SPI

#define VGIC_MAX_SPI   1019

Definition at line 29 of file arm_vgic.h.

◆ VGIC_MIN_LPI

#define VGIC_MIN_LPI   8192

Definition at line 31 of file arm_vgic.h.

◆ VGIC_NR_IRQS_LEGACY

#define VGIC_NR_IRQS_LEGACY   256

Definition at line 24 of file arm_vgic.h.

◆ VGIC_NR_PPIS

#define VGIC_NR_PPIS   16

Definition at line 26 of file arm_vgic.h.

◆ VGIC_NR_PRIVATE_IRQS

#define VGIC_NR_PRIVATE_IRQS   (VGIC_NR_SGIS + VGIC_NR_PPIS)

Definition at line 27 of file arm_vgic.h.

◆ VGIC_NR_SGIS

#define VGIC_NR_SGIS   16

Definition at line 25 of file arm_vgic.h.

◆ vgic_ready

#define vgic_ready (   k)    ((k)->arch.vgic.ready)

Definition at line 394 of file arm_vgic.h.

◆ VGIC_V2_MAX_CPUS

#define VGIC_V2_MAX_CPUS   8

Definition at line 23 of file arm_vgic.h.

◆ VGIC_V2_MAX_LRS

#define VGIC_V2_MAX_LRS   (1 << 6)

Definition at line 88 of file arm_vgic.h.

◆ VGIC_V3_LR_INDEX

#define VGIC_V3_LR_INDEX (   lr)    (VGIC_V3_MAX_LRS - 1 - lr)

Definition at line 90 of file arm_vgic.h.

◆ VGIC_V3_MAX_CPUS

#define VGIC_V3_MAX_CPUS   512

Definition at line 22 of file arm_vgic.h.

◆ VGIC_V3_MAX_LRS

#define VGIC_V3_MAX_LRS   16

Definition at line 89 of file arm_vgic.h.

◆ vgic_valid_spi

#define vgic_valid_spi (   k,
 
)
Value:
(((i) >= VGIC_NR_PRIVATE_IRQS) && \
((i) < (k)->arch.vgic.nr_spis + VGIC_NR_PRIVATE_IRQS))

Definition at line 395 of file arm_vgic.h.

Enumeration Type Documentation

◆ iodev_type

enum iodev_type
Enumerator
IODEV_CPUIF 
IODEV_DIST 
IODEV_REDIST 
IODEV_ITS 

Definition at line 168 of file arm_vgic.h.

168  {
169  IODEV_CPUIF,
170  IODEV_DIST,
171  IODEV_REDIST,
172  IODEV_ITS
173 };
@ IODEV_REDIST
Definition: arm_vgic.h:171
@ IODEV_ITS
Definition: arm_vgic.h:172
@ IODEV_CPUIF
Definition: arm_vgic.h:169
@ IODEV_DIST
Definition: arm_vgic.h:170

◆ vgic_irq_config

Enumerator
VGIC_CONFIG_EDGE 
VGIC_CONFIG_LEVEL 

Definition at line 92 of file arm_vgic.h.

92  {
93  VGIC_CONFIG_EDGE = 0,
95 };
@ VGIC_CONFIG_EDGE
Definition: arm_vgic.h:93
@ VGIC_CONFIG_LEVEL
Definition: arm_vgic.h:94

◆ vgic_type

enum vgic_type
Enumerator
VGIC_V2 
VGIC_V3 

Definition at line 38 of file arm_vgic.h.

38  {
39  VGIC_V2, /* Good ol' GICv2 */
40  VGIC_V3, /* New fancy GICv3 */
41 };
@ VGIC_V3
Definition: arm_vgic.h:40
@ VGIC_V2
Definition: arm_vgic.h:39

Function Documentation

◆ kvm_set_legacy_vgic_v2_addr()

int kvm_set_legacy_vgic_v2_addr ( struct kvm *  kvm,
struct kvm_arm_device_addr *  dev_addr 
)

Definition at line 45 of file vgic-kvm-device.c.

46 {
47  struct vgic_dist *vgic = &kvm->arch.vgic;
48  int r;
49 
50  mutex_lock(&kvm->arch.config_lock);
51  switch (FIELD_GET(KVM_ARM_DEVICE_TYPE_MASK, dev_addr->id)) {
52  case KVM_VGIC_V2_ADDR_TYPE_DIST:
53  r = vgic_check_type(kvm, KVM_DEV_TYPE_ARM_VGIC_V2);
54  if (!r)
55  r = vgic_check_iorange(kvm, vgic->vgic_dist_base, dev_addr->addr,
56  SZ_4K, KVM_VGIC_V2_DIST_SIZE);
57  if (!r)
58  vgic->vgic_dist_base = dev_addr->addr;
59  break;
60  case KVM_VGIC_V2_ADDR_TYPE_CPU:
61  r = vgic_check_type(kvm, KVM_DEV_TYPE_ARM_VGIC_V2);
62  if (!r)
63  r = vgic_check_iorange(kvm, vgic->vgic_cpu_base, dev_addr->addr,
64  SZ_4K, KVM_VGIC_V2_CPU_SIZE);
65  if (!r)
66  vgic->vgic_cpu_base = dev_addr->addr;
67  break;
68  default:
69  r = -ENODEV;
70  }
71 
72  mutex_unlock(&kvm->arch.config_lock);
73 
74  return r;
75 }
gpa_t vgic_dist_base
Definition: arm_vgic.h:247
gpa_t vgic_cpu_base
Definition: arm_vgic.h:250
static int vgic_check_type(struct kvm *kvm, int type_needed)
int vgic_check_iorange(struct kvm *kvm, phys_addr_t ioaddr, phys_addr_t addr, phys_addr_t alignment, phys_addr_t size)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_vcpu_has_pending_irqs()

bool kvm_vcpu_has_pending_irqs ( struct kvm_vcpu *  vcpu)

◆ kvm_vgic_cpu_down()

void kvm_vgic_cpu_down ( void  )

Definition at line 513 of file vgic-init.c.

514 {
515  disable_percpu_irq(kvm_vgic_global_state.maint_irq);
516 }
struct vgic_global kvm_vgic_global_state
unsigned int maint_irq
Definition: arm_vgic.h:65
Here is the caller graph for this function:

◆ kvm_vgic_cpu_up()

void kvm_vgic_cpu_up ( void  )

Definition at line 507 of file vgic-init.c.

508 {
509  enable_percpu_irq(kvm_vgic_global_state.maint_irq, 0);
510 }
Here is the caller graph for this function:

◆ kvm_vgic_create()

int kvm_vgic_create ( struct kvm *  kvm,
u32  type 
)

kvm_vgic_create: triggered by the instantiation of the VGIC device by user space, either through the legacy KVM_CREATE_IRQCHIP ioctl (v2 only) or through the generic KVM_CREATE_DEVICE API ioctl. irqchip_in_kernel() tells you if this function succeeded or not. @kvm: kvm struct pointer @type: KVM_DEV_TYPE_ARM_VGIC_V[23]

Definition at line 71 of file vgic-init.c.

72 {
73  struct kvm_vcpu *vcpu;
74  unsigned long i;
75  int ret;
76 
77  /*
78  * This function is also called by the KVM_CREATE_IRQCHIP handler,
79  * which had no chance yet to check the availability of the GICv2
80  * emulation. So check this here again. KVM_CREATE_DEVICE does
81  * the proper checks already.
82  */
83  if (type == KVM_DEV_TYPE_ARM_VGIC_V2 &&
85  return -ENODEV;
86 
87  /* Must be held to avoid race with vCPU creation */
88  lockdep_assert_held(&kvm->lock);
89 
90  ret = -EBUSY;
91  if (!lock_all_vcpus(kvm))
92  return ret;
93 
94  mutex_lock(&kvm->arch.config_lock);
95 
96  if (irqchip_in_kernel(kvm)) {
97  ret = -EEXIST;
98  goto out_unlock;
99  }
100 
101  kvm_for_each_vcpu(i, vcpu, kvm) {
102  if (vcpu_has_run_once(vcpu))
103  goto out_unlock;
104  }
105  ret = 0;
106 
107  if (type == KVM_DEV_TYPE_ARM_VGIC_V2)
108  kvm->max_vcpus = VGIC_V2_MAX_CPUS;
109  else
110  kvm->max_vcpus = VGIC_V3_MAX_CPUS;
111 
112  if (atomic_read(&kvm->online_vcpus) > kvm->max_vcpus) {
113  ret = -E2BIG;
114  goto out_unlock;
115  }
116 
117  kvm->arch.vgic.in_kernel = true;
118  kvm->arch.vgic.vgic_model = type;
119 
120  kvm->arch.vgic.vgic_dist_base = VGIC_ADDR_UNDEF;
121 
122  if (type == KVM_DEV_TYPE_ARM_VGIC_V2)
123  kvm->arch.vgic.vgic_cpu_base = VGIC_ADDR_UNDEF;
124  else
125  INIT_LIST_HEAD(&kvm->arch.vgic.rd_regions);
126 
127 out_unlock:
128  mutex_unlock(&kvm->arch.config_lock);
129  unlock_all_vcpus(kvm);
130  return ret;
131 }
bool lock_all_vcpus(struct kvm *kvm)
Definition: arm.c:1773
void unlock_all_vcpus(struct kvm *kvm)
Definition: arm.c:1765
#define VGIC_V3_MAX_CPUS
Definition: arm_vgic.h:22
#define irqchip_in_kernel(k)
Definition: arm_vgic.h:392
#define VGIC_V2_MAX_CPUS
Definition: arm_vgic.h:23
bool can_emulate_gicv2
Definition: arm_vgic.h:71
#define VGIC_ADDR_UNDEF
Definition: vgic.h:14
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_vgic_destroy()

void kvm_vgic_destroy ( struct kvm *  kvm)

Definition at line 397 of file vgic-init.c.

398 {
399  struct kvm_vcpu *vcpu;
400  unsigned long i;
401 
402  mutex_lock(&kvm->slots_lock);
403 
404  vgic_debug_destroy(kvm);
405 
406  kvm_for_each_vcpu(i, vcpu, kvm)
408 
409  mutex_lock(&kvm->arch.config_lock);
410 
412 
413  mutex_unlock(&kvm->arch.config_lock);
414  mutex_unlock(&kvm->slots_lock);
415 }
void vgic_debug_destroy(struct kvm *kvm)
Definition: vgic-debug.c:278
static void __kvm_vgic_vcpu_destroy(struct kvm_vcpu *vcpu)
Definition: vgic-init.c:371
static void kvm_vgic_dist_destroy(struct kvm *kvm)
Definition: vgic-init.c:343
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_vgic_early_init()

void kvm_vgic_early_init ( struct kvm *  kvm)

kvm_vgic_early_init() - Initialize static VGIC VCPU data structures @kvm: The VM whose VGIC districutor should be initialized

Only do initialization of static structures that don't require any allocation or sizing information from userspace. vgic_init() called kvm_vgic_dist_init() which takes care of the rest.

Definition at line 52 of file vgic-init.c.

53 {
54  struct vgic_dist *dist = &kvm->arch.vgic;
55 
56  INIT_LIST_HEAD(&dist->lpi_list_head);
57  INIT_LIST_HEAD(&dist->lpi_translation_cache);
58  raw_spin_lock_init(&dist->lpi_list_lock);
59 }
struct list_head lpi_translation_cache
Definition: arm_vgic.h:282
struct list_head lpi_list_head
Definition: arm_vgic.h:278
raw_spinlock_t lpi_list_lock
Definition: arm_vgic.h:277
Here is the caller graph for this function:

◆ kvm_vgic_flush_hwstate()

void kvm_vgic_flush_hwstate ( struct kvm_vcpu *  vcpu)

Definition at line 905 of file vgic.c.

906 {
907  /*
908  * If there are no virtual interrupts active or pending for this
909  * VCPU, then there is no work to do and we can bail out without
910  * taking any lock. There is a potential race with someone injecting
911  * interrupts to the VCPU, but it is a benign race as the VCPU will
912  * either observe the new interrupt before or after doing this check,
913  * and introducing additional synchronization mechanism doesn't change
914  * this.
915  *
916  * Note that we still need to go through the whole thing if anything
917  * can be directly injected (GICv4).
918  */
919  if (list_empty(&vcpu->arch.vgic_cpu.ap_list_head) &&
920  !vgic_supports_direct_msis(vcpu->kvm))
921  return;
922 
923  DEBUG_SPINLOCK_BUG_ON(!irqs_disabled());
924 
925  if (!list_empty(&vcpu->arch.vgic_cpu.ap_list_head)) {
926  raw_spin_lock(&vcpu->arch.vgic_cpu.ap_list_lock);
927  vgic_flush_lr_state(vcpu);
928  raw_spin_unlock(&vcpu->arch.vgic_cpu.ap_list_lock);
929  }
930 
932  vgic_restore_state(vcpu);
933 
934  if (vgic_supports_direct_msis(vcpu->kvm))
935  vgic_v4_commit(vcpu);
936 }
bool vgic_supports_direct_msis(struct kvm *kvm)
Definition: vgic-mmio-v3.c:51
void vgic_v4_commit(struct kvm_vcpu *vcpu)
Definition: vgic-v4.c:385
static void vgic_restore_state(struct kvm_vcpu *vcpu)
Definition: vgic.c:896
static void vgic_flush_lr_state(struct kvm_vcpu *vcpu)
Definition: vgic.c:797
static bool can_access_vgic_from_kernel(void)
Definition: vgic.c:856
#define DEBUG_SPINLOCK_BUG_ON(p)
Definition: vgic.h:99
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_vgic_get_map()

int kvm_vgic_get_map ( struct kvm_vcpu *  vcpu,
unsigned int  vintid 
)

Definition at line 576 of file vgic.c.

577 {
578  struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, vcpu, vintid);
579  unsigned long flags;
580  int ret = -1;
581 
582  raw_spin_lock_irqsave(&irq->irq_lock, flags);
583  if (irq->hw)
584  ret = irq->hwintid;
585  raw_spin_unlock_irqrestore(&irq->irq_lock, flags);
586 
587  vgic_put_irq(vcpu->kvm, irq);
588  return ret;
589 }
struct kvm_vcpu * vcpu
Definition: arm_vgic.h:122
bool hw
Definition: arm_vgic.h:140
u32 hwintid
Definition: arm_vgic.h:142
raw_spinlock_t irq_lock
Definition: arm_vgic.h:118
struct vgic_irq * vgic_get_irq(struct kvm *kvm, struct kvm_vcpu *vcpu, u32 intid)
Definition: vgic.c:92
void vgic_put_irq(struct kvm *kvm, struct vgic_irq *irq)
Definition: vgic.c:139
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_vgic_get_max_vcpus()

static int kvm_vgic_get_max_vcpus ( void  )
inlinestatic

kvm_vgic_get_max_vcpus - Get the maximum number of VCPUs allowed by HW

The host's GIC naturally limits the maximum amount of VCPUs a guest can use.

Definition at line 411 of file arm_vgic.h.

412 {
414 }
int max_gic_vcpus
Definition: arm_vgic.h:68
Here is the caller graph for this function:

◆ kvm_vgic_hyp_init()

int kvm_vgic_hyp_init ( void  )

kvm_vgic_hyp_init: populates the kvm_vgic_global_state variable according to the host GIC model. Accordingly calls either vgic_v2/v3_probe which registers the KVM_DEVICE that can be instantiated by a guest later on .

Definition at line 564 of file vgic-init.c.

565 {
566  bool has_mask;
567  int ret;
568 
569  if (!gic_kvm_info)
570  return -ENODEV;
571 
572  has_mask = !gic_kvm_info->no_maint_irq_mask;
573 
574  if (has_mask && !gic_kvm_info->maint_irq) {
575  kvm_err("No vgic maintenance irq\n");
576  return -ENXIO;
577  }
578 
579  /*
580  * If we get one of these oddball non-GICs, taint the kernel,
581  * as we have no idea of how they *really* behave.
582  */
583  if (gic_kvm_info->no_hw_deactivation) {
584  kvm_info("Non-architectural vgic, tainting kernel\n");
585  add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_STILL_OK);
587  }
588 
589  switch (gic_kvm_info->type) {
590  case GIC_V2:
592  break;
593  case GIC_V3:
595  if (!ret) {
596  static_branch_enable(&kvm_vgic_global_state.gicv3_cpuif);
597  kvm_info("GIC system register CPU interface enabled\n");
598  }
599  break;
600  default:
601  ret = -ENODEV;
602  }
603 
605 
606  kfree(gic_kvm_info);
607  gic_kvm_info = NULL;
608 
609  if (ret)
610  return ret;
611 
612  if (!has_mask && !kvm_vgic_global_state.maint_irq)
613  return 0;
614 
615  ret = request_percpu_irq(kvm_vgic_global_state.maint_irq,
617  "vgic", kvm_get_running_vcpus());
618  if (ret) {
619  kvm_err("Cannot register interrupt %d\n",
621  return ret;
622  }
623 
624  kvm_info("vgic interrupt IRQ%d\n", kvm_vgic_global_state.maint_irq);
625  return 0;
626 }
struct kvm_vcpu *__percpu * kvm_get_running_vcpus(void)
Definition: kvm_main.c:6353
struct static_key_false gicv3_cpuif
Definition: arm_vgic.h:81
bool no_hw_deactivation
Definition: arm_vgic.h:78
static irqreturn_t vgic_maintenance_handler(int irq, void *data)
Definition: vgic-init.c:518
static struct gic_kvm_info * gic_kvm_info
Definition: vgic-init.c:529
int vgic_v2_probe(const struct gic_kvm_info *info)
Definition: vgic-v2.c:337
int vgic_v3_probe(const struct gic_kvm_info *info)
Definition: vgic-v3.c:632
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_vgic_init_cpu_hardware()

void kvm_vgic_init_cpu_hardware ( void  )

kvm_vgic_init_cpu_hardware - initialize the GIC VE hardware

For a specific CPU, initialize the GIC VE hardware.

Definition at line 544 of file vgic-init.c.

545 {
546  BUG_ON(preemptible());
547 
548  /*
549  * We want to make sure the list registers start out clear so that we
550  * only have the program the used registers.
551  */
554  else
555  kvm_call_hyp(__vgic_v3_init_lrs);
556 }
enum vgic_type type
Definition: arm_vgic.h:46
void vgic_v2_init_lrs(void)
Definition: vgic-v2.c:21
void __vgic_v3_init_lrs(void)
Definition: vgic-v3-sr.c:399
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_vgic_inject_irq()

int kvm_vgic_inject_irq ( struct kvm *  kvm,
struct kvm_vcpu *  vcpu,
unsigned int  intid,
bool  level,
void *  owner 
)

kvm_vgic_inject_irq - Inject an IRQ from a device to the vgic @kvm: The VM structure pointer @vcpu: The CPU for PPIs or NULL for global interrupts @intid: The INTID to inject a new state to. @level: Edge-triggered: true: to trigger the interrupt false: to ignore the call Level-sensitive true: raise the input signal false: lower the input signal @owner: The opaque pointer to the owner of the IRQ being raised to verify that the caller is allowed to inject this IRQ. Userspace injections will have owner == NULL.

The VGIC is not concerned with devices being active-LOW or active-HIGH for level-sensitive interrupts. You can think of the level parameter as 1 being HIGH and 0 being LOW and all devices being active-HIGH.

Definition at line 439 of file vgic.c.

441 {
442  struct vgic_irq *irq;
443  unsigned long flags;
444  int ret;
445 
446  ret = vgic_lazy_init(kvm);
447  if (ret)
448  return ret;
449 
450  if (!vcpu && intid < VGIC_NR_PRIVATE_IRQS)
451  return -EINVAL;
452 
453  trace_vgic_update_irq_pending(vcpu ? vcpu->vcpu_idx : 0, intid, level);
454 
455  irq = vgic_get_irq(kvm, vcpu, intid);
456  if (!irq)
457  return -EINVAL;
458 
459  raw_spin_lock_irqsave(&irq->irq_lock, flags);
460 
461  if (!vgic_validate_injection(irq, level, owner)) {
462  /* Nothing to see here, move along... */
463  raw_spin_unlock_irqrestore(&irq->irq_lock, flags);
464  vgic_put_irq(kvm, irq);
465  return 0;
466  }
467 
468  if (irq->config == VGIC_CONFIG_LEVEL)
469  irq->line_level = level;
470  else
471  irq->pending_latch = true;
472 
473  vgic_queue_irq_unlock(kvm, irq, flags);
474  vgic_put_irq(kvm, irq);
475 
476  return 0;
477 }
u32 intid
Definition: arm_vgic.h:133
void * owner
Definition: arm_vgic.h:156
bool line_level
Definition: arm_vgic.h:134
bool pending_latch
Definition: arm_vgic.h:135
enum vgic_irq_config config
Definition: arm_vgic.h:152
int vgic_lazy_init(struct kvm *kvm)
Definition: vgic-init.c:423
static bool vgic_validate_injection(struct vgic_irq *irq, bool level, void *owner)
Definition: vgic.c:313
bool vgic_queue_irq_unlock(struct kvm *kvm, struct vgic_irq *irq, unsigned long flags)
Definition: vgic.c:336
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_vgic_load()

void kvm_vgic_load ( struct kvm_vcpu *  vcpu)

Definition at line 938 of file vgic.c.

939 {
940  if (unlikely(!vgic_initialized(vcpu->kvm)))
941  return;
942 
944  vgic_v2_load(vcpu);
945  else
946  vgic_v3_load(vcpu);
947 }
#define vgic_initialized(k)
Definition: arm_vgic.h:393
void vgic_v2_load(struct kvm_vcpu *vcpu)
Definition: vgic-v2.c:457
void vgic_v3_load(struct kvm_vcpu *vcpu)
Definition: vgic-v3.c:720
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_vgic_map_is_active()

bool kvm_vgic_map_is_active ( struct kvm_vcpu *  vcpu,
unsigned int  vintid 
)

Definition at line 1022 of file vgic.c.

1023 {
1024  struct vgic_irq *irq;
1025  bool map_is_active;
1026  unsigned long flags;
1027 
1028  if (!vgic_initialized(vcpu->kvm))
1029  return false;
1030 
1031  irq = vgic_get_irq(vcpu->kvm, vcpu, vintid);
1032  raw_spin_lock_irqsave(&irq->irq_lock, flags);
1033  map_is_active = irq->hw && irq->active;
1034  raw_spin_unlock_irqrestore(&irq->irq_lock, flags);
1035  vgic_put_irq(vcpu->kvm, irq);
1036 
1037  return map_is_active;
1038 }
bool active
Definition: arm_vgic.h:138
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_vgic_map_phys_irq()

int kvm_vgic_map_phys_irq ( struct kvm_vcpu *  vcpu,
unsigned int  host_irq,
u32  vintid,
struct irq_ops ops 
)

Definition at line 514 of file vgic.c.

516 {
517  struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, vcpu, vintid);
518  unsigned long flags;
519  int ret;
520 
521  BUG_ON(!irq);
522 
523  raw_spin_lock_irqsave(&irq->irq_lock, flags);
524  ret = kvm_vgic_map_irq(vcpu, irq, host_irq, ops);
525  raw_spin_unlock_irqrestore(&irq->irq_lock, flags);
526  vgic_put_irq(vcpu->kvm, irq);
527 
528  return ret;
529 }
struct irq_ops * ops
Definition: arm_vgic.h:154
unsigned int host_irq
Definition: arm_vgic.h:143
static int kvm_vgic_map_irq(struct kvm_vcpu *vcpu, struct vgic_irq *irq, unsigned int host_irq, struct irq_ops *ops)
Definition: vgic.c:480
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_vgic_map_resources()

int kvm_vgic_map_resources ( struct kvm *  kvm)

Map the MMIO regions depending on the VGIC model exposed to the guest called on the first VCPU run. Also map the virtual CPU interface into the VM. v2 calls vgic_init() if not already done. v3 and derivatives return an error if the VGIC is not initialized. vgic_ready() returns true if this function has succeeded. @kvm: kvm struct pointer

Definition at line 456 of file vgic-init.c.

457 {
458  struct vgic_dist *dist = &kvm->arch.vgic;
459  enum vgic_type type;
460  gpa_t dist_base;
461  int ret = 0;
462 
463  if (likely(vgic_ready(kvm)))
464  return 0;
465 
466  mutex_lock(&kvm->slots_lock);
467  mutex_lock(&kvm->arch.config_lock);
468  if (vgic_ready(kvm))
469  goto out;
470 
471  if (!irqchip_in_kernel(kvm))
472  goto out;
473 
474  if (dist->vgic_model == KVM_DEV_TYPE_ARM_VGIC_V2) {
475  ret = vgic_v2_map_resources(kvm);
476  type = VGIC_V2;
477  } else {
478  ret = vgic_v3_map_resources(kvm);
479  type = VGIC_V3;
480  }
481 
482  if (ret)
483  goto out;
484 
485  dist->ready = true;
486  dist_base = dist->vgic_dist_base;
487  mutex_unlock(&kvm->arch.config_lock);
488 
489  ret = vgic_register_dist_iodev(kvm, dist_base, type);
490  if (ret)
491  kvm_err("Unable to register VGIC dist MMIO regions\n");
492 
493  goto out_slots;
494 out:
495  mutex_unlock(&kvm->arch.config_lock);
496 out_slots:
497  mutex_unlock(&kvm->slots_lock);
498 
499  if (ret)
500  kvm_vgic_destroy(kvm);
501 
502  return ret;
503 }
vgic_type
Definition: arm_vgic.h:38
#define vgic_ready(k)
Definition: arm_vgic.h:394
u32 vgic_model
Definition: arm_vgic.h:230
bool ready
Definition: arm_vgic.h:226
void kvm_vgic_destroy(struct kvm *kvm)
Definition: vgic-init.c:397
int vgic_register_dist_iodev(struct kvm *kvm, gpa_t dist_base_address, enum vgic_type type)
Definition: vgic-mmio.c:1080
int vgic_v2_map_resources(struct kvm *kvm)
Definition: vgic-v2.c:289
int vgic_v3_map_resources(struct kvm *kvm)
Definition: vgic-v3.c:538
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_vgic_put()

void kvm_vgic_put ( struct kvm_vcpu *  vcpu)

Definition at line 949 of file vgic.c.

950 {
951  if (unlikely(!vgic_initialized(vcpu->kvm)))
952  return;
953 
955  vgic_v2_put(vcpu);
956  else
957  vgic_v3_put(vcpu);
958 }
void vgic_v2_put(struct kvm_vcpu *vcpu)
Definition: vgic-v2.c:474
void vgic_v3_put(struct kvm_vcpu *vcpu)
Definition: vgic-v3.c:748
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_vgic_reset_mapped_irq()

void kvm_vgic_reset_mapped_irq ( struct kvm_vcpu *  vcpu,
u32  vintid 
)

kvm_vgic_reset_mapped_irq - Reset a mapped IRQ @vcpu: The VCPU pointer @vintid: The INTID of the interrupt

Reset the active and pending states of a mapped interrupt. Kernel subsystems injecting mapped interrupts should reset their interrupt lines when we are doing a reset of the VM.

Definition at line 540 of file vgic.c.

541 {
542  struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, vcpu, vintid);
543  unsigned long flags;
544 
545  if (!irq->hw)
546  goto out;
547 
548  raw_spin_lock_irqsave(&irq->irq_lock, flags);
549  irq->active = false;
550  irq->pending_latch = false;
551  irq->line_level = false;
552  raw_spin_unlock_irqrestore(&irq->irq_lock, flags);
553 out:
554  vgic_put_irq(vcpu->kvm, irq);
555 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_vgic_set_owner()

int kvm_vgic_set_owner ( struct kvm_vcpu *  vcpu,
unsigned int  intid,
void *  owner 
)

kvm_vgic_set_owner - Set the owner of an interrupt for a VM

@vcpu: Pointer to the VCPU (used for PPIs) @intid: The virtual INTID identifying the interrupt (PPI or SPI) @owner: Opaque pointer to the owner

Returns 0 if intid is not already used by another in-kernel device and the owner is set, otherwise returns an error code.

Definition at line 601 of file vgic.c.

602 {
603  struct vgic_irq *irq;
604  unsigned long flags;
605  int ret = 0;
606 
607  if (!vgic_initialized(vcpu->kvm))
608  return -EAGAIN;
609 
610  /* SGIs and LPIs cannot be wired up to any device */
611  if (!irq_is_ppi(intid) && !vgic_valid_spi(vcpu->kvm, intid))
612  return -EINVAL;
613 
614  irq = vgic_get_irq(vcpu->kvm, vcpu, intid);
615  raw_spin_lock_irqsave(&irq->irq_lock, flags);
616  if (irq->owner && irq->owner != owner)
617  ret = -EEXIST;
618  else
619  irq->owner = owner;
620  raw_spin_unlock_irqrestore(&irq->irq_lock, flags);
621 
622  return ret;
623 }
#define irq_is_ppi(irq)
Definition: arm_vgic.h:34
#define vgic_valid_spi(k, i)
Definition: arm_vgic.h:395
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_vgic_setup_default_irq_routing()

int kvm_vgic_setup_default_irq_routing ( struct kvm *  kvm)

kvm_vgic_setup_default_irq_routing: Setup a default flat gsi routing table mapping all SPIs

Definition at line 135 of file vgic-irqfd.c.

136 {
137  struct kvm_irq_routing_entry *entries;
138  struct vgic_dist *dist = &kvm->arch.vgic;
139  u32 nr = dist->nr_spis;
140  int i, ret;
141 
142  entries = kcalloc(nr, sizeof(*entries), GFP_KERNEL_ACCOUNT);
143  if (!entries)
144  return -ENOMEM;
145 
146  for (i = 0; i < nr; i++) {
147  entries[i].gsi = i;
148  entries[i].type = KVM_IRQ_ROUTING_IRQCHIP;
149  entries[i].u.irqchip.irqchip = 0;
150  entries[i].u.irqchip.pin = i;
151  }
152  ret = kvm_set_irq_routing(kvm, entries, nr, 0);
153  kfree(entries);
154  return ret;
155 }
int kvm_set_irq_routing(struct kvm *kvm, const struct kvm_irq_routing_entry *ue, unsigned nr, unsigned flags)
Definition: irqchip.c:168
int nr_spis
Definition: arm_vgic.h:244
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_vgic_sync_hwstate()

void kvm_vgic_sync_hwstate ( struct kvm_vcpu *  vcpu)

Definition at line 875 of file vgic.c.

876 {
877  int used_lrs;
878 
879  /* An empty ap_list_head implies used_lrs == 0 */
880  if (list_empty(&vcpu->arch.vgic_cpu.ap_list_head))
881  return;
882 
884  vgic_save_state(vcpu);
885 
886  if (!static_branch_unlikely(&kvm_vgic_global_state.gicv3_cpuif))
887  used_lrs = vcpu->arch.vgic_cpu.vgic_v2.used_lrs;
888  else
889  used_lrs = vcpu->arch.vgic_cpu.vgic_v3.used_lrs;
890 
891  if (used_lrs)
892  vgic_fold_lr_state(vcpu);
893  vgic_prune_ap_list(vcpu);
894 }
static void vgic_save_state(struct kvm_vcpu *vcpu)
Definition: vgic.c:866
static void vgic_fold_lr_state(struct kvm_vcpu *vcpu)
Definition: vgic.c:734
static void vgic_prune_ap_list(struct kvm_vcpu *vcpu)
Definition: vgic.c:633
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_vgic_unmap_phys_irq()

int kvm_vgic_unmap_phys_irq ( struct kvm_vcpu *  vcpu,
unsigned int  vintid 
)

Definition at line 557 of file vgic.c.

558 {
559  struct vgic_irq *irq;
560  unsigned long flags;
561 
562  if (!vgic_initialized(vcpu->kvm))
563  return -EAGAIN;
564 
565  irq = vgic_get_irq(vcpu->kvm, vcpu, vintid);
566  BUG_ON(!irq);
567 
568  raw_spin_lock_irqsave(&irq->irq_lock, flags);
569  kvm_vgic_unmap_irq(irq);
570  raw_spin_unlock_irqrestore(&irq->irq_lock, flags);
571  vgic_put_irq(vcpu->kvm, irq);
572 
573  return 0;
574 }
static void kvm_vgic_unmap_irq(struct vgic_irq *irq)
Definition: vgic.c:507
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_vgic_v4_set_forwarding()

int kvm_vgic_v4_set_forwarding ( struct kvm *  kvm,
int  irq,
struct kvm_kernel_irq_routing_entry *  irq_entry 
)

Definition at line 411 of file vgic-v4.c.

413 {
414  struct vgic_its *its;
415  struct vgic_irq *irq;
416  struct its_vlpi_map map;
417  unsigned long flags;
418  int ret;
419 
420  if (!vgic_supports_direct_msis(kvm))
421  return 0;
422 
423  /*
424  * Get the ITS, and escape early on error (not a valid
425  * doorbell for any of our vITSs).
426  */
427  its = vgic_get_its(kvm, irq_entry);
428  if (IS_ERR(its))
429  return 0;
430 
431  mutex_lock(&its->its_lock);
432 
433  /* Perform the actual DevID/EventID -> LPI translation. */
434  ret = vgic_its_resolve_lpi(kvm, its, irq_entry->msi.devid,
435  irq_entry->msi.data, &irq);
436  if (ret)
437  goto out;
438 
439  /* Silently exit if the vLPI is already mapped */
440  if (irq->hw)
441  goto out;
442 
443  /*
444  * Emit the mapping request. If it fails, the ITS probably
445  * isn't v4 compatible, so let's silently bail out. Holding
446  * the ITS lock should ensure that nothing can modify the
447  * target vcpu.
448  */
449  map = (struct its_vlpi_map) {
450  .vm = &kvm->arch.vgic.its_vm,
451  .vpe = &irq->target_vcpu->arch.vgic_cpu.vgic_v3.its_vpe,
452  .vintid = irq->intid,
453  .properties = ((irq->priority & 0xfc) |
454  (irq->enabled ? LPI_PROP_ENABLED : 0) |
455  LPI_PROP_GROUP1),
456  .db_enabled = true,
457  };
458 
459  ret = its_map_vlpi(virq, &map);
460  if (ret)
461  goto out;
462 
463  irq->hw = true;
464  irq->host_irq = virq;
465  atomic_inc(&map.vpe->vlpi_count);
466 
467  /* Transfer pending state */
468  raw_spin_lock_irqsave(&irq->irq_lock, flags);
469  if (irq->pending_latch) {
470  ret = irq_set_irqchip_state(irq->host_irq,
471  IRQCHIP_STATE_PENDING,
472  irq->pending_latch);
473  WARN_RATELIMIT(ret, "IRQ %d", irq->host_irq);
474 
475  /*
476  * Clear pending_latch and communicate this state
477  * change via vgic_queue_irq_unlock.
478  */
479  irq->pending_latch = false;
480  vgic_queue_irq_unlock(kvm, irq, flags);
481  } else {
482  raw_spin_unlock_irqrestore(&irq->irq_lock, flags);
483  }
484 
485 out:
486  mutex_unlock(&its->its_lock);
487  return ret;
488 }
u8 priority
Definition: arm_vgic.h:150
bool enabled
Definition: arm_vgic.h:139
struct kvm_vcpu * target_vcpu
Definition: arm_vgic.h:127
struct mutex its_lock
Definition: arm_vgic.h:209
int vgic_its_resolve_lpi(struct kvm *kvm, struct vgic_its *its, u32 devid, u32 eventid, struct vgic_irq **irq)
Definition: vgic-its.c:682
static struct vgic_its * vgic_get_its(struct kvm *kvm, struct kvm_kernel_irq_routing_entry *irq_entry)
Definition: vgic-v4.c:397
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_vgic_v4_unset_forwarding()

int kvm_vgic_v4_unset_forwarding ( struct kvm *  kvm,
int  irq,
struct kvm_kernel_irq_routing_entry *  irq_entry 
)

Definition at line 490 of file vgic-v4.c.

492 {
493  struct vgic_its *its;
494  struct vgic_irq *irq;
495  int ret;
496 
497  if (!vgic_supports_direct_msis(kvm))
498  return 0;
499 
500  /*
501  * Get the ITS, and escape early on error (not a valid
502  * doorbell for any of our vITSs).
503  */
504  its = vgic_get_its(kvm, irq_entry);
505  if (IS_ERR(its))
506  return 0;
507 
508  mutex_lock(&its->its_lock);
509 
510  ret = vgic_its_resolve_lpi(kvm, its, irq_entry->msi.devid,
511  irq_entry->msi.data, &irq);
512  if (ret)
513  goto out;
514 
515  WARN_ON(!(irq->hw && irq->host_irq == virq));
516  if (irq->hw) {
517  atomic_dec(&irq->target_vcpu->arch.vgic_cpu.vgic_v3.its_vpe.vlpi_count);
518  irq->hw = false;
519  ret = its_unmap_vlpi(virq);
520  }
521 
522 out:
523  mutex_unlock(&its->its_lock);
524  return ret;
525 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_vgic_vcpu_destroy()

void kvm_vgic_vcpu_destroy ( struct kvm_vcpu *  vcpu)

Definition at line 388 of file vgic-init.c.

389 {
390  struct kvm *kvm = vcpu->kvm;
391 
392  mutex_lock(&kvm->slots_lock);
394  mutex_unlock(&kvm->slots_lock);
395 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_vgic_vcpu_init()

int kvm_vgic_vcpu_init ( struct kvm_vcpu *  vcpu)

kvm_vgic_vcpu_init() - Initialize static VGIC VCPU data structures and register VCPU-specific KVM iodevs

@vcpu: pointer to the VCPU being created and initialized

Only do initialization, but do not actually enable the VGIC CPU interface

Definition at line 194 of file vgic-init.c.

195 {
196  struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;
197  struct vgic_dist *dist = &vcpu->kvm->arch.vgic;
198  int ret = 0;
199  int i;
200 
202 
203  INIT_LIST_HEAD(&vgic_cpu->ap_list_head);
204  raw_spin_lock_init(&vgic_cpu->ap_list_lock);
205  atomic_set(&vgic_cpu->vgic_v3.its_vpe.vlpi_count, 0);
206 
207  /*
208  * Enable and configure all SGIs to be edge-triggered and
209  * configure all PPIs as level-triggered.
210  */
211  for (i = 0; i < VGIC_NR_PRIVATE_IRQS; i++) {
212  struct vgic_irq *irq = &vgic_cpu->private_irqs[i];
213 
214  INIT_LIST_HEAD(&irq->ap_list);
215  raw_spin_lock_init(&irq->irq_lock);
216  irq->intid = i;
217  irq->vcpu = NULL;
218  irq->target_vcpu = vcpu;
219  kref_init(&irq->refcount);
220  if (vgic_irq_is_sgi(i)) {
221  /* SGIs */
222  irq->enabled = 1;
223  irq->config = VGIC_CONFIG_EDGE;
224  } else {
225  /* PPIs */
226  irq->config = VGIC_CONFIG_LEVEL;
227  }
228  }
229 
230  if (!irqchip_in_kernel(vcpu->kvm))
231  return 0;
232 
233  /*
234  * If we are creating a VCPU with a GICv3 we must also register the
235  * KVM io device for the redistributor that belongs to this VCPU.
236  */
237  if (dist->vgic_model == KVM_DEV_TYPE_ARM_VGIC_V3) {
238  mutex_lock(&vcpu->kvm->slots_lock);
240  mutex_unlock(&vcpu->kvm->slots_lock);
241  }
242  return ret;
243 }
struct vgic_io_device rd_iodev
Definition: arm_vgic.h:348
struct vgic_irq private_irqs[VGIC_NR_PRIVATE_IRQS]
Definition: arm_vgic.h:332
raw_spinlock_t ap_list_lock
Definition: arm_vgic.h:334
struct vgic_v3_cpu_if vgic_v3
Definition: arm_vgic.h:329
struct list_head ap_list_head
Definition: arm_vgic.h:342
gpa_t base_addr
Definition: arm_vgic.h:176
struct list_head ap_list
Definition: arm_vgic.h:120
struct kref refcount
Definition: arm_vgic.h:141
struct its_vpe its_vpe
Definition: arm_vgic.h:320
int vgic_register_redist_iodev(struct kvm_vcpu *vcpu)
Definition: vgic-mmio-v3.c:746
#define vgic_irq_is_sgi(intid)
Definition: vgic.h:21
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_vgic_vcpu_pending_irq()

int kvm_vgic_vcpu_pending_irq ( struct kvm_vcpu *  vcpu)

Definition at line 971 of file vgic.c.

972 {
973  struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;
974  struct vgic_irq *irq;
975  bool pending = false;
976  unsigned long flags;
977  struct vgic_vmcr vmcr;
978 
979  if (!vcpu->kvm->arch.vgic.enabled)
980  return false;
981 
982  if (vcpu->arch.vgic_cpu.vgic_v3.its_vpe.pending_last)
983  return true;
984 
985  vgic_get_vmcr(vcpu, &vmcr);
986 
987  raw_spin_lock_irqsave(&vgic_cpu->ap_list_lock, flags);
988 
989  list_for_each_entry(irq, &vgic_cpu->ap_list_head, ap_list) {
990  raw_spin_lock(&irq->irq_lock);
991  pending = irq_is_pending(irq) && irq->enabled &&
992  !irq->active &&
993  irq->priority < vmcr.pmr;
994  raw_spin_unlock(&irq->irq_lock);
995 
996  if (pending)
997  break;
998  }
999 
1000  raw_spin_unlock_irqrestore(&vgic_cpu->ap_list_lock, flags);
1001 
1002  return pending;
1003 }
void vgic_get_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr)
Definition: vgic-mmio.c:851
static bool irq_is_pending(struct vgic_irq *irq)
Definition: vgic.h:108
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_vgic_vmcr_sync()

void kvm_vgic_vmcr_sync ( struct kvm_vcpu *  vcpu)

Definition at line 960 of file vgic.c.

961 {
962  if (unlikely(!irqchip_in_kernel(vcpu->kvm)))
963  return;
964 
966  vgic_v2_vmcr_sync(vcpu);
967  else
968  vgic_v3_vmcr_sync(vcpu);
969 }
void vgic_v2_vmcr_sync(struct kvm_vcpu *vcpu)
Definition: vgic-v2.c:467
void vgic_v3_vmcr_sync(struct kvm_vcpu *vcpu)
Definition: vgic-v3.c:740
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_irq_needs_resampling()

static bool vgic_irq_needs_resampling ( struct vgic_irq irq)
inlinestatic

Definition at line 160 of file arm_vgic.h.

161 {
162  return irq->ops && (irq->ops->flags & VGIC_IRQ_SW_RESAMPLE);
163 }
#define VGIC_IRQ_SW_RESAMPLE
Definition: arm_vgic.h:107
unsigned long flags
Definition: arm_vgic.h:105
Here is the caller graph for this function:

◆ vgic_v3_dispatch_sgi()

void vgic_v3_dispatch_sgi ( struct kvm_vcpu *  vcpu,
u64  reg,
bool  allow_group1 
)

vgic_v3_dispatch_sgi - handle SGI requests from VCPUs @vcpu: The VCPU requesting a SGI @reg: The value written into ICC_{ASGI1,SGI0,SGI1}R by that VCPU @allow_group1: Does the sysreg access allow generation of G1 SGIs

With GICv3 (and ARE=1) CPUs trigger SGIs by writing to a system register. This will trap in sys_regs.c and call this function. This ICC_SGI1R_EL1 register contains the upper three affinity levels of the target processors as well as a bitmask of 16 Aff0 CPUs.

If the interrupt routing mode bit is not set, we iterate over the Aff0 bits and signal the VCPUs matching the provided Aff{3,2,1}.

If this bit is set, we signal all, but not the calling VCPU.

Definition at line 1058 of file vgic-mmio-v3.c.

1059 {
1060  struct kvm *kvm = vcpu->kvm;
1061  struct kvm_vcpu *c_vcpu;
1062  unsigned long target_cpus;
1063  u64 mpidr;
1064  u32 sgi, aff0;
1065  unsigned long c;
1066 
1067  sgi = FIELD_GET(ICC_SGI1R_SGI_ID_MASK, reg);
1068 
1069  /* Broadcast */
1070  if (unlikely(reg & BIT_ULL(ICC_SGI1R_IRQ_ROUTING_MODE_BIT))) {
1071  kvm_for_each_vcpu(c, c_vcpu, kvm) {
1072  /* Don't signal the calling VCPU */
1073  if (c_vcpu == vcpu)
1074  continue;
1075 
1076  vgic_v3_queue_sgi(c_vcpu, sgi, allow_group1);
1077  }
1078 
1079  return;
1080  }
1081 
1082  /* We iterate over affinities to find the corresponding vcpus */
1083  mpidr = SGI_AFFINITY_LEVEL(reg, 3);
1084  mpidr |= SGI_AFFINITY_LEVEL(reg, 2);
1085  mpidr |= SGI_AFFINITY_LEVEL(reg, 1);
1086  target_cpus = FIELD_GET(ICC_SGI1R_TARGET_LIST_MASK, reg);
1087 
1088  for_each_set_bit(aff0, &target_cpus, hweight_long(ICC_SGI1R_TARGET_LIST_MASK)) {
1089  c_vcpu = kvm_mpidr_to_vcpu(kvm, mpidr | aff0);
1090  if (c_vcpu)
1091  vgic_v3_queue_sgi(c_vcpu, sgi, allow_group1);
1092  }
1093 }
struct kvm_vcpu * kvm_mpidr_to_vcpu(struct kvm *kvm, unsigned long mpidr)
Definition: arm.c:2460
static void vgic_v3_queue_sgi(struct kvm_vcpu *vcpu, u32 sgi, bool allow_group1)
#define SGI_AFFINITY_LEVEL(reg, level)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_v4_commit()

void vgic_v4_commit ( struct kvm_vcpu *  vcpu)

Definition at line 385 of file vgic-v4.c.

386 {
387  struct its_vpe *vpe = &vcpu->arch.vgic_cpu.vgic_v3.its_vpe;
388 
389  /*
390  * No need to wait for the vPE to be ready across a shallow guest
391  * exit, as only a vcpu_put will invalidate it.
392  */
393  if (!vpe->ready)
394  its_commit_vpe(vpe);
395 }
Here is the caller graph for this function:

◆ vgic_v4_load()

int vgic_v4_load ( struct kvm_vcpu *  vcpu)

Definition at line 349 of file vgic-v4.c.

350 {
351  struct its_vpe *vpe = &vcpu->arch.vgic_cpu.vgic_v3.its_vpe;
352  int err;
353 
354  if (!vgic_supports_direct_msis(vcpu->kvm) || vpe->resident)
355  return 0;
356 
357  if (vcpu_get_flag(vcpu, IN_WFI))
358  return 0;
359 
360  /*
361  * Before making the VPE resident, make sure the redistributor
362  * corresponding to our current CPU expects us here. See the
363  * doc in drivers/irqchip/irq-gic-v4.c to understand how this
364  * turns into a VMOVP command at the ITS level.
365  */
366  err = irq_set_affinity(vpe->irq, cpumask_of(smp_processor_id()));
367  if (err)
368  return err;
369 
370  err = its_make_vpe_resident(vpe, false, vcpu->kvm->arch.vgic.enabled);
371  if (err)
372  return err;
373 
374  /*
375  * Now that the VPE is resident, let's get rid of a potential
376  * doorbell interrupt that would still be pending. This is a
377  * GICv4.0 only "feature"...
378  */
380  err = irq_set_irqchip_state(vpe->irq, IRQCHIP_STATE_PENDING, false);
381 
382  return err;
383 }
bool has_gicv4_1
Definition: arm_vgic.h:75
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_v4_put()

int vgic_v4_put ( struct kvm_vcpu *  vcpu)

Definition at line 339 of file vgic-v4.c.

340 {
341  struct its_vpe *vpe = &vcpu->arch.vgic_cpu.vgic_v3.its_vpe;
342 
343  if (!vgic_supports_direct_msis(vcpu->kvm) || !vpe->resident)
344  return 0;
345 
346  return its_make_vpe_non_resident(vpe, !!vcpu_get_flag(vcpu, IN_WFI));
347 }
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ kvm_vgic_global_state

struct vgic_global kvm_vgic_global_state
extern

◆ vgic_v2_cpuif_trap

struct static_key_false vgic_v2_cpuif_trap
extern

◆ vgic_v3_cpuif_trap

struct static_key_false vgic_v3_cpuif_trap
extern