KVM/ARM updates for 4.11
Subsystems (6)
Paolo, Radim,
Here's the KVM/ARM updates for 4.11. On the menu this time, GICv3 save/restore, physical timer emulation, and a number of fixes.
Thanks,
M.
The following changes since commit 7a308bb3016f57e5be11a677d15b821536419d36:
Linux 4.10-rc5 (2017-01-22 12:54:15 -0800)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git tags/kvmarm-for-4.11
for you to fetch changes up to 7b6b46311a8562fb3a9e035ed6ffab6d49c28886:
KVM: arm/arm64: Emulate the EL1 phys timer registers (2017-02-08 15:13:37 +0000)
----------------------------------------------------------------
kvmarm updates for 4.11
- GICv3 save restore
- Cache flushing fixes
- MSI injection fix for GICv3 ITS
- Physical timer emulation support
----------------------------------------------------------------
Christoffer Dall (3):
KVM: arm/arm64: Remove struct vgic_irq pending field
KVM: arm/arm64: vgic: Add debugfs vgic-state file
KVM: arm/arm64: Remove kvm_vgic_inject_mapped_irq
Jintack Lim (10):
KVM: arm/arm64: Abstract virtual timer context into separate structure
KVM: arm/arm64: Move cntvoff to each timer context
KVM: arm/arm64: Decouple kvm timer functions from virtual timer
KVM: arm/arm64: Add the EL1 physical timer context
KVM: arm/arm64: Initialize the emulated EL1 physical timer
KVM: arm/arm64: Update the physical timer interrupt level
KVM: arm/arm64: Set a background timer to the earliest timer expiration
KVM: arm/arm64: Set up a background timer for the physical timer emulation
KVM: arm64: Add the EL1 physical timer access handler
KVM: arm/arm64: Emulate the EL1 phys timer registers
Marc Zyngier (3):
arm/arm64: KVM: Enforce unconditional flush to PoC when mapping to stage-2 arm/arm64: KVM: Stop propagating cacheability status of a faulted page arm/arm64: KVM: Get rid of KVM_MEMSLOT_INCOHERENT
Shanker Donthineni (1):
KVM: arm/arm64: vgic: Stop injecting the MSI occurrence twice
Vijaya Kumar K (8):
KVM: arm/arm64: vgic: Implement support for userspace access
KVM: arm/arm64: vgic: Add distributor and redistributor access
KVM: arm/arm64: vgic: Introduce find_reg_by_id() irqchip/gic-v3: Add missing system register definitions
KVM: arm/arm64: vgic: Introduce VENG0 and VENG1 fields to vmcr struct
KVM: arm/arm64: vgic: Implement VGICv3 CPU interface access
KVM: arm/arm64: vgic: Implement KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO ioctl
KVM: arm/arm64: Documentation: Update arm-vgic-v3.txt
Documentation/virtual/kvm/devices/arm-vgic-v3.txt | 11 +- arch/arm/include/asm/kvm_host.h | 3 - arch/arm/include/asm/kvm_mmu.h | 12 +- arch/arm/include/uapi/asm/kvm.h | 13 + arch/arm/kvm/Makefile | 5 +- arch/arm/kvm/arm.c | 4 +- arch/arm/kvm/mmu.c | 20 +- arch/arm/kvm/reset.c | 9 +- arch/arm/kvm/vgic-v3-coproc.c | 35 +++ arch/arm64/include/asm/kvm_host.h | 3 - arch/arm64/include/asm/kvm_mmu.h | 6 +- arch/arm64/include/uapi/asm/kvm.h | 13 + arch/arm64/kvm/Makefile | 4 +- arch/arm64/kvm/reset.c | 9 +- arch/arm64/kvm/sys_regs.c | 92 +++++- arch/arm64/kvm/sys_regs.h | 4 + arch/arm64/kvm/vgic-sys-reg-v3.c | 346 ++++++++++++++++++++++ include/kvm/arm_arch_timer.h | 39 +-- include/kvm/arm_vgic.h | 18 +- include/linux/irqchip/arm-gic-v3.h | 45 ++- include/linux/kvm_host.h | 1 - virt/kvm/arm/arch_timer.c | 201 +++++++++---- virt/kvm/arm/hyp/timer-sr.c | 13 +- virt/kvm/arm/vgic/vgic-debug.c | 283 ++++++++++++++++++ virt/kvm/arm/vgic/vgic-init.c | 4 + virt/kvm/arm/vgic/vgic-irqfd.c | 3 + virt/kvm/arm/vgic/vgic-its.c | 6 +- virt/kvm/arm/vgic/vgic-kvm-device.c | 231 ++++++++++++++- virt/kvm/arm/vgic/vgic-mmio-v2.c | 87 ++---- virt/kvm/arm/vgic/vgic-mmio-v3.c | 203 +++++++++++-- virt/kvm/arm/vgic/vgic-mmio.c | 167 +++++++++-- virt/kvm/arm/vgic/vgic-mmio.h | 24 ++ virt/kvm/arm/vgic/vgic-v2.c | 12 +- virt/kvm/arm/vgic/vgic-v3.c | 40 ++- virt/kvm/arm/vgic/vgic.c | 66 ++--- virt/kvm/arm/vgic/vgic.h | 83 +++++- 36 files changed, 1785 insertions(+), 330 deletions(-) create mode 100644 arch/arm/kvm/vgic-v3-coproc.c create mode 100644 arch/arm64/kvm/vgic-sys-reg-v3.c create mode 100644 virt/kvm/arm/vgic/vgic-debug.c
PATCH 1/25 KVM: arm/arm64: Remove struct vgic_irq pending field
From: Christoffer Dall <[email protected]>
One of the goals behind the VGIC redesign was to get rid of cached or intermediate state in the data structures, but we decided to allow ourselves to precompute the pending value of an IRQ based on the line level and pending latch state. However, this has now become difficult to base proper GICv3 save/restore on, because there is a potential to modify the pending state without knowing if an interrupt is edge or level configured.
See the following post and related message for more background:
https://lists.cs.columbia.edu/pipermail/kvmarm/2017-January/023195.html
This commit gets rid of the precomputed pending field in favor of a function that calculates the value when needed, irq_is_pending().
The soft_pending field is renamed to pending_latch to represent that this latch is the equivalent hardware latch which gets manipulated by the input signal for edge-triggered interrupts and when writing to the SPENDR/CPENDR registers.
After this commit save/restore code should be able to simply restore the pending_latch state, line_level state, and config state in any order and get the desired result.
--- include/kvm/arm_vgic.h | 5 +++-- virt/kvm/arm/vgic/vgic-its.c | 6 +++--- virt/kvm/arm/vgic/vgic-mmio-v2.c | 6 +++--- virt/kvm/arm/vgic/vgic-mmio-v3.c | 2 +- virt/kvm/arm/vgic/vgic-mmio.c | 19 +++++-------------- virt/kvm/arm/vgic/vgic-v2.c | 12 +++++------- virt/kvm/arm/vgic/vgic-v3.c | 12 +++++------- virt/kvm/arm/vgic/vgic.c | 16 +++++++--------- virt/kvm/arm/vgic/vgic.h | 8 ++++++++ 9 files changed, 40 insertions(+), 46 deletions(-)
include/kvm/arm_vgic.h +3 -2
@@ -101,9 +101,10 @@ struct vgic_irq {*/ u32 intid;/* Guest visible INTID */ -bool pending;bool line_level;/* Level only */ -bool soft_pending;/* Level only */ +bool pending_latch;/* The pending latch state used to calculate +* the pending state for both level +* and edge triggered IRQs. */ bool active;/* not used for LPIs */ bool enabled;bool hw;/* Tied to HW IRQ */
virt/kvm/arm/vgic/vgic-its.c +3 -3
@@ -350,7 +350,7 @@ static int its_sync_lpi_pending_table(struct kvm_vcpu *vcpu) irq =vgic_get_irq (vcpu->kvm,NULL , intids[i]);spin_lock (&irq->irq_lock); - irq->pending = pendmask & (1U << bit_nr); + irq->pending_latch = pendmask & (1U << bit_nr);vgic_queue_irq_unlock (vcpu->kvm, irq);vgic_put_irq (vcpu->kvm, irq); }
@@ -465,7 +465,7 @@ static int vgic_its_trigger_msi(struct kvm *kvm, struct vgic_its *its,return -EBUSY ;spin_lock (&itte->irq->irq_lock); - itte->irq->pending = true; + itte->irq->pending_latch = true;vgic_queue_irq_unlock (kvm, itte->irq);return 0 ;
@@ -913,7 +913,7 @@ static int vgic_its_cmd_handle_clear(struct kvm *kvm, struct vgic_its *its,if (!itte)return E_ITS_CLEAR_UNMAPPED_INTERRUPT ; - itte->irq->pending = false; + itte->irq->pending_latch = false;return 0 ; }
virt/kvm/arm/vgic/vgic-mmio-v2.c +3 -3
@@ -98,7 +98,7 @@ static void vgic_mmio_write_sgir(struct kvm_vcpu *source_vcpu, irq =vgic_get_irq (source_vcpu->kvm, vcpu, intid);spin_lock (&irq->irq_lock); - irq->pending = true; + irq->pending_latch = true; irq->source |=1U << source_vcpu->vcpu_id;vgic_queue_irq_unlock (source_vcpu->kvm, irq);
@@ -182,7 +182,7 @@ static void vgic_mmio_write_sgipendc(struct kvm_vcpu *vcpu, irq->source &= ~((val >> (i *8 )) &0xff );if (!irq->source) - irq->pending = false; + irq->pending_latch = false;spin_unlock (&irq->irq_lock);vgic_put_irq (vcpu->kvm, irq);
@@ -204,7 +204,7 @@ static void vgic_mmio_write_sgipends(struct kvm_vcpu *vcpu, irq->source |= (val >> (i *8 )) &0xff ;if (irq->source) { - irq->pending = true; + irq->pending_latch = true;vgic_queue_irq_unlock (vcpu->kvm, irq); }else {spin_unlock (&irq->irq_lock);
virt/kvm/arm/vgic/vgic-mmio-v3.c +1 -1
@@ -646,7 +646,7 @@ void vgic_v3_dispatch_sgi(struct kvm_vcpu *vcpu, u64 reg) irq =vgic_get_irq (vcpu->kvm, c_vcpu, sgi);spin_lock (&irq->irq_lock); - irq->pending = true; + irq->pending_latch = true;vgic_queue_irq_unlock (vcpu->kvm, irq);vgic_put_irq (vcpu->kvm, irq);
virt/kvm/arm/vgic/vgic-mmio.c +5 -14
@@ -111,7 +111,7 @@ unsigned long vgic_mmio_read_pending(struct kvm_vcpu *vcpu,for (i =0 ; i < len *8 ; i++) {struct vgic_irq *irq =vgic_get_irq (vcpu->kvm, vcpu, intid + i); -if (irq->pending) +if (irq_is_pending (irq)) value |= (1U << i);vgic_put_irq (vcpu->kvm, irq);
@@ -131,9 +131,7 @@ void vgic_mmio_write_spending(struct kvm_vcpu *vcpu,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; + irq->pending_latch = true;vgic_queue_irq_unlock (vcpu->kvm, irq);vgic_put_irq (vcpu->kvm, irq);
@@ -152,12 +150,7 @@ void vgic_mmio_write_cpending(struct kvm_vcpu *vcpu,spin_lock (&irq->irq_lock); -if (irq->config ==VGIC_CONFIG_LEVEL ) { - irq->soft_pending = false; - irq->pending = irq->line_level; - }else { - irq->pending = false; - } + irq->pending_latch = false;spin_unlock (&irq->irq_lock);vgic_put_irq (vcpu->kvm, irq);
@@ -359,12 +352,10 @@ void vgic_mmio_write_config(struct kvm_vcpu *vcpu, irq =vgic_get_irq (vcpu->kvm, vcpu, intid + i);spin_lock (&irq->irq_lock); -if (test_bit (i *2 +1 , &val)) { +if (test_bit (i *2 +1 , &val)) irq->config =VGIC_CONFIG_EDGE ; - }else { +else irq->config =VGIC_CONFIG_LEVEL ; - irq->pending = irq->line_level | irq->soft_pending; - }spin_unlock (&irq->irq_lock);vgic_put_irq (vcpu->kvm, irq);
virt/kvm/arm/vgic/vgic-v2.c +5 -7
@@ -104,7 +104,7 @@ void vgic_v2_fold_lr_state(struct kvm_vcpu *vcpu)/* 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; + irq->pending_latch = true;if (vgic_irq_is_sgi (intid)) {u32 cpuid = val &GICH_LR_PHYSID_CPUID ;
@@ -120,9 +120,7 @@ void vgic_v2_fold_lr_state(struct kvm_vcpu *vcpu)*/ if (irq->config ==VGIC_CONFIG_LEVEL ) {if (!(val &GICH_LR_PENDING_BIT )) - irq->soft_pending = false; - - irq->pending = irq->line_level || irq->soft_pending; + irq->pending_latch = false; }spin_unlock (&irq->irq_lock);
@@ -145,11 +143,11 @@ void vgic_v2_populate_lr(struct kvm_vcpu *vcpu, struct vgic_irq *irq, int lr) {u32 val = irq->intid; -if (irq->pending) { +if (irq_is_pending (irq)) { val |=GICH_LR_PENDING_BIT ;if (irq->config ==VGIC_CONFIG_EDGE ) - irq->pending = false; + irq->pending_latch = false;if (vgic_irq_is_sgi (irq->intid)) {u32 src =ffs (irq->source);
@@ -158,7 +156,7 @@ void vgic_v2_populate_lr(struct kvm_vcpu *vcpu, struct vgic_irq *irq, int lr) val |= (src -1 ) <<GICH_LR_PHYSID_CPUID_SHIFT ; irq->source &= ~(1 << (src -1 ));if (irq->source) - irq->pending = true; + irq->pending_latch = true; } }
virt/kvm/arm/vgic/vgic-v3.c +5 -7
@@ -94,7 +94,7 @@ void vgic_v3_fold_lr_state(struct kvm_vcpu *vcpu)/* 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; + irq->pending_latch = true;if (vgic_irq_is_sgi (intid) && model ==KVM_DEV_TYPE_ARM_VGIC_V2 ) {
@@ -111,9 +111,7 @@ void vgic_v3_fold_lr_state(struct kvm_vcpu *vcpu)*/ if (irq->config ==VGIC_CONFIG_LEVEL ) {if (!(val &ICH_LR_PENDING_BIT )) - irq->soft_pending = false; - - irq->pending = irq->line_level || irq->soft_pending; + irq->pending_latch = false; }spin_unlock (&irq->irq_lock);
@@ -127,11 +125,11 @@ 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) { +if (irq_is_pending (irq)) { val |=ICH_LR_PENDING_BIT ;if (irq->config ==VGIC_CONFIG_EDGE ) - irq->pending = false; + irq->pending_latch = false;if (vgic_irq_is_sgi (irq->intid) && model ==KVM_DEV_TYPE_ARM_VGIC_V2 ) {
@@ -141,7 +139,7 @@ void vgic_v3_populate_lr(struct kvm_vcpu *vcpu, struct vgic_irq *irq, int lr) val |= (src -1 ) <<GICH_LR_PHYSID_CPUID_SHIFT ; irq->source &= ~(1 << (src -1 ));if (irq->source) - irq->pending = true; + irq->pending_latch = true; } }
virt/kvm/arm/vgic/vgic.c +7 -9
@@ -160,7 +160,7 @@ static struct kvm_vcpu *vgic_target_oracle(struct vgic_irq *irq)* If the distributor is disabled, pending interrupts shouldn't be * forwarded. */ -if (irq->enabled && irq->pending) { +if (irq->enabled &&irq_is_pending (irq)) {if (unlikely (irq->target_vcpu && !irq->target_vcpu->kvm->arch.vgic.enabled))return NULL ;
@@ -204,8 +204,8 @@ static int vgic_irq_cmp(void *priv, struct list_head *a, struct list_head *b) goto out; } - penda = irqa->enabled && irqa->pending; - pendb = irqb->enabled && irqb->pending; + penda = irqa->enabled &&irq_is_pending (irqa); + pendb = irqb->enabled &&irq_is_pending (irqb);if (!penda || !pendb) { ret = (int )pendb - (int )penda;
@@ -371,12 +371,10 @@ static int vgic_update_irq_pending(struct kvm *kvm, int cpuid,return 0 ; } -if (irq->config ==VGIC_CONFIG_LEVEL ) { +if (irq->config ==VGIC_CONFIG_LEVEL ) irq->line_level = level; - irq->pending = level || irq->soft_pending; - }else { - irq->pending = true; - } +else + irq->pending_latch = true;vgic_queue_irq_unlock (kvm, irq);vgic_put_irq (kvm, irq);
@@ -689,7 +687,7 @@ int kvm_vgic_vcpu_pending_irq(struct kvm_vcpu *vcpu)list_for_each_entry (irq, &vgic_cpu->ap_list_head, ap_list) {spin_lock (&irq->irq_lock); - pending = irq->pending && irq->enabled; + pending =irq_is_pending (irq) && irq->enabled;spin_unlock (&irq->irq_lock);if (pending)
virt/kvm/arm/vgic/vgic.h +8 -0
@@ -30,6 +30,14 @@#define vgic_irq_is_sgi (intid) ((intid) < VGIC_NR_SGIS) +static inline bool irq_is_pending (struct vgic_irq *irq) +{ +if (irq->config ==VGIC_CONFIG_EDGE ) +return irq->pending_latch; +else +return irq->pending_latch || irq->line_level; +} +struct vgic_vmcr {u32 ctlr;u32 abpr;
Signature · 1 line
2.1.4
PATCH 2/25 KVM: arm/arm64: vgic: Add debugfs vgic-state file
In reply to Marc ZyngierFrom: Christoffer Dall <[email protected]>
Add a file to debugfs to read the in-kernel state of the vgic. We don't do any locking of the entire VGIC state while traversing all the IRQs, so if the VM is running the user/developer may not see a quiesced state, but should take care to pause the VM using facilities in user space for that purpose.
We also don't support LPIs yet, but they can be added easily if needed.
--- arch/arm/kvm/Makefile | 1 + arch/arm64/kvm/Makefile | 1 + include/kvm/arm_vgic.h | 5 + virt/kvm/arm/vgic/vgic-debug.c | 283 +++++++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-init.c | 4 + virt/kvm/arm/vgic/vgic.h | 3 + 6 files changed, 297 insertions(+) create mode 100644 virt/kvm/arm/vgic/vgic-debug.c
arch/arm/kvm/Makefile +1 -0
@@ -33,5 +33,6 @@ obj-y += $(KVM)/arm/vgic/vgic-mmio-v2.o obj-y += $(KVM)/arm/vgic/vgic-mmio-v3.o obj-y += $(KVM)/arm/vgic/vgic-kvm-device.o obj-y += $(KVM)/arm/vgic/vgic-its.o +obj-y += $(KVM)/arm/vgic/vgic-debug.o obj-y += $(KVM)/irqchip.o obj-y += $(KVM)/arm/arch_timer.o
arch/arm64/kvm/Makefile +1 -0
@@ -31,6 +31,7 @@ kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic-mmio-v2.o kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic-mmio-v3.o kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic-kvm-device.o kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic-its.o +kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic-debug.o kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/irqchip.o kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/arch_timer.o kvm-$(CONFIG_KVM_ARM_PMU) += $(KVM)/arm/pmu.o
include/kvm/arm_vgic.h +5 -0
@@ -166,6 +166,8 @@ struct vgic_its {struct list_head collection_list; }; +struct vgic_state_iter ; +struct vgic_dist {bool in_kernel;bool ready;
@@ -213,6 +215,9 @@ struct vgic_dist {spinlock_t lpi_list_lock;struct list_head lpi_list_head;int lpi_list_count; + +/* used by vgic-debug */ +struct vgic_state_iter *iter; };struct vgic_v2_cpu_if {
virt/kvm/arm/vgic/vgic-debug.c new file +283 -0
283 lines not on this page · raw message
virt/kvm/arm/vgic/vgic-init.c +4 -0
@@ -259,6 +259,8 @@ int vgic_init(struct kvm *kvm)if (ret) goto out; +vgic_debug_init (kvm); + dist->initialized = true; out:return ret;
@@ -288,6 +290,8 @@ static void __kvm_vgic_destroy(struct kvm *kvm)struct kvm_vcpu *vcpu;int i; +vgic_debug_destroy (kvm); +kvm_vgic_dist_destroy (kvm);kvm_for_each_vcpu (i, vcpu, kvm)
virt/kvm/arm/vgic/vgic.h +3 -0
@@ -102,4 +102,7 @@ int kvm_register_vgic_device(unsigned long type);int vgic_lazy_init (struct kvm *kvm);int vgic_init (struct kvm *kvm); +int vgic_debug_init (struct kvm *kvm); +int vgic_debug_destroy (struct kvm *kvm); +#endif
Signature · 1 line
2.1.4
PATCH 3/25 KVM: arm/arm64: vgic: Implement support for userspace access
In reply to Marc ZyngierFrom: Vijaya Kumar K <[email protected]>
Read and write of some registers like ISPENDR and ICPENDR from userspace requires special handling when compared to guest access for these registers.
Refer to Documentation/virtual/kvm/devices/arm-vgic-v3.txt for handling of ISPENDR, ICPENDR registers handling.
Add infrastructure to support guest and userspace read and write for the required registers
Also moved vgic_uaccess from vgic-mmio-v2.c to vgic-mmio.c
--- virt/kvm/arm/vgic/vgic-mmio-v2.c | 25 ----------- virt/kvm/arm/vgic/vgic-mmio-v3.c | 96 ++++++++++++++++++++++++++++++++-------- virt/kvm/arm/vgic/vgic-mmio.c | 78 +++++++++++++++++++++++++++++--- virt/kvm/arm/vgic/vgic-mmio.h | 19 ++++++++ 4 files changed, 169 insertions(+), 49 deletions(-)
virt/kvm/arm/vgic/vgic-mmio-v2.c +0 -25
@@ -407,31 +407,6 @@ int vgic_v2_has_attr_regs(struct kvm_device *dev, struct kvm_device_attr *attr)return -ENXIO ; } -/* -* When userland tries to access the VGIC register handlers, we need to -* create a usable struct vgic_io_device to be passed to the handlers and we -* have to set up a buffer similar to what would have happened if a guest MMIO -* access occurred, including doing endian conversions on BE systems. -*/ -static int vgic_uaccess (struct kvm_vcpu *vcpu,struct vgic_io_device *dev, -bool is_write,int offset,u32 *val) -{ -unsigned int len =4 ; -u8 buf[4 ]; -int ret; - -if (is_write) { -vgic_data_host_to_mmio_bus (buf, len, *val); - ret = kvm_io_gic_ops.write (vcpu, &dev->dev, offset, len, buf); - }else { - ret = kvm_io_gic_ops.read (vcpu, &dev->dev, offset, len, buf); -if (!ret) - *val =vgic_data_mmio_bus_to_host (buf, len); - } - -return ret; -} -int vgic_v2_cpuif_uaccess (struct kvm_vcpu *vcpu,bool is_write,int offset,u32 *val) {
virt/kvm/arm/vgic/vgic-mmio-v3.c +78 -18
148 lines not on this page · raw message
virt/kvm/arm/vgic/vgic-mmio.c +72 -6
96 lines not on this page · raw message
virt/kvm/arm/vgic/vgic-mmio.h +19 -0
@@ -34,6 +34,10 @@ struct vgic_register_region { gpa_t addr, unsigned int len, unsigned long val); }; +unsigned long (*uaccess_read)(struct kvm_vcpu *vcpu,gpa_t addr, +unsigned int len); +void (*uaccess_write)(struct kvm_vcpu *vcpu,gpa_t addr, +unsigned int len,unsigned long val); };extern struct kvm_io_device_ops kvm_io_gic_ops;
@@ -86,6 +90,18 @@ extern struct kvm_io_device_ops kvm_io_gic_ops; .write = wr, \ } +#define REGISTER_DESC_WITH_LENGTH_UACCESS (off, rd, wr, urd, uwr, length, acc) \ + { \ + .reg_offset = off, \ + .bits_per_irq = 0, \ + .len = length, \ + .access_flags = acc, \ + .read = rd, \ + .write = wr, \ + .uaccess_read = urd, \ + .uaccess_write = uwr, \ + } + int kvm_vgic_register_mmio_region(struct kvm *kvm, struct kvm_vcpu *vcpu, struct vgic_register_region *reg_desc, struct vgic_io_device *region,
@@ -158,6 +174,9 @@ void vgic_mmio_write_config(struct kvm_vcpu *vcpu, gpa_t addr, unsigned int len, unsigned long val); +int vgic_uaccess (struct kvm_vcpu *vcpu,struct vgic_io_device *dev, +bool is_write,int offset,u32 *val); +unsigned int vgic_v2_init_dist_iodev (struct vgic_io_device *dev);unsigned int vgic_v3_init_dist_iodev (struct vgic_io_device *dev);
Signature · 1 line
2.1.4
PATCH 4/25 KVM: arm/arm64: vgic: Add distributor and redistributor access
In reply to Marc ZyngierFrom: Vijaya Kumar K <[email protected]>
VGICv3 Distributor and Redistributor registers are accessed using KVM_DEV_ARM_VGIC_GRP_DIST_REGS and KVM_DEV_ARM_VGIC_GRP_REDIST_REGS with KVM_SET_DEVICE_ATTR and KVM_GET_DEVICE_ATTR ioctls. These registers are accessed as 32-bit and cpu mpidr value passed along with register offset is used to identify the cpu for redistributor registers access.
The version of VGIC v3 specification is defined here Documentation/virtual/kvm/devices/arm-vgic-v3.txt
Also update arch/arm/include/uapi/asm/kvm.h to compile for AArch32 mode.
--- arch/arm/include/uapi/asm/kvm.h | 4 + arch/arm64/include/uapi/asm/kvm.h | 4 + virt/kvm/arm/vgic/vgic-kvm-device.c | 161 ++++++++++++++++++++++++++++++++---- virt/kvm/arm/vgic/vgic-mmio-v2.c | 40 ++++----- virt/kvm/arm/vgic/vgic-mmio-v3.c | 85 +++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.c | 2 +- virt/kvm/arm/vgic/vgic.h | 40 ++++++++- 7 files changed, 300 insertions(+), 36 deletions(-)
arch/arm/include/uapi/asm/kvm.h +4 -0
@@ -181,10 +181,14 @@ struct kvm_arch_memory_slot {#define KVM_DEV_ARM_VGIC_GRP_CPU_REGS 2#define KVM_DEV_ARM_VGIC_CPUID_SHIFT 32#define KVM_DEV_ARM_VGIC_CPUID_MASK (0xffULL << KVM_DEV_ARM_VGIC_CPUID_SHIFT) +#define KVM_DEV_ARM_VGIC_V3_MPIDR_SHIFT 32 +#define KVM_DEV_ARM_VGIC_V3_MPIDR_MASK \ + (0xffffffffULL << KVM_DEV_ARM_VGIC_V3_MPIDR_SHIFT)#define KVM_DEV_ARM_VGIC_OFFSET_SHIFT 0#define KVM_DEV_ARM_VGIC_OFFSET_MASK (0xffffffffULL << KVM_DEV_ARM_VGIC_OFFSET_SHIFT)#define KVM_DEV_ARM_VGIC_GRP_NR_IRQS 3#define KVM_DEV_ARM_VGIC_GRP_CTRL 4 +#define KVM_DEV_ARM_VGIC_GRP_REDIST_REGS 5#define KVM_DEV_ARM_VGIC_CTRL_INIT 0/* KVM_IRQ_LINE irq field index values */
arch/arm64/include/uapi/asm/kvm.h +4 -0
@@ -201,10 +201,14 @@ struct kvm_arch_memory_slot {#define KVM_DEV_ARM_VGIC_GRP_CPU_REGS 2#define KVM_DEV_ARM_VGIC_CPUID_SHIFT 32#define KVM_DEV_ARM_VGIC_CPUID_MASK (0xffULL << KVM_DEV_ARM_VGIC_CPUID_SHIFT) +#define KVM_DEV_ARM_VGIC_V3_MPIDR_SHIFT 32 +#define KVM_DEV_ARM_VGIC_V3_MPIDR_MASK \ + (0xffffffffULL << KVM_DEV_ARM_VGIC_V3_MPIDR_SHIFT)#define KVM_DEV_ARM_VGIC_OFFSET_SHIFT 0#define KVM_DEV_ARM_VGIC_OFFSET_MASK (0xffffffffULL << KVM_DEV_ARM_VGIC_OFFSET_SHIFT)#define KVM_DEV_ARM_VGIC_GRP_NR_IRQS 3#define KVM_DEV_ARM_VGIC_GRP_CTRL 4 +#define KVM_DEV_ARM_VGIC_GRP_REDIST_REGS 5#define KVM_DEV_ARM_VGIC_CTRL_INIT 0/* Device Control API on vcpu fd */
virt/kvm/arm/vgic/vgic-kvm-device.c +146 -15
223 lines not on this page · raw message
virt/kvm/arm/vgic/vgic-mmio-v2.c +21 -19
@@ -369,21 +369,30 @@ unsigned int vgic_v2_init_dist_iodev(struct vgic_io_device *dev)int vgic_v2_has_attr_regs (struct kvm_device *dev,struct kvm_device_attr *attr) { -int nr_irqs = dev->kvm->arch.vgic.nr_spis +VGIC_NR_PRIVATE_IRQS ; -const struct vgic_register_region *regions; +const struct vgic_register_region *region; +struct vgic_io_device iodev; +struct vgic_reg_attr reg_attr; +struct kvm_vcpu *vcpu;gpa_t addr; -int nr_regions, i, len; +int ret; + + ret =vgic_v2_parse_attr (dev, attr, ®_attr); +if (ret) +return ret; - addr = attr->attr &KVM_DEV_ARM_VGIC_OFFSET_MASK ; + vcpu = reg_attr.vcpu; + addr = reg_attr.addr;switch (attr->group) {case KVM_DEV_ARM_VGIC_GRP_DIST_REGS : - regions = vgic_v2_dist_registers; - nr_regions =ARRAY_SIZE (vgic_v2_dist_registers); + iodev.regions = vgic_v2_dist_registers; + iodev.nr_regions =ARRAY_SIZE (vgic_v2_dist_registers); + iodev.base_addr =0 ;break ;case KVM_DEV_ARM_VGIC_GRP_CPU_REGS : - regions = vgic_v2_cpu_registers; - nr_regions =ARRAY_SIZE (vgic_v2_cpu_registers); + iodev.regions = vgic_v2_cpu_registers; + iodev.nr_regions =ARRAY_SIZE (vgic_v2_cpu_registers); + iodev.base_addr =0 ;break ;default :return -ENXIO ;
@@ -393,18 +402,11 @@ int vgic_v2_has_attr_regs(struct kvm_device *dev, struct kvm_device_attr *attr)if (addr &3 )return -ENXIO ; -for (i =0 ; i < nr_regions; i++) { -if (regions[i].bits_per_irq) - len = (regions[i].bits_per_irq * nr_irqs) /8 ; -else - len = regions[i].len; - -if (regions[i].reg_offset <= addr && - regions[i].reg_offset + len > addr) -return 0 ; - } + region =vgic_get_mmio_region (vcpu, &iodev, addr,sizeof (u32)); +if (!region) +return -ENXIO ; -return -ENXIO ; +return 0 ; } int vgic_v2_cpuif_uaccess(struct kvm_vcpu *vcpu, bool is_write,
virt/kvm/arm/vgic/vgic-mmio-v3.c +85 -0
118 lines not on this page · raw message
virt/kvm/arm/vgic/vgic-mmio.c +1 -1
@@ -475,7 +475,7 @@ static bool check_region(const struct kvm *kvm,return false; } -static const struct vgic_register_region * +const struct vgic_register_region *vgic_get_mmio_region (struct kvm_vcpu *vcpu,struct vgic_io_device *iodev,gpa_t addr,int len) {
virt/kvm/arm/vgic/vgic.h +39 -1
@@ -30,6 +30,28 @@#define vgic_irq_is_sgi (intid) ((intid) < VGIC_NR_SGIS) +#define VGIC_AFFINITY_0_SHIFT 0 +#define VGIC_AFFINITY_0_MASK (0xffUL << VGIC_AFFINITY_0_SHIFT) +#define VGIC_AFFINITY_1_SHIFT 8 +#define VGIC_AFFINITY_1_MASK (0xffUL << VGIC_AFFINITY_1_SHIFT) +#define VGIC_AFFINITY_2_SHIFT 16 +#define VGIC_AFFINITY_2_MASK (0xffUL << VGIC_AFFINITY_2_SHIFT) +#define VGIC_AFFINITY_3_SHIFT 24 +#define VGIC_AFFINITY_3_MASK (0xffUL << VGIC_AFFINITY_3_SHIFT) + +#define VGIC_AFFINITY_LEVEL (reg, level) \ + ((((reg) & VGIC_AFFINITY_## level ##_MASK) \ + >> VGIC_AFFINITY_## level ##_SHIFT) << MPIDR_LEVEL_SHIFT(level)) + +/* +* The Userspace encodes the affinity differently from the MPIDR, +* Below macro converts vgic userspace format to MPIDR reg format. +*/ +#define VGIC_TO_MPIDR (val) (VGIC_AFFINITY_LEVEL(val, 0) | \ + VGIC_AFFINITY_LEVEL(val, 1) | \ + VGIC_AFFINITY_LEVEL(val, 2) | \ + VGIC_AFFINITY_LEVEL(val, 3)) +static inline bool irq_is_pending (struct vgic_irq *irq) {if (irq->config ==VGIC_CONFIG_EDGE )
@@ -45,6 +67,18 @@ struct vgic_vmcr {u32 pmr; }; +struct vgic_reg_attr { +struct kvm_vcpu *vcpu; +gpa_t addr; +}; + +int vgic_v3_parse_attr (struct kvm_device *dev,struct kvm_device_attr *attr, +struct vgic_reg_attr *reg_attr); +int vgic_v2_parse_attr (struct kvm_device *dev,struct kvm_device_attr *attr, +struct vgic_reg_attr *reg_attr); +const struct vgic_register_region * +vgic_get_mmio_region (struct kvm_vcpu *vcpu,struct vgic_io_device *iodev, +gpa_t addr,int len);struct vgic_irq *vgic_get_irq (struct kvm *kvm,struct kvm_vcpu *vcpu,u32 intid);void vgic_put_irq (struct kvm *kvm,struct vgic_irq *irq);
@@ -97,7 +131,11 @@ bool vgic_has_its(struct kvm *kvm);int kvm_vgic_register_its_device (void );void vgic_enable_lpis (struct kvm_vcpu *vcpu);int vgic_its_inject_msi (struct kvm *kvm,struct kvm_msi *msi); - +int vgic_v3_has_attr_regs (struct kvm_device *dev,struct kvm_device_attr *attr); +int vgic_v3_dist_uaccess (struct kvm_vcpu *vcpu,bool is_write, +int offset,u32 *val); +int vgic_v3_redist_uaccess (struct kvm_vcpu *vcpu,bool is_write, +int offset,u32 *val);int kvm_register_vgic_device (unsigned long type);int vgic_lazy_init (struct kvm *kvm);int vgic_init (struct kvm *kvm);
Signature · 1 line
2.1.4
PATCH 5/25 KVM: arm/arm64: vgic: Introduce find_reg_by_id()
In reply to Marc ZyngierFrom: Vijaya Kumar K <[email protected]>
In order to implement vGICv3 CPU interface access, we will need to perform table lookup of system registers. We would need both index_to_params() and find_reg() exported for that purpose, but instead we export a single function which combines them both.
--- arch/arm64/kvm/sys_regs.c | 27 ++++++++++++++++----------- arch/arm64/kvm/sys_regs.h | 4 ++++ 2 files changed, 20 insertions(+), 11 deletions(-)
arch/arm64/kvm/sys_regs.c +16 -11
@@ -1795,6 +1795,17 @@ static bool index_to_params(u64 id, struct sys_reg_params *params) } } +const struct sys_reg_desc *find_reg_by_id (u64 id, +struct sys_reg_params *params, +const struct sys_reg_desc table[], +unsigned int num) +{ +if (!index_to_params (id, params)) +return NULL ; + +return find_reg (params, table, num); +} +/* Decode an index value, and find the sys_reg_desc entry. */ static const struct sys_reg_desc *index_to_sys_reg_desc (struct kvm_vcpu *vcpu,u64 id)
@@ -1807,11 +1818,8 @@ static const struct sys_reg_desc *index_to_sys_reg_desc(struct kvm_vcpu *vcpu,if ((id &KVM_REG_ARM_COPROC_MASK ) !=KVM_REG_ARM64_SYSREG )return NULL ; -if (!index_to_params (id, ¶ms)) -return NULL ; - table =get_target_table (vcpu->arch.target, true, &num); - r =find_reg (¶ms, table, num); + r =find_reg_by_id (id, ¶ms, table, num);if (!r) r =find_reg (¶ms, sys_reg_descs,ARRAY_SIZE (sys_reg_descs));
@@ -1918,10 +1926,8 @@ static int get_invariant_sys_reg(u64 id, void __user *uaddr)struct sys_reg_params params;const struct sys_reg_desc *r; -if (!index_to_params (id, ¶ms)) -return -ENOENT ; - - r =find_reg (¶ms, invariant_sys_regs,ARRAY_SIZE (invariant_sys_regs)); + r =find_reg_by_id (id, ¶ms, invariant_sys_regs, +ARRAY_SIZE (invariant_sys_regs));if (!r)return -ENOENT ;
@@ -1935,9 +1941,8 @@ static int set_invariant_sys_reg(u64 id, void __user *uaddr)int err;u64 val =0 ;/* Make sure high bits are 0 for 32-bit regs */ -if (!index_to_params (id, ¶ms)) -return -ENOENT ; - r =find_reg (¶ms, invariant_sys_regs,ARRAY_SIZE (invariant_sys_regs)); + r =find_reg_by_id (id, ¶ms, invariant_sys_regs, +ARRAY_SIZE (invariant_sys_regs));if (!r)return -ENOENT ;
arch/arm64/kvm/sys_regs.h +4 -0
@@ -136,6 +136,10 @@ static inline int cmp_sys_reg(const struct sys_reg_desc *i1,return i1->Op2 - i2->Op2; } +const struct sys_reg_desc *find_reg_by_id (u64 id, +struct sys_reg_params *params, +const struct sys_reg_desc table[], +unsigned int num);#define Op0 (_x) .Op0 = _x#define Op1 (_x) .Op1 = _x
Signature · 1 line
2.1.4
PATCH 6/25 irqchip/gic-v3: Add missing system register definitions
In reply to Marc ZyngierFrom: Vijaya Kumar K <[email protected]>
Define register definitions for ICH_VMCR_EL2, ICC_CTLR_EL1 and ICH_VTR_EL2, ICC_BPR0_EL1, ICC_BPR1_EL1 registers.
--- include/linux/irqchip/arm-gic-v3.h | 43 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-)
include/linux/irqchip/arm-gic-v3.h +41 -2
@@ -352,8 +352,30 @@/* * CPU interface registers */ -#define ICC_CTLR_EL1_EOImode_drop_dir (0U << 1) -#define ICC_CTLR_EL1_EOImode_drop (1U << 1) +#define ICC_CTLR_EL1_EOImode_SHIFT (1) +#define ICC_CTLR_EL1_EOImode_drop_dir (0U << ICC_CTLR_EL1_EOImode_SHIFT) +#define ICC_CTLR_EL1_EOImode_drop (1U << ICC_CTLR_EL1_EOImode_SHIFT) +#define ICC_CTLR_EL1_EOImode_MASK (1 << ICC_CTLR_EL1_EOImode_SHIFT) +#define ICC_CTLR_EL1_CBPR_SHIFT 0 +#define ICC_CTLR_EL1_CBPR_MASK (1 << ICC_CTLR_EL1_CBPR_SHIFT) +#define ICC_CTLR_EL1_PRI_BITS_SHIFT 8 +#define ICC_CTLR_EL1_PRI_BITS_MASK (0x7 << ICC_CTLR_EL1_PRI_BITS_SHIFT) +#define ICC_CTLR_EL1_ID_BITS_SHIFT 11 +#define ICC_CTLR_EL1_ID_BITS_MASK (0x7 << ICC_CTLR_EL1_ID_BITS_SHIFT) +#define ICC_CTLR_EL1_SEIS_SHIFT 14 +#define ICC_CTLR_EL1_SEIS_MASK (0x1 << ICC_CTLR_EL1_SEIS_SHIFT) +#define ICC_CTLR_EL1_A3V_SHIFT 15 +#define ICC_CTLR_EL1_A3V_MASK (0x1 << ICC_CTLR_EL1_A3V_SHIFT) +#define ICC_PMR_EL1_SHIFT 0 +#define ICC_PMR_EL1_MASK (0xff << ICC_PMR_EL1_SHIFT) +#define ICC_BPR0_EL1_SHIFT 0 +#define ICC_BPR0_EL1_MASK (0x7 << ICC_BPR0_EL1_SHIFT) +#define ICC_BPR1_EL1_SHIFT 0 +#define ICC_BPR1_EL1_MASK (0x7 << ICC_BPR1_EL1_SHIFT) +#define ICC_IGRPEN0_EL1_SHIFT 0 +#define ICC_IGRPEN0_EL1_MASK (1 << ICC_IGRPEN0_EL1_SHIFT) +#define ICC_IGRPEN1_EL1_SHIFT 0 +#define ICC_IGRPEN1_EL1_MASK (1 << ICC_IGRPEN1_EL1_SHIFT)#define ICC_SRE_EL1_SRE (1U << 0)/*
@@ -384,12 +406,29 @@#define ICH_VMCR_CTLR_SHIFT 0#define ICH_VMCR_CTLR_MASK (0x21f << ICH_VMCR_CTLR_SHIFT) +#define ICH_VMCR_CBPR_SHIFT 4 +#define ICH_VMCR_CBPR_MASK (1 << ICH_VMCR_CBPR_SHIFT) +#define ICH_VMCR_EOIM_SHIFT 9 +#define ICH_VMCR_EOIM_MASK (1 << ICH_VMCR_EOIM_SHIFT)#define ICH_VMCR_BPR1_SHIFT 18#define ICH_VMCR_BPR1_MASK (7 << ICH_VMCR_BPR1_SHIFT)#define ICH_VMCR_BPR0_SHIFT 21#define ICH_VMCR_BPR0_MASK (7 << ICH_VMCR_BPR0_SHIFT)#define ICH_VMCR_PMR_SHIFT 24#define ICH_VMCR_PMR_MASK (0xffUL << ICH_VMCR_PMR_SHIFT) +#define ICH_VMCR_ENG0_SHIFT 0 +#define ICH_VMCR_ENG0_MASK (1 << ICH_VMCR_ENG0_SHIFT) +#define ICH_VMCR_ENG1_SHIFT 1 +#define ICH_VMCR_ENG1_MASK (1 << ICH_VMCR_ENG1_SHIFT) + +#define ICH_VTR_PRI_BITS_SHIFT 29 +#define ICH_VTR_PRI_BITS_MASK (7 << ICH_VTR_PRI_BITS_SHIFT) +#define ICH_VTR_ID_BITS_SHIFT 23 +#define ICH_VTR_ID_BITS_MASK (7 << ICH_VTR_ID_BITS_SHIFT) +#define ICH_VTR_SEIS_SHIFT 22 +#define ICH_VTR_SEIS_MASK (1 << ICH_VTR_SEIS_SHIFT) +#define ICH_VTR_A3V_SHIFT 21 +#define ICH_VTR_A3V_MASK (1 << ICH_VTR_A3V_SHIFT)#define ICC_IAR1_EL1_SPURIOUS 0x3ff
Signature · 1 line
2.1.4
PATCH 7/25 KVM: arm/arm64: vgic: Introduce VENG0 and VENG1 fields to vmcr struct
In reply to Marc ZyngierFrom: Vijaya Kumar K <[email protected]>
ICC_VMCR_EL2 supports virtual access to ICC_IGRPEN1_EL1.Enable and ICC_IGRPEN0_EL1.Enable fields. Add grpen0 and grpen1 member variables to struct vmcr to support read and write of these fields.
Also refactor vgic_set_vmcr and vgic_get_vmcr() code. Drop ICH_VMCR_CTLR_SHIFT and ICH_VMCR_CTLR_MASK macros and instead use ICH_VMCR_EOI* and ICH_VMCR_CBPR* macros.
--- include/linux/irqchip/arm-gic-v3.h | 2 -- virt/kvm/arm/vgic/vgic-mmio-v2.c | 16 ---------------- virt/kvm/arm/vgic/vgic-mmio.c | 16 ++++++++++++++++ virt/kvm/arm/vgic/vgic-v3.c | 20 ++++++++++++++++++-- virt/kvm/arm/vgic/vgic.h | 5 +++++ 5 files changed, 39 insertions(+), 20 deletions(-)
include/linux/irqchip/arm-gic-v3.h +0 -2
@@ -404,8 +404,6 @@#define ICH_HCR_EN (1 << 0)#define ICH_HCR_UIE (1 << 1) -#define ICH_VMCR_CTLR_SHIFT 0 -#define ICH_VMCR_CTLR_MASK (0x21f << ICH_VMCR_CTLR_SHIFT)#define ICH_VMCR_CBPR_SHIFT 4#define ICH_VMCR_CBPR_MASK (1 << ICH_VMCR_CBPR_SHIFT)#define ICH_VMCR_EOIM_SHIFT 9
virt/kvm/arm/vgic/vgic-mmio-v2.c +0 -16
@@ -213,22 +213,6 @@ static void vgic_mmio_write_sgipends(struct kvm_vcpu *vcpu, } } -static void vgic_set_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr) -{ -if (kvm_vgic_global_state.type ==VGIC_V2 ) -vgic_v2_set_vmcr (vcpu, vmcr); -else -vgic_v3_set_vmcr (vcpu, vmcr); -} - -static void vgic_get_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr) -{ -if (kvm_vgic_global_state.type ==VGIC_V2 ) -vgic_v2_get_vmcr (vcpu, vmcr); -else -vgic_v3_get_vmcr (vcpu, vmcr); -} -#define GICC_ARCH_VERSION_V2 0x2/* These are for userland accesses only, there is no guest-facing emulation. */
virt/kvm/arm/vgic/vgic-mmio.c +16 -0
@@ -385,6 +385,22 @@ vgic_find_mmio_region(const struct vgic_register_region *region, int nr_regions, sizeof(region[0]), match_region); } +void vgic_set_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr) +{ +if (kvm_vgic_global_state.type ==VGIC_V2 ) +vgic_v2_set_vmcr (vcpu, vmcr); +else +vgic_v3_set_vmcr (vcpu, vmcr); +} + +void vgic_get_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr) +{ +if (kvm_vgic_global_state.type ==VGIC_V2 ) +vgic_v2_get_vmcr (vcpu, vmcr); +else +vgic_v3_get_vmcr (vcpu, vmcr); +} +/* * 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
virt/kvm/arm/vgic/vgic-v3.c +18 -2
@@ -175,10 +175,18 @@ void vgic_v3_set_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcrp) {u32 vmcr; - vmcr = (vmcrp->ctlr <<ICH_VMCR_CTLR_SHIFT ) &ICH_VMCR_CTLR_MASK ; +/* +* Ignore the FIQen bit, because GIC emulation always implies +* SRE=1 which means the vFIQEn bit is also RES1. +*/ + vmcr = ((vmcrp->ctlr >> ICC_CTLR_EL1_EOImode_SHIFT) << +ICH_VMCR_EOIM_SHIFT ) &ICH_VMCR_EOIM_MASK ; + vmcr |= (vmcrp->ctlr <<ICH_VMCR_CBPR_SHIFT ) &ICH_VMCR_CBPR_MASK ; vmcr |= (vmcrp->abpr <<ICH_VMCR_BPR1_SHIFT ) &ICH_VMCR_BPR1_MASK ; vmcr |= (vmcrp->bpr <<ICH_VMCR_BPR0_SHIFT ) &ICH_VMCR_BPR0_MASK ; vmcr |= (vmcrp->pmr <<ICH_VMCR_PMR_SHIFT ) &ICH_VMCR_PMR_MASK ; + vmcr |= (vmcrp->grpen0 <<ICH_VMCR_ENG0_SHIFT ) &ICH_VMCR_ENG0_MASK ; + vmcr |= (vmcrp->grpen1 <<ICH_VMCR_ENG1_SHIFT ) &ICH_VMCR_ENG1_MASK ; vcpu->arch.vgic_cpu.vgic_v3.vgic_vmcr = vmcr; }
@@ -187,10 +195,18 @@ void vgic_v3_get_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcrp) {u32 vmcr = vcpu->arch.vgic_cpu.vgic_v3.vgic_vmcr; - vmcrp->ctlr = (vmcr &ICH_VMCR_CTLR_MASK ) >>ICH_VMCR_CTLR_SHIFT ; +/* +* Ignore the FIQen bit, because GIC emulation always implies +* SRE=1 which means the vFIQEn bit is also RES1. +*/ + vmcrp->ctlr = ((vmcr >>ICH_VMCR_EOIM_SHIFT ) << + ICC_CTLR_EL1_EOImode_SHIFT) & ICC_CTLR_EL1_EOImode_MASK; + vmcrp->ctlr |= (vmcr &ICH_VMCR_CBPR_MASK ) >>ICH_VMCR_CBPR_SHIFT ; vmcrp->abpr = (vmcr &ICH_VMCR_BPR1_MASK ) >>ICH_VMCR_BPR1_SHIFT ; vmcrp->bpr = (vmcr &ICH_VMCR_BPR0_MASK ) >>ICH_VMCR_BPR0_SHIFT ; vmcrp->pmr = (vmcr &ICH_VMCR_PMR_MASK ) >>ICH_VMCR_PMR_SHIFT ; + vmcrp->grpen0 = (vmcr &ICH_VMCR_ENG0_MASK ) >>ICH_VMCR_ENG0_SHIFT ; + vmcrp->grpen1 = (vmcr &ICH_VMCR_ENG1_MASK ) >>ICH_VMCR_ENG1_SHIFT ; }#define INITIAL_PENDBASER_VALUE \
virt/kvm/arm/vgic/vgic.h +5 -0
@@ -65,6 +65,9 @@ struct vgic_vmcr {u32 abpr;u32 bpr;u32 pmr; +/* Below member variable are valid only for GICv3 */ +u32 grpen0; +u32 grpen1; };struct vgic_reg_attr {
@@ -137,6 +140,8 @@ int vgic_v3_dist_uaccess(struct kvm_vcpu *vcpu, bool is_write,int vgic_v3_redist_uaccess (struct kvm_vcpu *vcpu,bool is_write,int offset,u32 *val);int kvm_register_vgic_device (unsigned long type); +void vgic_set_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr); +void vgic_get_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr);int vgic_lazy_init (struct kvm *kvm);int vgic_init (struct kvm *kvm);
Signature · 1 line
2.1.4
PATCH 8/25 KVM: arm/arm64: vgic: Implement VGICv3 CPU interface access
In reply to Marc ZyngierFrom: Vijaya Kumar K <[email protected]>
VGICv3 CPU interface registers are accessed using KVM_DEV_ARM_VGIC_CPU_SYSREGS ioctl. These registers are accessed as 64-bit. The cpu MPIDR value is passed along with register id. It is used to identify the cpu for registers access.
The VM that supports SEIs expect it on destination machine to handle guest aborts and hence checked for ICC_CTLR_EL1.SEIS compatibility. Similarly, VM that supports Affinity Level 3 that is required for AArch64 mode, is required to be supported on destination machine. Hence checked for ICC_CTLR_EL1.A3V compatibility.
The arch/arm64/kvm/vgic-sys-reg-v3.c handles read and write of VGIC CPU registers for AArch64.
For AArch32 mode, arch/arm/kvm/vgic-v3-coproc.c file is created but APIs are not implemented.
Updated arch/arm/include/uapi/asm/kvm.h with new definitions required to compile for AArch32.
The version of VGIC v3 specification is defined here Documentation/virtual/kvm/devices/arm-vgic-v3.txt
--- arch/arm/include/uapi/asm/kvm.h | 3 + arch/arm/kvm/Makefile | 4 +- arch/arm/kvm/vgic-v3-coproc.c | 35 ++++ arch/arm64/include/uapi/asm/kvm.h | 3 + arch/arm64/kvm/Makefile | 3 +- arch/arm64/kvm/vgic-sys-reg-v3.c | 346 ++++++++++++++++++++++++++++++++++++ include/kvm/arm_vgic.h | 8 + virt/kvm/arm/vgic/vgic-kvm-device.c | 27 +++ virt/kvm/arm/vgic/vgic-mmio-v3.c | 6 + virt/kvm/arm/vgic/vgic-v3.c | 8 + virt/kvm/arm/vgic/vgic.h | 25 +++ 11 files changed, 465 insertions(+), 3 deletions(-) create mode 100644 arch/arm/kvm/vgic-v3-coproc.c create mode 100644 arch/arm64/kvm/vgic-sys-reg-v3.c
arch/arm/include/uapi/asm/kvm.h +3 -0
@@ -186,9 +186,12 @@ struct kvm_arch_memory_slot { (0xffffffffULL << KVM_DEV_ARM_VGIC_V3_MPIDR_SHIFT)#define KVM_DEV_ARM_VGIC_OFFSET_SHIFT 0#define KVM_DEV_ARM_VGIC_OFFSET_MASK (0xffffffffULL << KVM_DEV_ARM_VGIC_OFFSET_SHIFT) +#define KVM_DEV_ARM_VGIC_SYSREG_INSTR_MASK (0xffff)#define KVM_DEV_ARM_VGIC_GRP_NR_IRQS 3#define KVM_DEV_ARM_VGIC_GRP_CTRL 4#define KVM_DEV_ARM_VGIC_GRP_REDIST_REGS 5 +#define KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS 6 +#define KVM_DEV_ARM_VGIC_CTRL_INIT 0/* KVM_IRQ_LINE irq field index values */
arch/arm/kvm/Makefile +2 -2
@@ -7,7 +7,7 @@ ifeq ($(plus_virt),+virt) plus_virt_def := -DREQUIRES_VIRT=1 endif -ccflags-y += -Iarch/arm/kvm +ccflags-y += -Iarch/arm/kvm -Ivirt/kvm/arm/vgic CFLAGS_arm.o := -I. $(plus_virt_def) CFLAGS_mmu.o := -I.
@@ -20,7 +20,7 @@ kvm-arm-y = $(KVM)/kvm_main.o $(KVM)/coalesced_mmio.o $(KVM)/eventfd.o $(KVM)/vf obj-$(CONFIG_KVM_ARM_HOST) += hyp/ obj-y += kvm-arm.o init.o interrupts.o obj-y += arm.o handle_exit.o guest.o mmu.o emulate.o reset.o -obj-y += coproc.o coproc_a15.o coproc_a7.o mmio.o psci.o perf.o +obj-y += coproc.o coproc_a15.o coproc_a7.o mmio.o psci.o perf.o vgic-v3-coproc.o obj-y += $(KVM)/arm/aarch32.o obj-y += $(KVM)/arm/vgic/vgic.o
arch/arm/kvm/vgic-v3-coproc.c new file +35 -0
@@ -0,0 +1,35 @@ +/* +* VGIC system registers handling functions for AArch32 mode +* +* 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/kvm.h> +#include <linux/kvm_host.h> +#include <asm/kvm_emulate.h> +#include "vgic.h" + +int vgic_v3_has_cpu_sysregs_attr (struct kvm_vcpu *vcpu,bool is_write,u64 id, +u64 *reg) +{ +/* +* TODO: Implement for AArch32 +*/ +return -ENXIO ; +} + +int vgic_v3_cpu_sysregs_uaccess (struct kvm_vcpu *vcpu,bool is_write,u64 id, +u64 *reg) +{ +/* +* TODO: Implement for AArch32 +*/ +return -ENXIO ; +}
arch/arm64/include/uapi/asm/kvm.h +3 -0
@@ -206,9 +206,12 @@ struct kvm_arch_memory_slot { (0xffffffffULL << KVM_DEV_ARM_VGIC_V3_MPIDR_SHIFT)#define KVM_DEV_ARM_VGIC_OFFSET_SHIFT 0#define KVM_DEV_ARM_VGIC_OFFSET_MASK (0xffffffffULL << KVM_DEV_ARM_VGIC_OFFSET_SHIFT) +#define KVM_DEV_ARM_VGIC_SYSREG_INSTR_MASK (0xffff)#define KVM_DEV_ARM_VGIC_GRP_NR_IRQS 3#define KVM_DEV_ARM_VGIC_GRP_CTRL 4#define KVM_DEV_ARM_VGIC_GRP_REDIST_REGS 5 +#define KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS 6 +#define KVM_DEV_ARM_VGIC_CTRL_INIT 0/* Device Control API on vcpu fd */
arch/arm64/kvm/Makefile +2 -1
@@ -2,7 +2,7 @@ # Makefile for Kernel-based Virtual Machine module # -ccflags-y += -Iarch/arm64/kvm +ccflags-y += -Iarch/arm64/kvm -Ivirt/kvm/arm/vgic CFLAGS_arm.o := -I. CFLAGS_mmu.o := -I.
@@ -19,6 +19,7 @@ kvm-$(CONFIG_KVM_ARM_HOST) += $(ARM)/psci.o $(ARM)/perf.o kvm-$(CONFIG_KVM_ARM_HOST) += inject_fault.o regmap.o kvm-$(CONFIG_KVM_ARM_HOST) += hyp.o hyp-init.o handle_exit.o kvm-$(CONFIG_KVM_ARM_HOST) += guest.o debug.o reset.o sys_regs.o sys_regs_generic_v8.o +kvm-$(CONFIG_KVM_ARM_HOST) += vgic-sys-reg-v3.o kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/aarch32.o kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/arm/vgic/vgic.o
arch/arm64/kvm/vgic-sys-reg-v3.c new file +346 -0
346 lines not on this page · raw message
include/kvm/arm_vgic.h +8 -0
@@ -71,6 +71,8 @@ struct vgic_global {/* GIC system register CPU interface */ struct static_key_false gicv3_cpuif; + +u32 ich_vtr_el2; };extern struct vgic_global kvm_vgic_global_state;
@@ -275,6 +277,12 @@ struct vgic_cpu {u64 pendbaser;bool lpis_enabled; + +/* Cache guest priority bits */ +u32 num_pri_bits; + +/* Cache guest interrupt ID bits */ +u32 num_id_bits; };extern struct static_key_false vgic_v2_cpuif_trap;
virt/kvm/arm/vgic/vgic-kvm-device.c +27 -0
@@ -504,6 +504,14 @@ static int vgic_v3_attr_regs_access(struct kvm_device *dev,if (!is_write) *reg = tmp32;break ; +case KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS : { +u64 regid; + + regid = (attr->attr &KVM_DEV_ARM_VGIC_SYSREG_INSTR_MASK ); + ret =vgic_v3_cpu_sysregs_uaccess (vcpu, is_write, + regid, reg); +break ; + }default : ret = -EINVAL ;break ;
@@ -537,6 +545,15 @@ static int vgic_v3_set_attr(struct kvm_device *dev, reg = tmp32;return vgic_v3_attr_regs_access (dev, attr, ®, true); } +case KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS : { +u64 __user *uaddr = (u64 __user *)(long )attr->addr; +u64 reg; + +if (get_user (reg, uaddr)) +return -EFAULT ; + +return vgic_v3_attr_regs_access (dev, attr, ®, true); + } }return -ENXIO ; }
@@ -563,6 +580,15 @@ static int vgic_v3_get_attr(struct kvm_device *dev, tmp32 = reg;return put_user (tmp32, uaddr); } +case KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS : { +u64 __user *uaddr = (u64 __user *)(long )attr->addr; +u64 reg; + + ret =vgic_v3_attr_regs_access (dev, attr, ®, false); +if (ret) +return ret; +return put_user (reg, uaddr); + } }return -ENXIO ;
@@ -581,6 +607,7 @@ static int vgic_v3_has_attr(struct kvm_device *dev,break ;case KVM_DEV_ARM_VGIC_GRP_DIST_REGS :case KVM_DEV_ARM_VGIC_GRP_REDIST_REGS : +case KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS :return vgic_v3_has_attr_regs (dev, attr);case KVM_DEV_ARM_VGIC_GRP_NR_IRQS :return 0 ;
virt/kvm/arm/vgic/vgic-mmio-v3.c +6 -0
@@ -645,6 +645,12 @@ int vgic_v3_has_attr_regs(struct kvm_device *dev, struct kvm_device_attr *attr) iodev.base_addr =0 ;break ; } +case KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS : { +u64 reg, id; + + id = (attr->attr &KVM_DEV_ARM_VGIC_SYSREG_INSTR_MASK ); +return vgic_v3_has_cpu_sysregs_attr (vcpu,0 , id, ®); + }default :return -ENXIO ; }
virt/kvm/arm/vgic/vgic-v3.c +8 -0
@@ -238,6 +238,13 @@ void vgic_v3_enable(struct kvm_vcpu *vcpu) vgic_v3->vgic_sre =0 ; } + vcpu->arch.vgic_cpu.num_id_bits = (kvm_vgic_global_state.ich_vtr_el2 & +ICH_VTR_ID_BITS_MASK ) >> +ICH_VTR_ID_BITS_SHIFT ; + vcpu->arch.vgic_cpu.num_pri_bits = ((kvm_vgic_global_state.ich_vtr_el2 & +ICH_VTR_PRI_BITS_MASK ) >> +ICH_VTR_PRI_BITS_SHIFT ) +1 ; +/* Get the show on the road... */ vgic_v3->vgic_hcr =ICH_HCR_EN ; }
@@ -336,6 +343,7 @@ int vgic_v3_probe(const struct gic_kvm_info *info)*/ kvm_vgic_global_state.nr_lr = (ich_vtr_el2 &0xf ) +1 ; kvm_vgic_global_state.can_emulate_gicv2 = false; + kvm_vgic_global_state.ich_vtr_el2 = ich_vtr_el2;if (!info->vcpu.start) {kvm_info ("GICv3: no GICV resource entry\n" );
virt/kvm/arm/vgic/vgic.h +25 -0
@@ -52,6 +52,27 @@ VGIC_AFFINITY_LEVEL(val, 2) | \ VGIC_AFFINITY_LEVEL(val, 3)) +/* +* As per Documentation/virtual/kvm/devices/arm-vgic-v3.txt, +* below macros are defined for CPUREG encoding. +*/ +#define KVM_REG_ARM_VGIC_SYSREG_OP0_MASK 0x000000000000c000 +#define KVM_REG_ARM_VGIC_SYSREG_OP0_SHIFT 14 +#define KVM_REG_ARM_VGIC_SYSREG_OP1_MASK 0x0000000000003800 +#define KVM_REG_ARM_VGIC_SYSREG_OP1_SHIFT 11 +#define KVM_REG_ARM_VGIC_SYSREG_CRN_MASK 0x0000000000000780 +#define KVM_REG_ARM_VGIC_SYSREG_CRN_SHIFT 7 +#define KVM_REG_ARM_VGIC_SYSREG_CRM_MASK 0x0000000000000078 +#define KVM_REG_ARM_VGIC_SYSREG_CRM_SHIFT 3 +#define KVM_REG_ARM_VGIC_SYSREG_OP2_MASK 0x0000000000000007 +#define KVM_REG_ARM_VGIC_SYSREG_OP2_SHIFT 0 + +#define KVM_DEV_ARM_VGIC_SYSREG_MASK (KVM_REG_ARM_VGIC_SYSREG_OP0_MASK | \ + KVM_REG_ARM_VGIC_SYSREG_OP1_MASK | \ + KVM_REG_ARM_VGIC_SYSREG_CRN_MASK | \ + KVM_REG_ARM_VGIC_SYSREG_CRM_MASK | \ + KVM_REG_ARM_VGIC_SYSREG_OP2_MASK) +static inline bool irq_is_pending (struct vgic_irq *irq) {if (irq->config ==VGIC_CONFIG_EDGE )
@@ -139,6 +160,10 @@ int vgic_v3_dist_uaccess(struct kvm_vcpu *vcpu, bool is_write, int offset, u32 *val);int vgic_v3_redist_uaccess (struct kvm_vcpu *vcpu,bool is_write,int offset,u32 *val); +int vgic_v3_cpu_sysregs_uaccess (struct kvm_vcpu *vcpu,bool is_write, +u64 id,u64 *val); +int vgic_v3_has_cpu_sysregs_attr (struct kvm_vcpu *vcpu,bool is_write,u64 id, +u64 *reg);int kvm_register_vgic_device (unsigned long type);void vgic_set_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr);void vgic_get_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr);
Signature · 1 line
2.1.4
PATCH 9/25 KVM: arm/arm64: vgic: Implement KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO ioctl
In reply to Marc ZyngierFrom: Vijaya Kumar K <[email protected]>
Userspace requires to store and restore of line_level for level triggered interrupts using ioctl KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO.
--- arch/arm/include/uapi/asm/kvm.h | 6 +++++ arch/arm64/include/uapi/asm/kvm.h | 6 +++++ virt/kvm/arm/vgic/vgic-kvm-device.c | 45 ++++++++++++++++++++++++++++++- virt/kvm/arm/vgic/vgic-mmio-v3.c | 14 ++++++++++ virt/kvm/arm/vgic/vgic-mmio.c | 54 +++++++++++++++++++++++++++++++++++++ virt/kvm/arm/vgic/vgic-mmio.h | 5 ++++ virt/kvm/arm/vgic/vgic.h | 2 ++ 7 files changed, 131 insertions(+), 1 deletion(-)
arch/arm/include/uapi/asm/kvm.h +6 -0
@@ -191,6 +191,12 @@ struct kvm_arch_memory_slot {#define KVM_DEV_ARM_VGIC_GRP_CTRL 4#define KVM_DEV_ARM_VGIC_GRP_REDIST_REGS 5#define KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS 6 +#define KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO 7 +#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT 10 +#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_MASK \ + (0x3fffffULL << KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT) +#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INTID_MASK 0x3ff +#define VGIC_LEVEL_INFO_LINE_LEVEL 0#define KVM_DEV_ARM_VGIC_CTRL_INIT 0
arch/arm64/include/uapi/asm/kvm.h +6 -0
@@ -211,6 +211,12 @@ struct kvm_arch_memory_slot {#define KVM_DEV_ARM_VGIC_GRP_CTRL 4#define KVM_DEV_ARM_VGIC_GRP_REDIST_REGS 5#define KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS 6 +#define KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO 7 +#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT 10 +#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_MASK \ + (0x3fffffULL << KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT) +#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INTID_MASK 0x3ff +#define VGIC_LEVEL_INFO_LINE_LEVEL 0#define KVM_DEV_ARM_VGIC_CTRL_INIT 0
virt/kvm/arm/vgic/vgic-kvm-device.c +44 -1
70 lines not on this page · raw message
virt/kvm/arm/vgic/vgic-mmio-v3.c +14 -0
@@ -803,3 +803,17 @@ int vgic_v3_redist_uaccess(struct kvm_vcpu *vcpu, bool is_write,else return vgic_uaccess (vcpu, &rd_dev, is_write, offset, val); } + +int vgic_v3_line_level_info_uaccess (struct kvm_vcpu *vcpu,bool is_write, +u32 intid,u64 *val) +{ +if (intid %32 ) +return -EINVAL ; + +if (is_write) +vgic_write_irq_line_level_info (vcpu, intid, *val); +else + *val =vgic_read_irq_line_level_info (vcpu, intid); + +return 0 ; +}
virt/kvm/arm/vgic/vgic-mmio.c +54 -0
60 lines not on this page · raw message
virt/kvm/arm/vgic/vgic-mmio.h +5 -0
@@ -177,6 +177,11 @@ void vgic_mmio_write_config(struct kvm_vcpu *vcpu,int vgic_uaccess (struct kvm_vcpu *vcpu,struct vgic_io_device *dev,bool is_write,int offset,u32 *val); +u64 vgic_read_irq_line_level_info (struct kvm_vcpu *vcpu,u32 intid); + +void vgic_write_irq_line_level_info (struct kvm_vcpu *vcpu,u32 intid, +const u64 val); +unsigned int vgic_v2_init_dist_iodev (struct vgic_io_device *dev);unsigned int vgic_v3_init_dist_iodev (struct vgic_io_device *dev);
virt/kvm/arm/vgic/vgic.h +2 -0
@@ -164,6 +164,8 @@ int vgic_v3_cpu_sysregs_uaccess(struct kvm_vcpu *vcpu, bool is_write, u64 id, u64 *val);int vgic_v3_has_cpu_sysregs_attr (struct kvm_vcpu *vcpu,bool is_write,u64 id,u64 *reg); +int vgic_v3_line_level_info_uaccess (struct kvm_vcpu *vcpu,bool is_write, +u32 intid,u64 *val);int kvm_register_vgic_device (unsigned long type);void vgic_set_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr);void vgic_get_vmcr (struct kvm_vcpu *vcpu,struct vgic_vmcr *vmcr);
Signature · 1 line
2.1.4
PATCH 10/25 KVM: arm/arm64: Documentation: Update arm-vgic-v3.txt
In reply to Marc ZyngierFrom: Vijaya Kumar K <[email protected]>
Update error code returned for Invalid CPU interface register value and access in AArch32 mode.
--- Documentation/virtual/kvm/devices/arm-vgic-v3.txt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
Documentation/virtual/kvm/devices/arm-vgic-v3.txt +8 -3
@@ -118,7 +118,7 @@ Groups: -EBUSY: One or more VCPUs are running - KVM_DEV_ARM_VGIC_CPU_SYSREGS + KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS Attributes: The attr field of kvm_device_attr encodes two values: bits: | 63 .... 32 | 31 .... 16 | 15 .... 0 |
@@ -139,13 +139,15 @@ Groups: All system regs accessed through this API are (rw, 64-bit) and kvm_device_attr.addr points to a __u64 value. - KVM_DEV_ARM_VGIC_CPU_SYSREGS accesses the CPU interface registers for the + KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS accesses the CPU interface registers for the CPU specified by the mpidr field. + CPU interface registers access is not implemented for AArch32 mode. + Error -ENXIO is returned when accessed in AArch32 mode. Errors: -ENXIO: Getting or setting this register is not yet supported -EBUSY: VCPU is running - -EINVAL: Invalid mpidr supplied + -EINVAL: Invalid mpidr or register value supplied KVM_DEV_ARM_VGIC_GRP_NR_IRQS
@@ -204,3 +206,6 @@ Groups: architecture defined MPIDR, and the field is encoded as follows: | 63 .... 56 | 55 .... 48 | 47 .... 40 | 39 .... 32 | | Aff3 | Aff2 | Aff1 | Aff0 | + Errors: + -EINVAL: vINTID is not multiple of 32 or + info field is not VGIC_LEVEL_INFO_LINE_LEVEL
Signature · 1 line
2.1.4
PATCH 11/25 arm/arm64: KVM: Enforce unconditional flush to PoC when mapping to stage-2
In reply to Marc ZyngierWhen we fault in a page, we flush it to the PoC (Point of Coherency) if the faulting vcpu has its own caches off, so that it can observe the page we just brought it.
But if the vcpu has its caches on, we skip that step. Bad things happen when *another* vcpu tries to access that page with its own caches disabled. At that point, there is no garantee that the data has made it to the PoC, and we access stale data.
The obvious fix is to always flush to PoC when a page is faulted in, no matter what the state of the vcpu is.
--- arch/arm/include/asm/kvm_mmu.h | 9 +-------- arch/arm64/include/asm/kvm_mmu.h | 3 +-- 2 files changed, 2 insertions(+), 10 deletions(-)
arch/arm/include/asm/kvm_mmu.h +1 -8
@@ -150,18 +150,12 @@ static inline void __coherent_cache_guest_page(struct kvm_vcpu *vcpu,* and iterate over the range. */ -bool need_flush = !vcpu_has_cache_enabled (vcpu) || ipa_uncached; -VM_BUG_ON (size & ~PAGE_MASK ); -if (!need_flush && !icache_is_pipt ()) - goto vipt_cache; -while (size) {void *va =kmap_atomic_pfn (pfn); -if (need_flush) -kvm_flush_dcache_to_poc (va,PAGE_SIZE ); +kvm_flush_dcache_to_poc (va,PAGE_SIZE );if (icache_is_pipt ()) __cpuc_coherent_user_range((unsigned long)va,
@@ -173,7 +167,6 @@ static inline void __coherent_cache_guest_page(struct kvm_vcpu *vcpu,kunmap_atomic (va); } -vipt_cache:if (!icache_is_pipt () && !icache_is_vivt_asid_tagged ()) {/* any kind of VIPT cache */ __flush_icache_all ();
arch/arm64/include/asm/kvm_mmu.h +1 -2
@@ -241,8 +241,7 @@ static inline void __coherent_cache_guest_page(struct kvm_vcpu *vcpu, {void *va =page_address (pfn_to_page (pfn)); -if (!vcpu_has_cache_enabled (vcpu) || ipa_uncached) -kvm_flush_dcache_to_poc (va, size); +kvm_flush_dcache_to_poc (va, size);if (!icache_is_aliasing ()) {/* PIPT */ flush_icache_range((unsigned long)va,
Signature · 1 line
2.1.4
PATCH 12/25 arm/arm64: KVM: Stop propagating cacheability status of a faulted page
In reply to Marc ZyngierNow that we unconditionally flush newly mapped pages to the PoC, there is no need to care about the "uncached" status of individual pages - they must all be visible all the way down.
--- arch/arm/include/asm/kvm_mmu.h | 3 +-- arch/arm/kvm/mmu.c | 11 ++++------- arch/arm64/include/asm/kvm_mmu.h | 3 +-- 3 files changed, 6 insertions(+), 11 deletions(-)
arch/arm/include/asm/kvm_mmu.h +1 -2
@@ -129,8 +129,7 @@ static inline bool vcpu_has_cache_enabled(struct kvm_vcpu *vcpu)static inline void __coherent_cache_guest_page (struct kvm_vcpu *vcpu,kvm_pfn_t pfn, -unsigned long size, -bool ipa_uncached) +unsigned long size) {/* * If we are going to insert an instruction page and the icache is
arch/arm/kvm/mmu.c +4 -7
@@ -1232,9 +1232,9 @@ void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, }static void coherent_cache_guest_page (struct kvm_vcpu *vcpu,kvm_pfn_t pfn, -unsigned long size,bool uncached) +unsigned long size) { -__coherent_cache_guest_page (vcpu, pfn, size, uncached); +__coherent_cache_guest_page (vcpu, pfn, size); } static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
@@ -1250,7 +1250,6 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,struct vm_area_struct *vma;kvm_pfn_t pfn;pgprot_t mem_type =PAGE_S2 ; -bool fault_ipa_uncached;bool logging_active =memslot_is_logging (memslot);unsigned long flags =0 ;
@@ -1337,8 +1336,6 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,if (!hugetlb && !force_pte) hugetlb =transparent_hugepage_adjust (&pfn, &fault_ipa); - fault_ipa_uncached = memslot->flags &KVM_MEMSLOT_INCOHERENT ; -if (hugetlb) {pmd_t new_pmd =pfn_pmd (pfn, mem_type); new_pmd =pmd_mkhuge (new_pmd);
@@ -1346,7 +1343,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, new_pmd =kvm_s2pmd_mkwrite (new_pmd);kvm_set_pfn_dirty (pfn); } -coherent_cache_guest_page (vcpu, pfn,PMD_SIZE , fault_ipa_uncached); +coherent_cache_guest_page (vcpu, pfn,PMD_SIZE ); ret =stage2_set_pmd_huge (kvm, memcache, fault_ipa, &new_pmd); }else {pte_t new_pte =pfn_pte (pfn, mem_type);
@@ -1356,7 +1353,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,kvm_set_pfn_dirty (pfn);mark_page_dirty (kvm, gfn); } -coherent_cache_guest_page (vcpu, pfn,PAGE_SIZE , fault_ipa_uncached); +coherent_cache_guest_page (vcpu, pfn,PAGE_SIZE ); ret =stage2_set_pte (kvm, memcache, fault_ipa, &new_pte, flags); }
arch/arm64/include/asm/kvm_mmu.h +1 -2
@@ -236,8 +236,7 @@ static inline bool vcpu_has_cache_enabled(struct kvm_vcpu *vcpu)static inline void __coherent_cache_guest_page (struct kvm_vcpu *vcpu,kvm_pfn_t pfn, -unsigned long size, -bool ipa_uncached) +unsigned long size) {void *va =page_address (pfn_to_page (pfn));
Signature · 1 line
2.1.4
PATCH 13/25 arm/arm64: KVM: Get rid of KVM_MEMSLOT_INCOHERENT
In reply to Marc ZyngierKVM_MEMSLOT_INCOHERENT is not used anymore, as we've killed its only use in the arm/arm64 MMU code. Let's remove the last artifacts.
--- arch/arm/kvm/mmu.c | 9 --------- include/linux/kvm_host.h | 1 - 2 files changed, 10 deletions(-)
arch/arm/kvm/mmu.c +0 -9
@@ -1876,15 +1876,6 @@ void kvm_arch_free_memslot(struct kvm *kvm, struct kvm_memory_slot *free,int kvm_arch_create_memslot (struct kvm *kvm,struct kvm_memory_slot *slot,unsigned long npages) { -/* -* Readonly memslots are not incoherent with the caches by definition, -* but in practice, they are used mostly to emulate ROMs or NOR flashes -* that the guest may consider devices and hence map as uncached. -* To prevent incoherency issues in these cases, tag all readonly -* regions as incoherent. -*/ -if (slot->flags &KVM_MEM_READONLY ) - slot->flags |=KVM_MEMSLOT_INCOHERENT ;return 0 ; }
include/linux/kvm_host.h +0 -1
@@ -45,7 +45,6 @@* include/linux/kvm_h. */ #define KVM_MEMSLOT_INVALID (1UL << 16) -#define KVM_MEMSLOT_INCOHERENT (1UL << 17)/* Two fragments for cross MMIO pages. */ #define KVM_MAX_MMIO_FRAGMENTS 2
Signature · 1 line
2.1.4
PATCH 14/25 KVM: arm/arm64: Remove kvm_vgic_inject_mapped_irq
In reply to Marc ZyngierFrom: Christoffer Dall <[email protected]>
The only benefit of having kvm_vgic_inject_mapped_irq separate from kvm_vgic_inject_irq is that we pass a boolean that we use for error checking on the injection path.
While this could potentially help in some aspect of robustness, it's also a little bit of a defensive move, and arguably callers into the vgic should have make sure they have marked their virtual IRQs as mapped if required.
--- virt/kvm/arm/arch_timer.c | 3 ++- virt/kvm/arm/vgic/vgic.c | 50 +++++++++++++++-------------------------------- 2 files changed, 18 insertions(+), 35 deletions(-)
virt/kvm/arm/arch_timer.c +2 -1
@@ -175,7 +175,8 @@ static void kvm_timer_update_irq(struct kvm_vcpu *vcpu, bool new_level) timer->irq.level = new_level;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, + + ret =kvm_vgic_inject_irq (vcpu->kvm, vcpu->vcpu_id, timer->irq.irq, timer->irq.level);WARN_ON (ret);
virt/kvm/arm/vgic/vgic.c +16 -34
68 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH 15/25 KVM: arm/arm64: vgic: Stop injecting the MSI occurrence twice
In reply to Marc ZyngierFrom: Shanker Donthineni <[email protected]>
The IRQFD framework calls the architecture dependent function twice if the corresponding GSI type is edge triggered. For ARM, the function kvm_set_msi() is getting called twice whenever the IRQFD receives the event signal. The rest of the code path is trying to inject the MSI without any validation checks. No need to call the function vgic_its_inject_msi() second time to avoid an unnecessary overhead in IRQ queue logic. It also avoids the possibility of VM seeing the MSI twice.
Simple fix, return -1 if the argument 'level' value is zero.
--- virt/kvm/arm/vgic/vgic-irqfd.c | 3 +++ 1 file changed, 3 insertions(+)
virt/kvm/arm/vgic/vgic-irqfd.c +3 -0
@@ -99,6 +99,9 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e,if (!vgic_has_its (kvm))return -ENODEV ; +if (!level) +return -1 ; +return vgic_its_inject_msi (kvm, &msi); }
Signature · 1 line
2.1.4
PATCH 16/25 KVM: arm/arm64: Abstract virtual timer context into separate structure
In reply to Marc ZyngierFrom: Jintack Lim <[email protected]>
Abstract virtual timer context into a separate structure and change all callers referring to timer registers, irq state and so on. No change in functionality.
This is about to become very handy when adding the EL1 physical timer.
--- include/kvm/arm_arch_timer.h | 27 ++++++++--------- virt/kvm/arm/arch_timer.c | 69 +++++++++++++++++++++++--------------------- virt/kvm/arm/hyp/timer-sr.c | 10 ++++--- 3 files changed, 56 insertions(+), 50 deletions(-)
include/kvm/arm_arch_timer.h +14 -13
@@ -28,15 +28,20 @@ struct arch_timer_kvm {u64 cntvoff; }; -struct arch_timer_cpu { +struct arch_timer_context {/* Registers: control register, timer value */ -u32 cntv_ctl;/* Saved/restored */ -u64 cntv_cval;/* Saved/restored */ +u32 cnt_ctl; +u64 cnt_cval; + +/* Timer IRQ */ +struct kvm_irq_level irq; + +/* Active IRQ state caching */ +bool active_cleared_last; +}; -/* -* Anything that is not used directly from assembly code goes -* here. -*/ +struct arch_timer_cpu { +struct arch_timer_context vtimer;/* Background timer used when the guest is not running */ struct hrtimer timer;
@@ -47,12 +52,6 @@ struct arch_timer_cpu {/* Background timer active */ bool armed; -/* Timer IRQ */ -struct kvm_irq_level irq; - -/* Active IRQ state caching */ -bool active_cleared_last; -/* Is the timer enabled */ bool enabled; };
@@ -77,4 +76,6 @@ void kvm_timer_unschedule(struct kvm_vcpu *vcpu);void kvm_timer_vcpu_put (struct kvm_vcpu *vcpu);void kvm_timer_init_vhe (void ); + +#define vcpu_vtimer (v) (&(v)->arch.timer_cpu.vtimer)#endif
virt/kvm/arm/arch_timer.c +36 -33
210 lines not on this page · raw message
virt/kvm/arm/hyp/timer-sr.c +6 -4
@@ -25,11 +25,12 @@ void __hyp_text __timer_save_state(struct kvm_vcpu *vcpu) {struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu; +struct arch_timer_context *vtimer =vcpu_vtimer (vcpu);u64 val;if (timer->enabled) { - timer->cntv_ctl =read_sysreg_el0 (cntv_ctl); - timer->cntv_cval =read_sysreg_el0 (cntv_cval); + vtimer->cnt_ctl =read_sysreg_el0 (cntv_ctl); + vtimer->cnt_cval =read_sysreg_el0 (cntv_cval); }/* Disable the virtual timer */
@@ -54,6 +55,7 @@ void __hyp_text __timer_restore_state(struct kvm_vcpu *vcpu) {struct kvm *kvm =kern_hyp_va (vcpu->kvm);struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu; +struct arch_timer_context *vtimer =vcpu_vtimer (vcpu);u64 val;/* Those bits are already configured at boot on VHE-system */
@@ -70,8 +72,8 @@ void __hyp_text __timer_restore_state(struct kvm_vcpu *vcpu)if (timer->enabled) {write_sysreg (kvm->arch.timer.cntvoff, cntvoff_el2); -write_sysreg_el0 (timer->cntv_cval, cntv_cval); +write_sysreg_el0 (vtimer->cnt_cval, cntv_cval);isb (); -write_sysreg_el0 (timer->cntv_ctl, cntv_ctl); +write_sysreg_el0 (vtimer->cnt_ctl, cntv_ctl); } }
Signature · 1 line
2.1.4
PATCH 17/25 KVM: arm/arm64: Move cntvoff to each timer context
In reply to Marc ZyngierFrom: Jintack Lim <[email protected]>
Make cntvoff per each timer context. This is helpful to abstract kvm timer functions to work with timer context without considering timer types (e.g. physical timer or virtual timer).
This also would pave the way for ever doing adjustments of the cntvoff on a per-CPU basis if that should ever make sense.
--- arch/arm/include/asm/kvm_host.h | 3 --- arch/arm/kvm/arm.c | 1 - arch/arm64/include/asm/kvm_host.h | 3 --- include/kvm/arm_arch_timer.h | 9 +++------ virt/kvm/arm/arch_timer.c | 38 ++++++++++++++++++++++++++++---------- virt/kvm/arm/hyp/timer-sr.c | 3 +-- 6 files changed, 32 insertions(+), 25 deletions(-)
arch/arm/include/asm/kvm_host.h +0 -3
@@ -60,9 +60,6 @@ struct kvm_arch {/* The last vcpu id that ran on each physical CPU */ int __percpu *last_vcpu_ran; -/* Timer */ -struct arch_timer_kvm timer; -/* * Anything that is not used directly from assembly code goes * here.
arch/arm/kvm/arm.c +0 -1
@@ -135,7 +135,6 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) goto out_free_stage2_pgd;kvm_vgic_early_init (kvm); -kvm_timer_init (kvm);/* Mark the initial VMID generation invalid */ kvm->arch.vmid_gen =0 ;
arch/arm64/include/asm/kvm_host.h +0 -3
@@ -70,9 +70,6 @@ struct kvm_arch {/* Interrupt controller */ struct vgic_dist vgic; - -/* Timer */ -struct arch_timer_kvm timer; };#define KVM_NR_MEM_OBJS 40
include/kvm/arm_arch_timer.h +3 -6
@@ -23,11 +23,6 @@#include <linux/hrtimer.h> #include <linux/workqueue.h> -struct arch_timer_kvm { -/* Virtual offset */ -u64 cntvoff; -}; -struct arch_timer_context {/* Registers: control register, timer value */ u32 cnt_ctl;
@@ -38,6 +33,9 @@ struct arch_timer_context {/* Active IRQ state caching */ bool active_cleared_last; + +/* Virtual offset */ +u64 cntvoff; };struct arch_timer_cpu {
@@ -58,7 +56,6 @@ struct arch_timer_cpu {int kvm_timer_hyp_init (void );int kvm_timer_enable (struct kvm_vcpu *vcpu); -void kvm_timer_init (struct kvm *kvm);int kvm_timer_vcpu_reset (struct kvm_vcpu *vcpu,const struct kvm_irq_level *irq);void kvm_timer_vcpu_init (struct kvm_vcpu *vcpu);
virt/kvm/arm/arch_timer.c +28 -10
@@ -101,9 +101,10 @@ static void kvm_timer_inject_irq_work(struct work_struct *work)static u64 kvm_timer_compute_delta (struct kvm_vcpu *vcpu) {u64 cval, now; +struct arch_timer_context *vtimer =vcpu_vtimer (vcpu); - cval =vcpu_vtimer (vcpu)->cnt_cval; - now =kvm_phys_timer_read () - vcpu->kvm->arch.timer.cntvoff; + cval = vtimer->cnt_cval; + now =kvm_phys_timer_read () - vtimer->cntvoff;if (now < cval) {u64 ns;
@@ -159,7 +160,7 @@ bool kvm_timer_should_fire(struct kvm_vcpu *vcpu)return false; cval = vtimer->cnt_cval; - now =kvm_phys_timer_read () - vcpu->kvm->arch.timer.cntvoff; + now =kvm_phys_timer_read () - vtimer->cntvoff;return cval <= now; }
@@ -354,10 +355,32 @@ int kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu,return 0 ; } +/* Make the updates of cntvoff for all vtimer contexts atomic */ +static void update_vtimer_cntvoff (struct kvm_vcpu *vcpu,u64 cntvoff) +{ +int i; +struct kvm *kvm = vcpu->kvm; +struct kvm_vcpu *tmp; + +mutex_lock (&kvm->lock); +kvm_for_each_vcpu (i, tmp, kvm) +vcpu_vtimer (tmp)->cntvoff = cntvoff; + +/* +* When called from the vcpu create path, the CPU being created is not +* included in the loop above, so we just set it here as well. +*/ +vcpu_vtimer (vcpu)->cntvoff = cntvoff; +mutex_unlock (&kvm->lock); +} +void kvm_timer_vcpu_init (struct kvm_vcpu *vcpu) {struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu; +/* Synchronize cntvoff across all vtimers of a VM. */ +update_vtimer_cntvoff (vcpu,kvm_phys_timer_read ()); +INIT_WORK (&timer->expired, kvm_timer_inject_irq_work);hrtimer_init (&timer->timer,CLOCK_MONOTONIC ,HRTIMER_MODE_ABS ); timer->timer.function = kvm_timer_expire;
@@ -377,7 +400,7 @@ int kvm_arm_timer_set_reg(struct kvm_vcpu *vcpu, u64 regid, u64 value) vtimer->cnt_ctl = value;break ;case KVM_REG_ARM_TIMER_CNT : - vcpu->kvm->arch.timer.cntvoff =kvm_phys_timer_read () - value; +update_vtimer_cntvoff (vcpu,kvm_phys_timer_read () - value);break ;case KVM_REG_ARM_TIMER_CVAL : vtimer->cnt_cval = value;
@@ -398,7 +421,7 @@ u64 kvm_arm_timer_get_reg(struct kvm_vcpu *vcpu, u64 regid)case KVM_REG_ARM_TIMER_CTL :return vtimer->cnt_ctl;case KVM_REG_ARM_TIMER_CNT : -return kvm_phys_timer_read () - vcpu->kvm->arch.timer.cntvoff; +return kvm_phys_timer_read () - vtimer->cntvoff;case KVM_REG_ARM_TIMER_CVAL :return vtimer->cnt_cval; }
@@ -510,11 +533,6 @@ int kvm_timer_enable(struct kvm_vcpu *vcpu)return 0 ; } -void kvm_timer_init (struct kvm *kvm) -{ - kvm->arch.timer.cntvoff =kvm_phys_timer_read (); -} -/* * On VHE system, we only need to configure trap on physical timer and counter * accesses in EL0 and EL1 once, not for every world switch.
virt/kvm/arm/hyp/timer-sr.c +1 -2
@@ -53,7 +53,6 @@ void __hyp_text __timer_save_state(struct kvm_vcpu *vcpu) void __hyp_text __timer_restore_state(struct kvm_vcpu *vcpu) { -struct kvm *kvm =kern_hyp_va (vcpu->kvm);struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu;struct arch_timer_context *vtimer =vcpu_vtimer (vcpu);u64 val;
@@ -71,7 +70,7 @@ void __hyp_text __timer_restore_state(struct kvm_vcpu *vcpu) }if (timer->enabled) { -write_sysreg (kvm->arch.timer.cntvoff, cntvoff_el2); +write_sysreg (vtimer->cntvoff, cntvoff_el2);write_sysreg_el0 (vtimer->cnt_cval, cntv_cval);isb ();write_sysreg_el0 (vtimer->cnt_ctl, cntv_ctl);
Signature · 1 line
2.1.4
PATCH 18/25 KVM: arm/arm64: Decouple kvm timer functions from virtual timer
In reply to Marc ZyngierFrom: Jintack Lim <[email protected]>
Now that we have a separate structure for timer context, make functions generic so that they can work with any timer context, not just the virtual timer context. This does not change the virtual timer functionality.
--- arch/arm/kvm/arm.c | 2 +- include/kvm/arm_arch_timer.h | 2 +- virt/kvm/arm/arch_timer.c | 54 ++++++++++++++++++++------------------------ 3 files changed, 27 insertions(+), 31 deletions(-)
arch/arm/kvm/arm.c +1 -1
@@ -300,7 +300,7 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)int kvm_cpu_has_pending_timer (struct kvm_vcpu *vcpu) { -return kvm_timer_should_fire (vcpu); +return kvm_timer_should_fire (vcpu_vtimer (vcpu)); }void kvm_arch_vcpu_blocking (struct kvm_vcpu *vcpu)
include/kvm/arm_arch_timer.h +1 -1
@@ -66,7 +66,7 @@ void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu);u64 kvm_arm_timer_get_reg (struct kvm_vcpu *,u64 regid);int kvm_arm_timer_set_reg (struct kvm_vcpu *,u64 regid,u64 value); -bool kvm_timer_should_fire (struct kvm_vcpu *vcpu); +bool kvm_timer_should_fire (struct arch_timer_context *timer_ctx);void kvm_timer_schedule (struct kvm_vcpu *vcpu);void kvm_timer_unschedule (struct kvm_vcpu *vcpu);
virt/kvm/arm/arch_timer.c +25 -29
120 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH 19/25 KVM: arm/arm64: Add the EL1 physical timer context
In reply to Marc ZyngierFrom: Jintack Lim <[email protected]>
Add the EL1 physical timer context.
--- include/kvm/arm_arch_timer.h | 2 ++ 1 file changed, 2 insertions(+)
include/kvm/arm_arch_timer.h +2 -0
@@ -40,6 +40,7 @@ struct arch_timer_context {struct arch_timer_cpu {struct arch_timer_context vtimer; +struct arch_timer_context ptimer;/* Background timer used when the guest is not running */ struct hrtimer timer;
@@ -75,4 +76,5 @@ void kvm_timer_vcpu_put(struct kvm_vcpu *vcpu);void kvm_timer_init_vhe (void );#define vcpu_vtimer (v) (&(v)->arch.timer_cpu.vtimer) +#define vcpu_ptimer (v) (&(v)->arch.timer_cpu.ptimer)#endif
Signature · 1 line
2.1.4
PATCH 20/25 KVM: arm/arm64: Initialize the emulated EL1 physical timer
In reply to Marc ZyngierFrom: Jintack Lim <[email protected]>
Initialize the emulated EL1 physical timer with the default irq number.
--- arch/arm/kvm/reset.c | 9 ++++++++- arch/arm64/kvm/reset.c | 9 ++++++++- include/kvm/arm_arch_timer.h | 3 ++- virt/kvm/arm/arch_timer.c | 9 +++++++-- 4 files changed, 25 insertions(+), 5 deletions(-)
arch/arm/kvm/reset.c +8 -1
@@ -37,6 +37,11 @@ static struct kvm_regs cortexa_regs_reset = { .usr_regs.ARM_cpsr = SVC_MODE | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT, }; +static const struct kvm_irq_level cortexa_ptimer_irq = { + { .irq =30 }, + .level =1 , +}; +static const struct kvm_irq_level cortexa_vtimer_irq = { { .irq =27 }, .level =1 ,
@@ -58,6 +63,7 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu) {struct kvm_regs *reset_regs;const struct kvm_irq_level *cpu_vtimer_irq; +const struct kvm_irq_level *cpu_ptimer_irq;switch (vcpu->arch.target) {case KVM_ARM_TARGET_CORTEX_A7 :
@@ -65,6 +71,7 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu) reset_regs = &cortexa_regs_reset; vcpu->arch.midr =read_cpuid_id (); cpu_vtimer_irq = &cortexa_vtimer_irq; + cpu_ptimer_irq = &cortexa_ptimer_irq;break ;default :return -ENODEV ;
@@ -77,5 +84,5 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu)kvm_reset_coprocs (vcpu);/* Reset arch_timer context */ -return kvm_timer_vcpu_reset (vcpu, cpu_vtimer_irq); +return kvm_timer_vcpu_reset (vcpu, cpu_vtimer_irq, cpu_ptimer_irq); }
arch/arm64/kvm/reset.c +8 -1
@@ -46,6 +46,11 @@ static const struct kvm_regs default_regs_reset32 = { COMPAT_PSR_I_BIT | COMPAT_PSR_F_BIT), }; +static const struct kvm_irq_level default_ptimer_irq = { + .irq =30 , + .level =1 , +}; +static const struct kvm_irq_level default_vtimer_irq = { .irq =27 , .level =1 ,
@@ -104,6 +109,7 @@ int kvm_arch_dev_ioctl_check_extension(struct kvm *kvm, long ext)int kvm_reset_vcpu (struct kvm_vcpu *vcpu) {const struct kvm_irq_level *cpu_vtimer_irq; +const struct kvm_irq_level *cpu_ptimer_irq;const struct kvm_regs *cpu_reset;switch (vcpu->arch.target) {
@@ -117,6 +123,7 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu) } cpu_vtimer_irq = &default_vtimer_irq; + cpu_ptimer_irq = &default_ptimer_irq;break ; }
@@ -130,5 +137,5 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu)kvm_pmu_vcpu_reset (vcpu);/* Reset timer */ -return kvm_timer_vcpu_reset (vcpu, cpu_vtimer_irq); +return kvm_timer_vcpu_reset (vcpu, cpu_vtimer_irq, cpu_ptimer_irq); }
include/kvm/arm_arch_timer.h +2 -1
@@ -58,7 +58,8 @@ struct arch_timer_cpu {int kvm_timer_hyp_init (void );int kvm_timer_enable (struct kvm_vcpu *vcpu);int kvm_timer_vcpu_reset (struct kvm_vcpu *vcpu, -const struct kvm_irq_level *irq); +const struct kvm_irq_level *virt_irq, +const struct kvm_irq_level *phys_irq);void kvm_timer_vcpu_init (struct kvm_vcpu *vcpu);void kvm_timer_flush_hwstate (struct kvm_vcpu *vcpu);void kvm_timer_sync_hwstate (struct kvm_vcpu *vcpu);
virt/kvm/arm/arch_timer.c +7 -2
@@ -327,9 +327,11 @@ void kvm_timer_sync_hwstate(struct kvm_vcpu *vcpu) }int kvm_timer_vcpu_reset (struct kvm_vcpu *vcpu, -const struct kvm_irq_level *irq) +const struct kvm_irq_level *virt_irq, +const struct kvm_irq_level *phys_irq) {struct arch_timer_context *vtimer =vcpu_vtimer (vcpu); +struct arch_timer_context *ptimer =vcpu_ptimer (vcpu);/* * The vcpu timer irq number cannot be determined in
@@ -337,7 +339,8 @@ int kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu,* kvm_vcpu_set_target(). To handle this, we determine * vcpu timer irq number when the vcpu is reset. */ - vtimer->irq.irq = irq->irq; + vtimer->irq.irq = virt_irq->irq; + ptimer->irq.irq = phys_irq->irq;/* * The bits in CNTV_CTL are architecturally reset to UNKNOWN for ARMv8
@@ -346,6 +349,7 @@ int kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu,* the ARMv7 architecture. */ vtimer->cnt_ctl =0 ; + ptimer->cnt_ctl =0 ;kvm_timer_update_state (vcpu);return 0 ;
@@ -376,6 +380,7 @@ void kvm_timer_vcpu_init(struct kvm_vcpu *vcpu)/* Synchronize cntvoff across all vtimers of a VM. */ update_vtimer_cntvoff (vcpu,kvm_phys_timer_read ()); +vcpu_ptimer (vcpu)->cntvoff =0 ;INIT_WORK (&timer->expired, kvm_timer_inject_irq_work);hrtimer_init (&timer->timer,CLOCK_MONOTONIC ,HRTIMER_MODE_ABS );
Signature · 1 line
2.1.4
PATCH 21/25 KVM: arm/arm64: Update the physical timer interrupt level
In reply to Marc ZyngierFrom: Jintack Lim <[email protected]>
Now that we maintain the EL1 physical timer register states of VMs, update the physical timer interrupt level along with the virtual one.
--- virt/kvm/arm/arch_timer.c | 4 ++++ 1 file changed, 4 insertions(+)
virt/kvm/arm/arch_timer.c +4 -0
@@ -186,6 +186,7 @@ static int kvm_timer_update_state(struct kvm_vcpu *vcpu) {struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu;struct arch_timer_context *vtimer =vcpu_vtimer (vcpu); +struct arch_timer_context *ptimer =vcpu_ptimer (vcpu);/* * If userspace modified the timer registers via SET_ONE_REG before
@@ -199,6 +200,9 @@ static int kvm_timer_update_state(struct kvm_vcpu *vcpu)if (kvm_timer_should_fire (vtimer) != vtimer->irq.level)kvm_timer_update_irq (vcpu, !vtimer->irq.level, vtimer); +if (kvm_timer_should_fire (ptimer) != ptimer->irq.level) +kvm_timer_update_irq (vcpu, !ptimer->irq.level, ptimer); +return 0 ; }
Signature · 1 line
2.1.4
PATCH 22/25 KVM: arm/arm64: Set a background timer to the earliest timer expiration
In reply to Marc ZyngierFrom: Jintack Lim <[email protected]>
When scheduling a background timer, consider both of the virtual and physical timer and pick the earliest expiration time.
--- arch/arm/kvm/arm.c | 3 ++- virt/kvm/arm/arch_timer.c | 53 +++++++++++++++++++++++++++++++++++------------ 2 files changed, 42 insertions(+), 14 deletions(-)
arch/arm/kvm/arm.c +2 -1
@@ -300,7 +300,8 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)int kvm_cpu_has_pending_timer (struct kvm_vcpu *vcpu) { -return kvm_timer_should_fire (vcpu_vtimer (vcpu)); +return kvm_timer_should_fire (vcpu_vtimer (vcpu)) || +kvm_timer_should_fire (vcpu_ptimer (vcpu)); }void kvm_arch_vcpu_blocking (struct kvm_vcpu *vcpu)
virt/kvm/arm/arch_timer.c +40 -13
91 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH 23/25 KVM: arm/arm64: Set up a background timer for the physical timer emulation
In reply to Marc ZyngierFrom: Jintack Lim <[email protected]>
Set a background timer for the EL1 physical timer emulation while VMs are running, so that VMs get the physical timer interrupts in a timely manner.
Schedule the background timer on entry to the VM and cancel it on exit. This would not have any performance impact to the guest OSes that currently use the virtual timer since the physical timer is always not enabled.
--- virt/kvm/arm/arch_timer.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)
virt/kvm/arm/arch_timer.c +24 -1
@@ -229,6 +229,22 @@ static int kvm_timer_update_state(struct kvm_vcpu *vcpu)return 0 ; } +/* Schedule the background timer for the emulated timer. */ +static void kvm_timer_emulate (struct kvm_vcpu *vcpu, +struct arch_timer_context *timer_ctx) +{ +struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu; + +if (kvm_timer_should_fire (timer_ctx)) +return ; + +if (!kvm_timer_irq_can_fire (timer_ctx)) +return ; + +/* The timer has not yet expired, schedule a background timer */ +timer_arm (timer,kvm_timer_compute_delta (timer_ctx)); +} +/* * Schedule the background timer before calling kvm_vcpu_block, so that this * thread is removed from its waitqueue and made runnable when there's a timer
@@ -286,6 +302,9 @@ void kvm_timer_flush_hwstate(struct kvm_vcpu *vcpu)if (kvm_timer_update_state (vcpu))return ; +/* Set the background timer for the physical timer emulation. */ +kvm_timer_emulate (vcpu,vcpu_ptimer (vcpu)); +/* * If we enter the guest with the virtual input level to the VGIC * asserted, then we have already told the VGIC what we need to, and
@@ -348,7 +367,11 @@ void kvm_timer_sync_hwstate(struct kvm_vcpu *vcpu) {struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu; -BUG_ON (timer_is_armed (timer)); +/* +* This is to cancel the background timer for the physical timer +* emulation if it is set. +*/ +timer_disarm (timer);/* * The guest could have modified the timer registers or the timer
Signature · 1 line
2.1.4
PATCH 24/25 KVM: arm64: Add the EL1 physical timer access handler
In reply to Marc ZyngierFrom: Jintack Lim <[email protected]>
KVM traps on the EL1 phys timer accesses from VMs, but it doesn't handle those traps. This results in terminating VMs. Instead, set a handler for the EL1 phys timer access, and inject an undefined exception as an intermediate step.
--- arch/arm64/kvm/sys_regs.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
arch/arm64/kvm/sys_regs.c +34 -0
@@ -820,6 +820,30 @@ static bool access_pmuserenr(struct kvm_vcpu *vcpu, struct sys_reg_params *p, CRm((0b1100 | (((n) >> 3) & 0x3))), Op2(((n) & 0x7)), \ access_pmu_evtyper, reset_unknown, (PMEVTYPER0_EL0 + n), } +static bool access_cntp_tval (struct kvm_vcpu *vcpu, +struct sys_reg_params *p, +const struct sys_reg_desc *r) +{ +kvm_inject_undefined (vcpu); +return true; +} + +static bool access_cntp_ctl (struct kvm_vcpu *vcpu, +struct sys_reg_params *p, +const struct sys_reg_desc *r) +{ +kvm_inject_undefined (vcpu); +return true; +} + +static bool access_cntp_cval (struct kvm_vcpu *vcpu, +struct sys_reg_params *p, +const struct sys_reg_desc *r) +{ +kvm_inject_undefined (vcpu); +return true; +} +/* * Architected system registers. * Important: Must be sorted ascending by Op0, Op1, CRn, CRm, Op2
@@ -1029,6 +1053,16 @@ static const struct sys_reg_desc sys_reg_descs[] = { {Op0 (0b11 ),Op1 (0b011 ),CRn (0b1101 ),CRm (0b0000 ),Op2 (0b011 ), NULL, reset_unknown, TPIDRRO_EL0 }, +/* CNTP_TVAL_EL0 */ + { Op0(0b11), Op1(0b011), CRn(0b1110), CRm(0b0010), Op2(0b000), + access_cntp_tval }, +/* CNTP_CTL_EL0 */ + { Op0(0b11), Op1(0b011), CRn(0b1110), CRm(0b0010), Op2(0b001), + access_cntp_ctl }, +/* CNTP_CVAL_EL0 */ + { Op0(0b11), Op1(0b011), CRn(0b1110), CRm(0b0010), Op2(0b010), + access_cntp_cval }, +/* PMEVCNTRn_EL0 */ PMU_PMEVCNTR_EL0 (0 ), PMU_PMEVCNTR_EL0(1),
Signature · 1 line
2.1.4
PATCH 25/25 KVM: arm/arm64: Emulate the EL1 phys timer registers
In reply to Marc ZyngierFrom: Jintack Lim <[email protected]>
Emulate read and write operations to CNTP_TVAL, CNTP_CVAL and CNTP_CTL. Now VMs are able to use the EL1 physical timer.
--- arch/arm64/kvm/sys_regs.c | 37 ++++++++++++++++++++++++++++++++++--- include/kvm/arm_arch_timer.h | 2 ++ virt/kvm/arm/arch_timer.c | 2 +- 3 files changed, 37 insertions(+), 4 deletions(-)
arch/arm64/kvm/sys_regs.c +34 -3
@@ -824,7 +824,14 @@ static bool access_cntp_tval(struct kvm_vcpu *vcpu,struct sys_reg_params *p, const struct sys_reg_desc *r) { -kvm_inject_undefined (vcpu ); + struct arch_timer_context *ptimer = vcpu_ptimer(vcpu); +u64 now =kvm_phys_timer_read (); + +if (p->is_write) + ptimer->cnt_cval = p->regval + now; +else + p->regval = ptimer->cnt_cval - now; +return true; }
@@ -832,7 +839,25 @@ static bool access_cntp_ctl(struct kvm_vcpu *vcpu,struct sys_reg_params *p, const struct sys_reg_desc *r) { -kvm_inject_undefined (vcpu ); + struct arch_timer_context *ptimer = vcpu_ptimer(vcpu); + +if (p->is_write) { +/* ISTATUS bit is read-only */ + ptimer->cnt_ctl = p->regval & ~ARCH_TIMER_CTRL_IT_STAT ; + }else { +u64 now =kvm_phys_timer_read (); + + p->regval = ptimer->cnt_ctl; +/* +* Set ISTATUS bit if it's expired. +* Note that according to ARMv8 ARM Issue A.k, ISTATUS bit is +* UNKNOWN when ENABLE bit is 0, so we chose to set ISTATUS bit +* regardless of ENABLE bit for our implementation convenience. +*/ +if (ptimer->cnt_cval <= now) + p->regval |=ARCH_TIMER_CTRL_IT_STAT ; + } +return true; }
@@ -840,7 +865,13 @@ static bool access_cntp_cval(struct kvm_vcpu *vcpu,struct sys_reg_params *p, const struct sys_reg_desc *r) { -kvm_inject_undefined (vcpu ); + struct arch_timer_context *ptimer = vcpu_ptimer(vcpu); + +if (p->is_write) + ptimer->cnt_cval = p->regval; +else + p->regval = ptimer->cnt_cval; +return true; }
include/kvm/arm_arch_timer.h +2 -0
@@ -72,6 +72,8 @@ bool kvm_timer_should_fire(struct arch_timer_context *timer_ctx);void kvm_timer_schedule (struct kvm_vcpu *vcpu);void kvm_timer_unschedule (struct kvm_vcpu *vcpu); +u64 kvm_phys_timer_read (void ); +void kvm_timer_vcpu_put (struct kvm_vcpu *vcpu);void kvm_timer_init_vhe (void );
virt/kvm/arm/arch_timer.c +1 -1
@@ -40,7 +40,7 @@ void kvm_timer_vcpu_put(struct kvm_vcpu *vcpu)vcpu_vtimer (vcpu)->active_cleared_last = false; } -static u64 kvm_phys_timer_read (void ) +u64 kvm_phys_timer_read (void ) {return timecounter->cc->read (timecounter->cc); }
Signature · 1 line
2.1.4
Paolo Bonzini
maintainerQuoted 1 line · Marc Zyngier
git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.gittags/kvmarm-for-4.11
Pulled, thanks.
Paolo