mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-04 17:44:14 +08:00
b24413180f
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>
388 lines
8.6 KiB
C
388 lines
8.6 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <time.h>
|
|
#include <assert.h>
|
|
#include <limits.h>
|
|
|
|
#include <linux/slab.h>
|
|
#include <linux/radix-tree.h>
|
|
|
|
#include "test.h"
|
|
#include "regression.h"
|
|
|
|
void __gang_check(unsigned long middle, long down, long up, int chunk, int hop)
|
|
{
|
|
long idx;
|
|
RADIX_TREE(tree, GFP_KERNEL);
|
|
|
|
middle = 1 << 30;
|
|
|
|
for (idx = -down; idx < up; idx++)
|
|
item_insert(&tree, middle + idx);
|
|
|
|
item_check_absent(&tree, middle - down - 1);
|
|
for (idx = -down; idx < up; idx++)
|
|
item_check_present(&tree, middle + idx);
|
|
item_check_absent(&tree, middle + up);
|
|
|
|
item_gang_check_present(&tree, middle - down,
|
|
up + down, chunk, hop);
|
|
item_full_scan(&tree, middle - down, down + up, chunk);
|
|
item_kill_tree(&tree);
|
|
}
|
|
|
|
void gang_check(void)
|
|
{
|
|
__gang_check(1 << 30, 128, 128, 35, 2);
|
|
__gang_check(1 << 31, 128, 128, 32, 32);
|
|
__gang_check(1 << 31, 128, 128, 32, 100);
|
|
__gang_check(1 << 31, 128, 128, 17, 7);
|
|
__gang_check(0xffff0000, 0, 65536, 17, 7);
|
|
__gang_check(0xfffffffe, 1, 1, 17, 7);
|
|
}
|
|
|
|
void __big_gang_check(void)
|
|
{
|
|
unsigned long start;
|
|
int wrapped = 0;
|
|
|
|
start = 0;
|
|
do {
|
|
unsigned long old_start;
|
|
|
|
// printf("0x%08lx\n", start);
|
|
__gang_check(start, rand() % 113 + 1, rand() % 71,
|
|
rand() % 157, rand() % 91 + 1);
|
|
old_start = start;
|
|
start += rand() % 1000000;
|
|
start %= 1ULL << 33;
|
|
if (start < old_start)
|
|
wrapped = 1;
|
|
} while (!wrapped);
|
|
}
|
|
|
|
void big_gang_check(bool long_run)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < (long_run ? 1000 : 3); i++) {
|
|
__big_gang_check();
|
|
printv(2, "%d ", i);
|
|
fflush(stdout);
|
|
}
|
|
}
|
|
|
|
void add_and_check(void)
|
|
{
|
|
RADIX_TREE(tree, GFP_KERNEL);
|
|
|
|
item_insert(&tree, 44);
|
|
item_check_present(&tree, 44);
|
|
item_check_absent(&tree, 43);
|
|
item_kill_tree(&tree);
|
|
}
|
|
|
|
void dynamic_height_check(void)
|
|
{
|
|
int i;
|
|
RADIX_TREE(tree, GFP_KERNEL);
|
|
tree_verify_min_height(&tree, 0);
|
|
|
|
item_insert(&tree, 42);
|
|
tree_verify_min_height(&tree, 42);
|
|
|
|
item_insert(&tree, 1000000);
|
|
tree_verify_min_height(&tree, 1000000);
|
|
|
|
assert(item_delete(&tree, 1000000));
|
|
tree_verify_min_height(&tree, 42);
|
|
|
|
assert(item_delete(&tree, 42));
|
|
tree_verify_min_height(&tree, 0);
|
|
|
|
for (i = 0; i < 1000; i++) {
|
|
item_insert(&tree, i);
|
|
tree_verify_min_height(&tree, i);
|
|
}
|
|
|
|
i--;
|
|
for (;;) {
|
|
assert(item_delete(&tree, i));
|
|
if (i == 0) {
|
|
tree_verify_min_height(&tree, 0);
|
|
break;
|
|
}
|
|
i--;
|
|
tree_verify_min_height(&tree, i);
|
|
}
|
|
|
|
item_kill_tree(&tree);
|
|
}
|
|
|
|
void check_copied_tags(struct radix_tree_root *tree, unsigned long start, unsigned long end, unsigned long *idx, int count, int fromtag, int totag)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < count; i++) {
|
|
/* if (i % 1000 == 0)
|
|
putchar('.'); */
|
|
if (idx[i] < start || idx[i] > end) {
|
|
if (item_tag_get(tree, idx[i], totag)) {
|
|
printv(2, "%lu-%lu: %lu, tags %d-%d\n", start,
|
|
end, idx[i], item_tag_get(tree, idx[i],
|
|
fromtag),
|
|
item_tag_get(tree, idx[i], totag));
|
|
}
|
|
assert(!item_tag_get(tree, idx[i], totag));
|
|
continue;
|
|
}
|
|
if (item_tag_get(tree, idx[i], fromtag) ^
|
|
item_tag_get(tree, idx[i], totag)) {
|
|
printv(2, "%lu-%lu: %lu, tags %d-%d\n", start, end,
|
|
idx[i], item_tag_get(tree, idx[i], fromtag),
|
|
item_tag_get(tree, idx[i], totag));
|
|
}
|
|
assert(!(item_tag_get(tree, idx[i], fromtag) ^
|
|
item_tag_get(tree, idx[i], totag)));
|
|
}
|
|
}
|
|
|
|
#define ITEMS 50000
|
|
|
|
void copy_tag_check(void)
|
|
{
|
|
RADIX_TREE(tree, GFP_KERNEL);
|
|
unsigned long idx[ITEMS];
|
|
unsigned long start, end, count = 0, tagged, cur, tmp;
|
|
int i;
|
|
|
|
// printf("generating radix tree indices...\n");
|
|
start = rand();
|
|
end = rand();
|
|
if (start > end && (rand() % 10)) {
|
|
cur = start;
|
|
start = end;
|
|
end = cur;
|
|
}
|
|
/* Specifically create items around the start and the end of the range
|
|
* with high probability to check for off by one errors */
|
|
cur = rand();
|
|
if (cur & 1) {
|
|
item_insert(&tree, start);
|
|
if (cur & 2) {
|
|
if (start <= end)
|
|
count++;
|
|
item_tag_set(&tree, start, 0);
|
|
}
|
|
}
|
|
if (cur & 4) {
|
|
item_insert(&tree, start-1);
|
|
if (cur & 8)
|
|
item_tag_set(&tree, start-1, 0);
|
|
}
|
|
if (cur & 16) {
|
|
item_insert(&tree, end);
|
|
if (cur & 32) {
|
|
if (start <= end)
|
|
count++;
|
|
item_tag_set(&tree, end, 0);
|
|
}
|
|
}
|
|
if (cur & 64) {
|
|
item_insert(&tree, end+1);
|
|
if (cur & 128)
|
|
item_tag_set(&tree, end+1, 0);
|
|
}
|
|
|
|
for (i = 0; i < ITEMS; i++) {
|
|
do {
|
|
idx[i] = rand();
|
|
} while (item_lookup(&tree, idx[i]));
|
|
|
|
item_insert(&tree, idx[i]);
|
|
if (rand() & 1) {
|
|
item_tag_set(&tree, idx[i], 0);
|
|
if (idx[i] >= start && idx[i] <= end)
|
|
count++;
|
|
}
|
|
/* if (i % 1000 == 0)
|
|
putchar('.'); */
|
|
}
|
|
|
|
// printf("\ncopying tags...\n");
|
|
tagged = tag_tagged_items(&tree, NULL, start, end, ITEMS, 0, 1);
|
|
|
|
// printf("checking copied tags\n");
|
|
assert(tagged == count);
|
|
check_copied_tags(&tree, start, end, idx, ITEMS, 0, 1);
|
|
|
|
/* Copy tags in several rounds */
|
|
// printf("\ncopying tags...\n");
|
|
tmp = rand() % (count / 10 + 2);
|
|
tagged = tag_tagged_items(&tree, NULL, start, end, tmp, 0, 2);
|
|
assert(tagged == count);
|
|
|
|
// printf("%lu %lu %lu\n", tagged, tmp, count);
|
|
// printf("checking copied tags\n");
|
|
check_copied_tags(&tree, start, end, idx, ITEMS, 0, 2);
|
|
verify_tag_consistency(&tree, 0);
|
|
verify_tag_consistency(&tree, 1);
|
|
verify_tag_consistency(&tree, 2);
|
|
// printf("\n");
|
|
item_kill_tree(&tree);
|
|
}
|
|
|
|
static void __locate_check(struct radix_tree_root *tree, unsigned long index,
|
|
unsigned order)
|
|
{
|
|
struct item *item;
|
|
unsigned long index2;
|
|
|
|
item_insert_order(tree, index, order);
|
|
item = item_lookup(tree, index);
|
|
index2 = find_item(tree, item);
|
|
if (index != index2) {
|
|
printv(2, "index %ld order %d inserted; found %ld\n",
|
|
index, order, index2);
|
|
abort();
|
|
}
|
|
}
|
|
|
|
static void __order_0_locate_check(void)
|
|
{
|
|
RADIX_TREE(tree, GFP_KERNEL);
|
|
int i;
|
|
|
|
for (i = 0; i < 50; i++)
|
|
__locate_check(&tree, rand() % INT_MAX, 0);
|
|
|
|
item_kill_tree(&tree);
|
|
}
|
|
|
|
static void locate_check(void)
|
|
{
|
|
RADIX_TREE(tree, GFP_KERNEL);
|
|
unsigned order;
|
|
unsigned long offset, index;
|
|
|
|
__order_0_locate_check();
|
|
|
|
for (order = 0; order < 20; order++) {
|
|
for (offset = 0; offset < (1 << (order + 3));
|
|
offset += (1UL << order)) {
|
|
for (index = 0; index < (1UL << (order + 5));
|
|
index += (1UL << order)) {
|
|
__locate_check(&tree, index + offset, order);
|
|
}
|
|
if (find_item(&tree, &tree) != -1)
|
|
abort();
|
|
|
|
item_kill_tree(&tree);
|
|
}
|
|
}
|
|
|
|
if (find_item(&tree, &tree) != -1)
|
|
abort();
|
|
__locate_check(&tree, -1, 0);
|
|
if (find_item(&tree, &tree) != -1)
|
|
abort();
|
|
item_kill_tree(&tree);
|
|
}
|
|
|
|
static void single_thread_tests(bool long_run)
|
|
{
|
|
int i;
|
|
|
|
printv(1, "starting single_thread_tests: %d allocated, preempt %d\n",
|
|
nr_allocated, preempt_count);
|
|
multiorder_checks();
|
|
rcu_barrier();
|
|
printv(2, "after multiorder_check: %d allocated, preempt %d\n",
|
|
nr_allocated, preempt_count);
|
|
locate_check();
|
|
rcu_barrier();
|
|
printv(2, "after locate_check: %d allocated, preempt %d\n",
|
|
nr_allocated, preempt_count);
|
|
tag_check();
|
|
rcu_barrier();
|
|
printv(2, "after tag_check: %d allocated, preempt %d\n",
|
|
nr_allocated, preempt_count);
|
|
gang_check();
|
|
rcu_barrier();
|
|
printv(2, "after gang_check: %d allocated, preempt %d\n",
|
|
nr_allocated, preempt_count);
|
|
add_and_check();
|
|
rcu_barrier();
|
|
printv(2, "after add_and_check: %d allocated, preempt %d\n",
|
|
nr_allocated, preempt_count);
|
|
dynamic_height_check();
|
|
rcu_barrier();
|
|
printv(2, "after dynamic_height_check: %d allocated, preempt %d\n",
|
|
nr_allocated, preempt_count);
|
|
idr_checks();
|
|
ida_checks();
|
|
rcu_barrier();
|
|
printv(2, "after idr_checks: %d allocated, preempt %d\n",
|
|
nr_allocated, preempt_count);
|
|
big_gang_check(long_run);
|
|
rcu_barrier();
|
|
printv(2, "after big_gang_check: %d allocated, preempt %d\n",
|
|
nr_allocated, preempt_count);
|
|
for (i = 0; i < (long_run ? 2000 : 3); i++) {
|
|
copy_tag_check();
|
|
printv(2, "%d ", i);
|
|
fflush(stdout);
|
|
}
|
|
rcu_barrier();
|
|
printv(2, "after copy_tag_check: %d allocated, preempt %d\n",
|
|
nr_allocated, preempt_count);
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
bool long_run = false;
|
|
int opt;
|
|
unsigned int seed = time(NULL);
|
|
|
|
while ((opt = getopt(argc, argv, "ls:v")) != -1) {
|
|
if (opt == 'l')
|
|
long_run = true;
|
|
else if (opt == 's')
|
|
seed = strtoul(optarg, NULL, 0);
|
|
else if (opt == 'v')
|
|
test_verbose++;
|
|
}
|
|
|
|
printf("random seed %u\n", seed);
|
|
srand(seed);
|
|
|
|
printf("running tests\n");
|
|
|
|
rcu_register_thread();
|
|
radix_tree_init();
|
|
|
|
regression1_test();
|
|
regression2_test();
|
|
regression3_test();
|
|
iteration_test(0, 10 + 90 * long_run);
|
|
iteration_test(7, 10 + 90 * long_run);
|
|
single_thread_tests(long_run);
|
|
ida_thread_tests();
|
|
|
|
/* Free any remaining preallocated nodes */
|
|
radix_tree_cpu_dead(0);
|
|
|
|
benchmark();
|
|
|
|
rcu_barrier();
|
|
printv(2, "after rcu_barrier: %d allocated, preempt %d\n",
|
|
nr_allocated, preempt_count);
|
|
rcu_unregister_thread();
|
|
|
|
printf("tests completed\n");
|
|
|
|
exit(0);
|
|
}
|