Skip to contentSkip to conversation

Why /dev/sdc1 doesn't show up...

DISCUSSION Rusty Russell 6 participants 8 messages Nov 19, 2002 – Nov 20, 2002 SCSI

lore
Share & tools
lore
#0 lore raw
Quoted 2 lines

right). Or you can run a notifier on "enlivening" a module: I'd hoped to avoid that.

Actually, after some thought, this seems to clearly be the Right Thing, because it solves another existing race. Consider a module which does:

	if (!register_foo(&my_foo))
		goto cleanup;
	if (!create_proc_entry(&my_entry))
		goto cleanup_foo;

If register_foo() calls /sbin/hotplug, the module can still fail to load and /sbin/hotplug is called for something that doesn't exist. With the new module loader, you can also have /sbin/hotplug try to access the module before it's gone live, which will fail to prevent the "using before we know module won't fail init" race.

Now, if you run /sbin/hotplug out of a notifier which is fired when the module actually goes live, this problem vanishes. It also means we can block module unload until /sbin/hotplug is run.

The part that makes this feel like the Right Thing is that adding to init/main.c:

	/* THIS_MODULE == NULL */
	notifier_call_chain(&module_notifiers, MODULE_LIVE, NULL);

means that /sbin/hotplug is called for everything which was registered at boot. (We may not want to do this, but in general the symmetry seems really nice).

[ Note: the logic for /sbin/hotplug applies to any similar "publicity"
function which promises that something now exists. ]

Al, thoughts?
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

#1 lore raw
Quoted 9 lines · Rusty Russell

means that /sbin/hotplug is called for everything which was registered at boot. (We may not want to do this, but in general the symmetry seems really nice).

[ Note: the logic for /sbin/hotplug applies to any similar "publicity"
function which promises that something now exists. ]

Al, thoughts?
Rusty.

Wrong granularity. "module had finished initialization" is _not_ a natural event wrt stuff exported by that module. And that's one of the main problems I have with your approach - you are trying to make module loader do the stuff that has nothing whatsoever with modules.

Moreover, if driver is built into the kernel, you get (at the very least) a different mechanism for triggering the same events, if not the outright different sequence of events. Which is a Bad Thing(tm) since it leads to a shitload of extra problems with debugging.

I went through the init code of all block device drivers and there was a metric buttload of crap in handling failures. I doubt that more than 5% had any relation to races - much more often taking given failure path had lead to oops. Deterministic one. With nothing else happening with the system.

Double freeing. Forgetting to free. Dereference after freeing. Leaving timers active. Leaving pointers to local structures in global arrays. Plain and simple dereferencing of NULL due to wrong order. Freeing what you had never allocated. Similar for resources other than memory. Doing cleanup in a fashion that screws other drivers. IOW, all sorts of crap that can accumulate in a spaghetty code that never got any serious testing. Path-dependent crap, at that - different exits are fscked in different ways.

On that background all shite you are so concerned about is a noise. More often than not, screwups in export order that might be papered over by your semantics change either do not matter since the module doesn't fail in init _or_ do not matter since it does fail and gets the system fscked to hell and back on the failure exit path, races or not.

In other words, this band-aid doesn't do anything useful - if you go and fix the crap in driver's init you can fix the export order while you are at it. If you do not - pray that failure will not happen, because it it will you are screwed without any races.

There is no fscking way for module loader to handle that. Leave it as-is, possibly making the loader BUG() if init fails and refcount is positive. Anything beyond that is not a responsibility of modules code. Note that such BUG() doesn't add any new breakage - such situation had always been a bug.

And yes, that means the need to fix the error recovery in driver init. Tough. I don't know any other way to handle

	kfree(p);
	p = NULL;
	kfree(p->bar);

and I don't believe that you can find one. Again, no silver bullets - if you want to talk about handling half-way failures in module init, be ready to deal with the above (embedded into the mess of goto and function calls, to boot).

We are talking about bugs that had always been on these codepaths - both in modular and built-in cases. They need to be dealt with before we can do anything about these codepaths. Has nothing to module loader...

What we _can_ do (and that will be on per-subsystem basis) is providing APIs that would cut down on the amount of glue needed in driver init. And that's where switch to use of /sbin/hotplug (again, on per-subsystem basis) might help big way. But for each subsystem that will require looking through the drivers using it.

BTW, remember the flamef^Warguments about turning kdev_t into a pointer and thus avoiding digging through piles and piles of cr^Hode? Didn't fly for exactly the same reasons - there's no way to do it magically for entire kernel without breaking tons of code and/or creating an impossible-to-debug mess...

#2 lore raw

In message <[email protected]> you write:

Quoted 2 lines

Wrong granularity. "module had finished initialization" is _not_ a natural event wrt stuff exported by that module.

Well, I have to disagree here. "I have successfully finished my initialization" is the same logic you're trying to beat into module author's heads before they commit their interfaces.

Quoted 3 lines

And that's one of the main problems I have with your approach - you are trying to make module loader do the stuff that has nothing whatsoever with modules.

Or, put another way, I'm trying to ensure that correct code in the kernel is correct code in a module, by having the module code simulate the conditions in which the original occurred.

Quoted 4 lines

Moreover, if driver is built into the kernel, you get (at the very least) a different mechanism for triggering the same events, if not the outright different sequence of events. Which is a Bad Thing(tm) since it leads to a shitload of extra problems with debugging.

Speaking of which, what's the long-term plan for hotplug events at boot? Will you get a shitload of "add" events, or rely on userspace to scan?

Quoted 2 lines

Double freeing. Forgetting to free. Dereference after freeing. Leaving timers active. Leaving pointers to local structures in global arrays.

Hmm, my audit of copy_to/from_user uncovered similar bogosities, and I've dropped more than one Trivial Patch Monkey patches because they cleaned up one case in an incurable sewer of problems 8(

The "better to have a bad driver than no driver" becomes less true as people start copying from it, too. This is where meta-maintainers like Jeff Garzik make a definite difference as chief shit-kicker.

Quoted 1 line

On that background all shite you are so concerned about is a noise.

Perhaps. But I can't change the world: that's your job.

Quoted 2 lines

What we _can_ do (and that will be on per-subsystem basis) is providing APIs that would cut down on the amount of glue needed in driver init.

Fervently agree: it's hard to get one line wrong, *and* almost any scheme can be implemented on top of it.

Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

#3 lore raw
In reply to Alexander Viro
Quoted 5 lines · Alexander Viro

BTW, remember the flamef^Warguments about turning kdev_t into a pointer and thus avoiding digging through piles and piles of cr^Hode? Didn't fly for exactly the same reasons - there's no way to do it magically for entire kernel without breaking tons of code and/or creating an impossible-to-debug mess...

You never convinced me. Maybe we ever meet and can talk..

In the meantime:
Yesterday or so I built versions of 2.5.48 with 32-bit and 64-bit dev_t.

The code is full of conversions dev_t -> int -> dev_t -> int. Ugly. I gave the mknod method in struct inode_operations type

	int (*mknod) (struct inode *,struct dentry *,int,dev_t);

thus avoiding much conversion.
Do you have objections?

Andries

# mount /dev/hde6 /fbsd6 -t ufs -o ufstype=44bsd,ro
# ./ls -l /fbsd6/dev/da2s[34]
brw-r-----   1     root      disk    4, 0x040012 Oct 31 21:06 /fbsd6/dev/da2s3
brw-r-----   1     root      disk    4, 0x050012 Oct 31 21:06 /fbsd6/dev/da2s4
#
#4 lore raw
In reply to Rusty Russell
Quoted 11 lines · Rusty Russell
Quoted 2 lines

right). Or you can run a notifier on "enlivening" a module: I'd hoped to avoid that.

Actually, after some thought, this seems to clearly be the Right Thing, because it solves another existing race. Consider a module which does:

	if (!register_foo(&my_foo))
		goto cleanup;
	if (!create_proc_entry(&my_entry))
		goto cleanup_foo;

There is *NO* module that does this right now and can be considered even close to working. The rule always has been "register yourself when you are ready for use". You're trying to add this new "You can fail after registering yourself" semantic for brain dead coders that can't write an init function to save thier ass. My position is that in doing so, you fuck all of us that do write a reasonable init sequence and handle our error conditions. Plus, since this is a changes in semantics, you have possibly 50 or 100 modules that rely on the old behaviour, and maybe a few that are broken in regards to registration ordering. I think you are trying to fix the wrong group of modules here.

So, to me, the answer is clear. The rule is hard and fast, you don't hand out your function pointers to other modules or the core kernel until you are ready for them to be used. Don't muck with the module loader to solve the problem, fix the maybe 4 or 5 modules that might violate this rule.

Quoted 2 lines

If register_foo() calls /sbin/hotplug, the module can still fail to load and /sbin/hotplug is called for something that doesn't exist.

Which is just totally fucking stupid on the part of any module author that would do things in that order. You're trying to write a module loader that makes it safe for a module author to be a total moron. Don't. Let the morons go code somewhere else. For the kernel, make them follow a few sensible rules instead of enforcing moron proof crap on everyone else.

Quoted 14 lines

With the new module loader, you can also have /sbin/hotplug try to access the module before it's gone live, which will fail to prevent the "using before we know module won't fail init" race.

Now, if you run /sbin/hotplug out of a notifier which is fired when the module actually goes live, this problem vanishes. It also means we can block module unload until /sbin/hotplug is run.

The part that makes this feel like the Right Thing is that adding to init/main.c:

	/* THIS_MODULE == NULL */
	notifier_call_chain(&module_notifiers, MODULE_LIVE, NULL);
Quoted 8 lines

means that /sbin/hotplug is called for everything which was registered at boot. (We may not want to do this, but in general the symmetry seems really nice).

[ Note: the logic for /sbin/hotplug applies to any similar "publicity"
function which promises that something now exists. ]

Al, thoughts?

I actually like the idea of having an automatic go live function that we can trigger, but I still don't think that justifies blocking a module from entering itself during init.

Signature · 4 lines
  Doug Ledford <[email protected]>     919-754-3700 x44233
         Red Hat, Inc. 
         1801 Varsity Dr.
         Raleigh, NC 27606
#5 lore raw
In reply to Rusty Russell
Quoted 26 lines · Doug Ledford
Quoted 11 lines · Rusty Russell
Quoted 2 lines

right). Or you can run a notifier on "enlivening" a module: I'd hoped to avoid that.

Actually, after some thought, this seems to clearly be the Right Thing, because it solves another existing race. Consider a module which does:

	if (!register_foo(&my_foo))
		goto cleanup;
	if (!create_proc_entry(&my_entry))
		goto cleanup_foo;

There is *NO* module that does this right now and can be considered even close to working. The rule always has been "register yourself when you are ready for use". You're trying to add this new "You can fail after registering yourself" semantic for brain dead coders that can't write an init function to save thier ass. My position is that in doing so, you fuck all of us that do write a reasonable init sequence and handle our error conditions. Plus, since this is a changes in semantics, you have possibly 50 or 100 modules that rely on the old behaviour, and maybe a few that are broken in regards to registration ordering. I think you are trying to fix the wrong group of modules here.

Quoted 4 lines

So, to me, the answer is clear. The rule is hard and fast, you don't hand out your function pointers to other modules or the core kernel until you are ready for them to be used. Don't muck with the module loader to solve the problem, fix the maybe 4 or 5 modules that might violate this rule.

violently agreed. This has the potential for requiring an update of almost every driver in the kernel, does it not?

Jeff

#6 lore raw

In message <[email protected]> you write:

Quoted 7 lines
Quoted 3 lines · Doug Ledford

are ready for them to be used. Don't muck with the module loader to solve
the problem, fix the maybe 4 or 5 modules that might violate this rule.

violently agreed. This has the potential for requiring an update of almost every driver in the kernel, does it not?

God no! I'm crazy maybe, but not stupid. I know of two interfaces which would be affected, and no drivers.

Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

#7 lore raw
In reply to Jeff Garzik

[ cc trimmed a-plenty ]

Quoted 21 lines · Jeff Garzik
Quoted 12 lines

There is *NO* module that does this right now and can be considered even close to working. The rule always has been "register yourself when you are ready for use". You're trying to add this new "You can fail after registering yourself" semantic for brain dead coders that can't write an init function to save thier ass. My position is that in doing so, you fuck all of us that do write a reasonable init sequence and handle our error conditions. Plus, since this is a changes in semantics, you have possibly 50 or 100 modules that rely on the old behaviour, and maybe a few
that are broken in regards to registration ordering. I think you are trying to fix the wrong group of modules here.

Quoted 6 lines

So, to me, the answer is clear. The rule is hard and fast, you don't hand
out your function pointers to other modules or the core kernel until you are ready for them to be used. Don't muck with the module loader to solve
the problem, fix the maybe 4 or 5 modules that might violate this rule.

Quoted 2 lines

violently agreed. This has the potential for requiring an update of almost every driver in the kernel, does it not?

jeff, why not put some sample code in prominent public places (kernel.org, or perhaps more appropriately kernelnewbies.org) that provides examples of sane module code, since that appears to be the problem here.

i ask you since i have a vague recollection of you mentioning macro-fying all the nic drivers with m4 a while back, and to do this you must have had some sort of basic skeleton to flesh out.

it won't help the idiots, but it may help people who are less than intimate with the rules and regulations of lunix module authoring (perhaps having come from a different OS).

j.

Signature · 1 line
toyota power: http://indigoid.net/