Skip to contentSkip to conversation

Patch: linux-2.5.42/kernel/sys.c - warm reboot should not suspend devices

DISCUSSION Adam J. Richter 4 participants 4 messages Oct 14, 2002 – Oct 16, 2002

lore
Share & tools
lore
#0 lore raw
Quoted 6 lines · Eric W. Biederman
Quoted 4 lines · Adam J. Richter
Quoted 3 lines · Eric W. Biederman
Quoted 1 line · Russell King

"rebooting" in this particular case is "turn MMU off, jump to location 0"

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

And for x86 it is turn MMU off, jump to location 0xffff0.

The default reboot method of linux-2.5.42 on x86 is to have the
keyboard controller do a reset.

Resetting the cpu != resetting the system. And the keyboard controller only does a cpu level reset. Which is basically a convoluted way to jump
to: 0xfffffff0.

I would be quite surprised if that reset was not wired
to eventually ground RST# on the PCI bus.

[...]

Quoted 17 lines
Quoted 8 lines
        if(!reboot_thru_bios) {
                /* rebooting needs to touch the page at absolute addr 0 */
                *((unsigned short *)__va(0x472)) = reboot_mode;
                for (;;) {
                        int i;
                        for (i=0; i<100; i++) {
                                kb_wait();
                                udelay(50);
Quoted 8 lines
                                outb(0xfe,0x64);         /* pulse reset low */
                                udelay(50);
                        }
                        /* That didn't work - force a triple fault.. */
                        __asm__ __volatile__("lidt %0": :"m" (no_idt));
                        __asm__ __volatile__("int3");
                }
        }
Quoted 3 lines

Please note the write to: 0x40:0x72. If this was a full machine reset this would not make sense as memory would need to be reinitialized making it unsafe to keep values in ram.

The issue is not how you define the term "full machine reset."
The issue is whether the PCI bus is eventually reset as a result of this procedure before by BIOS Power On Self Test starts executing at 0xffff00. If it is, then most of the device cleanup is unnecessary. Even if it does not, it would make a lot more sense to just have machine_reset assert RST# after those few devices that really need cleanup are done.

Quoted 10 lines
Quoted 9 lines
Quoted 1 line · you

Exactly an in spec, PC does not need to ground RST# on reboot.

By "as in spec", were you referring to my quotation from _PCI
System Architecture, 4th Ed._ by Shanley and Anderson or are saying that there is a specification that supports your statement that "a PC does not need to ground RST# on reboot." If the latter, I would appreciate it if you would identify that specification and the appropriate section with it for verification.

Quoted 3 lines

I'd love to but mostly I was referring to the de facto standard for pc architecture. Which I don't know if anyone ever wrote down, all in one place.

Please do not say "as in spec" if you are not actually
referrring to a specification document (electronic form is OK). It is extremely misleading as to how reliable your claims are. Instead, please indicate what you remember about where you learned this information.

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines · Elsewhere you

Additionally it was decided quite a
while ago that calling device->remove() was the correct way to accomplish this.

Quoted 8 lines
Quoted 4 lines

Do you remember where this "was decided?" If it was on an
archived mailing list, do you remember approximately when and what the subject line might be? I'd like to look at this discussion both to verify you statement and to avoid repetition.

No. I was not in on that conversation. However given the fact it is all over the documentation. And has been in the kernel for quite a while now. I tracked it as early as 2.5.30.

Making stuff up just to win an argument is unlikely to produce
the best Linux kernel. If you don't remember things, if you're not sure of something, please just admit it instead of wasting an iteration of email by faking authoratitive references.

Quoted 18 lines

This is both device_shutdown in the reboot path,
and device_shutdown calling ->remove()

Quoted 11 lines
Quoted 6 lines · In another message you

machine_restart returns control to the BIOS.
It works this way on both x86 and alpha. And the BIOS does not always toggle the RESET line on the machine. The frequent case of devices not working in Linux after rebooting from windows, and visa versa is evidence of this. On alpha the SRM doesn't even pretend to reset the machine.

Here you are talk first about doing a warm reboot from Windows
to Linux and the device does not work. That sounds like a quirky device.

No it sounds like a driver that either can or cannot handle devices in an arbitrary state.

Quoted 8 lines
Quoted 5 lines

Also, you have failed to show that this is a device where the Linux driver's ->remove() function solves the problem and that there are so many of these devices that (where the remove function *does* solve the problem and there is no reboot notifier) that it would be impractical change those drivers.

I do not feel I need to defend the status quo. It is you who are proposing a change that needs to support why using ->remove() is a bad way to go.

sys_reboot does not call device_shutdown in 2.4.19 and it was
added to 2.5 in 2.5.8, so calling it status quo to the point where you think there is no need to defend it is pretty iffy. If most Linux systems are running 2.4 these days, then it appears that most are running without the ->remove() call just fine.

Also, it's not just a question of whether you should feel a
need to defend the status quo. The reality is that you made some factual claims ("frequent case of devices not working in Linux after rebooting from windows") and you seem to be unable to support, espeically with regard to the question of how many of these devices actually started to work correctly with ->remove() and which do not work without it (i.e., do not work in 2.4.19 but do work in 2.5.8+). I wouldn't have a problem with it if you would just admit that you don't remember or that you may have accidentally made this up or that you were repeating something you heard elsewhere but never checked, and we could weight that information accordingly.

Quoted 2 lines

I will just say that shutting devices in a depth first manner is a lot safer, and more reliable than a random walk, you will get with a reboot notifier.

I already said that I don't have a problem with having a
reboot notifier call in struct device for those devices that need some sort of specific shutdown code that cannot be handled by resetting their parent bus or something similar.

Quoted 8 lines
Quoted 5 lines

If the problem is that the warm reboot procedure failed to
"stop any ongoing DMA, etc." as you put it, then failure mode that you would more typically expect would be memory corruption, manifesting itself as random of other programs, not getting through the reboot process half of the time, etc.

You would only see it on the boot up side. Not placing devices in a consistent state so another os can talk to them is significant as well.

I quite don't understand what you're saying here. Are you
saying people usually cannot boot from linux-2.4.19 into Windows?

Quoted 10 lines
Quoted 5 lines

The underlying trade-off is that if I want to reboot fast, I
should not have to call a bunch of hotplug routines that have to do a lot of book keeping because they have to assume that the computer may continue to run user level programs indefinitely after they return (things like deallocating memory, unregistering devfs inodes, etc.).

I would be very surprised if this showed up in practice. If Russell King makes the argument about excess book keeping slowing things down. I will buy it because he runs on some very slow machines. Personally I doubt anything will be user noticeable.

When you want to optimize for resources like speed and space,
one is generally happy if an optimizations by a percent or two at a time. These calls can do IO. It could add up. Also, for code compiled into the kernel (or non-unloadable modules if anyone implements them, I suppose), it means that otherwise could be compiled out with __exit, so you have a bigger kernel foot print. Finally, from a reliability standpoint, in the case of rebooting because of a kernel bug, it means that the reboot process wants to execute code and walk through data structures in many more drivers.

Quoted 6 lines
Quoted 5 lines

On the other hand, if I want to halt, I really do want the disks to be spun down even if my motherboard does not do a master power-off from software. Doing that requires that the power management request that reboot makes differ from the one that halt makes. So they could not both be just "device_shtudown();".

Quoted 8 lines

So you want to send device_suspend(?, SUSPEND_POWER_DOWN) on a halt. Or do a software shutdown thing.

Whoever mapped the SUSPEND_SHUT_DOWN to SUSPEND_POWER_DOWN very much had it wrong when that code was merged with 2.5.42.

Mostly it looks to me that you have a problem with IDE driver spinning down disks on reboot. That change also is new in 2.5.41.

You do not understand. The fundamental problem is that
sys_reboot in linux-2.5.42/kernel/sys.c makes exactly the same power management call for a reboot and for a halt (device_shutdown()). I want my IDE, SCSI, USB, and FireWire hard disks to spin down if I do a halt. I do not want them to do that when I reboot. I also do not want my reboot to wait for an interrupt from a sound card because remove() needs to determine if it is being called because the device had just been unplugged. It is not just about IDE disk drives.

Adam J. Richter     __     ______________   575 Oroville Road
[email protected]     \ /                  Milpitas, California 95035
+1 408 309-6081         | g g d r a s i l   United States of America

"Free Software For The Rest Of Us."

#1 lore raw

For why 2.5.xx does as it does talk to the people who introduced are working on the driver model.

Docs are in Documentation/driver-model.
I am satisfied that there is some uniform policy in place that device drivers can uniformly tap into.

As for just using the reboot notifier. There are other times the same code should be called, like in the rmmod path so I don't think it should have a special case just for reboot.

For myself I am happy that someone introduced
device_shutdown and it has reasonable semantics.

As for halting the system, we currently have two cases:

	case LINUX_REBOOT_CMD_HALT:
		notifier_call_chain(&reboot_notifier_list, SYS_HALT, NULL);
		system_running = 0;
		device_shutdown();
		printk(KERN_EMERG "System halted.\n");
		machine_halt();
		do_exit(0);
		break;

	case LINUX_REBOOT_CMD_POWER_OFF:
		notifier_call_chain(&reboot_notifier_list, SYS_POWER_OFF, NULL);
		system_running = 0;
		device_shutdown();
		printk(KERN_EMERG "Power down.\n");
		machine_power_off();
		do_exit(0);
		break;

And quite possibly we should have a third:

	case LINUX_REBOOT_CMD_SOFTWARE_POWER_OFF:
		notifier_call_chain(&reboot_notifier_list, SYS_POWER_OFF, NULL);
		system_running = 0;
                suspend_device(SUSPEND_POWER_OFF);
                device_shutdown();
		printk(KERN_EMERG "Power down.\n");
		machine_halt();
		do_exit(0);
		break;

Yes there is a bug in 2.5.42 that maps SUSPEND_POWER_OFF to SUSPEND_SHUT_DOWN, but with that fixed you get a case that does what you want trivially.

More capable halt functions have been in the kernel. Please let's enhance the halt path instead of denuding the reboot path.

Quoted 8 lines

You do not understand. The fundamental problem is that
sys_reboot in linux-2.5.42/kernel/sys.c makes exactly the same power management call for a reboot and for a halt (device_shutdown()). I want my IDE, SCSI, USB, and FireWire hard disks to spin down if I do a halt. I do not want them to do that when I reboot. I also do not want my reboot to wait for an interrupt from a sound card because remove() needs to determine if it is being called because the device had just been unplugged. It is not just about IDE disk drives.

If detecting hot-plug removal is non-trivial that makes the work remove does not suitable for a reboot. However all of the hot-plug layers I am aware of give an interrupt when a device is removed so that should be trivially fixable by simply passing that information. Though I would expect a simple pci_read_config_byte to be just as good.

Do you seriously have a hot-plug sound card, that waits for an interrupt to be certain the card is plugged in during remove?

If there is non-trivial work to detect if a card is present it probably makes sense to factor remove into
->quiet() and ->remove()
Where quiet would put the device into a quiescent state, and remove would simply clean up the driver state.

But for the most part my impression is that we need to get devices
drivers behaving properly in the 2.5.x And that the basic model
is o.k. It just needs some pounding on the rough spots.

Eric

#2 lore raw
Quoted 15 lines · Eric W. Biederman

For myself I am happy that someone introduced
device_shutdown and it has reasonable semantics.

As for halting the system, we currently have two cases:

	case LINUX_REBOOT_CMD_HALT:
		notifier_call_chain(&reboot_notifier_list, SYS_HALT, NULL);
		system_running = 0;
		device_shutdown();
		printk(KERN_EMERG "System halted.\n");
		machine_halt();
		do_exit(0);
		break;
Quoted 9 lines
	case LINUX_REBOOT_CMD_POWER_OFF:
		notifier_call_chain(&reboot_notifier_list, SYS_POWER_OFF, NULL);
		system_running = 0;
		device_shutdown();
		printk(KERN_EMERG "Power down.\n");
		machine_power_off();
		do_exit(0);
		break;

i see four occurences in my 2.5.42: LINUX_REBOOT_CMD_RESTART,
LINUX_REBOOT_CMD_HALT, LINUX_REBOOT_CMD_POWER_OFF, and LINUX_REBOOT_CMD_RESTART2

Quoted 4 lines

But for the most part my impression is that we need to get devices
drivers behaving properly in the 2.5.x And that the basic model
is o.k. It just needs some pounding on the rough spots.

I agree on this point :)

#3 lore raw
In reply to Adam J. Richter

Hi!

Quoted 6 lines
Quoted 3 lines

Resetting the cpu != resetting the system. And the keyboard controller only does a cpu level reset. Which is basically a convoluted way to jump
to: 0xfffffff0.

I would be quite surprised if that reset was not wired
to eventually ground RST# on the PCI bus.

Surprise for you, then. That reset was used to return to real mode by win31 & similar. Resetting PCI would screw that.

				PavelEnd_of_mail_magic_4669