Skip to contentSkip to conversation

drivers/net/loopback.c: convert to module_init()

PATCH In review Adrian Bunk 5 participants 17 messages Dec 12, 2006 – Dec 14, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers/net/loopback.c: convert to module_init()

This patch converts drivers/net/loopback.c to using module_init().

---

 drivers/net/Space.c    |   11 -----------
 drivers/net/loopback.c |    4 +++-
 2 files changed, 3 insertions(+), 12 deletions(-)
drivers/net/loopback.c renamed from drivers/net/loopback.c.old +3 -1
@@ -229,9 +229,11 @@
 };
 
 /* Setup and register the loopback device. */
-int __init loopback_init(void)
+static int __init loopback_init(void)
 {
 	return register_netdev(&loopback_dev);
 };
 
+module_init(loopback_init);
+
 EXPORT_SYMBOL(loopback_dev);
drivers/net/Space.c renamed from drivers/net/Space.c.old +0 -11
@@ -345,22 +345,11 @@
 #endif
 
 
-/*
- *	The loopback device is global so it can be directly referenced
- *	by the network code. Also, it must be first on device list.
- */
-extern int loopback_init(void);
-
 /*  Statically configured drivers -- order matters here. */
 static int __init net_olddevs_init(void)
 {
 	int num;
 
-	if (loopback_init()) {
-		printk(KERN_ERR "Network loopback device setup failed\n");
-	}
-
-
 #ifdef CONFIG_SBNI
 	for (num = 0; num < 8; ++num)
 		sbni_probe(num);
maintainer
#1 lore raw

From: Adrian Bunk <[email protected]>
Date: Tue, 12 Dec 2006 17:24:35 +0100

Quoted 3 lines

This patch converts drivers/net/loopback.c to using module_init().

I'm not %100 sure of this one, let's look at the comment you are deleting:

drivers/net/Space.c line 353

Quoted 6 lines
drivers/net/Space.c renamed from drivers/net/Space.c.old +0 -6
-/*
- *	The loopback device is global so it can be directly referenced
- *	by the network code. Also, it must be first on device list.
- */
-extern int loopback_init(void);
-

in particular notice the part that says "it must be first on the device list".

I'm not sure whether that is important any longer. It probably isn't, but we should verify it before applying such a patch.

Since module_init() effectively == device_initcall() for statically built objects, which loopback always is, the Makefile ordering does not seem to indicate to me that there is anything guarenteeing this "first on the list" invariant. At least not via object file ordering.

So this gives some support to the idea that loopback_dev's position on the device list no longer matters.

#2 lore raw
Quoted 23 lines · David Miller

From: Adrian Bunk <[email protected]>
Date: Tue, 12 Dec 2006 17:24:35 +0100

Quoted 3 lines

This patch converts drivers/net/loopback.c to using module_init().

I'm not %100 sure of this one, let's look at the comment you are deleting:

drivers/net/Space.c line 353

Quoted 6 lines
drivers/net/Space.c renamed from drivers/net/Space.c.old +0 -6
-/*
- *	The loopback device is global so it can be directly referenced
- *	by the network code. Also, it must be first on device list.
- */
-extern int loopback_init(void);
-

in particular notice the part that says "it must be first on the device list".

I'm not sure whether that is important any longer. It probably isn't, but we should verify it before applying such a patch.

Quoted 8 lines

Since module_init() effectively == device_initcall() for statically built objects, which loopback always is, the Makefile ordering does not seem to indicate to me that there is anything guarenteeing this "first on the list" invariant. At least not via object file ordering.

So this gives some support to the idea that loopback_dev's position on the device list no longer matters.

That far I already was.

Additionally:
- it works for me (but my e100 is always initialized before loop)
- I didn't spot any obvious interdependency with the other Space.c drivers

It could be I missed anything, but I don't see any better way to verify this than getting the patch into the next -mm and wait whether someone will scream...

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
#3 lore raw

* Adrian Bunk <[email protected]> 2006-12-13 14:40

Quoted 8 lines

Additionally:
- it works for me (but my e100 is always initialized before loop)
- I didn't spot any obvious interdependency with the other Space.c drivers

It could be I missed anything, but I don't see any better way to verify this than getting the patch into the next -mm and wait whether someone will scream...

The loopback was traditionally on ifindex 1, some userspace applications even relied on it but that is no longer true. I think this is safe.

#4 lore raw
In reply to David Miller
Quoted 23 lines · On Tue, 12 Dec 2006 17:17:56 -0800 (PST) David Miller <[email protected]>…

From: Adrian Bunk <[email protected]>
Date: Tue, 12 Dec 2006 17:24:35 +0100

Quoted 3 lines

This patch converts drivers/net/loopback.c to using module_init().

I'm not %100 sure of this one, let's look at the comment you are deleting:

drivers/net/Space.c line 353

Quoted 6 lines
drivers/net/Space.c renamed from drivers/net/Space.c.old +0 -6
-/*
- *	The loopback device is global so it can be directly referenced
- *	by the network code. Also, it must be first on device list.
- */
-extern int loopback_init(void);
-

in particular notice the part that says "it must be first on the device list".

I'm not sure whether that is important any longer. It probably isn't, but we should verify it before applying such a patch.

Quoted 8 lines

Since module_init() effectively == device_initcall() for statically built objects, which loopback always is, the Makefile ordering does not seem to indicate to me that there is anything guarenteeing this "first on the list" invariant. At least not via object file ordering.

So this gives some support to the idea that loopback_dev's position on the device list no longer matters.

The dst code makes assumptions that loopback is ifindex 1 as well. NAK on Adrian's change, it doesn't buy anything

#5 lore raw
Quoted 32 lines · Stephen Hemminger
Quoted 29 lines · On Tue, 12 Dec 2006 17:17:56 -0800 (PST) David Miller <[email protected]>…

From: Adrian Bunk <[email protected]>
Date: Tue, 12 Dec 2006 17:24:35 +0100

Quoted 3 lines

This patch converts drivers/net/loopback.c to using module_init().

I'm not %100 sure of this one, let's look at the comment you are deleting:

drivers/net/Space.c line 353

Quoted 6 lines
drivers/net/Space.c renamed from drivers/net/Space.c.old +0 -6
-/*
- *	The loopback device is global so it can be directly referenced
- *	by the network code. Also, it must be first on device list.
- */
-extern int loopback_init(void);
-

in particular notice the part that says "it must be first on the device list".

I'm not sure whether that is important any longer. It probably isn't, but we should verify it before applying such a patch.

Since module_init() effectively == device_initcall() for statically built objects, which loopback always is, the Makefile ordering does not seem to indicate to me that there is anything guarenteeing this "first on the list" invariant. At least not via object file ordering.

Quoted 5 lines
Quoted 2 lines

So this gives some support to the idea that loopback_dev's position on the device list no longer matters.

The dst code makes assumptions that loopback is ifindex 1 as well.
...

But that assumption is already false for drivers not handled by Space.c:

E.g. on my computer [1], eth0 [2] has ifindex 1 and lo has ifindex 2.

cu
Adrian

[1] plain 2.6.16.36
[2] built-in e100 driver

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
#6 lore raw
In reply to David Miller
Quoted 20 lines · David Miller

From: Adrian Bunk <[email protected]>
Date: Tue, 12 Dec 2006 17:24:35 +0100

Quoted 3 lines

This patch converts drivers/net/loopback.c to using module_init().

I'm not %100 sure of this one, let's look at the comment you are deleting:

drivers/net/Space.c line 353

Quoted 6 lines
drivers/net/Space.c renamed from drivers/net/Space.c.old +0 -6
-/*
- *	The loopback device is global so it can be directly referenced
- *	by the network code. Also, it must be first on device list.
- */
-extern int loopback_init(void);
-

in particular notice the part that says "it must be first on the device list".

Quoted 2 lines

I'm not sure whether that is important any longer. It probably isn't, but we should verify it before applying such a patch.

There might be practical considerations along the lines of "we want lookups for loopback to be fast"...

#7 lore raw

* Al Viro <[email protected]> 2006-12-13 20:12

Quoted 6 lines · David Miller
Quoted 2 lines

I'm not sure whether that is important any longer. It probably isn't, but we should verify it before applying such a patch.

There might be practical considerations along the lines of "we want lookups for loopback to be fast"...

What is this discussion actually about? Since we started registering devices directly hooked into the init process before device_initcall() the order is random. Even the bonding device is registered before the loopback.

#8 lore raw
Quoted 8 lines · On Wed, 13 Dec 2006 21:49:33 +0100 Thomas Graf <[email protected]> wrote:

* Al Viro <[email protected]> 2006-12-13 20:12

Quoted 6 lines · David Miller
Quoted 2 lines

I'm not sure whether that is important any longer. It probably isn't, but we should verify it before applying such a patch.

There might be practical considerations along the lines of "we want lookups for loopback to be fast"...

Quoted 8 lines

What is this discussion actually about? Since we started registering devices directly hooked into the init process before device_initcall() the order is random. Even the bonding device is registered before the loopback.
-
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Loopback should be there before protocols are started. It makes sense to have a standard startup order.

#9 lore raw
Quoted 11 lines · Stephen Hemminger
Quoted 8 lines · On Wed, 13 Dec 2006 21:49:33 +0100 Thomas Graf <[email protected]> wrote:

* Al Viro <[email protected]> 2006-12-13 20:12

Quoted 6 lines · David Miller
Quoted 2 lines

I'm not sure whether that is important any longer. It probably isn't, but we should verify it before applying such a patch.

There might be practical considerations along the lines of "we want lookups for loopback to be fast"...

Quoted 7 lines
Quoted 4 lines

What is this discussion actually about? Since we started registering devices directly hooked into the init process before device_initcall() the order is random. Even the bonding device is registered before the loopback.

Loopback should be there before protocols are started. It makes sense to have a standard startup order.

This actually becomes easier after my patch:

Now that it's untangled from net_olddevs_init(), you can simply change the module_init(loopback_init) to a different initcall level.

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
#10 lore raw

* Adrian Bunk <[email protected]> 2006-12-14 00:12

Quoted 8 lines · Stephen Hemminger
Quoted 2 lines

Loopback should be there before protocols are started. It makes sense to have a standard startup order.

This actually becomes easier after my patch:

Now that it's untangled from net_olddevs_init(), you can simply change the module_init(loopback_init) to a different initcall level.

Not really, the device management inits as subsys, the ip layer hooks into fs_initcall() which comes right after. The loopback was actually registered after the protocol so far. I think Adrian's patch is fine if the module_init() is changed to device_initcall().

#11 lore raw
Quoted 7 lines · Thomas Graf

* Adrian Bunk <[email protected]> 2006-12-14 00:12

Quoted 6 lines · Stephen Hemminger
Quoted 2 lines

Loopback should be there before protocols are started. It makes sense to have a standard startup order.

This actually becomes easier after my patch:

Quoted 7 lines
Quoted 2 lines

Now that it's untangled from net_olddevs_init(), you can simply change the module_init(loopback_init) to a different initcall level.

Not really, the device management inits as subsys, the ip layer hooks into fs_initcall() which comes right after. The loopback was actually registered after the protocol so far. I think Adrian's patch is fine if the module_init() is changed to device_initcall().

It doesn't matter (and I don't care) since for the non-modular case (that always applies for loopback), there's:
#define __initcall(fn) device_initcall(fn)
#define module_init(x) __initcall(x);

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
#12 lore raw
Quoted 16 lines · On Thu, 14 Dec 2006 00:31:28 +0100 Adrian Bunk <[email protected]> wrote:
Quoted 7 lines · Thomas Graf

* Adrian Bunk <[email protected]> 2006-12-14 00:12

Quoted 6 lines · Stephen Hemminger
Quoted 2 lines

Loopback should be there before protocols are started. It makes sense to have a standard startup order.

This actually becomes easier after my patch:

Quoted 7 lines
Quoted 2 lines

Now that it's untangled from net_olddevs_init(), you can simply change the module_init(loopback_init) to a different initcall level.

Not really, the device management inits as subsys, the ip layer hooks into fs_initcall() which comes right after. The loopback was actually registered after the protocol so far. I think Adrian's patch is fine if the module_init() is changed to device_initcall().

Quoted 8 lines

It doesn't matter (and I don't care) since for the non-modular case (that always applies for loopback), there's:
#define __initcall(fn) device_initcall(fn)
#define module_init(x) __initcall(x);

cu
Adrian

But what if other network device is not a module. We want loopback to be first. so it needs to be before other device_initcall's

maintainer
#13 lore raw

From: Stephen Hemminger <[email protected]>
Date: Wed, 13 Dec 2006 15:41:25 -0800

Quoted 2 lines

But what if other network device is not a module. We want loopback to be first. so it needs to be before other device_initcall's

There is zero evidence that loopback must be first.

I was not able to provide any after my study of the code last night, and I haven't seen any concrete proof shown today either.

You mentioned "the dst code" relies on ifindex==1, what exactly do you mean by that? Give specific code examples instead of ambiguous and non-specific references.

And this claim doesn't make any sense, because anyone who looks at drivers/net/Makefile can see that several drivers are linked in way before Space.o, and thus when built statically would today end up in the device list way before the loopback driver. So it can't be "broken" by Adrian's change, since it's already not putting loopback first and we can prove this! :-)

maintainer
#14 lore raw
In reply to Stephen Hemminger

From: Stephen Hemminger <[email protected]>
Date: Wed, 13 Dec 2006 15:41:25 -0800

Quoted 2 lines

But what if other network device is not a module. We want loopback to be first. so it needs to be before other device_initcall's

That's not happening today, so it's "broken" today, which suggests that the order in all likelyhood no longer matters.

maintainer
#15 lore raw
In reply to Thomas Graf

From: Thomas Graf <[email protected]>
Date: Thu, 14 Dec 2006 00:18:48 +0100

Quoted 4 lines

Not really, the device management inits as subsys, the ip layer hooks into fs_initcall() which comes right after. The loopback was actually registered after the protocol so far. I think Adrian's patch is fine if the module_init() is changed to device_initcall().

module_init == device_initcall when the object is being compiled statically into the kernel, which is always the case for the loopback driver

I mentioned this in my original reply to Adrian, just in case anyone happened to actually read that :-)

maintainer
#16 lore raw
In reply to Al Viro

From: Al Viro <[email protected]>
Date: Wed, 13 Dec 2006 20:12:14 +0000

Quoted 2 lines

There might be practical considerations along the lines of "we want lookups for loopback to be fast"...

We have that taken care of, it's called "&loopback_dev".

None of the performance-caring paths do dev_get_by_name("lo")