mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-28 11:18:45 +07: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>
450 lines
9.9 KiB
C
450 lines
9.9 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <linux/capability.h>
|
|
#include <linux/seq_file.h>
|
|
#include <linux/uaccess.h>
|
|
#include <linux/proc_fs.h>
|
|
#include <linux/ctype.h>
|
|
#include <linux/string.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/init.h>
|
|
|
|
#define LINE_SIZE 80
|
|
|
|
#include <asm/mtrr.h>
|
|
|
|
#include "mtrr.h"
|
|
|
|
#define FILE_FCOUNT(f) (((struct seq_file *)((f)->private_data))->private)
|
|
|
|
static const char *const mtrr_strings[MTRR_NUM_TYPES] =
|
|
{
|
|
"uncachable", /* 0 */
|
|
"write-combining", /* 1 */
|
|
"?", /* 2 */
|
|
"?", /* 3 */
|
|
"write-through", /* 4 */
|
|
"write-protect", /* 5 */
|
|
"write-back", /* 6 */
|
|
};
|
|
|
|
const char *mtrr_attrib_to_str(int x)
|
|
{
|
|
return (x <= 6) ? mtrr_strings[x] : "?";
|
|
}
|
|
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
static int
|
|
mtrr_file_add(unsigned long base, unsigned long size,
|
|
unsigned int type, bool increment, struct file *file, int page)
|
|
{
|
|
unsigned int *fcount = FILE_FCOUNT(file);
|
|
int reg, max;
|
|
|
|
max = num_var_ranges;
|
|
if (fcount == NULL) {
|
|
fcount = kzalloc(max * sizeof *fcount, GFP_KERNEL);
|
|
if (!fcount)
|
|
return -ENOMEM;
|
|
FILE_FCOUNT(file) = fcount;
|
|
}
|
|
if (!page) {
|
|
if ((base & (PAGE_SIZE - 1)) || (size & (PAGE_SIZE - 1)))
|
|
return -EINVAL;
|
|
base >>= PAGE_SHIFT;
|
|
size >>= PAGE_SHIFT;
|
|
}
|
|
reg = mtrr_add_page(base, size, type, true);
|
|
if (reg >= 0)
|
|
++fcount[reg];
|
|
return reg;
|
|
}
|
|
|
|
static int
|
|
mtrr_file_del(unsigned long base, unsigned long size,
|
|
struct file *file, int page)
|
|
{
|
|
unsigned int *fcount = FILE_FCOUNT(file);
|
|
int reg;
|
|
|
|
if (!page) {
|
|
if ((base & (PAGE_SIZE - 1)) || (size & (PAGE_SIZE - 1)))
|
|
return -EINVAL;
|
|
base >>= PAGE_SHIFT;
|
|
size >>= PAGE_SHIFT;
|
|
}
|
|
reg = mtrr_del_page(-1, base, size);
|
|
if (reg < 0)
|
|
return reg;
|
|
if (fcount == NULL)
|
|
return reg;
|
|
if (fcount[reg] < 1)
|
|
return -EINVAL;
|
|
--fcount[reg];
|
|
return reg;
|
|
}
|
|
|
|
/*
|
|
* seq_file can seek but we ignore it.
|
|
*
|
|
* Format of control line:
|
|
* "base=%Lx size=%Lx type=%s" or "disable=%d"
|
|
*/
|
|
static ssize_t
|
|
mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos)
|
|
{
|
|
int i, err;
|
|
unsigned long reg;
|
|
unsigned long long base, size;
|
|
char *ptr;
|
|
char line[LINE_SIZE];
|
|
int length;
|
|
size_t linelen;
|
|
|
|
if (!capable(CAP_SYS_ADMIN))
|
|
return -EPERM;
|
|
|
|
memset(line, 0, LINE_SIZE);
|
|
|
|
length = len;
|
|
length--;
|
|
|
|
if (length > LINE_SIZE - 1)
|
|
length = LINE_SIZE - 1;
|
|
|
|
if (length < 0)
|
|
return -EINVAL;
|
|
|
|
if (copy_from_user(line, buf, length))
|
|
return -EFAULT;
|
|
|
|
linelen = strlen(line);
|
|
ptr = line + linelen - 1;
|
|
if (linelen && *ptr == '\n')
|
|
*ptr = '\0';
|
|
|
|
if (!strncmp(line, "disable=", 8)) {
|
|
reg = simple_strtoul(line + 8, &ptr, 0);
|
|
err = mtrr_del_page(reg, 0, 0);
|
|
if (err < 0)
|
|
return err;
|
|
return len;
|
|
}
|
|
|
|
if (strncmp(line, "base=", 5))
|
|
return -EINVAL;
|
|
|
|
base = simple_strtoull(line + 5, &ptr, 0);
|
|
ptr = skip_spaces(ptr);
|
|
|
|
if (strncmp(ptr, "size=", 5))
|
|
return -EINVAL;
|
|
|
|
size = simple_strtoull(ptr + 5, &ptr, 0);
|
|
if ((base & 0xfff) || (size & 0xfff))
|
|
return -EINVAL;
|
|
ptr = skip_spaces(ptr);
|
|
|
|
if (strncmp(ptr, "type=", 5))
|
|
return -EINVAL;
|
|
ptr = skip_spaces(ptr + 5);
|
|
|
|
for (i = 0; i < MTRR_NUM_TYPES; ++i) {
|
|
if (strcmp(ptr, mtrr_strings[i]))
|
|
continue;
|
|
base >>= PAGE_SHIFT;
|
|
size >>= PAGE_SHIFT;
|
|
err = mtrr_add_page((unsigned long)base, (unsigned long)size, i, true);
|
|
if (err < 0)
|
|
return err;
|
|
return len;
|
|
}
|
|
return -EINVAL;
|
|
}
|
|
|
|
static long
|
|
mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)
|
|
{
|
|
int err = 0;
|
|
mtrr_type type;
|
|
unsigned long base;
|
|
unsigned long size;
|
|
struct mtrr_sentry sentry;
|
|
struct mtrr_gentry gentry;
|
|
void __user *arg = (void __user *) __arg;
|
|
|
|
switch (cmd) {
|
|
case MTRRIOC_ADD_ENTRY:
|
|
case MTRRIOC_SET_ENTRY:
|
|
case MTRRIOC_DEL_ENTRY:
|
|
case MTRRIOC_KILL_ENTRY:
|
|
case MTRRIOC_ADD_PAGE_ENTRY:
|
|
case MTRRIOC_SET_PAGE_ENTRY:
|
|
case MTRRIOC_DEL_PAGE_ENTRY:
|
|
case MTRRIOC_KILL_PAGE_ENTRY:
|
|
if (copy_from_user(&sentry, arg, sizeof sentry))
|
|
return -EFAULT;
|
|
break;
|
|
case MTRRIOC_GET_ENTRY:
|
|
case MTRRIOC_GET_PAGE_ENTRY:
|
|
if (copy_from_user(&gentry, arg, sizeof gentry))
|
|
return -EFAULT;
|
|
break;
|
|
#ifdef CONFIG_COMPAT
|
|
case MTRRIOC32_ADD_ENTRY:
|
|
case MTRRIOC32_SET_ENTRY:
|
|
case MTRRIOC32_DEL_ENTRY:
|
|
case MTRRIOC32_KILL_ENTRY:
|
|
case MTRRIOC32_ADD_PAGE_ENTRY:
|
|
case MTRRIOC32_SET_PAGE_ENTRY:
|
|
case MTRRIOC32_DEL_PAGE_ENTRY:
|
|
case MTRRIOC32_KILL_PAGE_ENTRY: {
|
|
struct mtrr_sentry32 __user *s32;
|
|
|
|
s32 = (struct mtrr_sentry32 __user *)__arg;
|
|
err = get_user(sentry.base, &s32->base);
|
|
err |= get_user(sentry.size, &s32->size);
|
|
err |= get_user(sentry.type, &s32->type);
|
|
if (err)
|
|
return err;
|
|
break;
|
|
}
|
|
case MTRRIOC32_GET_ENTRY:
|
|
case MTRRIOC32_GET_PAGE_ENTRY: {
|
|
struct mtrr_gentry32 __user *g32;
|
|
|
|
g32 = (struct mtrr_gentry32 __user *)__arg;
|
|
err = get_user(gentry.regnum, &g32->regnum);
|
|
err |= get_user(gentry.base, &g32->base);
|
|
err |= get_user(gentry.size, &g32->size);
|
|
err |= get_user(gentry.type, &g32->type);
|
|
if (err)
|
|
return err;
|
|
break;
|
|
}
|
|
#endif
|
|
}
|
|
|
|
switch (cmd) {
|
|
default:
|
|
return -ENOTTY;
|
|
case MTRRIOC_ADD_ENTRY:
|
|
#ifdef CONFIG_COMPAT
|
|
case MTRRIOC32_ADD_ENTRY:
|
|
#endif
|
|
if (!capable(CAP_SYS_ADMIN))
|
|
return -EPERM;
|
|
err =
|
|
mtrr_file_add(sentry.base, sentry.size, sentry.type, true,
|
|
file, 0);
|
|
break;
|
|
case MTRRIOC_SET_ENTRY:
|
|
#ifdef CONFIG_COMPAT
|
|
case MTRRIOC32_SET_ENTRY:
|
|
#endif
|
|
if (!capable(CAP_SYS_ADMIN))
|
|
return -EPERM;
|
|
err = mtrr_add(sentry.base, sentry.size, sentry.type, false);
|
|
break;
|
|
case MTRRIOC_DEL_ENTRY:
|
|
#ifdef CONFIG_COMPAT
|
|
case MTRRIOC32_DEL_ENTRY:
|
|
#endif
|
|
if (!capable(CAP_SYS_ADMIN))
|
|
return -EPERM;
|
|
err = mtrr_file_del(sentry.base, sentry.size, file, 0);
|
|
break;
|
|
case MTRRIOC_KILL_ENTRY:
|
|
#ifdef CONFIG_COMPAT
|
|
case MTRRIOC32_KILL_ENTRY:
|
|
#endif
|
|
if (!capable(CAP_SYS_ADMIN))
|
|
return -EPERM;
|
|
err = mtrr_del(-1, sentry.base, sentry.size);
|
|
break;
|
|
case MTRRIOC_GET_ENTRY:
|
|
#ifdef CONFIG_COMPAT
|
|
case MTRRIOC32_GET_ENTRY:
|
|
#endif
|
|
if (gentry.regnum >= num_var_ranges)
|
|
return -EINVAL;
|
|
mtrr_if->get(gentry.regnum, &base, &size, &type);
|
|
|
|
/* Hide entries that go above 4GB */
|
|
if (base + size - 1 >= (1UL << (8 * sizeof(gentry.size) - PAGE_SHIFT))
|
|
|| size >= (1UL << (8 * sizeof(gentry.size) - PAGE_SHIFT)))
|
|
gentry.base = gentry.size = gentry.type = 0;
|
|
else {
|
|
gentry.base = base << PAGE_SHIFT;
|
|
gentry.size = size << PAGE_SHIFT;
|
|
gentry.type = type;
|
|
}
|
|
|
|
break;
|
|
case MTRRIOC_ADD_PAGE_ENTRY:
|
|
#ifdef CONFIG_COMPAT
|
|
case MTRRIOC32_ADD_PAGE_ENTRY:
|
|
#endif
|
|
if (!capable(CAP_SYS_ADMIN))
|
|
return -EPERM;
|
|
err =
|
|
mtrr_file_add(sentry.base, sentry.size, sentry.type, true,
|
|
file, 1);
|
|
break;
|
|
case MTRRIOC_SET_PAGE_ENTRY:
|
|
#ifdef CONFIG_COMPAT
|
|
case MTRRIOC32_SET_PAGE_ENTRY:
|
|
#endif
|
|
if (!capable(CAP_SYS_ADMIN))
|
|
return -EPERM;
|
|
err =
|
|
mtrr_add_page(sentry.base, sentry.size, sentry.type, false);
|
|
break;
|
|
case MTRRIOC_DEL_PAGE_ENTRY:
|
|
#ifdef CONFIG_COMPAT
|
|
case MTRRIOC32_DEL_PAGE_ENTRY:
|
|
#endif
|
|
if (!capable(CAP_SYS_ADMIN))
|
|
return -EPERM;
|
|
err = mtrr_file_del(sentry.base, sentry.size, file, 1);
|
|
break;
|
|
case MTRRIOC_KILL_PAGE_ENTRY:
|
|
#ifdef CONFIG_COMPAT
|
|
case MTRRIOC32_KILL_PAGE_ENTRY:
|
|
#endif
|
|
if (!capable(CAP_SYS_ADMIN))
|
|
return -EPERM;
|
|
err = mtrr_del_page(-1, sentry.base, sentry.size);
|
|
break;
|
|
case MTRRIOC_GET_PAGE_ENTRY:
|
|
#ifdef CONFIG_COMPAT
|
|
case MTRRIOC32_GET_PAGE_ENTRY:
|
|
#endif
|
|
if (gentry.regnum >= num_var_ranges)
|
|
return -EINVAL;
|
|
mtrr_if->get(gentry.regnum, &base, &size, &type);
|
|
/* Hide entries that would overflow */
|
|
if (size != (__typeof__(gentry.size))size)
|
|
gentry.base = gentry.size = gentry.type = 0;
|
|
else {
|
|
gentry.base = base;
|
|
gentry.size = size;
|
|
gentry.type = type;
|
|
}
|
|
break;
|
|
}
|
|
|
|
if (err)
|
|
return err;
|
|
|
|
switch (cmd) {
|
|
case MTRRIOC_GET_ENTRY:
|
|
case MTRRIOC_GET_PAGE_ENTRY:
|
|
if (copy_to_user(arg, &gentry, sizeof gentry))
|
|
err = -EFAULT;
|
|
break;
|
|
#ifdef CONFIG_COMPAT
|
|
case MTRRIOC32_GET_ENTRY:
|
|
case MTRRIOC32_GET_PAGE_ENTRY: {
|
|
struct mtrr_gentry32 __user *g32;
|
|
|
|
g32 = (struct mtrr_gentry32 __user *)__arg;
|
|
err = put_user(gentry.base, &g32->base);
|
|
err |= put_user(gentry.size, &g32->size);
|
|
err |= put_user(gentry.regnum, &g32->regnum);
|
|
err |= put_user(gentry.type, &g32->type);
|
|
break;
|
|
}
|
|
#endif
|
|
}
|
|
return err;
|
|
}
|
|
|
|
static int mtrr_close(struct inode *ino, struct file *file)
|
|
{
|
|
unsigned int *fcount = FILE_FCOUNT(file);
|
|
int i, max;
|
|
|
|
if (fcount != NULL) {
|
|
max = num_var_ranges;
|
|
for (i = 0; i < max; ++i) {
|
|
while (fcount[i] > 0) {
|
|
mtrr_del(i, 0, 0);
|
|
--fcount[i];
|
|
}
|
|
}
|
|
kfree(fcount);
|
|
FILE_FCOUNT(file) = NULL;
|
|
}
|
|
return single_release(ino, file);
|
|
}
|
|
|
|
static int mtrr_seq_show(struct seq_file *seq, void *offset);
|
|
|
|
static int mtrr_open(struct inode *inode, struct file *file)
|
|
{
|
|
if (!mtrr_if)
|
|
return -EIO;
|
|
if (!mtrr_if->get)
|
|
return -ENXIO;
|
|
return single_open(file, mtrr_seq_show, NULL);
|
|
}
|
|
|
|
static const struct file_operations mtrr_fops = {
|
|
.owner = THIS_MODULE,
|
|
.open = mtrr_open,
|
|
.read = seq_read,
|
|
.llseek = seq_lseek,
|
|
.write = mtrr_write,
|
|
.unlocked_ioctl = mtrr_ioctl,
|
|
.compat_ioctl = mtrr_ioctl,
|
|
.release = mtrr_close,
|
|
};
|
|
|
|
static int mtrr_seq_show(struct seq_file *seq, void *offset)
|
|
{
|
|
char factor;
|
|
int i, max;
|
|
mtrr_type type;
|
|
unsigned long base, size;
|
|
|
|
max = num_var_ranges;
|
|
for (i = 0; i < max; i++) {
|
|
mtrr_if->get(i, &base, &size, &type);
|
|
if (size == 0) {
|
|
mtrr_usage_table[i] = 0;
|
|
continue;
|
|
}
|
|
if (size < (0x100000 >> PAGE_SHIFT)) {
|
|
/* less than 1MB */
|
|
factor = 'K';
|
|
size <<= PAGE_SHIFT - 10;
|
|
} else {
|
|
factor = 'M';
|
|
size >>= 20 - PAGE_SHIFT;
|
|
}
|
|
/* Base can be > 32bit */
|
|
seq_printf(seq, "reg%02i: base=0x%06lx000 (%5luMB), size=%5lu%cB, count=%d: %s\n",
|
|
i, base, base >> (20 - PAGE_SHIFT),
|
|
size, factor,
|
|
mtrr_usage_table[i], mtrr_attrib_to_str(type));
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static int __init mtrr_if_init(void)
|
|
{
|
|
struct cpuinfo_x86 *c = &boot_cpu_data;
|
|
|
|
if ((!cpu_has(c, X86_FEATURE_MTRR)) &&
|
|
(!cpu_has(c, X86_FEATURE_K6_MTRR)) &&
|
|
(!cpu_has(c, X86_FEATURE_CYRIX_ARR)) &&
|
|
(!cpu_has(c, X86_FEATURE_CENTAUR_MCR)))
|
|
return -ENODEV;
|
|
|
|
proc_create("mtrr", S_IWUSR | S_IRUGO, NULL, &mtrr_fops);
|
|
return 0;
|
|
}
|
|
arch_initcall(mtrr_if_init);
|
|
#endif /* CONFIG_PROC_FS */
|