mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-23 17:30:02 +00:00
![Greg Kroah-Hartman](/assets/img/avatar_default.png)
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>
423 lines
8.9 KiB
C
423 lines
8.9 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* S/390 common I/O routines -- blacklisting of specific devices
|
|
*
|
|
* Copyright IBM Corp. 1999, 2013
|
|
* Author(s): Ingo Adlung (adlung@de.ibm.com)
|
|
* Cornelia Huck (cornelia.huck@de.ibm.com)
|
|
* Arnd Bergmann (arndb@de.ibm.com)
|
|
*/
|
|
|
|
#define KMSG_COMPONENT "cio"
|
|
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
|
|
|
|
#include <linux/init.h>
|
|
#include <linux/vmalloc.h>
|
|
#include <linux/proc_fs.h>
|
|
#include <linux/seq_file.h>
|
|
#include <linux/ctype.h>
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/uaccess.h>
|
|
#include <asm/cio.h>
|
|
#include <asm/ipl.h>
|
|
|
|
#include "blacklist.h"
|
|
#include "cio.h"
|
|
#include "cio_debug.h"
|
|
#include "css.h"
|
|
#include "device.h"
|
|
|
|
/*
|
|
* "Blacklisting" of certain devices:
|
|
* Device numbers given in the commandline as cio_ignore=... won't be known
|
|
* to Linux.
|
|
*
|
|
* These can be single devices or ranges of devices
|
|
*/
|
|
|
|
/* 65536 bits for each set to indicate if a devno is blacklisted or not */
|
|
#define __BL_DEV_WORDS ((__MAX_SUBCHANNEL + (8*sizeof(long) - 1)) / \
|
|
(8*sizeof(long)))
|
|
static unsigned long bl_dev[__MAX_SSID + 1][__BL_DEV_WORDS];
|
|
typedef enum {add, free} range_action;
|
|
|
|
/*
|
|
* Function: blacklist_range
|
|
* (Un-)blacklist the devices from-to
|
|
*/
|
|
static int blacklist_range(range_action action, unsigned int from_ssid,
|
|
unsigned int to_ssid, unsigned int from,
|
|
unsigned int to, int msgtrigger)
|
|
{
|
|
if ((from_ssid > to_ssid) || ((from_ssid == to_ssid) && (from > to))) {
|
|
if (msgtrigger)
|
|
pr_warn("0.%x.%04x to 0.%x.%04x is not a valid range for cio_ignore\n",
|
|
from_ssid, from, to_ssid, to);
|
|
|
|
return 1;
|
|
}
|
|
|
|
while ((from_ssid < to_ssid) || ((from_ssid == to_ssid) &&
|
|
(from <= to))) {
|
|
if (action == add)
|
|
set_bit(from, bl_dev[from_ssid]);
|
|
else
|
|
clear_bit(from, bl_dev[from_ssid]);
|
|
from++;
|
|
if (from > __MAX_SUBCHANNEL) {
|
|
from_ssid++;
|
|
from = 0;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int pure_hex(char **cp, unsigned int *val, int min_digit,
|
|
int max_digit, int max_val)
|
|
{
|
|
int diff;
|
|
|
|
diff = 0;
|
|
*val = 0;
|
|
|
|
while (diff <= max_digit) {
|
|
int value = hex_to_bin(**cp);
|
|
|
|
if (value < 0)
|
|
break;
|
|
*val = *val * 16 + value;
|
|
(*cp)++;
|
|
diff++;
|
|
}
|
|
|
|
if ((diff < min_digit) || (diff > max_digit) || (*val > max_val))
|
|
return 1;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int parse_busid(char *str, unsigned int *cssid, unsigned int *ssid,
|
|
unsigned int *devno, int msgtrigger)
|
|
{
|
|
char *str_work;
|
|
int val, rc, ret;
|
|
|
|
rc = 1;
|
|
|
|
if (*str == '\0')
|
|
goto out;
|
|
|
|
/* old style */
|
|
str_work = str;
|
|
val = simple_strtoul(str, &str_work, 16);
|
|
|
|
if (*str_work == '\0') {
|
|
if (val <= __MAX_SUBCHANNEL) {
|
|
*devno = val;
|
|
*ssid = 0;
|
|
*cssid = 0;
|
|
rc = 0;
|
|
}
|
|
goto out;
|
|
}
|
|
|
|
/* new style */
|
|
str_work = str;
|
|
ret = pure_hex(&str_work, cssid, 1, 2, __MAX_CSSID);
|
|
if (ret || (str_work[0] != '.'))
|
|
goto out;
|
|
str_work++;
|
|
ret = pure_hex(&str_work, ssid, 1, 1, __MAX_SSID);
|
|
if (ret || (str_work[0] != '.'))
|
|
goto out;
|
|
str_work++;
|
|
ret = pure_hex(&str_work, devno, 4, 4, __MAX_SUBCHANNEL);
|
|
if (ret || (str_work[0] != '\0'))
|
|
goto out;
|
|
|
|
rc = 0;
|
|
out:
|
|
if (rc && msgtrigger)
|
|
pr_warn("%s is not a valid device for the cio_ignore kernel parameter\n",
|
|
str);
|
|
|
|
return rc;
|
|
}
|
|
|
|
static int blacklist_parse_parameters(char *str, range_action action,
|
|
int msgtrigger)
|
|
{
|
|
unsigned int from_cssid, to_cssid, from_ssid, to_ssid, from, to;
|
|
int rc, totalrc;
|
|
char *parm;
|
|
range_action ra;
|
|
|
|
totalrc = 0;
|
|
|
|
while ((parm = strsep(&str, ","))) {
|
|
rc = 0;
|
|
ra = action;
|
|
if (*parm == '!') {
|
|
if (ra == add)
|
|
ra = free;
|
|
else
|
|
ra = add;
|
|
parm++;
|
|
}
|
|
if (strcmp(parm, "all") == 0) {
|
|
from_cssid = 0;
|
|
from_ssid = 0;
|
|
from = 0;
|
|
to_cssid = __MAX_CSSID;
|
|
to_ssid = __MAX_SSID;
|
|
to = __MAX_SUBCHANNEL;
|
|
} else if (strcmp(parm, "ipldev") == 0) {
|
|
if (ipl_info.type == IPL_TYPE_CCW) {
|
|
from_cssid = 0;
|
|
from_ssid = ipl_info.data.ccw.dev_id.ssid;
|
|
from = ipl_info.data.ccw.dev_id.devno;
|
|
} else if (ipl_info.type == IPL_TYPE_FCP ||
|
|
ipl_info.type == IPL_TYPE_FCP_DUMP) {
|
|
from_cssid = 0;
|
|
from_ssid = ipl_info.data.fcp.dev_id.ssid;
|
|
from = ipl_info.data.fcp.dev_id.devno;
|
|
} else {
|
|
continue;
|
|
}
|
|
to_cssid = from_cssid;
|
|
to_ssid = from_ssid;
|
|
to = from;
|
|
} else if (strcmp(parm, "condev") == 0) {
|
|
if (console_devno == -1)
|
|
continue;
|
|
|
|
from_cssid = to_cssid = 0;
|
|
from_ssid = to_ssid = 0;
|
|
from = to = console_devno;
|
|
} else {
|
|
rc = parse_busid(strsep(&parm, "-"), &from_cssid,
|
|
&from_ssid, &from, msgtrigger);
|
|
if (!rc) {
|
|
if (parm != NULL)
|
|
rc = parse_busid(parm, &to_cssid,
|
|
&to_ssid, &to,
|
|
msgtrigger);
|
|
else {
|
|
to_cssid = from_cssid;
|
|
to_ssid = from_ssid;
|
|
to = from;
|
|
}
|
|
}
|
|
}
|
|
if (!rc) {
|
|
rc = blacklist_range(ra, from_ssid, to_ssid, from, to,
|
|
msgtrigger);
|
|
if (rc)
|
|
totalrc = -EINVAL;
|
|
} else
|
|
totalrc = -EINVAL;
|
|
}
|
|
|
|
return totalrc;
|
|
}
|
|
|
|
static int __init
|
|
blacklist_setup (char *str)
|
|
{
|
|
CIO_MSG_EVENT(6, "Reading blacklist parameters\n");
|
|
if (blacklist_parse_parameters(str, add, 1))
|
|
return 0;
|
|
return 1;
|
|
}
|
|
|
|
__setup ("cio_ignore=", blacklist_setup);
|
|
|
|
/* Checking if devices are blacklisted */
|
|
|
|
/*
|
|
* Function: is_blacklisted
|
|
* Returns 1 if the given devicenumber can be found in the blacklist,
|
|
* otherwise 0.
|
|
* Used by validate_subchannel()
|
|
*/
|
|
int
|
|
is_blacklisted (int ssid, int devno)
|
|
{
|
|
return test_bit (devno, bl_dev[ssid]);
|
|
}
|
|
|
|
#ifdef CONFIG_PROC_FS
|
|
/*
|
|
* Function: blacklist_parse_proc_parameters
|
|
* parse the stuff which is piped to /proc/cio_ignore
|
|
*/
|
|
static int blacklist_parse_proc_parameters(char *buf)
|
|
{
|
|
int rc;
|
|
char *parm;
|
|
|
|
parm = strsep(&buf, " ");
|
|
|
|
if (strcmp("free", parm) == 0) {
|
|
rc = blacklist_parse_parameters(buf, free, 0);
|
|
css_schedule_eval_all_unreg(0);
|
|
} else if (strcmp("add", parm) == 0)
|
|
rc = blacklist_parse_parameters(buf, add, 0);
|
|
else if (strcmp("purge", parm) == 0)
|
|
return ccw_purge_blacklisted();
|
|
else
|
|
return -EINVAL;
|
|
|
|
|
|
return rc;
|
|
}
|
|
|
|
/* Iterator struct for all devices. */
|
|
struct ccwdev_iter {
|
|
int devno;
|
|
int ssid;
|
|
int in_range;
|
|
};
|
|
|
|
static void *
|
|
cio_ignore_proc_seq_start(struct seq_file *s, loff_t *offset)
|
|
{
|
|
struct ccwdev_iter *iter = s->private;
|
|
|
|
if (*offset >= (__MAX_SUBCHANNEL + 1) * (__MAX_SSID + 1))
|
|
return NULL;
|
|
memset(iter, 0, sizeof(*iter));
|
|
iter->ssid = *offset / (__MAX_SUBCHANNEL + 1);
|
|
iter->devno = *offset % (__MAX_SUBCHANNEL + 1);
|
|
return iter;
|
|
}
|
|
|
|
static void
|
|
cio_ignore_proc_seq_stop(struct seq_file *s, void *it)
|
|
{
|
|
}
|
|
|
|
static void *
|
|
cio_ignore_proc_seq_next(struct seq_file *s, void *it, loff_t *offset)
|
|
{
|
|
struct ccwdev_iter *iter;
|
|
|
|
if (*offset >= (__MAX_SUBCHANNEL + 1) * (__MAX_SSID + 1))
|
|
return NULL;
|
|
iter = it;
|
|
if (iter->devno == __MAX_SUBCHANNEL) {
|
|
iter->devno = 0;
|
|
iter->ssid++;
|
|
if (iter->ssid > __MAX_SSID)
|
|
return NULL;
|
|
} else
|
|
iter->devno++;
|
|
(*offset)++;
|
|
return iter;
|
|
}
|
|
|
|
static int
|
|
cio_ignore_proc_seq_show(struct seq_file *s, void *it)
|
|
{
|
|
struct ccwdev_iter *iter;
|
|
|
|
iter = it;
|
|
if (!is_blacklisted(iter->ssid, iter->devno))
|
|
/* Not blacklisted, nothing to output. */
|
|
return 0;
|
|
if (!iter->in_range) {
|
|
/* First device in range. */
|
|
if ((iter->devno == __MAX_SUBCHANNEL) ||
|
|
!is_blacklisted(iter->ssid, iter->devno + 1)) {
|
|
/* Singular device. */
|
|
seq_printf(s, "0.%x.%04x\n", iter->ssid, iter->devno);
|
|
return 0;
|
|
}
|
|
iter->in_range = 1;
|
|
seq_printf(s, "0.%x.%04x-", iter->ssid, iter->devno);
|
|
return 0;
|
|
}
|
|
if ((iter->devno == __MAX_SUBCHANNEL) ||
|
|
!is_blacklisted(iter->ssid, iter->devno + 1)) {
|
|
/* Last device in range. */
|
|
iter->in_range = 0;
|
|
seq_printf(s, "0.%x.%04x\n", iter->ssid, iter->devno);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static ssize_t
|
|
cio_ignore_write(struct file *file, const char __user *user_buf,
|
|
size_t user_len, loff_t *offset)
|
|
{
|
|
char *buf;
|
|
ssize_t rc, ret, i;
|
|
|
|
if (*offset)
|
|
return -EINVAL;
|
|
if (user_len > 65536)
|
|
user_len = 65536;
|
|
buf = vzalloc(user_len + 1); /* maybe better use the stack? */
|
|
if (buf == NULL)
|
|
return -ENOMEM;
|
|
|
|
if (strncpy_from_user (buf, user_buf, user_len) < 0) {
|
|
rc = -EFAULT;
|
|
goto out_free;
|
|
}
|
|
|
|
i = user_len - 1;
|
|
while ((i >= 0) && (isspace(buf[i]) || (buf[i] == 0))) {
|
|
buf[i] = '\0';
|
|
i--;
|
|
}
|
|
ret = blacklist_parse_proc_parameters(buf);
|
|
if (ret)
|
|
rc = ret;
|
|
else
|
|
rc = user_len;
|
|
|
|
out_free:
|
|
vfree (buf);
|
|
return rc;
|
|
}
|
|
|
|
static const struct seq_operations cio_ignore_proc_seq_ops = {
|
|
.start = cio_ignore_proc_seq_start,
|
|
.stop = cio_ignore_proc_seq_stop,
|
|
.next = cio_ignore_proc_seq_next,
|
|
.show = cio_ignore_proc_seq_show,
|
|
};
|
|
|
|
static int
|
|
cio_ignore_proc_open(struct inode *inode, struct file *file)
|
|
{
|
|
return seq_open_private(file, &cio_ignore_proc_seq_ops,
|
|
sizeof(struct ccwdev_iter));
|
|
}
|
|
|
|
static const struct file_operations cio_ignore_proc_fops = {
|
|
.open = cio_ignore_proc_open,
|
|
.read = seq_read,
|
|
.llseek = seq_lseek,
|
|
.release = seq_release_private,
|
|
.write = cio_ignore_write,
|
|
};
|
|
|
|
static int
|
|
cio_ignore_proc_init (void)
|
|
{
|
|
struct proc_dir_entry *entry;
|
|
|
|
entry = proc_create("cio_ignore", S_IFREG | S_IRUGO | S_IWUSR, NULL,
|
|
&cio_ignore_proc_fops);
|
|
if (!entry)
|
|
return -ENOENT;
|
|
return 0;
|
|
}
|
|
|
|
__initcall (cio_ignore_proc_init);
|
|
|
|
#endif /* CONFIG_PROC_FS */
|