alistair23-linux/arch/metag/kernel/process.c
Greg Kroah-Hartman b24413180f License cleanup: add SPDX GPL-2.0 license identifier to files with no license
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>
2017-11-02 11:10:55 +01:00

449 lines
11 KiB
C

// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2005,2006,2007,2008,2009,2010,2011 Imagination Technologies
*
* This file contains the architecture-dependent parts of process handling.
*
*/
#include <linux/errno.h>
#include <linux/export.h>
#include <linux/sched.h>
#include <linux/sched/debug.h>
#include <linux/sched/task.h>
#include <linux/sched/task_stack.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/unistd.h>
#include <linux/ptrace.h>
#include <linux/user.h>
#include <linux/reboot.h>
#include <linux/elfcore.h>
#include <linux/fs.h>
#include <linux/tick.h>
#include <linux/slab.h>
#include <linux/mman.h>
#include <linux/pm.h>
#include <linux/syscalls.h>
#include <linux/uaccess.h>
#include <linux/smp.h>
#include <asm/core_reg.h>
#include <asm/user_gateway.h>
#include <asm/tcm.h>
#include <asm/traps.h>
#include <asm/switch_to.h>
/*
* Wait for the next interrupt and enable local interrupts
*/
void arch_cpu_idle(void)
{
int tmp;
/*
* Quickly jump straight into the interrupt entry point without actually
* triggering an interrupt. When TXSTATI gets read the processor will
* block until an interrupt is triggered.
*/
asm volatile (/* Switch into ISTAT mode */
"RTH\n\t"
/* Enable local interrupts */
"MOV TXMASKI, %1\n\t"
/*
* We can't directly "SWAP PC, PCX", so we swap via a
* temporary. Essentially we do:
* PCX_new = 1f (the place to continue execution)
* PC = PCX_old
*/
"ADD %0, CPC0, #(1f-.)\n\t"
"SWAP PCX, %0\n\t"
"MOV PC, %0\n"
/* Continue execution here with interrupts enabled */
"1:"
: "=a" (tmp)
: "r" (get_trigger_mask()));
}
#ifdef CONFIG_HOTPLUG_CPU
void arch_cpu_idle_dead(void)
{
cpu_die();
}
#endif
void (*pm_power_off)(void);
EXPORT_SYMBOL(pm_power_off);
void (*soc_restart)(char *cmd);
void (*soc_halt)(void);
void machine_restart(char *cmd)
{
if (soc_restart)
soc_restart(cmd);
hard_processor_halt(HALT_OK);
}
void machine_halt(void)
{
if (soc_halt)
soc_halt();
smp_send_stop();
hard_processor_halt(HALT_OK);
}
void machine_power_off(void)
{
if (pm_power_off)
pm_power_off();
smp_send_stop();
hard_processor_halt(HALT_OK);
}
#define FLAG_Z 0x8
#define FLAG_N 0x4
#define FLAG_O 0x2
#define FLAG_C 0x1
void show_regs(struct pt_regs *regs)
{
int i;
const char *AX0_names[] = {"A0StP", "A0FrP"};
const char *AX1_names[] = {"A1GbP", "A1LbP"};
const char *DX0_names[] = {
"D0Re0",
"D0Ar6",
"D0Ar4",
"D0Ar2",
"D0FrT",
"D0.5 ",
"D0.6 ",
"D0.7 "
};
const char *DX1_names[] = {
"D1Re0",
"D1Ar5",
"D1Ar3",
"D1Ar1",
"D1RtP",
"D1.5 ",
"D1.6 ",
"D1.7 "
};
show_regs_print_info(KERN_INFO);
pr_info(" pt_regs @ %p\n", regs);
pr_info(" SaveMask = 0x%04hx\n", regs->ctx.SaveMask);
pr_info(" Flags = 0x%04hx (%c%c%c%c)\n", regs->ctx.Flags,
regs->ctx.Flags & FLAG_Z ? 'Z' : 'z',
regs->ctx.Flags & FLAG_N ? 'N' : 'n',
regs->ctx.Flags & FLAG_O ? 'O' : 'o',
regs->ctx.Flags & FLAG_C ? 'C' : 'c');
pr_info(" TXRPT = 0x%08x\n", regs->ctx.CurrRPT);
pr_info(" PC = 0x%08x\n", regs->ctx.CurrPC);
/* AX regs */
for (i = 0; i < 2; i++) {
pr_info(" %s = 0x%08x ",
AX0_names[i],
regs->ctx.AX[i].U0);
printk(" %s = 0x%08x\n",
AX1_names[i],
regs->ctx.AX[i].U1);
}
if (regs->ctx.SaveMask & TBICTX_XEXT_BIT)
pr_warn(" Extended state present - AX2.[01] will be WRONG\n");
/* Special place with AXx.2 */
pr_info(" A0.2 = 0x%08x ",
regs->ctx.Ext.AX2.U0);
printk(" A1.2 = 0x%08x\n",
regs->ctx.Ext.AX2.U1);
/* 'extended' AX regs (nominally, just AXx.3) */
for (i = 0; i < (TBICTX_AX_REGS - 3); i++) {
pr_info(" A0.%d = 0x%08x ", i + 3, regs->ctx.AX3[i].U0);
printk(" A1.%d = 0x%08x\n", i + 3, regs->ctx.AX3[i].U1);
}
for (i = 0; i < 8; i++) {
pr_info(" %s = 0x%08x ", DX0_names[i], regs->ctx.DX[i].U0);
printk(" %s = 0x%08x\n", DX1_names[i], regs->ctx.DX[i].U1);
}
show_trace(NULL, (unsigned long *)regs->ctx.AX[0].U0, regs);
}
/*
* Copy architecture-specific thread state
*/
int copy_thread(unsigned long clone_flags, unsigned long usp,
unsigned long kthread_arg, struct task_struct *tsk)
{
struct pt_regs *childregs = task_pt_regs(tsk);
void *kernel_context = ((void *) childregs +
sizeof(struct pt_regs));
unsigned long global_base;
BUG_ON(((unsigned long)childregs) & 0x7);
BUG_ON(((unsigned long)kernel_context) & 0x7);
memset(&tsk->thread.kernel_context, 0,
sizeof(tsk->thread.kernel_context));
tsk->thread.kernel_context = __TBISwitchInit(kernel_context,
ret_from_fork,
0, 0);
if (unlikely(tsk->flags & PF_KTHREAD)) {
/*
* Make sure we don't leak any kernel data to child's regs
* if kernel thread becomes a userspace thread in the future
*/
memset(childregs, 0 , sizeof(struct pt_regs));
global_base = __core_reg_get(A1GbP);
childregs->ctx.AX[0].U1 = (unsigned long) global_base;
childregs->ctx.AX[0].U0 = (unsigned long) kernel_context;
/* Set D1Ar1=kthread_arg and D1RtP=usp (fn) */
childregs->ctx.DX[4].U1 = usp;
childregs->ctx.DX[3].U1 = kthread_arg;
tsk->thread.int_depth = 2;
return 0;
}
/*
* Get a pointer to where the new child's register block should have
* been pushed.
* The Meta's stack grows upwards, and the context is the the first
* thing to be pushed by TBX (phew)
*/
*childregs = *current_pt_regs();
/* Set the correct stack for the clone mode */
if (usp)
childregs->ctx.AX[0].U0 = ALIGN(usp, 8);
tsk->thread.int_depth = 1;
/* set return value for child process */
childregs->ctx.DX[0].U0 = 0;
/* The TLS pointer is passed as an argument to sys_clone. */
if (clone_flags & CLONE_SETTLS)
tsk->thread.tls_ptr =
(__force void __user *)childregs->ctx.DX[1].U1;
#ifdef CONFIG_METAG_FPU
if (tsk->thread.fpu_context) {
struct meta_fpu_context *ctx;
ctx = kmemdup(tsk->thread.fpu_context,
sizeof(struct meta_fpu_context), GFP_ATOMIC);
tsk->thread.fpu_context = ctx;
}
#endif
#ifdef CONFIG_METAG_DSP
if (tsk->thread.dsp_context) {
struct meta_ext_context *ctx;
int i;
ctx = kmemdup(tsk->thread.dsp_context,
sizeof(struct meta_ext_context), GFP_ATOMIC);
for (i = 0; i < 2; i++)
ctx->ram[i] = kmemdup(ctx->ram[i], ctx->ram_sz[i],
GFP_ATOMIC);
tsk->thread.dsp_context = ctx;
}
#endif
return 0;
}
#ifdef CONFIG_METAG_FPU
static void alloc_fpu_context(struct thread_struct *thread)
{
thread->fpu_context = kzalloc(sizeof(struct meta_fpu_context),
GFP_ATOMIC);
}
static void clear_fpu(struct thread_struct *thread)
{
thread->user_flags &= ~TBICTX_FPAC_BIT;
kfree(thread->fpu_context);
thread->fpu_context = NULL;
}
#else
static void clear_fpu(struct thread_struct *thread)
{
}
#endif
#ifdef CONFIG_METAG_DSP
static void clear_dsp(struct thread_struct *thread)
{
if (thread->dsp_context) {
kfree(thread->dsp_context->ram[0]);
kfree(thread->dsp_context->ram[1]);
kfree(thread->dsp_context);
thread->dsp_context = NULL;
}
__core_reg_set(D0.8, 0);
}
#else
static void clear_dsp(struct thread_struct *thread)
{
}
#endif
struct task_struct *__sched __switch_to(struct task_struct *prev,
struct task_struct *next)
{
TBIRES to, from;
to.Switch.pCtx = next->thread.kernel_context;
to.Switch.pPara = prev;
#ifdef CONFIG_METAG_FPU
if (prev->thread.user_flags & TBICTX_FPAC_BIT) {
struct pt_regs *regs = task_pt_regs(prev);
TBIRES state;
state.Sig.SaveMask = prev->thread.user_flags;
state.Sig.pCtx = &regs->ctx;
if (!prev->thread.fpu_context)
alloc_fpu_context(&prev->thread);
if (prev->thread.fpu_context)
__TBICtxFPUSave(state, prev->thread.fpu_context);
}
/*
* Force a restore of the FPU context next time this process is
* scheduled.
*/
if (prev->thread.fpu_context)
prev->thread.fpu_context->needs_restore = true;
#endif
from = __TBISwitch(to, &prev->thread.kernel_context);
/* Restore TLS pointer for this process. */
set_gateway_tls(current->thread.tls_ptr);
return (struct task_struct *) from.Switch.pPara;
}
void flush_thread(void)
{
clear_fpu(&current->thread);
clear_dsp(&current->thread);
}
/*
* Free current thread data structures etc.
*/
void exit_thread(struct task_struct *tsk)
{
clear_fpu(&tsk->thread);
clear_dsp(&tsk->thread);
}
/* TODO: figure out how to unwind the kernel stack here to figure out
* where we went to sleep. */
unsigned long get_wchan(struct task_struct *p)
{
return 0;
}
int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
{
/* Returning 0 indicates that the FPU state was not stored (as it was
* not in use) */
return 0;
}
#ifdef CONFIG_METAG_USER_TCM
#define ELF_MIN_ALIGN PAGE_SIZE
#define ELF_PAGESTART(_v) ((_v) & ~(unsigned long)(ELF_MIN_ALIGN-1))
#define ELF_PAGEOFFSET(_v) ((_v) & (ELF_MIN_ALIGN-1))
#define ELF_PAGEALIGN(_v) (((_v) + ELF_MIN_ALIGN - 1) & ~(ELF_MIN_ALIGN - 1))
#define BAD_ADDR(x) ((unsigned long)(x) >= TASK_SIZE)
unsigned long __metag_elf_map(struct file *filep, unsigned long addr,
struct elf_phdr *eppnt, int prot, int type,
unsigned long total_size)
{
unsigned long map_addr, size;
unsigned long page_off = ELF_PAGEOFFSET(eppnt->p_vaddr);
unsigned long raw_size = eppnt->p_filesz + page_off;
unsigned long off = eppnt->p_offset - page_off;
unsigned int tcm_tag;
addr = ELF_PAGESTART(addr);
size = ELF_PAGEALIGN(raw_size);
/* mmap() will return -EINVAL if given a zero size, but a
* segment with zero filesize is perfectly valid */
if (!size)
return addr;
tcm_tag = tcm_lookup_tag(addr);
if (tcm_tag != TCM_INVALID_TAG)
type &= ~MAP_FIXED;
/*
* total_size is the size of the ELF (interpreter) image.
* The _first_ mmap needs to know the full size, otherwise
* randomization might put this image into an overlapping
* position with the ELF binary image. (since size < total_size)
* So we first map the 'big' image - and unmap the remainder at
* the end. (which unmap is needed for ELF images with holes.)
*/
if (total_size) {
total_size = ELF_PAGEALIGN(total_size);
map_addr = vm_mmap(filep, addr, total_size, prot, type, off);
if (!BAD_ADDR(map_addr))
vm_munmap(map_addr+size, total_size-size);
} else
map_addr = vm_mmap(filep, addr, size, prot, type, off);
if (!BAD_ADDR(map_addr) && tcm_tag != TCM_INVALID_TAG) {
struct tcm_allocation *tcm;
unsigned long tcm_addr;
tcm = kmalloc(sizeof(*tcm), GFP_KERNEL);
if (!tcm)
return -ENOMEM;
tcm_addr = tcm_alloc(tcm_tag, raw_size);
if (tcm_addr != addr) {
kfree(tcm);
return -ENOMEM;
}
tcm->tag = tcm_tag;
tcm->addr = tcm_addr;
tcm->size = raw_size;
list_add(&tcm->list, &current->mm->context.tcm);
eppnt->p_vaddr = map_addr;
if (copy_from_user((void *) addr, (void __user *) map_addr,
raw_size))
return -EFAULT;
}
return map_addr;
}
#endif