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
|
2024-07-05 01:03:36 +08:00
|
|
|
#include <linux/irq_work.h>
|
2012-05-11 08:59:07 +08:00
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/task_work.h>
|
2022-02-10 02:20:45 +08:00
|
|
|
#include <linux/resume_user_mode.h>
|
2012-05-11 08:59:07 +08:00
|
|
|
|
2012-08-27 03:12:11 +08:00
|
|
|
static struct callback_head work_exited; /* all we need is ->next == NULL */
|
|
|
|
|
2024-07-30 03:05:06 +08:00
|
|
|
#ifdef CONFIG_IRQ_WORK
|
2024-07-05 01:03:36 +08:00
|
|
|
static void task_work_set_notify_irq(struct irq_work *entry)
|
|
|
|
{
|
|
|
|
test_and_set_tsk_thread_flag(current, TIF_NOTIFY_RESUME);
|
|
|
|
}
|
|
|
|
static DEFINE_PER_CPU(struct irq_work, irq_work_NMI_resume) =
|
|
|
|
IRQ_WORK_INIT_HARD(task_work_set_notify_irq);
|
2024-07-30 03:05:06 +08:00
|
|
|
#endif
|
2024-07-05 01:03:36 +08:00
|
|
|
|
2013-09-12 05:23:31 +08:00
|
|
|
/**
|
|
|
|
* task_work_add - ask the @task to execute @work->func()
|
|
|
|
* @task: the task which should run the callback
|
|
|
|
* @work: the callback to run
|
task_work: cleanup notification modes
A previous commit changed the notification mode from true/false to an
int, allowing notify-no, notify-yes, or signal-notify. This was
backwards compatible in the sense that any existing true/false user
would translate to either 0 (on notification sent) or 1, the latter
which mapped to TWA_RESUME. TWA_SIGNAL was assigned a value of 2.
Clean this up properly, and define a proper enum for the notification
mode. Now we have:
- TWA_NONE. This is 0, same as before the original change, meaning no
notification requested.
- TWA_RESUME. This is 1, same as before the original change, meaning
that we use TIF_NOTIFY_RESUME.
- TWA_SIGNAL. This uses TIF_SIGPENDING/JOBCTL_TASK_WORK for the
notification.
Clean up all the callers, switching their 0/1/false/true to using the
appropriate TWA_* mode for notifications.
Fixes: e91b48162332 ("task_work: teach task_work_add() to do signal_wake_up()")
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2020-10-16 23:02:26 +08:00
|
|
|
* @notify: how to notify the targeted task
|
2013-09-12 05:23:31 +08:00
|
|
|
*
|
task_work: cleanup notification modes
A previous commit changed the notification mode from true/false to an
int, allowing notify-no, notify-yes, or signal-notify. This was
backwards compatible in the sense that any existing true/false user
would translate to either 0 (on notification sent) or 1, the latter
which mapped to TWA_RESUME. TWA_SIGNAL was assigned a value of 2.
Clean this up properly, and define a proper enum for the notification
mode. Now we have:
- TWA_NONE. This is 0, same as before the original change, meaning no
notification requested.
- TWA_RESUME. This is 1, same as before the original change, meaning
that we use TIF_NOTIFY_RESUME.
- TWA_SIGNAL. This uses TIF_SIGPENDING/JOBCTL_TASK_WORK for the
notification.
Clean up all the callers, switching their 0/1/false/true to using the
appropriate TWA_* mode for notifications.
Fixes: e91b48162332 ("task_work: teach task_work_add() to do signal_wake_up()")
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2020-10-16 23:02:26 +08:00
|
|
|
* Queue @work for task_work_run() below and notify the @task if @notify
|
2024-07-05 01:03:36 +08:00
|
|
|
* is @TWA_RESUME, @TWA_SIGNAL, @TWA_SIGNAL_NO_IPI or @TWA_NMI_CURRENT.
|
2022-04-29 07:25:16 +08:00
|
|
|
*
|
|
|
|
* @TWA_SIGNAL works like signals, in that the it will interrupt the targeted
|
|
|
|
* task and run the task_work, regardless of whether the task is currently
|
|
|
|
* running in the kernel or userspace.
|
|
|
|
* @TWA_SIGNAL_NO_IPI works like @TWA_SIGNAL, except it doesn't send a
|
|
|
|
* reschedule IPI to force the targeted task to reschedule and run task_work.
|
|
|
|
* This can be advantageous if there's no strict requirement that the
|
|
|
|
* task_work be run as soon as possible, just whenever the task enters the
|
|
|
|
* kernel anyway.
|
|
|
|
* @TWA_RESUME work is run only when the task exits the kernel and returns to
|
|
|
|
* user mode, or before entering guest mode.
|
2024-07-05 01:03:36 +08:00
|
|
|
* @TWA_NMI_CURRENT works like @TWA_RESUME, except it can only be used for the
|
|
|
|
* current @task and if the current context is NMI.
|
2022-04-29 07:25:16 +08:00
|
|
|
*
|
|
|
|
* Fails if the @task is exiting/exited and thus it can't process this @work.
|
|
|
|
* Otherwise @work->func() will be called when the @task goes through one of
|
|
|
|
* the aforementioned transitions, or exits.
|
2013-09-12 05:23:31 +08:00
|
|
|
*
|
task_work: cleanup notification modes
A previous commit changed the notification mode from true/false to an
int, allowing notify-no, notify-yes, or signal-notify. This was
backwards compatible in the sense that any existing true/false user
would translate to either 0 (on notification sent) or 1, the latter
which mapped to TWA_RESUME. TWA_SIGNAL was assigned a value of 2.
Clean this up properly, and define a proper enum for the notification
mode. Now we have:
- TWA_NONE. This is 0, same as before the original change, meaning no
notification requested.
- TWA_RESUME. This is 1, same as before the original change, meaning
that we use TIF_NOTIFY_RESUME.
- TWA_SIGNAL. This uses TIF_SIGPENDING/JOBCTL_TASK_WORK for the
notification.
Clean up all the callers, switching their 0/1/false/true to using the
appropriate TWA_* mode for notifications.
Fixes: e91b48162332 ("task_work: teach task_work_add() to do signal_wake_up()")
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2020-10-16 23:02:26 +08:00
|
|
|
* If the targeted task is exiting, then an error is returned and the work item
|
|
|
|
* is not queued. It's up to the caller to arrange for an alternative mechanism
|
|
|
|
* in that case.
|
2013-09-12 05:23:31 +08:00
|
|
|
*
|
task_work: cleanup notification modes
A previous commit changed the notification mode from true/false to an
int, allowing notify-no, notify-yes, or signal-notify. This was
backwards compatible in the sense that any existing true/false user
would translate to either 0 (on notification sent) or 1, the latter
which mapped to TWA_RESUME. TWA_SIGNAL was assigned a value of 2.
Clean this up properly, and define a proper enum for the notification
mode. Now we have:
- TWA_NONE. This is 0, same as before the original change, meaning no
notification requested.
- TWA_RESUME. This is 1, same as before the original change, meaning
that we use TIF_NOTIFY_RESUME.
- TWA_SIGNAL. This uses TIF_SIGPENDING/JOBCTL_TASK_WORK for the
notification.
Clean up all the callers, switching their 0/1/false/true to using the
appropriate TWA_* mode for notifications.
Fixes: e91b48162332 ("task_work: teach task_work_add() to do signal_wake_up()")
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2020-10-16 23:02:26 +08:00
|
|
|
* Note: there is no ordering guarantee on works queued here. The task_work
|
|
|
|
* list is LIFO.
|
2015-08-29 10:42:30 +08:00
|
|
|
*
|
2013-09-12 05:23:31 +08:00
|
|
|
* RETURNS:
|
|
|
|
* 0 if succeeds or -ESRCH.
|
|
|
|
*/
|
task_work: cleanup notification modes
A previous commit changed the notification mode from true/false to an
int, allowing notify-no, notify-yes, or signal-notify. This was
backwards compatible in the sense that any existing true/false user
would translate to either 0 (on notification sent) or 1, the latter
which mapped to TWA_RESUME. TWA_SIGNAL was assigned a value of 2.
Clean this up properly, and define a proper enum for the notification
mode. Now we have:
- TWA_NONE. This is 0, same as before the original change, meaning no
notification requested.
- TWA_RESUME. This is 1, same as before the original change, meaning
that we use TIF_NOTIFY_RESUME.
- TWA_SIGNAL. This uses TIF_SIGPENDING/JOBCTL_TASK_WORK for the
notification.
Clean up all the callers, switching their 0/1/false/true to using the
appropriate TWA_* mode for notifications.
Fixes: e91b48162332 ("task_work: teach task_work_add() to do signal_wake_up()")
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2020-10-16 23:02:26 +08:00
|
|
|
int task_work_add(struct task_struct *task, struct callback_head *work,
|
|
|
|
enum task_work_notify_mode notify)
|
2012-05-11 08:59:07 +08:00
|
|
|
{
|
2012-08-27 03:12:09 +08:00
|
|
|
struct callback_head *head;
|
2012-08-27 03:12:11 +08:00
|
|
|
|
2024-07-05 01:03:36 +08:00
|
|
|
if (notify == TWA_NMI_CURRENT) {
|
|
|
|
if (WARN_ON_ONCE(task != current))
|
|
|
|
return -EINVAL;
|
2024-07-30 03:05:06 +08:00
|
|
|
if (!IS_ENABLED(CONFIG_IRQ_WORK))
|
|
|
|
return -EINVAL;
|
2024-07-05 01:03:36 +08:00
|
|
|
} else {
|
|
|
|
/* record the work call stack in order to print it in KASAN reports */
|
|
|
|
kasan_record_aux_stack(work);
|
|
|
|
}
|
2021-04-30 14:00:45 +08:00
|
|
|
|
2022-08-23 23:26:32 +08:00
|
|
|
head = READ_ONCE(task->task_works);
|
2012-08-27 03:12:09 +08:00
|
|
|
do {
|
2012-08-27 03:12:11 +08:00
|
|
|
if (unlikely(head == &work_exited))
|
|
|
|
return -ESRCH;
|
2012-08-27 03:12:09 +08:00
|
|
|
work->next = head;
|
2022-08-23 23:26:32 +08:00
|
|
|
} while (!try_cmpxchg(&task->task_works, &head, work));
|
2012-05-11 08:59:07 +08:00
|
|
|
|
2020-06-30 23:32:54 +08:00
|
|
|
switch (notify) {
|
task_work: cleanup notification modes
A previous commit changed the notification mode from true/false to an
int, allowing notify-no, notify-yes, or signal-notify. This was
backwards compatible in the sense that any existing true/false user
would translate to either 0 (on notification sent) or 1, the latter
which mapped to TWA_RESUME. TWA_SIGNAL was assigned a value of 2.
Clean this up properly, and define a proper enum for the notification
mode. Now we have:
- TWA_NONE. This is 0, same as before the original change, meaning no
notification requested.
- TWA_RESUME. This is 1, same as before the original change, meaning
that we use TIF_NOTIFY_RESUME.
- TWA_SIGNAL. This uses TIF_SIGPENDING/JOBCTL_TASK_WORK for the
notification.
Clean up all the callers, switching their 0/1/false/true to using the
appropriate TWA_* mode for notifications.
Fixes: e91b48162332 ("task_work: teach task_work_add() to do signal_wake_up()")
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2020-10-16 23:02:26 +08:00
|
|
|
case TWA_NONE:
|
|
|
|
break;
|
2020-06-30 23:32:54 +08:00
|
|
|
case TWA_RESUME:
|
2012-05-11 08:59:07 +08:00
|
|
|
set_notify_resume(task);
|
2020-06-30 23:32:54 +08:00
|
|
|
break;
|
|
|
|
case TWA_SIGNAL:
|
2020-10-10 06:01:33 +08:00
|
|
|
set_notify_signal(task);
|
2020-06-30 23:32:54 +08:00
|
|
|
break;
|
2022-04-29 07:25:16 +08:00
|
|
|
case TWA_SIGNAL_NO_IPI:
|
|
|
|
__set_notify_signal(task);
|
|
|
|
break;
|
2024-07-30 03:05:06 +08:00
|
|
|
#ifdef CONFIG_IRQ_WORK
|
2024-07-05 01:03:36 +08:00
|
|
|
case TWA_NMI_CURRENT:
|
|
|
|
irq_work_queue(this_cpu_ptr(&irq_work_NMI_resume));
|
|
|
|
break;
|
2024-07-30 03:05:06 +08:00
|
|
|
#endif
|
task_work: cleanup notification modes
A previous commit changed the notification mode from true/false to an
int, allowing notify-no, notify-yes, or signal-notify. This was
backwards compatible in the sense that any existing true/false user
would translate to either 0 (on notification sent) or 1, the latter
which mapped to TWA_RESUME. TWA_SIGNAL was assigned a value of 2.
Clean this up properly, and define a proper enum for the notification
mode. Now we have:
- TWA_NONE. This is 0, same as before the original change, meaning no
notification requested.
- TWA_RESUME. This is 1, same as before the original change, meaning
that we use TIF_NOTIFY_RESUME.
- TWA_SIGNAL. This uses TIF_SIGPENDING/JOBCTL_TASK_WORK for the
notification.
Clean up all the callers, switching their 0/1/false/true to using the
appropriate TWA_* mode for notifications.
Fixes: e91b48162332 ("task_work: teach task_work_add() to do signal_wake_up()")
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2020-10-16 23:02:26 +08:00
|
|
|
default:
|
|
|
|
WARN_ON_ONCE(1);
|
|
|
|
break;
|
2020-06-30 23:32:54 +08:00
|
|
|
}
|
|
|
|
|
2012-06-27 15:31:24 +08:00
|
|
|
return 0;
|
2012-05-11 08:59:07 +08:00
|
|
|
}
|
|
|
|
|
2013-09-12 05:23:31 +08:00
|
|
|
/**
|
2021-04-02 09:53:29 +08:00
|
|
|
* task_work_cancel_match - cancel a pending work added by task_work_add()
|
2013-09-12 05:23:31 +08:00
|
|
|
* @task: the task which should execute the work
|
2021-04-02 09:53:29 +08:00
|
|
|
* @match: match function to call
|
2023-09-12 04:24:06 +08:00
|
|
|
* @data: data to be passed in to match function
|
2013-09-12 05:23:31 +08:00
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* The found work or NULL if not found.
|
|
|
|
*/
|
2012-06-27 15:07:19 +08:00
|
|
|
struct callback_head *
|
2021-04-02 09:53:29 +08:00
|
|
|
task_work_cancel_match(struct task_struct *task,
|
|
|
|
bool (*match)(struct callback_head *, void *data),
|
|
|
|
void *data)
|
2012-05-11 08:59:07 +08:00
|
|
|
{
|
2012-08-27 03:12:09 +08:00
|
|
|
struct callback_head **pprev = &task->task_works;
|
2013-09-12 05:23:30 +08:00
|
|
|
struct callback_head *work;
|
2012-05-11 08:59:07 +08:00
|
|
|
unsigned long flags;
|
2016-08-03 05:03:44 +08:00
|
|
|
|
2022-02-09 22:52:41 +08:00
|
|
|
if (likely(!task_work_pending(task)))
|
2016-08-03 05:03:44 +08:00
|
|
|
return NULL;
|
2012-08-27 03:12:09 +08:00
|
|
|
/*
|
|
|
|
* If cmpxchg() fails we continue without updating pprev.
|
|
|
|
* Either we raced with task_work_add() which added the
|
|
|
|
* new entry before this work, we will find it again. Or
|
2012-08-27 03:12:11 +08:00
|
|
|
* we raced with task_work_run(), *pprev == NULL/exited.
|
2012-08-27 03:12:09 +08:00
|
|
|
*/
|
2012-05-11 08:59:07 +08:00
|
|
|
raw_spin_lock_irqsave(&task->pi_lock, flags);
|
2022-08-23 23:26:32 +08:00
|
|
|
work = READ_ONCE(*pprev);
|
|
|
|
while (work) {
|
|
|
|
if (!match(work, data)) {
|
2012-08-27 03:12:09 +08:00
|
|
|
pprev = &work->next;
|
2022-08-23 23:26:32 +08:00
|
|
|
work = READ_ONCE(*pprev);
|
|
|
|
} else if (try_cmpxchg(pprev, &work, work->next))
|
2012-08-27 03:12:09 +08:00
|
|
|
break;
|
2012-05-11 08:59:07 +08:00
|
|
|
}
|
|
|
|
raw_spin_unlock_irqrestore(&task->pi_lock, flags);
|
2012-08-27 03:12:09 +08:00
|
|
|
|
|
|
|
return work;
|
2012-05-11 08:59:07 +08:00
|
|
|
}
|
|
|
|
|
2021-04-02 09:53:29 +08:00
|
|
|
static bool task_work_func_match(struct callback_head *cb, void *data)
|
|
|
|
{
|
|
|
|
return cb->func == data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-06-21 17:15:58 +08:00
|
|
|
* task_work_cancel_func - cancel a pending work matching a function added by task_work_add()
|
|
|
|
* @task: the task which should execute the func's work
|
|
|
|
* @func: identifies the func to match with a work to remove
|
2021-04-02 09:53:29 +08:00
|
|
|
*
|
|
|
|
* Find the last queued pending work with ->func == @func and remove
|
|
|
|
* it from queue.
|
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* The found work or NULL if not found.
|
|
|
|
*/
|
|
|
|
struct callback_head *
|
2024-06-21 17:15:58 +08:00
|
|
|
task_work_cancel_func(struct task_struct *task, task_work_func_t func)
|
2021-04-02 09:53:29 +08:00
|
|
|
{
|
|
|
|
return task_work_cancel_match(task, task_work_func_match, func);
|
|
|
|
}
|
|
|
|
|
2024-06-21 17:15:59 +08:00
|
|
|
static bool task_work_match(struct callback_head *cb, void *data)
|
|
|
|
{
|
|
|
|
return cb == data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* task_work_cancel - cancel a pending work added by task_work_add()
|
|
|
|
* @task: the task which should execute the work
|
|
|
|
* @cb: the callback to remove if queued
|
|
|
|
*
|
|
|
|
* Remove a callback from a task's queue if queued.
|
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* True if the callback was queued and got cancelled, false otherwise.
|
|
|
|
*/
|
|
|
|
bool task_work_cancel(struct task_struct *task, struct callback_head *cb)
|
|
|
|
{
|
|
|
|
struct callback_head *ret;
|
|
|
|
|
|
|
|
ret = task_work_cancel_match(task, task_work_match, cb);
|
|
|
|
|
|
|
|
return ret == cb;
|
|
|
|
}
|
|
|
|
|
2013-09-12 05:23:31 +08:00
|
|
|
/**
|
|
|
|
* task_work_run - execute the works added by task_work_add()
|
|
|
|
*
|
|
|
|
* Flush the pending works. Should be used by the core kernel code.
|
|
|
|
* Called before the task returns to the user-mode or stops, or when
|
|
|
|
* it exits. In the latter case task_work_add() can no longer add the
|
|
|
|
* new work after task_work_run() returns.
|
|
|
|
*/
|
2012-05-11 08:59:07 +08:00
|
|
|
void task_work_run(void)
|
|
|
|
{
|
|
|
|
struct task_struct *task = current;
|
2012-08-27 03:12:09 +08:00
|
|
|
struct callback_head *work, *head, *next;
|
2012-05-11 08:59:07 +08:00
|
|
|
|
2012-08-27 03:12:09 +08:00
|
|
|
for (;;) {
|
2012-08-27 03:12:11 +08:00
|
|
|
/*
|
|
|
|
* work->func() can do task_work_add(), do not set
|
|
|
|
* work_exited unless the list is empty.
|
|
|
|
*/
|
2022-08-23 23:26:32 +08:00
|
|
|
work = READ_ONCE(task->task_works);
|
2012-08-27 03:12:11 +08:00
|
|
|
do {
|
2020-02-18 23:50:18 +08:00
|
|
|
head = NULL;
|
|
|
|
if (!work) {
|
|
|
|
if (task->flags & PF_EXITING)
|
|
|
|
head = &work_exited;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
2022-08-23 23:26:32 +08:00
|
|
|
} while (!try_cmpxchg(&task->task_works, &work, head));
|
2012-08-27 03:12:11 +08:00
|
|
|
|
2012-08-27 03:12:09 +08:00
|
|
|
if (!work)
|
|
|
|
break;
|
2020-02-18 23:50:18 +08:00
|
|
|
/*
|
2024-06-21 17:15:58 +08:00
|
|
|
* Synchronize with task_work_cancel_match(). It can not remove
|
2020-02-18 23:50:18 +08:00
|
|
|
* the first entry == work, cmpxchg(task_works) must fail.
|
|
|
|
* But it can remove another entry from the ->next list.
|
|
|
|
*/
|
|
|
|
raw_spin_lock_irq(&task->pi_lock);
|
|
|
|
raw_spin_unlock_irq(&task->pi_lock);
|
2012-05-11 08:59:07 +08:00
|
|
|
|
2012-08-27 03:12:09 +08:00
|
|
|
do {
|
|
|
|
next = work->next;
|
|
|
|
work->func(work);
|
|
|
|
work = next;
|
2012-08-21 21:05:14 +08:00
|
|
|
cond_resched();
|
2012-08-27 03:12:09 +08:00
|
|
|
} while (work);
|
2012-05-11 08:59:07 +08:00
|
|
|
}
|
|
|
|
}
|