From: Christoffer Dall <christoffer.dall@linaro.org>
To: Andre Przywara <andre.przywara@arm.com>
Cc: Marc Zyngier <marc.zyngier@arm.com>,
kvmarm@lists.cs.columbia.edu,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH] KVM: arm64: check for ITS device on MSI injection
Date: Tue, 9 Aug 2016 16:48:02 +0200 [thread overview]
Message-ID: <20160809144802.GI9175@cbox> (raw)
In-Reply-To: <20160809095429.13393-1-andre.przywara@arm.com>
On Tue, Aug 09, 2016 at 10:54:29AM +0100, Andre Przywara wrote:
> When userspace provides the doorbell address for an MSI to be
> injected into the guest, we find a KVM device which feels responsible.
> Lets check that this device is really an emulated ITS before we make
> real use of the container_of-ed pointer.
>
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> ---
> virt/kvm/arm/vgic/vgic-its.c | 25 +++++++++++++++++++++----
> 1 file changed, 21 insertions(+), 4 deletions(-)
>
> diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c
> index 18a6871..9aeb3a4 100644
> --- a/virt/kvm/arm/vgic/vgic-its.c
> +++ b/virt/kvm/arm/vgic/vgic-its.c
> @@ -471,6 +471,24 @@ static int vgic_its_trigger_msi(struct kvm *kvm, struct vgic_its *its,
> return 0;
> }
>
> +static struct vgic_io_device *vgic_get_its_iodev(struct kvm_io_device *dev)
> +{
> + struct vgic_io_device *iodev;
> +
> + if (!dev)
> + return NULL;
this feels defensive. Wouldn't it make more sense to check the return
of kvm_io_bus_get_dev where its' called, and then conditionally call
this function?
Otherwise:
Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org>
> +
> + if (dev->ops != &kvm_io_gic_ops)
> + return NULL;
> +
> + iodev = container_of(dev, struct vgic_io_device, dev);
> +
> + if (iodev->iodev_type != IODEV_ITS)
> + return NULL;
> +
> + return iodev;
> +}
> +
> /*
> * Queries the KVM IO bus framework to get the ITS pointer from the given
> * doorbell address.
> @@ -493,10 +511,9 @@ int vgic_its_inject_msi(struct kvm *kvm, struct kvm_msi *msi)
> address = (u64)msi->address_hi << 32 | msi->address_lo;
>
> kvm_io_dev = kvm_io_bus_get_dev(kvm, KVM_MMIO_BUS, address);
> - if (!kvm_io_dev)
> - return -ENODEV;
> -
> - iodev = container_of(kvm_io_dev, struct vgic_io_device, dev);
> + iodev = vgic_get_its_iodev(kvm_io_dev);
> + if (!iodev)
> + return -EINVAL;
>
> mutex_lock(&iodev->its->its_lock);
> ret = vgic_its_trigger_msi(kvm, iodev->its, msi->devid, msi->data);
> --
> 2.9.0
>
WARNING: multiple messages have this Message-ID (diff)
From: christoffer.dall@linaro.org (Christoffer Dall)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] KVM: arm64: check for ITS device on MSI injection
Date: Tue, 9 Aug 2016 16:48:02 +0200 [thread overview]
Message-ID: <20160809144802.GI9175@cbox> (raw)
In-Reply-To: <20160809095429.13393-1-andre.przywara@arm.com>
On Tue, Aug 09, 2016 at 10:54:29AM +0100, Andre Przywara wrote:
> When userspace provides the doorbell address for an MSI to be
> injected into the guest, we find a KVM device which feels responsible.
> Lets check that this device is really an emulated ITS before we make
> real use of the container_of-ed pointer.
>
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> ---
> virt/kvm/arm/vgic/vgic-its.c | 25 +++++++++++++++++++++----
> 1 file changed, 21 insertions(+), 4 deletions(-)
>
> diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c
> index 18a6871..9aeb3a4 100644
> --- a/virt/kvm/arm/vgic/vgic-its.c
> +++ b/virt/kvm/arm/vgic/vgic-its.c
> @@ -471,6 +471,24 @@ static int vgic_its_trigger_msi(struct kvm *kvm, struct vgic_its *its,
> return 0;
> }
>
> +static struct vgic_io_device *vgic_get_its_iodev(struct kvm_io_device *dev)
> +{
> + struct vgic_io_device *iodev;
> +
> + if (!dev)
> + return NULL;
this feels defensive. Wouldn't it make more sense to check the return
of kvm_io_bus_get_dev where its' called, and then conditionally call
this function?
Otherwise:
Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org>
> +
> + if (dev->ops != &kvm_io_gic_ops)
> + return NULL;
> +
> + iodev = container_of(dev, struct vgic_io_device, dev);
> +
> + if (iodev->iodev_type != IODEV_ITS)
> + return NULL;
> +
> + return iodev;
> +}
> +
> /*
> * Queries the KVM IO bus framework to get the ITS pointer from the given
> * doorbell address.
> @@ -493,10 +511,9 @@ int vgic_its_inject_msi(struct kvm *kvm, struct kvm_msi *msi)
> address = (u64)msi->address_hi << 32 | msi->address_lo;
>
> kvm_io_dev = kvm_io_bus_get_dev(kvm, KVM_MMIO_BUS, address);
> - if (!kvm_io_dev)
> - return -ENODEV;
> -
> - iodev = container_of(kvm_io_dev, struct vgic_io_device, dev);
> + iodev = vgic_get_its_iodev(kvm_io_dev);
> + if (!iodev)
> + return -EINVAL;
>
> mutex_lock(&iodev->its->its_lock);
> ret = vgic_its_trigger_msi(kvm, iodev->its, msi->devid, msi->data);
> --
> 2.9.0
>
next prev parent reply other threads:[~2016-08-09 14:39 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-09 9:54 [PATCH] KVM: arm64: check for ITS device on MSI injection Andre Przywara
2016-08-09 9:54 ` Andre Przywara
2016-08-09 14:48 ` Christoffer Dall [this message]
2016-08-09 14:48 ` 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=20160809144802.GI9175@cbox \
--to=christoffer.dall@linaro.org \
--cc=andre.przywara@arm.com \
--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 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.