* MOD_{INC,SEC}_USE_COUNT() in net/ipv{4,6}
@ 2003-04-09 11:41 YOSHIFUJI Hideaki / 吉藤英明
2003-04-10 1:00 ` David S. Miller
0 siblings, 1 reply; 5+ messages in thread
From: YOSHIFUJI Hideaki / 吉藤英明 @ 2003-04-09 11:41 UTC (permalink / raw)
To: davem, kuznet; +Cc: netdev, usagi
Hello.
This patch (against 2.5.67) converts MOD_{INC,DEC}_USE_COUNT in
net/ipv{4,6} to try_module_get() and module_put().
Thanks you.
Index: net/ipv4/ip_gre.c
===================================================================
RCS file: /cvsroot/usagi/usagi-backport/linux25/net/ipv4/ip_gre.c,v
retrieving revision 1.1.1.8
diff -u -r1.1.1.8 ip_gre.c
--- net/ipv4/ip_gre.c 22 Mar 2003 01:52:17 -0000 1.1.1.8
+++ net/ipv4/ip_gre.c 9 Apr 2003 11:28:11 -0000
@@ -262,10 +262,11 @@
if (!create)
return NULL;
- MOD_INC_USE_COUNT;
+ if (!try_module_get(THIS_MODULE))
+ return NULL;
dev = kmalloc(sizeof(*dev) + sizeof(*t), GFP_KERNEL);
if (dev == NULL) {
- MOD_DEC_USE_COUNT;
+ module_put(THIS_MODULE);
return NULL;
}
memset(dev, 0, sizeof(*dev) + sizeof(*t));
@@ -297,7 +298,7 @@
failed:
kfree(dev);
- MOD_DEC_USE_COUNT;
+ module_put(THIS_MODULE);
return NULL;
}
@@ -305,7 +306,7 @@
{
if (dev != &ipgre_fb_tunnel_dev) {
kfree(dev);
- MOD_DEC_USE_COUNT;
+ module_put(THIS_MODULE);
}
}
@@ -920,7 +921,8 @@
struct ip_tunnel_parm p;
struct ip_tunnel *t;
- MOD_INC_USE_COUNT;
+ if (!try_module_get(THIS_MODULE))
+ return -EBUSY;
switch (cmd) {
case SIOCGETTUNNEL:
@@ -1035,7 +1037,7 @@
}
done:
- MOD_DEC_USE_COUNT;
+ module_put(THIS_MODULE);
return err;
}
@@ -1115,7 +1117,8 @@
{
struct ip_tunnel *t = (struct ip_tunnel*)dev->priv;
- MOD_INC_USE_COUNT;
+ if (!try_module_get(THIS_MODULE))
+ return -EBUSY;
if (MULTICAST(t->parms.iph.daddr)) {
struct flowi fl = { .oif = t->parms.link,
.nl_u = { .ip4_u =
@@ -1125,13 +1128,13 @@
.proto = IPPROTO_GRE };
struct rtable *rt;
if (ip_route_output_key(&rt, &fl)) {
- MOD_DEC_USE_COUNT;
+ module_put(THIS_MODULE);
return -EADDRNOTAVAIL;
}
dev = rt->u.dst.dev;
ip_rt_put(rt);
if (__in_dev_get(dev) == NULL) {
- MOD_DEC_USE_COUNT;
+ module_put(THIS_MODULE);
return -EADDRNOTAVAIL;
}
t->mlink = dev->ifindex;
@@ -1150,7 +1153,7 @@
in_dev_put(in_dev);
}
}
- MOD_DEC_USE_COUNT;
+ module_put(THIS_MODULE);
return 0;
}
@@ -1247,13 +1250,14 @@
#ifdef MODULE
static int ipgre_fb_tunnel_open(struct net_device *dev)
{
- MOD_INC_USE_COUNT;
+ if (!try_module_get(THIS_MODULE))
+ return -EBUSY;
return 0;
}
static int ipgre_fb_tunnel_close(struct net_device *dev)
{
- MOD_DEC_USE_COUNT;
+ module_put(THIS_MODULE);
return 0;
}
#endif
Index: net/ipv4/ipip.c
===================================================================
RCS file: /cvsroot/usagi/usagi-backport/linux25/net/ipv4/ipip.c,v
retrieving revision 1.1.1.8
diff -u -r1.1.1.8 ipip.c
--- net/ipv4/ipip.c 22 Mar 2003 01:52:17 -0000 1.1.1.8
+++ net/ipv4/ipip.c 9 Apr 2003 11:28:11 -0000
@@ -231,10 +231,11 @@
if (!create)
return NULL;
- MOD_INC_USE_COUNT;
+ if (!try_module_get(THIS_MODULE))
+ return NULL;
dev = kmalloc(sizeof(*dev) + sizeof(*t), GFP_KERNEL);
if (dev == NULL) {
- MOD_DEC_USE_COUNT;
+ module_put(THIS_MODULE);
return NULL;
}
memset(dev, 0, sizeof(*dev) + sizeof(*t));
@@ -266,7 +267,7 @@
failed:
kfree(dev);
- MOD_DEC_USE_COUNT;
+ module_put(THIS_MODULE);
return NULL;
}
@@ -274,7 +275,7 @@
{
if (dev != &ipip_fb_tunnel_dev) {
kfree(dev);
- MOD_DEC_USE_COUNT;
+ module_put(THIS_MODULE);
}
}
@@ -682,7 +683,8 @@
struct ip_tunnel_parm p;
struct ip_tunnel *t;
- MOD_INC_USE_COUNT;
+ if (!try_module_get(THIS_MODULE))
+ return -EBUSY;
switch (cmd) {
case SIOCGETTUNNEL:
@@ -782,7 +784,7 @@
}
done:
- MOD_DEC_USE_COUNT;
+ module_put(THIS_MODULE);
return err;
}
@@ -861,13 +863,14 @@
#ifdef MODULE
static int ipip_fb_tunnel_open(struct net_device *dev)
{
- MOD_INC_USE_COUNT;
+ if (!try_module_get(THIS_MODULE))
+ return -EBUSY;
return 0;
}
static int ipip_fb_tunnel_close(struct net_device *dev)
{
- MOD_DEC_USE_COUNT;
+ module_put(THIS_MODULE);
return 0;
}
#endif
Index: net/ipv6/af_inet6.c
===================================================================
RCS file: /cvsroot/usagi/usagi-backport/linux25/net/ipv6/af_inet6.c,v
retrieving revision 1.1.1.11
diff -u -r1.1.1.11 af_inet6.c
--- net/ipv6/af_inet6.c 8 Apr 2003 08:57:58 -0000 1.1.1.11
+++ net/ipv6/af_inet6.c 9 Apr 2003 11:28:11 -0000
@@ -111,7 +111,7 @@
#ifdef INET_REFCNT_DEBUG
atomic_dec(&inet6_sock_nr);
#endif
- MOD_DEC_USE_COUNT;
+ module_put(THIS_MODULE);
}
static __inline__ kmem_cache_t *inet6_sk_slab(int protocol)
@@ -242,7 +242,10 @@
atomic_inc(&inet6_sock_nr);
atomic_inc(&inet_sock_nr);
#endif
- MOD_INC_USE_COUNT;
+ if (!try_get_module(THIS_MODULE)) {
+ inet_sock_release(sk);
+ return -EBUSY;
+ }
if (inet->num) {
/* It assumes that any protocol which allows
@@ -255,7 +258,7 @@
if (sk->prot->init) {
int err = sk->prot->init(sk);
if (err != 0) {
- MOD_DEC_USE_COUNT;
+ module_put(THIS_MODULE);
inet_sock_release(sk);
return err;
}
Index: net/ipv6/ipv6_sockglue.c
===================================================================
RCS file: /cvsroot/usagi/usagi-backport/linux25/net/ipv6/ipv6_sockglue.c,v
retrieving revision 1.1.1.8
diff -u -r1.1.1.8 ipv6_sockglue.c
--- net/ipv6/ipv6_sockglue.c 8 Apr 2003 08:57:58 -0000 1.1.1.8
+++ net/ipv6/ipv6_sockglue.c 9 Apr 2003 11:28:11 -0000
@@ -196,7 +196,7 @@
#ifdef INET_REFCNT_DEBUG
atomic_dec(&inet6_sock_nr);
#endif
- MOD_DEC_USE_COUNT;
+ module_put(THIS_MODULE);
retv = 0;
break;
}
Index: net/ipv6/sit.c
===================================================================
RCS file: /cvsroot/usagi/usagi-backport/linux25/net/ipv6/sit.c,v
retrieving revision 1.1.1.8
diff -u -r1.1.1.8 sit.c
--- net/ipv6/sit.c 22 Mar 2003 01:52:23 -0000 1.1.1.8
+++ net/ipv6/sit.c 9 Apr 2003 11:28:11 -0000
@@ -170,10 +170,11 @@
if (!create)
return NULL;
- MOD_INC_USE_COUNT;
+ if (!try_module_get(THIS_MODULE))
+ return NULL;
dev = kmalloc(sizeof(*dev) + sizeof(*t), GFP_KERNEL);
if (dev == NULL) {
- MOD_DEC_USE_COUNT;
+ module_put(THIS_MODULE);
return NULL;
}
memset(dev, 0, sizeof(*dev) + sizeof(*t));
@@ -205,7 +206,7 @@
failed:
kfree(dev);
- MOD_DEC_USE_COUNT;
+ module_put(THIS_MODULE);
return NULL;
}
@@ -213,7 +214,7 @@
{
if (dev != &ipip6_fb_tunnel_dev) {
kfree(dev);
- MOD_DEC_USE_COUNT;
+ module_put(THIS_MODULE);
}
}
@@ -622,7 +623,8 @@
struct ip_tunnel_parm p;
struct ip_tunnel *t;
- MOD_INC_USE_COUNT;
+ if (!try_module_get(THIS_MODULE))
+ return -EBUSY;
switch (cmd) {
case SIOCGETTUNNEL:
@@ -721,7 +723,7 @@
}
done:
- MOD_DEC_USE_COUNT;
+ module_put(THIS_MODULE);
return err;
}
@@ -801,13 +803,14 @@
#ifdef MODULE
static int ipip6_fb_tunnel_open(struct net_device *dev)
{
- MOD_INC_USE_COUNT;
+ if (!try_module_get(THIS_MODULE))
+ return -EBUSY;
return 0;
}
static int ipip6_fb_tunnel_close(struct net_device *dev)
{
- MOD_DEC_USE_COUNT;
+ module_put(THIS_MODULE);
return 0;
}
#endif
--
Hideaki YOSHIFUJI @ USAGI Project <yoshfuji@linux-ipv6.org>
GPG FP: 9022 65EB 1ECF 3AD1 0BDF 80D8 4807 F894 E062 0EEA
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: MOD_{INC,SEC}_USE_COUNT() in net/ipv{4,6}
2003-04-09 11:41 MOD_{INC,SEC}_USE_COUNT() in net/ipv{4,6} YOSHIFUJI Hideaki / 吉藤英明
@ 2003-04-10 1:00 ` David S. Miller
2003-04-10 2:54 ` kuznet
0 siblings, 1 reply; 5+ messages in thread
From: David S. Miller @ 2003-04-10 1:00 UTC (permalink / raw)
To: yoshfuji; +Cc: kuznet, netdev, usagi
From: YOSHIFUJI Hideaki / 吉藤英明 <yoshfuji@linux-ipv6.org>
Date: Wed, 09 Apr 2003 20:41:57 +0900 (JST)
This patch (against 2.5.67) converts MOD_{INC,DEC}_USE_COUNT in
net/ipv{4,6} to try_module_get() and module_put().
Applied, but let's recognize that ipv6 is totally broken
in this area.
The try_module_get()'s, in order to work, would need to happen
at a higher layer (socket ops or similar). But even this is
broken, module unloading of ipv6 needs to be done via some kind
of callback scheme, the simple counter mechanism that modules
use now is inappropriate for things like ipv6 which already keeps
track of it's own references internally and only it knows how to
interlock properly to cleanly check for module references and to
shut down the whole module.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: MOD_{INC,SEC}_USE_COUNT() in net/ipv{4,6}
2003-04-10 1:00 ` David S. Miller
@ 2003-04-10 2:54 ` kuznet
2003-04-10 6:29 ` David S. Miller
0 siblings, 1 reply; 5+ messages in thread
From: kuznet @ 2003-04-10 2:54 UTC (permalink / raw)
To: David S. Miller; +Cc: yoshfuji, netdev, usagi
Hello!
> This patch (against 2.5.67) converts MOD_{INC,DEC}_USE_COUNT in
> net/ipv{4,6} to try_module_get() and module_put().
>
> Applied, but
Why not to delete this things instead? Calls of these functions from
inside of module is completely meaningless.
I remember I put them there just to mimic behaviour of another devices,
but it was just a mistake.
Alexey
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: MOD_{INC,SEC}_USE_COUNT() in net/ipv{4,6}
2003-04-10 2:54 ` kuznet
@ 2003-04-10 6:29 ` David S. Miller
2003-04-10 19:11 ` Arnaldo Carvalho de Melo
0 siblings, 1 reply; 5+ messages in thread
From: David S. Miller @ 2003-04-10 6:29 UTC (permalink / raw)
To: kuznet; +Cc: yoshfuji, netdev, usagi
From: kuznet@ms2.inr.ac.ru
Date: Thu, 10 Apr 2003 06:54:38 +0400 (MSD)
Why not to delete this things instead? Calls of these functions
from inside of module is completely meaningless.
Better to implement correctly than to outright delete.
Please review.
# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher.
# This patch includes the following deltas:
# ChangeSet 1.1176 -> 1.1177
# net/ipv4/ip_gre.c 1.21 -> 1.22
# net/ipv4/ipip.c 1.24 -> 1.25
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 03/04/09 davem@nuts.ninka.net 1.1177
# [IPV4]: Do proper netdev module refcounting in tunnel drivers.
# --------------------------------------------
#
diff -Nru a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
--- a/net/ipv4/ip_gre.c Wed Apr 9 23:34:23 2003
+++ b/net/ipv4/ip_gre.c Wed Apr 9 23:34:23 2003
@@ -262,13 +262,10 @@
if (!create)
return NULL;
- if (!try_module_get(THIS_MODULE))
- return NULL;
dev = kmalloc(sizeof(*dev) + sizeof(*t), GFP_KERNEL);
- if (dev == NULL) {
- module_put(THIS_MODULE);
+ if (dev == NULL)
return NULL;
- }
+
memset(dev, 0, sizeof(*dev) + sizeof(*t));
dev->priv = (void*)(dev+1);
nt = (struct ip_tunnel*)dev->priv;
@@ -288,6 +285,7 @@
goto failed;
memcpy(nt->parms.name, dev->name, IFNAMSIZ);
}
+ SET_MODULE_OWNER(dev);
if (register_netdevice(dev) < 0)
goto failed;
@@ -298,16 +296,13 @@
failed:
kfree(dev);
- module_put(THIS_MODULE);
return NULL;
}
static void ipgre_tunnel_destructor(struct net_device *dev)
{
- if (dev != &ipgre_fb_tunnel_dev) {
+ if (dev != &ipgre_fb_tunnel_dev)
kfree(dev);
- module_put(THIS_MODULE);
- }
}
static void ipgre_tunnel_uninit(struct net_device *dev)
@@ -921,9 +916,6 @@
struct ip_tunnel_parm p;
struct ip_tunnel *t;
- if (!try_module_get(THIS_MODULE))
- return -EBUSY;
-
switch (cmd) {
case SIOCGETTUNNEL:
t = NULL;
@@ -1037,7 +1029,6 @@
}
done:
- module_put(THIS_MODULE);
return err;
}
@@ -1117,8 +1108,6 @@
{
struct ip_tunnel *t = (struct ip_tunnel*)dev->priv;
- if (!try_module_get(THIS_MODULE))
- return -EBUSY;
if (MULTICAST(t->parms.iph.daddr)) {
struct flowi fl = { .oif = t->parms.link,
.nl_u = { .ip4_u =
@@ -1127,16 +1116,12 @@
.tos = RT_TOS(t->parms.iph.tos) } },
.proto = IPPROTO_GRE };
struct rtable *rt;
- if (ip_route_output_key(&rt, &fl)) {
- module_put(THIS_MODULE);
+ if (ip_route_output_key(&rt, &fl))
return -EADDRNOTAVAIL;
- }
dev = rt->u.dst.dev;
ip_rt_put(rt);
- if (__in_dev_get(dev) == NULL) {
- module_put(THIS_MODULE);
+ if (__in_dev_get(dev) == NULL)
return -EADDRNOTAVAIL;
- }
t->mlink = dev->ifindex;
ip_mc_inc_group(__in_dev_get(dev), t->parms.iph.daddr);
}
@@ -1153,7 +1138,6 @@
in_dev_put(in_dev);
}
}
- module_put(THIS_MODULE);
return 0;
}
@@ -1247,31 +1231,12 @@
return 0;
}
-#ifdef MODULE
-static int ipgre_fb_tunnel_open(struct net_device *dev)
-{
- if (!try_module_get(THIS_MODULE))
- return -EBUSY;
- return 0;
-}
-
-static int ipgre_fb_tunnel_close(struct net_device *dev)
-{
- module_put(THIS_MODULE);
- return 0;
-}
-#endif
-
int __init ipgre_fb_tunnel_init(struct net_device *dev)
{
struct ip_tunnel *tunnel = (struct ip_tunnel*)dev->priv;
struct iphdr *iph;
ipgre_tunnel_init_gen(dev);
-#ifdef MODULE
- dev->open = ipgre_fb_tunnel_open;
- dev->stop = ipgre_fb_tunnel_close;
-#endif
iph = &ipgre_fb_tunnel.parms.iph;
iph->version = 4;
@@ -1295,11 +1260,7 @@
* And now the modules code and kernel interface.
*/
-#ifdef MODULE
-int init_module(void)
-#else
int __init ipgre_init(void)
-#endif
{
printk(KERN_INFO "GRE over IPv4 tunneling driver\n");
@@ -1309,13 +1270,12 @@
}
ipgre_fb_tunnel_dev.priv = (void*)&ipgre_fb_tunnel;
+ SET_MODULE_OWNER(&ipgre_fb_tunnel_dev);
register_netdev(&ipgre_fb_tunnel_dev);
return 0;
}
-#ifdef MODULE
-
-void cleanup_module(void)
+void ipgre_fini(void)
{
if (inet_del_protocol(&ipgre_protocol, IPPROTO_GRE) < 0)
printk(KERN_INFO "ipgre close: can't remove protocol\n");
@@ -1323,5 +1283,8 @@
unregister_netdev(&ipgre_fb_tunnel_dev);
}
+#ifdef MODULE
+module_init(ipgre_init);
#endif
+module_exit(ipgre_fini);
MODULE_LICENSE("GPL");
diff -Nru a/net/ipv4/ipip.c b/net/ipv4/ipip.c
--- a/net/ipv4/ipip.c Wed Apr 9 23:34:23 2003
+++ b/net/ipv4/ipip.c Wed Apr 9 23:34:23 2003
@@ -231,13 +231,10 @@
if (!create)
return NULL;
- if (!try_module_get(THIS_MODULE))
- return NULL;
dev = kmalloc(sizeof(*dev) + sizeof(*t), GFP_KERNEL);
- if (dev == NULL) {
- module_put(THIS_MODULE);
+ if (dev == NULL)
return NULL;
- }
+
memset(dev, 0, sizeof(*dev) + sizeof(*t));
dev->priv = (void*)(dev+1);
nt = (struct ip_tunnel*)dev->priv;
@@ -257,6 +254,7 @@
goto failed;
memcpy(nt->parms.name, dev->name, IFNAMSIZ);
}
+ SET_MODULE_OWNER(dev);
if (register_netdevice(dev) < 0)
goto failed;
@@ -267,16 +265,13 @@
failed:
kfree(dev);
- module_put(THIS_MODULE);
return NULL;
}
static void ipip_tunnel_destructor(struct net_device *dev)
{
- if (dev != &ipip_fb_tunnel_dev) {
+ if (dev != &ipip_fb_tunnel_dev)
kfree(dev);
- module_put(THIS_MODULE);
- }
}
static void ipip_tunnel_uninit(struct net_device *dev)
@@ -683,9 +678,6 @@
struct ip_tunnel_parm p;
struct ip_tunnel *t;
- if (!try_module_get(THIS_MODULE))
- return -EBUSY;
-
switch (cmd) {
case SIOCGETTUNNEL:
t = NULL;
@@ -784,7 +776,6 @@
}
done:
- module_put(THIS_MODULE);
return err;
}
@@ -860,30 +851,11 @@
return 0;
}
-#ifdef MODULE
-static int ipip_fb_tunnel_open(struct net_device *dev)
-{
- if (!try_module_get(THIS_MODULE))
- return -EBUSY;
- return 0;
-}
-
-static int ipip_fb_tunnel_close(struct net_device *dev)
-{
- module_put(THIS_MODULE);
- return 0;
-}
-#endif
-
int __init ipip_fb_tunnel_init(struct net_device *dev)
{
struct iphdr *iph;
ipip_tunnel_init_gen(dev);
-#ifdef MODULE
- dev->open = ipip_fb_tunnel_open;
- dev->stop = ipip_fb_tunnel_close;
-#endif
iph = &ipip_fb_tunnel.parms.iph;
iph->version = 4;
@@ -913,6 +885,7 @@
}
ipip_fb_tunnel_dev.priv = (void*)&ipip_fb_tunnel;
+ SET_MODULE_OWNER(&ipip_fb_tunnel_dev);
register_netdev(&ipip_fb_tunnel_dev);
return 0;
}
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: MOD_{INC,SEC}_USE_COUNT() in net/ipv{4,6}
2003-04-10 6:29 ` David S. Miller
@ 2003-04-10 19:11 ` Arnaldo Carvalho de Melo
0 siblings, 0 replies; 5+ messages in thread
From: Arnaldo Carvalho de Melo @ 2003-04-10 19:11 UTC (permalink / raw)
To: David S. Miller; +Cc: kuznet, yoshfuji, netdev, usagi
I'm studying how to properly do this for net_proto_family, hope to get this
done in the weekend. I'm doing the try_module_get(net_families[family]->owner)
at sock_create, etc.
- Arnaldo
Em Wed, Apr 09, 2003 at 11:29:18PM -0700, David S. Miller escreveu:
> From: kuznet@ms2.inr.ac.ru
> Date: Thu, 10 Apr 2003 06:54:38 +0400 (MSD)
>
> Why not to delete this things instead? Calls of these functions
> from inside of module is completely meaningless.
>
> Better to implement correctly than to outright delete.
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2003-04-10 19:11 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-04-09 11:41 MOD_{INC,SEC}_USE_COUNT() in net/ipv{4,6} YOSHIFUJI Hideaki / 吉藤英明
2003-04-10 1:00 ` David S. Miller
2003-04-10 2:54 ` kuznet
2003-04-10 6:29 ` David S. Miller
2003-04-10 19:11 ` Arnaldo Carvalho de Melo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).