Re: [PATCH] kvm: fast-path msi injection with irqfd

2010-11-22 Thread Avi Kivity

On 11/18/2010 07:09 PM, Michael S. Tsirkin wrote:

Store irq routing table pointer in the irqfd object,
and use that to inject MSI directly without bouncing out to
a kernel thread.

While we touch this structure, rearrange irqfd fields to make fastpath
better packed for better cache utilization.

This also adds some comments about locking rules and rcu usage in code.

Some notes on the design:
- Use pointer into the rt instead of copying an entry,
   to make it possible to use rcu, thus side-stepping
   locking complexities.  We also save some memory this way.
- Old workqueue code is still used for level irqs.
   I don't think we DTRT with level anyway, however,
   it seems easier to keep the code around as
   it has been thought through and debugged, and fix level later than
   rip out and re-instate it later.



Applied, thanks.

--
error compiling committee.c: too many arguments to function

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] kvm: fast-path msi injection with irqfd

2010-11-19 Thread Gregory Haskins
>>> On 11/19/2010 at 10:54 AM, in message <20101119155427.ga20...@amt.cnet>,
Marcelo Tosatti  wrote: 
> On Thu, Nov 18, 2010 at 07:09:08PM +0200, Michael S. Tsirkin wrote:
>> Store irq routing table pointer in the irqfd object,
>> and use that to inject MSI directly without bouncing out to
>> a kernel thread.
>> 
>> While we touch this structure, rearrange irqfd fields to make fastpath
>> better packed for better cache utilization.
>> 
>> This also adds some comments about locking rules and rcu usage in code.
>> 
>> Some notes on the design:
>> - Use pointer into the rt instead of copying an entry,
>>   to make it possible to use rcu, thus side-stepping
>>   locking complexities.  We also save some memory this way.
>> - Old workqueue code is still used for level irqs.
>>   I don't think we DTRT with level anyway, however,
>>   it seems easier to keep the code around as
>>   it has been thought through and debugged, and fix level later than
>>   rip out and re-instate it later.
>> 
>> Signed-off-by: Michael S. Tsirkin 
>> ---
>> 
>> OK, this seems to work fine for me. Tested with virtio-net in guest
>> with and without vhost-net.  Pls review/apply if appropriate.
> 
> Acked-by: Marcelo Tosatti 

Acked-by: Gregory Haskins 



--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] kvm: fast-path msi injection with irqfd

2010-11-19 Thread Marcelo Tosatti
On Thu, Nov 18, 2010 at 07:09:08PM +0200, Michael S. Tsirkin wrote:
> Store irq routing table pointer in the irqfd object,
> and use that to inject MSI directly without bouncing out to
> a kernel thread.
> 
> While we touch this structure, rearrange irqfd fields to make fastpath
> better packed for better cache utilization.
> 
> This also adds some comments about locking rules and rcu usage in code.
> 
> Some notes on the design:
> - Use pointer into the rt instead of copying an entry,
>   to make it possible to use rcu, thus side-stepping
>   locking complexities.  We also save some memory this way.
> - Old workqueue code is still used for level irqs.
>   I don't think we DTRT with level anyway, however,
>   it seems easier to keep the code around as
>   it has been thought through and debugged, and fix level later than
>   rip out and re-instate it later.
> 
> Signed-off-by: Michael S. Tsirkin 
> ---
> 
> OK, this seems to work fine for me. Tested with virtio-net in guest
> with and without vhost-net.  Pls review/apply if appropriate.

Acked-by: Marcelo Tosatti 

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] kvm: fast-path msi injection with irqfd

2010-11-18 Thread Michael S. Tsirkin
Store irq routing table pointer in the irqfd object,
and use that to inject MSI directly without bouncing out to
a kernel thread.

While we touch this structure, rearrange irqfd fields to make fastpath
better packed for better cache utilization.

This also adds some comments about locking rules and rcu usage in code.

Some notes on the design:
- Use pointer into the rt instead of copying an entry,
  to make it possible to use rcu, thus side-stepping
  locking complexities.  We also save some memory this way.
- Old workqueue code is still used for level irqs.
  I don't think we DTRT with level anyway, however,
  it seems easier to keep the code around as
  it has been thought through and debugged, and fix level later than
  rip out and re-instate it later.

Signed-off-by: Michael S. Tsirkin 
---

OK, this seems to work fine for me. Tested with virtio-net in guest
with and without vhost-net.  Pls review/apply if appropriate.

 include/linux/kvm_host.h |   16 
 virt/kvm/eventfd.c   |   91 --
 virt/kvm/irq_comm.c  |7 ++--
 3 files changed, 99 insertions(+), 15 deletions(-)

diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index a055742..4393c1b 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -16,6 +16,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -206,6 +207,10 @@ struct kvm {
 
struct mutex irq_lock;
 #ifdef CONFIG_HAVE_KVM_IRQCHIP
+   /*
+* Update side is protected by irq_lock and,
+* if configured, irqfds.lock.
+*/
struct kvm_irq_routing_table __rcu *irq_routing;
struct hlist_head mask_notifier_list;
struct hlist_head irq_ack_notifier_list;
@@ -462,6 +467,8 @@ void kvm_get_intr_delivery_bitmask(struct kvm_ioapic 
*ioapic,
   unsigned long *deliver_bitmask);
 #endif
 int kvm_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, int level);
+int kvm_set_msi(struct kvm_kernel_irq_routing_entry *irq_entry, struct kvm 
*kvm,
+   int irq_source_id, int level);
 void kvm_notify_acked_irq(struct kvm *kvm, unsigned irqchip, unsigned pin);
 void kvm_register_irq_ack_notifier(struct kvm *kvm,
   struct kvm_irq_ack_notifier *kian);
@@ -603,17 +610,26 @@ static inline void kvm_free_irq_routing(struct kvm *kvm) 
{}
 void kvm_eventfd_init(struct kvm *kvm);
 int kvm_irqfd(struct kvm *kvm, int fd, int gsi, int flags);
 void kvm_irqfd_release(struct kvm *kvm);
+void kvm_irq_routing_update(struct kvm *, struct kvm_irq_routing_table *);
 int kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args);
 
 #else
 
 static inline void kvm_eventfd_init(struct kvm *kvm) {}
+
 static inline int kvm_irqfd(struct kvm *kvm, int fd, int gsi, int flags)
 {
return -EINVAL;
 }
 
 static inline void kvm_irqfd_release(struct kvm *kvm) {}
+
+static inline void kvm_irq_routing_update(struct kvm *kvm,
+ struct kvm_irq_routing_table *irq_rt)
+{
+   rcu_assign_pointer(kvm->irq_routing, irq_rt);
+}
+
 static inline int kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args)
 {
return -ENOSYS;
diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c
index c1f1e3c..2ca4535 100644
--- a/virt/kvm/eventfd.c
+++ b/virt/kvm/eventfd.c
@@ -44,14 +44,19 @@
  */
 
 struct _irqfd {
-   struct kvm   *kvm;
-   struct eventfd_ctx   *eventfd;
-   int   gsi;
-   struct list_head  list;
-   poll_tablept;
-   wait_queue_t  wait;
-   struct work_structinject;
-   struct work_structshutdown;
+   /* Used for MSI fast-path */
+   struct kvm *kvm;
+   wait_queue_t wait;
+   /* Update side is protected by irqfds.lock */
+   struct kvm_kernel_irq_routing_entry __rcu *irq_entry;
+   /* Used for level IRQ fast-path */
+   int gsi;
+   struct work_struct inject;
+   /* Used for setup/shutdown */
+   struct eventfd_ctx *eventfd;
+   struct list_head list;
+   poll_table pt;
+   struct work_struct shutdown;
 };
 
 static struct workqueue_struct *irqfd_cleanup_wq;
@@ -125,14 +130,22 @@ irqfd_wakeup(wait_queue_t *wait, unsigned mode, int sync, 
void *key)
 {
struct _irqfd *irqfd = container_of(wait, struct _irqfd, wait);
unsigned long flags = (unsigned long)key;
+   struct kvm_kernel_irq_routing_entry *irq;
+   struct kvm *kvm = irqfd->kvm;
 
-   if (flags & POLLIN)
+   if (flags & POLLIN) {
+   rcu_read_lock();
+   irq = rcu_dereference(irqfd->irq_entry);
/* An event has been signaled, inject an interrupt */
-   schedule_work(&irqfd->inject);
+   if (irq)
+   kvm_set_msi(irq, kvm, KVM_USERSPACE_IRQ_SOURCE_ID, 1);
+   else
+   schedule_work(&irq