xen-netback: fix a BUG() during initialization
authorPalik, Imre <imrep@amazon.de>
Fri, 19 Jun 2015 12:21:51 +0000 (14:21 +0200)
committerDavid S. Miller <davem@davemloft.net>
Tue, 23 Jun 2015 10:34:02 +0000 (03:34 -0700)
Commit edafc132baac ("xen-netback: making the bandwidth limiter runtime settable")
introduced the capability to change the bandwidth rate limit at runtime.
But it also introduced a possible crashing bug.

If netback receives two XenbusStateConnected without getting the
hotplug-status watch firing in between, then it will try to register the
watches for the rate limiter again.  But this triggers a BUG() in the watch
registration code.

The fix modifies connect() to remove the possibly existing packet-rate
watches before trying to install those watches.  This behaviour is in line
with how connect() deals with the hotplug-status watch.

Signed-off-by: Imre Palik <imrep@amazon.de>
Cc: Matt Wilson <msw@amazon.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/xen-netback/xenbus.c

index 968787abf78d454166561e0c79f9f7421dad931d..ec383b0f5443526c101c9e12cdbcec4fc526c78e 100644 (file)
@@ -681,6 +681,9 @@ static int xen_register_watchers(struct xenbus_device *dev, struct xenvif *vif)
        char *node;
        unsigned maxlen = strlen(dev->nodename) + sizeof("/rate");
 
+       if (vif->credit_watch.node)
+               return -EADDRINUSE;
+
        node = kmalloc(maxlen, GFP_KERNEL);
        if (!node)
                return -ENOMEM;
@@ -770,6 +773,7 @@ static void connect(struct backend_info *be)
        }
 
        xen_net_read_rate(dev, &credit_bytes, &credit_usec);
+       xen_unregister_watchers(be->vif);
        xen_register_watchers(dev, be->vif);
        read_xenbus_vif_flags(be);