Commit af235643fec62d70e147ac0833d4572a3c3cdc2d
Committed by
George Cherian
1 parent
08e17918d3
Exists in
v3.2_SMARCT335xPSP_04.06.00.11
and in
3 other branches
scsi_pm: Fix bug in the SCSI power management handler
This patch (as1520) fixes a bug in the SCSI layer's power management implementation. LUN scanning can be carried out asynchronously in do_scan_async(), and sd uses an asynchronous thread for the time-consuming parts of disk probing in sd_probe_async(). Currently nothing coordinates these async threads with system sleep transitions; they can and do attempt to continue scanning/probing SCSI devices even after the host adapter has been suspended. As one might expect, the outcome is not ideal. This is what the "prepare" stage of system suspend was created for. After the prepare callback has been called for a host, target, or device, drivers are not allowed to register any children underneath them. Currently the SCSI prepare callback is not implemented; this patch rectifies that omission. For SCSI hosts, the prepare routine calls scsi_complete_async_scans() to wait until async scanning is finished. It might be slightly more efficient to wait only until the host in question has been scanned, but there's currently no way to do that. Besides, during a sleep transition we will ultimately have to wait until all the host scanning has finished anyway. For SCSI devices, the prepare routine calls async_synchronize_full() to wait until sd probing is finished. The routine does nothing for SCSI targets, because asynchronous target scanning is done only as part of host scanning. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> CC: <stable@kernel.org> Signed-off-by: James Bottomley <JBottomley@Parallels.com>
Showing 2 changed files with 17 additions and 0 deletions Side-by-side Diff
drivers/scsi/scsi_pm.c
... | ... | @@ -7,6 +7,7 @@ |
7 | 7 | |
8 | 8 | #include <linux/pm_runtime.h> |
9 | 9 | #include <linux/export.h> |
10 | +#include <linux/async.h> | |
10 | 11 | |
11 | 12 | #include <scsi/scsi.h> |
12 | 13 | #include <scsi/scsi_device.h> |
... | ... | @@ -69,6 +70,19 @@ |
69 | 70 | return err; |
70 | 71 | } |
71 | 72 | |
73 | +static int scsi_bus_prepare(struct device *dev) | |
74 | +{ | |
75 | + if (scsi_is_sdev_device(dev)) { | |
76 | + /* sd probing uses async_schedule. Wait until it finishes. */ | |
77 | + async_synchronize_full(); | |
78 | + | |
79 | + } else if (scsi_is_host_device(dev)) { | |
80 | + /* Wait until async scanning is finished */ | |
81 | + scsi_complete_async_scans(); | |
82 | + } | |
83 | + return 0; | |
84 | +} | |
85 | + | |
72 | 86 | static int scsi_bus_suspend(struct device *dev) |
73 | 87 | { |
74 | 88 | return scsi_bus_suspend_common(dev, PMSG_SUSPEND); |
... | ... | @@ -87,6 +101,7 @@ |
87 | 101 | #else /* CONFIG_PM_SLEEP */ |
88 | 102 | |
89 | 103 | #define scsi_bus_resume_common NULL |
104 | +#define scsi_bus_prepare NULL | |
90 | 105 | #define scsi_bus_suspend NULL |
91 | 106 | #define scsi_bus_freeze NULL |
92 | 107 | #define scsi_bus_poweroff NULL |
... | ... | @@ -195,6 +210,7 @@ |
195 | 210 | #endif /* CONFIG_PM_RUNTIME */ |
196 | 211 | |
197 | 212 | const struct dev_pm_ops scsi_bus_pm_ops = { |
213 | + .prepare = scsi_bus_prepare, | |
198 | 214 | .suspend = scsi_bus_suspend, |
199 | 215 | .resume = scsi_bus_resume_common, |
200 | 216 | .freeze = scsi_bus_freeze, |
drivers/scsi/scsi_priv.h
... | ... | @@ -110,6 +110,7 @@ |
110 | 110 | #endif /* CONFIG_PROC_FS */ |
111 | 111 | |
112 | 112 | /* scsi_scan.c */ |
113 | +extern int scsi_complete_async_scans(void); | |
113 | 114 | extern int scsi_scan_host_selected(struct Scsi_Host *, unsigned int, |
114 | 115 | unsigned int, unsigned int, int); |
115 | 116 | extern void scsi_forget_host(struct Scsi_Host *); |