All of lore.kernel.org
 help / color / mirror / Atom feed
From: will.deacon@arm.com (Will Deacon)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v4 08/13] ARM: KVM: vgic: retire queued, disabled interrupts
Date: Mon, 3 Dec 2012 13:24:18 +0000	[thread overview]
Message-ID: <20121203132418.GD20074@mudshark.cambridge.arm.com> (raw)
In-Reply-To: <20121110154511.3061.36715.stgit@chazy-air>

On Sat, Nov 10, 2012 at 03:45:11PM +0000, Christoffer Dall wrote:
> From: Marc Zyngier <marc.zyngier@arm.com>
> 
> An interrupt may have been disabled after being made pending on the
> CPU interface (the classic case is a timer running while we're
> rebooting the guest - the interrupt would kick as soon as the CPU
> interface gets enabled, with deadly consequences).
> 
> The solution is to examine already active LRs, and check the
> interrupt is still enabled. If not, just retire it.
> 
> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
> Signed-off-by: Christoffer Dall <c.dall@virtualopensystems.com>
> ---
>  arch/arm/kvm/vgic.c |   30 ++++++++++++++++++++++++++++++
>  1 file changed, 30 insertions(+)
> 
> diff --git a/arch/arm/kvm/vgic.c b/arch/arm/kvm/vgic.c
> index d7cdec5..dda5623 100644
> --- a/arch/arm/kvm/vgic.c
> +++ b/arch/arm/kvm/vgic.c
> @@ -633,6 +633,34 @@ static void vgic_update_state(struct kvm *kvm)
>  
>  #define LR_PHYSID(lr) 		(((lr) & VGIC_LR_PHYSID_CPUID) >> 10)
>  #define MK_LR_PEND(src, irq)	(VGIC_LR_PENDING_BIT | ((src) << 10) | (irq))
> +
> +/*
> + * An interrupt may have been disabled after being made pending on the
> + * CPU interface (the classic case is a timer running while we're
> + * rebooting the guest - the interrupt would kick as soon as the CPU
> + * interface gets enabled, with deadly consequences).
> + *
> + * The solution is to examine already active LRs, and check the
> + * interrupt is still enabled. If not, just retire it.
> + */
> +static void vgic_retire_disabled_irqs(struct kvm_vcpu *vcpu)
> +{
> +	struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;
> +	struct vgic_dist *dist = &vcpu->kvm->arch.vgic;
> +	int lr;
> +
> +	for_each_set_bit(lr, vgic_cpu->lr_used, vgic_cpu->nr_lr) {
> +		int irq = vgic_cpu->vgic_lr[lr] & VGIC_LR_VIRTUALID;
> +
> +		if (!vgic_bitmap_get_irq_val(&dist->irq_enabled,
> +					     vcpu->vcpu_id, irq)) {
> +			vgic_cpu->vgic_irq_lr_map[irq] = LR_EMPTY;
> +			clear_bit(lr, vgic_cpu->lr_used);
> +			vgic_cpu->vgic_lr[lr] &= ~VGIC_LR_STATE;
> +		}
> +	}
> +}
> +
>  /*
>   * Queue an interrupt to a CPU virtual interface. Return true on success,
>   * or false if it wasn't possible to queue it.
> @@ -696,6 +724,8 @@ static void __kvm_vgic_sync_to_cpu(struct kvm_vcpu *vcpu)
>  
>  	vcpu_id = vcpu->vcpu_id;
>  
> +	vgic_retire_disabled_irqs(vcpu);

Wouldn't it be better to do this when the interrupt is disabled, rather
than do the checking in the sync_to_cpu path?

Will

WARNING: multiple messages have this Message-ID (diff)
From: Will Deacon <will.deacon@arm.com>
To: Christoffer Dall <c.dall@virtualopensystems.com>
Cc: "kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"kvmarm@lists.cs.columbia.edu" <kvmarm@lists.cs.columbia.edu>,
	Marc Zyngier <Marc.Zyngier@arm.com>
Subject: Re: [PATCH v4 08/13] ARM: KVM: vgic: retire queued, disabled interrupts
Date: Mon, 3 Dec 2012 13:24:18 +0000	[thread overview]
Message-ID: <20121203132418.GD20074@mudshark.cambridge.arm.com> (raw)
In-Reply-To: <20121110154511.3061.36715.stgit@chazy-air>

On Sat, Nov 10, 2012 at 03:45:11PM +0000, Christoffer Dall wrote:
> From: Marc Zyngier <marc.zyngier@arm.com>
> 
> An interrupt may have been disabled after being made pending on the
> CPU interface (the classic case is a timer running while we're
> rebooting the guest - the interrupt would kick as soon as the CPU
> interface gets enabled, with deadly consequences).
> 
> The solution is to examine already active LRs, and check the
> interrupt is still enabled. If not, just retire it.
> 
> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
> Signed-off-by: Christoffer Dall <c.dall@virtualopensystems.com>
> ---
>  arch/arm/kvm/vgic.c |   30 ++++++++++++++++++++++++++++++
>  1 file changed, 30 insertions(+)
> 
> diff --git a/arch/arm/kvm/vgic.c b/arch/arm/kvm/vgic.c
> index d7cdec5..dda5623 100644
> --- a/arch/arm/kvm/vgic.c
> +++ b/arch/arm/kvm/vgic.c
> @@ -633,6 +633,34 @@ static void vgic_update_state(struct kvm *kvm)
>  
>  #define LR_PHYSID(lr) 		(((lr) & VGIC_LR_PHYSID_CPUID) >> 10)
>  #define MK_LR_PEND(src, irq)	(VGIC_LR_PENDING_BIT | ((src) << 10) | (irq))
> +
> +/*
> + * An interrupt may have been disabled after being made pending on the
> + * CPU interface (the classic case is a timer running while we're
> + * rebooting the guest - the interrupt would kick as soon as the CPU
> + * interface gets enabled, with deadly consequences).
> + *
> + * The solution is to examine already active LRs, and check the
> + * interrupt is still enabled. If not, just retire it.
> + */
> +static void vgic_retire_disabled_irqs(struct kvm_vcpu *vcpu)
> +{
> +	struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;
> +	struct vgic_dist *dist = &vcpu->kvm->arch.vgic;
> +	int lr;
> +
> +	for_each_set_bit(lr, vgic_cpu->lr_used, vgic_cpu->nr_lr) {
> +		int irq = vgic_cpu->vgic_lr[lr] & VGIC_LR_VIRTUALID;
> +
> +		if (!vgic_bitmap_get_irq_val(&dist->irq_enabled,
> +					     vcpu->vcpu_id, irq)) {
> +			vgic_cpu->vgic_irq_lr_map[irq] = LR_EMPTY;
> +			clear_bit(lr, vgic_cpu->lr_used);
> +			vgic_cpu->vgic_lr[lr] &= ~VGIC_LR_STATE;
> +		}
> +	}
> +}
> +
>  /*
>   * Queue an interrupt to a CPU virtual interface. Return true on success,
>   * or false if it wasn't possible to queue it.
> @@ -696,6 +724,8 @@ static void __kvm_vgic_sync_to_cpu(struct kvm_vcpu *vcpu)
>  
>  	vcpu_id = vcpu->vcpu_id;
>  
> +	vgic_retire_disabled_irqs(vcpu);

Wouldn't it be better to do this when the interrupt is disabled, rather
than do the checking in the sync_to_cpu path?

Will

  reply	other threads:[~2012-12-03 13:24 UTC|newest]

Thread overview: 116+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-10 15:44 [PATCH v4 00/13] KVM/ARM vGIC support Christoffer Dall
2012-11-10 15:44 ` Christoffer Dall
2012-11-10 15:44 ` [PATCH v4 01/13] KVM: ARM: Introduce KVM_SET_DEVICE_ADDRESS ioctl Christoffer Dall
2012-11-10 15:44   ` Christoffer Dall
2012-11-10 15:44 ` [PATCH v4 02/13] ARM: KVM: Keep track of currently running vcpus Christoffer Dall
2012-11-10 15:44   ` Christoffer Dall
2012-11-28 12:47   ` Will Deacon
2012-11-28 12:47     ` Will Deacon
2012-11-28 13:15     ` Marc Zyngier
2012-11-28 13:15       ` Marc Zyngier
2012-11-30 22:39     ` Christoffer Dall
2012-11-30 22:39       ` Christoffer Dall
2012-11-10 15:44 ` [PATCH v4 03/13] ARM: KVM: Initial VGIC infrastructure support Christoffer Dall
2012-11-10 15:44   ` Christoffer Dall
2012-11-28 12:49   ` Will Deacon
2012-11-28 12:49     ` Will Deacon
2012-11-28 13:09     ` Marc Zyngier
2012-11-28 13:09       ` Marc Zyngier
2012-11-28 14:13       ` Will Deacon
2012-11-28 14:13         ` Will Deacon
2012-12-01  2:19     ` Christoffer Dall
2012-12-01  2:19       ` Christoffer Dall
2012-11-10 15:44 ` [PATCH v4 04/13] ARM: KVM: Initial VGIC MMIO support code Christoffer Dall
2012-11-10 15:44   ` Christoffer Dall
2012-11-12  8:54   ` Dong Aisheng
2012-11-12  8:54     ` Dong Aisheng
2012-11-13 13:32     ` Christoffer Dall
2012-11-13 13:32       ` Christoffer Dall
2012-11-28 13:09   ` Will Deacon
2012-11-28 13:09     ` Will Deacon
2012-11-28 13:44     ` Marc Zyngier
2012-11-28 13:44       ` Marc Zyngier
2012-11-10 15:44 ` [PATCH v4 05/13] ARM: KVM: VGIC accept vcpu and dist base addresses from user space Christoffer Dall
2012-11-10 15:44   ` Christoffer Dall
2012-11-12  8:56   ` Dong Aisheng
2012-11-12  8:56     ` Dong Aisheng
2012-11-13 13:35     ` Christoffer Dall
2012-11-13 13:35       ` Christoffer Dall
2012-11-28 13:11   ` Will Deacon
2012-11-28 13:11     ` Will Deacon
2012-11-28 13:22     ` [kvmarm] " Marc Zyngier
2012-11-28 13:22       ` Marc Zyngier
2012-12-01  2:52     ` Christoffer Dall
2012-12-01  2:52       ` Christoffer Dall
2012-12-01 15:57       ` Christoffer Dall
2012-12-01 15:57         ` Christoffer Dall
2012-12-03 10:40       ` Will Deacon
2012-12-03 10:40         ` Will Deacon
2012-11-10 15:44 ` [PATCH v4 06/13] ARM: KVM: VGIC distributor handling Christoffer Dall
2012-11-10 15:44   ` Christoffer Dall
2012-11-12  9:29   ` Dong Aisheng
2012-11-12  9:29     ` Dong Aisheng
2012-11-13 13:38     ` Christoffer Dall
2012-11-13 13:38       ` Christoffer Dall
2012-11-28 13:21   ` Will Deacon
2012-11-28 13:21     ` Will Deacon
2012-11-28 14:35     ` Marc Zyngier
2012-11-28 14:35       ` Marc Zyngier
2012-11-10 15:45 ` [PATCH v4 07/13] ARM: KVM: VGIC virtual CPU interface management Christoffer Dall
2012-11-10 15:45   ` Christoffer Dall
2012-12-03 13:23   ` Will Deacon
2012-12-03 13:23     ` Will Deacon
2012-12-03 14:11     ` Marc Zyngier
2012-12-03 14:11       ` Marc Zyngier
2012-12-03 14:34       ` Will Deacon
2012-12-03 14:34         ` Will Deacon
2012-12-03 15:24         ` Marc Zyngier
2012-12-03 15:24           ` Marc Zyngier
2012-12-03 14:54       ` Christoffer Dall
2012-12-03 14:54         ` Christoffer Dall
2012-11-10 15:45 ` [PATCH v4 08/13] ARM: KVM: vgic: retire queued, disabled interrupts Christoffer Dall
2012-11-10 15:45   ` Christoffer Dall
2012-12-03 13:24   ` Will Deacon [this message]
2012-12-03 13:24     ` Will Deacon
2012-11-10 15:45 ` [PATCH v4 09/13] ARM: KVM: VGIC interrupt injection Christoffer Dall
2012-11-10 15:45   ` Christoffer Dall
2012-12-03 13:25   ` Will Deacon
2012-12-03 13:25     ` Will Deacon
2012-12-03 14:21     ` Marc Zyngier
2012-12-03 14:21       ` Marc Zyngier
2012-12-03 14:58       ` Christoffer Dall
2012-12-03 14:58         ` Christoffer Dall
2012-12-03 19:13       ` Christoffer Dall
2012-12-03 19:13         ` Christoffer Dall
2012-12-03 19:22         ` Marc Zyngier
2012-12-03 19:22           ` Marc Zyngier
2012-11-10 15:45 ` [PATCH v4 10/13] ARM: KVM: VGIC control interface world switch Christoffer Dall
2012-11-10 15:45   ` Christoffer Dall
2012-12-03 13:31   ` Will Deacon
2012-12-03 13:31     ` Will Deacon
2012-12-03 14:26     ` Marc Zyngier
2012-12-03 14:26       ` Marc Zyngier
2012-11-10 15:45 ` [PATCH v4 11/13] ARM: KVM: VGIC initialisation code Christoffer Dall
2012-11-10 15:45   ` Christoffer Dall
2012-12-05 10:43   ` Will Deacon
2012-12-05 10:43     ` Will Deacon
2012-11-10 15:45 ` [PATCH v4 12/13] ARM: KVM: vgic: reduce the number of vcpu kick Christoffer Dall
2012-11-10 15:45   ` Christoffer Dall
2012-12-05 10:43   ` Will Deacon
2012-12-05 10:43     ` Will Deacon
2012-12-05 10:58     ` Russell King - ARM Linux
2012-12-05 10:58       ` Russell King - ARM Linux
2012-12-05 12:17       ` Marc Zyngier
2012-12-05 12:17         ` Marc Zyngier
2012-12-05 12:29         ` Russell King - ARM Linux
2012-12-05 12:29           ` Russell King - ARM Linux
2012-12-05 13:40           ` Marc Zyngier
2012-12-05 13:40             ` Marc Zyngier
2012-12-05 15:55             ` Russell King - ARM Linux
2012-12-05 15:55               ` Russell King - ARM Linux
2012-12-05 11:16   ` Russell King - ARM Linux
2012-12-05 11:16     ` Russell King - ARM Linux
2012-11-10 15:45 ` [PATCH v4 13/13] ARM: KVM: Add VGIC configuration option Christoffer Dall
2012-11-10 15:45   ` Christoffer Dall
2012-11-10 19:52   ` Sergei Shtylyov
2012-11-10 19:52     ` Sergei Shtylyov

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=20121203132418.GD20074@mudshark.cambridge.arm.com \
    --to=will.deacon@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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.