linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: christoffer.dall@linaro.org (Christoffer Dall)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 09/12] KVM: arm/arm64: prepare GICv2 emulation to be handled by kvm_io_bus
Date: Tue, 17 Mar 2015 19:51:18 +0100	[thread overview]
Message-ID: <20150317185118.GD26480@cbox> (raw)
In-Reply-To: <55086C41.9070209@arm.com>

On Tue, Mar 17, 2015 at 06:02:41PM +0000, Andre Przywara wrote:
> Hej,
> 
> On 14/03/15 14:30, Christoffer Dall wrote:
> > On Fri, Mar 13, 2015 at 04:10:09PM +0000, Andre Przywara wrote:
> >> Using the framework provided by the recent vgic.c changes we register
> >> a kvm_io_bus device when initializing the virtual GICv2.
> >>
> >> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> >> ---
> >>  include/kvm/arm_vgic.h      |    1 +
> >>  virt/kvm/arm/vgic-v2-emul.c |   13 +++++++++----
> >>  virt/kvm/arm/vgic.c         |   16 ++++++++++++++++
> >>  3 files changed, 26 insertions(+), 4 deletions(-)
> >>
> >> diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h
> >> index 4bfc6a3..74a4ac4 100644
> >> --- a/include/kvm/arm_vgic.h
> >> +++ b/include/kvm/arm_vgic.h
> >> @@ -245,6 +245,7 @@ struct vgic_dist {
> >>  	unsigned long		*irq_pending_on_cpu;
> >>  
> >>  	struct vgic_vm_ops	vm_ops;
> >> +	struct vgic_io_device	dist_iodev;
> >>  };
> >>  
> >>  struct vgic_v2_cpu_if {
> >> diff --git a/virt/kvm/arm/vgic-v2-emul.c b/virt/kvm/arm/vgic-v2-emul.c
> >> index 0defac6..6f685c9 100644
> >> --- a/virt/kvm/arm/vgic-v2-emul.c
> >> +++ b/virt/kvm/arm/vgic-v2-emul.c
> >> @@ -490,6 +490,7 @@ static bool vgic_v2_queue_sgi(struct kvm_vcpu *vcpu, int irq)
> >>  static int vgic_v2_map_resources(struct kvm *kvm,
> >>  				 const struct vgic_params *params)
> >>  {
> >> +	struct vgic_dist *dist = &kvm->arch.vgic;
> >>  	int ret = 0;
> >>  
> >>  	if (!irqchip_in_kernel(kvm))
> >> @@ -500,13 +501,17 @@ static int vgic_v2_map_resources(struct kvm *kvm,
> >>  	if (vgic_ready(kvm))
> >>  		goto out;
> >>  
> >> -	if (IS_VGIC_ADDR_UNDEF(kvm->arch.vgic.vgic_dist_base) ||
> >> -	    IS_VGIC_ADDR_UNDEF(kvm->arch.vgic.vgic_cpu_base)) {
> >> +	if (IS_VGIC_ADDR_UNDEF(dist->vgic_dist_base) ||
> >> +	    IS_VGIC_ADDR_UNDEF(dist->vgic_cpu_base)) {
> >>  		kvm_err("Need to set vgic cpu and dist addresses first\n");
> >>  		ret = -ENXIO;
> >>  		goto out;
> >>  	}
> >>  
> >> +	vgic_register_kvm_io_dev(kvm, dist->vgic_dist_base,
> >> +				 KVM_VGIC_V2_DIST_SIZE,
> >> +				 vgic_dist_ranges, -1, &dist->dist_iodev);
> >> +
> >>  	/*
> >>  	 * Initialize the vgic if this hasn't already been done on demand by
> >>  	 * accessing the vgic state from userspace.
> >> @@ -517,7 +522,7 @@ static int vgic_v2_map_resources(struct kvm *kvm,
> >>  		goto out;
> >>  	}
> >>  
> >> -	ret = kvm_phys_addr_ioremap(kvm, kvm->arch.vgic.vgic_cpu_base,
> >> +	ret = kvm_phys_addr_ioremap(kvm, dist->vgic_cpu_base,
> >>  				    params->vcpu_base, KVM_VGIC_V2_CPU_SIZE,
> >>  				    true);
> >>  	if (ret) {
> >> @@ -525,7 +530,7 @@ static int vgic_v2_map_resources(struct kvm *kvm,
> >>  		goto out;
> >>  	}
> >>  
> >> -	kvm->arch.vgic.ready = true;
> >> +	dist->ready = true;
> >>  out:
> >>  	if (ret)
> >>  		kvm_vgic_destroy(kvm);
> >> diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c
> >> index 71389b8..b1dd717 100644
> >> --- a/virt/kvm/arm/vgic.c
> >> +++ b/virt/kvm/arm/vgic.c
> >> @@ -908,6 +908,20 @@ int vgic_register_kvm_io_dev(struct kvm *kvm, gpa_t base, int len,
> >>  	return 0;
> >>  }
> >>  
> >> +static void vgic_unregister_kvm_io_dev(struct kvm *kvm)
> >> +{
> >> +	struct vgic_dist *dist = &kvm->arch.vgic;
> >> +
> >> +	if (!dist || !kvm->buses[KVM_MMIO_BUS])
> >> +		return;
> >> +
> >> +	mutex_lock(&kvm->slots_lock);
> >> +	if (dist->dist_iodev.dev.ops)
> >> +		kvm_io_bus_unregister_dev(kvm, KVM_MMIO_BUS,
> >> +					  &dist->dist_iodev.dev);
> > 
> > why are we only unregisttering the iodev when we have ops?
> 
> Because vgic_unregister_kvm_io_dev() is called by kvm_vgic_destroy(),
> which we call on some occasions during vgic_init() when we encounter an
> error. There is quite a window of cases where the kvm_io_bus devices
> haven't been registered yet, so we shouldn't try to unregister them at
> this place. Using the .ops parameter seemed like an elegant way to
> detect this case.
> Does that make sense? Or have I missed something?
> 
That's ok, but it derserves a comment explaining this.

-Christoffer

  reply	other threads:[~2015-03-17 18:51 UTC|newest]

Thread overview: 30+ 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 ` [PATCH 01/12] KVM: Redesign kvm_io_bus_ API to pass VCPU structure to the callbacks Andre Przywara
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-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-14 14:43   ` Christoffer Dall
2015-03-13 16:10 ` [PATCH 04/12] KVM: x86: " Andre Przywara
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-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-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-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-14 14:27   ` Christoffer Dall
2015-03-19 15:44     ` Andre Przywara
2015-03-20 12:40       ` Andre Przywara
2015-03-20 14:25         ` 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-14 14:30   ` Christoffer Dall
2015-03-17 18:02     ` Andre Przywara
2015-03-17 18:51       ` Christoffer Dall [this message]
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-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-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

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=20150317185118.GD26480@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).