License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 22:07:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* drivers/power/process.c - Functions for starting/stopping processes on
|
|
|
|
* suspend transitions.
|
|
|
|
*
|
|
|
|
* Originally from swsusp.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#undef DEBUG
|
|
|
|
|
|
|
|
#include <linux/interrupt.h>
|
2009-09-22 08:03:09 +08:00
|
|
|
#include <linux/oom.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/suspend.h>
|
|
|
|
#include <linux/module.h>
|
2017-02-09 01:51:35 +08:00
|
|
|
#include <linux/sched/debug.h>
|
2017-02-09 01:51:36 +08:00
|
|
|
#include <linux/sched/task.h>
|
2006-03-23 19:00:04 +08:00
|
|
|
#include <linux/syscalls.h>
|
2006-12-07 12:34:23 +08:00
|
|
|
#include <linux/freezer.h>
|
2009-10-09 04:47:30 +08:00
|
|
|
#include <linux/delay.h>
|
2010-06-29 16:07:12 +08:00
|
|
|
#include <linux/workqueue.h>
|
2012-03-29 05:30:21 +08:00
|
|
|
#include <linux/kmod.h>
|
2014-06-06 20:40:17 +08:00
|
|
|
#include <trace/events/power.h>
|
2017-09-07 17:13:38 +08:00
|
|
|
#include <linux/cpuset.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-09-07 17:13:38 +08:00
|
|
|
/*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Timeout for stopping processes
|
|
|
|
*/
|
2013-02-01 16:56:03 +08:00
|
|
|
unsigned int __read_mostly freeze_timeout_msecs = 20 * MSEC_PER_SEC;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-11-22 04:32:26 +08:00
|
|
|
static int try_to_freeze_tasks(bool user_only)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct task_struct *g, *p;
|
2006-12-07 12:34:40 +08:00
|
|
|
unsigned long end_time;
|
|
|
|
unsigned int todo;
|
2010-06-29 16:07:12 +08:00
|
|
|
bool wq_busy = false;
|
2016-02-01 03:29:01 +08:00
|
|
|
ktime_t start, end, elapsed;
|
2013-05-07 07:50:10 +08:00
|
|
|
unsigned int elapsed_msecs;
|
2010-10-05 04:07:32 +08:00
|
|
|
bool wakeup = false;
|
2013-05-07 07:50:10 +08:00
|
|
|
int sleep_usecs = USEC_PER_MSEC;
|
2007-10-18 18:04:49 +08:00
|
|
|
|
2016-02-01 03:29:01 +08:00
|
|
|
start = ktime_get_boottime();
|
2005-06-25 14:13:50 +08:00
|
|
|
|
2013-02-01 16:56:03 +08:00
|
|
|
end_time = jiffies + msecs_to_jiffies(freeze_timeout_msecs);
|
2010-06-29 16:07:12 +08:00
|
|
|
|
2011-11-22 04:32:26 +08:00
|
|
|
if (!user_only)
|
2010-06-29 16:07:12 +08:00
|
|
|
freeze_workqueues_begin();
|
|
|
|
|
2009-10-09 04:47:30 +08:00
|
|
|
while (true) {
|
2006-12-07 12:34:40 +08:00
|
|
|
todo = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
read_lock(&tasklist_lock);
|
2014-10-21 15:27:15 +08:00
|
|
|
for_each_process_thread(g, p) {
|
2011-11-22 04:32:26 +08:00
|
|
|
if (p == current || !freeze_task(p))
|
2007-10-18 18:04:46 +08:00
|
|
|
continue;
|
|
|
|
|
2012-10-27 01:46:06 +08:00
|
|
|
if (!freezer_should_skip(p))
|
2007-05-24 04:57:25 +08:00
|
|
|
todo++;
|
2014-10-21 15:27:15 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
read_unlock(&tasklist_lock);
|
2010-06-29 16:07:12 +08:00
|
|
|
|
2011-11-22 04:32:26 +08:00
|
|
|
if (!user_only) {
|
2010-06-29 16:07:12 +08:00
|
|
|
wq_busy = freeze_workqueues_busy();
|
|
|
|
todo += wq_busy;
|
|
|
|
}
|
|
|
|
|
2009-10-09 04:47:30 +08:00
|
|
|
if (!todo || time_after(jiffies, end_time))
|
2005-09-04 06:57:05 +08:00
|
|
|
break;
|
2009-10-09 04:47:30 +08:00
|
|
|
|
2010-12-04 05:58:31 +08:00
|
|
|
if (pm_wakeup_pending()) {
|
2010-10-05 04:07:32 +08:00
|
|
|
wakeup = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-10-09 04:47:30 +08:00
|
|
|
/*
|
|
|
|
* We need to retry, but first give the freezing tasks some
|
2013-05-07 07:50:10 +08:00
|
|
|
* time to enter the refrigerator. Start with an initial
|
|
|
|
* 1 ms sleep followed by exponential backoff until 8 ms.
|
2009-10-09 04:47:30 +08:00
|
|
|
*/
|
2013-05-07 07:50:10 +08:00
|
|
|
usleep_range(sleep_usecs / 2, sleep_usecs);
|
|
|
|
if (sleep_usecs < 8 * USEC_PER_MSEC)
|
|
|
|
sleep_usecs *= 2;
|
2009-10-09 04:47:30 +08:00
|
|
|
}
|
2005-06-25 14:13:50 +08:00
|
|
|
|
2016-02-01 03:29:01 +08:00
|
|
|
end = ktime_get_boottime();
|
|
|
|
elapsed = ktime_sub(end, start);
|
|
|
|
elapsed_msecs = ktime_to_ms(elapsed);
|
2007-10-18 18:04:49 +08:00
|
|
|
|
2005-09-04 06:57:05 +08:00
|
|
|
if (todo) {
|
2015-02-12 07:26:18 +08:00
|
|
|
pr_cont("\n");
|
|
|
|
pr_err("Freezing of tasks %s after %d.%03d seconds "
|
2010-06-29 16:07:12 +08:00
|
|
|
"(%d tasks refusing to freeze, wq_busy=%d):\n",
|
2010-10-05 04:07:32 +08:00
|
|
|
wakeup ? "aborted" : "failed",
|
2013-05-07 07:50:10 +08:00
|
|
|
elapsed_msecs / 1000, elapsed_msecs % 1000,
|
2010-06-29 16:07:12 +08:00
|
|
|
todo - wq_busy, wq_busy);
|
|
|
|
|
2016-07-01 11:05:02 +08:00
|
|
|
if (wq_busy)
|
|
|
|
show_workqueue_state();
|
|
|
|
|
2012-02-11 07:00:34 +08:00
|
|
|
if (!wakeup) {
|
|
|
|
read_lock(&tasklist_lock);
|
2014-10-21 15:27:15 +08:00
|
|
|
for_each_process_thread(g, p) {
|
2012-02-11 07:00:34 +08:00
|
|
|
if (p != current && !freezer_should_skip(p)
|
|
|
|
&& freezing(p) && !frozen(p))
|
|
|
|
sched_show_task(p);
|
2014-10-21 15:27:15 +08:00
|
|
|
}
|
2012-02-11 07:00:34 +08:00
|
|
|
read_unlock(&tasklist_lock);
|
|
|
|
}
|
2007-10-18 18:04:49 +08:00
|
|
|
} else {
|
2015-02-12 07:26:18 +08:00
|
|
|
pr_cont("(elapsed %d.%03d seconds) ", elapsed_msecs / 1000,
|
2013-05-07 07:50:10 +08:00
|
|
|
elapsed_msecs % 1000);
|
2005-09-04 06:57:05 +08:00
|
|
|
}
|
|
|
|
|
2007-07-19 16:47:34 +08:00
|
|
|
return todo ? -EBUSY : 0;
|
2006-12-07 12:34:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-09-27 02:32:27 +08:00
|
|
|
* freeze_processes - Signal user space processes to enter the refrigerator.
|
2013-07-25 08:41:33 +08:00
|
|
|
* The current thread will not be frozen. The same process that calls
|
|
|
|
* freeze_processes must later call thaw_processes.
|
2011-11-22 04:32:24 +08:00
|
|
|
*
|
|
|
|
* On success, returns 0. On failure, -errno and system is fully thawed.
|
2006-12-07 12:34:40 +08:00
|
|
|
*/
|
|
|
|
int freeze_processes(void)
|
|
|
|
{
|
2007-07-19 16:47:34 +08:00
|
|
|
int error;
|
2006-12-07 12:34:40 +08:00
|
|
|
|
PM / Sleep: Mitigate race between the freezer and request_firmware()
There is a race condition between the freezer and request_firmware()
such that if request_firmware() is run on one CPU and
freeze_processes() is run on another CPU and usermodehelper_disable()
called by it succeeds to grab umhelper_sem for writing before
usermodehelper_read_trylock() called from request_firmware()
acquires it for reading, the request_firmware() will fail and
trigger a WARN_ON() complaining that it was called at a wrong time.
However, in fact, it wasn't called at a wrong time and
freeze_processes() simply happened to be executed simultaneously.
To avoid this race, at least in some cases, modify
usermodehelper_read_trylock() so that it doesn't fail if the
freezing of tasks has just started and hasn't been completed yet.
Instead, during the freezing of tasks, it will try to freeze the
task that has called it so that it can wait until user space is
thawed without triggering the scary warning.
For this purpose, change usermodehelper_disabled so that it can
take three different values, UMH_ENABLED (0), UMH_FREEZING and
UMH_DISABLED. The first one means that usermode helpers are
enabled, the last one means "hard disable" (i.e. the system is not
ready for usermode helpers to be used) and the second one
is reserved for the freezer. Namely, when freeze_processes() is
started, it sets usermodehelper_disabled to UMH_FREEZING which
tells usermodehelper_read_trylock() that it shouldn't fail just
yet and should call try_to_freeze() if woken up and cannot
return immediately. This way all freezable tasks that happen
to call request_firmware() right before freeze_processes() is
started and lose the race for umhelper_sem with it will be
frozen and will sleep until thaw_processes() unsets
usermodehelper_disabled. [For the non-freezable callers of
request_firmware() the race for umhelper_sem against
freeze_processes() is unfortunately unavoidable.]
Reported-by: Stephen Boyd <sboyd@codeaurora.org>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: stable@vger.kernel.org
2012-03-29 05:30:28 +08:00
|
|
|
error = __usermodehelper_disable(UMH_FREEZING);
|
2012-03-29 05:30:21 +08:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
2013-07-25 08:41:33 +08:00
|
|
|
/* Make sure this task doesn't get frozen */
|
|
|
|
current->flags |= PF_SUSPEND_TASK;
|
|
|
|
|
2011-11-22 04:32:25 +08:00
|
|
|
if (!pm_freezing)
|
|
|
|
atomic_inc(&system_freezing_cnt);
|
|
|
|
|
ACPI / PM: Ignore spurious SCI wakeups from suspend-to-idle
The ACPI SCI (System Control Interrupt) is set up as a wakeup IRQ
during suspend-to-idle transitions and, consequently, any events
signaled through it wake up the system from that state. However,
on some systems some of the events signaled via the ACPI SCI while
suspended to idle should not cause the system to wake up. In fact,
quite often they should just be discarded.
Arguably, systems should not resume entirely on such events, but in
order to decide which events really should cause the system to resume
and which are spurious, it is necessary to resume up to the point
when ACPI SCIs are actually handled and processed, which is after
executing dpm_resume_noirq() in the system resume path.
For this reasons, add a loop around freeze_enter() in which the
platforms can process events signaled via multiplexed IRQ lines
like the ACPI SCI and add suspend-to-idle hooks that can be
used for this purpose to struct platform_freeze_ops.
In the ACPI case, the ->wake hook is used for checking if the SCI
has triggered while suspended and deferring the interrupt-induced
system wakeup until the events signaled through it are actually
processed sufficiently to decide whether or not the system should
resume. In turn, the ->sync hook allows all of the relevant event
queues to be flushed so as to prevent events from being missed due
to race conditions.
In addition to that, some ACPI code processing wakeup events needs
to be modified to use the "hard" version of wakeup triggers, so that
it will cause a system resume to happen on device-induced wakeup
events even if the "soft" mechanism to prevent the system from
suspending is not enabled. However, to preserve the existing
behavior with respect to suspend-to-RAM, this only is done in
the suspend-to-idle case and only if an SCI has occurred while
suspended.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2017-06-13 04:56:34 +08:00
|
|
|
pm_wakeup_clear(true);
|
2015-02-12 07:26:18 +08:00
|
|
|
pr_info("Freezing user space processes ... ");
|
2011-11-22 04:32:25 +08:00
|
|
|
pm_freezing = true;
|
2008-06-12 04:04:29 +08:00
|
|
|
error = try_to_freeze_tasks(true);
|
2011-09-27 02:32:27 +08:00
|
|
|
if (!error) {
|
PM / Sleep: Mitigate race between the freezer and request_firmware()
There is a race condition between the freezer and request_firmware()
such that if request_firmware() is run on one CPU and
freeze_processes() is run on another CPU and usermodehelper_disable()
called by it succeeds to grab umhelper_sem for writing before
usermodehelper_read_trylock() called from request_firmware()
acquires it for reading, the request_firmware() will fail and
trigger a WARN_ON() complaining that it was called at a wrong time.
However, in fact, it wasn't called at a wrong time and
freeze_processes() simply happened to be executed simultaneously.
To avoid this race, at least in some cases, modify
usermodehelper_read_trylock() so that it doesn't fail if the
freezing of tasks has just started and hasn't been completed yet.
Instead, during the freezing of tasks, it will try to freeze the
task that has called it so that it can wait until user space is
thawed without triggering the scary warning.
For this purpose, change usermodehelper_disabled so that it can
take three different values, UMH_ENABLED (0), UMH_FREEZING and
UMH_DISABLED. The first one means that usermode helpers are
enabled, the last one means "hard disable" (i.e. the system is not
ready for usermode helpers to be used) and the second one
is reserved for the freezer. Namely, when freeze_processes() is
started, it sets usermodehelper_disabled to UMH_FREEZING which
tells usermodehelper_read_trylock() that it shouldn't fail just
yet and should call try_to_freeze() if woken up and cannot
return immediately. This way all freezable tasks that happen
to call request_firmware() right before freeze_processes() is
started and lose the race for umhelper_sem with it will be
frozen and will sleep until thaw_processes() unsets
usermodehelper_disabled. [For the non-freezable callers of
request_firmware() the race for umhelper_sem against
freeze_processes() is unfortunately unavoidable.]
Reported-by: Stephen Boyd <sboyd@codeaurora.org>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: stable@vger.kernel.org
2012-03-29 05:30:28 +08:00
|
|
|
__usermodehelper_set_disable_depth(UMH_DISABLED);
|
2015-02-12 07:26:24 +08:00
|
|
|
pr_cont("done.");
|
2011-09-27 02:32:27 +08:00
|
|
|
}
|
2015-02-12 07:26:18 +08:00
|
|
|
pr_cont("\n");
|
2011-09-27 02:32:27 +08:00
|
|
|
BUG_ON(in_atomic());
|
|
|
|
|
2015-02-12 07:26:24 +08:00
|
|
|
/*
|
|
|
|
* Now that the whole userspace is frozen we need to disbale
|
|
|
|
* the OOM killer to disallow any further interference with
|
2016-10-08 07:59:00 +08:00
|
|
|
* killable tasks. There is no guarantee oom victims will
|
|
|
|
* ever reach a point they go away we have to wait with a timeout.
|
2015-02-12 07:26:24 +08:00
|
|
|
*/
|
2016-10-08 07:59:00 +08:00
|
|
|
if (!error && !oom_killer_disable(msecs_to_jiffies(freeze_timeout_msecs)))
|
2015-02-12 07:26:24 +08:00
|
|
|
error = -EBUSY;
|
|
|
|
|
2011-11-22 04:32:24 +08:00
|
|
|
if (error)
|
|
|
|
thaw_processes();
|
2011-09-27 02:32:27 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* freeze_kernel_threads - Make freezable kernel threads go to the refrigerator.
|
2011-11-22 04:32:24 +08:00
|
|
|
*
|
PM / Freezer: Thaw only kernel threads if freezing of kernel threads fails
If freezing of kernel threads fails, we are expected to automatically
thaw tasks in the error recovery path. However, at times, we encounter
situations in which we would like the automatic error recovery path
to thaw only the kernel threads, because we want to be able to do
some more cleanup before we thaw userspace. Something like:
error = freeze_kernel_threads();
if (error) {
/* Do some cleanup */
/* Only then thaw userspace tasks*/
thaw_processes();
}
An example of such a situation is where we freeze/thaw filesystems
during suspend/hibernation. There, if freezing of kernel threads
fails, we would like to thaw the frozen filesystems before thawing
the userspace tasks.
So, modify freeze_kernel_threads() to thaw only kernel threads in
case of freezing failure. And change suspend_freeze_processes()
accordingly. (At the same time, let us also get rid of the rather
cryptic usage of the conditional operator (:?) in that function.)
[rjw: In fact, this patch fixes a regression introduced during the
3.3 merge window, because without it thaw_processes() may be called
before swsusp_free() in some situations and that may lead to massive
memory allocation failures.]
Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
Acked-by: Tejun Heo <tj@kernel.org>
Acked-by: Nigel Cunningham <nigel@tuxonice.net>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
2012-02-04 05:22:41 +08:00
|
|
|
* On success, returns 0. On failure, -errno and only the kernel threads are
|
|
|
|
* thawed, so as to give a chance to the caller to do additional cleanups
|
|
|
|
* (if any) before thawing the userspace tasks. So, it is the responsibility
|
|
|
|
* of the caller to thaw the userspace tasks, when the time is right.
|
2011-09-27 02:32:27 +08:00
|
|
|
*/
|
|
|
|
int freeze_kernel_threads(void)
|
|
|
|
{
|
|
|
|
int error;
|
2006-12-07 12:34:40 +08:00
|
|
|
|
2015-02-12 07:26:18 +08:00
|
|
|
pr_info("Freezing remaining freezable tasks ... ");
|
|
|
|
|
2011-11-22 04:32:25 +08:00
|
|
|
pm_nosig_freezing = true;
|
2008-06-12 04:04:29 +08:00
|
|
|
error = try_to_freeze_tasks(false);
|
2011-09-27 02:32:27 +08:00
|
|
|
if (!error)
|
2015-02-12 07:26:18 +08:00
|
|
|
pr_cont("done.");
|
2009-06-17 06:32:41 +08:00
|
|
|
|
2015-02-12 07:26:18 +08:00
|
|
|
pr_cont("\n");
|
2011-09-27 02:32:27 +08:00
|
|
|
BUG_ON(in_atomic());
|
2009-06-17 06:32:41 +08:00
|
|
|
|
2011-11-22 04:32:24 +08:00
|
|
|
if (error)
|
PM / Freezer: Thaw only kernel threads if freezing of kernel threads fails
If freezing of kernel threads fails, we are expected to automatically
thaw tasks in the error recovery path. However, at times, we encounter
situations in which we would like the automatic error recovery path
to thaw only the kernel threads, because we want to be able to do
some more cleanup before we thaw userspace. Something like:
error = freeze_kernel_threads();
if (error) {
/* Do some cleanup */
/* Only then thaw userspace tasks*/
thaw_processes();
}
An example of such a situation is where we freeze/thaw filesystems
during suspend/hibernation. There, if freezing of kernel threads
fails, we would like to thaw the frozen filesystems before thawing
the userspace tasks.
So, modify freeze_kernel_threads() to thaw only kernel threads in
case of freezing failure. And change suspend_freeze_processes()
accordingly. (At the same time, let us also get rid of the rather
cryptic usage of the conditional operator (:?) in that function.)
[rjw: In fact, this patch fixes a regression introduced during the
3.3 merge window, because without it thaw_processes() may be called
before swsusp_free() in some situations and that may lead to massive
memory allocation failures.]
Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
Acked-by: Tejun Heo <tj@kernel.org>
Acked-by: Nigel Cunningham <nigel@tuxonice.net>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
2012-02-04 05:22:41 +08:00
|
|
|
thaw_kernel_threads();
|
2007-10-18 18:04:48 +08:00
|
|
|
return error;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2011-11-22 04:32:23 +08:00
|
|
|
void thaw_processes(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct task_struct *g, *p;
|
2013-07-25 08:41:33 +08:00
|
|
|
struct task_struct *curr = current;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-06-06 20:40:17 +08:00
|
|
|
trace_suspend_resume(TPS("thaw_processes"), 0, true);
|
2011-11-22 04:32:25 +08:00
|
|
|
if (pm_freezing)
|
|
|
|
atomic_dec(&system_freezing_cnt);
|
|
|
|
pm_freezing = false;
|
|
|
|
pm_nosig_freezing = false;
|
|
|
|
|
2011-11-22 04:32:23 +08:00
|
|
|
oom_killer_enable();
|
|
|
|
|
2015-02-12 07:26:18 +08:00
|
|
|
pr_info("Restarting tasks ... ");
|
2011-11-22 04:32:23 +08:00
|
|
|
|
2014-07-15 14:51:27 +08:00
|
|
|
__usermodehelper_set_disable_depth(UMH_FREEZING);
|
2011-11-22 04:32:23 +08:00
|
|
|
thaw_workqueues();
|
|
|
|
|
2017-09-07 17:13:38 +08:00
|
|
|
cpuset_wait_for_hotplug();
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
read_lock(&tasklist_lock);
|
2014-10-21 15:27:15 +08:00
|
|
|
for_each_process_thread(g, p) {
|
2013-07-25 08:41:33 +08:00
|
|
|
/* No other threads should have PF_SUSPEND_TASK set */
|
|
|
|
WARN_ON((p != curr) && (p->flags & PF_SUSPEND_TASK));
|
2011-11-22 04:32:23 +08:00
|
|
|
__thaw_task(p);
|
2014-10-21 15:27:15 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
read_unlock(&tasklist_lock);
|
2009-06-17 06:32:41 +08:00
|
|
|
|
2013-07-25 08:41:33 +08:00
|
|
|
WARN_ON(!(curr->flags & PF_SUSPEND_TASK));
|
|
|
|
curr->flags &= ~PF_SUSPEND_TASK;
|
|
|
|
|
2012-03-29 05:30:21 +08:00
|
|
|
usermodehelper_enable();
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
schedule();
|
2015-02-12 07:26:18 +08:00
|
|
|
pr_cont("done.\n");
|
2014-06-06 20:40:17 +08:00
|
|
|
trace_suspend_resume(TPS("thaw_processes"), 0, false);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2012-01-30 03:35:52 +08:00
|
|
|
void thaw_kernel_threads(void)
|
|
|
|
{
|
|
|
|
struct task_struct *g, *p;
|
|
|
|
|
|
|
|
pm_nosig_freezing = false;
|
2015-02-12 07:26:18 +08:00
|
|
|
pr_info("Restarting kernel threads ... ");
|
2012-01-30 03:35:52 +08:00
|
|
|
|
|
|
|
thaw_workqueues();
|
|
|
|
|
|
|
|
read_lock(&tasklist_lock);
|
2014-10-21 15:27:15 +08:00
|
|
|
for_each_process_thread(g, p) {
|
2012-01-30 03:35:52 +08:00
|
|
|
if (p->flags & (PF_KTHREAD | PF_WQ_WORKER))
|
|
|
|
__thaw_task(p);
|
2014-10-21 15:27:15 +08:00
|
|
|
}
|
2012-01-30 03:35:52 +08:00
|
|
|
read_unlock(&tasklist_lock);
|
|
|
|
|
|
|
|
schedule();
|
2015-02-12 07:26:18 +08:00
|
|
|
pr_cont("done.\n");
|
2012-01-30 03:35:52 +08:00
|
|
|
}
|