remove usage of __MOD_XXX_USAGE_COUNT and derivatives
Subsystems (2)
Hi.
Attached is a trivial patch the converts the usage of the macros __MOD_INC_USAGE_COUNT and __MOD_DEC_USAGE_COUNT to try_modules_get and module_put.
Conversion enables module unloading on 2.5 kernels.
The patch is against 2.5.55. I have only tested ipv4 functionality, and I see no reason that ipv6 shound not work also.
Please examine the patch, and if ok I will send it to Linus for kernel inclusion (Unless someone on the list is the preferred person to do so - maybe Harald Welte?).
Regards
Anders Fugmann
net/ipv4/netfilter/arp_tables.c +17 -20
@@ -539,8 +539,7 @@duprintf ("check_entry: `%s' not found\n" , t->u.user.name); goto out; } -if (target->me) -__MOD_INC_USE_COUNT (target->me); +try_module_get (target->me); t->u.kernel.target = target;up (&arpt_mutex);
@@ -554,8 +553,7 @@ t->u.target_size - sizeof(*t), e->comefrom)) { -if (t->u.kernel.target->me) -__MOD_DEC_USE_COUNT (t->u.kernel.target->me); +module_put (t->u.kernel.target->me);duprintf ("arp_tables: check failed for `%s'.\n" , t->u.kernel.target->name); ret = -EINVAL ;
@@ -622,8 +620,7 @@if (t->u.kernel.target->destroy) t->u.kernel.target->destroy (t->data, t->u.target_size -sizeof (*t)); -if (t->u.kernel.target->me) -__MOD_DEC_USE_COUNT (t->u.kernel.target->me); +module_put (t->u.kernel.target->me);return 0 ; }
@@ -918,12 +915,12 @@/* Update module usage count based on number of rules */ duprintf ("do_replace: oldnum=%u, initnum=%u, newnum=%u\n" , oldinfo->number, oldinfo->initial_entries, newinfo->number); -if (t->me && (oldinfo->number <= oldinfo->initial_entries) && +if ((oldinfo->number <= oldinfo->initial_entries) && (newinfo->number > oldinfo->initial_entries)) -__MOD_INC_USE_COUNT (t->me); -else if (t->me && (oldinfo->number > oldinfo->initial_entries) && +try_module_get (t->me); +else if ((oldinfo->number > oldinfo->initial_entries) && (newinfo->number <= oldinfo->initial_entries)) -__MOD_DEC_USE_COUNT (t->me); +module_put (t->me);/* Get the old counters. */ get_counters (oldinfo, counters);
@@ -1110,17 +1107,17 @@ {int ret; -MOD_INC_USE_COUNT ; +try_module_get (THIS_MODULE ); ret =down_interruptible (&arpt_mutex);if (ret !=0 ) { -MOD_DEC_USE_COUNT ; +module_put (THIS_MODULE );return ret; }if (!list_named_insert (&arpt_target, target)) {duprintf ("arpt_register_target: `%s' already in list!\n" , target->name); ret = -EINVAL ; -MOD_DEC_USE_COUNT ; +module_put (THIS_MODULE ); }up (&arpt_mutex);return ret;
@@ -1131,7 +1128,7 @@down (&arpt_mutex);LIST_DELETE (&arpt_target, target);up (&arpt_mutex); -MOD_DEC_USE_COUNT ; +module_put (THIS_MODULE ); }int arpt_register_table (struct arpt_table *table)
@@ -1141,12 +1138,12 @@static struct arpt_table_info bootstrap = {0 ,0 ,0 , {0 }, {0 }, { } }; -MOD_INC_USE_COUNT ; +try_module_get (THIS_MODULE ); newinfo =vmalloc (sizeof (struct arpt_table_info ) +SMP_ALIGN (table->table->size) *NR_CPUS );if (!newinfo) { ret = -ENOMEM ; -MOD_DEC_USE_COUNT ; +module_put (THIS_MODULE );return ret; }memcpy (newinfo->entries, table->table->entries, table->table->size);
@@ -1159,14 +1156,14 @@duprintf ("arpt_register_table: translate table gives %d\n" , ret);if (ret !=0 ) {vfree (newinfo); -MOD_DEC_USE_COUNT ; +module_put (THIS_MODULE );return ret; } ret =down_interruptible (&arpt_mutex);if (ret !=0 ) {vfree (newinfo); -MOD_DEC_USE_COUNT ; +module_put (THIS_MODULE );return ret; }
@@ -1196,7 +1193,7 @@ free_unlock:vfree (newinfo); -MOD_DEC_USE_COUNT ; +module_put (THIS_MODULE ); goto unlock; }
@@ -1210,7 +1207,7 @@ARPT_ENTRY_ITERATE (table->private->entries, table->private->size, cleanup_entry,NULL );vfree (table->private); -MOD_DEC_USE_COUNT ; +module_put (THIS_MODULE ); }/* The built-in targets: standard (NULL) and error. */
net/ipv4/netfilter/ip_conntrack_core.c +2 -2
@@ -1126,7 +1126,7 @@int ip_conntrack_helper_register (struct ip_conntrack_helper *me) { -MOD_INC_USE_COUNT ; +try_module_get (THIS_MODULE );WRITE_LOCK (&ip_conntrack_lock);list_prepend (&helpers, me);
@@ -1165,7 +1165,7 @@br_write_lock_bh (BR_NETPROTO_LOCK );br_write_unlock_bh (BR_NETPROTO_LOCK ); -MOD_DEC_USE_COUNT ; +module_put (THIS_MODULE ); }/* Refresh conntrack for this many jiffies. */
net/ipv4/netfilter/ip_conntrack_standalone.c +2 -2
@@ -310,7 +310,7 @@ }list_prepend (&protocol_list, proto); -MOD_INC_USE_COUNT ; +try_module_get (THIS_MODULE ); out:WRITE_UNLOCK (&ip_conntrack_lock);
@@ -333,7 +333,7 @@/* Remove all contrack entries for this protocol */ ip_ct_selective_cleanup (kill_proto, &proto->proto); -MOD_DEC_USE_COUNT ; +module_put (THIS_MODULE ); }static int __init init (void )
net/ipv4/netfilter/ip_nat_helper.c +14 -21
@@ -368,10 +368,9 @@if (me->me && !(me->flags &IP_NAT_HELPER_F_STANDALONE )) {struct ip_conntrack_helper *ct_helper; -if ((ct_helper =ip_ct_find_helper (&me->tuple)) - && ct_helper->me) { -__MOD_INC_USE_COUNT (ct_helper->me); - }else { +if (!(ct_helper =ip_ct_find_helper (&me->tuple)) || + (!(try_module_get (ct_helper->me)))) + {/* We are a NAT helper for protocol X. If we need * respective conntrack helper for protoccol X, compute * conntrack helper name and try to load module */
@@ -387,11 +386,9 @@ tmp +=6 ;sprintf (name,"ip_conntrack%s" , tmp);#ifdef CONFIG_KMOD -if (!request_module (name) - && (ct_helper =ip_ct_find_helper (&me->tuple)) - && ct_helper->me) { -__MOD_INC_USE_COUNT (ct_helper->me); - }else { +if (request_module (name) + || (!(ct_helper =ip_ct_find_helper (&me->tuple))) + || (!try_module_get (ct_helper->me))) {printk ("unable to load module %s\n" , name);return -EBUSY ; }
@@ -408,7 +405,8 @@ ret = -EBUSY ; else {list_prepend (&helpers, me); -MOD_INC_USE_COUNT ; + +try_module_get (THIS_MODULE ); }WRITE_UNLOCK (&ip_nat_lock);
@@ -453,22 +451,17 @@ip_ct_selective_cleanup (kill_helper, me);if (found) -MOD_DEC_USE_COUNT ; +module_put (THIS_MODULE );/* If we are no standalone NAT helper, we need to decrement usage count * on our conntrack helper */ if (me->me && !(me->flags &IP_NAT_HELPER_F_STANDALONE )) {struct ip_conntrack_helper *ct_helper; -if ((ct_helper =ip_ct_find_helper (&me->tuple)) - && ct_helper->me) { -__MOD_DEC_USE_COUNT (ct_helper->me); - } -#ifdef CONFIG_MODULES - else - printk("%s: unable to decrement usage count" -" of conntrack helper %s\n" , - __FUNCTION__, me->me->name); -#endif +if ((ct_helper =ip_ct_find_helper (&me->tuple))) +if (!try_module_get (ct_helper->me)) +printk ("%s: unable to decrement usage count" +" of conntrack helper %s\n" , + __FUNCTION__, me->me->name); } }
net/ipv4/netfilter/ip_nat_standalone.c +4 -6
@@ -255,7 +255,7 @@ }list_prepend (&protos, proto); -MOD_INC_USE_COUNT ; +try_module_get (THIS_MODULE ); out:WRITE_UNLOCK (&ip_nat_lock);
@@ -273,7 +273,7 @@br_write_lock_bh (BR_NETPROTO_LOCK );br_write_unlock_bh (BR_NETPROTO_LOCK ); -MOD_DEC_USE_COUNT ; +module_put (THIS_MODULE ); }static int init_or_cleanup (int init)
@@ -314,13 +314,11 @@ goto cleanup_localoutops; }#endif -if (ip_conntrack_module) -__MOD_INC_USE_COUNT (ip_conntrack_module); +try_module_get (ip_conntrack_module);return ret; cleanup: -if (ip_conntrack_module) -__MOD_DEC_USE_COUNT (ip_conntrack_module); +module_put (ip_conntrack_module);#ifdef CONFIG_IP_NF_NAT_LOCAL nf_unregister_hook (&ip_nat_local_in_ops); cleanup_localoutops:
net/ipv4/netfilter/ip_tables.c +24 -30
171 lines not on this page · raw message
net/ipv4/netfilter/ipchains_core.c +7 -7
@@ -839,7 +839,7 @@ i->branch->refcount--;kfree (i); i = tmp; -MOD_DEC_USE_COUNT ; +module_put (THIS_MODULE ); }return 0 ; }
@@ -886,7 +886,7 @@if (rule->branch) rule->branch->refcount++; append_successful: -MOD_INC_USE_COUNT ; +try_module_get (THIS_MODULE );return 0 ; }
@@ -917,7 +917,7 @@ f->next = frwl; insert_successful: -MOD_INC_USE_COUNT ; +try_module_get (THIS_MODULE );return 0 ; }
@@ -952,7 +952,7 @@kfree (tmp); } -MOD_DEC_USE_COUNT ; +module_put (THIS_MODULE );return 0 ; }
@@ -1059,7 +1059,7 @@else chainptr->chain = ftmp->next;kfree (ftmp); -MOD_DEC_USE_COUNT ; +module_put (THIS_MODULE );break ; }
@@ -1101,7 +1101,7 @@ tmp->next = tmp2->next;kfree (tmp2); -MOD_DEC_USE_COUNT ; +module_put (THIS_MODULE );return 0 ; }
@@ -1154,7 +1154,7 @@* user defined chain * * and therefore can be * deleted */ -MOD_INC_USE_COUNT ; +try_module_get (THIS_MODULE );return 0 ; }
net/ipv4/netfilter/ipfwadm_core.c +4 -4
@@ -705,7 +705,7 @@ ftmp = *chainptr; *chainptr = ftmp->fw_next;kfree (ftmp); -MOD_DEC_USE_COUNT ; +module_put (THIS_MODULE ); }WRITE_UNLOCK (&ip_fw_lock); }
@@ -746,7 +746,7 @@ ftmp->fw_next = *chainptr; *chainptr=ftmp;WRITE_UNLOCK (&ip_fw_lock); -MOD_INC_USE_COUNT ; +try_module_get (THIS_MODULE );return (0 ); }
@@ -794,7 +794,7 @@else *chainptr=ftmp;WRITE_UNLOCK (&ip_fw_lock); -MOD_INC_USE_COUNT ; +try_module_get (THIS_MODULE );return (0 ); }
@@ -867,7 +867,7 @@ }WRITE_UNLOCK (&ip_fw_lock);if (was_found) { -MOD_DEC_USE_COUNT ; +module_put (THIS_MODULE );return 0 ; }else return (EINVAL );
net/ipv4/netfilter/ipt_conntrack.c +2 -4
@@ -106,16 +106,14 @@static int __init init (void ) {/* NULL if ip_conntrack not a module */ -if (ip_conntrack_module) -__MOD_INC_USE_COUNT (ip_conntrack_module); +try_module_get (ip_conntrack_module);return ipt_register_match (&conntrack_match); } static void __exit fini(void) {ipt_unregister_match (&conntrack_match); -if (ip_conntrack_module) -__MOD_DEC_USE_COUNT (ip_conntrack_module); +module_put (ip_conntrack_module); }module_init (init);
net/ipv4/netfilter/ipt_helper.c +2 -4
@@ -95,16 +95,14 @@static int __init init (void ) {/* NULL if ip_conntrack not a module */ -if (ip_conntrack_module) -__MOD_INC_USE_COUNT (ip_conntrack_module); +try_module_get (ip_conntrack_module);return ipt_register_match (&helper_match); } static void __exit fini(void) {ipt_unregister_match (&helper_match); -if (ip_conntrack_module) -__MOD_DEC_USE_COUNT (ip_conntrack_module); +module_put (ip_conntrack_module); }module_init (init);
net/ipv4/netfilter/ipt_state.c +2 -4
@@ -47,16 +47,14 @@static int __init init (void ) {/* NULL if ip_conntrack not a module */ -if (ip_conntrack_module) -__MOD_INC_USE_COUNT (ip_conntrack_module); +try_module_get (ip_conntrack_module);return ipt_register_match (&state_match); } static void __exit fini(void) {ipt_unregister_match (&state_match); -if (ip_conntrack_module) -__MOD_DEC_USE_COUNT (ip_conntrack_module); +module_put (ip_conntrack_module); }module_init (init);
net/ipv6/netfilter/ip6_tables.c +24 -30
171 lines not on this page · raw message
Quoted 5 lines · Anders Fugmann
Hi.
Attached is a trivial patch the converts the usage of the macros
__MOD_INC_USAGE_COUNTand__MOD_DEC_USAGE_COUNTtotry_modules_getandmodule_put.
Ok, this seems to be some new 2.5.x api changes - I first need to get familiar with this.
Quoted 7 lines
Conversion enables module unloading on 2.5 kernels.
The patch is against 2.5.55. I have only tested ipv4 functionality, and I see no reason that ipv6 shound not work also.Please examine the patch, and if ok I will send it to Linus for kernel inclusion (Unless someone on the list is the preferred person to do so - maybe Harald Welte?).
Patches are usually submitted to the respective maintainers (see the MAINTAINERS file in the kernel source.
So if the patch is accepted (still need to look at it), I will submit it for kernel inclusion.
Quoted 2 lines
Regards
Anders Fugmann
Signature · 4 lines
- Harald Welte / [email protected] http://www.gnumonks.org/ ============================================================================ "If this were a dictatorship, it'd be a heck of a lot easier, just so long as I'm the dictator." -- George W. Bush Dec 18, 2000
Quoted 4 lines · Harald Welte
On Thu, Jan 09, 2003 at 10:52:45PM +0100, Anders Fugmann wrote:
Ok, this seems to be some new 2.5.x api changes - I first need to get familiar with this.
Most of the documentation I found in include/linux/module.h.
Quoted 4 lines
Quoted 4 lines
Conversion enables module unloading on 2.5 kernels.
The patch is against 2.5.55. I have only tested ipv4 functionality, and I see no reason that ipv6 shound not work also.
One thing I have noticed is that the module usage count for 'ip_tables'
gets incremented twice when loading a module that depends on theip_tables module. Unloading the module again also decrements usage count
on ip_tables with 2. This happens both on vanilla 2.5.55 and 2.5.55 with the patch applied. It does not happen on 2.4.20 though.
One question. Why is the module count increased (code wise) whenever a new module is loaded, that depends on the current module? Eg. When loading ipt_MARK, the module count for ip_tables is increased. The dependancies are still kept by the kernel so ip_tables cannot be unloaded anyhow.
Quoted 2 lines
So if the patch is accepted (still need to look at it), I will submit it for kernel inclusion.
Then I send it to the right place it seems.
Regards
Anders Fugmann.
Quoted 6 lines · Anders Fugmann
Quoted 4 lines · Harald Welte
On Thu, Jan 09, 2003 at 10:52:45PM +0100, Anders Fugmann wrote:
Ok, this seems to be some new 2.5.x api changes - I first need to get familiar with this.
Most of the documentation I found in
include/linux/module.h.
Ok, will read it when I have some time...
Quoted 5 lines
One thing I have noticed is that the module usage count for '
ip_tables' gets incremented twice when loading a module that depends on theip_tablesmodule. Unloading the module again also decrements usage count onip_tableswith 2. This happens both on vanilla 2.5.55 and 2.5.55 with the patch applied. It does not happen on 2.4.20 though.
Mh, strange. Maybe also related to the new module code. Seems like I should follow 2.5.x development a bit more closely.
Quoted 5 lines
One question. Why is the module count increased (code wise) whenever a new module is loaded, that depends on the current module? Eg. When loading
ipt_MARK, the module count forip_tablesis increased. The dependancies are still kept by the kernel soip_tablescannot be unloaded anyhow.
I don't think that this is necessarry. What is in fact necessarry, is increasing the module use count for every rule created. Otherwise it would state 'iptable_filter:unused' in case you had 10 dropping rules. This used to be the old behaviour, but confused a couple of users... so we decided to change it.
Quoted 3 lines
Quoted 2 lines
So if the patch is accepted (still need to look at it), I will submit it for kernel inclusion.
Then I send it to the right place it seems.
yup :)
Quoted 2 lines
Regards
Anders Fugmann.
Signature · 4 lines
- Harald Welte / [email protected] http://www.gnumonks.org/ ============================================================================ "If this were a dictatorship, it'd be a heck of a lot easier, just so long as I'm the dictator." -- George W. Bush Dec 18, 2000
Quoted 7 lines · Harald Welte
On Fri, Jan 10, 2003 at 02:49:31PM +0100, Anders Fugmann wrote:
I don't think that this is necessarry. What is in fact necessarry, is increasing the module use count for every rule created. Otherwise it would state 'iptable_filter:unused' in case you had 10 dropping rules. This used to be the old behaviour, but confused a couple of users... so we decided to change it.
Ok - I will split my answer up into two parts.
1. It seems that we agree upon modules should not have their module count increased because a new module is loaded. This is the current case.
2. If the general design goal is to have modules reflect all rules, I guess that the sum of all module counts should be equal or greater than the total number of rules. If this is the case, then where which module should be increased when inserting the rule "iptables -A INPUT". In general - Should not iptables_filter's module count be incremented for every inserted rule in the filter tabel (Same goes for NAT and MANGLE).
I'm asking, as I'm willing to spend some time understanding the system, and make patches for Netfilter.
Regards
Anders Fugmann
Quoted 11 lines · Anders Fugmann
Quoted 7 lines · Harald Welte
On Fri, Jan 10, 2003 at 02:49:31PM +0100, Anders Fugmann wrote:
I don't think that this is necessarry. What is in fact necessarry, is increasing the module use count for every rule created. Otherwise it would state 'iptable_filter:unused' in case you had 10 dropping rules. This used to be the old behaviour, but confused a couple of users... so we decided to change it.
Ok - I will split my answer up into two parts.
1. It seems that we agree upon modules should not have their module count increased because a new module is loaded. This is the current case.
Well, I don't consider it important, if there is 'just' a module dependency, or an increased module usage count (or both, like now). As long as it is assured that the system is in a consistent state.
It's a minor (cosmetic) issue, that we do both right now... it doesn't even affect runtime performance in any noticeable way - how often are new matches/targets loaded?
Quoted 6 lines
2. If the general design goal is to have modules reflect all rules, I guess that the sum of all module counts should be equal or greater than the total number of rules. If this is the case, then where which module should be increased when inserting the rule "iptables -A INPUT". In general - Should not iptables_filter's module count be incremented for every inserted rule in the filter tabel (Same goes for NAT and MANGLE).
iptable_filter usage count needs to be incremented. Either per rule, or increased to one as soon as there is >0 rules, and decreased to zero as soon as there is <1 rules.
Quoted 2 lines
I'm asking, as I'm willing to spend some time understanding the system, and make patches for Netfilter.
great, although I don't really see the need (see above).
Quoted 2 lines
Regards
Anders Fugmann
Signature · 5 lines
Live long and prosper - Harald Welte / [email protected] http://www.gnumonks.org/ ============================================================================ GCS/E/IT d- s-: a-- C+++ UL++++$ P+++ L++++$ E--- W- N++ o? K- w--- O- M- V-- PS+ PE-- Y+ PGP++ t++ 5-- !X !R tv-- b+++ DI? !D G+ e* h+ r% y+(*)
Quoted 11 lines · Harald Welte
Quoted 3 lines
Ok - I will split my answer up into two parts.
1. It seems that we agree upon modules should not have their module count increased because a new module is loaded. This is the current case.Well, I don't consider it important, if there is 'just' a module dependency, or an increased module usage count (or both, like now). As long as it is assured that the system is in a consistent state.
It's a minor (cosmetic) issue, that we do both right now... it doesn't even affect runtime performance in any noticeable way - how often are new matches/targets loaded?
Well, as is stated in Rusty's FAQ, a module doesn't need to increment its own usage count. Anyway, MOD_{INC,DEC}_USE_COUNT are deprecated in 2.5 now and even cause the module to be unable to be unloaded because "unsafe".
Quoted 10 lines
Quoted 6 lines
2. If the general design goal is to have modules reflect all rules, I guess that the sum of all module counts should be equal or greater than the total number of rules. If this is the case, then where which module should be increased when inserting the rule "iptables -A INPUT". In general - Should not iptables_filter's module count be incremented for every inserted rule in the filter tabel (Same goes for NAT and MANGLE).
iptable_filterusage count needs to be incremented. Either per rule, or increased to one as soon as there is >0 rules, and decreased to zero as soon as there is <1 rules.
Sorry if I misunderstand you, but the reason why the table modules don't need to get an incremented usage count for every rule is because it's a feature that an rmmod iptable_filter removes all rules from the table before removing the table module.
It's the usage count of match and target modules that needs to be incremented when they are used in a rule, and obviously that's being done.
inserting a rule "iptables -A INPUT" does not cause an increment in module usage count. Module usage count is not a rule count.
Quoted 4 lines
Quoted 2 lines
I'm asking, as I'm willing to spend some time understanding the system, and make patches for Netfilter.
great, although I don't really see the need (see above).
There is a need.
Signature · 2 lines
cheers, Bart
Take two on conversion from MOD_INC/DEC_USAGE_COUNT.
This version removes all MOD_INC_USAGE_COUNT and MOD_DEC_USAGE_COUNT, as this is done automatically by the kernel itself.
Whenever a module count is incremented and error can arise if the module is currently beeing loaded or unloaded. I treat this error by returning -EAGAIN, to signal that the operation should be retried.
Attached it the patch against 2.5.56. It's only for IPv4, and will await comment on this before convering IPv6.
net/ipv4/netfilter/arp_tables.c +22 -23
@@ -539,8 +539,8 @@duprintf ("check_entry: `%s' not found\n" , t->u.user.name); goto out; } -if (target->me) -__MOD_INC_USE_COUNT (target->me); +if (!try_module_get (target->me)) +return -EAGAIN ; t->u.kernel.target = target;up (&arpt_mutex);
@@ -554,8 +555,7 @@ t->u.target_size - sizeof(*t), e->comefrom)) { -if (t->u.kernel.target->me) -__MOD_DEC_USE_COUNT (t->u.kernel.target->me); +module_put (t->u.kernel.target->me);duprintf ("arp_tables: check failed for `%s'.\n" , t->u.kernel.target->name); ret = -EINVAL ;
@@ -622,8 +622,7 @@if (t->u.kernel.target->destroy) t->u.kernel.target->destroy (t->data, t->u.target_size -sizeof (*t)); -if (t->u.kernel.target->me) -__MOD_DEC_USE_COUNT (t->u.kernel.target->me); +module_put (t->u.kernel.target->me);return 0 ; }
@@ -910,20 +909,29 @@ ret = -EINVAL ; goto free_newinfo_counters_untrans_unlock; } +/* Increment before we know is there will be more or less +rules, as we cannot guarrantee the this operation will +be successful. */ +if (!try_module_get (t->me)) { + ret = -EAGAIN ; + goto free_newinfo_counters_untrans_unlock; + } oldinfo =replace_table (t, tmp.num_counters, newinfo, &ret);if (!oldinfo) - goto free_newinfo_counters_untrans_unlock; + goto free_newinfo_counters_untrans_unlock_module;/* Update module usage count based on number of rules */ duprintf ("do_replace: oldnum=%u, initnum=%u, newnum=%u\n" , oldinfo->number, oldinfo->initial_entries, newinfo->number); -if (t->me && (oldinfo->number <= oldinfo->initial_entries) && - (newinfo->number > oldinfo->initial_entries)) -__MOD_INC_USE_COUNT (t->me); -else if (t->me && (oldinfo->number > oldinfo->initial_entries) && - (newinfo->number <= oldinfo->initial_entries)) -__MOD_DEC_USE_COUNT (t->me); + +/* Now decrement count by two if nessesary. */ +if ((oldinfo->number > oldinfo->initial_entries) || + (newinfo->number <= oldinfo->initial_entries)) +module_put (t->me); +if ((oldinfo->number > oldinfo->initial_entries) && + (newinfo->number <= oldinfo->initial_entries)) +module_put (t->me);/* Get the old counters. */ get_counters (oldinfo, counters);
@@ -937,6 +945,8 @@up (&arpt_mutex);return 0 ; + free_newinfo_counters_untrans_unlock_module: +module_put (t->me); free_newinfo_counters_untrans_unlock:up (&arpt_mutex); free_newinfo_counters_untrans:
@@ -1110,17 +1120,14 @@ {int ret; -MOD_INC_USE_COUNT ; ret =down_interruptible (&arpt_mutex);if (ret !=0 ) { -MOD_DEC_USE_COUNT ;return ret; }if (!list_named_insert (&arpt_target, target)) {duprintf ("arpt_register_target: `%s' already in list!\n" , target->name); ret = -EINVAL ; -MOD_DEC_USE_COUNT ; }up (&arpt_mutex);return ret;
@@ -1131,7 +1138,6 @@down (&arpt_mutex);LIST_DELETE (&arpt_target, target);up (&arpt_mutex); -MOD_DEC_USE_COUNT ; }int arpt_register_table (struct arpt_table *table)
@@ -1141,12 +1147,10 @@static struct arpt_table_info bootstrap = {0 ,0 ,0 , {0 }, {0 }, { } }; -MOD_INC_USE_COUNT ; newinfo =vmalloc (sizeof (struct arpt_table_info ) +SMP_ALIGN (table->table->size) *NR_CPUS );if (!newinfo) { ret = -ENOMEM ; -MOD_DEC_USE_COUNT ;return ret; }memcpy (newinfo->entries, table->table->entries, table->table->size);
@@ -1159,14 +1163,12 @@duprintf ("arpt_register_table: translate table gives %d\n" , ret);if (ret !=0 ) {vfree (newinfo); -MOD_DEC_USE_COUNT ;return ret; } ret =down_interruptible (&arpt_mutex);if (ret !=0 ) {vfree (newinfo); -MOD_DEC_USE_COUNT ;return ret; }
@@ -1196,7 +1198,6 @@ free_unlock:vfree (newinfo); -MOD_DEC_USE_COUNT ; goto unlock; }
@@ -1210,7 +1211,6 @@ARPT_ENTRY_ITERATE (table->private->entries, table->private->size, cleanup_entry,NULL );vfree (table->private); -MOD_DEC_USE_COUNT ; }/* The built-in targets: standard (NULL) and error. */
net/ipv4/netfilter/ip_conntrack_core.c +2 -4
@@ -11,6 +11,8 @@* 16 Jul 2002: Harald Welte <[email protected]> * - add usage/reference counts to ip_conntrack_expect * - export ip_conntrack[_expect]_{find_get,put} functions +* 13 Jan 2003 Anders Fugmann <[email protected]> +* - convert MOD_INC/DEV_USAGE_COUNT to 2.5 API. * */ #ifdef MODULE
@@ -1131,8 +1133,6 @@int ip_conntrack_helper_register (struct ip_conntrack_helper *me) { -MOD_INC_USE_COUNT ; -WRITE_LOCK (&ip_conntrack_lock);list_prepend (&helpers, me);WRITE_UNLOCK (&ip_conntrack_lock);
@@ -1169,8 +1169,6 @@/* Someone could be still looking at the helper in a bh. */ br_write_lock_bh (BR_NETPROTO_LOCK );br_write_unlock_bh (BR_NETPROTO_LOCK ); - -MOD_DEC_USE_COUNT ; }/* Refresh conntrack for this many jiffies. */
net/ipv4/netfilter/ip_conntrack_standalone.c +0 -2
@@ -310,7 +310,6 @@ }list_prepend (&protocol_list, proto); -MOD_INC_USE_COUNT ; out:WRITE_UNLOCK (&ip_conntrack_lock);
@@ -333,7 +332,6 @@/* Remove all contrack entries for this protocol */ ip_ct_selective_cleanup (kill_proto, &proto->proto); -MOD_DEC_USE_COUNT ; }static int __init init (void )
Only in linux-2.5.56-new/net/ipv4/netfilter/: ip_conntrack_standalone.c~
Binary files linux-2.5.56/net/ipv4/netfilter/ip_conntrack_standalone.o and linux-2.5.56-new/net/ipv4/netfilter/ip_conntrack_standalone.o differ
net/ipv4/netfilter/ip_nat_helper.c +9 -7
@@ -11,6 +11,8 @@* 16 Aug 2002 Brian J. Murrell <[email protected]>: * - make ip_nat_resize_packet more generic (TCP and UDP) * - add ip_nat_mangle_udp_packet +* 13 Jan 2003 Anders Fugmann <[email protected]> +* - convert MOD_INC/DEV_USAGE_COUNT to 2.5 API. */ #include <linux/version.h> #include <linux/config.h>
@@ -481,7 +483,10 @@if ((ct_helper =ip_ct_find_helper (&me->tuple)) && ct_helper->me) { -__MOD_INC_USE_COUNT (ct_helper->me); +/* Double check, but we need to know if the module +is available */ +if (!try_module_get (ct_helper->me)) +return -EAGAIN ; }else {/* We are a NAT helper for protocol X. If we need * respective conntrack helper for protoccol X, compute
@@ -501,7 +506,8 @@if (!request_module (name) && (ct_helper =ip_ct_find_helper (&me->tuple)) && ct_helper->me) { -__MOD_INC_USE_COUNT (ct_helper->me); +if (!try_module_get (ct_helper->me)) +return -EAGAIN ; }else {printk ("unable to load module %s\n" , name);return -EBUSY ;
@@ -519,7 +525,6 @@ ret = -EBUSY ; else {list_prepend (&helpers, me); -MOD_INC_USE_COUNT ; }WRITE_UNLOCK (&ip_nat_lock);
@@ -563,9 +568,6 @@worse. --RR */ ip_ct_selective_cleanup (kill_helper, me); -if (found) -MOD_DEC_USE_COUNT ; -/* If we are no standalone NAT helper, we need to decrement usage count * on our conntrack helper */ if (me->me && !(me->flags &IP_NAT_HELPER_F_STANDALONE )) {
@@ -573,7 +575,7 @@if ((ct_helper =ip_ct_find_helper (&me->tuple)) && ct_helper->me) { -__MOD_DEC_USE_COUNT (ct_helper->me); +module_put (ct_helper->me); }#ifdef CONFIG_MODULES else
Binary files linux-2.5.56/net/ipv4/netfilter/ip_nat_helper.o and linux-2.5.56-new/net/ipv4/netfilter/ip_nat_helper.o differ
net/ipv4/netfilter/ip_nat_standalone.c +9 -7
@@ -10,6 +10,8 @@* 23 Apr 2001: Harald Welte <[email protected]> * - new API and handling of conntrack/nat helpers * - now capable of multiple expectations for one master +* 13 Jan 2003 Anders Fugmann <[email protected]> +* - convert MOD_INC/DEV_USAGE_COUNT to 2.5 API. * */ #include <linux/config.h>
@@ -255,7 +257,6 @@ }list_prepend (&protos, proto); -MOD_INC_USE_COUNT ; out:WRITE_UNLOCK (&ip_nat_lock);
@@ -272,8 +273,6 @@/* Someone could be still looking at the proto in a bh. */ br_write_lock_bh (BR_NETPROTO_LOCK );br_write_unlock_bh (BR_NETPROTO_LOCK ); - -MOD_DEC_USE_COUNT ; }static int init_or_cleanup (int init)
@@ -314,13 +313,16 @@ goto cleanup_localoutops; }#endif -if (ip_conntrack_module) -__MOD_INC_USE_COUNT (ip_conntrack_module); +if (!try_module_get (ip_conntrack_module)) { + ret = -EAGAIN ; + goto cleanup_module; + }return ret; cleanup: -if (ip_conntrack_module) -__MOD_DEC_USE_COUNT (ip_conntrack_module); +module_put (ip_conntrack_module); + cleanup_module: +#ifdef CONFIG_IP_NF_NAT_LOCAL nf_unregister_hook (&ip_nat_local_in_ops); cleanup_localoutops:
net/ipv4/netfilter/ip_tables.c +30 -34
200 lines not on this page · raw message
net/ipv4/netfilter/ipchains_core.c +2 -7
@@ -44,6 +44,8 @@* 23-Jul-1999: Fixed small fragment security exposure opened on 15-May-1998. * John McDonald <[email protected]> * Thomas Lopatic <[email protected]> +* 13-Jan-2003: Removed all MOD_INC/DEV_USAGE_COUNT. +* Anders Fugmann <[email protected]> */ /*
@@ -839,7 +841,6 @@ i->branch->refcount--;kfree (i); i = tmp; -MOD_DEC_USE_COUNT ; }return 0 ; }
@@ -886,7 +887,6 @@if (rule->branch) rule->branch->refcount++; append_successful: -MOD_INC_USE_COUNT ;return 0 ; }
@@ -917,7 +917,6 @@ f->next = frwl; insert_successful: -MOD_INC_USE_COUNT ;return 0 ; }
@@ -952,7 +951,6 @@kfree (tmp); } -MOD_DEC_USE_COUNT ;return 0 ; }
@@ -1059,7 +1057,6 @@else chainptr->chain = ftmp->next;kfree (ftmp); -MOD_DEC_USE_COUNT ;break ; }
@@ -1101,7 +1098,6 @@ tmp->next = tmp2->next;kfree (tmp2); -MOD_DEC_USE_COUNT ;return 0 ; }
@@ -1154,7 +1150,6 @@* user defined chain * * and therefore can be * deleted */ -MOD_INC_USE_COUNT ;return 0 ; }
net/ipv4/netfilter/ipfwadm_core.c +2 -4
@@ -55,6 +55,8 @@* Jos Vos <[email protected]> 18/5/1996. * Added trap out of bad frames. * Alan Cox <[email protected]> 17/11/1996 +* Removed all module count manipulations +* Anders Fugmann <[email protected]> 1/10/2003 * * * Masquerading functionality
@@ -705,7 +707,6 @@ ftmp = *chainptr; *chainptr = ftmp->fw_next;kfree (ftmp); -MOD_DEC_USE_COUNT ; }WRITE_UNLOCK (&ip_fw_lock); }
@@ -746,7 +747,6 @@ ftmp->fw_next = *chainptr; *chainptr=ftmp;WRITE_UNLOCK (&ip_fw_lock); -MOD_INC_USE_COUNT ;return (0 ); }
@@ -794,7 +794,6 @@else *chainptr=ftmp;WRITE_UNLOCK (&ip_fw_lock); -MOD_INC_USE_COUNT ;return (0 ); }
@@ -867,7 +866,6 @@ }WRITE_UNLOCK (&ip_fw_lock);if (was_found) { -MOD_DEC_USE_COUNT ;return 0 ; }else return (EINVAL );
net/ipv4/netfilter/ipt_conntrack.c +4 -4
@@ -106,16 +106,16 @@static int __init init (void ) {/* NULL if ip_conntrack not a module */ -if (ip_conntrack_module) -__MOD_INC_USE_COUNT (ip_conntrack_module); +if (!try_module_get (ip_conntrack_module)) +return -EAGAIN ; +return ipt_register_match (&conntrack_match); } static void __exit fini(void) {ipt_unregister_match (&conntrack_match); -if (ip_conntrack_module) -__MOD_DEC_USE_COUNT (ip_conntrack_module); +module_put (ip_conntrack_module); }module_init (init);
Binary files linux-2.5.56/net/ipv4/netfilter/ipt_conntrack.ko and linux-2.5.56-new/net/ipv4/netfilter/ipt_conntrack.ko differ Binary files linux-2.5.56/net/ipv4/netfilter/ipt_conntrack.o and linux-2.5.56-new/net/ipv4/netfilter/ipt_conntrack.o differ
net/ipv4/netfilter/ipt_helper.c +5 -4
@@ -6,6 +6,8 @@* * 19 Mar 2002 Harald Welte <[email protected]>: * - Port to newnat infrastructure +* 13 Jan 2003 Anders Fugmann <[email protected]> +* - convert MOD_INC/DEV_USAGE_COUNT to 2.5 API. */ #include <linux/module.h> #include <linux/skbuff.h>
@@ -95,16 +97,15 @@static int __init init (void ) {/* NULL if ip_conntrack not a module */ -if (ip_conntrack_module) -__MOD_INC_USE_COUNT (ip_conntrack_module); +if (!try_module_get (ip_conntrack_module)) +return -EAGAIN ;return ipt_register_match (&helper_match); } static void __exit fini(void) {ipt_unregister_match (&helper_match); -if (ip_conntrack_module) -__MOD_DEC_USE_COUNT (ip_conntrack_module); +module_put (ip_conntrack_module); }module_init (init);
net/ipv4/netfilter/ipt_state.c +3 -4
@@ -47,16 +47,15 @@static int __init init (void ) {/* NULL if ip_conntrack not a module */ -if (ip_conntrack_module) -__MOD_INC_USE_COUNT (ip_conntrack_module); +if (!try_module_get (ip_conntrack_module)) +return -EAGAIN ;return ipt_register_match (&state_match); } static void __exit fini(void) {ipt_unregister_match (&state_match); -if (ip_conntrack_module) -__MOD_DEC_USE_COUNT (ip_conntrack_module); +module_put (ip_conntrack_module); }module_init (init);
Quoted 11 lines · Anders Fugmann
Take two on conversion from MOD_INC/DEC_USAGE_COUNT.
This version removes all
MOD_INC_USAGE_COUNTandMOD_DEC_USAGE_COUNT, as this is done automatically by the kernel itself.Whenever a module count is incremented and error can arise if the module is currently beeing loaded or unloaded. I treat this error by returning
-EAGAIN, to signal that the operation should be retried.Attached it the patch against 2.5.56. It's only for IPv4, and will await comment on this before convering IPv6.
I see that other files than ip_tables.c use MOD_{INC,DEC}_USE_COUNT. I can only say that for ip_tables.c (and arp_tables.c I guess) these are no longer needed. It could be that simply removing these from another file (like ip_nat_standalone.c) could cause kernel panics. For example, the bridge code uses these two macro's too and just removing them will cause a kernel panic when removing a bridge device that is still used...
These changes should be well-thought of...
Also, use correct spelling and don't overcomment stuff...
You seem to be adding/changing code too, f.e. in arp_tables.c:
- (newinfo->number > oldinfo->initial_entries))
- __MOD_INC_USE_COUNT(t->me);
- else if (t->me && (oldinfo->number > oldinfo->initial_entries) &&
- (newinfo->number <= oldinfo->initial_entries))
- __MOD_DEC_USE_COUNT(t->me);
+
+ /* Now decrement count by two if nessesary. */
+ if ((oldinfo->number > oldinfo->initial_entries) ||
+ (newinfo->number <= oldinfo->initial_entries))
+ module_put(t->me);
+ if ((oldinfo->number > oldinfo->initial_entries) &&
+ (newinfo->number <= oldinfo->initial_entries))
+ module_put(t->me);
Is that equivalent?
Signature · 2 lines
cheers, Bart
Quoted 11 lines · Bart De Schuymer
Quoted 9 lines · Anders Fugmann
Take two on conversion from MOD_INC/DEC_USAGE_COUNT.
This version removes all
MOD_INC_USAGE_COUNTandMOD_DEC_USAGE_COUNT, as this is done automatically by the kernel itself.Whenever a module count is incremented and error can arise if the module is currently beeing loaded or unloaded. I treat this error by returning
-EAGAIN, to signal that the operation should be retried.
Quoted 8 lines
Quoted 2 lines
Attached it the patch against 2.5.56. It's only for IPv4, and will await comment on this before convering IPv6.
I see that other files than
ip_tables.cuse MOD_{INC,DEC}_USE_COUNT. I can only say that forip_tables.c(andarp_tables.cI guess) these are no longer needed.It could be that simply removing these from another file (like
ip_nat_standalone.c) could cause kernel panics. For example, the bridge code uses these two macro's too and just removing them will cause a kernel panic when removing a bridge device that is still used...
I see. The question is if it is actually a problem. If the bridging code uses anything from ip_nat_standalone, then module count would be automatically incremented? This needs to be examined.
Quoted 2 lines
These changes should be well-thought of...
Also, use correct spelling and don't overcomment stuff...
Overcommit? Please elaborate on that.
Quoted 16 lines
You seem to be adding/changing code too, f.e. in
arp_tables.c:net/ipv4/netfilter/arp_tables.c +8
-5- (newinfo->number > oldinfo->initial_entries)) -__MOD_INC_USE_COUNT (t->me); - else if (t->me && (oldinfo->number > oldinfo->initial_entries) && - (newinfo->number <= oldinfo->initial_entries)) - __MOD_DEC_USE_COUNT(t->me); + +/* Now decrement count by two if nessesary. */ +if ((oldinfo->number > oldinfo->initial_entries) || + (newinfo->number <= oldinfo->initial_entries)) +module_put (t->me); +if ((oldinfo->number > oldinfo->initial_entries) && + (newinfo->number <= oldinfo->initial_entries)) +module_put (t->me);
Quoted 2 lines
Is that equivalent?
No. In the old code __MOD_INC_USE_COUNT would always succeed. As try_module_get can return an error, the module count is incremented before the above code in order to handle the posibility of not beeing able to increment the module count. The logic decrements the module count after the operation by one, if the number of new rules is equal to or lower than the number of old rules, and decrement again if it's actually lower. So the logic is changed in order to handle possible errors from try_module_put. If all suceeds the module_count is set correctly, othervice module count is not touched at all.
Thanks for the comments.
Anders Fugmann
Quoted 3 lines · Anders Fugmann
I see. The question is if it is actually a problem. If the bridging code uses anything from
ip_nat_standalone, then module count would be automatically incremented? This needs to be examined.
I was just giving an example... The bridge code has nothing to do with iptables for this.
Quoted 4 lines
Quoted 2 lines
These changes should be well-thought of...
Also, use correct spelling and don't overcomment stuff...Overcommit? Please elaborate on that.
for example:
- __MOD_INC_USE_COUNT(ct_helper->me);
+ /* Double check, but we need to know if the module
+ is available */
+ if (! try_module_get(ct_helper->me))
+ return -EAGAIN;
Originally there was no comment here and I don't see a need to add one now...
Quoted 18 lines
Quoted 16 lines
You seem to be adding/changing code too, f.e. in
arp_tables.c:net/ipv4/netfilter/arp_tables.c +8
-5- (newinfo->number > oldinfo->initial_entries)) -__MOD_INC_USE_COUNT (t->me); - else if (t->me && (oldinfo->number > oldinfo->initial_entries) && - (newinfo->number <= oldinfo->initial_entries)) - __MOD_DEC_USE_COUNT(t->me); + +/* Now decrement count by two if nessesary. */ +if ((oldinfo->number > oldinfo->initial_entries) || + (newinfo->number <= oldinfo->initial_entries)) +module_put (t->me); +if ((oldinfo->number > oldinfo->initial_entries) && + (newinfo->number <= oldinfo->initial_entries)) +module_put (t->me);Quoted 1 line
Is that equivalent?
Quoted 9 lines
No. In the old code
__MOD_INC_USE_COUNTwould always succeed. Astry_module_getcan return an error, the module count is incremented before the above code in order to handle the posibility of not beeing able to increment the module count. The logic decrements the module count after the operation by one, if the number of new rules is equal to or lower than the number of old rules, and decrement again if it's actually lower. So the logic is changed in order to handle possible errors fromtry_module_put. If all suceeds themodule_countis set correctly, othervice module count is not touched at all.
Can't you just change
if (t->me && (oldinfo->number <= oldinfo->initial_entries) &&
(newinfo->number > oldinfo->initial_entries))
__MOD_INC_USE_COUNT(t->me);
else if (t->me && (oldinfo->number > oldinfo->initial_entries) &&
(newinfo->number <= oldinfo->initial_entries))
__MOD_DEC_USE_COUNT(t->me);into
if (t->me && (oldinfo->number <= oldinfo->initial_entries) &&
(newinfo->number > oldinfo->initial_entries)) {
if (!try_module_get(t->me)) {
ret = -EAGAIN;
goto free_newinfo_counters_untrans_unlock;
}
} else if (t->me && (oldinfo->number > oldinfo->initial_entries) &&
(newinfo->number <= oldinfo->initial_entries))
module_put(t->me);Try not to add new logic if it's not necessary...
Signature · 2 lines
cheers, Bart
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 8 lines · Anders Fugmann
Ahh. I misread. I read it as "overcommit" and not as you wrote "overcomment" :-).
It is a double check as
try_module_getalso tests for arguemtn==NULL. This example is take out of context. Its fine by me if you dont like comments in code but IMHO documentation is vital and comments are usually not harming anyone. I can remove all comments in the next patch if you like. (I dont, but then again - who am I to decide.)
try_module_get is a function that will be used all over the kernel, so it's my feeling that the reader should have no problem with understanding this. Anyway, I'm not the one who's the final judge, Rusty or Harald seem to be more appropriate, I'm just trying to help :) Maybe you should CC Rusty ( Rusty Russell <rusty_at_rustcorp.com.au>) if you post another patch for this. Then again, maybe he is too busy with other stuff now...
Quoted 1 line
Quoted 1 line
Can't you just change
<snip>
Quoted 4 lines
No. At this point the replace has already occured, and we must ignore the error if anything. The above is wrong as we cannot abort at that point. (If I understand the code correctly - Please correct me if I'm wrong).
Aha, it's been more than a year (two years would be more accurate) since I've read the iptables code and I see this code was added since then. My comment in another mail about the table module count not being increased when new rules are added is probably wrong then. I don't really see why this code is in here since the original code was made so that an rmmod of a non-empty table would just empty the whole table first. That code now seems useless. A quick scan of the netfilter devel list of around the time this code was added doesn't show anything.
Quoted 2 lines
Agreed, But I really believe that the the change discussed is nessesary. (There are two of these).
Yes, my bad.
Signature · 2 lines
cheers, Bart
Quoted 5 lines · Anders Fugmann
One thing I have noticed is that the module usage count for '
ip_tables' gets incremented twice when loading a module that depends on theip_tablesmodule. Unloading the module again also decrements usage count onip_tableswith 2. This happens both on vanilla 2.5.55 and 2.5.55 with the patch applied. It does not happen on 2.4.20 though.
It seems the generic module code already increments the usage count. The iptables code also increments it, so that results in +2.
Quoted 5 lines
One question. Why is the module count increased (code wise) whenever a new module is loaded, that depends on the current module? Eg. When loading
ipt_MARK, the module count forip_tablesis increased. The dependancies are still kept by the kernel soip_tablescannot be unloaded anyhow.
It's in Rusty's FAQ for his new module scheme:
http://www.kernel.org/pub/linux/kernel/people/rusty/modules/FAQMOD_INC_USE_COUNT is deprecated and should be removed.
Your patch has some problems:
- MOD_INC_USE_COUNT;
+ try_module_get(THIS_MODULE);
(see above)
- if (match->me)
- __MOD_INC_USE_COUNT(match->me);
+ try_module_get(match->me);
you should check on the return value of try_module_get(), if it's zero then an error value must be returned to userspace.
Signature · 2 lines
cheers, Bart
Quoted 10 lines · Bart De Schuymer
Quoted 5 lines · Anders Fugmann
One thing I have noticed is that the module usage count for '
ip_tables' gets incremented twice when loading a module that depends on theip_tablesmodule. Unloading the module again also decrements usage count onip_tableswith 2. This happens both on vanilla 2.5.55 and 2.5.55 with the patch applied. It does not happen on 2.4.20 though.It seems the generic module code already increments the usage count. The iptables code also increments it, so that results in +2.
Yes. I think that this will be cured by removing all MOD_INC_USE_COUNT (see below).
Quoted 17 lines
Quoted 7 lines
One question. Why is the module count increased (code wise) whenever a new module is loaded, that depends on the current module? Eg. When loading
ipt_MARK, the module count forip_tablesis increased. The dependancies are still kept by the kernel soip_tablescannot be unloaded anyhow.It's in Rusty's FAQ for his new module scheme: http://www.kernel.org/pub/linux/kernel/people/rusty/modules/FAQ
MOD_INC_USE_COUNTis deprecated and should be removed.Your patch has some problems:
(quoted diff) +1
-1- MOD_INC_USE_COUNT; + try_module_get(THIS_MODULE);
Quoted 1 line
(see above)
Thanks. I will make an update to the patch.
(In which basically all MOD_INC_USE_COUNT and MOD_DEC_USE_COUNTS will be removed.)
net/ipv4/netfilter/ip_tables.c line 652
Quoted 5 lines
net/ipv4/netfilter/ip_tables.c +1
-2-if (match->me) -__MOD_INC_USE_COUNT (match->me); +try_module_get (match->me);
I will see how this can be done. The probem is not rerutning the error, but rather handling it correctly (Reporting back to userspace that a module could not be loaded or is beeing loaded).
Regards
Anders Fugmann
Attached is a updated patch for covertion of MOD_(DEC|INC)_USE_COUNT macros to the new 2.5 kernel API.
The patch attached is for version 2.5.61.
If there are no comments on the patch, I request that this is sent to Linus for kernel inclusion. I will post a simmiliar patch for the ipv6 netfilter modules soon.
Regards
Anders Fugmann
net/ipv4/netfilter/arp_tables.c +16 -23
@@ -539,8 +539,8 @@duprintf ("check_entry: `%s' not found\n" , t->u.user.name); goto out; } -if (target->me) -__MOD_INC_USE_COUNT (target->me); +if (!try_module_get (target->me)) +return -EAGAIN ; t->u.kernel.target = target;up (&arpt_mutex);
@@ -554,8 +554,7 @@ t->u.target_size - sizeof(*t), e->comefrom)) { -if (t->u.kernel.target->me) -__MOD_DEC_USE_COUNT (t->u.kernel.target->me); +module_put (t->u.kernel.target->me);duprintf ("arp_tables: check failed for `%s'.\n" , t->u.kernel.target->name); ret = -EINVAL ;
@@ -622,8 +621,7 @@if (t->u.kernel.target->destroy) t->u.kernel.target->destroy (t->data, t->u.target_size -sizeof (*t)); -if (t->u.kernel.target->me) -__MOD_DEC_USE_COUNT (t->u.kernel.target->me); +module_put (t->u.kernel.target->me);return 0 ; }
@@ -910,20 +908,23 @@ ret = -EINVAL ; goto free_newinfo_counters_untrans_unlock; } +if (!try_module_get (t->me)) { + ret = -EAGAIN ; + goto free_newinfo_counters_untrans_unlock; + } oldinfo =replace_table (t, tmp.num_counters, newinfo, &ret);if (!oldinfo) - goto free_newinfo_counters_untrans_unlock; + goto free_newinfo_counters_untrans_unlock_module;/* Update module usage count based on number of rules */ duprintf ("do_replace: oldnum=%u, initnum=%u, newnum=%u\n" , oldinfo->number, oldinfo->initial_entries, newinfo->number); -if (t->me && (oldinfo->number <= oldinfo->initial_entries) && - (newinfo->number > oldinfo->initial_entries)) -__MOD_INC_USE_COUNT (t->me); -else if (t->me && (oldinfo->number > oldinfo->initial_entries) && - (newinfo->number <= oldinfo->initial_entries)) -__MOD_DEC_USE_COUNT (t->me); + +if (oldinfo->number > oldinfo->initial_entries) +module_put (t->me); +if (newinfo->number <= oldinfo->initial_entries) +module_put (t->me);/* Get the old counters. */ get_counters (oldinfo, counters);
@@ -937,6 +938,8 @@up (&arpt_mutex);return 0 ; + free_newinfo_counters_untrans_unlock_module: +module_put (t->me); free_newinfo_counters_untrans_unlock:up (&arpt_mutex); free_newinfo_counters_untrans:
@@ -1110,17 +1113,14 @@ {int ret; -MOD_INC_USE_COUNT ; ret =down_interruptible (&arpt_mutex);if (ret !=0 ) { -MOD_DEC_USE_COUNT ;return ret; }if (!list_named_insert (&arpt_target, target)) {duprintf ("arpt_register_target: `%s' already in list!\n" , target->name); ret = -EINVAL ; -MOD_DEC_USE_COUNT ; }up (&arpt_mutex);return ret;
@@ -1131,7 +1131,6 @@down (&arpt_mutex);LIST_DELETE (&arpt_target, target);up (&arpt_mutex); -MOD_DEC_USE_COUNT ; }int arpt_register_table (struct arpt_table *table)
@@ -1141,12 +1140,10 @@static struct arpt_table_info bootstrap = {0 ,0 ,0 , {0 }, {0 }, { } }; -MOD_INC_USE_COUNT ; newinfo =vmalloc (sizeof (struct arpt_table_info ) +SMP_ALIGN (table->table->size) *NR_CPUS );if (!newinfo) { ret = -ENOMEM ; -MOD_DEC_USE_COUNT ;return ret; }memcpy (newinfo->entries, table->table->entries, table->table->size);
@@ -1159,14 +1156,12 @@duprintf ("arpt_register_table: translate table gives %d\n" , ret);if (ret !=0 ) {vfree (newinfo); -MOD_DEC_USE_COUNT ;return ret; } ret =down_interruptible (&arpt_mutex);if (ret !=0 ) {vfree (newinfo); -MOD_DEC_USE_COUNT ;return ret; }
@@ -1196,7 +1191,6 @@ free_unlock:vfree (newinfo); -MOD_DEC_USE_COUNT ; goto unlock; }
@@ -1210,7 +1204,6 @@ARPT_ENTRY_ITERATE (table->private->entries, table->private->size, cleanup_entry,NULL );vfree (table->private); -MOD_DEC_USE_COUNT ; }/* The built-in targets: standard (NULL) and error. */
net/ipv4/netfilter/ip_conntrack_core.c +2 -4
@@ -11,6 +11,8 @@* 16 Jul 2002: Harald Welte <[email protected]> * - add usage/reference counts to ip_conntrack_expect * - export ip_conntrack[_expect]_{find_get,put} functions +* 14 Jan 2003: Anders Fugmann <[email protected]> +* - Convert to 2.5 module API. * */ #ifdef MODULE
@@ -1131,8 +1133,6 @@int ip_conntrack_helper_register (struct ip_conntrack_helper *me) { -MOD_INC_USE_COUNT ; -WRITE_LOCK (&ip_conntrack_lock);list_prepend (&helpers, me);WRITE_UNLOCK (&ip_conntrack_lock);
@@ -1169,8 +1169,6 @@/* Someone could be still looking at the helper in a bh. */ br_write_lock_bh (BR_NETPROTO_LOCK );br_write_unlock_bh (BR_NETPROTO_LOCK ); - -MOD_DEC_USE_COUNT ; }/* Refresh conntrack for this many jiffies. */
net/ipv4/netfilter/ip_conntrack_standalone.c +0 -2
@@ -310,7 +310,6 @@ }list_prepend (&protocol_list, proto); -MOD_INC_USE_COUNT ; out:WRITE_UNLOCK (&ip_conntrack_lock);
@@ -333,7 +332,6 @@/* Remove all contrack entries for this protocol */ ip_ct_selective_cleanup (kill_proto, &proto->proto); -MOD_DEC_USE_COUNT ; }static int __init init (void )
net/ipv4/netfilter/ip_nat_helper.c +7 -7
@@ -11,6 +11,8 @@* 16 Aug 2002 Brian J. Murrell <[email protected]>: * - make ip_nat_resize_packet more generic (TCP and UDP) * - add ip_nat_mangle_udp_packet +* 13 Jan 2003 Anders Fugmann <[email protected]> +* - convert to 2.5 module API. */ #include <linux/version.h> #include <linux/config.h>
@@ -480,7 +482,8 @@if ((ct_helper =ip_ct_find_helper (&me->tuple)) && ct_helper->me) { -__MOD_INC_USE_COUNT (ct_helper->me); +if (!try_module_get (ct_helper->me)) +return -EAGAIN ; }else {/* We are a NAT helper for protocol X. If we need * respective conntrack helper for protoccol X, compute
@@ -500,7 +503,8 @@if (!request_module (name) && (ct_helper =ip_ct_find_helper (&me->tuple)) && ct_helper->me) { -__MOD_INC_USE_COUNT (ct_helper->me); +if (!try_module_get (ct_helper->me)) +return -EAGAIN ; }else {printk ("unable to load module %s\n" , name);return -EBUSY ;
@@ -518,7 +522,6 @@ ret = -EBUSY ; else {list_prepend (&helpers, me); -MOD_INC_USE_COUNT ; }WRITE_UNLOCK (&ip_nat_lock);
@@ -562,9 +565,6 @@worse. --RR */ ip_ct_selective_cleanup (kill_helper, me); -if (found) -MOD_DEC_USE_COUNT ; -/* If we are no standalone NAT helper, we need to decrement usage count * on our conntrack helper */ if (me->me && !(me->flags &IP_NAT_HELPER_F_STANDALONE )) {
@@ -572,7 +572,7 @@if ((ct_helper =ip_ct_find_helper (&me->tuple)) && ct_helper->me) { -__MOD_DEC_USE_COUNT (ct_helper->me); +module_put (ct_helper->me); }#ifdef CONFIG_MODULES else
net/ipv4/netfilter/ip_nat_standalone.c +14 -6
@@ -10,6 +10,8 @@* 23 Apr 2001: Harald Welte <[email protected]> * - new API and handling of conntrack/nat helpers * - now capable of multiple expectations for one master +* 13 Jan 2003 Anders Fugmann <[email protected]> +* - Convert to 2.5 module API. * */ #include <linux/config.h>
@@ -253,9 +255,12 @@ goto out; } } +if (!try_module_get (THIS_MODULE )) { + ret = -EAGAIN ; + goto out; + }list_prepend (&protos, proto); -MOD_INC_USE_COUNT ; out:WRITE_UNLOCK (&ip_nat_lock);
@@ -273,7 +278,7 @@br_write_lock_bh (BR_NETPROTO_LOCK );br_write_unlock_bh (BR_NETPROTO_LOCK ); -MOD_DEC_USE_COUNT ; +module_put (THIS_MODULE ); }static int init_or_cleanup (int init)
@@ -314,13 +319,16 @@ goto cleanup_localoutops; }#endif -if (ip_conntrack_module) -__MOD_INC_USE_COUNT (ip_conntrack_module); +if (!try_module_get (ip_conntrack_module)) { + ret = -EAGAIN ; + goto cleanup_module; + }return ret; cleanup: -if (ip_conntrack_module) -__MOD_DEC_USE_COUNT (ip_conntrack_module); +module_put (ip_conntrack_module); + cleanup_module: +#ifdef CONFIG_IP_NF_NAT_LOCAL nf_unregister_hook (&ip_nat_local_in_ops); cleanup_localoutops:
net/ipv4/netfilter/ip_tables.c +23 -33
190 lines not on this page · raw message
net/ipv4/netfilter/ipchains_core.c +26 -11
@@ -44,6 +44,8 @@* 23-Jul-1999: Fixed small fragment security exposure opened on 15-May-1998. * John McDonald <[email protected]> * Thomas Lopatic <[email protected]> +* 14-Jan-2003 Convert to 2.5 module API. +* Anders Fugmann <[email protected]> */ /*
@@ -839,7 +841,7 @@ i->branch->refcount--;kfree (i); i = tmp; -MOD_DEC_USE_COUNT ; +module_put (THIS_MODULE ); }return 0 ; }
@@ -869,6 +871,9 @@ {struct ip_fwkernel *i; +if (!try_module_get (THIS_MODULE )) +return EAGAIN ; +FWC_HAVE_LOCK (fwc_wlocks);/* Special case if no rules already present */ if (chainptr->chain ==NULL ) {
@@ -886,7 +891,6 @@if (rule->branch) rule->branch->refcount++; append_successful: -MOD_INC_USE_COUNT ;return 0 ; }
@@ -897,8 +901,12 @@struct ip_fwkernel *frwl, __u32 position) { + int ret=0;struct ip_fwkernel *f = chainptr->chain; +if (!try_module_get (THIS_MODULE )) +return EAGAIN ; +FWC_HAVE_LOCK (fwc_wlocks);/* special case if the position is number 1 */ if (position ==1 ) {
@@ -909,16 +917,20 @@ } position--;while (--position && f !=NULL ) f = f->next; -if (f ==NULL ) -return EINVAL ; +if (f ==NULL ) { + ret =EINVAL ; + goto insert_unsuccessful; + }if (frwl->branch) frwl->branch->refcount++; frwl->next = f->next; f->next = frwl; -insert_successful: -MOD_INC_USE_COUNT ; -return 0 ; + insert_unsuccessful: +module_put (THIS_MODULE ); + insert_successful: +return ret; + }/* This function deletes the a rule from a given rulenum and chain.
@@ -952,7 +964,7 @@kfree (tmp); } -MOD_DEC_USE_COUNT ; +module_put (THIS_MODULE );return 0 ; }
@@ -1059,7 +1071,7 @@else chainptr->chain = ftmp->next;kfree (ftmp); -MOD_DEC_USE_COUNT ; +module_put (THIS_MODULE );break ; }
@@ -1101,7 +1113,7 @@ tmp->next = tmp2->next;kfree (tmp2); -MOD_DEC_USE_COUNT ; +module_put (THIS_MODULE );return 0 ; }
@@ -1149,12 +1161,15 @@if (strcmp (tmp->label,label) ==0 )return EEXIST ; +if (!try_module_get (THIS_MODULE )) +return EGAGIN ; + tmp->next =ip_init_chain (label,0 ,FW_SKIP );/* refcount is * zero since this is a * user defined chain * * and therefore can be * deleted */ -MOD_INC_USE_COUNT ; +return 0 ; }
net/ipv4/netfilter/ipfwadm_core.c +10 -4
@@ -55,6 +55,8 @@* Jos Vos <[email protected]> 18/5/1996. * Added trap out of bad frames. * Alan Cox <[email protected]> 17/11/1996 +* Convert to 2.5 module API. +* Anders Fugmann <[email protected]> * * * Masquerading functionality
@@ -705,7 +707,7 @@ ftmp = *chainptr; *chainptr = ftmp->fw_next;kfree (ftmp); -MOD_DEC_USE_COUNT ; +try_module_put (THIS_MODULE ); }WRITE_UNLOCK (&ip_fw_lock); }
@@ -716,6 +718,9 @@ {struct ip_fw *ftmp; +if (!try_module_get (THIS_MODULE )) +return EAGAIN ; + ftmp =kmalloc (sizeof (struct ip_fw ),GFP_KERNEL );if ( ftmp ==NULL ) {
@@ -746,7 +751,6 @@ ftmp->fw_next = *chainptr; *chainptr=ftmp;WRITE_UNLOCK (&ip_fw_lock); -MOD_INC_USE_COUNT ;return (0 ); }
@@ -756,6 +760,9 @@struct ip_fw *chtmp=NULL ;struct ip_fw *volatile chtmp_prev=NULL ; +if (!try_module_get (THIS_MODULE )) +return EAGAIN ; + ftmp =kmalloc (sizeof (struct ip_fw ),GFP_KERNEL );if ( ftmp ==NULL ) {
@@ -794,7 +801,6 @@else *chainptr=ftmp;WRITE_UNLOCK (&ip_fw_lock); -MOD_INC_USE_COUNT ;return (0 ); }
@@ -867,7 +873,7 @@ }WRITE_UNLOCK (&ip_fw_lock);if (was_found) { -MOD_DEC_USE_COUNT ; +module_put (THIS_MODULE );return 0 ; }else return (EINVAL );
net/ipv4/netfilter/ipt_conntrack.c +4 -4
@@ -106,16 +106,16 @@static int __init init (void ) {/* NULL if ip_conntrack not a module */ -if (ip_conntrack_module) -__MOD_INC_USE_COUNT (ip_conntrack_module); +if (!try_module_get (ip_conntrack_module)) +return -EAGAIN ; +return ipt_register_match (&conntrack_match); } static void __exit fini(void) {ipt_unregister_match (&conntrack_match); -if (ip_conntrack_module) -__MOD_DEC_USE_COUNT (ip_conntrack_module); +module_put (ip_conntrack_module); }module_init (init);
net/ipv4/netfilter/ipt_helper.c +5 -4
@@ -6,6 +6,8 @@* * 19 Mar 2002 Harald Welte <[email protected]>: * - Port to newnat infrastructure +* 13 Jan 2003 Anders Fugmann <[email protected]> +* - convert to 2.5 module API. */ #include <linux/module.h> #include <linux/skbuff.h>
@@ -95,16 +97,15 @@static int __init init (void ) {/* NULL if ip_conntrack not a module */ -if (ip_conntrack_module) -__MOD_INC_USE_COUNT (ip_conntrack_module); +if (!try_module_get (ip_conntrack_module)) +return -EAGAIN ;return ipt_register_match (&helper_match); } static void __exit fini(void) {ipt_unregister_match (&helper_match); -if (ip_conntrack_module) -__MOD_DEC_USE_COUNT (ip_conntrack_module); +module_put (ip_conntrack_module); }module_init (init);
net/ipv4/netfilter/ipt_state.c +3 -4
@@ -47,16 +47,15 @@static int __init init (void ) {/* NULL if ip_conntrack not a module */ -if (ip_conntrack_module) -__MOD_INC_USE_COUNT (ip_conntrack_module); +if (!try_module_get (ip_conntrack_module)) +return -EAGAIN ;return ipt_register_match (&state_match); } static void __exit fini(void) {ipt_unregister_match (&state_match); -if (ip_conntrack_module) -__MOD_DEC_USE_COUNT (ip_conntrack_module); +module_put (ip_conntrack_module); }module_init (init);