diff options
author | Alan Stern <stern@rowland.harvard.edu> | 2007-05-04 11:52:20 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2007-07-12 19:29:47 -0400 |
commit | 0458d5b4c9cc4ca0f62625d0144ddc4b4bc97a3c (patch) | |
tree | 8b1fcb4f063ef4aa6f2e3cd41a60d986a1e432d4 /Documentation | |
parent | ce7cd137fced114d49178b73d468b82096a107fb (diff) |
USB: add USB-Persist facility
This patch (as886) adds the controversial USB-persist facility,
allowing USB devices to persist across a power loss during system
suspend.
The facility is controlled by a new Kconfig option (with appropriate
warnings about the potential dangers); when the option is off the
behavior will remain the same as it is now. But when the option is
on, people will be able to use suspend-to-disk and keep their USB
filesystems intact -- something particularly valuable for small
machines where the root filesystem is on a USB device!
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'Documentation')
-rw-r--r-- | Documentation/power/swsusp.txt | 3 | ||||
-rw-r--r-- | Documentation/usb/persist.txt | 144 |
2 files changed, 147 insertions, 0 deletions
diff --git a/Documentation/power/swsusp.txt b/Documentation/power/swsusp.txt index 5b8d6953f05e..152b510d1bbb 100644 --- a/Documentation/power/swsusp.txt +++ b/Documentation/power/swsusp.txt | |||
@@ -393,6 +393,9 @@ safest thing is to unmount all filesystems on removable media (such USB, | |||
393 | Firewire, CompactFlash, MMC, external SATA, or even IDE hotplug bays) | 393 | Firewire, CompactFlash, MMC, external SATA, or even IDE hotplug bays) |
394 | before suspending; then remount them after resuming. | 394 | before suspending; then remount them after resuming. |
395 | 395 | ||
396 | There is a work-around for this problem. For more information, see | ||
397 | Documentation/usb/persist.txt. | ||
398 | |||
396 | Q: I upgraded the kernel from 2.6.15 to 2.6.16. Both kernels were | 399 | Q: I upgraded the kernel from 2.6.15 to 2.6.16. Both kernels were |
397 | compiled with the similar configuration files. Anyway I found that | 400 | compiled with the similar configuration files. Anyway I found that |
398 | suspend to disk (and resume) is much slower on 2.6.16 compared to | 401 | suspend to disk (and resume) is much slower on 2.6.16 compared to |
diff --git a/Documentation/usb/persist.txt b/Documentation/usb/persist.txt new file mode 100644 index 000000000000..6dcd5f884795 --- /dev/null +++ b/Documentation/usb/persist.txt | |||
@@ -0,0 +1,144 @@ | |||
1 | USB device persistence during system suspend | ||
2 | |||
3 | Alan Stern <stern@rowland.harvard.edu> | ||
4 | |||
5 | September 2, 2006 (Updated March 27, 2007) | ||
6 | |||
7 | |||
8 | What is the problem? | ||
9 | |||
10 | According to the USB specification, when a USB bus is suspended the | ||
11 | bus must continue to supply suspend current (around 1-5 mA). This | ||
12 | is so that devices can maintain their internal state and hubs can | ||
13 | detect connect-change events (devices being plugged in or unplugged). | ||
14 | The technical term is "power session". | ||
15 | |||
16 | If a USB device's power session is interrupted then the system is | ||
17 | required to behave as though the device has been unplugged. It's a | ||
18 | conservative approach; in the absence of suspend current the computer | ||
19 | has no way to know what has actually happened. Perhaps the same | ||
20 | device is still attached or perhaps it was removed and a different | ||
21 | device plugged into the port. The system must assume the worst. | ||
22 | |||
23 | By default, Linux behaves according to the spec. If a USB host | ||
24 | controller loses power during a system suspend, then when the system | ||
25 | wakes up all the devices attached to that controller are treated as | ||
26 | though they had disconnected. This is always safe and it is the | ||
27 | "officially correct" thing to do. | ||
28 | |||
29 | For many sorts of devices this behavior doesn't matter in the least. | ||
30 | If the kernel wants to believe that your USB keyboard was unplugged | ||
31 | while the system was asleep and a new keyboard was plugged in when the | ||
32 | system woke up, who cares? It'll still work the same when you type on | ||
33 | it. | ||
34 | |||
35 | Unfortunately problems _can_ arise, particularly with mass-storage | ||
36 | devices. The effect is exactly the same as if the device really had | ||
37 | been unplugged while the system was suspended. If you had a mounted | ||
38 | filesystem on the device, you're out of luck -- everything in that | ||
39 | filesystem is now inaccessible. This is especially annoying if your | ||
40 | root filesystem was located on the device, since your system will | ||
41 | instantly crash. | ||
42 | |||
43 | Loss of power isn't the only mechanism to worry about. Anything that | ||
44 | interrupts a power session will have the same effect. For example, | ||
45 | even though suspend current may have been maintained while the system | ||
46 | was asleep, on many systems during the initial stages of wakeup the | ||
47 | firmware (i.e., the BIOS) resets the motherboard's USB host | ||
48 | controllers. Result: all the power sessions are destroyed and again | ||
49 | it's as though you had unplugged all the USB devices. Yes, it's | ||
50 | entirely the BIOS's fault, but that doesn't do _you_ any good unless | ||
51 | you can convince the BIOS supplier to fix the problem (lots of luck!). | ||
52 | |||
53 | On many systems the USB host controllers will get reset after a | ||
54 | suspend-to-RAM. On almost all systems, no suspend current is | ||
55 | available during suspend-to-disk (also known as swsusp). You can | ||
56 | check the kernel log after resuming to see if either of these has | ||
57 | happened; look for lines saying "root hub lost power or was reset". | ||
58 | |||
59 | In practice, people are forced to unmount any filesystems on a USB | ||
60 | device before suspending. If the root filesystem is on a USB device, | ||
61 | the system can't be suspended at all. (All right, it _can_ be | ||
62 | suspended -- but it will crash as soon as it wakes up, which isn't | ||
63 | much better.) | ||
64 | |||
65 | |||
66 | What is the solution? | ||
67 | |||
68 | Setting CONFIG_USB_PERSIST will cause the kernel to work around these | ||
69 | issues. It enables a mode in which the core USB device data | ||
70 | structures are allowed to persist across a power-session disruption. | ||
71 | It works like this. If the kernel sees that a USB host controller is | ||
72 | not in the expected state during resume (i.e., if the controller was | ||
73 | reset or otherwise had lost power) then it applies a persistence check | ||
74 | to each of the USB devices below that controller. It doesn't try to | ||
75 | resume the device; that can't work once the power session is gone. | ||
76 | Instead it issues a USB port reset and then re-enumerates the device. | ||
77 | (This is exactly the same thing that happens whenever a USB device is | ||
78 | reset.) If the re-enumeration shows that the device now attached to | ||
79 | that port has the same descriptors as before, including the Vendor and | ||
80 | Product IDs, then the kernel continues to use the same device | ||
81 | structure. In effect, the kernel treats the device as though it had | ||
82 | merely been reset instead of unplugged. | ||
83 | |||
84 | If no device is now attached to the port, or if the descriptors are | ||
85 | different from what the kernel remembers, then the treatment is what | ||
86 | you would expect. The kernel destroys the old device structure and | ||
87 | behaves as though the old device had been unplugged and a new device | ||
88 | plugged in, just as it would without the CONFIG_USB_PERSIST option. | ||
89 | |||
90 | The end result is that the USB device remains available and usable. | ||
91 | Filesystem mounts and memory mappings are unaffected, and the world is | ||
92 | now a good and happy place. | ||
93 | |||
94 | |||
95 | Is this the best solution? | ||
96 | |||
97 | Perhaps not. Arguably, keeping track of mounted filesystems and | ||
98 | memory mappings across device disconnects should be handled by a | ||
99 | centralized Logical Volume Manager. Such a solution would allow you | ||
100 | to plug in a USB flash device, create a persistent volume associated | ||
101 | with it, unplug the flash device, plug it back in later, and still | ||
102 | have the same persistent volume associated with the device. As such | ||
103 | it would be more far-reaching than CONFIG_USB_PERSIST. | ||
104 | |||
105 | On the other hand, writing a persistent volume manager would be a big | ||
106 | job and using it would require significant input from the user. This | ||
107 | solution is much quicker and easier -- and it exists now, a giant | ||
108 | point in its favor! | ||
109 | |||
110 | Furthermore, the USB_PERSIST option applies to _all_ USB devices, not | ||
111 | just mass-storage devices. It might turn out to be equally useful for | ||
112 | other device types, such as network interfaces. | ||
113 | |||
114 | |||
115 | WARNING: Using CONFIG_USB_PERSIST can be dangerous!! | ||
116 | |||
117 | When recovering an interrupted power session the kernel does its best | ||
118 | to make sure the USB device hasn't been changed; that is, the same | ||
119 | device is still plugged into the port as before. But the checks | ||
120 | aren't guaranteed to be 100% accurate. | ||
121 | |||
122 | If you replace one USB device with another of the same type (same | ||
123 | manufacturer, same IDs, and so on) there's an excellent chance the | ||
124 | kernel won't detect the change. Serial numbers and other strings are | ||
125 | not compared. In many cases it wouldn't help if they were, because | ||
126 | manufacturers frequently omit serial numbers entirely in their | ||
127 | devices. | ||
128 | |||
129 | Furthermore it's quite possible to leave a USB device exactly the same | ||
130 | while changing its media. If you replace the flash memory card in a | ||
131 | USB card reader while the system is asleep, the kernel will have no | ||
132 | way to know you did it. The kernel will assume that nothing has | ||
133 | happened and will continue to use the partition tables, inodes, and | ||
134 | memory mappings for the old card. | ||
135 | |||
136 | If the kernel gets fooled in this way, it's almost certain to cause | ||
137 | data corruption and to crash your system. You'll have no one to blame | ||
138 | but yourself. | ||
139 | |||
140 | YOU HAVE BEEN WARNED! USE AT YOUR OWN RISK! | ||
141 | |||
142 | That having been said, most of the time there shouldn't be any trouble | ||
143 | at all. The "persist" feature can be extremely useful. Make the most | ||
144 | of it. | ||