All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: "Wu, Feng" <feng.wu@intel.com>
Cc: Eric Auger <eric.auger@linaro.org>,
	Avi Kivity <avi.kivity@gmail.com>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"pbonzini@redhat.com" <pbonzini@redhat.com>,
	"mtosatti@redhat.com" <mtosatti@redhat.com>,
	Joerg Roedel <joro@8bytes.org>
Subject: Re: [v4 08/16] KVM: kvm-vfio: User API for IRQ forwarding
Date: Mon, 29 Jun 2015 09:18:37 -0600	[thread overview]
Message-ID: <1435591117.3700.519.camel@redhat.com> (raw)
In-Reply-To: <E959C4978C3B6342920538CF579893F0025D800A@SHSMSX104.ccr.corp.intel.com>

On Mon, 2015-06-29 at 13:27 +0000, Wu, Feng wrote:
> 
> 
> > -----Original Message-----
> > From: Alex Williamson [mailto:alex.williamson@redhat.com]
> > Sent: Friday, June 19, 2015 4:04 AM
> > To: Wu, Feng
> > Cc: Eric Auger; Avi Kivity; kvm@vger.kernel.org; linux-kernel@vger.kernel.org;
> > pbonzini@redhat.com; mtosatti@redhat.com; Joerg Roedel
> > Subject: Re: [v4 08/16] KVM: kvm-vfio: User API for IRQ forwarding
> > 
> > [Adding Joerg since he was part of this original idea]
> > 
> > 
> > There are plenty of details to be filled in, but I think the basics
> > looks something like the code below.  The IRQ bypass manager just
> > defines a pair of structures, one for interrupt producers and one for
> > interrupt consumers.  I'm certain that we'll need more callbacks than
> > I've defined below, but figuring out what those should be for the best
> > abstraction is the hardest part of this idea.  The manager provides both
> > registration and de-registration interfaces for both types of objects
> > and keeps lists for each, protected by a lock.  The manager doesn't even
> > really need to know what the match token is, but I assume for our
> > purposes it will be an eventfd_ctx.
> > 
> > On the vfio side, the producer struct would be embedded in the
> > vfio_pci_irq_ctx struct.  KVM would probably embed the consumer struct
> > in _irqfd.  As I've coded below, the IRQ bypass manager calls the
> > consumer callbacks, so the producer struct would need fields or
> > callbacks to provide the consumer the info it needs.  AIUI the Posted
> > Interrupt model, VFIO only needs to provide data to the consumer.  For
> > IRQ Forwarding, I think the producer needs to be informed when bypass is
> > active to model the incoming interrupt as edge vs level.
> > 
> > I've prototyped the base IRQ bypass manager here as static, but I don't
> > see any reason it couldn't be a module that's loaded by dependency when
> > either vfio-pci or kvm-intel is loaded (or other producer/consumer
> > objects).
> > 
> > Is this a reasonable starting point to craft the additional fields and
> > callbacks and interaction of who calls who that we need to support
> > Posted Interrupts and IRQ Forwarding?  Is the AMD version of this still
> > alive?  Thanks,
> > 
> > Alex
> > 
> > diff --git a/arch/x86/kvm/Kconfig b/arch/x86/kvm/Kconfig
> > index 413a7bf..22f6fcb 100644
> > --- a/arch/x86/kvm/Kconfig
> > +++ b/arch/x86/kvm/Kconfig
> > @@ -61,6 +61,7 @@ config KVM_INTEL
> >  	depends on KVM
> >  	# for perf_guest_get_msrs():
> >  	depends on CPU_SUP_INTEL
> > +	select IRQ_BYPASS_MANAGER
> >  	---help---
> >  	  Provides support for KVM on Intel processors equipped with the VT
> >  	  extensions.
> > diff --git a/drivers/vfio/pci/Kconfig b/drivers/vfio/pci/Kconfig
> > index 579d83b..02912f1 100644
> > --- a/drivers/vfio/pci/Kconfig
> > +++ b/drivers/vfio/pci/Kconfig
> > @@ -2,6 +2,7 @@ config VFIO_PCI
> >  	tristate "VFIO support for PCI devices"
> >  	depends on VFIO && PCI && EVENTFD
> >  	select VFIO_VIRQFD
> > +	select IRQ_BYPASS_MANAGER
> >  	help
> >  	  Support for the PCI VFIO bus driver.  This is required to make
> >  	  use of PCI drivers using the VFIO framework.
> > diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c
> > index 1f577b4..4e053be 100644
> > --- a/drivers/vfio/pci/vfio_pci_intrs.c
> > +++ b/drivers/vfio/pci/vfio_pci_intrs.c
> > @@ -181,6 +181,7 @@ static int vfio_intx_set_signal(struct vfio_pci_device
> > *vdev, int fd)
> > 
> >  	if (vdev->ctx[0].trigger) {
> >  		free_irq(pdev->irq, vdev);
> > +		/* irq_bypass_unregister_producer(); */
> >  		kfree(vdev->ctx[0].name);
> >  		eventfd_ctx_put(vdev->ctx[0].trigger);
> >  		vdev->ctx[0].trigger = NULL;
> > @@ -214,6 +215,8 @@ static int vfio_intx_set_signal(struct vfio_pci_device
> > *vdev, int fd)
> >  		return ret;
> >  	}
> > 
> > +	/* irq_bypass_register_producer(); */
> > +
> >  	/*
> >  	 * INTx disable will stick across the new irq setup,
> >  	 * disable_irq won't.
> > @@ -319,6 +322,7 @@ static int vfio_msi_set_vector_signal(struct
> > vfio_pci_device *vdev,
> > 
> >  	if (vdev->ctx[vector].trigger) {
> >  		free_irq(irq, vdev->ctx[vector].trigger);
> > +		/* irq_bypass_unregister_producer(); */
> >  		kfree(vdev->ctx[vector].name);
> >  		eventfd_ctx_put(vdev->ctx[vector].trigger);
> >  		vdev->ctx[vector].trigger = NULL;
> > @@ -360,6 +364,8 @@ static int vfio_msi_set_vector_signal(struct
> > vfio_pci_device *vdev,
> >  		return ret;
> >  	}
> > 
> > +	/* irq_bypass_register_producer(); */
> > +
> >  	vdev->ctx[vector].trigger = trigger;
> > 
> >  	return 0;
> > diff --git a/include/linux/irqbypass.h b/include/linux/irqbypass.h
> > new file mode 100644
> > index 0000000..718508e
> > --- /dev/null
> > +++ b/include/linux/irqbypass.h
> > @@ -0,0 +1,23 @@
> > +#ifndef IRQBYPASS_H
> > +#define IRQBYPASS_H
> > +
> > +#include <linux/list.h>
> > +
> > +struct irq_bypass_producer {
> > +	struct list_head node;
> > +	void *token;
> > +	/* TBD */
> > +};
> > +
> > +struct irq_bypass_consumer {
> > +	struct list_head node;
> > +	void *token;
> > +	void (*add_producer)(struct irq_bypass_producer *);
> > +	void (*del_producer)(struct irq_bypass_producer *);
> 
> These two callbacks should be common function, for PI, I need to add
> something specific to x86, such as, updating the associated IRTE, how
> should I do for this?

These are function pointers, the consumer (kvm in this case) can
populate them with whatever implementation it needs.  The details of
updating the IRTE should be completely hidden from this interface.  This
interface only handles identifying matches between producer and consumer
and providing an API for the handshake.  Feel free to use more
appropriate callbacks and structure fields, these are only meant as a
rough sketch of the idea and possible interaction, but please keep
layering in mind to make a generic interface.

> > +};
> > +
> > +int irq_bypass_register_producer(struct irq_bypass_producer *);
> > +void irq_bypass_unregister_producer(struct irq_bypass_producer *);
> > +int irq_bypass_register_consumer(struct irq_bypass_consumer *);
> > +void irq_bypass_unregister_consumer(struct irq_bypass_consumer *);
> > +#endif /* IRQBYPASS_H */
> > diff --git a/kernel/irq/Kconfig b/kernel/irq/Kconfig
> > index 9a76e3b..4502cdc 100644
> > --- a/kernel/irq/Kconfig
> > +++ b/kernel/irq/Kconfig
> > @@ -100,4 +100,7 @@ config SPARSE_IRQ
> > 
> >  	  If you don't know what to do here, say N.
> > 
> > +config IRQ_BYPASS_MANAGER
> > +	bool
> > +
> >  endmenu
> > diff --git a/kernel/irq/Makefile b/kernel/irq/Makefile
> > index d121235..a30ed77 100644
> > --- a/kernel/irq/Makefile
> > +++ b/kernel/irq/Makefile
> > @@ -7,3 +7,4 @@ obj-$(CONFIG_PROC_FS) += proc.o
> >  obj-$(CONFIG_GENERIC_PENDING_IRQ) += migration.o
> >  obj-$(CONFIG_PM_SLEEP) += pm.o
> >  obj-$(CONFIG_GENERIC_MSI_IRQ) += msi.o
> > +obj-$(CONFIG_IRQ_BYPASS_MANAGER) += bypass.o
> > diff --git a/kernel/irq/bypass.c b/kernel/irq/bypass.c
> > new file mode 100644
> > index 0000000..5d0f92b
> > --- /dev/null
> > +++ b/kernel/irq/bypass.c
> 
> Is it better to put this code here or in vfio folder?

What about it is specific to vfio?  Both vfio and kvm are clients to the
interface, but I don't think we want to add any barriers that restrict
it to that pair.  I think we originally thought of this as an IOMMU
service, so drivers/iommu might be another possible home for it.
Thanks,

Alex


  reply	other threads:[~2015-06-29 15:18 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-11 10:51 [v4 00/16] Add VT-d Posted-Interrupts support Feng Wu
2015-06-11 10:51 ` [v4 01/16] KVM: Extend struct pi_desc for VT-d Posted-Interrupts Feng Wu
2015-06-23 15:49   ` Paolo Bonzini
2015-06-24  5:42     ` Wu, Feng
2015-06-24  8:46       ` Paolo Bonzini
2015-06-11 10:51 ` [v4 02/16] KVM: Add some helper functions for Posted-Interrupts Feng Wu
2015-06-11 10:51 ` [v4 03/16] KVM: Define a new interface kvm_intr_is_single_vcpu() Feng Wu
2015-06-11 10:51 ` [v4 04/16] KVM: Get Posted-Interrupts descriptor address from struct kvm_vcpu Feng Wu
2015-06-11 10:51 ` [v4 05/16] KVM: Add interfaces to control PI outside vmx Feng Wu
2015-06-11 10:51 ` [v4 06/16] KVM: Make struct kvm_irq_routing_table accessible Feng Wu
2015-06-11 10:51 ` [v4 07/16] KVM: make kvm_set_msi_irq() public Feng Wu
2015-06-11 10:51 ` [v4 08/16] KVM: kvm-vfio: User API for IRQ forwarding Feng Wu
2015-06-11 13:37   ` Eric Auger
2015-06-12  0:20     ` Wu, Feng
2015-06-11 19:59   ` Avi Kivity
2015-06-12  0:23     ` Wu, Feng
2015-06-12 15:41       ` Alex Williamson
2015-06-12 18:48         ` Avi Kivity
2015-06-12 19:03           ` Alex Williamson
2015-06-15  6:42             ` Wu, Feng
2015-06-15  6:42               ` Wu, Feng
2015-06-15 16:17             ` Eric Auger
2015-06-15 16:45               ` Alex Williamson
2015-06-18  9:16                 ` Wu, Feng
2015-06-18  9:16                   ` Wu, Feng
2015-06-18 20:04                   ` Alex Williamson
2015-06-24 15:46                     ` Joerg Roedel
2015-06-25  1:54                       ` Wu, Feng
2015-06-25  9:37                       ` Wu, Feng
2015-06-25 15:11                         ` Alex Williamson
2015-06-29  9:06                           ` Joerg Roedel
2015-06-29  9:14                             ` Wu, Feng
2015-06-29  9:22                               ` Joerg Roedel
2015-06-29 13:01                                 ` Wu, Feng
2015-06-29 13:27                     ` Wu, Feng
2015-06-29 13:27                       ` Wu, Feng
2015-06-29 15:18                       ` Alex Williamson [this message]
2015-06-24 15:50               ` Joerg Roedel
2015-06-24 16:25                 ` Eric Auger
2015-06-24 19:49                   ` Alex Williamson
2015-06-25  1:57                     ` Wu, Feng
2015-06-25  1:57                       ` Wu, Feng
2015-06-11 10:51 ` [v4 09/16] VFIO: external user API for interaction Feng Wu
2015-06-11 10:51 ` [v4 10/16] KVM: kvm-vfio: wrappers to VFIO external API device helpers Feng Wu
2015-06-11 10:51 ` [v4 11/16] KVM: kvm-vfio: User API for VT-d Posted-Interrupts Feng Wu
2015-06-11 10:51 ` [v4 12/16] KVM: kvm-vfio: implement the VFIO skeleton " Feng Wu
2015-06-11 17:15   ` Alex Williamson
2015-06-12  4:54     ` Wu, Feng
2015-06-12  4:54       ` Wu, Feng
2015-06-12 14:51       ` Alex Williamson
2015-06-23 16:00         ` Paolo Bonzini
2015-06-11 10:51 ` [v4 13/16] KVM: x86: kvm-vfio: VT-d posted-interrupts setup Feng Wu
2015-06-11 17:16   ` Alex Williamson
2015-06-12  4:58     ` Wu, Feng
2015-06-12  4:58       ` Wu, Feng
2015-06-11 10:51 ` [v4 14/16] KVM: Update Posted-Interrupts Descriptor when vCPU is preempted Feng Wu
2015-06-11 10:51 ` [v4 15/16] KVM: Update Posted-Interrupts Descriptor when vCPU is blocked Feng Wu
2015-06-23 16:05   ` Paolo Bonzini
2015-06-11 10:51 ` [v4 16/16] KVM: Warn if 'SN' is set during posting interrupts by software Feng Wu

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=1435591117.3700.519.camel@redhat.com \
    --to=alex.williamson@redhat.com \
    --cc=avi.kivity@gmail.com \
    --cc=eric.auger@linaro.org \
    --cc=feng.wu@intel.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mtosatti@redhat.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.