KVM: arm/arm64: Rework virtual GIC emulation
Subsystems (5)
v3 cover KVM: arm/arm64: Rework virtual GIC emulation
Hi,
another week, another rework of the new-VGIC series.
Mostly minor changes this time, some moving and streamlining of patches (move prototypes to the same patch as the definition etc.)
The most prominent change though is the rework of the GICv2 CPU interface access functionality. It turns out that this was not properly wired, so now we treat is very similar to the distributor registers and declare the registers in our register structure.
Find a summary changelog below and more details in the respective patches.
As this new VGIC emulation will probably become the default very shortly, please test it full steam on whatever setup you have access to. Any reports are warmly welcome.
This series is still based on v4.6-rc5 as the previous version, though a test rebase to -rc6 didn't trigger any issues.
A git tree containing this series can be found on linux-arm.org:
git://linux-arm.org/linux-ap.git branch: vgic-new/v3
http://www.linux-arm.org/git?p=linux-ap.git;a=log;h=refs/heads/vgic-new/v3
Cheers,
Andre.
Changelog v2 .. v3:
- arch_timer: remove bogus validity check from kvm_vgic_unmap_phys_irq()
- arch_timer: simplify return in kvm_timer_vcpu_reset()
- move some code between patches to fix rebase artifacts
- add patch 12/55 to move some definitions into arm-vgic-v3.h
- replace inclusions of vgic/vgic.h with arm_vgic.h
- rename v3 redist register description variables to _rdbase_ and _sgibase_
- don't export VMCR accessor wrappers
- rework CPU i/f access from userland, moving code into vgic-mmio-v2.c
- make ich_vtr_el2 variable local
===========================
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 structure, which holds all information about a virtual interrupt. Interruts which should be injected are held 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.
Andre Przywara (29):
KVM: arm/arm64: vgic: streamline vgic_update_irq_pending() interface
KVM: arm/arm64: vgic: avoid map in kvm_vgic_inject_mapped_irq()
KVM: arm/arm64: vgic: avoid map in kvm_vgic_map_is_active()
KVM: arm/arm64: vgic: avoid map in kvm_vgic_unmap_phys_irq()
KVM: arm/arm64: arch_timer: Remove irq_phys_map
KVM: arm/arm64: vgic: Remove irq_phys_map from interface
KVM: arm/arm64: pmu: abstract access to number of SPIs
KVM: arm/arm64: move GICv2 emulation defines into arm-gic-v3.h
KVM: arm/arm64: vgic-new: Add GICv2 MMIO handling framework
KVM: arm/arm64: vgic-new: Add ENABLE registers handlers
KVM: arm/arm64: vgic-new: Add PENDING registers handlers
KVM: arm/arm64: vgic-new: Add ACTIVE registers handlers
KVM: arm/arm64: vgic-new: Add PRIORITY 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 and TYPER handler
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 (9):
KVM: arm/arm64: Remove the IRQ field from struct irq_phys_map
KVM: arm/arm64: Get rid of vgic_cpu->nr_lr
KVM: arm/arm64: Fix MMIO emulation data handling
KVM: arm/arm64: Export mmio_read/write_bus
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
KVM: arm/arm64: vgic-new: Export register access interface
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: implement kvm_vgic_addr
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_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 (5):
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
KVM: arm/arm64: vgic-new: Add MMIO handling framework
KVM: arm/arm64: vgic-new: Add CTLR, TYPER and IIDR handlers
arch/arm/include/asm/kvm_mmio.h | 3 + arch/arm/kvm/Kconfig | 7 + arch/arm/kvm/Makefile | 11 + arch/arm/kvm/mmio.c | 24 +- arch/arm64/include/asm/kvm_mmio.h | 3 + arch/arm64/kvm/Kconfig | 7 + arch/arm64/kvm/Makefile | 12 + include/kvm/arm_arch_timer.h | 3 - include/kvm/arm_vgic.h | 20 +- include/kvm/vgic/vgic.h | 253 +++++++++++++++ include/linux/irqchip/arm-gic-v3.h | 6 + include/linux/irqchip/arm-gic.h | 2 + virt/kvm/arm/arch_timer.c | 42 ++- 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-v3.c | 8 +- virt/kvm/arm/vgic.c | 86 ++--- virt/kvm/arm/vgic/vgic-init.c | 446 ++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-irqfd.c | 52 +++ virt/kvm/arm/vgic/vgic-kvm-device.c | 452 ++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio-v2.c | 422 +++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio-v3.c | 464 +++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.c | 523 ++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.h | 128 ++++++++ virt/kvm/arm/vgic/vgic-v2.c | 358 +++++++++++++++++++++ virt/kvm/arm/vgic/vgic-v3.c | 333 +++++++++++++++++++ virt/kvm/arm/vgic/vgic.c | 615 ++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.h | 121 +++++++ 29 files changed, 4309 insertions(+), 115 deletions(-) create mode 100644 include/kvm/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-v2.c create mode 100644 virt/kvm/arm/vgic/vgic-mmio-v3.c create mode 100644 virt/kvm/arm/vgic/vgic-mmio.c create mode 100644 virt/kvm/arm/vgic/vgic-mmio.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
Signature · 1 line
2.7.3
PATCH v3 1/55 KVM: arm/arm64: vgic: streamline vgic_update_irq_pending() interface
We actually don't use the irq_phys_map parameter in vgic_update_irq_pending(), so let's just remove it.
--- virt/kvm/arm/vgic.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
virt/kvm/arm/vgic.c +2 -3
@@ -1522,7 +1522,6 @@ static int vgic_validate_injection(struct kvm_vcpu *vcpu, int irq, int level) }static int vgic_update_irq_pending (struct kvm *kvm,int cpuid, -struct irq_phys_map *map,unsigned int irq_num,bool level) {struct vgic_dist *dist = &kvm->arch.vgic;
@@ -1661,7 +1660,7 @@ int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int irq_num,if (map)return -EINVAL ; -return vgic_update_irq_pending (kvm, cpuid,NULL , irq_num, level); +return vgic_update_irq_pending (kvm, cpuid, irq_num, level); }/**
@@ -1687,7 +1686,7 @@ int kvm_vgic_inject_mapped_irq(struct kvm *kvm, int cpuid,if (ret)return ret; -return vgic_update_irq_pending (kvm, cpuid, map, map->virt_irq, level); +return vgic_update_irq_pending (kvm, cpuid, map->virt_irq, level); }static irqreturn_t vgic_maintenance_handler (int irq,void *data)
Signature · 1 line
2.7.3
PATCH v3 2/55 KVM: arm/arm64: vgic: avoid map in kvm_vgic_inject_mapped_irq()
In reply to Andre PrzywaraWhen we want to inject a hardware mapped IRQ into a guest, we actually only need the virtual IRQ number from the irq_phys_map.
So let's pass this number directly from the arch timer to the VGIC to avoid using the map as a parameter.
--- include/kvm/arm_vgic.h | 2 +- virt/kvm/arm/arch_timer.c | 2 +- virt/kvm/arm/vgic.c | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-)
include/kvm/arm_vgic.h +1 -1
@@ -341,7 +341,7 @@ void kvm_vgic_sync_hwstate(struct kvm_vcpu *vcpu);int kvm_vgic_inject_irq (struct kvm *kvm,int cpuid,unsigned int irq_num,bool level);int kvm_vgic_inject_mapped_irq (struct kvm *kvm,int cpuid, -struct irq_phys_map *map,bool level); +unsigned int virt_irq,bool level);void vgic_v3_dispatch_sgi (struct kvm_vcpu *vcpu,u64 reg);int kvm_vgic_vcpu_pending_irq (struct kvm_vcpu *vcpu); struct irq_phys_map *kvm_vgic_map_phys_irq(struct kvm_vcpu *vcpu,
virt/kvm/arm/arch_timer.c +1 -1
@@ -178,7 +178,7 @@ static void kvm_timer_update_irq(struct kvm_vcpu *vcpu, bool new_level)trace_kvm_timer_update_irq (vcpu->vcpu_id, timer->map->virt_irq, timer->irq.level); ret =kvm_vgic_inject_mapped_irq (vcpu->kvm, vcpu->vcpu_id, - timer->map, + timer->map->virt_irq, timer->irq.level);WARN_ON (ret); }
virt/kvm/arm/vgic.c +3 -3
@@ -1667,7 +1667,7 @@ int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int irq_num,* kvm_vgic_inject_mapped_irq - Inject a physically mapped IRQ to the vgic * @kvm: The VM structure pointer * @cpuid: The CPU for PPIs -* @map: Pointer to a irq_phys_map structure describing the mapping +* @virt_irq: The virtual IRQ to be injected * @level: Edge-triggered: true: to trigger the interrupt * false: to ignore the call * Level-sensitive true: raise the input signal
@@ -1678,7 +1678,7 @@ int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int irq_num,* being HIGH and 0 being LOW and all devices being active-HIGH. */ int kvm_vgic_inject_mapped_irq (struct kvm *kvm,int cpuid, -struct irq_phys_map *map,bool level) +unsigned int virt_irq,bool level) {int ret;
@@ -1686,7 +1686,7 @@ int kvm_vgic_inject_mapped_irq(struct kvm *kvm, int cpuid,if (ret)return ret; -return vgic_update_irq_pending (kvm, cpuid, map->virt_irq, level); +return vgic_update_irq_pending (kvm, cpuid, virt_irq, level); }static irqreturn_t vgic_maintenance_handler (int irq,void *data)
Signature · 1 line
2.7.3
PATCH v3 3/55 KVM: arm/arm64: vgic: avoid map in kvm_vgic_map_is_active()
In reply to Andre PrzywaraFor getting the active state of a mapped IRQ, we actually only need the virtual IRQ number, not the pointer to the mapping entry. Pass the virtual IRQ number from the arch timer to the VGIC directly.
---
Changelog v1 .. v2:
- rewrap phys_active determination to fit in 80 characters
include/kvm/arm_vgic.h | 2 +- virt/kvm/arm/arch_timer.c | 6 ++---- virt/kvm/arm/vgic.c | 6 +++--- 3 files changed, 6 insertions(+), 8 deletions(-)
include/kvm/arm_vgic.h +1 -1
@@ -347,7 +347,7 @@ int kvm_vgic_vcpu_pending_irq(struct kvm_vcpu *vcpu);struct irq_phys_map *kvm_vgic_map_phys_irq (struct kvm_vcpu *vcpu,int virt_irq,int irq);int kvm_vgic_unmap_phys_irq (struct kvm_vcpu *vcpu,struct irq_phys_map *map); -bool kvm_vgic_map_is_active (struct kvm_vcpu *vcpu,struct irq_phys_map *map); +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))
virt/kvm/arm/arch_timer.c +2 -4
@@ -275,10 +275,8 @@ void kvm_timer_flush_hwstate(struct kvm_vcpu *vcpu)* to ensure that hardware interrupts from the timer triggers a guest * exit. */ -if (timer->irq.level ||kvm_vgic_map_is_active (vcpu, timer->map)) - phys_active = true; -else - phys_active = false; + phys_active = timer->irq.level || +kvm_vgic_map_is_active (vcpu, timer->map->virt_irq);/* * We want to avoid hitting the (re)distributor as much as
virt/kvm/arm/vgic.c +3 -3
@@ -1103,18 +1103,18 @@ static bool dist_active_irq(struct kvm_vcpu *vcpu)return test_bit (vcpu->vcpu_id, dist->irq_active_on_cpu); } -bool kvm_vgic_map_is_active (struct kvm_vcpu *vcpu,struct irq_phys_map *map) +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++) {struct vgic_lr vlr =vgic_get_lr (vcpu, i); -if (vlr.irq == map->virt_irq && vlr.state &LR_STATE_ACTIVE ) +if (vlr.irq == virt_irq && vlr.state &LR_STATE_ACTIVE )return true; } -return vgic_irq_is_active (vcpu, map->virt_irq); +return vgic_irq_is_active (vcpu, virt_irq); }/*
Signature · 1 line
2.7.3
PATCH v3 4/55 KVM: arm/arm64: vgic: avoid map in kvm_vgic_unmap_phys_irq()
In reply to Andre Przywarakvm_vgic_unmap_phys_irq() only needs the virtual IRQ number, so let's just pass that between the arch timer and the VGIC to get rid of the irq_phys_map pointer.
--- include/kvm/arm_vgic.h | 2 +- virt/kvm/arm/arch_timer.c | 2 +- virt/kvm/arm/vgic.c | 11 ++++------- 3 files changed, 6 insertions(+), 9 deletions(-)
include/kvm/arm_vgic.h +1 -1
@@ -346,7 +346,7 @@ void vgic_v3_dispatch_sgi(struct kvm_vcpu *vcpu, u64 reg);int kvm_vgic_vcpu_pending_irq (struct kvm_vcpu *vcpu);struct irq_phys_map *kvm_vgic_map_phys_irq (struct kvm_vcpu *vcpu,int virt_irq,int irq); -int kvm_vgic_unmap_phys_irq (struct kvm_vcpu *vcpu,struct irq_phys_map *map); +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);#define irqchip_in_kernel (k) (!!((k)->arch.vgic.in_kernel))
virt/kvm/arm/arch_timer.c +1 -1
@@ -504,7 +504,7 @@ void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu)timer_disarm (timer);if (timer->map) -kvm_vgic_unmap_phys_irq (vcpu, timer->map); +kvm_vgic_unmap_phys_irq (vcpu, timer->map->virt_irq); }void kvm_timer_enable (struct kvm *kvm)
virt/kvm/arm/vgic.c +4 -7
@@ -1813,25 +1813,22 @@ static void vgic_free_phys_irq_map_rcu(struct rcu_head *rcu)/** * kvm_vgic_unmap_phys_irq - Remove a virtual to physical IRQ mapping * @vcpu: The VCPU pointer -* @map: The pointer to a mapping obtained through kvm_vgic_map_phys_irq +* @virt_irq: The virtual IRQ number to be unmapped * * Remove an existing mapping between virtual and physical interrupts. */ -int kvm_vgic_unmap_phys_irq (struct kvm_vcpu *vcpu,struct irq_phys_map *map) +int kvm_vgic_unmap_phys_irq (struct kvm_vcpu *vcpu,unsigned int virt_irq) {struct vgic_dist *dist = &vcpu->kvm->arch.vgic;struct irq_phys_map_entry *entry;struct list_head *root; -if (!map) -return -EINVAL ; - - root =vgic_get_irq_phys_map_list (vcpu, map->virt_irq); + root =vgic_get_irq_phys_map_list (vcpu, virt_irq);spin_lock (&dist->irq_phys_map_lock);list_for_each_entry (entry, root, entry) { -if (&entry->map == map) { +if (entry->map.virt_irq == virt_irq) {list_del_rcu (&entry->entry);call_rcu (&entry->rcu, vgic_free_phys_irq_map_rcu);break ;
Signature · 1 line
2.7.3
PATCH v3 5/55 KVM: arm/arm64: Remove the IRQ field from struct irq_phys_map
In reply to Andre PrzywaraFrom: Christoffer Dall <[email protected]>
The communication of a Linux IRQ number from outside the VGIC to the vgic was a leftover from the day when the vgic code cared about how a particular device injects virtual interrupts mapped to a physical interrupt.
We can safely remove this notion, leaving all physical IRQ handling to be done in the device driver (the arch timer in this case), which makes room for a saner API for the new VGIC.
---
Changelog v1 .. v2:
- update kerneldoc comments on kvm_vgic_map_phys_irq()
Changelog v2 .. v3:
- include <linux/irq.h>
include/kvm/arm_vgic.h | 3 +-- virt/kvm/arm/arch_timer.c | 23 +++++++++++++++++++++-- virt/kvm/arm/vgic.c | 28 ++++++---------------------- 3 files changed, 28 insertions(+), 26 deletions(-)
include/kvm/arm_vgic.h +1 -2
@@ -157,7 +157,6 @@ struct vgic_io_device {struct irq_phys_map {u32 virt_irq;u32 phys_irq; -u32 irq; };struct irq_phys_map_entry {
@@ -345,7 +344,7 @@ int kvm_vgic_inject_mapped_irq(struct kvm *kvm, int cpuid,void vgic_v3_dispatch_sgi (struct kvm_vcpu *vcpu,u64 reg);int kvm_vgic_vcpu_pending_irq (struct kvm_vcpu *vcpu);struct irq_phys_map *kvm_vgic_map_phys_irq (struct kvm_vcpu *vcpu, -int virt_irq,int irq); +int virt_irq,int 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);
virt/kvm/arm/arch_timer.c +21 -2
@@ -21,6 +21,7 @@#include <linux/kvm.h> #include <linux/kvm_host.h> #include <linux/interrupt.h> +#include <linux/irq.h> #include <clocksource/arm_arch_timer.h> #include <asm/arch_timer.h>
@@ -301,7 +302,7 @@ void kvm_timer_flush_hwstate(struct kvm_vcpu *vcpu)if (timer->active_cleared_last && !phys_active)return ; - ret =irq_set_irqchip_state (timer->map->irq, + ret =irq_set_irqchip_state (host_vtimer_irq,IRQCHIP_STATE_ACTIVE , phys_active);WARN_ON (ret);
@@ -334,6 +335,9 @@ int kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu, {struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu;struct irq_phys_map *map; +struct irq_desc *desc; +struct irq_data *data; +int phys_irq;/* * The vcpu timer irq number cannot be determined in
@@ -353,10 +357,25 @@ int kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu,kvm_timer_update_state (vcpu);/* +* Find the physical IRQ number corresponding to the host_vtimer_irq +*/ + desc =irq_to_desc (host_vtimer_irq); +if (!desc) { +kvm_err ("%s: no interrupt descriptor\n" , __func__); +return -EINVAL ; + } + + data =irq_desc_get_irq_data (desc); +while (data->parent_data) + data = data->parent_data; + + phys_irq = data->hwirq; + +/* * Tell the VGIC that the virtual interrupt is tied to a * physical interrupt. We do that once per VCPU. */ - map =kvm_vgic_map_phys_irq (vcpu, irq->irq, host_vtimer_irq); + map =kvm_vgic_map_phys_irq (vcpu, irq->irq, phys_irq);if (WARN_ON (IS_ERR (map)))return PTR_ERR (map);
virt/kvm/arm/vgic.c +6 -22
@@ -1712,38 +1712,24 @@ static struct list_head *vgic_get_irq_phys_map_list(struct kvm_vcpu *vcpu,/** * kvm_vgic_map_phys_irq - map a virtual IRQ to a physical IRQ * @vcpu: The VCPU pointer -* @virt_irq: The virtual irq number -* @irq: The Linux IRQ number +* @virt_irq: The virtual IRQ number for the guest +* @phys_irq: The hardware IRQ number of the host * * Establish a mapping between a guest visible irq (@virt_irq) and a -* Linux irq (@irq). On injection, @virt_irq will be associated with -* the physical interrupt represented by @irq. This mapping can be +* hardware irq (@phys_irq). On injection, @virt_irq will be associated with +* the physical interrupt represented by @phys_irq. This mapping can be * established multiple times as long as the parameters are the same. * * Returns a valid pointer on success, and an error pointer otherwise */ struct irq_phys_map *kvm_vgic_map_phys_irq (struct kvm_vcpu *vcpu, -int virt_irq,int irq) +int virt_irq,int phys_irq) {struct vgic_dist *dist = &vcpu->kvm->arch.vgic;struct list_head *root =vgic_get_irq_phys_map_list (vcpu, virt_irq);struct irq_phys_map *map;struct irq_phys_map_entry *entry; -struct irq_desc *desc; -struct irq_data *data; -int phys_irq; - desc =irq_to_desc (irq); -if (!desc) { -kvm_err ("%s: no interrupt descriptor\n" , __func__); -return ERR_PTR (-EINVAL ); - } - - data =irq_desc_get_irq_data (desc); -while (data->parent_data) - data = data->parent_data; - - phys_irq = data->hwirq;/* Create a new mapping */ entry =kzalloc (sizeof (*entry),GFP_KERNEL );
@@ -1756,8 +1742,7 @@ struct irq_phys_map *kvm_vgic_map_phys_irq(struct kvm_vcpu *vcpu, map =vgic_irq_map_search (vcpu, virt_irq);if (map) {/* Make sure this mapping matches */ -if (map->phys_irq != phys_irq || - map->irq != irq) +if (map->phys_irq != phys_irq) map =ERR_PTR (-EINVAL );/* Found an existing, valid mapping */
@@ -1767,7 +1752,6 @@ struct irq_phys_map *kvm_vgic_map_phys_irq(struct kvm_vcpu *vcpu, map = &entry->map; map->virt_irq = virt_irq; map->phys_irq = phys_irq; - map->irq = irq;list_add_tail_rcu (&entry->entry, root);
Signature · 1 line
2.7.3
PATCH v3 6/55 KVM: arm/arm64: arch_timer: Remove irq_phys_map
In reply to Andre PrzywaraNow that the interface between the arch timer and the VGIC does not require passing the irq_phys_map entry pointer anymore, let's remove it from the virtual arch timer and use the virtual IRQ number instead directly.
The remaining pointer returned by kvm_vgic_map_phys_irq() will be removed in the following patch.
---
Changelog v1 .. v2:
- remove extra virt_irq member from struct, instead use irq.irq directly
Changelog v2 .. v3:
- remove bogus validity check from kvm_vgic_unmap_phys_irq()
include/kvm/arm_arch_timer.h | 3 --- virt/kvm/arm/arch_timer.c | 10 ++++------ 2 files changed, 4 insertions(+), 9 deletions(-)
include/kvm/arm_arch_timer.h +0 -3
@@ -53,9 +53,6 @@ struct arch_timer_cpu {/* Timer IRQ */ struct kvm_irq_level irq; -/* VGIC mapping */ -struct irq_phys_map *map; -/* Active IRQ state caching */ bool active_cleared_last; };
virt/kvm/arm/arch_timer.c +4 -6
@@ -176,10 +176,10 @@ static void kvm_timer_update_irq(struct kvm_vcpu *vcpu, bool new_level) timer->active_cleared_last = false; timer->irq.level = new_level; -trace_kvm_timer_update_irq (vcpu->vcpu_id, timer->map->virt_irq, +trace_kvm_timer_update_irq (vcpu->vcpu_id, timer->irq.irq, timer->irq.level); ret =kvm_vgic_inject_mapped_irq (vcpu->kvm, vcpu->vcpu_id, - timer->map->virt_irq, + timer->irq.irq, timer->irq.level);WARN_ON (ret); }
@@ -277,7 +277,7 @@ void kvm_timer_flush_hwstate(struct kvm_vcpu *vcpu)* exit. */ phys_active = timer->irq.level || -kvm_vgic_map_is_active (vcpu, timer->map->virt_irq); +kvm_vgic_map_is_active (vcpu, timer->irq.irq);/* * We want to avoid hitting the (re)distributor as much as
@@ -379,7 +379,6 @@ int kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu,if (WARN_ON (IS_ERR (map)))return PTR_ERR (map); - timer->map = map;return 0 ; }
@@ -522,8 +521,7 @@ void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu)struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu;timer_disarm (timer); -if (timer->map) -kvm_vgic_unmap_phys_irq (vcpu, timer->map->virt_irq); +kvm_vgic_unmap_phys_irq (vcpu, timer->irq.irq); }void kvm_timer_enable (struct kvm *kvm)
Signature · 1 line
2.7.3
Re: [PATCH v3 06/55] KVM: arm/arm64: arch_timer: Remove irq_phys_map
Hi Andre,
Quoted 68 lines · Andre Przywara
Now that the interface between the arch timer and the VGIC does not require passing the
irq_phys_mapentry pointer anymore, let's remove it from the virtual arch timer and use the virtual IRQ number instead directly.
The remaining pointer returned bykvm_vgic_map_phys_irq()will be removed in the following patch.Signed-off-by Andre Przywara <[email protected]>---
Changelog v1 .. v2:
- remove extravirt_irqmember from struct, instead use irq.irq directlyChangelog v2 .. v3:
- remove bogus validity check fromkvm_vgic_unmap_phys_irq()include/kvm/arm_arch_timer.h | 3 --- virt/kvm/arm/arch_timer.c | 10 ++++------ 2 files changed, 4 insertions(+), 9 deletions(-)include/kvm/arm_arch_timer.h +0
-3@@ -53,9 +53,6 @@ struct arch_timer_cpu {/* Timer IRQ */ struct kvm_irq_level irq; -/* VGIC mapping */ -struct irq_phys_map *map; -/* Active IRQ state caching */ bool active_cleared_last; };virt/kvm/arm/arch_timer.c +3
-4@@ -176,10 +176,10 @@ static void kvm_timer_update_irq(struct kvm_vcpu *vcpu, bool new_level) timer->active_cleared_last = false; timer->irq.level = new_level; -trace_kvm_timer_update_irq (vcpu->vcpu_id, timer->map->virt_irq, +trace_kvm_timer_update_irq (vcpu->vcpu_id, timer->irq.irq, timer->irq.level); ret =kvm_vgic_inject_mapped_irq (vcpu->kvm, vcpu->vcpu_id, - timer->map->virt_irq, + timer->irq.irq, timer->irq.level);WARN_ON (ret); }@@ -277,7 +277,7 @@ void kvm_timer_flush_hwstate(struct kvm_vcpu *vcpu)* exit. */ phys_active = timer->irq.level || -kvm_vgic_map_is_active (vcpu, timer->map->virt_irq); +kvm_vgic_map_is_active (vcpu, timer->irq.irq);/* * We want to avoid hitting the (re)distributor as much as @@ -379,7 +379,6 @@ int kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu,if (WARN_ON (IS_ERR (map)))return PTR_ERR (map); - timer->map = map;return 0 ; }
virt/kvm/arm/arch_timer.c void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu) · line 524
Quoted 6 lines
virt/kvm/arm/arch_timer.c +1
-2@@ -522,8 +521,7 @@ void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu)struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu;timer_disarm (timer); -if (timer->map) -kvm_vgic_unmap_phys_irq (vcpu, timer->map->virt_irq); +kvm_vgic_unmap_phys_irq (vcpu, timer->irq.irq);
Eric
Quoted 4 lines
virt/kvm/arm/arch_timer.c +0
-0}void kvm_timer_enable (struct kvm *kvm)
PATCH v3 7/55 KVM: arm/arm64: vgic: Remove irq_phys_map from interface
In reply to Andre PrzywaraNow that the virtual arch timer does not care about the irq_phys_map anymore, let's rework kvm_vgic_map_phys_irq() to return an error value instead. Any reference to that mapping can later be done by passing the correct combination of VCPU and virtual IRQ number. This makes the irq_phys_map handling completely private to the VGIC code.
---
Changelog v1 .. v2:
- adaptations to changes in previous patches (removal of virt_irq)
Changelog v2 .. v3:
- simplify return in kvm_timer_vcpu_reset()
include/kvm/arm_vgic.h | 3 +-- virt/kvm/arm/arch_timer.c | 7 +------ virt/kvm/arm/vgic.c | 15 +++++++-------- 3 files changed, 9 insertions(+), 16 deletions(-)
include/kvm/arm_vgic.h +1 -2
@@ -343,8 +343,7 @@ int kvm_vgic_inject_mapped_irq(struct kvm *kvm, int cpuid, unsigned int virt_irq, bool level);void vgic_v3_dispatch_sgi (struct kvm_vcpu *vcpu,u64 reg);int kvm_vgic_vcpu_pending_irq (struct kvm_vcpu *vcpu); -struct irq_phys_map *kvm_vgic_map_phys_irq (struct kvm_vcpu *vcpu, -int virt_irq,int phys_irq); +int kvm_vgic_map_phys_irq (struct kvm_vcpu *vcpu,int virt_irq,int 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);
virt/kvm/arm/arch_timer.c +1 -6
@@ -334,7 +334,6 @@ int kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu, const struct kvm_irq_level *irq) {struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu; -struct irq_phys_map *map;struct irq_desc *desc;struct irq_data *data;int phys_irq;
@@ -375,11 +374,7 @@ int kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu,* Tell the VGIC that the virtual interrupt is tied to a * physical interrupt. We do that once per VCPU. */ - map =kvm_vgic_map_phys_irq (vcpu, irq->irq, phys_irq); -if (WARN_ON (IS_ERR (map))) -return PTR_ERR (map); - -return 0 ; +return kvm_vgic_map_phys_irq (vcpu, irq->irq, phys_irq); }void kvm_timer_vcpu_init (struct kvm_vcpu *vcpu)
virt/kvm/arm/vgic.c +7 -8
@@ -1720,21 +1720,20 @@ static struct list_head *vgic_get_irq_phys_map_list(struct kvm_vcpu *vcpu,* the physical interrupt represented by @phys_irq. This mapping can be * established multiple times as long as the parameters are the same. * -* Returns a valid pointer on success, and an error pointer otherwise +* Returns 0 on success or an error value otherwise. */ -struct irq_phys_map *kvm_vgic_map_phys_irq (struct kvm_vcpu *vcpu, -int virt_irq,int phys_irq) +int kvm_vgic_map_phys_irq (struct kvm_vcpu *vcpu,int virt_irq,int phys_irq) {struct vgic_dist *dist = &vcpu->kvm->arch.vgic;struct list_head *root =vgic_get_irq_phys_map_list (vcpu, virt_irq);struct irq_phys_map *map;struct irq_phys_map_entry *entry; - +int ret =0 ;/* Create a new mapping */ entry =kzalloc (sizeof (*entry),GFP_KERNEL );if (!entry) -return ERR_PTR (-ENOMEM ); +return -ENOMEM ;spin_lock (&dist->irq_phys_map_lock);
@@ -1743,7 +1742,7 @@ struct irq_phys_map *kvm_vgic_map_phys_irq(struct kvm_vcpu *vcpu,if (map) {/* Make sure this mapping matches */ if (map->phys_irq != phys_irq) - map =ERR_PTR (-EINVAL ); + ret = -EINVAL ;/* Found an existing, valid mapping */ goto out;
@@ -1759,9 +1758,9 @@ out:spin_unlock (&dist->irq_phys_map_lock);/* If we've found a hit in the existing list, free the useless * entry */ -if (IS_ERR (map) || map != &entry->map) +if (ret || map != &entry->map)kfree (entry); -return map; +return ret; } static struct irq_phys_map *vgic_irq_map_search(struct kvm_vcpu *vcpu,
Signature · 1 line
2.7.3
PATCH v3 8/55 KVM: arm/arm64: Get rid of vgic_cpu->nr_lr
In reply to Andre PrzywaraFrom: 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
Re: [PATCH v3 08/55] KVM: arm/arm64: Get rid of vgic_cpu->nr_lr
Quoted 11 lines · Andre Przywara
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.
Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Andre Przywara <[email protected]>
Thanks,
Andre.
PATCH v3 9/55 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
Re: [PATCH v3 09/55] KVM: arm/arm64: Fix MMIO emulation data handling
Quoted 13 lines · Andre Przywara
From: 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->mmiostructure in order for thekvm_handle_mmio_return()function to pick it up and inject the
result back into the guest.Currently the only user of
kvm_io_busfor 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.
Quoted 8 lines
Update the
kvm_handle_mmio_returndescription and cleanup the code to only perform a single copying when needed.Code and commit message inspired by Andre Przywara.
Reported-by Andre Przywara <[email protected]>Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Andre Przywara <[email protected]>
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH v3 09/55] KVM: arm/arm64: Fix MMIO emulation data handling
In reply to Andre PrzywaraQuoted 13 lines · Andre Przywara
From: 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->mmiostructure in order for thekvm_handle_mmio_return()function to pick it up and inject the
result back into the guest.Currently the only user of
kvm_io_busfor 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.
Quoted 8 lines
Update the
kvm_handle_mmio_returndescription and cleanup the code to only perform a single copying when needed.Code and commit message inspired by Andre Przywara.
Reported-by Andre Przywara <[email protected]>Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Andre Przywara <[email protected]>
Thanks,
Andre.
PATCH v3 10/55 KVM: arm/arm64: Export mmio_read/write_bus
In reply to Andre PrzywaraFrom: Christoffer Dall <[email protected]>
Rename mmio_{read,write}_bus to kvm_mmio_{read,write}_bus and export them out of mmio.c.
This will be needed later for the new VGIC implementation.
--- arch/arm/include/asm/kvm_mmio.h | 3 +++ arch/arm/kvm/mmio.c | 10 +++++----- arch/arm64/include/asm/kvm_mmio.h | 3 +++ 3 files changed, 11 insertions(+), 5 deletions(-)
arch/arm/include/asm/kvm_mmio.h +3 -0
@@ -28,6 +28,9 @@ struct kvm_decode {bool sign_extend; }; +void kvm_mmio_write_buf (void *buf,unsigned int len,unsigned long data); +unsigned long kvm_mmio_read_buf (const void *buf,unsigned int len); +int kvm_handle_mmio_return (struct kvm_vcpu *vcpu,struct kvm_run *run);int io_mem_abort (struct kvm_vcpu *vcpu,struct kvm_run *run,phys_addr_t fault_ipa);
arch/arm/kvm/mmio.c +5 -5
@@ -23,7 +23,7 @@#include "trace.h" -static void mmio_write_buf (char *buf,unsigned int len,unsigned long data) +void kvm_mmio_write_buf (void *buf,unsigned int len,unsigned long data) {void *datap =NULL ;union {
@@ -55,7 +55,7 @@ static void mmio_write_buf(char *buf, unsigned int len, unsigned long data)memcpy (buf, datap, len); } -static unsigned long mmio_read_buf (char *buf,unsigned int len) +unsigned long kvm_mmio_read_buf (const void *buf,unsigned int len) {unsigned long data =0 ;union {
@@ -66,7 +66,7 @@ static unsigned long mmio_read_buf(char *buf, unsigned int len)switch (len) {case 1 : - data = buf[0 ]; + data = *(u8 *)buf;break ;case 2 :memcpy (&tmp.hword, buf, len);
@@ -103,7 +103,7 @@ int kvm_handle_mmio_return(struct kvm_vcpu *vcpu, struct kvm_run *run)if (len >sizeof (unsigned long ))return -EINVAL ; - data =mmio_read_buf (run->mmio.data, len); + data =kvm_mmio_read_buf (run->mmio.data, len);if (vcpu->arch.mmio_decode.sign_extend && len <sizeof (unsigned long )) {
@@ -189,7 +189,7 @@ int io_mem_abort(struct kvm_vcpu *vcpu, struct kvm_run *run, len);trace_kvm_mmio (KVM_TRACE_MMIO_WRITE , len, fault_ipa, data); -mmio_write_buf (data_buf, len, data); +kvm_mmio_write_buf (data_buf, len, data); ret =kvm_io_bus_write (vcpu,KVM_MMIO_BUS , fault_ipa, len, data_buf);
arch/arm64/include/asm/kvm_mmio.h +3 -0
@@ -30,6 +30,9 @@ struct kvm_decode {bool sign_extend; }; +void kvm_mmio_write_buf (void *buf,unsigned int len,unsigned long data); +unsigned long kvm_mmio_read_buf (const void *buf,unsigned int len); +int kvm_handle_mmio_return (struct kvm_vcpu *vcpu,struct kvm_run *run);int io_mem_abort (struct kvm_vcpu *vcpu,struct kvm_run *run,phys_addr_t fault_ipa);
Signature · 1 line
2.7.3
Re: [PATCH v3 10/55] KVM: arm/arm64: Export mmio_read/write_bus
Quoted 8 lines · Andre Przywara
From: Christoffer Dall <[email protected]>
Rename mmio_{read,write}_bus to kvm_mmio_{read,write}_bus and export them out of
mmio.c.
This will be needed later for the new VGIC implementation.Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Andre Przywara <[email protected]>
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH v3 10/55] KVM: arm/arm64: Export mmio_read/write_bus
In reply to Andre PrzywaraQuoted 8 lines · Andre Przywara
From: Christoffer Dall <[email protected]>
Rename mmio_{read,write}_bus to kvm_mmio_{read,write}_bus and export them out of
mmio.c.
This will be needed later for the new VGIC implementation.Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Andre Przywara <[email protected]>
Thanks,
Andre.
Quoted 84 lines
--- arch/arm/include/asm/kvm_mmio.h | 3 +++ arch/arm/kvm/mmio.c | 10 +++++----- arch/arm64/include/asm/kvm_mmio.h | 3 +++ 3 files changed, 11 insertions(+), 5 deletions(-)arch/arm/include/asm/kvm_mmio.h +3
-0@@ -28,6 +28,9 @@ struct kvm_decode {bool sign_extend; }; +void kvm_mmio_write_buf (void *buf,unsigned int len,unsigned long data); +unsigned long kvm_mmio_read_buf (const void *buf,unsigned int len); +int kvm_handle_mmio_return (struct kvm_vcpu *vcpu,struct kvm_run *run);int io_mem_abort (struct kvm_vcpu *vcpu,struct kvm_run *run,phys_addr_t fault_ipa);arch/arm/kvm/mmio.c +5
-5@@ -23,7 +23,7 @@#include "trace.h" -static void mmio_write_buf (char *buf,unsigned int len,unsigned long data) +void kvm_mmio_write_buf (void *buf,unsigned int len,unsigned long data) {void *datap =NULL ;union {@@ -55,7 +55,7 @@ static void mmio_write_buf(char *buf, unsigned int len, unsigned long data)memcpy (buf, datap, len); } -static unsigned long mmio_read_buf (char *buf,unsigned int len) +unsigned long kvm_mmio_read_buf (const void *buf,unsigned int len) {unsigned long data =0 ;union {@@ -66,7 +66,7 @@ static unsigned long mmio_read_buf(char *buf, unsigned int len)switch (len) {case 1 : - data = buf[0 ]; + data = *(u8 *)buf;break ;case 2 :memcpy (&tmp.hword, buf, len);@@ -103,7 +103,7 @@ int kvm_handle_mmio_return(struct kvm_vcpu *vcpu, struct kvm_run *run)if (len >sizeof (unsigned long ))return -EINVAL ; - data =mmio_read_buf (run->mmio.data, len); + data =kvm_mmio_read_buf (run->mmio.data, len);if (vcpu->arch.mmio_decode.sign_extend && len <sizeof (unsigned long )) {@@ -189,7 +189,7 @@ int io_mem_abort(struct kvm_vcpu *vcpu, struct kvm_run *run, len);trace_kvm_mmio (KVM_TRACE_MMIO_WRITE , len, fault_ipa, data); -mmio_write_buf (data_buf, len, data); +kvm_mmio_write_buf (data_buf, len, data); ret =kvm_io_bus_write (vcpu,KVM_MMIO_BUS , fault_ipa, len, data_buf);arch/arm64/include/asm/kvm_mmio.h +3
-0@@ -30,6 +30,9 @@ struct kvm_decode {bool sign_extend; }; +void kvm_mmio_write_buf (void *buf,unsigned int len,unsigned long data); +unsigned long kvm_mmio_read_buf (const void *buf,unsigned int len); +int kvm_handle_mmio_return (struct kvm_vcpu *vcpu,struct kvm_run *run);int io_mem_abort (struct kvm_vcpu *vcpu,struct kvm_run *run,phys_addr_t fault_ipa);
PATCH v3 11/55 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
@@ -477,7 +477,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
Re: [PATCH v3 11/55] KVM: arm/arm64: pmu: abstract access to number of SPIs
Quoted 5 lines · Andre Przywara
Currently the PMU uses a member of the struct
vgic_distdirectly, which not only breaks abstraction, but will fail with the new VGIC. Abstract this access in the VGIC header file.Signed-off-by Andre Przywara <[email protected]>
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH v3 11/55] KVM: arm/arm64: pmu: abstract access to number of SPIs
In reply to Andre PrzywaraHi Andre,
Quoted 29 lines · Andre Przywara
Currently the PMU uses a member of the struct
vgic_distdirectly, which not only breaks abstraction, but will fail with the new VGIC. Abstract this access in the VGIC header file.Signed-off-by Andre Przywara <[email protected]>--- 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 +0
-0
virt/kvm/arm/pmu.c int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr) · line 483
Quoted 8 lines
virt/kvm/arm/pmu.c +1
-1@@ -477,7 +477,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 ;
in case this is a PPI it will now return an error, right? I don't think this is what we expect.
Cheers
Eric
Re: [PATCH v3 11/55] KVM: arm/arm64: pmu: abstract access to number of SPIs
Quoted 33 lines · Eric Auger
Hi Andre,
Quoted 31 lines · Andre Przywara
Currently the PMU uses a member of the struct
vgic_distdirectly, which not only breaks abstraction, but will fail with the new VGIC. Abstract this access in the VGIC header file.Signed-off-by Andre Przywara <[email protected]>--- 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 +0
-0@@ -477,7 +477,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. */
Quoted 8 lines
virt/kvm/arm/pmu.c int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr) · line 483
Quoted 6 lines
virt/kvm/arm/pmu.c +1
-1-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 ;in case this is a PPI it will now return an error, right? I don't think this is what we expect.
Ouch. Good catch. I missed the ! too...
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
PATCH 1/1 KVM: arm/arm64: pmu: abstract access to number of SPIs
In reply to Eric AugerCurrently 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.
---
Hi Eric, Marc,
as this if-statement was quite confusing (it wasn't even the negation that was wrong), I rewrote it a bit to be more readable. This one works now with PPIs (after fixing kvmtool).
Does that make sense?
Cheers,
Andre.
include/kvm/arm_vgic.h | 2 ++ virt/kvm/arm/pmu.c | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-)
include/kvm/arm_vgic.h +2 -0
@@ -351,6 +351,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 +11 -8
@@ -436,6 +436,11 @@ static int kvm_arm_pmu_v3_init(struct kvm_vcpu *vcpu)return 0 ; } +/* +* For one VM the interrupt type must be same for each vcpu. +* As a PPI, the interrupt number is the same for all vcpus, +* while as an SPI it must be a separate number per vcpu. +*/ static bool irq_is_valid (struct kvm *kvm,int irq,bool is_ppi) {int i;
@@ -457,6 +462,7 @@ static bool irq_is_valid(struct kvm *kvm, int irq, bool is_ppi)return true; } +#define irq_is_ppi (irq) ((irq) >= VGIC_NR_SGIS && (irq) < VGIC_NR_PRIVATE_IRQS)int kvm_arm_pmu_v3_set_attr (struct kvm_vcpu *vcpu,struct kvm_device_attr *attr) {
@@ -471,14 +477,11 @@ int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr)if (get_user (irq, uaddr))return -EFAULT ; -/* -* The PMU overflow interrupt could be a PPI or SPI, but for one -* VM the interrupt type must be same for each vcpu. As a PPI, -* 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 || - !irq_is_valid (vcpu->kvm, irq, irq <VGIC_NR_PRIVATE_IRQS )) +/* The PMU overflow interrupt can be a PPI or a valid SPI. */ +if (!(irq_is_ppi (irq) ||vgic_valid_spi (vcpu->kvm, irq))) +return -EINVAL ; + +if (!irq_is_valid (vcpu->kvm, irq, irq <VGIC_NR_PRIVATE_IRQS ))return -EINVAL ;if (kvm_arm_pmu_irq_initialized (vcpu))
Signature · 1 line
2.7.3
Re: [PATCH v3a] KVM: arm/arm64: pmu: abstract access to number of SPIs
Quoted 39 lines · Andre Przywara
Currently the PMU uses a member of the struct
vgic_distdirectly, which not only breaks abstraction, but will fail with the new VGIC. Abstract this access in the VGIC header file.Signed-off-by Andre Przywara <[email protected]>---
Hi Eric, Marc,as this if-statement was quite confusing (it wasn't even the negation that was wrong), I rewrote it a bit to be more readable. This one works now with PPIs (after fixing kvmtool).
Does that make sense?
Cheers,
Andre.include/kvm/arm_vgic.h | 2 ++ virt/kvm/arm/pmu.c | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-)include/kvm/arm_vgic.h +2
-0@@ -351,6 +351,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 +0
-0
virt/kvm/arm/pmu.c static int kvm_arm_pmu_v3_init(struct kvm_vcpu *vcpu) · line 444
Quoted 9 lines
virt/kvm/arm/pmu.c +5
-0@@ -436,6 +436,11 @@ static int kvm_arm_pmu_v3_init(struct kvm_vcpu *vcpu)return 0 ; } +/* +* For one VM the interrupt type must be same for each vcpu. +* As a PPI, the interrupt number is the same for all vcpus, +* while as an SPI it must be a separate number per vcpu. +*/ static bool irq_is_valid (struct kvm *kvm,int irq,bool is_ppi)
While at it, I'd change this function name to have 'pmu' in it. It's just a static function, but without pmu in it it looks a bit confusing now to check the irq is [a valid] spi or ppi number, and then to call the generically named 'irq_is_valid' on it as well.
Thanks,
drew
Quoted 37 lines
virt/kvm/arm/pmu.c +6
-8{int i;@@ -457,6 +462,7 @@ static bool irq_is_valid(struct kvm *kvm, int irq, bool is_ppi)return true; } +#define irq_is_ppi (irq) ((irq) >= VGIC_NR_SGIS && (irq) < VGIC_NR_PRIVATE_IRQS)int kvm_arm_pmu_v3_set_attr (struct kvm_vcpu *vcpu,struct kvm_device_attr *attr) {@@ -471,14 +477,11 @@ int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr)if (get_user (irq, uaddr))return -EFAULT ; -/* -* The PMU overflow interrupt could be a PPI or SPI, but for one -* VM the interrupt type must be same for each vcpu. As a PPI, -* 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 || - !irq_is_valid (vcpu->kvm, irq, irq <VGIC_NR_PRIVATE_IRQS )) +/* The PMU overflow interrupt can be a PPI or a valid SPI. */ +if (!(irq_is_ppi (irq) ||vgic_valid_spi (vcpu->kvm, irq))) +return -EINVAL ; + +if (!irq_is_valid (vcpu->kvm, irq, irq <VGIC_NR_PRIVATE_IRQS ))return -EINVAL ;if (kvm_arm_pmu_irq_initialized (vcpu))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 v3a] KVM: arm/arm64: pmu: abstract access to number of SPIs
Hi Drew,
Quoted 43 lines · Andrew Jones
Quoted 42 lines · Andre Przywara
Currently the PMU uses a member of the struct
vgic_distdirectly, which not only breaks abstraction, but will fail with the new VGIC. Abstract this access in the VGIC header file.Signed-off-by Andre Przywara <[email protected]>---
Hi Eric, Marc,as this if-statement was quite confusing (it wasn't even the negation that was wrong), I rewrote it a bit to be more readable. This one works now with PPIs (after fixing kvmtool).
Does that make sense?
Cheers,
Andre.include/kvm/arm_vgic.h | 2 ++ virt/kvm/arm/pmu.c | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-)include/kvm/arm_vgic.h +2
-0@@ -351,6 +351,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 +0
-0@@ -436,6 +436,11 @@ static int kvm_arm_pmu_v3_init(struct kvm_vcpu *vcpu)return 0 ; }
Quoted 11 lines
virt/kvm/arm/pmu.c static int kvm_arm_pmu_v3_init(struct kvm_vcpu *vcpu) · line 444
Quoted 6 lines
virt/kvm/arm/pmu.c +5
-0+/* +* For one VM the interrupt type must be same for each vcpu. +* As a PPI, the interrupt number is the same for all vcpus, +* while as an SPI it must be a separate number per vcpu. +*/ static bool irq_is_valid (struct kvm *kvm,int irq,bool is_ppi)While at it, I'd change this function name to have 'pmu' in it. It's just a static function, but without pmu in it it looks a bit confusing now to check the irq is [a valid] spi or ppi number, and then to call the generically named '
irq_is_valid' on it as well.
Yes, indeed. Did that in the new series.
Thanks!
Andre.
Re: [PATCH v3a] KVM: arm/arm64: pmu: abstract access to number of SPIs
In reply to Andre PrzywaraQuoted 51 lines · Andre Przywara
Currently the PMU uses a member of the struct
vgic_distdirectly, which not only breaks abstraction, but will fail with the new VGIC. Abstract this access in the VGIC header file.Signed-off-by Andre Przywara <[email protected]>---
Hi Eric, Marc,as this if-statement was quite confusing (it wasn't even the negation that was wrong), I rewrote it a bit to be more readable. This one works now with PPIs (after fixing kvmtool).
Does that make sense?
Cheers,
Andre.include/kvm/arm_vgic.h | 2 ++ virt/kvm/arm/pmu.c | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-)include/kvm/arm_vgic.h +2
-0@@ -351,6 +351,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 +5
-0@@ -436,6 +436,11 @@ static int kvm_arm_pmu_v3_init(struct kvm_vcpu *vcpu)return 0 ; } +/* +* For one VM the interrupt type must be same for each vcpu. +* As a PPI, the interrupt number is the same for all vcpus, +* while as an SPI it must be a separate number per vcpu. +*/ static bool irq_is_valid (struct kvm *kvm,int irq,bool is_ppi) {int i;
virt/kvm/arm/pmu.c static bool irq_is_valid(struct kvm *kvm, int irq, bool is_ppi) · line 465
Quoted 4 lines
virt/kvm/arm/pmu.c +1
-0@@ -457,6 +462,7 @@ static bool irq_is_valid(struct kvm *kvm, int irq, bool is_ppi)return true; } +#define irq_is_ppi (irq) ((irq) >= VGIC_NR_SGIS && (irq) < VGIC_NR_PRIVATE_IRQS)
You might as well move this to the VGIC code.
Quoted 10 lines
virt/kvm/arm/pmu.c +0
-3int kvm_arm_pmu_v3_set_attr (struct kvm_vcpu *vcpu,struct kvm_device_attr *attr) {@@ -471,14 +477,11 @@ int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr)if (get_user (irq, uaddr))return -EFAULT ; -/* -* The PMU overflow interrupt could be a PPI or SPI, but for one -* VM the interrupt type must be same for each vcpu. As a PPI,
virt/kvm/arm/pmu.c int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr) · line 484
Quoted 10 lines
virt/kvm/arm/pmu.c +5
-5-* 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 || - !irq_is_valid (vcpu->kvm, irq, irq <VGIC_NR_PRIVATE_IRQS )) +/* The PMU overflow interrupt can be a PPI or a valid SPI. */ +if (!(irq_is_ppi (irq) ||vgic_valid_spi (vcpu->kvm, irq))) +return -EINVAL ; + +if (!irq_is_valid (vcpu->kvm, irq, irq <VGIC_NR_PRIVATE_IRQS ))
Why do we need to pass this boolean as a parameter? You could rewrite irq_is_valid() to generate the is_ppi boolean by itself.
virt/kvm/arm/pmu.c int kvm_arm_pmu_v3_set_attr(struct kvm_vcpu *vcpu, struct kvm_device_attr *attr) · line 487
Quoted 4 lines
virt/kvm/arm/pmu.c +0
-0return -EINVAL ;if (kvm_arm_pmu_irq_initialized (vcpu))
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
PATCH v3 12/55 KVM: arm/arm64: move GICv2 emulation defines into arm-gic-v3.h
In reply to Andre PrzywaraAs (some) GICv3 hosts can emulate a GICv2, some GICv2 specific masks for the list register definition also apply to GICv3 LRs. At the moment we have those definitions in the KVM VGICv3 implementation, so let's move them into the GICv3 header file to have them automatically defined.
--- include/linux/irqchip/arm-gic-v3.h | 5 +++++ virt/kvm/arm/vgic-v3.c | 8 +------- 2 files changed, 6 insertions(+), 7 deletions(-)
include/linux/irqchip/arm-gic-v3.h +5 -0
@@ -276,6 +276,11 @@#define ICH_LR_PHYS_ID_SHIFT 32#define ICH_LR_PHYS_ID_MASK (0x3ffULL << ICH_LR_PHYS_ID_SHIFT) +/* These are for GICv2 emulation only */ +#define GICH_LR_VIRTUALID (0x3ffUL << 0) +#define GICH_LR_PHYSID_CPUID_SHIFT (10) +#define GICH_LR_PHYSID_CPUID (7UL << GICH_LR_PHYSID_CPUID_SHIFT) +#define ICH_MISR_EOI (1 << 0)#define ICH_MISR_U (1 << 1)
virt/kvm/arm/vgic-v3.c +1 -7
@@ -31,12 +31,6 @@#include <asm/kvm_asm.h> #include <asm/kvm_mmu.h> -/* These are for GICv2 emulation only */ -#define GICH_LR_VIRTUALID (0x3ffUL << 0) -#define GICH_LR_PHYSID_CPUID_SHIFT (10) -#define GICH_LR_PHYSID_CPUID (7UL << GICH_LR_PHYSID_CPUID_SHIFT) -#define ICH_LR_VIRTUALID_MASK (BIT_ULL(32) - 1) -static u32 ich_vtr_el2;static struct vgic_lr vgic_v3_get_lr (const struct kvm_vcpu *vcpu,int lr)
@@ -45,7 +39,7 @@ static struct vgic_lr vgic_v3_get_lr(const struct kvm_vcpu *vcpu, int lr)u64 val = vcpu->arch.vgic_cpu.vgic_v3.vgic_lr[lr];if (vcpu->kvm->arch.vgic.vgic_model ==KVM_DEV_TYPE_ARM_VGIC_V3 ) - lr_desc.irq = val &ICH_LR_VIRTUALID_MASK ; + lr_desc.irq = val &ICH_LR_VIRTUAL_ID_MASK ;else lr_desc.irq = val &GICH_LR_VIRTUALID ;
Signature · 1 line
2.7.3
Re: [PATCH v3 12/55] KVM: arm/arm64: move GICv2 emulation defines into arm-gic-v3.h
Quoted 7 lines · Andre Przywara
As (some) GICv3 hosts can emulate a GICv2, some GICv2 specific masks for the list register definition also apply to GICv3 LRs. At the moment we have those definitions in the KVM VGICv3 implementation, so let's move them into the GICv3 header file to have them automatically defined.
Signed-off-by Andre Przywara <[email protected]>
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
PATCH v3 13/55 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
Changes v1 .. v2:
- change data type of dist->enabled to bool
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
Re: [PATCH v3 13/55] KVM: arm/arm64: vgic-new: Add data structure definitions
Quoted 11 lines · Andre Przywara
From: 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_irqper 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.
Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Andre Przywara <[email protected]>
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH v3 13/55] KVM: arm/arm64: vgic-new: Add data structure definitions
In reply to Andre PrzywaraQuoted 97 lines · Andre Przywara
From: 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_irqper 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.
Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changes RFC .. v1:
- adapt to 4.6-rc (addinglive_lrsmember)
- elaborate onap_listusageChanges v1 .. v2:
- change data type ofdist->enabledto boolinclude/kvm/arm_vgic.h | 5 ++ include/kvm/vgic/vgic.h | 201 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 206 insertions(+) create mode 100644 include/kvm/vgic/vgic.hinclude/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 +46
-0@@ -0,0 +1,201 @@ +/* +* 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 __ASM_ARM_KVM_VGIC_VGIC_H +#define __ASM_ARM_KVM_VGIC_VGIC_H + +#include <linux/kernel.h> +#include <linux/kvm.h> +#include <linux/irqreturn.h> +#include <linux/spinlock.h> +#include <linux/types.h> +#include <kvm/iodev.h> + +#define VGIC_V3_MAX_CPUS 255 +#define VGIC_V2_MAX_CPUS 8 +#define VGIC_NR_IRQS_LEGACY 256 +#define VGIC_NR_SGIS 16 +#define VGIC_NR_PPIS 16 +#define VGIC_NR_PRIVATE_IRQS (VGIC_NR_SGIS + VGIC_NR_PPIS) +#define VGIC_MAX_PRIVATE (VGIC_NR_PRIVATE_IRQS - 1) +#define VGIC_MAX_SPI 1019 +#define VGIC_MAX_RESERVED 1023 +#define VGIC_MIN_LPI 8192 + +enum vgic_type { + VGIC_V2, /* Good ol' GICv2 */ + VGIC_V3, /* New fancy GICv3 */ +}; + +/* same for all guests, as depending only on the _host's_ GIC model */ +struct vgic_global { + /* type of the host GIC */ + enum vgic_type type; +
include/kvm/vgic/vgic.h line 56
Quoted 10 lines
include/kvm/vgic/vgic.h new file +10
-0+/* Physical address of vgic virtual cpu interface */ +phys_addr_t vcpu_base; + +/* virtual control interface mapping */ +void __iomem *vctrl_base; + +/* Number of implemented list registers */ +int nr_lr; + +/* Maintenance IRQ number */
nit: this is the physial INTID, right?
Quoted 17 lines
include/kvm/vgic/vgic.h new file +17
-0+unsigned int maint_irq; + +/* maximum number of VCPUs allowed (GICv2 limits us to 8) */ +int max_gic_vcpus; + +/* Only needed for the legacy KVM_CREATE_IRQCHIP */ +bool can_emulate_gicv2; +}; + +extern struct vgic_global kvm_vgic_global_state; + +#define VGIC_V2_MAX_LRS (1 << 6) +#define VGIC_V3_MAX_LRS 16 +#define VGIC_V3_LR_INDEX (lr) (VGIC_V3_MAX_LRS - 1 - lr) + +enum vgic_irq_config { +VGIC_CONFIG_EDGE =0 ,
include/kvm/vgic/vgic.h line 83
Quoted 10 lines
include/kvm/vgic/vgic.h new file +10
-0+VGIC_CONFIG_LEVEL +}; + +struct vgic_irq { +spinlock_t irq_lock;/* Protects the content of the struct */ +struct list_head ap_list; + +struct kvm_vcpu *vcpu;/* SGIs and PPIs: The VCPU +* SPIs and LPIs: The VCPU whose ap_list +* on which this is queued.
nit: s/on which this is queued/this is queued on/
include/kvm/vgic/vgic.h line 87
Quoted 4 lines
include/kvm/vgic/vgic.h new file +4
-0+*/ + +struct kvm_vcpu *target_vcpu;/* The VCPU that this interrupt should +* be send to, as a result of the
nit: s/send/sent/
Quoted 91 lines
include/kvm/vgic/vgic.h new file +91
-0+* targets reg (v2) or the +* affinity reg (v3). +*/ + +u32 intid;/* Guest visible INTID */ +bool pending; +bool line_level;/* Level only */ +bool soft_pending;/* Level only */ +bool active;/* not used for LPIs */ +bool enabled; +bool hw;/* Tied to HW IRQ */ +u32 hwintid;/* HW INTID number */ +union { +u8 targets;/* GICv2 target VCPUs mask */ +u32 mpidr;/* GICv3 target VCPU */ + }; +u8 source;/* GICv2 SGIs only */ +u8 priority; +enum vgic_irq_config config;/* Level or edge */ +}; + +struct vgic_dist { +bool in_kernel; +bool ready; + +/* vGIC model the kernel emulates for the guest (GICv2 or GICv3) */ +u32 vgic_model; + +int nr_spis; + +/* TODO: Consider moving to global state */ +/* Virtual control interface mapping */ +void __iomem *vctrl_base; + +/* base addresses in guest physical address space: */ +gpa_t vgic_dist_base;/* distributor */ +union { +/* either a GICv2 CPU interface */ +gpa_t vgic_cpu_base; +/* or a number of GICv3 redistributor regions */ +gpa_t vgic_redist_base; + }; + +/* distributor enabled */ +bool enabled; + +struct vgic_irq *spis; +}; + +struct vgic_v2_cpu_if { +u32 vgic_hcr; +u32 vgic_vmcr; +u32 vgic_misr;/* Saved only */ +u64 vgic_eisr;/* Saved only */ +u64 vgic_elrsr;/* Saved only */ +u32 vgic_apr; +u32 vgic_lr[VGIC_V2_MAX_LRS ]; +}; + +struct vgic_v3_cpu_if { +#ifdef CONFIG_KVM_ARM_VGIC_V3 +u32 vgic_hcr; +u32 vgic_vmcr; +u32 vgic_sre;/* Restored only, change ignored */ +u32 vgic_misr;/* Saved only */ +u32 vgic_eisr;/* Saved only */ +u32 vgic_elrsr;/* Saved only */ +u32 vgic_ap0r[4 ]; +u32 vgic_ap1r[4 ]; +u64 vgic_lr[VGIC_V3_MAX_LRS ]; +#endif +}; + +struct vgic_cpu { +/* CPU vif control registers for world switch */ +union { +struct vgic_v2_cpu_if vgic_v2; +struct vgic_v3_cpu_if vgic_v3; + }; + +unsigned int used_lrs; +struct vgic_irq private_irqs[VGIC_NR_PRIVATE_IRQS ]; + +spinlock_t ap_list_lock;/* Protects the ap_list */ + +/* +* List of IRQs that this VCPU should consider because they are either +* Active or Pending (hence the name; AP list), or because they recently +* were one of the two and need to be migrated off this list to another +* VCPU. +*/
include/kvm/vgic/vgic.h line 188
Quoted 10 lines
include/kvm/vgic/vgic.h new file +10
-0+struct list_head ap_list_head; + +u64 live_lrs; +}; + +#define irqchip_in_kernel (k) (!!((k)->arch.vgic.in_kernel)) +#define vgic_initialized (k) (false) +#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))
this should really be a static inline at this point.
Quoted 16 lines
include/kvm/vgic/vgic.h new file +13
-0+ +/** +* kvm_vgic_get_max_vcpus - Get the maximum number of VCPUs allowed by HW +* +* The host's GIC naturally limits the maximum amount of VCPUs a guest +* can use. +*/ +static inline int kvm_vgic_get_max_vcpus (void ) +{ +return kvm_vgic_global_state.max_gic_vcpus; +} + +#endif /* __ASM_ARM_KVM_VGIC_VGIC_H */ Signature · 1 line
2.7.3
Re: [PATCH v3 13/55] KVM: arm/arm64: vgic-new: Add data structure definitions
Quoted 111 lines · Christoffer Dall
Quoted 97 lines · Andre Przywara
From: 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_irqper 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.
Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changes RFC .. v1:
- adapt to 4.6-rc (addinglive_lrsmember)
- elaborate onap_listusageChanges v1 .. v2:
- change data type ofdist->enabledto boolinclude/kvm/arm_vgic.h | 5 ++ include/kvm/vgic/vgic.h | 201 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 206 insertions(+) create mode 100644 include/kvm/vgic/vgic.hinclude/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 +46
-0@@ -0,0 +1,201 @@ +/* +* 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 __ASM_ARM_KVM_VGIC_VGIC_H +#define __ASM_ARM_KVM_VGIC_VGIC_H + +#include <linux/kernel.h> +#include <linux/kvm.h> +#include <linux/irqreturn.h> +#include <linux/spinlock.h> +#include <linux/types.h> +#include <kvm/iodev.h> + +#define VGIC_V3_MAX_CPUS 255 +#define VGIC_V2_MAX_CPUS 8 +#define VGIC_NR_IRQS_LEGACY 256 +#define VGIC_NR_SGIS 16 +#define VGIC_NR_PPIS 16 +#define VGIC_NR_PRIVATE_IRQS (VGIC_NR_SGIS + VGIC_NR_PPIS) +#define VGIC_MAX_PRIVATE (VGIC_NR_PRIVATE_IRQS - 1) +#define VGIC_MAX_SPI 1019 +#define VGIC_MAX_RESERVED 1023 +#define VGIC_MIN_LPI 8192 + +enum vgic_type { + VGIC_V2, /* Good ol' GICv2 */ + VGIC_V3, /* New fancy GICv3 */ +}; + +/* same for all guests, as depending only on the _host's_ GIC model */ +struct vgic_global { + /* type of the host GIC */ + enum vgic_type type; +include/kvm/vgic/vgic.h line 56
Quoted 10 lines
include/kvm/vgic/vgic.h new file +10
-0+/* Physical address of vgic virtual cpu interface */ +phys_addr_t vcpu_base; + +/* virtual control interface mapping */ +void __iomem *vctrl_base; + +/* Number of implemented list registers */ +int nr_lr; + +/* Maintenance IRQ number */ nit: this is the physial INTID, right?
Quoted 1 line
include/kvm/vgic/vgic.h line 57
Quoted 1 line
include/kvm/vgic/vgic.h new file +1
-0+unsigned int maint_irq;
No, this is the actual Linux IRQ number.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH v3 13/55] KVM: arm/arm64: vgic-new: Add data structure definitions
Quoted 112 lines · Marc Zyngier
Quoted 111 lines · Christoffer Dall
Quoted 97 lines · Andre Przywara
From: 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_irqper 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.
Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changes RFC .. v1:
- adapt to 4.6-rc (addinglive_lrsmember)
- elaborate onap_listusageChanges v1 .. v2:
- change data type ofdist->enabledto boolinclude/kvm/arm_vgic.h | 5 ++ include/kvm/vgic/vgic.h | 201 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 206 insertions(+) create mode 100644 include/kvm/vgic/vgic.hinclude/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 +46
-0@@ -0,0 +1,201 @@ +/* +* 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 __ASM_ARM_KVM_VGIC_VGIC_H +#define __ASM_ARM_KVM_VGIC_VGIC_H + +#include <linux/kernel.h> +#include <linux/kvm.h> +#include <linux/irqreturn.h> +#include <linux/spinlock.h> +#include <linux/types.h> +#include <kvm/iodev.h> + +#define VGIC_V3_MAX_CPUS 255 +#define VGIC_V2_MAX_CPUS 8 +#define VGIC_NR_IRQS_LEGACY 256 +#define VGIC_NR_SGIS 16 +#define VGIC_NR_PPIS 16 +#define VGIC_NR_PRIVATE_IRQS (VGIC_NR_SGIS + VGIC_NR_PPIS) +#define VGIC_MAX_PRIVATE (VGIC_NR_PRIVATE_IRQS - 1) +#define VGIC_MAX_SPI 1019 +#define VGIC_MAX_RESERVED 1023 +#define VGIC_MIN_LPI 8192 + +enum vgic_type { + VGIC_V2, /* Good ol' GICv2 */ + VGIC_V3, /* New fancy GICv3 */ +}; + +/* same for all guests, as depending only on the _host's_ GIC model */ +struct vgic_global { + /* type of the host GIC */ + enum vgic_type type; +include/kvm/vgic/vgic.h line 56
Quoted 10 lines
include/kvm/vgic/vgic.h new file +10
-0+/* Physical address of vgic virtual cpu interface */ +phys_addr_t vcpu_base; + +/* virtual control interface mapping */ +void __iomem *vctrl_base; + +/* Number of implemented list registers */ +int nr_lr; + +/* Maintenance IRQ number */ nit: this is the physial INTID, right?
Quoted 4 lines
Quoted 1 line
include/kvm/vgic/vgic.h line 57
Quoted 1 line
include/kvm/vgic/vgic.h new file +1
-0+unsigned int maint_irq;No, this is the actual Linux IRQ number.
oh right, it's set by irq_of_parse_and_map.
My bad,
-Christoffer
Re: [PATCH v3 13/55] KVM: arm/arm64: vgic-new: Add data structure definitions
In reply to Christoffer DallHi,
Quoted 141 lines · Christoffer Dall
Quoted 97 lines · Andre Przywara
From: 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_irqper 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.
Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changes RFC .. v1:
- adapt to 4.6-rc (addinglive_lrsmember)
- elaborate onap_listusageChanges v1 .. v2:
- change data type ofdist->enabledto boolinclude/kvm/arm_vgic.h | 5 ++ include/kvm/vgic/vgic.h | 201 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 206 insertions(+) create mode 100644 include/kvm/vgic/vgic.hinclude/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 +46
-0@@ -0,0 +1,201 @@ +/* +* 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 __ASM_ARM_KVM_VGIC_VGIC_H +#define __ASM_ARM_KVM_VGIC_VGIC_H + +#include <linux/kernel.h> +#include <linux/kvm.h> +#include <linux/irqreturn.h> +#include <linux/spinlock.h> +#include <linux/types.h> +#include <kvm/iodev.h> + +#define VGIC_V3_MAX_CPUS 255 +#define VGIC_V2_MAX_CPUS 8 +#define VGIC_NR_IRQS_LEGACY 256 +#define VGIC_NR_SGIS 16 +#define VGIC_NR_PPIS 16 +#define VGIC_NR_PRIVATE_IRQS (VGIC_NR_SGIS + VGIC_NR_PPIS) +#define VGIC_MAX_PRIVATE (VGIC_NR_PRIVATE_IRQS - 1) +#define VGIC_MAX_SPI 1019 +#define VGIC_MAX_RESERVED 1023 +#define VGIC_MIN_LPI 8192 + +enum vgic_type { + VGIC_V2, /* Good ol' GICv2 */ + VGIC_V3, /* New fancy GICv3 */ +}; + +/* same for all guests, as depending only on the _host's_ GIC model */ +struct vgic_global { + /* type of the host GIC */ + enum vgic_type type; +include/kvm/vgic/vgic.h line 56
Quoted 10 lines
include/kvm/vgic/vgic.h new file +10
-0+/* Physical address of vgic virtual cpu interface */ +phys_addr_t vcpu_base; + +/* virtual control interface mapping */ +void __iomem *vctrl_base; + +/* Number of implemented list registers */ +int nr_lr; + +/* Maintenance IRQ number */ nit: this is the physial INTID, right?
Quoted 17 lines
include/kvm/vgic/vgic.h new file +17
-0+unsigned int maint_irq; + +/* maximum number of VCPUs allowed (GICv2 limits us to 8) */ +int max_gic_vcpus; + +/* Only needed for the legacy KVM_CREATE_IRQCHIP */ +bool can_emulate_gicv2; +}; + +extern struct vgic_global kvm_vgic_global_state; + +#define VGIC_V2_MAX_LRS (1 << 6) +#define VGIC_V3_MAX_LRS 16 +#define VGIC_V3_LR_INDEX (lr) (VGIC_V3_MAX_LRS - 1 - lr) + +enum vgic_irq_config { +VGIC_CONFIG_EDGE =0 ,include/kvm/vgic/vgic.h line 83
Quoted 10 lines
include/kvm/vgic/vgic.h new file +10
-0+VGIC_CONFIG_LEVEL +}; + +struct vgic_irq { +spinlock_t irq_lock;/* Protects the content of the struct */ +struct list_head ap_list; + +struct kvm_vcpu *vcpu;/* SGIs and PPIs: The VCPU +* SPIs and LPIs: The VCPU whose ap_list +* on which this is queued. nit: s/on which this is queued/this is queued on/
Quoted 6 lines
include/kvm/vgic/vgic.h line 87
Quoted 4 lines
include/kvm/vgic/vgic.h new file +4
-0+*/ + +struct kvm_vcpu *target_vcpu;/* The VCPU that this interrupt should +* be send to, as a result of the nit: s/send/sent/
Both fixed.
Quoted 95 lines
Quoted 95 lines
include/kvm/vgic/vgic.h new file +95
-0+* targets reg (v2) or the +* affinity reg (v3). +*/ + +u32 intid;/* Guest visible INTID */ +bool pending; +bool line_level;/* Level only */ +bool soft_pending;/* Level only */ +bool active;/* not used for LPIs */ +bool enabled; +bool hw;/* Tied to HW IRQ */ +u32 hwintid;/* HW INTID number */ +union { +u8 targets;/* GICv2 target VCPUs mask */ +u32 mpidr;/* GICv3 target VCPU */ + }; +u8 source;/* GICv2 SGIs only */ +u8 priority; +enum vgic_irq_config config;/* Level or edge */ +}; + +struct vgic_dist { +bool in_kernel; +bool ready; + +/* vGIC model the kernel emulates for the guest (GICv2 or GICv3) */ +u32 vgic_model; + +int nr_spis; + +/* TODO: Consider moving to global state */ +/* Virtual control interface mapping */ +void __iomem *vctrl_base; + +/* base addresses in guest physical address space: */ +gpa_t vgic_dist_base;/* distributor */ +union { +/* either a GICv2 CPU interface */ +gpa_t vgic_cpu_base; +/* or a number of GICv3 redistributor regions */ +gpa_t vgic_redist_base; + }; + +/* distributor enabled */ +bool enabled; + +struct vgic_irq *spis; +}; + +struct vgic_v2_cpu_if { +u32 vgic_hcr; +u32 vgic_vmcr; +u32 vgic_misr;/* Saved only */ +u64 vgic_eisr;/* Saved only */ +u64 vgic_elrsr;/* Saved only */ +u32 vgic_apr; +u32 vgic_lr[VGIC_V2_MAX_LRS ]; +}; + +struct vgic_v3_cpu_if { +#ifdef CONFIG_KVM_ARM_VGIC_V3 +u32 vgic_hcr; +u32 vgic_vmcr; +u32 vgic_sre;/* Restored only, change ignored */ +u32 vgic_misr;/* Saved only */ +u32 vgic_eisr;/* Saved only */ +u32 vgic_elrsr;/* Saved only */ +u32 vgic_ap0r[4 ]; +u32 vgic_ap1r[4 ]; +u64 vgic_lr[VGIC_V3_MAX_LRS ]; +#endif +}; + +struct vgic_cpu { +/* CPU vif control registers for world switch */ +union { +struct vgic_v2_cpu_if vgic_v2; +struct vgic_v3_cpu_if vgic_v3; + }; + +unsigned int used_lrs; +struct vgic_irq private_irqs[VGIC_NR_PRIVATE_IRQS ]; + +spinlock_t ap_list_lock;/* Protects the ap_list */ + +/* +* List of IRQs that this VCPU should consider because they are either +* Active or Pending (hence the name; AP list), or because they recently +* were one of the two and need to be migrated off this list to another +* VCPU. +*/ +struct list_head ap_list_head; + +u64 live_lrs; +};
Quoted 8 lines
include/kvm/vgic/vgic.h line 188
Quoted 6 lines
include/kvm/vgic/vgic.h new file +6
-0+ +#define irqchip_in_kernel (k) (!!((k)->arch.vgic.in_kernel)) +#define vgic_initialized (k) (false) +#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))this should really be a static inline at this point.
I think I tried this at the very beginning and it doesn't work. I get:
In file included from include/kvm/arm_vgic.h:23:0,
from arch/arm64/include/asm/kvm_host.h:39,
from include/linux/kvm_host.h:36,
from arch/arm64/kernel/asm-offsets.c:24:
include/kvm/vgic/vgic.h: In function 'vgic_valid_spi':
include/kvm/vgic/vgic.h:232:13: error: dereferencing pointer to
incomplete type 'struct kvm'
(irq < kvm->arch.vgic.nr_spis + VGIC_NR_PRIVATE_IRQS);
^./Kbuild:80: recipe for target 'arch/arm64/kernel/asm-offsets.s' failed make[3]: *** [arch/arm64/kernel/asm-offsets.s] Error 1
Is this because asm-offsets.s includes this file and struct kvm is opaque at this point?
Or is my brain totally GICed by now?
Cheers,
Andre.
Re: [PATCH v3 13/55] KVM: arm/arm64: vgic-new: Add data structure definitions
Quoted 268 lines · Andre Przywara
Hi,
Quoted 141 lines · Christoffer Dall
Quoted 97 lines · Andre Przywara
From: 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_irqper 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.
Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changes RFC .. v1:
- adapt to 4.6-rc (addinglive_lrsmember)
- elaborate onap_listusageChanges v1 .. v2:
- change data type ofdist->enabledto boolinclude/kvm/arm_vgic.h | 5 ++ include/kvm/vgic/vgic.h | 201 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 206 insertions(+) create mode 100644 include/kvm/vgic/vgic.hinclude/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 +46
-0@@ -0,0 +1,201 @@ +/* +* 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 __ASM_ARM_KVM_VGIC_VGIC_H +#define __ASM_ARM_KVM_VGIC_VGIC_H + +#include <linux/kernel.h> +#include <linux/kvm.h> +#include <linux/irqreturn.h> +#include <linux/spinlock.h> +#include <linux/types.h> +#include <kvm/iodev.h> + +#define VGIC_V3_MAX_CPUS 255 +#define VGIC_V2_MAX_CPUS 8 +#define VGIC_NR_IRQS_LEGACY 256 +#define VGIC_NR_SGIS 16 +#define VGIC_NR_PPIS 16 +#define VGIC_NR_PRIVATE_IRQS (VGIC_NR_SGIS + VGIC_NR_PPIS) +#define VGIC_MAX_PRIVATE (VGIC_NR_PRIVATE_IRQS - 1) +#define VGIC_MAX_SPI 1019 +#define VGIC_MAX_RESERVED 1023 +#define VGIC_MIN_LPI 8192 + +enum vgic_type { + VGIC_V2, /* Good ol' GICv2 */ + VGIC_V3, /* New fancy GICv3 */ +}; + +/* same for all guests, as depending only on the _host's_ GIC model */ +struct vgic_global { + /* type of the host GIC */ + enum vgic_type type; +include/kvm/vgic/vgic.h line 56
Quoted 10 lines
include/kvm/vgic/vgic.h new file +10
-0+/* Physical address of vgic virtual cpu interface */ +phys_addr_t vcpu_base; + +/* virtual control interface mapping */ +void __iomem *vctrl_base; + +/* Number of implemented list registers */ +int nr_lr; + +/* Maintenance IRQ number */ nit: this is the physial INTID, right?
Quoted 17 lines
include/kvm/vgic/vgic.h new file +17
-0+unsigned int maint_irq; + +/* maximum number of VCPUs allowed (GICv2 limits us to 8) */ +int max_gic_vcpus; + +/* Only needed for the legacy KVM_CREATE_IRQCHIP */ +bool can_emulate_gicv2; +}; + +extern struct vgic_global kvm_vgic_global_state; + +#define VGIC_V2_MAX_LRS (1 << 6) +#define VGIC_V3_MAX_LRS 16 +#define VGIC_V3_LR_INDEX (lr) (VGIC_V3_MAX_LRS - 1 - lr) + +enum vgic_irq_config { +VGIC_CONFIG_EDGE =0 ,include/kvm/vgic/vgic.h line 83
Quoted 10 lines
include/kvm/vgic/vgic.h new file +10
-0+VGIC_CONFIG_LEVEL +}; + +struct vgic_irq { +spinlock_t irq_lock;/* Protects the content of the struct */ +struct list_head ap_list; + +struct kvm_vcpu *vcpu;/* SGIs and PPIs: The VCPU +* SPIs and LPIs: The VCPU whose ap_list +* on which this is queued. nit: s/on which this is queued/this is queued on/
Quoted 6 lines
include/kvm/vgic/vgic.h line 87
Quoted 4 lines
include/kvm/vgic/vgic.h new file +4
-0+*/ + +struct kvm_vcpu *target_vcpu;/* The VCPU that this interrupt should +* be send to, as a result of the nit: s/send/sent/
Both fixed.
Quoted 95 lines
Quoted 95 lines
include/kvm/vgic/vgic.h new file +95
-0+* targets reg (v2) or the +* affinity reg (v3). +*/ + +u32 intid;/* Guest visible INTID */ +bool pending; +bool line_level;/* Level only */ +bool soft_pending;/* Level only */ +bool active;/* not used for LPIs */ +bool enabled; +bool hw;/* Tied to HW IRQ */ +u32 hwintid;/* HW INTID number */ +union { +u8 targets;/* GICv2 target VCPUs mask */ +u32 mpidr;/* GICv3 target VCPU */ + }; +u8 source;/* GICv2 SGIs only */ +u8 priority; +enum vgic_irq_config config;/* Level or edge */ +}; + +struct vgic_dist { +bool in_kernel; +bool ready; + +/* vGIC model the kernel emulates for the guest (GICv2 or GICv3) */ +u32 vgic_model; + +int nr_spis; + +/* TODO: Consider moving to global state */ +/* Virtual control interface mapping */ +void __iomem *vctrl_base; + +/* base addresses in guest physical address space: */ +gpa_t vgic_dist_base;/* distributor */ +union { +/* either a GICv2 CPU interface */ +gpa_t vgic_cpu_base; +/* or a number of GICv3 redistributor regions */ +gpa_t vgic_redist_base; + }; + +/* distributor enabled */ +bool enabled; + +struct vgic_irq *spis; +}; + +struct vgic_v2_cpu_if { +u32 vgic_hcr; +u32 vgic_vmcr; +u32 vgic_misr;/* Saved only */ +u64 vgic_eisr;/* Saved only */ +u64 vgic_elrsr;/* Saved only */ +u32 vgic_apr; +u32 vgic_lr[VGIC_V2_MAX_LRS ]; +}; + +struct vgic_v3_cpu_if { +#ifdef CONFIG_KVM_ARM_VGIC_V3 +u32 vgic_hcr; +u32 vgic_vmcr; +u32 vgic_sre;/* Restored only, change ignored */ +u32 vgic_misr;/* Saved only */ +u32 vgic_eisr;/* Saved only */ +u32 vgic_elrsr;/* Saved only */ +u32 vgic_ap0r[4 ]; +u32 vgic_ap1r[4 ]; +u64 vgic_lr[VGIC_V3_MAX_LRS ]; +#endif +}; + +struct vgic_cpu { +/* CPU vif control registers for world switch */ +union { +struct vgic_v2_cpu_if vgic_v2; +struct vgic_v3_cpu_if vgic_v3; + }; + +unsigned int used_lrs; +struct vgic_irq private_irqs[VGIC_NR_PRIVATE_IRQS ]; + +spinlock_t ap_list_lock;/* Protects the ap_list */ + +/* +* List of IRQs that this VCPU should consider because they are either +* Active or Pending (hence the name; AP list), or because they recently +* were one of the two and need to be migrated off this list to another +* VCPU. +*/ +struct list_head ap_list_head; + +u64 live_lrs; +};Quoted 8 lines
include/kvm/vgic/vgic.h line 188
Quoted 6 lines
include/kvm/vgic/vgic.h new file +6
-0+ +#define irqchip_in_kernel (k) (!!((k)->arch.vgic.in_kernel)) +#define vgic_initialized (k) (false) +#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))this should really be a static inline at this point.
I think I tried this at the very beginning and it doesn't work. I get:
In file included from
include/kvm/arm_vgic.h:23:0,from arch/arm64/include/asm/kvm_host.h:39, from include/linux/kvm_host.h:36, from arch/arm64/kernel/asm-offsets.c:24: include/kvm/vgic/vgic.h: In function 'vgic_valid_spi': include/kvm/vgic/vgic.h:232:13: error: dereferencing pointer to incomplete type 'struct kvm' (irq < kvm->arch.vgic.nr_spis + VGIC_NR_PRIVATE_IRQS); ^
Quoted 5 lines
./Kbuild:80: recipe for target '
arch/arm64/kernel/asm-offsets.s' failed make[3]: *** [arch/arm64/kernel/asm-offsets.s] Error 1Is this because asm-offsets.s includes this file and struct kvm is opaque at this point?
Probably, but in this case, never mind, we can rework that another time.
Quoted 2 lines
Or is my brain totally GICed by now?
Haha, I definitely feel GICed!
-Christoffer
PATCH v3 14/55 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 v3 14/55] KVM: arm/arm64: vgic-new: Add acccessor to new struct vgic_irq instance
Quoted 34 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 +12
-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. +*
virt/kvm/arm/vgic/vgic.c line 22
Quoted 10 lines
virt/kvm/arm/vgic/vgic.c new file +10
-0+* 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;
nit: this structure isn't referenced anywhere yet.
Quoted 38 lines
virt/kvm/arm/vgic/vgic.c new file +19
-0+ +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 +12
-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. +*
virt/kvm/arm/vgic/vgic.h line 22
Quoted 10 lines
virt/kvm/arm/vgic/vgic.h new file +10
-0+* 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
Otherwise:
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH v3 14/55] KVM: arm/arm64: vgic-new: Add acccessor to new struct vgic_irq instance
Hi,
Quoted 39 lines · Marc Zyngier
Quoted 38 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 +16
-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/>. +*/ +
Quoted 8 lines
virt/kvm/arm/vgic/vgic.c line 22
Quoted 6 lines
virt/kvm/arm/vgic/vgic.c new file +6
-0+#include <linux/kvm.h> +#include <linux/kvm_host.h> + +#include "vgic.h" + +struct vgic_global __section(.hyp.text) kvm_vgic_global_state;nit: this structure isn't referenced anywhere yet.
I see it actually been used in the previous patch, but we only introduce the header file here. This is one example of why we decided to not enable compilation early. If you don't mind, I keep it in here.
Thanks for the ACK.
Cheers,
Andre.
Quoted 55 lines
Quoted 38 lines
virt/kvm/arm/vgic/vgic.c new file +19
-0+ +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 +12
-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. +* virt/kvm/arm/vgic/vgic.h line 22
Quoted 10 lines
virt/kvm/arm/vgic/vgic.h new file +10
-0+* 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 Otherwise:
Acked-by Marc Zyngier <[email protected]>M.
Re: [PATCH v3 14/55] KVM: arm/arm64: vgic-new: Add acccessor to new struct vgic_irq instance
In reply to Andre PrzywaraQuoted 82 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 +12
-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. +*
virt/kvm/arm/vgic/vgic.h line 22
Quoted 10 lines
virt/kvm/arm/vgic/vgic.h new file +10
-0+* 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
Eric
PATCH v3 15/55 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
Changelog v1 .. v2:
- move most IRQ injection code into vgic_update_irq_pending()
include/kvm/vgic/vgic.h | 3 + virt/kvm/arm/vgic/vgic.c | 209 +++++++++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.h | 1 + 3 files changed, 213 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 +209 -0
220 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
Re: [PATCH v3 15/55] KVM: arm/arm64: vgic-new: Implement virtual IRQ injection
Hi,
Quoted 3 lines · Andre Przywara
From: Christoffer Dall <[email protected]>
Provide a
vgic_queue_irq()function which decides whether a given
nit: now called vgic_queue_irq_unlock
Quoted 174 lines
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()]Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- add spinlock checks protected byCONFIG_DEBUG_SPINLOCK
- add more comments tovgic_target_oracle
- removeBUG_ON()if IRQ is neither edge or level
- renamevgic_queue_irq()tovgic_queue_irq_unlock()
- simplify initial check invgic_queue_irq_unlock()
- extend retry loop to ask the oracle again
- minor comment fixesChangelog v1 .. v2:
- move most IRQ injection code intovgic_update_irq_pending()include/kvm/vgic/vgic.h | 3 + virt/kvm/arm/vgic/vgic.c | 209 +++++++++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.h | 1 + 3 files changed, 213 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 +110
-0@@ -19,8 +19,31 @@#include "vgic.h" +#define CREATE_TRACE_POINTS +#include "../trace.h" + +#ifdef CONFIG_DEBUG_SPINLOCK +#define DEBUG_SPINLOCK_BUG_ON (p) BUG_ON(p) +#else +#define DEBUG_SPINLOCK_BUG_ON (p) +#endif + struct vgic_global __section(.hyp.text) kvm_vgic_global_state; +/* +* Locking order is always: +* vgic_cpu->ap_list_lock +* vgic_irq->irq_lock +* +* (that is, always take the ap_list_lock before the struct vgic_irq lock). +* +* When taking more than one ap_list_lock at the same time, always take the +* lowest numbered VCPU's ap_list_lock first, so: +* vcpuX->vcpu_id < vcpuY->vcpu_id: +* spin_lock(vcpuX->arch.vgic_cpu.ap_list_lock); +* spin_lock(vcpuY->arch.vgic_cpu.ap_list_lock); +*/ +struct vgic_irq *vgic_get_irq (struct kvm *kvm,struct kvm_vcpu *vcpu,u32 intid) {@@ -39,3 +62,189 @@ struct vgic_irq *vgic_get_irq(struct kvm *kvm, struct kvm_vcpu *vcpu,WARN (1 ,"Looking up struct vgic_irq for reserved INTID" );return NULL ; } + +/** +* kvm_vgic_target_oracle - compute the target vcpu for an irq +* +* @irq: The irq to route. Must be already locked. +* +* Based on the current state of the interrupt (enabled, pending, +* active, vcpu and target_vcpu), compute the next vcpu this should be +* given to. Return NULL if this shouldn't be injected at all. +* +* Requires the IRQ lock to be held. +*/ +static struct kvm_vcpu *vgic_target_oracle (struct vgic_irq *irq) +{ +DEBUG_SPINLOCK_BUG_ON (!spin_is_locked (&irq->irq_lock)); + +/* If the interrupt is active, it must stay on the current vcpu */ +if (irq->active) +return irq->vcpu; + +/* +* If the IRQ is not active but enabled and pending, we should direct +* it to its configured target VCPU. +*/ +if (irq->enabled && irq->pending) +return irq->target_vcpu; + +/* If neither active nor pending and enabled, then this IRQ should not +* be queued to any VCPU. +*/ +return NULL ; +} + +/* +* Only valid injection if changing level for level-triggered IRQs or for a +* rising edge. +*/ +static bool vgic_validate_injection (struct vgic_irq *irq,bool level) +{ +switch (irq->config) { +case VGIC_CONFIG_LEVEL : +return irq->line_level != level; +case VGIC_CONFIG_EDGE : +return level; + } + +return false; +} + +/* +* Check whether an IRQ needs to (and can) be queued to a VCPU's ap list. +* Do the queuing if necessary, taking the right locks in the right order. +* Returns true when the IRQ was queued, false otherwise. +* +* Needs to be entered with the IRQ lock already held, but will return +* with all locks dropped. +*/ +bool vgic_queue_irq_unlock (struct kvm *kvm,struct vgic_irq *irq) +{ +struct kvm_vcpu *vcpu; + +DEBUG_SPINLOCK_BUG_ON (!spin_is_locked (&irq->irq_lock)); + +retry: + vcpu =vgic_target_oracle (irq); +if (irq->vcpu || !vcpu) { +/* +* If this IRQ is already on a VCPU's ap_list, then it +* cannot be moved or modified and there is no more work for +* us to do. +* +* Otherwise, if the irq is not pending and enabled, it does +* not need to be inserted into an ap_list and there is also +* no more work for us to do. +*/ +spin_unlock (&irq->irq_lock); +return false; + } + +/* +* We must unlock the irq lock to take the ap_list_lock where +* we are going to insert this new pending interrupt. +*/ +spin_unlock (&irq->irq_lock); + +/* someone can do stuff here, which we re-check below */ +
virt/kvm/arm/vgic/vgic.c struct vgic_irq *vgic_get_irq(struct kvm *kvm, struct kvm_vcpu *vcpu, · line 161
Quoted 10 lines
virt/kvm/arm/vgic/vgic.c +10
-0+spin_lock (&vcpu->arch.vgic_cpu.ap_list_lock); +spin_lock (&irq->irq_lock); + +/* +* Did something change behind our backs? +* +* There are two cases: +* 1) The irq became pending or active behind our backs and/or +* the irq->vcpu field was set correspondingly when putting +* the irq on an ap_list. Then drop the locks and return.
Don't we actually implement 3 cases here:
1) the IRQ was queued in our back
2) the IRQ was disabled/turned not pending in our back
3) someone changed the affinity?
Quoted 95 lines
virt/kvm/arm/vgic/vgic.c +89
-0+* 2) Someone changed the affinity on this irq behind our +* backs and we are now holding the wrong ap_list_lock. +* Then drop the locks and try the new VCPU. +*/ +if (irq->vcpu || !(irq->pending && irq->enabled)) { +spin_unlock (&irq->irq_lock); +spin_unlock (&vcpu->arch.vgic_cpu.ap_list_lock); +return false; + } + +if (irq->target_vcpu != vcpu) { +spin_unlock (&irq->irq_lock); +spin_unlock (&vcpu->arch.vgic_cpu.ap_list_lock); + +spin_lock (&irq->irq_lock); + goto retry; + } + +list_add_tail (&irq->ap_list, &vcpu->arch.vgic_cpu.ap_list_head); + irq->vcpu = vcpu; + +spin_unlock (&irq->irq_lock); +spin_unlock (&vcpu->arch.vgic_cpu.ap_list_lock); + +kvm_vcpu_kick (vcpu); + +return true; +} + +static int vgic_update_irq_pending (struct kvm *kvm,int cpuid, +unsigned int intid,bool level, +bool mapped_irq) +{ +struct kvm_vcpu *vcpu; +struct vgic_irq *irq; +int ret; + +trace_vgic_update_irq_pending (cpuid, intid, level); + + vcpu =kvm_get_vcpu (kvm, cpuid); +if (!vcpu && intid <VGIC_NR_PRIVATE_IRQS ) +return -EINVAL ; + + irq =vgic_get_irq (kvm, vcpu, intid); +if (!irq) +return -EINVAL ; + +if (irq->hw != mapped_irq) +return -EINVAL ; + +spin_lock (&irq->irq_lock); + +if (!vgic_validate_injection (irq, level)) { +/* Nothing to see here, move along... */ +spin_unlock (&irq->irq_lock); +return 0 ; + } + +if (irq->config ==VGIC_CONFIG_LEVEL ) { + irq->line_level = level; + irq->pending = level || irq->soft_pending; + }else { + irq->pending = true; + } + +vgic_queue_irq_unlock (kvm, irq); + +return 0 ; +} + +/** +* kvm_vgic_inject_irq - Inject an IRQ from a device to the vgic +* @kvm: The VM structure pointer +* @cpuid: The CPU for PPIs +* @intid: The INTID to inject a new state to. +* @level: Edge-triggered: true: to trigger the interrupt +* false: to ignore the call +* Level-sensitive true: raise the input signal +* false: lower the input signal +* +* The VGIC is not concerned with devices being active-LOW or active-HIGH for +* level-sensitive interrupts. You can think of the level parameter as 1 +* being HIGH and 0 being LOW and all devices being active-HIGH. +*/ +int kvm_vgic_inject_irq (struct kvm *kvm,int cpuid,unsigned int intid, +bool level) +{ +return vgic_update_irq_pending (kvm, cpuid, intid, level, false); +}virt/kvm/arm/vgic/vgic.h +0
-0
virt/kvm/arm/vgic/vgic.h line 23
Quoted 6 lines
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
Eric
Re: [PATCH v3 15/55] KVM: arm/arm64: vgic-new: Implement virtual IRQ injection
In reply to Andre PrzywaraQuoted 14 lines · Andre Przywara
From: Christoffer Dall <[email protected]>
Provide a
vgic_queue_irq()function which decides whether a given IRQ needs to be queued to a VCPU'sap_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.
Quoted 4 lines
[Andre: refactor out
vgic_queue_irq_unlock()]Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Andre Przywara <[email protected]>
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH v3 15/55] KVM: arm/arm64: vgic-new: Implement virtual IRQ injection
In reply to Andre PrzywaraQuoted 175 lines · Andre Przywara
From: Christoffer Dall <[email protected]>
Provide a
vgic_queue_irq()function which decides whether a given IRQ needs to be queued to a VCPU'sap_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()]Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- add spinlock checks protected byCONFIG_DEBUG_SPINLOCK
- add more comments tovgic_target_oracle
- removeBUG_ON()if IRQ is neither edge or level
- renamevgic_queue_irq()tovgic_queue_irq_unlock()
- simplify initial check invgic_queue_irq_unlock()
- extend retry loop to ask the oracle again
- minor comment fixesChangelog v1 .. v2:
- move most IRQ injection code intovgic_update_irq_pending()include/kvm/vgic/vgic.h | 3 + virt/kvm/arm/vgic/vgic.c | 209 +++++++++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.h | 1 + 3 files changed, 213 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 +108
-0@@ -19,8 +19,31 @@#include "vgic.h" +#define CREATE_TRACE_POINTS +#include "../trace.h" + +#ifdef CONFIG_DEBUG_SPINLOCK +#define DEBUG_SPINLOCK_BUG_ON (p) BUG_ON(p) +#else +#define DEBUG_SPINLOCK_BUG_ON (p) +#endif + struct vgic_global __section(.hyp.text) kvm_vgic_global_state; +/* +* Locking order is always: +* vgic_cpu->ap_list_lock +* vgic_irq->irq_lock +* +* (that is, always take the ap_list_lock before the struct vgic_irq lock). +* +* When taking more than one ap_list_lock at the same time, always take the +* lowest numbered VCPU's ap_list_lock first, so: +* vcpuX->vcpu_id < vcpuY->vcpu_id: +* spin_lock(vcpuX->arch.vgic_cpu.ap_list_lock); +* spin_lock(vcpuY->arch.vgic_cpu.ap_list_lock); +*/ +struct vgic_irq *vgic_get_irq (struct kvm *kvm,struct kvm_vcpu *vcpu,u32 intid) {@@ -39,3 +62,189 @@ struct vgic_irq *vgic_get_irq(struct kvm *kvm, struct kvm_vcpu *vcpu,WARN (1 ,"Looking up struct vgic_irq for reserved INTID" );return NULL ; } + +/** +* kvm_vgic_target_oracle - compute the target vcpu for an irq +* +* @irq: The irq to route. Must be already locked. +* +* Based on the current state of the interrupt (enabled, pending, +* active, vcpu and target_vcpu), compute the next vcpu this should be +* given to. Return NULL if this shouldn't be injected at all. +* +* Requires the IRQ lock to be held. +*/ +static struct kvm_vcpu *vgic_target_oracle (struct vgic_irq *irq) +{ +DEBUG_SPINLOCK_BUG_ON (!spin_is_locked (&irq->irq_lock)); + +/* If the interrupt is active, it must stay on the current vcpu */ +if (irq->active) +return irq->vcpu; + +/* +* If the IRQ is not active but enabled and pending, we should direct +* it to its configured target VCPU. +*/ +if (irq->enabled && irq->pending) +return irq->target_vcpu; + +/* If neither active nor pending and enabled, then this IRQ should not +* be queued to any VCPU. +*/ +return NULL ; +} + +/* +* Only valid injection if changing level for level-triggered IRQs or for a +* rising edge. +*/ +static bool vgic_validate_injection (struct vgic_irq *irq,bool level) +{ +switch (irq->config) { +case VGIC_CONFIG_LEVEL : +return irq->line_level != level; +case VGIC_CONFIG_EDGE : +return level; + } + +return false; +} + +/* +* Check whether an IRQ needs to (and can) be queued to a VCPU's ap list. +* Do the queuing if necessary, taking the right locks in the right order. +* Returns true when the IRQ was queued, false otherwise. +* +* Needs to be entered with the IRQ lock already held, but will return +* with all locks dropped. +*/ +bool vgic_queue_irq_unlock (struct kvm *kvm,struct vgic_irq *irq) +{ +struct kvm_vcpu *vcpu; + +DEBUG_SPINLOCK_BUG_ON (!spin_is_locked (&irq->irq_lock)); + +retry: + vcpu =vgic_target_oracle (irq); +if (irq->vcpu || !vcpu) { +/* +* If this IRQ is already on a VCPU's ap_list, then it +* cannot be moved or modified and there is no more work for +* us to do. +* +* Otherwise, if the irq is not pending and enabled, it does +* not need to be inserted into an ap_list and there is also +* no more work for us to do. +*/ +spin_unlock (&irq->irq_lock); +return false; + } + +/* +* We must unlock the irq lock to take the ap_list_lock where +* we are going to insert this new pending interrupt. +*/ +spin_unlock (&irq->irq_lock); +
virt/kvm/arm/vgic/vgic.c struct vgic_irq *vgic_get_irq(struct kvm *kvm, struct kvm_vcpu *vcpu, · line 159
Quoted 10 lines
virt/kvm/arm/vgic/vgic.c +10
-0+/* someone can do stuff here, which we re-check below */ + +spin_lock (&vcpu->arch.vgic_cpu.ap_list_lock); +spin_lock (&irq->irq_lock); + +/* +* Did something change behind our backs? +* +* There are two cases: +* 1) The irq became pending or active behind our backs and/or
but you're not checking the active state below?
so did you mean 'became pending and enabled' ?
virt/kvm/arm/vgic/vgic.c struct vgic_irq *vgic_get_irq(struct kvm *kvm, struct kvm_vcpu *vcpu, · line 165
Quoted 6 lines
virt/kvm/arm/vgic/vgic.c +6
-0+* the irq->vcpu field was set correspondingly when putting +* the irq on an ap_list. Then drop the locks and return. +* 2) Someone changed the affinity on this irq behind our +* backs and we are now holding the wrong ap_list_lock. +* Then drop the locks and try the new VCPU. +*/
I thought we agreed a long time ago to change this to:
if (unlinkely(irq->vcpu || vcpu != vgic_target_oracle(irq))) {
spin_unlock(&irq->irq_lock);
spin_unlock(&vcpu->arch.vgic_cpu.ap_list_lock);
spin_lock(&irq->irq_lock);
goto retry;
}and get rid of two different if statements below ??
At least I don't understand why we are explicitly evaluating !(irq->pending && irq->enabled) here, but using the oracle above?
In fact, I think if you did what I suggest above, then you can reuse this for the active state, which frankly looks more complicated than we had hoped for...
Quoted 99 lines
virt/kvm/arm/vgic/vgic.c +85
-0+if (irq->vcpu || !(irq->pending && irq->enabled)) { +spin_unlock (&irq->irq_lock); +spin_unlock (&vcpu->arch.vgic_cpu.ap_list_lock); +return false; + } + +if (irq->target_vcpu != vcpu) { +spin_unlock (&irq->irq_lock); +spin_unlock (&vcpu->arch.vgic_cpu.ap_list_lock); + +spin_lock (&irq->irq_lock); + goto retry; + } + +list_add_tail (&irq->ap_list, &vcpu->arch.vgic_cpu.ap_list_head); + irq->vcpu = vcpu; + +spin_unlock (&irq->irq_lock); +spin_unlock (&vcpu->arch.vgic_cpu.ap_list_lock); + +kvm_vcpu_kick (vcpu); + +return true; +} + +static int vgic_update_irq_pending (struct kvm *kvm,int cpuid, +unsigned int intid,bool level, +bool mapped_irq) +{ +struct kvm_vcpu *vcpu; +struct vgic_irq *irq; +int ret; + +trace_vgic_update_irq_pending (cpuid, intid, level); + + vcpu =kvm_get_vcpu (kvm, cpuid); +if (!vcpu && intid <VGIC_NR_PRIVATE_IRQS ) +return -EINVAL ; + + irq =vgic_get_irq (kvm, vcpu, intid); +if (!irq) +return -EINVAL ; + +if (irq->hw != mapped_irq) +return -EINVAL ; + +spin_lock (&irq->irq_lock); + +if (!vgic_validate_injection (irq, level)) { +/* Nothing to see here, move along... */ +spin_unlock (&irq->irq_lock); +return 0 ; + } + +if (irq->config ==VGIC_CONFIG_LEVEL ) { + irq->line_level = level; + irq->pending = level || irq->soft_pending; + }else { + irq->pending = true; + } + +vgic_queue_irq_unlock (kvm, irq); + +return 0 ; +} + +/** +* kvm_vgic_inject_irq - Inject an IRQ from a device to the vgic +* @kvm: The VM structure pointer +* @cpuid: The CPU for PPIs +* @intid: The INTID to inject a new state to. +* @level: Edge-triggered: true: to trigger the interrupt +* false: to ignore the call +* Level-sensitive true: raise the input signal +* false: lower the input signal +* +* The VGIC is not concerned with devices being active-LOW or active-HIGH for +* level-sensitive interrupts. You can think of the level parameter as 1 +* being HIGH and 0 being LOW and all devices being active-HIGH. +*/ +int kvm_vgic_inject_irq (struct kvm *kvm,int cpuid,unsigned int intid, +bool level) +{ +return vgic_update_irq_pending (kvm, cpuid, intid, level, false); +}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 v3 16/55 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
Re: [PATCH v3 16/55] KVM: arm/arm64: vgic-new: Add IRQ sorting
Quoted 77 lines · Andre Przywara
From: 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.
Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Andre Przywara <[email protected]>--- virt/kvm/arm/vgic/vgic.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+)virt/kvm/arm/vgic/vgic.c +50
-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;
virt/kvm/arm/vgic/vgic.c static struct kvm_vcpu *vgic_target_oracle(struct vgic_irq *irq) · line 158
Quoted 10 lines
virt/kvm/arm/vgic/vgic.c +7
-0+ +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. */
Eric
Re: [PATCH v3 16/55] KVM: arm/arm64: vgic-new: Add IRQ sorting
In reply to Andre PrzywaraQuoted 7 lines · Andre Przywara
From: 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.
Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Andre Przywara <[email protected]>
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
PATCH v3 17/55 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()
Changelog v2 .. v3:
- remove bogus v2 specific rebase leftovers
include/kvm/vgic/vgic.h | 4 + virt/kvm/arm/vgic/vgic.c | 193 +++++++++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.h | 2 + 3 files changed, 199 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 +193 -0
196 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
Re: [PATCH v3 17/55] KVM: arm/arm64: vgic-new: Add IRQ sync/flush framework
Quoted 9 lines · Andre Przywara
From: 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_hwstateandkvm_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.
Quoted 5 lines
Signed-off-by Marc Zyngier <[email protected]>Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Eric Auger <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Quoted 248 lines
Changelog RFC..v1:
- split outvgic_clear_lr()fromvgic_populate_lr()
- renamevgic_populate_lrs()tovgic_flush_lr_state()
- clean all LRs when the distributor is disabled
- uselist_del()instead oflist_del_init()
- add comments to explain the direction of sync/flush_hwstate
- remove unneeded BUG_ON(in_interrupt()Changelog v2 .. v3:
- remove bogus v2 specific rebase leftoversinclude/kvm/vgic/vgic.h | 4 + virt/kvm/arm/vgic/vgic.c | 193 +++++++++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.h | 2 + 3 files changed, 199 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 +193
-0@@ -305,3 +305,196 @@ int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid, {return vgic_update_irq_pending (kvm, cpuid, intid, level, false); } + +/** +* vgic_prune_ap_list - Remove non-relevant interrupts from the list +* +* @vcpu: The VCPU pointer +* +* Go over the list of "interesting" interrupts, and prune those that we +* won't have to consider in the near future. +*/ +static void vgic_prune_ap_list (struct kvm_vcpu *vcpu) +{ +struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; +struct vgic_irq *irq, *tmp; + +retry: +spin_lock (&vgic_cpu->ap_list_lock); + +list_for_each_entry_safe (irq, tmp, &vgic_cpu->ap_list_head, ap_list) { +struct kvm_vcpu *target_vcpu, *vcpuA, *vcpuB; + +spin_lock (&irq->irq_lock); + +BUG_ON (vcpu != irq->vcpu); + + target_vcpu =vgic_target_oracle (irq); + +if (!target_vcpu) { +/* +* We don't need to process this interrupt any +* further, move it off the list. +*/ +list_del (&irq->ap_list); + irq->vcpu =NULL ; +spin_unlock (&irq->irq_lock); +continue ; + } + +if (target_vcpu == vcpu) { +/* We're on the right CPU */ +spin_unlock (&irq->irq_lock); +continue ; + } + +/* This interrupt looks like it has to be migrated. */ + +spin_unlock (&irq->irq_lock); +spin_unlock (&vgic_cpu->ap_list_lock); + +/* +* Ensure locking order by always locking the smallest +* ID first. +*/ +if (vcpu->vcpu_id < target_vcpu->vcpu_id) { + vcpuA = vcpu; + vcpuB = target_vcpu; + }else { + vcpuA = target_vcpu; + vcpuB = vcpu; + } + +spin_lock (&vcpuA->arch.vgic_cpu.ap_list_lock); +spin_lock (&vcpuB->arch.vgic_cpu.ap_list_lock); +spin_lock (&irq->irq_lock); + +/* +* If the affinity has been preserved, move the +* interrupt around. Otherwise, it means things have +* changed while the interrupt was unlocked, and we +* need to replay this. +* +* In all cases, we cannot trust the list not to have +* changed, so we restart from the beginning. +*/ +if (target_vcpu ==vgic_target_oracle (irq)) { +struct vgic_cpu *new_cpu = &target_vcpu->arch.vgic_cpu; + +list_del (&irq->ap_list); + irq->vcpu = target_vcpu; +list_add_tail (&irq->ap_list, &new_cpu->ap_list_head); + } + +spin_unlock (&irq->irq_lock); +spin_unlock (&vcpuB->arch.vgic_cpu.ap_list_lock); +spin_unlock (&vcpuA->arch.vgic_cpu.ap_list_lock); + goto retry; + } + +spin_unlock (&vgic_cpu->ap_list_lock); +} + +static inline void vgic_process_maintenance_interrupt (struct kvm_vcpu *vcpu) +{ +} + +static inline void vgic_fold_lr_state (struct kvm_vcpu *vcpu) +{ +} + +/* Requires the ap_list_lock and the irq_lock to be held. */ +static inline void vgic_populate_lr (struct kvm_vcpu *vcpu, +struct vgic_irq *irq,int lr) +{ +DEBUG_SPINLOCK_BUG_ON (!spin_is_locked (&vcpu->arch.vgic_cpu.ap_list_lock)); +DEBUG_SPINLOCK_BUG_ON (!spin_is_locked (&irq->irq_lock)); +} + +static inline void vgic_clear_lr (struct kvm_vcpu *vcpu,int lr) +{ +} + +static inline void vgic_set_underflow (struct kvm_vcpu *vcpu) +{ +} + +static int compute_ap_list_depth (struct kvm_vcpu *vcpu) +{ +struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; +struct vgic_irq *irq; +int count =0 ; + +list_for_each_entry (irq, &vgic_cpu->ap_list_head, ap_list) { +spin_lock (&irq->irq_lock); +/* GICv2 SGIs can count for more than one... */ +if (vgic_irq_is_sgi (irq->intid) && irq->source) + count +=hweight8 (irq->source); +else + count++; +spin_unlock (&irq->irq_lock); + } +return count; +} + +/* Requires the VCPU's ap_list_lock to be held. */ +static void vgic_flush_lr_state (struct kvm_vcpu *vcpu) +{ +struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; +struct vgic_irq *irq; +int count =0 ; + +DEBUG_SPINLOCK_BUG_ON (!spin_is_locked (&vgic_cpu->ap_list_lock)); + +if (unlikely (!vcpu->kvm->arch.vgic.enabled)) + goto out_clean; + +if (compute_ap_list_depth (vcpu) > kvm_vgic_global_state.nr_lr) { +vgic_set_underflow (vcpu); +vgic_sort_ap_list (vcpu); + } + +list_for_each_entry (irq, &vgic_cpu->ap_list_head, ap_list) { +spin_lock (&irq->irq_lock); + +if (unlikely (vgic_target_oracle (irq) != vcpu)) + goto next; + +/* +* If we get an SGI with multiple sources, try to get +* them in all at once. +*/ +do { +vgic_populate_lr (vcpu, irq, count++); + }while (irq->source && count < kvm_vgic_global_state.nr_lr); + +next: +spin_unlock (&irq->irq_lock); + +if (count == kvm_vgic_global_state.nr_lr) +break ; + } + +out_clean: + vcpu->arch.vgic_cpu.used_lrs = count; + +/* Nuke remaining LRs */ +for ( ; count < kvm_vgic_global_state.nr_lr; count++) +vgic_clear_lr (vcpu, count); +} + +/* Sync back the hardware VGIC state into our emulation after a guest's run. */ +void kvm_vgic_sync_hwstate (struct kvm_vcpu *vcpu) +{ +vgic_process_maintenance_interrupt (vcpu); +vgic_fold_lr_state (vcpu); +vgic_prune_ap_list (vcpu); +} + +/* Flush our emulation state into the GIC hardware before entering the guest. */ +void kvm_vgic_flush_hwstate (struct kvm_vcpu *vcpu) +{ +spin_lock (&vcpu->arch.vgic_cpu.ap_list_lock); +vgic_flush_lr_state (vcpu); +spin_unlock (&vcpu->arch.vgic_cpu.ap_list_lock); +}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
Re: [PATCH v3 17/55] KVM: arm/arm64: vgic-new: Add IRQ sync/flush framework
In reply to Andre PrzywaraQuoted 157 lines · Andre Przywara
From: 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_hwstateandkvm_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.Signed-off-by Marc Zyngier <[email protected]>Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Eric Auger <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- split outvgic_clear_lr()fromvgic_populate_lr()
- renamevgic_populate_lrs()tovgic_flush_lr_state()
- clean all LRs when the distributor is disabled
- uselist_del()instead oflist_del_init()
- add comments to explain the direction of sync/flush_hwstate
- remove unneeded BUG_ON(in_interrupt()Changelog v2 .. v3:
- remove bogus v2 specific rebase leftoversinclude/kvm/vgic/vgic.h | 4 + virt/kvm/arm/vgic/vgic.c | 193 +++++++++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.h | 2 + 3 files changed, 199 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 +104
-0@@ -305,3 +305,196 @@ int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid, {return vgic_update_irq_pending (kvm, cpuid, intid, level, false); } + +/** +* vgic_prune_ap_list - Remove non-relevant interrupts from the list +* +* @vcpu: The VCPU pointer +* +* Go over the list of "interesting" interrupts, and prune those that we +* won't have to consider in the near future. +*/ +static void vgic_prune_ap_list (struct kvm_vcpu *vcpu) +{ +struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; +struct vgic_irq *irq, *tmp; + +retry: +spin_lock (&vgic_cpu->ap_list_lock); + +list_for_each_entry_safe (irq, tmp, &vgic_cpu->ap_list_head, ap_list) { +struct kvm_vcpu *target_vcpu, *vcpuA, *vcpuB; + +spin_lock (&irq->irq_lock); + +BUG_ON (vcpu != irq->vcpu); + + target_vcpu =vgic_target_oracle (irq); + +if (!target_vcpu) { +/* +* We don't need to process this interrupt any +* further, move it off the list. +*/ +list_del (&irq->ap_list); + irq->vcpu =NULL ; +spin_unlock (&irq->irq_lock); +continue ; + } + +if (target_vcpu == vcpu) { +/* We're on the right CPU */ +spin_unlock (&irq->irq_lock); +continue ; + } + +/* This interrupt looks like it has to be migrated. */ + +spin_unlock (&irq->irq_lock); +spin_unlock (&vgic_cpu->ap_list_lock); + +/* +* Ensure locking order by always locking the smallest +* ID first. +*/ +if (vcpu->vcpu_id < target_vcpu->vcpu_id) { + vcpuA = vcpu; + vcpuB = target_vcpu; + }else { + vcpuA = target_vcpu; + vcpuB = vcpu; + } + +spin_lock (&vcpuA->arch.vgic_cpu.ap_list_lock); +spin_lock (&vcpuB->arch.vgic_cpu.ap_list_lock); +spin_lock (&irq->irq_lock); + +/* +* If the affinity has been preserved, move the +* interrupt around. Otherwise, it means things have +* changed while the interrupt was unlocked, and we +* need to replay this. +* +* In all cases, we cannot trust the list not to have +* changed, so we restart from the beginning. +*/ +if (target_vcpu ==vgic_target_oracle (irq)) { +struct vgic_cpu *new_cpu = &target_vcpu->arch.vgic_cpu; + +list_del (&irq->ap_list); + irq->vcpu = target_vcpu; +list_add_tail (&irq->ap_list, &new_cpu->ap_list_head); + } + +spin_unlock (&irq->irq_lock); +spin_unlock (&vcpuB->arch.vgic_cpu.ap_list_lock); +spin_unlock (&vcpuA->arch.vgic_cpu.ap_list_lock); + goto retry; + } + +spin_unlock (&vgic_cpu->ap_list_lock); +} + +static inline void vgic_process_maintenance_interrupt (struct kvm_vcpu *vcpu) +{ +} + +static inline void vgic_fold_lr_state (struct kvm_vcpu *vcpu) +{ +} + +/* Requires the ap_list_lock and the irq_lock to be held. */ +static inline void vgic_populate_lr (struct kvm_vcpu *vcpu, +struct vgic_irq *irq,int lr) +{ +DEBUG_SPINLOCK_BUG_ON (!spin_is_locked (&vcpu->arch.vgic_cpu.ap_list_lock)); +DEBUG_SPINLOCK_BUG_ON (!spin_is_locked (&irq->irq_lock));
virt/kvm/arm/vgic/vgic.c int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid, · line 421
Quoted 10 lines
virt/kvm/arm/vgic/vgic.c +10
-0+} + +static inline void vgic_clear_lr (struct kvm_vcpu *vcpu,int lr) +{ +} + +static inline void vgic_set_underflow (struct kvm_vcpu *vcpu) +{ +} +
nit: we may add a comment for compute_ap_list_depth, saying vgic_cpu->ap_list_lock must be held
Besides Reviewed-by: Eric Auger <[email protected]>
Eric
Quoted 93 lines
virt/kvm/arm/vgic/vgic.c +79
-0+static int compute_ap_list_depth (struct kvm_vcpu *vcpu) +{ +struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; +struct vgic_irq *irq; +int count =0 ; + +list_for_each_entry (irq, &vgic_cpu->ap_list_head, ap_list) { +spin_lock (&irq->irq_lock); +/* GICv2 SGIs can count for more than one... */ +if (vgic_irq_is_sgi (irq->intid) && irq->source) + count +=hweight8 (irq->source); +else + count++; +spin_unlock (&irq->irq_lock); + } +return count; +} + +/* Requires the VCPU's ap_list_lock to be held. */ +static void vgic_flush_lr_state (struct kvm_vcpu *vcpu) +{ +struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; +struct vgic_irq *irq; +int count =0 ; + +DEBUG_SPINLOCK_BUG_ON (!spin_is_locked (&vgic_cpu->ap_list_lock)); + +if (unlikely (!vcpu->kvm->arch.vgic.enabled)) + goto out_clean; + +if (compute_ap_list_depth (vcpu) > kvm_vgic_global_state.nr_lr) { +vgic_set_underflow (vcpu); +vgic_sort_ap_list (vcpu); + } + +list_for_each_entry (irq, &vgic_cpu->ap_list_head, ap_list) { +spin_lock (&irq->irq_lock); + +if (unlikely (vgic_target_oracle (irq) != vcpu)) + goto next; + +/* +* If we get an SGI with multiple sources, try to get +* them in all at once. +*/ +do { +vgic_populate_lr (vcpu, irq, count++); + }while (irq->source && count < kvm_vgic_global_state.nr_lr); + +next: +spin_unlock (&irq->irq_lock); + +if (count == kvm_vgic_global_state.nr_lr) +break ; + } + +out_clean: + vcpu->arch.vgic_cpu.used_lrs = count; + +/* Nuke remaining LRs */ +for ( ; count < kvm_vgic_global_state.nr_lr; count++) +vgic_clear_lr (vcpu, count); +} + +/* Sync back the hardware VGIC state into our emulation after a guest's run. */ +void kvm_vgic_sync_hwstate (struct kvm_vcpu *vcpu) +{ +vgic_process_maintenance_interrupt (vcpu); +vgic_fold_lr_state (vcpu); +vgic_prune_ap_list (vcpu); +} + +/* Flush our emulation state into the GIC hardware before entering the guest. */ +void kvm_vgic_flush_hwstate (struct kvm_vcpu *vcpu) +{ +spin_lock (&vcpu->arch.vgic_cpu.ap_list_lock); +vgic_flush_lr_state (vcpu); +spin_unlock (&vcpu->arch.vgic_cpu.ap_list_lock); +}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);
Re: [PATCH v3 17/55] KVM: arm/arm64: vgic-new: Add IRQ sync/flush framework
In reply to Andre PrzywaraQuoted 142 lines · Andre Przywara
From: 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_hwstateandkvm_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.Signed-off-by Marc Zyngier <[email protected]>Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Eric Auger <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- split outvgic_clear_lr()fromvgic_populate_lr()
- renamevgic_populate_lrs()tovgic_flush_lr_state()
- clean all LRs when the distributor is disabled
- uselist_del()instead oflist_del_init()
- add comments to explain the direction of sync/flush_hwstate
- remove unneeded BUG_ON(in_interrupt()Changelog v2 .. v3:
- remove bogus v2 specific rebase leftoversinclude/kvm/vgic/vgic.h | 4 + virt/kvm/arm/vgic/vgic.c | 193 +++++++++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.h | 2 + 3 files changed, 199 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 +89
-0@@ -305,3 +305,196 @@ int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid, {return vgic_update_irq_pending (kvm, cpuid, intid, level, false); } + +/** +* vgic_prune_ap_list - Remove non-relevant interrupts from the list +* +* @vcpu: The VCPU pointer +* +* Go over the list of "interesting" interrupts, and prune those that we +* won't have to consider in the near future. +*/ +static void vgic_prune_ap_list (struct kvm_vcpu *vcpu) +{ +struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; +struct vgic_irq *irq, *tmp; + +retry: +spin_lock (&vgic_cpu->ap_list_lock); + +list_for_each_entry_safe (irq, tmp, &vgic_cpu->ap_list_head, ap_list) { +struct kvm_vcpu *target_vcpu, *vcpuA, *vcpuB; + +spin_lock (&irq->irq_lock); + +BUG_ON (vcpu != irq->vcpu); + + target_vcpu =vgic_target_oracle (irq); + +if (!target_vcpu) { +/* +* We don't need to process this interrupt any +* further, move it off the list. +*/ +list_del (&irq->ap_list); + irq->vcpu =NULL ; +spin_unlock (&irq->irq_lock); +continue ; + } + +if (target_vcpu == vcpu) { +/* We're on the right CPU */ +spin_unlock (&irq->irq_lock); +continue ; + } + +/* This interrupt looks like it has to be migrated. */ + +spin_unlock (&irq->irq_lock); +spin_unlock (&vgic_cpu->ap_list_lock); + +/* +* Ensure locking order by always locking the smallest +* ID first. +*/ +if (vcpu->vcpu_id < target_vcpu->vcpu_id) { + vcpuA = vcpu; + vcpuB = target_vcpu; + }else { + vcpuA = target_vcpu; + vcpuB = vcpu; + } + +spin_lock (&vcpuA->arch.vgic_cpu.ap_list_lock); +spin_lock (&vcpuB->arch.vgic_cpu.ap_list_lock); +spin_lock (&irq->irq_lock); + +/* +* If the affinity has been preserved, move the +* interrupt around. Otherwise, it means things have +* changed while the interrupt was unlocked, and we +* need to replay this. +* +* In all cases, we cannot trust the list not to have +* changed, so we restart from the beginning. +*/ +if (target_vcpu ==vgic_target_oracle (irq)) { +struct vgic_cpu *new_cpu = &target_vcpu->arch.vgic_cpu; + +list_del (&irq->ap_list); + irq->vcpu = target_vcpu; +list_add_tail (&irq->ap_list, &new_cpu->ap_list_head); + } + +spin_unlock (&irq->irq_lock); +spin_unlock (&vcpuB->arch.vgic_cpu.ap_list_lock); +spin_unlock (&vcpuA->arch.vgic_cpu.ap_list_lock); + goto retry; + } + +spin_unlock (&vgic_cpu->ap_list_lock); +}
virt/kvm/arm/vgic/vgic.c int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid, · line 406
Quoted 10 lines
virt/kvm/arm/vgic/vgic.c +10
-0+ +static inline void vgic_process_maintenance_interrupt (struct kvm_vcpu *vcpu) +{ +} + +static inline void vgic_fold_lr_state (struct kvm_vcpu *vcpu) +{ +} + +/* Requires the ap_list_lock and the irq_lock to be held. */
why is it needed to hold the ap_list lock here?
virt/kvm/arm/vgic/vgic.c int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid, · line 410
Quoted 4 lines
virt/kvm/arm/vgic/vgic.c +4
-0+static inline void vgic_populate_lr (struct kvm_vcpu *vcpu, +struct vgic_irq *irq,int lr) +{ +DEBUG_SPINLOCK_BUG_ON (!spin_is_locked (&vcpu->arch.vgic_cpu.ap_list_lock));
?
Eric
Quoted 104 lines
virt/kvm/arm/vgic/vgic.c +90
-0+DEBUG_SPINLOCK_BUG_ON (!spin_is_locked (&irq->irq_lock)); +} + +static inline void vgic_clear_lr (struct kvm_vcpu *vcpu,int lr) +{ +} + +static inline void vgic_set_underflow (struct kvm_vcpu *vcpu) +{ +} + +static int compute_ap_list_depth (struct kvm_vcpu *vcpu) +{ +struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; +struct vgic_irq *irq; +int count =0 ; + +list_for_each_entry (irq, &vgic_cpu->ap_list_head, ap_list) { +spin_lock (&irq->irq_lock); +/* GICv2 SGIs can count for more than one... */ +if (vgic_irq_is_sgi (irq->intid) && irq->source) + count +=hweight8 (irq->source); +else + count++; +spin_unlock (&irq->irq_lock); + } +return count; +} + +/* Requires the VCPU's ap_list_lock to be held. */ +static void vgic_flush_lr_state (struct kvm_vcpu *vcpu) +{ +struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; +struct vgic_irq *irq; +int count =0 ; + +DEBUG_SPINLOCK_BUG_ON (!spin_is_locked (&vgic_cpu->ap_list_lock)); + +if (unlikely (!vcpu->kvm->arch.vgic.enabled)) + goto out_clean; + +if (compute_ap_list_depth (vcpu) > kvm_vgic_global_state.nr_lr) { +vgic_set_underflow (vcpu); +vgic_sort_ap_list (vcpu); + } + +list_for_each_entry (irq, &vgic_cpu->ap_list_head, ap_list) { +spin_lock (&irq->irq_lock); + +if (unlikely (vgic_target_oracle (irq) != vcpu)) + goto next; + +/* +* If we get an SGI with multiple sources, try to get +* them in all at once. +*/ +do { +vgic_populate_lr (vcpu, irq, count++); + }while (irq->source && count < kvm_vgic_global_state.nr_lr); + +next: +spin_unlock (&irq->irq_lock); + +if (count == kvm_vgic_global_state.nr_lr) +break ; + } + +out_clean: + vcpu->arch.vgic_cpu.used_lrs = count; + +/* Nuke remaining LRs */ +for ( ; count < kvm_vgic_global_state.nr_lr; count++) +vgic_clear_lr (vcpu, count); +} + +/* Sync back the hardware VGIC state into our emulation after a guest's run. */ +void kvm_vgic_sync_hwstate (struct kvm_vcpu *vcpu) +{ +vgic_process_maintenance_interrupt (vcpu); +vgic_fold_lr_state (vcpu); +vgic_prune_ap_list (vcpu); +} + +/* Flush our emulation state into the GIC hardware before entering the guest. */ +void kvm_vgic_flush_hwstate (struct kvm_vcpu *vcpu) +{ +spin_lock (&vcpu->arch.vgic_cpu.ap_list_lock); +vgic_flush_lr_state (vcpu); +spin_unlock (&vcpu->arch.vgic_cpu.ap_list_lock); +}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);
Re: [PATCH v3 17/55] KVM: arm/arm64: vgic-new: Add IRQ sync/flush framework
Quoted 154 lines · Eric Auger
Quoted 142 lines · Andre Przywara
From: 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_hwstateandkvm_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.Signed-off-by Marc Zyngier <[email protected]>Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Eric Auger <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- split outvgic_clear_lr()fromvgic_populate_lr()
- renamevgic_populate_lrs()tovgic_flush_lr_state()
- clean all LRs when the distributor is disabled
- uselist_del()instead oflist_del_init()
- add comments to explain the direction of sync/flush_hwstate
- remove unneeded BUG_ON(in_interrupt()Changelog v2 .. v3:
- remove bogus v2 specific rebase leftoversinclude/kvm/vgic/vgic.h | 4 + virt/kvm/arm/vgic/vgic.c | 193 +++++++++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.h | 2 + 3 files changed, 199 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 +89
-0@@ -305,3 +305,196 @@ int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid, {return vgic_update_irq_pending (kvm, cpuid, intid, level, false); } + +/** +* vgic_prune_ap_list - Remove non-relevant interrupts from the list +* +* @vcpu: The VCPU pointer +* +* Go over the list of "interesting" interrupts, and prune those that we +* won't have to consider in the near future. +*/ +static void vgic_prune_ap_list (struct kvm_vcpu *vcpu) +{ +struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; +struct vgic_irq *irq, *tmp; + +retry: +spin_lock (&vgic_cpu->ap_list_lock); + +list_for_each_entry_safe (irq, tmp, &vgic_cpu->ap_list_head, ap_list) { +struct kvm_vcpu *target_vcpu, *vcpuA, *vcpuB; + +spin_lock (&irq->irq_lock); + +BUG_ON (vcpu != irq->vcpu); + + target_vcpu =vgic_target_oracle (irq); + +if (!target_vcpu) { +/* +* We don't need to process this interrupt any +* further, move it off the list. +*/ +list_del (&irq->ap_list); + irq->vcpu =NULL ; +spin_unlock (&irq->irq_lock); +continue ; + } + +if (target_vcpu == vcpu) { +/* We're on the right CPU */ +spin_unlock (&irq->irq_lock); +continue ; + } + +/* This interrupt looks like it has to be migrated. */ + +spin_unlock (&irq->irq_lock); +spin_unlock (&vgic_cpu->ap_list_lock); + +/* +* Ensure locking order by always locking the smallest +* ID first. +*/ +if (vcpu->vcpu_id < target_vcpu->vcpu_id) { + vcpuA = vcpu; + vcpuB = target_vcpu; + }else { + vcpuA = target_vcpu; + vcpuB = vcpu; + } + +spin_lock (&vcpuA->arch.vgic_cpu.ap_list_lock); +spin_lock (&vcpuB->arch.vgic_cpu.ap_list_lock); +spin_lock (&irq->irq_lock); + +/* +* If the affinity has been preserved, move the +* interrupt around. Otherwise, it means things have +* changed while the interrupt was unlocked, and we +* need to replay this. +* +* In all cases, we cannot trust the list not to have +* changed, so we restart from the beginning. +*/ +if (target_vcpu ==vgic_target_oracle (irq)) { +struct vgic_cpu *new_cpu = &target_vcpu->arch.vgic_cpu; + +list_del (&irq->ap_list); + irq->vcpu = target_vcpu; +list_add_tail (&irq->ap_list, &new_cpu->ap_list_head); + } + +spin_unlock (&irq->irq_lock); +spin_unlock (&vcpuB->arch.vgic_cpu.ap_list_lock); +spin_unlock (&vcpuA->arch.vgic_cpu.ap_list_lock); + goto retry; + } + +spin_unlock (&vgic_cpu->ap_list_lock); +}virt/kvm/arm/vgic/vgic.c int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid, · line 406
Quoted 10 lines
virt/kvm/arm/vgic/vgic.c +10
-0+ +static inline void vgic_process_maintenance_interrupt (struct kvm_vcpu *vcpu) +{ +} + +static inline void vgic_fold_lr_state (struct kvm_vcpu *vcpu) +{ +} + +/* Requires the ap_list_lock and the irq_lock to be held. */ why is it needed to hold the
ap_listlock here?
Quoted 5 lines
virt/kvm/arm/vgic/vgic.c int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid, · line 410
Quoted 4 lines
virt/kvm/arm/vgic/vgic.c +4
-0+static inline void vgic_populate_lr (struct kvm_vcpu *vcpu, +struct vgic_irq *irq,int lr) +{ +DEBUG_SPINLOCK_BUG_ON (!spin_is_locked (&vcpu->arch.vgic_cpu.ap_list_lock));?
Only the irq lock needs to be held for this particular function. It is vgic_flush_lr_state that requires the ap_list lock to be held, as it is iterating over all the interrupts for that particular vcpu.
Andre, can you please amend the comment and drop that assertion?
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH v3 17/55] KVM: arm/arm64: vgic-new: Add IRQ sync/flush framework
In reply to Andre PrzywaraQuoted 14 lines · Andre Przywara
From: 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_hwstateandkvm_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.Signed-off-by Marc Zyngier <[email protected]>Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Eric Auger <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
[...]
Quoted 4 lines
virt/kvm/arm/vgic/vgic.c +0
-0
[...]
virt/kvm/arm/vgic/vgic.c int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid, · line 450
Quoted 12 lines
virt/kvm/arm/vgic/vgic.c +12
-0+ +/* Requires the VCPU's ap_list_lock to be held. */ +static void vgic_flush_lr_state (struct kvm_vcpu *vcpu) +{ +struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; +struct vgic_irq *irq; +int count =0 ; + +DEBUG_SPINLOCK_BUG_ON (!spin_is_locked (&vgic_cpu->ap_list_lock)); + +if (unlikely (!vcpu->kvm->arch.vgic.enabled)) + goto out_clean;
I know I said I reviewed this, but thinking about this more carefully, doesn't the enable bit actually tell us if forwarding of pending interrupts is enabled, but not whether or not the vgic exists?
So you could imagine a guest that turns off the GIC, but still has active interrupts that it wants to disable/EOI, in the case of shutdown/reboot for example, or is this architecturally not allowed?
If it is, then we should, at least theoretically, still forward active interrupts in LRs despite the enabled bit being clear, but modify the oracle to take the global enable bit into account.
Thanks,
-Christoffer
Quoted 35 lines
virt/kvm/arm/vgic/vgic.c +35
-0+ +if (compute_ap_list_depth (vcpu) > kvm_vgic_global_state.nr_lr) { +vgic_set_underflow (vcpu); +vgic_sort_ap_list (vcpu); + } + +list_for_each_entry (irq, &vgic_cpu->ap_list_head, ap_list) { +spin_lock (&irq->irq_lock); + +if (unlikely (vgic_target_oracle (irq) != vcpu)) + goto next; + +/* +* If we get an SGI with multiple sources, try to get +* them in all at once. +*/ +do { +vgic_populate_lr (vcpu, irq, count++); + }while (irq->source && count < kvm_vgic_global_state.nr_lr); + +next: +spin_unlock (&irq->irq_lock); + +if (count == kvm_vgic_global_state.nr_lr) +break ; + } + +out_clean: + vcpu->arch.vgic_cpu.used_lrs = count; + +/* Nuke remaining LRs */ +for ( ; count < kvm_vgic_global_state.nr_lr; count++) +vgic_clear_lr (vcpu, count); +} +
Re: [PATCH v3 17/55] KVM: arm/arm64: vgic-new: Add IRQ sync/flush framework
Hi,
Quoted 43 lines · Christoffer Dall
Quoted 14 lines · Andre Przywara
From: 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_hwstateandkvm_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.Signed-off-by Marc Zyngier <[email protected]>Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Eric Auger <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
[...]
Quoted 4 lines
virt/kvm/arm/vgic/vgic.c +0
-0[...]
virt/kvm/arm/vgic/vgic.c int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid, · line 450
Quoted 12 lines
virt/kvm/arm/vgic/vgic.c +12
-0+ +/* Requires the VCPU's ap_list_lock to be held. */ +static void vgic_flush_lr_state (struct kvm_vcpu *vcpu) +{ +struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; +struct vgic_irq *irq; +int count =0 ; + +DEBUG_SPINLOCK_BUG_ON (!spin_is_locked (&vgic_cpu->ap_list_lock)); + +if (unlikely (!vcpu->kvm->arch.vgic.enabled)) + goto out_clean;I know I said I reviewed this, but thinking about this more carefully, doesn't the enable bit actually tell us if forwarding of pending interrupts is enabled, but not whether or not the vgic exists?
Quoted 3 lines
So you could imagine a guest that turns off the GIC, but still has active interrupts that it wants to disable/EOI, in the case of shutdown/reboot for example, or is this architecturally not allowed?
I guess you are right, the spec talks only about GICD.CTLR[Enable] controlling the forwarding of pending interrupts to the CPU interface. If you don't want interrupts at all, I guess you disable the CPU interface.
So we just don't put pending IRQs in the LR, but only active ones. I am coding this right now.
Cheers,
Andre
Quoted 7 lines
If it is, then we should, at least theoretically, still forward active interrupts in LRs despite the enabled bit being clear, but modify the oracle to take the global enable bit into account.
Thanks,
-Christoffer
PATCH v3 18/55 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.
---
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
Changelog v1 .. v2:
- inject the IRQ priority into the list register
Changelog v2 .. v3:
- cleanup diff containing rebase artifacts
include/linux/irqchip/arm-gic.h | 1 + virt/kvm/arm/vgic/vgic-v2.c | 178 ++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.c | 6 ++ virt/kvm/arm/vgic/vgic.h | 6 ++ 4 files changed, 191 insertions(+) create mode 100644 virt/kvm/arm/vgic/vgic-v2.c
include/linux/irqchip/arm-gic.h +1 -0
@@ -76,6 +76,7 @@#define GICH_LR_VIRTUALID (0x3ff << 0)#define GICH_LR_PHYSID_CPUID_SHIFT (10)#define GICH_LR_PHYSID_CPUID (0x3ff << GICH_LR_PHYSID_CPUID_SHIFT) +#define GICH_LR_PRIORITY_SHIFT 23#define GICH_LR_STATE (3 << 28)#define GICH_LR_PENDING_BIT (1 << 28)#define GICH_LR_ACTIVE_BIT (1 << 29)
virt/kvm/arm/vgic/vgic-v2.c new file +178 -0
178 lines not on this page · raw message
virt/kvm/arm/vgic/vgic.c +6 -0
@@ -397,10 +397,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. */
@@ -409,14 +411,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)
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
Re: [PATCH v3 18/55] KVM: arm/arm64: vgic-new: Add GICv2 world switch backend
Quoted 93 lines · Andre Przywara
From: Marc Zyngier <[email protected]>
Processing maintenance interrupts and accessing the list registers are dependent on the host's GIC version.
Introducevgic-v2.cto contain GICv2 specific functions. Implement the GICv2 specific code for syncing the emulation state into the VGIC registers.Signed-off-by Marc Zyngier <[email protected]>Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Eric Auger <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- remove explicitLR_STATEclearing on maintenance interrupt handling
- improve documentation forvgic_v2_populate_lr()
- removeWARN_ONon non-edge IRQs in maintenance interrupts
- simplify multi-CPU source SGI handlingChangelog v1 .. v2:
- inject the IRQ priority into the list registerChangelog v2 .. v3:
- cleanup diff containing rebase artifactsinclude/linux/irqchip/arm-gic.h | 1 + virt/kvm/arm/vgic/vgic-v2.c | 178 ++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.c | 6 ++ virt/kvm/arm/vgic/vgic.h | 6 ++ 4 files changed, 191 insertions(+) create mode 100644 virt/kvm/arm/vgic/vgic-v2.cinclude/linux/irqchip/arm-gic.h +1
-0@@ -76,6 +76,7 @@#define GICH_LR_VIRTUALID (0x3ff << 0)#define GICH_LR_PHYSID_CPUID_SHIFT (10)#define GICH_LR_PHYSID_CPUID (0x3ff << GICH_LR_PHYSID_CPUID_SHIFT) +#define GICH_LR_PRIORITY_SHIFT 23#define GICH_LR_STATE (3 << 28)#define GICH_LR_PENDING_BIT (1 << 28)#define GICH_LR_ACTIVE_BIT (1 << 29)virt/kvm/arm/vgic/vgic-v2.c new file +43
-0@@ -0,0 +1,178 @@ +/* +* 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);
virt/kvm/arm/vgic/vgic-v2.c line 53
Quoted 10 lines
virt/kvm/arm/vgic/vgic-v2.c new file +10
-0+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 ); +
why do we need to do this? I cannot find any consumers of this info after we've left the hyp code.
Also, I think I offered a comment about why we would potentially need this in the first place. This is the famous race where hardware doesn't guarantee consistency between the MISR and ELRSR right?
Quoted 179 lines
virt/kvm/arm/vgic/vgic-v2.c new file +125
-0+ 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 ; + } + +/* The GICv2 LR only holds five bits of priority. */ + val |= (irq->priority >>3 ) <<GICH_LR_PRIORITY_SHIFT ; + + 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 +6
-0@@ -397,10 +397,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. */ @@ -409,14 +411,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)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
Re: [PATCH v3 18/55] KVM: arm/arm64: vgic-new: Add GICv2 world switch backend
Quoted 99 lines · Christoffer Dall
Quoted 98 lines · Andre Przywara
From: Marc Zyngier <[email protected]>
Processing maintenance interrupts and accessing the list registers are dependent on the host's GIC version.
Introducevgic-v2.cto contain GICv2 specific functions. Implement the GICv2 specific code for syncing the emulation state into the VGIC registers.Signed-off-by Marc Zyngier <[email protected]>Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Eric Auger <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- remove explicitLR_STATEclearing on maintenance interrupt handling
- improve documentation forvgic_v2_populate_lr()
- removeWARN_ONon non-edge IRQs in maintenance interrupts
- simplify multi-CPU source SGI handlingChangelog v1 .. v2:
- inject the IRQ priority into the list registerChangelog v2 .. v3:
- cleanup diff containing rebase artifactsinclude/linux/irqchip/arm-gic.h | 1 + virt/kvm/arm/vgic/vgic-v2.c | 178 ++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.c | 6 ++ virt/kvm/arm/vgic/vgic.h | 6 ++ 4 files changed, 191 insertions(+) create mode 100644 virt/kvm/arm/vgic/vgic-v2.cinclude/linux/irqchip/arm-gic.h +1
-0@@ -76,6 +76,7 @@#define GICH_LR_VIRTUALID (0x3ff << 0)#define GICH_LR_PHYSID_CPUID_SHIFT (10)#define GICH_LR_PHYSID_CPUID (0x3ff << GICH_LR_PHYSID_CPUID_SHIFT) +#define GICH_LR_PRIORITY_SHIFT 23#define GICH_LR_STATE (3 << 28)#define GICH_LR_PENDING_BIT (1 << 28)#define GICH_LR_ACTIVE_BIT (1 << 29)virt/kvm/arm/vgic/vgic-v2.c new file +48
-0@@ -0,0 +1,178 @@ +/* +* 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 ; +
Quoted 8 lines
virt/kvm/arm/vgic/vgic-v2.c line 53
Quoted 5 lines
virt/kvm/arm/vgic/vgic-v2.c new file +5
-0+WARN_ON (cpuif->vgic_lr[lr] &GICH_LR_STATE ); + +kvm_notify_acked_irq (vcpu->kvm,0 , + intid -VGIC_NR_PRIVATE_IRQS ); +why do we need to do this? I cannot find any consumers of this info after we've left the hyp code.
I believe that's for vhost and irqfd. Or am I misreading your question?
Quoted 3 lines
Also, I think I offered a comment about why we would potentially need this in the first place. This is the famous race where hardware doesn't guarantee consistency between the MISR and ELRSR right?
That's the one (except it is between EISR and ELRSR). I don't have your initial comment at hand, but would something like the following do?
/*
* The maintenance interrupt may not have had a
* chance to update ELRSR, so let's mark the LRs
* presents in EISR as empty.
*/
Quoted 4 lines
virt/kvm/arm/vgic/vgic-v2.c line 56
Quoted 4 lines
virt/kvm/arm/vgic/vgic-v2.c new file +3
-0+ cpuif->vgic_elrsr |=1ULL << lr; + } + }
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH v3 18/55] KVM: arm/arm64: vgic-new: Add GICv2 world switch backend
Quoted 109 lines · Marc Zyngier
Quoted 99 lines · Christoffer Dall
Quoted 98 lines · Andre Przywara
From: Marc Zyngier <[email protected]>
Processing maintenance interrupts and accessing the list registers are dependent on the host's GIC version.
Introducevgic-v2.cto contain GICv2 specific functions. Implement the GICv2 specific code for syncing the emulation state into the VGIC registers.Signed-off-by Marc Zyngier <[email protected]>Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Eric Auger <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- remove explicitLR_STATEclearing on maintenance interrupt handling
- improve documentation forvgic_v2_populate_lr()
- removeWARN_ONon non-edge IRQs in maintenance interrupts
- simplify multi-CPU source SGI handlingChangelog v1 .. v2:
- inject the IRQ priority into the list registerChangelog v2 .. v3:
- cleanup diff containing rebase artifactsinclude/linux/irqchip/arm-gic.h | 1 + virt/kvm/arm/vgic/vgic-v2.c | 178 ++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.c | 6 ++ virt/kvm/arm/vgic/vgic.h | 6 ++ 4 files changed, 191 insertions(+) create mode 100644 virt/kvm/arm/vgic/vgic-v2.cinclude/linux/irqchip/arm-gic.h +1
-0@@ -76,6 +76,7 @@#define GICH_LR_VIRTUALID (0x3ff << 0)#define GICH_LR_PHYSID_CPUID_SHIFT (10)#define GICH_LR_PHYSID_CPUID (0x3ff << GICH_LR_PHYSID_CPUID_SHIFT) +#define GICH_LR_PRIORITY_SHIFT 23#define GICH_LR_STATE (3 << 28)#define GICH_LR_PENDING_BIT (1 << 28)#define GICH_LR_ACTIVE_BIT (1 << 29)virt/kvm/arm/vgic/vgic-v2.c new file +48
-0@@ -0,0 +1,178 @@ +/* +* 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 ; +Quoted 8 lines
virt/kvm/arm/vgic/vgic-v2.c line 53
Quoted 5 lines
virt/kvm/arm/vgic/vgic-v2.c new file +5
-0+WARN_ON (cpuif->vgic_lr[lr] &GICH_LR_STATE ); + +kvm_notify_acked_irq (vcpu->kvm,0 , + intid -VGIC_NR_PRIVATE_IRQS ); +why do we need to do this? I cannot find any consumers of this info after we've left the hyp code.
Quoted 1 line
I believe that's for vhost and irqfd. Or am I misreading your question?
Yes that's for irqfd. It triggers the resamplerfd which then "VFIO unmasks" the IRQ
Eric
Quoted 22 lines
Quoted 4 lines
Also, I think I offered a comment about why we would potentially need this in the first place. This is the famous race where hardware doesn't guarantee consistency between the MISR and ELRSR right?
That's the one (except it is between EISR and ELRSR). I don't have your initial comment at hand, but would something like the following do?
/*
* The maintenance interrupt may not have had a
* chance to update ELRSR, so let's mark the LRs
* presents in EISR as empty.
*/Quoted 4 lines
virt/kvm/arm/vgic/vgic-v2.c line 56
Quoted 4 lines
virt/kvm/arm/vgic/vgic-v2.c new file +3
-0+ cpuif->vgic_elrsr |=1ULL << lr; + } + }Thanks,
M.
Re: [PATCH v3 18/55] KVM: arm/arm64: vgic-new: Add GICv2 world switch backend
In reply to Marc ZyngierQuoted 109 lines · Marc Zyngier
Quoted 99 lines · Christoffer Dall
Quoted 98 lines · Andre Przywara
From: Marc Zyngier <[email protected]>
Processing maintenance interrupts and accessing the list registers are dependent on the host's GIC version.
Introducevgic-v2.cto contain GICv2 specific functions. Implement the GICv2 specific code for syncing the emulation state into the VGIC registers.Signed-off-by Marc Zyngier <[email protected]>Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Eric Auger <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- remove explicitLR_STATEclearing on maintenance interrupt handling
- improve documentation forvgic_v2_populate_lr()
- removeWARN_ONon non-edge IRQs in maintenance interrupts
- simplify multi-CPU source SGI handlingChangelog v1 .. v2:
- inject the IRQ priority into the list registerChangelog v2 .. v3:
- cleanup diff containing rebase artifactsinclude/linux/irqchip/arm-gic.h | 1 + virt/kvm/arm/vgic/vgic-v2.c | 178 ++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.c | 6 ++ virt/kvm/arm/vgic/vgic.h | 6 ++ 4 files changed, 191 insertions(+) create mode 100644 virt/kvm/arm/vgic/vgic-v2.cinclude/linux/irqchip/arm-gic.h +1
-0@@ -76,6 +76,7 @@#define GICH_LR_VIRTUALID (0x3ff << 0)#define GICH_LR_PHYSID_CPUID_SHIFT (10)#define GICH_LR_PHYSID_CPUID (0x3ff << GICH_LR_PHYSID_CPUID_SHIFT) +#define GICH_LR_PRIORITY_SHIFT 23#define GICH_LR_STATE (3 << 28)#define GICH_LR_PENDING_BIT (1 << 28)#define GICH_LR_ACTIVE_BIT (1 << 29)virt/kvm/arm/vgic/vgic-v2.c new file +48
-0@@ -0,0 +1,178 @@ +/* +* 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 ; +Quoted 8 lines
virt/kvm/arm/vgic/vgic-v2.c line 53
Quoted 5 lines
virt/kvm/arm/vgic/vgic-v2.c new file +5
-0+WARN_ON (cpuif->vgic_lr[lr] &GICH_LR_STATE ); + +kvm_notify_acked_irq (vcpu->kvm,0 , + intid -VGIC_NR_PRIVATE_IRQS ); +why do we need to do this? I cannot find any consumers of this info after we've left the hyp code.
Quoted 2 lines
I believe that's for vhost and irqfd. Or am I misreading your question?
I meant the setting of the bits in vgic_elrsr (sorry, badly placed comment)...
Quoted 7 lines
Quoted 3 lines
Also, I think I offered a comment about why we would potentially need this in the first place. This is the famous race where hardware doesn't guarantee consistency between the MISR and ELRSR right?
That's the one (except it is between EISR and ELRSR). I don't have your initial comment at hand, but would something like the following do?
Quoted 7 lines
/*
* The maintenance interrupt may not have had a
* chance to update ELRSR, so let's mark the LRs
* presents in EISR as empty.
*/Quoted 2 lines
virt/kvm/arm/vgic/vgic-v2.c line 54
Quoted 2 lines
virt/kvm/arm/vgic/vgic-v2.c new file +1
-0+ cpuif->vgic_elrsr |=1ULL << lr;
so, why are we doing this?
Quoted 8 lines
Quoted 2 lines
virt/kvm/arm/vgic/vgic-v2.c line 56
Quoted 2 lines
virt/kvm/arm/vgic/vgic-v2.c new file +2
-0+ } + }Thanks,
M.Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH v3 18/55] KVM: arm/arm64: vgic-new: Add GICv2 world switch backend
Quoted 129 lines · Christoffer Dall
Quoted 109 lines · Marc Zyngier
Quoted 99 lines · Christoffer Dall
Quoted 98 lines · Andre Przywara
From: Marc Zyngier <[email protected]>
Processing maintenance interrupts and accessing the list registers are dependent on the host's GIC version.
Introducevgic-v2.cto contain GICv2 specific functions. Implement the GICv2 specific code for syncing the emulation state into the VGIC registers.Signed-off-by Marc Zyngier <[email protected]>Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Eric Auger <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- remove explicitLR_STATEclearing on maintenance interrupt handling
- improve documentation forvgic_v2_populate_lr()
- removeWARN_ONon non-edge IRQs in maintenance interrupts
- simplify multi-CPU source SGI handlingChangelog v1 .. v2:
- inject the IRQ priority into the list registerChangelog v2 .. v3:
- cleanup diff containing rebase artifactsinclude/linux/irqchip/arm-gic.h | 1 + virt/kvm/arm/vgic/vgic-v2.c | 178 ++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.c | 6 ++ virt/kvm/arm/vgic/vgic.h | 6 ++ 4 files changed, 191 insertions(+) create mode 100644 virt/kvm/arm/vgic/vgic-v2.cinclude/linux/irqchip/arm-gic.h +1
-0@@ -76,6 +76,7 @@#define GICH_LR_VIRTUALID (0x3ff << 0)#define GICH_LR_PHYSID_CPUID_SHIFT (10)#define GICH_LR_PHYSID_CPUID (0x3ff << GICH_LR_PHYSID_CPUID_SHIFT) +#define GICH_LR_PRIORITY_SHIFT 23#define GICH_LR_STATE (3 << 28)#define GICH_LR_PENDING_BIT (1 << 28)#define GICH_LR_ACTIVE_BIT (1 << 29)virt/kvm/arm/vgic/vgic-v2.c new file +48
-0@@ -0,0 +1,178 @@ +/* +* 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 ; +Quoted 8 lines
virt/kvm/arm/vgic/vgic-v2.c line 53
Quoted 5 lines
virt/kvm/arm/vgic/vgic-v2.c new file +5
-0+WARN_ON (cpuif->vgic_lr[lr] &GICH_LR_STATE ); + +kvm_notify_acked_irq (vcpu->kvm,0 , + intid -VGIC_NR_PRIVATE_IRQS ); +why do we need to do this? I cannot find any consumers of this info after we've left the hyp code.
Quoted 2 lines
I believe that's for vhost and irqfd. Or am I misreading your question?
I meant the setting of the bits in
vgic_elrsr(sorry, badly placed comment)...Quoted 13 lines
Quoted 3 lines
Also, I think I offered a comment about why we would potentially need this in the first place. This is the famous race where hardware doesn't guarantee consistency between the MISR and ELRSR right?
That's the one (except it is between EISR and ELRSR). I don't have your initial comment at hand, but would something like the following do?
/*
* The maintenance interrupt may not have had a
* chance to update ELRSR, so let's mark the LRs
* presents in EISR as empty.
*/Quoted 1 line
Quoted 3 lines
Quoted 1 line
Quoted 1 line
virt/kvm/arm/vgic/vgic-v2.c line 54
Quoted 1 line
virt/kvm/arm/vgic/vgic-v2.c new file +1
-0+ cpuif->vgic_elrsr |=1ULL << lr;so, why are we doing this?
Ah! I finally see what you mean: we don't reuse LRs at all with the new code base, so knowing which LR is empty is irrelevant. In which case, something like that should be done:
virt/kvm/arm/vgic/vgic-v2.c +0 -2
@@ -52,8 +52,6 @@ void vgic_v2_process_maintenance(struct kvm_vcpu *vcpu)kvm_notify_acked_irq (vcpu->kvm,0 , intid -VGIC_NR_PRIVATE_IRQS ); - - cpuif->vgic_elrsr |=1ULL << lr; } }
virt/kvm/arm/vgic/vgic-v3.c +0 -2
@@ -43,8 +43,6 @@ void vgic_v3_process_maintenance(struct kvm_vcpu *vcpu)kvm_notify_acked_irq (vcpu->kvm,0 , intid -VGIC_NR_PRIVATE_IRQS ); - - cpuif->vgic_elrsr |=1ULL << lr; }/*
I'll give it a spin, just to be safe.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH v3 18/55] KVM: arm/arm64: vgic-new: Add GICv2 world switch backend
Quoted 165 lines · Marc Zyngier
Quoted 129 lines · Christoffer Dall
Quoted 109 lines · Marc Zyngier
Quoted 99 lines · Christoffer Dall
Quoted 98 lines · Andre Przywara
From: Marc Zyngier <[email protected]>
Processing maintenance interrupts and accessing the list registers are dependent on the host's GIC version.
Introducevgic-v2.cto contain GICv2 specific functions. Implement the GICv2 specific code for syncing the emulation state into the VGIC registers.Signed-off-by Marc Zyngier <[email protected]>Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Eric Auger <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- remove explicitLR_STATEclearing on maintenance interrupt handling
- improve documentation forvgic_v2_populate_lr()
- removeWARN_ONon non-edge IRQs in maintenance interrupts
- simplify multi-CPU source SGI handlingChangelog v1 .. v2:
- inject the IRQ priority into the list registerChangelog v2 .. v3:
- cleanup diff containing rebase artifactsinclude/linux/irqchip/arm-gic.h | 1 + virt/kvm/arm/vgic/vgic-v2.c | 178 ++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.c | 6 ++ virt/kvm/arm/vgic/vgic.h | 6 ++ 4 files changed, 191 insertions(+) create mode 100644 virt/kvm/arm/vgic/vgic-v2.cinclude/linux/irqchip/arm-gic.h +1
-0@@ -76,6 +76,7 @@#define GICH_LR_VIRTUALID (0x3ff << 0)#define GICH_LR_PHYSID_CPUID_SHIFT (10)#define GICH_LR_PHYSID_CPUID (0x3ff << GICH_LR_PHYSID_CPUID_SHIFT) +#define GICH_LR_PRIORITY_SHIFT 23#define GICH_LR_STATE (3 << 28)#define GICH_LR_PENDING_BIT (1 << 28)#define GICH_LR_ACTIVE_BIT (1 << 29)virt/kvm/arm/vgic/vgic-v2.c new file +48
-0@@ -0,0 +1,178 @@ +/* +* 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 ; +Quoted 8 lines
virt/kvm/arm/vgic/vgic-v2.c line 53
Quoted 5 lines
virt/kvm/arm/vgic/vgic-v2.c new file +5
-0+WARN_ON (cpuif->vgic_lr[lr] &GICH_LR_STATE ); + +kvm_notify_acked_irq (vcpu->kvm,0 , + intid -VGIC_NR_PRIVATE_IRQS ); +why do we need to do this? I cannot find any consumers of this info after we've left the hyp code.
Quoted 2 lines
I believe that's for vhost and irqfd. Or am I misreading your question?
I meant the setting of the bits in
vgic_elrsr(sorry, badly placed comment)...Quoted 13 lines
Quoted 3 lines
Also, I think I offered a comment about why we would potentially need this in the first place. This is the famous race where hardware doesn't guarantee consistency between the MISR and ELRSR right?
That's the one (except it is between EISR and ELRSR). I don't have your initial comment at hand, but would something like the following do?
/*
* The maintenance interrupt may not have had a
* chance to update ELRSR, so let's mark the LRs
* presents in EISR as empty.
*/Quoted 1 line
Quoted 3 lines
Quoted 1 line
Quoted 1 line
virt/kvm/arm/vgic/vgic-v2.c line 54
Quoted 1 line
virt/kvm/arm/vgic/vgic-v2.c new file +1
-0+ cpuif->vgic_elrsr |=1ULL << lr;so, why are we doing this?
Ah! I finally see what you mean: we don't reuse LRs at all with the new code base, so knowing which LR is empty is irrelevant. In which case, something like that should be done:
virt/kvm/arm/vgic/vgic-v2.c +0
-2@@ -52,8 +52,6 @@ void vgic_v2_process_maintenance(struct kvm_vcpu *vcpu)kvm_notify_acked_irq (vcpu->kvm,0 , intid -VGIC_NR_PRIVATE_IRQS ); - - cpuif->vgic_elrsr |=1ULL << lr; } }virt/kvm/arm/vgic/vgic-v3.c +0
-2@@ -43,8 +43,6 @@ void vgic_v3_process_maintenance(struct kvm_vcpu *vcpu)kvm_notify_acked_irq (vcpu->kvm,0 , intid -VGIC_NR_PRIVATE_IRQS ); - - cpuif->vgic_elrsr |=1ULL << lr; }/*
Quoted 1 line
I'll give it a spin, just to be safe.
Seems OK on GICv2, and this of course leads to some more possible cleanups or optimizations (I think we can get to a state where we completely disregards ELRSR). I'll have a look.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH v3 18/55] KVM: arm/arm64: vgic-new: Add GICv2 world switch backend
Quoted 164 lines · Marc Zyngier
Quoted 163 lines · Marc Zyngier
Quoted 129 lines · Christoffer Dall
Quoted 109 lines · Marc Zyngier
Quoted 99 lines · Christoffer Dall
Quoted 98 lines · Andre Przywara
From: Marc Zyngier <[email protected]>
Processing maintenance interrupts and accessing the list registers are dependent on the host's GIC version.
Introducevgic-v2.cto contain GICv2 specific functions. Implement the GICv2 specific code for syncing the emulation state into the VGIC registers.Signed-off-by Marc Zyngier <[email protected]>Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Eric Auger <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- remove explicitLR_STATEclearing on maintenance interrupt handling
- improve documentation forvgic_v2_populate_lr()
- removeWARN_ONon non-edge IRQs in maintenance interrupts
- simplify multi-CPU source SGI handlingChangelog v1 .. v2:
- inject the IRQ priority into the list registerChangelog v2 .. v3:
- cleanup diff containing rebase artifactsinclude/linux/irqchip/arm-gic.h | 1 + virt/kvm/arm/vgic/vgic-v2.c | 178 ++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.c | 6 ++ virt/kvm/arm/vgic/vgic.h | 6 ++ 4 files changed, 191 insertions(+) create mode 100644 virt/kvm/arm/vgic/vgic-v2.cinclude/linux/irqchip/arm-gic.h +1
-0@@ -76,6 +76,7 @@#define GICH_LR_VIRTUALID (0x3ff << 0)#define GICH_LR_PHYSID_CPUID_SHIFT (10)#define GICH_LR_PHYSID_CPUID (0x3ff << GICH_LR_PHYSID_CPUID_SHIFT) +#define GICH_LR_PRIORITY_SHIFT 23#define GICH_LR_STATE (3 << 28)#define GICH_LR_PENDING_BIT (1 << 28)#define GICH_LR_ACTIVE_BIT (1 << 29)virt/kvm/arm/vgic/vgic-v2.c new file +48
-0@@ -0,0 +1,178 @@ +/* +* 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 ; +Quoted 8 lines
virt/kvm/arm/vgic/vgic-v2.c line 53
Quoted 5 lines
virt/kvm/arm/vgic/vgic-v2.c new file +5
-0+WARN_ON (cpuif->vgic_lr[lr] &GICH_LR_STATE ); + +kvm_notify_acked_irq (vcpu->kvm,0 , + intid -VGIC_NR_PRIVATE_IRQS ); +why do we need to do this? I cannot find any consumers of this info after we've left the hyp code.
Quoted 2 lines
I believe that's for vhost and irqfd. Or am I misreading your question?
I meant the setting of the bits in
vgic_elrsr(sorry, badly placed comment)...Quoted 13 lines
Quoted 3 lines
Also, I think I offered a comment about why we would potentially need this in the first place. This is the famous race where hardware doesn't guarantee consistency between the MISR and ELRSR right?
That's the one (except it is between EISR and ELRSR). I don't have your initial comment at hand, but would something like the following do?
/*
* The maintenance interrupt may not have had a
* chance to update ELRSR, so let's mark the LRs
* presents in EISR as empty.
*/Quoted 1 line
Quoted 3 lines
Quoted 1 line
Quoted 1 line
virt/kvm/arm/vgic/vgic-v2.c line 54
Quoted 1 line
virt/kvm/arm/vgic/vgic-v2.c new file +1
-0+ cpuif->vgic_elrsr |=1ULL << lr;so, why are we doing this?
Ah! I finally see what you mean: we don't reuse LRs at all with the new code base, so knowing which LR is empty is irrelevant. In which case, something like that should be done:
virt/kvm/arm/vgic/vgic-v2.c +0
-2@@ -52,8 +52,6 @@ void vgic_v2_process_maintenance(struct kvm_vcpu *vcpu)kvm_notify_acked_irq (vcpu->kvm,0 , intid -VGIC_NR_PRIVATE_IRQS ); - - cpuif->vgic_elrsr |=1ULL << lr; } }virt/kvm/arm/vgic/vgic-v3.c +0
-2@@ -43,8 +43,6 @@ void vgic_v3_process_maintenance(struct kvm_vcpu *vcpu)kvm_notify_acked_irq (vcpu->kvm,0 , intid -VGIC_NR_PRIVATE_IRQS ); - - cpuif->vgic_elrsr |=1ULL << lr; }
Quoted 8 lines
Quoted 3 lines
virt/kvm/arm/vgic/vgic-v3.c +0
-0/* I'll give it a spin, just to be safe.
Seems OK on GICv2, and this of course leads to some more possible cleanups or optimizations (I think we can get to a state where we completely disregards ELRSR). I'll have a look.
should be possible. Eventually I was thinking if we really need EISR as well? Could we not deduct that if we have an incative LR from a struct vgic_irq that is CONFIG_LEVEL where we wrote the LR to either pending/active on entry, then an EOI has happened and we should signal the kvm_notify_acked_irq()...
-Christoffer
Re: [PATCH v3 18/55] KVM: arm/arm64: vgic-new: Add GICv2 world switch backend
In reply to Andre PrzywaraQuoted 86 lines · Andre Przywara
From: Marc Zyngier <[email protected]>
Processing maintenance interrupts and accessing the list registers are dependent on the host's GIC version.
Introducevgic-v2.cto contain GICv2 specific functions. Implement the GICv2 specific code for syncing the emulation state into the VGIC registers.Signed-off-by Marc Zyngier <[email protected]>Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Eric Auger <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- remove explicitLR_STATEclearing on maintenance interrupt handling
- improve documentation forvgic_v2_populate_lr()
- removeWARN_ONon non-edge IRQs in maintenance interrupts
- simplify multi-CPU source SGI handlingChangelog v1 .. v2:
- inject the IRQ priority into the list registerChangelog v2 .. v3:
- cleanup diff containing rebase artifactsinclude/linux/irqchip/arm-gic.h | 1 + virt/kvm/arm/vgic/vgic-v2.c | 178 ++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.c | 6 ++ virt/kvm/arm/vgic/vgic.h | 6 ++ 4 files changed, 191 insertions(+) create mode 100644 virt/kvm/arm/vgic/vgic-v2.cinclude/linux/irqchip/arm-gic.h +1
-0@@ -76,6 +76,7 @@#define GICH_LR_VIRTUALID (0x3ff << 0)#define GICH_LR_PHYSID_CPUID_SHIFT (10)#define GICH_LR_PHYSID_CPUID (0x3ff << GICH_LR_PHYSID_CPUID_SHIFT) +#define GICH_LR_PRIORITY_SHIFT 23#define GICH_LR_STATE (3 << 28)#define GICH_LR_PENDING_BIT (1 << 28)#define GICH_LR_ACTIVE_BIT (1 << 29)virt/kvm/arm/vgic/vgic-v2.c new file +36
-0@@ -0,0 +1,178 @@ +/* +* 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; +} +
virt/kvm/arm/vgic/vgic-v2.c line 46
Quoted 10 lines
virt/kvm/arm/vgic/vgic-v2.c new file +10
-0+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) {
Didn't we say we could use vcpu->arch.vgic_cpu.used_lrs here?
virt/kvm/arm/vgic/vgic-v2.c line 58
Quoted 12 lines
virt/kvm/arm/vgic/vgic-v2.c new file +12
-0+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 */
check?
Besides
Eric
Quoted 172 lines
virt/kvm/arm/vgic/vgic-v2.c new file +120
-0+ 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 ; + } + +/* The GICv2 LR only holds five bits of priority. */ + val |= (irq->priority >>3 ) <<GICH_LR_PRIORITY_SHIFT ; + + 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 +6
-0@@ -397,10 +397,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. */ @@ -409,14 +411,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)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
Re: [PATCH v3 18/55] KVM: arm/arm64: vgic-new: Add GICv2 world switch backend
Hi,
Quoted 90 lines · Eric Auger
Quoted 89 lines · Andre Przywara
From: Marc Zyngier <[email protected]>
Processing maintenance interrupts and accessing the list registers are dependent on the host's GIC version.
Introducevgic-v2.cto contain GICv2 specific functions. Implement the GICv2 specific code for syncing the emulation state into the VGIC registers.Signed-off-by Marc Zyngier <[email protected]>Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Eric Auger <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- remove explicitLR_STATEclearing on maintenance interrupt handling
- improve documentation forvgic_v2_populate_lr()
- removeWARN_ONon non-edge IRQs in maintenance interrupts
- simplify multi-CPU source SGI handlingChangelog v1 .. v2:
- inject the IRQ priority into the list registerChangelog v2 .. v3:
- cleanup diff containing rebase artifactsinclude/linux/irqchip/arm-gic.h | 1 + virt/kvm/arm/vgic/vgic-v2.c | 178 ++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.c | 6 ++ virt/kvm/arm/vgic/vgic.h | 6 ++ 4 files changed, 191 insertions(+) create mode 100644 virt/kvm/arm/vgic/vgic-v2.cinclude/linux/irqchip/arm-gic.h +1
-0@@ -76,6 +76,7 @@#define GICH_LR_VIRTUALID (0x3ff << 0)#define GICH_LR_PHYSID_CPUID_SHIFT (10)#define GICH_LR_PHYSID_CPUID (0x3ff << GICH_LR_PHYSID_CPUID_SHIFT) +#define GICH_LR_PRIORITY_SHIFT 23#define GICH_LR_STATE (3 << 28)#define GICH_LR_PENDING_BIT (1 << 28)#define GICH_LR_ACTIVE_BIT (1 << 29)virt/kvm/arm/vgic/vgic-v2.c new file +39
-0@@ -0,0 +1,178 @@ +/* +* 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;
Quoted 8 lines
virt/kvm/arm/vgic/vgic-v2.c line 46
Quoted 7 lines
virt/kvm/arm/vgic/vgic-v2.c new file +7
-0+ +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) {Didn't we say we could use
vcpu->arch.vgic_cpu.used_lrshere?
Why would that be useful? Don't we just want to see those LRs that had a maintenance interrupt received? I don't see the point if iterating over the used LRs, where we need to check for this condition somehow manually? Or what am I missing here?
Quoted 8 lines
virt/kvm/arm/vgic/vgic-v2.c line 54
Quoted 8 lines
virt/kvm/arm/vgic/vgic-v2.c new file +8
-0+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;
So are we good with removing this line (and the respective one in v3)?
Cheers,
Andre.
Quoted 183 lines
virt/kvm/arm/vgic/vgic-v2.c line 58
Quoted 4 lines
virt/kvm/arm/vgic/vgic-v2.c new file +4
-0+ } + } + +/* check and disable underflow maintenance IRQ */ check?
Besides
Reviewed-by Eric Auger <[email protected]>Eric
Quoted 172 lines
virt/kvm/arm/vgic/vgic-v2.c new file +120
-0+ 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 ; + } + +/* The GICv2 LR only holds five bits of priority. */ + val |= (irq->priority >>3 ) <<GICH_LR_PRIORITY_SHIFT ; + + 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 +6
-0@@ -397,10 +397,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. */ @@ -409,14 +411,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)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
Re: [PATCH v3 18/55] KVM: arm/arm64: vgic-new: Add GICv2 world switch backend
Quoted 102 lines · Andre Przywara
Hi,
Quoted 90 lines · Eric Auger
Quoted 89 lines · Andre Przywara
From: Marc Zyngier <[email protected]>
Processing maintenance interrupts and accessing the list registers are dependent on the host's GIC version.
Introducevgic-v2.cto contain GICv2 specific functions. Implement the GICv2 specific code for syncing the emulation state into the VGIC registers.Signed-off-by Marc Zyngier <[email protected]>Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Eric Auger <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- remove explicitLR_STATEclearing on maintenance interrupt handling
- improve documentation forvgic_v2_populate_lr()
- removeWARN_ONon non-edge IRQs in maintenance interrupts
- simplify multi-CPU source SGI handlingChangelog v1 .. v2:
- inject the IRQ priority into the list registerChangelog v2 .. v3:
- cleanup diff containing rebase artifactsinclude/linux/irqchip/arm-gic.h | 1 + virt/kvm/arm/vgic/vgic-v2.c | 178 ++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.c | 6 ++ virt/kvm/arm/vgic/vgic.h | 6 ++ 4 files changed, 191 insertions(+) create mode 100644 virt/kvm/arm/vgic/vgic-v2.cinclude/linux/irqchip/arm-gic.h +1
-0@@ -76,6 +76,7 @@#define GICH_LR_VIRTUALID (0x3ff << 0)#define GICH_LR_PHYSID_CPUID_SHIFT (10)#define GICH_LR_PHYSID_CPUID (0x3ff << GICH_LR_PHYSID_CPUID_SHIFT) +#define GICH_LR_PRIORITY_SHIFT 23#define GICH_LR_STATE (3 << 28)#define GICH_LR_PENDING_BIT (1 << 28)#define GICH_LR_ACTIVE_BIT (1 << 29)virt/kvm/arm/vgic/vgic-v2.c new file +39
-0@@ -0,0 +1,178 @@ +/* +* 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;Quoted 8 lines
virt/kvm/arm/vgic/vgic-v2.c line 46
Quoted 7 lines
virt/kvm/arm/vgic/vgic-v2.c new file +7
-0+ +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) {Didn't we say we could use
vcpu->arch.vgic_cpu.used_lrshere?
Quoted 4 lines
Why would that be useful? Don't we just want to see those LRs that had a maintenance interrupt received? I don't see the point if iterating over the used LRs, where we need to check for this condition somehow manually? Or what am I missing here?
Well I thought that there is no use inspecting bits corresponding to unused LRs, no?
Cheers
Eric
Quoted 198 lines
Quoted 9 lines
virt/kvm/arm/vgic/vgic-v2.c line 54
Quoted 9 lines
virt/kvm/arm/vgic/vgic-v2.c new file +8
-0+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;So are we good with removing this line (and the respective one in v3)?
Cheers,
Andre.Quoted 183 lines
virt/kvm/arm/vgic/vgic-v2.c line 58
Quoted 4 lines
virt/kvm/arm/vgic/vgic-v2.c new file +4
-0+ } + } + +/* check and disable underflow maintenance IRQ */ check?
Besides
Reviewed-by Eric Auger <[email protected]>Eric
Quoted 172 lines
virt/kvm/arm/vgic/vgic-v2.c new file +120
-0+ 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 ; + } + +/* The GICv2 LR only holds five bits of priority. */ + val |= (irq->priority >>3 ) <<GICH_LR_PRIORITY_SHIFT ; + + 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 +6
-0@@ -397,10 +397,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. */ @@ -409,14 +411,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)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
Re: [PATCH v3 18/55] KVM: arm/arm64: vgic-new: Add GICv2 world switch backend
Hi,
Quoted 103 lines · Eric Auger
Quoted 102 lines · Andre Przywara
Hi,
Quoted 98 lines · Eric Auger
Quoted 86 lines · Andre Przywara
From: Marc Zyngier <[email protected]>
Processing maintenance interrupts and accessing the list registers are dependent on the host's GIC version.
Introducevgic-v2.cto contain GICv2 specific functions. Implement the GICv2 specific code for syncing the emulation state into the VGIC registers.Signed-off-by Marc Zyngier <[email protected]>Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Eric Auger <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- remove explicitLR_STATEclearing on maintenance interrupt handling
- improve documentation forvgic_v2_populate_lr()
- removeWARN_ONon non-edge IRQs in maintenance interrupts
- simplify multi-CPU source SGI handlingChangelog v1 .. v2:
- inject the IRQ priority into the list registerChangelog v2 .. v3:
- cleanup diff containing rebase artifactsinclude/linux/irqchip/arm-gic.h | 1 + virt/kvm/arm/vgic/vgic-v2.c | 178 ++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.c | 6 ++ virt/kvm/arm/vgic/vgic.h | 6 ++ 4 files changed, 191 insertions(+) create mode 100644 virt/kvm/arm/vgic/vgic-v2.cinclude/linux/irqchip/arm-gic.h +1
-0@@ -76,6 +76,7 @@#define GICH_LR_VIRTUALID (0x3ff << 0)#define GICH_LR_PHYSID_CPUID_SHIFT (10)#define GICH_LR_PHYSID_CPUID (0x3ff << GICH_LR_PHYSID_CPUID_SHIFT) +#define GICH_LR_PRIORITY_SHIFT 23#define GICH_LR_STATE (3 << 28)#define GICH_LR_PENDING_BIT (1 << 28)#define GICH_LR_ACTIVE_BIT (1 << 29)virt/kvm/arm/vgic/vgic-v2.c new file +36
-0@@ -0,0 +1,178 @@ +/* +* 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; +} +virt/kvm/arm/vgic/vgic-v2.c line 46
Quoted 10 lines
virt/kvm/arm/vgic/vgic-v2.c new file +10
-0+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) {Didn't we say we could use
vcpu->arch.vgic_cpu.used_lrshere?
Quoted 7 lines
Quoted 4 lines
Why would that be useful? Don't we just want to see those LRs that had a maintenance interrupt received? I don't see the point if iterating over the used LRs, where we need to check for this condition somehow manually? Or what am I missing here?
Well I thought that there is no use inspecting bits corresponding to unused LRs, no?
Mmh, maybe I got something wrong here, but this bitmap is supposedly having only one bit set most of the time, also it points us to every LR that we need to take care of. So it will never set bits for unused LRs. By iterating over every used LR on the other hand we would touch LRs that don't need servicing in this function, also the WARN_ON had to go then (as we may touch EOIed IRQs).
Do you agree?
Cheers,
Andre.
Quoted 203 lines
Cheers
Eric
Quoted 198 lines
Quoted 9 lines
virt/kvm/arm/vgic/vgic-v2.c line 54
Quoted 9 lines
virt/kvm/arm/vgic/vgic-v2.c new file +8
-0+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;So are we good with removing this line (and the respective one in v3)?
Cheers,
Andre.Quoted 183 lines
virt/kvm/arm/vgic/vgic-v2.c line 58
Quoted 4 lines
virt/kvm/arm/vgic/vgic-v2.c new file +4
-0+ } + } + +/* check and disable underflow maintenance IRQ */ check?
Besides
Reviewed-by Eric Auger <[email protected]>Eric
Quoted 172 lines
virt/kvm/arm/vgic/vgic-v2.c new file +120
-0+ 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 ; + } + +/* The GICv2 LR only holds five bits of priority. */ + val |= (irq->priority >>3 ) <<GICH_LR_PRIORITY_SHIFT ; + + 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 +6
-0@@ -397,10 +397,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. */ @@ -409,14 +411,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)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
Re: [PATCH v3 18/55] KVM: arm/arm64: vgic-new: Add GICv2 world switch backend
In reply to Andre PrzywaraQuoted 102 lines · Andre Przywara
Hi,
Quoted 90 lines · Eric Auger
Quoted 89 lines · Andre Przywara
From: Marc Zyngier <[email protected]>
Processing maintenance interrupts and accessing the list registers are dependent on the host's GIC version.
Introducevgic-v2.cto contain GICv2 specific functions. Implement the GICv2 specific code for syncing the emulation state into the VGIC registers.Signed-off-by Marc Zyngier <[email protected]>Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Eric Auger <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- remove explicitLR_STATEclearing on maintenance interrupt handling
- improve documentation forvgic_v2_populate_lr()
- removeWARN_ONon non-edge IRQs in maintenance interrupts
- simplify multi-CPU source SGI handlingChangelog v1 .. v2:
- inject the IRQ priority into the list registerChangelog v2 .. v3:
- cleanup diff containing rebase artifactsinclude/linux/irqchip/arm-gic.h | 1 + virt/kvm/arm/vgic/vgic-v2.c | 178 ++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.c | 6 ++ virt/kvm/arm/vgic/vgic.h | 6 ++ 4 files changed, 191 insertions(+) create mode 100644 virt/kvm/arm/vgic/vgic-v2.cinclude/linux/irqchip/arm-gic.h +1
-0@@ -76,6 +76,7 @@#define GICH_LR_VIRTUALID (0x3ff << 0)#define GICH_LR_PHYSID_CPUID_SHIFT (10)#define GICH_LR_PHYSID_CPUID (0x3ff << GICH_LR_PHYSID_CPUID_SHIFT) +#define GICH_LR_PRIORITY_SHIFT 23#define GICH_LR_STATE (3 << 28)#define GICH_LR_PENDING_BIT (1 << 28)#define GICH_LR_ACTIVE_BIT (1 << 29)virt/kvm/arm/vgic/vgic-v2.c new file +39
-0@@ -0,0 +1,178 @@ +/* +* 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;Quoted 8 lines
virt/kvm/arm/vgic/vgic-v2.c line 46
Quoted 7 lines
virt/kvm/arm/vgic/vgic-v2.c new file +7
-0+ +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) {Didn't we say we could use
vcpu->arch.vgic_cpu.used_lrshere?
Quoted 4 lines
Why would that be useful? Don't we just want to see those LRs that had a maintenance interrupt received? I don't see the point if iterating over the used LRs, where we need to check for this condition somehow manually? Or what am I missing here?
if we get rid of eisr eventually we can optimize the reading of that away, but I honestly don't think we should be pursuing this straight away.
Quoted 12 lines
Quoted 9 lines
virt/kvm/arm/vgic/vgic-v2.c line 54
Quoted 9 lines
virt/kvm/arm/vgic/vgic-v2.c new file +8
-0+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;So are we good with removing this line (and the respective one in v3)?
Yes.
-Christoffer
Re: [PATCH v3 18/55] KVM: arm/arm64: vgic-new: Add GICv2 world switch backend
Hej,
Quoted 103 lines · Christoffer Dall
Quoted 102 lines · Andre Przywara
Hi,
Quoted 98 lines · Eric Auger
Quoted 86 lines · Andre Przywara
From: Marc Zyngier <[email protected]>
Processing maintenance interrupts and accessing the list registers are dependent on the host's GIC version.
Introducevgic-v2.cto contain GICv2 specific functions. Implement the GICv2 specific code for syncing the emulation state into the VGIC registers.Signed-off-by Marc Zyngier <[email protected]>Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Eric Auger <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- remove explicitLR_STATEclearing on maintenance interrupt handling
- improve documentation forvgic_v2_populate_lr()
- removeWARN_ONon non-edge IRQs in maintenance interrupts
- simplify multi-CPU source SGI handlingChangelog v1 .. v2:
- inject the IRQ priority into the list registerChangelog v2 .. v3:
- cleanup diff containing rebase artifactsinclude/linux/irqchip/arm-gic.h | 1 + virt/kvm/arm/vgic/vgic-v2.c | 178 ++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.c | 6 ++ virt/kvm/arm/vgic/vgic.h | 6 ++ 4 files changed, 191 insertions(+) create mode 100644 virt/kvm/arm/vgic/vgic-v2.cinclude/linux/irqchip/arm-gic.h +1
-0@@ -76,6 +76,7 @@#define GICH_LR_VIRTUALID (0x3ff << 0)#define GICH_LR_PHYSID_CPUID_SHIFT (10)#define GICH_LR_PHYSID_CPUID (0x3ff << GICH_LR_PHYSID_CPUID_SHIFT) +#define GICH_LR_PRIORITY_SHIFT 23#define GICH_LR_STATE (3 << 28)#define GICH_LR_PENDING_BIT (1 << 28)#define GICH_LR_ACTIVE_BIT (1 << 29)virt/kvm/arm/vgic/vgic-v2.c new file +36
-0@@ -0,0 +1,178 @@ +/* +* 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; +} +virt/kvm/arm/vgic/vgic-v2.c line 46
Quoted 10 lines
virt/kvm/arm/vgic/vgic-v2.c new file +10
-0+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) {Didn't we say we could use
vcpu->arch.vgic_cpu.used_lrshere?
Quoted 8 lines
Quoted 4 lines
Why would that be useful? Don't we just want to see those LRs that had a maintenance interrupt received? I don't see the point if iterating over the used LRs, where we need to check for this condition somehow manually? Or what am I missing here?
if we get rid of eisr eventually we can optimize the reading of that away, but I honestly don't think we should be pursuing this straight away.
Yes, I realized that too when I tried to change the code. But then we would need to somehow check for that condition anyway? Whereas right now the hardware points us exactly to the LRs that need servicing?
Or am I confused about the meaning of the EISR bitmap?
And I agree that this possible optimization is something we should keep for later. I guess we get plenty of opportunity once we remove the old VGIC.
Cheers,
Andre.
PATCH v3 19/55 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.
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
Changelog v1 .. v2:
- inject the IRQ priority into the list register
Changelog v2 .. v3:
- remove no longer needed irqchip/arm-gic.h inclusion
include/linux/irqchip/arm-gic-v3.h | 1 + virt/kvm/arm/vgic/vgic-v3.c | 168 +++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.c | 25 ++++-- virt/kvm/arm/vgic/vgic.h | 29 +++++++ 4 files changed, 218 insertions(+), 5 deletions(-) create mode 100644 virt/kvm/arm/vgic/vgic-v3.c
include/linux/irqchip/arm-gic-v3.h +1 -0
@@ -275,6 +275,7 @@#define ICH_LR_ACTIVE_BIT (1ULL << 63)#define ICH_LR_PHYS_ID_SHIFT 32#define ICH_LR_PHYS_ID_MASK (0x3ffULL << ICH_LR_PHYS_ID_SHIFT) +#define ICH_LR_PRIORITY_SHIFT 48/* These are for GICv2 emulation only */ #define GICH_LR_VIRTUALID (0x3ffUL << 0)
virt/kvm/arm/vgic/vgic-v3.c new file +168 -0
168 lines not on this page · raw message
virt/kvm/arm/vgic/vgic.c +20 -5
@@ -397,12 +397,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. */
@@ -412,17 +418,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
Re: [PATCH v3 19/55] KVM: arm/arm64: vgic-new: Add GICv3 world switch backend
Quoted 45 lines · Andre Przywara
From: 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.
Implement the respective handler functions and connect them to existing code to be called if the host is using a GICv3.Signed-off-by Marc Zyngier <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- remove outdated comment about thedist_lock
- addWARN_ONaboutLR_STATEnot being 0 in maintenance interruptsChangelog v1 .. v2:
- inject the IRQ priority into the list registerChangelog v2 .. v3:
- remove no longer neededirqchip/arm-gic.hinclusioninclude/linux/irqchip/arm-gic-v3.h | 1 + virt/kvm/arm/vgic/vgic-v3.c | 168 +++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.c | 25 ++++-- virt/kvm/arm/vgic/vgic.h | 29 +++++++ 4 files changed, 218 insertions(+), 5 deletions(-)create mode 100644
virt/kvm/arm/vgic/vgic-v3.cinclude/linux/irqchip/arm-gic-v3.h +1
-0@@ -275,6 +275,7 @@#define ICH_LR_ACTIVE_BIT (1ULL << 63)#define ICH_LR_PHYS_ID_SHIFT 32#define ICH_LR_PHYS_ID_MASK (0x3ffULL << ICH_LR_PHYS_ID_SHIFT) +#define ICH_LR_PRIORITY_SHIFT 48/* These are for GICv2 emulation only */ #define GICH_LR_VIRTUALID (0x3ffUL << 0)virt/kvm/arm/vgic/vgic-v3.c new file +0
-0
...
virt/kvm/arm/vgic/vgic-v3.c line 73
Quoted 7 lines
virt/kvm/arm/vgic/vgic-v3.c new file +7
-0+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 */
If truly required that ap_list_lock already be locked, then the code should enforce it. At least in dev mode. Maybe:
DEBUG_SPINLOCK_BUG_ON(!spin_is_locked(&vcpu->ap_list_lock));
...
virt/kvm/arm/vgic/vgic-v3.c line 117
Quoted 2 lines
virt/kvm/arm/vgic/vgic-v3.c new file +2
-0+/* Requires the irq to be locked already */ +void vgic_v3_populate_lr (struct kvm_vcpu *vcpu,struct vgic_irq *irq,int lr)
Similarly, if required then the code should enforce it.
DEBUG_SPINLOCK_BUG_ON(!spin_is_locked(&irq->irq_lock));
...
Re: [PATCH v3 19/55] KVM: arm/arm64: vgic-new: Add GICv3 world switch backend
In reply to Andre PrzywaraQuoted 79 lines · Andre Przywara
From: 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.
Implement the respective handler functions and connect them to existing code to be called if the host is using a GICv3.Signed-off-by Marc Zyngier <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- remove outdated comment about thedist_lock
- addWARN_ONaboutLR_STATEnot being 0 in maintenance interruptsChangelog v1 .. v2:
- inject the IRQ priority into the list registerChangelog v2 .. v3:
- remove no longer neededirqchip/arm-gic.hinclusioninclude/linux/irqchip/arm-gic-v3.h | 1 + virt/kvm/arm/vgic/vgic-v3.c | 168 +++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.c | 25 ++++-- virt/kvm/arm/vgic/vgic.h | 29 +++++++ 4 files changed, 218 insertions(+), 5 deletions(-) create mode 100644 virt/kvm/arm/vgic/vgic-v3.cinclude/linux/irqchip/arm-gic-v3.h +1
-0@@ -275,6 +275,7 @@#define ICH_LR_ACTIVE_BIT (1ULL << 63)#define ICH_LR_PHYS_ID_SHIFT 32#define ICH_LR_PHYS_ID_MASK (0x3ffULL << ICH_LR_PHYS_ID_SHIFT) +#define ICH_LR_PRIORITY_SHIFT 48/* These are for GICv2 emulation only */ #define GICH_LR_VIRTUALID (0x3ffUL << 0)virt/kvm/arm/vgic/vgic-v3.c new file +33
-0@@ -0,0 +1,168 @@ +/* +* 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 "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]; +
virt/kvm/arm/vgic/vgic-v3.c line 43
Quoted 10 lines
virt/kvm/arm/vgic/vgic-v3.c new file +10
-0+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 ); +
same question as on the last patch
Quoted 100 lines
virt/kvm/arm/vgic/vgic-v3.c new file +100
-0+ 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) {
virt/kvm/arm/vgic/vgic-v3.c line 153
Quoted 10 lines
virt/kvm/arm/vgic/vgic-v3.c new file +10
-0+ 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.
I still don't like or understand this comment. This should simply say that we're making a gross assumption about all interrupts being group1 here.
Quoted 111 lines
virt/kvm/arm/vgic/vgic-v3.c new file +15
-0+* 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 ; + + val |= (u64 )irq->priority <<ICH_LR_PRIORITY_SHIFT ; + + 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@@ -397,12 +397,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. */ @@ -412,17 +418,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
Otherwise:
Re: [PATCH v3 19/55] KVM: arm/arm64: vgic-new: Add GICv3 world switch backend
Quoted 8 lines · Christoffer Dall
virt/kvm/arm/vgic/vgic-v3.c line 153
Quoted 3 lines · Andre Przywara
virt/kvm/arm/vgic/vgic-v3.c new file +3
-0+/* +* Currently all guest IRQs are Group1, as Group0 would result +* in a FIQ in the guest, which it wouldn't expect. I still don't like or understand this comment. This should simply say that we're making a gross assumption about all interrupts being group1 here.
It's not really an assumption so much as it's a missing feature (aka bug):
there's no reason the vGIC shouldn't support group 0 interrupts. We just get away with only supporting group 1 because Linux guests happen to only use group 1 interrupts. If/when the vGIC gains support for group0 interrupts, then it should reset with interrupts configured in group0 by default.
Quoted 3 lines
virt/kvm/arm/vgic/vgic-v3.c line 156
Quoted 3 lines
virt/kvm/arm/vgic/vgic-v3.c new file +3
-0+* Eventually we want to make this configurable, so we may +* revisit this in the future. +*/
The only reason to make it configurable is to work around a guest kernel bug whereby Linux assumes that all interrupts start out in Group1. Marc sent out a patch earlier today that fixes that bug:
https://lkml.org/lkml/2016/5/10/297
Depending on how long it takes you to fix this missing vgic feature, such kernels may all be long-forgotten, in which case you can get away without the config option :-)
thanks
-- PMM
Re: [PATCH v3 19/55] KVM: arm/arm64: vgic-new: Add GICv3 world switch backend
Quoted 21 lines · Peter Maydell
Quoted 8 lines · Christoffer Dall
virt/kvm/arm/vgic/vgic-v3.c line 153
Quoted 3 lines · Andre Przywara
virt/kvm/arm/vgic/vgic-v3.c new file +3
-0+/* +* Currently all guest IRQs are Group1, as Group0 would result +* in a FIQ in the guest, which it wouldn't expect. I still don't like or understand this comment. This should simply say that we're making a gross assumption about all interrupts being group1 here.
It's not really an assumption so much as it's a missing feature (aka bug):
there's no reason the vGIC shouldn't support group 0 interrupts. We just get away with only supporting group 1 because Linux guests happen to only use group 1 interrupts. If/when the vGIC gains support for group0 interrupts, then it should reset with interrupts configured in group0 by default.Quoted 3 lines
virt/kvm/arm/vgic/vgic-v3.c line 156
Quoted 3 lines
virt/kvm/arm/vgic/vgic-v3.c new file +3
-0+* Eventually we want to make this configurable, so we may +* revisit this in the future. +*/
Quoted 7 lines
The only reason to make it configurable is to work around a guest kernel bug whereby Linux assumes that all interrupts start out in Group1. Marc sent out a patch earlier today that fixes that bug:
https://lkml.org/lkml/2016/5/10/297
Depending on how long it takes you to fix this missing vgic feature, such kernels may all be long-forgotten, in which case you can get away without the config option :-)
I've CC'd stable for this particular patch, so hopefully we won't have to make it configurable as people will diligently update their kernels... I also have a patch for handling both groups in KVM, but I'll hold onto it until we have something we agree on for the bulk of the code.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH v3 19/55] KVM: arm/arm64: vgic-new: Add GICv3 world switch backend
In reply to Peter MaydellQuoted 21 lines · Peter Maydell
Quoted 8 lines · Christoffer Dall
virt/kvm/arm/vgic/vgic-v3.c line 153
Quoted 3 lines · Andre Przywara
virt/kvm/arm/vgic/vgic-v3.c new file +3
-0+/* +* Currently all guest IRQs are Group1, as Group0 would result +* in a FIQ in the guest, which it wouldn't expect. I still don't like or understand this comment. This should simply say that we're making a gross assumption about all interrupts being group1 here.
It's not really an assumption so much as it's a missing feature (aka bug):
there's no reason the vGIC shouldn't support group 0 interrupts. We just get away with only supporting group 1 because Linux guests happen to only use group 1 interrupts. If/when the vGIC gains support for group0 interrupts, then it should reset with interrupts configured in group0 by default.Quoted 3 lines
virt/kvm/arm/vgic/vgic-v3.c line 156
Quoted 3 lines
virt/kvm/arm/vgic/vgic-v3.c new file +3
-0+* Eventually we want to make this configurable, so we may +* revisit this in the future. +*/
Quoted 8 lines
The only reason to make it configurable is to work around a guest kernel bug whereby Linux assumes that all interrupts start out in Group1. Marc sent out a patch earlier today that fixes that bug:
https://lkml.org/lkml/2016/5/10/297
Depending on how long it takes you to fix this missing vgic feature, such kernels may all be long-forgotten, in which case you can get away without the config option :-)
Agreed with all of the above. My nit here is simply that if we don't implement grouping support now, then it's just a gross hack, and we should just state that until we fix it properly.
-Christoffer
Re: [PATCH v3 19/55] KVM: arm/arm64: vgic-new: Add GICv3 world switch backend
In reply to Andre PrzywaraQuoted 66 lines · Andre Przywara
From: 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.
Implement the respective handler functions and connect them to existing code to be called if the host is using a GICv3.Signed-off-by Marc Zyngier <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- remove outdated comment about thedist_lock
- addWARN_ONaboutLR_STATEnot being 0 in maintenance interruptsChangelog v1 .. v2:
- inject the IRQ priority into the list registerChangelog v2 .. v3:
- remove no longer neededirqchip/arm-gic.hinclusioninclude/linux/irqchip/arm-gic-v3.h | 1 + virt/kvm/arm/vgic/vgic-v3.c | 168 +++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.c | 25 ++++-- virt/kvm/arm/vgic/vgic.h | 29 +++++++ 4 files changed, 218 insertions(+), 5 deletions(-) create mode 100644 virt/kvm/arm/vgic/vgic-v3.cinclude/linux/irqchip/arm-gic-v3.h +1
-0@@ -275,6 +275,7 @@#define ICH_LR_ACTIVE_BIT (1ULL << 63)#define ICH_LR_PHYS_ID_SHIFT 32#define ICH_LR_PHYS_ID_MASK (0x3ffULL << ICH_LR_PHYS_ID_SHIFT) +#define ICH_LR_PRIORITY_SHIFT 48/* These are for GICv2 emulation only */ #define GICH_LR_VIRTUALID (0x3ffUL << 0)virt/kvm/arm/vgic/vgic-v3.c new file +20
-0@@ -0,0 +1,168 @@ +/* +* 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 "vgic.h" +
virt/kvm/arm/vgic/vgic-v3.c line 30
Quoted 10 lines
virt/kvm/arm/vgic/vgic-v3.c new file +10
-0+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) {
used_lrs?
Quoted 33 lines
virt/kvm/arm/vgic/vgic-v3.c new file +33
-0+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; +
virt/kvm/arm/vgic/vgic-v3.c line 73
Quoted 10 lines
virt/kvm/arm/vgic/vgic-v3.c new file +10
-0+ 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 */
I don't think there is such requirement and failed finding the lock held.
Besides Reviewed-by: Eric Auger <[email protected]>
Eric
Quoted 189 lines
virt/kvm/arm/vgic/vgic-v3.c new file +95
-0+ +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 ; + + val |= (u64 )irq->priority <<ICH_LR_PRIORITY_SHIFT ; + + 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@@ -397,12 +397,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. */ @@ -412,17 +418,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
Re: [PATCH v3 19/55] KVM: arm/arm64: vgic-new: Add GICv3 world switch backend
Quoted 70 lines · Eric Auger
Quoted 69 lines · Andre Przywara
From: 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.
Implement the respective handler functions and connect them to existing code to be called if the host is using a GICv3.Signed-off-by Marc Zyngier <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- remove outdated comment about thedist_lock
- addWARN_ONaboutLR_STATEnot being 0 in maintenance interruptsChangelog v1 .. v2:
- inject the IRQ priority into the list registerChangelog v2 .. v3:
- remove no longer neededirqchip/arm-gic.hinclusioninclude/linux/irqchip/arm-gic-v3.h | 1 + virt/kvm/arm/vgic/vgic-v3.c | 168 +++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic.c | 25 ++++-- virt/kvm/arm/vgic/vgic.h | 29 +++++++ 4 files changed, 218 insertions(+), 5 deletions(-) create mode 100644 virt/kvm/arm/vgic/vgic-v3.cinclude/linux/irqchip/arm-gic-v3.h +1
-0@@ -275,6 +275,7 @@#define ICH_LR_ACTIVE_BIT (1ULL << 63)#define ICH_LR_PHYS_ID_SHIFT 32#define ICH_LR_PHYS_ID_MASK (0x3ffULL << ICH_LR_PHYS_ID_SHIFT) +#define ICH_LR_PRIORITY_SHIFT 48/* These are for GICv2 emulation only */ #define GICH_LR_VIRTUALID (0x3ffUL << 0)virt/kvm/arm/vgic/vgic-v3.c new file +23
-0@@ -0,0 +1,168 @@ +/* +* 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 "vgic.h" + +void vgic_v3_process_maintenance (struct kvm_vcpu *vcpu) +{ +struct vgic_v3_cpu_if *cpuif = &vcpu->arch.vgic_cpu.vgic_v3;
Quoted 8 lines
virt/kvm/arm/vgic/vgic-v3.c line 30
Quoted 7 lines
virt/kvm/arm/vgic/vgic-v3.c new file +7
-0+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) {
used_lrs?
Indeed.
Quoted 36 lines
Quoted 36 lines
virt/kvm/arm/vgic/vgic-v3.c new file +36
-0+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 ; +} +
Quoted 8 lines
virt/kvm/arm/vgic/vgic-v3.c line 73
Quoted 7 lines
virt/kvm/arm/vgic/vgic-v3.c new file +7
-0+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 */ I don't think there is such requirement and failed finding the lock held.
This looks like a leftover from a previous version. Folding the state is done on a per-irq basis, and doesn't require to parse the ap_list.
Quoted 1 line
Besides Reviewed-by: Eric Auger <[email protected]>
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
PATCH v3 20/55 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
Changelog v2 .. v3:
- remove vgic_kick_vcpus() implementation from this patch
include/kvm/vgic/vgic.h | 2 ++ virt/kvm/arm/vgic/vgic.c | 25 +++++++++++++++++++++++++ 2 files changed, 27 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 +25 -0
@@ -519,3 +519,28 @@ 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; +}
Signature · 1 line
2.7.3
Re: [PATCH v3 20/55] KVM: arm/arm64: vgic-new: Implement kvm_vgic_vcpu_pending_irq
Quoted 7 lines · Andre Przywara
From: 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.
Signed-off-by Eric Auger <[email protected]>Signed-off-by Andre Przywara <[email protected]>
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH v3 20/55] KVM: arm/arm64: vgic-new: Implement kvm_vgic_vcpu_pending_irq
In reply to Andre PrzywaraQuoted 7 lines · Andre Przywara
From: 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.
Signed-off-by Eric Auger <[email protected]>Signed-off-by Andre Przywara <[email protected]>
PATCH v3 21/55 KVM: arm/arm64: vgic-new: Add MMIO handling framework
In reply to Andre PrzywaraFrom: Marc Zyngier <[email protected]>
Add an MMIO handling framework to the VGIC emulation:
Each register is described by its offset, size (or number of bits per IRQ, if applicable) and the read/write handler functions. We provide initialization macros to describe each GIC register later easily.
Separate dispatch functions for read and write accesses are connected to the kvm_io_bus framework and binary-search for the responsible register handler based on the offset address within the region. We convert the incoming data (referenced by a pointer) to the host's endianess and use pass-by-value to hand the data over to the actual handler functions.
The register handler prototype and the endianess conversion are courtesy of Christoffer Dall.
---
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)
Changelog v1 .. v2:
* MASSIVE rework:
- store register_region pointer in kvm_io_bus linked struct
- replace write_mask_xxx functions with extract_bytes() implementation
- change handler functions' prototypes to take and return unsigned long
- use binary search to find matching register handler
- convert endianess of input data in dispatch_mmio_xxx functions
- improve readability of register initializer macros
- remove any GICv2/GICv3 specific functions from vgic-mmio.c
- rename file from vgic_mmio.c to vgic-mmio.c
Changelog v2 .. v3:
- replace inclusion of vgic/vgic.h with arm_vgic.h
include/kvm/vgic/vgic.h | 13 ++++ virt/kvm/arm/vgic/vgic-mmio.c | 171 ++++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.h | 77 +++++++++++++++++++ 3 files changed, 261 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 +13 -0
@@ -106,6 +106,16 @@ struct vgic_irq {enum vgic_irq_config config;/* Level or edge */ }; +struct vgic_register_region ; + +struct vgic_io_device { +gpa_t base_addr; +struct kvm_vcpu *redist_vcpu; +const struct vgic_register_region *regions; +int nr_regions; +struct kvm_io_device dev; +}; +struct vgic_dist {bool in_kernel;bool ready;
@@ -132,6 +142,9 @@ struct vgic_dist {bool 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 +171 -0
171 lines not on this page · raw message
virt/kvm/arm/vgic/vgic-mmio.h new file +77 -0
77 lines not on this page · raw message
Signature · 1 line
2.7.3
Re: [PATCH v3 21/55] KVM: arm/arm64: vgic-new: Add MMIO handling framework
Quoted 346 lines · Andre Przywara
From: Marc Zyngier <[email protected]>
Add an MMIO handling framework to the VGIC emulation:
Each register is described by its offset, size (or number of bits per IRQ, if applicable) and the read/write handler functions. We provide initialization macros to describe each GIC register later easily.Separate dispatch functions for read and write accesses are connected to the
kvm_io_busframework and binary-search for the responsible register handler based on the offset address within the region. We convert the incoming data (referenced by a pointer) to the host's endianess and use pass-by-value to hand the data over to the actual handler functions.The register handler prototype and the endianess conversion are courtesy of Christoffer Dall.
Signed-off-by Marc Zyngier <[email protected]>Signed-off-by Christoffer Dall <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- rework MMIO dispatching to use only onekvm_io_busdevice
- document purpose of register region macros
- rename "this" parameter to "dev"
- change IGROUPR to be RAO (returning 1 => Group1 IRQs)Changelog v1 .. v2:
* MASSIVE rework:
- storeregister_regionpointer inkvm_io_buslinked struct
- replacewrite_mask_xxxfunctions withextract_bytes()implementation
- change handler functions' prototypes to take and return unsigned long
- use binary search to find matching register handler
- convert endianess of input data indispatch_mmio_xxxfunctions
- improve readability of register initializer macros
- remove any GICv2/GICv3 specific functions fromvgic-mmio.c
- rename file fromvgic_mmio.ctovgic-mmio.cChangelog v2 .. v3:
- replace inclusion ofvgic/vgic.hwitharm_vgic.hinclude/kvm/vgic/vgic.h | 13 ++++ virt/kvm/arm/vgic/vgic-mmio.c | 171 ++++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.h | 77 +++++++++++++++++++ 3 files changed, 261 insertions(+) create mode 100644 virt/kvm/arm/vgic/vgic-mmio.c create mode 100644 virt/kvm/arm/vgic/vgic-mmio.hinclude/kvm/vgic/vgic.h +13
-0@@ -106,6 +106,16 @@ struct vgic_irq {enum vgic_irq_config config;/* Level or edge */ }; +struct vgic_register_region ; + +struct vgic_io_device { +gpa_t base_addr; +struct kvm_vcpu *redist_vcpu; +const struct vgic_register_region *regions; +int nr_regions; +struct kvm_io_device dev; +}; +struct vgic_dist {bool in_kernel;bool ready;@@ -132,6 +142,9 @@ struct vgic_dist {bool 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 +171
-0@@ -0,0 +1,171 @@ +/* +* VGIC MMIO handling functions +* +* 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. +*/ + +#include <linux/bitops.h> +#include <linux/bsearch.h> +#include <linux/kvm.h> +#include <linux/kvm_host.h> +#include <kvm/iodev.h> +#include <kvm/arm_vgic.h> + +#include "vgic.h" +#include "vgic-mmio.h" + +/* extract @num bytes at @offset bytes offset in data */ +unsigned long extract_bytes (unsigned long data, +unsigned int offset,unsigned int num) +{ +return (data >> (offset *8 )) &GENMASK_ULL (num *8 -1 ,0 ); +} + +unsigned long vgic_mmio_read_raz (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len) +{ +return 0 ; +} + +unsigned long vgic_mmio_read_rao (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len) +{ +return -1UL ; +} + +void vgic_mmio_write_wi (struct kvm_vcpu *vcpu,gpa_t addr, +unsigned int len,unsigned long val) +{ +/* Ignore */ +} + +static int match_region (const void *key,const void *elt) +{ +const unsigned int offset = (unsigned long )key; +const struct vgic_register_region *region = elt; + +if (offset < region->reg_offset) +return -1 ; + +if (offset >= region->reg_offset + region->len) +return 1 ; + +return 0 ; +} + +/* Find the proper register handler entry given a certain address offset. */ +static const struct vgic_register_region * +vgic_find_mmio_region (const struct vgic_register_region *region,int nr_regions, +unsigned int offset) +{ +return bsearch ((void *)(uintptr_t )offset, region, nr_regions, +sizeof (region[0 ]), match_region); +} + +/* +* kvm_mmio_read_buf() returns a value in a format where it can be converted +* to a byte array and be directly observed as the guest wanted it to appear +* in memory if it had done the store itself, which is LE for the GIC, as the +* guest knows the GIC is always LE. +* +* We convert this value to the CPUs native format to deal with it as a data +* value. +*/ +unsigned long vgic_data_mmio_bus_to_host (const void *val,unsigned int len) +{ +unsigned long data =kvm_mmio_read_buf (val, len); + +switch (len) { +case 1 : +return data; +case 2 : +return le16_to_cpu (data); +case 4 : +return le32_to_cpu (data); +default : +return le64_to_cpu (data); + } +} + +/* +* kvm_mmio_write_buf() expects a value in a format such that if converted to +* a byte array it is observed as the guest would see it if it could perform +* the load directly. Since the GIC is LE, and the guest knows this, the +* guest expects a value in little endian format. +* +* We convert the data value from the CPUs native format to LE so that the +* value is returned in the proper format. +*/ +void vgic_data_host_to_mmio_bus (void *buf,unsigned int len, +unsigned long data) +{ +switch (len) { +case 1 : +break ; +case 2 : + data =cpu_to_le16 (data); +break ; +case 4 : + data =cpu_to_le32 (data); +break ; +default : + data =cpu_to_le64 (data); + } + +kvm_mmio_write_buf (buf, len, data); +} + +static +struct vgic_io_device *kvm_to_vgic_iodev (const struct kvm_io_device *dev) +{ + return container_of(dev, struct vgic_io_device, dev); +} + +static int dispatch_mmio_read (struct kvm_vcpu *vcpu,struct kvm_io_device *dev, +gpa_t addr,int len,void *val) +{ +struct vgic_io_device *iodev =kvm_to_vgic_iodev (dev); +const struct vgic_register_region *region; +struct kvm_vcpu *r_vcpu; +unsigned long data; + + region =vgic_find_mmio_region (iodev->regions, iodev->nr_regions, + addr - iodev->base_addr); +if (!region) +return -EOPNOTSUPP ; + + r_vcpu = iodev->redist_vcpu ? iodev->redist_vcpu : vcpu; + data = region->read (r_vcpu, addr, len); +vgic_data_host_to_mmio_bus (val, len, data); +return 0 ; +} + +static int dispatch_mmio_write (struct kvm_vcpu *vcpu,struct kvm_io_device *dev, +gpa_t addr,int len,const void *val) +{ +struct vgic_io_device *iodev =kvm_to_vgic_iodev (dev); +const struct vgic_register_region *region; +struct kvm_vcpu *r_vcpu; +unsigned long data =vgic_data_mmio_bus_to_host (val, len); + + region =vgic_find_mmio_region (iodev->regions, iodev->nr_regions, + addr - iodev->base_addr); +if (!region) +return -EOPNOTSUPP ; + + r_vcpu = iodev->redist_vcpu ? iodev->redist_vcpu : vcpu; + region->write (r_vcpu, addr, len, data); +return 0 ; +} + +struct kvm_io_device_ops kvm_io_gic_ops = { + .read = dispatch_mmio_read, + .write = dispatch_mmio_write, +};virt/kvm/arm/vgic/vgic-mmio.h new file +77
-0@@ -0,0 +1,77 @@ +/* +* 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_MMIO_H__ +#define __KVM_ARM_VGIC_MMIO_H__ + +struct vgic_register_region { +unsigned int reg_offset; +unsigned int len; +unsigned int bits_per_irq; +unsigned long (*read)(struct kvm_vcpu *vcpu,gpa_t addr, +unsigned int len); +void (*write)(struct kvm_vcpu *vcpu,gpa_t addr,unsigned int len, +unsigned long val); +}; + +extern struct kvm_io_device_ops kvm_io_gic_ops; + +/* +* Some VGIC registers store per-IRQ information, with a different number +* of bits per IRQ. For those registers this macro is used. +* The _WITH_LENGTH version instantiates registers with a fixed length +* and is mutually exclusive with the _PER_IRQ version. +*/ +#define REGISTER_DESC_WITH_BITS_PER_IRQ (off, read_ops, write_ops, bpi) \ + { \ + .reg_offset = off, \ + .bits_per_irq = bpi, \ + .len = bpi * 1024 / 8, \ + .read = read_ops, \ + .write = write_ops, \ + } + +#define REGISTER_DESC_WITH_LENGTH (off, read_ops, write_ops, length) \ + { \ + .reg_offset = off, \ + .bits_per_irq = 0, \ + .len = length, \ + .read = read_ops, \ + .write = write_ops, \ + } + +int kvm_vgic_register_mmio_region (struct kvm *kvm,struct kvm_vcpu *vcpu, +struct vgic_register_region *reg_desc, +struct vgic_io_device *region, +int nr_irqs,bool offset_private); + +unsigned long vgic_data_mmio_bus_to_host (const void *val,unsigned int len); + +void vgic_data_host_to_mmio_bus (void *buf,unsigned int len, +unsigned long data); + +unsigned long extract_bytes (unsigned long data, +unsigned int offset,unsigned int num); + +unsigned long vgic_mmio_read_raz (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len); + +unsigned long vgic_mmio_read_rao (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len); + +void vgic_mmio_write_wi (struct kvm_vcpu *vcpu,gpa_t addr, +unsigned int len,unsigned long val); + +#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
PATCH v3 22/55 KVM: arm/arm64: vgic-new: Add GICv2 MMIO handling framework
In reply to Andre PrzywaraCreate vgic-mmio-v2.c to describe GICv2 emulation specific handlers using the initializer macros provided by the VGIC MMIO framework. Provide a function to register the GICv2 distributor registers to the kvm_io_bus framework.
The actual handler functions are still stubs in this patch.
---
Changelog v1 .. v2:
- new patch, split out from the generic MMIO framework patch
- use a separate file to hold GICv2 emulation specific handlers
- replace _nyi stub functions with raz/wi versions
Changelog v2 .. v3:
- replace kvm/vgic/vgic.h with kvm/arm_vgic.h
- add vgic_register_dist_iodev() prototype
virt/kvm/arm/vgic/vgic-mmio-v2.c | 62 ++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.c | 26 +++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.h | 2 ++ virt/kvm/arm/vgic/vgic.h | 2 ++ 4 files changed, 92 insertions(+) create mode 100644 virt/kvm/arm/vgic/vgic-mmio-v2.c
virt/kvm/arm/vgic/vgic-mmio-v2.c new file +62 -0
@@ -0,0 +1,62 @@ +/* +* VGICv2 MMIO handling functions +* +* 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. +*/ + +#include <linux/irqchip/arm-gic.h> +#include <linux/kvm.h> +#include <linux/kvm_host.h> +#include <kvm/iodev.h> +#include <kvm/arm_vgic.h> + +#include "vgic.h" +#include "vgic-mmio.h" + +static const struct vgic_register_region vgic_v2_dist_registers[] = { +REGISTER_DESC_WITH_LENGTH (GIC_DIST_CTRL , + vgic_mmio_read_raz, vgic_mmio_write_wi,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_raz, vgic_mmio_write_wi,1 ), +REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_ENABLE_CLEAR , + vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), +REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_PENDING_SET , + vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), +REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_PENDING_CLEAR , + vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), +REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_ACTIVE_SET , + vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), +REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_ACTIVE_CLEAR , + vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), +REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_PRI , + vgic_mmio_read_raz, vgic_mmio_write_wi,8 ), +REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_TARGET , + vgic_mmio_read_raz, vgic_mmio_write_wi,8 ), +REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_CONFIG , + vgic_mmio_read_raz, vgic_mmio_write_wi,2 ), +REGISTER_DESC_WITH_LENGTH (GIC_DIST_SOFTINT , + vgic_mmio_read_raz, vgic_mmio_write_wi,4 ), +REGISTER_DESC_WITH_LENGTH (GIC_DIST_SGI_PENDING_CLEAR , + vgic_mmio_read_raz, vgic_mmio_write_wi,16 ), +REGISTER_DESC_WITH_LENGTH (GIC_DIST_SGI_PENDING_SET , + vgic_mmio_read_raz, vgic_mmio_write_wi,16 ), +}; + +unsigned int vgic_v2_init_dist_iodev (struct vgic_io_device *dev) +{ + dev->regions = vgic_v2_dist_registers; + dev->nr_regions =ARRAY_SIZE (vgic_v2_dist_registers); + +kvm_iodevice_init (&dev->dev, &kvm_io_gic_ops); + +return SZ_4K ; +}
virt/kvm/arm/vgic/vgic-mmio.c +26 -0
@@ -169,3 +169,29 @@ struct kvm_io_device_ops kvm_io_gic_ops = { .read = dispatch_mmio_read, .write = dispatch_mmio_write, }; + +int vgic_register_dist_iodev (struct kvm *kvm,gpa_t dist_base_address, +enum vgic_type type) +{ +struct vgic_io_device *io_device = &kvm->arch.vgic.dist_iodev; +int ret =0 ; +unsigned int len; + +switch (type) { +case VGIC_V2 : + len =vgic_v2_init_dist_iodev (io_device); +break ; +default : +BUG_ON (1 ); + } + + io_device->base_addr = dist_base_address; + io_device->redist_vcpu =NULL ; + +mutex_lock (&kvm->slots_lock); + ret =kvm_io_bus_register_dev (kvm,KVM_MMIO_BUS , dist_base_address, + len, &io_device->dev); +mutex_unlock (&kvm->slots_lock); + +return ret; +}
virt/kvm/arm/vgic/vgic-mmio.h +2 -0
@@ -74,4 +74,6 @@ unsigned long vgic_mmio_read_rao(struct kvm_vcpu *vcpu,void vgic_mmio_write_wi (struct kvm_vcpu *vcpu,gpa_t addr,unsigned int len,unsigned long val); +unsigned int vgic_v2_init_dist_iodev (struct vgic_io_device *dev); +#endif
virt/kvm/arm/vgic/vgic.h +2 -0
@@ -27,6 +27,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_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);
Signature · 1 line
2.7.3
Re: [PATCH v3 22/55] KVM: arm/arm64: vgic-new: Add GICv2 MMIO handling framework
Quoted 154 lines · Andre Przywara
Create
vgic-mmio-v2.cto describe GICv2 emulation specific handlers using the initializer macros provided by the VGIC MMIO framework. Provide a function to register the GICv2 distributor registers to thekvm_io_busframework.
The actual handler functions are still stubs in this patch.Signed-off-by Andre Przywara <[email protected]>Signed-off-by Marc Zyngier <[email protected]>---
Changelog v1 .. v2:
- new patch, split out from the generic MMIO framework patch
- use a separate file to hold GICv2 emulation specific handlers
- replace_nyistub functions with raz/wi versionsChangelog v2 .. v3:
- replacekvm/vgic/vgic.hwithkvm/arm_vgic.h
- addvgic_register_dist_iodev()prototypevirt/kvm/arm/vgic/vgic-mmio-v2.c | 62 ++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.c | 26 +++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.h | 2 ++ virt/kvm/arm/vgic/vgic.h | 2 ++ 4 files changed, 92 insertions(+) create mode 100644 virt/kvm/arm/vgic/vgic-mmio-v2.cvirt/kvm/arm/vgic/vgic-mmio-v2.c new file +62
-0@@ -0,0 +1,62 @@ +/* +* VGICv2 MMIO handling functions +* +* 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. +*/ + +#include <linux/irqchip/arm-gic.h> +#include <linux/kvm.h> +#include <linux/kvm_host.h> +#include <kvm/iodev.h> +#include <kvm/arm_vgic.h> + +#include "vgic.h" +#include "vgic-mmio.h" + +static const struct vgic_register_region vgic_v2_dist_registers[] = { +REGISTER_DESC_WITH_LENGTH (GIC_DIST_CTRL , + vgic_mmio_read_raz, vgic_mmio_write_wi,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_raz, vgic_mmio_write_wi,1 ), +REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_ENABLE_CLEAR , + vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), +REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_PENDING_SET , + vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), +REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_PENDING_CLEAR , + vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), +REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_ACTIVE_SET , + vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), +REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_ACTIVE_CLEAR , + vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), +REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_PRI , + vgic_mmio_read_raz, vgic_mmio_write_wi,8 ), +REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_TARGET , + vgic_mmio_read_raz, vgic_mmio_write_wi,8 ), +REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_CONFIG , + vgic_mmio_read_raz, vgic_mmio_write_wi,2 ), +REGISTER_DESC_WITH_LENGTH (GIC_DIST_SOFTINT , + vgic_mmio_read_raz, vgic_mmio_write_wi,4 ), +REGISTER_DESC_WITH_LENGTH (GIC_DIST_SGI_PENDING_CLEAR , + vgic_mmio_read_raz, vgic_mmio_write_wi,16 ), +REGISTER_DESC_WITH_LENGTH (GIC_DIST_SGI_PENDING_SET , + vgic_mmio_read_raz, vgic_mmio_write_wi,16 ), +}; + +unsigned int vgic_v2_init_dist_iodev (struct vgic_io_device *dev) +{ + dev->regions = vgic_v2_dist_registers; + dev->nr_regions =ARRAY_SIZE (vgic_v2_dist_registers); + +kvm_iodevice_init (&dev->dev, &kvm_io_gic_ops); + +return SZ_4K ; +}virt/kvm/arm/vgic/vgic-mmio.c +26
-0@@ -169,3 +169,29 @@ struct kvm_io_device_ops kvm_io_gic_ops = { .read = dispatch_mmio_read, .write = dispatch_mmio_write, }; + +int vgic_register_dist_iodev (struct kvm *kvm,gpa_t dist_base_address, +enum vgic_type type) +{ +struct vgic_io_device *io_device = &kvm->arch.vgic.dist_iodev; +int ret =0 ; +unsigned int len; + +switch (type) { +case VGIC_V2 : + len =vgic_v2_init_dist_iodev (io_device); +break ; +default : +BUG_ON (1 ); + } + + io_device->base_addr = dist_base_address; + io_device->redist_vcpu =NULL ; + +mutex_lock (&kvm->slots_lock); + ret =kvm_io_bus_register_dev (kvm,KVM_MMIO_BUS , dist_base_address, + len, &io_device->dev); +mutex_unlock (&kvm->slots_lock); + +return ret; +}virt/kvm/arm/vgic/vgic-mmio.h +2
-0@@ -74,4 +74,6 @@ unsigned long vgic_mmio_read_rao(struct kvm_vcpu *vcpu,void vgic_mmio_write_wi (struct kvm_vcpu *vcpu,gpa_t addr,unsigned int len,unsigned long val); +unsigned int vgic_v2_init_dist_iodev (struct vgic_io_device *dev); +#endif virt/kvm/arm/vgic/vgic.h +2
-0@@ -27,6 +27,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_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);Signature · 1 line
2.7.3
PATCH v3 23/55 KVM: arm/arm64: vgic-new: Add CTLR, TYPER and IIDR handlers
In reply to Andre PrzywaraFrom: Marc Zyngier <[email protected]>
Those three registers are v2 emulation specific, so their implementation lives entirely in vgic-mmio-v2.c. Also they are handled in one function, as their implementation is pretty simple.
When the guest enables the distributor, we kick all VCPUs to get potentially pending interrupts serviced.
---
Changelog RFC..v1:
- kick VCPUs is the distributor gets enabled
- improve comment
Changelog v1 .. v2:
- adapt to new MMIO framework
- use switch() statements to improve readability
Changelog v2 .. v3:
- add vgic_kick_vcpus() implementation
include/linux/irqchip/arm-gic.h | 1 + virt/kvm/arm/vgic/vgic-mmio-v2.c | 48 +++++++++++++++++++++++++++++++++++++++- virt/kvm/arm/vgic/vgic.c | 15 +++++++++++++ virt/kvm/arm/vgic/vgic.h | 4 ++++ 4 files changed, 67 insertions(+), 1 deletion(-)
include/linux/irqchip/arm-gic.h +1 -0
@@ -33,6 +33,7 @@#define GIC_DIST_CTRL 0x000#define GIC_DIST_CTR 0x004 +#define GIC_DIST_IIDR 0x008#define GIC_DIST_IGROUP 0x080#define GIC_DIST_ENABLE_SET 0x100#define GIC_DIST_ENABLE_CLEAR 0x180
virt/kvm/arm/vgic/vgic-mmio-v2.c +47 -1
56 lines not on this page · raw message
virt/kvm/arm/vgic/vgic.c +15 -0
@@ -544,3 +544,18 @@ int kvm_vgic_vcpu_pending_irq(struct kvm_vcpu *vcpu)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 +4 -0
@@ -16,11 +16,15 @@#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,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
Re: [PATCH v3 23/55] KVM: arm/arm64: vgic-new: Add CTLR, TYPER and IIDR handlers
Quoted 69 lines · Andre Przywara
From: Marc Zyngier <[email protected]>
Those three registers are v2 emulation specific, so their implementation lives entirely in
vgic-mmio-v2.c. Also they are handled in one function, as their implementation is pretty simple.
When the guest enables the distributor, we kick all VCPUs to get potentially pending interrupts serviced.Signed-off-by Marc Zyngier <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- kick VCPUs is the distributor gets enabled
- improve commentChangelog v1 .. v2:
- adapt to new MMIO framework
- useswitch()statements to improve readabilityChangelog v2 .. v3:
- addvgic_kick_vcpus()implementationinclude/linux/irqchip/arm-gic.h | 1 + virt/kvm/arm/vgic/vgic-mmio-v2.c | 48 +++++++++++++++++++++++++++++++++++++++- virt/kvm/arm/vgic/vgic.c | 15 +++++++++++++ virt/kvm/arm/vgic/vgic.h | 4 ++++ 4 files changed, 67 insertions(+), 1 deletion(-)include/linux/irqchip/arm-gic.h +1
-0@@ -33,6 +33,7 @@#define GIC_DIST_CTRL 0x000#define GIC_DIST_CTR 0x004 +#define GIC_DIST_IIDR 0x008#define GIC_DIST_IGROUP 0x080#define GIC_DIST_ENABLE_SET 0x100#define GIC_DIST_ENABLE_CLEAR 0x180virt/kvm/arm/vgic/vgic-mmio-v2.c +21
-0@@ -20,9 +20,55 @@#include "vgic.h" #include "vgic-mmio.h" +static unsigned long vgic_mmio_read_v2_misc (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len) +{ +u32 value; + +switch (addr &0x0c ) { +case GIC_DIST_CTRL : + value = vcpu->kvm->arch.vgic.enabled ?GICD_ENABLE :0 ; +break ; +case GIC_DIST_CTR : + value = vcpu->kvm->arch.vgic.nr_spis +VGIC_NR_PRIVATE_IRQS ; + value = (value >>5 ) -1 ; + value |= (atomic_read (&vcpu->kvm->online_vcpus) -1 ) <<5 ; +break ; +case GIC_DIST_IIDR : + value = (PRODUCT_ID_KVM <<24 ) | (IMPLEMENTER_ARM <<0 ); +break ; +default : +return 0 ; + } +
virt/kvm/arm/vgic/vgic-mmio-v2.c line 53
Quoted 10 lines
virt/kvm/arm/vgic/vgic-mmio-v2.c +10
-0+return extract_bytes (value, addr &3 , len); +} + +static void vgic_mmio_write_v2_misc (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val) +{ +switch (addr &0x0c ) { +case GIC_DIST_CTRL : +if (!(addr &1 )) {
what is this !(addr & 1) check?
Quoted 72 lines
virt/kvm/arm/vgic/vgic-mmio-v2.c +16
-1+struct vgic_dist *dist = &vcpu->kvm->arch.vgic; +bool was_enabled = dist->enabled; + + dist->enabled = val &GICD_ENABLE ; +if (!was_enabled && dist->enabled) +vgic_kick_vcpus (vcpu->kvm); + } +break ; +case GIC_DIST_CTR : +case GIC_DIST_IIDR : +/* Nothing to do */ +return ; + } +} +static const struct vgic_register_region vgic_v2_dist_registers[] = {REGISTER_DESC_WITH_LENGTH (GIC_DIST_CTRL , - vgic_mmio_read_raz, vgic_mmio_write_wi,12 ), + 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,virt/kvm/arm/vgic/vgic.c +15
-0@@ -544,3 +544,18 @@ int kvm_vgic_vcpu_pending_irq(struct kvm_vcpu *vcpu)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 +4
-0@@ -16,11 +16,15 @@#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,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 · 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 v3 23/55] KVM: arm/arm64: vgic-new: Add CTLR, TYPER and IIDR handlers
Hej,
Quoted 74 lines · Christoffer Dall
Quoted 73 lines · Andre Przywara
From: Marc Zyngier <[email protected]>
Those three registers are v2 emulation specific, so their implementation lives entirely in
vgic-mmio-v2.c. Also they are handled in one function, as their implementation is pretty simple.
When the guest enables the distributor, we kick all VCPUs to get potentially pending interrupts serviced.Signed-off-by Marc Zyngier <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- kick VCPUs is the distributor gets enabled
- improve commentChangelog v1 .. v2:
- adapt to new MMIO framework
- useswitch()statements to improve readabilityChangelog v2 .. v3:
- addvgic_kick_vcpus()implementationinclude/linux/irqchip/arm-gic.h | 1 + virt/kvm/arm/vgic/vgic-mmio-v2.c | 48 +++++++++++++++++++++++++++++++++++++++- virt/kvm/arm/vgic/vgic.c | 15 +++++++++++++ virt/kvm/arm/vgic/vgic.h | 4 ++++ 4 files changed, 67 insertions(+), 1 deletion(-)include/linux/irqchip/arm-gic.h +1
-0@@ -33,6 +33,7 @@#define GIC_DIST_CTRL 0x000#define GIC_DIST_CTR 0x004 +#define GIC_DIST_IIDR 0x008#define GIC_DIST_IGROUP 0x080#define GIC_DIST_ENABLE_SET 0x100#define GIC_DIST_ENABLE_CLEAR 0x180virt/kvm/arm/vgic/vgic-mmio-v2.c +25
-0@@ -20,9 +20,55 @@#include "vgic.h" #include "vgic-mmio.h" +static unsigned long vgic_mmio_read_v2_misc (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len) +{ +u32 value; + +switch (addr &0x0c ) { +case GIC_DIST_CTRL : + value = vcpu->kvm->arch.vgic.enabled ?GICD_ENABLE :0 ; +break ; +case GIC_DIST_CTR : + value = vcpu->kvm->arch.vgic.nr_spis +VGIC_NR_PRIVATE_IRQS ; + value = (value >>5 ) -1 ; + value |= (atomic_read (&vcpu->kvm->online_vcpus) -1 ) <<5 ; +break ; +case GIC_DIST_IIDR : + value = (PRODUCT_ID_KVM <<24 ) | (IMPLEMENTER_ARM <<0 ); +break ; +default : +return 0 ; + } + +return extract_bytes (value, addr &3 , len); +} + +static void vgic_mmio_write_v2_misc(struct kvm_vcpu *vcpu,
Quoted 8 lines
virt/kvm/arm/vgic/vgic-mmio-v2.c line 53
Quoted 6 lines
virt/kvm/arm/vgic/vgic-mmio-v2.c +6
-0+ gpa_t addr, unsigned int len, + unsigned long val) +{ + switch (addr & 0x0c) { +case GIC_DIST_CTRL : +if (!(addr &1 )) {what is this !(addr & 1) check?
Mmmh, interesting. The original idea was that we care only about the lowest significant byte. I guess this was somehow lost in translation when Marc reworked the function. I think it should at least read:
"if (!(addr & 3))" to match the switch mask, otherwise for instance a byte write to address 2 triggers the if branch as well.
I will fix the mask to 3 and add a comment.
Thanks,
Andre.
Quoted 74 lines
Quoted 73 lines
virt/kvm/arm/vgic/vgic-mmio-v2.c +16
-1+struct vgic_dist *dist = &vcpu->kvm->arch.vgic; +bool was_enabled = dist->enabled; + + dist->enabled = val &GICD_ENABLE ; +if (!was_enabled && dist->enabled) +vgic_kick_vcpus (vcpu->kvm); + } +break ; +case GIC_DIST_CTR : +case GIC_DIST_IIDR : +/* Nothing to do */ +return ; + } +} +static const struct vgic_register_region vgic_v2_dist_registers[] = {REGISTER_DESC_WITH_LENGTH (GIC_DIST_CTRL , - vgic_mmio_read_raz, vgic_mmio_write_wi,12 ), + 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,virt/kvm/arm/vgic/vgic.c +15
-0@@ -544,3 +544,18 @@ int kvm_vgic_vcpu_pending_irq(struct kvm_vcpu *vcpu)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 +4
-0@@ -16,11 +16,15 @@#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,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 · 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 v3 23/55] KVM: arm/arm64: vgic-new: Add CTLR, TYPER and IIDR handlers
In reply to Christoffer DallQuoted 74 lines · Christoffer Dall
Quoted 73 lines · Andre Przywara
From: Marc Zyngier <[email protected]>
Those three registers are v2 emulation specific, so their implementation lives entirely in
vgic-mmio-v2.c. Also they are handled in one function, as their implementation is pretty simple.
When the guest enables the distributor, we kick all VCPUs to get potentially pending interrupts serviced.Signed-off-by Marc Zyngier <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- kick VCPUs is the distributor gets enabled
- improve commentChangelog v1 .. v2:
- adapt to new MMIO framework
- useswitch()statements to improve readabilityChangelog v2 .. v3:
- addvgic_kick_vcpus()implementationinclude/linux/irqchip/arm-gic.h | 1 + virt/kvm/arm/vgic/vgic-mmio-v2.c | 48 +++++++++++++++++++++++++++++++++++++++- virt/kvm/arm/vgic/vgic.c | 15 +++++++++++++ virt/kvm/arm/vgic/vgic.h | 4 ++++ 4 files changed, 67 insertions(+), 1 deletion(-)include/linux/irqchip/arm-gic.h +1
-0@@ -33,6 +33,7 @@#define GIC_DIST_CTRL 0x000#define GIC_DIST_CTR 0x004 +#define GIC_DIST_IIDR 0x008#define GIC_DIST_IGROUP 0x080#define GIC_DIST_ENABLE_SET 0x100#define GIC_DIST_ENABLE_CLEAR 0x180virt/kvm/arm/vgic/vgic-mmio-v2.c +25
-0@@ -20,9 +20,55 @@#include "vgic.h" #include "vgic-mmio.h" +static unsigned long vgic_mmio_read_v2_misc (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len) +{ +u32 value; + +switch (addr &0x0c ) { +case GIC_DIST_CTRL : + value = vcpu->kvm->arch.vgic.enabled ?GICD_ENABLE :0 ; +break ; +case GIC_DIST_CTR : + value = vcpu->kvm->arch.vgic.nr_spis +VGIC_NR_PRIVATE_IRQS ; + value = (value >>5 ) -1 ; + value |= (atomic_read (&vcpu->kvm->online_vcpus) -1 ) <<5 ; +break ; +case GIC_DIST_IIDR : + value = (PRODUCT_ID_KVM <<24 ) | (IMPLEMENTER_ARM <<0 ); +break ; +default : +return 0 ; + } + +return extract_bytes (value, addr &3 , len); +} + +static void vgic_mmio_write_v2_misc(struct kvm_vcpu *vcpu,
Quoted 8 lines
virt/kvm/arm/vgic/vgic-mmio-v2.c line 53
Quoted 6 lines
virt/kvm/arm/vgic/vgic-mmio-v2.c +6
-0+ gpa_t addr, unsigned int len, + unsigned long val) +{ + switch (addr & 0x0c) { +case GIC_DIST_CTRL : +if (!(addr &1 )) {what is this !(addr & 1) check?
We check that the write includes the lowest byte of the register. But as we only have aligned accesses, it probably doesn't matter... I'll hack that away.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH v3 23/55] KVM: arm/arm64: vgic-new: Add CTLR, TYPER and IIDR handlers
Quoted 84 lines · Marc Zyngier
Quoted 74 lines · Christoffer Dall
Quoted 73 lines · Andre Przywara
From: Marc Zyngier <[email protected]>
Those three registers are v2 emulation specific, so their implementation lives entirely in
vgic-mmio-v2.c. Also they are handled in one function, as their implementation is pretty simple.
When the guest enables the distributor, we kick all VCPUs to get potentially pending interrupts serviced.Signed-off-by Marc Zyngier <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- kick VCPUs is the distributor gets enabled
- improve commentChangelog v1 .. v2:
- adapt to new MMIO framework
- useswitch()statements to improve readabilityChangelog v2 .. v3:
- addvgic_kick_vcpus()implementationinclude/linux/irqchip/arm-gic.h | 1 + virt/kvm/arm/vgic/vgic-mmio-v2.c | 48 +++++++++++++++++++++++++++++++++++++++- virt/kvm/arm/vgic/vgic.c | 15 +++++++++++++ virt/kvm/arm/vgic/vgic.h | 4 ++++ 4 files changed, 67 insertions(+), 1 deletion(-)include/linux/irqchip/arm-gic.h +1
-0@@ -33,6 +33,7 @@#define GIC_DIST_CTRL 0x000#define GIC_DIST_CTR 0x004 +#define GIC_DIST_IIDR 0x008#define GIC_DIST_IGROUP 0x080#define GIC_DIST_ENABLE_SET 0x100#define GIC_DIST_ENABLE_CLEAR 0x180virt/kvm/arm/vgic/vgic-mmio-v2.c +25
-0@@ -20,9 +20,55 @@#include "vgic.h" #include "vgic-mmio.h" +static unsigned long vgic_mmio_read_v2_misc (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len) +{ +u32 value; + +switch (addr &0x0c ) { +case GIC_DIST_CTRL : + value = vcpu->kvm->arch.vgic.enabled ?GICD_ENABLE :0 ; +break ; +case GIC_DIST_CTR : + value = vcpu->kvm->arch.vgic.nr_spis +VGIC_NR_PRIVATE_IRQS ; + value = (value >>5 ) -1 ; + value |= (atomic_read (&vcpu->kvm->online_vcpus) -1 ) <<5 ; +break ; +case GIC_DIST_IIDR : + value = (PRODUCT_ID_KVM <<24 ) | (IMPLEMENTER_ARM <<0 ); +break ; +default : +return 0 ; + } + +return extract_bytes (value, addr &3 , len); +} + +static void vgic_mmio_write_v2_misc(struct kvm_vcpu *vcpu,Quoted 8 lines
virt/kvm/arm/vgic/vgic-mmio-v2.c line 53
Quoted 6 lines
virt/kvm/arm/vgic/vgic-mmio-v2.c +6
-0+ gpa_t addr, unsigned int len, + unsigned long val) +{ + switch (addr & 0x0c) { +case GIC_DIST_CTRL : +if (!(addr &1 )) {what is this !(addr & 1) check?
Quoted 4 lines
We check that the write includes the lowest byte of the register. But as we only have aligned accesses, it probably doesn't matter... I'll hack that away.
where do we check to only have aligned accesses?
-Christoffer
Re: [PATCH v3 23/55] KVM: arm/arm64: vgic-new: Add CTLR, TYPER and IIDR handlers
Quoted 85 lines · Christoffer Dall
Quoted 84 lines · Marc Zyngier
Quoted 82 lines · Christoffer Dall
Quoted 69 lines · Andre Przywara
From: Marc Zyngier <[email protected]>
Those three registers are v2 emulation specific, so their implementation lives entirely in
vgic-mmio-v2.c. Also they are handled in one function, as their implementation is pretty simple.
When the guest enables the distributor, we kick all VCPUs to get potentially pending interrupts serviced.Signed-off-by Marc Zyngier <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- kick VCPUs is the distributor gets enabled
- improve commentChangelog v1 .. v2:
- adapt to new MMIO framework
- useswitch()statements to improve readabilityChangelog v2 .. v3:
- addvgic_kick_vcpus()implementationinclude/linux/irqchip/arm-gic.h | 1 + virt/kvm/arm/vgic/vgic-mmio-v2.c | 48 +++++++++++++++++++++++++++++++++++++++- virt/kvm/arm/vgic/vgic.c | 15 +++++++++++++ virt/kvm/arm/vgic/vgic.h | 4 ++++ 4 files changed, 67 insertions(+), 1 deletion(-)include/linux/irqchip/arm-gic.h +1
-0@@ -33,6 +33,7 @@#define GIC_DIST_CTRL 0x000#define GIC_DIST_CTR 0x004 +#define GIC_DIST_IIDR 0x008#define GIC_DIST_IGROUP 0x080#define GIC_DIST_ENABLE_SET 0x100#define GIC_DIST_ENABLE_CLEAR 0x180virt/kvm/arm/vgic/vgic-mmio-v2.c +21
-0@@ -20,9 +20,55 @@#include "vgic.h" #include "vgic-mmio.h" +static unsigned long vgic_mmio_read_v2_misc (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len) +{ +u32 value; + +switch (addr &0x0c ) { +case GIC_DIST_CTRL : + value = vcpu->kvm->arch.vgic.enabled ?GICD_ENABLE :0 ; +break ; +case GIC_DIST_CTR : + value = vcpu->kvm->arch.vgic.nr_spis +VGIC_NR_PRIVATE_IRQS ; + value = (value >>5 ) -1 ; + value |= (atomic_read (&vcpu->kvm->online_vcpus) -1 ) <<5 ; +break ; +case GIC_DIST_IIDR : + value = (PRODUCT_ID_KVM <<24 ) | (IMPLEMENTER_ARM <<0 ); +break ; +default : +return 0 ; + } +virt/kvm/arm/vgic/vgic-mmio-v2.c line 53
Quoted 10 lines
virt/kvm/arm/vgic/vgic-mmio-v2.c +10
-0+return extract_bytes (value, addr &3 , len); +} + +static void vgic_mmio_write_v2_misc (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val) +{ +switch (addr &0x0c ) { +case GIC_DIST_CTRL : +if (!(addr &1 )) {what is this !(addr & 1) check?
Quoted 5 lines
Quoted 4 lines
We check that the write includes the lowest byte of the register. But as we only have aligned accesses, it probably doesn't matter... I'll hack that away.
where do we check to only have aligned accesses?
Looks like a missing feature. The v2 spec says:
4.1.4 GIC register access
All registers support 32-bit word accesses with the access type defined in Table 4-1 on page 4-73 and Table 4-2 on page 4-74.
In addition, the GICD_IPRIORITYRn, GICD_ITARGETSRn, GICD_CPENDSGIRn, and GICD_SPENDSGIRn registers support byte accesses.
Similar thing for v3 (8.1.3).
By the look of it, we should add checks in all accessors. I'll get onto it.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH v3 23/55] KVM: arm/arm64: vgic-new: Add CTLR, TYPER and IIDR handlers
Hi,
Quoted 100 lines · Marc Zyngier
Quoted 85 lines · Christoffer Dall
Quoted 84 lines · Marc Zyngier
Quoted 82 lines · Christoffer Dall
Quoted 69 lines · Andre Przywara
From: Marc Zyngier <[email protected]>
Those three registers are v2 emulation specific, so their implementation lives entirely in
vgic-mmio-v2.c. Also they are handled in one function, as their implementation is pretty simple.
When the guest enables the distributor, we kick all VCPUs to get potentially pending interrupts serviced.Signed-off-by Marc Zyngier <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- kick VCPUs is the distributor gets enabled
- improve commentChangelog v1 .. v2:
- adapt to new MMIO framework
- useswitch()statements to improve readabilityChangelog v2 .. v3:
- addvgic_kick_vcpus()implementationinclude/linux/irqchip/arm-gic.h | 1 + virt/kvm/arm/vgic/vgic-mmio-v2.c | 48 +++++++++++++++++++++++++++++++++++++++- virt/kvm/arm/vgic/vgic.c | 15 +++++++++++++ virt/kvm/arm/vgic/vgic.h | 4 ++++ 4 files changed, 67 insertions(+), 1 deletion(-)include/linux/irqchip/arm-gic.h +1
-0@@ -33,6 +33,7 @@#define GIC_DIST_CTRL 0x000#define GIC_DIST_CTR 0x004 +#define GIC_DIST_IIDR 0x008#define GIC_DIST_IGROUP 0x080#define GIC_DIST_ENABLE_SET 0x100#define GIC_DIST_ENABLE_CLEAR 0x180virt/kvm/arm/vgic/vgic-mmio-v2.c +21
-0@@ -20,9 +20,55 @@#include "vgic.h" #include "vgic-mmio.h" +static unsigned long vgic_mmio_read_v2_misc (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len) +{ +u32 value; + +switch (addr &0x0c ) { +case GIC_DIST_CTRL : + value = vcpu->kvm->arch.vgic.enabled ?GICD_ENABLE :0 ; +break ; +case GIC_DIST_CTR : + value = vcpu->kvm->arch.vgic.nr_spis +VGIC_NR_PRIVATE_IRQS ; + value = (value >>5 ) -1 ; + value |= (atomic_read (&vcpu->kvm->online_vcpus) -1 ) <<5 ; +break ; +case GIC_DIST_IIDR : + value = (PRODUCT_ID_KVM <<24 ) | (IMPLEMENTER_ARM <<0 ); +break ; +default : +return 0 ; + } +virt/kvm/arm/vgic/vgic-mmio-v2.c line 53
Quoted 10 lines
virt/kvm/arm/vgic/vgic-mmio-v2.c +10
-0+return extract_bytes (value, addr &3 , len); +} + +static void vgic_mmio_write_v2_misc (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val) +{ +switch (addr &0x0c ) { +case GIC_DIST_CTRL : +if (!(addr &1 )) {what is this !(addr & 1) check?
Quoted 5 lines
Quoted 4 lines
We check that the write includes the lowest byte of the register. But as we only have aligned accesses, it probably doesn't matter... I'll hack that away.
where do we check to only have aligned accesses?
Looks like a missing feature. The v2 spec says:
4.1.4 GIC register access
All registers support 32-bit word accesses with the access type defined in Table 4-1 on page 4-73 and Table 4-2 on page 4-74.
In addition, theGICD_IPRIORITYRn,GICD_ITARGETSRn,GICD_CPENDSGIRn, andGICD_SPENDSGIRnregisters support byte accesses.
Quoted 3 lines
Similar thing for v3 (8.1.3).
By the look of it, we should add checks in all accessors. I'll get onto it.
What about to tag every register in our vgic_register_region with a possible access width and do a generic check in dispatch_mmio_{read,write}? Then we wouldn't need to touch every handler.
Cheers,
Andre.
Re: [PATCH v3 23/55] KVM: arm/arm64: vgic-new: Add CTLR, TYPER and IIDR handlers
Quoted 103 lines · Andre Przywara
Hi,
Quoted 100 lines · Marc Zyngier
Quoted 85 lines · Christoffer Dall
Quoted 84 lines · Marc Zyngier
Quoted 82 lines · Christoffer Dall
Quoted 69 lines · Andre Przywara
From: Marc Zyngier <[email protected]>
Those three registers are v2 emulation specific, so their implementation lives entirely in
vgic-mmio-v2.c. Also they are handled in one function, as their implementation is pretty simple.
When the guest enables the distributor, we kick all VCPUs to get potentially pending interrupts serviced.Signed-off-by Marc Zyngier <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- kick VCPUs is the distributor gets enabled
- improve commentChangelog v1 .. v2:
- adapt to new MMIO framework
- useswitch()statements to improve readabilityChangelog v2 .. v3:
- addvgic_kick_vcpus()implementationinclude/linux/irqchip/arm-gic.h | 1 + virt/kvm/arm/vgic/vgic-mmio-v2.c | 48 +++++++++++++++++++++++++++++++++++++++- virt/kvm/arm/vgic/vgic.c | 15 +++++++++++++ virt/kvm/arm/vgic/vgic.h | 4 ++++ 4 files changed, 67 insertions(+), 1 deletion(-)include/linux/irqchip/arm-gic.h +1
-0@@ -33,6 +33,7 @@#define GIC_DIST_CTRL 0x000#define GIC_DIST_CTR 0x004 +#define GIC_DIST_IIDR 0x008#define GIC_DIST_IGROUP 0x080#define GIC_DIST_ENABLE_SET 0x100#define GIC_DIST_ENABLE_CLEAR 0x180virt/kvm/arm/vgic/vgic-mmio-v2.c +21
-0@@ -20,9 +20,55 @@#include "vgic.h" #include "vgic-mmio.h" +static unsigned long vgic_mmio_read_v2_misc (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len) +{ +u32 value; + +switch (addr &0x0c ) { +case GIC_DIST_CTRL : + value = vcpu->kvm->arch.vgic.enabled ?GICD_ENABLE :0 ; +break ; +case GIC_DIST_CTR : + value = vcpu->kvm->arch.vgic.nr_spis +VGIC_NR_PRIVATE_IRQS ; + value = (value >>5 ) -1 ; + value |= (atomic_read (&vcpu->kvm->online_vcpus) -1 ) <<5 ; +break ; +case GIC_DIST_IIDR : + value = (PRODUCT_ID_KVM <<24 ) | (IMPLEMENTER_ARM <<0 ); +break ; +default : +return 0 ; + } +virt/kvm/arm/vgic/vgic-mmio-v2.c line 53
Quoted 10 lines
virt/kvm/arm/vgic/vgic-mmio-v2.c +10
-0+return extract_bytes (value, addr &3 , len); +} + +static void vgic_mmio_write_v2_misc (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val) +{ +switch (addr &0x0c ) { +case GIC_DIST_CTRL : +if (!(addr &1 )) {what is this !(addr & 1) check?
Quoted 5 lines
Quoted 4 lines
We check that the write includes the lowest byte of the register. But as we only have aligned accesses, it probably doesn't matter... I'll hack that away.
where do we check to only have aligned accesses?
Looks like a missing feature. The v2 spec says:
4.1.4 GIC register access
All registers support 32-bit word accesses with the access type defined in Table 4-1 on page 4-73 and Table 4-2 on page 4-74.
In addition, theGICD_IPRIORITYRn,GICD_ITARGETSRn,GICD_CPENDSGIRn, andGICD_SPENDSGIRnregisters support byte accesses.
Quoted 7 lines
Quoted 3 lines
Similar thing for v3 (8.1.3).
By the look of it, we should add checks in all accessors. I'll get onto it.
What about to tag every register in our
vgic_register_regionwith a possible access width and do a generic check in dispatch_mmio_{read,write}? Then we wouldn't need to touch every handler.
That's my plan.
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH v3 23/55] KVM: arm/arm64: vgic-new: Add CTLR, TYPER and IIDR handlers
In reply to Marc ZyngierQuoted 100 lines · Marc Zyngier
Quoted 85 lines · Christoffer Dall
Quoted 84 lines · Marc Zyngier
Quoted 82 lines · Christoffer Dall
Quoted 69 lines · Andre Przywara
From: Marc Zyngier <[email protected]>
Those three registers are v2 emulation specific, so their implementation lives entirely in
vgic-mmio-v2.c. Also they are handled in one function, as their implementation is pretty simple.
When the guest enables the distributor, we kick all VCPUs to get potentially pending interrupts serviced.Signed-off-by Marc Zyngier <[email protected]>Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- kick VCPUs is the distributor gets enabled
- improve commentChangelog v1 .. v2:
- adapt to new MMIO framework
- useswitch()statements to improve readabilityChangelog v2 .. v3:
- addvgic_kick_vcpus()implementationinclude/linux/irqchip/arm-gic.h | 1 + virt/kvm/arm/vgic/vgic-mmio-v2.c | 48 +++++++++++++++++++++++++++++++++++++++- virt/kvm/arm/vgic/vgic.c | 15 +++++++++++++ virt/kvm/arm/vgic/vgic.h | 4 ++++ 4 files changed, 67 insertions(+), 1 deletion(-)include/linux/irqchip/arm-gic.h +1
-0@@ -33,6 +33,7 @@#define GIC_DIST_CTRL 0x000#define GIC_DIST_CTR 0x004 +#define GIC_DIST_IIDR 0x008#define GIC_DIST_IGROUP 0x080#define GIC_DIST_ENABLE_SET 0x100#define GIC_DIST_ENABLE_CLEAR 0x180virt/kvm/arm/vgic/vgic-mmio-v2.c +21
-0@@ -20,9 +20,55 @@#include "vgic.h" #include "vgic-mmio.h" +static unsigned long vgic_mmio_read_v2_misc (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len) +{ +u32 value; + +switch (addr &0x0c ) { +case GIC_DIST_CTRL : + value = vcpu->kvm->arch.vgic.enabled ?GICD_ENABLE :0 ; +break ; +case GIC_DIST_CTR : + value = vcpu->kvm->arch.vgic.nr_spis +VGIC_NR_PRIVATE_IRQS ; + value = (value >>5 ) -1 ; + value |= (atomic_read (&vcpu->kvm->online_vcpus) -1 ) <<5 ; +break ; +case GIC_DIST_IIDR : + value = (PRODUCT_ID_KVM <<24 ) | (IMPLEMENTER_ARM <<0 ); +break ; +default : +return 0 ; + } +virt/kvm/arm/vgic/vgic-mmio-v2.c line 53
Quoted 10 lines
virt/kvm/arm/vgic/vgic-mmio-v2.c +10
-0+return extract_bytes (value, addr &3 , len); +} + +static void vgic_mmio_write_v2_misc (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val) +{ +switch (addr &0x0c ) { +case GIC_DIST_CTRL : +if (!(addr &1 )) {what is this !(addr & 1) check?
Quoted 5 lines
Quoted 4 lines
We check that the write includes the lowest byte of the register. But as we only have aligned accesses, it probably doesn't matter... I'll hack that away.
where do we check to only have aligned accesses?
Looks like a missing feature. The v2 spec says:
4.1.4 GIC register access
All registers support 32-bit word accesses with the access type defined in Table 4-1 on page 4-73 and Table 4-2 on page 4-74.
In addition, theGICD_IPRIORITYRn,GICD_ITARGETSRn,GICD_CPENDSGIRn, andGICD_SPENDSGIRnregisters support byte accesses.
Quoted 4 lines
Similar thing for v3 (8.1.3).
By the look of it, we should add checks in all accessors. I'll get onto it.
Yeah, that's probably the easiest.
-Christoffer
PATCH v3 24/55 KVM: arm/arm64: vgic-new: Add ENABLE registers handlers
In reply to Andre PrzywaraAs the enable register handlers are shared between the v2 and v3 emulation, their implementation goes into vgic-mmio.c, to be easily referenced from the v3 emulation as well later.
---
Changelog RFC..v1:
- use lower bits of address to determine IRQ number
- remove TODO, confirmed to be fine
Changelog v1 .. v2:
- adapt to new MMIO framework
virt/kvm/arm/vgic/vgic-mmio-v2.c | 4 +-- virt/kvm/arm/vgic/vgic-mmio.c | 56 ++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.h | 11 ++++++++ 3 files changed, 69 insertions(+), 2 deletions(-)
virt/kvm/arm/vgic/vgic-mmio-v2.c +2 -2
@@ -72,9 +72,9 @@ static const struct vgic_register_region vgic_v2_dist_registers[] = {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_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_enable, vgic_mmio_write_senable,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_ENABLE_CLEAR , - vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_enable, vgic_mmio_write_cenable,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_PENDING_SET , vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), REGISTER_DESC_WITH_BITS_PER_IRQ(GIC_DIST_PENDING_CLEAR,
virt/kvm/arm/vgic/vgic-mmio.c +56 -0
62 lines not on this page · raw message
virt/kvm/arm/vgic/vgic-mmio.h +11 -0
@@ -74,6 +74,17 @@ unsigned long vgic_mmio_read_rao(struct kvm_vcpu *vcpu,void vgic_mmio_write_wi (struct kvm_vcpu *vcpu,gpa_t addr,unsigned int len,unsigned long val); +unsigned long vgic_mmio_read_enable (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len); + +void vgic_mmio_write_senable (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val); + +void vgic_mmio_write_cenable (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val); +unsigned int vgic_v2_init_dist_iodev (struct vgic_io_device *dev);#endif
Signature · 1 line
2.7.3
Re: [PATCH v3 24/55] KVM: arm/arm64: vgic-new: Add ENABLE registers handlers
Quoted 5 lines · Andre Przywara
As the enable register handlers are shared between the v2 and v3 emulation, their implementation goes into
vgic-mmio.c, to be easily referenced from the v3 emulation as well later.Signed-off-by Andre Przywara <[email protected]>
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH v3 24/55] KVM: arm/arm64: vgic-new: Add ENABLE registers handlers
In reply to Andre PrzywaraQuoted 40 lines · Andre Przywara
As the enable register handlers are shared between the v2 and v3 emulation, their implementation goes into
vgic-mmio.c, to be easily referenced from the v3 emulation as well later.Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- use lower bits of address to determine IRQ number
- remove TODO, confirmed to be fineChangelog v1 .. v2:
- adapt to new MMIO frameworkvirt/kvm/arm/vgic/vgic-mmio-v2.c | 4 +-- virt/kvm/arm/vgic/vgic-mmio.c | 56 ++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.h | 11 ++++++++ 3 files changed, 69 insertions(+), 2 deletions(-)virt/kvm/arm/vgic/vgic-mmio-v2.c +2
-2@@ -72,9 +72,9 @@ static const struct vgic_register_region vgic_v2_dist_registers[] = {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_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_enable, vgic_mmio_write_senable,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_ENABLE_CLEAR , - vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_enable, vgic_mmio_write_cenable,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_PENDING_SET , vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), REGISTER_DESC_WITH_BITS_PER_IRQ(GIC_DIST_PENDING_CLEAR,virt/kvm/arm/vgic/vgic-mmio.c +0
-0@@ -46,6 +46,62 @@ void vgic_mmio_write_wi(struct kvm_vcpu *vcpu, gpa_t addr,/* Ignore */
virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_wi(struct kvm_vcpu *vcpu, gpa_t addr, · line 56
Quoted 10 lines
virt/kvm/arm/vgic/vgic-mmio.c +8
-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. +*/ +unsigned long vgic_mmio_read_enable (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len) +{ +u32 intid = (addr &0x7f ) *8 ;
is there anything we can do about this to make it more intuitive? A macro to generate the mask/offset based on bits per interrupt or something?
virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_wi(struct kvm_vcpu *vcpu, gpa_t addr, · line 65
Quoted 9 lines
virt/kvm/arm/vgic/vgic-mmio.c +9
-0+u32 value =0 ; +int i; + +/* 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);
I couldn't find the code anywhere that enforces word-aligned accesses to these registers. Do we have that?
If that's not the case, doesn't this break of you do a non-word aligned access?
Quoted 26 lines
virt/kvm/arm/vgic/vgic-mmio.c +26
-0+ } + +return extract_bytes (value, addr &3 , len); +} + +void vgic_mmio_write_senable (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val) +{ +u32 intid = (addr &0x7f ) *8 ; +int i; + +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); + } +} + +void vgic_mmio_write_cenable (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val) +{ +u32 intid = (addr &0x7f ) *8 ;
virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_wi(struct kvm_vcpu *vcpu, gpa_t addr, · line 101
Quoted 10 lines
virt/kvm/arm/vgic/vgic-mmio.c +10
-0+int i; + +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);
nit: whitespace consistency with senable
Quoted 31 lines
virt/kvm/arm/vgic/vgic-mmio.c +3
-0+ } +} +static int match_region (const void *key,const void *elt) {const unsigned int offset = (unsigned long )key;virt/kvm/arm/vgic/vgic-mmio.h +11
-0@@ -74,6 +74,17 @@ unsigned long vgic_mmio_read_rao(struct kvm_vcpu *vcpu,void vgic_mmio_write_wi (struct kvm_vcpu *vcpu,gpa_t addr,unsigned int len,unsigned long val); +unsigned long vgic_mmio_read_enable (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len); + +void vgic_mmio_write_senable (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val); + +void vgic_mmio_write_cenable (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val); +unsigned int vgic_v2_init_dist_iodev (struct vgic_io_device *dev);#endif Signature · 1 line
2.7.3
Re: [PATCH v3 24/55] KVM: arm/arm64: vgic-new: Add ENABLE registers handlers
Hi,
Quoted 43 lines · Christoffer Dall
Quoted 42 lines · Andre Przywara
As the enable register handlers are shared between the v2 and v3 emulation, their implementation goes into
vgic-mmio.c, to be easily referenced from the v3 emulation as well later.Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- use lower bits of address to determine IRQ number
- remove TODO, confirmed to be fineChangelog v1 .. v2:
- adapt to new MMIO frameworkvirt/kvm/arm/vgic/vgic-mmio-v2.c | 4 +-- virt/kvm/arm/vgic/vgic-mmio.c | 56 ++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.h | 11 ++++++++ 3 files changed, 69 insertions(+), 2 deletions(-)virt/kvm/arm/vgic/vgic-mmio-v2.c +2
-2@@ -72,9 +72,9 @@ static const struct vgic_register_region vgic_v2_dist_registers[] = {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_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_enable, vgic_mmio_write_senable,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_ENABLE_CLEAR , - vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_enable, vgic_mmio_write_cenable,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_PENDING_SET , vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), REGISTER_DESC_WITH_BITS_PER_IRQ(GIC_DIST_PENDING_CLEAR,virt/kvm/arm/vgic/vgic-mmio.c +0
-0@@ -46,6 +46,62 @@ void vgic_mmio_write_wi(struct kvm_vcpu *vcpu, gpa_t addr,/* Ignore */ }
Quoted 12 lines
virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_wi(struct kvm_vcpu *vcpu, gpa_t addr, · line 56
Quoted 8 lines
virt/kvm/arm/vgic/vgic-mmio.c +8
-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. +*/ +unsigned long vgic_mmio_read_enable (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len) +{ +u32 intid = (addr &0x7f ) *8 ;is there anything we can do about this to make it more intuitive? A macro to generate the mask/offset based on bits per interrupt or something?
Yes, something where you give it the address and the bits-per-IRQ and it tells you the IRQ number.
Not sure it is advisable to squash this into v4 still?
Quoted 13 lines
virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_wi(struct kvm_vcpu *vcpu, gpa_t addr, · line 65
Quoted 10 lines
virt/kvm/arm/vgic/vgic-mmio.c +9
-0+u32 value =0 ; +int i; + +/* 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);I couldn't find the code anywhere that enforces word-aligned accesses to these registers. Do we have that?
Not that I am aware of. I was suggesting this since we have one in the IROUTER function. Architecturally we don't need to support halfword accesses, it's: byte + word, word only or double-word + word, depending on the actual register, IIRC.
As a fix we can at least deny (read: ignore) halfword accesses in general in the dispatcher. Shall I do this (two two-liners)? I think byte and word accesses are safe with the existing handlers last time I checked.
Quoted 2 lines
If that's not the case, doesn't this break of you do a non-word aligned access?
Why would it? vgic_data_host_to_mmio_bus and extract_bytes should cover this, shouldn't they?
Cheers,
Andre.
Quoted 72 lines
Quoted 27 lines
virt/kvm/arm/vgic/vgic-mmio.c +26
-0+ } + +return extract_bytes (value, addr &3 , len); +} + +void vgic_mmio_write_senable (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val) +{ +u32 intid = (addr &0x7f ) *8 ; +int i; + +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); + } +} + +void vgic_mmio_write_cenable (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val) +{ +u32 intid = (addr &0x7f ) *8 ;virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_wi(struct kvm_vcpu *vcpu, gpa_t addr, · line 101
Quoted 10 lines
virt/kvm/arm/vgic/vgic-mmio.c +10
-0+int i; + +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);nit: whitespace consistency with senable
Quoted 31 lines
virt/kvm/arm/vgic/vgic-mmio.c +3
-0+ } +} +static int match_region (const void *key,const void *elt) {const unsigned int offset = (unsigned long )key;virt/kvm/arm/vgic/vgic-mmio.h +11
-0@@ -74,6 +74,17 @@ unsigned long vgic_mmio_read_rao(struct kvm_vcpu *vcpu,void vgic_mmio_write_wi (struct kvm_vcpu *vcpu,gpa_t addr,unsigned int len,unsigned long val); +unsigned long vgic_mmio_read_enable (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len); + +void vgic_mmio_write_senable (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val); + +void vgic_mmio_write_cenable (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val); +unsigned int vgic_v2_init_dist_iodev (struct vgic_io_device *dev);#endif Signature · 1 line
2.7.3
Re: [PATCH v3 24/55] KVM: arm/arm64: vgic-new: Add ENABLE registers handlers
Quoted 86 lines · Andre Przywara
Hi,
Quoted 43 lines · Christoffer Dall
Quoted 42 lines · Andre Przywara
As the enable register handlers are shared between the v2 and v3 emulation, their implementation goes into
vgic-mmio.c, to be easily referenced from the v3 emulation as well later.Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- use lower bits of address to determine IRQ number
- remove TODO, confirmed to be fineChangelog v1 .. v2:
- adapt to new MMIO frameworkvirt/kvm/arm/vgic/vgic-mmio-v2.c | 4 +-- virt/kvm/arm/vgic/vgic-mmio.c | 56 ++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.h | 11 ++++++++ 3 files changed, 69 insertions(+), 2 deletions(-)virt/kvm/arm/vgic/vgic-mmio-v2.c +2
-2@@ -72,9 +72,9 @@ static const struct vgic_register_region vgic_v2_dist_registers[] = {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_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_enable, vgic_mmio_write_senable,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_ENABLE_CLEAR , - vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_enable, vgic_mmio_write_cenable,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_PENDING_SET , vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), REGISTER_DESC_WITH_BITS_PER_IRQ(GIC_DIST_PENDING_CLEAR,virt/kvm/arm/vgic/vgic-mmio.c +0
-0@@ -46,6 +46,62 @@ void vgic_mmio_write_wi(struct kvm_vcpu *vcpu, gpa_t addr,/* Ignore */ }Quoted 12 lines
virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_wi(struct kvm_vcpu *vcpu, gpa_t addr, · line 56
Quoted 8 lines
virt/kvm/arm/vgic/vgic-mmio.c +8
-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. +*/ +unsigned long vgic_mmio_read_enable (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len) +{ +u32 intid = (addr &0x7f ) *8 ;is there anything we can do about this to make it more intuitive? A macro to generate the mask/offset based on bits per interrupt or something?
Yes, something where you give it the address and the bits-per-IRQ and it tells you the IRQ number.
Not sure it is advisable to squash this into v4 still?Quoted 13 lines
virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_wi(struct kvm_vcpu *vcpu, gpa_t addr, · line 65
Quoted 10 lines
virt/kvm/arm/vgic/vgic-mmio.c +9
-0+u32 value =0 ; +int i; + +/* 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);I couldn't find the code anywhere that enforces word-aligned accesses to these registers. Do we have that?
Not that I am aware of. I was suggesting this since we have one in the IROUTER function. Architecturally we don't need to support halfword accesses, it's: byte + word, word only or double-word + word, depending on the actual register, IIRC.
As a fix we can at least deny (read: ignore) halfword accesses in general in the dispatcher. Shall I do this (two two-liners)? I think byte and word accesses are safe with the existing handlers last time I checked.
Quoted 6 lines
Quoted 2 lines
If that's not the case, doesn't this break of you do a non-word aligned access?
Why would it?
vgic_data_host_to_mmio_busandextract_bytesshould cover this, shouldn't they?
I think this breaks on a simple byte access. Let's say you are accessing byte 1 (addr & 0x7ff == 1), then because you start your loop at 0, you're going to set bits [7:0] in the value variable, and then extract bits [15:8] in extract_bytes(), right?
-Christoffer
Re: [PATCH v3 24/55] KVM: arm/arm64: vgic-new: Add ENABLE registers handlers
Quoted 90 lines · Christoffer Dall
Quoted 89 lines · Andre Przywara
Hi,
Quoted 43 lines · Christoffer Dall
Quoted 42 lines · Andre Przywara
As the enable register handlers are shared between the v2 and v3 emulation, their implementation goes into
vgic-mmio.c, to be easily referenced from the v3 emulation as well later.Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- use lower bits of address to determine IRQ number
- remove TODO, confirmed to be fineChangelog v1 .. v2:
- adapt to new MMIO frameworkvirt/kvm/arm/vgic/vgic-mmio-v2.c | 4 +-- virt/kvm/arm/vgic/vgic-mmio.c | 56 ++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.h | 11 ++++++++ 3 files changed, 69 insertions(+), 2 deletions(-)virt/kvm/arm/vgic/vgic-mmio-v2.c +2
-2@@ -72,9 +72,9 @@ static const struct vgic_register_region vgic_v2_dist_registers[] = {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_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_enable, vgic_mmio_write_senable,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_ENABLE_CLEAR , - vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_enable, vgic_mmio_write_cenable,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_PENDING_SET , vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), REGISTER_DESC_WITH_BITS_PER_IRQ(GIC_DIST_PENDING_CLEAR,virt/kvm/arm/vgic/vgic-mmio.c +0
-0@@ -46,6 +46,62 @@ void vgic_mmio_write_wi(struct kvm_vcpu *vcpu, gpa_t addr,/* Ignore */ }Quoted 12 lines
virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_wi(struct kvm_vcpu *vcpu, gpa_t addr, · line 56
Quoted 8 lines
virt/kvm/arm/vgic/vgic-mmio.c +8
-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. +*/ +unsigned long vgic_mmio_read_enable (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len) +{ +u32 intid = (addr &0x7f ) *8 ;is there anything we can do about this to make it more intuitive? A macro to generate the mask/offset based on bits per interrupt or something?
Yes, something where you give it the address and the bits-per-IRQ and it tells you the IRQ number.
Not sure it is advisable to squash this into v4 still?Quoted 13 lines
virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_wi(struct kvm_vcpu *vcpu, gpa_t addr, · line 65
Quoted 10 lines
virt/kvm/arm/vgic/vgic-mmio.c +9
-0+u32 value =0 ; +int i; + +/* 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);I couldn't find the code anywhere that enforces word-aligned accesses to these registers. Do we have that?
Not that I am aware of. I was suggesting this since we have one in the IROUTER function. Architecturally we don't need to support halfword accesses, it's: byte + word, word only or double-word + word, depending on the actual register, IIRC.
As a fix we can at least deny (read: ignore) halfword accesses in general in the dispatcher. Shall I do this (two two-liners)? I think byte and word accesses are safe with the existing handlers last time I checked.Quoted 2 lines
If that's not the case, doesn't this break of you do a non-word aligned access?
Quoted 8 lines
Quoted 3 lines
Why would it?
vgic_data_host_to_mmio_busandextract_bytesshould cover this, shouldn't they?I think this breaks on a simple byte access. Let's say you are accessing byte 1 (addr &
0x7ff== 1), then because you start your loop at 0, you're going to set bits [7:0] in the value variable, and then extract bits [15:8] inextract_bytes(), right?
Looks like, yes. I thought that it would take care of that, because a handler function shouldn't be bothered with this: it just acts on the lower bytes (till the length) and extract_bytes() does the rest. I think this is what the old magic vgic_reg_access does due to "regval >> word_offset".
Do you care to fix this in extract_bytes?
Cheers,
Andre.
Re: [PATCH v3 24/55] KVM: arm/arm64: vgic-new: Add ENABLE registers handlers
Quoted 102 lines · Andre Przywara
Quoted 90 lines · Christoffer Dall
Quoted 89 lines · Andre Przywara
Hi,
Quoted 43 lines · Christoffer Dall
Quoted 42 lines · Andre Przywara
As the enable register handlers are shared between the v2 and v3 emulation, their implementation goes into
vgic-mmio.c, to be easily referenced from the v3 emulation as well later.Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- use lower bits of address to determine IRQ number
- remove TODO, confirmed to be fineChangelog v1 .. v2:
- adapt to new MMIO frameworkvirt/kvm/arm/vgic/vgic-mmio-v2.c | 4 +-- virt/kvm/arm/vgic/vgic-mmio.c | 56 ++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.h | 11 ++++++++ 3 files changed, 69 insertions(+), 2 deletions(-)virt/kvm/arm/vgic/vgic-mmio-v2.c +2
-2@@ -72,9 +72,9 @@ static const struct vgic_register_region vgic_v2_dist_registers[] = {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_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_enable, vgic_mmio_write_senable,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_ENABLE_CLEAR , - vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_enable, vgic_mmio_write_cenable,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_PENDING_SET , vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), REGISTER_DESC_WITH_BITS_PER_IRQ(GIC_DIST_PENDING_CLEAR,virt/kvm/arm/vgic/vgic-mmio.c +0
-0@@ -46,6 +46,62 @@ void vgic_mmio_write_wi(struct kvm_vcpu *vcpu, gpa_t addr,/* Ignore */ }Quoted 12 lines
virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_wi(struct kvm_vcpu *vcpu, gpa_t addr, · line 56
Quoted 8 lines
virt/kvm/arm/vgic/vgic-mmio.c +8
-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. +*/ +unsigned long vgic_mmio_read_enable (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len) +{ +u32 intid = (addr &0x7f ) *8 ;is there anything we can do about this to make it more intuitive? A macro to generate the mask/offset based on bits per interrupt or something?
Yes, something where you give it the address and the bits-per-IRQ and it tells you the IRQ number.
Not sure it is advisable to squash this into v4 still?Quoted 13 lines
virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_wi(struct kvm_vcpu *vcpu, gpa_t addr, · line 65
Quoted 10 lines
virt/kvm/arm/vgic/vgic-mmio.c +9
-0+u32 value =0 ; +int i; + +/* 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);I couldn't find the code anywhere that enforces word-aligned accesses to these registers. Do we have that?
Not that I am aware of. I was suggesting this since we have one in the IROUTER function. Architecturally we don't need to support halfword accesses, it's: byte + word, word only or double-word + word, depending on the actual register, IIRC.
As a fix we can at least deny (read: ignore) halfword accesses in general in the dispatcher. Shall I do this (two two-liners)? I think byte and word accesses are safe with the existing handlers last time I checked.Quoted 2 lines
If that's not the case, doesn't this break of you do a non-word aligned access?
Quoted 8 lines
Quoted 3 lines
Why would it?
vgic_data_host_to_mmio_busandextract_bytesshould cover this, shouldn't they?I think this breaks on a simple byte access. Let's say you are accessing byte 1 (addr &
0x7ff== 1), then because you start your loop at 0, you're going to set bits [7:0] in the value variable, and then extract bits [15:8] inextract_bytes(), right?
Quoted 8 lines
Looks like, yes. I thought that it would take care of that, because a handler function shouldn't be bothered with this: it just acts on the lower bytes (till the length) and
extract_bytes()does the rest. I think this is what the old magicvgic_reg_accessdoes due to "regval >>word_offset".Do you care to fix this in
extract_bytes?
I don't think this is a fix to extract_bytes. I think the issue is with how we build the values. I though the semanticsehre were that the u32 value in this case would the entire 32-bit register, so can't we simply mask off the lower bits in the addr on entry to these functions and add additional checks if there are registers where specifically do not wish to support byte accessed?
-Christoffer
Re: [PATCH v3 24/55] KVM: arm/arm64: vgic-new: Add ENABLE registers handlers
In reply to Andre PrzywaraQuoted 59 lines · Andre Przywara
Hi,
Quoted 43 lines · Christoffer Dall
Quoted 42 lines · Andre Przywara
As the enable register handlers are shared between the v2 and v3 emulation, their implementation goes into
vgic-mmio.c, to be easily referenced from the v3 emulation as well later.Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- use lower bits of address to determine IRQ number
- remove TODO, confirmed to be fineChangelog v1 .. v2:
- adapt to new MMIO frameworkvirt/kvm/arm/vgic/vgic-mmio-v2.c | 4 +-- virt/kvm/arm/vgic/vgic-mmio.c | 56 ++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.h | 11 ++++++++ 3 files changed, 69 insertions(+), 2 deletions(-)virt/kvm/arm/vgic/vgic-mmio-v2.c +2
-2@@ -72,9 +72,9 @@ static const struct vgic_register_region vgic_v2_dist_registers[] = {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_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_enable, vgic_mmio_write_senable,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_ENABLE_CLEAR , - vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_enable, vgic_mmio_write_cenable,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_PENDING_SET , vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), REGISTER_DESC_WITH_BITS_PER_IRQ(GIC_DIST_PENDING_CLEAR,virt/kvm/arm/vgic/vgic-mmio.c +0
-0@@ -46,6 +46,62 @@ void vgic_mmio_write_wi(struct kvm_vcpu *vcpu, gpa_t addr,/* Ignore */ }Quoted 12 lines
virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_wi(struct kvm_vcpu *vcpu, gpa_t addr, · line 56
Quoted 8 lines
virt/kvm/arm/vgic/vgic-mmio.c +8
-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. +*/ +unsigned long vgic_mmio_read_enable (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len) +{ +u32 intid = (addr &0x7f ) *8 ;is there anything we can do about this to make it more intuitive? A macro to generate the mask/offset based on bits per interrupt or something?
Quoted 4 lines
Yes, something where you give it the address and the bits-per-IRQ and it tells you the IRQ number.
Not sure it is advisable to squash this into v4 still?
I think it should be fairly mechanical and easy to squash, so would prefer it, but if it gives you hours of headache, maybe not.
-Christoffer
Re: [PATCH v3 24/55] KVM: arm/arm64: vgic-new: Add ENABLE registers handlers
In reply to Christoffer DallQuoted 43 lines · Christoffer Dall
Quoted 42 lines · Andre Przywara
As the enable register handlers are shared between the v2 and v3 emulation, their implementation goes into
vgic-mmio.c, to be easily referenced from the v3 emulation as well later.Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- use lower bits of address to determine IRQ number
- remove TODO, confirmed to be fineChangelog v1 .. v2:
- adapt to new MMIO frameworkvirt/kvm/arm/vgic/vgic-mmio-v2.c | 4 +-- virt/kvm/arm/vgic/vgic-mmio.c | 56 ++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.h | 11 ++++++++ 3 files changed, 69 insertions(+), 2 deletions(-)virt/kvm/arm/vgic/vgic-mmio-v2.c +2
-2@@ -72,9 +72,9 @@ static const struct vgic_register_region vgic_v2_dist_registers[] = {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_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_enable, vgic_mmio_write_senable,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_ENABLE_CLEAR , - vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_enable, vgic_mmio_write_cenable,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_PENDING_SET , vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), REGISTER_DESC_WITH_BITS_PER_IRQ(GIC_DIST_PENDING_CLEAR,virt/kvm/arm/vgic/vgic-mmio.c +0
-0@@ -46,6 +46,62 @@ void vgic_mmio_write_wi(struct kvm_vcpu *vcpu, gpa_t addr,/* Ignore */ }
Quoted 12 lines
virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_wi(struct kvm_vcpu *vcpu, gpa_t addr, · line 56
Quoted 8 lines
virt/kvm/arm/vgic/vgic-mmio.c +8
-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. +*/ +unsigned long vgic_mmio_read_enable (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len) +{ +u32 intid = (addr &0x7f ) *8 ;is there anything we can do about this to make it more intuitive? A macro to generate the mask/offset based on bits per interrupt or something?
Untested (and thus probably wrong):
#define VGIC_ADDR_IRQ_MASK(bits) ((1024 - 1) >> (4 - (bits)) #define VGIC_ADDR_IRQ_MULT(bits) (8 / (bits))
#define VGIC_ADDR_TO_INTID(addr, bits) (((addr) & VGIC_ADDR_IRQ_MASK(bits)) * \ VGIC_ADDR_IRQ_MULT(bits)) u32 intid = VGIC_ADDR_TO_INTID(addr, 1);
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH v3 24/55] KVM: arm/arm64: vgic-new: Add ENABLE registers handlers
Hi,
Quoted 57 lines · Marc Zyngier
Quoted 43 lines · Christoffer Dall
Quoted 42 lines · Andre Przywara
As the enable register handlers are shared between the v2 and v3 emulation, their implementation goes into
vgic-mmio.c, to be easily referenced from the v3 emulation as well later.Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- use lower bits of address to determine IRQ number
- remove TODO, confirmed to be fineChangelog v1 .. v2:
- adapt to new MMIO frameworkvirt/kvm/arm/vgic/vgic-mmio-v2.c | 4 +-- virt/kvm/arm/vgic/vgic-mmio.c | 56 ++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.h | 11 ++++++++ 3 files changed, 69 insertions(+), 2 deletions(-)virt/kvm/arm/vgic/vgic-mmio-v2.c +2
-2@@ -72,9 +72,9 @@ static const struct vgic_register_region vgic_v2_dist_registers[] = {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_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_enable, vgic_mmio_write_senable,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_ENABLE_CLEAR , - vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_enable, vgic_mmio_write_cenable,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_PENDING_SET , vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), REGISTER_DESC_WITH_BITS_PER_IRQ(GIC_DIST_PENDING_CLEAR,virt/kvm/arm/vgic/vgic-mmio.c +0
-0@@ -46,6 +46,62 @@ void vgic_mmio_write_wi(struct kvm_vcpu *vcpu, gpa_t addr,/* Ignore */ }Quoted 12 lines
virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_wi(struct kvm_vcpu *vcpu, gpa_t addr, · line 56
Quoted 8 lines
virt/kvm/arm/vgic/vgic-mmio.c +8
-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. +*/ +unsigned long vgic_mmio_read_enable (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len) +{ +u32 intid = (addr &0x7f ) *8 ;is there anything we can do about this to make it more intuitive? A macro to generate the mask/offset based on bits per interrupt or something?
Quoted 3 lines
Untested (and thus probably wrong):
#define
VGIC_ADDR_IRQ_MASK(bits)((1024 - 1) >> (4 - (bits))
What about if bits is 8?
Wouldn't GENMASK(bits + 10 - 2, 0) do the trick?
Quoted 1 line
#define
VGIC_ADDR_IRQ_MULT(bits)(8 / (bits))
IROUTER has a bits_per_irq value of 64. We just don't need to call it from there, but it would be nice if it could cover this. But I don't know a neat solution for this either.
Cheers,
Andre.
Quoted 9 lines
#define VGIC_ADDR_TO_INTID(addr, bits) (((addr) & VGIC_ADDR_IRQ_MASK(bits)) * \ VGIC_ADDR_IRQ_MULT(bits)) u32 intid = VGIC_ADDR_TO_INTID(addr, 1);Thanks,
M.
Re: [PATCH v3 24/55] KVM: arm/arm64: vgic-new: Add ENABLE registers handlers
Quoted 60 lines · Andre Przywara
Hi,
Quoted 57 lines · Marc Zyngier
Quoted 55 lines · Christoffer Dall
Quoted 40 lines · Andre Przywara
As the enable register handlers are shared between the v2 and v3 emulation, their implementation goes into
vgic-mmio.c, to be easily referenced from the v3 emulation as well later.Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- use lower bits of address to determine IRQ number
- remove TODO, confirmed to be fineChangelog v1 .. v2:
- adapt to new MMIO frameworkvirt/kvm/arm/vgic/vgic-mmio-v2.c | 4 +-- virt/kvm/arm/vgic/vgic-mmio.c | 56 ++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.h | 11 ++++++++ 3 files changed, 69 insertions(+), 2 deletions(-)virt/kvm/arm/vgic/vgic-mmio-v2.c +2
-2@@ -72,9 +72,9 @@ static const struct vgic_register_region vgic_v2_dist_registers[] = {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_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_enable, vgic_mmio_write_senable,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_ENABLE_CLEAR , - vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_enable, vgic_mmio_write_cenable,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_PENDING_SET , vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), REGISTER_DESC_WITH_BITS_PER_IRQ(GIC_DIST_PENDING_CLEAR,virt/kvm/arm/vgic/vgic-mmio.c +0
-0@@ -46,6 +46,62 @@ void vgic_mmio_write_wi(struct kvm_vcpu *vcpu, gpa_t addr,/* Ignore */ virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_wi(struct kvm_vcpu *vcpu, gpa_t addr, · line 56
Quoted 10 lines
virt/kvm/arm/vgic/vgic-mmio.c +8
-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. +*/ +unsigned long vgic_mmio_read_enable (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len) +{ +u32 intid = (addr &0x7f ) *8 ;is there anything we can do about this to make it more intuitive? A macro to generate the mask/offset based on bits per interrupt or something?
Quoted 5 lines
Quoted 3 lines
Untested (and thus probably wrong):
#define
VGIC_ADDR_IRQ_MASK(bits)((1024 - 1) >> (4 - (bits))What about if bits is 8?
Gnii. This should be ((1024 - 1) >> (4 - ffs(bits))
Quoted 1 line
Wouldn't
GENMASK(bits + 10 - 2, 0)do the trick?
I really can't see how that works... It could beGENMASK(10 - 1 - ffs(bits), 0) though.
Quoted 5 lines
Quoted 1 line
#define
VGIC_ADDR_IRQ_MULT(bits)(8 / (bits))IROUTER has a
bits_per_irqvalue of 64. We just don't need to call it from there, but it would be nice if it could cover this. But I don't know a neat solution for this either.
Me neither, but I don't see that as a major issue so far.
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH v3 24/55] KVM: arm/arm64: vgic-new: Add ENABLE registers handlers
In reply to Marc ZyngierQuoted 57 lines · Marc Zyngier
Quoted 43 lines · Christoffer Dall
Quoted 42 lines · Andre Przywara
As the enable register handlers are shared between the v2 and v3 emulation, their implementation goes into
vgic-mmio.c, to be easily referenced from the v3 emulation as well later.Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- use lower bits of address to determine IRQ number
- remove TODO, confirmed to be fineChangelog v1 .. v2:
- adapt to new MMIO frameworkvirt/kvm/arm/vgic/vgic-mmio-v2.c | 4 +-- virt/kvm/arm/vgic/vgic-mmio.c | 56 ++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.h | 11 ++++++++ 3 files changed, 69 insertions(+), 2 deletions(-)virt/kvm/arm/vgic/vgic-mmio-v2.c +2
-2@@ -72,9 +72,9 @@ static const struct vgic_register_region vgic_v2_dist_registers[] = {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_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_enable, vgic_mmio_write_senable,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_ENABLE_CLEAR , - vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_enable, vgic_mmio_write_cenable,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_PENDING_SET , vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), REGISTER_DESC_WITH_BITS_PER_IRQ(GIC_DIST_PENDING_CLEAR,virt/kvm/arm/vgic/vgic-mmio.c +0
-0@@ -46,6 +46,62 @@ void vgic_mmio_write_wi(struct kvm_vcpu *vcpu, gpa_t addr,/* Ignore */ }Quoted 12 lines
virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_wi(struct kvm_vcpu *vcpu, gpa_t addr, · line 56
Quoted 8 lines
virt/kvm/arm/vgic/vgic-mmio.c +8
-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. +*/ +unsigned long vgic_mmio_read_enable (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len) +{ +u32 intid = (addr &0x7f ) *8 ;is there anything we can do about this to make it more intuitive? A macro to generate the mask/offset based on bits per interrupt or something?
Quoted 3 lines
Untested (and thus probably wrong):
#define
VGIC_ADDR_IRQ_MASK(bits)((1024 - 1) >> (4 - (bits))
you're going to have to explain this to me, where is the (4 - bits) coming from?
Quoted 13 lines
#define
VGIC_ADDR_IRQ_MULT(bits)(8 / (bits))#define VGIC_ADDR_TO_INTID(addr, bits) (((addr) & VGIC_ADDR_IRQ_MASK(bits)) * \ VGIC_ADDR_IRQ_MULT(bits)) u32 intid = VGIC_ADDR_TO_INTID(addr, 1);Thanks,
M.Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH v3 24/55] KVM: arm/arm64: vgic-new: Add ENABLE registers handlers
In reply to Marc ZyngierHi,
Quoted 57 lines · Marc Zyngier
Quoted 43 lines · Christoffer Dall
Quoted 42 lines · Andre Przywara
As the enable register handlers are shared between the v2 and v3 emulation, their implementation goes into
vgic-mmio.c, to be easily referenced from the v3 emulation as well later.Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- use lower bits of address to determine IRQ number
- remove TODO, confirmed to be fineChangelog v1 .. v2:
- adapt to new MMIO frameworkvirt/kvm/arm/vgic/vgic-mmio-v2.c | 4 +-- virt/kvm/arm/vgic/vgic-mmio.c | 56 ++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.h | 11 ++++++++ 3 files changed, 69 insertions(+), 2 deletions(-)virt/kvm/arm/vgic/vgic-mmio-v2.c +2
-2@@ -72,9 +72,9 @@ static const struct vgic_register_region vgic_v2_dist_registers[] = {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_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_enable, vgic_mmio_write_senable,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_ENABLE_CLEAR , - vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_enable, vgic_mmio_write_cenable,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_PENDING_SET , vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), REGISTER_DESC_WITH_BITS_PER_IRQ(GIC_DIST_PENDING_CLEAR,virt/kvm/arm/vgic/vgic-mmio.c +0
-0@@ -46,6 +46,62 @@ void vgic_mmio_write_wi(struct kvm_vcpu *vcpu, gpa_t addr,/* Ignore */ }Quoted 12 lines
virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_wi(struct kvm_vcpu *vcpu, gpa_t addr, · line 56
Quoted 8 lines
virt/kvm/arm/vgic/vgic-mmio.c +8
-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. +*/ +unsigned long vgic_mmio_read_enable (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len) +{ +u32 intid = (addr &0x7f ) *8 ;is there anything we can do about this to make it more intuitive? A macro to generate the mask/offset based on bits per interrupt or something?
Quoted 7 lines
Untested (and thus probably wrong):
#define
VGIC_ADDR_IRQ_MASK(bits)((1024 - 1) >> (4 - (bits)) #defineVGIC_ADDR_IRQ_MULT(bits)(8 / (bits))
#defineVGIC_ADDR_TO_INTID(addr, bits)(((addr) &VGIC_ADDR_IRQ_MASK(bits)) * \
VGIC_ADDR_IRQ_MULT(bits))
Would:
#define VGIC_ADDR_IRQ_MASK(bits) GENMASK_ULL((bits) + 10 - 1 - 1, 0)
#define VGIC_ADDR_TO_INTID(addr, bits) (((addr) & \ VGIC_ADDR_IRQ_MASK(bits)) * 64 / (bits) / 8)
work for all bitnesses?
Cheers,
Andre.
Re: [PATCH v3 24/55] KVM: arm/arm64: vgic-new: Add ENABLE registers handlers
Quoted 3 lines · Andre Przywara
Would:
#define
VGIC_ADDR_IRQ_MASK(bits)GENMASK_ULL((bits) + 10 - 1 - 1, 0)
Nonsense. Must be ... ilog2(bits) ..., of course.
Andre.
Quoted 4 lines
#define VGIC_ADDR_TO_INTID(addr, bits) (((addr) & \ VGIC_ADDR_IRQ_MASK(bits)) * 64 / (bits) / 8)work for all bitnesses?
PATCH v3 25/55 KVM: arm/arm64: vgic-new: Add PENDING registers handlers
In reply to Andre PrzywaraThe pending register handlers are shared between the v2 and v3 emulation, so their implementation goes into vgic-mmio.c, to be easily referenced from the v3 emulation as well later.
For level triggered interrupts the real line level is unaffected by this write, so we keep this state separate and combine it with the device's level to get the actual pending state.
---
Changelog RFC..v1:
- remove IRQ lock from read handler
- remove TODO from clear pending handler
Changelog v1 .. v2:
- adapt to new MMIO framework
virt/kvm/arm/vgic/vgic-mmio-v2.c | 4 +-- virt/kvm/arm/vgic/vgic-mmio.c | 60 ++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.h | 12 ++++++++ 3 files changed, 74 insertions(+), 2 deletions(-)
virt/kvm/arm/vgic/vgic-mmio-v2.c +2 -2
@@ -76,9 +76,9 @@ static const 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_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_pending, vgic_mmio_write_spending,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_PENDING_CLEAR , - vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_pending, vgic_mmio_write_cpending,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_ACTIVE_SET , vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), REGISTER_DESC_WITH_BITS_PER_IRQ(GIC_DIST_ACTIVE_CLEAR,
virt/kvm/arm/vgic/vgic-mmio.c +60 -0
66 lines not on this page · raw message
virt/kvm/arm/vgic/vgic-mmio.h +12 -0
@@ -85,6 +85,18 @@ void vgic_mmio_write_cenable(struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len, unsigned long val); +unsigned long vgic_mmio_read_pending (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len); + +void vgic_mmio_write_spending (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val); + +void vgic_mmio_write_cpending (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val); + +unsigned int vgic_v2_init_dist_iodev (struct vgic_io_device *dev);#endif
Signature · 1 line
2.7.3
Re: [PATCH v3 25/55] KVM: arm/arm64: vgic-new: Add PENDING registers handlers
Quoted 8 lines · Andre Przywara
The pending register handlers are shared between the v2 and v3 emulation, so their implementation goes into
vgic-mmio.c, to be easily referenced from the v3 emulation as well later.
For level triggered interrupts the real line level is unaffected by this write, so we keep this state separate and combine it with the device's level to get the actual pending state.Signed-off-by Andre Przywara <[email protected]>
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH v3 25/55] KVM: arm/arm64: vgic-new: Add PENDING registers handlers
In reply to Andre PrzywaraQuoted 48 lines · Andre Przywara
The pending register handlers are shared between the v2 and v3 emulation, so their implementation goes into
vgic-mmio.c, to be easily referenced from the v3 emulation as well later.
For level triggered interrupts the real line level is unaffected by this write, so we keep this state separate and combine it with the device's level to get the actual pending state.Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- remove IRQ lock from read handler
- remove TODO from clear pending handlerChangelog v1 .. v2:
- adapt to new MMIO frameworkvirt/kvm/arm/vgic/vgic-mmio-v2.c | 4 +-- virt/kvm/arm/vgic/vgic-mmio.c | 60 ++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.h | 12 ++++++++ 3 files changed, 74 insertions(+), 2 deletions(-)virt/kvm/arm/vgic/vgic-mmio-v2.c +2
-2@@ -76,9 +76,9 @@ static const 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_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_pending, vgic_mmio_write_spending,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_PENDING_CLEAR , - vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_pending, vgic_mmio_write_cpending,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_ACTIVE_SET , vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), REGISTER_DESC_WITH_BITS_PER_IRQ(GIC_DIST_ACTIVE_CLEAR,virt/kvm/arm/vgic/vgic-mmio.c +3
-0@@ -102,6 +102,66 @@ void vgic_mmio_write_cenable(struct kvm_vcpu *vcpu, } } +unsigned long vgic_mmio_read_pending (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len) +{
virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_cenable(struct kvm_vcpu *vcpu, · line 117
Quoted 10 lines
virt/kvm/arm/vgic/vgic-mmio.c +10
-0+u32 intid = (addr &0x7f ) *8 ; +u32 value =0 ; +int i; + +/* 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);
same question as on the previous patch
Quoted 76 lines
virt/kvm/arm/vgic/vgic-mmio.c +47
-0+ } + +return extract_bytes (value, addr &3 , len); +} + +void vgic_mmio_write_spending (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val) +{ +u32 intid = (addr &0x7f ) *8 ; +int i; + +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); + } +} + +void vgic_mmio_write_cpending (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val) +{ +u32 intid = (addr &0x7f ) *8 ; +int i; + +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); + } +} +static int match_region (const void *key,const void *elt) {const unsigned int offset = (unsigned long )key;virt/kvm/arm/vgic/vgic-mmio.h +12
-0@@ -85,6 +85,18 @@ void vgic_mmio_write_cenable(struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len, unsigned long val); +unsigned long vgic_mmio_read_pending (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len); + +void vgic_mmio_write_spending (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val); + +void vgic_mmio_write_cpending (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val); + +unsigned int vgic_v2_init_dist_iodev (struct vgic_io_device *dev);#endif Signature · 1 line
2.7.3
Otherwise this looks good.
Thanks,
-Christoffer
PATCH v3 26/55 KVM: arm/arm64: vgic-new: Add ACTIVE registers handlers
In reply to Andre PrzywaraThe active register handlers are shared between the v2 and v3 emulation, so their implementation goes into vgic-mmio.c, to be easily referenced from the v3 emulation as well later. Since activation/deactivation of an interrupt may happen entirely in the guest without it ever exiting, we need some extra logic to properly track the active state.
Putting it on an ap_list on activation is similar to the normal case handled by vgic_queue_irq_unlock(), but differs in some details that make a separate implementation worthwhile.
---
Changelog RFC..v1:
- handling queueing in write handler
- remove IRQ lock from read handler
Changelog v1 .. v2:
- adapt to new MMIO framework
virt/kvm/arm/vgic/vgic-mmio-v2.c | 4 +- virt/kvm/arm/vgic/vgic-mmio.c | 120 +++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.h | 10 ++++ 3 files changed, 132 insertions(+), 2 deletions(-)
virt/kvm/arm/vgic/vgic-mmio-v2.c +2 -2
@@ -80,9 +80,9 @@ static const 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_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_active, vgic_mmio_write_sactive,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_ACTIVE_CLEAR , - vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_active, vgic_mmio_write_cactive,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_PRI , vgic_mmio_read_raz, vgic_mmio_write_wi,8 ), REGISTER_DESC_WITH_BITS_PER_IRQ(GIC_DIST_TARGET,
virt/kvm/arm/vgic/vgic-mmio.c +120 -0
126 lines not on this page · raw message
virt/kvm/arm/vgic/vgic-mmio.h +10 -0
@@ -96,6 +96,16 @@ void vgic_mmio_write_cpending(struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len, unsigned long val); +unsigned long vgic_mmio_read_active (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len); + +void vgic_mmio_write_cactive (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val); + +void vgic_mmio_write_sactive (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val);unsigned int vgic_v2_init_dist_iodev (struct vgic_io_device *dev);
Signature · 1 line
2.7.3
Re: [PATCH v3 26/55] KVM: arm/arm64: vgic-new: Add ACTIVE registers handlers
Quoted 87 lines · Andre Przywara
The active register handlers are shared between the v2 and v3 emulation, so their implementation goes into
vgic-mmio.c, to be easily referenced from the v3 emulation as well later. Since activation/deactivation of an interrupt may happen entirely in the guest without it ever exiting, we need some extra logic to properly track the active state.
Putting it on anap_liston activation is similar to the normal case handled byvgic_queue_irq_unlock(), but differs in some details that make a separate implementation worthwhile.Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- handling queueing in write handler
- remove IRQ lock from read handlerChangelog v1 .. v2:
- adapt to new MMIO frameworkvirt/kvm/arm/vgic/vgic-mmio-v2.c | 4 +- virt/kvm/arm/vgic/vgic-mmio.c | 120 +++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.h | 10 ++++ 3 files changed, 132 insertions(+), 2 deletions(-)virt/kvm/arm/vgic/vgic-mmio-v2.c +2
-2@@ -80,9 +80,9 @@ static const 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_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_active, vgic_mmio_write_sactive,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_ACTIVE_CLEAR , - vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_active, vgic_mmio_write_cactive,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_PRI , vgic_mmio_read_raz, vgic_mmio_write_wi,8 ), REGISTER_DESC_WITH_BITS_PER_IRQ(GIC_DIST_TARGET,virt/kvm/arm/vgic/vgic-mmio.c +39
-0@@ -162,6 +162,126 @@ void vgic_mmio_write_cpending(struct kvm_vcpu *vcpu, } } +unsigned long vgic_mmio_read_active (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len) +{ +u32 intid = (addr &0x7f ) *8 ; +u32 value =0 ; +int i; + +/* 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); + } + +return extract_bytes (value, addr &3 , len); +} + +void vgic_mmio_write_cactive (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val) +{ +u32 intid = (addr &0x7f ) *8 ; +int i; + +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. +*
virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_cpending(struct kvm_vcpu *vcpu, · line 213
Quoted 10 lines
virt/kvm/arm/vgic/vgic-mmio.c +10
-0+* 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... +*/
I thought I wrote a patch for this?
Quoted 58 lines
virt/kvm/arm/vgic/vgic-mmio.c +58
-0+ +spin_unlock (&irq->irq_lock); + } +} + +void vgic_mmio_write_sactive (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val) +{ +u32 intid = (addr &0x7f ) *8 ; +int i; + +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; + } +
virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_cpending(struct kvm_vcpu *vcpu, · line 281
Quoted 10 lines
virt/kvm/arm/vgic/vgic-mmio.c +10
-0+/* 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);
quite frankly, this looks very complicated and I really think it's worth reusing the queue function after seeing this (sorry I haven't been able to before).
-Christoffer
Quoted 30 lines
virt/kvm/arm/vgic/vgic-mmio.c +3
-0+ } +} +static int match_region (const void *key,const void *elt) {const unsigned int offset = (unsigned long )key;virt/kvm/arm/vgic/vgic-mmio.h +10
-0@@ -96,6 +96,16 @@ void vgic_mmio_write_cpending(struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len, unsigned long val); +unsigned long vgic_mmio_read_active (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len); + +void vgic_mmio_write_cactive (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val); + +void vgic_mmio_write_sactive (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val);unsigned int vgic_v2_init_dist_iodev (struct vgic_io_device *dev);Signature · 1 line
2.7.3
Re: [PATCH v3 26/55] KVM: arm/arm64: vgic-new: Add ACTIVE registers handlers
In reply to Andre PrzywaraQuoted 87 lines · Andre Przywara
The active register handlers are shared between the v2 and v3 emulation, so their implementation goes into
vgic-mmio.c, to be easily referenced from the v3 emulation as well later. Since activation/deactivation of an interrupt may happen entirely in the guest without it ever exiting, we need some extra logic to properly track the active state.
Putting it on anap_liston activation is similar to the normal case handled byvgic_queue_irq_unlock(), but differs in some details that make a separate implementation worthwhile.Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- handling queueing in write handler
- remove IRQ lock from read handlerChangelog v1 .. v2:
- adapt to new MMIO frameworkvirt/kvm/arm/vgic/vgic-mmio-v2.c | 4 +- virt/kvm/arm/vgic/vgic-mmio.c | 120 +++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.h | 10 ++++ 3 files changed, 132 insertions(+), 2 deletions(-)virt/kvm/arm/vgic/vgic-mmio-v2.c +2
-2@@ -80,9 +80,9 @@ static const 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_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_active, vgic_mmio_write_sactive,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_ACTIVE_CLEAR , - vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_active, vgic_mmio_write_cactive,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_PRI , vgic_mmio_read_raz, vgic_mmio_write_wi,8 ), REGISTER_DESC_WITH_BITS_PER_IRQ(GIC_DIST_TARGET,virt/kvm/arm/vgic/vgic-mmio.c +39
-0@@ -162,6 +162,126 @@ void vgic_mmio_write_cpending(struct kvm_vcpu *vcpu, } } +unsigned long vgic_mmio_read_active (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len) +{ +u32 intid = (addr &0x7f ) *8 ; +u32 value =0 ; +int i; + +/* 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); + } + +return extract_bytes (value, addr &3 , len); +} + +void vgic_mmio_write_cactive (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val) +{ +u32 intid = (addr &0x7f ) *8 ; +int i; + +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. +*
virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_cpending(struct kvm_vcpu *vcpu, · line 213
Quoted 10 lines
virt/kvm/arm/vgic/vgic-mmio.c +10
-0+* 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... +*/
Don't we have a patch by Christoffer that addresses this exact issue?
Quoted 59 lines
virt/kvm/arm/vgic/vgic-mmio.c +59
-0+ +spin_unlock (&irq->irq_lock); + } +} + +void vgic_mmio_write_sactive (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val) +{ +u32 intid = (addr &0x7f ) *8 ; +int i; + +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. */
virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_cpending(struct kvm_vcpu *vcpu, · line 282
Quoted 10 lines
virt/kvm/arm/vgic/vgic-mmio.c +10
-0+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); + }
This is annoyingly close to vgic_queue_irq_unlock()... Maybe switching this to some form of preprocessor template. Or not.
Quoted 17 lines
virt/kvm/arm/vgic/vgic-mmio.c +2
-0+} +static int match_region (const void *key,const void *elt) {const unsigned int offset = (unsigned long )key;virt/kvm/arm/vgic/vgic-mmio.h +3
-0@@ -96,6 +96,16 @@ void vgic_mmio_write_cpending(struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len, unsigned long val); +unsigned long vgic_mmio_read_active (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len); +
virt/kvm/arm/vgic/vgic-mmio.h void vgic_mmio_write_cpending(struct kvm_vcpu *vcpu, · line 111
Quoted 10 lines
virt/kvm/arm/vgic/vgic-mmio.h +7
-0+void vgic_mmio_write_cactive (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val); + +void vgic_mmio_write_sactive (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val);unsigned int vgic_v2_init_dist_iodev (struct vgic_io_device *dev);
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Re: [PATCH v3 26/55] KVM: arm/arm64: vgic-new: Add ACTIVE registers handlers
Hi Marc,
Quoted 92 lines · Marc Zyngier
Quoted 91 lines · Andre Przywara
The active register handlers are shared between the v2 and v3 emulation, so their implementation goes into
vgic-mmio.c, to be easily referenced from the v3 emulation as well later. Since activation/deactivation of an interrupt may happen entirely in the guest without it ever exiting, we need some extra logic to properly track the active state.
Putting it on anap_liston activation is similar to the normal case handled byvgic_queue_irq_unlock(), but differs in some details that make a separate implementation worthwhile.Signed-off-by Andre Przywara <[email protected]>---
Changelog RFC..v1:
- handling queueing in write handler
- remove IRQ lock from read handlerChangelog v1 .. v2:
- adapt to new MMIO frameworkvirt/kvm/arm/vgic/vgic-mmio-v2.c | 4 +- virt/kvm/arm/vgic/vgic-mmio.c | 120 +++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.h | 10 ++++ 3 files changed, 132 insertions(+), 2 deletions(-)virt/kvm/arm/vgic/vgic-mmio-v2.c +2
-2@@ -80,9 +80,9 @@ static const 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_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_active, vgic_mmio_write_sactive,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_ACTIVE_CLEAR , - vgic_mmio_read_raz, vgic_mmio_write_wi,1 ), + vgic_mmio_read_active, vgic_mmio_write_cactive,1 ),REGISTER_DESC_WITH_BITS_PER_IRQ (GIC_DIST_PRI , vgic_mmio_read_raz, vgic_mmio_write_wi,8 ), REGISTER_DESC_WITH_BITS_PER_IRQ(GIC_DIST_TARGET,virt/kvm/arm/vgic/vgic-mmio.c +43
-0@@ -162,6 +162,126 @@ void vgic_mmio_write_cpending(struct kvm_vcpu *vcpu, } } +unsigned long vgic_mmio_read_active (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len) +{ +u32 intid = (addr &0x7f ) *8 ; +u32 value =0 ; +int i; + +/* 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); + } + +return extract_bytes (value, addr &3 , len); +} + +void vgic_mmio_write_cactive (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val) +{ +u32 intid = (addr &0x7f ) *8 ; +int i; + +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.
Quoted 8 lines
virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_cpending(struct kvm_vcpu *vcpu, · line 213
Quoted 6 lines
virt/kvm/arm/vgic/vgic-mmio.c +6
-0+* 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... +*/ Don't we have a patch by Christoffer that addresses this exact issue?
Yes, and if I am not mistaken you said last week that we put this patch and the firmware-independent probing on top of the queue, so I didn't merge it.
Quoted 64 lines
Quoted 64 lines
virt/kvm/arm/vgic/vgic-mmio.c +64
-0+ +spin_unlock (&irq->irq_lock); + } +} + +void vgic_mmio_write_sactive (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val) +{ +u32 intid = (addr &0x7f ) *8 ; +int i; + +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; +
Quoted 8 lines
virt/kvm/arm/vgic/vgic-mmio.c void vgic_mmio_write_cpending(struct kvm_vcpu *vcpu, · line 282
Quoted 5 lines
virt/kvm/arm/vgic/vgic-mmio.c +5
-0+spin_unlock (&irq->irq_lock); +spin_unlock (&vcpu->arch.vgic_cpu.ap_list_lock); + +kvm_vcpu_kick (vcpu); + }This is annoyingly close to
vgic_queue_irq_unlock()... Maybe switching this to some form of preprocessor template. Or not.
I think we had this discussion with Christoffer before. There are subtle differences and the impression was that unifying the two would make them basically unreadable because of all this special handling. Not sure if the preprocessor would help here.
Cheers,
Andre.
Quoted 33 lines
Quoted 18 lines
virt/kvm/arm/vgic/vgic-mmio.c +2
-0+} +static int match_region (const void *key,const void *elt) {const unsigned int offset = (unsigned long )key;virt/kvm/arm/vgic/vgic-mmio.h +3
-0@@ -96,6 +96,16 @@ void vgic_mmio_write_cpending(struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len, unsigned long val); +unsigned long vgic_mmio_read_active (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len); +virt/kvm/arm/vgic/vgic-mmio.h void vgic_mmio_write_cpending(struct kvm_vcpu *vcpu, · line 111
Quoted 10 lines
virt/kvm/arm/vgic/vgic-mmio.h +7
-0+void vgic_mmio_write_cactive (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val); + +void vgic_mmio_write_sactive (struct kvm_vcpu *vcpu, +gpa_t addr,unsigned int len, +unsigned long val);unsigned int vgic_v2_init_dist_iodev (struct vgic_io_device *dev);Thanks,
M.