Skip to content

Commit 1fbcaa9

Browse files
author
Peter Zijlstra
committed
freezer,umh: Clean up freezer/initrd interaction
handle_initrd() marks itself as PF_FREEZER_SKIP in order to ensure that the UMH, which is going to freeze the system, doesn't indefinitely wait for it's caller. Rework things by adding UMH_FREEZABLE to indicate the completion is freezable. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Rafael J. Wysocki <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 5950e5d commit 1fbcaa9

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

include/linux/umh.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
struct cred;
1212
struct file;
1313

14-
#define UMH_NO_WAIT 0 /* don't wait at all */
15-
#define UMH_WAIT_EXEC 1 /* wait for the exec, but not the process */
16-
#define UMH_WAIT_PROC 2 /* wait for the process to complete */
17-
#define UMH_KILLABLE 4 /* wait for EXEC/PROC killable */
14+
#define UMH_NO_WAIT 0x00 /* don't wait at all */
15+
#define UMH_WAIT_EXEC 0x01 /* wait for the exec, but not the process */
16+
#define UMH_WAIT_PROC 0x02 /* wait for the process to complete */
17+
#define UMH_KILLABLE 0x04 /* wait for EXEC/PROC killable */
18+
#define UMH_FREEZABLE 0x08 /* wait for EXEC/PROC freezable */
1819

1920
struct subprocess_info {
2021
struct work_struct work;

init/do_mounts_initrd.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,11 @@ static void __init handle_initrd(void)
9999
init_mkdir("/old", 0700);
100100
init_chdir("/old");
101101

102-
/*
103-
* In case that a resume from disk is carried out by linuxrc or one of
104-
* its children, we need to tell the freezer not to wait for us.
105-
*/
106-
current->flags |= PF_FREEZER_SKIP;
107-
108102
info = call_usermodehelper_setup("/linuxrc", argv, envp_init,
109103
GFP_KERNEL, init_linuxrc, NULL, NULL);
110104
if (!info)
111105
return;
112-
call_usermodehelper_exec(info, UMH_WAIT_PROC);
113-
114-
current->flags &= ~PF_FREEZER_SKIP;
106+
call_usermodehelper_exec(info, UMH_WAIT_PROC|UMH_FREEZABLE);
115107

116108
/* move initrd to rootfs' /old */
117109
init_mount("..", ".", NULL, MS_MOVE, NULL);

kernel/umh.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <linux/async.h>
2929
#include <linux/uaccess.h>
3030
#include <linux/initrd.h>
31+
#include <linux/freezer.h>
3132

3233
#include <trace/events/module.h>
3334

@@ -436,6 +437,9 @@ int call_usermodehelper_exec(struct subprocess_info *sub_info, int wait)
436437
if (wait == UMH_NO_WAIT) /* task has freed sub_info */
437438
goto unlock;
438439

440+
if (wait & UMH_FREEZABLE)
441+
freezer_do_not_count();
442+
439443
if (wait & UMH_KILLABLE) {
440444
retval = wait_for_completion_killable(&done);
441445
if (!retval)
@@ -448,6 +452,10 @@ int call_usermodehelper_exec(struct subprocess_info *sub_info, int wait)
448452
}
449453

450454
wait_for_completion(&done);
455+
456+
if (wait & UMH_FREEZABLE)
457+
freezer_count();
458+
451459
wait_done:
452460
retval = sub_info->retval;
453461
out:

0 commit comments

Comments
 (0)