2019-05-29 22:18:00 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2017-07-11 09:08:08 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 Regents of the University of California
|
|
|
|
* Copyright (C) 2017 SiFive
|
|
|
|
*/
|
|
|
|
|
2021-11-18 19:26:05 +08:00
|
|
|
#define RO_EXCEPTION_TABLE_ALIGN 4
|
2021-08-26 22:11:18 +08:00
|
|
|
|
2021-04-13 14:35:14 +08:00
|
|
|
#ifdef CONFIG_XIP_KERNEL
|
|
|
|
#include "vmlinux-xip.lds.S"
|
|
|
|
#else
|
|
|
|
|
2021-04-12 00:41:44 +08:00
|
|
|
#include <asm/pgtable.h>
|
|
|
|
#define LOAD_OFFSET KERNEL_LINK_ADDR
|
2021-04-13 14:35:14 +08:00
|
|
|
|
2017-07-11 09:08:08 +08:00
|
|
|
#include <asm/vmlinux.lds.h>
|
|
|
|
#include <asm/page.h>
|
|
|
|
#include <asm/cache.h>
|
|
|
|
#include <asm/thread_info.h>
|
2020-03-10 00:55:40 +08:00
|
|
|
#include <asm/set_memory.h>
|
2020-09-18 06:37:13 +08:00
|
|
|
#include "image-vars.h"
|
2017-07-11 09:08:08 +08:00
|
|
|
|
2020-03-18 09:11:39 +08:00
|
|
|
#include <linux/sizes.h>
|
2017-07-11 09:08:08 +08:00
|
|
|
OUTPUT_ARCH(riscv)
|
|
|
|
ENTRY(_start)
|
|
|
|
|
|
|
|
jiffies = jiffies_64;
|
|
|
|
|
2020-09-18 06:37:13 +08:00
|
|
|
PECOFF_SECTION_ALIGNMENT = 0x1000;
|
|
|
|
PECOFF_FILE_ALIGNMENT = 0x200;
|
|
|
|
|
2017-07-11 09:08:08 +08:00
|
|
|
SECTIONS
|
|
|
|
{
|
|
|
|
/* Beginning of code and text segment */
|
|
|
|
. = LOAD_OFFSET;
|
|
|
|
_start = .;
|
|
|
|
HEAD_TEXT_SECTION
|
2020-03-18 09:11:39 +08:00
|
|
|
. = ALIGN(PAGE_SIZE);
|
|
|
|
|
2020-11-05 08:04:38 +08:00
|
|
|
.text : {
|
|
|
|
_text = .;
|
|
|
|
_stext = .;
|
|
|
|
TEXT_TEXT
|
|
|
|
SCHED_TEXT
|
|
|
|
CPUIDLE_TEXT
|
|
|
|
LOCK_TEXT
|
|
|
|
KPROBES_TEXT
|
|
|
|
ENTRY_TEXT
|
|
|
|
IRQENTRY_TEXT
|
|
|
|
SOFTIRQENTRY_TEXT
|
|
|
|
_etext = .;
|
|
|
|
}
|
|
|
|
|
|
|
|
. = ALIGN(SECTION_ALIGN);
|
2020-03-18 09:11:39 +08:00
|
|
|
__init_begin = .;
|
2020-11-05 08:04:37 +08:00
|
|
|
__init_text_begin = .;
|
|
|
|
.init.text : AT(ADDR(.init.text) - LOAD_OFFSET) ALIGN(SECTION_ALIGN) { \
|
|
|
|
_sinittext = .; \
|
|
|
|
INIT_TEXT \
|
|
|
|
_einittext = .; \
|
|
|
|
}
|
|
|
|
|
2020-03-16 08:47:38 +08:00
|
|
|
. = ALIGN(8);
|
|
|
|
__soc_early_init_table : {
|
|
|
|
__soc_early_init_table_start = .;
|
|
|
|
KEEP(*(__soc_early_init_table))
|
|
|
|
__soc_early_init_table_end = .;
|
|
|
|
}
|
2020-04-14 12:43:24 +08:00
|
|
|
__soc_builtin_dtb_table : {
|
|
|
|
__soc_builtin_dtb_table_start = .;
|
|
|
|
KEEP(*(__soc_builtin_dtb_table))
|
|
|
|
__soc_builtin_dtb_table_end = .;
|
|
|
|
}
|
2017-07-11 09:08:08 +08:00
|
|
|
/* we have to discard exit text and such at runtime, not link time */
|
|
|
|
.exit.text :
|
|
|
|
{
|
|
|
|
EXIT_TEXT
|
|
|
|
}
|
|
|
|
|
2020-11-05 08:04:38 +08:00
|
|
|
__init_text_end = .;
|
2020-03-10 00:55:40 +08:00
|
|
|
. = ALIGN(SECTION_ALIGN);
|
2020-09-18 06:37:13 +08:00
|
|
|
#ifdef CONFIG_EFI
|
|
|
|
. = ALIGN(PECOFF_SECTION_ALIGNMENT);
|
|
|
|
__pecoff_text_end = .;
|
|
|
|
#endif
|
2020-11-05 08:04:38 +08:00
|
|
|
/* Start of init data section */
|
|
|
|
__init_data_begin = .;
|
2020-10-07 00:49:33 +08:00
|
|
|
INIT_DATA_SECTION(16)
|
2020-11-05 08:04:38 +08:00
|
|
|
.exit.data :
|
|
|
|
{
|
|
|
|
EXIT_DATA
|
|
|
|
}
|
|
|
|
PERCPU_SECTION(L1_CACHE_BYTES)
|
|
|
|
|
2020-11-05 08:04:39 +08:00
|
|
|
.rel.dyn : {
|
|
|
|
*(.rel.dyn*)
|
|
|
|
}
|
|
|
|
|
2020-11-05 08:04:38 +08:00
|
|
|
__init_data_end = .;
|
riscv: Introduce alternative mechanism to apply errata solution
Introduce the "alternative" mechanism from ARM64 and x86 to apply the CPU
vendors' errata solution at runtime. The main purpose of this patch is
to provide a framework. Therefore, the implementation is quite basic for
now so that some scenarios could not use this schemei, such as patching
code to a module, relocating the patching code and heterogeneous CPU
topology.
Users could use the macro ALTERNATIVE to apply an errata to the existing
code flow. In the macro ALTERNATIVE, users need to specify the manufacturer
information(vendorid, archid, and impid) for this errata. Therefore, kernel
will know this errata is suitable for which CPU core. During the booting
procedure, kernel will select the errata required by the CPU core and then
patch it. It means that the kernel only applies the errata to the specified
CPU core. In this case, the vendor's errata does not affect each other at
runtime. The above patching procedure only occurs during the booting phase,
so we only take the overhead of the "alternative" mechanism once.
This "alternative" mechanism is enabled by default to ensure that all
required errata will be applied. However, users can disable this feature by
the Kconfig "CONFIG_RISCV_ERRATA_ALTERNATIVE".
Signed-off-by: Vincent Chen <vincent.chen@sifive.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
2021-03-22 22:26:03 +08:00
|
|
|
|
|
|
|
. = ALIGN(8);
|
|
|
|
.alternative : {
|
|
|
|
__alt_start = .;
|
|
|
|
*(.alternative)
|
|
|
|
__alt_end = .;
|
|
|
|
}
|
2020-11-05 08:04:38 +08:00
|
|
|
__init_end = .;
|
2020-10-07 00:49:33 +08:00
|
|
|
|
2017-07-11 09:08:08 +08:00
|
|
|
/* Start of data section */
|
|
|
|
_sdata = .;
|
2020-03-10 00:55:40 +08:00
|
|
|
RO_DATA(SECTION_ALIGN)
|
2017-07-11 09:08:08 +08:00
|
|
|
.srodata : {
|
|
|
|
*(.srodata*)
|
|
|
|
}
|
|
|
|
|
2020-03-10 00:55:40 +08:00
|
|
|
. = ALIGN(SECTION_ALIGN);
|
2020-03-10 00:55:39 +08:00
|
|
|
_data = .;
|
|
|
|
|
riscv: add VMAP_STACK overflow detection
This patch adds stack overflow detection to riscv, usable when
CONFIG_VMAP_STACK=y.
Overflow is detected in kernel exception entry(kernel/entry.S), if the
kernel stack is overflow and been detected, the overflow handler is
invoked on a per-cpu overflow stack. This approach preserves GPRs and
the original exception information.
The overflow detect is performed before any attempt is made to access
the stack and the principle of stack overflow detection: kernel stacks
are aligned to double their size, enabling overflow to be detected with
a single bit test. For example, a 16K stack is aligned to 32K, ensuring
that bit 14 of the SP must be zero. On an overflow (or underflow), this
bit is flipped. Thus, overflow (of less than the size of the stack) can
be detected by testing whether this bit is set.
This gives us a useful error message on stack overflow, as can be
trigger with the LKDTM overflow test:
[ 388.053267] lkdtm: Performing direct entry EXHAUST_STACK
[ 388.053663] lkdtm: Calling function with 1024 frame size to depth 32 ...
[ 388.054016] lkdtm: loop 32/32 ...
[ 388.054186] lkdtm: loop 31/32 ...
[ 388.054491] lkdtm: loop 30/32 ...
[ 388.054672] lkdtm: loop 29/32 ...
[ 388.054859] lkdtm: loop 28/32 ...
[ 388.055010] lkdtm: loop 27/32 ...
[ 388.055163] lkdtm: loop 26/32 ...
[ 388.055309] lkdtm: loop 25/32 ...
[ 388.055481] lkdtm: loop 24/32 ...
[ 388.055653] lkdtm: loop 23/32 ...
[ 388.055837] lkdtm: loop 22/32 ...
[ 388.056015] lkdtm: loop 21/32 ...
[ 388.056188] lkdtm: loop 20/32 ...
[ 388.058145] Insufficient stack space to handle exception!
[ 388.058153] Task stack: [0xffffffd014260000..0xffffffd014264000]
[ 388.058160] Overflow stack: [0xffffffe1f8d2c220..0xffffffe1f8d2d220]
[ 388.058168] CPU: 0 PID: 89 Comm: bash Not tainted 5.12.0-rc8-dirty #90
[ 388.058175] Hardware name: riscv-virtio,qemu (DT)
[ 388.058187] epc : number+0x32/0x2c0
[ 388.058247] ra : vsnprintf+0x2ae/0x3f0
[ 388.058255] epc : ffffffe0002d38f6 ra : ffffffe0002d814e sp : ffffffd01425ffc0
[ 388.058263] gp : ffffffe0012e4010 tp : ffffffe08014da00 t0 : ffffffd0142606e8
[ 388.058271] t1 : 0000000000000000 t2 : 0000000000000000 s0 : ffffffd014260070
[ 388.058303] s1 : ffffffd014260158 a0 : ffffffd01426015e a1 : ffffffd014260158
[ 388.058311] a2 : 0000000000000013 a3 : ffff0a01ffffff10 a4 : ffffffe000c398e0
[ 388.058319] a5 : 511b02ec65f3e300 a6 : 0000000000a1749a a7 : 0000000000000000
[ 388.058327] s2 : ffffffff000000ff s3 : 00000000ffff0a01 s4 : ffffffe0012e50a8
[ 388.058335] s5 : 0000000000ffff0a s6 : ffffffe0012e50a8 s7 : ffffffe000da1cc0
[ 388.058343] s8 : ffffffffffffffff s9 : ffffffd0142602b0 s10: ffffffd0142602a8
[ 388.058351] s11: ffffffd01426015e t3 : 00000000000f0000 t4 : ffffffffffffffff
[ 388.058359] t5 : 000000000000002f t6 : ffffffd014260158
[ 388.058366] status: 0000000000000100 badaddr: ffffffd01425fff8 cause: 000000000000000f
[ 388.058374] Kernel panic - not syncing: Kernel stack overflow
[ 388.058381] CPU: 0 PID: 89 Comm: bash Not tainted 5.12.0-rc8-dirty #90
[ 388.058387] Hardware name: riscv-virtio,qemu (DT)
[ 388.058393] Call Trace:
[ 388.058400] [<ffffffe000004944>] walk_stackframe+0x0/0xce
[ 388.058406] [<ffffffe0006f0b28>] dump_backtrace+0x38/0x46
[ 388.058412] [<ffffffe0006f0b46>] show_stack+0x10/0x18
[ 388.058418] [<ffffffe0006f3690>] dump_stack+0x74/0x8e
[ 388.058424] [<ffffffe0006f0d52>] panic+0xfc/0x2b2
[ 388.058430] [<ffffffe0006f0acc>] print_trace_address+0x0/0x24
[ 388.058436] [<ffffffe0002d814e>] vsnprintf+0x2ae/0x3f0
[ 388.058956] SMP: stopping secondary CPUs
Signed-off-by: Tong Tiangen <tongtiangen@huawei.com>
Reviewed-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
2021-06-21 11:28:55 +08:00
|
|
|
RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
|
2017-07-11 09:08:08 +08:00
|
|
|
.sdata : {
|
|
|
|
__global_pointer$ = . + 0x800;
|
|
|
|
*(.sdata*)
|
|
|
|
}
|
|
|
|
|
2020-09-18 06:37:13 +08:00
|
|
|
#ifdef CONFIG_EFI
|
|
|
|
.pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
|
|
|
|
__pecoff_data_raw_size = ABSOLUTE(. - __pecoff_text_end);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* End of data section */
|
|
|
|
_edata = .;
|
|
|
|
|
2019-02-09 01:11:08 +08:00
|
|
|
BSS_SECTION(PAGE_SIZE, PAGE_SIZE, 0)
|
|
|
|
|
2020-09-18 06:37:13 +08:00
|
|
|
#ifdef CONFIG_EFI
|
|
|
|
. = ALIGN(PECOFF_SECTION_ALIGNMENT);
|
|
|
|
__pecoff_data_virt_size = ABSOLUTE(. - __pecoff_text_end);
|
|
|
|
#endif
|
2017-07-11 09:08:08 +08:00
|
|
|
_end = .;
|
|
|
|
|
|
|
|
STABS_DEBUG
|
|
|
|
DWARF_DEBUG
|
2020-08-22 03:42:45 +08:00
|
|
|
ELF_DETAILS
|
2017-07-11 09:08:08 +08:00
|
|
|
|
|
|
|
DISCARDS
|
|
|
|
}
|
2021-04-13 14:35:14 +08:00
|
|
|
#endif /* CONFIG_XIP_KERNEL */
|