WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 1/2] xen/event: Add reference counting to event chann

To: konrad.wilk@xxxxxxxxxx
Subject: [Xen-devel] [PATCH 1/2] xen/event: Add reference counting to event channel
From: Daniel De Graaf <dgdegra@xxxxxxxxxxxxx>
Date: Fri, 16 Sep 2011 17:14:43 -0400
Cc: Daniel De Graaf <dgdegra@xxxxxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxx, Ian.Jackson@xxxxxxxxxxxxx
Delivery-date: Fri, 16 Sep 2011 14:18:34 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <1316207684-19860-1-git-send-email-dgdegra@xxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <1316207684-19860-1-git-send-email-dgdegra@xxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
Event channels exposed to userspace by the evtchn module may be used by
other modules in an asynchronous manner, which requires that reference
counting be used to prevent the event channel from being closed before
the signals are delivered.

Signed-off-by: Daniel De Graaf <dgdegra@xxxxxxxxxxxxx>
---
 drivers/xen/events.c |   38 ++++++++++++++++++++++++++++++++++++++
 include/xen/events.h |    6 ++++++
 2 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/drivers/xen/events.c b/drivers/xen/events.c
index da70f5c..c9343b9 100644
--- a/drivers/xen/events.c
+++ b/drivers/xen/events.c
@@ -89,6 +89,7 @@ struct irq_info
 {
        struct list_head list;
        enum xen_irq_type type; /* type */
+       unsigned short refcount;
        unsigned irq;
        unsigned short evtchn;  /* event channel */
        unsigned short cpu;     /* cpu bound */
@@ -407,6 +408,7 @@ static void xen_irq_init(unsigned irq)
                panic("Unable to allocate metadata for IRQ%d\n", irq);
 
        info->type = IRQT_UNBOUND;
+       info->refcount = 1;
 
        irq_set_handler_data(irq, info);
 
@@ -469,6 +471,8 @@ static void xen_free_irq(unsigned irq)
 
        irq_set_handler_data(irq, NULL);
 
+       BUG_ON(info->refcount > 1);
+
        kfree(info);
 
        /* Legacy IRQ descriptors are managed by the arch. */
@@ -912,9 +916,14 @@ static void unbind_from_irq(unsigned int irq)
 {
        struct evtchn_close close;
        int evtchn = evtchn_from_irq(irq);
+       struct irq_info *info = irq_get_handler_data(irq);
 
        spin_lock(&irq_mapping_update_lock);
 
+       info->refcount--;
+       if (info->refcount > 0)
+               goto out_unlock;
+
        if (VALID_EVTCHN(evtchn)) {
                close.port = evtchn;
                if (HYPERVISOR_event_channel_op(EVTCHNOP_close, &close) != 0)
@@ -943,6 +952,7 @@ static void unbind_from_irq(unsigned int irq)
 
        xen_free_irq(irq);
 
+ out_unlock:
        spin_unlock(&irq_mapping_update_lock);
 }
 
@@ -1038,6 +1048,34 @@ void unbind_from_irqhandler(unsigned int irq, void 
*dev_id)
 }
 EXPORT_SYMBOL_GPL(unbind_from_irqhandler);
 
+int get_evtchn_reservation(unsigned int evtchn)
+{
+       int irq = evtchn_to_irq[evtchn];
+       struct irq_info *info;
+
+       if (irq == -1)
+               return -ENOENT;
+
+       info = irq_get_handler_data(irq);
+
+       if (!info)
+               return -ENOENT;
+
+       spin_lock(&irq_mapping_update_lock);
+       info->refcount++;
+       spin_unlock(&irq_mapping_update_lock);
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(get_evtchn_reservation);
+
+void put_evtchn_reservation(unsigned int evtchn)
+{
+       int irq = evtchn_to_irq[evtchn];
+       unbind_from_irq(irq);
+}
+EXPORT_SYMBOL_GPL(put_evtchn_reservation);
+
 void xen_send_IPI_one(unsigned int cpu, enum ipi_vector vector)
 {
        int irq = per_cpu(ipi_to_irq, cpu)[vector];
diff --git a/include/xen/events.h b/include/xen/events.h
index d287997..23bd5fd 100644
--- a/include/xen/events.h
+++ b/include/xen/events.h
@@ -37,6 +37,12 @@ int bind_interdomain_evtchn_to_irqhandler(unsigned int 
remote_domain,
  */
 void unbind_from_irqhandler(unsigned int irq, void *dev_id);
 
+/*
+ * Allow extra references to event channels exposed to userspace by evtchn
+ */
+int get_evtchn_reservation(unsigned int evtchn);
+void put_evtchn_reservation(unsigned int evtchn);
+
 void xen_send_IPI_one(unsigned int cpu, enum ipi_vector vector);
 int resend_irq_on_evtchn(unsigned int irq);
 void rebind_evtchn_irq(int evtchn, int irq);
-- 
1.7.6


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel