All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Marc Zyngier <marc.zyngier@arm.com>, Gleb Natapov <gleb@kernel.org>
Cc: "Christoffer Dall" <christoffer.dall@linaro.org>,
	"Will Deacon" <will.deacon@arm.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Marek Majtyka" <marek.majtyka@tieto.com>,
	"Pavel Fedin" <p.fedin@samsung.com>,
	"Ming Lei" <ming.lei@canonical.com>,
	kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 5/8] arm64: KVM: Disable virtual timer even if the guest is not using it
Date: Thu, 17 Sep 2015 17:02:31 +0200	[thread overview]
Message-ID: <55FAD607.9040305@redhat.com> (raw)
In-Reply-To: <1442501171-24484-6-git-send-email-marc.zyngier@arm.com>



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@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;

WARNING: multiple messages have this Message-ID (diff)
From: pbonzini@redhat.com (Paolo Bonzini)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 5/8] arm64: KVM: Disable virtual timer even if the guest is not using it
Date: Thu, 17 Sep 2015 17:02:31 +0200	[thread overview]
Message-ID: <55FAD607.9040305@redhat.com> (raw)
In-Reply-To: <1442501171-24484-6-git-send-email-marc.zyngier@arm.com>



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;

  reply	other threads:[~2015-09-17 15:02 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 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 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 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 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 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 15:02   ` Paolo Bonzini [this message]
2015-09-17 15:02     ` Paolo Bonzini
2015-09-17 15:28     ` Marc Zyngier
2015-09-17 15:28       ` Marc Zyngier
2015-09-17 15:31       ` Paolo Bonzini
2015-09-17 15:31         ` Paolo Bonzini
2015-09-17 14:46 ` [PATCH 6/8] arm: " 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
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:46   ` Marc Zyngier
2015-09-17 14:53 ` [GIT PULL] Second set of KVM/ARM updates for 4.3-rc2 Paolo Bonzini
2015-09-17 14:53   ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55FAD607.9040305@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=christoffer.dall@linaro.org \
    --cc=gleb@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=marc.zyngier@arm.com \
    --cc=marek.majtyka@tieto.com \
    --cc=ming.lei@canonical.com \
    --cc=p.fedin@samsung.com \
    --cc=peter.maydell@linaro.org \
    --cc=will.deacon@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.