Skip to content

Commit 24cab82

Browse files
author
Marc Zyngier
committed
KVM: arm/arm64: vgic: Add LPI translation cache definition
Add the basic data structure that expresses an MSI to LPI translation as well as the allocation/release hooks. The size of the cache is arbitrarily defined as 16*nr_vcpus. Tested-by: Andre Przywara <andre.przywara@arm.com> Reviewed-by: Eric Auger <eric.auger@redhat.com> Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent d45331b commit 24cab82

4 files changed

Lines changed: 59 additions & 0 deletions

File tree

‎include/kvm/arm_vgic.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ struct vgic_dist {
249249
struct list_head lpi_list_head;
250250
int lpi_list_count;
251251

252+
/* LPI translation cache */
253+
struct list_head lpi_translation_cache;
254+
252255
/* used by vgic-debug */
253256
struct vgic_state_iter *iter;
254257

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ void kvm_vgic_early_init(struct kvm *kvm)
5353
struct vgic_dist *dist = &kvm->arch.vgic;
5454

5555
INIT_LIST_HEAD(&dist->lpi_list_head);
56+
INIT_LIST_HEAD(&dist->lpi_translation_cache);
5657
raw_spin_lock_init(&dist->lpi_list_lock);
5758
}
5859

@@ -294,6 +295,7 @@ int vgic_init(struct kvm *kvm)
294295
}
295296

296297
if (vgic_has_its(kvm)) {
298+
vgic_lpi_translation_cache_init(kvm);
297299
ret = vgic_v4_init(kvm);
298300
if (ret)
299301
goto out;
@@ -335,6 +337,9 @@ static void kvm_vgic_dist_destroy(struct kvm *kvm)
335337
INIT_LIST_HEAD(&dist->rd_regions);
336338
}
337339

340+
if (vgic_has_its(kvm))
341+
vgic_lpi_translation_cache_destroy(kvm);
342+
338343
if (vgic_supports_direct_msis(kvm))
339344
vgic_v4_teardown(kvm);
340345
}

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ struct its_ite {
138138
u32 event_id;
139139
};
140140

141+
struct vgic_translation_cache_entry {
142+
struct list_head entry;
143+
phys_addr_t db;
144+
u32 devid;
145+
u32 eventid;
146+
struct vgic_irq *irq;
147+
};
148+
141149
/**
142150
* struct vgic_its_abi - ITS abi ops and settings
143151
* @cte_esz: collection table entry size
@@ -1657,6 +1665,45 @@ static int vgic_register_its_iodev(struct kvm *kvm, struct vgic_its *its,
16571665
return ret;
16581666
}
16591667

1668+
/* Default is 16 cached LPIs per vcpu */
1669+
#define LPI_DEFAULT_PCPU_CACHE_SIZE 16
1670+
1671+
void vgic_lpi_translation_cache_init(struct kvm *kvm)
1672+
{
1673+
struct vgic_dist *dist = &kvm->arch.vgic;
1674+
unsigned int sz;
1675+
int i;
1676+
1677+
if (!list_empty(&dist->lpi_translation_cache))
1678+
return;
1679+
1680+
sz = atomic_read(&kvm->online_vcpus) * LPI_DEFAULT_PCPU_CACHE_SIZE;
1681+
1682+
for (i = 0; i < sz; i++) {
1683+
struct vgic_translation_cache_entry *cte;
1684+
1685+
/* An allocation failure is not fatal */
1686+
cte = kzalloc(sizeof(*cte), GFP_KERNEL);
1687+
if (WARN_ON(!cte))
1688+
break;
1689+
1690+
INIT_LIST_HEAD(&cte->entry);
1691+
list_add(&cte->entry, &dist->lpi_translation_cache);
1692+
}
1693+
}
1694+
1695+
void vgic_lpi_translation_cache_destroy(struct kvm *kvm)
1696+
{
1697+
struct vgic_dist *dist = &kvm->arch.vgic;
1698+
struct vgic_translation_cache_entry *cte, *tmp;
1699+
1700+
list_for_each_entry_safe(cte, tmp,
1701+
&dist->lpi_translation_cache, entry) {
1702+
list_del(&cte->entry);
1703+
kfree(cte);
1704+
}
1705+
}
1706+
16601707
#define INITIAL_BASER_VALUE \
16611708
(GIC_BASER_CACHEABILITY(GITS_BASER, INNER, RaWb) | \
16621709
GIC_BASER_CACHEABILITY(GITS_BASER, OUTER, SameAsInner) | \
@@ -1685,6 +1732,8 @@ static int vgic_its_create(struct kvm_device *dev, u32 type)
16851732
kfree(its);
16861733
return ret;
16871734
}
1735+
1736+
vgic_lpi_translation_cache_init(dev->kvm);
16881737
}
16891738

16901739
mutex_init(&its->its_lock);

‎virt/kvm/arm/vgic/vgic.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ int vgic_copy_lpi_list(struct kvm *kvm, struct kvm_vcpu *vcpu, u32 **intid_ptr);
307307
int vgic_its_resolve_lpi(struct kvm *kvm, struct vgic_its *its,
308308
u32 devid, u32 eventid, struct vgic_irq **irq);
309309
struct vgic_its *vgic_msi_to_its(struct kvm *kvm, struct kvm_msi *msi);
310+
void vgic_lpi_translation_cache_init(struct kvm *kvm);
311+
void vgic_lpi_translation_cache_destroy(struct kvm *kvm);
310312

311313
bool vgic_supports_direct_msis(struct kvm *kvm);
312314
int vgic_v4_init(struct kvm *kvm);

0 commit comments

Comments
 (0)