Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: arm/arm64: prepare GICv3 emulation to use kvm_io_bus MMIO handling

Using the framework provided by the recent vgic.c changes, we
register a kvm_io_bus device on mapping the virtual GICv3 resources.
The distributor mapping is pretty straight forward, but the
redistributors need some more love, since they need to be tagged with
the respective redistributor (read: VCPU) they are connected with.
We use the kvm_io_bus framework to register one devices per VCPU.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Reviewed-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>

authored by

Andre Przywara and committed by
Marc Zyngier
fb8f61ab 0ba10d53

+39 -1
+1
include/kvm/arm_vgic.h
··· 252 252 253 253 struct vgic_vm_ops vm_ops; 254 254 struct vgic_io_device dist_iodev; 255 + struct vgic_io_device *redist_iodevs; 255 256 }; 256 257 257 258 struct vgic_v2_cpu_if {
+38 -1
virt/kvm/arm/vgic-v3-emul.c
··· 758 758 { 759 759 int ret = 0; 760 760 struct vgic_dist *dist = &kvm->arch.vgic; 761 + gpa_t rdbase = dist->vgic_redist_base; 762 + struct vgic_io_device *iodevs = NULL; 763 + int i; 761 764 762 765 if (!irqchip_in_kernel(kvm)) 763 766 return 0; ··· 786 783 goto out; 787 784 } 788 785 789 - kvm->arch.vgic.ready = true; 786 + ret = vgic_register_kvm_io_dev(kvm, dist->vgic_dist_base, 787 + GIC_V3_DIST_SIZE, vgic_v3_dist_ranges, 788 + -1, &dist->dist_iodev); 789 + if (ret) 790 + goto out; 791 + 792 + iodevs = kcalloc(dist->nr_cpus, sizeof(iodevs[0]), GFP_KERNEL); 793 + if (!iodevs) { 794 + ret = -ENOMEM; 795 + goto out_unregister; 796 + } 797 + 798 + for (i = 0; i < dist->nr_cpus; i++) { 799 + ret = vgic_register_kvm_io_dev(kvm, rdbase, 800 + SZ_128K, vgic_redist_ranges, 801 + i, &iodevs[i]); 802 + if (ret) 803 + goto out_unregister; 804 + rdbase += GIC_V3_REDIST_SIZE; 805 + } 806 + 807 + dist->redist_iodevs = iodevs; 808 + dist->ready = true; 809 + goto out; 810 + 811 + out_unregister: 812 + kvm_io_bus_unregister_dev(kvm, KVM_MMIO_BUS, &dist->dist_iodev.dev); 813 + if (iodevs) { 814 + for (i = 0; i < dist->nr_cpus; i++) { 815 + if (iodevs[i].dev.ops) 816 + kvm_io_bus_unregister_dev(kvm, KVM_MMIO_BUS, 817 + &iodevs[i].dev); 818 + } 819 + } 820 + 790 821 out: 791 822 if (ret) 792 823 kvm_vgic_destroy(kvm);