irq bypass interface implementation for VT-d Posted-interrupts
Subsystems (4)
cover irq bypass interface implementation for VT-d Posted-interrupts
This series is based on Alex and Eric's irq bypass manager framework. To make things clear, I only send out the patches related to irq bypass manager, the purpose here is to show how certain callbacks are used in VT-d PI and help to improve the irqbypass manager itself.
Feng Wu (5):
vfio: Register/unregister irq_bypass_producer
KVM: x86: Update IRTE for posted-interrupts
KVM: Add pointer to 'struct irq_bypass_produce' in 'kvm_kernel_irqfd'
KVM: x86: Add arch specific routines for irqbypass manager Call irqbypass update routine when updating irqfd
arch/x86/kvm/Kconfig | 1 + arch/x86/kvm/x86.c | 128 ++++++++++++++++++++++++++++++++++++ drivers/vfio/pci/vfio_pci_intrs.c | 8 ++- drivers/vfio/pci/vfio_pci_private.h | 2 + include/linux/kvm_irqfd.h | 1 + virt/kvm/eventfd.c | 4 +- 6 files changed, 141 insertions(+), 3 deletions(-)
Signature · 1 line
2.1.0
RFC 1/5 vfio: Register/unregister irq_bypass_producer
This patch adds the registration/unregistration of an irq_bypass_producer for MSI/MSIx on vfio pci devices.
--- drivers/vfio/pci/vfio_pci_intrs.c | 8 ++++++-- drivers/vfio/pci/vfio_pci_private.h | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-)
drivers/vfio/pci/vfio_pci_intrs.c +6 -2
@@ -322,7 +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(); */ +irq_bypass_unregister_producer (&vdev->ctx[vector].producer);kfree (vdev->ctx[vector].name);eventfd_ctx_put (vdev->ctx[vector].trigger); vdev->ctx[vector].trigger =NULL ;
@@ -364,7 +364,11 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_device *vdev,return ret; } -/* irq_bypass_register_producer(); */ +INIT_LIST_HEAD (&vdev->ctx[vector].producer.node); + vdev->ctx[vector].producer.token = trigger; + vdev->ctx[vector].producer.irq = irq; + ret =irq_bypass_register_producer (&vdev->ctx[vector].producer); +WARN_ON (ret); vdev->ctx[vector].trigger = trigger;
drivers/vfio/pci/vfio_pci_private.h +2 -0
@@ -13,6 +13,7 @@#include <linux/mutex.h> #include <linux/pci.h> +#include <linux/irqbypass.h> #ifndef VFIO_PCI_PRIVATE_H #define VFIO_PCI_PRIVATE_H
@@ -29,6 +30,7 @@ struct vfio_pci_irq_ctx {struct virqfd *mask;char *name;bool masked; +struct irq_bypass_producer producer; };struct vfio_pci_device {
Signature · 1 line
2.1.0
RFC 2/5 KVM: x86: Update IRTE for posted-interrupts
In reply to Feng WuThis patch adds the routine to update IRTE for posted-interrupts when guest changes the interrupt configuration.
--- arch/x86/kvm/x86.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+)
arch/x86/kvm/x86.c +73 -0
@@ -63,6 +63,7 @@#include <asm/fpu/internal.h> /* Ugh! */ #include <asm/pvclock.h> #include <asm/div64.h> +#include <asm/irq_remapping.h> #define MAX_IO_MSRS 256#define KVM_MAX_MCE_BANKS 32
@@ -7950,6 +7951,78 @@ bool kvm_arch_has_noncoherent_dma(struct kvm *kvm) }EXPORT_SYMBOL_GPL (kvm_arch_has_noncoherent_dma); +/* +* kvm_arch_update_pi_irte - set IRTE for Posted-Interrupts +* +* @kvm: kvm +* @host_irq: host irq of the interrupt +* @guest_irq: gsi of the interrupt +* @set: set or unset PI +* returns 0 on success, < 0 on failure +*/ +int kvm_arch_update_pi_irte (struct kvm *kvm,unsigned int host_irq, +uint32_t guest_irq,bool set) +{ +struct kvm_kernel_irq_routing_entry *e; +struct kvm_irq_routing_table *irq_rt; +struct kvm_lapic_irq irq; +struct kvm_vcpu *vcpu; +struct vcpu_data vcpu_info; +int idx, ret = -EINVAL ; + +if (!irq_remapping_cap (IRQ_POSTING_CAP )) +return 0 ; + + idx =srcu_read_lock (&kvm->irq_srcu); + irq_rt =srcu_dereference (kvm->irq_routing, &kvm->irq_srcu); +BUG_ON (guest_irq >= irq_rt->nr_rt_entries); + +hlist_for_each_entry (e, &irq_rt->map[guest_irq], link) { +if (e->type !=KVM_IRQ_ROUTING_MSI ) +continue ; +/* +* VT-d PI cannot support posting multicast/broadcast +* interrupts to a VCPU, we still use interrupt remapping +* for these kind of interrupts. +* +* For lowest-priority interrupts, we only support +* those with single CPU as the destination, e.g. user +* configures the interrupts via /proc/irq or uses +* irqbalance to make the interrupts single-CPU. +* +* We will support full lowest-priority interrupt later. +* +*/ + +kvm_set_msi_irq (e, &irq); +if (!kvm_intr_is_single_vcpu (kvm, &irq, &vcpu)) +continue ; + + vcpu_info.pi_desc_addr = kvm_x86_ops->get_pi_desc_addr (vcpu); + vcpu_info.vector = irq.vector; + +if (set) + ret =irq_set_vcpu_affinity (host_irq, &vcpu_info); +else { +/* suppress notification event before unposting */ + kvm_x86_ops->pi_set_sn (vcpu); + ret =irq_set_vcpu_affinity (host_irq,NULL ); + kvm_x86_ops->pi_clear_sn (vcpu); + } + +if (ret <0 ) { +printk (KERN_INFO "%s: failed to update PI IRTE\n" , + __func__); + goto out; + } + } + + ret =0 ; +out: +srcu_read_unlock (&kvm->irq_srcu, idx); +return ret; +} +EXPORT_TRACEPOINT_SYMBOL_GPL (kvm_exit);EXPORT_TRACEPOINT_SYMBOL_GPL (kvm_inj_virq);EXPORT_TRACEPOINT_SYMBOL_GPL (kvm_page_fault);
Signature · 1 line
2.1.0
RFC 3/5 KVM: Add pointer to 'struct irq_bypass_produce' in 'kvm_kernel_irqfd'
In reply to Feng WuAdd reference to struct irq_bypass_produce so we can get the producer information from the consumer side.
--- include/linux/kvm_irqfd.h | 1 + 1 file changed, 1 insertion(+)
include/linux/kvm_irqfd.h +1 -0
@@ -65,6 +65,7 @@ struct kvm_kernel_irqfd {poll_table pt;struct work_struct shutdown;struct irq_bypass_consumer consumer; + struct irq_bypass_producer *producer; };#endif /* __LINUX_KVM_IRQFD_H */
Signature · 1 line
2.1.0
RFC 4/5 KVM: x86: Add arch specific routines for irqbypass manager
In reply to Feng WuAdd the following x86 specific routines for irqbypass manger:
- kvm_arch_irq_bypass_add_producer
- kvm_arch_irq_bypass_del_producer
- kvm_arch_irq_bypass_stop
- kvm_arch_irq_bypass_resume
- kvm_arch_irq_bypass_update
--- arch/x86/kvm/Kconfig | 1 + arch/x86/kvm/x86.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+)
arch/x86/kvm/Kconfig +1 -0
@@ -62,6 +62,7 @@ config KVM_INTEL # for perf_guest_get_msrs(): depends on CPU_SUP_INTEL select IRQ_BYPASS_MANAGER + select HAVE_KVM_IRQ_BYPASS ---help--- Provides support for KVM on Intel processors equipped with the VT extensions.
arch/x86/kvm/x86.c +55 -0
67 lines not on this page · raw message
Signature · 1 line
2.1.0
RFC 5/5 Call irqbypass update routine when updating irqfd
In reply to Feng WuCall update routine when updating irqfd, this can update the IRTE for Intel posted-interrupts.
--- virt/kvm/eventfd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
virt/kvm/eventfd.c +3 -1
@@ -570,8 +570,10 @@ void kvm_irq_routing_update(struct kvm *kvm)spin_lock_irq (&kvm->irqfds.lock); -list_for_each_entry (irqfd, &kvm->irqfds.items, list) +list_for_each_entry (irqfd, &kvm->irqfds.items, list) {irqfd_update (kvm, irqfd); + irqfd->consumer.update (&irqfd->consumer); + }spin_unlock_irq (&kvm->irqfds.lock); }
Signature · 1 line
2.1.0
Re: [RFC v1 5/5] Call irqbypass update routine when updating irqfd
Quoted 14 lines · Feng Wu
Call update routine when updating irqfd, this can update the IRTE for Intel posted-interrupts.
Signed-off-by Feng Wu <[email protected]>--- virt/kvm/eventfd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)virt/kvm/eventfd.c +0
-0@@ -570,8 +570,10 @@ void kvm_irq_routing_update(struct kvm *kvm)
virt/kvm/eventfd.c void kvm_irq_routing_update(struct kvm *kvm) · line 579
Quoted 10 lines
virt/kvm/eventfd.c +3
-1spin_lock_irq (&kvm->irqfds.lock); -list_for_each_entry (irqfd, &kvm->irqfds.items, list) +list_for_each_entry (irqfd, &kvm->irqfds.items, list) {irqfd_update (kvm, irqfd); + irqfd->consumer.update (&irqfd->consumer); + }spin_unlock_irq (&kvm->irqfds.lock); }
I don't understand why the irq bypass manager needs to know about this update callback. We could just as easily make it be a function pointer on the irqfd structure or maybe just open code it. It's defined by the consumer and called by the consumer, the irq bypass manager shouldn't know about it. Thanks,
Alex
Re: [RFC v1 4/5] KVM: x86: Add arch specific routines for irqbypass manager
In reply to Feng WuQuoted 72 lines · Feng Wu
Add the following x86 specific routines for irqbypass manger:
-
kvm_arch_irq_bypass_add_producer
-kvm_arch_irq_bypass_del_producer
-kvm_arch_irq_bypass_stop
-kvm_arch_irq_bypass_resume
-kvm_arch_irq_bypass_updateSigned-off-by Feng Wu <[email protected]>--- arch/x86/kvm/Kconfig | 1 + arch/x86/kvm/x86.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+)arch/x86/kvm/Kconfig +1
-0@@ -62,6 +62,7 @@ config KVM_INTEL # for perf_guest_get_msrs(): depends on CPU_SUP_INTEL select IRQ_BYPASS_MANAGER + select HAVE_KVM_IRQ_BYPASS ---help--- Provides support for KVM on Intel processors equipped with the VT extensions.arch/x86/kvm/x86.c +31
-0@@ -49,6 +49,8 @@#include <linux/pci.h> #include <linux/timekeeper_internal.h> #include <linux/pvclock_gtod.h> +#include <linux/kvm_irqfd.h> +#include <linux/irqbypass.h> #include <trace/events/kvm.h> #define CREATE_TRACE_POINTS @@ -8023,6 +8025,59 @@ out:return ret; } +void kvm_arch_irq_bypass_add_producer (struct irq_bypass_consumer *cons, +struct irq_bypass_producer *prod) +{ +int ret; +struct kvm_kernel_irqfd *irqfd = + container_of(cons, struct kvm_kernel_irqfd, consumer); + + irqfd->producer = prod; + + ret =kvm_arch_update_pi_irte (irqfd->kvm, prod->irq, irqfd->gsi,1 ); +WARN_ON (ret); +} + +void kvm_arch_irq_bypass_del_producer (struct irq_bypass_consumer *cons, +struct irq_bypass_producer *prod) +{ +int ret; +struct kvm_kernel_irqfd *irqfd = + container_of(cons, struct kvm_kernel_irqfd, consumer); + + irqfd->producer =NULL ; + +/* +* When producer of consumer is unregistered, we change back to +* remapped mode, so we can re-use the current implementation +* when the irq is masked/disabed or the consumer side (KVM +* int this case doesn't want to receive the interrupts. +*/ + ret =kvm_arch_update_pi_irte (irqfd->kvm, prod->irq, irqfd->gsi,0 );
arch/x86/kvm/x86.c out: · line 8066
Quoted 10 lines
arch/x86/kvm/x86.c +10
-0+WARN_ON (ret); +} + +void kvm_arch_irq_bypass_stop (struct irq_bypass_consumer *cons) +{ +} + +void kvm_arch_irq_bypass_resume (struct irq_bypass_consumer *cons) +{ +}
No need for dummy functions, these callbacks will be optional. Thanks,
Alex
Quoted 17 lines
arch/x86/kvm/x86.c +14
-0+ +void kvm_arch_irq_bypass_update (struct irq_bypass_consumer *cons) +{ +int ret; +struct kvm_kernel_irqfd *irqfd = + container_of(cons, struct kvm_kernel_irqfd, consumer); + +BUG_ON (!irqfd->producer); + + ret =kvm_arch_update_pi_irte (irqfd->kvm, irqfd->producer->irq, + irqfd->gsi,1 ); +WARN_ON (ret); +} +EXPORT_TRACEPOINT_SYMBOL_GPL (kvm_exit);EXPORT_TRACEPOINT_SYMBOL_GPL (kvm_inj_virq);EXPORT_TRACEPOINT_SYMBOL_GPL (kvm_page_fault);
RE: [RFC v1 5/5] Call irqbypass update routine when updating irqfd
In reply to Alex WilliamsonQuoted 34 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Alex Williamson
Sent: Friday, July 10, 2015 11:26 AM
To: Wu, Feng
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC v1 5/5] Call irqbypass update routine when updating irqfdQuoted 22 lines · Feng Wu
Call update routine when updating irqfd, this can update the IRTE for Intel posted-interrupts.
Signed-off-by Feng Wu <[email protected]>--- virt/kvm/eventfd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)virt/kvm/eventfd.c +3
-1@@ -570,8 +570,10 @@ void kvm_irq_routing_update(struct kvm *kvm)spin_lock_irq (&kvm->irqfds.lock); -list_for_each_entry (irqfd, &kvm->irqfds.items, list) +list_for_each_entry (irqfd, &kvm->irqfds.items, list) {irqfd_update (kvm, irqfd); + irqfd->consumer.update (&irqfd->consumer); + }
Quoted 8 lines
virt/kvm/eventfd.c void kvm_irq_routing_update(struct kvm *kvm) · line 579
Quoted 2 lines
virt/kvm/eventfd.c +0
-0spin_unlock_irq (&kvm->irqfds.lock); }I don't understand why the irq bypass manager needs to know about this update callback. We could just as easily make it be a function pointer on the irqfd structure or maybe just open code it. It's defined by the consumer and called by the consumer, the irq bypass manager shouldn't know about it. Thanks,
Yes, you are right. All we need is the producer information which has been passed in the register routine. And we can easily make this update logic inside the consumer. Thanks for your comments!
Thanks,
Feng
Quoted 7 lines
Alex
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [RFC v1 5/5] Call irqbypass update routine when updating irqfd
Quoted 53 lines
-----Original Message-----
From: Wu, Feng
Sent: Friday, July 10, 2015 12:13 PM
To: Alex Williamson
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Wu, Feng
Subject: RE: [RFC v1 5/5] Call irqbypass update routine when updating irqfdQuoted 32 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Alex Williamson
Sent: Friday, July 10, 2015 11:26 AM
To: Wu, Feng
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC v1 5/5] Call irqbypass update routine when updating irqfdQuoted 22 lines · Feng Wu
Call update routine when updating irqfd, this can update the IRTE for Intel posted-interrupts.
Signed-off-by Feng Wu <[email protected]>--- virt/kvm/eventfd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)virt/kvm/eventfd.c +3
-1@@ -570,8 +570,10 @@ void kvm_irq_routing_update(struct kvm *kvm)spin_lock_irq (&kvm->irqfds.lock); -list_for_each_entry (irqfd, &kvm->irqfds.items, list) +list_for_each_entry (irqfd, &kvm->irqfds.items, list) {irqfd_update (kvm, irqfd); + irqfd->consumer.update (&irqfd->consumer); + }Quoted 8 lines
virt/kvm/eventfd.c void kvm_irq_routing_update(struct kvm *kvm) · line 579
Quoted 2 lines
virt/kvm/eventfd.c +0
-0spin_unlock_irq (&kvm->irqfds.lock); }I don't understand why the irq bypass manager needs to know about this update callback. We could just as easily make it be a function pointer on the irqfd structure or maybe just open code it. It's defined by the consumer and called by the consumer, the irq bypass manager shouldn't know about it. Thanks,
Quoted 6 lines
Yes, you are right. All we need is the producer information which has been passed in the register routine. And we can easily make this update logic inside the consumer. Thanks for your comments!
Thanks,
Feng
BTW, Paolo & Alex, in VFIO framework, how can we know a vCPU or a guest has assigned devices to it?
Thanks,
Feng
Quoted 8 lines
Quoted 8 lines
Alex
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Paolo Bonzini
maintainerRe: [RFC v1 5/5] Call irqbypass update routine when updating irqfd
Quoted 6 lines · Feng
Quoted 3 lines
Yes, you are right. All we need is the producer information which has been passed in the register routine. And we can easily make this update logic inside the consumer. Thanks for your comments!
BTW, Paolo & Alex, in VFIO framework, how can we know a vCPU or a guest has assigned devices to it?
See here:
http://article.gmane.org/gmane.comp.emulators.kvm.devel/137930/raw
Paolo
Re: [RFC v1 5/5] Call irqbypass update routine when updating irqfd
Quoted 11 lines · Paolo Bonzini
Quoted 6 lines · Feng
Quoted 3 lines
Yes, you are right. All we need is the producer information which has been passed in the register routine. And we can easily make this update logic inside the consumer. Thanks for your comments!
BTW, Paolo & Alex, in VFIO framework, how can we know a vCPU or a guest has assigned devices to it?
See here:
http://article.gmane.org/gmane.comp.emulators.kvm.devel/137930/raw
In general, VFIO has zero visibility into KVM. VFIO doesn't know or care what the userspace driver is, whether it's QEMU/KVM, a set of ruby bindings for VFIO, a DPDK library, etc. As Paolo points out, KVM does have ways to be told about assigned devices from userspace and probe some properties, like whether the IOMMU allows non-coherent DMA. These are handled by the KVM-VFIO pseudo device (virt/kvm/vfio.c). Thanks,
Alex