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 14:07:57 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
2021-06-08 07:44:37 +00:00
|
|
|
* drivers/power/process.c - Functions for starting/stopping processes on
|
2005-04-16 22:20:36 +00:00
|
|
|
* suspend transitions.
|
|
|
|
*
|
|
|
|
* Originally from swsusp.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/interrupt.h>
|
2009-09-22 00:03:09 +00:00
|
|
|
#include <linux/oom.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/suspend.h>
|
|
|
|
#include <linux/module.h>
|
2017-02-08 17:51:35 +00:00
|
|
|
#include <linux/sched/debug.h>
|
2017-02-08 17:51:36 +00:00
|
|
|
#include <linux/sched/task.h>
|
2006-03-23 11:00:04 +00:00
|
|
|
#include <linux/syscalls.h>
|
2006-12-07 04:34:23 +00:00
|
|
|
#include <linux/freezer.h>
|
2009-10-08 20:47:30 +00:00
|
|
|
#include <linux/delay.h>
|
2010-06-29 08:07:12 +00:00
|
|
|
#include <linux/workqueue.h>
|
2012-03-28 21:30:21 +00:00
|
|
|
#include <linux/kmod.h>
|
2014-06-06 12:40:17 +00:00
|
|
|
#include <trace/events/power.h>
|
2017-09-07 09:13:38 +00:00
|
|
|
#include <linux/cpuset.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-09-07 09:13:38 +00:00
|
|
|
/*
|
2005-04-16 22:20:36 +00:00
|
|
|
* Timeout for stopping processes
|
|
|
|
*/
|
2013-02-01 08:56:03 +00:00
|
|
|
unsigned int __read_mostly freeze_timeout_msecs = 20 * MSEC_PER_SEC;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-11-21 20:32:26 +00:00
|
|
|
static int try_to_freeze_tasks(bool user_only)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2022-12-01 18:33:09 +00:00
|
|
|
const char *what = user_only ? "user space processes" :
|
|
|
|
"remaining freezable tasks";
|
2005-04-16 22:20:36 +00:00
|
|
|
struct task_struct *g, *p;
|
2006-12-07 04:34:40 +00:00
|
|
|
unsigned long end_time;
|
|
|
|
unsigned int todo;
|
2010-06-29 08:07:12 +00:00
|
|
|
bool wq_busy = false;
|
2016-01-31 19:29:01 +00:00
|
|
|
ktime_t start, end, elapsed;
|
2013-05-06 23:50:10 +00:00
|
|
|
unsigned int elapsed_msecs;
|
2010-10-04 20:07:32 +00:00
|
|
|
bool wakeup = false;
|
2013-05-06 23:50:10 +00:00
|
|
|
int sleep_usecs = USEC_PER_MSEC;
|
2007-10-18 10:04:49 +00:00
|
|
|
|
2022-12-01 18:33:09 +00:00
|
|
|
pr_info("Freezing %s\n", what);
|
|
|
|
|
2016-01-31 19:29:01 +00:00
|
|
|
start = ktime_get_boottime();
|
2005-06-25 06:13:50 +00:00
|
|
|
|
2013-02-01 08:56:03 +00:00
|
|
|
end_time = jiffies + msecs_to_jiffies(freeze_timeout_msecs);
|
2010-06-29 08:07:12 +00:00
|
|
|
|
2011-11-21 20:32:26 +00:00
|
|
|
if (!user_only)
|
2010-06-29 08:07:12 +00:00
|
|
|
freeze_workqueues_begin();
|
|
|
|
|
2009-10-08 20:47:30 +00:00
|
|
|
while (true) {
|
2006-12-07 04:34:40 +00:00
|
|
|
todo = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
read_lock(&tasklist_lock);
|
2014-10-21 07:27:15 +00:00
|
|
|
for_each_process_thread(g, p) {
|
2011-11-21 20:32:26 +00:00
|
|
|
if (p == current || !freeze_task(p))
|
2007-10-18 10:04:46 +00:00
|
|
|
continue;
|
|
|
|
|
freezer,sched: Rewrite core freezer logic
Rewrite the core freezer to behave better wrt thawing and be simpler
in general.
By replacing PF_FROZEN with TASK_FROZEN, a special block state, it is
ensured frozen tasks stay frozen until thawed and don't randomly wake
up early, as is currently possible.
As such, it does away with PF_FROZEN and PF_FREEZER_SKIP, freeing up
two PF_flags (yay!).
Specifically; the current scheme works a little like:
freezer_do_not_count();
schedule();
freezer_count();
And either the task is blocked, or it lands in try_to_freezer()
through freezer_count(). Now, when it is blocked, the freezer
considers it frozen and continues.
However, on thawing, once pm_freezing is cleared, freezer_count()
stops working, and any random/spurious wakeup will let a task run
before its time.
That is, thawing tries to thaw things in explicit order; kernel
threads and workqueues before doing bringing SMP back before userspace
etc.. However due to the above mentioned races it is entirely possible
for userspace tasks to thaw (by accident) before SMP is back.
This can be a fatal problem in asymmetric ISA architectures (eg ARMv9)
where the userspace task requires a special CPU to run.
As said; replace this with a special task state TASK_FROZEN and add
the following state transitions:
TASK_FREEZABLE -> TASK_FROZEN
__TASK_STOPPED -> TASK_FROZEN
__TASK_TRACED -> TASK_FROZEN
The new TASK_FREEZABLE can be set on any state part of TASK_NORMAL
(IOW. TASK_INTERRUPTIBLE and TASK_UNINTERRUPTIBLE) -- any such state
is already required to deal with spurious wakeups and the freezer
causes one such when thawing the task (since the original state is
lost).
The special __TASK_{STOPPED,TRACED} states *can* be restored since
their canonical state is in ->jobctl.
With this, frozen tasks need an explicit TASK_FROZEN wakeup and are
free of undue (early / spurious) wakeups.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://lore.kernel.org/r/20220822114649.055452969@infradead.org
2022-08-22 11:18:22 +00:00
|
|
|
todo++;
|
2014-10-21 07:27:15 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
read_unlock(&tasklist_lock);
|
2010-06-29 08:07:12 +00:00
|
|
|
|
2011-11-21 20:32:26 +00:00
|
|
|
if (!user_only) {
|
2010-06-29 08:07:12 +00:00
|
|
|
wq_busy = freeze_workqueues_busy();
|
|
|
|
todo += wq_busy;
|
|
|
|
}
|
|
|
|
|
2009-10-08 20:47:30 +00:00
|
|
|
if (!todo || time_after(jiffies, end_time))
|
2005-09-03 22:57:05 +00:00
|
|
|
break;
|
2009-10-08 20:47:30 +00:00
|
|
|
|
2010-12-03 21:58:31 +00:00
|
|
|
if (pm_wakeup_pending()) {
|
2010-10-04 20:07:32 +00:00
|
|
|
wakeup = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-10-08 20:47:30 +00:00
|
|
|
/*
|
|
|
|
* We need to retry, but first give the freezing tasks some
|
2013-05-06 23:50:10 +00:00
|
|
|
* time to enter the refrigerator. Start with an initial
|
|
|
|
* 1 ms sleep followed by exponential backoff until 8 ms.
|
2009-10-08 20:47:30 +00:00
|
|
|
*/
|
2013-05-06 23:50:10 +00:00
|
|
|
usleep_range(sleep_usecs / 2, sleep_usecs);
|
|
|
|
if (sleep_usecs < 8 * USEC_PER_MSEC)
|
|
|
|
sleep_usecs *= 2;
|
2009-10-08 20:47:30 +00:00
|
|
|
}
|
2005-06-25 06:13:50 +00:00
|
|
|
|
2016-01-31 19:29:01 +00:00
|
|
|
end = ktime_get_boottime();
|
|
|
|
elapsed = ktime_sub(end, start);
|
|
|
|
elapsed_msecs = ktime_to_ms(elapsed);
|
2007-10-18 10:04:49 +00:00
|
|
|
|
2005-09-03 22:57:05 +00:00
|
|
|
if (todo) {
|
2022-12-01 18:34:44 +00:00
|
|
|
pr_err("Freezing %s %s after %d.%03d seconds "
|
|
|
|
"(%d tasks refusing to freeze, wq_busy=%d):\n", what,
|
2010-10-04 20:07:32 +00:00
|
|
|
wakeup ? "aborted" : "failed",
|
2013-05-06 23:50:10 +00:00
|
|
|
elapsed_msecs / 1000, elapsed_msecs % 1000,
|
2010-06-29 08:07:12 +00:00
|
|
|
todo - wq_busy, wq_busy);
|
|
|
|
|
2016-07-01 03:05:02 +00:00
|
|
|
if (wq_busy)
|
2023-03-20 03:29:05 +00:00
|
|
|
show_freezable_workqueues();
|
2016-07-01 03:05:02 +00:00
|
|
|
|
2018-08-23 01:37:11 +00:00
|
|
|
if (!wakeup || pm_debug_messages_on) {
|
2012-02-10 23:00:34 +00:00
|
|
|
read_lock(&tasklist_lock);
|
2014-10-21 07:27:15 +00:00
|
|
|
for_each_process_thread(g, p) {
|
freezer,sched: Rewrite core freezer logic
Rewrite the core freezer to behave better wrt thawing and be simpler
in general.
By replacing PF_FROZEN with TASK_FROZEN, a special block state, it is
ensured frozen tasks stay frozen until thawed and don't randomly wake
up early, as is currently possible.
As such, it does away with PF_FROZEN and PF_FREEZER_SKIP, freeing up
two PF_flags (yay!).
Specifically; the current scheme works a little like:
freezer_do_not_count();
schedule();
freezer_count();
And either the task is blocked, or it lands in try_to_freezer()
through freezer_count(). Now, when it is blocked, the freezer
considers it frozen and continues.
However, on thawing, once pm_freezing is cleared, freezer_count()
stops working, and any random/spurious wakeup will let a task run
before its time.
That is, thawing tries to thaw things in explicit order; kernel
threads and workqueues before doing bringing SMP back before userspace
etc.. However due to the above mentioned races it is entirely possible
for userspace tasks to thaw (by accident) before SMP is back.
This can be a fatal problem in asymmetric ISA architectures (eg ARMv9)
where the userspace task requires a special CPU to run.
As said; replace this with a special task state TASK_FROZEN and add
the following state transitions:
TASK_FREEZABLE -> TASK_FROZEN
__TASK_STOPPED -> TASK_FROZEN
__TASK_TRACED -> TASK_FROZEN
The new TASK_FREEZABLE can be set on any state part of TASK_NORMAL
(IOW. TASK_INTERRUPTIBLE and TASK_UNINTERRUPTIBLE) -- any such state
is already required to deal with spurious wakeups and the freezer
causes one such when thawing the task (since the original state is
lost).
The special __TASK_{STOPPED,TRACED} states *can* be restored since
their canonical state is in ->jobctl.
With this, frozen tasks need an explicit TASK_FROZEN wakeup and are
free of undue (early / spurious) wakeups.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://lore.kernel.org/r/20220822114649.055452969@infradead.org
2022-08-22 11:18:22 +00:00
|
|
|
if (p != current && freezing(p) && !frozen(p))
|
2012-02-10 23:00:34 +00:00
|
|
|
sched_show_task(p);
|
2014-10-21 07:27:15 +00:00
|
|
|
}
|
2012-02-10 23:00:34 +00:00
|
|
|
read_unlock(&tasklist_lock);
|
|
|
|
}
|
2007-10-18 10:04:49 +00:00
|
|
|
} else {
|
2022-12-01 18:33:09 +00:00
|
|
|
pr_info("Freezing %s completed (elapsed %d.%03d seconds)\n",
|
|
|
|
what, elapsed_msecs / 1000, elapsed_msecs % 1000);
|
2005-09-03 22:57:05 +00:00
|
|
|
}
|
|
|
|
|
2007-07-19 08:47:34 +00:00
|
|
|
return todo ? -EBUSY : 0;
|
2006-12-07 04:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-09-26 18:32:27 +00:00
|
|
|
* freeze_processes - Signal user space processes to enter the refrigerator.
|
2013-07-25 00:41:33 +00:00
|
|
|
* The current thread will not be frozen. The same process that calls
|
|
|
|
* freeze_processes must later call thaw_processes.
|
2011-11-21 20:32:24 +00:00
|
|
|
*
|
|
|
|
* On success, returns 0. On failure, -errno and system is fully thawed.
|
2006-12-07 04:34:40 +00:00
|
|
|
*/
|
|
|
|
int freeze_processes(void)
|
|
|
|
{
|
2007-07-19 08:47:34 +00:00
|
|
|
int error;
|
2006-12-07 04:34:40 +00: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-28 21:30:28 +00:00
|
|
|
error = __usermodehelper_disable(UMH_FREEZING);
|
2012-03-28 21:30:21 +00:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
2013-07-25 00:41:33 +00:00
|
|
|
/* Make sure this task doesn't get frozen */
|
|
|
|
current->flags |= PF_SUSPEND_TASK;
|
|
|
|
|
2011-11-21 20:32:25 +00:00
|
|
|
if (!pm_freezing)
|
freezer,sched: Rewrite core freezer logic
Rewrite the core freezer to behave better wrt thawing and be simpler
in general.
By replacing PF_FROZEN with TASK_FROZEN, a special block state, it is
ensured frozen tasks stay frozen until thawed and don't randomly wake
up early, as is currently possible.
As such, it does away with PF_FROZEN and PF_FREEZER_SKIP, freeing up
two PF_flags (yay!).
Specifically; the current scheme works a little like:
freezer_do_not_count();
schedule();
freezer_count();
And either the task is blocked, or it lands in try_to_freezer()
through freezer_count(). Now, when it is blocked, the freezer
considers it frozen and continues.
However, on thawing, once pm_freezing is cleared, freezer_count()
stops working, and any random/spurious wakeup will let a task run
before its time.
That is, thawing tries to thaw things in explicit order; kernel
threads and workqueues before doing bringing SMP back before userspace
etc.. However due to the above mentioned races it is entirely possible
for userspace tasks to thaw (by accident) before SMP is back.
This can be a fatal problem in asymmetric ISA architectures (eg ARMv9)
where the userspace task requires a special CPU to run.
As said; replace this with a special task state TASK_FROZEN and add
the following state transitions:
TASK_FREEZABLE -> TASK_FROZEN
__TASK_STOPPED -> TASK_FROZEN
__TASK_TRACED -> TASK_FROZEN
The new TASK_FREEZABLE can be set on any state part of TASK_NORMAL
(IOW. TASK_INTERRUPTIBLE and TASK_UNINTERRUPTIBLE) -- any such state
is already required to deal with spurious wakeups and the freezer
causes one such when thawing the task (since the original state is
lost).
The special __TASK_{STOPPED,TRACED} states *can* be restored since
their canonical state is in ->jobctl.
With this, frozen tasks need an explicit TASK_FROZEN wakeup and are
free of undue (early / spurious) wakeups.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://lore.kernel.org/r/20220822114649.055452969@infradead.org
2022-08-22 11:18:22 +00:00
|
|
|
static_branch_inc(&freezer_active);
|
2011-11-21 20:32:25 +00:00
|
|
|
|
PM: s2idle: ACPI: Fix wakeup interrupts handling
After commit e3728b50cd9b ("ACPI: PM: s2idle: Avoid possible race
related to the EC GPE") wakeup interrupts occurring immediately after
the one discarded by acpi_s2idle_wake() may be missed. Moreover, if
the SCI triggers again immediately after the rearming in
acpi_s2idle_wake(), that wakeup may be missed too.
The problem is that pm_system_irq_wakeup() only calls pm_system_wakeup()
when pm_wakeup_irq is 0, but that's not the case any more after the
interrupt causing acpi_s2idle_wake() to run until pm_wakeup_irq is
cleared by the pm_wakeup_clear() call in s2idle_loop(). However,
there may be wakeup interrupts occurring in that time frame and if
that happens, they will be missed.
To address that issue first move the clearing of pm_wakeup_irq to
the point at which it is known that the interrupt causing
acpi_s2idle_wake() to tun will be discarded, before rearming the SCI
for wakeup. Moreover, because that only reduces the size of the
time window in which the issue may manifest itself, allow
pm_system_irq_wakeup() to register two second wakeup interrupts in
a row and, when discarding the first one, replace it with the second
one. [Of course, this assumes that only one wakeup interrupt can be
discarded in one go, but currently that is the case and I am not
aware of any plans to change that.]
Fixes: e3728b50cd9b ("ACPI: PM: s2idle: Avoid possible race related to the EC GPE")
Cc: 5.4+ <stable@vger.kernel.org> # 5.4+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2022-02-04 17:35:22 +00:00
|
|
|
pm_wakeup_clear(0);
|
2011-11-21 20:32:25 +00:00
|
|
|
pm_freezing = true;
|
2008-06-11 20:04:29 +00:00
|
|
|
error = try_to_freeze_tasks(true);
|
2022-12-01 18:33:09 +00: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-28 21:30:28 +00:00
|
|
|
__usermodehelper_set_disable_depth(UMH_DISABLED);
|
2022-12-01 18:33:09 +00:00
|
|
|
|
2011-09-26 18:32:27 +00:00
|
|
|
BUG_ON(in_atomic());
|
|
|
|
|
2015-02-11 23:26:24 +00:00
|
|
|
/*
|
2020-10-27 12:43:19 +00:00
|
|
|
* Now that the whole userspace is frozen we need to disable
|
2015-02-11 23:26:24 +00:00
|
|
|
* the OOM killer to disallow any further interference with
|
2016-10-07 23:59:00 +00: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-11 23:26:24 +00:00
|
|
|
*/
|
2016-10-07 23:59:00 +00:00
|
|
|
if (!error && !oom_killer_disable(msecs_to_jiffies(freeze_timeout_msecs)))
|
2015-02-11 23:26:24 +00:00
|
|
|
error = -EBUSY;
|
|
|
|
|
2011-11-21 20:32:24 +00:00
|
|
|
if (error)
|
|
|
|
thaw_processes();
|
2011-09-26 18:32:27 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* freeze_kernel_threads - Make freezable kernel threads go to the refrigerator.
|
2011-11-21 20:32:24 +00: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-03 21:22:41 +00: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-26 18:32:27 +00:00
|
|
|
*/
|
|
|
|
int freeze_kernel_threads(void)
|
|
|
|
{
|
|
|
|
int error;
|
2006-12-07 04:34:40 +00:00
|
|
|
|
2011-11-21 20:32:25 +00:00
|
|
|
pm_nosig_freezing = true;
|
2008-06-11 20:04:29 +00:00
|
|
|
error = try_to_freeze_tasks(false);
|
2009-06-16 22:32:41 +00:00
|
|
|
|
2011-09-26 18:32:27 +00:00
|
|
|
BUG_ON(in_atomic());
|
2009-06-16 22:32:41 +00:00
|
|
|
|
2011-11-21 20:32:24 +00: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-03 21:22:41 +00:00
|
|
|
thaw_kernel_threads();
|
2007-10-18 10:04:48 +00:00
|
|
|
return error;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2011-11-21 20:32:23 +00:00
|
|
|
void thaw_processes(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct task_struct *g, *p;
|
2013-07-25 00:41:33 +00:00
|
|
|
struct task_struct *curr = current;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2014-06-06 12:40:17 +00:00
|
|
|
trace_suspend_resume(TPS("thaw_processes"), 0, true);
|
2011-11-21 20:32:25 +00:00
|
|
|
if (pm_freezing)
|
freezer,sched: Rewrite core freezer logic
Rewrite the core freezer to behave better wrt thawing and be simpler
in general.
By replacing PF_FROZEN with TASK_FROZEN, a special block state, it is
ensured frozen tasks stay frozen until thawed and don't randomly wake
up early, as is currently possible.
As such, it does away with PF_FROZEN and PF_FREEZER_SKIP, freeing up
two PF_flags (yay!).
Specifically; the current scheme works a little like:
freezer_do_not_count();
schedule();
freezer_count();
And either the task is blocked, or it lands in try_to_freezer()
through freezer_count(). Now, when it is blocked, the freezer
considers it frozen and continues.
However, on thawing, once pm_freezing is cleared, freezer_count()
stops working, and any random/spurious wakeup will let a task run
before its time.
That is, thawing tries to thaw things in explicit order; kernel
threads and workqueues before doing bringing SMP back before userspace
etc.. However due to the above mentioned races it is entirely possible
for userspace tasks to thaw (by accident) before SMP is back.
This can be a fatal problem in asymmetric ISA architectures (eg ARMv9)
where the userspace task requires a special CPU to run.
As said; replace this with a special task state TASK_FROZEN and add
the following state transitions:
TASK_FREEZABLE -> TASK_FROZEN
__TASK_STOPPED -> TASK_FROZEN
__TASK_TRACED -> TASK_FROZEN
The new TASK_FREEZABLE can be set on any state part of TASK_NORMAL
(IOW. TASK_INTERRUPTIBLE and TASK_UNINTERRUPTIBLE) -- any such state
is already required to deal with spurious wakeups and the freezer
causes one such when thawing the task (since the original state is
lost).
The special __TASK_{STOPPED,TRACED} states *can* be restored since
their canonical state is in ->jobctl.
With this, frozen tasks need an explicit TASK_FROZEN wakeup and are
free of undue (early / spurious) wakeups.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://lore.kernel.org/r/20220822114649.055452969@infradead.org
2022-08-22 11:18:22 +00:00
|
|
|
static_branch_dec(&freezer_active);
|
2011-11-21 20:32:25 +00:00
|
|
|
pm_freezing = false;
|
|
|
|
pm_nosig_freezing = false;
|
|
|
|
|
2011-11-21 20:32:23 +00:00
|
|
|
oom_killer_enable();
|
|
|
|
|
2015-02-11 23:26:18 +00:00
|
|
|
pr_info("Restarting tasks ... ");
|
2011-11-21 20:32:23 +00:00
|
|
|
|
2014-07-15 06:51:27 +00:00
|
|
|
__usermodehelper_set_disable_depth(UMH_FREEZING);
|
2011-11-21 20:32:23 +00:00
|
|
|
thaw_workqueues();
|
|
|
|
|
2017-09-07 09:13:38 +00:00
|
|
|
cpuset_wait_for_hotplug();
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
read_lock(&tasklist_lock);
|
2014-10-21 07:27:15 +00:00
|
|
|
for_each_process_thread(g, p) {
|
2013-07-25 00:41:33 +00:00
|
|
|
/* No other threads should have PF_SUSPEND_TASK set */
|
|
|
|
WARN_ON((p != curr) && (p->flags & PF_SUSPEND_TASK));
|
2011-11-21 20:32:23 +00:00
|
|
|
__thaw_task(p);
|
2014-10-21 07:27:15 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
read_unlock(&tasklist_lock);
|
2009-06-16 22:32:41 +00:00
|
|
|
|
2013-07-25 00:41:33 +00:00
|
|
|
WARN_ON(!(curr->flags & PF_SUSPEND_TASK));
|
|
|
|
curr->flags &= ~PF_SUSPEND_TASK;
|
|
|
|
|
2012-03-28 21:30:21 +00:00
|
|
|
usermodehelper_enable();
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
schedule();
|
2015-02-11 23:26:18 +00:00
|
|
|
pr_cont("done.\n");
|
2014-06-06 12:40:17 +00:00
|
|
|
trace_suspend_resume(TPS("thaw_processes"), 0, false);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2012-01-29 19:35:52 +00:00
|
|
|
void thaw_kernel_threads(void)
|
|
|
|
{
|
|
|
|
struct task_struct *g, *p;
|
|
|
|
|
|
|
|
pm_nosig_freezing = false;
|
2015-02-11 23:26:18 +00:00
|
|
|
pr_info("Restarting kernel threads ... ");
|
2012-01-29 19:35:52 +00:00
|
|
|
|
|
|
|
thaw_workqueues();
|
|
|
|
|
|
|
|
read_lock(&tasklist_lock);
|
2014-10-21 07:27:15 +00:00
|
|
|
for_each_process_thread(g, p) {
|
2021-01-25 04:18:28 +00:00
|
|
|
if (p->flags & PF_KTHREAD)
|
2012-01-29 19:35:52 +00:00
|
|
|
__thaw_task(p);
|
2014-10-21 07:27:15 +00:00
|
|
|
}
|
2012-01-29 19:35:52 +00:00
|
|
|
read_unlock(&tasklist_lock);
|
|
|
|
|
|
|
|
schedule();
|
2015-02-11 23:26:18 +00:00
|
|
|
pr_cont("done.\n");
|
2012-01-29 19:35:52 +00:00
|
|
|
}
|