xenbus and driver issues with kexec
Hi,
There are a number of problems in xenbus and the paravirtualized drivers when it comes to kexec'ing a domU kernel. It's not specific to kexec, but to handing over devices to someone else within the same domU. The same issues will come up when someone tries to combine mini-os and grub to build some kind of in-domain bootloader.
Fundamental issue is that there is no way to cleanly shutdown the frontend/backend drivers without destroying the domain and the backend devices. The patch addresses some but not all of the problems arising from that. It also has some debug stuff left in and needs some more polishing before final submission.
Here are the changes:
(1) ballon: print unconditionally driver_pages in /proc/xen/balloon.
(2) xenbus: unregister watches in xs_suspend()
(3) blk/netback: allow Closing -> Initialising state transition.
(4) blk/netfront: shutdown (but *not* destroy) devices when devices_shutdown is called, by jumping from Closing to Initialising state.
(5) Some cleanups along the way.
Not solved yet:
The netfront driver leaks pages in case it is shutdown while the interface is active. Problem is that it can't get back the rx buffers, the netback driver sits on them and doesn't release them until it has some packet data to fill in. The patch adds a netif_release_rx_bufs() function, but it doesn't work reliable, usually it gets back only a few pages.
To reproduce this you don't need to play with kexec. Just apply the balloon driver patch. Boot a domU with the new kernel. Configure the eth0 interface, "xm network-detach ...", "xm network-attach", repeat. Watch driver_pages grow in /proc/xen/balloon.
cheers,
Gerd
PS: documentation and complete domU kexec patches are available from
http://www.suse.de/~kraxel/xen/kexec.html
Signature · 2 lines
Gerd Hoffmann <[email protected]> http://www.suse.de/~kraxel/julika-dora.jpeg
linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c +5 -3
@@ -440,15 +440,17 @@ static int balloon_read(char *page, char"Requested target: %8lu kB\n" "Low-mem balloon: %8lu kB\n" "High-mem balloon: %8lu kB\n" +"Driver pages: %8lu kB\n" "Xen hard limit: " ,PAGES2KB (current_pages),PAGES2KB (target_pages), - PAGES2KB(balloon_low), PAGES2KB(balloon_high)); +PAGES2KB (balloon_low),PAGES2KB (balloon_high), + PAGES2KB(driver_pages));if (hard_limit != ~0UL ) { len +=sprintf ( page + len, -"%8lu kB (inc. %8lu kB driver headroom)\n" , -PAGES2KB (hard_limit),PAGES2KB (driver_pages)); +"%8lu kB\n" , +PAGES2KB (hard_limit)); }else { len += sprintf( page + len,
linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c +5 -0
@@ -305,6 +305,11 @@ static void frontend_changed(struct xenbswitch (frontend_state) {case XenbusStateInitialising: +if (dev->state == XenbusStateClosing) { +printk ("%s: %s: prepare for reconnect\n" , + __FUNCTION__, dev->nodename); +xenbus_switch_state (dev, XenbusStateInitWait); + }break ;case XenbusStateInitialised:
linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c +6 -3
@@ -272,10 +272,13 @@ static void backend_changed(struct xenbuxenbus_dev_fatal (dev, -ENODEV ,"bdget failed" );down (&bd->bd_sem); -if (info->users >0 ) +if (info->users) +printk ("%-20s: %s: %d user(s) left\n" , __FUNCTION__, + dev->nodename, info->users); +if (info->users >0 && !dev->shutdown_in_progress) {xenbus_dev_error (dev, -EBUSY ,"Device in use; refusing to close" ); -else + }else blkfront_closing (dev);up (&bd->bd_sem);bdput (bd);
@@ -359,7 +362,7 @@ static void blkfront_closing(struct xenbxlvbd_del (info); -xenbus_switch_state (dev, XenbusStateClosed); +xenbus_closing_done (dev); }
linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c +15 -0
@@ -228,10 +228,25 @@ static void frontend_changed(struct xenbswitch (frontend_state) {case XenbusStateInitialising: +if (dev->state == XenbusStateClosing) { +printk ("%s: %s: prepare for reconnect\n" , + __FUNCTION__, dev->nodename); +if (be->netif) { +netif_disconnect (be->netif); + be->netif =NULL ; + } +xenbus_switch_state (dev, XenbusStateInitWait); + } +break ; +case XenbusStateInitialised:break ;case XenbusStateConnected: +if (!be->netif) { +/* reconnect: setup be->netif */ +backend_changed (&be->backend_watch,NULL ,0 ); + }maybe_connect (be);break ;
linux-2.6-xen-sparse/drivers/xen/netfront/Makefile +1 -0
@@ -1,3 +1,4 @@ +EXTRA_CFLAGS += -DDEBUG=1 obj-$(CONFIG_XEN_NETDEV_FRONTEND) := xennet.o
linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c +89 -9
180 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_client.c +32 -0
@@ -41,6 +41,21 @@ extern char *kasprintf(const char *fmt, #define DPRINTK(fmt, args...) \ pr_debug("xenbus_client (%s:%d) " fmt ".\n", __FUNCTION__, __LINE__, ##args) +char *xenbus_strstate (enum xenbus_state state) +{ +static char *name[] = { + [ XenbusStateUnknown ] ="Unknown" , + [ XenbusStateInitialising ] ="Initialising" , + [ XenbusStateInitWait ] ="InitWait" , + [ XenbusStateInitialised ] ="Initialised" , + [ XenbusStateConnected ] ="Connected" , + [ XenbusStateClosing ] ="Closing" , + [ XenbusStateClosed ] ="Closed" , + }; +return state <sizeof (name)/sizeof (name[0 ]) + ? name[state] :"INVALID" ; +} + int xenbus_watch_path(struct xenbus_device *dev, const char *path, struct xenbus_watch *watch, void (*callback)(struct xenbus_watch *,
@@ -124,6 +139,23 @@ int xenbus_switch_state(struct xenbus_de }EXPORT_SYMBOL_GPL (xenbus_switch_state); +int xenbus_closing_done (struct xenbus_device *dev) +{ +if (dev->shutdown_in_progress) { +/* frontend (we) triggered closing, because of devices_shutdown(), +* prepare for possible re-connect */ +printk ("%-20s: %s: => Initialising\n" , __FUNCTION__, dev->nodename); +xenbus_switch_state (dev, XenbusStateInitialising); + }else { +/* backend triggered closing, probably the device went away, +* thus we are going to close down too. */ +printk ("%-20s: %s: => Closed\n" , __FUNCTION__, dev->nodename); +xenbus_switch_state (dev, XenbusStateClosed); + } +complete (&dev->down); +return 0 ; +} +EXPORT_SYMBOL_GPL (xenbus_closing_done);/** * Return the path to the error node for the given device, or NULL on failure.
linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c +41 -11
100 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c +11 -0
@@ -665,7 +665,18 @@ EXPORT_SYMBOL_GPL(unregister_xenbus_watcvoid xs_suspend (void ) { +struct xenbus_watch *watch; +char token[sizeof (watch) *2 +1 ]; +down_write (&xs_state.suspend_mutex); + +/* No need for watches_lock: the suspend_mutex is sufficient. */ +list_for_each_entry (watch, &watches, list) { +sprintf (token,"%lX" , (long )watch); +xs_unwatch (watch->node, token); +// printk("%s: unwatch %s\n", __FUNCTION__, watch->node); + } +mutex_lock (&xs_state.request_mutex); }
linux-2.6-xen-sparse/include/xen/xenbus.h +7 -0
@@ -37,6 +37,7 @@#include <linux/device.h> #include <linux/notifier.h> #include <linux/mutex.h> +#include <linux/completion.h> #include <xen/interface/xen.h> #include <xen/interface/grant_table.h> #include <xen/interface/io/xenbus.h>
@@ -74,6 +75,9 @@ struct xenbus_device {struct xenbus_watch otherend_watch;struct device dev;enum xenbus_state state; + +struct completion down; +int shutdown_in_progress; };static inline struct xenbus_device *to_xenbus_device (struct device *dev)
@@ -296,4 +300,7 @@ void xenbus_dev_fatal(struct xenbus_devi ...); +int xenbus_closing_done (struct xenbus_device *dev); +char *xenbus_strstate (enum xenbus_state state); +#endif /* _XEN_XENBUS_H */
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel