Skip to content

Commit 0e4e82f

Browse files
Andre-ARMMarc Zyngier
authored andcommitted
KVM: arm64: vgic-its: Enable ITS emulation as a virtual MSI controller
Now that all ITS emulation functionality is in place, we advertise MSI functionality to userland and also the ITS device to the guest - if userland has configured that. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Reviewed-by: Marc Zyngier <marc.zyngier@arm.com> Tested-by: Eric Auger <eric.auger@redhat.com> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
1 parent 2891a7d commit 0e4e82f

10 files changed

Lines changed: 44 additions & 5 deletions

File tree

‎Documentation/virtual/kvm/api.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2162,7 +2162,7 @@ after pausing the vcpu, but before it is resumed.
21622162
4.71 KVM_SIGNAL_MSI
21632163

21642164
Capability: KVM_CAP_SIGNAL_MSI
2165-
Architectures: x86
2165+
Architectures: x86 arm64
21662166
Type: vm ioctl
21672167
Parameters: struct kvm_msi (in)
21682168
Returns: >0 on delivery, 0 if guest blocked the MSI, and -1 on error

‎arch/arm64/kvm/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ config KVM
3636
select HAVE_KVM_IRQFD
3737
select KVM_ARM_VGIC_V3
3838
select KVM_ARM_PMU if HW_PERF_EVENTS
39+
select HAVE_KVM_MSI
3940
---help---
4041
Support hosting virtualized guest machines.
4142
We don't support KVM with 16K page tables yet, due to the multiple

‎arch/arm64/kvm/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic-mmio.o
2929
kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic-mmio-v2.o
3030
kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic-mmio-v3.o
3131
kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic-kvm-device.o
32+
kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic-its.o
3233
kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/arch_timer.o
3334
kvm-$(CONFIG_KVM_ARM_PMU) += $(KVM)/arm/pmu.o

‎arch/arm64/kvm/reset.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ int kvm_arch_dev_ioctl_check_extension(struct kvm *kvm, long ext)
8686
case KVM_CAP_VCPU_ATTRIBUTES:
8787
r = 1;
8888
break;
89+
case KVM_CAP_MSI_DEVID:
90+
if (!kvm)
91+
r = -EINVAL;
92+
else
93+
r = kvm->arch.vgic.msis_require_devid;
94+
break;
8995
default:
9096
r = 0;
9197
}

‎include/kvm/arm_vgic.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ struct vgic_dist {
163163
/* vGIC model the kernel emulates for the guest (GICv2 or GICv3) */
164164
u32 vgic_model;
165165

166+
/* Do injected MSIs require an additional device ID? */
167+
bool msis_require_devid;
168+
166169
int nr_spis;
167170

168171
/* TODO: Consider moving to global state */
@@ -308,4 +311,6 @@ static inline int kvm_vgic_get_max_vcpus(void)
308311
return kvm_vgic_global_state.max_gic_vcpus;
309312
}
310313

314+
int kvm_send_userspace_msi(struct kvm *kvm, struct kvm_msi *msi);
315+
311316
#endif /* __KVM_ARM_VGIC_H */

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ int vgic_init(struct kvm *kvm)
258258
if (ret)
259259
goto out;
260260

261+
if (vgic_has_its(kvm))
262+
dist->msis_require_devid = true;
263+
261264
kvm_for_each_vcpu(i, vcpu, kvm)
262265
kvm_vgic_vcpu_init(vcpu);
263266

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ int kvm_register_vgic_device(unsigned long type)
223223
case KVM_DEV_TYPE_ARM_VGIC_V3:
224224
ret = kvm_register_device_ops(&kvm_arm_vgic_v3_ops,
225225
KVM_DEV_TYPE_ARM_VGIC_V3);
226+
if (ret)
227+
break;
228+
ret = kvm_vgic_register_its_device();
226229
break;
227230
#endif
228231
}

‎virt/kvm/arm/vgic/vgic-mmio-v3.c‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ static unsigned long vgic_mmio_read_v3_misc(struct kvm_vcpu *vcpu,
6666
case GICD_TYPER:
6767
value = vcpu->kvm->arch.vgic.nr_spis + VGIC_NR_PRIVATE_IRQS;
6868
value = (value >> 5) - 1;
69-
value |= (INTERRUPT_ID_BITS_SPIS - 1) << 19;
69+
if (vgic_has_its(vcpu->kvm)) {
70+
value |= (INTERRUPT_ID_BITS_ITS - 1) << 19;
71+
value |= GICD_TYPER_LPIS;
72+
} else {
73+
value |= (INTERRUPT_ID_BITS_SPIS - 1) << 19;
74+
}
7075
break;
7176
case GICD_IIDR:
7277
value = (PRODUCT_ID_KVM << 24) | (IMPLEMENTER_ARM << 0);
@@ -163,9 +168,8 @@ static void vgic_mmio_write_v3r_ctlr(struct kvm_vcpu *vcpu,
163168

164169
vgic_cpu->lpis_enabled = val & GICR_CTLR_ENABLE_LPIS;
165170

166-
if (!was_enabled && vgic_cpu->lpis_enabled) {
167-
/* Eventually do something */
168-
}
171+
if (!was_enabled && vgic_cpu->lpis_enabled)
172+
vgic_enable_lpis(vcpu);
169173
}
170174

171175
static unsigned long vgic_mmio_read_v3r_typer(struct kvm_vcpu *vcpu,
@@ -179,6 +183,8 @@ static unsigned long vgic_mmio_read_v3r_typer(struct kvm_vcpu *vcpu,
179183
value |= ((target_vcpu_id & 0xffff) << 8);
180184
if (target_vcpu_id == atomic_read(&vcpu->kvm->online_vcpus) - 1)
181185
value |= GICR_TYPER_LAST;
186+
if (vgic_has_its(vcpu->kvm))
187+
value |= GICR_TYPER_PLPIS;
182188

183189
return extract_bytes(value, addr & 7, len);
184190
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,3 +718,11 @@ bool kvm_vgic_map_is_active(struct kvm_vcpu *vcpu, unsigned int virt_irq)
718718

719719
return map_is_active;
720720
}
721+
722+
int kvm_send_userspace_msi(struct kvm *kvm, struct kvm_msi *msi)
723+
{
724+
if (vgic_has_its(kvm))
725+
return vgic_its_inject_msi(kvm, msi);
726+
else
727+
return -ENODEV;
728+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ int vgic_v3_probe(const struct gic_kvm_info *info);
7777
int vgic_v3_map_resources(struct kvm *kvm);
7878
int vgic_register_redist_iodevs(struct kvm *kvm, gpa_t dist_base_address);
7979
bool vgic_has_its(struct kvm *kvm);
80+
int kvm_vgic_register_its_device(void);
8081
void vgic_enable_lpis(struct kvm_vcpu *vcpu);
8182
int vgic_its_inject_msi(struct kvm *kvm, struct kvm_msi *msi);
8283
#else
@@ -136,6 +137,11 @@ static inline bool vgic_has_its(struct kvm *kvm)
136137
return false;
137138
}
138139

140+
static inline int kvm_vgic_register_its_device(void)
141+
{
142+
return -ENODEV;
143+
}
144+
139145
static inline void vgic_enable_lpis(struct kvm_vcpu *vcpu)
140146
{
141147
}

0 commit comments

Comments
 (0)