public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Scott Wood <scottwood@freescale.com>
To: Alexander Graf <agraf@suse.de>
Cc: <kvm-ppc@vger.kernel.org>,
	"kvm@vger.kernel.org mailing list" <kvm@vger.kernel.org>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	Gleb Natapov <gleb@redhat.com>
Subject: Re: [PATCH 15/17] KVM: PPC: Support irq routing and irqfd for in-kernel MPIC
Date: Thu, 18 Apr 2013 16:39:46 -0500	[thread overview]
Message-ID: <1366321186.9938.13@snotra> (raw)
In-Reply-To: <1366294317-25529-16-git-send-email-agraf@suse.de> (from agraf@suse.de on Thu Apr 18 09:11:55 2013)

On 04/18/2013 09:11:55 AM, Alexander Graf wrote:
> Now that all the irq routing and irqfd pieces are generic, we can  
> expose
> real irqchip support to all of KVM's internal helpers.
> 
> This allows us to use irqfd with the in-kernel MPIC.
> 
> Signed-off-by: Alexander Graf <agraf@suse.de>
> ---
>  arch/powerpc/include/asm/kvm_host.h |    7 ++
>  arch/powerpc/include/uapi/asm/kvm.h |    1 +
>  arch/powerpc/kvm/Kconfig            |    3 +
>  arch/powerpc/kvm/Makefile           |    1 +
>  arch/powerpc/kvm/irq.h              |   17 ++++++
>  arch/powerpc/kvm/mpic.c             |  106  
> +++++++++++++++++++++++++++++++++++
>  6 files changed, 135 insertions(+), 0 deletions(-)
>  create mode 100644 arch/powerpc/kvm/irq.h
> 
> diff --git a/arch/powerpc/include/asm/kvm_host.h  
> b/arch/powerpc/include/asm/kvm_host.h
> index 36368c9..d5fbb4b 100644
> --- a/arch/powerpc/include/asm/kvm_host.h
> +++ b/arch/powerpc/include/asm/kvm_host.h
> @@ -44,6 +44,10 @@
>  #define KVM_COALESCED_MMIO_PAGE_OFFSET 1
>  #endif
> 
> +/* These values are internal and can be increased later */
> +#define KVM_NR_IRQCHIPS          1
> +#define KVM_IRQCHIP_NUM_PINS     256
> +
>  #if !defined(CONFIG_KVM_440)
>  #include <linux/mmu_notifier.h>
> 
> @@ -256,6 +260,9 @@ struct kvm_arch {
>  #ifdef CONFIG_PPC_BOOK3S_64
>  	struct list_head spapr_tce_tables;
>  #endif
> +#ifdef CONFIG_KVM_MPIC
> +	void *mpic;
> +#endif
>  };

This can be "struct openpic *mpic" -- we already do this in the vcpu.

> diff --git a/arch/powerpc/kvm/irq.h b/arch/powerpc/kvm/irq.h
> new file mode 100644
> index 0000000..f1e27fd
> --- /dev/null
> +++ b/arch/powerpc/kvm/irq.h
> @@ -0,0 +1,17 @@
> +#ifndef __IRQ_H
> +#define __IRQ_H
> +
> +#include <linux/kvm_host.h>
> +
> +static inline int irqchip_in_kernel(struct kvm *kvm)
> +{
> +	int ret = 0;
> +
> +#ifdef CONFIG_KVM_MPIC
> +	ret = ret || (kvm->arch.mpic != NULL);
> +#endif
> +	smp_rmb();
> +	return ret;
> +}

Couldn't we just set a non-irqchip-specific bool?  Though eventually  
this
shouldn't be needed at all -- instead the check would be "does the
requested irqchip fd exist and refer to something that exposes an  
irqchip
interface"?

The rmb needs documentation.  I don't see a corresponding wmb before
writing to kvm->arch.mpic.

> diff --git a/arch/powerpc/kvm/mpic.c b/arch/powerpc/kvm/mpic.c
> index b1ae02d..c8de2f2 100644
> --- a/arch/powerpc/kvm/mpic.c
> +++ b/arch/powerpc/kvm/mpic.c
> @@ -1087,6 +1087,8 @@ static int openpic_cpu_write_internal(void  
> *opaque, gpa_t addr,
>  		}
> 
>  		IRQ_resetbit(&dst->servicing, s_IRQ);
> +		/* Notify listeners that the IRQ is over */
> +		kvm_notify_acked_irq(opp->kvm, 0, s_IRQ);

I don't think we want to call that with the lock held -- it looks like  
it
can call back into kvm_set_irq.  In our old internal version I waited
until the end of the EOI code, and called the notify function with the
lock dropped temporarily.

>  		/* Set up next servicing IRQ */
>  		s_IRQ = IRQ_get_next(opp, &dst->servicing);
>  		/* Check queued interrupts. */
> @@ -1639,14 +1641,42 @@ static void mpic_destroy(struct kvm_device  
> *dev)
>  		unmap_mmio(opp);
>  	}
> 
> +	dev->kvm->arch.mpic = NULL;
>  	kfree(opp);
>  }
> 
> +static int mpic_set_default_irq_routing(struct openpic *opp)
> +{
> +	int i;
> +	struct kvm_irq_routing_entry *routing;
> +
> +	/* XXX be more dynamic if we ever want to support multiple MPIC  
> chips */
> +	routing = kzalloc((sizeof(*routing) * opp->nb_irqs),  
> GFP_KERNEL);
> +	if (!routing)
> +		return -ENOMEM;
> +
> +	for (i = 0; i < opp->nb_irqs; i++) {
> +		routing[i].gsi = i;
> +		routing[i].type = KVM_IRQ_ROUTING_IRQCHIP;
> +		routing[i].u.irqchip.irqchip = 0;
> +		routing[i].u.irqchip.pin = i;
> +	}
> +
> +	kvm_set_irq_routing(opp->kvm, routing, opp->nb_irqs, 0);
> +
> +	kfree(routing);
> +	return 0;
> +}

Do we really want any default routes?  There's no platform notion of GSI
here, so how is userspace to know how the kernel set it up (or what GSIs
are free to be used for new routes) -- other than the "read the code"
answer I got when I asked about x86?  :-P

> +int kvm_set_routing_entry(struct kvm_irq_routing_table *rt,
> +			  struct kvm_kernel_irq_routing_entry *e,
> +			  const struct kvm_irq_routing_entry *ue)
> +{
> +	int r = -EINVAL;
> +
> +	switch (ue->type) {
> +	case KVM_IRQ_ROUTING_IRQCHIP:
> +		e->set = mpic_set_irq;
> +		e->irqchip.irqchip = ue->u.irqchip.irqchip;
> +		e->irqchip.pin = ue->u.irqchip.pin;
> +		if (e->irqchip.pin >= KVM_IRQCHIP_NUM_PINS)
> +			goto out;
> +		rt->chip[ue->u.irqchip.irqchip][e->irqchip.pin] =  
> ue->gsi;
> +		break;
> +	case KVM_IRQ_ROUTING_MSI:
> +		e->set = kvm_set_msi;
> +		e->msi.address_lo = ue->u.msi.address_lo;
> +		e->msi.address_hi = ue->u.msi.address_hi;
> +		e->msi.data = ue->u.msi.data;
> +		break;
> +	default:
> +		goto out;
> +	}
> +
> +	r = 0;
> +out:
> +	return r;
> +}

How would one create a route for IPIs, timers, etc (we have had  
customers
wanting to assign those to KVM guests)?  What about error interrupts on
MPIC 4.2?  How are you defining the "pin" field for MPIC?  Shouldn't
there be an API documentation update for this?

We also need to document whach irqchip means, if we want to reserve the
ability to use it in the future -- otherwise userspace could fill in any
old junk there and we'd need to retain compatibility.  It should  
probably
be the fd of the MPIC.

It looks like you only support having one type of irqchip built into
the kernel at a time?  That may be OK for now given the existing
restrictions for building KVM, but it should be noted as a
limitation/TODO.

BTW, thanks for taking this on -- it would have taken me a while to
digest the existing code.

-Scott

  reply	other threads:[~2013-04-18 21:39 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-18 14:11 [PATCH 00/17] KVM: PPC: In-kernel MPIC support with irqfd Alexander Graf
2013-04-18 14:11 ` [PATCH 01/17] KVM: Add KVM_IRQCHIP_NUM_PINS in addition to KVM_IOAPIC_NUM_PINS Alexander Graf
2013-04-18 14:11 ` [PATCH 02/17] KVM: Introduce CONFIG_HAVE_KVM_IRQ_ROUTING Alexander Graf
2013-04-18 14:11 ` [PATCH 03/17] KVM: Drop __KVM_HAVE_IOAPIC condition on irq routing Alexander Graf
2013-04-18 14:11 ` [PATCH 04/17] KVM: Remove kvm_get_intr_delivery_bitmask Alexander Graf
2013-04-18 14:11 ` [PATCH 05/17] KVM: Move irq routing to generic code Alexander Graf
2013-04-18 14:11 ` [PATCH 06/17] KVM: Extract generic irqchip logic into irqchip.c Alexander Graf
2013-04-18 14:11 ` [PATCH 07/17] KVM: Move irq routing setup to irqchip.c Alexander Graf
2013-04-18 14:11 ` [PATCH 08/17] KVM: Move irqfd resample cap handling to generic code Alexander Graf
2013-04-18 14:11 ` [PATCH 09/17] kvm: add device control API Alexander Graf
2013-04-18 14:11 ` [PATCH 10/17] kvm/ppc/mpic: import hw/openpic.c from QEMU Alexander Graf
2013-04-18 14:11 ` [PATCH 11/17] kvm/ppc/mpic: remove some obviously unneeded code Alexander Graf
2013-04-18 14:11 ` [PATCH 12/17] kvm/ppc/mpic: adapt to kernel style and environment Alexander Graf
2013-04-18 14:11 ` [PATCH 13/17] kvm/ppc/mpic: in-kernel MPIC emulation Alexander Graf
2013-04-18 14:11 ` [PATCH 14/17] kvm/ppc/mpic: add KVM_CAP_IRQ_MPIC Alexander Graf
2013-04-18 14:11 ` [PATCH 15/17] KVM: PPC: Support irq routing and irqfd for in-kernel MPIC Alexander Graf
2013-04-18 21:39   ` Scott Wood [this message]
2013-04-19  0:15     ` Alexander Graf
2013-04-19  0:50       ` Scott Wood
2013-04-19  1:09         ` Alexander Graf
2013-04-19  1:37           ` Scott Wood
2013-04-22 23:31       ` Scott Wood
2013-04-18 14:11 ` [PATCH 16/17] KVM: PPC: MPIC: Add support for KVM_IRQ_LINE Alexander Graf
2013-04-18 14:11 ` [PATCH 17/17] KVM: PPC: MPIC: Restrict to e500 platforms Alexander Graf
2013-04-18 14:29   ` Scott Wood
2013-04-18 14:52     ` Alexander Graf
  -- strict thread matches above, loose matches on Subject: below --
2013-04-19 14:06 [PATCH 00/17] KVM: PPC: In-kernel MPIC support with irqfd v3 Alexander Graf
2013-04-19 14:06 ` [PATCH 15/17] KVM: PPC: Support irq routing and irqfd for in-kernel MPIC Alexander Graf
2013-04-19 18:02   ` Scott Wood
2013-04-25  9:58     ` Alexander Graf
2013-04-25 16:53       ` Scott Wood
2013-04-23  6:38   ` Paul Mackerras
2013-04-25 10:02     ` Alexander Graf

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=1366321186.9938.13@snotra \
    --to=scottwood@freescale.com \
    --cc=agraf@suse.de \
    --cc=gleb@redhat.com \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox