All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Auger <eric.auger@linaro.org>
To: Christoffer Dall <christoffer.dall@linaro.org>,
	kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Cc: Marc Zyngier <marc.zyngier@arm.com>, Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH 3/3] arm/arm64: KVM: Fix disabled distributor operation
Date: Tue, 20 Oct 2015 11:08:44 +0200	[thread overview]
Message-ID: <5626049C.3000005@linaro.org> (raw)
In-Reply-To: <1445113822-7831-4-git-send-email-christoffer.dall@linaro.org>

Hi Christoffer,
On 10/17/2015 10:30 PM, Christoffer Dall wrote:
> We currently do a single update of the vgic state when the distrbutor
distributor
> enable/disable control register is accessed and then bypass updating the
> state for as long as the distributor remains disabled.
> 
> This is incorrect, because updating the state does not consider the
> distributor enable bit, and this you can end up in a situation where an
> interrupt is marked as pending on the CPU interface, but not pending on
> the distributor, which is an impossible state to be in, and triggers a
> warning.  Consider for example the following sequence of events:
> 
> 1. An interrupt is marked as pending on the distributor
>    - the interrupt is also forwarded to the CPU interface
> 2. The guest turns off the distributor (it's about to do a reboot)
>    - we stop updating the CPU interface state from now on
> 3. The guest disables the pending interrupt
>    - we remove the pending state from the distributor, but don't touch
>      the CPU interface, see point 2.
> 
> Since the distributor disable bit really means that no interrupts should
> be forwarded to the CPU interface, we modify the code to keep updating
> the internal VGIC state, but always set the CPU interface pending bits
> to zero when the distributor is disabled.
> 
> Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
> ---
>  virt/kvm/arm/vgic.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c
> index 58b1256..66c6616 100644
> --- a/virt/kvm/arm/vgic.c
> +++ b/virt/kvm/arm/vgic.c
> @@ -1012,6 +1012,12 @@ static int compute_pending_for_cpu(struct kvm_vcpu *vcpu)
>  	pend_percpu = vcpu->arch.vgic_cpu.pending_percpu;
>  	pend_shared = vcpu->arch.vgic_cpu.pending_shared;
>  
> +	if (!dist->enabled) {
> +		bitmap_zero(pend_percpu, VGIC_NR_PRIVATE_IRQS);
> +		bitmap_zero(pend_shared, nr_shared);
> +		return 0;
> +	}
> +
>  	pending = vgic_bitmap_get_cpu_map(&dist->irq_pending, vcpu_id);
>  	enabled = vgic_bitmap_get_cpu_map(&dist->irq_enabled, vcpu_id);
>  	bitmap_and(pend_percpu, pending, enabled, VGIC_NR_PRIVATE_IRQS);
> @@ -1039,11 +1045,6 @@ void vgic_update_state(struct kvm *kvm)
>  	struct kvm_vcpu *vcpu;
>  	int c;
>  
> -	if (!dist->enabled) {
> -		set_bit(0, dist->irq_pending_on_cpu);
> -		return;
I am confused. Don't you want to clear the whole bitmap?

Shouldn't we also handle interrupts programmed in the LR. Spec says any
ack should return a spurious ID. Is it what is going to happen with the
current implementation?

Eric
> -	}
> -
>  	kvm_for_each_vcpu(c, vcpu, kvm) {
>  		if (compute_pending_for_cpu(vcpu))
>  			set_bit(c, dist->irq_pending_on_cpu);
> 


WARNING: multiple messages have this Message-ID (diff)
From: eric.auger@linaro.org (Eric Auger)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 3/3] arm/arm64: KVM: Fix disabled distributor operation
Date: Tue, 20 Oct 2015 11:08:44 +0200	[thread overview]
Message-ID: <5626049C.3000005@linaro.org> (raw)
In-Reply-To: <1445113822-7831-4-git-send-email-christoffer.dall@linaro.org>

Hi Christoffer,
On 10/17/2015 10:30 PM, Christoffer Dall wrote:
> We currently do a single update of the vgic state when the distrbutor
distributor
> enable/disable control register is accessed and then bypass updating the
> state for as long as the distributor remains disabled.
> 
> This is incorrect, because updating the state does not consider the
> distributor enable bit, and this you can end up in a situation where an
> interrupt is marked as pending on the CPU interface, but not pending on
> the distributor, which is an impossible state to be in, and triggers a
> warning.  Consider for example the following sequence of events:
> 
> 1. An interrupt is marked as pending on the distributor
>    - the interrupt is also forwarded to the CPU interface
> 2. The guest turns off the distributor (it's about to do a reboot)
>    - we stop updating the CPU interface state from now on
> 3. The guest disables the pending interrupt
>    - we remove the pending state from the distributor, but don't touch
>      the CPU interface, see point 2.
> 
> Since the distributor disable bit really means that no interrupts should
> be forwarded to the CPU interface, we modify the code to keep updating
> the internal VGIC state, but always set the CPU interface pending bits
> to zero when the distributor is disabled.
> 
> Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
> ---
>  virt/kvm/arm/vgic.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c
> index 58b1256..66c6616 100644
> --- a/virt/kvm/arm/vgic.c
> +++ b/virt/kvm/arm/vgic.c
> @@ -1012,6 +1012,12 @@ static int compute_pending_for_cpu(struct kvm_vcpu *vcpu)
>  	pend_percpu = vcpu->arch.vgic_cpu.pending_percpu;
>  	pend_shared = vcpu->arch.vgic_cpu.pending_shared;
>  
> +	if (!dist->enabled) {
> +		bitmap_zero(pend_percpu, VGIC_NR_PRIVATE_IRQS);
> +		bitmap_zero(pend_shared, nr_shared);
> +		return 0;
> +	}
> +
>  	pending = vgic_bitmap_get_cpu_map(&dist->irq_pending, vcpu_id);
>  	enabled = vgic_bitmap_get_cpu_map(&dist->irq_enabled, vcpu_id);
>  	bitmap_and(pend_percpu, pending, enabled, VGIC_NR_PRIVATE_IRQS);
> @@ -1039,11 +1045,6 @@ void vgic_update_state(struct kvm *kvm)
>  	struct kvm_vcpu *vcpu;
>  	int c;
>  
> -	if (!dist->enabled) {
> -		set_bit(0, dist->irq_pending_on_cpu);
> -		return;
I am confused. Don't you want to clear the whole bitmap?

Shouldn't we also handle interrupts programmed in the LR. Spec says any
ack should return a spurious ID. Is it what is going to happen with the
current implementation?

Eric
> -	}
> -
>  	kvm_for_each_vcpu(c, vcpu, kvm) {
>  		if (compute_pending_for_cpu(vcpu))
>  			set_bit(c, dist->irq_pending_on_cpu);
> 

  reply	other threads:[~2015-10-20  9:08 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-17 20:30 [PATCH 0/3] arm/arm64: KVM: arch timer boot fixes Christoffer Dall
2015-10-17 20:30 ` Christoffer Dall
2015-10-17 20:30 ` [PATCH 1/3] arm/arm64: KVM: Fix arch timer behavior for disabled interrupts Christoffer Dall
2015-10-17 20:30   ` Christoffer Dall
2015-10-17 21:50   ` Christoffer Dall
2015-10-17 21:50     ` Christoffer Dall
2015-10-19 13:07   ` Eric Auger
2015-10-19 13:07     ` Eric Auger
2015-10-19 13:14     ` Christoffer Dall
2015-10-19 13:14       ` Christoffer Dall
2015-10-19 13:27       ` Eric Auger
2015-10-19 13:27         ` Eric Auger
2015-10-19 13:38         ` Christoffer Dall
2015-10-19 13:38           ` Christoffer Dall
2015-10-17 20:30 ` [PATCH 2/3] arm/arm64: KVM: Clear map->active on pend/active clear Christoffer Dall
2015-10-17 20:30   ` Christoffer Dall
2015-10-19 15:32   ` Eric Auger
2015-10-19 15:32     ` Eric Auger
2015-10-19 15:39     ` Christoffer Dall
2015-10-19 15:39       ` Christoffer Dall
2015-10-19 15:45       ` Eric Auger
2015-10-19 15:45         ` Eric Auger
2015-10-17 20:30 ` [PATCH 3/3] arm/arm64: KVM: Fix disabled distributor operation Christoffer Dall
2015-10-17 20:30   ` Christoffer Dall
2015-10-20  9:08   ` Eric Auger [this message]
2015-10-20  9:08     ` Eric Auger
2015-10-20  9:44     ` Christoffer Dall
2015-10-20  9:44       ` Christoffer Dall
2015-10-20 17:44       ` Eric Auger
2015-10-20 17:44         ` Eric Auger

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=5626049C.3000005@linaro.org \
    --to=eric.auger@linaro.org \
    --cc=christoffer.dall@linaro.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=pbonzini@redhat.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.