evtchn: make EVTCHNOP_reset suitable for kexec
authorVitaly Kuznetsov <vkuznets@redhat.com>
Fri, 1 Aug 2014 14:46:40 +0000 (16:46 +0200)
committerJan Beulich <jbeulich@suse.com>
Fri, 1 Aug 2014 14:46:40 +0000 (16:46 +0200)
It would be nice to allow guests to close all event channels in
ABI-agnostic way in case of kexec/kdump. EVTCHNOP_reset looks suitable
for this purpose. However control blocks for vcpus and event array need
cleanup when FIFO ABI is being used.

With this change a guest can simply do EVTCHNOP_reset before kexec in
both 2-level and FIFO cases. It is also important to perform store/console
channel remapping after such call.

The issue can also be solved by introducing a new EVTCHNOP operation but
it seems that EVTCHNOP_reset can be reused.

[The idea was suggested by Ian Campbell, Andrew Cooper, and David Vrabel]

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
xen/common/event_channel.c
xen/common/event_fifo.c
xen/include/public/event_channel.h

index 685384221cb1a3c41a48d0a3e16e8f1b6593c526..7d6de5411336e300374d8e334a4d66155fe1640d 100644 (file)
@@ -957,6 +957,21 @@ static long evtchn_reset(evtchn_reset_t *r)
     for ( i = 0; port_is_valid(d, i); i++ )
         (void)__evtchn_close(d, i);
 
+    spin_lock(&d->event_lock);
+
+    if ( (dom == DOMID_SELF) && d->evtchn_fifo )
+    {
+        /*
+         * Guest domain called EVTCHNOP_reset with DOMID_SELF, destroying
+         * FIFO event array and control blocks, resetting evtchn_port_ops to
+         * evtchn_port_ops_2l.
+         */
+        evtchn_fifo_destroy(d);
+        evtchn_2l_init(d);
+    }
+
+    spin_unlock(&d->event_lock);
+
     rc = 0;
 
 out:
index 1fce3f1f723c8ae72365b36019992e02e74537e7..51b4ff657903ec483ef7bce814b5e915b355a732 100644 (file)
@@ -451,6 +451,7 @@ static void cleanup_event_array(struct domain *d)
     for ( i = 0; i < EVTCHN_FIFO_MAX_EVENT_ARRAY_PAGES; i++ )
         unmap_guest_page(d->evtchn_fifo->event_array[i]);
     xfree(d->evtchn_fifo);
+    d->evtchn_fifo = NULL;
 }
 
 static void setup_ports(struct domain *d)
index 49ac8cca5390e096b0ca37a81525c0480254ee60..05e531da2c1f4752a9cb1ad830d34e81e34f45f0 100644 (file)
@@ -264,6 +264,10 @@ typedef struct evtchn_unmask evtchn_unmask_t;
  * NOTES:
  *  1. <dom> may be specified as DOMID_SELF.
  *  2. Only a sufficiently-privileged domain may specify other than DOMID_SELF.
+ *  3. Destroys all control blocks and event array, resets event channel
+ *     operations to 2-level ABI if called with <dom> == DOMID_SELF and FIFO
+ *     ABI was used. Guests should not bind events during EVTCHNOP_reset call
+ *     as these events are likely to be lost.
  */
 struct evtchn_reset {
     /* IN parameters. */