Linux KVM/arm64 development list
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Christoffer Dall <christoffer.dall@linaro.org>,
	Andre Przywara <andre.przywara@arm.com>
Cc: Marc Zyngier <marc.zyngier@arm.com>,
	linux-arm-kernel@lists.infradead.org,
	kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org,
	Eric Auger <eric.auger@linaro.org>
Subject: Re: [PATCH] KVM: arm64: vgic-its: Grab kvm->lock when reading kvm->devices
Date: Wed, 10 Aug 2016 15:10:51 +0200	[thread overview]
Message-ID: <d02583ed-d396-4431-ba91-903d04843fb3@redhat.com> (raw)
In-Reply-To: <20160810103914.30322-1-christoffer.dall@linaro.org>



On 10/08/2016 12:39, Christoffer Dall wrote:
> Since we are about to synchronize all accesses to kvm->devices using the
> kvm->lock mutex, we should hold this mutex while iterating over the list
> of devices in the ITS code.
> 
> Also move the vgic_register_its_iodev function to where it's called and
> rename it to register_its_iodev to avoid having two almost identially
> named functions.
> 
> Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
> ---
>  virt/kvm/arm/vgic/vgic-its.c | 64 +++++++++++++++++++++++---------------------
>  1 file changed, 34 insertions(+), 30 deletions(-)
> 
> diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c
> index 1cf9f59..4e76877 100644
> --- a/virt/kvm/arm/vgic/vgic-its.c
> +++ b/virt/kvm/arm/vgic/vgic-its.c
> @@ -1319,32 +1319,6 @@ void vgic_enable_lpis(struct kvm_vcpu *vcpu)
>  		its_sync_lpi_pending_table(vcpu);
>  }
>  
> -static int vgic_register_its_iodev(struct kvm *kvm, struct vgic_its *its)
> -{
> -	struct vgic_io_device *iodev = &its->iodev;
> -	int ret;
> -
> -	if (!its->initialized)
> -		return -EBUSY;
> -
> -	if (IS_VGIC_ADDR_UNDEF(its->vgic_its_base))
> -		return -ENXIO;
> -
> -	iodev->regions = its_registers;
> -	iodev->nr_regions = ARRAY_SIZE(its_registers);
> -	kvm_iodevice_init(&iodev->dev, &kvm_io_gic_ops);
> -
> -	iodev->base_addr = its->vgic_its_base;
> -	iodev->iodev_type = IODEV_ITS;
> -	iodev->its = its;
> -	mutex_lock(&kvm->slots_lock);
> -	ret = kvm_io_bus_register_dev(kvm, KVM_MMIO_BUS, iodev->base_addr,
> -				      KVM_VGIC_V3_ITS_SIZE, &iodev->dev);
> -	mutex_unlock(&kvm->slots_lock);
> -
> -	return ret;
> -}
> -
>  #define INITIAL_BASER_VALUE						  \
>  	(GIC_BASER_CACHEABILITY(GITS_BASER, INNER, RaWb)		| \
>  	 GIC_BASER_CACHEABILITY(GITS_BASER, OUTER, SameAsInner)		| \
> @@ -1526,6 +1500,32 @@ int kvm_vgic_register_its_device(void)
>  				       KVM_DEV_TYPE_ARM_VGIC_ITS);
>  }
>  
> +static int register_its_iodev(struct kvm *kvm, struct vgic_its *its)
> +{
> +	struct vgic_io_device *iodev = &its->iodev;
> +	int ret;
> +
> +	if (!its->initialized)
> +		return -EBUSY;
> +
> +	if (IS_VGIC_ADDR_UNDEF(its->vgic_its_base))
> +		return -ENXIO;
> +
> +	iodev->regions = its_registers;
> +	iodev->nr_regions = ARRAY_SIZE(its_registers);
> +	kvm_iodevice_init(&iodev->dev, &kvm_io_gic_ops);
> +
> +	iodev->base_addr = its->vgic_its_base;
> +	iodev->iodev_type = IODEV_ITS;
> +	iodev->its = its;
> +	mutex_lock(&kvm->slots_lock);
> +	ret = kvm_io_bus_register_dev(kvm, KVM_MMIO_BUS, iodev->base_addr,
> +				      KVM_VGIC_V3_ITS_SIZE, &iodev->dev);
> +	mutex_unlock(&kvm->slots_lock);
> +
> +	return ret;
> +}
> +
>  /*
>   * Registers all ITSes with the kvm_io_bus framework.
>   * To follow the existing VGIC initialization sequence, this has to be
> @@ -1536,19 +1536,23 @@ int vgic_register_its_iodevs(struct kvm *kvm)
>  	struct kvm_device *dev;
>  	int ret = 0;
>  
> +	mutex_lock(&kvm->lock);
>  	list_for_each_entry(dev, &kvm->devices, vm_node) {
>  		if (dev->ops != &kvm_arm_vgic_its_ops)
>  			continue;
>  
> -		ret = vgic_register_its_iodev(kvm, dev->private);
> +		ret = register_its_iodev(kvm, dev->private);
>  		if (ret)
> -			return ret;
> +			goto out;
> +
>  		/*
>  		 * We don't need to care about tearing down previously
> -		 * registered ITSes, as the kvm_io_bus framework removes
> -		 * them for us if the VM gets destroyed.
> +		 * registered ITSes on error, as the kvm_io_bus framework
> +		 * removes them for us if the VM gets destroyed.
>  		 */
>  	}
>  
> +out:
> +	mutex_unlock(&kvm->lock);
>  	return ret;
>  }
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

  reply	other threads:[~2016-08-10 13:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-08 15:45 [PATCH v2] KVM: arm64: ITS: move ITS registration into first VCPU run Andre Przywara
2016-08-09  7:49 ` Auger Eric
2016-08-10 10:39 ` [PATCH] KVM: arm64: vgic-its: Grab kvm->lock when reading kvm->devices Christoffer Dall
2016-08-10 13:10   ` Paolo Bonzini [this message]
2016-08-10 14:34     ` Christoffer Dall

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=d02583ed-d396-4431-ba91-903d04843fb3@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=andre.przywara@arm.com \
    --cc=christoffer.dall@linaro.org \
    --cc=eric.auger@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 \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox