KVM: arm/arm64: Rework virtual GIC emulation
Subsystems (4)
cover KVM: arm/arm64: Rework virtual GIC emulation
Hi,
this is a rework of the new VGIC series.
Many thanks to all reviewers, especially Christoffer.
Major changes include a dependency on a new, separate arch_timer rework series [1], a total rework of the MMIO dispatching, which now uses much less kvm_io_bus devices, the proper handling of enabling and disabling the distributor and the much more elaborate handling of activating an IRQ via the MMIO interface.
Also the patches have been rearranged a bit in the world switch area and for the GICv3 MMIO handling to be more logical and avoid stub functions that get populated only later.
Minor changes are:
- removal of vgic_cpu->nr_lr in favour of kvm_vgic_global_state
- refinements in the virtual IRQ queueing function
- introduction of a separate vgic_clear_lr() function
- the removal of the vgic_v[23]_irq_change_affinity functions
- caring about SGI injection on SGIPENDR writes
- removing locks for atomic reads in the MMIO handlers
- removal of ITS stub functions
- introducing vgic_irq_is_sgi()
- many comment fixes
The simple arch_timer rework in the RFC series has been replaced with a separate rework series [1]. Also there is new preparatory patch from Christoffer which gets rid of reading the number of LRs from the vgic_cpu structure. The MMIO data write back fix has also been replaced with a more sophisticated version.
I refrained from merging vgic_v[23]_populate_lr() and vgic_v[23]_process_maintenance(), respectively. Having taken a closer look it does not appear worthwhile to me to unify the implementations.
Topics which I couldn't manage to address due to timing restraints are:
- proper PHYS_CPUID masking when populating GICv2 LRs
- proper handling of priorites on injection, also filtering(?)
- proper endianess handling in the MMIO framework (not in the VGIC)
- handling corner cases when clearing the active state via MMIO
- cleanup of register region description with new MMIO framework
This series is now based on v4.6-rc3 plus the arch_timer rework[1].
A git tree containing this series and the prerequisites can be found on linux-arm.org:
git://linux-arm.org/linux-ap.git branch: vgic-new/v1
http://www.linux-arm.org/git?p=linux-ap.git;a=log;h=refs/heads/vgic-new/v1
Cheers,
Andre.
===========================
This series is a joint effort to re-implement KVM's GIC emulation.
While the current implementation is centered around providing efficient MMIO emulation, the hot path for most guests is actually the guest entry and exit, which currently is rather costly. Also the existing emulation has a global distributor lock, which quickly becomes a bottleneck once the number of VCPUs increases. Additionally the emulation was originally designed for GICv2, adding GICv3 ITS emulation support to this proved to be rather painful. Last, but not least the existing code became less and less maintainable, with many special cases handled explicitly.
The new implementation is build around a struct vgic_irq data data structure, which holds all information about a virtual interrupt. Interruts which should be injected are hold in a per-VCPU list, this make the entry/exit path much more efficient. Also the new structure allows to have more fine grained locking - per IRQ and per VCPU - getting rid of the global distributor lock.
As a result of the new design ITS emulation fits in more nicely, the respective code will be provided as a follow-up series.
This series implements the same feature set as the existing emulation, as a goodie we now implement priorities correctly.
To allow an easy transition with good test coverage, but still maintain stability, both implementations live side by side, selectable via a Kconfig option. The default is the new implementation.
If this code proves to be reliable, we will later remove the current implementation with an extra patch set.
Please have a look at the series, review it and give the code some serious testing (and possibly debugging). All feedback is appreciated.
Cheers,
Andre.
[1] http://lists.infradead.org/pipermail/linux-arm-kernel/2016-April/422580.html
Andre Przywara (24):
KVM: arm/arm64: pmu: abstract access to number of SPIs
KVM: arm/arm64: vgic-new: Add MMIO handling framework
KVM: arm/arm64: vgic-new: Export register access interface
KVM: arm/arm64: vgic-new: Add CTLR, TYPER and IIDR handlers
KVM: arm/arm64: vgic-new: Add ENABLE registers handlers
KVM: arm/arm64: vgic-new: Add PENDING registers handlers
KVM: arm/arm64: vgic-new: Add PRIORITY registers handlers
KVM: arm/arm64: vgic-new: Add ACTIVE registers handlers
KVM: arm/arm64: vgic-new: Add CONFIG registers handlers
KVM: arm/arm64: vgic-new: Add TARGET registers handlers
KVM: arm/arm64: vgic-new: Add SGIR register handler
KVM: arm/arm64: vgic-new: Add SGIPENDR register handlers
KVM: arm/arm64: vgic-new: Add GICv3 MMIO handling framework
KVM: arm/arm64: vgic-new: Add GICv3 CTLR, IIDR, TYPER handlers
KVM: arm/arm64: vgic-new: Add GICv3 redistributor IIDR, TYPER handlers
KVM: arm/arm64: vgic-new: Add GICv3 IDREGS register handler
KVM: arm/arm64: vgic-new: Add GICv3 IROUTER register handlers
KVM: arm/arm64: vgic-new: Add GICv3 SGI system register trap handler
KVM: arm/arm64: vgic-new: Add userland access to VGIC dist registers
KVM: arm/arm64: vgic-new: Add GICH_VMCR accessors
KVM: arm/arm64: vgic-new: Add userland GIC CPU interface access
KVM: arm/arm64: vgic-new: Wire up irqfd injection
KVM: arm/arm64: vgic-new: implement mapped IRQ handling
KVM: arm/arm64: vgic-new: enable build
Christoffer Dall (6):
KVM: arm/arm64: Get rid of vgic_cpu->nr_lr
KVM: arm/arm64: Fix MMIO emulation data handling
KVM: arm/arm64: vgic-new: Add data structure definitions
KVM: arm/arm64: vgic-new: Add acccessor to new struct vgic_irq
instance
KVM: arm/arm64: vgic-new: Implement virtual IRQ injection
KVM: arm/arm64: vgic-new: Add IRQ sorting
Eric Auger (12):
KVM: arm/arm64: vgic-new: Implement kvm_vgic_vcpu_pending_irq
KVM: arm/arm64: vgic-new: vgic_kvm_device: KVM device ops registration
KVM: arm/arm64: vgic-new: vgic_kvm_device:
KVM_DEV_ARM_VGIC_GRP_NR_IRQS
KVM: arm/arm64: vgic-new: vgic_kvm_device: KVM_DEV_ARM_VGIC_GRP_CTRL
KVM: arm/arm64: vgic-new: vgic_kvm_device: KVM_DEV_ARM_VGIC_GRP_ADDR
KVM: arm/arm64: vgic-new: vgic_kvm_device: access to VGIC registers
KVM: arm/arm64: vgic-new: vgic_kvm_device: implement kvm_vgic_addr
KVM: arm/arm64: vgic-new: vgic_init: implement kvm_vgic_hyp_init
KVM: arm/arm64: vgic-new: vgic_init: implement vgic_create
KVM: arm/arm64: vgic-new: vgic_init: implement vgic_init
KVM: arm/arm64: vgic-new: vgic_init: implement map_resources
KVM: arm/arm64: vgic-new: Add vgic_v2/v3_enable
Marc Zyngier (3):
KVM: arm/arm64: vgic-new: Add IRQ sync/flush framework
KVM: arm/arm64: vgic-new: Add GICv2 world switch backend
KVM: arm/arm64: vgic-new: Add GICv3 world switch backend
arch/arm/kvm/Kconfig | 7 + arch/arm/kvm/Makefile | 10 + arch/arm/kvm/mmio.c | 14 +- arch/arm64/kvm/Kconfig | 7 + arch/arm64/kvm/Makefile | 10 + include/kvm/arm_vgic.h | 10 +- include/kvm/vgic/vgic.h | 250 +++++++ virt/kvm/arm/hyp/vgic-v2-sr.c | 17 +- virt/kvm/arm/pmu.c | 2 +- virt/kvm/arm/vgic-v2.c | 4 +- virt/kvm/arm/vgic.c | 19 +- virt/kvm/arm/vgic/vgic-v2.c | 355 +++++++++ virt/kvm/arm/vgic/vgic-v3.c | 333 +++++++++ virt/kvm/arm/vgic/vgic.c | 617 +++++++++++++++ virt/kvm/arm/vgic/vgic.h | 138 ++++ virt/kvm/arm/vgic/vgic_init.c | 446 +++++++++++ virt/kvm/arm/vgic/vgic_irqfd.c | 51 ++ virt/kvm/arm/vgic/vgic_kvm_device.c | 522 +++++++++++++ virt/kvm/arm/vgic/vgic_mmio.c | 1411 +++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic_mmio.h | 53 ++ 20 files changed, 4242 insertions(+), 34 deletions(-) create mode 100644 include/kvm/vgic/vgic.h create mode 100644 virt/kvm/arm/vgic/vgic-v2.c create mode 100644 virt/kvm/arm/vgic/vgic-v3.c create mode 100644 virt/kvm/arm/vgic/vgic.c create mode 100644 virt/kvm/arm/vgic/vgic.h create mode 100644 virt/kvm/arm/vgic/vgic_init.c create mode 100644 virt/kvm/arm/vgic/vgic_irqfd.c create mode 100644 virt/kvm/arm/vgic/vgic_kvm_device.c create mode 100644 virt/kvm/arm/vgic/vgic_mmio.c create mode 100644 virt/kvm/arm/vgic/vgic_mmio.h
Signature · 1 line
2.7.3
PATCH 1/45 KVM: arm/arm64: Get rid of vgic_cpu->nr_lr
From: Christoffer Dall <[email protected]>
The number of list registers is a property of the underlying system, not of emulated VGIC CPU interface.
As we are about to move this variable to global state in the new vgic for clarity, move it from the legacy implementation as well to make the merge of the new code easier.
--- include/kvm/arm_vgic.h | 3 --- virt/kvm/arm/hyp/vgic-v2-sr.c | 12 +++++++----- virt/kvm/arm/vgic-v2.c | 4 +++- virt/kvm/arm/vgic.c | 12 ++---------- 4 files changed, 12 insertions(+), 19 deletions(-)
include/kvm/arm_vgic.h +0 -3
@@ -303,9 +303,6 @@ struct vgic_cpu {unsigned long *active_shared;unsigned long *pend_act_shared; -/* Number of list registers on this CPU */ -int nr_lr; -/* CPU vif control registers for world switch */ union {struct vgic_v2_cpu_if vgic_v2;
virt/kvm/arm/hyp/vgic-v2-sr.c +7 -5
@@ -21,11 +21,13 @@#include <asm/kvm_hyp.h> +extern struct vgic_params vgic_v2_params; + static void __hyp_text save_maint_int_state(struct kvm_vcpu *vcpu,void __iomem *base) {struct vgic_v2_cpu_if *cpu_if = &vcpu->arch.vgic_cpu.vgic_v2; -int nr_lr = vcpu->arch.vgic_cpu.nr_lr; +int nr_lr = (kern_hyp_va (&vgic_v2_params))->nr_lr;u32 eisr0, eisr1;int i;bool expect_mi;
@@ -67,7 +69,7 @@ static void __hyp_text save_maint_int_state(struct kvm_vcpu *vcpu, static void __hyp_text save_elrsr(struct kvm_vcpu *vcpu, void __iomem *base) {struct vgic_v2_cpu_if *cpu_if = &vcpu->arch.vgic_cpu.vgic_v2; -int nr_lr = vcpu->arch.vgic_cpu.nr_lr; +int nr_lr = (kern_hyp_va (&vgic_v2_params))->nr_lr;u32 elrsr0, elrsr1; elrsr0 =readl_relaxed (base +GICH_ELRSR0 );
@@ -86,7 +88,7 @@ static void __hyp_text save_elrsr(struct kvm_vcpu *vcpu, void __iomem *base) static void __hyp_text save_lrs(struct kvm_vcpu *vcpu, void __iomem *base) {struct vgic_v2_cpu_if *cpu_if = &vcpu->arch.vgic_cpu.vgic_v2; -int nr_lr = vcpu->arch.vgic_cpu.nr_lr; +int nr_lr = (kern_hyp_va (&vgic_v2_params))->nr_lr;int i;for (i =0 ; i < nr_lr; i++) {
@@ -141,13 +143,13 @@ void __hyp_text __vgic_v2_restore_state(struct kvm_vcpu *vcpu)struct vgic_v2_cpu_if *cpu_if = &vcpu->arch.vgic_cpu.vgic_v2;struct vgic_dist *vgic = &kvm->arch.vgic;void __iomem *base =kern_hyp_va (vgic->vctrl_base); -int i, nr_lr; +int nr_lr = (kern_hyp_va (&vgic_v2_params))->nr_lr; +int i;u64 live_lrs =0 ;if (!base)return ; - nr_lr = vcpu->arch.vgic_cpu.nr_lr;for (i =0 ; i < nr_lr; i++)if (cpu_if->vgic_lr[i] &GICH_LR_STATE )
virt/kvm/arm/vgic-v2.c +3 -1
@@ -174,7 +174,7 @@ static const struct vgic_ops vgic_v2_ops = { .enable = vgic_v2_enable, }; -static struct vgic_params vgic_v2_params; +struct vgic_params __section(.hyp.text) vgic_v2_params;static void vgic_cpu_init_lrs (void *params) {
@@ -204,6 +204,8 @@ int vgic_v2_probe(struct device_node *vgic_node,struct resource vcpu_res;struct vgic_params *vgic = &vgic_v2_params; +memset (vgic,0 ,sizeof (*vgic)); + vgic->maint_irq =irq_of_parse_and_map (vgic_node,0 );if (!vgic->maint_irq) {kvm_err ("error getting vgic maintenance irq from DT\n" );
virt/kvm/arm/vgic.c +2 -10
@@ -691,12 +691,11 @@ bool vgic_handle_cfg_reg(u32 *reg, struct kvm_exit_mmio *mmio,*/ void vgic_unqueue_irqs (struct kvm_vcpu *vcpu) { -struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;u64 elrsr =vgic_get_elrsr (vcpu);unsigned long *elrsr_ptr =u64_to_bitmask (&elrsr);int i; -for_each_clear_bit (i, elrsr_ptr, vgic_cpu->nr_lr) { +for_each_clear_bit (i, elrsr_ptr, vgic->nr_lr) {struct vgic_lr lr =vgic_get_lr (vcpu, i);/*
@@ -1107,7 +1106,7 @@ bool kvm_vgic_map_is_active(struct kvm_vcpu *vcpu, unsigned int virt_irq) {int i; -for (i =0 ; i < vcpu->arch.vgic_cpu.nr_lr; i++) { +for (i =0 ; i < vgic->nr_lr; i++) {struct vgic_lr vlr =vgic_get_lr (vcpu, i);if (vlr.irq == virt_irq && vlr.state &LR_STATE_ACTIVE )
@@ -1867,13 +1866,6 @@ static int vgic_vcpu_init_maps(struct kvm_vcpu *vcpu, int nr_irqs)return -ENOMEM ; } -/* -* Store the number of LRs per vcpu, so we don't have to go -* all the way to the distributor structure to find out. Only -* assembly code should use this one. -*/ - vgic_cpu->nr_lr = vgic->nr_lr; -return 0 ; }
Signature · 1 line
2.7.3
PATCH 2/45 KVM: arm/arm64: Fix MMIO emulation data handling
In reply to Andre PrzywaraFrom: Christoffer Dall <[email protected]>
When the kernel was handling a guest MMIO read access internally, we need to copy the emulation result into the run->mmio structure in order for the kvm_handle_mmio_return() function to pick it up and inject the
result back into the guest.
Currently the only user of kvm_io_bus for ARM is the VGIC, which did this copying itself, so this was not causing issues so far.
But with the upcoming new vgic implementation we need this done properly.
Update the kvm_handle_mmio_return description and cleanup the code to only perform a single copying when needed.
Code and commit message inspired by Andre Przywara.
--- arch/arm/kvm/mmio.c | 14 +++++++------- virt/kvm/arm/vgic.c | 7 ------- 2 files changed, 7 insertions(+), 14 deletions(-)
arch/arm/kvm/mmio.c +7 -7
@@ -87,11 +87,10 @@ static unsigned long mmio_read_buf(char *buf, unsigned int len)/** * kvm_handle_mmio_return -- Handle MMIO loads after user space emulation +* or in-kernel IO emulation +* * @vcpu: The VCPU pointer * @run: The VCPU run struct containing the mmio data -* -* This should only be called after returning from userspace for MMIO load -* emulation. */ int kvm_handle_mmio_return (struct kvm_vcpu *vcpu,struct kvm_run *run) {
@@ -206,18 +205,19 @@ int io_mem_abort(struct kvm_vcpu *vcpu, struct kvm_run *run, run->mmio.is_write = is_write; run->mmio.phys_addr = fault_ipa; run->mmio.len = len; -if (is_write) -memcpy (run->mmio.data, data_buf, len);if (!ret) {/* We handled the access successfully in the kernel. */ +if (!is_write) +memcpy (run->mmio.data, data_buf, len); vcpu->stat.mmio_exit_kernel++;kvm_handle_mmio_return (vcpu, run);return 1 ; - }else { - vcpu->stat.mmio_exit_user++; } +if (is_write) +memcpy (run->mmio.data, data_buf, len); + vcpu->stat.mmio_exit_user++; run->exit_reason =KVM_EXIT_MMIO ;return 0 ; }
virt/kvm/arm/vgic.c +0 -7
@@ -820,7 +820,6 @@ static int vgic_handle_mmio_access(struct kvm_vcpu *vcpu,struct vgic_dist *dist = &vcpu->kvm->arch.vgic;struct vgic_io_device *iodev =container_of (this, struct vgic_io_device, dev); -struct kvm_run *run = vcpu->run;const struct vgic_io_range *range;struct kvm_exit_mmio mmio;bool updated_state;
@@ -849,12 +848,6 @@ static int vgic_handle_mmio_access(struct kvm_vcpu *vcpu, updated_state = false; }spin_unlock (&dist->lock); - run->mmio.is_write = is_write; - run->mmio.len = len; - run->mmio.phys_addr = addr; -memcpy (run->mmio.data, val, len); - -kvm_handle_mmio_return (vcpu, run);if (updated_state)vgic_kick_vcpus (vcpu->kvm);
Signature · 1 line
2.7.3
PATCH 3/45 KVM: arm/arm64: pmu: abstract access to number of SPIs
In reply to Andre PrzywaraCurrently the PMU uses a member of the struct vgic_dist directly, which not only breaks abstraction, but will fail with the new VGIC. Abstract this access in the VGIC header file.
--- include/kvm/arm_vgic.h | 2 ++ virt/kvm/arm/pmu.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
include/kvm/arm_vgic.h +2 -0
@@ -347,6 +347,8 @@ bool kvm_vgic_map_is_active(struct kvm_vcpu *vcpu, unsigned int virt_irq);#define irqchip_in_kernel (k) (!!((k)->arch.vgic.in_kernel))#define vgic_initialized (k) (!!((k)->arch.vgic.nr_cpus))#define vgic_ready (k) ((k)->arch.vgic.ready) +#define vgic_valid_spi (k,i) (((i) >= VGIC_NR_PRIVATE_IRQS) && \ + ((i) < (k)->arch.vgic.nr_irqs)) int vgic_v2_probe(struct device_node *vgic_node, const struct vgic_ops **ops,
virt/kvm/arm/pmu.c +1 -1
@@ -476,7 +476,7 @@ int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr)* the interrupt number is the same for all vcpus, while as an * SPI it must be a separate number per vcpu. */ -if (irq <VGIC_NR_SGIS || irq >= vcpu->kvm->arch.vgic.nr_irqs || +if (irq <VGIC_NR_SGIS || !vgic_valid_spi (vcpu->kvm, irq) || !irq_is_valid (vcpu->kvm, irq, irq <VGIC_NR_PRIVATE_IRQS ))return -EINVAL ;
Signature · 1 line
2.7.3
PATCH 4/45 KVM: arm/arm64: vgic-new: Add data structure definitions
In reply to Andre PrzywaraFrom: Christoffer Dall <[email protected]>
Add a new header file for the new and improved GIC implementation. The big change is that we now have a struct vgic_irq per IRQ instead of spreading all the information over various bitmaps.
We include this new header conditionally from within the old header file for the time being to avoid touching all the users.
Changes RFC .. v1:
- adapt to 4.6-rc (adding live_lrs member)
- elaborate on ap_list usage
--- include/kvm/arm_vgic.h | 5 ++ include/kvm/vgic/vgic.h | 201 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 206 insertions(+) create mode 100644 include/kvm/vgic/vgic.h
include/kvm/arm_vgic.h +5 -0
@@ -19,6 +19,10 @@#ifndef __ASM_ARM_KVM_VGIC_H#define __ASM_ARM_KVM_VGIC_H +#ifdef CONFIG_KVM_NEW_VGIC +#include <kvm/vgic/vgic.h> +#else +#include <linux/kernel.h> #include <linux/kvm.h> #include <linux/irqreturn.h>
@@ -366,4 +370,5 @@ static inline int vgic_v3_probe(struct device_node *vgic_node, }#endif +#endif /* old VGIC include */ #endif
include/kvm/vgic/vgic.h new file +201 -0
201 lines not on this page · raw message
Signature · 1 line
2.7.3
PATCH 5/45 KVM: arm/arm64: vgic-new: Add acccessor to new struct vgic_irq instance
In reply to Andre PrzywaraFrom: Christoffer Dall <[email protected]>
The new VGIC implementation centers around a struct vgic_irq instance per virtual IRQ.
Provide a function to retrieve the right instance for a given IRQ number and (in case of private interrupts) the right VCPU.
--- virt/kvm/arm/vgic/vgic.c | 41 +++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.h | 22 ++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 virt/kvm/arm/vgic/vgic.c create mode 100644 virt/kvm/arm/vgic/vgic.h
virt/kvm/arm/vgic/vgic.c new file +41 -0
@@ -0,0 +1,41 @@ +/* +* Copyright (C) 2015, 2016 ARM Ltd. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <linux/kvm.h> +#include <linux/kvm_host.h> + +#include "vgic.h" + +struct vgic_global __section(.hyp.text) kvm_vgic_global_state; + +struct vgic_irq *vgic_get_irq (struct kvm *kvm,struct kvm_vcpu *vcpu, +u32 intid) +{ +/* SGIs and PPIs */ +if (intid <=VGIC_MAX_PRIVATE ) +return &vcpu->arch.vgic_cpu.private_irqs[intid]; + +/* SPIs */ +if (intid <=VGIC_MAX_SPI ) +return &kvm->arch.vgic.spis[intid -VGIC_NR_PRIVATE_IRQS ]; + +/* LPIs are not yet covered */ +if (intid >=VGIC_MIN_LPI ) +return NULL ; + +WARN (1 ,"Looking up struct vgic_irq for reserved INTID" ); +return NULL ; +}
virt/kvm/arm/vgic/vgic.h new file +22 -0
@@ -0,0 +1,22 @@ +/* +* Copyright (C) 2015, 2016 ARM Ltd. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ +#ifndef __KVM_ARM_VGIC_NEW_H__ +#define __KVM_ARM_VGIC_NEW_H__ + +struct vgic_irq *vgic_get_irq (struct kvm *kvm,struct kvm_vcpu *vcpu, +u32 intid); + +#endif
Signature · 1 line
2.7.3
Re: [PATCH 05/45] KVM: arm/arm64: vgic-new: Add acccessor to new struct vgic_irq instance
Hi Andre,
I'm just randomly jumping in here because I spotted a typo in $SUBJECT. 'accessor' has too many c's. Also, just curious, but if the author is from Linaro (hi Christoffer), then why do the new files this patch adds have ARM copyrights?
Thanks,
drew
Quoted 98 lines · Andre Przywara
From: Christoffer Dall <[email protected]>
The new VGIC implementation centers around a struct
vgic_irqinstance per virtual IRQ.
Provide a function to retrieve the right instance for a given IRQ number and (in case of private interrupts) the right VCPU.Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Andre Przywara <[email protected]>--- virt/kvm/arm/vgic/vgic.c | 41 +++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.h | 22 ++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 virt/kvm/arm/vgic/vgic.c create mode 100644 virt/kvm/arm/vgic/vgic.hvirt/kvm/arm/vgic/vgic.c new file +41
-0@@ -0,0 +1,41 @@ +/* +* Copyright (C) 2015, 2016 ARM Ltd. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <linux/kvm.h> +#include <linux/kvm_host.h> + +#include "vgic.h" + +struct vgic_global __section(.hyp.text) kvm_vgic_global_state; + +struct vgic_irq *vgic_get_irq (struct kvm *kvm,struct kvm_vcpu *vcpu, +u32 intid) +{ +/* SGIs and PPIs */ +if (intid <=VGIC_MAX_PRIVATE ) +return &vcpu->arch.vgic_cpu.private_irqs[intid]; + +/* SPIs */ +if (intid <=VGIC_MAX_SPI ) +return &kvm->arch.vgic.spis[intid -VGIC_NR_PRIVATE_IRQS ]; + +/* LPIs are not yet covered */ +if (intid >=VGIC_MIN_LPI ) +return NULL ; + +WARN (1 ,"Looking up struct vgic_irq for reserved INTID" ); +return NULL ; +}virt/kvm/arm/vgic/vgic.h new file +22
-0@@ -0,0 +1,22 @@ +/* +* Copyright (C) 2015, 2016 ARM Ltd. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ +#ifndef __KVM_ARM_VGIC_NEW_H__ +#define __KVM_ARM_VGIC_NEW_H__ + +struct vgic_irq *vgic_get_irq (struct kvm *kvm,struct kvm_vcpu *vcpu, +u32 intid); + +#endif Signature · 6 lines
2.7.3 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 05/45] KVM: arm/arm64: vgic-new: Add acccessor to new struct vgic_irq instance
Quoted 7 lines · Andrew Jones
Hi Andre,
I'm just randomly jumping in here because I spotted a typo in $SUBJECT. 'accessor' has too many c's. Also, just curious, but if the author is from Linaro (hi Christoffer), then why do the new files this patch adds have ARM copyrights?
We just decided to let ARM deal with asserting the license since we all collaborated on it, but others also suggested that we should let ARM and Linaro share the license.
-Christoffer
Quoted 100 lines · Andre Przywara
Quoted 98 lines
From: Christoffer Dall <[email protected]>
The new VGIC implementation centers around a struct
vgic_irqinstance per virtual IRQ.
Provide a function to retrieve the right instance for a given IRQ number and (in case of private interrupts) the right VCPU.Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Andre Przywara <[email protected]>--- virt/kvm/arm/vgic/vgic.c | 41 +++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.h | 22 ++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 virt/kvm/arm/vgic/vgic.c create mode 100644 virt/kvm/arm/vgic/vgic.hvirt/kvm/arm/vgic/vgic.c new file +41
-0@@ -0,0 +1,41 @@ +/* +* Copyright (C) 2015, 2016 ARM Ltd. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <linux/kvm.h> +#include <linux/kvm_host.h> + +#include "vgic.h" + +struct vgic_global __section(.hyp.text) kvm_vgic_global_state; + +struct vgic_irq *vgic_get_irq (struct kvm *kvm,struct kvm_vcpu *vcpu, +u32 intid) +{ +/* SGIs and PPIs */ +if (intid <=VGIC_MAX_PRIVATE ) +return &vcpu->arch.vgic_cpu.private_irqs[intid]; + +/* SPIs */ +if (intid <=VGIC_MAX_SPI ) +return &kvm->arch.vgic.spis[intid -VGIC_NR_PRIVATE_IRQS ]; + +/* LPIs are not yet covered */ +if (intid >=VGIC_MIN_LPI ) +return NULL ; + +WARN (1 ,"Looking up struct vgic_irq for reserved INTID" ); +return NULL ; +}virt/kvm/arm/vgic/vgic.h new file +22
-0@@ -0,0 +1,22 @@ +/* +* Copyright (C) 2015, 2016 ARM Ltd. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ +#ifndef __KVM_ARM_VGIC_NEW_H__ +#define __KVM_ARM_VGIC_NEW_H__ + +struct vgic_irq *vgic_get_irq (struct kvm *kvm,struct kvm_vcpu *vcpu, +u32 intid); + +#endif Signature · 6 lines
2.7.3 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 05/45] KVM: arm/arm64: vgic-new: Add acccessor to new struct vgic_irq instance
Quoted 9 lines · Christoffer Dall
Quoted 7 lines · Andrew Jones
Hi Andre,
I'm just randomly jumping in here because I spotted a typo in $SUBJECT. 'accessor' has too many c's. Also, just curious, but if the author is from Linaro (hi Christoffer), then why do the new files this patch adds have ARM copyrights?
Quoted 3 lines
We just decided to let ARM deal with asserting the license since we all collaborated on it, but others also suggested that we should let ARM and Linaro share the license.
I personally have no objections to having both ARM and Linaro sharing the copyright, but I just don't know how this works in practice (and asking any legal department is a sure recipe to delay these patches for an extra 6 months, give or take a few years).
In the end, all I care about is the licence under which the code is released.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH 05/45] KVM: arm/arm64: vgic-new: Add acccessor to new struct vgic_irq instance
Quoted 14 lines · Marc Zyngier
Quoted 9 lines · Christoffer Dall
Quoted 7 lines · Andrew Jones
Hi Andre,
I'm just randomly jumping in here because I spotted a typo in $SUBJECT. 'accessor' has too many c's. Also, just curious, but if the author is from Linaro (hi Christoffer), then why do the new files this patch adds have ARM copyrights?
Quoted 3 lines
We just decided to let ARM deal with asserting the license since we all collaborated on it, but others also suggested that we should let ARM and Linaro share the license.
Quoted 8 lines
I personally have no objections to having both ARM and Linaro sharing the copyright, but I just don't know how this works in practice (and asking any legal department is a sure recipe to delay these patches for an extra 6 months, give or take a few years).
In the end, all I care about is the licence under which the code is released.
Thanks, my curiosity is satisfied. I fully agree that if it's not easy to share a collaborated file, then it's just a matter of flipping a coin, or defaulting to whichever has the majority.
drew
Re: [PATCH 05/45] KVM: arm/arm64: vgic-new: Add acccessor to new struct vgic_irq instance
Quoted 20 lines · Andrew Jones
Quoted 19 lines · Marc Zyngier
Quoted 9 lines · Christoffer Dall
Quoted 7 lines · Andrew Jones
Hi Andre,
I'm just randomly jumping in here because I spotted a typo in $SUBJECT. 'accessor' has too many c's. Also, just curious, but if the author is from Linaro (hi Christoffer), then why do the new files this patch adds have ARM copyrights?
Quoted 3 lines
We just decided to let ARM deal with asserting the license since we all collaborated on it, but others also suggested that we should let ARM and Linaro share the license.
I personally have no objections to having both ARM and Linaro sharing the copyright, but I just don't know how this works in practice (and asking any legal department is a sure recipe to delay these patches for an extra 6 months, give or take a few years).
Quoted 8 lines
Quoted 3 lines
In the end, all I care about is the licence under which the code is released.
Thanks, my curiosity is satisfied. I fully agree that if it's not easy to share a collaborated file, then it's just a matter of flipping a coin, or defaulting to whichever has the majority.
I also only care about the license under which it is released.
I opted for defaulting to the company that is most set up to pursue any potential infringement on the copyright.
-Christoffer
PATCH 6/45 KVM: arm/arm64: vgic-new: Implement virtual IRQ injection
In reply to Andre PrzywaraFrom: Christoffer Dall <[email protected]>
Provide a vgic_queue_irq() function which decides whether a given IRQ needs to be queued to a VCPU's ap_list.
This should be called whenever an IRQ becomes pending or enabled, either as a result of userspace injection, from in-kernel emulated devices like the architected timer or from MMIO accesses to the distributor emulation.
Also provides the necessary functions to allow userland to inject an IRQ to a guest.
Since this is the first code that starts using our locking mechanism, we add some (hopefully) clear documentation of our locking strategy and requirements along with this patch.
[Andre: refactor out vgic_queue_irq_unlock()]
Changelog RFC..v1:
- add spinlock checks protected by CONFIG_DEBUG_SPINLOCK
- add more comments to vgic_target_oracle
- remove BUG_ON() if IRQ is neither edge or level
- rename vgic_queue_irq() to vgic_queue_irq_unlock()
- simplify initial check in vgic_queue_irq_unlock()
- extend retry loop to ask the oracle again
- minor comment fixes
--- include/kvm/vgic/vgic.h | 3 + virt/kvm/arm/vgic/vgic.c | 197 +++++++++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.h | 1 + 3 files changed, 201 insertions(+)
include/kvm/vgic/vgic.h +3 -0
@@ -181,6 +181,9 @@ struct vgic_cpu {u64 live_lrs; }; +int kvm_vgic_inject_irq (struct kvm *kvm,int cpuid,unsigned int intid, +bool level); +#define irqchip_in_kernel (k) (!!((k)->arch.vgic.in_kernel))#define vgic_initialized (k) (false)#define vgic_ready (k) ((k)->arch.vgic.ready)
virt/kvm/arm/vgic/vgic.c +197 -0
208 lines not on this page · raw message
virt/kvm/arm/vgic/vgic.h +1 -0
@@ -18,5 +18,6 @@struct vgic_irq *vgic_get_irq (struct kvm *kvm,struct kvm_vcpu *vcpu,u32 intid); +bool vgic_queue_irq_unlock (struct kvm *kvm,struct vgic_irq *irq);#endif
Signature · 1 line
2.7.3
PATCH 7/45 KVM: arm/arm64: vgic-new: Add IRQ sorting
In reply to Andre PrzywaraFrom: Christoffer Dall <[email protected]>
Adds the sorting function to cover the case where you have more IRQs to consider than you have LRs. We now consider priorities.
--- virt/kvm/arm/vgic/vgic.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+)
virt/kvm/arm/vgic/vgic.c +57 -0
@@ -16,6 +16,7 @@#include <linux/kvm.h> #include <linux/kvm_host.h> +#include <linux/list_sort.h> #include "vgic.h"
@@ -96,6 +97,62 @@ static struct kvm_vcpu *vgic_target_oracle(struct vgic_irq *irq) }/* +* The order of items in the ap_lists defines how we'll pack things in LRs as +* well, the first items in the list being the first things populated in the +* LRs. +* +* A hard rule is that active interrupts can never be pushed out of the LRs +* (and therefore take priority) since we cannot reliably trap on deactivation +* of IRQs and therefore they have to be present in the LRs. +* +* Otherwise things should be sorted by the priority field and the GIC +* hardware support will take care of preemption of priority groups etc. +* +* Return negative if "a" sorts before "b", 0 to preserve order, and positive +* to sort "b" before "a". +*/ +static int vgic_irq_cmp (void *priv,struct list_head *a,struct list_head *b) +{ + struct vgic_irq *irqa = container_of(a, struct vgic_irq, ap_list); + struct vgic_irq *irqb = container_of(b, struct vgic_irq, ap_list); +bool penda, pendb; +int ret; + +spin_lock (&irqa->irq_lock); +spin_lock (&irqb->irq_lock); + +if (irqa->active || irqb->active) { + ret = (int )irqb->active - (int )irqa->active; + goto out; + } + + penda = irqa->enabled && irqa->pending; + pendb = irqb->enabled && irqb->pending; + +if (!penda || !pendb) { + ret = (int )pendb - (int )penda; + goto out; + } + +/* Both pending and enabled, sort by priority */ + ret = irqa->priority - irqb->priority; +out: +spin_unlock (&irqb->irq_lock); +spin_unlock (&irqa->irq_lock); +return ret; +} + +/* Must be called with the ap_list_lock held */ +static void vgic_sort_ap_list (struct kvm_vcpu *vcpu) +{ +struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; + +DEBUG_SPINLOCK_BUG_ON (!spin_is_locked (&vgic_cpu->ap_list_lock)); + +list_sort (NULL , &vgic_cpu->ap_list_head, vgic_irq_cmp); +} + +/* * Only valid injection if changing level for level-triggered IRQs or for a * rising edge. */
Signature · 1 line
2.7.3
PATCH 8/45 KVM: arm/arm64: vgic-new: Add IRQ sync/flush framework
In reply to Andre PrzywaraFrom: Marc Zyngier <[email protected]>
Implement the framework for syncing IRQs between our emulation and the list registers, which represent the guest's view of IRQs. This is done in kvm_vgic_flush_hwstate and kvm_vgic_sync_hwstate, which gets called on guest entry and exit.
The code talking to the actual GICv2/v3 hardware is added in the following patches.
Changelog RFC..v1:
- split out vgic_clear_lr() from vgic_populate_lr()
- rename vgic_populate_lrs() to vgic_flush_lr_state()
- clean all LRs when the distributor is disabled
- use list_del() instead of list_del_init()
- add comments to explain the direction of sync/flush_hwstate
- remove unneeded BUG_ON(in_interrupt()
--- include/kvm/vgic/vgic.h | 4 + virt/kvm/arm/vgic/vgic.c | 200 +++++++++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.h | 2 + 3 files changed, 206 insertions(+)
include/kvm/vgic/vgic.h +4 -0
@@ -190,6 +190,10 @@ int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid,#define vgic_valid_spi (k,i) (((i) >= VGIC_NR_PRIVATE_IRQS) && \ ((i) < (k)->arch.vgic.nr_spis + VGIC_NR_PRIVATE_IRQS)) +bool kvm_vcpu_has_pending_irqs (struct kvm_vcpu *vcpu); +void kvm_vgic_sync_hwstate (struct kvm_vcpu *vcpu); +void kvm_vgic_flush_hwstate (struct kvm_vcpu *vcpu); +/** * kvm_vgic_get_max_vcpus - Get the maximum number of VCPUs allowed by HW *
virt/kvm/arm/vgic/vgic.c +200 -0
203 lines not on this page · raw message
virt/kvm/arm/vgic/vgic.h +2 -0
@@ -16,6 +16,8 @@#ifndef __KVM_ARM_VGIC_NEW_H__#define __KVM_ARM_VGIC_NEW_H__ +#define vgic_irq_is_sgi (intid) ((intid) < VGIC_NR_SGIS) +struct vgic_irq *vgic_get_irq (struct kvm *kvm,struct kvm_vcpu *vcpu,u32 intid);bool vgic_queue_irq_unlock (struct kvm *kvm,struct vgic_irq *irq);
Signature · 1 line
2.7.3
PATCH 9/45 KVM: arm/arm64: vgic-new: Add GICv2 world switch backend
In reply to Andre PrzywaraFrom: Marc Zyngier <[email protected]>
Processing maintenance interrupts and accessing the list registers are dependent on the host's GIC version.
Introduce vgic-v2.c to contain GICv2 specific functions. Implement the GICv2 specific code for syncing the emulation state into the VGIC registers.
Also add vgic_v2_irq_change_affinity() to change the target VCPU of a particular interrupt.
Changelog RFC..v1:
- remove explicit LR_STATE clearing on maintenance interrupt handling
- improve documentation for vgic_v2_populate_lr()
- remove WARN_ON on non-edge IRQs in maintenance interrupts
- simplify multi-CPU source SGI handling
--- virt/kvm/arm/vgic/vgic-v2.c | 175 ++++++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.c | 19 +++-- virt/kvm/arm/vgic/vgic.h | 6 ++ 3 files changed, 190 insertions(+), 10 deletions(-) create mode 100644 virt/kvm/arm/vgic/vgic-v2.c
virt/kvm/arm/vgic/vgic-v2.c new file +175 -0
@@ -0,0 +1,175 @@ +/* +* Copyright (C) 2015, 2016 ARM Ltd. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <linux/irqchip/arm-gic.h> +#include <linux/kvm.h> +#include <linux/kvm_host.h> + +#include "vgic.h" + +/* +* Call this function to convert a u64 value to an unsigned long * bitmask +* in a way that works on both 32-bit and 64-bit LE and BE platforms. +* +* Warning: Calling this function may modify *val. +*/ +static unsigned long *u64_to_bitmask (u64 *val) +{ +#if defined(CONFIG_CPU_BIG_ENDIAN ) &&BITS_PER_LONG ==32 + *val = (*val >>32 ) | (*val <<32 ); +#endif +return (unsigned long *)val; +} + +void vgic_v2_process_maintenance (struct kvm_vcpu *vcpu) +{ +struct vgic_v2_cpu_if *cpuif = &vcpu->arch.vgic_cpu.vgic_v2; + +if (cpuif->vgic_misr &GICH_MISR_EOI ) { +u64 eisr = cpuif->vgic_eisr; +unsigned long *eisr_bmap =u64_to_bitmask (&eisr); +int lr; + +for_each_set_bit (lr, eisr_bmap, kvm_vgic_global_state.nr_lr) { +u32 intid = cpuif->vgic_lr[lr] &GICH_LR_VIRTUALID ; + +WARN_ON (cpuif->vgic_lr[lr] &GICH_LR_STATE ); + +kvm_notify_acked_irq (vcpu->kvm,0 , + intid -VGIC_NR_PRIVATE_IRQS ); + + cpuif->vgic_elrsr |=1ULL << lr; + } + } + +/* check and disable underflow maintenance IRQ */ + cpuif->vgic_hcr &= ~GICH_HCR_UIE ; + +/* +* In the next iterations of the vcpu loop, if we sync the +* vgic state after flushing it, but before entering the guest +* (this happens for pending signals and vmid rollovers), then +* make sure we don't pick up any old maintenance interrupts +* here. +*/ + cpuif->vgic_eisr =0 ; +} + +void vgic_v2_set_underflow (struct kvm_vcpu *vcpu) +{ +struct vgic_v2_cpu_if *cpuif = &vcpu->arch.vgic_cpu.vgic_v2; + + cpuif->vgic_hcr |=GICH_HCR_UIE ; +} + +/* +* transfer the content of the LRs back into the corresponding ap_list: +* - active bit is transferred as is +* - pending bit is +* - transferred as is in case of edge sensitive IRQs +* - set to the line-level (resample time) for level sensitive IRQs +*/ +void vgic_v2_fold_lr_state (struct kvm_vcpu *vcpu) +{ +struct vgic_v2_cpu_if *cpuif = &vcpu->arch.vgic_cpu.vgic_v2; +int lr; + +for (lr =0 ; lr < vcpu->arch.vgic_cpu.used_lrs; lr++) { +u32 val = cpuif->vgic_lr[lr]; +u32 intid = val &GICH_LR_VIRTUALID ; +struct vgic_irq *irq; + + irq =vgic_get_irq (vcpu->kvm, vcpu, intid); + +spin_lock (&irq->irq_lock); + +/* Always preserve the active bit */ + irq->active = !!(val &GICH_LR_ACTIVE_BIT ); + +/* Edge is the only case where we preserve the pending bit */ +if (irq->config ==VGIC_CONFIG_EDGE && + (val &GICH_LR_PENDING_BIT )) { + irq->pending = true; + +if (vgic_irq_is_sgi (intid)) { +u32 cpuid = val &GICH_LR_PHYSID_CPUID ; + + cpuid >>=GICH_LR_PHYSID_CPUID_SHIFT ; + irq->source |= (1 << cpuid); + } + } + +/* Clear soft pending state when level IRQs have been acked */ +if (irq->config ==VGIC_CONFIG_LEVEL && + !(val &GICH_LR_PENDING_BIT )) { + irq->soft_pending = false; + irq->pending = irq->line_level; + } + +spin_unlock (&irq->irq_lock); + } +} + +/* +* Populates the particular LR with the state of a given IRQ: +* - for an edge sensitive IRQ the pending state is cleared in struct vgic_irq +* - for a level sensitive IRQ the pending state value is unchanged; +* it is dictated directly by the input level +* +* If @irq describes an SGI with multiple sources, we choose the +* lowest-numbered source VCPU and clear that bit in the source bitmap. +* +* The irq_lock must be held by the caller. +*/ +void vgic_v2_populate_lr (struct kvm_vcpu *vcpu,struct vgic_irq *irq,int lr) +{ +u32 val = irq->intid; + +if (irq->pending) { + val |=GICH_LR_PENDING_BIT ; + +if (irq->config ==VGIC_CONFIG_EDGE ) + irq->pending = false; + +if (vgic_irq_is_sgi (irq->intid)) { +u32 src =ffs (irq->source); + +BUG_ON (!src); + val |= (src -1 ) <<GICH_LR_PHYSID_CPUID_SHIFT ; + irq->source &= ~(1 << (src -1 )); +if (irq->source) + irq->pending = true; + } + } + +if (irq->active) + val |=GICH_LR_ACTIVE_BIT ; + +if (irq->hw) { + val |=GICH_LR_HW ; + val |= irq->hwintid <<GICH_LR_PHYSID_CPUID_SHIFT ; + }else { +if (irq->config ==VGIC_CONFIG_LEVEL ) + val |=GICH_LR_EOI ; + } + + vcpu->arch.vgic_cpu.vgic_v2.vgic_lr[lr] = val; +} + +void vgic_v2_clear_lr (struct kvm_vcpu *vcpu,int lr) +{ + vcpu->arch.vgic_cpu.vgic_v2.vgic_lr[lr] =0 ; +}
virt/kvm/arm/vgic/vgic.c +9 -10
@@ -385,10 +385,12 @@ retry:static inline void vgic_process_maintenance_interrupt (struct kvm_vcpu *vcpu) { +vgic_v2_process_maintenance (vcpu); }static inline void vgic_fold_lr_state (struct kvm_vcpu *vcpu) { +vgic_v2_fold_lr_state (vcpu); }/* Requires the ap_list_lock and the irq_lock to be held. */
@@ -397,14 +399,18 @@ static inline void vgic_populate_lr(struct kvm_vcpu *vcpu, {DEBUG_SPINLOCK_BUG_ON (!spin_is_locked (&vcpu->arch.vgic_cpu.ap_list_lock));DEBUG_SPINLOCK_BUG_ON (!spin_is_locked (&irq->irq_lock)); + +vgic_v2_populate_lr (vcpu, irq, lr); }static inline void vgic_clear_lr (struct kvm_vcpu *vcpu,int lr) { +vgic_v2_clear_lr (vcpu, lr); }static inline void vgic_set_underflow (struct kvm_vcpu *vcpu) { +vgic_v2_set_underflow (vcpu); }static int compute_ap_list_depth (struct kvm_vcpu *vcpu)
@@ -429,14 +435,12 @@ static int compute_ap_list_depth(struct kvm_vcpu *vcpu)static void vgic_flush_lr_state (struct kvm_vcpu *vcpu) {struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; -struct vgic_dist *dist = &vcpu->kvm->arch.vgic; -u32 model = dist->vgic_model;struct vgic_irq *irq;int count =0 ;DEBUG_SPINLOCK_BUG_ON (!spin_is_locked (vgic_cpu->ap_list_lock)); -if (unlikely (!dist->enabled)) +if (unlikely (!vcpu->kvm->arch.vgic.enabled)) goto out_clean;if (compute_ap_list_depth (vcpu) > kvm_vgic_global_state.nr_lr) {
@@ -454,14 +458,9 @@ static void vgic_flush_lr_state(struct kvm_vcpu *vcpu)* If we get an SGI with multiple sources, try to get * them in all at once. */ -if (model ==KVM_DEV_TYPE_ARM_VGIC_V2 && -vgic_irq_is_sgi (irq->intid)) { -while (irq->source && - count < kvm_vgic_global_state.nr_lr) -vgic_populate_lr (vcpu, irq, count++); - }else { +do {vgic_populate_lr (vcpu, irq, count++); - } + }while (irq->source && count < kvm_vgic_global_state.nr_lr); next:spin_unlock (&irq->irq_lock);
virt/kvm/arm/vgic/vgic.h +6 -0
@@ -22,4 +22,10 @@ struct vgic_irq *vgic_get_irq(struct kvm *kvm, struct kvm_vcpu *vcpu, u32 intid);bool vgic_queue_irq_unlock (struct kvm *kvm,struct vgic_irq *irq); +void vgic_v2_process_maintenance (struct kvm_vcpu *vcpu); +void vgic_v2_fold_lr_state (struct kvm_vcpu *vcpu); +void vgic_v2_populate_lr (struct kvm_vcpu *vcpu,struct vgic_irq *irq,int lr); +void vgic_v2_clear_lr (struct kvm_vcpu *vcpu,int lr); +void vgic_v2_set_underflow (struct kvm_vcpu *vcpu); +#endif
Signature · 1 line
2.7.3
PATCH 10/45 KVM: arm/arm64: vgic-new: Add GICv3 world switch backend
In reply to Andre PrzywaraFrom: Marc Zyngier <[email protected]>
As the GICv3 virtual interface registers differ from their GICv2 siblings, we need different handlers for processing maintenance interrupts and reading/writing to the LRs.
Also as we store an IRQ's affinity directly as a MPIDR, we need a separate change_affinity() implementation too. Implement the respective handler functions and connect them to existing code to be called if the host is using a GICv3.
Changelog RFC..v1:
- remove outdated comment about the dist_lock
- add WARN_ON about LR_STATE not being 0 in maintenance interrupts
--- virt/kvm/arm/vgic/vgic-v3.c | 167 ++++++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.c | 25 +++++-- virt/kvm/arm/vgic/vgic.h | 29 ++++++++ 3 files changed, 216 insertions(+), 5 deletions(-) create mode 100644 virt/kvm/arm/vgic/vgic-v3.c
virt/kvm/arm/vgic/vgic-v3.c new file +167 -0
@@ -0,0 +1,167 @@ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <linux/irqchip/arm-gic-v3.h> +#include <linux/kvm.h> +#include <linux/kvm_host.h> +#include <linux/irqchip/arm-gic.h> + +#include "vgic.h" + +void vgic_v3_process_maintenance (struct kvm_vcpu *vcpu) +{ +struct vgic_v3_cpu_if *cpuif = &vcpu->arch.vgic_cpu.vgic_v3; +u32 model = vcpu->kvm->arch.vgic.vgic_model; + +if (cpuif->vgic_misr &ICH_MISR_EOI ) { +unsigned long eisr_bmap = cpuif->vgic_eisr; +int lr; + +for_each_set_bit (lr, &eisr_bmap, kvm_vgic_global_state.nr_lr) { +u32 intid; +u64 val = cpuif->vgic_lr[lr]; + +if (model ==KVM_DEV_TYPE_ARM_VGIC_V3 ) + intid = val &ICH_LR_VIRTUAL_ID_MASK ; +else + intid = val &GICH_LR_VIRTUALID ; + +WARN_ON (cpuif->vgic_lr[lr] &ICH_LR_STATE ); + +kvm_notify_acked_irq (vcpu->kvm,0 , + intid -VGIC_NR_PRIVATE_IRQS ); + + cpuif->vgic_elrsr |=1ULL << lr; + } + +/* +* In the next iterations of the vcpu loop, if we sync +* the vgic state after flushing it, but before +* entering the guest (this happens for pending +* signals and vmid rollovers), then make sure we +* don't pick up any old maintenance interrupts here. +*/ + cpuif->vgic_eisr =0 ; + } + + cpuif->vgic_hcr &= ~ICH_HCR_UIE ; +} + +void vgic_v3_set_underflow (struct kvm_vcpu *vcpu) +{ +struct vgic_v3_cpu_if *cpuif = &vcpu->arch.vgic_cpu.vgic_v3; + + cpuif->vgic_hcr |=ICH_HCR_UIE ; +} + +void vgic_v3_fold_lr_state (struct kvm_vcpu *vcpu) +{ +struct vgic_v3_cpu_if *cpuif = &vcpu->arch.vgic_cpu.vgic_v3; +u32 model = vcpu->kvm->arch.vgic.vgic_model; +int lr; + +/* Assumes ap_list_lock held */ + +for (lr =0 ; lr < vcpu->arch.vgic_cpu.used_lrs; lr++) { +u64 val = cpuif->vgic_lr[lr]; +u32 intid; +struct vgic_irq *irq; + +if (model ==KVM_DEV_TYPE_ARM_VGIC_V3 ) + intid = val &ICH_LR_VIRTUAL_ID_MASK ; +else + intid = val &GICH_LR_VIRTUALID ; + irq =vgic_get_irq (vcpu->kvm, vcpu, intid); + +spin_lock (&irq->irq_lock); + +/* Always preserve the active bit */ + irq->active = !!(val &ICH_LR_ACTIVE_BIT ); + +/* Edge is the only case where we preserve the pending bit */ +if (irq->config ==VGIC_CONFIG_EDGE && + (val &ICH_LR_PENDING_BIT )) { + irq->pending = true; + +if (vgic_irq_is_sgi (intid) && + model ==KVM_DEV_TYPE_ARM_VGIC_V2 ) { +u32 cpuid = val &GICH_LR_PHYSID_CPUID ; + + cpuid >>=GICH_LR_PHYSID_CPUID_SHIFT ; + irq->source |= (1 << cpuid); + } + } + +/* Clear soft pending state when level irqs have been acked */ +if (irq->config ==VGIC_CONFIG_LEVEL && + !(val &ICH_LR_PENDING_BIT )) { + irq->soft_pending = false; + irq->pending = irq->line_level; + } + +spin_unlock (&irq->irq_lock); + } +} + +/* Requires the irq to be locked already */ +void vgic_v3_populate_lr (struct kvm_vcpu *vcpu,struct vgic_irq *irq,int lr) +{ +u32 model = vcpu->kvm->arch.vgic.vgic_model; +u64 val = irq->intid; + +if (irq->pending) { + val |=ICH_LR_PENDING_BIT ; + +if (irq->config ==VGIC_CONFIG_EDGE ) + irq->pending = false; + +if (vgic_irq_is_sgi (irq->intid) && + model ==KVM_DEV_TYPE_ARM_VGIC_V2 ) { +u32 src =ffs (irq->source); + +BUG_ON (!src); + val |= (src -1 ) <<GICH_LR_PHYSID_CPUID_SHIFT ; + irq->source &= ~(1 << (src -1 )); +if (irq->source) + irq->pending = true; + } + } + +if (irq->active) + val |=ICH_LR_ACTIVE_BIT ; + +if (irq->hw) { + val |=ICH_LR_HW ; + val |= ((u64 )irq->hwintid) <<ICH_LR_PHYS_ID_SHIFT ; + }else { +if (irq->config ==VGIC_CONFIG_LEVEL ) + val |=ICH_LR_EOI ; + } + +/* +* Currently all guest IRQs are Group1, as Group0 would result +* in a FIQ in the guest, which it wouldn't expect. +* Eventually we want to make this configurable, so we may +* revisit this in the future. +*/ +if (model ==KVM_DEV_TYPE_ARM_VGIC_V3 ) + val |=ICH_LR_GROUP ; + + vcpu->arch.vgic_cpu.vgic_v3.vgic_lr[lr] = val; +} + +void vgic_v3_clear_lr (struct kvm_vcpu *vcpu,int lr) +{ + vcpu->arch.vgic_cpu.vgic_v3.vgic_lr[lr] =0 ; +}
virt/kvm/arm/vgic/vgic.c +20 -5
@@ -385,12 +385,18 @@ retry:static inline void vgic_process_maintenance_interrupt (struct kvm_vcpu *vcpu) { -vgic_v2_process_maintenance (vcpu); +if (kvm_vgic_global_state.type ==VGIC_V2 ) +vgic_v2_process_maintenance (vcpu); +else +vgic_v3_process_maintenance (vcpu); }static inline void vgic_fold_lr_state (struct kvm_vcpu *vcpu) { -vgic_v2_fold_lr_state (vcpu); +if (kvm_vgic_global_state.type ==VGIC_V2 ) +vgic_v2_fold_lr_state (vcpu); +else +vgic_v3_fold_lr_state (vcpu); }/* Requires the ap_list_lock and the irq_lock to be held. */
@@ -400,17 +406,26 @@ static inline void vgic_populate_lr(struct kvm_vcpu *vcpu,DEBUG_SPINLOCK_BUG_ON (!spin_is_locked (&vcpu->arch.vgic_cpu.ap_list_lock));DEBUG_SPINLOCK_BUG_ON (!spin_is_locked (&irq->irq_lock)); -vgic_v2_populate_lr (vcpu, irq, lr); +if (kvm_vgic_global_state.type ==VGIC_V2 ) +vgic_v2_populate_lr (vcpu, irq, lr); +else +vgic_v3_populate_lr (vcpu, irq, lr); }static inline void vgic_clear_lr (struct kvm_vcpu *vcpu,int lr) { -vgic_v2_clear_lr (vcpu, lr); +if (kvm_vgic_global_state.type ==VGIC_V2 ) +vgic_v2_clear_lr (vcpu, lr); +else +vgic_v3_clear_lr (vcpu, lr); }static inline void vgic_set_underflow (struct kvm_vcpu *vcpu) { -vgic_v2_set_underflow (vcpu); +if (kvm_vgic_global_state.type ==VGIC_V2 ) +vgic_v2_set_underflow (vcpu); +else +vgic_v3_set_underflow (vcpu); }static int compute_ap_list_depth (struct kvm_vcpu *vcpu)
virt/kvm/arm/vgic/vgic.h +29 -0
@@ -28,4 +28,33 @@ void vgic_v2_populate_lr(struct kvm_vcpu *vcpu, struct vgic_irq *irq, int lr);void vgic_v2_clear_lr (struct kvm_vcpu *vcpu,int lr);void vgic_v2_set_underflow (struct kvm_vcpu *vcpu); +#ifdef CONFIG_KVM_ARM_VGIC_V3 +void vgic_v3_process_maintenance (struct kvm_vcpu *vcpu); +void vgic_v3_fold_lr_state (struct kvm_vcpu *vcpu); +void vgic_v3_populate_lr (struct kvm_vcpu *vcpu,struct vgic_irq *irq,int lr); +void vgic_v3_clear_lr (struct kvm_vcpu *vcpu,int lr); +void vgic_v3_set_underflow (struct kvm_vcpu *vcpu); +#else +static inline void vgic_v3_process_maintenance (struct kvm_vcpu *vcpu) +{ +} + +static inline void vgic_v3_fold_lr_state (struct kvm_vcpu *vcpu) +{ +} + +static inline void vgic_v3_populate_lr (struct kvm_vcpu *vcpu, +struct vgic_irq *irq,int lr) +{ +} + +static inline void vgic_v3_clear_lr (struct kvm_vcpu *vcpu,int lr) +{ +} + +static inline void vgic_v3_set_underflow (struct kvm_vcpu *vcpu) +{ +} +#endif +#endif
Signature · 1 line
2.7.3
PATCH 11/45 KVM: arm/arm64: vgic-new: Implement kvm_vgic_vcpu_pending_irq
In reply to Andre PrzywaraFrom: Eric Auger <[email protected]>
Tell KVM whether a particular VCPU has an IRQ that needs handling in the guest. This is used to decide whether a VCPU is runnable.
Changelog RFC..v1:
- return false if distributor is disabled
- add vgic_kick_vcpus() implementations
--- include/kvm/vgic/vgic.h | 2 ++ virt/kvm/arm/vgic/vgic.c | 40 ++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.h | 1 + 3 files changed, 43 insertions(+)
include/kvm/vgic/vgic.h +2 -0
@@ -184,6 +184,8 @@ struct vgic_cpu {int kvm_vgic_inject_irq (struct kvm *kvm,int cpuid,unsigned int intid,bool level); +int kvm_vgic_vcpu_pending_irq (struct kvm_vcpu *vcpu); +#define irqchip_in_kernel (k) (!!((k)->arch.vgic.in_kernel))#define vgic_initialized (k) (false)#define vgic_ready (k) ((k)->arch.vgic.ready)
virt/kvm/arm/vgic/vgic.c +40 -0
@@ -507,3 +507,43 @@ void kvm_vgic_flush_hwstate(struct kvm_vcpu *vcpu)vgic_flush_lr_state (vcpu);spin_unlock (&vcpu->arch.vgic_cpu.ap_list_lock); } + +int kvm_vgic_vcpu_pending_irq (struct kvm_vcpu *vcpu) +{ +struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; +struct vgic_irq *irq; +bool pending = false; + +if (!vcpu->kvm->arch.vgic.enabled) +return false; + +spin_lock (&vgic_cpu->ap_list_lock); + +list_for_each_entry (irq, &vgic_cpu->ap_list_head, ap_list) { +spin_lock (&irq->irq_lock); + pending = irq->pending && irq->enabled; +spin_unlock (&irq->irq_lock); + +if (pending) +break ; + } + +spin_unlock (&vgic_cpu->ap_list_lock); + +return pending; +} + +void vgic_kick_vcpus (struct kvm *kvm) +{ +struct kvm_vcpu *vcpu; +int c; + +/* +* We've injected an interrupt, time to find out who deserves +* a good kick... +*/ +kvm_for_each_vcpu (c, vcpu, kvm) { +if (kvm_vgic_vcpu_pending_irq (vcpu)) +kvm_vcpu_kick (vcpu); + } +}
virt/kvm/arm/vgic/vgic.h +1 -0
@@ -21,6 +21,7 @@struct vgic_irq *vgic_get_irq (struct kvm *kvm,struct kvm_vcpu *vcpu,u32 intid);bool vgic_queue_irq_unlock (struct kvm *kvm,struct vgic_irq *irq); +void vgic_kick_vcpus (struct kvm *kvm);void vgic_v2_process_maintenance (struct kvm_vcpu *vcpu);void vgic_v2_fold_lr_state (struct kvm_vcpu *vcpu);
Signature · 1 line
2.7.3
PATCH 12/45 KVM: arm/arm64: vgic-new: Add MMIO handling framework
In reply to Andre PrzywaraWe register a kvm_io_bus device for the distributor and dispatch the calls to the actual register handler at runtime. Ideally we would register each register group directly with the kvm_io_bus framework, but currently we run into the limit of 1000 devices pretty quickly (with GICv3), so we use this approach here, at least for the time being.
Changelog RFC..v1:
- rework MMIO dispatching to use only one kvm_io_bus device
- document purpose of register region macros
- rename "this" parameter to "dev"
- change IGROUPR to be RAO (returning 1 => Group1 IRQs)
--- include/kvm/vgic/vgic.h | 9 ++ virt/kvm/arm/vgic/vgic_mmio.c | 226 ++++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic_mmio.h | 53 ++++++++++ 3 files changed, 288 insertions(+) create mode 100644 virt/kvm/arm/vgic/vgic_mmio.c create mode 100644 virt/kvm/arm/vgic/vgic_mmio.h
include/kvm/vgic/vgic.h +9 -0
@@ -106,6 +106,12 @@ struct vgic_irq {enum vgic_irq_config config;/* Level or edge */ }; +struct vgic_io_device { +gpa_t base_addr; +struct kvm_vcpu *redist_vcpu; +struct kvm_io_device dev; +}; +struct vgic_dist {bool in_kernel;bool ready;
@@ -132,6 +138,9 @@ struct vgic_dist {u32 enabled;struct vgic_irq *spis; + +struct vgic_io_device dist_iodev; +struct vgic_io_device *redist_iodevs; };struct vgic_v2_cpu_if {
virt/kvm/arm/vgic/vgic_mmio.c new file +226 -0
226 lines not on this page · raw message
virt/kvm/arm/vgic/vgic_mmio.h new file +53 -0
53 lines not on this page · raw message
Signature · 1 line
2.7.3
PATCH 13/45 KVM: arm/arm64: vgic-new: Export register access interface
In reply to Andre PrzywaraUserland can access the emulated GIC to save and restore its state for initialization or migration purposes.
The kvm_io_bus API requires an absolute gpa, which does not fit the KVM_DEV_ARM_VGIC_GRP_DIST_REGS user API, that only provides relative offsets. So we explicitly iterate our register list to connect userland to the VGIC.
--- virt/kvm/arm/vgic/vgic.h | 2 ++ virt/kvm/arm/vgic/vgic_mmio.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+)
virt/kvm/arm/vgic/vgic.h +2 -0
@@ -28,6 +28,8 @@ void vgic_v2_fold_lr_state(struct kvm_vcpu *vcpu);void vgic_v2_populate_lr (struct kvm_vcpu *vcpu,struct vgic_irq *irq,int lr);void vgic_v2_clear_lr (struct kvm_vcpu *vcpu,int lr);void vgic_v2_set_underflow (struct kvm_vcpu *vcpu); +int vgic_v2_dist_access (struct kvm_vcpu *vcpu,bool is_write, +int offset,int len,void *val);#ifdef CONFIG_KVM_ARM_VGIC_V3 void vgic_v3_process_maintenance (struct kvm_vcpu *vcpu);
virt/kvm/arm/vgic/vgic_mmio.c +30 -0
@@ -178,6 +178,36 @@ static int dispatch_mmio_write(struct kvm_vcpu *vcpu,return region->ops.write (vcpu, dev, addr, len, val); } +/* +* When userland tries to access the VGIC register handlers, we need to +* create a usable struct vgic_io_device to be passed to the handlers. +*/ +static int vgic_device_mmio_access (struct kvm_vcpu *vcpu, +struct vgic_register_region *regions, +int nr_regions,bool is_write, +int offset,int len,void *val) +{ +struct vgic_io_device dev = { + .base_addr =0 , + .redist_vcpu = vcpu, + }; + +if (is_write) +return dispatch_mmio_write (vcpu, regions, nr_regions, + &dev.dev, offset, len, val); +else +return dispatch_mmio_read (vcpu, regions, nr_regions, + &dev.dev, offset, len, val); +} + +int vgic_v2_dist_access (struct kvm_vcpu *vcpu,bool is_write, +int offset,int len,void *val) +{ +return vgic_device_mmio_access (vcpu, vgic_v2_dist_registers, +ARRAY_SIZE (vgic_v2_dist_registers), + is_write, offset, len, val); +} +int vgic_mmio_read_v2dist (struct kvm_vcpu *vcpu,struct kvm_io_device *dev,gpa_t addr,int len,void *val) {
Signature · 1 line
2.7.3
PATCH 14/45 KVM: arm/arm64: vgic-new: Add CTLR, TYPER and IIDR handlers
In reply to Andre PrzywaraChangelog RFC..v1:
- kick VCPUs is the distributor gets enabled
- improve comment
--- virt/kvm/arm/vgic/vgic.h | 3 +++ virt/kvm/arm/vgic/vgic_mmio.c | 50 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-)
virt/kvm/arm/vgic/vgic.h +3 -0
@@ -16,6 +16,9 @@#ifndef __KVM_ARM_VGIC_NEW_H__#define __KVM_ARM_VGIC_NEW_H__ +#define PRODUCT_ID_KVM 0x4b/* ASCII code K */ +#define IMPLEMENTER_ARM 0x43b +#define vgic_irq_is_sgi (intid) ((intid) < VGIC_NR_SGIS) struct vgic_irq *vgic_get_irq(struct kvm *kvm, struct kvm_vcpu *vcpu,
virt/kvm/arm/vgic/vgic_mmio.c +49 -1
58 lines not on this page · raw message
Signature · 1 line
2.7.3
PATCH 15/45 KVM: arm/arm64: vgic-new: Add ENABLE registers handlers
In reply to Andre PrzywaraChangelog RFC..v1:
- use lower bits of address to determine IRQ number
- remove TODO, confirmed to be fine
--- virt/kvm/arm/vgic/vgic_mmio.c | 80 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 2 deletions(-)
virt/kvm/arm/vgic/vgic_mmio.c +78 -2
@@ -138,15 +138,91 @@ static int vgic_mmio_write_v2_misc(struct kvm_vcpu *vcpu,return 0 ; } +/* +* Read accesses to both GICD_ICENABLER and GICD_ISENABLER return the value +* of the enabled bit, so there is only one function for both here. +*/ +static int vgic_mmio_read_enable (struct kvm_vcpu *vcpu, +struct kvm_io_device *dev, +gpa_t addr,int len,void *val) +{ +struct vgic_io_device *iodev =container_of (dev, + struct vgic_io_device, dev); +u32 intid = (addr &0x7f ) *8 ; +u32 value =0 ; +int i; + +if (iodev->redist_vcpu) + vcpu = iodev->redist_vcpu; + +/* Loop over all IRQs affected by this read */ +for (i =0 ; i < len *8 ; i++) { +struct vgic_irq *irq =vgic_get_irq (vcpu->kvm, vcpu, intid + i); + +if (irq->enabled) + value |= (1U << i); + } + +write_mask32 (value, addr &3 , len, val); +return 0 ; +} + +static int vgic_mmio_write_senable (struct kvm_vcpu *vcpu, +struct kvm_io_device *dev, +gpa_t addr,int len,const void *val) +{ +struct vgic_io_device *iodev =container_of (dev, + struct vgic_io_device, dev); +u32 intid = (addr &0x7f ) *8 ; +int i; + +if (iodev->redist_vcpu) + vcpu = iodev->redist_vcpu; + +for_each_set_bit (i, val, len *8 ) { +struct vgic_irq *irq =vgic_get_irq (vcpu->kvm, vcpu, intid + i); + +spin_lock (&irq->irq_lock); + irq->enabled = true; +vgic_queue_irq_unlock (vcpu->kvm, irq); + } + +return 0 ; +} + +static int vgic_mmio_write_cenable (struct kvm_vcpu *vcpu, +struct kvm_io_device *dev, +gpa_t addr,int len,const void *val) +{ +struct vgic_io_device *iodev =container_of (dev, + struct vgic_io_device, dev); +u32 intid = (addr &0x7f ) *8 ; +int i; + +if (iodev->redist_vcpu) + vcpu = iodev->redist_vcpu; + +for_each_set_bit (i, val, len *8 ) { +struct vgic_irq *irq =vgic_get_irq (vcpu->kvm, vcpu, intid + i); + +spin_lock (&irq->irq_lock); + + irq->enabled = false; + +spin_unlock (&irq->irq_lock); + } +return 0 ; +} +struct vgic_register_region vgic_v2_dist_registers[] = {REGISTER_DESC_WITH_LENGTH (GIC_DIST_CTRL , vgic_mmio_read_v2_misc, vgic_mmio_write_v2_misc,12 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_IGROUP , vgic_mmio_read_rao, vgic_mmio_write_wi,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_ENABLE_SET , - vgic_mmio_read_nyi, vgic_mmio_write_nyi,1 ), + vgic_mmio_read_enable, vgic_mmio_write_senable,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_ENABLE_CLEAR , - vgic_mmio_read_nyi, vgic_mmio_write_nyi,1 ), + vgic_mmio_read_enable, vgic_mmio_write_cenable,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_PENDING_SET , vgic_mmio_read_nyi, vgic_mmio_write_nyi,1 ), REGISTER_DESC_WITH_BITS_PER_IRQ(GIC_DIST_PENDING_CLEAR,
Signature · 1 line
2.7.3
PATCH 16/45 KVM: arm/arm64: vgic-new: Add PENDING registers handlers
In reply to Andre PrzywaraChangelog RFC..v1:
- remove IRQ lock from read handler
- remove TODO from clear pending handler
--- virt/kvm/arm/vgic/vgic_mmio.c | 84 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 2 deletions(-)
virt/kvm/arm/vgic/vgic_mmio.c +82 -2
@@ -214,6 +214,86 @@ static int vgic_mmio_write_cenable(struct kvm_vcpu *vcpu,return 0 ; } +static int vgic_mmio_read_pending (struct kvm_vcpu *vcpu, +struct kvm_io_device *dev, +gpa_t addr,int len,void *val) +{ +struct vgic_io_device *iodev =container_of (dev, + struct vgic_io_device, dev); +u32 intid = (addr &0x7f ) *8 ; +u32 value =0 ; +int i; + +if (iodev->redist_vcpu) + vcpu = iodev->redist_vcpu; + +/* Loop over all IRQs affected by this read */ +for (i =0 ; i < len *8 ; i++) { +struct vgic_irq *irq =vgic_get_irq (vcpu->kvm, vcpu, intid + i); + +if (irq->pending) + value |= (1U << i); + } + +write_mask32 (value, addr &3 , len, val); +return 0 ; +} + +static int vgic_mmio_write_spending (struct kvm_vcpu *vcpu, +struct kvm_io_device *dev, +gpa_t addr,int len,const void *val) +{ +struct vgic_io_device *iodev =container_of (dev, + struct vgic_io_device, dev); +u32 intid = (addr &0x7f ) *8 ; +int i; + +if (iodev->redist_vcpu) + vcpu = iodev->redist_vcpu; + +for_each_set_bit (i, val, len *8 ) { +struct vgic_irq *irq =vgic_get_irq (vcpu->kvm, vcpu, intid + i); + +spin_lock (&irq->irq_lock); + irq->pending = true; +if (irq->config ==VGIC_CONFIG_LEVEL ) + irq->soft_pending = true; + +vgic_queue_irq_unlock (vcpu->kvm, irq); + } + +return 0 ; +} + +static int vgic_mmio_write_cpending (struct kvm_vcpu *vcpu, +struct kvm_io_device *dev, +gpa_t addr,int len,const void *val) +{ +struct vgic_io_device *iodev =container_of (dev, + struct vgic_io_device, dev); +u32 intid = (addr &0x7f ) *8 ; +int i; + +if (iodev->redist_vcpu) + vcpu = iodev->redist_vcpu; + +for_each_set_bit (i, val, len *8 ) { +struct vgic_irq *irq =vgic_get_irq (vcpu->kvm, vcpu, intid + i); + +spin_lock (&irq->irq_lock); + +if (irq->config ==VGIC_CONFIG_LEVEL ) { + irq->soft_pending = false; + irq->pending = irq->line_level; + }else { + irq->pending = false; + } + +spin_unlock (&irq->irq_lock); + } +return 0 ; +} +struct vgic_register_region vgic_v2_dist_registers[] = {REGISTER_DESC_WITH_LENGTH (GIC_DIST_CTRL , vgic_mmio_read_v2_misc, vgic_mmio_write_v2_misc,12 ),
@@ -224,9 +304,9 @@ struct vgic_register_region vgic_v2_dist_registers[] = {REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_ENABLE_CLEAR , vgic_mmio_read_enable, vgic_mmio_write_cenable,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_PENDING_SET , - vgic_mmio_read_nyi, vgic_mmio_write_nyi,1 ), + vgic_mmio_read_pending, vgic_mmio_write_spending,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_PENDING_CLEAR , - vgic_mmio_read_nyi, vgic_mmio_write_nyi,1 ), + vgic_mmio_read_pending, vgic_mmio_write_cpending,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_ACTIVE_SET , vgic_mmio_read_nyi, vgic_mmio_write_nyi,1 ), REGISTER_DESC_WITH_BITS_PER_IRQ(GIC_DIST_ACTIVE_CLEAR,
Signature · 1 line
2.7.3
PATCH 17/45 KVM: arm/arm64: vgic-new: Add PRIORITY registers handlers
In reply to Andre Przywara--- virt/kvm/arm/vgic/vgic_mmio.c | 46 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-)
virt/kvm/arm/vgic/vgic_mmio.c +45 -1
@@ -294,6 +294,50 @@ static int vgic_mmio_write_cpending(struct kvm_vcpu *vcpu,return 0 ; } +static int vgic_mmio_read_priority (struct kvm_vcpu *vcpu, +struct kvm_io_device *dev, +gpa_t addr,int len,void *val) +{ +struct vgic_io_device *iodev =container_of (dev, + struct vgic_io_device, dev); +u32 intid = addr &0x3ff ; +int i; + +if (iodev->redist_vcpu) + vcpu = iodev->redist_vcpu; + +for (i =0 ; i < len; i++) { +struct vgic_irq *irq =vgic_get_irq (vcpu->kvm, vcpu, intid + i); + + ((u8 *)val)[i] = irq->priority; + } + +return 0 ; +} + +static int vgic_mmio_write_priority (struct kvm_vcpu *vcpu, +struct kvm_io_device *dev, +gpa_t addr,int len,const void *val) +{ +struct vgic_io_device *iodev =container_of (dev, + struct vgic_io_device, dev); +u32 intid = addr &0x3ff ; +int i; + +if (iodev->redist_vcpu) + vcpu = iodev->redist_vcpu; + +for (i =0 ; i < len; i++) { +struct vgic_irq *irq =vgic_get_irq (vcpu->kvm, vcpu, intid + i); + +spin_lock (&irq->irq_lock); + irq->priority = ((u8 *)val)[i]; +spin_unlock (&irq->irq_lock); + } + +return 0 ; +} +struct vgic_register_region vgic_v2_dist_registers[] = {REGISTER_DESC_WITH_LENGTH (GIC_DIST_CTRL , vgic_mmio_read_v2_misc, vgic_mmio_write_v2_misc,12 ),
@@ -312,7 +356,7 @@ struct vgic_register_region vgic_v2_dist_registers[] = {REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_ACTIVE_CLEAR , vgic_mmio_read_nyi, vgic_mmio_write_nyi,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_PRI , - vgic_mmio_read_nyi, vgic_mmio_write_nyi,8 ), + vgic_mmio_read_priority, vgic_mmio_write_priority,8 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_TARGET , vgic_mmio_read_nyi, vgic_mmio_write_nyi,8 ), REGISTER_DESC_WITH_BITS_PER_IRQ(GIC_DIST_CONFIG,
Signature · 1 line
2.7.3
PATCH 18/45 KVM: arm/arm64: vgic-new: Add ACTIVE registers handlers
In reply to Andre PrzywaraChangelog RFC..v1:
- handling queueing in write handler
- remove IRQ lock from read handler
--- virt/kvm/arm/vgic/vgic_mmio.c | 143 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 141 insertions(+), 2 deletions(-)
virt/kvm/arm/vgic/vgic_mmio.c +141 -2
@@ -294,6 +294,145 @@ static int vgic_mmio_write_cpending(struct kvm_vcpu *vcpu,return 0 ; } +static int vgic_mmio_read_active (struct kvm_vcpu *vcpu, +struct kvm_io_device *dev, +gpa_t addr,int len,void *val) +{ +struct vgic_io_device *iodev =container_of (dev, + struct vgic_io_device, dev); +u32 intid = (addr &0x7f ) *8 ; +u32 value =0 ; +int i; + +if (iodev->redist_vcpu) + vcpu = iodev->redist_vcpu; + +/* Loop over all IRQs affected by this read */ +for (i =0 ; i < len *8 ; i++) { +struct vgic_irq *irq =vgic_get_irq (vcpu->kvm, vcpu, intid + i); + +if (irq->active) + value |= (1U << i); + } + +write_mask32 (value, addr &3 , len, val); +return 0 ; +} + +static int vgic_mmio_write_cactive (struct kvm_vcpu *vcpu, +struct kvm_io_device *dev, +gpa_t addr,int len,const void *val) +{ +struct vgic_io_device *iodev =container_of (dev, + struct vgic_io_device, dev); +u32 intid = (addr &0x7f ) *8 ; +int i; + +if (iodev->redist_vcpu) + vcpu = iodev->redist_vcpu; + +for_each_set_bit (i, val, len *8 ) { +struct vgic_irq *irq =vgic_get_irq (vcpu->kvm, vcpu, intid + i); + +spin_lock (&irq->irq_lock); + + irq->active = false; + +/* +* Christoffer wrote: +* The question is what to do if the vcpu for this irq is +* running and the LR there has the active bit set, then we'll +* overwrite this change when we fold the LR state back into +* the vgic_irq struct. +* +* Since I expect this to be extremely rare, one option is to +* force irq->vcpu to exit (if non-null) and then do you +* thing here after you've confirm it has exited while holding +* some lock preventing it from re-entering again. +* Slightly crazy. +* +* The alternative is to put a big fat comment nothing that +* this is non-supported bad race, and wait until someone +* submits a bug report relating to this... +*/ + +spin_unlock (&irq->irq_lock); + } +return 0 ; +} + +static int vgic_mmio_write_sactive (struct kvm_vcpu *vcpu, +struct kvm_io_device *dev, +gpa_t addr,int len,const void *val) +{ +struct vgic_io_device *iodev =container_of (dev, + struct vgic_io_device, dev); +u32 intid = (addr &0x7f ) *8 ; +int i; + +if (iodev->redist_vcpu) + vcpu = iodev->redist_vcpu; + +for_each_set_bit (i, val, len *8 ) { +struct vgic_irq *irq =vgic_get_irq (vcpu->kvm, vcpu, intid + i); + +spin_lock (&irq->irq_lock); + +/* As this is a special case, we can't use the +* vgic_queue_irq_unlock() function to put this on a VCPU. +* So deal with this here explicitly unless the IRQs was +* already active, it was on a VCPU before or there is no +* target VCPU assigned at the moment. +*/ +if (irq->active || irq->vcpu || !irq->target_vcpu) { + irq->active = true; + +spin_unlock (&irq->irq_lock); +continue ; + } + +spin_unlock (&irq->irq_lock); +retry: + vcpu = irq->target_vcpu; + +spin_lock (&vcpu->arch.vgic_cpu.ap_list_lock); +spin_lock (&irq->irq_lock); + +/* +* Recheck after dropping the IRQ lock to see if we should +* still care about queueing it. +*/ +if (irq->active || irq->vcpu) { + irq->active = true; + +spin_unlock (&irq->irq_lock); +spin_unlock (&vcpu->arch.vgic_cpu.ap_list_lock); + +continue ; + } + +/* Did the target VCPU change while we had the lock dropped? */ +if (vcpu != irq->target_vcpu) { +spin_unlock (&irq->irq_lock); +spin_unlock (&vcpu->arch.vgic_cpu.ap_list_lock); + + goto retry; + } + +/* Now queue the IRQ to the VCPU's ap_list. */ +list_add_tail (&irq->ap_list, &vcpu->arch.vgic_cpu.ap_list_head); + irq->vcpu = vcpu; + + irq->active = true; + +spin_unlock (&irq->irq_lock); +spin_unlock (&vcpu->arch.vgic_cpu.ap_list_lock); + +kvm_vcpu_kick (vcpu); + } +return 0 ; +} +static int vgic_mmio_read_priority (struct kvm_vcpu *vcpu,struct kvm_io_device *dev,gpa_t addr,int len,void *val)
@@ -352,9 +491,9 @@ struct vgic_register_region vgic_v2_dist_registers[] = {REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_PENDING_CLEAR , vgic_mmio_read_pending, vgic_mmio_write_cpending,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_ACTIVE_SET , - vgic_mmio_read_nyi, vgic_mmio_write_nyi,1 ), + vgic_mmio_read_active, vgic_mmio_write_sactive,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_ACTIVE_CLEAR , - vgic_mmio_read_nyi, vgic_mmio_write_nyi,1 ), + vgic_mmio_read_active, vgic_mmio_write_cactive,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_PRI , vgic_mmio_read_priority, vgic_mmio_write_priority,8 ), REGISTER_DESC_WITH_BITS_PER_IRQ(GIC_DIST_TARGET,
Signature · 1 line
2.7.3
PATCH 19/45 KVM: arm/arm64: vgic-new: Add CONFIG registers handlers
In reply to Andre Przywara--- virt/kvm/arm/vgic/vgic_mmio.c | 62 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-)
virt/kvm/arm/vgic/vgic_mmio.c +61 -1
@@ -477,6 +477,66 @@ static int vgic_mmio_write_priority(struct kvm_vcpu *vcpu,return 0 ; } +static int vgic_mmio_read_config (struct kvm_vcpu *vcpu, +struct kvm_io_device *dev, +gpa_t addr,int len,void *val) +{ +struct vgic_io_device *iodev =container_of (dev, + struct vgic_io_device, dev); +u32 intid = (addr &0xff ) *4 ; +u32 value =0 ; +int i; + +if (iodev->redist_vcpu) + vcpu = iodev->redist_vcpu; + +for (i =0 ; i < len *4 ; i++) { +struct vgic_irq *irq =vgic_get_irq (vcpu->kvm, vcpu, intid + i); + +if (irq->config ==VGIC_CONFIG_EDGE ) + value |= (2U << (i *2 )); + } + +write_mask32 (value, addr &3 , len, val); +return 0 ; +} + +static int vgic_mmio_write_config (struct kvm_vcpu *vcpu, +struct kvm_io_device *dev, +gpa_t addr,int len,const void *val) +{ +struct vgic_io_device *iodev =container_of (dev, + struct vgic_io_device, dev); +u32 intid = (addr &0xff ) *4 ; +int i; + +if (iodev->redist_vcpu) + vcpu = iodev->redist_vcpu; + +for (i =0 ; i < len *4 ; i++) { +struct vgic_irq *irq =vgic_get_irq (vcpu->kvm, vcpu, intid + i); + +if (intid + i <16 ) +continue ; + +/* +* The spec says that interrupts must be disabled before +* changing the configuration to avoid UNDEFINED behaviour. +*/ + +spin_lock (&irq->irq_lock); +if (test_bit (i *2 +1 , val)) { + irq->config =VGIC_CONFIG_EDGE ; + }else { + irq->config =VGIC_CONFIG_LEVEL ; + irq->pending = irq->line_level | irq->soft_pending; + } +spin_unlock (&irq->irq_lock); + } + +return 0 ; +} +struct vgic_register_region vgic_v2_dist_registers[] = {REGISTER_DESC_WITH_LENGTH (GIC_DIST_CTRL , vgic_mmio_read_v2_misc, vgic_mmio_write_v2_misc,12 ),
@@ -499,7 +559,7 @@ struct vgic_register_region vgic_v2_dist_registers[] = {REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_TARGET , vgic_mmio_read_nyi, vgic_mmio_write_nyi,8 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_CONFIG , - vgic_mmio_read_nyi, vgic_mmio_write_nyi,8 ), + vgic_mmio_read_config, vgic_mmio_write_config,2 ),REGISTER_DESC_WITH_LENGTH (GIC_DIST_SOFTINT , vgic_mmio_read_nyi, vgic_mmio_write_nyi,4 ), REGISTER_DESC_WITH_LENGTH(GIC_DIST_SGI_PENDING_CLEAR,
Signature · 1 line
2.7.3
PATCH 20/45 KVM: arm/arm64: vgic-new: Add TARGET registers handlers
In reply to Andre PrzywaraChangelog RFC..v1:
- remove runtime VCPU determination from this v2-only register
- fold in implementation of vgic_v2_irq_change_affinity()
- replace ffs() with __ffs()
--- virt/kvm/arm/vgic/vgic_mmio.c | 45 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-)
virt/kvm/arm/vgic/vgic_mmio.c +44 -1
@@ -537,6 +537,49 @@ static int vgic_mmio_write_config(struct kvm_vcpu *vcpu,return 0 ; } +static int vgic_mmio_read_target (struct kvm_vcpu *vcpu, +struct kvm_io_device *dev, +gpa_t addr,int len,void *val) +{ +u32 intid = addr &0x3ff ; +int i; + +for (i =0 ; i < len; i++) { +struct vgic_irq *irq =vgic_get_irq (vcpu->kvm, vcpu, intid + i); + + ((u8 *)val)[i] = irq->targets; + } + +return 0 ; +} + +static int vgic_mmio_write_target (struct kvm_vcpu *vcpu, +struct kvm_io_device *dev, +gpa_t addr,int len,const void *val) +{ +u32 intid = addr &0x3ff ; +int i; + +/* GICD_ITARGETSR[0-7] are read-only */ +if (intid <VGIC_NR_PRIVATE_IRQS ) +return 0 ; + +for (i =0 ; i < len; i++) { +struct vgic_irq *irq =vgic_get_irq (vcpu->kvm,NULL , intid + i); +int target; + +spin_lock (&irq->irq_lock); + + irq->targets = ((u8 *)val)[i]; + target = irq->targets ?__ffs (irq->targets) :0 ; + irq->target_vcpu =kvm_get_vcpu (vcpu->kvm, target); + +spin_unlock (&irq->irq_lock); + } + +return 0 ; +} +struct vgic_register_region vgic_v2_dist_registers[] = {REGISTER_DESC_WITH_LENGTH (GIC_DIST_CTRL , vgic_mmio_read_v2_misc, vgic_mmio_write_v2_misc,12 ),
@@ -557,7 +600,7 @@ struct vgic_register_region vgic_v2_dist_registers[] = {REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_PRI , vgic_mmio_read_priority, vgic_mmio_write_priority,8 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_TARGET , - vgic_mmio_read_nyi, vgic_mmio_write_nyi,8 ), + vgic_mmio_read_target, vgic_mmio_write_target,8 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_CONFIG , vgic_mmio_read_config, vgic_mmio_write_config,2 ), REGISTER_DESC_WITH_LENGTH(GIC_DIST_SOFTINT,
Signature · 1 line
2.7.3
PATCH 21/45 KVM: arm/arm64: vgic-new: Add SGIR register handler
In reply to Andre PrzywaraChangelog RFC..v1:
- silently return on illegal TargetListFilter value (=3)
--- virt/kvm/arm/vgic/vgic_mmio.c | 46 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-)
virt/kvm/arm/vgic/vgic_mmio.c +45 -1
@@ -580,6 +580,50 @@ static int vgic_mmio_write_target(struct kvm_vcpu *vcpu,return 0 ; } +static int vgic_mmio_write_sgir (struct kvm_vcpu *source_vcpu, +struct kvm_io_device *dev, +gpa_t addr,int len,const void *val) +{ +int nr_vcpus =atomic_read (&source_vcpu->kvm->online_vcpus); +u32 value = *(u32 *)val; +int intid = value &0xf ; +int targets = (value >>16 ) &0xff ; +int mode = (value >>24 ) &0x03 ; +int c; +struct kvm_vcpu *vcpu; + +switch (mode) { +case 0x0 :/* as specified by targets */ +break ; +case 0x1 : + targets = (1U << nr_vcpus) -1 ;/* all, ... */ + targets &= ~(1U << source_vcpu->vcpu_id);/* but self */ +break ; +case 0x2 :/* this very vCPU only */ + targets = (1U << source_vcpu->vcpu_id); +break ; +case 0x3 :/* reserved */ +return 0 ; + } + +kvm_for_each_vcpu (c, vcpu, source_vcpu->kvm) { +struct vgic_irq *irq; + +if (!(targets & (1U << c))) +continue ; + + irq =vgic_get_irq (source_vcpu->kvm, vcpu, intid); + +spin_lock (&irq->irq_lock); + irq->pending = true; + irq->source |=1U << source_vcpu->vcpu_id; + +vgic_queue_irq_unlock (source_vcpu->kvm, irq); + } + +return 0 ; +} +struct vgic_register_region vgic_v2_dist_registers[] = {REGISTER_DESC_WITH_LENGTH (GIC_DIST_CTRL , vgic_mmio_read_v2_misc, vgic_mmio_write_v2_misc,12 ),
@@ -604,7 +648,7 @@ struct vgic_register_region vgic_v2_dist_registers[] = {REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_CONFIG , vgic_mmio_read_config, vgic_mmio_write_config,2 ),REGISTER_DESC_WITH_LENGTH (GIC_DIST_SOFTINT , - vgic_mmio_read_nyi, vgic_mmio_write_nyi,4 ), + vgic_mmio_read_raz, vgic_mmio_write_sgir,4 ),REGISTER_DESC_WITH_LENGTH (GIC_DIST_SGI_PENDING_CLEAR , vgic_mmio_read_nyi, vgic_mmio_write_nyi,16 ), REGISTER_DESC_WITH_LENGTH(GIC_DIST_SGI_PENDING_SET,
Signature · 1 line
2.7.3
PATCH 22/45 KVM: arm/arm64: vgic-new: Add SGIPENDR register handlers
In reply to Andre PrzywaraChangelog RFC..v1:
- remove IRQ lock from read handler
- update pending bit on setting the first / clearing the last bit
- queue virtual IRQ if necessary
--- virt/kvm/arm/vgic/vgic_mmio.c | 64 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-)
virt/kvm/arm/vgic/vgic_mmio.c +62 -2
@@ -624,6 +624,66 @@ static int vgic_mmio_write_sgir(struct kvm_vcpu *source_vcpu,return 0 ; } +static int vgic_mmio_read_sgipend (struct kvm_vcpu *vcpu, +struct kvm_io_device *dev, +gpa_t addr,int len,void *val) +{ +u32 intid = addr &0x0f ; +int i; + +for (i =0 ; i < len; i++) { +struct vgic_irq *irq =vgic_get_irq (vcpu->kvm, vcpu, intid + i); + + ((u8 *)val)[i] = irq->source; + } +return 0 ; +} + +static int vgic_mmio_write_sgipendc (struct kvm_vcpu *vcpu, +struct kvm_io_device *dev, +gpa_t addr,int len,const void *val) +{ +u32 intid = addr &0x0f ; +int i; + +for (i =0 ; i < len; i++) { +struct vgic_irq *irq =vgic_get_irq (vcpu->kvm, vcpu, intid + i); + +spin_lock (&irq->irq_lock); + + irq->source &= ~((u8 *)val)[i]; +if (!irq->source) + irq->pending = false; + +spin_unlock (&irq->irq_lock); + } +return 0 ; +} + +static int vgic_mmio_write_sgipends (struct kvm_vcpu *vcpu, +struct kvm_io_device *dev, +gpa_t addr,int len,const void *val) +{ +u32 intid = addr &0x0f ; +int i; + +for (i =0 ; i < len; i++) { +struct vgic_irq *irq =vgic_get_irq (vcpu->kvm, vcpu, intid + i); + +spin_lock (&irq->irq_lock); + + irq->source |= ((u8 *)val)[i]; + +if (irq->source) { + irq->pending = true; +vgic_queue_irq_unlock (vcpu->kvm, irq); + }else { +spin_unlock (&irq->irq_lock); + } + } +return 0 ; +} +struct vgic_register_region vgic_v2_dist_registers[] = {REGISTER_DESC_WITH_LENGTH (GIC_DIST_CTRL , vgic_mmio_read_v2_misc, vgic_mmio_write_v2_misc,12 ),
@@ -650,9 +710,9 @@ struct vgic_register_region vgic_v2_dist_registers[] = {REGISTER_DESC_WITH_LENGTH (GIC_DIST_SOFTINT , vgic_mmio_read_raz, vgic_mmio_write_sgir,4 ),REGISTER_DESC_WITH_LENGTH (GIC_DIST_SGI_PENDING_CLEAR , - vgic_mmio_read_nyi, vgic_mmio_write_nyi,16 ), + vgic_mmio_read_sgipend, vgic_mmio_write_sgipendc,16 ),REGISTER_DESC_WITH_LENGTH (GIC_DIST_SGI_PENDING_SET , - vgic_mmio_read_nyi, vgic_mmio_write_nyi, 16), + vgic_mmio_read_sgipend, vgic_mmio_write_sgipends, 16), };/* Find the proper register handler entry given a certain address offset. */
Signature · 1 line
2.7.3
PATCH 23/45 KVM: arm/arm64: vgic-new: Add GICv3 MMIO handling framework
In reply to Andre PrzywaraDescribe the GICv3 distributor and redistributor registers in our structure. This adds a special macro to deal with the split of SGI/PPI in the redistributor and SPIs in the distributor, which allows us to reuse the existing GICv2 handlers for those registers which are compatible.
Also we register the separate MMIO page for the redistributor registers dealing with private interrupts.
Changelog RFC..v1:
- adapt to new MMIO registration approach:
register one device for the distributor and two for each VCPU
- implement special handling for private interrupts
- remove empty stub functions
- make IGROUPR return RAO
--- virt/kvm/arm/vgic/vgic.h | 16 +++ virt/kvm/arm/vgic/vgic_mmio.c | 269 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 285 insertions(+)
virt/kvm/arm/vgic/vgic.h +16 -0
@@ -40,6 +40,10 @@ void vgic_v3_fold_lr_state(struct kvm_vcpu *vcpu);void vgic_v3_populate_lr (struct kvm_vcpu *vcpu,struct vgic_irq *irq,int lr);void vgic_v3_clear_lr (struct kvm_vcpu *vcpu,int lr);void vgic_v3_set_underflow (struct kvm_vcpu *vcpu); +int vgic_v3_dist_access (struct kvm_vcpu *vcpu,bool is_write, +int offset,int len,void *val); +int vgic_v3_redist_access (struct kvm_vcpu *vcpu,bool is_write, +int offset,int len,void *val);#else static inline void vgic_v3_process_maintenance (struct kvm_vcpu *vcpu) {
@@ -61,6 +65,18 @@ static inline void vgic_v3_clear_lr(struct kvm_vcpu *vcpu, int lr)static inline void vgic_v3_set_underflow (struct kvm_vcpu *vcpu) { } + +static inline int vgic_v3_dist_access (struct kvm_vcpu *vcpu,bool is_write, +int offset,int len,void *val) +{ +return -ENXIO ; +} + +static inline int vgic_v3_redist_access (struct kvm_vcpu *vcpu,bool is_write, +int offset,int len,void *val) +{ +return -ENXIO ; +}#endif #endif
virt/kvm/arm/vgic/vgic_mmio.c +269 -0
302 lines not on this page · raw message
Signature · 1 line
2.7.3
Re: [PATCH 23/45] KVM: arm/arm64: vgic-new: Add GICv3 MMIO handling framework
Quoted 60 lines · Andre Przywara
Describe the GICv3 distributor and redistributor registers in our structure. This adds a special macro to deal with the split of SGI/PPI in the redistributor and SPIs in the distributor, which allows us to reuse the existing GICv2 handlers for those registers which are compatible.
Also we register the separate MMIO page for the redistributor registers dealing with private interrupts.Signed-off-by Andre Przywara <[email protected]>Changelog RFC..v1:
- adapt to new MMIO registration approach:
register one device for the distributor and two for each VCPU
- implement special handling for private interrupts
- remove empty stub functions
- make IGROUPR return RAO--- virt/kvm/arm/vgic/vgic.h | 16 +++ virt/kvm/arm/vgic/vgic_mmio.c | 269 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 285 insertions(+)virt/kvm/arm/vgic/vgic.h +16
-0@@ -40,6 +40,10 @@ void vgic_v3_fold_lr_state(struct kvm_vcpu *vcpu);void vgic_v3_populate_lr (struct kvm_vcpu *vcpu,struct vgic_irq *irq,int lr);void vgic_v3_clear_lr (struct kvm_vcpu *vcpu,int lr);void vgic_v3_set_underflow (struct kvm_vcpu *vcpu); +int vgic_v3_dist_access (struct kvm_vcpu *vcpu,bool is_write, +int offset,int len,void *val); +int vgic_v3_redist_access (struct kvm_vcpu *vcpu,bool is_write, +int offset,int len,void *val);#else static inline void vgic_v3_process_maintenance (struct kvm_vcpu *vcpu) {@@ -61,6 +65,18 @@ static inline void vgic_v3_clear_lr(struct kvm_vcpu *vcpu, int lr)static inline void vgic_v3_set_underflow (struct kvm_vcpu *vcpu) { } + +static inline int vgic_v3_dist_access (struct kvm_vcpu *vcpu,bool is_write, +int offset,int len,void *val) +{ +return -ENXIO ; +} + +static inline int vgic_v3_redist_access (struct kvm_vcpu *vcpu,bool is_write, +int offset,int len,void *val) +{ +return -ENXIO ; +}#endif #endif virt/kvm/arm/vgic/vgic_mmio.c +0
-0
virt/kvm/arm/vgic/vgic_mmio.c line 20
Quoted 4 lines
virt/kvm/arm/vgic/vgic_mmio.c +1
-0@@ -17,6 +17,8 @@#include <kvm/vgic/vgic.h> #include <linux/bitops.h> #include <linux/irqchip/arm-gic.h> +#include <linux/irqchip/arm-gic-v3.h>
This is going to cause no end of trouble in the long run. There two include files were never designed to co-exist, and it is only a matter of chance if they do not clash.
I'm afraid we'll eventually need to split that file in vgic-mmio.c, vgic-mmio-v2.c and vgic-mmio-v3.c.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
PATCH 24/45 KVM: arm/arm64: vgic-new: Add GICv3 CTLR, IIDR, TYPER handlers
In reply to Andre PrzywaraAs in the GICv2 emulation we handle those three registers in one function.
Changelog RFC..v1:
- kick VCPUs if distributor gets enabled
--- virt/kvm/arm/vgic/vgic.h | 2 ++ virt/kvm/arm/vgic/vgic_mmio.c | 56 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-)
virt/kvm/arm/vgic/vgic.h +2 -0
@@ -19,6 +19,8 @@#define PRODUCT_ID_KVM 0x4b/* ASCII code K */ #define IMPLEMENTER_ARM 0x43b +#define INTERRUPT_ID_BITS_SPIS 10 +#define vgic_irq_is_sgi (intid) ((intid) < VGIC_NR_SGIS) struct vgic_irq *vgic_get_irq(struct kvm *kvm, struct kvm_vcpu *vcpu,
virt/kvm/arm/vgic/vgic_mmio.c +55 -1
68 lines not on this page · raw message
Signature · 1 line
2.7.3
Re: [PATCH 24/45] KVM: arm/arm64: vgic-new: Add GICv3 CTLR, IIDR, TYPER handlers
Quoted 38 lines · Andre Przywara
As in the GICv2 emulation we handle those three registers in one function.
Signed-off-by Andre Przywara <[email protected]>Changelog RFC..v1:
- kick VCPUs if distributor gets enabled--- virt/kvm/arm/vgic/vgic.h | 2 ++ virt/kvm/arm/vgic/vgic_mmio.c | 56 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-)virt/kvm/arm/vgic/vgic.h +2
-0@@ -19,6 +19,8 @@#define PRODUCT_ID_KVM 0x4b/* ASCII code K */ #define IMPLEMENTER_ARM 0x43b +#define INTERRUPT_ID_BITS_SPIS 10 +#define vgic_irq_is_sgi (intid) ((intid) < VGIC_NR_SGIS) struct vgic_irq *vgic_get_irq(struct kvm *kvm, struct kvm_vcpu *vcpu,virt/kvm/arm/vgic/vgic_mmio.c +5
-0@@ -686,6 +686,60 @@ static int vgic_mmio_write_sgipends(struct kvm_vcpu *vcpu,return 0 ; } +/*****************************/ +/* GICv3 emulation functions */ +/*****************************/ +#ifdef CONFIG_KVM_ARM_VGIC_V3 +
virt/kvm/arm/vgic/vgic_mmio.c static int vgic_mmio_write_sgipends(struct kvm_vcpu *vcpu, · line 703
Quoted 10 lines
virt/kvm/arm/vgic/vgic_mmio.c +10
-0+static int vgic_mmio_read_v3_misc (struct kvm_vcpu *vcpu, +struct kvm_io_device *dev, +gpa_t addr,int len,void *val) +{ +u32 value =0 ; + +switch (addr &0x0c ) { +case GICD_CTLR : +if (vcpu->kvm->arch.vgic.enabled) + value |=GICD_CTLR_ENABLE_SS_G1 ;
...what about the EnableGrp0 bit ? You're a single-security-State GIC (since you advertise DS==1), so you should have two enable bits here.
virt/kvm/arm/vgic/vgic_mmio.c static int vgic_mmio_write_sgipends(struct kvm_vcpu *vcpu, · line 709
Quoted 6 lines
virt/kvm/arm/vgic/vgic_mmio.c +6
-0+ value |=GICD_CTLR_ARE_NS |GICD_CTLR_DS ; +break ; +case GICD_TYPER : + value = vcpu->kvm->arch.vgic.nr_spis +VGIC_NR_PRIVATE_IRQS ; + value = (value >>5 ) -1 ; + value |= (INTERRUPT_ID_BITS_SPIS -1 ) <<19 ;
Are you deliberately claiming support for 1-of-N SPI interrupts (No1N == 0) ? Is A3V==0 (no support for non-zero Aff3) correct? Is it a restriction we might lift in future?
Quoted 15 lines
virt/kvm/arm/vgic/vgic_mmio.c +15
-0+break ; +case GICD_IIDR : + value = (PRODUCT_ID_KVM <<24 ) | (IMPLEMENTER_ARM <<0 ); +break ; +default : +return 0 ; + } + +write_mask32 (value, addr &3 , len, val); +return 0 ; +} + +static int vgic_mmio_write_v3_misc (struct kvm_vcpu *vcpu, +struct kvm_io_device *dev, +gpa_t addr,int len,const void *val)
virt/kvm/arm/vgic/vgic_mmio.c static int vgic_mmio_write_sgipends(struct kvm_vcpu *vcpu, · line 734
Quoted 10 lines
virt/kvm/arm/vgic/vgic_mmio.c +10
-0+{ +struct vgic_dist *dist = &vcpu->kvm->arch.vgic; +bool was_enabled = dist->enabled; + +/* Of the whole region only the first byte is actually writeable. */ +if ((addr &0x0f ) >0 ) +return 0 ; + +/* We only care about the enable bit, all other bits are WI. */ + dist->enabled = *(u8 *)val &GICD_CTLR_ENABLE_SS_G1 ;
Again, there are two enable bits here.
Also, this is a 32-bit register, so how does the *(u8*) work?
Quoted 12 lines
virt/kvm/arm/vgic/vgic_mmio.c +8
-0+ +if (!was_enabled && dist->enabled) +vgic_kick_vcpus (vcpu->kvm); + +return 0 ; +} + +/* * The GICv3 per-IRQ registers are split to control PPIs and SGIs in the * redistributors, while SPIs are covered by registers in the distributor
virt/kvm/arm/vgic/vgic_mmio.c struct vgic_register_region vgic_v2_dist_registers[] = { · line 791
Quoted 5 lines
virt/kvm/arm/vgic/vgic_mmio.c +1
-1@@ -734,7 +788,7 @@ struct vgic_register_region vgic_v2_dist_registers[] = {#ifdef CONFIG_KVM_ARM_VGIC_V3 struct vgic_register_region vgic_v3_dist_registers[] = {REGISTER_DESC_WITH_LENGTH (GICD_CTLR , - vgic_mmio_read_nyi, vgic_mmio_write_nyi, 16), + vgic_mmio_read_v3_misc, vgic_mmio_write_v3_misc, 16),
...and here it says 16, which is neither 8 nor 32...
Quoted 5 lines
virt/kvm/arm/vgic/vgic_mmio.c +0
-1REGISTER_DESC_WITH_BITS_PER_IRQ_SHARED (GICD_IGROUPR , vgic_mmio_read_rao, vgic_mmio_write_wi,1 ), REGISTER_DESC_WITH_BITS_PER_IRQ_SHARED(GICD_ISENABLER, --2.7.3
thanks
-- PMM
PATCH 25/45 KVM: arm/arm64: vgic-new: Add GICv3 redistributor IIDR, TYPER handlers
In reply to Andre PrzywaraThe redistributor TYPER tells the OS about the associated MPIDR, also the LAST bit is crucial to determine the number of redistributors.
--- virt/kvm/arm/vgic/vgic_mmio.c | 50 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-)
virt/kvm/arm/vgic/vgic_mmio.c +48 -2
@@ -739,6 +739,52 @@ static int vgic_mmio_write_v3_misc(struct kvm_vcpu *vcpu, return 0; } +/* +* We use a compressed version of the MPIDR (all 32 bits in one 32-bit word) +* when we store the target MPIDR written by the guest. +*/ +static u32 compress_mpidr (unsigned long mpidr) +{ +u32 ret; + + ret =MPIDR_AFFINITY_LEVEL (mpidr,0 ); + ret |=MPIDR_AFFINITY_LEVEL (mpidr,1 ) <<8 ; + ret |=MPIDR_AFFINITY_LEVEL (mpidr,2 ) <<16 ; + ret |=MPIDR_AFFINITY_LEVEL (mpidr,3 ) <<24 ; + +return ret; +} + +static int vgic_mmio_read_v3r_typer (struct kvm_vcpu *vcpu, +struct kvm_io_device *dev, +gpa_t addr,int len,void *val) +{ +struct vgic_io_device *iodev =container_of (dev, + struct vgic_io_device, dev); +unsigned long mpidr =kvm_vcpu_get_mpidr_aff (iodev->redist_vcpu); +int target_vcpu_id = iodev->redist_vcpu->vcpu_id; +u64 value; + + value = (u64 )compress_mpidr (mpidr) <<32 ; + value |= ((target_vcpu_id &0xffff ) <<8 ); +if (target_vcpu_id ==atomic_read (&vcpu->kvm->online_vcpus) -1 ) + value |=GICR_TYPER_LAST ; + +write_mask64 (value, addr &7 , len, val); +return 0 ; +} + +static int vgic_mmio_read_v3r_iidr (struct kvm_vcpu *vcpu, +struct kvm_io_device *dev, +gpa_t addr,int len,void *val) +{ +write_mask32 ((PRODUCT_ID_KVM <<24 ) | (IMPLEMENTER_ARM <<0 ), + addr &3 , len, val); + +return 0 ; +} + +#endif /* * The GICv3 per-IRQ registers are split to control PPIs and SGIs in the
@@ -821,9 +867,9 @@ struct vgic_register_region vgic_v3_redist_registers[] = {REGISTER_DESC_WITH_LENGTH (GICR_CTLR , vgic_mmio_read_raz, vgic_mmio_write_wi,4 ),REGISTER_DESC_WITH_LENGTH (GICR_IIDR , - vgic_mmio_read_nyi, vgic_mmio_write_wi,4 ), + vgic_mmio_read_v3r_iidr, vgic_mmio_write_wi,4 ),REGISTER_DESC_WITH_LENGTH (GICR_TYPER , - vgic_mmio_read_nyi, vgic_mmio_write_wi,8 ), + vgic_mmio_read_v3r_typer, vgic_mmio_write_wi,8 ),REGISTER_DESC_WITH_LENGTH (GICR_PROPBASER , vgic_mmio_read_raz, vgic_mmio_write_wi,8 ), REGISTER_DESC_WITH_LENGTH(GICR_PENDBASER,
Signature · 1 line
2.7.3
PATCH 26/45 KVM: arm/arm64: vgic-new: Add GICv3 IDREGS register handler
In reply to Andre Przywara--- virt/kvm/arm/vgic/vgic_mmio.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)
virt/kvm/arm/vgic/vgic_mmio.c +19 -2
@@ -784,6 +784,23 @@ static int vgic_mmio_read_v3r_iidr(struct kvm_vcpu *vcpu, return 0; } +static int vgic_mmio_read_v3_idregs (struct kvm_vcpu *vcpu, +struct kvm_io_device *dev, +gpa_t addr,int len,void *val) +{ +u32 regnr = (addr &0x3f ) - (GICD_IDREGS &0x3f ); +u32 reg =0 ; + +switch (regnr +GICD_IDREGS ) { +case GICD_PIDR2 : +/* report a GICv3 compliant implementation */ + reg =0x3b ; +break ; + } + +write_mask32 (reg , addr &3 , len, val); +return 0 ; +}#endif /*
@@ -860,7 +877,7 @@ struct vgic_register_region vgic_v3_dist_registers[] = {REGISTER_DESC_WITH_BITS_PER_IRQ_SHARED (GICD_IROUTER , vgic_mmio_read_nyi, vgic_mmio_write_nyi,64 ),REGISTER_DESC_WITH_LENGTH (GICD_IDREGS , - vgic_mmio_read_nyi, vgic_mmio_write_wi, 48), + vgic_mmio_read_v3_idregs, vgic_mmio_write_wi, 48), }; struct vgic_register_region vgic_v3_redist_registers[] = {
@@ -875,7 +892,7 @@ struct vgic_register_region vgic_v3_redist_registers[] = {REGISTER_DESC_WITH_LENGTH (GICR_PENDBASER , vgic_mmio_read_raz, vgic_mmio_write_wi,8 ),REGISTER_DESC_WITH_LENGTH (GICR_IDREGS , - vgic_mmio_read_nyi, vgic_mmio_write_wi, 48), + vgic_mmio_read_v3_idregs, vgic_mmio_write_wi, 48), }; struct vgic_register_region vgic_v3_private_registers[] = {
Signature · 1 line
2.7.3
Re: [PATCH 26/45] KVM: arm/arm64: vgic-new: Add GICv3 IDREGS register handler
Quoted 16 lines · Andre Przywara
Signed-off-by Andre Przywara <[email protected]>--- virt/kvm/arm/vgic/vgic_mmio.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)virt/kvm/arm/vgic/vgic_mmio.c +3
-0@@ -784,6 +784,23 @@ static int vgic_mmio_read_v3r_iidr(struct kvm_vcpu *vcpu,return 0 ; } +static int vgic_mmio_read_v3_idregs (struct kvm_vcpu *vcpu, +struct kvm_io_device *dev, +gpa_t addr,int len,void *val)
virt/kvm/arm/vgic/vgic_mmio.c static int vgic_mmio_read_v3r_iidr(struct kvm_vcpu *vcpu, · line 799
Quoted 10 lines
virt/kvm/arm/vgic/vgic_mmio.c +10
-0+{ +u32 regnr = (addr &0x3f ) - (GICD_IDREGS &0x3f ); +u32 reg =0 ; + +switch (regnr +GICD_IDREGS ) { +case GICD_PIDR2 : +/* report a GICv3 compliant implementation */ + reg =0x3b ; +break ; + }
We claim to be an ARM implementation, so we should report the full set of ARM ID registers, not just GICD_PIDR2:
0x44, 0x00, 0x00, 0x00, 0x92, 0xB4, 0x3B, 0x00, 0x0D, 0xF0, 0x05, 0xB1
(starting at 0xFFD0 and going up to 0xFFFC.)
virt/kvm/arm/vgic/vgic_mmio.c static int vgic_mmio_read_v3r_iidr(struct kvm_vcpu *vcpu, · line 804
Quoted 4 lines
virt/kvm/arm/vgic/vgic_mmio.c +3
-0+write_mask32 (reg , addr &3 , len, val); + return 0; +}#endif
thanks
-- PMM
Re: [PATCH 26/45] KVM: arm/arm64: vgic-new: Add GICv3 IDREGS register handler
Hi Peter,
thanks for going through the pain of looking into this!
Quoted 14 lines · Peter Maydell
Quoted 13 lines · Andre Przywara
Signed-off-by Andre Przywara <[email protected]>--- virt/kvm/arm/vgic/vgic_mmio.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)virt/kvm/arm/vgic/vgic_mmio.c +0
-0@@ -784,6 +784,23 @@ static int vgic_mmio_read_v3r_iidr(struct kvm_vcpu *vcpu,return 0 ; }
Quoted 16 lines
virt/kvm/arm/vgic/vgic_mmio.c static int vgic_mmio_read_v3r_iidr(struct kvm_vcpu *vcpu, · line 799
Quoted 13 lines
virt/kvm/arm/vgic/vgic_mmio.c +13
-0+static int vgic_mmio_read_v3_idregs (struct kvm_vcpu *vcpu, +struct kvm_io_device *dev, +gpa_t addr,int len,void *val) +{ +u32 regnr = (addr &0x3f ) - (GICD_IDREGS &0x3f ); +u32 reg =0 ; + +switch (regnr +GICD_IDREGS ) { +case GICD_PIDR2 : +/* report a GICv3 compliant implementation */ + reg =0x3b ; +break ; + }We claim to be an ARM implementation, so we should report the full set of ARM ID registers, not just
GICD_PIDR2:
Do we really have to? Please note that though we say our implementor is ARM (because we lack alternatives, I think), we don't claim to be a GIC-500, for instance, but a made-up KVM implementation.
So there is no need to implement the other ID registers, except for the architecturally defined PIDR2, which Linux actually checks to confirm that this is a GICv3 compliant GIC.
Quoted 1 line
0x44, 0x00, 0x00, 0x00, 0x92, 0xB4, 0x3B, 0x00, 0x0D, 0xF0, 0x05, 0xB1
Yes, I had those registers defined like this in an earlier version, but Marc's comment IIRC correctly was that we shouldn't claim to be a GIC-500, for instance, because then we would need to mimic GIC-500 behavior quite closely, which we simply don't and also don't want to.
So architecturally we are fine, I think.
Do you think by claiming coming from ARM we are obliged to implement all the other PIDR/CIDR registers the ARM way?
Cheers,
Andre.
Quoted 11 lines
(starting at
0xFFD0and going up to0xFFFC.)virt/kvm/arm/vgic/vgic_mmio.c static int vgic_mmio_read_v3r_iidr(struct kvm_vcpu *vcpu, · line 804
Quoted 4 lines
virt/kvm/arm/vgic/vgic_mmio.c +3
-0+write_mask32 (reg , addr &3 , len, val); + return 0; +}#endif thanks
-- PMM
Re: [PATCH 26/45] KVM: arm/arm64: vgic-new: Add GICv3 IDREGS register handler
Quoted 3 lines · André Przywara
Hi Peter,
thanks for going through the pain of looking into this!
No problem -- I figured I might as well while I have my head full of the GICv3 spec for the QEMU emulated version.
Quoted 11 lines · Peter Maydell
Quoted 2 lines
We claim to be an ARM implementation, so we should report the full set of ARM ID registers, not just
GICD_PIDR2:Do we really have to? Please note that though we say our implementor is ARM (because we lack alternatives, I think), we don't claim to be a GIC-500, for instance, but a made-up KVM implementation.
So there is no need to implement the other ID registers, except for the architecturally defined PIDR2, which Linux actually checks to confirm that this is a GICv3 compliant GIC.
Quoted 6 lines
Quoted 1 line
0x44, 0x00, 0x00, 0x00, 0x92, 0xB4, 0x3B, 0x00, 0x0D, 0xF0, 0x05, 0xB1Yes, I had those registers defined like this in an earlier version, but Marc's comment IIRC correctly was that we shouldn't claim to be a GIC-500, for instance, because then we would need to mimic GIC-500 behavior quite closely, which we simply don't and also don't want to.
This isn't claiming to be a GIC-500 (which you would do via the GICD_IIDR and GICR_IIDR by specifying the right Product field). This is implementing the Coresight ID registers, which the spec says have the same values for all ARM implementations (and as you note, you are claiming in the IIDR registers to be an ARM implementation). The spec also says "ARM strongly recommends that other implementers also use this scheme", so even if we weren't saying we were an ARM implementation I think it would be a good idea.
Quoted 2 lines
Do you think by claiming coming from ARM we are obliged to implement all the other PIDR/CIDR registers the ARM way?
I think so, and it's not exactly difficult so why not?
Any guest that thinks these ID values mean "I'm a GIC-500" is broken :-)
thanks
-- PMM
PATCH 27/45 KVM: arm/arm64: vgic-new: Add GICv3 IROUTER register handlers
In reply to Andre PrzywaraThose set the affinity of a SPI interrupt.
Changelog RFC..v1:
- fold in and simplify vgic_v3_irq_change_affinity
--- virt/kvm/arm/vgic/vgic_mmio.c | 73 ++++++++++++++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 19 deletions(-)
virt/kvm/arm/vgic/vgic_mmio.c +54 -19
@@ -74,24 +74,6 @@ int vgic_mmio_write_wi(struct kvm_vcpu *vcpu, struct kvm_io_device *dev,return 0 ; } -static int vgic_mmio_read_nyi (struct kvm_vcpu *vcpu, -struct kvm_io_device *dev, -gpa_t addr,int len,void *val) -{ -pr_warn ("KVM: handling unimplemented VGIC MMIO read: VCPU %d, address: 0x%llx\n" , - vcpu->vcpu_id, (unsigned long long )addr); -return 0 ; -} - -static int vgic_mmio_write_nyi (struct kvm_vcpu *vcpu, -struct kvm_io_device *dev, -gpa_t addr,int len,const void *val) -{ -pr_warn ("KVM: handling unimplemented VGIC MMIO write: VCPU %d, address: 0x%llx\n" , - vcpu->vcpu_id, (unsigned long long )addr); -return 0 ; -} -static int vgic_mmio_read_v2_misc (struct kvm_vcpu *vcpu,struct kvm_io_device *dev,gpa_t addr,int len,void *val)
@@ -755,6 +737,59 @@ static u32 compress_mpidr(unsigned long mpidr)return ret; } +static unsigned long decompress_mpidr (u32 value) +{ +unsigned long mpidr; + + mpidr = ((value >>0 ) &0xFF ) <<MPIDR_LEVEL_SHIFT (0 ); + mpidr |= ((value >>8 ) &0xFF ) <<MPIDR_LEVEL_SHIFT (1 ); + mpidr |= ((value >>16 ) &0xFF ) <<MPIDR_LEVEL_SHIFT (2 ); + mpidr |= (u64)((value >>24 ) &0xFF ) <<MPIDR_LEVEL_SHIFT (3 ); + +return mpidr; +} + +static int vgic_mmio_read_irouter (struct kvm_vcpu *vcpu, +struct kvm_io_device *dev, +gpa_t addr,int len,void *val) +{ +int intid = (addr &0x1fff ) /8 ; +struct vgic_irq *irq =vgic_get_irq (vcpu->kvm,NULL , intid); + +if (!irq) { +memset (val,0 , len); +return 0 ; + } + +write_mask64 (decompress_mpidr (irq->mpidr), addr &7 , len, val); + +return 0 ; +} + +static int vgic_mmio_write_irouter (struct kvm_vcpu *vcpu, +struct kvm_io_device *dev, +gpa_t addr,int len,const void *val) +{ +int intid = (addr &0x1fff ) /8 ; +struct vgic_irq *irq =vgic_get_irq (vcpu->kvm,NULL , intid); +u64 mpidr; + +if (!irq) +return 0 ; + + mpidr =decompress_mpidr (irq->mpidr); + mpidr =mask64 (mpidr, addr &7 , len, val); + +spin_lock (&irq->irq_lock); + + irq->mpidr =compress_mpidr (mpidr); + irq->target_vcpu =kvm_mpidr_to_vcpu (vcpu->kvm, mpidr); + +spin_unlock (&irq->irq_lock); + +return 0 ; +} +static int vgic_mmio_read_v3r_typer (struct kvm_vcpu *vcpu,struct kvm_io_device *dev,gpa_t addr,int len,void *val)
@@ -875,7 +910,7 @@ struct vgic_register_region vgic_v3_dist_registers[] = {REGISTER_DESC_WITH_BITS_PER_IRQ_SHARED (GICD_IGRPMODR , vgic_mmio_read_raz, vgic_mmio_write_wi,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ_SHARED (GICD_IROUTER , - vgic_mmio_read_nyi, vgic_mmio_write_nyi,64 ), + vgic_mmio_read_irouter, vgic_mmio_write_irouter,64 ),REGISTER_DESC_WITH_LENGTH (GICD_IDREGS , vgic_mmio_read_v3_idregs, vgic_mmio_write_wi, 48), };
Signature · 1 line
2.7.3
PATCH 28/45 KVM: arm/arm64: vgic-new: Add GICv3 SGI system register trap handler
In reply to Andre PrzywaraIn contrast to GICv2 SGIs in a GICv3 implementation are not triggered by a MMIO write, but with a system register write. KVM knows about that register already, we just need to implement the handler and wire it up to the core KVM/ARM code.
Changelog RFC..v1:
- add comment about SGI_AFFINITY_LEVEL macro
--- include/kvm/vgic/vgic.h | 8 ++++ virt/kvm/arm/vgic/vgic_mmio.c | 106 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+)
include/kvm/vgic/vgic.h +8 -0
@@ -205,6 +205,14 @@ bool kvm_vcpu_has_pending_irqs(struct kvm_vcpu *vcpu);void kvm_vgic_sync_hwstate (struct kvm_vcpu *vcpu);void kvm_vgic_flush_hwstate (struct kvm_vcpu *vcpu); +#ifdef CONFIG_KVM_ARM_VGIC_V3 +void vgic_v3_dispatch_sgi (struct kvm_vcpu *vcpu,u64 reg); +#else +static inline void vgic_v3_dispatch_sgi (struct kvm_vcpu *vcpu,u64 reg) +{ +} +#endif +/** * kvm_vgic_get_max_vcpus - Get the maximum number of VCPUs allowed by HW *
virt/kvm/arm/vgic/vgic_mmio.c +106 -0
110 lines not on this page · raw message
Signature · 1 line
2.7.3
Re: [PATCH 28/45] KVM: arm/arm64: vgic-new: Add GICv3 SGI system register trap handler
Quoted 10 lines · Andre Przywara
In contrast to GICv2 SGIs in a GICv3 implementation are not triggered by a MMIO write, but with a system register write. KVM knows about that register already, we just need to implement the handler and wire it up to the core KVM/ARM code.
Signed-off-by Andre Przywara <[email protected]>Changelog RFC..v1:
- add comment aboutSGI_AFFINITY_LEVELmacro
Quoted 13 lines
+/**
+ *vgic_v3_dispatch_sgi- handle SGI requests from VCPUs
+ * @vcpu: The VCPU requesting a SGI
+ * @reg: The value written into theICC_SGI1R_EL1register by that VCPU
+ *
+ * With GICv3 (and ARE=1) CPUs trigger SGIs by writing to a system register.
+ * This will trap insys_regs.cand call this function.
+ * ThisICC_SGI1R_EL1register 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 all VCPUs to
+ * check for matching ones. If this bit is set, we signal all, but not the
+ * calling VCPU.
+ */
No ICC_SGI0R_EL1, ICC_ASGI1R_EL1 ?
Quoted 34 lines
virt/kvm/arm/vgic/vgic_mmio.c +34
-0+void vgic_v3_dispatch_sgi (struct kvm_vcpu *vcpu,u64 reg) +{ +struct kvm *kvm = vcpu->kvm; +struct kvm_vcpu *c_vcpu; +u16 target_cpus; +u64 mpidr; +int sgi, c; +int vcpu_id = vcpu->vcpu_id; +bool broadcast; + + sgi = (reg &ICC_SGI1R_SGI_ID_MASK ) >>ICC_SGI1R_SGI_ID_SHIFT ; + broadcast = reg &BIT (ICC_SGI1R_IRQ_ROUTING_MODE_BIT ); + target_cpus = (reg &ICC_SGI1R_TARGET_LIST_MASK ) >>ICC_SGI1R_TARGET_LIST_SHIFT ; + mpidr =SGI_AFFINITY_LEVEL (reg,3 ); + mpidr |=SGI_AFFINITY_LEVEL (reg,2 ); + mpidr |=SGI_AFFINITY_LEVEL (reg,1 ); + +/* +* We iterate over all VCPUs to find the MPIDRs matching the request. +* If we have handled one CPU, we clear its bit to detect early +* if we are already finished. This avoids iterating through all +* VCPUs when most of the times we just signal a single VCPU. +*/ +kvm_for_each_vcpu (c, c_vcpu, kvm) { +struct vgic_irq *irq; + +/* Exit early if we have dealt with all requested CPUs */ +if (!broadcast && target_cpus ==0 ) +break ; + +/* Don't signal the calling VCPU */ +if (broadcast && c == vcpu_id) +continue ; +
virt/kvm/arm/vgic/vgic_mmio.c int vgic_register_redist_iodevs(struct kvm *kvm, gpa_t redist_base_address) · line 1367
Quoted 10 lines
virt/kvm/arm/vgic/vgic_mmio.c +10
-0+if (!broadcast) { +int level0; + + level0 =match_mpidr (mpidr, target_cpus, c_vcpu); +if (level0 ==-1 ) +continue ; + +/* remove this matching VCPU from the mask */ + target_cpus &= ~BIT (level0); + }
I think you need a check in here that the SGI is actually configured to be the group that's been requested.
Quoted 11 lines
virt/kvm/arm/vgic/vgic_mmio.c +9
-1+ + irq =vgic_get_irq (vcpu->kvm, c_vcpu, sgi); + +spin_lock (&irq->irq_lock); + irq->pending = true; + + vgic_queue_irq_unlock(vcpu->kvm, irq); + } +}#endif --
Quoted 1 line
2.7.3
thanks
-- PMM
PATCH 29/45 KVM: arm/arm64: vgic-new: vgic_kvm_device: KVM device ops registration
In reply to Andre PrzywaraFrom: Eric Auger <[email protected]>
This patch introduces the skeleton for the KVM device operations associated to KVM_DEV_TYPE_ARM_VGIC_V2 and KVM_DEV_TYPE_ARM_VGIC_V3.
At that stage kvm_vgic_create is stubbed.
--- virt/kvm/arm/vgic/vgic.h | 2 + virt/kvm/arm/vgic/vgic_kvm_device.c | 108 ++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 virt/kvm/arm/vgic/vgic_kvm_device.c
virt/kvm/arm/vgic/vgic.h +2 -0
@@ -81,4 +81,6 @@ static inline int vgic_v3_redist_access(struct kvm_vcpu *vcpu, bool is_write, }#endif +void kvm_register_vgic_device (unsigned long type); +#endif
virt/kvm/arm/vgic/vgic_kvm_device.c new file +108 -0
108 lines not on this page · raw message
Signature · 1 line
2.7.3
PATCH 30/45 KVM: arm/arm64: vgic-new: vgic_kvm_device: KVM_DEV_ARM_VGIC_GRP_NR_IRQS
In reply to Andre PrzywaraFrom: Eric Auger <[email protected]>
This patch implements the KVM_DEV_ARM_VGIC_GRP_NR_IRQS group. This modality is supported by both VGIC V2 and V3 KVM device as will be other groups, hence the introduction of common helpers.
--- virt/kvm/arm/vgic/vgic_kvm_device.c | 83 +++++++++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 4 deletions(-)
virt/kvm/arm/vgic/vgic_kvm_device.c +79 -4
@@ -15,9 +15,69 @@*/ #include <linux/kvm_host.h> #include <kvm/vgic/vgic.h> +#include <linux/uaccess.h> +#include "vgic.h" /* common helpers */ +static int vgic_set_common_attr (struct kvm_device *dev, +struct kvm_device_attr *attr) +{ +switch (attr->group) { +case KVM_DEV_ARM_VGIC_GRP_NR_IRQS : { +u32 __user *uaddr = (u32 __user *)(long )attr->addr; +u32 val; +int ret =0 ; + +if (get_user (val, uaddr)) +return -EFAULT ; + +/* +* We require: +* - at least 32 SPIs on top of the 16 SGIs and 16 PPIs +* - at most 1024 interrupts +* - a multiple of 32 interrupts +*/ +if (val < (VGIC_NR_PRIVATE_IRQS +32 ) || + val >VGIC_MAX_RESERVED || + (val &31 )) +return -EINVAL ; + +mutex_lock (&dev->kvm->lock); + +if (vgic_ready (dev->kvm) || dev->kvm->arch.vgic.nr_spis) + ret = -EBUSY ; +else + dev->kvm->arch.vgic.nr_spis = + val -VGIC_NR_PRIVATE_IRQS ; + +mutex_unlock (&dev->kvm->lock); + +return ret; + } + } + +return -ENXIO ; +} + +static int vgic_get_common_attr (struct kvm_device *dev, +struct kvm_device_attr *attr) +{ +int r = -ENXIO ; + +switch (attr->group) { +case KVM_DEV_ARM_VGIC_GRP_NR_IRQS : { +u32 __user *uaddr = (u32 __user *)(long )attr->addr; + + r =put_user (dev->kvm->arch.vgic.nr_spis + +VGIC_NR_PRIVATE_IRQS , uaddr); +break ; + } + } + +return r; +} +static int vgic_create (struct kvm_device *dev,u32 type) {return kvm_vgic_create (dev->kvm, type);
@@ -49,18 +109,29 @@ void kvm_register_vgic_device(unsigned long type)static int vgic_v2_set_attr (struct kvm_device *dev,struct kvm_device_attr *attr) { -return -ENXIO ; +int ret; + + ret =vgic_set_common_attr (dev, attr); +return ret; + }static int vgic_v2_get_attr (struct kvm_device *dev,struct kvm_device_attr *attr) { -return -ENXIO ; +int ret; + + ret =vgic_get_common_attr (dev, attr); +return ret; }static int vgic_v2_has_attr (struct kvm_device *dev,struct kvm_device_attr *attr) { +switch (attr->group) { +case KVM_DEV_ARM_VGIC_GRP_NR_IRQS : +return 0 ; + }return -ENXIO ; }
@@ -80,18 +151,22 @@ struct kvm_device_ops kvm_arm_vgic_v2_ops = {static int vgic_v3_set_attr (struct kvm_device *dev,struct kvm_device_attr *attr) { -return -ENXIO ; +return vgic_set_common_attr (dev, attr); }static int vgic_v3_get_attr (struct kvm_device *dev,struct kvm_device_attr *attr) { -return -ENXIO ; +return vgic_get_common_attr (dev, attr); }static int vgic_v3_has_attr (struct kvm_device *dev,struct kvm_device_attr *attr) { +switch (attr->group) { +case KVM_DEV_ARM_VGIC_GRP_NR_IRQS : +return 0 ; + }return -ENXIO ; }
Signature · 1 line
2.7.3
PATCH 31/45 KVM: arm/arm64: vgic-new: vgic_kvm_device: KVM_DEV_ARM_VGIC_GRP_CTRL
In reply to Andre PrzywaraFrom: Eric Auger <[email protected]>
This patch implements the KVM_DEV_ARM_VGIC_GRP_CTRL group API featuring KVM_DEV_ARM_VGIC_CTRL_INIT attribute. The vgic_init function is not yet implemented though.
--- virt/kvm/arm/vgic/vgic_kvm_device.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
virt/kvm/arm/vgic/vgic_kvm_device.c +22 -0
@@ -23,6 +23,8 @@static int vgic_set_common_attr (struct kvm_device *dev,struct kvm_device_attr *attr) { +int r; +switch (attr->group) {case KVM_DEV_ARM_VGIC_GRP_NR_IRQS : {u32 __user *uaddr = (u32 __user *)(long )attr->addr;
@@ -55,6 +57,16 @@ static int vgic_set_common_attr(struct kvm_device *dev,return ret; } +case KVM_DEV_ARM_VGIC_GRP_CTRL : { +switch (attr->attr) { +case KVM_DEV_ARM_VGIC_CTRL_INIT : +mutex_lock (&dev->kvm->lock); + r =vgic_init (dev->kvm); +mutex_unlock (&dev->kvm->lock); +return r; + } +break ; + } }return -ENXIO ;
@@ -131,6 +143,11 @@ static int vgic_v2_has_attr(struct kvm_device *dev,switch (attr->group) {case KVM_DEV_ARM_VGIC_GRP_NR_IRQS :return 0 ; +case KVM_DEV_ARM_VGIC_GRP_CTRL : +switch (attr->attr) { +case KVM_DEV_ARM_VGIC_CTRL_INIT : +return 0 ; + } }return -ENXIO ; }
@@ -166,6 +183,11 @@ static int vgic_v3_has_attr(struct kvm_device *dev,switch (attr->group) {case KVM_DEV_ARM_VGIC_GRP_NR_IRQS :return 0 ; +case KVM_DEV_ARM_VGIC_GRP_CTRL : +switch (attr->attr) { +case KVM_DEV_ARM_VGIC_CTRL_INIT : +return 0 ; + } }return -ENXIO ; }
Signature · 1 line
2.7.3
PATCH 32/45 KVM: arm/arm64: vgic-new: vgic_kvm_device: KVM_DEV_ARM_VGIC_GRP_ADDR
In reply to Andre PrzywaraFrom: Eric Auger <[email protected]>
This patch implements the KVM_DEV_ARM_VGIC_GRP_ADDR group which enables to set the base address of GIC regions as seen by the guest.
The kvm_vgic_addr function whci eventually assigns the chosen address to the internal structure still is stubbed.
--- virt/kvm/arm/vgic/vgic_kvm_device.c | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
virt/kvm/arm/vgic/vgic_kvm_device.c +38 -0
@@ -26,6 +26,17 @@ static int vgic_set_common_attr(struct kvm_device *dev,int r;switch (attr->group) { +case KVM_DEV_ARM_VGIC_GRP_ADDR : { +u64 __user *uaddr = (u64 __user *)(long )attr->addr; +u64 addr; +unsigned long type = (unsigned long )attr->attr; + +if (copy_from_user (&addr, uaddr,sizeof (addr))) +return -EFAULT ; + + r =kvm_vgic_addr (dev->kvm, type, &addr, true); +return (r == -ENODEV ) ? -ENXIO : r; + }case KVM_DEV_ARM_VGIC_GRP_NR_IRQS : {u32 __user *uaddr = (u32 __user *)(long )attr->addr;u32 val;
@@ -78,6 +89,19 @@ static int vgic_get_common_attr(struct kvm_device *dev,int r = -ENXIO ;switch (attr->group) { +case KVM_DEV_ARM_VGIC_GRP_ADDR : { +u64 __user *uaddr = (u64 __user *)(long )attr->addr; +u64 addr; +unsigned long type = (unsigned long )attr->attr; + + r =kvm_vgic_addr (dev->kvm, type, &addr, false); +if (r) +return (r == -ENODEV ) ? -ENXIO : r; + +if (copy_to_user (uaddr, &addr,sizeof (addr))) +return -EFAULT ; +break ; + }case KVM_DEV_ARM_VGIC_GRP_NR_IRQS : {u32 __user *uaddr = (u32 __user *)(long )attr->addr;
@@ -141,6 +165,13 @@ static int vgic_v2_has_attr(struct kvm_device *dev, struct kvm_device_attr *attr) {switch (attr->group) { +case KVM_DEV_ARM_VGIC_GRP_ADDR : +switch (attr->attr) { +case KVM_VGIC_V2_ADDR_TYPE_DIST : +case KVM_VGIC_V2_ADDR_TYPE_CPU : +return 0 ; + } +break ;case KVM_DEV_ARM_VGIC_GRP_NR_IRQS :return 0 ;case KVM_DEV_ARM_VGIC_GRP_CTRL :
@@ -181,6 +212,13 @@ static int vgic_v3_has_attr(struct kvm_device *dev, struct kvm_device_attr *attr) {switch (attr->group) { +case KVM_DEV_ARM_VGIC_GRP_ADDR : +switch (attr->attr) { +case KVM_VGIC_V3_ADDR_TYPE_DIST : +case KVM_VGIC_V3_ADDR_TYPE_REDIST : +return 0 ; + } +break ;case KVM_DEV_ARM_VGIC_GRP_NR_IRQS :return 0 ;case KVM_DEV_ARM_VGIC_GRP_CTRL :
Signature · 1 line
2.7.3
PATCH 33/45 KVM: arm/arm64: vgic-new: vgic_kvm_device: access to VGIC registers
In reply to Andre PrzywaraFrom: Eric Auger <[email protected]>
This patch implements the switches for KVM_DEV_ARM_VGIC_GRP_DIST_REGS and KVM_DEV_ARM_VGIC_GRP_CPU_REGS API which allows the userspace to access VGIC registers.
At that stage the interfaces with the MMIO API are not implemented:
- vgic_attr_regs_access
- vgic_v2_has_attr_regs
--- virt/kvm/arm/vgic/vgic.h | 1 + virt/kvm/arm/vgic/vgic_kvm_device.c | 53 +++++++++++++++++++++++++++++++++++-- virt/kvm/arm/vgic/vgic_mmio.c | 34 ++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 2 deletions(-)
virt/kvm/arm/vgic/vgic.h +1 -0
@@ -35,6 +35,7 @@ void vgic_v2_clear_lr(struct kvm_vcpu *vcpu, int lr);void vgic_v2_set_underflow (struct kvm_vcpu *vcpu);int vgic_v2_dist_access (struct kvm_vcpu *vcpu,bool is_write,int offset,int len,void *val); +int vgic_v2_has_attr_regs (struct kvm_device *dev,struct kvm_device_attr *attr);#ifdef CONFIG_KVM_ARM_VGIC_V3 void vgic_v3_process_maintenance (struct kvm_vcpu *vcpu);
virt/kvm/arm/vgic/vgic_kvm_device.c +51 -2
78 lines not on this page · raw message
virt/kvm/arm/vgic/vgic_mmio.c +34 -0
@@ -1375,3 +1375,37 @@ void vgic_v3_dispatch_sgi(struct kvm_vcpu *vcpu, u64 reg) } }#endif + +int vgic_v2_has_attr_regs (struct kvm_device *dev,struct kvm_device_attr *attr) +{ +int nr_irqs = dev->kvm->arch.vgic.nr_spis +VGIC_NR_PRIVATE_IRQS ; +struct vgic_register_region *regions; +gpa_t addr; +int nr_regions, i, len; + + addr = attr->attr &KVM_DEV_ARM_VGIC_OFFSET_MASK ; + +switch (attr->group) { +case KVM_DEV_ARM_VGIC_GRP_DIST_REGS : + regions = vgic_v2_dist_registers; + nr_regions =ARRAY_SIZE (vgic_v2_dist_registers); +break ; +case KVM_DEV_ARM_VGIC_GRP_CPU_REGS : +return -ENXIO ;/* TODO: describe CPU i/f regs also */ +default : +return -ENXIO ; + } + +for (i =0 ; i < nr_regions; i++) { +if (regions[i].bits_per_irq) + len = (regions[i].bits_per_irq * nr_irqs) /8 ; +else + len = regions[i].len; + +if (regions[i].reg_offset <= addr && + regions[i].reg_offset + len > addr) +return 0 ; + } + +return -ENXIO ; +}
Signature · 1 line
2.7.3
PATCH 34/45 KVM: arm/arm64: vgic-new: vgic_kvm_device: implement kvm_vgic_addr
In reply to Andre PrzywaraFrom: Eric Auger <[email protected]>
kvm_vgic_addr is used by the userspace to set the base address of the following register regions, as seen by the guest:
- distributor(v2 and v3),
- re-distributors (v3),
- CPU interface (v2).
--- include/kvm/vgic/vgic.h | 2 + virt/kvm/arm/vgic/vgic.h | 3 + virt/kvm/arm/vgic/vgic_kvm_device.c | 112 ++++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+)
include/kvm/vgic/vgic.h +2 -0
@@ -190,6 +190,8 @@ struct vgic_cpu {u64 live_lrs; }; +int kvm_vgic_addr (struct kvm *kvm,unsigned long type,u64 *addr,bool write); +int kvm_vgic_inject_irq (struct kvm *kvm,int cpuid,unsigned int intid,bool level);
virt/kvm/arm/vgic/vgic.h +3 -0
@@ -19,6 +19,9 @@#define PRODUCT_ID_KVM 0x4b/* ASCII code K */ #define IMPLEMENTER_ARM 0x43b +#define VGIC_ADDR_UNDEF (-1) +#define IS_VGIC_ADDR_UNDEF (_x) ((_x) == VGIC_ADDR_UNDEF) +#define INTERRUPT_ID_BITS_SPIS 10#define vgic_irq_is_sgi (intid) ((intid) < VGIC_NR_SGIS)
virt/kvm/arm/vgic/vgic_kvm_device.c +112 -0
122 lines not on this page · raw message
Signature · 1 line
2.7.3
PATCH 35/45 KVM: arm/arm64: vgic-new: Add userland access to VGIC dist registers
In reply to Andre Przywara--- virt/kvm/arm/vgic/vgic_kvm_device.c | 50 ++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-)
virt/kvm/arm/vgic/vgic_kvm_device.c +49 -1
@@ -264,7 +264,55 @@ static int vgic_attr_regs_access(struct kvm_device *dev,struct kvm_device_attr *attr, u32 *reg, bool is_write) { - return -ENXIO; + gpa_t addr; +int cpuid, ret, c; +struct kvm_vcpu *vcpu, *tmp_vcpu; + + cpuid = (attr->attr &KVM_DEV_ARM_VGIC_CPUID_MASK ) >> +KVM_DEV_ARM_VGIC_CPUID_SHIFT ; + vcpu =kvm_get_vcpu (dev->kvm, cpuid); + addr = attr->attr &KVM_DEV_ARM_VGIC_OFFSET_MASK ; + +mutex_lock (&dev->kvm->lock); + + ret =vgic_init (dev->kvm); +if (ret) + goto out; + +if (cpuid >=atomic_read (&dev->kvm->online_vcpus)) { + ret = -EINVAL ; + goto out; + } + +/* +* Ensure that no other VCPU is running by checking the vcpu->cpu +* field. If no other VPCUs are running we can safely access the VGIC +* state, because even if another VPU is run after this point, that +* VCPU will not touch the vgic state, because it will block on +* getting the vgic->lock in kvm_vgic_sync_hwstate(). +*/ +kvm_for_each_vcpu (c, tmp_vcpu, dev->kvm) { +if (unlikely (tmp_vcpu->cpu !=-1 )) { + ret = -EBUSY ; + goto out; + } + } + +switch (attr->group) { +case KVM_DEV_ARM_VGIC_GRP_CPU_REGS : + ret = -EINVAL ; +break ; +case KVM_DEV_ARM_VGIC_GRP_DIST_REGS : + ret =vgic_v2_dist_access (vcpu, is_write, addr,4 , reg); +break ; +default : + ret = -EINVAL ; +break ; + } + +out: +mutex_unlock (&dev->kvm->lock); +return ret; }/* V2 ops */
Signature · 1 line
2.7.3
PATCH 36/45 KVM: arm/arm64: vgic-new: Add GICH_VMCR accessors
In reply to Andre Przywara--- include/kvm/vgic/vgic.h | 7 +++++++ virt/kvm/arm/vgic/vgic-v2.c | 29 +++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-v3.c | 22 ++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.c | 16 ++++++++++++++++ virt/kvm/arm/vgic/vgic.h | 18 ++++++++++++++++++ 5 files changed, 92 insertions(+)
include/kvm/vgic/vgic.h +7 -0
@@ -167,6 +167,13 @@ struct vgic_v3_cpu_if {#endif }; +struct vgic_vmcr { +u32 ctlr; +u32 abpr; +u32 bpr; +u32 pmr; +}; +struct vgic_cpu {/* CPU vif control registers for world switch */ union {
virt/kvm/arm/vgic/vgic-v2.c +29 -0
@@ -173,3 +173,32 @@ void vgic_v2_clear_lr(struct kvm_vcpu *vcpu, int lr) { vcpu->arch.vgic_cpu.vgic_v2.vgic_lr[lr] =0 ; } + +void vgic_v2_set_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcrp) +{ +u32 vmcr; + + vmcr = (vmcrp->ctlr <<GICH_VMCR_CTRL_SHIFT ) &GICH_VMCR_CTRL_MASK ; + vmcr |= (vmcrp->abpr <<GICH_VMCR_ALIAS_BINPOINT_SHIFT ) & +GICH_VMCR_ALIAS_BINPOINT_MASK ; + vmcr |= (vmcrp->bpr <<GICH_VMCR_BINPOINT_SHIFT ) & +GICH_VMCR_BINPOINT_MASK ; + vmcr |= (vmcrp->pmr <<GICH_VMCR_PRIMASK_SHIFT ) & +GICH_VMCR_PRIMASK_MASK ; + + vcpu->arch.vgic_cpu.vgic_v2.vgic_vmcr = vmcr; +} + +void vgic_v2_get_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcrp) +{ +u32 vmcr = vcpu->arch.vgic_cpu.vgic_v2.vgic_vmcr; + + vmcrp->ctlr = (vmcr &GICH_VMCR_CTRL_MASK ) >> +GICH_VMCR_CTRL_SHIFT ; + vmcrp->abpr = (vmcr &GICH_VMCR_ALIAS_BINPOINT_MASK ) >> +GICH_VMCR_ALIAS_BINPOINT_SHIFT ; + vmcrp->bpr = (vmcr &GICH_VMCR_BINPOINT_MASK ) >> +GICH_VMCR_BINPOINT_SHIFT ; + vmcrp->pmr = (vmcr &GICH_VMCR_PRIMASK_MASK ) >> +GICH_VMCR_PRIMASK_SHIFT ; +}
virt/kvm/arm/vgic/vgic-v3.c +22 -0
@@ -165,3 +165,25 @@ void vgic_v3_clear_lr(struct kvm_vcpu *vcpu, int lr) { vcpu->arch.vgic_cpu.vgic_v3.vgic_lr[lr] =0 ; } + +void vgic_v3_set_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcrp) +{ +u32 vmcr; + + vmcr = (vmcrp->ctlr <<ICH_VMCR_CTLR_SHIFT ) &ICH_VMCR_CTLR_MASK ; + vmcr |= (vmcrp->abpr <<ICH_VMCR_BPR1_SHIFT ) &ICH_VMCR_BPR1_MASK ; + vmcr |= (vmcrp->bpr <<ICH_VMCR_BPR0_SHIFT ) &ICH_VMCR_BPR0_MASK ; + vmcr |= (vmcrp->pmr <<ICH_VMCR_PMR_SHIFT ) &ICH_VMCR_PMR_MASK ; + + vcpu->arch.vgic_cpu.vgic_v3.vgic_vmcr = vmcr; +} + +void vgic_v3_get_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcrp) +{ +u32 vmcr = vcpu->arch.vgic_cpu.vgic_v3.vgic_vmcr; + + vmcrp->ctlr = (vmcr &ICH_VMCR_CTLR_MASK ) >>ICH_VMCR_CTLR_SHIFT ; + vmcrp->abpr = (vmcr &ICH_VMCR_BPR1_MASK ) >>ICH_VMCR_BPR1_SHIFT ; + vmcrp->bpr = (vmcr &ICH_VMCR_BPR0_MASK ) >>ICH_VMCR_BPR0_SHIFT ; + vmcrp->pmr = (vmcr &ICH_VMCR_PMR_MASK ) >>ICH_VMCR_PMR_SHIFT ; +}
virt/kvm/arm/vgic/vgic.c +16 -0
@@ -428,6 +428,22 @@ static inline void vgic_set_underflow(struct kvm_vcpu *vcpu)vgic_v3_set_underflow (vcpu); } +void vgic_set_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr) +{ +if (kvm_vgic_global_state.type ==VGIC_V2 ) +vgic_v2_set_vmcr (vcpu, vmcr); +else +vgic_v3_set_vmcr (vcpu, vmcr); +} + +void vgic_get_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr) +{ +if (kvm_vgic_global_state.type ==VGIC_V2 ) +vgic_v2_get_vmcr (vcpu, vmcr); +else +vgic_v3_get_vmcr (vcpu, vmcr); +} +static int compute_ap_list_depth (struct kvm_vcpu *vcpu) {struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;
virt/kvm/arm/vgic/vgic.h +18 -0
@@ -39,6 +39,8 @@ void vgic_v2_set_underflow(struct kvm_vcpu *vcpu);int vgic_v2_dist_access (struct kvm_vcpu *vcpu,bool is_write,int offset,int len,void *val);int vgic_v2_has_attr_regs (struct kvm_device *dev,struct kvm_device_attr *attr); +void vgic_v2_set_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr); +void vgic_v2_get_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr);#ifdef CONFIG_KVM_ARM_VGIC_V3 void vgic_v3_process_maintenance (struct kvm_vcpu *vcpu);
@@ -50,6 +52,8 @@ int vgic_v3_dist_access(struct kvm_vcpu *vcpu, bool is_write, int offset, int len, void *val);int vgic_v3_redist_access (struct kvm_vcpu *vcpu,bool is_write,int offset,int len,void *val); +void vgic_v3_set_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr); +void vgic_v3_get_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr);#else static inline void vgic_v3_process_maintenance (struct kvm_vcpu *vcpu) {
@@ -83,8 +87,22 @@ static inline int vgic_v3_redist_access(struct kvm_vcpu *vcpu, bool is_write, {return -ENXIO ; } + +static inline +void vgic_v3_set_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr) +{ +} + +static inline +void vgic_v3_get_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr) +{ +} +#endif +void vgic_set_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr); +void vgic_get_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr); +void kvm_register_vgic_device (unsigned long type);#endif
Signature · 1 line
2.7.3
PATCH 37/45 KVM: arm/arm64: vgic-new: Add userland GIC CPU interface access
In reply to Andre Przywara--- virt/kvm/arm/vgic/vgic_kvm_device.c | 72 ++++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-)
virt/kvm/arm/vgic/vgic_kvm_device.c +71 -1
@@ -17,8 +17,11 @@#include <kvm/vgic/vgic.h> #include <linux/uaccess.h> #include <asm/kvm_mmu.h> +#include <linux/irqchip/arm-gic.h> #include "vgic.h" +#define GICC_ARCH_VERSION_V2 0x2 +/* common helpers */ static int vgic_ioaddr_overlap (struct kvm *kvm)
@@ -252,6 +255,69 @@ void kvm_register_vgic_device(unsigned long type) } } +static u32 vgic_read_vcpuif (struct kvm_vcpu *vcpu,int offset) +{ +struct vgic_vmcr vmcr; +u32 *field; + +switch (offset) { +case GIC_CPU_CTRL : + field = &vmcr.ctlr; +break ; +case GIC_CPU_PRIMASK : + field = &vmcr.pmr; +break ; +case GIC_CPU_BINPOINT : + field = &vmcr.bpr; +break ; +case GIC_CPU_ALIAS_BINPOINT : + field = &vmcr.abpr; +break ; +case GIC_CPU_IDENT : +return (PRODUCT_ID_KVM <<20 ) | + (GICC_ARCH_VERSION_V2 <<16 ) | + (IMPLEMENTER_ARM <<0 ); +default : +return 0 ; + } + +vgic_get_vmcr (vcpu, &vmcr); + +return *field; +} + +static bool vgic_write_vcpuif (struct kvm_vcpu *vcpu,int offset,u32 value) +{ +struct vgic_vmcr vmcr; +u32 *field; + +switch (offset) { +case GIC_CPU_CTRL : + field = &vmcr.ctlr; +break ; +case GIC_CPU_PRIMASK : + field = &vmcr.pmr; +break ; +case GIC_CPU_BINPOINT : + field = &vmcr.bpr; +break ; +case GIC_CPU_ALIAS_BINPOINT : + field = &vmcr.abpr; +break ; +default : +return false; + } + +vgic_get_vmcr (vcpu, &vmcr); +if (*field == value) +return false; + + *field = value; +vgic_set_vmcr (vcpu, &vmcr); + +return true; +} +/** vgic_attr_regs_access: allows user space to read/write VGIC registers * * @dev: kvm device handle
@@ -300,7 +366,11 @@ static int vgic_attr_regs_access(struct kvm_device *dev,switch (attr->group) {case KVM_DEV_ARM_VGIC_GRP_CPU_REGS : - ret = -EINVAL ; + ret =0 ; +if (is_write) +vgic_write_vcpuif (vcpu, addr, *reg); +else + *reg =vgic_read_vcpuif (vcpu, addr);break ;case KVM_DEV_ARM_VGIC_GRP_DIST_REGS : ret =vgic_v2_dist_access (vcpu, is_write, addr,4 , reg);
Signature · 1 line
2.7.3
PATCH 38/45 KVM: arm/arm64: vgic-new: vgic_init: implement kvm_vgic_hyp_init
In reply to Andre PrzywaraFrom: Eric Auger <[email protected]>
Implements kvm_vgic_hyp_init and vgic_probe function.
The vgic_global struct is enriched with new fields populated by those functions.
--- include/kvm/vgic/vgic.h | 1 + virt/kvm/arm/vgic/vgic-v2.c | 90 +++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-v3.c | 74 +++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.h | 6 +++ virt/kvm/arm/vgic/vgic_init.c | 122 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 293 insertions(+) create mode 100644 virt/kvm/arm/vgic/vgic_init.c
include/kvm/vgic/vgic.h +1 -0
@@ -198,6 +198,7 @@ struct vgic_cpu { };int kvm_vgic_addr (struct kvm *kvm,unsigned long type,u64 *addr,bool write); +int kvm_vgic_hyp_init (void );int kvm_vgic_inject_irq (struct kvm *kvm,int cpuid,unsigned int intid,bool level);
virt/kvm/arm/vgic/vgic-v2.c +90 -0
99 lines not on this page · raw message
virt/kvm/arm/vgic/vgic-v3.c +74 -0
86 lines not on this page · raw message
virt/kvm/arm/vgic/vgic.h +6 -0
@@ -41,6 +41,7 @@ int vgic_v2_dist_access(struct kvm_vcpu *vcpu, bool is_write,int vgic_v2_has_attr_regs (struct kvm_device *dev,struct kvm_device_attr *attr);void vgic_v2_set_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr);void vgic_v2_get_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr); +int vgic_v2_probe (struct device_node *vgic_node);#ifdef CONFIG_KVM_ARM_VGIC_V3 void vgic_v3_process_maintenance (struct kvm_vcpu *vcpu);
@@ -54,6 +55,7 @@ int vgic_v3_redist_access(struct kvm_vcpu *vcpu, bool is_write, int offset, int len, void *val);void vgic_v3_set_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr);void vgic_v3_get_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr); +int vgic_v3_probe (struct device_node *vgic_node);#else static inline void vgic_v3_process_maintenance (struct kvm_vcpu *vcpu) {
@@ -98,6 +100,10 @@ void vgic_v3_get_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr) { } +static inline int vgic_v3_probe (struct device_node *vgic_node) +{ +return -ENODEV ; +}#endif void vgic_set_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr);
virt/kvm/arm/vgic/vgic_init.c new file +122 -0
122 lines not on this page · raw message
Signature · 1 line
2.7.3
PATCH 39/45 KVM: arm/arm64: vgic-new: vgic_init: implement vgic_create
In reply to Andre PrzywaraFrom: Eric Auger <[email protected]>
This patch implements the vgic_creation function which is called on CREATE_IRQCHIP VM IOCTL (v2 only) or KVM_CREATE_DEVICE
--- include/kvm/vgic/vgic.h | 1 + virt/kvm/arm/vgic/vgic_init.c | 84 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+)
include/kvm/vgic/vgic.h +1 -0
@@ -198,6 +198,7 @@ struct vgic_cpu { };int kvm_vgic_addr (struct kvm *kvm,unsigned long type,u64 *addr,bool write); +int kvm_vgic_create (struct kvm *kvm,u32 type);int kvm_vgic_hyp_init (void ); int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid,
virt/kvm/arm/vgic/vgic_init.c +84 -0
90 lines not on this page · raw message
Signature · 1 line
2.7.3
PATCH 40/45 KVM: arm/arm64: vgic-new: vgic_init: implement vgic_init
In reply to Andre PrzywaraFrom: Eric Auger <[email protected]>
This patch allocates and initializes the data structures used to model the vgic distributor and virtual cpu interfaces. At that stage the number of IRQs and number of virtual CPUs is frozen.
The following early_init functions are kept since they are called from arm.c. However they may disappear in subsequent patches since they are void.
vgic_[v2|v3]_enable still is stubbed at this stage.
Changelog RFC..v1:
- initialize v2/v3 default CPU affinities explicitly
--- include/kvm/vgic/vgic.h | 7 +- virt/kvm/arm/vgic/vgic-v2.c | 5 + virt/kvm/arm/vgic/vgic-v3.c | 5 + virt/kvm/arm/vgic/vgic.c | 5 + virt/kvm/arm/vgic/vgic.h | 8 ++ virt/kvm/arm/vgic/vgic_init.c | 213 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 242 insertions(+), 1 deletion(-)
include/kvm/vgic/vgic.h +6 -1
@@ -115,6 +115,7 @@ struct vgic_io_device {struct vgic_dist {bool in_kernel;bool ready; +bool initialized;/* vGIC model the kernel emulates for the guest (GICv2 or GICv3) */ u32 vgic_model;
@@ -198,7 +199,11 @@ struct vgic_cpu { };int kvm_vgic_addr (struct kvm *kvm,unsigned long type,u64 *addr,bool write); +void kvm_vgic_early_init (struct kvm *kvm);int kvm_vgic_create (struct kvm *kvm,u32 type); +void kvm_vgic_destroy (struct kvm *kvm); +void kvm_vgic_vcpu_early_init (struct kvm_vcpu *vcpu); +void kvm_vgic_vcpu_destroy (struct kvm_vcpu *vcpu);int kvm_vgic_hyp_init (void ); int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid,
@@ -207,7 +212,7 @@ int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid,int kvm_vgic_vcpu_pending_irq (struct kvm_vcpu *vcpu);#define irqchip_in_kernel (k) (!!((k)->arch.vgic.in_kernel)) -#define vgic_initialized (k) (false) +#define vgic_initialized (k) ((k)->arch.vgic.initialized)#define vgic_ready (k) ((k)->arch.vgic.ready)#define vgic_valid_spi (k,i) (((i) >= VGIC_NR_PRIVATE_IRQS) && \ ((i) < (k)->arch.vgic.nr_spis + VGIC_NR_PRIVATE_IRQS))
virt/kvm/arm/vgic/vgic-v2.c +5 -0
@@ -208,6 +208,11 @@ void vgic_v2_get_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcrp)GICH_VMCR_PRIMASK_SHIFT ; } +/* not yet implemented */ +void vgic_v2_enable (struct kvm_vcpu *vcpu) +{ +} +/** * vgic_v2_probe - probe for a GICv2 compatible interrupt controller in DT * @node: pointer to the DT node
virt/kvm/arm/vgic/vgic-v3.c +5 -0
@@ -196,6 +196,11 @@ void vgic_v3_get_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcrp) vmcrp->pmr = (vmcr &ICH_VMCR_PMR_MASK ) >>ICH_VMCR_PMR_SHIFT ; } +/* not yet implemented */ +void vgic_v3_enable (struct kvm_vcpu *vcpu) +{ +} +/** * vgic_v3_probe - probe for a GICv3 compatible interrupt controller in DT * @node: pointer to the DT node
virt/kvm/arm/vgic/vgic.c +5 -0
@@ -288,6 +288,11 @@ int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid, bool level) {struct kvm_vcpu *vcpu; +int ret; + + ret =vgic_lazy_init (kvm); +if (ret) +return ret; vcpu =kvm_get_vcpu (kvm, cpuid);vgic_update_irq_pending (kvm, vcpu, intid, level);
virt/kvm/arm/vgic/vgic.h +8 -0
@@ -41,6 +41,7 @@ int vgic_v2_dist_access(struct kvm_vcpu *vcpu, bool is_write,int vgic_v2_has_attr_regs (struct kvm_device *dev,struct kvm_device_attr *attr);void vgic_v2_set_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr);void vgic_v2_get_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr); +void vgic_v2_enable (struct kvm_vcpu *vcpu);int vgic_v2_probe (struct device_node *vgic_node);#ifdef CONFIG_KVM_ARM_VGIC_V3
@@ -55,6 +56,7 @@ int vgic_v3_redist_access(struct kvm_vcpu *vcpu, bool is_write, int offset, int len, void *val);void vgic_v3_set_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr);void vgic_v3_get_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr); +void vgic_v3_enable (struct kvm_vcpu *vcpu);int vgic_v3_probe (struct device_node *vgic_node);#else static inline void vgic_v3_process_maintenance (struct kvm_vcpu *vcpu)
@@ -100,6 +102,10 @@ void vgic_v3_get_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr) { } +static inline void vgic_v3_enable (struct kvm_vcpu *vcpu) +{ +} +static inline int vgic_v3_probe (struct device_node *vgic_node) {return -ENODEV ;
@@ -109,6 +115,8 @@ static inline int vgic_v3_probe(struct device_node *vgic_node)void vgic_set_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr);void vgic_get_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr); +int vgic_lazy_init (struct kvm *kvm); +int vgic_init (struct kvm *kvm);void kvm_register_vgic_device (unsigned long type);#endif
virt/kvm/arm/vgic/vgic_init.c +213 -0
225 lines not on this page · raw message
Signature · 1 line
2.7.3
PATCH 41/45 KVM: arm/arm64: vgic-new: vgic_init: implement map_resources
In reply to Andre PrzywaraFrom: Eric Auger <[email protected]>
map_resources is the last initialization step. It is executed on 1st VCPU run. At that stage the code checks the userspace has provided the base addresses for the relevant VGIC regions, which depend on the type of VGIC that is exposed to the guest.
The function also forces the vgic_init if it has not been executed yet (only allowed for VGIC v2).
for GICv2, The VGIC CPU interface is mapped onto the GIC virtual CPU interface.
--- include/kvm/vgic/vgic.h | 1 + virt/kvm/arm/vgic/vgic-v2.c | 47 +++++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-v3.c | 44 ++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.h | 16 +++++++++++++++ virt/kvm/arm/vgic/vgic_init.c | 27 +++++++++++++++++++++++++ 5 files changed, 135 insertions(+)
include/kvm/vgic/vgic.h +1 -0
@@ -204,6 +204,7 @@ int kvm_vgic_create(struct kvm *kvm, u32 type);void kvm_vgic_destroy (struct kvm *kvm);void kvm_vgic_vcpu_early_init (struct kvm_vcpu *vcpu);void kvm_vgic_vcpu_destroy (struct kvm_vcpu *vcpu); +int kvm_vgic_map_resources (struct kvm *kvm);int kvm_vgic_hyp_init (void ); int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid,
virt/kvm/arm/vgic/vgic-v2.c +47 -0
53 lines not on this page · raw message
virt/kvm/arm/vgic/vgic-v3.c +44 -0
50 lines not on this page · raw message
virt/kvm/arm/vgic/vgic.h +16 -0
@@ -43,6 +43,9 @@ void vgic_v2_set_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr);void vgic_v2_get_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr);void vgic_v2_enable (struct kvm_vcpu *vcpu);int vgic_v2_probe (struct device_node *vgic_node); +int vgic_v2_map_resources (struct kvm *kvm); +int vgic_register_dist_iodev (struct kvm *kvm,gpa_t dist_base_address, +enum vgic_type );#ifdef CONFIG_KVM_ARM_VGIC_V3 void vgic_v3_process_maintenance (struct kvm_vcpu *vcpu);
@@ -58,6 +61,8 @@ void vgic_v3_set_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcr);void vgic_v3_get_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr);void vgic_v3_enable (struct kvm_vcpu *vcpu);int vgic_v3_probe (struct device_node *vgic_node); +int vgic_v3_map_resources (struct kvm *kvm); +int vgic_register_redist_iodevs (struct kvm *kvm,gpa_t dist_base_address);#else static inline void vgic_v3_process_maintenance (struct kvm_vcpu *vcpu) {
@@ -110,6 +115,17 @@ static inline int vgic_v3_probe(struct device_node *vgic_node) {return -ENODEV ; } + +static inline int vgic_v3_map_resources (struct kvm *kvm) +{ +return -ENODEV ; +} + +static inline int vgic_register_redist_iodevs (struct kvm *kvm, +gpa_t dist_base_address) +{ +return -ENODEV ; +}#endif void vgic_set_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr);
virt/kvm/arm/vgic/vgic_init.c +27 -0
@@ -321,6 +321,33 @@ int vgic_lazy_init(struct kvm *kvm)return ret; } +/* RESOURCE MAPPING */ + +/** +* Map the MMIO regions depending on the VGIC model exposed to the guest +* called on the first VCPU run. +* Also map the virtual CPU interface into the VM. +* v2/v3 derivatives call vgic_init if not already done. +* Completion can be tested by vgic_ready +*/ +int kvm_vgic_map_resources (struct kvm *kvm) +{ +struct vgic_dist *dist = &kvm->arch.vgic; +int ret =0 ; + +mutex_lock (&kvm->lock); +if (!irqchip_in_kernel (kvm)) + goto out; + +if (dist->vgic_model ==KVM_DEV_TYPE_ARM_VGIC_V2 ) + ret =vgic_v2_map_resources (kvm); +else + ret =vgic_v3_map_resources (kvm); +out: +mutex_unlock (&kvm->lock); +return ret; +} +/* GENERIC PROBE */ static void vgic_init_maintenance_interrupt (void *info)
Signature · 1 line
2.7.3
PATCH 42/45 KVM: arm/arm64: vgic-new: Add vgic_v2/v3_enable
In reply to Andre PrzywaraFrom: Eric Auger <[email protected]>
Enable the VGIC operation by properly initialising the registers in the hypervisor GIC interface.
--- virt/kvm/arm/vgic/vgic-v2.c | 11 ++++++++++- virt/kvm/arm/vgic/vgic-v3.c | 23 ++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-)
virt/kvm/arm/vgic/vgic-v2.c +10 -1
@@ -208,9 +208,18 @@ void vgic_v2_get_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcrp)GICH_VMCR_PRIMASK_SHIFT ; } -/* not yet implemented */ void vgic_v2_enable (struct kvm_vcpu *vcpu) { +/* +* By forcing VMCR to zero, the GIC will restore the binary +* points to their reset values. Anything else resets to zero +* anyway. +*/ + vcpu->arch.vgic_cpu.vgic_v2.vgic_vmcr =0 ; + vcpu->arch.vgic_cpu.vgic_v2.vgic_elrsr = ~0 ; + +/* Get the show on the road... */ + vcpu->arch.vgic_cpu.vgic_v2.vgic_hcr =GICH_HCR_EN ; }int vgic_v2_map_resources (struct kvm *kvm)
virt/kvm/arm/vgic/vgic-v3.c +22 -1
@@ -196,9 +196,30 @@ void vgic_v3_get_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcrp) vmcrp->pmr = (vmcr &ICH_VMCR_PMR_MASK ) >>ICH_VMCR_PMR_SHIFT ; } -/* not yet implemented */ void vgic_v3_enable (struct kvm_vcpu *vcpu) { +struct vgic_v3_cpu_if *vgic_v3 = &vcpu->arch.vgic_cpu.vgic_v3; + +/* +* By forcing VMCR to zero, the GIC will restore the binary +* points to their reset values. Anything else resets to zero +* anyway. +*/ + vgic_v3->vgic_vmcr =0 ; + vgic_v3->vgic_elrsr = ~0 ; + +/* +* If we are emulating a GICv3, we do it in an non-GICv2-compatible +* way, so we force SRE to 1 to demonstrate this to the guest. +* This goes with the spec allowing the value to be RAO/WI. +*/ +if (vcpu->kvm->arch.vgic.vgic_model ==KVM_DEV_TYPE_ARM_VGIC_V3 ) + vgic_v3->vgic_sre =ICC_SRE_EL1_SRE ; +else + vgic_v3->vgic_sre =0 ; + +/* Get the show on the road... */ + vgic_v3->vgic_hcr =ICH_HCR_EN ; }int vgic_v3_map_resources (struct kvm *kvm)
Signature · 1 line
2.7.3
PATCH 43/45 KVM: arm/arm64: vgic-new: Wire up irqfd injection
In reply to Andre PrzywaraConnect to the new VGIC to the irqfd framework, so that we can inject IRQs.
GSI routing and MSI routing is not yet implemented.
--- virt/kvm/arm/vgic/vgic_irqfd.c | 51 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 virt/kvm/arm/vgic/vgic_irqfd.c
virt/kvm/arm/vgic/vgic_irqfd.c new file +51 -0
@@ -0,0 +1,51 @@ +/* +* Copyright (C) 2015, 2016 ARM Ltd. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <linux/kvm.h> +#include <linux/kvm_host.h> +#include <trace/events/kvm.h> + +int kvm_irq_map_gsi (struct kvm *kvm, +struct kvm_kernel_irq_routing_entry *entries, +int gsi) +{ +return 0 ; +} + +int kvm_irq_map_chip_pin (struct kvm *kvm,unsigned irqchip,unsigned pin) +{ +return pin; +} + +int kvm_set_irq (struct kvm *kvm,int irq_source_id, +u32 irq,int level,bool line_status) +{ +unsigned int spi = irq +VGIC_NR_PRIVATE_IRQS ; + +trace_kvm_set_irq (irq, level, irq_source_id); + +BUG_ON (!vgic_initialized (kvm)); + +return kvm_vgic_inject_irq (kvm,0 , spi, level); +} + +/* MSI not implemented yet */ +int kvm_set_msi (struct kvm_kernel_irq_routing_entry *e, +struct kvm *kvm,int irq_source_id, +int level,bool line_status) +{ +return 0 ; +}
Signature · 1 line
2.7.3
PATCH 44/45 KVM: arm/arm64: vgic-new: implement mapped IRQ handling
In reply to Andre PrzywaraWe now store the mapped hardware IRQ number in our struct, so we don't need the irq_phys_map for the new VGIC. Implement the hardware IRQ mapping on top of the reworked arch timer interface.
Changelog RFC..v1:
- adapt to new arch_timer mapped IRQ interface
- implement inject_mapped_irq() as a macro (since it is identical to the "un-mapped" IRQ implementation)
--- include/kvm/vgic/vgic.h | 6 ++++++ virt/kvm/arm/vgic/vgic.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+)
include/kvm/vgic/vgic.h +6 -0
@@ -209,6 +209,12 @@ int kvm_vgic_hyp_init(void);int kvm_vgic_inject_irq (struct kvm *kvm,int cpuid,unsigned int intid,bool level); +/* TODO: for compatibility with the old VGIC's timer implementation */ +#define kvm_vgic_inject_mapped_irq kvm_vgic_inject_irq + +int kvm_vgic_map_phys_irq (struct kvm_vcpu *vcpu,u32 virt_irq,u32 phys_irq); +int kvm_vgic_unmap_phys_irq (struct kvm_vcpu *vcpu,unsigned int virt_irq); +bool kvm_vgic_map_is_active (struct kvm_vcpu *vcpu,unsigned int virt_irq);int kvm_vgic_vcpu_pending_irq (struct kvm_vcpu *vcpu);
virt/kvm/arm/vgic/vgic.c +47 -0
62 lines not on this page · raw message
Signature · 1 line
2.7.3
PATCH 45/45 KVM: arm/arm64: vgic-new: enable build
In reply to Andre PrzywaraNow that the new VGIC implementation has reached feature parity with the old one, add the new files to the build system and add a Kconfig option to switch between the two versions.
We set the default to the new version to get maximum test coverage, in case people experience problems they can switch back to the old behaviour if needed.
--- arch/arm/kvm/Kconfig | 7 +++++++ arch/arm/kvm/Makefile | 10 ++++++++++ arch/arm64/kvm/Kconfig | 7 +++++++ arch/arm64/kvm/Makefile | 10 ++++++++++ virt/kvm/arm/hyp/vgic-v2-sr.c | 5 +++++ 5 files changed, 39 insertions(+)
arch/arm/kvm/Kconfig +7 -0
@@ -46,6 +46,13 @@ config KVM_ARM_HOST ---help--- Provides host support for ARM processors. +config KVM_NEW_VGIC + bool "New VGIC implementation" + depends on KVM + default y + ---help--- + uses the new VGIC implementation + source drivers/vhost/Kconfig endif # VIRTUALIZATION
arch/arm/kvm/Makefile +10 -0
@@ -21,7 +21,17 @@ obj-$(CONFIG_KVM_ARM_HOST) += hyp/ obj-y += kvm-arm.o init.o interrupts.o obj-y += arm.o handle_exit.o guest.o mmu.o emulate.o reset.o obj-y += coproc.o coproc_a15.o coproc_a7.o mmio.o psci.o perf.o + +ifeq ($(CONFIG_KVM_NEW_VGIC),y) +obj-y += $(KVM)/arm/vgic/vgic.o +obj-y += $(KVM)/arm/vgic/vgic_init.o +obj-y += $(KVM)/arm/vgic/vgic_irqfd.o +obj-y += $(KVM)/arm/vgic/vgic-v2.o +obj-y += $(KVM)/arm/vgic/vgic_mmio.o +obj-y += $(KVM)/arm/vgic/vgic_kvm_device.o +else obj-y += $(KVM)/arm/vgic.o obj-y += $(KVM)/arm/vgic-v2.o obj-y += $(KVM)/arm/vgic-v2-emul.o +endif obj-y += $(KVM)/arm/arch_timer.o
arch/arm64/kvm/Kconfig +7 -0
@@ -55,6 +55,13 @@ config KVM_ARM_PMU Adds support for a virtual Performance Monitoring Unit (PMU) in virtual machines. +config KVM_NEW_VGIC + bool "New VGIC implementation" + depends on KVM + default y + ---help--- + uses the new VGIC implementation + source drivers/vhost/Kconfig endif # VIRTUALIZATION
arch/arm64/kvm/Makefile +10 -0
@@ -20,10 +20,20 @@ kvm-$(CONFIG_KVM_ARM_HOST) += emulate.o inject_fault.o regmap.o kvm-$(CONFIG_KVM_ARM_HOST) += hyp.o hyp-init.o handle_exit.o kvm-$(CONFIG_KVM_ARM_HOST) += guest.o debug.o reset.o sys_regs.o sys_regs_generic_v8.o +ifeq ($(CONFIG_KVM_NEW_VGIC),y) +kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic.o +kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic_init.o +kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic_irqfd.o +kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic-v2.o +kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic-v3.o +kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic_mmio.o +kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic_kvm_device.o +else kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic.o kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic-v2.o kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic-v2-emul.o kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic-v3.o kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic-v3-emul.o +endif kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/arch_timer.o kvm-$(CONFIG_KVM_ARM_PMU) += $(KVM)/arm/pmu.o
virt/kvm/arm/hyp/vgic-v2-sr.c +5 -0
@@ -21,7 +21,12 @@#include <asm/kvm_hyp.h> +#ifdef CONFIG_KVM_NEW_VGIC +extern struct vgic_global kvm_vgic_global_state; +#define vgic_v2_params kvm_vgic_global_state +#else extern struct vgic_params vgic_v2_params; +#endif static void __hyp_text save_maint_int_state(struct kvm_vcpu *vcpu,void __iomem *base)
Signature · 1 line
2.7.3
Hi Andre,
Quoted 2 lines · Andre Przywara
Please have a look at the series, review it and give the code some serious testing (and possibly debugging). All feedback is appreciated.
I've tried to give it a slight test with --irqchip=gicv3 -c 255, but even with -c8 I get quite often:
Quoted 111 lines
# lkvm run -k gic-test.flat -m 704 -c 8 --name guest-1167 Info: Loaded kernel to 0x80080000 (69624 bytes) Info: Placing fdt at 0x8fe00000 - 0x8fffffff # Warning: The maximum recommended amount of VCPUs is 4 Info: virtio-mmio.devices=0x200@0x10000:36Info: virtio-mmio.devices=0x200@0x10200:37
Info: virtio-mmio.devices=0x200@0x10400:38
Info: virtio-mmio.devices=0x200@0x10600:39
Unable to handle kernel paging request at virtual address 3ffc0000 pgd = ffffffc077ae3000 [3ffc0000] *pgd=00000000f7989003, *pud=00000000f7989003, *pmd=0000000000000000 Internal error: Oops: 96000006 [#1] PREEMPT SMP Modules linked in: CPU: 3 PID: 1176 Comm: kvm-vcpu-1 Tainted: G W 4.6.0-rc3+ #776 Hardware name: FVP Base (DT) task: ffffffc078698c00 ti: ffffffc077b38000 task.ti: ffffffc077b38000 PC is at vgic_mmio_write_priority+0x38/0x84 LR is at dispatch_mmio_write+0x64/0x7c pc : [<ffffff80080ad868>] lr : [<ffffff80080acb50>] pstate: 20000145sp :
ffffffc077b3b8f0
x29:ffffffc077b3b8f0x28: 0000000000000004
x27:ffffffc077463b00x26:ffffffc077913000
x25: 0000000000000000 x24: 0000000000000000
x23: 0000000000000004 x22:000000003ffc0000
x21:ffffffc077b3ba30x20:000000003ffe0400
x19: 0000000000000000 x18: 0000000000000000
x17: 0000000000000000 x16: 0000000000000000
x15: 0000000000000000 x14: 0000000000000000
x13: 0000000000000000 x12: 0000000000000000
x11:000000008015ffd0x10:000000008015f660
x9 :000000008015f661x8 :000000003ffe0404
x7 :ffffff80080ad830x6 :ffffffc077b3ba30
x5 : 0000000000000004 x4 :ffffffc077b3ba30
x3 : 0000000000000004 x2 : 0000000000000000
x1 :ffffffc07792e0d0x0 :ffffffc077463b00Process kvm-vcpu-1 (pid: 1176, stack limit =
0xffffffc077b38020)Stack: (0xffffffc077b3b8f0 to 0xffffffc077b3c000)b8e0:
ffffffc077b3b930ffffff80080acb50
b900:ffffffc07792e0d0000000003ffe0400ffffffc077463b00ffffffc07792f600
b920:ffffffc077b3b9d80000000000000000ffffffc077b3b970ffffff80080acd84
b940: 0000000000000011ffffffc077463b00ffffffc077b3ba30ffffffc077463b00
b960: 0000000000000004ffffffc077b3ba30ffffffc077b3b980ffffff800809bc2c
b980:ffffffc077b3b9c0ffffff800809bcccffffffc077463b000000000000000004
b9a0:ffffffc077913000000000003ffe04000000000000000004 0000000000000001
b9c0:ffffffc077b3b9f0ffffff80080a6a580000000000000000000000003ffe0400
b9e0: 0000000000000004 0000000000000000ffffffc077b3ba40ffffff80080a5c0c
ba00:000000003ffe00000000000000000000 0000000000000004000000000003ffe0
ba20: 0000000000000024ffffff80080a59cc00000000a0a0a0a000000000a0a0a0a0
ba40:ffffffc077b3bad0ffffff80080a7840ffffffc077463b00ffffffc077913000
ba60: 0000000000000001 0000000000000000ffffffc077464b00ffffff8008a69000
ba80: 0000000000000001ffffffc077b3bb90ffffffc077913000ffffff8008af1318
baa0:ffffffc077b3bab0ffffff80080ab134ffffffc077b3bb10ffffff80080a2a44
bac0:ffffffc077463b000000000000000001ffffffc077b3bb10ffffff80080a2a70
bae0:ffffffc077463b000000000000000001ffffffc077b38000ffffffc077b3bb90
bb00:ffffffc077913000ffffff8008af1318ffffffc077b3bba0ffffff800809db88
bb20:ffffffc0785b2f000000000000000000ffffffc077463b000000000000000000
bb40:ffffffc0779be0000000000000000000000000000000011e000000000000001d
bb60:ffffff80086f0000ffffffc077b38000ffffffc0779be000ffffff8008af1300
bb80:ffffffc077463b00ffffff8008411d18ffffffc077b3bbc00000000000000003
bba0:ffffffc077b3be00ffffff80081cae44ffffffc0779be0000000000000000000
bbc0:ffffffc078031920000000000000000c000000000000ae80ffffff80084122a4
bbe0:ffffffc078734418000000000000ae80ffffffc077e5f001ffffff8008b802a8
bc00:ffffffc077b3bc10ffffff8008412340ffffffc077b3bc40ffffff8008403d5c
bc20:ffffffc078734418ffffffc077e5ec00ffffffc077e5f001ffffff8008b802a8
bc40:ffffffc077b3bc50ffffff8008403d9cffffffc077b3bc90ffffff80080ed7e0
bc60:ffffffc077b3bc70ffffff80080eda0cffffffc077b3bc90ffffff80083e95f8
bc80:ffffffc077b3bc90ffffff80083e9600ffffffc077b3bce0ffffff80080eda58
bca0:ffffffc077e5ee30000000000000014000000000004c995d0000000000000001
bcc0:ffffffc0778f58000000000000000001ffffffc077b3bce0ffffff80080eda64
bce0:ffffffc077b3bd20ffffff80083e4114ffffffc077e5ec00ffffffc0785e0508
bd00:ffffffc077b380000000000000000004 0000000000000001 0000000000000001
bd20:ffffffc077b3bd30ffffff80083ed098ffffffc077b3bd40ffffff80083e50b0
bd40:ffffffc077b3bdb0ffffff80081b8618ffffffc0778f5800ffffffc077b3bec8
bd60:00000000004c995cffffffc077b3bec80000000080000000 0000000000000015
bd80:000000000000011e0000000000000040ffffffc077b3be30ffffff80081b9588
bda0:ffffffc0778f58000000000000000001ffffffc0785e05080000000000000002
bdc0:ffffffc0778f58100000000000000015000000000000011e0000000000000040
bde0:ffffff80086f0000ffffffc077b38000ffffffc077b3be3000000000081b956c
be00:ffffffc077b3be90ffffff80081cb5740000000000000000ffffffc0779be001
be20:ffffffc0779be000000000000000000c000000000000ae80ffffff80081ba828
be40:ffffffc077b3be70ffffff80081d5458ffffffc077b3be90ffffff80081cb530
be60: 0000000000000000ffffffc0779be001ffffffc0779be000000000000000000c
be80:000000000000ae80ffffff80081cb5140000000000000000ffffff8008085e70
bea0: 0000000000000000 0000000000493444 ffffffffffffffff000000000044734c
bec0: 0000000060000000 0000000000000015000000000000000c000000000000ae80
bee0: 0000000000000000 0000000000000000 000000000000000000000000ffffffff
bf00:0000007f641800000000000000000000000000000000001d000000000e461000
bf20: 00000000000000000000007f611718500000007f611718500000007f61171820
bf40:ffffff80ffffffd00000000000573000 0000000000000000 0000000000000001
bf60: 0000000000000000000000000e464b600000000000493444000000000000ffff
bf80:0000007fe582d3f80000000000000001 0000000000000000 0000000000800000
bfa0:0000007fe582d3f800000000000010000000000000401f680000007f61171790
bfc0: 00000000004061300000007f61171790000000000044734c0000000060000000
bfe0:000000000000000c000000000000001dcfdfdfdfdfdfdfcf cfdfdfdfdfdfdfcfCall trace: Exception stack(0xffffffc077b3b730 to 0xffffffc077b3b850)b720: 0000000000000000
000000003ffe0400
b740:ffffffc077b3b8f0ffffff80080ad868ffffffc077b3b8e0ffffff80080e79fc
b760:00000000ffff0b210000000000000001ffffffc0784222000000000000000003
b780:ffffff8008a5d0000000000000000001ffffffc078421300ffffffc077b3bb90
b7a0:ffffff8008a5d000ffffffc077b3b9a8ffffffc000000000ffffff80080dba68
b7c0:ffffffc077b3b830fffffffffffffff8ffffffc077463b00ffffffc07792e0d0
b7e0: 0000000000000000 0000000000000004ffffffc077b3ba300000000000000004
b800:ffffffc077b3ba30ffffff80080ad830000000003ffe0404000000008015f661
b820:000000008015f660000000008015ffd00000000000000000 0000000000000000
b840: 0000000000000000 0000000000000000
Quoted 15 lines
[<ffffff80080ad868>] vgic_mmio_write_priority+0x38/0x84 [<ffffff80080acb50>] dispatch_mmio_write+0x64/0x7c [<ffffff80080acd84>] vgic_mmio_write_v3redist_private+0x2c/0x34 [<ffffff800809bc2c>] __kvm_io_bus_write+0xb8/0x11c [<ffffff800809bccc>] kvm_io_bus_write+0x3c/0x4c [<ffffff80080a6a58>] io_mem_abort+0x1b0/0x28c [<ffffff80080a5c0c>] kvm_handle_guest_abort+0x300/0x680 [<ffffff80080a7840>] handle_exit+0x5c/0x150 [<ffffff80080a2a70>] kvm_arch_vcpu_ioctl_run+0x290/0x47c [<ffffff800809db88>] kvm_vcpu_ioctl+0x2d4/0x6ec [<ffffff80081cae44>] do_vfs_ioctl+0xb4/0x760 [<ffffff80081cb574>] SyS_ioctl+0x84/0x98 [<ffffff8008085e70>] el0_svc_naked+0x24/0x28 Code: 5400022d aa0403f5 0b030057 2a0203f3 (f94002c0) ---[ end trace 9d998e161d0dbdb6 ]---
or something like that (I've seen NULL pointer dereference with -c2) but with the same call trace. It happens only with --irqchip=gicv3, gicv2 works fine.
Code around PC at vgic_mmio_write_priority+0x38/0x84 matches to:
Quoted 11 lines
if (iodev->redist_vcpu)
ffffff80080ad848: f85f8036 ldr x22, [x1,#-8]
ffffff80080ad84c: eb1f02df cmp x22, xzr
ffffff80080ad850: 9a8012d6 csel x22, x22, x0, ne
vcpu = iodev->redist_vcpu;
for (i = 0; i < len; i++) {
ffffff80080ad854: 6b1f007f cmp w3, wzr
ffffff80080ad858: 5400022d b.le ffffff80080ad89c <vgic_mmio_write_priority+0x6c>
ffffff80080ad85c: aa0403f5 mov x21, x4
ffffff80080ad860: 0b030057 add w23, w2, w3Quoted 8 lines
ffffff80080ad864: 2a0203f3 mov w19, w2
struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, vcpu, intid + i);
ffffff80080ad868: f94002c0 ldr x0, [x22]
ffffff80080ad86c: 2a1303e2 mov w2, w19
ffffff80080ad870: aa1603e1 mov x1, x22
ffffff80080ad874: 11000673 add w19, w19, #0x1
ffffff80080ad878: 97fff4d0 bl ffffff80080aabb8 <vgic_get_irq>
ffffff80080ad87c: aa0003f4 mov x20, x0Cheers
Vladimir
Hi Vladimir,
can you try the attached patch on top of the series to see if this fixes the GICv3 emulation issues you see?
I think these lines got lost during the MMIO framework rebasing.
Cheers,
Andre.
--- virt/kvm/arm/vgic/vgic_mmio.c | 2 ++ 1 file changed, 2 insertions(+)
virt/kvm/arm/vgic/vgic_mmio.c +2 -0
@@ -1228,6 +1228,7 @@ int vgic_register_redist_iodevs(struct kvm *kvm, gpa_t redist_base_address)kvm_for_each_vcpu (c, vcpu, kvm) {kvm_iodevice_init (®ion->dev, &kvm_io_v3redist_ops); region->base_addr = redist_base_address; + region->redist_vcpu = vcpu;mutex_lock (&kvm->slots_lock); ret = kvm_io_bus_register_dev(kvm, KVM_MMIO_BUS,
@@ -1241,6 +1242,7 @@ int vgic_register_redist_iodevs(struct kvm *kvm, gpa_t redist_base_address) region++;kvm_iodevice_init (®ion->dev, &kvm_io_v3redist_private_ops); region->base_addr = redist_base_address +SZ_64K ; + region->redist_vcpu = vcpu;mutex_lock (&kvm->slots_lock); ret = kvm_io_bus_register_dev(kvm, KVM_MMIO_BUS,
Signature · 1 line
2.7.3
Quoted 5 lines · Andre Przywara
Hi Vladimir,
can you try the attached patch on top of the series to see if this fixes the GICv3 emulation issues you see?
With attached patch I don't see issue any more - all 255 vcpus are able to boot and send/receive self SGI.
Thanks
Vladimir
Quoted 30 lines
I think these lines got lost during the MMIO framework rebasing.
Cheers,
Andre.--- virt/kvm/arm/vgic/vgic_mmio.c | 2 ++ 1 file changed, 2 insertions(+)virt/kvm/arm/vgic/vgic_mmio.c +2
-0@@ -1228,6 +1228,7 @@ int vgic_register_redist_iodevs(struct kvm *kvm, gpa_t redist_base_address)kvm_for_each_vcpu (c, vcpu, kvm) {kvm_iodevice_init (®ion->dev, &kvm_io_v3redist_ops); region->base_addr = redist_base_address; + region->redist_vcpu = vcpu;mutex_lock (&kvm->slots_lock); ret = kvm_io_bus_register_dev(kvm, KVM_MMIO_BUS,@@ -1241,6 +1242,7 @@ int vgic_register_redist_iodevs(struct kvm *kvm, gpa_t redist_base_address) region++;kvm_iodevice_init (®ion->dev, &kvm_io_v3redist_private_ops); region->base_addr = redist_base_address +SZ_64K ; + region->redist_vcpu = vcpu;mutex_lock (&kvm->slots_lock); ret = kvm_io_bus_register_dev(kvm, KVM_MMIO_BUS,