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 */
|
blockdev: turn a rw semaphore into a percpu rw semaphore
This avoids cache line bouncing when many processes lock the semaphore
for read.
New percpu lock implementation
The lock consists of an array of percpu unsigned integers, a boolean
variable and a mutex.
When we take the lock for read, we enter rcu read section, check for a
"locked" variable. If it is false, we increase a percpu counter on the
current cpu and exit the rcu section. If "locked" is true, we exit the
rcu section, take the mutex and drop it (this waits until a writer
finished) and retry.
Unlocking for read just decreases percpu variable. Note that we can
unlock on a difference cpu than where we locked, in this case the
counter underflows. The sum of all percpu counters represents the number
of processes that hold the lock for read.
When we need to lock for write, we take the mutex, set "locked" variable
to true and synchronize rcu. Since RCU has been synchronized, no
processes can create new read locks. We wait until the sum of percpu
counters is zero - when it is, there are no readers in the critical
section.
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2012-09-26 13:46:43 +08:00
|
|
|
#ifndef _LINUX_PERCPU_RWSEM_H
|
|
|
|
#define _LINUX_PERCPU_RWSEM_H
|
|
|
|
|
2012-12-18 08:01:36 +08:00
|
|
|
#include <linux/atomic.h>
|
2012-12-18 08:01:32 +08:00
|
|
|
#include <linux/rwsem.h>
|
blockdev: turn a rw semaphore into a percpu rw semaphore
This avoids cache line bouncing when many processes lock the semaphore
for read.
New percpu lock implementation
The lock consists of an array of percpu unsigned integers, a boolean
variable and a mutex.
When we take the lock for read, we enter rcu read section, check for a
"locked" variable. If it is false, we increase a percpu counter on the
current cpu and exit the rcu section. If "locked" is true, we exit the
rcu section, take the mutex and drop it (this waits until a writer
finished) and retry.
Unlocking for read just decreases percpu variable. Note that we can
unlock on a difference cpu than where we locked, in this case the
counter underflows. The sum of all percpu counters represents the number
of processes that hold the lock for read.
When we need to lock for write, we take the mutex, set "locked" variable
to true and synchronize rcu. Since RCU has been synchronized, no
processes can create new read locks. We wait until the sum of percpu
counters is zero - when it is, there are no readers in the critical
section.
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2012-09-26 13:46:43 +08:00
|
|
|
#include <linux/percpu.h>
|
2017-01-11 23:22:26 +08:00
|
|
|
#include <linux/rcuwait.h>
|
2015-08-22 01:42:57 +08:00
|
|
|
#include <linux/rcu_sync.h>
|
2012-12-18 08:01:38 +08:00
|
|
|
#include <linux/lockdep.h>
|
blockdev: turn a rw semaphore into a percpu rw semaphore
This avoids cache line bouncing when many processes lock the semaphore
for read.
New percpu lock implementation
The lock consists of an array of percpu unsigned integers, a boolean
variable and a mutex.
When we take the lock for read, we enter rcu read section, check for a
"locked" variable. If it is false, we increase a percpu counter on the
current cpu and exit the rcu section. If "locked" is true, we exit the
rcu section, take the mutex and drop it (this waits until a writer
finished) and retry.
Unlocking for read just decreases percpu variable. Note that we can
unlock on a difference cpu than where we locked, in this case the
counter underflows. The sum of all percpu counters represents the number
of processes that hold the lock for read.
When we need to lock for write, we take the mutex, set "locked" variable
to true and synchronize rcu. Since RCU has been synchronized, no
processes can create new read locks. We wait until the sum of percpu
counters is zero - when it is, there are no readers in the critical
section.
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2012-09-26 13:46:43 +08:00
|
|
|
|
|
|
|
struct percpu_rw_semaphore {
|
2015-08-22 01:42:57 +08:00
|
|
|
struct rcu_sync rss;
|
2016-07-15 02:08:46 +08:00
|
|
|
unsigned int __percpu *read_count;
|
2017-01-11 23:22:26 +08:00
|
|
|
struct rw_semaphore rw_sem; /* slowpath */
|
|
|
|
struct rcuwait writer; /* blocked writer */
|
2016-07-15 02:08:46 +08:00
|
|
|
int readers_block;
|
blockdev: turn a rw semaphore into a percpu rw semaphore
This avoids cache line bouncing when many processes lock the semaphore
for read.
New percpu lock implementation
The lock consists of an array of percpu unsigned integers, a boolean
variable and a mutex.
When we take the lock for read, we enter rcu read section, check for a
"locked" variable. If it is false, we increase a percpu counter on the
current cpu and exit the rcu section. If "locked" is true, we exit the
rcu section, take the mutex and drop it (this waits until a writer
finished) and retry.
Unlocking for read just decreases percpu variable. Note that we can
unlock on a difference cpu than where we locked, in this case the
counter underflows. The sum of all percpu counters represents the number
of processes that hold the lock for read.
When we need to lock for write, we take the mutex, set "locked" variable
to true and synchronize rcu. Since RCU has been synchronized, no
processes can create new read locks. We wait until the sum of percpu
counters is zero - when it is, there are no readers in the critical
section.
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2012-09-26 13:46:43 +08:00
|
|
|
};
|
|
|
|
|
2019-04-24 00:32:41 +08:00
|
|
|
#define __DEFINE_PERCPU_RWSEM(name, is_static) \
|
2015-06-22 20:16:31 +08:00
|
|
|
static DEFINE_PER_CPU(unsigned int, __percpu_rwsem_rc_##name); \
|
2019-04-24 00:32:41 +08:00
|
|
|
is_static struct percpu_rw_semaphore name = { \
|
2019-04-23 20:07:24 +08:00
|
|
|
.rss = __RCU_SYNC_INITIALIZER(name.rss), \
|
2015-06-22 20:16:31 +08:00
|
|
|
.read_count = &__percpu_rwsem_rc_##name, \
|
|
|
|
.rw_sem = __RWSEM_INITIALIZER(name.rw_sem), \
|
2017-01-11 23:22:26 +08:00
|
|
|
.writer = __RCUWAIT_INITIALIZER(name.writer), \
|
2015-06-22 20:16:31 +08:00
|
|
|
}
|
2019-04-24 00:32:41 +08:00
|
|
|
#define DEFINE_PERCPU_RWSEM(name) \
|
|
|
|
__DEFINE_PERCPU_RWSEM(name, /* not static */)
|
|
|
|
#define DEFINE_STATIC_PERCPU_RWSEM(name) \
|
|
|
|
__DEFINE_PERCPU_RWSEM(name, static)
|
2015-06-22 20:16:31 +08:00
|
|
|
|
2016-07-15 02:08:46 +08:00
|
|
|
extern int __percpu_down_read(struct percpu_rw_semaphore *, int);
|
|
|
|
extern void __percpu_up_read(struct percpu_rw_semaphore *);
|
|
|
|
|
2019-02-21 22:38:40 +08:00
|
|
|
static inline void percpu_down_read(struct percpu_rw_semaphore *sem)
|
2016-07-15 02:08:46 +08:00
|
|
|
{
|
|
|
|
might_sleep();
|
|
|
|
|
|
|
|
rwsem_acquire_read(&sem->rw_sem.dep_map, 0, 0, _RET_IP_);
|
|
|
|
|
|
|
|
preempt_disable();
|
|
|
|
/*
|
|
|
|
* We are in an RCU-sched read-side critical section, so the writer
|
|
|
|
* cannot both change sem->state from readers_fast and start checking
|
|
|
|
* counters while we are here. So if we see !sem->state, we know that
|
|
|
|
* the writer won't be checking until we're past the preempt_enable()
|
2018-11-08 05:53:34 +08:00
|
|
|
* and that once the synchronize_rcu() is done, the writer will see
|
2016-07-15 02:08:46 +08:00
|
|
|
* anything we did within this RCU-sched read-size critical section.
|
|
|
|
*/
|
2024-06-11 20:26:44 +08:00
|
|
|
this_cpu_inc(*sem->read_count);
|
2016-07-15 02:08:46 +08:00
|
|
|
if (unlikely(!rcu_sync_is_idle(&sem->rss)))
|
|
|
|
__percpu_down_read(sem, false); /* Unconditional memory barrier */
|
|
|
|
/*
|
2019-02-21 22:38:40 +08:00
|
|
|
* The preempt_enable() prevents the compiler from
|
2016-07-15 02:08:46 +08:00
|
|
|
* bleeding the critical section out.
|
|
|
|
*/
|
2015-11-23 22:23:55 +08:00
|
|
|
preempt_enable();
|
|
|
|
}
|
|
|
|
|
2016-07-15 02:08:46 +08:00
|
|
|
static inline int percpu_down_read_trylock(struct percpu_rw_semaphore *sem)
|
|
|
|
{
|
|
|
|
int ret = 1;
|
|
|
|
|
|
|
|
preempt_disable();
|
|
|
|
/*
|
|
|
|
* Same as in percpu_down_read().
|
|
|
|
*/
|
2024-06-11 20:26:44 +08:00
|
|
|
this_cpu_inc(*sem->read_count);
|
2016-07-15 02:08:46 +08:00
|
|
|
if (unlikely(!rcu_sync_is_idle(&sem->rss)))
|
|
|
|
ret = __percpu_down_read(sem, true); /* Unconditional memory barrier */
|
|
|
|
preempt_enable();
|
|
|
|
/*
|
|
|
|
* The barrier() from preempt_enable() prevents the compiler from
|
|
|
|
* bleeding the critical section out.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
rwsem_acquire_read(&sem->rw_sem.dep_map, 0, 1, _RET_IP_);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-02-21 22:38:40 +08:00
|
|
|
static inline void percpu_up_read(struct percpu_rw_semaphore *sem)
|
2016-07-15 02:08:46 +08:00
|
|
|
{
|
2019-02-21 22:38:40 +08:00
|
|
|
preempt_disable();
|
2016-07-15 02:08:46 +08:00
|
|
|
/*
|
|
|
|
* Same as in percpu_down_read().
|
|
|
|
*/
|
|
|
|
if (likely(rcu_sync_is_idle(&sem->rss)))
|
2024-06-11 20:26:44 +08:00
|
|
|
this_cpu_dec(*sem->read_count);
|
2016-07-15 02:08:46 +08:00
|
|
|
else
|
|
|
|
__percpu_up_read(sem); /* Unconditional memory barrier */
|
|
|
|
preempt_enable();
|
|
|
|
|
|
|
|
rwsem_release(&sem->rw_sem.dep_map, 1, _RET_IP_);
|
|
|
|
}
|
2012-10-23 07:37:47 +08:00
|
|
|
|
2012-12-18 08:01:32 +08:00
|
|
|
extern void percpu_down_write(struct percpu_rw_semaphore *);
|
|
|
|
extern void percpu_up_write(struct percpu_rw_semaphore *);
|
blockdev: turn a rw semaphore into a percpu rw semaphore
This avoids cache line bouncing when many processes lock the semaphore
for read.
New percpu lock implementation
The lock consists of an array of percpu unsigned integers, a boolean
variable and a mutex.
When we take the lock for read, we enter rcu read section, check for a
"locked" variable. If it is false, we increase a percpu counter on the
current cpu and exit the rcu section. If "locked" is true, we exit the
rcu section, take the mutex and drop it (this waits until a writer
finished) and retry.
Unlocking for read just decreases percpu variable. Note that we can
unlock on a difference cpu than where we locked, in this case the
counter underflows. The sum of all percpu counters represents the number
of processes that hold the lock for read.
When we need to lock for write, we take the mutex, set "locked" variable
to true and synchronize rcu. Since RCU has been synchronized, no
processes can create new read locks. We wait until the sum of percpu
counters is zero - when it is, there are no readers in the critical
section.
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2012-09-26 13:46:43 +08:00
|
|
|
|
2012-12-18 08:01:38 +08:00
|
|
|
extern int __percpu_init_rwsem(struct percpu_rw_semaphore *,
|
|
|
|
const char *, struct lock_class_key *);
|
2016-07-15 02:08:46 +08:00
|
|
|
|
2012-12-18 08:01:32 +08:00
|
|
|
extern void percpu_free_rwsem(struct percpu_rw_semaphore *);
|
blockdev: turn a rw semaphore into a percpu rw semaphore
This avoids cache line bouncing when many processes lock the semaphore
for read.
New percpu lock implementation
The lock consists of an array of percpu unsigned integers, a boolean
variable and a mutex.
When we take the lock for read, we enter rcu read section, check for a
"locked" variable. If it is false, we increase a percpu counter on the
current cpu and exit the rcu section. If "locked" is true, we exit the
rcu section, take the mutex and drop it (this waits until a writer
finished) and retry.
Unlocking for read just decreases percpu variable. Note that we can
unlock on a difference cpu than where we locked, in this case the
counter underflows. The sum of all percpu counters represents the number
of processes that hold the lock for read.
When we need to lock for write, we take the mutex, set "locked" variable
to true and synchronize rcu. Since RCU has been synchronized, no
processes can create new read locks. We wait until the sum of percpu
counters is zero - when it is, there are no readers in the critical
section.
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2012-09-26 13:46:43 +08:00
|
|
|
|
2016-07-15 02:08:46 +08:00
|
|
|
#define percpu_init_rwsem(sem) \
|
2012-12-18 08:01:38 +08:00
|
|
|
({ \
|
|
|
|
static struct lock_class_key rwsem_key; \
|
2016-07-15 02:08:46 +08:00
|
|
|
__percpu_init_rwsem(sem, #sem, &rwsem_key); \
|
2012-12-18 08:01:38 +08:00
|
|
|
})
|
|
|
|
|
2015-07-22 02:26:44 +08:00
|
|
|
#define percpu_rwsem_is_held(sem) lockdep_is_held(&(sem)->rw_sem)
|
|
|
|
|
2015-06-22 20:16:31 +08:00
|
|
|
#define percpu_rwsem_assert_held(sem) \
|
|
|
|
lockdep_assert_held(&(sem)->rw_sem)
|
|
|
|
|
2015-07-22 02:26:44 +08:00
|
|
|
static inline void percpu_rwsem_release(struct percpu_rw_semaphore *sem,
|
|
|
|
bool read, unsigned long ip)
|
|
|
|
{
|
|
|
|
lock_release(&sem->rw_sem.dep_map, 1, ip);
|
|
|
|
#ifdef CONFIG_RWSEM_SPIN_ON_OWNER
|
|
|
|
if (!read)
|
2019-05-21 04:59:12 +08:00
|
|
|
atomic_long_set(&sem->rw_sem.owner, RWSEM_OWNER_UNKNOWN);
|
2015-07-22 02:26:44 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void percpu_rwsem_acquire(struct percpu_rw_semaphore *sem,
|
|
|
|
bool read, unsigned long ip)
|
|
|
|
{
|
|
|
|
lock_acquire(&sem->rw_sem.dep_map, 0, 1, read, 1, NULL, ip);
|
2018-05-16 05:49:51 +08:00
|
|
|
#ifdef CONFIG_RWSEM_SPIN_ON_OWNER
|
|
|
|
if (!read)
|
2019-05-21 04:59:12 +08:00
|
|
|
atomic_long_set(&sem->rw_sem.owner, (long)current);
|
2018-05-16 05:49:51 +08:00
|
|
|
#endif
|
2015-07-22 02:26:44 +08:00
|
|
|
}
|
|
|
|
|
blockdev: turn a rw semaphore into a percpu rw semaphore
This avoids cache line bouncing when many processes lock the semaphore
for read.
New percpu lock implementation
The lock consists of an array of percpu unsigned integers, a boolean
variable and a mutex.
When we take the lock for read, we enter rcu read section, check for a
"locked" variable. If it is false, we increase a percpu counter on the
current cpu and exit the rcu section. If "locked" is true, we exit the
rcu section, take the mutex and drop it (this waits until a writer
finished) and retry.
Unlocking for read just decreases percpu variable. Note that we can
unlock on a difference cpu than where we locked, in this case the
counter underflows. The sum of all percpu counters represents the number
of processes that hold the lock for read.
When we need to lock for write, we take the mutex, set "locked" variable
to true and synchronize rcu. Since RCU has been synchronized, no
processes can create new read locks. We wait until the sum of percpu
counters is zero - when it is, there are no readers in the critical
section.
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2012-09-26 13:46:43 +08:00
|
|
|
#endif
|