Skip to contentSkip to conversation

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

DISCUSSION Adam J. Richter 3 participants 5 messages Oct 14, 2002

lore
Share & tools
lore
#0 lore raw
Quoted 4 lines · Eric W. Biederman
Quoted 1 line · Russell King

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

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. If you want to reboot by jumping to ffff00, you have to pass "reboot=b" unless you are running on one of three specific models of computers: the Dell PowerEdge 300, 1300 or 2400 (linux-2.5.42/arch/i386/kernel/dmi-scan.c line 522). Here is the relevant excerpt from machine_restart in linux-2.5.42/arch/i386/reboot.c:

        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);
                                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 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 · Elsewhere you

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

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.

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. 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.

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.

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.). 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();".

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
Quoted 9 lines · Adam J. Richter
Quoted 4 lines · Eric W. Biederman
Quoted 1 line · Russell King

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

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.

Quoted 6 lines

If you want to reboot by jumping to ffff00,
you have to pass "reboot=b" unless you are running on one of three specific models of computers: the Dell PowerEdge 300, 1300 or 2400 (linux-2.5.42/arch/i386/kernel/dmi-scan.c line 522). Here is the relevant excerpt from machine_restart in linux-2.5.42/arch/i386/reboot.c:

Quoted 16 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);
                                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");
                }
        }

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.

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.

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.

Quoted 9 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.

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.

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 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.

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.

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.

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.

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();".

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.

Eric

#2 lore raw
Quoted 9 lines · Eric W. Biederman
Quoted 7 lines · Adam J. Richter
Quoted 4 lines · Eric W. Biederman
Quoted 1 line · Russell King

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

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

Quoted 7 lines
Quoted 2 lines

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.

If you really do get to 0xfffffff0, in real mode, you reset the CPU and the BIOS will perform a complete reinitialization of everything unless data at absolute address 0x0472 tells the BIOS not to. If the entry is 0x1234, the BIOS will bypass the memory test, but this does not guarantee that memory contents are saved. It just speeds up the boot. If the entry is 0x4321, the BIOS will not initialize memory nor its controller. RAM contents will be saved.

This is all documented in "System BIOS for IBM PC/XT/AT Computers and Compatibles", Phoenix Technologies, Ltd. Addison-Wesley Publishing Company, Inc. ISBN 0-201-51806-6. This is the "bible" of the BIOS industry because Phoenix was the first to document what IBM BIOS did, and then, using "clean-room" techniques, write a BIOS from that documentation.
[SNIPPED...]

Quoted 5 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.

This effectively hits the reset button. This will reset anything that is connected to the reset line which includes the memory controller. You don't want to do this if you intend to preserve RAM contents.

[SNIPPED...]

Quoted 4 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.

See above. It's documented well enough so you can "roll your own" from the specification alone.

[SNIPPED...]

Quoted 4 lines

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

Some drivers don't work after a "warm-boot" because the I/O resources shown in the PCI initialization have changed. It's only after they get hit with a reset that they put their default resource type and length back into their registers. I am told that some lap-tops have semi-documented methods of sending a hardware reset to the PCI bridge(s) only. This is needed to get them into a restartable state.

[SNIPPED...]

Quoted 4 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.

Shutting down devices seldom (perhaps never) restores the reset-entries of the PCI devices. If this was done, it might make warm-boot restarts more reliable. Emphasis on the 'might'.

Quoted 6 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.

A processor reset will get the processor onto the bus even if there is an ongoing DMA operation. Since the first of many instructions are fetched from ROM, it is quite likely that any DMA activity would have stopped before the ROM is shadowed by the BIOS. I don't see "ongoing" DMA as being a problem, which you can verify by forcing a reset in the FDC code (easiest to do) while waiting for read DMA to complete. FDC DMA is slow, so you can catch it 100% of the time.

Quoted 3 lines

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.

The BIOS is the only thing that can really put the devices into a consistant state because, in the case of PCI initialization, if the device requests no resources upon startup, it's not going to get any. The only "known" way to get the devices to write their true resource requests into their registers is a hardware reset.

[SNIPPED...]

Cheers,
Dick Johnson
Penguin : Linux version 2.4.18 on an i686 machine (797.90 BogoMips). The US military has given us many words, FUBAR, SNAFU, now ENRON. Yes, top management were graduates of West Point and Annapolis.

#3 lore raw

So in summary.
- Asserting the system level reset line is the most reliable way to reboot.

Note: This is not always true, I have seen machines with hardware bugs where asserting the reset line destabilizes things. And they do not come back reliably.

- The kernel does not assert this line but politely requests the x86 BIOS to do so.

- There is at least some BIOS code that runs before the reset line is toggled. And the reset line may not actually be toggled.

If we want reliable reboots what can the Linux kernel do.
1) Include chipset+motherboard specific logic that toggles the reset line directly.
2) Walk the driver tree and ask the drivers politely to place their devices in a reasonable state.

The dangers of not doing this are:
- Network cards can DMA random packets into memory. And if the network is quiet this can take a while.

- Disks can have multiple outstanding disk requests and may DMA them into memory as well.

- Drivers may not be able to initialize a device in a random state. I doubt you can do much with a floppy or ide device that is transfer data via pio and the transaction is left half finished.

- On some platforms if we reassign device resources the firmware may fail to track where the new resources are. This is arguably a firmware bug.

Additionally there is one extra nasty case. On some platforms the firmware cannot reliably reboot in a reasonable amount of time. On those platforms we need some kind of soft reboot that does the Linux booting linux thing to get a reliable reboot in a reasonable amount of time.

I am all for reboots being fast. But until I observe that walking the device tree and placing devices in a quiescent state is a major time waster I do not see that we should skip it. And given the recent problems with the IDE driver I think it is good that we are running this code on every reboot so we can see the drivers that take way to much time placing their devices in a quiescent state.

With respect to the IDE code if we have to spin down the disk to get a reliable sync we should do this whenever the sync command is issued. Or we could have data loss from an unplanned power outage. When I ask the device driver to let go of the device, turning it off sounds quite excessive to me.

Quoted 6 lines · Richard B. Johnson

Some drivers don't work after a "warm-boot" because the I/O resources shown in the PCI initialization have changed. It's only after they get hit with a reset that they put their default resource type and length back into their registers. I am told that some lap-tops have semi-documented methods of sending a hardware reset to the PCI bridge(s) only. This is needed to get them into a restartable state.

I have only seen this on Alpha, with the SRM. Or with drivers that think they are dealing with ISA devices when they are not.

In a standard pci base address register, you can always derive the resource type, and length. In fact the kernel does this when
it loads. You do not need a pci reset to be able to get the
pci base address, and resource size out of a pci bar.

Actually I can confirm that pci devices do not place anything special in their bars after a pci reset. Since a random bar is safe they save hardware circuits not setting it to anything during a reset. I have actually had this byte me, in conjunction with detecting read-only BARs.

Quoted 7 lines

A processor reset will get the processor onto the bus even if there is an ongoing DMA operation. Since the first of many instructions are fetched from ROM, it is quite likely that any DMA activity would have stopped before the ROM is shadowed by the BIOS. I don't see "ongoing" DMA as being a problem, which you can verify by forcing a reset in the FDC code (easiest to do) while waiting for read DMA to complete. FDC DMA is slow, so you can catch it 100% of the time.

I have seen it as a problem in real life. With a NIC several seconds after a reboot. The network was quiet and than an arp request came in. So baring a reset of the device in question this can happen.

So in summary:
I am firmly convinced that:
- device_shutdown should walk the device tree asking drivers to place their devices in a quiescent state. ->remove() is likely the right method for this, and it what the device-mode people have selected. I personally don't care so long as there is an appropriate method.

- device_shutdown should be fast.

- The kernel has more general hardware knowledge than the BIOS so it is more likely to get the case of a soft reboot (no reset line asserted) correct.

- The x86 BIOS does not always toggle the reset line on the motherboard, and device_shutdown should have a negligible cost. So we should always calling device_shutdown, to so it does not regress from being under used.

Eric

#4 lore raw
Quoted 4 lines · Eric W. Biederman

So in summary.
- Asserting the system level reset line is the most reliable way to reboot.

[SNIPPED...to save space]

I think you can get all the PCI Bus-Masters shut off simply by writing PCI device 0 (The bridge itself) command register to 0.

This is what I do in my BIOS (Intel dest<--source):

;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= ;
; The PCI bus may be on from a previous boot or from a failure to
; reset. This causes a lot of problems that took me weeks to find.
; Make sure the damn thing is dead, dead, dead before we continue.
; It is not sufficient to just clear SYSARBMEMB as the documentation
; shows. PCI devices will "jabber", corrupting data if the host
; bridge is not turned off.
;
MOV DX,PCICFGADR ; PCI configuration address
MOV EAX,80000004H ; Enable, index 1 (command)
OUT DX,EAX ; Set index register
MOV DX,PCICFGDATA ; Data address
IN EAX,DX ; Get status/command
AND EAX,0FFFF0000H ; Really turn it OFF
OUT DX,EAX ; This should do it.
;
MOV WORD PTR DS:[SYSARBMEMB],00H ; Now disable PCI access
MOV DX,PCICFGADR ; PCI configuration address
MOV EAX,80000000H ; Enable, index 0
OUT DX,EAX ; Set index register
MOV DX,PCICFGDATA ; Data address
IN EAX,DX ; Get, throw away

Cheers,
Dick Johnson
Penguin : Linux version 2.4.18 on an i686 machine (797.90 BogoMips). The US military has given us many words, FUBAR, SNAFU, now ENRON. Yes, top management were graduates of West Point and Annapolis.