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 17:07:57 +03:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2013-07-05 11:29:32 +04:00
|
|
|
/*
|
|
|
|
* Wound/Wait Mutexes: blocking mutual exclusion locks with deadlock avoidance
|
|
|
|
*
|
|
|
|
* Original mutex implementation started by Ingo Molnar:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004, 2005, 2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
|
|
|
|
*
|
2018-06-15 11:07:12 +03:00
|
|
|
* Wait/Die implementation:
|
2013-07-05 11:29:32 +04:00
|
|
|
* Copyright (C) 2013 Canonical Ltd.
|
2018-06-15 11:17:38 +03:00
|
|
|
* Choice of algorithm:
|
|
|
|
* Copyright (C) 2018 WMWare Inc.
|
2013-07-05 11:29:32 +04:00
|
|
|
*
|
|
|
|
* This file contains the main data structure and API definitions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __LINUX_WW_MUTEX_H
|
|
|
|
#define __LINUX_WW_MUTEX_H
|
|
|
|
|
|
|
|
#include <linux/mutex.h>
|
|
|
|
|
|
|
|
struct ww_class {
|
|
|
|
atomic_long_t stamp;
|
|
|
|
struct lock_class_key acquire_key;
|
|
|
|
struct lock_class_key mutex_key;
|
|
|
|
const char *acquire_name;
|
|
|
|
const char *mutex_name;
|
2018-06-15 11:17:38 +03:00
|
|
|
unsigned int is_wait_die;
|
2013-07-05 11:29:32 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ww_acquire_ctx {
|
|
|
|
struct task_struct *task;
|
|
|
|
unsigned long stamp;
|
2018-06-15 11:07:12 +03:00
|
|
|
unsigned int acquired;
|
2018-06-15 11:17:38 +03:00
|
|
|
unsigned short wounded;
|
|
|
|
unsigned short is_wait_die;
|
2013-07-05 11:29:32 +04:00
|
|
|
#ifdef CONFIG_DEBUG_MUTEXES
|
2018-06-15 11:07:12 +03:00
|
|
|
unsigned int done_acquire;
|
2013-07-05 11:29:32 +04:00
|
|
|
struct ww_class *ww_class;
|
|
|
|
struct ww_mutex *contending_lock;
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_DEBUG_LOCK_ALLOC
|
|
|
|
struct lockdep_map dep_map;
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
|
2018-06-15 11:07:12 +03:00
|
|
|
unsigned int deadlock_inject_interval;
|
|
|
|
unsigned int deadlock_inject_countdown;
|
2013-07-05 11:29:32 +04:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ww_mutex {
|
|
|
|
struct mutex base;
|
|
|
|
struct ww_acquire_ctx *ctx;
|
|
|
|
#ifdef CONFIG_DEBUG_MUTEXES
|
|
|
|
struct ww_class *ww_class;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_LOCK_ALLOC
|
2016-12-01 14:47:04 +03:00
|
|
|
# define __WW_CLASS_MUTEX_INITIALIZER(lockname, class) \
|
|
|
|
, .ww_class = class
|
2013-07-05 11:29:32 +04:00
|
|
|
#else
|
2016-12-01 14:47:04 +03:00
|
|
|
# define __WW_CLASS_MUTEX_INITIALIZER(lockname, class)
|
2013-07-05 11:29:32 +04:00
|
|
|
#endif
|
|
|
|
|
2018-06-15 11:17:38 +03:00
|
|
|
#define __WW_CLASS_INITIALIZER(ww_class, _is_wait_die) \
|
2013-07-05 11:29:32 +04:00
|
|
|
{ .stamp = ATOMIC_LONG_INIT(0) \
|
|
|
|
, .acquire_name = #ww_class "_acquire" \
|
2018-06-15 11:17:38 +03:00
|
|
|
, .mutex_name = #ww_class "_mutex" \
|
|
|
|
, .is_wait_die = _is_wait_die }
|
2013-07-05 11:29:32 +04:00
|
|
|
|
|
|
|
#define __WW_MUTEX_INITIALIZER(lockname, class) \
|
2016-12-01 14:47:04 +03:00
|
|
|
{ .base = __MUTEX_INITIALIZER(lockname.base) \
|
2013-07-05 11:29:32 +04:00
|
|
|
__WW_CLASS_MUTEX_INITIALIZER(lockname, class) }
|
|
|
|
|
2018-06-15 11:17:38 +03:00
|
|
|
#define DEFINE_WD_CLASS(classname) \
|
|
|
|
struct ww_class classname = __WW_CLASS_INITIALIZER(classname, 1)
|
|
|
|
|
2013-07-05 11:29:32 +04:00
|
|
|
#define DEFINE_WW_CLASS(classname) \
|
2018-06-15 11:17:38 +03:00
|
|
|
struct ww_class classname = __WW_CLASS_INITIALIZER(classname, 0)
|
2013-07-05 11:29:32 +04:00
|
|
|
|
|
|
|
#define DEFINE_WW_MUTEX(mutexname, ww_class) \
|
|
|
|
struct ww_mutex mutexname = __WW_MUTEX_INITIALIZER(mutexname, ww_class)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ww_mutex_init - initialize the w/w mutex
|
|
|
|
* @lock: the mutex to be initialized
|
|
|
|
* @ww_class: the w/w class the mutex should belong to
|
|
|
|
*
|
|
|
|
* Initialize the w/w mutex to unlocked state and associate it with the given
|
|
|
|
* class.
|
|
|
|
*
|
|
|
|
* It is not allowed to initialize an already locked mutex.
|
|
|
|
*/
|
|
|
|
static inline void ww_mutex_init(struct ww_mutex *lock,
|
|
|
|
struct ww_class *ww_class)
|
|
|
|
{
|
|
|
|
__mutex_init(&lock->base, ww_class->mutex_name, &ww_class->mutex_key);
|
|
|
|
lock->ctx = NULL;
|
|
|
|
#ifdef CONFIG_DEBUG_MUTEXES
|
|
|
|
lock->ww_class = ww_class;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ww_acquire_init - initialize a w/w acquire context
|
|
|
|
* @ctx: w/w acquire context to initialize
|
|
|
|
* @ww_class: w/w class of the context
|
|
|
|
*
|
|
|
|
* Initializes an context to acquire multiple mutexes of the given w/w class.
|
|
|
|
*
|
|
|
|
* Context-based w/w mutex acquiring can be done in any order whatsoever within
|
|
|
|
* a given lock class. Deadlocks will be detected and handled with the
|
2018-06-15 11:07:12 +03:00
|
|
|
* wait/die logic.
|
2013-07-05 11:29:32 +04:00
|
|
|
*
|
|
|
|
* Mixing of context-based w/w mutex acquiring and single w/w mutex locking can
|
|
|
|
* result in undetected deadlocks and is so forbidden. Mixing different contexts
|
|
|
|
* for the same w/w class when acquiring mutexes can also result in undetected
|
|
|
|
* deadlocks, and is hence also forbidden. Both types of abuse will be caught by
|
|
|
|
* enabling CONFIG_PROVE_LOCKING.
|
|
|
|
*
|
|
|
|
* Nesting of acquire contexts for _different_ w/w classes is possible, subject
|
|
|
|
* to the usual locking rules between different lock classes.
|
|
|
|
*
|
|
|
|
* An acquire context must be released with ww_acquire_fini by the same task
|
|
|
|
* before the memory is freed. It is recommended to allocate the context itself
|
|
|
|
* on the stack.
|
|
|
|
*/
|
|
|
|
static inline void ww_acquire_init(struct ww_acquire_ctx *ctx,
|
|
|
|
struct ww_class *ww_class)
|
|
|
|
{
|
|
|
|
ctx->task = current;
|
2016-11-24 14:46:26 +03:00
|
|
|
ctx->stamp = atomic_long_inc_return_relaxed(&ww_class->stamp);
|
2013-07-05 11:29:32 +04:00
|
|
|
ctx->acquired = 0;
|
2018-06-15 11:17:38 +03:00
|
|
|
ctx->wounded = false;
|
|
|
|
ctx->is_wait_die = ww_class->is_wait_die;
|
2013-07-05 11:29:32 +04:00
|
|
|
#ifdef CONFIG_DEBUG_MUTEXES
|
|
|
|
ctx->ww_class = ww_class;
|
|
|
|
ctx->done_acquire = 0;
|
|
|
|
ctx->contending_lock = NULL;
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_DEBUG_LOCK_ALLOC
|
|
|
|
debug_check_no_locks_freed((void *)ctx, sizeof(*ctx));
|
|
|
|
lockdep_init_map(&ctx->dep_map, ww_class->acquire_name,
|
|
|
|
&ww_class->acquire_key, 0);
|
|
|
|
mutex_acquire(&ctx->dep_map, 0, 0, _RET_IP_);
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
|
|
|
|
ctx->deadlock_inject_interval = 1;
|
|
|
|
ctx->deadlock_inject_countdown = ctx->stamp & 0xf;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ww_acquire_done - marks the end of the acquire phase
|
|
|
|
* @ctx: the acquire context
|
|
|
|
*
|
|
|
|
* Marks the end of the acquire phase, any further w/w mutex lock calls using
|
|
|
|
* this context are forbidden.
|
|
|
|
*
|
|
|
|
* Calling this function is optional, it is just useful to document w/w mutex
|
|
|
|
* code and clearly designated the acquire phase from actually using the locked
|
|
|
|
* data structures.
|
|
|
|
*/
|
|
|
|
static inline void ww_acquire_done(struct ww_acquire_ctx *ctx)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_DEBUG_MUTEXES
|
|
|
|
lockdep_assert_held(ctx);
|
|
|
|
|
|
|
|
DEBUG_LOCKS_WARN_ON(ctx->done_acquire);
|
|
|
|
ctx->done_acquire = 1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ww_acquire_fini - releases a w/w acquire context
|
|
|
|
* @ctx: the acquire context to free
|
|
|
|
*
|
|
|
|
* Releases a w/w acquire context. This must be called _after_ all acquired w/w
|
|
|
|
* mutexes have been released with ww_mutex_unlock.
|
|
|
|
*/
|
|
|
|
static inline void ww_acquire_fini(struct ww_acquire_ctx *ctx)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_DEBUG_MUTEXES
|
2019-09-19 19:09:40 +03:00
|
|
|
mutex_release(&ctx->dep_map, _THIS_IP_);
|
2013-07-05 11:29:32 +04:00
|
|
|
|
|
|
|
DEBUG_LOCKS_WARN_ON(ctx->acquired);
|
2016-08-03 23:45:50 +03:00
|
|
|
if (!IS_ENABLED(CONFIG_PROVE_LOCKING))
|
2013-07-05 11:29:32 +04:00
|
|
|
/*
|
|
|
|
* lockdep will normally handle this,
|
|
|
|
* but fail without anyway
|
|
|
|
*/
|
|
|
|
ctx->done_acquire = 1;
|
|
|
|
|
2016-08-03 23:45:50 +03:00
|
|
|
if (!IS_ENABLED(CONFIG_DEBUG_LOCK_ALLOC))
|
2013-07-05 11:29:32 +04:00
|
|
|
/* ensure ww_acquire_fini will still fail if called twice */
|
|
|
|
ctx->acquired = ~0U;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ww_mutex_lock - acquire the w/w mutex
|
|
|
|
* @lock: the mutex to be acquired
|
|
|
|
* @ctx: w/w acquire context, or NULL to acquire only a single lock.
|
|
|
|
*
|
|
|
|
* Lock the w/w mutex exclusively for this task.
|
|
|
|
*
|
|
|
|
* Deadlocks within a given w/w class of locks are detected and handled with the
|
2018-06-15 11:07:12 +03:00
|
|
|
* wait/die algorithm. If the lock isn't immediately available this function
|
2013-07-05 11:29:32 +04:00
|
|
|
* will either sleep until it is (wait case). Or it selects the current context
|
2018-06-15 11:07:12 +03:00
|
|
|
* for backing off by returning -EDEADLK (die case). Trying to acquire the
|
2013-07-05 11:29:32 +04:00
|
|
|
* same lock with the same context twice is also detected and signalled by
|
|
|
|
* returning -EALREADY. Returns 0 if the mutex was successfully acquired.
|
|
|
|
*
|
2018-06-15 11:07:12 +03:00
|
|
|
* In the die case the caller must release all currently held w/w mutexes for
|
2013-07-05 11:29:32 +04:00
|
|
|
* the given context and then wait for this contending lock to be available by
|
|
|
|
* calling ww_mutex_lock_slow. Alternatively callers can opt to not acquire this
|
|
|
|
* lock and proceed with trying to acquire further w/w mutexes (e.g. when
|
|
|
|
* scanning through lru lists trying to free resources).
|
|
|
|
*
|
|
|
|
* The mutex must later on be released by the same task that
|
|
|
|
* acquired it. The task may not exit without first unlocking the mutex. Also,
|
|
|
|
* kernel memory where the mutex resides must not be freed with the mutex still
|
|
|
|
* locked. The mutex must first be initialized (or statically defined) before it
|
|
|
|
* can be locked. memset()-ing the mutex to 0 is not allowed. The mutex must be
|
|
|
|
* of the same w/w lock class as was used to initialize the acquire context.
|
|
|
|
*
|
|
|
|
* A mutex acquired with this function must be released with ww_mutex_unlock.
|
|
|
|
*/
|
locking/ww_mutex: Turn off __must_check for now
With the ww_mutex inline wrappers gone there's a lot of dormant
anti-patterns emerging in an x86 allyesconfig build:
kernel/locking/test-ww_mutex.c:80:2: warning: ignoring return value of ‘ww_mutex_lock’, declared with attribute warn_unused_result [-Wunused-result]
kernel/locking/test-ww_mutex.c:55:3: warning: ignoring return value of ‘ww_mutex_lock’, declared with attribute warn_unused_result [-Wunused-result]
kernel/locking/test-ww_mutex.c:134:2: warning: ignoring return value of ‘ww_mutex_lock’, declared with attribute warn_unused_result [-Wunused-result]
kernel/locking/test-ww_mutex.c:213:2: warning: ignoring return value of ‘ww_mutex_lock’, declared with attribute warn_unused_result [-Wunused-result]
kernel/locking/test-ww_mutex.c:177:2: warning: ignoring return value of ‘ww_mutex_lock’, declared with attribute warn_unused_result [-Wunused-result]
kernel/locking/test-ww_mutex.c:266:2: warning: ignoring return value of ‘ww_mutex_lock’, declared with attribute warn_unused_result [-Wunused-result]
lib/locking-selftest.c:213:19: warning: ignoring return value of ‘ww_mutex_lock’, declared with attribute warn_unused_result [-Wunused-result]
lib/locking-selftest.c:213:19: warning: ignoring return value of ‘ww_mutex_lock’, declared with attribute warn_unused_result [-Wunused-result]
lib/locking-selftest.c:213:19: warning: ignoring return value of ‘ww_mutex_lock’, declared with attribute warn_unused_result [-Wunused-result]
lib/locking-selftest.c:213:19: warning: ignoring return value of ‘ww_mutex_lock’, declared with attribute warn_unused_result [-Wunused-result]
lib/locking-selftest.c:213:19: warning: ignoring return value of ‘ww_mutex_lock’, declared with attribute warn_unused_result [-Wunused-result]
lib/locking-selftest.c:213:19: warning: ignoring return value of ‘ww_mutex_lock’, declared with attribute warn_unused_result [-Wunused-result]
lib/locking-selftest.c:213:19: warning: ignoring return value of ‘ww_mutex_lock’, declared with attribute warn_unused_result [-Wunused-result]
lib/locking-selftest.c:213:19: warning: ignoring return value of ‘ww_mutex_lock’, declared with attribute warn_unused_result [-Wunused-result]
lib/locking-selftest.c:211:20: warning: ignoring return value of ‘ww_mutex_lock’, declared with attribute warn_unused_result [-Wunused-result]
lib/locking-selftest.c:211:20: warning: ignoring return value of ‘ww_mutex_lock’, declared with attribute warn_unused_result [-Wunused-result]
lib/locking-selftest.c:211:20: warning: ignoring return value of ‘ww_mutex_lock’, declared with attribute warn_unused_result [-Wunused-result]
lib/locking-selftest.c:211:20: warning: ignoring return value of ‘ww_mutex_lock’, declared with attribute warn_unused_result [-Wunused-result]
lib/locking-selftest.c:213:19: warning: ignoring return value of ‘ww_mutex_lock’, declared with attribute warn_unused_result [-Wunused-result]
lib/locking-selftest.c:211:20: warning: ignoring return value of ‘ww_mutex_lock’, declared with attribute warn_unused_result [-Wunused-result]
lib/locking-selftest.c:211:20: warning: ignoring return value of ‘ww_mutex_lock’, declared with attribute warn_unused_result [-Wunused-result]
lib/locking-selftest.c:211:20: warning: ignoring return value of ‘ww_mutex_lock’, declared with attribute warn_unused_result [-Wunused-result]
drivers/gpu/drm/drm_modeset_lock.c:430:2: warning: ignoring return value of ‘ww_mutex_lock’, declared with attribute warn_unused_result [-Wunused-result]
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c:70:2: warning: ignoring return value of ‘ww_mutex_lock’, declared with attribute warn_unused_result [-Wunused-result]
drivers/gpu/drm/vgem/vgem_fence.c:193:2: warning: ignoring return value of ‘ww_mutex_lock’, declared with attribute warn_unused_result [-Wunused-result]
drivers/gpu/drm/i915/i915_gem_batch_pool.c:125:4: warning: ignoring return value of ‘ww_mutex_lock’, declared with attribute warn_unused_result [-Wunused-result]
drivers/gpu/drm/i915/i915_gem_execbuffer.c:1302:2: warning: ignoring return value of ‘ww_mutex_lock’, declared with attribute warn_unused_result [-Wunused-result]
drivers/gpu/drm/radeon/radeon_prime.c:69:2: warning: ignoring return value of ‘ww_mutex_lock’, declared with attribute warn_unused_result [-Wunused-result]
drivers/gpu/drm/nouveau/nouveau_prime.c:70:2: warning: ignoring return value of ‘ww_mutex_lock’, declared with attribute warn_unused_result [-Wunused-result]
... but we cannot just litter the kernel build log with such warnings.
These need to be fixed separately - turn off the warning for now.
Cc: Nicolai Hähnle <nicolai.haehnle@amd.com>
Cc: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Maarten Lankhorst <dev@mblankhorst.nl>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2017-01-14 14:11:59 +03:00
|
|
|
extern int /* __must_check */ ww_mutex_lock(struct ww_mutex *lock, struct ww_acquire_ctx *ctx);
|
2013-07-05 11:29:32 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ww_mutex_lock_interruptible - acquire the w/w mutex, interruptible
|
|
|
|
* @lock: the mutex to be acquired
|
|
|
|
* @ctx: w/w acquire context
|
|
|
|
*
|
|
|
|
* Lock the w/w mutex exclusively for this task.
|
|
|
|
*
|
|
|
|
* Deadlocks within a given w/w class of locks are detected and handled with the
|
2018-06-15 11:07:12 +03:00
|
|
|
* wait/die algorithm. If the lock isn't immediately available this function
|
2013-07-05 11:29:32 +04:00
|
|
|
* will either sleep until it is (wait case). Or it selects the current context
|
2018-06-15 11:07:12 +03:00
|
|
|
* for backing off by returning -EDEADLK (die case). Trying to acquire the
|
2013-07-05 11:29:32 +04:00
|
|
|
* same lock with the same context twice is also detected and signalled by
|
|
|
|
* returning -EALREADY. Returns 0 if the mutex was successfully acquired. If a
|
|
|
|
* signal arrives while waiting for the lock then this function returns -EINTR.
|
|
|
|
*
|
2018-06-15 11:07:12 +03:00
|
|
|
* In the die case the caller must release all currently held w/w mutexes for
|
2013-07-05 11:29:32 +04:00
|
|
|
* the given context and then wait for this contending lock to be available by
|
|
|
|
* calling ww_mutex_lock_slow_interruptible. Alternatively callers can opt to
|
|
|
|
* not acquire this lock and proceed with trying to acquire further w/w mutexes
|
|
|
|
* (e.g. when scanning through lru lists trying to free resources).
|
|
|
|
*
|
|
|
|
* The mutex must later on be released by the same task that
|
|
|
|
* acquired it. The task may not exit without first unlocking the mutex. Also,
|
|
|
|
* kernel memory where the mutex resides must not be freed with the mutex still
|
|
|
|
* locked. The mutex must first be initialized (or statically defined) before it
|
|
|
|
* can be locked. memset()-ing the mutex to 0 is not allowed. The mutex must be
|
|
|
|
* of the same w/w lock class as was used to initialize the acquire context.
|
|
|
|
*
|
|
|
|
* A mutex acquired with this function must be released with ww_mutex_unlock.
|
|
|
|
*/
|
2016-12-21 21:46:33 +03:00
|
|
|
extern int __must_check ww_mutex_lock_interruptible(struct ww_mutex *lock,
|
|
|
|
struct ww_acquire_ctx *ctx);
|
2013-07-05 11:29:32 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ww_mutex_lock_slow - slowpath acquiring of the w/w mutex
|
|
|
|
* @lock: the mutex to be acquired
|
|
|
|
* @ctx: w/w acquire context
|
|
|
|
*
|
2018-06-15 11:07:12 +03:00
|
|
|
* Acquires a w/w mutex with the given context after a die case. This function
|
2013-07-05 11:29:32 +04:00
|
|
|
* will sleep until the lock becomes available.
|
|
|
|
*
|
|
|
|
* The caller must have released all w/w mutexes already acquired with the
|
|
|
|
* context and then call this function on the contended lock.
|
|
|
|
*
|
|
|
|
* Afterwards the caller may continue to (re)acquire the other w/w mutexes it
|
|
|
|
* needs with ww_mutex_lock. Note that the -EALREADY return code from
|
|
|
|
* ww_mutex_lock can be used to avoid locking this contended mutex twice.
|
|
|
|
*
|
|
|
|
* It is forbidden to call this function with any other w/w mutexes associated
|
|
|
|
* with the context held. It is forbidden to call this on anything else than the
|
|
|
|
* contending mutex.
|
|
|
|
*
|
|
|
|
* Note that the slowpath lock acquiring can also be done by calling
|
|
|
|
* ww_mutex_lock directly. This function here is simply to help w/w mutex
|
|
|
|
* locking code readability by clearly denoting the slowpath.
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
ww_mutex_lock_slow(struct ww_mutex *lock, struct ww_acquire_ctx *ctx)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
#ifdef CONFIG_DEBUG_MUTEXES
|
|
|
|
DEBUG_LOCKS_WARN_ON(!ctx->contending_lock);
|
|
|
|
#endif
|
|
|
|
ret = ww_mutex_lock(lock, ctx);
|
|
|
|
(void)ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ww_mutex_lock_slow_interruptible - slowpath acquiring of the w/w mutex, interruptible
|
|
|
|
* @lock: the mutex to be acquired
|
|
|
|
* @ctx: w/w acquire context
|
|
|
|
*
|
2018-06-15 11:07:12 +03:00
|
|
|
* Acquires a w/w mutex with the given context after a die case. This function
|
2013-07-05 11:29:32 +04:00
|
|
|
* will sleep until the lock becomes available and returns 0 when the lock has
|
|
|
|
* been acquired. If a signal arrives while waiting for the lock then this
|
|
|
|
* function returns -EINTR.
|
|
|
|
*
|
|
|
|
* The caller must have released all w/w mutexes already acquired with the
|
|
|
|
* context and then call this function on the contended lock.
|
|
|
|
*
|
|
|
|
* Afterwards the caller may continue to (re)acquire the other w/w mutexes it
|
|
|
|
* needs with ww_mutex_lock. Note that the -EALREADY return code from
|
|
|
|
* ww_mutex_lock can be used to avoid locking this contended mutex twice.
|
|
|
|
*
|
|
|
|
* It is forbidden to call this function with any other w/w mutexes associated
|
|
|
|
* with the given context held. It is forbidden to call this on anything else
|
|
|
|
* than the contending mutex.
|
|
|
|
*
|
|
|
|
* Note that the slowpath lock acquiring can also be done by calling
|
|
|
|
* ww_mutex_lock_interruptible directly. This function here is simply to help
|
|
|
|
* w/w mutex locking code readability by clearly denoting the slowpath.
|
|
|
|
*/
|
|
|
|
static inline int __must_check
|
|
|
|
ww_mutex_lock_slow_interruptible(struct ww_mutex *lock,
|
|
|
|
struct ww_acquire_ctx *ctx)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_DEBUG_MUTEXES
|
|
|
|
DEBUG_LOCKS_WARN_ON(!ctx->contending_lock);
|
|
|
|
#endif
|
|
|
|
return ww_mutex_lock_interruptible(lock, ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern void ww_mutex_unlock(struct ww_mutex *lock);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ww_mutex_trylock - tries to acquire the w/w mutex without acquire context
|
|
|
|
* @lock: mutex to lock
|
|
|
|
*
|
|
|
|
* Trylocks a mutex without acquire context, so no deadlock detection is
|
|
|
|
* possible. Returns 1 if the mutex has been acquired successfully, 0 otherwise.
|
|
|
|
*/
|
|
|
|
static inline int __must_check ww_mutex_trylock(struct ww_mutex *lock)
|
|
|
|
{
|
|
|
|
return mutex_trylock(&lock->base);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
* ww_mutex_destroy - mark a w/w mutex unusable
|
|
|
|
* @lock: the mutex to be destroyed
|
|
|
|
*
|
|
|
|
* This function marks the mutex uninitialized, and any subsequent
|
|
|
|
* use of the mutex is forbidden. The mutex must not be locked when
|
|
|
|
* this function is called.
|
|
|
|
*/
|
|
|
|
static inline void ww_mutex_destroy(struct ww_mutex *lock)
|
|
|
|
{
|
|
|
|
mutex_destroy(&lock->base);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ww_mutex_is_locked - is the w/w mutex locked
|
|
|
|
* @lock: the mutex to be queried
|
|
|
|
*
|
|
|
|
* Returns 1 if the mutex is locked, 0 if unlocked.
|
|
|
|
*/
|
|
|
|
static inline bool ww_mutex_is_locked(struct ww_mutex *lock)
|
|
|
|
{
|
|
|
|
return mutex_is_locked(&lock->base);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|