Skip to content

Commit

Permalink
freezer,umh: Clean up freezer/initrd interaction
Browse files Browse the repository at this point in the history
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) <peterz@infradead.org>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://lore.kernel.org/r/20220822114648.791019324@infradead.org
  • Loading branch information
Peter Zijlstra committed Sep 7, 2022
1 parent 5950e5d commit 1fbcaa9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
9 changes: 5 additions & 4 deletions include/linux/umh.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
struct cred;
struct file;

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

struct subprocess_info {
struct work_struct work;
Expand Down
10 changes: 1 addition & 9 deletions init/do_mounts_initrd.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,11 @@ static void __init handle_initrd(void)
init_mkdir("/old", 0700);
init_chdir("/old");

/*
* In case that a resume from disk is carried out by linuxrc or one of
* its children, we need to tell the freezer not to wait for us.
*/
current->flags |= PF_FREEZER_SKIP;

info = call_usermodehelper_setup("/linuxrc", argv, envp_init,
GFP_KERNEL, init_linuxrc, NULL, NULL);
if (!info)
return;
call_usermodehelper_exec(info, UMH_WAIT_PROC);

current->flags &= ~PF_FREEZER_SKIP;
call_usermodehelper_exec(info, UMH_WAIT_PROC|UMH_FREEZABLE);

/* move initrd to rootfs' /old */
init_mount("..", ".", NULL, MS_MOVE, NULL);
Expand Down
8 changes: 8 additions & 0 deletions kernel/umh.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <linux/async.h>
#include <linux/uaccess.h>
#include <linux/initrd.h>
#include <linux/freezer.h>

#include <trace/events/module.h>

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

if (wait & UMH_FREEZABLE)
freezer_do_not_count();

if (wait & UMH_KILLABLE) {
retval = wait_for_completion_killable(&done);
if (!retval)
Expand All @@ -448,6 +452,10 @@ int call_usermodehelper_exec(struct subprocess_info *sub_info, int wait)
}

wait_for_completion(&done);

if (wait & UMH_FREEZABLE)
freezer_count();

wait_done:
retval = sub_info->retval;
out:
Expand Down

0 comments on commit 1fbcaa9

Please sign in to comment.