mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-17 08:58:11 +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>
345 lines
8.0 KiB
C
345 lines
8.0 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* HMC Drive FTP Services
|
|
*
|
|
* Copyright IBM Corp. 2013
|
|
* Author(s): Ralf Hoppe (rhoppe@de.ibm.com)
|
|
*/
|
|
|
|
#define KMSG_COMPONENT "hmcdrv"
|
|
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/uaccess.h>
|
|
#include <linux/export.h>
|
|
|
|
#include <linux/ctype.h>
|
|
#include <linux/crc16.h>
|
|
|
|
#include "hmcdrv_ftp.h"
|
|
#include "hmcdrv_cache.h"
|
|
#include "sclp_ftp.h"
|
|
#include "diag_ftp.h"
|
|
|
|
/**
|
|
* struct hmcdrv_ftp_ops - HMC drive FTP operations
|
|
* @startup: startup function
|
|
* @shutdown: shutdown function
|
|
* @cmd: FTP transfer function
|
|
*/
|
|
struct hmcdrv_ftp_ops {
|
|
int (*startup)(void);
|
|
void (*shutdown)(void);
|
|
ssize_t (*transfer)(const struct hmcdrv_ftp_cmdspec *ftp,
|
|
size_t *fsize);
|
|
};
|
|
|
|
static enum hmcdrv_ftp_cmdid hmcdrv_ftp_cmd_getid(const char *cmd, int len);
|
|
static int hmcdrv_ftp_parse(char *cmd, struct hmcdrv_ftp_cmdspec *ftp);
|
|
|
|
static const struct hmcdrv_ftp_ops *hmcdrv_ftp_funcs; /* current operations */
|
|
static DEFINE_MUTEX(hmcdrv_ftp_mutex); /* mutex for hmcdrv_ftp_funcs */
|
|
static unsigned hmcdrv_ftp_refcnt; /* start/shutdown reference counter */
|
|
|
|
/**
|
|
* hmcdrv_ftp_cmd_getid() - determine FTP command ID from a command string
|
|
* @cmd: FTP command string (NOT zero-terminated)
|
|
* @len: length of FTP command string in @cmd
|
|
*/
|
|
static enum hmcdrv_ftp_cmdid hmcdrv_ftp_cmd_getid(const char *cmd, int len)
|
|
{
|
|
/* HMC FTP command descriptor */
|
|
struct hmcdrv_ftp_cmd_desc {
|
|
const char *str; /* command string */
|
|
enum hmcdrv_ftp_cmdid cmd; /* associated command as enum */
|
|
};
|
|
|
|
/* Description of all HMC drive FTP commands
|
|
*
|
|
* Notes:
|
|
* 1. Array size should be a prime number.
|
|
* 2. Do not change the order of commands in table (because the
|
|
* index is determined by CRC % ARRAY_SIZE).
|
|
* 3. Original command 'nlist' was renamed, else the CRC would
|
|
* collide with 'append' (see point 2).
|
|
*/
|
|
static const struct hmcdrv_ftp_cmd_desc ftpcmds[7] = {
|
|
|
|
{.str = "get", /* [0] get (CRC = 0x68eb) */
|
|
.cmd = HMCDRV_FTP_GET},
|
|
{.str = "dir", /* [1] dir (CRC = 0x6a9e) */
|
|
.cmd = HMCDRV_FTP_DIR},
|
|
{.str = "delete", /* [2] delete (CRC = 0x53ae) */
|
|
.cmd = HMCDRV_FTP_DELETE},
|
|
{.str = "nls", /* [3] nls (CRC = 0xf87c) */
|
|
.cmd = HMCDRV_FTP_NLIST},
|
|
{.str = "put", /* [4] put (CRC = 0xac56) */
|
|
.cmd = HMCDRV_FTP_PUT},
|
|
{.str = "append", /* [5] append (CRC = 0xf56e) */
|
|
.cmd = HMCDRV_FTP_APPEND},
|
|
{.str = NULL} /* [6] unused */
|
|
};
|
|
|
|
const struct hmcdrv_ftp_cmd_desc *pdesc;
|
|
|
|
u16 crc = 0xffffU;
|
|
|
|
if (len == 0)
|
|
return HMCDRV_FTP_NOOP; /* error indiactor */
|
|
|
|
crc = crc16(crc, cmd, len);
|
|
pdesc = ftpcmds + (crc % ARRAY_SIZE(ftpcmds));
|
|
pr_debug("FTP command '%s' has CRC 0x%04x, at table pos. %lu\n",
|
|
cmd, crc, (crc % ARRAY_SIZE(ftpcmds)));
|
|
|
|
if (!pdesc->str || strncmp(pdesc->str, cmd, len))
|
|
return HMCDRV_FTP_NOOP;
|
|
|
|
pr_debug("FTP command '%s' found, with ID %d\n",
|
|
pdesc->str, pdesc->cmd);
|
|
|
|
return pdesc->cmd;
|
|
}
|
|
|
|
/**
|
|
* hmcdrv_ftp_parse() - HMC drive FTP command parser
|
|
* @cmd: FTP command string "<cmd> <filename>"
|
|
* @ftp: Pointer to FTP command specification buffer (output)
|
|
*
|
|
* Return: 0 on success, else a (negative) error code
|
|
*/
|
|
static int hmcdrv_ftp_parse(char *cmd, struct hmcdrv_ftp_cmdspec *ftp)
|
|
{
|
|
char *start;
|
|
int argc = 0;
|
|
|
|
ftp->id = HMCDRV_FTP_NOOP;
|
|
ftp->fname = NULL;
|
|
|
|
while (*cmd != '\0') {
|
|
|
|
while (isspace(*cmd))
|
|
++cmd;
|
|
|
|
if (*cmd == '\0')
|
|
break;
|
|
|
|
start = cmd;
|
|
|
|
switch (argc) {
|
|
case 0: /* 1st argument (FTP command) */
|
|
while ((*cmd != '\0') && !isspace(*cmd))
|
|
++cmd;
|
|
ftp->id = hmcdrv_ftp_cmd_getid(start, cmd - start);
|
|
break;
|
|
case 1: /* 2nd / last argument (rest of line) */
|
|
while ((*cmd != '\0') && !iscntrl(*cmd))
|
|
++cmd;
|
|
ftp->fname = start;
|
|
/* fall through */
|
|
default:
|
|
*cmd = '\0';
|
|
break;
|
|
} /* switch */
|
|
|
|
++argc;
|
|
} /* while */
|
|
|
|
if (!ftp->fname || (ftp->id == HMCDRV_FTP_NOOP))
|
|
return -EINVAL;
|
|
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* hmcdrv_ftp_do() - perform a HMC drive FTP, with data from kernel-space
|
|
* @ftp: pointer to FTP command specification
|
|
*
|
|
* Return: number of bytes read/written or a negative error code
|
|
*/
|
|
ssize_t hmcdrv_ftp_do(const struct hmcdrv_ftp_cmdspec *ftp)
|
|
{
|
|
ssize_t len;
|
|
|
|
mutex_lock(&hmcdrv_ftp_mutex);
|
|
|
|
if (hmcdrv_ftp_funcs && hmcdrv_ftp_refcnt) {
|
|
pr_debug("starting transfer, cmd %d for '%s' at %lld with %zd bytes\n",
|
|
ftp->id, ftp->fname, (long long) ftp->ofs, ftp->len);
|
|
len = hmcdrv_cache_cmd(ftp, hmcdrv_ftp_funcs->transfer);
|
|
} else {
|
|
len = -ENXIO;
|
|
}
|
|
|
|
mutex_unlock(&hmcdrv_ftp_mutex);
|
|
return len;
|
|
}
|
|
EXPORT_SYMBOL(hmcdrv_ftp_do);
|
|
|
|
/**
|
|
* hmcdrv_ftp_probe() - probe for the HMC drive FTP service
|
|
*
|
|
* Return: 0 if service is available, else an (negative) error code
|
|
*/
|
|
int hmcdrv_ftp_probe(void)
|
|
{
|
|
int rc;
|
|
|
|
struct hmcdrv_ftp_cmdspec ftp = {
|
|
.id = HMCDRV_FTP_NOOP,
|
|
.ofs = 0,
|
|
.fname = "",
|
|
.len = PAGE_SIZE
|
|
};
|
|
|
|
ftp.buf = (void *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
|
|
|
|
if (!ftp.buf)
|
|
return -ENOMEM;
|
|
|
|
rc = hmcdrv_ftp_startup();
|
|
|
|
if (rc)
|
|
goto out;
|
|
|
|
rc = hmcdrv_ftp_do(&ftp);
|
|
hmcdrv_ftp_shutdown();
|
|
|
|
switch (rc) {
|
|
case -ENOENT: /* no such file/media or currently busy, */
|
|
case -EBUSY: /* but service seems to be available */
|
|
rc = 0;
|
|
break;
|
|
default: /* leave 'rc' as it is for [0, -EPERM, -E...] */
|
|
if (rc > 0)
|
|
rc = 0; /* clear length (success) */
|
|
break;
|
|
} /* switch */
|
|
out:
|
|
free_page((unsigned long) ftp.buf);
|
|
return rc;
|
|
}
|
|
EXPORT_SYMBOL(hmcdrv_ftp_probe);
|
|
|
|
/**
|
|
* hmcdrv_ftp_cmd() - Perform a HMC drive FTP, with data from user-space
|
|
*
|
|
* @cmd: FTP command string "<cmd> <filename>"
|
|
* @offset: file position to read/write
|
|
* @buf: user-space buffer for read/written directory/file
|
|
* @len: size of @buf (read/dir) or number of bytes to write
|
|
*
|
|
* This function must not be called before hmcdrv_ftp_startup() was called.
|
|
*
|
|
* Return: number of bytes read/written or a negative error code
|
|
*/
|
|
ssize_t hmcdrv_ftp_cmd(char __kernel *cmd, loff_t offset,
|
|
char __user *buf, size_t len)
|
|
{
|
|
int order;
|
|
|
|
struct hmcdrv_ftp_cmdspec ftp = {.len = len, .ofs = offset};
|
|
ssize_t retlen = hmcdrv_ftp_parse(cmd, &ftp);
|
|
|
|
if (retlen)
|
|
return retlen;
|
|
|
|
order = get_order(ftp.len);
|
|
ftp.buf = (void *) __get_free_pages(GFP_KERNEL | GFP_DMA, order);
|
|
|
|
if (!ftp.buf)
|
|
return -ENOMEM;
|
|
|
|
switch (ftp.id) {
|
|
case HMCDRV_FTP_DIR:
|
|
case HMCDRV_FTP_NLIST:
|
|
case HMCDRV_FTP_GET:
|
|
retlen = hmcdrv_ftp_do(&ftp);
|
|
|
|
if ((retlen >= 0) &&
|
|
copy_to_user(buf, ftp.buf, retlen))
|
|
retlen = -EFAULT;
|
|
break;
|
|
|
|
case HMCDRV_FTP_PUT:
|
|
case HMCDRV_FTP_APPEND:
|
|
if (!copy_from_user(ftp.buf, buf, ftp.len))
|
|
retlen = hmcdrv_ftp_do(&ftp);
|
|
else
|
|
retlen = -EFAULT;
|
|
break;
|
|
|
|
case HMCDRV_FTP_DELETE:
|
|
retlen = hmcdrv_ftp_do(&ftp);
|
|
break;
|
|
|
|
default:
|
|
retlen = -EOPNOTSUPP;
|
|
break;
|
|
}
|
|
|
|
free_pages((unsigned long) ftp.buf, order);
|
|
return retlen;
|
|
}
|
|
|
|
/**
|
|
* hmcdrv_ftp_startup() - startup of HMC drive FTP functionality for a
|
|
* dedicated (owner) instance
|
|
*
|
|
* Return: 0 on success, else an (negative) error code
|
|
*/
|
|
int hmcdrv_ftp_startup(void)
|
|
{
|
|
static const struct hmcdrv_ftp_ops hmcdrv_ftp_zvm = {
|
|
.startup = diag_ftp_startup,
|
|
.shutdown = diag_ftp_shutdown,
|
|
.transfer = diag_ftp_cmd
|
|
};
|
|
|
|
static const struct hmcdrv_ftp_ops hmcdrv_ftp_lpar = {
|
|
.startup = sclp_ftp_startup,
|
|
.shutdown = sclp_ftp_shutdown,
|
|
.transfer = sclp_ftp_cmd
|
|
};
|
|
|
|
int rc = 0;
|
|
|
|
mutex_lock(&hmcdrv_ftp_mutex); /* block transfers while start-up */
|
|
|
|
if (hmcdrv_ftp_refcnt == 0) {
|
|
if (MACHINE_IS_VM)
|
|
hmcdrv_ftp_funcs = &hmcdrv_ftp_zvm;
|
|
else if (MACHINE_IS_LPAR || MACHINE_IS_KVM)
|
|
hmcdrv_ftp_funcs = &hmcdrv_ftp_lpar;
|
|
else
|
|
rc = -EOPNOTSUPP;
|
|
|
|
if (hmcdrv_ftp_funcs)
|
|
rc = hmcdrv_ftp_funcs->startup();
|
|
}
|
|
|
|
if (!rc)
|
|
++hmcdrv_ftp_refcnt;
|
|
|
|
mutex_unlock(&hmcdrv_ftp_mutex);
|
|
return rc;
|
|
}
|
|
EXPORT_SYMBOL(hmcdrv_ftp_startup);
|
|
|
|
/**
|
|
* hmcdrv_ftp_shutdown() - shutdown of HMC drive FTP functionality for a
|
|
* dedicated (owner) instance
|
|
*/
|
|
void hmcdrv_ftp_shutdown(void)
|
|
{
|
|
mutex_lock(&hmcdrv_ftp_mutex);
|
|
--hmcdrv_ftp_refcnt;
|
|
|
|
if ((hmcdrv_ftp_refcnt == 0) && hmcdrv_ftp_funcs)
|
|
hmcdrv_ftp_funcs->shutdown();
|
|
|
|
mutex_unlock(&hmcdrv_ftp_mutex);
|
|
}
|
|
EXPORT_SYMBOL(hmcdrv_ftp_shutdown);
|