* [PATCH 1/3] arm/arm64: KVM: vgic: Check for !irqchip_in_kernel() when mapping resources
2015-09-16 15:58 [PATCH 0/3] arm/arm64: KVM: Fix !irqchip_in_kernel() handling Marc Zyngier
@ 2015-09-16 15:58 ` Marc Zyngier
2015-09-24 11:33 ` Pavel Fedin
2015-09-16 15:58 ` [PATCH 2/3] arm64: KVM: Disable virtual timer even if the guest is not using it Marc Zyngier
2015-09-16 15:58 ` [PATCH 3/3] arm: " Marc Zyngier
2 siblings, 1 reply; 7+ messages in thread
From: Marc Zyngier @ 2015-09-16 15:58 UTC (permalink / raw)
To: linux-arm-kernel, kvm, kvmarm
Cc: Pavel Fedin, Christoffer Dall, Alex Bennée
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@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] 7+ messages in thread* RE: [PATCH 1/3] arm/arm64: KVM: vgic: Check for !irqchip_in_kernel() when mapping resources
2015-09-16 15:58 ` [PATCH 1/3] arm/arm64: KVM: vgic: Check for !irqchip_in_kernel() when mapping resources Marc Zyngier
@ 2015-09-24 11:33 ` Pavel Fedin
0 siblings, 0 replies; 7+ messages in thread
From: Pavel Fedin @ 2015-09-24 11:33 UTC (permalink / raw)
To: 'Marc Zyngier', linux-arm-kernel, kvm, kvmarm
Cc: 'Christoffer Dall', 'Alex Bennée'
Hello!
> 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.
I'm back from vacation and very glad to see myself being useful :)
What's with the rest of that patch set? Does it need rebase or what ?
By the way, after this is applied, we can drop useless check inside vgic_v2_map_resources().
Kind regards,
Pavel Fedin
Expert Engineer
Samsung Electronics Research center Russia
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/3] arm64: KVM: Disable virtual timer even if the guest is not using it
2015-09-16 15:58 [PATCH 0/3] arm/arm64: KVM: Fix !irqchip_in_kernel() handling Marc Zyngier
2015-09-16 15:58 ` [PATCH 1/3] arm/arm64: KVM: vgic: Check for !irqchip_in_kernel() when mapping resources Marc Zyngier
@ 2015-09-16 15:58 ` Marc Zyngier
2015-09-17 11:17 ` Christoffer Dall
2015-09-16 15:58 ` [PATCH 3/3] arm: " Marc Zyngier
2 siblings, 1 reply; 7+ messages in thread
From: Marc Zyngier @ 2015-09-16 15:58 UTC (permalink / raw)
To: linux-arm-kernel, kvm, kvmarm
Cc: Pavel Fedin, Christoffer Dall, Alex Bennée
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@vger.kernel.org
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
arch/arm64/kvm/hyp.S | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/kvm/hyp.S b/arch/arm64/kvm/hyp.S
index 6addf97..38f5434 100644
--- a/arch/arm64/kvm/hyp.S
+++ b/arch/arm64/kvm/hyp.S
@@ -570,8 +570,6 @@ alternative_endif
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
@@ -579,6 +577,8 @@ alternative_endif
str x3, [x0, #VCPU_TIMER_CNTV_CVAL]
1:
+ 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] 7+ messages in thread
* Re: [PATCH 2/3] arm64: KVM: Disable virtual timer even if the guest is not using it
2015-09-16 15:58 ` [PATCH 2/3] arm64: KVM: Disable virtual timer even if the guest is not using it Marc Zyngier
@ 2015-09-17 11:17 ` Christoffer Dall
2015-09-17 12:11 ` Marc Zyngier
0 siblings, 1 reply; 7+ messages in thread
From: Christoffer Dall @ 2015-09-17 11:17 UTC (permalink / raw)
To: Marc Zyngier; +Cc: linux-arm-kernel, kvm, kvmarm, Pavel Fedin, Alex Bennée
On Wed, Sep 16, 2015 at 04:58:06PM +0100, 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@vger.kernel.org
> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
> ---
> arch/arm64/kvm/hyp.S | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm64/kvm/hyp.S b/arch/arm64/kvm/hyp.S
> index 6addf97..38f5434 100644
> --- a/arch/arm64/kvm/hyp.S
> +++ b/arch/arm64/kvm/hyp.S
> @@ -570,8 +570,6 @@ alternative_endif
The context confuses me; did you happen to base this on your VHE
patches?
> 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
>
> @@ -579,6 +577,8 @@ alternative_endif
> str x3, [x0, #VCPU_TIMER_CNTV_CVAL]
>
> 1:
> + msr cntv_ctl_el0, xzr
> +
We could have a comment here, but ok.
> // Allow physical timer/counter access for the host
> mrs x2, cnthctl_el2
> orr x2, x2, #3
> --
> 2.1.4
>
Otherwise:
Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/3] arm64: KVM: Disable virtual timer even if the guest is not using it
2015-09-17 11:17 ` Christoffer Dall
@ 2015-09-17 12:11 ` Marc Zyngier
0 siblings, 0 replies; 7+ messages in thread
From: Marc Zyngier @ 2015-09-17 12:11 UTC (permalink / raw)
To: Christoffer Dall
Cc: linux-arm-kernel, kvm, kvmarm, Pavel Fedin, Alex Bennée
On 17/09/15 12:17, Christoffer Dall wrote:
> On Wed, Sep 16, 2015 at 04:58:06PM +0100, 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@vger.kernel.org
>> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
>> ---
>> arch/arm64/kvm/hyp.S | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/arm64/kvm/hyp.S b/arch/arm64/kvm/hyp.S
>> index 6addf97..38f5434 100644
>> --- a/arch/arm64/kvm/hyp.S
>> +++ b/arch/arm64/kvm/hyp.S
>> @@ -570,8 +570,6 @@ alternative_endif
>
> The context confuses me; did you happen to base this on your VHE
> patches?
No, that's on top of 4.3-rc1, which happens to have this:
[...]
alternative_if_not ARM64_HAS_SYSREG_GIC_CPUIF
bl __restore_vgic_v2_state
alternative_else
bl __restore_vgic_v3_state
alternative_endif
.endm
.macro save_timer_state
[...]
and for some reason git doesn't use save_timer_state as the context anchor.
>> 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
>>
>> @@ -579,6 +577,8 @@ alternative_endif
>> str x3, [x0, #VCPU_TIMER_CNTV_CVAL]
>>
>> 1:
>> + msr cntv_ctl_el0, xzr
>> +
>
> We could have a comment here, but ok.
I'll add something.
>> // Allow physical timer/counter access for the host
>> mrs x2, cnthctl_el2
>> orr x2, x2, #3
>> --
>> 2.1.4
>>
>
> Otherwise:
>
> Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org>
>
Thanks!
M.
--
Jazz is not dead. It just smells funny...
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 3/3] arm: KVM: Disable virtual timer even if the guest is not using it
2015-09-16 15:58 [PATCH 0/3] arm/arm64: KVM: Fix !irqchip_in_kernel() handling Marc Zyngier
2015-09-16 15:58 ` [PATCH 1/3] arm/arm64: KVM: vgic: Check for !irqchip_in_kernel() when mapping resources Marc Zyngier
2015-09-16 15:58 ` [PATCH 2/3] arm64: KVM: Disable virtual timer even if the guest is not using it Marc Zyngier
@ 2015-09-16 15:58 ` Marc Zyngier
2 siblings, 0 replies; 7+ messages in thread
From: Marc Zyngier @ 2015-09-16 15:58 UTC (permalink / raw)
To: linux-arm-kernel, kvm, kvmarm
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@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] 7+ messages in thread