From: Christoffer Dall <christoffer.dall@linaro.org>
To: Andre Przywara <andre.przywara@arm.com>
Cc: kvm@vger.kernel.org, marc.zyngier@arm.com, pbonzini@redhat.com,
kvmarm@lists.cs.columbia.edu,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 10/12] KVM: arm/arm64: prepare GICv3 emulation to use kvm_io_bus MMIO handling
Date: Sat, 14 Mar 2015 15:39:57 +0100 [thread overview]
Message-ID: <20150314143957.GF10935@cbox> (raw)
In-Reply-To: <1426263012-22935-11-git-send-email-andre.przywara@arm.com>
On Fri, Mar 13, 2015 at 04:10:10PM +0000, Andre Przywara wrote:
> Using the framework provided by the recent vgic.c changes, we
> register a kvm_io_bus device on mapping the virtual GICv3 resources.
> The distributor mapping is pretty straight forward, but the
> redistributors need some more love, since they need to be tagged with
> the respective redistributor (read: VCPU) they are connected with.
> We use the kvm_io_bus framework to register two devices per VCPU, as
> each block is handled independently by the VGIC code.
>
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> ---
> include/kvm/arm_vgic.h | 1 +
> virt/kvm/arm/vgic-v3-emul.c | 32 +++++++++++++++++++++++++++++++-
> virt/kvm/arm/vgic.c | 14 ++++++++++++++
> 3 files changed, 46 insertions(+), 1 deletion(-)
>
> diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h
> index 74a4ac4..09fd324 100644
> --- a/include/kvm/arm_vgic.h
> +++ b/include/kvm/arm_vgic.h
> @@ -246,6 +246,7 @@ struct vgic_dist {
>
> struct vgic_vm_ops vm_ops;
> struct vgic_io_device dist_iodev;
> + struct vgic_io_device *redist_iodevs;
> };
>
> struct vgic_v2_cpu_if {
> diff --git a/virt/kvm/arm/vgic-v3-emul.c b/virt/kvm/arm/vgic-v3-emul.c
> index 14943e3..8a81c67 100644
> --- a/virt/kvm/arm/vgic-v3-emul.c
> +++ b/virt/kvm/arm/vgic-v3-emul.c
> @@ -766,6 +766,9 @@ static int vgic_v3_map_resources(struct kvm *kvm,
> {
> int ret = 0;
> struct vgic_dist *dist = &kvm->arch.vgic;
> + gpa_t rdbase = dist->vgic_redist_base;
> + struct vgic_io_device *iodevs = NULL;
> + int i;
>
> if (!irqchip_in_kernel(kvm))
> return 0;
> @@ -791,7 +794,34 @@ static int vgic_v3_map_resources(struct kvm *kvm,
> goto out;
> }
>
> - kvm->arch.vgic.ready = true;
> + ret = vgic_register_kvm_io_dev(kvm, dist->vgic_dist_base,
> + GIC_V3_DIST_SIZE, vgic_v3_dist_ranges,
> + -1, &dist->dist_iodev);
> + if (ret)
> + goto out;
> +
> + iodevs = kcalloc(dist->nr_cpus * 2, sizeof(iodevs[0]), GFP_KERNEL);
> + if (!iodevs) {
> + ret = -ENOMEM;
> + goto out;
> + }
> + for (i = 0; i < dist->nr_cpus; i++) {
> + ret = vgic_register_kvm_io_dev(kvm, rdbase,
> + SZ_64K, vgic_redist_ranges,
> + i, &iodevs[i * 2]);
> + if (ret)
> + goto out;
> + ret = vgic_register_kvm_io_dev(kvm, rdbase + SGI_BASE_OFFSET,
> + SZ_64K, vgic_redist_sgi_ranges,
> + i, &iodevs[i * 2 + 1]);
> + if (ret)
> + goto out;
> + rdbase += GIC_V3_REDIST_SIZE;
> + }
> +
> + dist->redist_iodevs = iodevs;
> + dist->ready = true;
> +
May be worth placing a comment in the error path that kvm_vgic_destroy
will clean up all registered kvm iodevs and free the allocated array.
> out:
> if (ret)
> kvm_vgic_destroy(kvm);
> diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c
> index b1dd717..f762738 100644
> --- a/virt/kvm/arm/vgic.c
> +++ b/virt/kvm/arm/vgic.c
> @@ -911,6 +911,8 @@ int vgic_register_kvm_io_dev(struct kvm *kvm, gpa_t base, int len,
> static void vgic_unregister_kvm_io_dev(struct kvm *kvm)
> {
> struct vgic_dist *dist = &kvm->arch.vgic;
> + struct vgic_io_device *iodevs;
> + int i;
>
> if (!dist || !kvm->buses[KVM_MMIO_BUS])
> return;
> @@ -919,6 +921,18 @@ static void vgic_unregister_kvm_io_dev(struct kvm *kvm)
> if (dist->dist_iodev.dev.ops)
> kvm_io_bus_unregister_dev(kvm, KVM_MMIO_BUS,
> &dist->dist_iodev.dev);
> +
> + iodevs = dist->redist_iodevs;
> + if (iodevs) {
> + for (i = 0; i < dist->nr_cpus * 2; i++) {
> + if (!iodevs[i].dev.ops)
> + continue;
this looks a bit strange because vgic_register_kvm_io_dev does not clear
the ops pointer if kvm_io_bus_register_dev fails... ?
> + kvm_io_bus_unregister_dev(kvm, KVM_MMIO_BUS,
> + &iodevs[i].dev);
> + }
> + kfree(iodevs);
> + dist->redist_iodevs = NULL;
> + }
> mutex_unlock(&kvm->slots_lock);
> }
>
> --
> 1.7.9.5
>
WARNING: multiple messages have this Message-ID (diff)
From: christoffer.dall@linaro.org (Christoffer Dall)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 10/12] KVM: arm/arm64: prepare GICv3 emulation to use kvm_io_bus MMIO handling
Date: Sat, 14 Mar 2015 15:39:57 +0100 [thread overview]
Message-ID: <20150314143957.GF10935@cbox> (raw)
In-Reply-To: <1426263012-22935-11-git-send-email-andre.przywara@arm.com>
On Fri, Mar 13, 2015 at 04:10:10PM +0000, Andre Przywara wrote:
> Using the framework provided by the recent vgic.c changes, we
> register a kvm_io_bus device on mapping the virtual GICv3 resources.
> The distributor mapping is pretty straight forward, but the
> redistributors need some more love, since they need to be tagged with
> the respective redistributor (read: VCPU) they are connected with.
> We use the kvm_io_bus framework to register two devices per VCPU, as
> each block is handled independently by the VGIC code.
>
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> ---
> include/kvm/arm_vgic.h | 1 +
> virt/kvm/arm/vgic-v3-emul.c | 32 +++++++++++++++++++++++++++++++-
> virt/kvm/arm/vgic.c | 14 ++++++++++++++
> 3 files changed, 46 insertions(+), 1 deletion(-)
>
> diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h
> index 74a4ac4..09fd324 100644
> --- a/include/kvm/arm_vgic.h
> +++ b/include/kvm/arm_vgic.h
> @@ -246,6 +246,7 @@ struct vgic_dist {
>
> struct vgic_vm_ops vm_ops;
> struct vgic_io_device dist_iodev;
> + struct vgic_io_device *redist_iodevs;
> };
>
> struct vgic_v2_cpu_if {
> diff --git a/virt/kvm/arm/vgic-v3-emul.c b/virt/kvm/arm/vgic-v3-emul.c
> index 14943e3..8a81c67 100644
> --- a/virt/kvm/arm/vgic-v3-emul.c
> +++ b/virt/kvm/arm/vgic-v3-emul.c
> @@ -766,6 +766,9 @@ static int vgic_v3_map_resources(struct kvm *kvm,
> {
> int ret = 0;
> struct vgic_dist *dist = &kvm->arch.vgic;
> + gpa_t rdbase = dist->vgic_redist_base;
> + struct vgic_io_device *iodevs = NULL;
> + int i;
>
> if (!irqchip_in_kernel(kvm))
> return 0;
> @@ -791,7 +794,34 @@ static int vgic_v3_map_resources(struct kvm *kvm,
> goto out;
> }
>
> - kvm->arch.vgic.ready = true;
> + ret = vgic_register_kvm_io_dev(kvm, dist->vgic_dist_base,
> + GIC_V3_DIST_SIZE, vgic_v3_dist_ranges,
> + -1, &dist->dist_iodev);
> + if (ret)
> + goto out;
> +
> + iodevs = kcalloc(dist->nr_cpus * 2, sizeof(iodevs[0]), GFP_KERNEL);
> + if (!iodevs) {
> + ret = -ENOMEM;
> + goto out;
> + }
> + for (i = 0; i < dist->nr_cpus; i++) {
> + ret = vgic_register_kvm_io_dev(kvm, rdbase,
> + SZ_64K, vgic_redist_ranges,
> + i, &iodevs[i * 2]);
> + if (ret)
> + goto out;
> + ret = vgic_register_kvm_io_dev(kvm, rdbase + SGI_BASE_OFFSET,
> + SZ_64K, vgic_redist_sgi_ranges,
> + i, &iodevs[i * 2 + 1]);
> + if (ret)
> + goto out;
> + rdbase += GIC_V3_REDIST_SIZE;
> + }
> +
> + dist->redist_iodevs = iodevs;
> + dist->ready = true;
> +
May be worth placing a comment in the error path that kvm_vgic_destroy
will clean up all registered kvm iodevs and free the allocated array.
> out:
> if (ret)
> kvm_vgic_destroy(kvm);
> diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c
> index b1dd717..f762738 100644
> --- a/virt/kvm/arm/vgic.c
> +++ b/virt/kvm/arm/vgic.c
> @@ -911,6 +911,8 @@ int vgic_register_kvm_io_dev(struct kvm *kvm, gpa_t base, int len,
> static void vgic_unregister_kvm_io_dev(struct kvm *kvm)
> {
> struct vgic_dist *dist = &kvm->arch.vgic;
> + struct vgic_io_device *iodevs;
> + int i;
>
> if (!dist || !kvm->buses[KVM_MMIO_BUS])
> return;
> @@ -919,6 +921,18 @@ static void vgic_unregister_kvm_io_dev(struct kvm *kvm)
> if (dist->dist_iodev.dev.ops)
> kvm_io_bus_unregister_dev(kvm, KVM_MMIO_BUS,
> &dist->dist_iodev.dev);
> +
> + iodevs = dist->redist_iodevs;
> + if (iodevs) {
> + for (i = 0; i < dist->nr_cpus * 2; i++) {
> + if (!iodevs[i].dev.ops)
> + continue;
this looks a bit strange because vgic_register_kvm_io_dev does not clear
the ops pointer if kvm_io_bus_register_dev fails... ?
> + kvm_io_bus_unregister_dev(kvm, KVM_MMIO_BUS,
> + &iodevs[i].dev);
> + }
> + kfree(iodevs);
> + dist->redist_iodevs = NULL;
> + }
> mutex_unlock(&kvm->slots_lock);
> }
>
> --
> 1.7.9.5
>
next prev parent reply other threads:[~2015-03-14 14:33 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-13 16:10 [PATCH 00/12] KVM: arm/arm64: move VGIC MMIO to kvm_io_bus Andre Przywara
2015-03-13 16:10 ` Andre Przywara
2015-03-13 16:10 ` [PATCH 01/12] KVM: Redesign kvm_io_bus_ API to pass VCPU structure to the callbacks Andre Przywara
2015-03-13 16:10 ` Andre Przywara
2015-03-14 14:43 ` Christoffer Dall
2015-03-14 14:43 ` Christoffer Dall
2015-03-13 16:10 ` [PATCH 02/12] KVM: move iodev.h from virt/kvm/ to include/kvm Andre Przywara
2015-03-13 16:10 ` Andre Przywara
2015-03-14 14:43 ` Christoffer Dall
2015-03-14 14:43 ` Christoffer Dall
2015-03-13 16:10 ` [PATCH 03/12] KVM: arm/arm64: remove now unneeded include directory from Makefile Andre Przywara
2015-03-13 16:10 ` Andre Przywara
2015-03-14 14:43 ` Christoffer Dall
2015-03-14 14:43 ` Christoffer Dall
2015-03-13 16:10 ` [PATCH 04/12] KVM: x86: " Andre Przywara
2015-03-13 16:10 ` Andre Przywara
2015-03-14 13:57 ` Christoffer Dall
2015-03-14 13:57 ` Christoffer Dall
2015-03-13 16:10 ` [PATCH 05/12] KVM: arm/arm64: rename struct kvm_mmio_range to vgic_io_range Andre Przywara
2015-03-13 16:10 ` Andre Przywara
2015-03-14 14:43 ` Christoffer Dall
2015-03-14 14:43 ` Christoffer Dall
2015-03-13 16:10 ` [PATCH 06/12] KVM: mark kvm->buses as empty once they were destroyed Andre Przywara
2015-03-13 16:10 ` Andre Przywara
2015-03-14 14:43 ` Christoffer Dall
2015-03-14 14:43 ` Christoffer Dall
2015-03-13 16:10 ` [PATCH 07/12] KVM: arm/arm64: simplify vgic_find_range() and callers Andre Przywara
2015-03-13 16:10 ` Andre Przywara
2015-03-14 14:44 ` Christoffer Dall
2015-03-14 14:44 ` Christoffer Dall
2015-03-13 16:10 ` [PATCH 08/12] KVM: arm/arm64: implement kvm_io_bus MMIO handling for the VGIC Andre Przywara
2015-03-13 16:10 ` Andre Przywara
2015-03-14 14:27 ` Christoffer Dall
2015-03-14 14:27 ` Christoffer Dall
2015-03-19 15:44 ` Andre Przywara
2015-03-19 15:44 ` Andre Przywara
2015-03-20 12:40 ` Andre Przywara
2015-03-20 12:40 ` Andre Przywara
2015-03-20 14:25 ` Christoffer Dall
2015-03-20 14:25 ` Christoffer Dall
2015-03-20 14:24 ` Christoffer Dall
2015-03-20 14:24 ` Christoffer Dall
2015-03-13 16:10 ` [PATCH 09/12] KVM: arm/arm64: prepare GICv2 emulation to be handled by kvm_io_bus Andre Przywara
2015-03-13 16:10 ` Andre Przywara
2015-03-14 14:30 ` Christoffer Dall
2015-03-14 14:30 ` Christoffer Dall
2015-03-17 18:02 ` Andre Przywara
2015-03-17 18:02 ` Andre Przywara
2015-03-17 18:51 ` Christoffer Dall
2015-03-17 18:51 ` Christoffer Dall
2015-03-13 16:10 ` [PATCH 10/12] KVM: arm/arm64: prepare GICv3 emulation to use kvm_io_bus MMIO handling Andre Przywara
2015-03-13 16:10 ` Andre Przywara
2015-03-14 14:39 ` Christoffer Dall [this message]
2015-03-14 14:39 ` Christoffer Dall
2015-03-13 16:10 ` [PATCH 11/12] KVM: ARM: on IO mem abort - route the call to KVM MMIO bus Andre Przywara
2015-03-13 16:10 ` Andre Przywara
2015-03-14 14:43 ` Christoffer Dall
2015-03-14 14:43 ` Christoffer Dall
2015-03-13 16:10 ` [PATCH 12/12] KVM: arm/arm64: remove now obsolete VGIC specific MMIO handling code Andre Przywara
2015-03-13 16:10 ` Andre Przywara
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=20150314143957.GF10935@cbox \
--to=christoffer.dall@linaro.org \
--cc=andre.przywara@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=marc.zyngier@arm.com \
--cc=pbonzini@redhat.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.