Skip to content

Commit 71afe47

Browse files
eaugerChristoffer Dall
authored andcommitted
KVM: arm64: vgic-its: Introduce migration ABI infrastructure
We plan to support different migration ABIs, ie. characterizing the ITS table layout format in guest RAM. For example, a new ABI will be needed if vLPIs get supported for nested use case. So let's introduce an array of supported ABIs (at the moment a single ABI is supported though). The following characteristics are foreseen to vary with the ABI: size of table entries, save/restore operation, the way abi settings are applied. By default the MAX_ABI_REV is applied on its creation. In subsequent patches we will introduce a way for the userspace to change the ABI in use. The entry sizes now are set according to the ABI version and not hardcoded anymore. Signed-off-by: Eric Auger <eric.auger@redhat.com> Reviewed-by: Christoffer Dall <cdall@linaro.org>
1 parent 0979bfa commit 71afe47

3 files changed

Lines changed: 97 additions & 4 deletions

File tree

‎include/kvm/arm_vgic.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ struct vgic_its {
162162
u32 creadr;
163163
u32 cwriter;
164164

165+
/* migration ABI revision in use */
166+
u32 abi_rev;
167+
165168
/* Protects the device and collection lists */
166169
struct mutex its_lock;
167170
struct list_head device_list;

‎include/linux/irqchip/arm-gic-v3.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@
132132
#define GIC_BASER_SHAREABILITY(reg, type) \
133133
(GIC_BASER_##type << reg##_SHAREABILITY_SHIFT)
134134

135+
/* encode a size field of width @w containing @n - 1 units */
136+
#define GIC_ENCODE_SZ(n, w) (((unsigned long)(n) - 1) & GENMASK_ULL(((w) - 1), 0))
137+
135138
#define GICR_PROPBASER_SHAREABILITY_SHIFT (10)
136139
#define GICR_PROPBASER_INNER_CACHEABILITY_SHIFT (7)
137140
#define GICR_PROPBASER_OUTER_CACHEABILITY_SHIFT (56)
@@ -232,6 +235,7 @@
232235
#define GITS_CTLR_QUIESCENT (1U << 31)
233236

234237
#define GITS_TYPER_PLPIS (1UL << 0)
238+
#define GITS_TYPER_ITT_ENTRY_SIZE_SHIFT 4
235239
#define GITS_TYPER_IDBITS_SHIFT 8
236240
#define GITS_TYPER_DEVBITS_SHIFT 13
237241
#define GITS_TYPER_DEVBITS(r) ((((r) >> GITS_TYPER_DEVBITS_SHIFT) & 0x1f) + 1)
@@ -290,6 +294,7 @@
290294
#define GITS_BASER_TYPE(r) (((r) >> GITS_BASER_TYPE_SHIFT) & 7)
291295
#define GITS_BASER_ENTRY_SIZE_SHIFT (48)
292296
#define GITS_BASER_ENTRY_SIZE(r) ((((r) >> GITS_BASER_ENTRY_SIZE_SHIFT) & 0x1f) + 1)
297+
#define GITS_BASER_ENTRY_SIZE_MASK GENMASK_ULL(52, 48)
293298
#define GITS_BASER_SHAREABILITY_SHIFT (10)
294299
#define GITS_BASER_InnerShareable \
295300
GIC_BASER_SHAREABILITY(GITS_BASER, InnerShareable)

‎virt/kvm/arm/vgic/vgic-its.c‎

Lines changed: 89 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
#include "vgic.h"
3434
#include "vgic-mmio.h"
3535

36+
static int vgic_its_save_tables_v0(struct vgic_its *its);
37+
static int vgic_its_restore_tables_v0(struct vgic_its *its);
38+
static int vgic_its_commit_v0(struct vgic_its *its);
39+
3640
/*
3741
* Creates a new (reference to a) struct vgic_irq for a given LPI.
3842
* If this LPI is already mapped on another ITS, we increase its refcount
@@ -123,6 +127,50 @@ struct its_ite {
123127
u32 event_id;
124128
};
125129

130+
/**
131+
* struct vgic_its_abi - ITS abi ops and settings
132+
* @cte_esz: collection table entry size
133+
* @dte_esz: device table entry size
134+
* @ite_esz: interrupt translation table entry size
135+
* @save tables: save the ITS tables into guest RAM
136+
* @restore_tables: restore the ITS internal structs from tables
137+
* stored in guest RAM
138+
* @commit: initialize the registers which expose the ABI settings,
139+
* especially the entry sizes
140+
*/
141+
struct vgic_its_abi {
142+
int cte_esz;
143+
int dte_esz;
144+
int ite_esz;
145+
int (*save_tables)(struct vgic_its *its);
146+
int (*restore_tables)(struct vgic_its *its);
147+
int (*commit)(struct vgic_its *its);
148+
};
149+
150+
static const struct vgic_its_abi its_table_abi_versions[] = {
151+
[0] = {.cte_esz = 8, .dte_esz = 8, .ite_esz = 8,
152+
.save_tables = vgic_its_save_tables_v0,
153+
.restore_tables = vgic_its_restore_tables_v0,
154+
.commit = vgic_its_commit_v0,
155+
},
156+
};
157+
158+
#define NR_ITS_ABIS ARRAY_SIZE(its_table_abi_versions)
159+
160+
inline const struct vgic_its_abi *vgic_its_get_abi(struct vgic_its *its)
161+
{
162+
return &its_table_abi_versions[its->abi_rev];
163+
}
164+
165+
int vgic_its_set_abi(struct vgic_its *its, int rev)
166+
{
167+
const struct vgic_its_abi *abi;
168+
169+
its->abi_rev = rev;
170+
abi = vgic_its_get_abi(its);
171+
return abi->commit(its);
172+
}
173+
126174
/*
127175
* Find and returns a device in the device table for an ITS.
128176
* Must be called with the its_lock mutex held.
@@ -364,6 +412,7 @@ static unsigned long vgic_mmio_read_its_typer(struct kvm *kvm,
364412
struct vgic_its *its,
365413
gpa_t addr, unsigned int len)
366414
{
415+
const struct vgic_its_abi *abi = vgic_its_get_abi(its);
367416
u64 reg = GITS_TYPER_PLPIS;
368417

369418
/*
@@ -376,6 +425,7 @@ static unsigned long vgic_mmio_read_its_typer(struct kvm *kvm,
376425
*/
377426
reg |= 0x0f << GITS_TYPER_DEVBITS_SHIFT;
378427
reg |= 0x0f << GITS_TYPER_IDBITS_SHIFT;
428+
reg |= GIC_ENCODE_SZ(abi->ite_esz, 4) << GITS_TYPER_ITT_ENTRY_SIZE_SHIFT;
379429

380430
return extract_bytes(reg, addr & 7, len);
381431
}
@@ -1268,6 +1318,7 @@ static void vgic_mmio_write_its_baser(struct kvm *kvm,
12681318
gpa_t addr, unsigned int len,
12691319
unsigned long val)
12701320
{
1321+
const struct vgic_its_abi *abi = vgic_its_get_abi(its);
12711322
u64 entry_size, device_type;
12721323
u64 reg, *regptr, clearbits = 0;
12731324

@@ -1278,12 +1329,12 @@ static void vgic_mmio_write_its_baser(struct kvm *kvm,
12781329
switch (BASER_INDEX(addr)) {
12791330
case 0:
12801331
regptr = &its->baser_device_table;
1281-
entry_size = 8;
1332+
entry_size = abi->dte_esz;
12821333
device_type = GITS_BASER_TYPE_DEVICE;
12831334
break;
12841335
case 1:
12851336
regptr = &its->baser_coll_table;
1286-
entry_size = 8;
1337+
entry_size = abi->cte_esz;
12871338
device_type = GITS_BASER_TYPE_COLLECTION;
12881339
clearbits = GITS_BASER_INDIRECT;
12891340
break;
@@ -1425,7 +1476,6 @@ static int vgic_register_its_iodev(struct kvm *kvm, struct vgic_its *its)
14251476
(GIC_BASER_CACHEABILITY(GITS_BASER, INNER, RaWb) | \
14261477
GIC_BASER_CACHEABILITY(GITS_BASER, OUTER, SameAsInner) | \
14271478
GIC_BASER_SHAREABILITY(GITS_BASER, InnerShareable) | \
1428-
((8ULL - 1) << GITS_BASER_ENTRY_SIZE_SHIFT) | \
14291479
GITS_BASER_PAGE_SIZE_64K)
14301480

14311481
#define INITIAL_PROPBASER_VALUE \
@@ -1465,7 +1515,7 @@ static int vgic_its_create(struct kvm_device *dev, u32 type)
14651515

14661516
dev->private = its;
14671517

1468-
return 0;
1518+
return vgic_its_set_abi(its, NR_ITS_ABIS - 1);
14691519
}
14701520

14711521
static void vgic_its_destroy(struct kvm_device *kvm_dev)
@@ -1592,6 +1642,41 @@ int vgic_its_attr_regs_access(struct kvm_device *dev,
15921642
return ret;
15931643
}
15941644

1645+
/**
1646+
* vgic_its_save_tables_v0 - Save the ITS tables into guest ARM
1647+
* according to v0 ABI
1648+
*/
1649+
static int vgic_its_save_tables_v0(struct vgic_its *its)
1650+
{
1651+
return -ENXIO;
1652+
}
1653+
1654+
/**
1655+
* vgic_its_restore_tables_v0 - Restore the ITS tables from guest RAM
1656+
* to internal data structs according to V0 ABI
1657+
*
1658+
*/
1659+
static int vgic_its_restore_tables_v0(struct vgic_its *its)
1660+
{
1661+
return -ENXIO;
1662+
}
1663+
1664+
static int vgic_its_commit_v0(struct vgic_its *its)
1665+
{
1666+
const struct vgic_its_abi *abi;
1667+
1668+
abi = vgic_its_get_abi(its);
1669+
its->baser_coll_table &= ~GITS_BASER_ENTRY_SIZE_MASK;
1670+
its->baser_device_table &= ~GITS_BASER_ENTRY_SIZE_MASK;
1671+
1672+
its->baser_coll_table |= (GIC_ENCODE_SZ(abi->cte_esz, 5)
1673+
<< GITS_BASER_ENTRY_SIZE_SHIFT);
1674+
1675+
its->baser_device_table |= (GIC_ENCODE_SZ(abi->dte_esz, 5)
1676+
<< GITS_BASER_ENTRY_SIZE_SHIFT);
1677+
return 0;
1678+
}
1679+
15951680
static int vgic_its_has_attr(struct kvm_device *dev,
15961681
struct kvm_device_attr *attr)
15971682
{

0 commit comments

Comments
 (0)