Skip to content

Commit 0709db6

Browse files
rjwysockiLinus Torvalds
authored andcommitted
swsusp: use GFP_KERNEL for creating basic data structures
Make swsusp call create_basic_memory_bitmaps() before processes are frozen, so that GFP_KERNEL allocations can be made in it. Additionally, ensure that the swsusp's userland interface won't be used while either pm_suspend_disk() or software_resume() is being executed. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Acked-by: Pavel Machek <pavel@ucw.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 1525a2a commit 0709db6

4 files changed

Lines changed: 38 additions & 20 deletions

File tree

‎kernel/power/disk.c‎

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,28 +130,33 @@ int pm_suspend_disk(void)
130130
{
131131
int error;
132132

133+
/* The snapshot device should not be opened while we're running */
134+
if (!atomic_add_unless(&snapshot_device_available, -1, 0))
135+
return -EBUSY;
136+
137+
/* Allocate memory management structures */
138+
error = create_basic_memory_bitmaps();
139+
if (error)
140+
goto Exit;
141+
133142
error = prepare_processes();
134143
if (error)
135-
return error;
144+
goto Finish;
136145

137146
if (pm_disk_mode == PM_DISK_TESTPROC) {
138147
printk("swsusp debug: Waiting for 5 seconds.\n");
139148
mdelay(5000);
140149
goto Thaw;
141150
}
142-
/* Allocate memory management structures */
143-
error = create_basic_memory_bitmaps();
144-
if (error)
145-
goto Thaw;
146151

147152
/* Free memory before shutting down devices. */
148153
error = swsusp_shrink_memory();
149154
if (error)
150-
goto Finish;
155+
goto Thaw;
151156

152157
error = platform_prepare();
153158
if (error)
154-
goto Finish;
159+
goto Thaw;
155160

156161
suspend_console();
157162
error = device_suspend(PMSG_FREEZE);
@@ -186,7 +191,7 @@ int pm_suspend_disk(void)
186191
power_down();
187192
else {
188193
swsusp_free();
189-
goto Finish;
194+
goto Thaw;
190195
}
191196
} else {
192197
pr_debug("PM: Image restored successfully.\n");
@@ -199,10 +204,12 @@ int pm_suspend_disk(void)
199204
platform_finish();
200205
device_resume();
201206
resume_console();
202-
Finish:
203-
free_basic_memory_bitmaps();
204207
Thaw:
205208
unprepare_processes();
209+
Finish:
210+
free_basic_memory_bitmaps();
211+
Exit:
212+
atomic_inc(&snapshot_device_available);
206213
return error;
207214
}
208215

@@ -250,9 +257,15 @@ static int software_resume(void)
250257
if (error)
251258
goto Unlock;
252259

260+
/* The snapshot device should not be opened while we're running */
261+
if (!atomic_add_unless(&snapshot_device_available, -1, 0)) {
262+
error = -EBUSY;
263+
goto Unlock;
264+
}
265+
253266
error = create_basic_memory_bitmaps();
254267
if (error)
255-
goto Unlock;
268+
goto Finish;
256269

257270
pr_debug("PM: Preparing processes for restore.\n");
258271
error = prepare_processes();
@@ -290,6 +303,8 @@ static int software_resume(void)
290303
unprepare_processes();
291304
Done:
292305
free_basic_memory_bitmaps();
306+
Finish:
307+
atomic_inc(&snapshot_device_available);
293308
/* For success case, the suspend path will release the lock */
294309
Unlock:
295310
mutex_unlock(&pm_mutex);

‎kernel/power/power.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ struct resume_swap_area {
140140
#define PMOPS_ENTER 2
141141
#define PMOPS_FINISH 3
142142

143+
/* If unset, the snapshot device cannot be open. */
144+
extern atomic_t snapshot_device_available;
145+
143146
/**
144147
* The bitmap is used for tracing allocated swap pages
145148
*

‎kernel/power/snapshot.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -723,19 +723,19 @@ int create_basic_memory_bitmaps(void)
723723

724724
BUG_ON(forbidden_pages_map || free_pages_map);
725725

726-
bm1 = kzalloc(sizeof(struct memory_bitmap), GFP_ATOMIC);
726+
bm1 = kzalloc(sizeof(struct memory_bitmap), GFP_KERNEL);
727727
if (!bm1)
728728
return -ENOMEM;
729729

730-
error = memory_bm_create(bm1, GFP_ATOMIC | __GFP_COLD, PG_ANY);
730+
error = memory_bm_create(bm1, GFP_KERNEL, PG_ANY);
731731
if (error)
732732
goto Free_first_object;
733733

734-
bm2 = kzalloc(sizeof(struct memory_bitmap), GFP_ATOMIC);
734+
bm2 = kzalloc(sizeof(struct memory_bitmap), GFP_KERNEL);
735735
if (!bm2)
736736
goto Free_first_bitmap;
737737

738-
error = memory_bm_create(bm2, GFP_ATOMIC | __GFP_COLD, PG_ANY);
738+
error = memory_bm_create(bm2, GFP_KERNEL, PG_ANY);
739739
if (error)
740740
goto Free_second_object;
741741

‎kernel/power/user.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,21 @@ static struct snapshot_data {
4040
char platform_suspend;
4141
} snapshot_state;
4242

43-
static atomic_t device_available = ATOMIC_INIT(1);
43+
atomic_t snapshot_device_available = ATOMIC_INIT(1);
4444

4545
static int snapshot_open(struct inode *inode, struct file *filp)
4646
{
4747
struct snapshot_data *data;
4848

49-
if (!atomic_add_unless(&device_available, -1, 0))
49+
if (!atomic_add_unless(&snapshot_device_available, -1, 0))
5050
return -EBUSY;
5151

5252
if ((filp->f_flags & O_ACCMODE) == O_RDWR) {
53-
atomic_inc(&device_available);
53+
atomic_inc(&snapshot_device_available);
5454
return -ENOSYS;
5555
}
5656
if(create_basic_memory_bitmaps()) {
57-
atomic_inc(&device_available);
57+
atomic_inc(&snapshot_device_available);
5858
return -ENOMEM;
5959
}
6060
nonseekable_open(inode, filp);
@@ -92,7 +92,7 @@ static int snapshot_release(struct inode *inode, struct file *filp)
9292
enable_nonboot_cpus();
9393
mutex_unlock(&pm_mutex);
9494
}
95-
atomic_inc(&device_available);
95+
atomic_inc(&snapshot_device_available);
9696
return 0;
9797
}
9898

0 commit comments

Comments
 (0)