KVM/ARM Fixes for v4.12-rc5 - Take 2
Subsystems (6)
[PULL v2 1/6] KVM: arm/arm64: Fix isues with GICv2 on GICv3 migration
In reply to Christoffer DallWe have been a little loose with our intermediate VMCR representation where we had a 'ctlr' field, but we failed to differentiate between the GICv2 GICC_CTLR and ICC_CTLR_EL1 layouts, and therefore ended up mapping the wrong bits into the individual fields of the ICH_VMCR_EL2 when emulating a GICv2 on a GICv3 system.
Fix this by using explicit fields for the VMCR bits instead.
--- arch/arm64/kvm/vgic-sys-reg-v3.c | 10 ++++---- include/linux/irqchip/arm-gic-v3.h | 4 ++++ include/linux/irqchip/arm-gic.h | 28 ++++++++++++++++++++--- virt/kvm/arm/vgic/vgic-mmio-v2.c | 16 +++++++++++-- virt/kvm/arm/vgic/vgic-v2.c | 28 ++++++++++++++++++++--- virt/kvm/arm/vgic/vgic-v3.c | 47 ++++++++++++++++++++++++++------------ virt/kvm/arm/vgic/vgic.h | 12 ++++++---- 7 files changed, 114 insertions(+), 31 deletions(-)
arch/arm64/kvm/vgic-sys-reg-v3.c +5 -5
@@ -65,8 +65,8 @@ static bool access_gic_ctlr(struct kvm_vcpu *vcpu, struct sys_reg_params *p,* Here set VMCR.CTLR in ICC_CTLR_EL1 layout. * The vgic_set_vmcr() will convert to ICH_VMCR layout. */ - vmcr.ctlr = val &ICC_CTLR_EL1_CBPR_MASK ; - vmcr.ctlr |= val & ICC_CTLR_EL1_EOImode_MASK; + vmcr.cbpr = (val &ICC_CTLR_EL1_CBPR_MASK ) >>ICC_CTLR_EL1_CBPR_SHIFT ; + vmcr.eoim = (val & ICC_CTLR_EL1_EOImode_MASK) >> ICC_CTLR_EL1_EOImode_SHIFT;vgic_set_vmcr (vcpu, &vmcr); }else { val =0 ;
@@ -83,8 +83,8 @@ static bool access_gic_ctlr(struct kvm_vcpu *vcpu, struct sys_reg_params *p,* The VMCR.CTLR value is in ICC_CTLR_EL1 layout. * Extract it directly using ICC_CTLR_EL1 reg definitions. */ - val |= vmcr.ctlr &ICC_CTLR_EL1_CBPR_MASK ; - val |= vmcr.ctlr & ICC_CTLR_EL1_EOImode_MASK; + val |= (vmcr.cbpr <<ICC_CTLR_EL1_CBPR_SHIFT ) &ICC_CTLR_EL1_CBPR_MASK ; + val |= (vmcr.eoim << ICC_CTLR_EL1_EOImode_SHIFT) & ICC_CTLR_EL1_EOImode_MASK; p->regval = val; }
@@ -135,7 +135,7 @@ static bool access_gic_bpr1(struct kvm_vcpu *vcpu, struct sys_reg_params *p, p->regval =0 ;vgic_get_vmcr (vcpu, &vmcr); -if (!((vmcr.ctlr &ICH_VMCR_CBPR_MASK ) >>ICH_VMCR_CBPR_SHIFT )) { +if (!vmcr.cbpr) {if (p->is_write) { vmcr.abpr = (p->regval &ICC_BPR1_EL1_MASK ) >>ICC_BPR1_EL1_SHIFT ;
include/linux/irqchip/arm-gic-v3.h +4 -0
@@ -417,6 +417,10 @@#define ICH_HCR_EN (1 << 0)#define ICH_HCR_UIE (1 << 1) +#define ICH_VMCR_ACK_CTL_SHIFT 2 +#define ICH_VMCR_ACK_CTL_MASK (1 << ICH_VMCR_ACK_CTL_SHIFT) +#define ICH_VMCR_FIQ_EN_SHIFT 3 +#define ICH_VMCR_FIQ_EN_MASK (1 << ICH_VMCR_FIQ_EN_SHIFT)#define ICH_VMCR_CBPR_SHIFT 4#define ICH_VMCR_CBPR_MASK (1 << ICH_VMCR_CBPR_SHIFT)#define ICH_VMCR_EOIM_SHIFT 9
include/linux/irqchip/arm-gic.h +25 -3
@@ -25,7 +25,18 @@#define GICC_ENABLE 0x1#define GICC_INT_PRI_THRESHOLD 0xf0 -#define GIC_CPU_CTRL_EOImodeNS (1 << 9) +#define GIC_CPU_CTRL_EnableGrp0_SHIFT 0 +#define GIC_CPU_CTRL_EnableGrp0 (1 << GIC_CPU_CTRL_EnableGrp0_SHIFT) +#define GIC_CPU_CTRL_EnableGrp1_SHIFT 1 +#define GIC_CPU_CTRL_EnableGrp1 (1 << GIC_CPU_CTRL_EnableGrp1_SHIFT) +#define GIC_CPU_CTRL_AckCtl_SHIFT 2 +#define GIC_CPU_CTRL_AckCtl (1 << GIC_CPU_CTRL_AckCtl_SHIFT) +#define GIC_CPU_CTRL_FIQEn_SHIFT 3 +#define GIC_CPU_CTRL_FIQEn (1 << GIC_CPU_CTRL_FIQEn_SHIFT) +#define GIC_CPU_CTRL_CBPR_SHIFT 4 +#define GIC_CPU_CTRL_CBPR (1 << GIC_CPU_CTRL_CBPR_SHIFT) +#define GIC_CPU_CTRL_EOImodeNS_SHIFT 9 +#define GIC_CPU_CTRL_EOImodeNS (1 << GIC_CPU_CTRL_EOImodeNS_SHIFT)#define GICC_IAR_INT_ID_MASK 0x3ff#define GICC_INT_SPURIOUS 1023
@@ -84,8 +95,19 @@#define GICH_LR_EOI (1 << 19)#define GICH_LR_HW (1 << 31) -#define GICH_VMCR_CTRL_SHIFT 0 -#define GICH_VMCR_CTRL_MASK (0x21f << GICH_VMCR_CTRL_SHIFT) +#define GICH_VMCR_ENABLE_GRP0_SHIFT 0 +#define GICH_VMCR_ENABLE_GRP0_MASK (1 << GICH_VMCR_ENABLE_GRP0_SHIFT) +#define GICH_VMCR_ENABLE_GRP1_SHIFT 1 +#define GICH_VMCR_ENABLE_GRP1_MASK (1 << GICH_VMCR_ENABLE_GRP1_SHIFT) +#define GICH_VMCR_ACK_CTL_SHIFT 2 +#define GICH_VMCR_ACK_CTL_MASK (1 << GICH_VMCR_ACK_CTL_SHIFT) +#define GICH_VMCR_FIQ_EN_SHIFT 3 +#define GICH_VMCR_FIQ_EN_MASK (1 << GICH_VMCR_FIQ_EN_SHIFT) +#define GICH_VMCR_CBPR_SHIFT 4 +#define GICH_VMCR_CBPR_MASK (1 << GICH_VMCR_CBPR_SHIFT) +#define GICH_VMCR_EOI_MODE_SHIFT 9 +#define GICH_VMCR_EOI_MODE_MASK (1 << GICH_VMCR_EOI_MODE_SHIFT) +#define GICH_VMCR_PRIMASK_SHIFT 27#define GICH_VMCR_PRIMASK_MASK (0x1f << GICH_VMCR_PRIMASK_SHIFT)#define GICH_VMCR_BINPOINT_SHIFT 21
virt/kvm/arm/vgic/vgic-mmio-v2.c +14 -2
@@ -226,7 +226,13 @@ static unsigned long vgic_mmio_read_vcpuif(struct kvm_vcpu *vcpu,switch (addr &0xff ) {case GIC_CPU_CTRL : - val = vmcr.ctlr; + val = vmcr.grpen0 << GIC_CPU_CTRL_EnableGrp0_SHIFT; + val |= vmcr.grpen1 << GIC_CPU_CTRL_EnableGrp1_SHIFT; + val |= vmcr.ackctl << GIC_CPU_CTRL_AckCtl_SHIFT; + val |= vmcr.fiqen << GIC_CPU_CTRL_FIQEn_SHIFT; + val |= vmcr.cbpr <<GIC_CPU_CTRL_CBPR_SHIFT ; + val |= vmcr.eoim << GIC_CPU_CTRL_EOImodeNS_SHIFT; +break ;case GIC_CPU_PRIMASK :/*
@@ -267,7 +273,13 @@ static void vgic_mmio_write_vcpuif(struct kvm_vcpu *vcpu,switch (addr &0xff ) {case GIC_CPU_CTRL : - vmcr.ctlr = val; + vmcr.grpen0 = !!(val & GIC_CPU_CTRL_EnableGrp0); + vmcr.grpen1 = !!(val & GIC_CPU_CTRL_EnableGrp1); + vmcr.ackctl = !!(val & GIC_CPU_CTRL_AckCtl); + vmcr.fiqen = !!(val & GIC_CPU_CTRL_FIQEn); + vmcr.cbpr = !!(val &GIC_CPU_CTRL_CBPR ); + vmcr.eoim = !!(val & GIC_CPU_CTRL_EOImodeNS); +break ;case GIC_CPU_PRIMASK :/*
virt/kvm/arm/vgic/vgic-v2.c +25 -3
@@ -177,7 +177,18 @@ void vgic_v2_set_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcrp)struct vgic_v2_cpu_if *cpu_if = &vcpu->arch.vgic_cpu.vgic_v2;u32 vmcr; - vmcr = (vmcrp->ctlr <<GICH_VMCR_CTRL_SHIFT ) &GICH_VMCR_CTRL_MASK ; + vmcr = (vmcrp->grpen0 <<GICH_VMCR_ENABLE_GRP0_SHIFT ) & +GICH_VMCR_ENABLE_GRP0_MASK ; + vmcr |= (vmcrp->grpen1 <<GICH_VMCR_ENABLE_GRP1_SHIFT ) & +GICH_VMCR_ENABLE_GRP1_MASK ; + vmcr |= (vmcrp->ackctl <<GICH_VMCR_ACK_CTL_SHIFT ) & +GICH_VMCR_ACK_CTL_MASK ; + vmcr |= (vmcrp->fiqen <<GICH_VMCR_FIQ_EN_SHIFT ) & +GICH_VMCR_FIQ_EN_MASK ; + vmcr |= (vmcrp->cbpr <<GICH_VMCR_CBPR_SHIFT ) & +GICH_VMCR_CBPR_MASK ; + vmcr |= (vmcrp->eoim <<GICH_VMCR_EOI_MODE_SHIFT ) & +GICH_VMCR_EOI_MODE_MASK ; vmcr |= (vmcrp->abpr <<GICH_VMCR_ALIAS_BINPOINT_SHIFT ) &GICH_VMCR_ALIAS_BINPOINT_MASK ; vmcr |= (vmcrp->bpr << GICH_VMCR_BINPOINT_SHIFT) &
@@ -195,8 +206,19 @@ void vgic_v2_get_vmcr(struct kvm_vcpu *vcpu, struct vgic_vmcr *vmcrp) vmcr = cpu_if->vgic_vmcr; - vmcrp->ctlr = (vmcr &GICH_VMCR_CTRL_MASK ) >> -GICH_VMCR_CTRL_SHIFT ; + vmcrp->grpen0 = (vmcr &GICH_VMCR_ENABLE_GRP0_MASK ) >> +GICH_VMCR_ENABLE_GRP0_SHIFT ; + vmcrp->grpen1 = (vmcr &GICH_VMCR_ENABLE_GRP1_MASK ) >> +GICH_VMCR_ENABLE_GRP1_SHIFT ; + vmcrp->ackctl = (vmcr &GICH_VMCR_ACK_CTL_MASK ) >> +GICH_VMCR_ACK_CTL_SHIFT ; + vmcrp->fiqen = (vmcr &GICH_VMCR_FIQ_EN_MASK ) >> +GICH_VMCR_FIQ_EN_SHIFT ; + vmcrp->cbpr = (vmcr &GICH_VMCR_CBPR_MASK ) >> +GICH_VMCR_CBPR_SHIFT ; + vmcrp->eoim = (vmcr &GICH_VMCR_EOI_MODE_MASK ) >> +GICH_VMCR_EOI_MODE_SHIFT ; + vmcrp->abpr = (vmcr &GICH_VMCR_ALIAS_BINPOINT_MASK ) >>GICH_VMCR_ALIAS_BINPOINT_SHIFT ; vmcrp->bpr = (vmcr & GICH_VMCR_BINPOINT_MASK) >>
virt/kvm/arm/vgic/vgic-v3.c +33 -14
65 lines not on this page · raw message
virt/kvm/arm/vgic/vgic.h +8 -4
@@ -111,14 +111,18 @@ static inline bool irq_is_pending(struct vgic_irq *irq)* registers regardless of the hardware backed GIC used. */ struct vgic_vmcr { -u32 ctlr; +u32 grpen0; +u32 grpen1; + +u32 ackctl; +u32 fiqen; +u32 cbpr; +u32 eoim; +u32 abpr;u32 bpr;u32 pmr;/* Priority mask field in the GICC_PMR and * ICC_PMR_EL1 priority field format */ -/* Below member variable are valid only for GICv3 */ -u32 grpen0; -u32 grpen1; };struct vgic_reg_attr {
Signature · 1 line
2.9.0
[PULL v2 3/6] KVM: arm/arm64: Handle possible NULL stage2 pud when ageing pages
In reply to Christoffer DallFrom: Marc Zyngier <[email protected]>
Under memory pressure, we start ageing pages, which amounts to parsing the page tables. Since we don't want to allocate any extra level, we pass NULL for our private allocation cache. Which means that stage2_get_pud() is allowed to fail. This results in the following splat:
[ 1520.409577] Unable to handle kernel NULL pointer dereference at virtual address 00000008 [ 1520.417741] pgd = ffff810f52fef000 [ 1520.421201] [00000008] *pgd=0000010f636c5003, *pud=0000010f56f48003, *pmd=0000000000000000 [ 1520.429546] Internal error: Oops: 96000006 [#1] PREEMPT SMP [ 1520.435156] Modules linked in: [ 1520.438246] CPU: 15 PID: 53550 Comm: qemu-system-aar Tainted: G W 4.12.0-rc4-00027-g1885c397eaec #7205 [ 1520.448705] Hardware name: FOXCONN R2-1221R-A4/C2U4N_MB, BIOS G31FB12A 10/26/2016 [ 1520.463726] task: ffff800ac5fb4e00 task.stack: ffff800ce04e0000 [ 1520.469666] PC is at stage2_get_pmd+0x34/0x110 [ 1520.474119] LR is at kvm_age_hva_handler+0x44/0xf0 [ 1520.478917] pc : [<ffff0000080b137c>] lr : [<ffff0000080b149c>] pstate: 40000145 [ 1520.486325] sp : ffff800ce04e33d0 [ 1520.489644] x29: ffff800ce04e33d0 x28: 0000000ffff40064 [ 1520.494967] x27: 0000ffff27e00000 x26: 0000000000000000 [ 1520.500289] x25: ffff81051ba65008 x24: 0000ffff40065000 [ 1520.505618] x23: 0000ffff40064000 x22: 0000000000000000 [ 1520.510947] x21: ffff810f52b20000 x20: 0000000000000000 [ 1520.516274] x19: 0000000058264000 x18: 0000000000000000 [ 1520.521603] x17: 0000ffffa6fe7438 x16: ffff000008278b70 [ 1520.526940] x15: 000028ccd8000000 x14: 0000000000000008 [ 1520.532264] x13: ffff7e0018298000 x12: 0000000000000002 [ 1520.537582] x11: ffff000009241b93 x10: 0000000000000940 [ 1520.542908] x9 : ffff0000092ef800 x8 : 0000000000000200 [ 1520.548229] x7 : ffff800ce04e36a8 x6 : 0000000000000000 [ 1520.553552] x5 : 0000000000000001 x4 : 0000000000000000 [ 1520.558873] x3 : 0000000000000000 x2 : 0000000000000008 [ 1520.571696] x1 : ffff000008fd5000 x0 : ffff0000080b149c [ 1520.577039] Process qemu-system-aar (pid: 53550, stack limit = 0xffff800ce04e0000) [...] [ 1521.510735] [<ffff0000080b137c>] stage2_get_pmd+0x34/0x110 [ 1521.516221] [<ffff0000080b149c>] kvm_age_hva_handler+0x44/0xf0 [ 1521.522054] [<ffff0000080b0610>] handle_hva_to_gpa+0xb8/0xe8 [ 1521.527716] [<ffff0000080b3434>] kvm_age_hva+0x44/0xf0 [ 1521.532854] [<ffff0000080a58b0>] kvm_mmu_notifier_clear_flush_young+0x70/0xc0 [ 1521.539992] [<ffff000008238378>] __mmu_notifier_clear_flush_young+0x88/0xd0 [ 1521.546958] [<ffff00000821eca0>] page_referenced_one+0xf0/0x188 [ 1521.552881] [<ffff00000821f36c>] rmap_walk_anon+0xec/0x250 [ 1521.558370] [<ffff000008220f78>] rmap_walk+0x78/0xa0 [ 1521.563337] [<ffff000008221104>] page_referenced+0x164/0x180 [ 1521.569002] [<ffff0000081f1af0>] shrink_active_list+0x178/0x3b8 [ 1521.574922] [<ffff0000081f2058>] shrink_node_memcg+0x328/0x600 [ 1521.580758] [<ffff0000081f23f4>] shrink_node+0xc4/0x328 [ 1521.585986] [<ffff0000081f2718>] do_try_to_free_pages+0xc0/0x340 [ 1521.592000] [<ffff0000081f2a64>] try_to_free_pages+0xcc/0x240
[...]
The trivial fix is to handle this NULL pud value early, rather than dereferencing it blindly.
--- virt/kvm/arm/mmu.c | 3 +++ 1 file changed, 3 insertions(+)
virt/kvm/arm/mmu.c +3 -0
@@ -879,6 +879,9 @@ static pmd_t *stage2_get_pmd(struct kvm *kvm, struct kvm_mmu_memory_cache *cachepmd_t *pmd; pud =stage2_get_pud (kvm, cache, addr); +if (!pud) +return NULL ; +if (stage2_pud_none (*pud)) {if (!cache)return NULL ;
Signature · 1 line
2.9.0
[PULL v2 4/6] arm64: KVM: Preserve RES1 bits in SCTLR_EL2
In reply to Christoffer DallFrom: Marc Zyngier <[email protected]>
__do_hyp_init has the rather bad habit of ignoring RES1 bits and writing them back as zero. On a v8.0-8.2 CPU, this doesn't do anything bad, but may end-up being pretty nasty on future revisions of the architecture.
Let's preserve those bits so that we don't have to fix this later on.
--- arch/arm64/include/asm/sysreg.h | 4 ++++ arch/arm64/kvm/hyp-init.S | 10 ++++++---- 2 files changed, 10 insertions(+), 4 deletions(-)
arch/arm64/include/asm/sysreg.h +4 -0
@@ -286,6 +286,10 @@#define SCTLR_ELx_A (1 << 1)#define SCTLR_ELx_M 1 +#define SCTLR_EL2_RES1 ((1 << 4) | (1 << 5) | (1 << 11) | (1 << 16) | \ + (1 << 16) | (1 << 18) | (1 << 22) | (1 << 23) | \ + (1 << 28) | (1 << 29)) +#define SCTLR_ELx_FLAGS (SCTLR_ELx_M | SCTLR_ELx_A | SCTLR_ELx_C | \ SCTLR_ELx_SA | SCTLR_ELx_I)
arch/arm64/kvm/hyp-init.S +6 -4
@@ -106,10 +106,12 @@ __do_hyp_init: tlbi alle2 dsb sy - mrs x4, sctlr_el2 - and x4, x4, #SCTLR_ELx_EE // preserve endianness of EL2 - ldr x5, =SCTLR_ELx_FLAGS - orr x4, x4, x5 + /* + * Preserve all the RES1 bits while setting the default flags, + * as well as the EE bit on BE. + */ + ldr x4, =(SCTLR_EL2_RES1 | SCTLR_ELx_FLAGS) +CPU_BE( orr x4, x4, #SCTLR_ELx_EE) msr sctlr_el2, x4 isb
Signature · 1 line
2.9.0
[PULL v2 6/6] arm: KVM: Allow unaligned accesses at HYP
In reply to Christoffer DallFrom: Marc Zyngier <[email protected]>
We currently have the HSCTLR.A bit set, trapping unaligned accesses at HYP, but we're not really prepared to deal with it.
Since the rest of the kernel is pretty happy about that, let's follow its example and set HSCTLR.A to zero. Modern CPUs don't really care.
--- arch/arm/kvm/init.S | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
arch/arm/kvm/init.S +2 -3
@@ -104,7 +104,6 @@ __do_hyp_init: @ - Write permission implies XN: disabled @ - Instruction cache: enabled @ - Data/Unified cache: enabled - @ - Memory alignment checks: enabled @ - MMU: enabled (this code must be run from an identity mapping) mrc p15, 4, r0, c1, c0, 0 @ HSCR ldr r2, =HSCTLR_MASK
@@ -112,8 +111,8 @@ __do_hyp_init: mrc p15, 0, r1, c1, c0, 0 @ SCTLR ldr r2, =(HSCTLR_EE | HSCTLR_FI | HSCTLR_I | HSCTLR_C) and r1, r1, r2 - ARM( ldr r2, =(HSCTLR_M | HSCTLR_A) ) - THUMB( ldr r2, =(HSCTLR_M | HSCTLR_A | HSCTLR_TE) ) + ARM( ldr r2, =(HSCTLR_M) ) + THUMB( ldr r2, =(HSCTLR_M | HSCTLR_TE) ) orr r1, r1, r2 orr r0, r0, r1 mcr p15, 4, r0, c1, c0, 0 @ HSCR
Signature · 1 line
2.9.0
Hi Radim and Paolo,
Six additional fixes for KVM/ARM for v4.12 (instead of only the first three in the first version of this pull request).
The changes are:
- Fix an issue with migrating GICv2 VMs on GICv3 systems.
- Squashed a bug for gicv3 when figuring out preemption levels.
- Fix a potential null pointer derefence in KVM happening under memory pressure.
- Maintain RES1 bits in the SCTLR_EL2 to make sure KVM works on new architecture revisions.
- Allow unaligned accesses at EL2/HYP
The following changes since commit fa472fa91a5a0b241f5ddae927d2e235d07545df:
KVM: arm/arm64: Hold slots_lock when unregistering kvm io bus devices (2017-05-18 11:18:16 +0200)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git kvm-arm-for-v4.12-rc5-take2
for you to fetch changes up to 33b5c38852b29736f3b472dd095c9a18ec22746f:
arm: KVM: Allow unaligned accesses at HYP (2017-06-06 22:20:02 +0200)
Thanks,
-Christoffer
---
Christoffer Dall (2):
KVM: arm/arm64: Fix isues with GICv2 on GICv3 migration
KVM: arm/arm64: vgic-v3: Fix nr_pre_bits bitfield extraction
Marc Zyngier (4):
KVM: arm/arm64: Handle possible NULL stage2 pud when ageing pages
arm64: KVM: Preserve RES1 bits in SCTLR_EL2
arm64: KVM: Allow unaligned accesses at EL2
arm: KVM: Allow unaligned accesses at HYP
arch/arm/kvm/init.S | 5 ++-- arch/arm64/include/asm/sysreg.h | 4 ++++ arch/arm64/kvm/hyp-init.S | 11 +++++---- arch/arm64/kvm/vgic-sys-reg-v3.c | 10 ++++---- include/linux/irqchip/arm-gic-v3.h | 4 ++++ include/linux/irqchip/arm-gic.h | 28 ++++++++++++++++++++--- virt/kvm/arm/hyp/vgic-v3-sr.c | 2 +- virt/kvm/arm/mmu.c | 3 +++ virt/kvm/arm/vgic/vgic-mmio-v2.c | 16 +++++++++++-- virt/kvm/arm/vgic/vgic-v2.c | 28 ++++++++++++++++++++--- virt/kvm/arm/vgic/vgic-v3.c | 47 ++++++++++++++++++++++++++------------ virt/kvm/arm/vgic/vgic.h | 12 ++++++---- 12 files changed, 131 insertions(+), 39 deletions(-)
[PULL v2 2/6] KVM: arm/arm64: vgic-v3: Fix nr_pre_bits bitfield extraction
We used to extract PRIbits from the ICH_VT_EL2 which was the upper field in the register word, so a mask wasn't necessary, but as we switched to looking at PREbits, which is bits 26 through 28 with the PRIbits field being potentially non-zero, we really need to mask off the field value, otherwise fun things may happen.
--- virt/kvm/arm/hyp/vgic-v3-sr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
virt/kvm/arm/hyp/vgic-v3-sr.c +1 -1
@@ -22,7 +22,7 @@#include <asm/kvm_hyp.h> #define vtr_to_max_lr_idx (v) ((v) & 0xf) -#define vtr_to_nr_pre_bits (v) (((u32)(v) >> 26) + 1) +#define vtr_to_nr_pre_bits (v) ((((u32)(v) >> 26) & 7) + 1) static u64 __hyp_text __gic_v3_get_lr(unsigned int lr) {
Signature · 1 line
2.9.0
[PULL v2 5/6] arm64: KVM: Allow unaligned accesses at EL2
In reply to Christoffer DallFrom: Marc Zyngier <[email protected]>
We currently have the SCTLR_EL2.A bit set, trapping unaligned accesses at EL2, but we're not really prepared to deal with it. So far, this has been unnoticed, until GCC 7 started emitting those (in particular 64bit writes on a 32bit boundary).
Since the rest of the kernel is pretty happy about that, let's follow its example and set SCTLR_EL2.A to zero. Modern CPUs don't really care.
--- arch/arm64/kvm/hyp-init.S | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm64/kvm/hyp-init.S +3 -2
@@ -108,9 +108,10 @@ __do_hyp_init: /* * Preserve all the RES1 bits while setting the default flags, - * as well as the EE bit on BE. + * as well as the EE bit on BE. Drop the A flag since the compiler + * is allowed to generate unaligned accesses. */ - ldr x4, =(SCTLR_EL2_RES1 | SCTLR_ELx_FLAGS) + ldr x4, =(SCTLR_EL2_RES1 | (SCTLR_ELx_FLAGS & ~SCTLR_ELx_A)) CPU_BE( orr x4, x4, #SCTLR_ELx_EE) msr sctlr_el2, x4 isb
Signature · 1 line
2.9.0
Paolo Bonzini
maintainerQuoted 20 lines · Christoffer Dall
Hi Radim and Paolo,
Six additional fixes for KVM/ARM for v4.12 (instead of only the first three in the first version of this pull request).
The changes are:
- Fix an issue with migrating GICv2 VMs on GICv3 systems.
- Squashed a bug for gicv3 when figuring out preemption levels.
- Fix a potential null pointer derefence in KVM happening under memory pressure.
- Maintain RES1 bits in theSCTLR_EL2to make sure KVM works on new architecture revisions.
- Allow unaligned accesses at EL2/HYPThe following changes since commit
fa472fa91a5a0b241f5ddae927d2e235d07545df:KVM: arm/arm64: Hold
slots_lockwhen unregistering kvm io bus devices (2017-05-18 11:18:16 +0200)are available in the git repository at:
Quoted 8 lines
git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.gitkvm-arm-for-v4.12-rc5-take2for you to fetch changes up to
33b5c38852b29736f3b472dd095c9a18ec22746f:arm: KVM: Allow unaligned accesses at HYP (2017-06-06 22:20:02 +0200)
Thanks,
-Christoffer
Pulled, thanks.
Paolo
Quoted 25 lines
---
Christoffer Dall (2):
KVM: arm/arm64: Fix isues with GICv2 on GICv3 migration
KVM: arm/arm64: vgic-v3: Fixnr_pre_bitsbitfield extractionMarc Zyngier (4):
KVM: arm/arm64: Handle possible NULL stage2 pud when ageing pages
arm64: KVM: Preserve RES1 bits inSCTLR_EL2
arm64: KVM: Allow unaligned accesses at EL2
arm: KVM: Allow unaligned accesses at HYParch/arm/kvm/init.S | 5 ++-- arch/arm64/include/asm/sysreg.h | 4 ++++ arch/arm64/kvm/hyp-init.S | 11 +++++---- arch/arm64/kvm/vgic-sys-reg-v3.c | 10 ++++---- include/linux/irqchip/arm-gic-v3.h | 4 ++++ include/linux/irqchip/arm-gic.h | 28 ++++++++++++++++++++--- virt/kvm/arm/hyp/vgic-v3-sr.c | 2 +- virt/kvm/arm/mmu.c | 3 +++ virt/kvm/arm/vgic/vgic-mmio-v2.c | 16 +++++++++++-- virt/kvm/arm/vgic/vgic-v2.c | 28 ++++++++++++++++++++--- virt/kvm/arm/vgic/vgic-v3.c | 47 ++++++++++++++++++++++++++------------ virt/kvm/arm/vgic/vgic.h | 12 ++++++---- 12 files changed, 131 insertions(+), 39 deletions(-)