KVM
Macros | Functions | Variables
vgic-mmio-v3.c File Reference
#include <linux/bitfield.h>
#include <linux/irqchip/arm-gic-v3.h>
#include <linux/kvm.h>
#include <linux/kvm_host.h>
#include <linux/interrupt.h>
#include <kvm/iodev.h>
#include <kvm/arm_vgic.h>
#include <asm/kvm_emulate.h>
#include <asm/kvm_arm.h>
#include <asm/kvm_mmu.h>
#include "vgic.h"
#include "vgic-mmio.h"
Include dependency graph for vgic-mmio-v3.c:

Go to the source code of this file.

Macros

#define PROPBASER_RES0_MASK    (GENMASK_ULL(63, 59) | GENMASK_ULL(55, 52) | GENMASK_ULL(6, 5))
 
#define PENDBASER_RES0_MASK
 
#define REGISTER_DESC_WITH_BITS_PER_IRQ_SHARED(off, rd, wr, ur, uw, bpi, acc)
 
#define SGI_AFFINITY_LEVEL(reg, level)
 

Functions

unsigned long extract_bytes (u64 data, unsigned int offset, unsigned int num)
 
u64 update_64bit_reg (u64 reg, unsigned int offset, unsigned int len, unsigned long val)
 
bool vgic_has_its (struct kvm *kvm)
 
bool vgic_supports_direct_msis (struct kvm *kvm)
 
static unsigned long vgic_mmio_read_v3_misc (struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len)
 
static void vgic_mmio_write_v3_misc (struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len, unsigned long val)
 
static int vgic_mmio_uaccess_write_v3_misc (struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len, unsigned long val)
 
static unsigned long vgic_mmio_read_irouter (struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len)
 
static void vgic_mmio_write_irouter (struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len, unsigned long val)
 
bool vgic_lpis_enabled (struct kvm_vcpu *vcpu)
 
static unsigned long vgic_mmio_read_v3r_ctlr (struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len)
 
static void vgic_mmio_write_v3r_ctlr (struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len, unsigned long val)
 
static bool vgic_mmio_vcpu_rdist_is_last (struct kvm_vcpu *vcpu)
 
static unsigned long vgic_mmio_read_v3r_typer (struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len)
 
static unsigned long vgic_mmio_read_v3r_iidr (struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len)
 
static unsigned long vgic_mmio_read_v3_idregs (struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len)
 
static int vgic_v3_uaccess_write_pending (struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len, unsigned long val)
 
u64 vgic_sanitise_shareability (u64 field)
 
u64 vgic_sanitise_inner_cacheability (u64 field)
 
u64 vgic_sanitise_outer_cacheability (u64 field)
 
u64 vgic_sanitise_field (u64 reg, u64 field_mask, int field_shift, u64(*sanitise_fn)(u64))
 
static u64 vgic_sanitise_pendbaser (u64 reg)
 
static u64 vgic_sanitise_propbaser (u64 reg)
 
static unsigned long vgic_mmio_read_propbase (struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len)
 
static void vgic_mmio_write_propbase (struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len, unsigned long val)
 
static unsigned long vgic_mmio_read_pendbase (struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len)
 
static void vgic_mmio_write_pendbase (struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len, unsigned long val)
 
static unsigned long vgic_mmio_read_sync (struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len)
 
static void vgic_set_rdist_busy (struct kvm_vcpu *vcpu, bool busy)
 
static void vgic_mmio_write_invlpi (struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len, unsigned long val)
 
static void vgic_mmio_write_invall (struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len, unsigned long val)
 
unsigned int vgic_v3_init_dist_iodev (struct vgic_io_device *dev)
 
int vgic_register_redist_iodev (struct kvm_vcpu *vcpu)
 
void vgic_unregister_redist_iodev (struct kvm_vcpu *vcpu)
 
static int vgic_register_all_redist_iodevs (struct kvm *kvm)
 
static int vgic_v3_alloc_redist_region (struct kvm *kvm, uint32_t index, gpa_t base, uint32_t count)
 
void vgic_v3_free_redist_region (struct vgic_redist_region *rdreg)
 
int vgic_v3_set_redist_base (struct kvm *kvm, u32 index, u64 addr, u32 count)
 
int vgic_v3_has_attr_regs (struct kvm_device *dev, struct kvm_device_attr *attr)
 
static void vgic_v3_queue_sgi (struct kvm_vcpu *vcpu, u32 sgi, bool allow_group1)
 
void vgic_v3_dispatch_sgi (struct kvm_vcpu *vcpu, u64 reg, bool allow_group1)
 
int vgic_v3_dist_uaccess (struct kvm_vcpu *vcpu, bool is_write, int offset, u32 *val)
 
int vgic_v3_redist_uaccess (struct kvm_vcpu *vcpu, bool is_write, int offset, u32 *val)
 
int vgic_v3_line_level_info_uaccess (struct kvm_vcpu *vcpu, bool is_write, u32 intid, u32 *val)
 

Variables

static const struct vgic_register_region vgic_v3_dist_registers []
 
static const struct vgic_register_region vgic_v3_rd_registers []
 

Macro Definition Documentation

◆ PENDBASER_RES0_MASK

#define PENDBASER_RES0_MASK
Value:
(BIT_ULL(63) | GENMASK_ULL(61, 59) | GENMASK_ULL(55, 52) | \
GENMASK_ULL(15, 12) | GENMASK_ULL(6, 0))

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

◆ PROPBASER_RES0_MASK

#define PROPBASER_RES0_MASK    (GENMASK_ULL(63, 59) | GENMASK_ULL(55, 52) | GENMASK_ULL(6, 5))

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

◆ REGISTER_DESC_WITH_BITS_PER_IRQ_SHARED

#define REGISTER_DESC_WITH_BITS_PER_IRQ_SHARED (   off,
  rd,
  wr,
  ur,
  uw,
  bpi,
  acc 
)
Value:
{ \
.reg_offset = off, \
.bits_per_irq = bpi, \
.len = (bpi * VGIC_NR_PRIVATE_IRQS) / 8, \
.access_flags = acc, \
.read = vgic_mmio_read_raz, \
.write = vgic_mmio_write_wi, \
}, { \
.reg_offset = off + (bpi * VGIC_NR_PRIVATE_IRQS) / 8, \
.bits_per_irq = bpi, \
.len = (bpi * (1024 - VGIC_NR_PRIVATE_IRQS)) / 8, \
.access_flags = acc, \
.read = rd, \
.write = wr, \
.uaccess_read = ur, \
.uaccess_write = uw, \
}
#define VGIC_NR_PRIVATE_IRQS
Definition: arm_vgic.h:27
unsigned long vgic_mmio_read_raz(struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len)
Definition: vgic-mmio.c:19
void vgic_mmio_write_wi(struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len, unsigned long val)
Definition: vgic-mmio.c:31

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

◆ SGI_AFFINITY_LEVEL

#define SGI_AFFINITY_LEVEL (   reg,
  level 
)
Value:
((((reg) & ICC_SGI1R_AFFINITY_## level ##_MASK) \
>> ICC_SGI1R_AFFINITY_## level ##_SHIFT) << MPIDR_LEVEL_SHIFT(level))

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

Function Documentation

◆ extract_bytes()

unsigned long extract_bytes ( u64  data,
unsigned int  offset,
unsigned int  num 
)

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

24 {
25  return (data >> (offset * 8)) & GENMASK_ULL(num * 8 - 1, 0);
26 }
Here is the caller graph for this function:

◆ update_64bit_reg()

u64 update_64bit_reg ( u64  reg,
unsigned int  offset,
unsigned int  len,
unsigned long  val 
)

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

31 {
32  int lower = (offset & 4) * 8;
33  int upper = lower + 8 * len - 1;
34 
35  reg &= ~GENMASK_ULL(upper, lower);
36  val &= GENMASK_ULL(len * 8 - 1, 0);
37 
38  return reg | ((u64)val << lower);
39 }
Here is the caller graph for this function:

◆ vgic_has_its()

bool vgic_has_its ( struct kvm *  kvm)

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

42 {
43  struct vgic_dist *dist = &kvm->arch.vgic;
44 
45  if (dist->vgic_model != KVM_DEV_TYPE_ARM_VGIC_V3)
46  return false;
47 
48  return dist->has_its;
49 }
bool has_its
Definition: arm_vgic.h:265
u32 vgic_model
Definition: arm_vgic.h:230
Here is the caller graph for this function:

◆ vgic_lpis_enabled()

bool vgic_lpis_enabled ( struct kvm_vcpu *  vcpu)

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

239 {
240  struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;
241 
242  return atomic_read(&vgic_cpu->ctlr) == GICR_CTLR_ENABLE_LPIS;
243 }
atomic_t ctlr
Definition: arm_vgic.h:356
Here is the caller graph for this function:

◆ vgic_mmio_read_irouter()

static unsigned long vgic_mmio_read_irouter ( struct kvm_vcpu *  vcpu,
gpa_t  addr,
unsigned int  len 
)
static

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

195 {
196  int intid = VGIC_ADDR_TO_INTID(addr, 64);
197  struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, NULL, intid);
198  unsigned long ret = 0;
199 
200  if (!irq)
201  return 0;
202 
203  /* The upper word is RAZ for us. */
204  if (!(addr & 4))
205  ret = extract_bytes(READ_ONCE(irq->mpidr), addr & 7, len);
206 
207  vgic_put_irq(vcpu->kvm, irq);
208  return ret;
209 }
u32 mpidr
Definition: arm_vgic.h:146
u32 intid
Definition: arm_vgic.h:133
struct kvm_vcpu * vcpu
Definition: arm_vgic.h:122
unsigned long extract_bytes(u64 data, unsigned int offset, unsigned int num)
Definition: vgic-mmio-v3.c:22
#define VGIC_ADDR_TO_INTID(addr, bits)
Definition: vgic-mmio.h:58
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:

◆ vgic_mmio_read_pendbase()

static unsigned long vgic_mmio_read_pendbase ( struct kvm_vcpu *  vcpu,
gpa_t  addr,
unsigned int  len 
)
static

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

482 {
483  struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;
484  u64 value = vgic_cpu->pendbaser;
485 
486  value &= ~GICR_PENDBASER_PTZ;
487 
488  return extract_bytes(value, addr & 7, len);
489 }
u64 pendbaser
Definition: arm_vgic.h:354
Here is the call graph for this function:

◆ vgic_mmio_read_propbase()

static unsigned long vgic_mmio_read_propbase ( struct kvm_vcpu *  vcpu,
gpa_t  addr,
unsigned int  len 
)
static

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

454 {
455  struct vgic_dist *dist = &vcpu->kvm->arch.vgic;
456 
457  return extract_bytes(dist->propbaser, addr & 7, len);
458 }
u64 propbaser
Definition: arm_vgic.h:274
Here is the call graph for this function:

◆ vgic_mmio_read_sync()

static unsigned long vgic_mmio_read_sync ( struct kvm_vcpu *  vcpu,
gpa_t  addr,
unsigned int  len 
)
static

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

513 {
514  return !!atomic_read(&vcpu->arch.vgic_cpu.syncr_busy);
515 }

◆ vgic_mmio_read_v3_idregs()

static unsigned long vgic_mmio_read_v3_idregs ( struct kvm_vcpu *  vcpu,
gpa_t  addr,
unsigned int  len 
)
static

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

346 {
347  switch (addr & 0xffff) {
348  case GICD_PIDR2:
349  /* report a GICv3 compliant implementation */
350  return 0x3b;
351  }
352 
353  return 0;
354 }

◆ vgic_mmio_read_v3_misc()

static unsigned long vgic_mmio_read_v3_misc ( struct kvm_vcpu *  vcpu,
gpa_t  addr,
unsigned int  len 
)
static

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

66 {
67  struct vgic_dist *vgic = &vcpu->kvm->arch.vgic;
68  u32 value = 0;
69 
70  switch (addr & 0x0c) {
71  case GICD_CTLR:
72  if (vgic->enabled)
73  value |= GICD_CTLR_ENABLE_SS_G1;
74  value |= GICD_CTLR_ARE_NS | GICD_CTLR_DS;
75  if (vgic->nassgireq)
76  value |= GICD_CTLR_nASSGIreq;
77  break;
78  case GICD_TYPER:
79  value = vgic->nr_spis + VGIC_NR_PRIVATE_IRQS;
80  value = (value >> 5) - 1;
81  if (vgic_has_its(vcpu->kvm)) {
82  value |= (INTERRUPT_ID_BITS_ITS - 1) << 19;
83  value |= GICD_TYPER_LPIS;
84  } else {
85  value |= (INTERRUPT_ID_BITS_SPIS - 1) << 19;
86  }
87  break;
88  case GICD_TYPER2:
89  if (kvm_vgic_global_state.has_gicv4_1 && gic_cpuif_has_vsgi())
90  value = GICD_TYPER2_nASSGIcap;
91  break;
92  case GICD_IIDR:
93  value = (PRODUCT_ID_KVM << GICD_IIDR_PRODUCT_ID_SHIFT) |
94  (vgic->implementation_rev << GICD_IIDR_REVISION_SHIFT) |
95  (IMPLEMENTER_ARM << GICD_IIDR_IMPLEMENTER_SHIFT);
96  break;
97  default:
98  return 0;
99  }
100 
101  return value;
102 }
struct vgic_global kvm_vgic_global_state
int nr_spis
Definition: arm_vgic.h:244
u32 implementation_rev
Definition: arm_vgic.h:233
bool nassgireq
Definition: arm_vgic.h:259
bool enabled
Definition: arm_vgic.h:256
bool has_gicv4_1
Definition: arm_vgic.h:75
bool vgic_has_its(struct kvm *kvm)
Definition: vgic-mmio-v3.c:41
#define INTERRUPT_ID_BITS_SPIS
Definition: vgic.h:17
#define INTERRUPT_ID_BITS_ITS
Definition: vgic.h:18
#define IMPLEMENTER_ARM
Definition: vgic.h:12
#define PRODUCT_ID_KVM
Definition: vgic.h:11
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_mmio_read_v3r_ctlr()

static unsigned long vgic_mmio_read_v3r_ctlr ( struct kvm_vcpu *  vcpu,
gpa_t  addr,
unsigned int  len 
)
static

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

247 {
248  struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;
249  unsigned long val;
250 
251  val = atomic_read(&vgic_cpu->ctlr);
253  val |= GICR_CTLR_IR | GICR_CTLR_CES;
254 
255  return val;
256 }
#define KVM_VGIC_IMP_REV_3
Definition: arm_vgic.h:235
static u32 vgic_get_implementation_rev(struct kvm_vcpu *vcpu)
Definition: vgic.h:102
Here is the call graph for this function:

◆ vgic_mmio_read_v3r_iidr()

static unsigned long vgic_mmio_read_v3r_iidr ( struct kvm_vcpu *  vcpu,
gpa_t  addr,
unsigned int  len 
)
static

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

340 {
341  return (PRODUCT_ID_KVM << 24) | (IMPLEMENTER_ARM << 0);
342 }

◆ vgic_mmio_read_v3r_typer()

static unsigned long vgic_mmio_read_v3r_typer ( struct kvm_vcpu *  vcpu,
gpa_t  addr,
unsigned int  len 
)
static

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

321 {
322  unsigned long mpidr = kvm_vcpu_get_mpidr_aff(vcpu);
323  int target_vcpu_id = vcpu->vcpu_id;
324  u64 value;
325 
326  value = (u64)(mpidr & GENMASK(23, 0)) << 32;
327  value |= ((target_vcpu_id & 0xffff) << 8);
328 
329  if (vgic_has_its(vcpu->kvm))
330  value |= GICR_TYPER_PLPIS;
331 
333  value |= GICR_TYPER_LAST;
334 
335  return extract_bytes(value, addr & 7, len);
336 }
static bool vgic_mmio_vcpu_rdist_is_last(struct kvm_vcpu *vcpu)
Definition: vgic-mmio-v3.c:292
Here is the call graph for this function:

◆ vgic_mmio_uaccess_write_v3_misc()

static int vgic_mmio_uaccess_write_v3_misc ( struct kvm_vcpu *  vcpu,
gpa_t  addr,
unsigned int  len,
unsigned long  val 
)
static

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

156 {
157  struct vgic_dist *dist = &vcpu->kvm->arch.vgic;
158  u32 reg;
159 
160  switch (addr & 0x0c) {
161  case GICD_TYPER2:
162  if (val != vgic_mmio_read_v3_misc(vcpu, addr, len))
163  return -EINVAL;
164  return 0;
165  case GICD_IIDR:
166  reg = vgic_mmio_read_v3_misc(vcpu, addr, len);
167  if ((reg ^ val) & ~GICD_IIDR_REVISION_MASK)
168  return -EINVAL;
169 
170  reg = FIELD_GET(GICD_IIDR_REVISION_MASK, reg);
171  switch (reg) {
172  case KVM_VGIC_IMP_REV_2:
173  case KVM_VGIC_IMP_REV_3:
174  dist->implementation_rev = reg;
175  return 0;
176  default:
177  return -EINVAL;
178  }
179  case GICD_CTLR:
180  /* Not a GICv4.1? No HW SGIs */
182  val &= ~GICD_CTLR_nASSGIreq;
183 
184  dist->enabled = val & GICD_CTLR_ENABLE_SS_G1;
185  dist->nassgireq = val & GICD_CTLR_nASSGIreq;
186  return 0;
187  }
188 
189  vgic_mmio_write_v3_misc(vcpu, addr, len, val);
190  return 0;
191 }
#define KVM_VGIC_IMP_REV_2
Definition: arm_vgic.h:234
static void vgic_mmio_write_v3_misc(struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len, unsigned long val)
Definition: vgic-mmio-v3.c:104
static unsigned long vgic_mmio_read_v3_misc(struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len)
Definition: vgic-mmio-v3.c:64
Here is the call graph for this function:

◆ vgic_mmio_vcpu_rdist_is_last()

static bool vgic_mmio_vcpu_rdist_is_last ( struct kvm_vcpu *  vcpu)
static

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

293 {
294  struct vgic_dist *vgic = &vcpu->kvm->arch.vgic;
295  struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;
296  struct vgic_redist_region *iter, *rdreg = vgic_cpu->rdreg;
297 
298  if (!rdreg)
299  return false;
300 
301  if (vgic_cpu->rdreg_index < rdreg->free_index - 1) {
302  return false;
303  } else if (rdreg->count && vgic_cpu->rdreg_index == (rdreg->count - 1)) {
304  struct list_head *rd_regions = &vgic->rd_regions;
305  gpa_t end = rdreg->base + rdreg->count * KVM_VGIC_V3_REDIST_SIZE;
306 
307  /*
308  * the rdist is the last one of the redist region,
309  * check whether there is no other contiguous rdist region
310  */
311  list_for_each_entry(iter, rd_regions, list) {
312  if (iter->base == end && iter->free_index > 0)
313  return false;
314  }
315  }
316  return true;
317 }
static unsigned long end
Definition: early_alloc.c:16
struct vgic_redist_region * rdreg
Definition: arm_vgic.h:349
u32 rdreg_index
Definition: arm_vgic.h:350
struct list_head rd_regions
Definition: arm_vgic.h:252
Here is the caller graph for this function:

◆ vgic_mmio_write_invall()

static void vgic_mmio_write_invall ( struct kvm_vcpu *  vcpu,
gpa_t  addr,
unsigned int  len,
unsigned long  val 
)
static

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

558 {
559  /* See vgic_mmio_write_invlpi() for the early return rationale */
560  if ((addr & 4) || !vgic_lpis_enabled(vcpu))
561  return;
562 
563  vgic_set_rdist_busy(vcpu, true);
564  vgic_its_invall(vcpu);
565  vgic_set_rdist_busy(vcpu, false);
566 }
int vgic_its_invall(struct kvm_vcpu *vcpu)
Definition: vgic-its.c:1355
bool vgic_lpis_enabled(struct kvm_vcpu *vcpu)
Definition: vgic-mmio-v3.c:238
static void vgic_set_rdist_busy(struct kvm_vcpu *vcpu, bool busy)
Definition: vgic-mmio-v3.c:517
Here is the call graph for this function:

◆ vgic_mmio_write_invlpi()

static void vgic_mmio_write_invlpi ( struct kvm_vcpu *  vcpu,
gpa_t  addr,
unsigned int  len,
unsigned long  val 
)
static

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

531 {
532  struct vgic_irq *irq;
533 
534  /*
535  * If the guest wrote only to the upper 32bit part of the
536  * register, drop the write on the floor, as it is only for
537  * vPEs (which we don't support for obvious reasons).
538  *
539  * Also discard the access if LPIs are not enabled.
540  */
541  if ((addr & 4) || !vgic_lpis_enabled(vcpu))
542  return;
543 
544  vgic_set_rdist_busy(vcpu, true);
545 
546  irq = vgic_get_irq(vcpu->kvm, NULL, lower_32_bits(val));
547  if (irq) {
548  vgic_its_inv_lpi(vcpu->kvm, irq);
549  vgic_put_irq(vcpu->kvm, irq);
550  }
551 
552  vgic_set_rdist_busy(vcpu, false);
553 }
int vgic_its_inv_lpi(struct kvm *kvm, struct vgic_irq *irq)
Definition: vgic-its.c:1323
Here is the call graph for this function:

◆ vgic_mmio_write_irouter()

static void vgic_mmio_write_irouter ( struct kvm_vcpu *  vcpu,
gpa_t  addr,
unsigned int  len,
unsigned long  val 
)
static

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

214 {
215  int intid = VGIC_ADDR_TO_INTID(addr, 64);
216  struct vgic_irq *irq;
217  unsigned long flags;
218 
219  /* The upper word is WI for us since we don't implement Aff3. */
220  if (addr & 4)
221  return;
222 
223  irq = vgic_get_irq(vcpu->kvm, NULL, intid);
224 
225  if (!irq)
226  return;
227 
228  raw_spin_lock_irqsave(&irq->irq_lock, flags);
229 
230  /* We only care about and preserve Aff0, Aff1 and Aff2. */
231  irq->mpidr = val & GENMASK(23, 0);
232  irq->target_vcpu = kvm_mpidr_to_vcpu(vcpu->kvm, irq->mpidr);
233 
234  raw_spin_unlock_irqrestore(&irq->irq_lock, flags);
235  vgic_put_irq(vcpu->kvm, irq);
236 }
struct kvm_vcpu * kvm_mpidr_to_vcpu(struct kvm *kvm, unsigned long mpidr)
Definition: arm.c:2460
struct kvm_vcpu * target_vcpu
Definition: arm_vgic.h:127
raw_spinlock_t irq_lock
Definition: arm_vgic.h:118
Here is the call graph for this function:

◆ vgic_mmio_write_pendbase()

static void vgic_mmio_write_pendbase ( struct kvm_vcpu *  vcpu,
gpa_t  addr,
unsigned int  len,
unsigned long  val 
)
static

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

494 {
495  struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;
496  u64 old_pendbaser, pendbaser;
497 
498  /* Storing a value with LPIs already enabled is undefined */
499  if (vgic_lpis_enabled(vcpu))
500  return;
501 
502  do {
503  old_pendbaser = READ_ONCE(vgic_cpu->pendbaser);
504  pendbaser = old_pendbaser;
505  pendbaser = update_64bit_reg(pendbaser, addr & 4, len, val);
507  } while (cmpxchg64(&vgic_cpu->pendbaser, old_pendbaser,
508  pendbaser) != old_pendbaser);
509 }
static u64 vgic_sanitise_pendbaser(u64 reg)
Definition: vgic-mmio-v3.c:419
u64 update_64bit_reg(u64 reg, unsigned int offset, unsigned int len, unsigned long val)
Definition: vgic-mmio-v3.c:29
Here is the call graph for this function:

◆ vgic_mmio_write_propbase()

static void vgic_mmio_write_propbase ( struct kvm_vcpu *  vcpu,
gpa_t  addr,
unsigned int  len,
unsigned long  val 
)
static

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

463 {
464  struct vgic_dist *dist = &vcpu->kvm->arch.vgic;
465  u64 old_propbaser, propbaser;
466 
467  /* Storing a value with LPIs already enabled is undefined */
468  if (vgic_lpis_enabled(vcpu))
469  return;
470 
471  do {
472  old_propbaser = READ_ONCE(dist->propbaser);
473  propbaser = old_propbaser;
474  propbaser = update_64bit_reg(propbaser, addr & 4, len, val);
476  } while (cmpxchg64(&dist->propbaser, old_propbaser,
477  propbaser) != old_propbaser);
478 }
static u64 vgic_sanitise_propbaser(u64 reg)
Definition: vgic-mmio-v3.c:436
Here is the call graph for this function:

◆ vgic_mmio_write_v3_misc()

static void vgic_mmio_write_v3_misc ( struct kvm_vcpu *  vcpu,
gpa_t  addr,
unsigned int  len,
unsigned long  val 
)
static

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

107 {
108  struct vgic_dist *dist = &vcpu->kvm->arch.vgic;
109 
110  switch (addr & 0x0c) {
111  case GICD_CTLR: {
112  bool was_enabled, is_hwsgi;
113 
114  mutex_lock(&vcpu->kvm->arch.config_lock);
115 
116  was_enabled = dist->enabled;
117  is_hwsgi = dist->nassgireq;
118 
119  dist->enabled = val & GICD_CTLR_ENABLE_SS_G1;
120 
121  /* Not a GICv4.1? No HW SGIs */
122  if (!kvm_vgic_global_state.has_gicv4_1 || !gic_cpuif_has_vsgi())
123  val &= ~GICD_CTLR_nASSGIreq;
124 
125  /* Dist stays enabled? nASSGIreq is RO */
126  if (was_enabled && dist->enabled) {
127  val &= ~GICD_CTLR_nASSGIreq;
128  val |= FIELD_PREP(GICD_CTLR_nASSGIreq, is_hwsgi);
129  }
130 
131  /* Switching HW SGIs? */
132  dist->nassgireq = val & GICD_CTLR_nASSGIreq;
133  if (is_hwsgi != dist->nassgireq)
134  vgic_v4_configure_vsgis(vcpu->kvm);
135 
137  was_enabled != dist->enabled)
138  kvm_make_all_cpus_request(vcpu->kvm, KVM_REQ_RELOAD_GICv4);
139  else if (!was_enabled && dist->enabled)
140  vgic_kick_vcpus(vcpu->kvm);
141 
142  mutex_unlock(&vcpu->kvm->arch.config_lock);
143  break;
144  }
145  case GICD_TYPER:
146  case GICD_TYPER2:
147  case GICD_IIDR:
148  /* This is at best for documentation purposes... */
149  return;
150  }
151 }
bool kvm_make_all_cpus_request(struct kvm *kvm, unsigned int req)
Definition: kvm_main.c:340
void vgic_v4_configure_vsgis(struct kvm *kvm)
Definition: vgic-v4.c:187
void vgic_kick_vcpus(struct kvm *kvm)
Definition: vgic.c:1005
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_mmio_write_v3r_ctlr()

static void vgic_mmio_write_v3r_ctlr ( struct kvm_vcpu *  vcpu,
gpa_t  addr,
unsigned int  len,
unsigned long  val 
)
static

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

261 {
262  struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;
263  u32 ctlr;
264 
265  if (!vgic_has_its(vcpu->kvm))
266  return;
267 
268  if (!(val & GICR_CTLR_ENABLE_LPIS)) {
269  /*
270  * Don't disable if RWP is set, as there already an
271  * ongoing disable. Funky guest...
272  */
273  ctlr = atomic_cmpxchg_acquire(&vgic_cpu->ctlr,
274  GICR_CTLR_ENABLE_LPIS,
275  GICR_CTLR_RWP);
276  if (ctlr != GICR_CTLR_ENABLE_LPIS)
277  return;
278 
280  vgic_its_invalidate_cache(vcpu->kvm);
281  atomic_set_release(&vgic_cpu->ctlr, 0);
282  } else {
283  ctlr = atomic_cmpxchg_acquire(&vgic_cpu->ctlr, 0,
284  GICR_CTLR_ENABLE_LPIS);
285  if (ctlr != 0)
286  return;
287 
288  vgic_enable_lpis(vcpu);
289  }
290 }
void vgic_enable_lpis(struct kvm_vcpu *vcpu)
Definition: vgic-its.c:1866
void vgic_its_invalidate_cache(struct kvm *kvm)
Definition: vgic-its.c:659
void vgic_flush_pending_lpis(struct kvm_vcpu *vcpu)
Definition: vgic.c:152
Here is the call graph for this function:

◆ vgic_register_all_redist_iodevs()

static int vgic_register_all_redist_iodevs ( struct kvm *  kvm)
static

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

813 {
814  struct kvm_vcpu *vcpu;
815  unsigned long c;
816  int ret = 0;
817 
818  lockdep_assert_held(&kvm->slots_lock);
819 
820  kvm_for_each_vcpu(c, vcpu, kvm) {
821  ret = vgic_register_redist_iodev(vcpu);
822  if (ret)
823  break;
824  }
825 
826  if (ret) {
827  /* The current c failed, so iterate over the previous ones. */
828  int i;
829 
830  for (i = 0; i < c; i++) {
831  vcpu = kvm_get_vcpu(kvm, i);
833  }
834  }
835 
836  return ret;
837 }
void vgic_unregister_redist_iodev(struct kvm_vcpu *vcpu)
Definition: vgic-mmio-v3.c:805
int vgic_register_redist_iodev(struct kvm_vcpu *vcpu)
Definition: vgic-mmio-v3.c:746
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_register_redist_iodev()

int vgic_register_redist_iodev ( struct kvm_vcpu *  vcpu)

vgic_register_redist_iodev - register a single redist iodev @vcpu: The VCPU to which the redistributor belongs

Register a KVM iodev for this VCPU's redistributor using the address provided.

Return 0 on success, -ERRNO otherwise.

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

747 {
748  struct kvm *kvm = vcpu->kvm;
749  struct vgic_dist *vgic = &kvm->arch.vgic;
750  struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;
751  struct vgic_io_device *rd_dev = &vcpu->arch.vgic_cpu.rd_iodev;
752  struct vgic_redist_region *rdreg;
753  gpa_t rd_base;
754  int ret = 0;
755 
756  lockdep_assert_held(&kvm->slots_lock);
757  mutex_lock(&kvm->arch.config_lock);
758 
760  goto out_unlock;
761 
762  /*
763  * We may be creating VCPUs before having set the base address for the
764  * redistributor region, in which case we will come back to this
765  * function for all VCPUs when the base address is set. Just return
766  * without doing any work for now.
767  */
768  rdreg = vgic_v3_rdist_free_slot(&vgic->rd_regions);
769  if (!rdreg)
770  goto out_unlock;
771 
772  if (!vgic_v3_check_base(kvm)) {
773  ret = -EINVAL;
774  goto out_unlock;
775  }
776 
777  vgic_cpu->rdreg = rdreg;
778  vgic_cpu->rdreg_index = rdreg->free_index;
779 
780  rd_base = rdreg->base + rdreg->free_index * KVM_VGIC_V3_REDIST_SIZE;
781 
783  rd_dev->base_addr = rd_base;
784  rd_dev->iodev_type = IODEV_REDIST;
785  rd_dev->regions = vgic_v3_rd_registers;
786  rd_dev->nr_regions = ARRAY_SIZE(vgic_v3_rd_registers);
787  rd_dev->redist_vcpu = vcpu;
788 
789  mutex_unlock(&kvm->arch.config_lock);
790 
791  ret = kvm_io_bus_register_dev(kvm, KVM_MMIO_BUS, rd_base,
792  2 * SZ_64K, &rd_dev->dev);
793  if (ret)
794  return ret;
795 
796  /* Protected by slots_lock */
797  rdreg->free_index++;
798  return 0;
799 
800 out_unlock:
801  mutex_unlock(&kvm->arch.config_lock);
802  return ret;
803 }
@ IODEV_REDIST
Definition: arm_vgic.h:171
static void kvm_iodevice_init(struct kvm_io_device *dev, const struct kvm_io_device_ops *ops)
Definition: iodev.h:36
int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr, int len, struct kvm_io_device *dev)
Definition: kvm_main.c:5897
struct vgic_io_device rd_iodev
Definition: arm_vgic.h:348
struct kvm_vcpu * redist_vcpu
Definition: arm_vgic.h:178
const struct vgic_register_region * regions
Definition: arm_vgic.h:181
gpa_t base_addr
Definition: arm_vgic.h:176
enum iodev_type iodev_type
Definition: arm_vgic.h:182
struct kvm_io_device dev
Definition: arm_vgic.h:184
static const struct vgic_register_region vgic_v3_rd_registers[]
Definition: vgic-mmio-v3.c:649
const struct kvm_io_device_ops kvm_io_gic_ops
Definition: vgic-mmio.c:1075
struct vgic_redist_region * vgic_v3_rdist_free_slot(struct list_head *rd_regions)
Definition: vgic-v3.c:513
bool vgic_v3_check_base(struct kvm *kvm)
Definition: vgic-v3.c:477
#define IS_VGIC_ADDR_UNDEF(_x)
Definition: vgic.h:15
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_sanitise_field()

u64 vgic_sanitise_field ( u64  reg,
u64  field_mask,
int  field_shift,
u64(*)(u64)  sanitise_fn 
)

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

406 {
407  u64 field = (reg & field_mask) >> field_shift;
408 
409  field = sanitise_fn(field) << field_shift;
410  return (reg & ~field_mask) | field;
411 }
Here is the caller graph for this function:

◆ vgic_sanitise_inner_cacheability()

u64 vgic_sanitise_inner_cacheability ( u64  field)

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

382 {
383  switch (field) {
384  case GIC_BASER_CACHE_nCnB:
385  case GIC_BASER_CACHE_nC:
386  return GIC_BASER_CACHE_RaWb;
387  default:
388  return field;
389  }
390 }
Here is the caller graph for this function:

◆ vgic_sanitise_outer_cacheability()

u64 vgic_sanitise_outer_cacheability ( u64  field)

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

394 {
395  switch (field) {
396  case GIC_BASER_CACHE_SameAsInner:
397  case GIC_BASER_CACHE_nC:
398  return field;
399  default:
400  return GIC_BASER_CACHE_SameAsInner;
401  }
402 }
Here is the caller graph for this function:

◆ vgic_sanitise_pendbaser()

static u64 vgic_sanitise_pendbaser ( u64  reg)
static

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

420 {
421  reg = vgic_sanitise_field(reg, GICR_PENDBASER_SHAREABILITY_MASK,
422  GICR_PENDBASER_SHAREABILITY_SHIFT,
424  reg = vgic_sanitise_field(reg, GICR_PENDBASER_INNER_CACHEABILITY_MASK,
425  GICR_PENDBASER_INNER_CACHEABILITY_SHIFT,
427  reg = vgic_sanitise_field(reg, GICR_PENDBASER_OUTER_CACHEABILITY_MASK,
428  GICR_PENDBASER_OUTER_CACHEABILITY_SHIFT,
430 
431  reg &= ~PENDBASER_RES0_MASK;
432 
433  return reg;
434 }
u64 vgic_sanitise_shareability(u64 field)
Definition: vgic-mmio-v3.c:370
u64 vgic_sanitise_inner_cacheability(u64 field)
Definition: vgic-mmio-v3.c:381
u64 vgic_sanitise_outer_cacheability(u64 field)
Definition: vgic-mmio-v3.c:393
#define PENDBASER_RES0_MASK
Definition: vgic-mmio-v3.c:415
u64 vgic_sanitise_field(u64 reg, u64 field_mask, int field_shift, u64(*sanitise_fn)(u64))
Definition: vgic-mmio-v3.c:404
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_sanitise_propbaser()

static u64 vgic_sanitise_propbaser ( u64  reg)
static

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

437 {
438  reg = vgic_sanitise_field(reg, GICR_PROPBASER_SHAREABILITY_MASK,
439  GICR_PROPBASER_SHAREABILITY_SHIFT,
441  reg = vgic_sanitise_field(reg, GICR_PROPBASER_INNER_CACHEABILITY_MASK,
442  GICR_PROPBASER_INNER_CACHEABILITY_SHIFT,
444  reg = vgic_sanitise_field(reg, GICR_PROPBASER_OUTER_CACHEABILITY_MASK,
445  GICR_PROPBASER_OUTER_CACHEABILITY_SHIFT,
447 
448  reg &= ~PROPBASER_RES0_MASK;
449  return reg;
450 }
#define PROPBASER_RES0_MASK
Definition: vgic-mmio-v3.c:413
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_sanitise_shareability()

u64 vgic_sanitise_shareability ( u64  field)

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

371 {
372  switch (field) {
373  case GIC_BASER_OuterShareable:
374  return GIC_BASER_InnerShareable;
375  default:
376  return field;
377  }
378 }
Here is the caller graph for this function:

◆ vgic_set_rdist_busy()

static void vgic_set_rdist_busy ( struct kvm_vcpu *  vcpu,
bool  busy 
)
static

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

518 {
519  if (busy) {
520  atomic_inc(&vcpu->arch.vgic_cpu.syncr_busy);
521  smp_mb__after_atomic();
522  } else {
523  smp_mb__before_atomic();
524  atomic_dec(&vcpu->arch.vgic_cpu.syncr_busy);
525  }
526 }
Here is the caller graph for this function:

◆ vgic_supports_direct_msis()

bool vgic_supports_direct_msis ( struct kvm *  kvm)

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

52 {
55 }
bool has_gicv4
Definition: arm_vgic.h:74
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_unregister_redist_iodev()

void vgic_unregister_redist_iodev ( struct kvm_vcpu *  vcpu)

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

806 {
807  struct vgic_io_device *rd_dev = &vcpu->arch.vgic_cpu.rd_iodev;
808 
809  kvm_io_bus_unregister_dev(vcpu->kvm, KVM_MMIO_BUS, &rd_dev->dev);
810 }
int kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx, struct kvm_io_device *dev)
Definition: kvm_main.c:5941
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_v3_alloc_redist_region()

static int vgic_v3_alloc_redist_region ( struct kvm *  kvm,
uint32_t  index,
gpa_t  base,
uint32_t  count 
)
static

vgic_v3_alloc_redist_region - Allocate a new redistributor region

Performs various checks before inserting the rdist region in the list. Those tests depend on whether the size of the rdist region is known (ie. count != 0). The list is sorted by rdist region index.

@kvm: kvm handle @index: redist region index @base: base of the new rdist region @count: number of redistributors the region is made of (0 in the old style single region, whose size is induced from the number of vcpus)

Return 0 on success, < 0 otherwise

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

856 {
857  struct vgic_dist *d = &kvm->arch.vgic;
858  struct vgic_redist_region *rdreg;
859  struct list_head *rd_regions = &d->rd_regions;
860  int nr_vcpus = atomic_read(&kvm->online_vcpus);
861  size_t size = count ? count * KVM_VGIC_V3_REDIST_SIZE
862  : nr_vcpus * KVM_VGIC_V3_REDIST_SIZE;
863  int ret;
864 
865  /* cross the end of memory ? */
866  if (base + size < base)
867  return -EINVAL;
868 
869  if (list_empty(rd_regions)) {
870  if (index != 0)
871  return -EINVAL;
872  } else {
873  rdreg = list_last_entry(rd_regions,
874  struct vgic_redist_region, list);
875 
876  /* Don't mix single region and discrete redist regions */
877  if (!count && rdreg->count)
878  return -EINVAL;
879 
880  if (!count)
881  return -EEXIST;
882 
883  if (index != rdreg->index + 1)
884  return -EINVAL;
885  }
886 
887  /*
888  * For legacy single-region redistributor regions (!count),
889  * check that the redistributor region does not overlap with the
890  * distributor's address space.
891  */
892  if (!count && !IS_VGIC_ADDR_UNDEF(d->vgic_dist_base) &&
893  vgic_dist_overlap(kvm, base, size))
894  return -EINVAL;
895 
896  /* collision with any other rdist region? */
897  if (vgic_v3_rdist_overlap(kvm, base, size))
898  return -EINVAL;
899 
900  rdreg = kzalloc(sizeof(*rdreg), GFP_KERNEL_ACCOUNT);
901  if (!rdreg)
902  return -ENOMEM;
903 
904  rdreg->base = VGIC_ADDR_UNDEF;
905 
906  ret = vgic_check_iorange(kvm, rdreg->base, base, SZ_64K, size);
907  if (ret)
908  goto free;
909 
910  rdreg->base = base;
911  rdreg->count = count;
912  rdreg->free_index = 0;
913  rdreg->index = index;
914 
915  list_add_tail(&rdreg->list, rd_regions);
916  return 0;
917 free:
918  kfree(rdreg);
919  return ret;
920 }
static unsigned long base
Definition: early_alloc.c:15
size_t size
Definition: gen-hyprel.c:133
gpa_t vgic_dist_base
Definition: arm_vgic.h:247
struct list_head list
Definition: arm_vgic.h:221
int vgic_check_iorange(struct kvm *kvm, phys_addr_t ioaddr, phys_addr_t addr, phys_addr_t alignment, phys_addr_t size)
bool vgic_v3_rdist_overlap(struct kvm *kvm, gpa_t base, size_t size)
Definition: vgic-v3.c:460
static bool vgic_dist_overlap(struct kvm *kvm, gpa_t base, size_t size)
Definition: vgic.h:317
#define VGIC_ADDR_UNDEF
Definition: vgic.h:14
Here is the call graph for this function:
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 }
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_v3_dist_uaccess()

int vgic_v3_dist_uaccess ( struct kvm_vcpu *  vcpu,
bool  is_write,
int  offset,
u32 *  val 
)

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

1097 {
1098  struct vgic_io_device dev = {
1099  .regions = vgic_v3_dist_registers,
1100  .nr_regions = ARRAY_SIZE(vgic_v3_dist_registers),
1101  };
1102 
1103  return vgic_uaccess(vcpu, &dev, is_write, offset, val);
1104 }
static const struct vgic_register_region vgic_v3_dist_registers[]
Definition: vgic-mmio-v3.c:594
int vgic_uaccess(struct kvm_vcpu *vcpu, struct vgic_io_device *dev, bool is_write, int offset, u32 *val)
Definition: vgic-mmio.c:1005
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_v3_free_redist_region()

void vgic_v3_free_redist_region ( struct vgic_redist_region rdreg)

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

923 {
924  list_del(&rdreg->list);
925  kfree(rdreg);
926 }
Here is the caller graph for this function:

◆ vgic_v3_has_attr_regs()

int vgic_v3_has_attr_regs ( struct kvm_device *  dev,
struct kvm_device_attr *  attr 
)

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

957 {
958  const struct vgic_register_region *region;
959  struct vgic_io_device iodev;
960  struct vgic_reg_attr reg_attr;
961  struct kvm_vcpu *vcpu;
962  gpa_t addr;
963  int ret;
964 
965  ret = vgic_v3_parse_attr(dev, attr, &reg_attr);
966  if (ret)
967  return ret;
968 
969  vcpu = reg_attr.vcpu;
970  addr = reg_attr.addr;
971 
972  switch (attr->group) {
973  case KVM_DEV_ARM_VGIC_GRP_DIST_REGS:
974  iodev.regions = vgic_v3_dist_registers;
975  iodev.nr_regions = ARRAY_SIZE(vgic_v3_dist_registers);
976  iodev.base_addr = 0;
977  break;
978  case KVM_DEV_ARM_VGIC_GRP_REDIST_REGS:{
979  iodev.regions = vgic_v3_rd_registers;
980  iodev.nr_regions = ARRAY_SIZE(vgic_v3_rd_registers);
981  iodev.base_addr = 0;
982  break;
983  }
984  case KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS:
985  return vgic_v3_has_cpu_sysregs_attr(vcpu, attr);
986  default:
987  return -ENXIO;
988  }
989 
990  /* We only support aligned 32-bit accesses. */
991  if (addr & 3)
992  return -ENXIO;
993 
994  region = vgic_get_mmio_region(vcpu, &iodev, addr, sizeof(u32));
995  if (!region)
996  return -ENXIO;
997 
998  return 0;
999 }
int vgic_v3_parse_attr(struct kvm_device *dev, struct kvm_device_attr *attr, struct vgic_reg_attr *reg_attr)
const struct vgic_register_region * vgic_get_mmio_region(struct kvm_vcpu *vcpu, struct vgic_io_device *iodev, gpa_t addr, int len)
Definition: vgic-mmio.c:950
int vgic_v3_has_cpu_sysregs_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr)
Here is the call graph for this function:

◆ vgic_v3_init_dist_iodev()

unsigned int vgic_v3_init_dist_iodev ( struct vgic_io_device dev)

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

728 {
730  dev->nr_regions = ARRAY_SIZE(vgic_v3_dist_registers);
731 
733 
734  return SZ_64K;
735 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_v3_line_level_info_uaccess()

int vgic_v3_line_level_info_uaccess ( struct kvm_vcpu *  vcpu,
bool  is_write,
u32  intid,
u32 *  val 
)

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

1119 {
1120  if (intid % 32)
1121  return -EINVAL;
1122 
1123  if (is_write)
1124  vgic_write_irq_line_level_info(vcpu, intid, *val);
1125  else
1126  *val = vgic_read_irq_line_level_info(vcpu, intid);
1127 
1128  return 0;
1129 }
void vgic_write_irq_line_level_info(struct kvm_vcpu *vcpu, u32 intid, const u32 val)
Definition: vgic-mmio.c:788
u32 vgic_read_irq_line_level_info(struct kvm_vcpu *vcpu, u32 intid)
Definition: vgic-mmio.c:766
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_v3_queue_sgi()

static void vgic_v3_queue_sgi ( struct kvm_vcpu *  vcpu,
u32  sgi,
bool  allow_group1 
)
static

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

1011 {
1012  struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, vcpu, sgi);
1013  unsigned long flags;
1014 
1015  raw_spin_lock_irqsave(&irq->irq_lock, flags);
1016 
1017  /*
1018  * An access targeting Group0 SGIs can only generate
1019  * those, while an access targeting Group1 SGIs can
1020  * generate interrupts of either group.
1021  */
1022  if (!irq->group || allow_group1) {
1023  if (!irq->hw) {
1024  irq->pending_latch = true;
1025  vgic_queue_irq_unlock(vcpu->kvm, irq, flags);
1026  } else {
1027  /* HW SGI? Ask the GIC to inject it */
1028  int err;
1029  err = irq_set_irqchip_state(irq->host_irq,
1030  IRQCHIP_STATE_PENDING,
1031  true);
1032  WARN_RATELIMIT(err, "IRQ %d", irq->host_irq);
1033  raw_spin_unlock_irqrestore(&irq->irq_lock, flags);
1034  }
1035  } else {
1036  raw_spin_unlock_irqrestore(&irq->irq_lock, flags);
1037  }
1038 
1039  vgic_put_irq(vcpu->kvm, irq);
1040 }
unsigned int host_irq
Definition: arm_vgic.h:143
bool pending_latch
Definition: arm_vgic.h:135
bool hw
Definition: arm_vgic.h:140
u8 group
Definition: arm_vgic.h:151
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:

◆ vgic_v3_redist_uaccess()

int vgic_v3_redist_uaccess ( struct kvm_vcpu *  vcpu,
bool  is_write,
int  offset,
u32 *  val 
)

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

1108 {
1109  struct vgic_io_device rd_dev = {
1111  .nr_regions = ARRAY_SIZE(vgic_v3_rd_registers),
1112  };
1113 
1114  return vgic_uaccess(vcpu, &rd_dev, is_write, offset, val);
1115 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_v3_set_redist_base()

int vgic_v3_set_redist_base ( struct kvm *  kvm,
u32  index,
u64  addr,
u32  count 
)

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

929 {
930  int ret;
931 
932  mutex_lock(&kvm->arch.config_lock);
933  ret = vgic_v3_alloc_redist_region(kvm, index, addr, count);
934  mutex_unlock(&kvm->arch.config_lock);
935  if (ret)
936  return ret;
937 
938  /*
939  * Register iodevs for each existing VCPU. Adding more VCPUs
940  * afterwards will register the iodevs when needed.
941  */
943  if (ret) {
944  struct vgic_redist_region *rdreg;
945 
946  mutex_lock(&kvm->arch.config_lock);
949  mutex_unlock(&kvm->arch.config_lock);
950  return ret;
951  }
952 
953  return 0;
954 }
static int vgic_v3_alloc_redist_region(struct kvm *kvm, uint32_t index, gpa_t base, uint32_t count)
Definition: vgic-mmio-v3.c:854
static int vgic_register_all_redist_iodevs(struct kvm *kvm)
Definition: vgic-mmio-v3.c:812
void vgic_v3_free_redist_region(struct vgic_redist_region *rdreg)
Definition: vgic-mmio-v3.c:922
struct vgic_redist_region * vgic_v3_rdist_region_from_index(struct kvm *kvm, u32 index)
Definition: vgic-v3.c:524
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vgic_v3_uaccess_write_pending()

static int vgic_v3_uaccess_write_pending ( struct kvm_vcpu *  vcpu,
gpa_t  addr,
unsigned int  len,
unsigned long  val 
)
static

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

359 {
360  int ret;
361 
362  ret = vgic_uaccess_write_spending(vcpu, addr, len, val);
363  if (ret)
364  return ret;
365 
366  return vgic_uaccess_write_cpending(vcpu, addr, len, ~val);
367 }
int vgic_uaccess_write_spending(struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len, unsigned long val)
Definition: vgic-mmio.c:360
int vgic_uaccess_write_cpending(struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len, unsigned long val)
Definition: vgic-mmio.c:447
Here is the call graph for this function:

Variable Documentation

◆ vgic_v3_dist_registers

const struct vgic_register_region vgic_v3_dist_registers[]
static

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

◆ vgic_v3_rd_registers

const struct vgic_register_region vgic_v3_rd_registers[]
static

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