* [PATCH 1/8] KVM: arm64: add workaround for Cortex-A57 erratum #852523
2015-09-17 14:46 [GIT PULL] Second set of KVM/ARM updates for 4.3-rc2 Marc Zyngier
@ 2015-09-17 14:46 ` Marc Zyngier
2015-09-17 14:46 ` [PATCH 2/8] arm64: KVM: Fix user access for debug registers Marc Zyngier
` (7 subsequent siblings)
8 siblings, 0 replies; 13+ messages in thread
From: Marc Zyngier @ 2015-09-17 14:46 UTC (permalink / raw)
To: linux-arm-kernel
From: Will Deacon <will.deacon@arm.com>
When restoring the system register state for an AArch32 guest at EL2,
writes to DACR32_EL2 may not be correctly synchronised by Cortex-A57,
which can lead to the guest effectively running with junk in the DACR
and running into unexpected domain faults.
This patch works around the issue by re-ordering our restoration of the
AArch32 register aliases so that they happen before the AArch64 system
registers. Ensuring that the registers are restored in this order
guarantees that they will be correctly synchronised by the core.
Cc: <stable@vger.kernel.org>
Reviewed-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
arch/arm64/kvm/hyp.S | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/kvm/hyp.S b/arch/arm64/kvm/hyp.S
index 8188f6a..39aa322 100644
--- a/arch/arm64/kvm/hyp.S
+++ b/arch/arm64/kvm/hyp.S
@@ -745,6 +745,9 @@ ENTRY(__kvm_vcpu_run)
// Guest context
add x2, x0, #VCPU_CONTEXT
+ // We must restore the 32-bit state before the sysregs, thanks
+ // to Cortex-A57 erratum #852523.
+ restore_guest_32bit_state
bl __restore_sysregs
skip_debug_state x3, 1f
@@ -752,7 +755,6 @@ ENTRY(__kvm_vcpu_run)
kern_hyp_va x3
bl __restore_debug
1:
- restore_guest_32bit_state
restore_guest_regs
// That's it, no more messing around.
--
2.1.4
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 2/8] arm64: KVM: Fix user access for debug registers
2015-09-17 14:46 [GIT PULL] Second set of KVM/ARM updates for 4.3-rc2 Marc Zyngier
2015-09-17 14:46 ` [PATCH 1/8] KVM: arm64: add workaround for Cortex-A57 erratum #852523 Marc Zyngier
@ 2015-09-17 14:46 ` Marc Zyngier
2015-09-17 14:46 ` [PATCH 3/8] arm: KVM: Fix incorrect device to IPA mapping Marc Zyngier
` (6 subsequent siblings)
8 siblings, 0 replies; 13+ messages in thread
From: Marc Zyngier @ 2015-09-17 14:46 UTC (permalink / raw)
To: linux-arm-kernel
When setting the debug register from userspace, make sure that
copy_from_user() is called with its parameters in the expected
order. It otherwise doesn't do what you think.
Fixes: 84e690bfbed1 ("KVM: arm64: introduce vcpu->arch.debug_ptr")
Reported-by: Peter Maydell <peter.maydell@linaro.org>
Cc: Alex Benn?e <alex.bennee@linaro.org>
Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
arch/arm64/kvm/sys_regs.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index b41607d..1d0463e 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -272,7 +272,7 @@ static int set_bvr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
{
__u64 *r = &vcpu->arch.vcpu_debug_state.dbg_bvr[rd->reg];
- if (copy_from_user(uaddr, r, KVM_REG_SIZE(reg->id)) != 0)
+ if (copy_from_user(r, uaddr, KVM_REG_SIZE(reg->id)) != 0)
return -EFAULT;
return 0;
}
@@ -314,7 +314,7 @@ static int set_bcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
{
__u64 *r = &vcpu->arch.vcpu_debug_state.dbg_bcr[rd->reg];
- if (copy_from_user(uaddr, r, KVM_REG_SIZE(reg->id)) != 0)
+ if (copy_from_user(r, uaddr, KVM_REG_SIZE(reg->id)) != 0)
return -EFAULT;
return 0;
@@ -358,7 +358,7 @@ static int set_wvr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
{
__u64 *r = &vcpu->arch.vcpu_debug_state.dbg_wvr[rd->reg];
- if (copy_from_user(uaddr, r, KVM_REG_SIZE(reg->id)) != 0)
+ if (copy_from_user(r, uaddr, KVM_REG_SIZE(reg->id)) != 0)
return -EFAULT;
return 0;
}
@@ -400,7 +400,7 @@ static int set_wcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
{
__u64 *r = &vcpu->arch.vcpu_debug_state.dbg_wcr[rd->reg];
- if (copy_from_user(uaddr, r, KVM_REG_SIZE(reg->id)) != 0)
+ if (copy_from_user(r, uaddr, KVM_REG_SIZE(reg->id)) != 0)
return -EFAULT;
return 0;
}
--
2.1.4
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 3/8] arm: KVM: Fix incorrect device to IPA mapping
2015-09-17 14:46 [GIT PULL] Second set of KVM/ARM updates for 4.3-rc2 Marc Zyngier
2015-09-17 14:46 ` [PATCH 1/8] KVM: arm64: add workaround for Cortex-A57 erratum #852523 Marc Zyngier
2015-09-17 14:46 ` [PATCH 2/8] arm64: KVM: Fix user access for debug registers Marc Zyngier
@ 2015-09-17 14:46 ` Marc Zyngier
2015-09-17 14:46 ` [PATCH 4/8] arm/arm64: KVM: vgic: Check for !irqchip_in_kernel() when mapping resources Marc Zyngier
` (5 subsequent siblings)
8 siblings, 0 replies; 13+ messages in thread
From: Marc Zyngier @ 2015-09-17 14:46 UTC (permalink / raw)
To: linux-arm-kernel
From: Marek Majtyka <marek.majtyka@tieto.com>
A critical bug has been found in device memory stage1 translation for
VMs with more then 4GB of address space. Once vm_pgoff size is smaller
then pa (which is true for LPAE case, u32 and u64 respectively) some
more significant bits of pa may be lost as a shift operation is performed
on u32 and later cast onto u64.
Example: vm_pgoff(u32)=0x00210030, PAGE_SHIFT=12
expected pa(u64): 0x0000002010030000
produced pa(u64): 0x0000000010030000
The fix is to change the order of operations (casting first onto phys_addr_t
and then shifting).
Reviewed-by: Marc Zyngier <marc.zyngier@arm.com>
[maz: fixed changelog and patch formatting]
Cc: stable at vger.kernel.org
Signed-off-by: Marek Majtyka <marek.majtyka@tieto.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
arch/arm/kvm/mmu.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c
index 7b42012..6984342 100644
--- a/arch/arm/kvm/mmu.c
+++ b/arch/arm/kvm/mmu.c
@@ -1792,8 +1792,10 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
if (vma->vm_flags & VM_PFNMAP) {
gpa_t gpa = mem->guest_phys_addr +
(vm_start - mem->userspace_addr);
- phys_addr_t pa = (vma->vm_pgoff << PAGE_SHIFT) +
- vm_start - vma->vm_start;
+ phys_addr_t pa;
+
+ pa = (phys_addr_t)vma->vm_pgoff << PAGE_SHIFT;
+ pa += vm_start - vma->vm_start;
/* IO region dirty page logging not allowed */
if (memslot->flags & KVM_MEM_LOG_DIRTY_PAGES)
--
2.1.4
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 4/8] arm/arm64: KVM: vgic: Check for !irqchip_in_kernel() when mapping resources
2015-09-17 14:46 [GIT PULL] Second set of KVM/ARM updates for 4.3-rc2 Marc Zyngier
` (2 preceding siblings ...)
2015-09-17 14:46 ` [PATCH 3/8] arm: KVM: Fix incorrect device to IPA mapping Marc Zyngier
@ 2015-09-17 14:46 ` Marc Zyngier
2015-09-17 14:46 ` [PATCH 5/8] arm64: KVM: Disable virtual timer even if the guest is not using it Marc Zyngier
` (4 subsequent siblings)
8 siblings, 0 replies; 13+ messages in thread
From: Marc Zyngier @ 2015-09-17 14:46 UTC (permalink / raw)
To: linux-arm-kernel
From: Pavel Fedin <p.fedin@samsung.com>
Until b26e5fdac43c ("arm/arm64: KVM: introduce per-VM ops"),
kvm_vgic_map_resources() used to include a check on irqchip_in_kernel(),
and vgic_v2_map_resources() still has it.
But now vm_ops are not initialized until we call kvm_vgic_create().
Therefore kvm_vgic_map_resources() can being called without a VGIC,
and we die because vm_ops.map_resources is NULL.
Fixing this restores QEMU's kernel-irqchip=off option to a working state,
allowing to use GIC emulation in userspace.
Fixes: b26e5fdac43c ("arm/arm64: KVM: introduce per-VM ops")
Cc: stable at vger.kernel.org
Signed-off-by: Pavel Fedin <p.fedin@samsung.com>
[maz: reworked commit message]
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
arch/arm/kvm/arm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index ce404a5..dc017ad 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -446,7 +446,7 @@ static int kvm_vcpu_first_run_init(struct kvm_vcpu *vcpu)
* Map the VGIC hardware resources before running a vcpu the first
* time on this VM.
*/
- if (unlikely(!vgic_ready(kvm))) {
+ if (unlikely(irqchip_in_kernel(kvm) && !vgic_ready(kvm))) {
ret = kvm_vgic_map_resources(kvm);
if (ret)
return ret;
--
2.1.4
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 5/8] arm64: KVM: Disable virtual timer even if the guest is not using it
2015-09-17 14:46 [GIT PULL] Second set of KVM/ARM updates for 4.3-rc2 Marc Zyngier
` (3 preceding siblings ...)
2015-09-17 14:46 ` [PATCH 4/8] arm/arm64: KVM: vgic: Check for !irqchip_in_kernel() when mapping resources Marc Zyngier
@ 2015-09-17 14:46 ` Marc Zyngier
2015-09-17 15:02 ` Paolo Bonzini
2015-09-17 14:46 ` [PATCH 6/8] arm: " Marc Zyngier
` (3 subsequent siblings)
8 siblings, 1 reply; 13+ messages in thread
From: Marc Zyngier @ 2015-09-17 14:46 UTC (permalink / raw)
To: linux-arm-kernel
When running a guest with the architected timer disabled (with QEMU and
the kernel_irqchip=off option, for example), it is important to make
sure the timer gets turned off. Otherwise, the guest may try to
enable it anyway, leading to a screaming HW interrupt.
The fix is to unconditionally turn off the virtual timer on guest
exit.
Cc: stable at vger.kernel.org
Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
arch/arm64/kvm/hyp.S | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/kvm/hyp.S b/arch/arm64/kvm/hyp.S
index 39aa322..60a83e2 100644
--- a/arch/arm64/kvm/hyp.S
+++ b/arch/arm64/kvm/hyp.S
@@ -562,8 +562,6 @@
mrs x3, cntv_ctl_el0
and x3, x3, #3
str w3, [x0, #VCPU_TIMER_CNTV_CTL]
- bic x3, x3, #1 // Clear Enable
- msr cntv_ctl_el0, x3
isb
@@ -571,6 +569,9 @@
str x3, [x0, #VCPU_TIMER_CNTV_CVAL]
1:
+ // Disable the virtual timer
+ msr cntv_ctl_el0, xzr
+
// Allow physical timer/counter access for the host
mrs x2, cnthctl_el2
orr x2, x2, #3
--
2.1.4
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 5/8] arm64: KVM: Disable virtual timer even if the guest is not using it
2015-09-17 14:46 ` [PATCH 5/8] arm64: KVM: Disable virtual timer even if the guest is not using it Marc Zyngier
@ 2015-09-17 15:02 ` Paolo Bonzini
2015-09-17 15:28 ` Marc Zyngier
0 siblings, 1 reply; 13+ messages in thread
From: Paolo Bonzini @ 2015-09-17 15:02 UTC (permalink / raw)
To: linux-arm-kernel
On 17/09/2015 16:46, Marc Zyngier wrote:
> When running a guest with the architected timer disabled (with QEMU and
> the kernel_irqchip=off option, for example), it is important to make
> sure the timer gets turned off. Otherwise, the guest may try to
> enable it anyway, leading to a screaming HW interrupt.
>
> The fix is to unconditionally turn off the virtual timer on guest
> exit.
>
> Cc: stable at vger.kernel.org
> Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org>
> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
> ---
> arch/arm64/kvm/hyp.S | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm64/kvm/hyp.S b/arch/arm64/kvm/hyp.S
> index 39aa322..60a83e2 100644
> --- a/arch/arm64/kvm/hyp.S
> +++ b/arch/arm64/kvm/hyp.S
> @@ -562,8 +562,6 @@
> mrs x3, cntv_ctl_el0
> and x3, x3, #3
> str w3, [x0, #VCPU_TIMER_CNTV_CTL]
> - bic x3, x3, #1 // Clear Enable
> - msr cntv_ctl_el0, x3
>
> isb
>
> @@ -571,6 +569,9 @@
> str x3, [x0, #VCPU_TIMER_CNTV_CVAL]
>
> 1:
> + // Disable the virtual timer
> + msr cntv_ctl_el0, xzr
> +
> // Allow physical timer/counter access for the host
> mrs x2, cnthctl_el2
> orr x2, x2, #3
>
It looks like here in restore_timer_state:
ldr w2, [x0, #VCPU_TIMER_CNTV_CTL]
and x2, x2, #3
msr cntv_ctl_el0, x2
the "and" would be unnecessary if kvm_arm_timer_set_reg remembered to
do it. Something like this, which would also make the code more
consistent between arm and arm64...
diff --git a/arch/arm/kvm/interrupts_head.S b/arch/arm/kvm/interrupts_head.S
index 702740d37465..93e322b4d242 100644
--- a/arch/arm/kvm/interrupts_head.S
+++ b/arch/arm/kvm/interrupts_head.S
@@ -514,6 +514,7 @@ ARM_BE8(rev r6, r6 )
beq 1f
mrc p15, 0, r2, c14, c3, 1 @ CNTV_CTL
+ and r2, r2, #3
str r2, [vcpu, #VCPU_TIMER_CNTV_CTL]
bic r2, #1 @ Clear ENABLE
mcr p15, 0, r2, c14, c3, 1 @ CNTV_CTL
@@ -566,7 +567,6 @@ ARM_BE8(rev r6, r6 )
isb
ldr r2, [vcpu, #VCPU_TIMER_CNTV_CTL]
- and r2, r2, #3
mcr p15, 0, r2, c14, c3, 1 @ CNTV_CTL
1:
.endm
diff --git a/arch/arm64/kvm/hyp.S b/arch/arm64/kvm/hyp.S
index 10915aaf0b01..bfcd3f3a947b 100644
--- a/arch/arm64/kvm/hyp.S
+++ b/arch/arm64/kvm/hyp.S
@@ -887,7 +887,6 @@ alternative_endif
isb
ldr w2, [x0, #VCPU_TIMER_CNTV_CTL]
- and x2, x2, #3
msr cntv_ctl_el0, x2
1:
.endm
diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c
index 98c95f2fcba4..9b03c9f5abbf 100644
--- a/virt/kvm/arm/arch_timer.c
+++ b/virt/kvm/arm/arch_timer.c
@@ -218,7 +218,7 @@ int kvm_arm_timer_set_reg(struct kvm_vcpu *vcpu, u64 regid, u64 value)
switch (regid) {
case KVM_REG_ARM_TIMER_CTL:
- timer->cntv_ctl = value;
+ timer->cntv_ctl = value & (ARCH_TIMER_CTRL_IT_MASK | ARCH_TIMER_CTRL_ENABLE);
break;
case KVM_REG_ARM_TIMER_CNT:
vcpu->kvm->arch.timer.cntvoff = kvm_phys_timer_read() - value;
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 5/8] arm64: KVM: Disable virtual timer even if the guest is not using it
2015-09-17 15:02 ` Paolo Bonzini
@ 2015-09-17 15:28 ` Marc Zyngier
2015-09-17 15:31 ` Paolo Bonzini
0 siblings, 1 reply; 13+ messages in thread
From: Marc Zyngier @ 2015-09-17 15:28 UTC (permalink / raw)
To: linux-arm-kernel
On 17/09/15 16:02, Paolo Bonzini wrote:
>
>
> On 17/09/2015 16:46, Marc Zyngier wrote:
>> When running a guest with the architected timer disabled (with QEMU and
>> the kernel_irqchip=off option, for example), it is important to make
>> sure the timer gets turned off. Otherwise, the guest may try to
>> enable it anyway, leading to a screaming HW interrupt.
>>
>> The fix is to unconditionally turn off the virtual timer on guest
>> exit.
>>
>> Cc: stable at vger.kernel.org
>> Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org>
>> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
>> ---
>> arch/arm64/kvm/hyp.S | 5 +++--
>> 1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/arm64/kvm/hyp.S b/arch/arm64/kvm/hyp.S
>> index 39aa322..60a83e2 100644
>> --- a/arch/arm64/kvm/hyp.S
>> +++ b/arch/arm64/kvm/hyp.S
>> @@ -562,8 +562,6 @@
>> mrs x3, cntv_ctl_el0
>> and x3, x3, #3
>> str w3, [x0, #VCPU_TIMER_CNTV_CTL]
>> - bic x3, x3, #1 // Clear Enable
>> - msr cntv_ctl_el0, x3
>>
>> isb
>>
>> @@ -571,6 +569,9 @@
>> str x3, [x0, #VCPU_TIMER_CNTV_CVAL]
>>
>> 1:
>> + // Disable the virtual timer
>> + msr cntv_ctl_el0, xzr
>> +
>> // Allow physical timer/counter access for the host
>> mrs x2, cnthctl_el2
>> orr x2, x2, #3
>>
>
> It looks like here in restore_timer_state:
>
> ldr w2, [x0, #VCPU_TIMER_CNTV_CTL]
> and x2, x2, #3
> msr cntv_ctl_el0, x2
>
> the "and" would be unnecessary if kvm_arm_timer_set_reg remembered to
> do it. Something like this, which would also make the code more
> consistent between arm and arm64...
>
> diff --git a/arch/arm/kvm/interrupts_head.S b/arch/arm/kvm/interrupts_head.S
> index 702740d37465..93e322b4d242 100644
> --- a/arch/arm/kvm/interrupts_head.S
> +++ b/arch/arm/kvm/interrupts_head.S
> @@ -514,6 +514,7 @@ ARM_BE8(rev r6, r6 )
> beq 1f
>
> mrc p15, 0, r2, c14, c3, 1 @ CNTV_CTL
> + and r2, r2, #3
I don't think we need this. Exposing the ISTATUS bit to the kernel (or
even userspace) is not really a problem (that's actually an interesting
piece of information), and restoring it is not possible since it is
read-only.
We should drop the equivalent 'and' from the arm64 version.
> str r2, [vcpu, #VCPU_TIMER_CNTV_CTL]
> bic r2, #1 @ Clear ENABLE
> mcr p15, 0, r2, c14, c3, 1 @ CNTV_CTL
> @@ -566,7 +567,6 @@ ARM_BE8(rev r6, r6 )
> isb
>
> ldr r2, [vcpu, #VCPU_TIMER_CNTV_CTL]
> - and r2, r2, #3
> mcr p15, 0, r2, c14, c3, 1 @ CNTV_CTL
> 1:
> .endm
> diff --git a/arch/arm64/kvm/hyp.S b/arch/arm64/kvm/hyp.S
> index 10915aaf0b01..bfcd3f3a947b 100644
> --- a/arch/arm64/kvm/hyp.S
> +++ b/arch/arm64/kvm/hyp.S
> @@ -887,7 +887,6 @@ alternative_endif
> isb
>
> ldr w2, [x0, #VCPU_TIMER_CNTV_CTL]
> - and x2, x2, #3
> msr cntv_ctl_el0, x2
> 1:
> .endm
> diff --git a/virt/kvm/arm/arch_timer.c b/virt/kvm/arm/arch_timer.c
> index 98c95f2fcba4..9b03c9f5abbf 100644
> --- a/virt/kvm/arm/arch_timer.c
> +++ b/virt/kvm/arm/arch_timer.c
> @@ -218,7 +218,7 @@ int kvm_arm_timer_set_reg(struct kvm_vcpu *vcpu, u64 regid, u64 value)
>
> switch (regid) {
> case KVM_REG_ARM_TIMER_CTL:
> - timer->cntv_ctl = value;
> + timer->cntv_ctl = value & (ARCH_TIMER_CTRL_IT_MASK | ARCH_TIMER_CTRL_ENABLE);
> break;
> case KVM_REG_ARM_TIMER_CNT:
> vcpu->kvm->arch.timer.cntvoff = kvm_phys_timer_read() - value;
>
Otherwise looks pretty good. Can you send an updated patch?
Thanks,
M.
--
Jazz is not dead. It just smells funny...
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 5/8] arm64: KVM: Disable virtual timer even if the guest is not using it
2015-09-17 15:28 ` Marc Zyngier
@ 2015-09-17 15:31 ` Paolo Bonzini
0 siblings, 0 replies; 13+ messages in thread
From: Paolo Bonzini @ 2015-09-17 15:31 UTC (permalink / raw)
To: linux-arm-kernel
On 17/09/2015 17:28, Marc Zyngier wrote:
> > diff --git a/arch/arm/kvm/interrupts_head.S b/arch/arm/kvm/interrupts_head.S
> > index 702740d37465..93e322b4d242 100644
> > --- a/arch/arm/kvm/interrupts_head.S
> > +++ b/arch/arm/kvm/interrupts_head.S
> > @@ -514,6 +514,7 @@ ARM_BE8(rev r6, r6 )
> > beq 1f
> >
> > mrc p15, 0, r2, c14, c3, 1 @ CNTV_CTL
> > + and r2, r2, #3
>
> I don't think we need this. Exposing the ISTATUS bit to the kernel (or
> even userspace) is not really a problem (that's actually an interesting
> piece of information), and restoring it is not possible since it is
> read-only.
>
> We should drop the equivalent 'and' from the arm64 version.
Ok. I'll resend the thing as a proper patch.
Paolo
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH 6/8] arm: KVM: Disable virtual timer even if the guest is not using it
2015-09-17 14:46 [GIT PULL] Second set of KVM/ARM updates for 4.3-rc2 Marc Zyngier
` (4 preceding siblings ...)
2015-09-17 14:46 ` [PATCH 5/8] arm64: KVM: Disable virtual timer even if the guest is not using it Marc Zyngier
@ 2015-09-17 14:46 ` Marc Zyngier
2015-09-17 14:46 ` [PATCH 7/8] arm64: KVM: Remove all traces of the ThumbEE registers Marc Zyngier
` (2 subsequent siblings)
8 siblings, 0 replies; 13+ messages in thread
From: Marc Zyngier @ 2015-09-17 14:46 UTC (permalink / raw)
To: linux-arm-kernel
When running a guest with the architected timer disabled (with QEMU and
the kernel_irqchip=off option, for example), it is important to make
sure the timer gets turned off. Otherwise, the guest may try to
enable it anyway, leading to a screaming HW interrupt.
The fix is to unconditionally turn off the virtual timer on guest
exit.
Cc: stable at vger.kernel.org
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
arch/arm/kvm/interrupts_head.S | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/arch/arm/kvm/interrupts_head.S b/arch/arm/kvm/interrupts_head.S
index 702740d..51a5950 100644
--- a/arch/arm/kvm/interrupts_head.S
+++ b/arch/arm/kvm/interrupts_head.S
@@ -515,8 +515,7 @@ ARM_BE8(rev r6, r6 )
mrc p15, 0, r2, c14, c3, 1 @ CNTV_CTL
str r2, [vcpu, #VCPU_TIMER_CNTV_CTL]
- bic r2, #1 @ Clear ENABLE
- mcr p15, 0, r2, c14, c3, 1 @ CNTV_CTL
+
isb
mrrc p15, 3, rr_lo_hi(r2, r3), c14 @ CNTV_CVAL
@@ -529,6 +528,9 @@ ARM_BE8(rev r6, r6 )
mcrr p15, 4, r2, r2, c14 @ CNTVOFF
1:
+ mov r2, #0 @ Clear ENABLE
+ mcr p15, 0, r2, c14, c3, 1 @ CNTV_CTL
+
@ Allow physical timer/counter access for the host
mrc p15, 4, r2, c14, c1, 0 @ CNTHCTL
orr r2, r2, #(CNTHCTL_PL1PCEN | CNTHCTL_PL1PCTEN)
--
2.1.4
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 7/8] arm64: KVM: Remove all traces of the ThumbEE registers
2015-09-17 14:46 [GIT PULL] Second set of KVM/ARM updates for 4.3-rc2 Marc Zyngier
` (5 preceding siblings ...)
2015-09-17 14:46 ` [PATCH 6/8] arm: " Marc Zyngier
@ 2015-09-17 14:46 ` Marc Zyngier
2015-09-17 14:46 ` [PATCH 8/8] arm/arm64: KVM: Remove 'config KVM_ARM_MAX_VCPUS' Marc Zyngier
2015-09-17 14:53 ` [GIT PULL] Second set of KVM/ARM updates for 4.3-rc2 Paolo Bonzini
8 siblings, 0 replies; 13+ messages in thread
From: Marc Zyngier @ 2015-09-17 14:46 UTC (permalink / raw)
To: linux-arm-kernel
From: Will Deacon <will.deacon@arm.com>
Although the ThumbEE registers and traps were present in earlier
versions of the v8 architecture, it was retrospectively removed and so
we can do the same.
Whilst this breaks migrating a guest started on a previous version of
the kernel, it is much better to kill these (non existent) registers
as soon as possible.
Reviewed-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
[maz: added commend about migration]
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
arch/arm64/include/asm/kvm_arm.h | 1 -
arch/arm64/include/asm/kvm_asm.h | 4 +---
arch/arm64/kvm/hyp.S | 22 ++++------------------
arch/arm64/kvm/sys_regs.c | 7 -------
4 files changed, 5 insertions(+), 29 deletions(-)
diff --git a/arch/arm64/include/asm/kvm_arm.h b/arch/arm64/include/asm/kvm_arm.h
index cbc5e1a..9694f26 100644
--- a/arch/arm64/include/asm/kvm_arm.h
+++ b/arch/arm64/include/asm/kvm_arm.h
@@ -172,7 +172,6 @@
#define VTTBR_VMID_MASK (UL(0xFF) << VTTBR_VMID_SHIFT)
/* Hyp System Trap Register */
-#define HSTR_EL2_TTEE (1 << 16)
#define HSTR_EL2_T(x) (1 << x)
/* Hyp Coproccessor Trap Register Shifts */
diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h
index 67fa0de..5e37710 100644
--- a/arch/arm64/include/asm/kvm_asm.h
+++ b/arch/arm64/include/asm/kvm_asm.h
@@ -53,9 +53,7 @@
#define IFSR32_EL2 25 /* Instruction Fault Status Register */
#define FPEXC32_EL2 26 /* Floating-Point Exception Control Register */
#define DBGVCR32_EL2 27 /* Debug Vector Catch Register */
-#define TEECR32_EL1 28 /* ThumbEE Configuration Register */
-#define TEEHBR32_EL1 29 /* ThumbEE Handler Base Register */
-#define NR_SYS_REGS 30
+#define NR_SYS_REGS 28
/* 32bit mapping */
#define c0_MPIDR (MPIDR_EL1 * 2) /* MultiProcessor ID Register */
diff --git a/arch/arm64/kvm/hyp.S b/arch/arm64/kvm/hyp.S
index 60a83e2..8563477 100644
--- a/arch/arm64/kvm/hyp.S
+++ b/arch/arm64/kvm/hyp.S
@@ -433,20 +433,13 @@
mrs x5, ifsr32_el2
stp x4, x5, [x3]
- skip_fpsimd_state x8, 3f
+ skip_fpsimd_state x8, 2f
mrs x6, fpexc32_el2
str x6, [x3, #16]
-3:
- skip_debug_state x8, 2f
+2:
+ skip_debug_state x8, 1f
mrs x7, dbgvcr32_el2
str x7, [x3, #24]
-2:
- skip_tee_state x8, 1f
-
- add x3, x2, #CPU_SYSREG_OFFSET(TEECR32_EL1)
- mrs x4, teecr32_el1
- mrs x5, teehbr32_el1
- stp x4, x5, [x3]
1:
.endm
@@ -466,16 +459,9 @@
msr dacr32_el2, x4
msr ifsr32_el2, x5
- skip_debug_state x8, 2f
+ skip_debug_state x8, 1f
ldr x7, [x3, #24]
msr dbgvcr32_el2, x7
-2:
- skip_tee_state x8, 1f
-
- add x3, x2, #CPU_SYSREG_OFFSET(TEECR32_EL1)
- ldp x4, x5, [x3]
- msr teecr32_el1, x4
- msr teehbr32_el1, x5
1:
.endm
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 1d0463e..d03d3af 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -539,13 +539,6 @@ static const struct sys_reg_desc sys_reg_descs[] = {
{ Op0(0b10), Op1(0b000), CRn(0b0111), CRm(0b1110), Op2(0b110),
trap_dbgauthstatus_el1 },
- /* TEECR32_EL1 */
- { Op0(0b10), Op1(0b010), CRn(0b0000), CRm(0b0000), Op2(0b000),
- NULL, reset_val, TEECR32_EL1, 0 },
- /* TEEHBR32_EL1 */
- { Op0(0b10), Op1(0b010), CRn(0b0001), CRm(0b0000), Op2(0b000),
- NULL, reset_val, TEEHBR32_EL1, 0 },
-
/* MDCCSR_EL1 */
{ Op0(0b10), Op1(0b011), CRn(0b0000), CRm(0b0001), Op2(0b000),
trap_raz_wi },
--
2.1.4
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH 8/8] arm/arm64: KVM: Remove 'config KVM_ARM_MAX_VCPUS'
2015-09-17 14:46 [GIT PULL] Second set of KVM/ARM updates for 4.3-rc2 Marc Zyngier
` (6 preceding siblings ...)
2015-09-17 14:46 ` [PATCH 7/8] arm64: KVM: Remove all traces of the ThumbEE registers Marc Zyngier
@ 2015-09-17 14:46 ` Marc Zyngier
2015-09-17 14:53 ` [GIT PULL] Second set of KVM/ARM updates for 4.3-rc2 Paolo Bonzini
8 siblings, 0 replies; 13+ messages in thread
From: Marc Zyngier @ 2015-09-17 14:46 UTC (permalink / raw)
To: linux-arm-kernel
From: Ming Lei <ming.lei@canonical.com>
This patch removes config option of KVM_ARM_MAX_VCPUS,
and like other ARCHs, just choose the maximum allowed
value from hardware, and follows the reasons:
1) from distribution view, the option has to be
defined as the max allowed value because it need to
meet all kinds of virtulization applications and
need to support most of SoCs;
2) using a bigger value doesn't introduce extra memory
consumption, and the help text in Kconfig isn't accurate
because kvm_vpu structure isn't allocated until request
of creating VCPU is sent from QEMU;
3) the main effect is that the field of vcpus[] in 'struct kvm'
becomes a bit bigger(sizeof(void *) per vcpu) and need more cache
lines to hold the structure, but 'struct kvm' is one generic struct,
and it has worked well on other ARCHs already in this way. Also,
the world switch frequecy is often low, for example, it is ~2000
when running kernel building load in VM from APM xgene KVM host,
so the effect is very small, and the difference can't be observed
in my test at all.
Cc: Dann Frazier <dann.frazier@canonical.com>
Signed-off-by: Ming Lei <ming.lei@canonical.com>
Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
arch/arm/include/asm/kvm_host.h | 8 ++------
arch/arm/kvm/Kconfig | 11 -----------
arch/arm64/include/asm/kvm_host.h | 8 ++------
arch/arm64/kvm/Kconfig | 11 -----------
include/kvm/arm_vgic.h | 6 +-----
virt/kvm/arm/vgic-v3.c | 2 +-
6 files changed, 6 insertions(+), 40 deletions(-)
diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h
index dcba0fa..c8c226a 100644
--- a/arch/arm/include/asm/kvm_host.h
+++ b/arch/arm/include/asm/kvm_host.h
@@ -29,12 +29,6 @@
#define __KVM_HAVE_ARCH_INTC_INITIALIZED
-#if defined(CONFIG_KVM_ARM_MAX_VCPUS)
-#define KVM_MAX_VCPUS CONFIG_KVM_ARM_MAX_VCPUS
-#else
-#define KVM_MAX_VCPUS 0
-#endif
-
#define KVM_USER_MEM_SLOTS 32
#define KVM_PRIVATE_MEM_SLOTS 4
#define KVM_COALESCED_MMIO_PAGE_OFFSET 1
@@ -44,6 +38,8 @@
#include <kvm/arm_vgic.h>
+#define KVM_MAX_VCPUS VGIC_V2_MAX_CPUS
+
u32 *kvm_vcpu_reg(struct kvm_vcpu *vcpu, u8 reg_num, u32 mode);
int __attribute_const__ kvm_target_cpu(void);
int kvm_reset_vcpu(struct kvm_vcpu *vcpu);
diff --git a/arch/arm/kvm/Kconfig b/arch/arm/kvm/Kconfig
index bfb915d..210ecca 100644
--- a/arch/arm/kvm/Kconfig
+++ b/arch/arm/kvm/Kconfig
@@ -45,15 +45,4 @@ config KVM_ARM_HOST
---help---
Provides host support for ARM processors.
-config KVM_ARM_MAX_VCPUS
- int "Number maximum supported virtual CPUs per VM"
- depends on KVM_ARM_HOST
- default 4
- help
- Static number of max supported virtual CPUs per VM.
-
- If you choose a high number, the vcpu structures will be quite
- large, so only choose a reasonable number that you expect to
- actually use.
-
endif # VIRTUALIZATION
diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index 415938d..3fb58ea 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -30,12 +30,6 @@
#define __KVM_HAVE_ARCH_INTC_INITIALIZED
-#if defined(CONFIG_KVM_ARM_MAX_VCPUS)
-#define KVM_MAX_VCPUS CONFIG_KVM_ARM_MAX_VCPUS
-#else
-#define KVM_MAX_VCPUS 0
-#endif
-
#define KVM_USER_MEM_SLOTS 32
#define KVM_PRIVATE_MEM_SLOTS 4
#define KVM_COALESCED_MMIO_PAGE_OFFSET 1
@@ -43,6 +37,8 @@
#include <kvm/arm_vgic.h>
#include <kvm/arm_arch_timer.h>
+#define KVM_MAX_VCPUS VGIC_V3_MAX_CPUS
+
#define KVM_VCPU_MAX_FEATURES 3
int __attribute_const__ kvm_target_cpu(void);
diff --git a/arch/arm64/kvm/Kconfig b/arch/arm64/kvm/Kconfig
index bfffe8f..5c7e920 100644
--- a/arch/arm64/kvm/Kconfig
+++ b/arch/arm64/kvm/Kconfig
@@ -41,15 +41,4 @@ config KVM_ARM_HOST
---help---
Provides host support for ARM processors.
-config KVM_ARM_MAX_VCPUS
- int "Number maximum supported virtual CPUs per VM"
- depends on KVM_ARM_HOST
- default 4
- help
- Static number of max supported virtual CPUs per VM.
-
- If you choose a high number, the vcpu structures will be quite
- large, so only choose a reasonable number that you expect to
- actually use.
-
endif # VIRTUALIZATION
diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h
index d901f1a..4e14dac 100644
--- a/include/kvm/arm_vgic.h
+++ b/include/kvm/arm_vgic.h
@@ -35,11 +35,7 @@
#define VGIC_V3_MAX_LRS 16
#define VGIC_MAX_IRQS 1024
#define VGIC_V2_MAX_CPUS 8
-
-/* Sanity checks... */
-#if (KVM_MAX_VCPUS > 255)
-#error Too many KVM VCPUs, the VGIC only supports up to 255 VCPUs for now
-#endif
+#define VGIC_V3_MAX_CPUS 255
#if (VGIC_NR_IRQS_LEGACY & 31)
#error "VGIC_NR_IRQS must be a multiple of 32"
diff --git a/virt/kvm/arm/vgic-v3.c b/virt/kvm/arm/vgic-v3.c
index afbf925..7dd5d62 100644
--- a/virt/kvm/arm/vgic-v3.c
+++ b/virt/kvm/arm/vgic-v3.c
@@ -288,7 +288,7 @@ int vgic_v3_probe(struct device_node *vgic_node,
vgic->vctrl_base = NULL;
vgic->type = VGIC_V3;
- vgic->max_gic_vcpus = KVM_MAX_VCPUS;
+ vgic->max_gic_vcpus = VGIC_V3_MAX_CPUS;
kvm_info("%s@%llx IRQ%d\n", vgic_node->name,
vcpu_res.start, vgic->maint_irq);
--
2.1.4
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [GIT PULL] Second set of KVM/ARM updates for 4.3-rc2
2015-09-17 14:46 [GIT PULL] Second set of KVM/ARM updates for 4.3-rc2 Marc Zyngier
` (7 preceding siblings ...)
2015-09-17 14:46 ` [PATCH 8/8] arm/arm64: KVM: Remove 'config KVM_ARM_MAX_VCPUS' Marc Zyngier
@ 2015-09-17 14:53 ` Paolo Bonzini
8 siblings, 0 replies; 13+ messages in thread
From: Paolo Bonzini @ 2015-09-17 14:53 UTC (permalink / raw)
To: linux-arm-kernel
On 17/09/2015 16:46, Marc Zyngier wrote:
> Hi Paolo,
>
> We've had a "nice" collection of fixes trickling in this week, and
> since both Christoffer and I are away next week, I've decided to send
> everything your way a bit early.
Sure, thanks.
I'll send the pull request to Linus tomorrow.
Paolo
Fairly random stuff to be honnest,
> but a negative diffstat can't be that bad! :-)
>
> Thanks,
>
> M.
>
> The following changes since commit 0c0672922dcc70ffba11d96385e98e42fb3ae08d:
>
> arm/arm64: KVM: Fix PSCI affinity info return value for non valid cores (2015-09-04 17:02:48 +0100)
>
> are available in the git repository at:
>
> git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git tags/kvm-arm-for-4.3-rc2-2
>
> for you to fetch changes up to ef748917b529847277f07c98c55e1c0ce416449f:
>
> arm/arm64: KVM: Remove 'config KVM_ARM_MAX_VCPUS' (2015-09-17 13:13:27 +0100)
>
> ----------------------------------------------------------------
> Second set of KVM/ARM changes for 4.3-rc2
>
> - Workaround for a Cortex-A57 erratum
> - Bug fix for the debugging infrastructure
> - Fix for 32bit guests with more than 4GB of address space
> on a 32bit host
> - A number of fixes for the (unusual) case when we don't use
> the in-kernel GIC emulation
> - Removal of ThumbEE handling on arm64, since these have been
> dropped from the architecture before anyone actually ever
> built a CPU
> - Remove the KVM_ARM_MAX_VCPUS limitation which has become
> fairly pointless
>
> ----------------------------------------------------------------
> Marc Zyngier (3):
> arm64: KVM: Fix user access for debug registers
> arm64: KVM: Disable virtual timer even if the guest is not using it
> arm: KVM: Disable virtual timer even if the guest is not using it
>
> Marek Majtyka (1):
> arm: KVM: Fix incorrect device to IPA mapping
>
> Ming Lei (1):
> arm/arm64: KVM: Remove 'config KVM_ARM_MAX_VCPUS'
>
> Pavel Fedin (1):
> arm/arm64: KVM: vgic: Check for !irqchip_in_kernel() when mapping resources
>
> Will Deacon (2):
> KVM: arm64: add workaround for Cortex-A57 erratum #852523
> arm64: KVM: Remove all traces of the ThumbEE registers
>
> arch/arm/include/asm/kvm_host.h | 8 ++------
> arch/arm/kvm/Kconfig | 11 -----------
> arch/arm/kvm/arm.c | 2 +-
> arch/arm/kvm/interrupts_head.S | 6 ++++--
> arch/arm/kvm/mmu.c | 6 ++++--
> arch/arm64/include/asm/kvm_arm.h | 1 -
> arch/arm64/include/asm/kvm_asm.h | 4 +---
> arch/arm64/include/asm/kvm_host.h | 8 ++------
> arch/arm64/kvm/Kconfig | 11 -----------
> arch/arm64/kvm/hyp.S | 31 ++++++++++---------------------
> arch/arm64/kvm/sys_regs.c | 15 ++++-----------
> include/kvm/arm_vgic.h | 6 +-----
> virt/kvm/arm/vgic-v3.c | 2 +-
> 13 files changed, 30 insertions(+), 81 deletions(-)
>
^ permalink raw reply [flat|nested] 13+ messages in thread