2018-05-15 13:28:53 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2019-02-27 17:36:35 +01:00
|
|
|
#include <linux/kernel.h>
|
2018-05-15 13:28:53 +02:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/ctype.h>
|
2020-06-08 21:32:42 -07:00
|
|
|
#include <linux/pgtable.h>
|
s390: Add infrastructure to patch lowcore accesses
The s390 architecture defines two special per-CPU data pages
called the "prefix area". In s390-linux terminology this is usually
called "lowcore". This memory area contains system configuration
data like old/new PSW's for system call/interrupt/machine check
handlers and lots of other data. It is normally mapped to logical
address 0. This area can only be accessed when in supervisor mode.
This means that kernel code can dereference NULL pointers, because
accesses to address 0 are allowed. Parts of lowcore can be write
protected, but read accesses and write accesses outside of the write
protected areas are not caught.
To remove this limitation for debugging and testing, remap lowcore to
another address and define a function get_lowcore() which simply
returns the address where lowcore is mapped at. This would normally
introduce a pointer dereference (=memory read). As lowcore is used
for several very often used variables, add code to patch this function
during runtime, so we avoid the memory reads.
For C code get_lowcore() has to be used, for assembly code it is
the GET_LC macro. When using this macro/function a reference is added
to alternative patching. All these locations will be patched to the
actual lowcore location when the kernel is booted or a module is loaded.
To make debugging/bisecting problems easier, this patch adds all the
infrastructure but the lowcore address is still hardwired to 0. This
way the code can be converted on a per function basis, and the
functionality is enabled in a patch after all the functions have
been converted.
Note that this requires at least z16 because the old lpsw instruction
only allowed a 12 bit displacement. z16 introduced lpswey which allows
20 bits (signed), so the lowcore can effectively be mapped from
address 0 - 0x7e000. To use 0x7e000 as address, a 6 byte lgfi
instruction would have to be used in the alternative. To save two
bytes, llilh can be used, but this only allows to set bits 16-31 of
the address. In order to use the llilh instruction, use 0x70000 as
alternative lowcore address. This is still large enough to catch
NULL pointer dereferences into large arrays.
Reviewed-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
2024-07-22 15:41:14 +02:00
|
|
|
#include <asm/abs_lowcore.h>
|
2023-10-27 14:12:36 +02:00
|
|
|
#include <asm/page-states.h>
|
2025-02-07 15:48:57 +01:00
|
|
|
#include <asm/machine.h>
|
2018-05-15 13:28:53 +02:00
|
|
|
#include <asm/ebcdic.h>
|
|
|
|
#include <asm/sclp.h>
|
|
|
|
#include <asm/sections.h>
|
|
|
|
#include <asm/boot_data.h>
|
2019-02-27 16:52:42 +01:00
|
|
|
#include <asm/facility.h>
|
2022-04-25 21:24:56 +02:00
|
|
|
#include <asm/setup.h>
|
2019-04-01 19:11:04 +02:00
|
|
|
#include <asm/uv.h>
|
2018-05-15 13:28:53 +02:00
|
|
|
#include "boot.h"
|
|
|
|
|
2022-04-25 21:24:56 +02:00
|
|
|
struct parmarea parmarea __section(".parmarea") = {
|
|
|
|
.kernel_version = (unsigned long)kernel_version,
|
|
|
|
.max_command_line_size = COMMAND_LINE_SIZE,
|
|
|
|
.command_line = "root=/dev/ram0 ro",
|
|
|
|
};
|
|
|
|
|
2018-05-15 13:28:53 +02:00
|
|
|
char __bootdata(early_command_line)[COMMAND_LINE_SIZE];
|
2020-10-06 22:12:39 +02:00
|
|
|
|
|
|
|
unsigned int __bootdata_preserved(zlib_dfltcc_support) = ZLIB_DFLTCC_FULL;
|
2019-04-01 19:10:51 +02:00
|
|
|
struct ipl_parameter_block __bootdata_preserved(ipl_block);
|
|
|
|
int __bootdata_preserved(ipl_block_valid);
|
2023-03-31 15:03:22 +02:00
|
|
|
int __bootdata_preserved(__kaslr_enabled);
|
2023-10-27 14:12:36 +02:00
|
|
|
int __bootdata_preserved(cmma_flag) = 1;
|
2018-05-15 13:28:53 +02:00
|
|
|
|
2020-10-06 22:12:39 +02:00
|
|
|
unsigned long vmalloc_size = VMALLOC_DEFAULT_SIZE;
|
2020-10-19 11:01:33 +02:00
|
|
|
unsigned long memory_limit;
|
2020-09-18 12:25:37 +02:00
|
|
|
int vmalloc_size_set;
|
2019-02-03 21:37:20 +01:00
|
|
|
|
2018-05-15 13:28:53 +02:00
|
|
|
static inline int __diag308(unsigned long subcode, void *addr)
|
|
|
|
{
|
2025-02-24 15:59:11 +01:00
|
|
|
union register_pair r1 = { .even = (unsigned long)addr, .odd = 0 };
|
2018-05-15 13:28:53 +02:00
|
|
|
|
2025-03-17 16:22:35 +01:00
|
|
|
asm_inline volatile(
|
2021-06-14 18:55:07 +02:00
|
|
|
" diag %[r1],%[subcode],0x308\n"
|
2025-02-24 15:59:11 +01:00
|
|
|
"0:\n"
|
|
|
|
EX_TABLE(0b, 0b)
|
|
|
|
: [r1] "+d" (r1.pair)
|
|
|
|
: [subcode] "d" (subcode)
|
2018-05-15 13:28:53 +02:00
|
|
|
: "cc", "memory");
|
2021-06-14 18:55:07 +02:00
|
|
|
return r1.odd;
|
2018-05-15 13:28:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void store_ipl_parmblock(void)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2019-04-01 19:10:51 +02:00
|
|
|
rc = __diag308(DIAG308_STORE, &ipl_block);
|
2018-05-15 13:28:53 +02:00
|
|
|
if (rc == DIAG308_RC_OK &&
|
2019-04-01 19:10:51 +02:00
|
|
|
ipl_block.hdr.version <= IPL_MAX_SUPPORTED_VERSION)
|
|
|
|
ipl_block_valid = 1;
|
2018-05-15 13:28:53 +02:00
|
|
|
}
|
|
|
|
|
2020-10-19 11:01:33 +02:00
|
|
|
bool is_ipl_block_dump(void)
|
|
|
|
{
|
|
|
|
if (ipl_block.pb0_hdr.pbt == IPL_PBT_FCP &&
|
|
|
|
ipl_block.fcp.opt == IPL_PB0_FCP_OPT_DUMP)
|
|
|
|
return true;
|
|
|
|
if (ipl_block.pb0_hdr.pbt == IPL_PBT_NVME &&
|
|
|
|
ipl_block.nvme.opt == IPL_PB0_NVME_OPT_DUMP)
|
|
|
|
return true;
|
2022-10-05 10:17:41 +02:00
|
|
|
if (ipl_block.pb0_hdr.pbt == IPL_PBT_ECKD &&
|
|
|
|
ipl_block.eckd.opt == IPL_PB0_ECKD_OPT_DUMP)
|
|
|
|
return true;
|
2020-10-19 11:01:33 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-04-15 10:35:54 +02:00
|
|
|
static size_t scpdata_length(const u8 *buf, size_t count)
|
2018-05-15 13:28:53 +02:00
|
|
|
{
|
|
|
|
while (count) {
|
|
|
|
if (buf[count - 1] != '\0' && buf[count - 1] != ' ')
|
|
|
|
break;
|
|
|
|
count--;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t ipl_block_get_ascii_scpdata(char *dest, size_t size,
|
|
|
|
const struct ipl_parameter_block *ipb)
|
|
|
|
{
|
2020-09-29 20:23:17 +02:00
|
|
|
const __u8 *scp_data;
|
|
|
|
__u32 scp_data_len;
|
2018-05-15 13:28:53 +02:00
|
|
|
int has_lowercase;
|
2020-09-29 20:23:17 +02:00
|
|
|
size_t count = 0;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
switch (ipb->pb0_hdr.pbt) {
|
|
|
|
case IPL_PBT_FCP:
|
|
|
|
scp_data_len = ipb->fcp.scp_data_len;
|
|
|
|
scp_data = ipb->fcp.scp_data;
|
|
|
|
break;
|
|
|
|
case IPL_PBT_NVME:
|
|
|
|
scp_data_len = ipb->nvme.scp_data_len;
|
|
|
|
scp_data = ipb->nvme.scp_data;
|
|
|
|
break;
|
2022-10-05 10:17:40 +02:00
|
|
|
case IPL_PBT_ECKD:
|
|
|
|
scp_data_len = ipb->eckd.scp_data_len;
|
|
|
|
scp_data = ipb->eckd.scp_data;
|
|
|
|
break;
|
|
|
|
|
2020-09-29 20:23:17 +02:00
|
|
|
default:
|
|
|
|
goto out;
|
|
|
|
}
|
2018-05-15 13:28:53 +02:00
|
|
|
|
2020-09-29 20:23:17 +02:00
|
|
|
count = min(size - 1, scpdata_length(scp_data, scp_data_len));
|
2018-05-15 13:28:53 +02:00
|
|
|
if (!count)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
has_lowercase = 0;
|
|
|
|
for (i = 0; i < count; i++) {
|
2020-09-29 20:23:17 +02:00
|
|
|
if (!isascii(scp_data[i])) {
|
2018-05-15 13:28:53 +02:00
|
|
|
count = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2020-09-29 20:23:17 +02:00
|
|
|
if (!has_lowercase && islower(scp_data[i]))
|
2018-05-15 13:28:53 +02:00
|
|
|
has_lowercase = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has_lowercase)
|
2020-09-29 20:23:17 +02:00
|
|
|
memcpy(dest, scp_data, count);
|
2018-05-15 13:28:53 +02:00
|
|
|
else
|
|
|
|
for (i = 0; i < count; i++)
|
2020-09-29 20:23:17 +02:00
|
|
|
dest[i] = tolower(scp_data[i]);
|
2018-05-15 13:28:53 +02:00
|
|
|
out:
|
|
|
|
dest[count] = '\0';
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void append_ipl_block_parm(void)
|
|
|
|
{
|
|
|
|
char *parm, *delim;
|
|
|
|
size_t len, rc = 0;
|
|
|
|
|
|
|
|
len = strlen(early_command_line);
|
|
|
|
|
|
|
|
delim = early_command_line + len; /* '\0' character position */
|
|
|
|
parm = early_command_line + len + 1; /* append right after '\0' */
|
|
|
|
|
2019-02-20 14:26:51 +01:00
|
|
|
switch (ipl_block.pb0_hdr.pbt) {
|
|
|
|
case IPL_PBT_CCW:
|
2018-05-15 13:28:53 +02:00
|
|
|
rc = ipl_block_get_ascii_vmparm(
|
2019-04-01 19:10:51 +02:00
|
|
|
parm, COMMAND_LINE_SIZE - len - 1, &ipl_block);
|
2018-05-15 13:28:53 +02:00
|
|
|
break;
|
2019-02-20 14:26:51 +01:00
|
|
|
case IPL_PBT_FCP:
|
2020-09-29 20:23:17 +02:00
|
|
|
case IPL_PBT_NVME:
|
2022-10-05 10:17:40 +02:00
|
|
|
case IPL_PBT_ECKD:
|
2018-05-15 13:28:53 +02:00
|
|
|
rc = ipl_block_get_ascii_scpdata(
|
2019-04-01 19:10:51 +02:00
|
|
|
parm, COMMAND_LINE_SIZE - len - 1, &ipl_block);
|
2018-05-15 13:28:53 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (rc) {
|
|
|
|
if (*parm == '=')
|
|
|
|
memmove(early_command_line, parm + 1, rc);
|
|
|
|
else
|
|
|
|
*delim = ' '; /* replace '\0' with space */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int has_ebcdic_char(const char *str)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; str[i]; i++)
|
|
|
|
if (str[i] & 0x80)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setup_boot_command_line(void)
|
|
|
|
{
|
2021-09-23 21:22:52 +02:00
|
|
|
parmarea.command_line[COMMAND_LINE_SIZE - 1] = 0;
|
2018-05-15 13:28:53 +02:00
|
|
|
/* convert arch command line to ascii if necessary */
|
2021-05-07 19:12:54 +02:00
|
|
|
if (has_ebcdic_char(parmarea.command_line))
|
2021-09-23 21:22:52 +02:00
|
|
|
EBCASC(parmarea.command_line, COMMAND_LINE_SIZE);
|
2018-05-15 13:28:53 +02:00
|
|
|
/* copy arch command line */
|
2025-04-24 11:27:09 +02:00
|
|
|
strscpy(early_command_line, strim(parmarea.command_line));
|
2018-05-15 13:28:53 +02:00
|
|
|
|
|
|
|
/* append IPL PARM data to the boot command line */
|
2019-04-01 19:11:08 +02:00
|
|
|
if (!is_prot_virt_guest() && ipl_block_valid)
|
2018-05-15 13:28:53 +02:00
|
|
|
append_ipl_block_parm();
|
|
|
|
}
|
|
|
|
|
2019-02-27 16:52:42 +01:00
|
|
|
static void modify_facility(unsigned long nr, bool clear)
|
|
|
|
{
|
|
|
|
if (clear)
|
2021-05-05 22:01:10 +02:00
|
|
|
__clear_facility(nr, stfle_fac_list);
|
2019-02-27 16:52:42 +01:00
|
|
|
else
|
2021-05-05 22:01:10 +02:00
|
|
|
__set_facility(nr, stfle_fac_list);
|
2019-02-27 16:52:42 +01:00
|
|
|
}
|
|
|
|
|
2019-02-27 17:36:35 +01:00
|
|
|
static void check_cleared_facilities(void)
|
|
|
|
{
|
|
|
|
unsigned long als[] = { FACILITIES_ALS };
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(als); i++) {
|
2021-05-05 22:01:10 +02:00
|
|
|
if ((stfle_fac_list[i] & als[i]) != als[i]) {
|
2024-11-20 17:07:56 +01:00
|
|
|
boot_emerg("The Linux kernel requires facilities cleared via command line option\n");
|
2019-02-27 17:36:35 +01:00
|
|
|
print_missing_facilities();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-27 16:52:42 +01:00
|
|
|
static void modify_fac_list(char *str)
|
|
|
|
{
|
|
|
|
unsigned long val, endval;
|
|
|
|
char *endp;
|
|
|
|
bool clear;
|
|
|
|
|
|
|
|
while (*str) {
|
|
|
|
clear = false;
|
|
|
|
if (*str == '!') {
|
|
|
|
clear = true;
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
val = simple_strtoull(str, &endp, 0);
|
|
|
|
if (str == endp)
|
|
|
|
break;
|
|
|
|
str = endp;
|
|
|
|
if (*str == '-') {
|
|
|
|
str++;
|
|
|
|
endval = simple_strtoull(str, &endp, 0);
|
|
|
|
if (str == endp)
|
|
|
|
break;
|
|
|
|
str = endp;
|
|
|
|
while (val <= endval) {
|
|
|
|
modify_facility(val, clear);
|
|
|
|
val++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
modify_facility(val, clear);
|
|
|
|
}
|
|
|
|
if (*str != ',')
|
|
|
|
break;
|
|
|
|
str++;
|
|
|
|
}
|
2019-02-27 17:36:35 +01:00
|
|
|
check_cleared_facilities();
|
2019-02-27 16:52:42 +01:00
|
|
|
}
|
|
|
|
|
2020-09-02 16:52:06 +02:00
|
|
|
static char command_line_buf[COMMAND_LINE_SIZE];
|
2019-02-27 16:52:42 +01:00
|
|
|
void parse_boot_command_line(void)
|
2018-05-15 13:28:53 +02:00
|
|
|
{
|
|
|
|
char *param, *val;
|
2017-11-17 18:44:28 +01:00
|
|
|
bool enabled;
|
|
|
|
char *args;
|
|
|
|
int rc;
|
2018-05-15 13:28:53 +02:00
|
|
|
|
2023-03-31 15:03:22 +02:00
|
|
|
__kaslr_enabled = IS_ENABLED(CONFIG_RANDOMIZE_BASE);
|
2025-04-24 11:27:09 +02:00
|
|
|
strscpy(command_line_buf, early_command_line);
|
|
|
|
args = command_line_buf;
|
2018-05-15 13:28:53 +02:00
|
|
|
while (*args) {
|
|
|
|
args = next_arg(args, ¶m, &val);
|
|
|
|
|
2020-10-19 11:01:33 +02:00
|
|
|
if (!strcmp(param, "mem") && val)
|
|
|
|
memory_limit = round_down(memparse(val, NULL), PAGE_SIZE);
|
2017-11-17 18:44:28 +01:00
|
|
|
|
2020-09-18 12:25:37 +02:00
|
|
|
if (!strcmp(param, "vmalloc") && val) {
|
2023-07-16 10:56:00 +02:00
|
|
|
vmalloc_size = round_up(memparse(val, NULL), _SEGMENT_SIZE);
|
2020-09-18 12:25:37 +02:00
|
|
|
vmalloc_size_set = 1;
|
|
|
|
}
|
2019-08-02 12:28:20 +02:00
|
|
|
|
2020-09-25 22:42:30 +02:00
|
|
|
if (!strcmp(param, "dfltcc") && val) {
|
2020-01-30 22:16:27 -08:00
|
|
|
if (!strcmp(val, "off"))
|
|
|
|
zlib_dfltcc_support = ZLIB_DFLTCC_DISABLED;
|
|
|
|
else if (!strcmp(val, "on"))
|
|
|
|
zlib_dfltcc_support = ZLIB_DFLTCC_FULL;
|
|
|
|
else if (!strcmp(val, "def_only"))
|
|
|
|
zlib_dfltcc_support = ZLIB_DFLTCC_DEFLATE_ONLY;
|
|
|
|
else if (!strcmp(val, "inf_only"))
|
|
|
|
zlib_dfltcc_support = ZLIB_DFLTCC_INFLATE_ONLY;
|
|
|
|
else if (!strcmp(val, "always"))
|
|
|
|
zlib_dfltcc_support = ZLIB_DFLTCC_FULL_DEBUG;
|
|
|
|
}
|
|
|
|
|
2019-08-19 10:49:53 +02:00
|
|
|
if (!strcmp(param, "facilities") && val)
|
2019-02-27 16:52:42 +01:00
|
|
|
modify_fac_list(val);
|
2019-02-03 21:37:20 +01:00
|
|
|
|
2025-02-07 15:49:11 +01:00
|
|
|
if (!strcmp(param, "debug-alternative"))
|
|
|
|
alt_debug_setup(val);
|
|
|
|
|
2019-02-03 21:37:20 +01:00
|
|
|
if (!strcmp(param, "nokaslr"))
|
2023-03-31 15:03:22 +02:00
|
|
|
__kaslr_enabled = 0;
|
2020-09-11 11:38:21 +02:00
|
|
|
|
2023-10-27 14:12:36 +02:00
|
|
|
if (!strcmp(param, "cmma")) {
|
|
|
|
rc = kstrtobool(val, &enabled);
|
|
|
|
if (!rc && !enabled)
|
|
|
|
cmma_flag = 0;
|
|
|
|
}
|
|
|
|
|
2020-09-11 11:38:21 +02:00
|
|
|
#if IS_ENABLED(CONFIG_KVM)
|
|
|
|
if (!strcmp(param, "prot_virt")) {
|
|
|
|
rc = kstrtobool(val, &enabled);
|
|
|
|
if (!rc && enabled)
|
|
|
|
prot_virt_host = 1;
|
|
|
|
}
|
|
|
|
#endif
|
2024-07-22 15:41:28 +02:00
|
|
|
if (!strcmp(param, "relocate_lowcore") && test_facility(193))
|
2025-02-07 15:48:57 +01:00
|
|
|
set_machine_feature(MFEATURE_LOWCORE);
|
2024-11-20 21:46:17 +01:00
|
|
|
if (!strcmp(param, "earlyprintk"))
|
|
|
|
boot_earlyprintk = true;
|
2024-11-20 16:56:12 +01:00
|
|
|
if (!strcmp(param, "debug"))
|
|
|
|
boot_console_loglevel = CONSOLE_LOGLEVEL_DEBUG;
|
2024-11-23 00:02:25 +01:00
|
|
|
if (!strcmp(param, "bootdebug")) {
|
2024-11-20 22:23:48 +01:00
|
|
|
bootdebug = true;
|
2024-11-23 00:02:25 +01:00
|
|
|
if (val)
|
2025-04-11 01:45:49 +02:00
|
|
|
strscpy(bootdebug_filter, val);
|
2024-11-23 00:02:25 +01:00
|
|
|
}
|
2024-11-20 16:56:12 +01:00
|
|
|
if (!strcmp(param, "quiet"))
|
|
|
|
boot_console_loglevel = CONSOLE_LOGLEVEL_QUIET;
|
|
|
|
if (!strcmp(param, "ignore_loglevel"))
|
|
|
|
boot_ignore_loglevel = true;
|
|
|
|
if (!strcmp(param, "loglevel")) {
|
|
|
|
boot_console_loglevel = simple_strtoull(val, NULL, 10);
|
|
|
|
if (boot_console_loglevel < CONSOLE_LOGLEVEL_MIN)
|
|
|
|
boot_console_loglevel = CONSOLE_LOGLEVEL_MIN;
|
|
|
|
}
|
2018-05-15 13:28:53 +02:00
|
|
|
}
|
|
|
|
}
|