All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: David Vrabel <david.vrabel@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: Keir Fraser <keir@xen.org>, Tim Deegan <tim@xen.org>,
	David Vrabel <david.vrabel@citrix.com>,
	Jan Beulich <jbeulich@suse.com>,
	Ian Campbell <ian.campbell@citrix.com>
Subject: [PATCHv3 2/6] evtchn: defer freeing struct evtchn's until evtchn_destroy_final()
Date: Wed, 17 Jun 2015 13:02:59 +0100	[thread overview]
Message-ID: <1434542583-28073-3-git-send-email-david.vrabel@citrix.com> (raw)
In-Reply-To: <1434542583-28073-1-git-send-email-david.vrabel@citrix.com>

notify_via_xen_event_channel() and free_xen_event_channel() had to
check if the domain was dying because they may be called while the
domain is being destroyed and the struct evtchn's are being freed.

By deferring the freeing of the struct evtchn's until all references
to the domain are dropped, these functions can rely on the channel
state being present and valid.

Signed-off-by: David Vrabel <david.vrabel@citrix.com>
---
 xen/common/event_channel.c |   48 +++++++++++---------------------------------
 1 file changed, 12 insertions(+), 36 deletions(-)

diff --git a/xen/common/event_channel.c b/xen/common/event_channel.c
index 90e3121..ab3b48e 100644
--- a/xen/common/event_channel.c
+++ b/xen/common/event_channel.c
@@ -1175,22 +1175,6 @@ int alloc_unbound_xen_event_channel(
 
 void free_xen_event_channel(struct domain *d, int port)
 {
-    struct evtchn *chn;
-
-    spin_lock(&d->event_lock);
-
-    if ( unlikely(d->is_dying) )
-    {
-        spin_unlock(&d->event_lock);
-        return;
-    }
-
-    BUG_ON(!port_is_valid(d, port));
-    chn = evtchn_from_port(d, port);
-    BUG_ON(!consumer_is_xen(chn));
-
-    spin_unlock(&d->event_lock);
-
     (void)__evtchn_close(d, port);
 }
 
@@ -1202,18 +1186,12 @@ void notify_via_xen_event_channel(struct domain *ld, int lport)
 
     spin_lock(&ld->event_lock);
 
-    if ( unlikely(ld->is_dying) )
-    {
-        spin_unlock(&ld->event_lock);
-        return;
-    }
-
     ASSERT(port_is_valid(ld, lport));
     lchn = evtchn_from_port(ld, lport);
-    ASSERT(consumer_is_xen(lchn));
 
     if ( likely(lchn->state == ECS_INTERDOMAIN) )
     {
+        ASSERT(consumer_is_xen(lchn));
         rd    = lchn->u.interdomain.remote_dom;
         rchn  = evtchn_from_port(rd, lchn->u.interdomain.remote_port);
         evtchn_port_set_pending(rd, rchn->notify_vcpu_id, rchn);
@@ -1279,7 +1257,7 @@ int evtchn_init(struct domain *d)
 
 void evtchn_destroy(struct domain *d)
 {
-    unsigned int i, j;
+    unsigned int i;
 
     /* After this barrier no new event-channel allocations can occur. */
     BUG_ON(!d->is_dying);
@@ -1289,8 +1267,17 @@ void evtchn_destroy(struct domain *d)
     for ( i = 0; port_is_valid(d, i); i++ )
         (void)__evtchn_close(d, i);
 
+    clear_global_virq_handlers(d);
+
+    evtchn_fifo_destroy(d);
+}
+
+
+void evtchn_destroy_final(struct domain *d)
+{
+    unsigned int i, j;
+
     /* Free all event-channel buckets. */
-    spin_lock(&d->event_lock);
     for ( i = 0; i < NR_EVTCHN_GROUPS; i++ )
     {
         if ( !d->evtchn_group[i] )
@@ -1298,20 +1285,9 @@ void evtchn_destroy(struct domain *d)
         for ( j = 0; j < BUCKETS_PER_GROUP; j++ )
             free_evtchn_bucket(d, d->evtchn_group[i][j]);
         xfree(d->evtchn_group[i]);
-        d->evtchn_group[i] = NULL;
     }
     free_evtchn_bucket(d, d->evtchn);
-    d->evtchn = NULL;
-    spin_unlock(&d->event_lock);
-
-    clear_global_virq_handlers(d);
-
-    evtchn_fifo_destroy(d);
-}
-
 
-void evtchn_destroy_final(struct domain *d)
-{
 #if MAX_VIRT_CPUS > BITS_PER_LONG
     xfree(d->poll_mask);
     d->poll_mask = NULL;
-- 
1.7.10.4

  parent reply	other threads:[~2015-06-17 12:03 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-17 12:02 [PATCHv3 0/6] evtchn: Improve scalebility David Vrabel
2015-06-17 12:02 ` [PATCHv3 1/6] evtchn: clear xen_consumer when clearing state David Vrabel
2015-06-18 10:30   ` Jan Beulich
2015-06-17 12:02 ` David Vrabel [this message]
2015-06-18 10:36   ` [PATCHv3 2/6] evtchn: defer freeing struct evtchn's until evtchn_destroy_final() Jan Beulich
2015-06-18 10:40     ` David Vrabel
2015-06-18 11:01       ` Jan Beulich
2015-06-19  9:29       ` Jan Beulich
2015-06-19  9:52         ` David Vrabel
2015-06-19 10:55           ` Jan Beulich
2015-06-19 12:23             ` David Vrabel
2015-06-19 13:04               ` Jan Beulich
2015-06-19 16:58                 ` David Vrabel
2015-06-17 12:03 ` [PATCHv3 3/6] evtchn: simplify port_is_valid() David Vrabel
2015-06-17 12:03 ` [PATCHv3 4/6] evtchn: use a per-event channel lock for sending events David Vrabel
2015-06-18 11:20   ` Jan Beulich
2015-06-18 11:39     ` David Vrabel
2015-06-17 12:03 ` [PATCHv3 5/6] evtchn: remove the locking when unmasking an event channel David Vrabel
2015-06-18 11:30   ` Jan Beulich
2015-06-18 11:36     ` David Vrabel
2015-06-18 12:08       ` Jan Beulich
2015-06-18 12:17         ` David Vrabel
2015-06-17 12:03 ` [PATCHv3 6/6] evtchn: pad struct evtchn to 64 bytes David Vrabel
2015-06-18 11:31   ` Jan Beulich

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=1434542583-28073-3-git-send-email-david.vrabel@citrix.com \
    --to=david.vrabel@citrix.com \
    --cc=ian.campbell@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=keir@xen.org \
    --cc=tim@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /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.