public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: arm/arm64: VGIC: extend !vgic_is_initialized guard
@ 2017-11-17 17:58 Andre Przywara
  2017-11-20  8:12 ` Auger Eric
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Andre Przywara @ 2017-11-17 17:58 UTC (permalink / raw)
  To: Christoffer Dall; +Cc: Marc Zyngier, kvmarm, kvm

Commit f39d16cbabf9 ("KVM: arm/arm64: Guard kvm_vgic_map_is_active against
!vgic_initialized") introduced a check whether the VGIC has been
initialized before accessing the spinlock and the VGIC data structure.
However the vgic_get_irq() call in the variable declaration sneaked
through the net, so lets make sure that this also gets called only after
we actually allocated the arrays this function accesses.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
 virt/kvm/arm/vgic/vgic.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/virt/kvm/arm/vgic/vgic.c b/virt/kvm/arm/vgic/vgic.c
index e54ef2fdf73d..967983a33ab2 100644
--- a/virt/kvm/arm/vgic/vgic.c
+++ b/virt/kvm/arm/vgic/vgic.c
@@ -786,13 +786,14 @@ void vgic_kick_vcpus(struct kvm *kvm)
 
 bool kvm_vgic_map_is_active(struct kvm_vcpu *vcpu, unsigned int virt_irq)
 {
-	struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, vcpu, virt_irq);
+	struct vgic_irq *irq;
 	bool map_is_active;
 	unsigned long flags;
 
 	if (!vgic_initialized(vcpu->kvm))
 		return false;
 
+	irq = vgic_get_irq(vcpu->kvm, vcpu, virt_irq);
 	spin_lock_irqsave(&irq->irq_lock, flags);
 	map_is_active = irq->hw && irq->active;
 	spin_unlock_irqrestore(&irq->irq_lock, flags);
-- 
2.14.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] KVM: arm/arm64: VGIC: extend !vgic_is_initialized guard
  2017-11-17 17:58 [PATCH] KVM: arm/arm64: VGIC: extend !vgic_is_initialized guard Andre Przywara
@ 2017-11-20  8:12 ` Auger Eric
  2017-11-20  9:12 ` Auger Eric
  2017-11-20 11:23 ` Christoffer Dall
  2 siblings, 0 replies; 4+ messages in thread
From: Auger Eric @ 2017-11-20  8:12 UTC (permalink / raw)
  To: Andre Przywara, Christoffer Dall; +Cc: Marc Zyngier, kvmarm, kvm

Hi Andre,

On 17/11/2017 18:58, Andre Przywara wrote:
> Commit f39d16cbabf9 ("KVM: arm/arm64: Guard kvm_vgic_map_is_active against
> !vgic_initialized") introduced a check whether the VGIC has been
> initialized before accessing the spinlock and the VGIC data structure.
> However the vgic_get_irq() call in the variable declaration sneaked
> through the net, so lets make sure that this also gets called only after
> we actually allocated the arrays this function accesses.
> 
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>

Thanks

Eric
> ---
>  virt/kvm/arm/vgic/vgic.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/virt/kvm/arm/vgic/vgic.c b/virt/kvm/arm/vgic/vgic.c
> index e54ef2fdf73d..967983a33ab2 100644
> --- a/virt/kvm/arm/vgic/vgic.c
> +++ b/virt/kvm/arm/vgic/vgic.c
> @@ -786,13 +786,14 @@ void vgic_kick_vcpus(struct kvm *kvm)
>  
>  bool kvm_vgic_map_is_active(struct kvm_vcpu *vcpu, unsigned int virt_irq)
>  {
> -	struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, vcpu, virt_irq);
> +	struct vgic_irq *irq;
>  	bool map_is_active;
>  	unsigned long flags;
>  
>  	if (!vgic_initialized(vcpu->kvm))
>  		return false;
>  
> +	irq = vgic_get_irq(vcpu->kvm, vcpu, virt_irq);
>  	spin_lock_irqsave(&irq->irq_lock, flags);
>  	map_is_active = irq->hw && irq->active;
>  	spin_unlock_irqrestore(&irq->irq_lock, flags);
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] KVM: arm/arm64: VGIC: extend !vgic_is_initialized guard
  2017-11-17 17:58 [PATCH] KVM: arm/arm64: VGIC: extend !vgic_is_initialized guard Andre Przywara
  2017-11-20  8:12 ` Auger Eric
@ 2017-11-20  9:12 ` Auger Eric
  2017-11-20 11:23 ` Christoffer Dall
  2 siblings, 0 replies; 4+ messages in thread
From: Auger Eric @ 2017-11-20  9:12 UTC (permalink / raw)
  To: Andre Przywara, Christoffer Dall; +Cc: Marc Zyngier, kvmarm, kvm

Hi Andre,

On 17/11/2017 18:58, Andre Przywara wrote:
> Commit f39d16cbabf9 ("KVM: arm/arm64: Guard kvm_vgic_map_is_active against
> !vgic_initialized") introduced a check whether the VGIC has been
> initialized before accessing the spinlock and the VGIC data structure.
> However the vgic_get_irq() call in the variable declaration sneaked
> through the net, so lets make sure that this also gets called only after
> we actually allocated the arrays this function accesses.
> 
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
actually it does not directly apply on kvmarm/next. There is a small
conflict with 47bbd31  KVM: arm/arm64: vgic: restructure
kvm_vgic_(un)map_phys_irq I think.

Cheers

Eric
> ---
>  virt/kvm/arm/vgic/vgic.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/virt/kvm/arm/vgic/vgic.c b/virt/kvm/arm/vgic/vgic.c
> index e54ef2fdf73d..967983a33ab2 100644
> --- a/virt/kvm/arm/vgic/vgic.c
> +++ b/virt/kvm/arm/vgic/vgic.c
> @@ -786,13 +786,14 @@ void vgic_kick_vcpus(struct kvm *kvm)
>  
>  bool kvm_vgic_map_is_active(struct kvm_vcpu *vcpu, unsigned int virt_irq)
>  {
> -	struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, vcpu, virt_irq);
> +	struct vgic_irq *irq;
>  	bool map_is_active;
>  	unsigned long flags;
>  
>  	if (!vgic_initialized(vcpu->kvm))
>  		return false;
>  
> +	irq = vgic_get_irq(vcpu->kvm, vcpu, virt_irq);
>  	spin_lock_irqsave(&irq->irq_lock, flags);
>  	map_is_active = irq->hw && irq->active;
>  	spin_unlock_irqrestore(&irq->irq_lock, flags);
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] KVM: arm/arm64: VGIC: extend !vgic_is_initialized guard
  2017-11-17 17:58 [PATCH] KVM: arm/arm64: VGIC: extend !vgic_is_initialized guard Andre Przywara
  2017-11-20  8:12 ` Auger Eric
  2017-11-20  9:12 ` Auger Eric
@ 2017-11-20 11:23 ` Christoffer Dall
  2 siblings, 0 replies; 4+ messages in thread
From: Christoffer Dall @ 2017-11-20 11:23 UTC (permalink / raw)
  To: Andre Przywara; +Cc: Christoffer Dall, Marc Zyngier, kvmarm, kvm

Hi Andre,

On Fri, Nov 17, 2017 at 05:58:21PM +0000, Andre Przywara wrote:
> Commit f39d16cbabf9 ("KVM: arm/arm64: Guard kvm_vgic_map_is_active against
> !vgic_initialized") introduced a check whether the VGIC has been
> initialized before accessing the spinlock and the VGIC data structure.
> However the vgic_get_irq() call in the variable declaration sneaked
> through the net, so lets make sure that this also gets called only after
> we actually allocated the arrays this function accesses.
> 
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> ---
>  virt/kvm/arm/vgic/vgic.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/virt/kvm/arm/vgic/vgic.c b/virt/kvm/arm/vgic/vgic.c
> index e54ef2fdf73d..967983a33ab2 100644
> --- a/virt/kvm/arm/vgic/vgic.c
> +++ b/virt/kvm/arm/vgic/vgic.c
> @@ -786,13 +786,14 @@ void vgic_kick_vcpus(struct kvm *kvm)
>  
>  bool kvm_vgic_map_is_active(struct kvm_vcpu *vcpu, unsigned int virt_irq)
>  {
> -	struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, vcpu, virt_irq);
> +	struct vgic_irq *irq;
>  	bool map_is_active;
>  	unsigned long flags;
>  
>  	if (!vgic_initialized(vcpu->kvm))
>  		return false;
>  
> +	irq = vgic_get_irq(vcpu->kvm, vcpu, virt_irq);
>  	spin_lock_irqsave(&irq->irq_lock, flags);
>  	map_is_active = irq->hw && irq->active;
>  	spin_unlock_irqrestore(&irq->irq_lock, flags);
> -- 
> 2.14.1
> 
As explained in the other e-mail this isn't actually strictly necessary
anymore, but I think our current appraoch of "how do we handle calls
from generic code the VGIC when the VGIC potentially hasn't been
initialized yet?" is to have an initialized check on most entry points
to the VGIC, unless strictly performance sensitive.

Therefore:

Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-11-20 11:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-17 17:58 [PATCH] KVM: arm/arm64: VGIC: extend !vgic_is_initialized guard Andre Przywara
2017-11-20  8:12 ` Auger Eric
2017-11-20  9:12 ` Auger Eric
2017-11-20 11:23 ` Christoffer Dall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox