From: christoffer.dall@linaro.org (Christoffer Dall)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] KVM: arm64: vgic-its: Grab kvm->lock when reading kvm->devices
Date: Wed, 10 Aug 2016 16:34:29 +0200 [thread overview]
Message-ID: <20160810143429.GA11515@cbox> (raw)
In-Reply-To: <d02583ed-d396-4431-ba91-903d04843fb3@redhat.com>
On Wed, Aug 10, 2016 at 03:10:51PM +0200, Paolo Bonzini wrote:
>
>
> 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>
Thanks Paolo!
-Christoffer
prev parent reply other threads:[~2016-08-10 14:34 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
2016-08-10 14:34 ` Christoffer Dall [this message]
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=20160810143429.GA11515@cbox \
--to=christoffer.dall@linaro.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).