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-01 22:07:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2012-03-11 23:59:26 +08:00
|
|
|
* SMP related functions
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2012-07-20 17:15:04 +08:00
|
|
|
* Copyright IBM Corp. 1999, 2012
|
2012-03-11 23:59:26 +08:00
|
|
|
* Author(s): Denis Joseph Barrow,
|
|
|
|
* Martin Schwidefsky <schwidefsky@de.ibm.com>,
|
|
|
|
* Heiko Carstens <heiko.carstens@de.ibm.com>,
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2007-04-27 22:02:00 +08:00
|
|
|
* based on other smp stuff by
|
2005-04-17 06:20:36 +08:00
|
|
|
* (c) 1995 Alan Cox, CymruNET Ltd <alan@cymru.net>
|
|
|
|
* (c) 1998 Ingo Molnar
|
|
|
|
*
|
2012-03-11 23:59:26 +08:00
|
|
|
* The code outside of smp.c uses logical cpu numbers, only smp.c does
|
|
|
|
* the translation of logical to physical cpu ids. All new code that
|
|
|
|
* operates on physical cpu numbers needs to go into smp.c.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
2008-12-25 20:39:50 +08:00
|
|
|
#define KMSG_COMPONENT "cpu"
|
|
|
|
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
|
|
|
|
|
2011-01-05 19:48:08 +08:00
|
|
|
#include <linux/workqueue.h>
|
2018-10-31 06:09:49 +08:00
|
|
|
#include <linux/memblock.h>
|
2017-02-10 04:20:23 +08:00
|
|
|
#include <linux/export.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/mm.h>
|
2007-07-30 06:36:13 +08:00
|
|
|
#include <linux/err.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/kernel_stat.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/interrupt.h>
|
2009-03-26 22:23:56 +08:00
|
|
|
#include <linux/irqflags.h>
|
2021-02-20 06:32:56 +08:00
|
|
|
#include <linux/irq_work.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/cpu.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2017-02-09 01:51:36 +08:00
|
|
|
#include <linux/sched/hotplug.h>
|
2017-02-09 01:51:37 +08:00
|
|
|
#include <linux/sched/task_stack.h>
|
2011-10-30 22:16:40 +08:00
|
|
|
#include <linux/crash_dump.h>
|
2017-09-15 22:24:31 +08:00
|
|
|
#include <linux/kprobes.h>
|
2010-02-27 05:37:43 +08:00
|
|
|
#include <asm/asm-offsets.h>
|
2015-08-20 23:28:44 +08:00
|
|
|
#include <asm/diag.h>
|
2012-03-30 15:40:55 +08:00
|
|
|
#include <asm/switch_to.h>
|
|
|
|
#include <asm/facility.h>
|
2007-02-21 17:55:21 +08:00
|
|
|
#include <asm/ipl.h>
|
2007-02-06 04:16:47 +08:00
|
|
|
#include <asm/setup.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/irq.h>
|
|
|
|
#include <asm/tlbflush.h>
|
2012-07-20 17:15:08 +08:00
|
|
|
#include <asm/vtimer.h>
|
2007-04-27 22:01:49 +08:00
|
|
|
#include <asm/lowcore.h>
|
2008-01-26 21:10:56 +08:00
|
|
|
#include <asm/sclp.h>
|
2012-03-11 23:59:32 +08:00
|
|
|
#include <asm/debug.h>
|
2012-03-11 23:59:34 +08:00
|
|
|
#include <asm/os_info.h>
|
2012-06-04 18:55:15 +08:00
|
|
|
#include <asm/sigp.h>
|
2014-10-01 16:57:57 +08:00
|
|
|
#include <asm/idle.h>
|
2016-01-26 21:10:34 +08:00
|
|
|
#include <asm/nmi.h>
|
2019-01-28 15:33:08 +08:00
|
|
|
#include <asm/stacktrace.h>
|
2017-11-16 21:26:36 +08:00
|
|
|
#include <asm/topology.h>
|
2020-11-16 15:06:41 +08:00
|
|
|
#include <asm/vdso.h>
|
2008-04-17 13:46:26 +08:00
|
|
|
#include "entry.h"
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-11 23:59:26 +08:00
|
|
|
enum {
|
|
|
|
ec_schedule = 0,
|
|
|
|
ec_call_function_single,
|
|
|
|
ec_stop_cpu,
|
2020-03-17 20:37:49 +08:00
|
|
|
ec_mcck_pending,
|
2021-02-20 06:32:56 +08:00
|
|
|
ec_irq_work,
|
2012-03-11 23:59:26 +08:00
|
|
|
};
|
2008-01-26 21:10:56 +08:00
|
|
|
|
2012-03-11 23:59:26 +08:00
|
|
|
enum {
|
2008-01-26 21:10:56 +08:00
|
|
|
CPU_STATE_STANDBY,
|
|
|
|
CPU_STATE_CONFIGURED,
|
|
|
|
};
|
|
|
|
|
2015-02-11 19:31:03 +08:00
|
|
|
static DEFINE_PER_CPU(struct cpu *, cpu_device);
|
|
|
|
|
2012-03-11 23:59:26 +08:00
|
|
|
struct pcpu {
|
|
|
|
unsigned long ec_mask; /* bit mask for ec_xxx functions */
|
2015-12-08 21:10:12 +08:00
|
|
|
unsigned long ec_clk; /* sigp timestamp for ec_xxx */
|
2015-02-11 19:31:03 +08:00
|
|
|
signed char state; /* physical cpu state */
|
|
|
|
signed char polarization; /* physical polarization */
|
2012-03-11 23:59:26 +08:00
|
|
|
u16 address; /* physical cpu address */
|
|
|
|
};
|
|
|
|
|
2015-06-18 20:23:00 +08:00
|
|
|
static u8 boot_core_type;
|
2012-03-11 23:59:26 +08:00
|
|
|
static struct pcpu pcpu_devices[NR_CPUS];
|
|
|
|
|
2015-01-15 00:52:10 +08:00
|
|
|
unsigned int smp_cpu_mt_shift;
|
|
|
|
EXPORT_SYMBOL(smp_cpu_mt_shift);
|
|
|
|
|
|
|
|
unsigned int smp_cpu_mtid;
|
|
|
|
EXPORT_SYMBOL(smp_cpu_mtid);
|
|
|
|
|
2015-10-29 17:28:26 +08:00
|
|
|
#ifdef CONFIG_CRASH_DUMP
|
|
|
|
__vector128 __initdata boot_cpu_vector_save_area[__NUM_VXRS];
|
|
|
|
#endif
|
|
|
|
|
2015-01-15 00:52:10 +08:00
|
|
|
static unsigned int smp_max_threads __initdata = -1U;
|
|
|
|
|
|
|
|
static int __init early_nosmt(char *s)
|
|
|
|
{
|
|
|
|
smp_max_threads = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
early_param("nosmt", early_nosmt);
|
|
|
|
|
|
|
|
static int __init early_smt(char *s)
|
|
|
|
{
|
|
|
|
get_option(&s, &smp_max_threads);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
early_param("smt", early_smt);
|
|
|
|
|
2012-09-04 23:36:16 +08:00
|
|
|
/*
|
|
|
|
* The smp_cpu_state_mutex must be held when changing the state or polarization
|
|
|
|
* member of a pcpu data structure within the pcpu_devices arreay.
|
|
|
|
*/
|
2008-04-17 13:46:12 +08:00
|
|
|
DEFINE_MUTEX(smp_cpu_state_mutex);
|
2008-01-26 21:10:56 +08:00
|
|
|
|
2012-03-11 23:59:26 +08:00
|
|
|
/*
|
|
|
|
* Signal processor helper functions.
|
|
|
|
*/
|
2015-10-29 17:28:26 +08:00
|
|
|
static inline int __pcpu_sigp_relax(u16 addr, u8 order, unsigned long parm)
|
2009-09-11 16:29:05 +08:00
|
|
|
{
|
2012-03-11 23:59:26 +08:00
|
|
|
int cc;
|
2009-09-11 16:29:05 +08:00
|
|
|
|
2012-03-11 23:59:26 +08:00
|
|
|
while (1) {
|
2012-08-30 20:24:42 +08:00
|
|
|
cc = __pcpu_sigp(addr, order, parm, NULL);
|
2012-06-04 18:55:15 +08:00
|
|
|
if (cc != SIGP_CC_BUSY)
|
2012-03-11 23:59:26 +08:00
|
|
|
return cc;
|
|
|
|
cpu_relax();
|
2009-09-11 16:29:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-11 23:59:26 +08:00
|
|
|
static int pcpu_sigp_retry(struct pcpu *pcpu, u8 order, u32 parm)
|
2010-02-27 05:37:35 +08:00
|
|
|
{
|
2012-03-11 23:59:26 +08:00
|
|
|
int cc, retry;
|
|
|
|
|
|
|
|
for (retry = 0; ; retry++) {
|
2012-08-30 20:24:42 +08:00
|
|
|
cc = __pcpu_sigp(pcpu->address, order, parm, NULL);
|
2012-06-04 18:55:15 +08:00
|
|
|
if (cc != SIGP_CC_BUSY)
|
2012-03-11 23:59:26 +08:00
|
|
|
break;
|
|
|
|
if (retry >= 3)
|
|
|
|
udelay(10);
|
|
|
|
}
|
|
|
|
return cc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int pcpu_stopped(struct pcpu *pcpu)
|
|
|
|
{
|
treewide: Remove uninitialized_var() usage
Using uninitialized_var() is dangerous as it papers over real bugs[1]
(or can in the future), and suppresses unrelated compiler warnings
(e.g. "unused variable"). If the compiler thinks it is uninitialized,
either simply initialize the variable or make compiler changes.
In preparation for removing[2] the[3] macro[4], remove all remaining
needless uses with the following script:
git grep '\buninitialized_var\b' | cut -d: -f1 | sort -u | \
xargs perl -pi -e \
's/\buninitialized_var\(([^\)]+)\)/\1/g;
s:\s*/\* (GCC be quiet|to make compiler happy) \*/$::g;'
drivers/video/fbdev/riva/riva_hw.c was manually tweaked to avoid
pathological white-space.
No outstanding warnings were found building allmodconfig with GCC 9.3.0
for x86_64, i386, arm64, arm, powerpc, powerpc64le, s390x, mips, sparc64,
alpha, and m68k.
[1] https://lore.kernel.org/lkml/20200603174714.192027-1-glider@google.com/
[2] https://lore.kernel.org/lkml/CA+55aFw+Vbj0i=1TGqCR5vQkCzWJ0QxK6CernOU6eedsudAixw@mail.gmail.com/
[3] https://lore.kernel.org/lkml/CA+55aFwgbgqhbp1fkxvRKEpzyR5J8n1vKT1VZdz9knmPuXhOeg@mail.gmail.com/
[4] https://lore.kernel.org/lkml/CA+55aFz2500WfbKXAx8s67wrm9=yVJu65TpLgN_ybYNv0VEOKA@mail.gmail.com/
Reviewed-by: Leon Romanovsky <leonro@mellanox.com> # drivers/infiniband and mlx4/mlx5
Acked-by: Jason Gunthorpe <jgg@mellanox.com> # IB
Acked-by: Kalle Valo <kvalo@codeaurora.org> # wireless drivers
Reviewed-by: Chao Yu <yuchao0@huawei.com> # erofs
Signed-off-by: Kees Cook <keescook@chromium.org>
2020-06-04 04:09:38 +08:00
|
|
|
u32 status;
|
2012-08-30 20:24:42 +08:00
|
|
|
|
2012-06-04 18:55:15 +08:00
|
|
|
if (__pcpu_sigp(pcpu->address, SIGP_SENSE,
|
2012-08-30 20:24:42 +08:00
|
|
|
0, &status) != SIGP_CC_STATUS_STORED)
|
2012-03-11 23:59:26 +08:00
|
|
|
return 0;
|
2012-08-30 20:24:42 +08:00
|
|
|
return !!(status & (SIGP_STATUS_CHECK_STOP|SIGP_STATUS_STOPPED));
|
2012-03-11 23:59:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int pcpu_running(struct pcpu *pcpu)
|
2010-02-27 05:37:35 +08:00
|
|
|
{
|
2012-06-04 18:55:15 +08:00
|
|
|
if (__pcpu_sigp(pcpu->address, SIGP_SENSE_RUNNING,
|
2012-08-30 20:24:42 +08:00
|
|
|
0, NULL) != SIGP_CC_STATUS_STORED)
|
2012-03-11 23:59:26 +08:00
|
|
|
return 1;
|
2012-06-04 18:11:41 +08:00
|
|
|
/* Status stored condition code is equivalent to cpu not running. */
|
|
|
|
return 0;
|
2010-02-27 05:37:35 +08:00
|
|
|
}
|
|
|
|
|
2011-10-30 22:16:38 +08:00
|
|
|
/*
|
2012-03-11 23:59:26 +08:00
|
|
|
* Find struct pcpu by cpu address.
|
2011-10-30 22:16:38 +08:00
|
|
|
*/
|
2015-01-15 00:52:10 +08:00
|
|
|
static struct pcpu *pcpu_find_address(const struct cpumask *mask, u16 address)
|
2011-10-30 22:16:38 +08:00
|
|
|
{
|
|
|
|
int cpu;
|
|
|
|
|
2012-03-11 23:59:26 +08:00
|
|
|
for_each_cpu(cpu, mask)
|
|
|
|
if (pcpu_devices[cpu].address == address)
|
|
|
|
return pcpu_devices + cpu;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pcpu_ec_call(struct pcpu *pcpu, int ec_bit)
|
|
|
|
{
|
|
|
|
int order;
|
|
|
|
|
2013-12-03 17:06:29 +08:00
|
|
|
if (test_and_set_bit(ec_bit, &pcpu->ec_mask))
|
|
|
|
return;
|
|
|
|
order = pcpu_running(pcpu) ? SIGP_EXTERNAL_CALL : SIGP_EMERGENCY_SIGNAL;
|
2015-12-08 21:10:12 +08:00
|
|
|
pcpu->ec_clk = get_tod_clock_fast();
|
2012-03-11 23:59:26 +08:00
|
|
|
pcpu_sigp_retry(pcpu, order, 0);
|
|
|
|
}
|
|
|
|
|
2013-06-19 05:04:52 +08:00
|
|
|
static int pcpu_alloc_lowcore(struct pcpu *pcpu, int cpu)
|
2012-03-11 23:59:26 +08:00
|
|
|
{
|
2021-02-03 16:02:51 +08:00
|
|
|
unsigned long async_stack, nodat_stack, mcck_stack;
|
2015-12-31 17:29:00 +08:00
|
|
|
struct lowcore *lc;
|
2012-03-11 23:59:26 +08:00
|
|
|
|
2021-05-06 22:26:53 +08:00
|
|
|
lc = (struct lowcore *) __get_free_pages(GFP_KERNEL | GFP_DMA, LC_ORDER);
|
|
|
|
nodat_stack = __get_free_pages(GFP_KERNEL, THREAD_SIZE_ORDER);
|
2017-09-12 22:37:33 +08:00
|
|
|
async_stack = stack_alloc();
|
2021-02-03 16:02:51 +08:00
|
|
|
mcck_stack = stack_alloc();
|
2021-05-06 22:26:53 +08:00
|
|
|
if (!lc || !nodat_stack || !async_stack || !mcck_stack)
|
|
|
|
goto out;
|
2012-03-11 23:59:26 +08:00
|
|
|
memcpy(lc, &S390_lowcore, 512);
|
|
|
|
memset((char *) lc + 512, 0, sizeof(*lc) - 512);
|
2017-09-12 22:37:33 +08:00
|
|
|
lc->async_stack = async_stack + STACK_INIT_OFFSET;
|
|
|
|
lc->nodat_stack = nodat_stack + STACK_INIT_OFFSET;
|
2021-02-03 16:02:51 +08:00
|
|
|
lc->mcck_stack = mcck_stack + STACK_INIT_OFFSET;
|
2012-03-11 23:59:26 +08:00
|
|
|
lc->cpu_nr = cpu;
|
2014-04-08 00:25:23 +08:00
|
|
|
lc->spinlock_lockval = arch_spin_lockval(cpu);
|
s390/spinlock: introduce spinlock wait queueing
The queued spinlock code for s390 follows the principles of the common
code qspinlock implementation but with a few notable differences.
The format of the spinlock_t locking word differs, s390 needs to store
the logical CPU number of the lock holder in the spinlock_t to be able
to use the diagnose 9c directed yield hypervisor call.
The inline code sequences for spin_lock and spin_unlock are nice and
short. The inline portion of a spin_lock now typically looks like this:
lhi %r0,0 # 0 indicates an empty lock
l %r1,0x3a0 # CPU number + 1 from lowcore
cs %r0,%r1,<some_lock> # lock operation
jnz call_wait # on failure call wait function
locked:
...
call_wait:
la %r2,<some_lock>
brasl %r14,arch_spin_lock_wait
j locked
A spin_unlock is as simple as before:
lhi %r0,0
sth %r0,2(%r2) # unlock operation
After a CPU has queued itself it may not enable interrupts again for the
arch_spin_lock_flags() variant. The arch_spin_lock_wait_flags wait function
is removed.
To improve performance the code implements opportunistic lock stealing.
If the wait function finds a spinlock_t that indicates that the lock is
free but there are queued waiters, the CPU may steal the lock up to three
times without queueing itself. The lock stealing update the steal counter
in the lock word to prevent more than 3 steals. The counter is reset at
the time the CPU next in the queue successfully takes the lock.
While the queued spinlocks improve performance in a system with dedicated
CPUs, in a virtualized environment with continuously overcommitted CPUs
the queued spinlocks can have a negative effect on performance. This
is due to the fact that a queued CPU that is preempted by the hypervisor
will block the queue at some point even without holding the lock. With
the classic spinlock it does not matter if a CPU is preempted that waits
for the lock. Therefore use the queued spinlock code only if the system
runs with dedicated CPUs and fall back to classic spinlocks when running
with shared CPUs.
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
2017-03-25 00:25:02 +08:00
|
|
|
lc->spinlock_index = 0;
|
2018-01-26 19:46:47 +08:00
|
|
|
lc->br_r1_trampoline = 0x07f1; /* br %r1 */
|
2020-01-22 20:38:22 +08:00
|
|
|
lc->return_lpswe = gen_lpswe(__LC_RETURN_PSW);
|
|
|
|
lc->return_mcck_lpswe = gen_lpswe(__LC_RETURN_MCCK_PSW);
|
2017-10-12 19:24:47 +08:00
|
|
|
if (nmi_alloc_per_cpu(lc))
|
2021-05-06 22:26:53 +08:00
|
|
|
goto out;
|
2012-03-11 23:59:26 +08:00
|
|
|
lowcore_ptr[cpu] = lc;
|
2012-06-04 18:55:15 +08:00
|
|
|
pcpu_sigp_retry(pcpu, SIGP_SET_PREFIX, (u32)(unsigned long) lc);
|
2012-03-11 23:59:26 +08:00
|
|
|
return 0;
|
2017-10-12 19:24:47 +08:00
|
|
|
|
2021-05-06 22:26:53 +08:00
|
|
|
out:
|
2021-02-03 16:02:51 +08:00
|
|
|
stack_free(mcck_stack);
|
2017-09-12 22:37:33 +08:00
|
|
|
stack_free(async_stack);
|
2021-05-06 22:26:53 +08:00
|
|
|
free_pages(nodat_stack, THREAD_SIZE_ORDER);
|
|
|
|
free_pages((unsigned long) lc, LC_ORDER);
|
2012-03-11 23:59:26 +08:00
|
|
|
return -ENOMEM;
|
2011-10-30 22:16:38 +08:00
|
|
|
}
|
|
|
|
|
2012-03-11 23:59:26 +08:00
|
|
|
static void pcpu_free_lowcore(struct pcpu *pcpu)
|
2010-02-27 05:37:34 +08:00
|
|
|
{
|
2021-05-06 22:26:53 +08:00
|
|
|
unsigned long async_stack, nodat_stack, mcck_stack;
|
|
|
|
struct lowcore *lc;
|
2021-05-06 22:26:54 +08:00
|
|
|
int cpu;
|
2017-09-12 22:37:33 +08:00
|
|
|
|
2021-05-06 22:26:54 +08:00
|
|
|
cpu = pcpu - pcpu_devices;
|
|
|
|
lc = lowcore_ptr[cpu];
|
2021-05-06 22:26:53 +08:00
|
|
|
nodat_stack = lc->nodat_stack - STACK_INIT_OFFSET;
|
|
|
|
async_stack = lc->async_stack - STACK_INIT_OFFSET;
|
|
|
|
mcck_stack = lc->mcck_stack - STACK_INIT_OFFSET;
|
2012-06-04 18:55:15 +08:00
|
|
|
pcpu_sigp_retry(pcpu, SIGP_SET_PREFIX, 0);
|
2021-05-06 22:26:54 +08:00
|
|
|
lowcore_ptr[cpu] = NULL;
|
2021-05-06 22:26:53 +08:00
|
|
|
nmi_free_per_cpu(lc);
|
2017-09-12 22:37:33 +08:00
|
|
|
stack_free(async_stack);
|
2021-02-03 16:02:51 +08:00
|
|
|
stack_free(mcck_stack);
|
2018-09-19 00:23:40 +08:00
|
|
|
free_pages(nodat_stack, THREAD_SIZE_ORDER);
|
2021-05-06 22:26:53 +08:00
|
|
|
free_pages((unsigned long) lc, LC_ORDER);
|
2012-03-11 23:59:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void pcpu_prepare_secondary(struct pcpu *pcpu, int cpu)
|
|
|
|
{
|
2021-05-06 22:26:54 +08:00
|
|
|
struct lowcore *lc = lowcore_ptr[cpu];
|
2012-03-11 23:59:26 +08:00
|
|
|
|
2016-05-25 15:45:26 +08:00
|
|
|
cpumask_set_cpu(cpu, &init_mm.context.cpu_attach_mask);
|
2014-04-03 19:55:01 +08:00
|
|
|
cpumask_set_cpu(cpu, mm_cpumask(&init_mm));
|
2012-03-11 23:59:26 +08:00
|
|
|
lc->cpu_nr = cpu;
|
2014-04-08 00:25:23 +08:00
|
|
|
lc->spinlock_lockval = arch_spin_lockval(cpu);
|
s390/spinlock: introduce spinlock wait queueing
The queued spinlock code for s390 follows the principles of the common
code qspinlock implementation but with a few notable differences.
The format of the spinlock_t locking word differs, s390 needs to store
the logical CPU number of the lock holder in the spinlock_t to be able
to use the diagnose 9c directed yield hypervisor call.
The inline code sequences for spin_lock and spin_unlock are nice and
short. The inline portion of a spin_lock now typically looks like this:
lhi %r0,0 # 0 indicates an empty lock
l %r1,0x3a0 # CPU number + 1 from lowcore
cs %r0,%r1,<some_lock> # lock operation
jnz call_wait # on failure call wait function
locked:
...
call_wait:
la %r2,<some_lock>
brasl %r14,arch_spin_lock_wait
j locked
A spin_unlock is as simple as before:
lhi %r0,0
sth %r0,2(%r2) # unlock operation
After a CPU has queued itself it may not enable interrupts again for the
arch_spin_lock_flags() variant. The arch_spin_lock_wait_flags wait function
is removed.
To improve performance the code implements opportunistic lock stealing.
If the wait function finds a spinlock_t that indicates that the lock is
free but there are queued waiters, the CPU may steal the lock up to three
times without queueing itself. The lock stealing update the steal counter
in the lock word to prevent more than 3 steals. The counter is reset at
the time the CPU next in the queue successfully takes the lock.
While the queued spinlocks improve performance in a system with dedicated
CPUs, in a virtualized environment with continuously overcommitted CPUs
the queued spinlocks can have a negative effect on performance. This
is due to the fact that a queued CPU that is preempted by the hypervisor
will block the queue at some point even without holding the lock. With
the classic spinlock it does not matter if a CPU is preempted that waits
for the lock. Therefore use the queued spinlock code only if the system
runs with dedicated CPUs and fall back to classic spinlocks when running
with shared CPUs.
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
2017-03-25 00:25:02 +08:00
|
|
|
lc->spinlock_index = 0;
|
2012-03-11 23:59:26 +08:00
|
|
|
lc->percpu_offset = __per_cpu_offset[cpu];
|
|
|
|
lc->kernel_asce = S390_lowcore.kernel_asce;
|
2020-11-16 15:06:41 +08:00
|
|
|
lc->user_asce = s390_invalid_asce;
|
2012-03-11 23:59:26 +08:00
|
|
|
lc->machine_flags = S390_lowcore.machine_flags;
|
2019-03-06 19:31:21 +08:00
|
|
|
lc->user_timer = lc->system_timer =
|
|
|
|
lc->steal_timer = lc->avg_steal_timer = 0;
|
2012-03-11 23:59:26 +08:00
|
|
|
__ctl_store(lc->cregs_save_area, 0, 15);
|
2019-11-18 20:09:52 +08:00
|
|
|
lc->cregs_save_area[1] = lc->kernel_asce;
|
2020-11-16 15:06:40 +08:00
|
|
|
lc->cregs_save_area[7] = lc->user_asce;
|
2012-03-11 23:59:26 +08:00
|
|
|
save_access_regs((unsigned int *) lc->access_regs_save_area);
|
s390/spinlock: introduce spinlock wait queueing
The queued spinlock code for s390 follows the principles of the common
code qspinlock implementation but with a few notable differences.
The format of the spinlock_t locking word differs, s390 needs to store
the logical CPU number of the lock holder in the spinlock_t to be able
to use the diagnose 9c directed yield hypervisor call.
The inline code sequences for spin_lock and spin_unlock are nice and
short. The inline portion of a spin_lock now typically looks like this:
lhi %r0,0 # 0 indicates an empty lock
l %r1,0x3a0 # CPU number + 1 from lowcore
cs %r0,%r1,<some_lock> # lock operation
jnz call_wait # on failure call wait function
locked:
...
call_wait:
la %r2,<some_lock>
brasl %r14,arch_spin_lock_wait
j locked
A spin_unlock is as simple as before:
lhi %r0,0
sth %r0,2(%r2) # unlock operation
After a CPU has queued itself it may not enable interrupts again for the
arch_spin_lock_flags() variant. The arch_spin_lock_wait_flags wait function
is removed.
To improve performance the code implements opportunistic lock stealing.
If the wait function finds a spinlock_t that indicates that the lock is
free but there are queued waiters, the CPU may steal the lock up to three
times without queueing itself. The lock stealing update the steal counter
in the lock word to prevent more than 3 steals. The counter is reset at
the time the CPU next in the queue successfully takes the lock.
While the queued spinlocks improve performance in a system with dedicated
CPUs, in a virtualized environment with continuously overcommitted CPUs
the queued spinlocks can have a negative effect on performance. This
is due to the fact that a queued CPU that is preempted by the hypervisor
will block the queue at some point even without holding the lock. With
the classic spinlock it does not matter if a CPU is preempted that waits
for the lock. Therefore use the queued spinlock code only if the system
runs with dedicated CPUs and fall back to classic spinlocks when running
with shared CPUs.
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
2017-03-25 00:25:02 +08:00
|
|
|
arch_spin_lock_setup(cpu);
|
2012-03-11 23:59:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void pcpu_attach_task(struct pcpu *pcpu, struct task_struct *tsk)
|
|
|
|
{
|
2021-05-06 22:26:54 +08:00
|
|
|
struct lowcore *lc;
|
|
|
|
int cpu;
|
2012-03-11 23:59:26 +08:00
|
|
|
|
2021-05-06 22:26:54 +08:00
|
|
|
cpu = pcpu - pcpu_devices;
|
|
|
|
lc = lowcore_ptr[cpu];
|
2013-04-24 16:20:43 +08:00
|
|
|
lc->kernel_stack = (unsigned long) task_stack_page(tsk)
|
|
|
|
+ THREAD_SIZE - STACK_FRAME_OVERHEAD - sizeof(struct pt_regs);
|
2012-03-11 23:59:26 +08:00
|
|
|
lc->current_task = (unsigned long) tsk;
|
2015-10-07 00:06:15 +08:00
|
|
|
lc->lpp = LPP_MAGIC;
|
|
|
|
lc->current_pid = tsk->pid;
|
2016-11-08 19:15:59 +08:00
|
|
|
lc->user_timer = tsk->thread.user_timer;
|
2017-10-04 20:46:17 +08:00
|
|
|
lc->guest_timer = tsk->thread.guest_timer;
|
2016-11-08 19:15:59 +08:00
|
|
|
lc->system_timer = tsk->thread.system_timer;
|
2017-10-04 20:46:17 +08:00
|
|
|
lc->hardirq_timer = tsk->thread.hardirq_timer;
|
|
|
|
lc->softirq_timer = tsk->thread.softirq_timer;
|
2012-03-11 23:59:26 +08:00
|
|
|
lc->steal_timer = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pcpu_start_fn(struct pcpu *pcpu, void (*func)(void *), void *data)
|
|
|
|
{
|
2021-05-06 22:26:54 +08:00
|
|
|
struct lowcore *lc;
|
|
|
|
int cpu;
|
2012-03-11 23:59:26 +08:00
|
|
|
|
2021-05-06 22:26:54 +08:00
|
|
|
cpu = pcpu - pcpu_devices;
|
|
|
|
lc = lowcore_ptr[cpu];
|
2017-09-12 22:37:33 +08:00
|
|
|
lc->restart_stack = lc->nodat_stack;
|
2012-03-11 23:59:26 +08:00
|
|
|
lc->restart_fn = (unsigned long) func;
|
|
|
|
lc->restart_data = (unsigned long) data;
|
|
|
|
lc->restart_source = -1UL;
|
2012-06-04 18:55:15 +08:00
|
|
|
pcpu_sigp_retry(pcpu, SIGP_RESTART, 0);
|
2012-03-11 23:59:26 +08:00
|
|
|
}
|
|
|
|
|
2021-07-06 02:38:36 +08:00
|
|
|
typedef void (pcpu_delegate_fn)(void *);
|
|
|
|
|
2012-03-11 23:59:26 +08:00
|
|
|
/*
|
|
|
|
* Call function via PSW restart on pcpu and stop the current cpu.
|
|
|
|
*/
|
2021-07-06 02:38:36 +08:00
|
|
|
static void __pcpu_delegate(pcpu_delegate_fn *func, void *data)
|
2017-09-12 22:37:33 +08:00
|
|
|
{
|
|
|
|
func(data); /* should not return */
|
|
|
|
}
|
|
|
|
|
2017-11-20 19:15:10 +08:00
|
|
|
static void __no_sanitize_address pcpu_delegate(struct pcpu *pcpu,
|
2021-07-06 02:38:36 +08:00
|
|
|
pcpu_delegate_fn *func,
|
2017-11-20 19:15:10 +08:00
|
|
|
void *data, unsigned long stack)
|
2012-03-11 23:59:26 +08:00
|
|
|
{
|
2015-12-31 17:29:00 +08:00
|
|
|
struct lowcore *lc = lowcore_ptr[pcpu - pcpu_devices];
|
2012-06-05 15:59:52 +08:00
|
|
|
unsigned long source_cpu = stap();
|
2012-03-11 23:59:26 +08:00
|
|
|
|
2017-09-12 22:37:33 +08:00
|
|
|
__load_psw_mask(PSW_KERNEL_BITS | PSW_MASK_DAT);
|
2021-07-06 02:38:36 +08:00
|
|
|
if (pcpu->address == source_cpu) {
|
|
|
|
call_on_stack(2, stack, void, __pcpu_delegate,
|
|
|
|
pcpu_delegate_fn *, func, void *, data);
|
|
|
|
}
|
2012-03-11 23:59:26 +08:00
|
|
|
/* Stop target cpu (if func returns this stops the current cpu). */
|
2012-06-04 18:55:15 +08:00
|
|
|
pcpu_sigp_retry(pcpu, SIGP_STOP, 0);
|
2012-03-11 23:59:26 +08:00
|
|
|
/* Restart func on the target cpu and stop the current cpu. */
|
2012-06-05 15:59:52 +08:00
|
|
|
mem_assign_absolute(lc->restart_stack, stack);
|
|
|
|
mem_assign_absolute(lc->restart_fn, (unsigned long) func);
|
|
|
|
mem_assign_absolute(lc->restart_data, (unsigned long) data);
|
|
|
|
mem_assign_absolute(lc->restart_source, source_cpu);
|
2018-01-16 14:11:45 +08:00
|
|
|
__bpon();
|
2012-03-11 23:59:26 +08:00
|
|
|
asm volatile(
|
2012-06-04 21:05:43 +08:00
|
|
|
"0: sigp 0,%0,%2 # sigp restart to target cpu\n"
|
2012-03-11 23:59:26 +08:00
|
|
|
" brc 2,0b # busy, try again\n"
|
2012-06-04 21:05:43 +08:00
|
|
|
"1: sigp 0,%1,%3 # sigp stop to current cpu\n"
|
2012-03-11 23:59:26 +08:00
|
|
|
" brc 2,1b # busy, try again\n"
|
2012-06-05 15:59:52 +08:00
|
|
|
: : "d" (pcpu->address), "d" (source_cpu),
|
2012-06-04 21:05:43 +08:00
|
|
|
"K" (SIGP_RESTART), "K" (SIGP_STOP)
|
|
|
|
: "0", "1", "cc");
|
2012-03-11 23:59:26 +08:00
|
|
|
for (;;) ;
|
|
|
|
}
|
|
|
|
|
2015-01-15 00:52:10 +08:00
|
|
|
/*
|
|
|
|
* Enable additional logical cpus for multi-threading.
|
|
|
|
*/
|
|
|
|
static int pcpu_set_smt(unsigned int mtid)
|
|
|
|
{
|
|
|
|
int cc;
|
|
|
|
|
|
|
|
if (smp_cpu_mtid == mtid)
|
|
|
|
return 0;
|
2016-06-20 20:04:17 +08:00
|
|
|
cc = __pcpu_sigp(0, SIGP_SET_MULTI_THREADING, mtid, NULL);
|
2015-01-15 00:52:10 +08:00
|
|
|
if (cc == 0) {
|
|
|
|
smp_cpu_mtid = mtid;
|
|
|
|
smp_cpu_mt_shift = 0;
|
|
|
|
while (smp_cpu_mtid >= (1U << smp_cpu_mt_shift))
|
|
|
|
smp_cpu_mt_shift++;
|
|
|
|
pcpu_devices[0].address = stap();
|
|
|
|
}
|
|
|
|
return cc;
|
|
|
|
}
|
|
|
|
|
2012-03-11 23:59:26 +08:00
|
|
|
/*
|
|
|
|
* Call function on an online CPU.
|
|
|
|
*/
|
|
|
|
void smp_call_online_cpu(void (*func)(void *), void *data)
|
|
|
|
{
|
|
|
|
struct pcpu *pcpu;
|
|
|
|
|
|
|
|
/* Use the current cpu if it is online. */
|
|
|
|
pcpu = pcpu_find_address(cpu_online_mask, stap());
|
|
|
|
if (!pcpu)
|
|
|
|
/* Use the first online cpu. */
|
|
|
|
pcpu = pcpu_devices + cpumask_first(cpu_online_mask);
|
|
|
|
pcpu_delegate(pcpu, func, data, (unsigned long) restart_stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call function on the ipl CPU.
|
|
|
|
*/
|
|
|
|
void smp_call_ipl_cpu(void (*func)(void *), void *data)
|
|
|
|
{
|
2021-05-06 22:26:54 +08:00
|
|
|
struct lowcore *lc = lowcore_ptr[0];
|
s390/smp: Fix calling smp_call_ipl_cpu() from ipl CPU
When calling smp_call_ipl_cpu() from the IPL CPU, we will try to read
from pcpu_devices->lowcore. However, due to prefixing, that will result
in reading from absolute address 0 on that CPU. We have to go via the
actual lowcore instead.
This means that right now, we will read lc->nodat_stack == 0 and
therfore work on a very wrong stack.
This BUG essentially broke rebooting under QEMU TCG (which will report
a low address protection exception). And checking under KVM, it is
also broken under KVM. With 1 VCPU it can be easily triggered.
:/# echo 1 > /proc/sys/kernel/sysrq
:/# echo b > /proc/sysrq-trigger
[ 28.476745] sysrq: SysRq : Resetting
[ 28.476793] Kernel stack overflow.
[ 28.476817] CPU: 0 PID: 424 Comm: sh Not tainted 5.0.0-rc1+ #13
[ 28.476820] Hardware name: IBM 2964 NE1 716 (KVM/Linux)
[ 28.476826] Krnl PSW : 0400c00180000000 0000000000115c0c (pcpu_delegate+0x12c/0x140)
[ 28.476861] R:0 T:1 IO:0 EX:0 Key:0 M:0 W:0 P:0 AS:3 CC:0 PM:0 RI:0 EA:3
[ 28.476863] Krnl GPRS: ffffffffffffffff 0000000000000000 000000000010dff8 0000000000000000
[ 28.476864] 0000000000000000 0000000000000000 0000000000ab7090 000003e0006efbf0
[ 28.476864] 000000000010dff8 0000000000000000 0000000000000000 0000000000000000
[ 28.476865] 000000007fffc000 0000000000730408 000003e0006efc58 0000000000000000
[ 28.476887] Krnl Code: 0000000000115bfe: 4170f000 la %r7,0(%r15)
[ 28.476887] 0000000000115c02: 41f0a000 la %r15,0(%r10)
[ 28.476887] #0000000000115c06: e370f0980024 stg %r7,152(%r15)
[ 28.476887] >0000000000115c0c: c0e5fffff86e brasl %r14,114ce8
[ 28.476887] 0000000000115c12: 41f07000 la %r15,0(%r7)
[ 28.476887] 0000000000115c16: a7f4ffa8 brc 15,115b66
[ 28.476887] 0000000000115c1a: 0707 bcr 0,%r7
[ 28.476887] 0000000000115c1c: 0707 bcr 0,%r7
[ 28.476901] Call Trace:
[ 28.476902] Last Breaking-Event-Address:
[ 28.476920] [<0000000000a01c4a>] arch_call_rest_init+0x22/0x80
[ 28.476927] Kernel panic - not syncing: Corrupt kernel stack, can't continue.
[ 28.476930] CPU: 0 PID: 424 Comm: sh Not tainted 5.0.0-rc1+ #13
[ 28.476932] Hardware name: IBM 2964 NE1 716 (KVM/Linux)
[ 28.476932] Call Trace:
Fixes: 2f859d0dad81 ("s390/smp: reduce size of struct pcpu")
Cc: stable@vger.kernel.org # 4.0+
Reported-by: Cornelia Huck <cohuck@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
2019-01-11 22:18:22 +08:00
|
|
|
|
|
|
|
if (pcpu_devices[0].address == stap())
|
|
|
|
lc = &S390_lowcore;
|
|
|
|
|
2012-03-13 23:25:08 +08:00
|
|
|
pcpu_delegate(&pcpu_devices[0], func, data,
|
s390/smp: Fix calling smp_call_ipl_cpu() from ipl CPU
When calling smp_call_ipl_cpu() from the IPL CPU, we will try to read
from pcpu_devices->lowcore. However, due to prefixing, that will result
in reading from absolute address 0 on that CPU. We have to go via the
actual lowcore instead.
This means that right now, we will read lc->nodat_stack == 0 and
therfore work on a very wrong stack.
This BUG essentially broke rebooting under QEMU TCG (which will report
a low address protection exception). And checking under KVM, it is
also broken under KVM. With 1 VCPU it can be easily triggered.
:/# echo 1 > /proc/sys/kernel/sysrq
:/# echo b > /proc/sysrq-trigger
[ 28.476745] sysrq: SysRq : Resetting
[ 28.476793] Kernel stack overflow.
[ 28.476817] CPU: 0 PID: 424 Comm: sh Not tainted 5.0.0-rc1+ #13
[ 28.476820] Hardware name: IBM 2964 NE1 716 (KVM/Linux)
[ 28.476826] Krnl PSW : 0400c00180000000 0000000000115c0c (pcpu_delegate+0x12c/0x140)
[ 28.476861] R:0 T:1 IO:0 EX:0 Key:0 M:0 W:0 P:0 AS:3 CC:0 PM:0 RI:0 EA:3
[ 28.476863] Krnl GPRS: ffffffffffffffff 0000000000000000 000000000010dff8 0000000000000000
[ 28.476864] 0000000000000000 0000000000000000 0000000000ab7090 000003e0006efbf0
[ 28.476864] 000000000010dff8 0000000000000000 0000000000000000 0000000000000000
[ 28.476865] 000000007fffc000 0000000000730408 000003e0006efc58 0000000000000000
[ 28.476887] Krnl Code: 0000000000115bfe: 4170f000 la %r7,0(%r15)
[ 28.476887] 0000000000115c02: 41f0a000 la %r15,0(%r10)
[ 28.476887] #0000000000115c06: e370f0980024 stg %r7,152(%r15)
[ 28.476887] >0000000000115c0c: c0e5fffff86e brasl %r14,114ce8
[ 28.476887] 0000000000115c12: 41f07000 la %r15,0(%r7)
[ 28.476887] 0000000000115c16: a7f4ffa8 brc 15,115b66
[ 28.476887] 0000000000115c1a: 0707 bcr 0,%r7
[ 28.476887] 0000000000115c1c: 0707 bcr 0,%r7
[ 28.476901] Call Trace:
[ 28.476902] Last Breaking-Event-Address:
[ 28.476920] [<0000000000a01c4a>] arch_call_rest_init+0x22/0x80
[ 28.476927] Kernel panic - not syncing: Corrupt kernel stack, can't continue.
[ 28.476930] CPU: 0 PID: 424 Comm: sh Not tainted 5.0.0-rc1+ #13
[ 28.476932] Hardware name: IBM 2964 NE1 716 (KVM/Linux)
[ 28.476932] Call Trace:
Fixes: 2f859d0dad81 ("s390/smp: reduce size of struct pcpu")
Cc: stable@vger.kernel.org # 4.0+
Reported-by: Cornelia Huck <cohuck@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
2019-01-11 22:18:22 +08:00
|
|
|
lc->nodat_stack);
|
2012-03-11 23:59:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int smp_find_processor_id(u16 address)
|
|
|
|
{
|
|
|
|
int cpu;
|
|
|
|
|
|
|
|
for_each_present_cpu(cpu)
|
|
|
|
if (pcpu_devices[cpu].address == address)
|
|
|
|
return cpu;
|
|
|
|
return -1;
|
2010-02-27 05:37:34 +08:00
|
|
|
}
|
|
|
|
|
2020-03-17 20:37:49 +08:00
|
|
|
void schedule_mcck_handler(void)
|
|
|
|
{
|
|
|
|
pcpu_ec_call(pcpu_devices + smp_processor_id(), ec_mcck_pending);
|
|
|
|
}
|
|
|
|
|
2020-04-06 20:47:48 +08:00
|
|
|
bool notrace arch_vcpu_is_preempted(int cpu)
|
2011-12-27 18:27:22 +08:00
|
|
|
{
|
2016-11-02 17:08:32 +08:00
|
|
|
if (test_cpu_flag_of(CIF_ENABLED_WAIT, cpu))
|
|
|
|
return false;
|
|
|
|
if (pcpu_running(pcpu_devices + cpu))
|
|
|
|
return false;
|
|
|
|
return true;
|
2012-03-11 23:59:26 +08:00
|
|
|
}
|
2016-11-02 17:08:32 +08:00
|
|
|
EXPORT_SYMBOL(arch_vcpu_is_preempted);
|
2012-03-11 23:59:26 +08:00
|
|
|
|
2020-04-06 20:47:48 +08:00
|
|
|
void notrace smp_yield_cpu(int cpu)
|
2011-12-27 18:27:22 +08:00
|
|
|
{
|
2019-11-29 19:59:59 +08:00
|
|
|
if (!MACHINE_HAS_DIAG9C)
|
|
|
|
return;
|
|
|
|
diag_stat_inc_norecursion(DIAG_STAT_X09C);
|
|
|
|
asm volatile("diag %0,0,0x9c"
|
|
|
|
: : "d" (pcpu_devices[cpu].address));
|
2012-03-11 23:59:26 +08:00
|
|
|
}
|
2020-09-07 21:26:07 +08:00
|
|
|
EXPORT_SYMBOL_GPL(smp_yield_cpu);
|
2012-03-11 23:59:26 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Send cpus emergency shutdown signal. This gives the cpus the
|
|
|
|
* opportunity to complete outstanding interrupts.
|
|
|
|
*/
|
2017-09-15 22:24:31 +08:00
|
|
|
void notrace smp_emergency_stop(void)
|
2012-03-11 23:59:26 +08:00
|
|
|
{
|
2021-02-17 14:19:09 +08:00
|
|
|
static arch_spinlock_t lock = __ARCH_SPIN_LOCK_UNLOCKED;
|
|
|
|
static cpumask_t cpumask;
|
2012-03-11 23:59:26 +08:00
|
|
|
u64 end;
|
|
|
|
int cpu;
|
|
|
|
|
2021-02-17 14:19:09 +08:00
|
|
|
arch_spin_lock(&lock);
|
2017-09-15 22:24:31 +08:00
|
|
|
cpumask_copy(&cpumask, cpu_online_mask);
|
|
|
|
cpumask_clear_cpu(smp_processor_id(), &cpumask);
|
|
|
|
|
2013-01-30 16:49:40 +08:00
|
|
|
end = get_tod_clock() + (1000000UL << 12);
|
2017-09-15 22:24:31 +08:00
|
|
|
for_each_cpu(cpu, &cpumask) {
|
2012-03-11 23:59:26 +08:00
|
|
|
struct pcpu *pcpu = pcpu_devices + cpu;
|
|
|
|
set_bit(ec_stop_cpu, &pcpu->ec_mask);
|
2012-06-04 18:55:15 +08:00
|
|
|
while (__pcpu_sigp(pcpu->address, SIGP_EMERGENCY_SIGNAL,
|
|
|
|
0, NULL) == SIGP_CC_BUSY &&
|
2013-01-30 16:49:40 +08:00
|
|
|
get_tod_clock() < end)
|
2012-03-11 23:59:26 +08:00
|
|
|
cpu_relax();
|
|
|
|
}
|
2013-01-30 16:49:40 +08:00
|
|
|
while (get_tod_clock() < end) {
|
2017-09-15 22:24:31 +08:00
|
|
|
for_each_cpu(cpu, &cpumask)
|
2012-03-11 23:59:26 +08:00
|
|
|
if (pcpu_stopped(pcpu_devices + cpu))
|
2017-09-15 22:24:31 +08:00
|
|
|
cpumask_clear_cpu(cpu, &cpumask);
|
|
|
|
if (cpumask_empty(&cpumask))
|
2012-03-11 23:59:26 +08:00
|
|
|
break;
|
2011-12-27 18:27:22 +08:00
|
|
|
cpu_relax();
|
2012-03-11 23:59:26 +08:00
|
|
|
}
|
2021-02-17 14:19:09 +08:00
|
|
|
arch_spin_unlock(&lock);
|
2011-12-27 18:27:22 +08:00
|
|
|
}
|
2017-09-15 22:24:31 +08:00
|
|
|
NOKPROBE_SYMBOL(smp_emergency_stop);
|
2011-12-27 18:27:22 +08:00
|
|
|
|
2012-03-11 23:59:26 +08:00
|
|
|
/*
|
|
|
|
* Stop all cpus but the current one.
|
|
|
|
*/
|
2007-11-20 18:13:37 +08:00
|
|
|
void smp_send_stop(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2011-12-27 18:27:22 +08:00
|
|
|
int cpu;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-11-20 18:13:37 +08:00
|
|
|
/* Disable all interrupts/machine checks */
|
2013-09-24 15:14:56 +08:00
|
|
|
__load_psw_mask(PSW_KERNEL_BITS | PSW_MASK_DAT);
|
2009-03-26 22:23:56 +08:00
|
|
|
trace_hardirqs_off();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-11 23:59:32 +08:00
|
|
|
debug_set_critical();
|
2011-12-27 18:27:22 +08:00
|
|
|
|
2012-03-11 23:59:26 +08:00
|
|
|
if (oops_in_progress)
|
2017-09-15 22:24:31 +08:00
|
|
|
smp_emergency_stop();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-12-27 18:27:22 +08:00
|
|
|
/* stop all processors */
|
2017-09-15 22:24:31 +08:00
|
|
|
for_each_online_cpu(cpu) {
|
|
|
|
if (cpu == smp_processor_id())
|
|
|
|
continue;
|
|
|
|
pcpu_sigp_retry(pcpu_devices + cpu, SIGP_STOP, 0);
|
|
|
|
while (!pcpu_stopped(pcpu_devices + cpu))
|
2006-12-04 22:40:33 +08:00
|
|
|
cpu_relax();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* This is the main routine where commands issued by other
|
|
|
|
* cpus are handled.
|
|
|
|
*/
|
2013-05-22 16:24:37 +08:00
|
|
|
static void smp_handle_ext_call(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-04-27 22:02:00 +08:00
|
|
|
unsigned long bits;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-05-22 16:24:37 +08:00
|
|
|
/* handle bit signal external calls */
|
|
|
|
bits = xchg(&pcpu_devices[smp_processor_id()].ec_mask, 0);
|
2011-12-27 18:27:22 +08:00
|
|
|
if (test_bit(ec_stop_cpu, &bits))
|
|
|
|
smp_stop_cpu();
|
2011-04-05 23:23:39 +08:00
|
|
|
if (test_bit(ec_schedule, &bits))
|
|
|
|
scheduler_ipi();
|
2008-12-25 20:38:39 +08:00
|
|
|
if (test_bit(ec_call_function_single, &bits))
|
|
|
|
generic_smp_call_function_single_interrupt();
|
2020-03-17 20:37:49 +08:00
|
|
|
if (test_bit(ec_mcck_pending, &bits))
|
2020-11-21 18:14:56 +08:00
|
|
|
__s390_handle_mcck();
|
2021-02-20 06:32:56 +08:00
|
|
|
if (test_bit(ec_irq_work, &bits))
|
|
|
|
irq_work_run();
|
2013-05-22 16:24:37 +08:00
|
|
|
}
|
2011-12-27 18:27:22 +08:00
|
|
|
|
2013-05-22 16:24:37 +08:00
|
|
|
static void do_ext_call_interrupt(struct ext_code ext_code,
|
|
|
|
unsigned int param32, unsigned long param64)
|
|
|
|
{
|
|
|
|
inc_irq_stat(ext_code.code == 0x1202 ? IRQEXT_EXC : IRQEXT_EMS);
|
|
|
|
smp_handle_ext_call();
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-09-24 23:34:45 +08:00
|
|
|
void arch_send_call_function_ipi_mask(const struct cpumask *mask)
|
2008-12-25 20:38:39 +08:00
|
|
|
{
|
|
|
|
int cpu;
|
|
|
|
|
2009-09-24 23:34:45 +08:00
|
|
|
for_each_cpu(cpu, mask)
|
2013-05-21 21:34:56 +08:00
|
|
|
pcpu_ec_call(pcpu_devices + cpu, ec_call_function_single);
|
2008-12-25 20:38:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void arch_send_call_function_single_ipi(int cpu)
|
|
|
|
{
|
2012-03-11 23:59:26 +08:00
|
|
|
pcpu_ec_call(pcpu_devices + cpu, ec_call_function_single);
|
2008-12-25 20:38:39 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* this function sends a 'reschedule' IPI to another CPU.
|
|
|
|
* it goes straight through and wastes no time serializing
|
|
|
|
* anything. Worst case is that we lose a reschedule ...
|
|
|
|
*/
|
|
|
|
void smp_send_reschedule(int cpu)
|
|
|
|
{
|
2012-03-11 23:59:26 +08:00
|
|
|
pcpu_ec_call(pcpu_devices + cpu, ec_schedule);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2021-02-20 06:32:56 +08:00
|
|
|
#ifdef CONFIG_IRQ_WORK
|
|
|
|
void arch_irq_work_raise(void)
|
|
|
|
{
|
|
|
|
pcpu_ec_call(pcpu_devices + smp_processor_id(), ec_irq_work);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* parameter area for the set/clear control bit callbacks
|
|
|
|
*/
|
2006-09-28 22:56:43 +08:00
|
|
|
struct ec_creg_mask_parms {
|
2012-03-11 23:59:26 +08:00
|
|
|
unsigned long orval;
|
|
|
|
unsigned long andval;
|
|
|
|
int cr;
|
2006-09-28 22:56:43 +08:00
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* callback for setting/clearing control bits
|
|
|
|
*/
|
2007-04-27 22:02:00 +08:00
|
|
|
static void smp_ctl_bit_callback(void *info)
|
|
|
|
{
|
2006-09-28 22:56:43 +08:00
|
|
|
struct ec_creg_mask_parms *pp = info;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long cregs[16];
|
2007-04-27 22:02:00 +08:00
|
|
|
|
2006-09-28 22:56:43 +08:00
|
|
|
__ctl_store(cregs, 0, 15);
|
2012-03-11 23:59:26 +08:00
|
|
|
cregs[pp->cr] = (cregs[pp->cr] & pp->andval) | pp->orval;
|
2006-09-28 22:56:43 +08:00
|
|
|
__ctl_load(cregs, 0, 15);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set a bit in a control register of all cpus
|
|
|
|
*/
|
2006-09-28 22:56:43 +08:00
|
|
|
void smp_ctl_set_bit(int cr, int bit)
|
|
|
|
{
|
2012-03-11 23:59:26 +08:00
|
|
|
struct ec_creg_mask_parms parms = { 1UL << bit, -1UL, cr };
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-05-09 15:39:44 +08:00
|
|
|
on_each_cpu(smp_ctl_bit_callback, &parms, 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-04-27 22:02:00 +08:00
|
|
|
EXPORT_SYMBOL(smp_ctl_set_bit);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear a bit in a control register of all cpus
|
|
|
|
*/
|
2006-09-28 22:56:43 +08:00
|
|
|
void smp_ctl_clear_bit(int cr, int bit)
|
|
|
|
{
|
2012-03-11 23:59:26 +08:00
|
|
|
struct ec_creg_mask_parms parms = { 0, ~(1UL << bit), cr };
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-05-09 15:39:44 +08:00
|
|
|
on_each_cpu(smp_ctl_bit_callback, &parms, 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-04-27 22:02:00 +08:00
|
|
|
EXPORT_SYMBOL(smp_ctl_clear_bit);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-04-14 16:38:05 +08:00
|
|
|
#ifdef CONFIG_CRASH_DUMP
|
2007-04-27 22:01:49 +08:00
|
|
|
|
2015-06-26 18:10:49 +08:00
|
|
|
int smp_store_status(int cpu)
|
|
|
|
{
|
2021-05-06 22:26:54 +08:00
|
|
|
struct lowcore *lc;
|
|
|
|
struct pcpu *pcpu;
|
2015-10-29 17:28:26 +08:00
|
|
|
unsigned long pa;
|
2015-06-26 18:10:49 +08:00
|
|
|
|
2021-05-06 22:26:54 +08:00
|
|
|
pcpu = pcpu_devices + cpu;
|
|
|
|
lc = lowcore_ptr[cpu];
|
|
|
|
pa = __pa(&lc->floating_pt_save_area);
|
2015-10-29 17:28:26 +08:00
|
|
|
if (__pcpu_sigp_relax(pcpu->address, SIGP_STORE_STATUS_AT_ADDRESS,
|
|
|
|
pa) != SIGP_CC_ORDER_CODE_ACCEPTED)
|
2015-06-26 18:10:49 +08:00
|
|
|
return -EIO;
|
2016-01-26 21:10:34 +08:00
|
|
|
if (!MACHINE_HAS_VX && !MACHINE_HAS_GS)
|
2015-06-26 18:10:49 +08:00
|
|
|
return 0;
|
2021-05-06 22:26:54 +08:00
|
|
|
pa = __pa(lc->mcesad & MCESA_ORIGIN_MASK);
|
2016-01-26 21:10:34 +08:00
|
|
|
if (MACHINE_HAS_GS)
|
2021-05-06 22:26:54 +08:00
|
|
|
pa |= lc->mcesad & MCESA_LC_MASK;
|
2015-10-29 17:28:26 +08:00
|
|
|
if (__pcpu_sigp_relax(pcpu->address, SIGP_STORE_ADDITIONAL_STATUS,
|
|
|
|
pa) != SIGP_CC_ORDER_CODE_ACCEPTED)
|
|
|
|
return -EIO;
|
2015-06-26 18:10:49 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-15 00:52:10 +08:00
|
|
|
/*
|
|
|
|
* Collect CPU state of the previous, crashed system.
|
|
|
|
* There are four cases:
|
2020-09-30 02:24:55 +08:00
|
|
|
* 1) standard zfcp/nvme dump
|
|
|
|
* condition: OLDMEM_BASE == NULL && is_ipl_type_dump() == true
|
2015-01-15 00:52:10 +08:00
|
|
|
* The state for all CPUs except the boot CPU needs to be collected
|
|
|
|
* with sigp stop-and-store-status. The boot CPU state is located in
|
|
|
|
* the absolute lowcore of the memory stored in the HSA. The zcore code
|
2015-10-29 17:28:26 +08:00
|
|
|
* will copy the boot CPU state from the HSA.
|
2020-09-30 02:24:55 +08:00
|
|
|
* 2) stand-alone kdump for SCSI/NVMe (zfcp/nvme dump with swapped memory)
|
|
|
|
* condition: OLDMEM_BASE != NULL && is_ipl_type_dump() == true
|
2015-01-15 00:52:10 +08:00
|
|
|
* The state for all CPUs except the boot CPU needs to be collected
|
|
|
|
* with sigp stop-and-store-status. The firmware or the boot-loader
|
|
|
|
* stored the registers of the boot CPU in the absolute lowcore in the
|
|
|
|
* memory of the old system.
|
|
|
|
* 3) kdump and the old kernel did not store the CPU state,
|
|
|
|
* or stand-alone kdump for DASD
|
|
|
|
* condition: OLDMEM_BASE != NULL && !is_kdump_kernel()
|
|
|
|
* The state for all CPUs except the boot CPU needs to be collected
|
|
|
|
* with sigp stop-and-store-status. The kexec code or the boot-loader
|
|
|
|
* stored the registers of the boot CPU in the memory of the old system.
|
|
|
|
* 4) kdump and the old kernel stored the CPU state
|
|
|
|
* condition: OLDMEM_BASE != NULL && is_kdump_kernel()
|
2015-10-14 21:53:06 +08:00
|
|
|
* This case does not exist for s390 anymore, setup_arch explicitly
|
|
|
|
* deactivates the elfcorehdr= kernel parameter
|
2015-01-15 00:52:10 +08:00
|
|
|
*/
|
2015-10-29 17:59:15 +08:00
|
|
|
static __init void smp_save_cpu_vxrs(struct save_area *sa, u16 addr,
|
2015-10-29 17:28:26 +08:00
|
|
|
bool is_boot_cpu, unsigned long page)
|
|
|
|
{
|
|
|
|
__vector128 *vxrs = (__vector128 *) page;
|
|
|
|
|
|
|
|
if (is_boot_cpu)
|
|
|
|
vxrs = boot_cpu_vector_save_area;
|
|
|
|
else
|
|
|
|
__pcpu_sigp_relax(addr, SIGP_STORE_ADDITIONAL_STATUS, page);
|
2015-10-29 17:59:15 +08:00
|
|
|
save_area_add_vxrs(sa, vxrs);
|
2015-10-29 17:28:26 +08:00
|
|
|
}
|
|
|
|
|
2015-10-29 17:59:15 +08:00
|
|
|
static __init void smp_save_cpu_regs(struct save_area *sa, u16 addr,
|
2015-10-29 17:28:26 +08:00
|
|
|
bool is_boot_cpu, unsigned long page)
|
|
|
|
{
|
|
|
|
void *regs = (void *) page;
|
|
|
|
|
|
|
|
if (is_boot_cpu)
|
|
|
|
copy_oldmem_kernel(regs, (void *) __LC_FPREGS_SAVE_AREA, 512);
|
|
|
|
else
|
|
|
|
__pcpu_sigp_relax(addr, SIGP_STORE_STATUS_AT_ADDRESS, page);
|
2015-10-29 17:59:15 +08:00
|
|
|
save_area_add_regs(sa, regs);
|
2015-10-29 17:28:26 +08:00
|
|
|
}
|
|
|
|
|
2015-05-27 01:05:23 +08:00
|
|
|
void __init smp_save_dump_cpus(void)
|
2015-01-15 00:52:10 +08:00
|
|
|
{
|
2015-10-29 17:59:15 +08:00
|
|
|
int addr, boot_cpu_addr, max_cpu_addr;
|
|
|
|
struct save_area *sa;
|
2015-10-29 17:28:26 +08:00
|
|
|
unsigned long page;
|
2015-05-27 01:05:23 +08:00
|
|
|
bool is_boot_cpu;
|
2015-01-15 00:52:10 +08:00
|
|
|
|
2020-09-30 02:24:55 +08:00
|
|
|
if (!(OLDMEM_BASE || is_ipl_type_dump()))
|
2015-01-15 00:52:10 +08:00
|
|
|
/* No previous system present, normal boot. */
|
|
|
|
return;
|
2015-10-29 17:28:26 +08:00
|
|
|
/* Allocate a page as dumping area for the store status sigps */
|
2019-03-12 14:29:35 +08:00
|
|
|
page = memblock_phys_alloc_range(PAGE_SIZE, PAGE_SIZE, 0, 1UL << 31);
|
|
|
|
if (!page)
|
2019-03-12 14:30:31 +08:00
|
|
|
panic("ERROR: Failed to allocate %lx bytes below %lx\n",
|
2019-03-12 14:29:35 +08:00
|
|
|
PAGE_SIZE, 1UL << 31);
|
|
|
|
|
2015-01-15 00:52:10 +08:00
|
|
|
/* Set multi-threading state to the previous system. */
|
2015-05-06 19:18:59 +08:00
|
|
|
pcpu_set_smt(sclp.mtid_prev);
|
2015-05-27 01:05:23 +08:00
|
|
|
boot_cpu_addr = stap();
|
2015-10-29 17:59:15 +08:00
|
|
|
max_cpu_addr = SCLP_MAX_CORES << sclp.mtid_prev;
|
|
|
|
for (addr = 0; addr <= max_cpu_addr; addr++) {
|
2015-10-29 17:28:26 +08:00
|
|
|
if (__pcpu_sigp_relax(addr, SIGP_SENSE, 0) ==
|
2015-05-27 01:05:23 +08:00
|
|
|
SIGP_CC_NOT_OPERATIONAL)
|
|
|
|
continue;
|
|
|
|
is_boot_cpu = (addr == boot_cpu_addr);
|
2015-10-29 17:59:15 +08:00
|
|
|
/* Allocate save area */
|
|
|
|
sa = save_area_alloc(is_boot_cpu);
|
|
|
|
if (!sa)
|
|
|
|
panic("could not allocate memory for save area\n");
|
2015-10-29 17:28:26 +08:00
|
|
|
if (MACHINE_HAS_VX)
|
|
|
|
/* Get the vector registers */
|
2015-10-29 17:59:15 +08:00
|
|
|
smp_save_cpu_vxrs(sa, addr, is_boot_cpu, page);
|
2015-10-29 17:28:26 +08:00
|
|
|
/*
|
2020-09-30 02:24:55 +08:00
|
|
|
* For a zfcp/nvme dump OLDMEM_BASE == NULL and the registers
|
2015-10-29 17:28:26 +08:00
|
|
|
* of the boot CPU are stored in the HSA. To retrieve
|
|
|
|
* these registers an SCLP request is required which is
|
|
|
|
* done by drivers/s390/char/zcore.c:init_cpu_info()
|
|
|
|
*/
|
|
|
|
if (!is_boot_cpu || OLDMEM_BASE)
|
|
|
|
/* Get the CPU registers */
|
2015-10-29 17:59:15 +08:00
|
|
|
smp_save_cpu_regs(sa, addr, is_boot_cpu, page);
|
2015-01-15 00:52:10 +08:00
|
|
|
}
|
2015-10-29 17:28:26 +08:00
|
|
|
memblock_free(page, PAGE_SIZE);
|
2019-02-04 04:37:20 +08:00
|
|
|
diag_dma_ops.diag308_reset();
|
2015-05-27 01:05:23 +08:00
|
|
|
pcpu_set_smt(0);
|
2015-06-26 18:10:49 +08:00
|
|
|
}
|
2015-10-29 17:28:26 +08:00
|
|
|
#endif /* CONFIG_CRASH_DUMP */
|
2008-01-26 21:10:56 +08:00
|
|
|
|
2012-09-04 23:36:16 +08:00
|
|
|
void smp_cpu_set_polarization(int cpu, int val)
|
|
|
|
{
|
|
|
|
pcpu_devices[cpu].polarization = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
int smp_cpu_get_polarization(int cpu)
|
|
|
|
{
|
|
|
|
return pcpu_devices[cpu].polarization;
|
|
|
|
}
|
|
|
|
|
2020-03-11 21:18:05 +08:00
|
|
|
int smp_cpu_get_cpu_address(int cpu)
|
|
|
|
{
|
|
|
|
return pcpu_devices[cpu].address;
|
|
|
|
}
|
|
|
|
|
2016-12-03 16:48:01 +08:00
|
|
|
static void __ref smp_get_core_info(struct sclp_core_info *info, int early)
|
2008-01-26 21:10:56 +08:00
|
|
|
{
|
2012-03-11 23:59:26 +08:00
|
|
|
static int use_sigp_detection;
|
|
|
|
int address;
|
|
|
|
|
2016-12-03 16:48:01 +08:00
|
|
|
if (use_sigp_detection || sclp_get_core_info(info, early)) {
|
2012-03-11 23:59:26 +08:00
|
|
|
use_sigp_detection = 1;
|
2015-06-17 16:45:31 +08:00
|
|
|
for (address = 0;
|
2015-06-18 20:23:00 +08:00
|
|
|
address < (SCLP_MAX_CORES << smp_cpu_mt_shift);
|
2015-01-15 00:52:10 +08:00
|
|
|
address += (1U << smp_cpu_mt_shift)) {
|
2015-10-29 17:28:26 +08:00
|
|
|
if (__pcpu_sigp_relax(address, SIGP_SENSE, 0) ==
|
2012-06-04 18:55:15 +08:00
|
|
|
SIGP_CC_NOT_OPERATIONAL)
|
2012-03-11 23:59:26 +08:00
|
|
|
continue;
|
2015-06-18 20:23:00 +08:00
|
|
|
info->core[info->configured].core_id =
|
2015-01-15 00:52:10 +08:00
|
|
|
address >> smp_cpu_mt_shift;
|
2012-03-11 23:59:26 +08:00
|
|
|
info->configured++;
|
|
|
|
}
|
|
|
|
info->combined = info->configured;
|
2008-01-26 21:10:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-19 05:04:52 +08:00
|
|
|
static int smp_add_present_cpu(int cpu);
|
2012-03-11 23:59:26 +08:00
|
|
|
|
2019-11-17 21:55:38 +08:00
|
|
|
static int smp_add_core(struct sclp_core_entry *core, cpumask_t *avail,
|
|
|
|
bool configured, bool early)
|
2008-01-26 21:10:56 +08:00
|
|
|
{
|
2012-03-11 23:59:26 +08:00
|
|
|
struct pcpu *pcpu;
|
2019-11-17 21:55:38 +08:00
|
|
|
int cpu, nr, i;
|
2015-01-15 00:52:10 +08:00
|
|
|
u16 address;
|
2008-01-26 21:10:56 +08:00
|
|
|
|
2012-03-11 23:59:26 +08:00
|
|
|
nr = 0;
|
2019-11-17 21:55:38 +08:00
|
|
|
if (sclp.has_core_type && core->type != boot_core_type)
|
|
|
|
return nr;
|
|
|
|
cpu = cpumask_first(avail);
|
|
|
|
address = core->core_id << smp_cpu_mt_shift;
|
|
|
|
for (i = 0; (i <= smp_cpu_mtid) && (cpu < nr_cpu_ids); i++) {
|
|
|
|
if (pcpu_find_address(cpu_present_mask, address + i))
|
2012-03-11 23:59:26 +08:00
|
|
|
continue;
|
2019-11-17 21:55:38 +08:00
|
|
|
pcpu = pcpu_devices + cpu;
|
|
|
|
pcpu->address = address + i;
|
|
|
|
if (configured)
|
|
|
|
pcpu->state = CPU_STATE_CONFIGURED;
|
|
|
|
else
|
|
|
|
pcpu->state = CPU_STATE_STANDBY;
|
|
|
|
smp_cpu_set_polarization(cpu, POLARIZATION_UNKNOWN);
|
|
|
|
set_cpu_present(cpu, true);
|
|
|
|
if (!early && smp_add_present_cpu(cpu) != 0)
|
|
|
|
set_cpu_present(cpu, false);
|
|
|
|
else
|
|
|
|
nr++;
|
|
|
|
cpumask_clear_cpu(cpu, avail);
|
|
|
|
cpu = cpumask_next(cpu, avail);
|
|
|
|
}
|
|
|
|
return nr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __smp_rescan_cpus(struct sclp_core_info *info, bool early)
|
|
|
|
{
|
|
|
|
struct sclp_core_entry *core;
|
2021-02-17 14:13:02 +08:00
|
|
|
static cpumask_t avail;
|
2019-11-17 21:55:38 +08:00
|
|
|
bool configured;
|
|
|
|
u16 core_id;
|
|
|
|
int nr, i;
|
|
|
|
|
2021-02-17 14:10:46 +08:00
|
|
|
get_online_cpus();
|
|
|
|
mutex_lock(&smp_cpu_state_mutex);
|
2019-11-17 21:55:38 +08:00
|
|
|
nr = 0;
|
|
|
|
cpumask_xor(&avail, cpu_possible_mask, cpu_present_mask);
|
|
|
|
/*
|
|
|
|
* Add IPL core first (which got logical CPU number 0) to make sure
|
|
|
|
* that all SMT threads get subsequent logical CPU numbers.
|
|
|
|
*/
|
|
|
|
if (early) {
|
|
|
|
core_id = pcpu_devices[0].address >> smp_cpu_mt_shift;
|
|
|
|
for (i = 0; i < info->configured; i++) {
|
|
|
|
core = &info->core[i];
|
|
|
|
if (core->core_id == core_id) {
|
|
|
|
nr += smp_add_core(core, &avail, true, early);
|
2015-01-15 00:52:10 +08:00
|
|
|
break;
|
2019-11-17 21:55:38 +08:00
|
|
|
}
|
2015-01-15 00:52:10 +08:00
|
|
|
}
|
2012-03-11 23:59:26 +08:00
|
|
|
}
|
2019-11-17 21:55:38 +08:00
|
|
|
for (i = 0; i < info->combined; i++) {
|
|
|
|
configured = i < info->configured;
|
|
|
|
nr += smp_add_core(&info->core[i], &avail, configured, early);
|
|
|
|
}
|
2021-02-17 14:10:46 +08:00
|
|
|
mutex_unlock(&smp_cpu_state_mutex);
|
|
|
|
put_online_cpus();
|
2012-03-11 23:59:26 +08:00
|
|
|
return nr;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2016-12-03 16:48:01 +08:00
|
|
|
void __init smp_detect_cpus(void)
|
2008-01-26 21:11:05 +08:00
|
|
|
{
|
2015-01-15 00:52:10 +08:00
|
|
|
unsigned int cpu, mtid, c_cpus, s_cpus;
|
2015-06-18 20:23:00 +08:00
|
|
|
struct sclp_core_info *info;
|
2015-01-15 00:52:10 +08:00
|
|
|
u16 address;
|
2008-01-26 21:11:05 +08:00
|
|
|
|
2015-01-15 00:52:10 +08:00
|
|
|
/* Get CPU information */
|
2018-10-31 06:08:04 +08:00
|
|
|
info = memblock_alloc(sizeof(*info), 8);
|
2019-03-12 14:30:31 +08:00
|
|
|
if (!info)
|
|
|
|
panic("%s: Failed to allocate %zu bytes align=0x%x\n",
|
|
|
|
__func__, sizeof(*info), 8);
|
2016-12-03 16:48:01 +08:00
|
|
|
smp_get_core_info(info, 1);
|
2015-01-15 00:52:10 +08:00
|
|
|
/* Find boot CPU type */
|
2015-06-18 20:23:00 +08:00
|
|
|
if (sclp.has_core_type) {
|
2015-01-15 00:52:10 +08:00
|
|
|
address = stap();
|
|
|
|
for (cpu = 0; cpu < info->combined; cpu++)
|
2015-06-18 20:23:00 +08:00
|
|
|
if (info->core[cpu].core_id == address) {
|
2015-01-15 00:52:10 +08:00
|
|
|
/* The boot cpu dictates the cpu type. */
|
2015-06-18 20:23:00 +08:00
|
|
|
boot_core_type = info->core[cpu].type;
|
2015-01-15 00:52:10 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (cpu >= info->combined)
|
|
|
|
panic("Could not find boot CPU type");
|
2008-01-26 21:11:05 +08:00
|
|
|
}
|
2015-01-15 00:52:10 +08:00
|
|
|
|
|
|
|
/* Set multi-threading state for the current system */
|
2015-06-18 20:23:00 +08:00
|
|
|
mtid = boot_core_type ? sclp.mtid : sclp.mtid_cp;
|
2015-01-15 00:52:10 +08:00
|
|
|
mtid = (mtid < smp_max_threads) ? mtid : smp_max_threads - 1;
|
|
|
|
pcpu_set_smt(mtid);
|
|
|
|
|
|
|
|
/* Print number of CPUs */
|
2012-03-11 23:59:26 +08:00
|
|
|
c_cpus = s_cpus = 0;
|
2008-01-26 21:11:05 +08:00
|
|
|
for (cpu = 0; cpu < info->combined; cpu++) {
|
2015-06-18 20:23:00 +08:00
|
|
|
if (sclp.has_core_type &&
|
|
|
|
info->core[cpu].type != boot_core_type)
|
2008-01-26 21:11:05 +08:00
|
|
|
continue;
|
2015-01-15 00:52:10 +08:00
|
|
|
if (cpu < info->configured)
|
|
|
|
c_cpus += smp_cpu_mtid + 1;
|
|
|
|
else
|
|
|
|
s_cpus += smp_cpu_mtid + 1;
|
2008-01-26 21:11:05 +08:00
|
|
|
}
|
2008-12-25 20:39:50 +08:00
|
|
|
pr_info("%d configured CPUs, %d standby CPUs\n", c_cpus, s_cpus);
|
2015-01-15 00:52:10 +08:00
|
|
|
|
|
|
|
/* Add CPUs present at boot */
|
2019-11-17 21:55:38 +08:00
|
|
|
__smp_rescan_cpus(info, true);
|
2016-12-03 16:48:01 +08:00
|
|
|
memblock_free_early((unsigned long)info, sizeof(*info));
|
2008-01-26 21:11:05 +08:00
|
|
|
}
|
|
|
|
|
2017-09-12 22:37:33 +08:00
|
|
|
static void smp_init_secondary(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2020-10-29 02:27:42 +08:00
|
|
|
int cpu = raw_smp_processor_id();
|
2017-09-22 20:17:41 +08:00
|
|
|
|
2017-11-20 19:13:52 +08:00
|
|
|
S390_lowcore.last_update_clock = get_tod_clock();
|
|
|
|
restore_access_regs(S390_lowcore.access_regs_save_area);
|
2007-04-27 22:02:00 +08:00
|
|
|
cpu_init();
|
2020-10-29 02:27:42 +08:00
|
|
|
rcu_cpu_starting(cpu);
|
2007-04-27 22:02:00 +08:00
|
|
|
init_cpu_timer();
|
2014-10-01 16:57:57 +08:00
|
|
|
vtime_init();
|
2020-11-16 15:06:41 +08:00
|
|
|
vdso_getcpu_init();
|
2006-12-04 22:40:40 +08:00
|
|
|
pfault_init();
|
2020-03-12 18:32:23 +08:00
|
|
|
notify_cpu_starting(cpu);
|
2017-09-22 20:17:41 +08:00
|
|
|
if (topology_cpu_dedicated(cpu))
|
|
|
|
set_cpu_flag(CIF_DEDICATED_CPU);
|
|
|
|
else
|
|
|
|
clear_cpu_flag(CIF_DEDICATED_CPU);
|
2020-03-12 18:32:23 +08:00
|
|
|
set_cpu_online(cpu, true);
|
|
|
|
update_cpu_masks();
|
2013-01-02 23:54:12 +08:00
|
|
|
inc_irq_stat(CPU_RST);
|
2005-04-17 06:20:36 +08:00
|
|
|
local_irq_enable();
|
2016-02-27 02:43:40 +08:00
|
|
|
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2017-09-12 22:37:33 +08:00
|
|
|
/*
|
|
|
|
* Activate a secondary processor.
|
|
|
|
*/
|
2017-11-20 19:13:52 +08:00
|
|
|
static void __no_sanitize_address smp_start_secondary(void *cpuvoid)
|
2017-09-12 22:37:33 +08:00
|
|
|
{
|
|
|
|
S390_lowcore.restart_stack = (unsigned long) restart_stack;
|
|
|
|
S390_lowcore.restart_fn = (unsigned long) do_restart;
|
|
|
|
S390_lowcore.restart_data = 0;
|
|
|
|
S390_lowcore.restart_source = -1UL;
|
|
|
|
__ctl_load(S390_lowcore.cregs_save_area, 0, 15);
|
|
|
|
__load_psw_mask(PSW_KERNEL_BITS | PSW_MASK_DAT);
|
2019-11-22 20:12:57 +08:00
|
|
|
CALL_ON_STACK_NORETURN(smp_init_secondary, S390_lowcore.kernel_stack);
|
2017-09-12 22:37:33 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Upping and downing of CPUs */
|
2013-06-19 05:04:52 +08:00
|
|
|
int __cpu_up(unsigned int cpu, struct task_struct *tidle)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2020-12-08 14:35:21 +08:00
|
|
|
struct pcpu *pcpu = pcpu_devices + cpu;
|
|
|
|
int rc;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-03-11 23:59:26 +08:00
|
|
|
if (pcpu->state != CPU_STATE_CONFIGURED)
|
2008-01-26 21:10:56 +08:00
|
|
|
return -EIO;
|
2020-12-08 14:35:21 +08:00
|
|
|
if (pcpu_sigp_retry(pcpu, SIGP_INITIAL_CPU_RESET, 0) !=
|
2012-06-04 18:55:15 +08:00
|
|
|
SIGP_CC_ORDER_CODE_ACCEPTED)
|
2008-01-26 21:10:56 +08:00
|
|
|
return -EIO;
|
2012-04-20 21:05:52 +08:00
|
|
|
|
2012-03-11 23:59:26 +08:00
|
|
|
rc = pcpu_alloc_lowcore(pcpu, cpu);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
pcpu_prepare_secondary(pcpu, cpu);
|
2012-04-20 21:05:52 +08:00
|
|
|
pcpu_attach_task(pcpu, tidle);
|
2012-03-11 23:59:26 +08:00
|
|
|
pcpu_start_fn(pcpu, smp_start_secondary, NULL);
|
2015-03-30 18:51:42 +08:00
|
|
|
/* Wait until cpu puts itself in the online & active maps */
|
2016-03-10 19:54:08 +08:00
|
|
|
while (!cpu_online(cpu))
|
2005-04-17 06:20:36 +08:00
|
|
|
cpu_relax();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-12-16 21:31:26 +08:00
|
|
|
static unsigned int setup_possible_cpus __initdata;
|
2006-02-18 05:52:46 +08:00
|
|
|
|
2013-12-16 21:31:26 +08:00
|
|
|
static int __init _setup_possible_cpus(char *s)
|
|
|
|
{
|
|
|
|
get_option(&s, &setup_possible_cpus);
|
2006-02-18 05:52:47 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2013-12-16 21:31:26 +08:00
|
|
|
early_param("possible_cpus", _setup_possible_cpus);
|
2006-02-18 05:52:47 +08:00
|
|
|
|
2007-04-27 22:02:00 +08:00
|
|
|
int __cpu_disable(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-03-11 23:59:26 +08:00
|
|
|
unsigned long cregs[16];
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-05-22 16:24:37 +08:00
|
|
|
/* Handle possible pending IPIs */
|
|
|
|
smp_handle_ext_call();
|
2012-03-11 23:59:26 +08:00
|
|
|
set_cpu_online(smp_processor_id(), false);
|
2020-03-12 18:32:23 +08:00
|
|
|
update_cpu_masks();
|
2012-03-11 23:59:26 +08:00
|
|
|
/* Disable pseudo page faults on this cpu. */
|
2006-12-04 22:40:40 +08:00
|
|
|
pfault_fini();
|
2012-03-11 23:59:26 +08:00
|
|
|
/* Disable interrupt sources via control register. */
|
|
|
|
__ctl_store(cregs, 0, 15);
|
|
|
|
cregs[0] &= ~0x0000ee70UL; /* disable all external interrupts */
|
|
|
|
cregs[6] &= ~0xff000000UL; /* disable all I/O interrupts */
|
|
|
|
cregs[14] &= ~0x1f000000UL; /* disable most machine checks */
|
|
|
|
__ctl_load(cregs, 0, 15);
|
2014-09-30 23:37:52 +08:00
|
|
|
clear_cpu_flag(CIF_NOHZ_DELAY);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-04-27 22:02:00 +08:00
|
|
|
void __cpu_die(unsigned int cpu)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-03-11 23:59:26 +08:00
|
|
|
struct pcpu *pcpu;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Wait until target cpu is down */
|
2012-03-11 23:59:26 +08:00
|
|
|
pcpu = pcpu_devices + cpu;
|
|
|
|
while (!pcpu_stopped(pcpu))
|
2005-04-17 06:20:36 +08:00
|
|
|
cpu_relax();
|
2012-03-11 23:59:26 +08:00
|
|
|
pcpu_free_lowcore(pcpu);
|
2014-04-03 19:55:01 +08:00
|
|
|
cpumask_clear_cpu(cpu, mm_cpumask(&init_mm));
|
2016-05-25 15:45:26 +08:00
|
|
|
cpumask_clear_cpu(cpu, &init_mm.context.cpu_attach_mask);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2011-05-23 16:24:33 +08:00
|
|
|
void __noreturn cpu_die(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
idle_task_exit();
|
2018-01-16 14:11:45 +08:00
|
|
|
__bpon();
|
2012-06-04 18:55:15 +08:00
|
|
|
pcpu_sigp_retry(pcpu_devices + smp_processor_id(), SIGP_STOP, 0);
|
2012-03-11 23:59:26 +08:00
|
|
|
for (;;) ;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2013-12-16 21:31:26 +08:00
|
|
|
void __init smp_fill_possible_mask(void)
|
|
|
|
{
|
2015-05-06 15:29:53 +08:00
|
|
|
unsigned int possible, sclp_max, cpu;
|
2013-12-16 21:31:26 +08:00
|
|
|
|
2015-05-06 19:19:29 +08:00
|
|
|
sclp_max = max(sclp.mtid, sclp.mtid_cp) + 1;
|
|
|
|
sclp_max = min(smp_max_threads, sclp_max);
|
2016-07-18 15:02:56 +08:00
|
|
|
sclp_max = (sclp.max_cores * sclp_max) ?: nr_cpu_ids;
|
2014-03-10 21:50:16 +08:00
|
|
|
possible = setup_possible_cpus ?: nr_cpu_ids;
|
2015-05-06 15:29:53 +08:00
|
|
|
possible = min(possible, sclp_max);
|
2013-12-16 21:31:26 +08:00
|
|
|
for (cpu = 0; cpu < possible && cpu < nr_cpu_ids; cpu++)
|
|
|
|
set_cpu_possible(cpu, true);
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
void __init smp_prepare_cpus(unsigned int max_cpus)
|
|
|
|
{
|
2007-04-27 22:02:00 +08:00
|
|
|
/* request the 0x1201 emergency signal external interrupt */
|
2014-03-31 21:24:08 +08:00
|
|
|
if (register_external_irq(EXT_IRQ_EMERGENCY_SIG, do_ext_call_interrupt))
|
2007-04-27 22:02:00 +08:00
|
|
|
panic("Couldn't request external interrupt 0x1201");
|
2011-10-30 22:16:58 +08:00
|
|
|
/* request the 0x1202 external call external interrupt */
|
2014-03-31 21:24:08 +08:00
|
|
|
if (register_external_irq(EXT_IRQ_EXTERNAL_CALL, do_ext_call_interrupt))
|
2011-10-30 22:16:58 +08:00
|
|
|
panic("Couldn't request external interrupt 0x1202");
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-05-31 23:38:05 +08:00
|
|
|
void __init smp_prepare_boot_cpu(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-03-11 23:59:26 +08:00
|
|
|
struct pcpu *pcpu = pcpu_devices;
|
|
|
|
|
2017-03-16 18:02:36 +08:00
|
|
|
WARN_ON(!cpu_present(0) || !cpu_online(0));
|
2012-03-11 23:59:26 +08:00
|
|
|
pcpu->state = CPU_STATE_CONFIGURED;
|
2005-04-17 06:20:36 +08:00
|
|
|
S390_lowcore.percpu_offset = __per_cpu_offset[0];
|
2012-09-04 23:36:16 +08:00
|
|
|
smp_cpu_set_polarization(0, POLARIZATION_UNKNOWN);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2010-01-14 03:44:34 +08:00
|
|
|
void __init smp_setup_processor_id(void)
|
|
|
|
{
|
2017-03-16 18:02:36 +08:00
|
|
|
pcpu_devices[0].address = stap();
|
2010-01-14 03:44:34 +08:00
|
|
|
S390_lowcore.cpu_nr = 0;
|
2014-04-08 00:25:23 +08:00
|
|
|
S390_lowcore.spinlock_lockval = arch_spin_lockval(0);
|
s390/spinlock: introduce spinlock wait queueing
The queued spinlock code for s390 follows the principles of the common
code qspinlock implementation but with a few notable differences.
The format of the spinlock_t locking word differs, s390 needs to store
the logical CPU number of the lock holder in the spinlock_t to be able
to use the diagnose 9c directed yield hypervisor call.
The inline code sequences for spin_lock and spin_unlock are nice and
short. The inline portion of a spin_lock now typically looks like this:
lhi %r0,0 # 0 indicates an empty lock
l %r1,0x3a0 # CPU number + 1 from lowcore
cs %r0,%r1,<some_lock> # lock operation
jnz call_wait # on failure call wait function
locked:
...
call_wait:
la %r2,<some_lock>
brasl %r14,arch_spin_lock_wait
j locked
A spin_unlock is as simple as before:
lhi %r0,0
sth %r0,2(%r2) # unlock operation
After a CPU has queued itself it may not enable interrupts again for the
arch_spin_lock_flags() variant. The arch_spin_lock_wait_flags wait function
is removed.
To improve performance the code implements opportunistic lock stealing.
If the wait function finds a spinlock_t that indicates that the lock is
free but there are queued waiters, the CPU may steal the lock up to three
times without queueing itself. The lock stealing update the steal counter
in the lock word to prevent more than 3 steals. The counter is reset at
the time the CPU next in the queue successfully takes the lock.
While the queued spinlocks improve performance in a system with dedicated
CPUs, in a virtualized environment with continuously overcommitted CPUs
the queued spinlocks can have a negative effect on performance. This
is due to the fact that a queued CPU that is preempted by the hypervisor
will block the queue at some point even without holding the lock. With
the classic spinlock it does not matter if a CPU is preempted that waits
for the lock. Therefore use the queued spinlock code only if the system
runs with dedicated CPUs and fall back to classic spinlocks when running
with shared CPUs.
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
2017-03-25 00:25:02 +08:00
|
|
|
S390_lowcore.spinlock_index = 0;
|
2010-01-14 03:44:34 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* the frequency of the profiling timer can be changed
|
|
|
|
* by writing a multiplier value into /proc/profile.
|
|
|
|
*
|
|
|
|
* usually you want to run this on all CPUs ;)
|
|
|
|
*/
|
|
|
|
int setup_profiling_timer(unsigned int multiplier)
|
|
|
|
{
|
2007-04-27 22:02:00 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2011-12-22 06:29:42 +08:00
|
|
|
static ssize_t cpu_configure_show(struct device *dev,
|
2012-03-11 23:59:26 +08:00
|
|
|
struct device_attribute *attr, char *buf)
|
2008-01-26 21:10:56 +08:00
|
|
|
{
|
|
|
|
ssize_t count;
|
|
|
|
|
|
|
|
mutex_lock(&smp_cpu_state_mutex);
|
2012-03-11 23:59:26 +08:00
|
|
|
count = sprintf(buf, "%d\n", pcpu_devices[dev->id].state);
|
2008-01-26 21:10:56 +08:00
|
|
|
mutex_unlock(&smp_cpu_state_mutex);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2011-12-22 06:29:42 +08:00
|
|
|
static ssize_t cpu_configure_store(struct device *dev,
|
2012-03-11 23:59:26 +08:00
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
2008-01-26 21:10:56 +08:00
|
|
|
{
|
2012-03-11 23:59:26 +08:00
|
|
|
struct pcpu *pcpu;
|
2015-01-15 00:52:10 +08:00
|
|
|
int cpu, val, rc, i;
|
2008-01-26 21:10:56 +08:00
|
|
|
char delim;
|
|
|
|
|
|
|
|
if (sscanf(buf, "%d %c", &val, &delim) != 1)
|
|
|
|
return -EINVAL;
|
|
|
|
if (val != 0 && val != 1)
|
|
|
|
return -EINVAL;
|
2008-01-26 21:11:31 +08:00
|
|
|
get_online_cpus();
|
2008-04-30 19:38:36 +08:00
|
|
|
mutex_lock(&smp_cpu_state_mutex);
|
2008-01-26 21:10:56 +08:00
|
|
|
rc = -EBUSY;
|
2010-02-27 05:37:34 +08:00
|
|
|
/* disallow configuration changes of online cpus and cpu 0 */
|
2012-03-11 23:59:26 +08:00
|
|
|
cpu = dev->id;
|
2016-12-06 04:18:58 +08:00
|
|
|
cpu = smp_get_base_cpu(cpu);
|
2015-01-15 00:52:10 +08:00
|
|
|
if (cpu == 0)
|
2008-01-26 21:10:56 +08:00
|
|
|
goto out;
|
2015-01-15 00:52:10 +08:00
|
|
|
for (i = 0; i <= smp_cpu_mtid; i++)
|
|
|
|
if (cpu_online(cpu + i))
|
|
|
|
goto out;
|
2012-03-11 23:59:26 +08:00
|
|
|
pcpu = pcpu_devices + cpu;
|
2008-01-26 21:10:56 +08:00
|
|
|
rc = 0;
|
|
|
|
switch (val) {
|
|
|
|
case 0:
|
2012-03-11 23:59:26 +08:00
|
|
|
if (pcpu->state != CPU_STATE_CONFIGURED)
|
|
|
|
break;
|
2015-06-18 20:23:00 +08:00
|
|
|
rc = sclp_core_deconfigure(pcpu->address >> smp_cpu_mt_shift);
|
2012-03-11 23:59:26 +08:00
|
|
|
if (rc)
|
|
|
|
break;
|
2015-01-15 00:52:10 +08:00
|
|
|
for (i = 0; i <= smp_cpu_mtid; i++) {
|
|
|
|
if (cpu + i >= nr_cpu_ids || !cpu_present(cpu + i))
|
|
|
|
continue;
|
|
|
|
pcpu[i].state = CPU_STATE_STANDBY;
|
|
|
|
smp_cpu_set_polarization(cpu + i,
|
|
|
|
POLARIZATION_UNKNOWN);
|
|
|
|
}
|
2012-03-11 23:59:26 +08:00
|
|
|
topology_expect_change();
|
2008-01-26 21:10:56 +08:00
|
|
|
break;
|
|
|
|
case 1:
|
2012-03-11 23:59:26 +08:00
|
|
|
if (pcpu->state != CPU_STATE_STANDBY)
|
|
|
|
break;
|
2015-06-18 20:23:00 +08:00
|
|
|
rc = sclp_core_configure(pcpu->address >> smp_cpu_mt_shift);
|
2012-03-11 23:59:26 +08:00
|
|
|
if (rc)
|
|
|
|
break;
|
2015-01-15 00:52:10 +08:00
|
|
|
for (i = 0; i <= smp_cpu_mtid; i++) {
|
|
|
|
if (cpu + i >= nr_cpu_ids || !cpu_present(cpu + i))
|
|
|
|
continue;
|
|
|
|
pcpu[i].state = CPU_STATE_CONFIGURED;
|
|
|
|
smp_cpu_set_polarization(cpu + i,
|
|
|
|
POLARIZATION_UNKNOWN);
|
|
|
|
}
|
2012-03-11 23:59:26 +08:00
|
|
|
topology_expect_change();
|
2008-01-26 21:10:56 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
mutex_unlock(&smp_cpu_state_mutex);
|
2008-04-30 19:38:36 +08:00
|
|
|
put_online_cpus();
|
2008-01-26 21:10:56 +08:00
|
|
|
return rc ? rc : count;
|
|
|
|
}
|
2011-12-22 06:29:42 +08:00
|
|
|
static DEVICE_ATTR(configure, 0644, cpu_configure_show, cpu_configure_store);
|
2008-01-26 21:10:56 +08:00
|
|
|
|
2011-12-22 06:29:42 +08:00
|
|
|
static ssize_t show_cpu_address(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
2008-01-26 21:10:56 +08:00
|
|
|
{
|
2012-03-11 23:59:26 +08:00
|
|
|
return sprintf(buf, "%d\n", pcpu_devices[dev->id].address);
|
2008-01-26 21:10:56 +08:00
|
|
|
}
|
2011-12-22 06:29:42 +08:00
|
|
|
static DEVICE_ATTR(address, 0444, show_cpu_address, NULL);
|
2008-01-26 21:10:56 +08:00
|
|
|
|
|
|
|
static struct attribute *cpu_common_attrs[] = {
|
2011-12-22 06:29:42 +08:00
|
|
|
&dev_attr_configure.attr,
|
|
|
|
&dev_attr_address.attr,
|
2008-01-26 21:10:56 +08:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct attribute_group cpu_common_attr_group = {
|
|
|
|
.attrs = cpu_common_attrs,
|
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-01-26 21:10:56 +08:00
|
|
|
static struct attribute *cpu_online_attrs[] = {
|
2011-12-22 06:29:42 +08:00
|
|
|
&dev_attr_idle_count.attr,
|
|
|
|
&dev_attr_idle_time_us.attr,
|
2007-10-22 18:52:39 +08:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2008-01-26 21:10:56 +08:00
|
|
|
static struct attribute_group cpu_online_attr_group = {
|
|
|
|
.attrs = cpu_online_attrs,
|
2007-10-22 18:52:39 +08:00
|
|
|
};
|
|
|
|
|
2016-11-04 22:45:03 +08:00
|
|
|
static int smp_cpu_online(unsigned int cpu)
|
2007-04-27 22:01:56 +08:00
|
|
|
{
|
2015-02-11 19:31:03 +08:00
|
|
|
struct device *s = &per_cpu(cpu_device, cpu)->dev;
|
2007-04-27 22:01:56 +08:00
|
|
|
|
2016-11-04 22:45:03 +08:00
|
|
|
return sysfs_create_group(&s->kobj, &cpu_online_attr_group);
|
|
|
|
}
|
2020-07-01 17:17:52 +08:00
|
|
|
|
2016-11-04 22:45:03 +08:00
|
|
|
static int smp_cpu_pre_down(unsigned int cpu)
|
|
|
|
{
|
|
|
|
struct device *s = &per_cpu(cpu_device, cpu)->dev;
|
|
|
|
|
|
|
|
sysfs_remove_group(&s->kobj, &cpu_online_attr_group);
|
|
|
|
return 0;
|
2007-04-27 22:01:56 +08:00
|
|
|
}
|
|
|
|
|
2013-06-19 05:04:52 +08:00
|
|
|
static int smp_add_present_cpu(int cpu)
|
2008-01-26 21:10:56 +08:00
|
|
|
{
|
2013-12-05 19:42:09 +08:00
|
|
|
struct device *s;
|
|
|
|
struct cpu *c;
|
2008-01-26 21:10:56 +08:00
|
|
|
int rc;
|
|
|
|
|
2013-12-05 19:42:09 +08:00
|
|
|
c = kzalloc(sizeof(*c), GFP_KERNEL);
|
|
|
|
if (!c)
|
|
|
|
return -ENOMEM;
|
2015-02-11 19:31:03 +08:00
|
|
|
per_cpu(cpu_device, cpu) = c;
|
2013-12-05 19:42:09 +08:00
|
|
|
s = &c->dev;
|
2008-01-26 21:10:56 +08:00
|
|
|
c->hotpluggable = 1;
|
|
|
|
rc = register_cpu(c, cpu);
|
|
|
|
if (rc)
|
|
|
|
goto out;
|
|
|
|
rc = sysfs_create_group(&s->kobj, &cpu_common_attr_group);
|
|
|
|
if (rc)
|
|
|
|
goto out_cpu;
|
2011-12-27 18:27:09 +08:00
|
|
|
rc = topology_cpu_init(c);
|
|
|
|
if (rc)
|
|
|
|
goto out_topology;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_topology:
|
2008-01-26 21:10:56 +08:00
|
|
|
sysfs_remove_group(&s->kobj, &cpu_common_attr_group);
|
|
|
|
out_cpu:
|
|
|
|
unregister_cpu(c);
|
|
|
|
out:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2008-05-30 16:03:27 +08:00
|
|
|
int __ref smp_rescan_cpus(void)
|
2008-01-26 21:10:56 +08:00
|
|
|
{
|
2015-06-18 20:23:00 +08:00
|
|
|
struct sclp_core_info *info;
|
2012-03-11 23:59:26 +08:00
|
|
|
int nr;
|
2008-01-26 21:10:56 +08:00
|
|
|
|
2016-12-03 16:48:01 +08:00
|
|
|
info = kzalloc(sizeof(*info), GFP_KERNEL);
|
2012-03-11 23:59:26 +08:00
|
|
|
if (!info)
|
|
|
|
return -ENOMEM;
|
2016-12-03 16:48:01 +08:00
|
|
|
smp_get_core_info(info, 0);
|
2019-11-17 21:55:38 +08:00
|
|
|
nr = __smp_rescan_cpus(info, false);
|
2012-03-11 23:59:26 +08:00
|
|
|
kfree(info);
|
|
|
|
if (nr)
|
2008-04-17 13:46:13 +08:00
|
|
|
topology_schedule_update();
|
2012-03-11 23:59:26 +08:00
|
|
|
return 0;
|
2008-04-30 19:38:37 +08:00
|
|
|
}
|
|
|
|
|
2011-12-22 06:29:42 +08:00
|
|
|
static ssize_t __ref rescan_store(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
2010-01-05 19:47:58 +08:00
|
|
|
const char *buf,
|
2008-04-30 19:38:37 +08:00
|
|
|
size_t count)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2019-01-09 20:00:03 +08:00
|
|
|
rc = lock_device_hotplug_sysfs();
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
2008-04-30 19:38:37 +08:00
|
|
|
rc = smp_rescan_cpus();
|
2019-01-09 20:00:03 +08:00
|
|
|
unlock_device_hotplug();
|
2008-01-26 21:10:56 +08:00
|
|
|
return rc ? rc : count;
|
|
|
|
}
|
2017-12-20 02:15:09 +08:00
|
|
|
static DEVICE_ATTR_WO(rescan);
|
2008-01-26 21:10:56 +08:00
|
|
|
|
2011-12-27 18:27:09 +08:00
|
|
|
static int __init s390_smp_init(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-03-11 04:35:58 +08:00
|
|
|
int cpu, rc = 0;
|
2007-04-27 22:01:56 +08:00
|
|
|
|
2011-12-22 06:29:42 +08:00
|
|
|
rc = device_create_file(cpu_subsys.dev_root, &dev_attr_rescan);
|
2008-01-26 21:10:56 +08:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
for_each_present_cpu(cpu) {
|
|
|
|
rc = smp_add_present_cpu(cpu);
|
2007-10-22 18:52:39 +08:00
|
|
|
if (rc)
|
2014-03-11 04:35:58 +08:00
|
|
|
goto out;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2014-03-11 04:35:58 +08:00
|
|
|
|
2016-11-04 22:45:03 +08:00
|
|
|
rc = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "s390/smp:online",
|
|
|
|
smp_cpu_online, smp_cpu_pre_down);
|
2017-08-14 13:54:32 +08:00
|
|
|
rc = rc <= 0 ? rc : 0;
|
2014-03-11 04:35:58 +08:00
|
|
|
out:
|
|
|
|
return rc;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2011-12-27 18:27:09 +08:00
|
|
|
subsys_initcall(s390_smp_init);
|
2021-05-06 22:26:52 +08:00
|
|
|
|
|
|
|
static __always_inline void set_new_lowcore(struct lowcore *lc)
|
|
|
|
{
|
2021-06-10 04:59:13 +08:00
|
|
|
union register_pair dst, src;
|
2021-05-06 22:26:52 +08:00
|
|
|
u32 pfx;
|
2021-06-10 04:59:13 +08:00
|
|
|
|
|
|
|
src.even = (unsigned long) &S390_lowcore;
|
|
|
|
src.odd = sizeof(S390_lowcore);
|
|
|
|
dst.even = (unsigned long) lc;
|
|
|
|
dst.odd = sizeof(*lc);
|
|
|
|
pfx = (unsigned long) lc;
|
2021-05-06 22:26:52 +08:00
|
|
|
|
|
|
|
asm volatile(
|
2021-06-10 04:59:13 +08:00
|
|
|
" mvcl %[dst],%[src]\n"
|
2021-05-06 22:26:52 +08:00
|
|
|
" spx %[pfx]\n"
|
2021-06-10 04:59:13 +08:00
|
|
|
: [dst] "+&d" (dst.pair), [src] "+&d" (src.pair)
|
|
|
|
: [pfx] "Q" (pfx)
|
|
|
|
: "memory", "cc");
|
2021-05-06 22:26:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int __init smp_reinit_ipl_cpu(void)
|
|
|
|
{
|
|
|
|
unsigned long async_stack, nodat_stack, mcck_stack;
|
|
|
|
struct lowcore *lc, *lc_ipl;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
lc_ipl = lowcore_ptr[0];
|
|
|
|
lc = (struct lowcore *) __get_free_pages(GFP_KERNEL | GFP_DMA, LC_ORDER);
|
|
|
|
nodat_stack = __get_free_pages(GFP_KERNEL, THREAD_SIZE_ORDER);
|
|
|
|
async_stack = stack_alloc();
|
|
|
|
mcck_stack = stack_alloc();
|
|
|
|
if (!lc || !nodat_stack || !async_stack || !mcck_stack)
|
|
|
|
panic("Couldn't allocate memory");
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
local_mcck_disable();
|
|
|
|
set_new_lowcore(lc);
|
|
|
|
S390_lowcore.nodat_stack = nodat_stack + STACK_INIT_OFFSET;
|
|
|
|
S390_lowcore.async_stack = async_stack + STACK_INIT_OFFSET;
|
|
|
|
S390_lowcore.mcck_stack = mcck_stack + STACK_INIT_OFFSET;
|
|
|
|
lowcore_ptr[0] = lc;
|
|
|
|
local_mcck_enable();
|
|
|
|
local_irq_restore(flags);
|
|
|
|
|
|
|
|
free_pages(lc_ipl->async_stack - STACK_INIT_OFFSET, THREAD_SIZE_ORDER);
|
|
|
|
memblock_free_late(lc_ipl->mcck_stack - STACK_INIT_OFFSET, THREAD_SIZE);
|
|
|
|
memblock_free_late((unsigned long) lc_ipl, sizeof(*lc_ipl));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
early_initcall(smp_reinit_ipl_cpu);
|