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>
385 lines
8.2 KiB
C
385 lines
8.2 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <dirent.h>
|
|
#include <stdlib.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/types.h>
|
|
#include <sys/stat.h>
|
|
#include <fcntl.h>
|
|
#include <string.h>
|
|
#include <sys/time.h>
|
|
#include <sys/resource.h>
|
|
#include <api/fs/fs.h>
|
|
#include "util.h"
|
|
#include "machine.h"
|
|
#include "symbol.h"
|
|
#include "tests.h"
|
|
#include "debug.h"
|
|
|
|
static char *test_file(int size)
|
|
{
|
|
#define TEMPL "/tmp/perf-test-XXXXXX"
|
|
static char buf_templ[sizeof(TEMPL)];
|
|
char *templ = buf_templ;
|
|
int fd, i;
|
|
unsigned char *buf;
|
|
|
|
strcpy(buf_templ, TEMPL);
|
|
#undef TEMPL
|
|
|
|
fd = mkstemp(templ);
|
|
if (fd < 0) {
|
|
perror("mkstemp failed");
|
|
return NULL;
|
|
}
|
|
|
|
buf = malloc(size);
|
|
if (!buf) {
|
|
close(fd);
|
|
return NULL;
|
|
}
|
|
|
|
for (i = 0; i < size; i++)
|
|
buf[i] = (unsigned char) ((int) i % 10);
|
|
|
|
if (size != write(fd, buf, size))
|
|
templ = NULL;
|
|
|
|
free(buf);
|
|
close(fd);
|
|
return templ;
|
|
}
|
|
|
|
#define TEST_FILE_SIZE (DSO__DATA_CACHE_SIZE * 20)
|
|
|
|
struct test_data_offset {
|
|
off_t offset;
|
|
u8 data[10];
|
|
int size;
|
|
};
|
|
|
|
struct test_data_offset offsets[] = {
|
|
/* Fill first cache page. */
|
|
{
|
|
.offset = 10,
|
|
.data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
|
|
.size = 10,
|
|
},
|
|
/* Read first cache page. */
|
|
{
|
|
.offset = 10,
|
|
.data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
|
|
.size = 10,
|
|
},
|
|
/* Fill cache boundary pages. */
|
|
{
|
|
.offset = DSO__DATA_CACHE_SIZE - DSO__DATA_CACHE_SIZE % 10,
|
|
.data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
|
|
.size = 10,
|
|
},
|
|
/* Read cache boundary pages. */
|
|
{
|
|
.offset = DSO__DATA_CACHE_SIZE - DSO__DATA_CACHE_SIZE % 10,
|
|
.data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
|
|
.size = 10,
|
|
},
|
|
/* Fill final cache page. */
|
|
{
|
|
.offset = TEST_FILE_SIZE - 10,
|
|
.data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
|
|
.size = 10,
|
|
},
|
|
/* Read final cache page. */
|
|
{
|
|
.offset = TEST_FILE_SIZE - 10,
|
|
.data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
|
|
.size = 10,
|
|
},
|
|
/* Read final cache page. */
|
|
{
|
|
.offset = TEST_FILE_SIZE - 3,
|
|
.data = { 7, 8, 9, 0, 0, 0, 0, 0, 0, 0 },
|
|
.size = 3,
|
|
},
|
|
};
|
|
|
|
/* move it from util/dso.c for compatibility */
|
|
static int dso__data_fd(struct dso *dso, struct machine *machine)
|
|
{
|
|
int fd = dso__data_get_fd(dso, machine);
|
|
|
|
if (fd >= 0)
|
|
dso__data_put_fd(dso);
|
|
|
|
return fd;
|
|
}
|
|
|
|
int test__dso_data(struct test *test __maybe_unused, int subtest __maybe_unused)
|
|
{
|
|
struct machine machine;
|
|
struct dso *dso;
|
|
char *file = test_file(TEST_FILE_SIZE);
|
|
size_t i;
|
|
|
|
TEST_ASSERT_VAL("No test file", file);
|
|
|
|
memset(&machine, 0, sizeof(machine));
|
|
|
|
dso = dso__new((const char *)file);
|
|
|
|
TEST_ASSERT_VAL("Failed to access to dso",
|
|
dso__data_fd(dso, &machine) >= 0);
|
|
|
|
/* Basic 10 bytes tests. */
|
|
for (i = 0; i < ARRAY_SIZE(offsets); i++) {
|
|
struct test_data_offset *data = &offsets[i];
|
|
ssize_t size;
|
|
u8 buf[10];
|
|
|
|
memset(buf, 0, 10);
|
|
size = dso__data_read_offset(dso, &machine, data->offset,
|
|
buf, 10);
|
|
|
|
TEST_ASSERT_VAL("Wrong size", size == data->size);
|
|
TEST_ASSERT_VAL("Wrong data", !memcmp(buf, data->data, 10));
|
|
}
|
|
|
|
/* Read cross multiple cache pages. */
|
|
{
|
|
ssize_t size;
|
|
int c;
|
|
u8 *buf;
|
|
|
|
buf = malloc(TEST_FILE_SIZE);
|
|
TEST_ASSERT_VAL("ENOMEM\n", buf);
|
|
|
|
/* First iteration to fill caches, second one to read them. */
|
|
for (c = 0; c < 2; c++) {
|
|
memset(buf, 0, TEST_FILE_SIZE);
|
|
size = dso__data_read_offset(dso, &machine, 10,
|
|
buf, TEST_FILE_SIZE);
|
|
|
|
TEST_ASSERT_VAL("Wrong size",
|
|
size == (TEST_FILE_SIZE - 10));
|
|
|
|
for (i = 0; i < (size_t)size; i++)
|
|
TEST_ASSERT_VAL("Wrong data",
|
|
buf[i] == (i % 10));
|
|
}
|
|
|
|
free(buf);
|
|
}
|
|
|
|
dso__put(dso);
|
|
unlink(file);
|
|
return 0;
|
|
}
|
|
|
|
static long open_files_cnt(void)
|
|
{
|
|
char path[PATH_MAX];
|
|
struct dirent *dent;
|
|
DIR *dir;
|
|
long nr = 0;
|
|
|
|
scnprintf(path, PATH_MAX, "%s/self/fd", procfs__mountpoint());
|
|
pr_debug("fd path: %s\n", path);
|
|
|
|
dir = opendir(path);
|
|
TEST_ASSERT_VAL("failed to open fd directory", dir);
|
|
|
|
while ((dent = readdir(dir)) != NULL) {
|
|
if (!strcmp(dent->d_name, ".") ||
|
|
!strcmp(dent->d_name, ".."))
|
|
continue;
|
|
|
|
nr++;
|
|
}
|
|
|
|
closedir(dir);
|
|
return nr - 1;
|
|
}
|
|
|
|
static struct dso **dsos;
|
|
|
|
static int dsos__create(int cnt, int size)
|
|
{
|
|
int i;
|
|
|
|
dsos = malloc(sizeof(*dsos) * cnt);
|
|
TEST_ASSERT_VAL("failed to alloc dsos array", dsos);
|
|
|
|
for (i = 0; i < cnt; i++) {
|
|
char *file;
|
|
|
|
file = test_file(size);
|
|
TEST_ASSERT_VAL("failed to get dso file", file);
|
|
|
|
dsos[i] = dso__new(file);
|
|
TEST_ASSERT_VAL("failed to get dso", dsos[i]);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void dsos__delete(int cnt)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < cnt; i++) {
|
|
struct dso *dso = dsos[i];
|
|
|
|
unlink(dso->name);
|
|
dso__put(dso);
|
|
}
|
|
|
|
free(dsos);
|
|
}
|
|
|
|
static int set_fd_limit(int n)
|
|
{
|
|
struct rlimit rlim;
|
|
|
|
if (getrlimit(RLIMIT_NOFILE, &rlim))
|
|
return -1;
|
|
|
|
pr_debug("file limit %ld, new %d\n", (long) rlim.rlim_cur, n);
|
|
|
|
rlim.rlim_cur = n;
|
|
return setrlimit(RLIMIT_NOFILE, &rlim);
|
|
}
|
|
|
|
int test__dso_data_cache(struct test *test __maybe_unused, int subtest __maybe_unused)
|
|
{
|
|
struct machine machine;
|
|
long nr_end, nr = open_files_cnt();
|
|
int dso_cnt, limit, i, fd;
|
|
|
|
/* Rest the internal dso open counter limit. */
|
|
reset_fd_limit();
|
|
|
|
memset(&machine, 0, sizeof(machine));
|
|
|
|
/* set as system limit */
|
|
limit = nr * 4;
|
|
TEST_ASSERT_VAL("failed to set file limit", !set_fd_limit(limit));
|
|
|
|
/* and this is now our dso open FDs limit */
|
|
dso_cnt = limit / 2;
|
|
TEST_ASSERT_VAL("failed to create dsos\n",
|
|
!dsos__create(dso_cnt, TEST_FILE_SIZE));
|
|
|
|
for (i = 0; i < (dso_cnt - 1); i++) {
|
|
struct dso *dso = dsos[i];
|
|
|
|
/*
|
|
* Open dsos via dso__data_fd(), it opens the data
|
|
* file and keep it open (unless open file limit).
|
|
*/
|
|
fd = dso__data_fd(dso, &machine);
|
|
TEST_ASSERT_VAL("failed to get fd", fd > 0);
|
|
|
|
if (i % 2) {
|
|
#define BUFSIZE 10
|
|
u8 buf[BUFSIZE];
|
|
ssize_t n;
|
|
|
|
n = dso__data_read_offset(dso, &machine, 0, buf, BUFSIZE);
|
|
TEST_ASSERT_VAL("failed to read dso", n == BUFSIZE);
|
|
}
|
|
}
|
|
|
|
/* verify the first one is already open */
|
|
TEST_ASSERT_VAL("dsos[0] is not open", dsos[0]->data.fd != -1);
|
|
|
|
/* open +1 dso to reach the allowed limit */
|
|
fd = dso__data_fd(dsos[i], &machine);
|
|
TEST_ASSERT_VAL("failed to get fd", fd > 0);
|
|
|
|
/* should force the first one to be closed */
|
|
TEST_ASSERT_VAL("failed to close dsos[0]", dsos[0]->data.fd == -1);
|
|
|
|
/* cleanup everything */
|
|
dsos__delete(dso_cnt);
|
|
|
|
/* Make sure we did not leak any file descriptor. */
|
|
nr_end = open_files_cnt();
|
|
pr_debug("nr start %ld, nr stop %ld\n", nr, nr_end);
|
|
TEST_ASSERT_VAL("failed leadking files", nr == nr_end);
|
|
return 0;
|
|
}
|
|
|
|
int test__dso_data_reopen(struct test *test __maybe_unused, int subtest __maybe_unused)
|
|
{
|
|
struct machine machine;
|
|
long nr_end, nr = open_files_cnt();
|
|
int fd, fd_extra;
|
|
|
|
#define dso_0 (dsos[0])
|
|
#define dso_1 (dsos[1])
|
|
#define dso_2 (dsos[2])
|
|
|
|
/* Rest the internal dso open counter limit. */
|
|
reset_fd_limit();
|
|
|
|
memset(&machine, 0, sizeof(machine));
|
|
|
|
/*
|
|
* Test scenario:
|
|
* - create 3 dso objects
|
|
* - set process file descriptor limit to current
|
|
* files count + 3
|
|
* - test that the first dso gets closed when we
|
|
* reach the files count limit
|
|
*/
|
|
|
|
/* Make sure we are able to open 3 fds anyway */
|
|
TEST_ASSERT_VAL("failed to set file limit",
|
|
!set_fd_limit((nr + 3)));
|
|
|
|
TEST_ASSERT_VAL("failed to create dsos\n", !dsos__create(3, TEST_FILE_SIZE));
|
|
|
|
/* open dso_0 */
|
|
fd = dso__data_fd(dso_0, &machine);
|
|
TEST_ASSERT_VAL("failed to get fd", fd > 0);
|
|
|
|
/* open dso_1 */
|
|
fd = dso__data_fd(dso_1, &machine);
|
|
TEST_ASSERT_VAL("failed to get fd", fd > 0);
|
|
|
|
/*
|
|
* open extra file descriptor and we just
|
|
* reached the files count limit
|
|
*/
|
|
fd_extra = open("/dev/null", O_RDONLY);
|
|
TEST_ASSERT_VAL("failed to open extra fd", fd_extra > 0);
|
|
|
|
/* open dso_2 */
|
|
fd = dso__data_fd(dso_2, &machine);
|
|
TEST_ASSERT_VAL("failed to get fd", fd > 0);
|
|
|
|
/*
|
|
* dso_0 should get closed, because we reached
|
|
* the file descriptor limit
|
|
*/
|
|
TEST_ASSERT_VAL("failed to close dso_0", dso_0->data.fd == -1);
|
|
|
|
/* open dso_0 */
|
|
fd = dso__data_fd(dso_0, &machine);
|
|
TEST_ASSERT_VAL("failed to get fd", fd > 0);
|
|
|
|
/*
|
|
* dso_1 should get closed, because we reached
|
|
* the file descriptor limit
|
|
*/
|
|
TEST_ASSERT_VAL("failed to close dso_1", dso_1->data.fd == -1);
|
|
|
|
/* cleanup everything */
|
|
close(fd_extra);
|
|
dsos__delete(3);
|
|
|
|
/* Make sure we did not leak any file descriptor. */
|
|
nr_end = open_files_cnt();
|
|
pr_debug("nr start %ld, nr stop %ld\n", nr, nr_end);
|
|
TEST_ASSERT_VAL("failed leadking files", nr == nr_end);
|
|
return 0;
|
|
}
|