From: Kieran Mansley Subject: [PATCH 5/6] Network acceleration improvements Date: Wed, 03 Oct 2007 14:18:36 +0100 Message-ID: <1191417516.4157.39.camel@moonstone.uk.level5networks.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-6vcfNwWezGNCRJ98vwxr" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org --=-6vcfNwWezGNCRJ98vwxr Content-Type: text/plain Content-Transfer-Encoding: 7bit Signed-off-by: Kieran Mansley Use module use count on accel plugin to prevent premature unload diff -r 3e8b5cb457d9 drivers/xen/netback/accel.c --- a/drivers/xen/netback/accel.c Wed Oct 03 13:38:09 2007 +0100 +++ b/drivers/xen/netback/accel.c Wed Oct 03 13:41:15 2007 +0100 @@ -187,8 +187,8 @@ static int netback_accelerator_cleanup_b * * This should only be allowed when there are no remaining users - * i.e. it is not necessary to go through and clear all the hooks, as - * they should have already been removed. This is enforced through a - * usage count and BUG_ON(use!=0), but should be made more user-friendly + * they should have already been removed. This is enforced by taking + * a module reference to the plugin while the interfaces are in use */ void netback_disconnect_accelerator(int id, const char *eth_name) { @@ -227,7 +227,8 @@ void netback_probe_accelerators(struct b */ spin_lock_irqsave(&accelerators_lock, flags); list_for_each_entry(accelerator, &accelerators_list, link) { - if (match_accelerator(dev, be, accelerator)) { + if (match_accelerator(dev, be, accelerator) && + try_module_get(accelerator->hooks->owner)) { be->accelerator = accelerator; atomic_inc(&be->accelerator->use_count); be->accelerator->hooks->probe(dev); @@ -242,9 +243,10 @@ void netback_remove_accelerators(struct struct xenbus_device *dev) { /* Notify the accelerator (if any) of this device's removal */ - if ( be->accelerator ) { + if (be->accelerator) { be->accelerator->hooks->remove(dev); atomic_dec(&be->accelerator->use_count); + module_put(be->accelerator->hooks->owner); } be->accelerator = NULL; } diff -r 3e8b5cb457d9 drivers/xen/netback/common.h --- a/drivers/xen/netback/common.h Wed Oct 03 13:38:09 2007 +0100 +++ b/drivers/xen/netback/common.h Wed Oct 03 13:38:46 2007 +0100 @@ -125,6 +125,7 @@ extern int netbk_copy_skb_mode; /* Function pointers into netback accelerator plugin modules */ struct netback_accel_hooks { + struct module *owner; int (*probe)(struct xenbus_device *dev); int (*remove)(struct xenbus_device *dev); }; --=-6vcfNwWezGNCRJ98vwxr Content-Disposition: attachment; filename=netback_module_use_count Content-Type: text/plain; name=netback_module_use_count; charset=UTF-8 Content-Transfer-Encoding: 7bit Use module use count on accel plugin to prevent premature unload diff -r 3e8b5cb457d9 drivers/xen/netback/accel.c --- a/drivers/xen/netback/accel.c Wed Oct 03 13:38:09 2007 +0100 +++ b/drivers/xen/netback/accel.c Wed Oct 03 13:41:15 2007 +0100 @@ -187,8 +187,8 @@ static int netback_accelerator_cleanup_b * * This should only be allowed when there are no remaining users - * i.e. it is not necessary to go through and clear all the hooks, as - * they should have already been removed. This is enforced through a - * usage count and BUG_ON(use!=0), but should be made more user-friendly + * they should have already been removed. This is enforced by taking + * a module reference to the plugin while the interfaces are in use */ void netback_disconnect_accelerator(int id, const char *eth_name) { @@ -227,7 +227,8 @@ void netback_probe_accelerators(struct b */ spin_lock_irqsave(&accelerators_lock, flags); list_for_each_entry(accelerator, &accelerators_list, link) { - if (match_accelerator(dev, be, accelerator)) { + if (match_accelerator(dev, be, accelerator) && + try_module_get(accelerator->hooks->owner)) { be->accelerator = accelerator; atomic_inc(&be->accelerator->use_count); be->accelerator->hooks->probe(dev); @@ -242,9 +243,10 @@ void netback_remove_accelerators(struct struct xenbus_device *dev) { /* Notify the accelerator (if any) of this device's removal */ - if ( be->accelerator ) { + if (be->accelerator) { be->accelerator->hooks->remove(dev); atomic_dec(&be->accelerator->use_count); + module_put(be->accelerator->hooks->owner); } be->accelerator = NULL; } diff -r 3e8b5cb457d9 drivers/xen/netback/common.h --- a/drivers/xen/netback/common.h Wed Oct 03 13:38:09 2007 +0100 +++ b/drivers/xen/netback/common.h Wed Oct 03 13:38:46 2007 +0100 @@ -125,6 +125,7 @@ extern int netbk_copy_skb_mode; /* Function pointers into netback accelerator plugin modules */ struct netback_accel_hooks { + struct module *owner; int (*probe)(struct xenbus_device *dev); int (*remove)(struct xenbus_device *dev); }; --=-6vcfNwWezGNCRJ98vwxr Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=-6vcfNwWezGNCRJ98vwxr--