From 2f181e0ba8db654cf9e1b6abe454aebca9587448 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Tue, 27 Feb 2018 22:39:27 -0500 Subject: [PATCH 01/10] ARM: linker script: factor out some common definitions between XIP and non-XIP Lots of duplications between vmlinux.lds.S and vmlinux-xip.lds.S. This may lead to one file being updated but not the other. For example, SOFTIRQENTRY_TEXT and HYPERVISOR_TEXT were missing from the XIP version. This creates vmlinux.lds.h where a bunch of common defines are moved. Signed-off-by: Nicolas Pitre Tested-by: Chris Brandt --- arch/arm/kernel/vmlinux-xip.lds.S | 35 +++------------------------ arch/arm/kernel/vmlinux.lds.S | 38 +---------------------------- arch/arm/kernel/vmlinux.lds.h | 40 +++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 69 deletions(-) create mode 100644 arch/arm/kernel/vmlinux.lds.h diff --git a/arch/arm/kernel/vmlinux-xip.lds.S b/arch/arm/kernel/vmlinux-xip.lds.S index 12b87591eb7c..0a8922b61613 100644 --- a/arch/arm/kernel/vmlinux-xip.lds.S +++ b/arch/arm/kernel/vmlinux-xip.lds.S @@ -15,38 +15,7 @@ #include #include -#define PROC_INFO \ - . = ALIGN(4); \ - VMLINUX_SYMBOL(__proc_info_begin) = .; \ - *(.proc.info.init) \ - VMLINUX_SYMBOL(__proc_info_end) = .; - -#define IDMAP_TEXT \ - ALIGN_FUNCTION(); \ - VMLINUX_SYMBOL(__idmap_text_start) = .; \ - *(.idmap.text) \ - VMLINUX_SYMBOL(__idmap_text_end) = .; \ - . = ALIGN(PAGE_SIZE); \ - VMLINUX_SYMBOL(__hyp_idmap_text_start) = .; \ - *(.hyp.idmap.text) \ - VMLINUX_SYMBOL(__hyp_idmap_text_end) = .; - -#ifdef CONFIG_HOTPLUG_CPU -#define ARM_CPU_DISCARD(x) -#define ARM_CPU_KEEP(x) x -#else -#define ARM_CPU_DISCARD(x) x -#define ARM_CPU_KEEP(x) -#endif - -#if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \ - defined(CONFIG_GENERIC_BUG) -#define ARM_EXIT_KEEP(x) x -#define ARM_EXIT_DISCARD(x) -#else -#define ARM_EXIT_KEEP(x) -#define ARM_EXIT_DISCARD(x) x -#endif +#include "vmlinux.lds.h" OUTPUT_ARCH(arm) ENTRY(stext) @@ -100,10 +69,12 @@ SECTIONS *(.entry.text) __entry_text_end = .; IRQENTRY_TEXT + SOFTIRQENTRY_TEXT TEXT_TEXT SCHED_TEXT CPUIDLE_TEXT LOCK_TEXT + HYPERVISOR_TEXT KPROBES_TEXT *(.gnu.warning) *(.glue_7) diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S index 84a1ae3ce46e..6a6eb483d92c 100644 --- a/arch/arm/kernel/vmlinux.lds.S +++ b/arch/arm/kernel/vmlinux.lds.S @@ -15,43 +15,7 @@ #include #include -#define PROC_INFO \ - . = ALIGN(4); \ - VMLINUX_SYMBOL(__proc_info_begin) = .; \ - *(.proc.info.init) \ - VMLINUX_SYMBOL(__proc_info_end) = .; - -#define HYPERVISOR_TEXT \ - VMLINUX_SYMBOL(__hyp_text_start) = .; \ - *(.hyp.text) \ - VMLINUX_SYMBOL(__hyp_text_end) = .; - -#define IDMAP_TEXT \ - ALIGN_FUNCTION(); \ - VMLINUX_SYMBOL(__idmap_text_start) = .; \ - *(.idmap.text) \ - VMLINUX_SYMBOL(__idmap_text_end) = .; \ - . = ALIGN(PAGE_SIZE); \ - VMLINUX_SYMBOL(__hyp_idmap_text_start) = .; \ - *(.hyp.idmap.text) \ - VMLINUX_SYMBOL(__hyp_idmap_text_end) = .; - -#ifdef CONFIG_HOTPLUG_CPU -#define ARM_CPU_DISCARD(x) -#define ARM_CPU_KEEP(x) x -#else -#define ARM_CPU_DISCARD(x) x -#define ARM_CPU_KEEP(x) -#endif - -#if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \ - defined(CONFIG_GENERIC_BUG) || defined(CONFIG_JUMP_LABEL) -#define ARM_EXIT_KEEP(x) x -#define ARM_EXIT_DISCARD(x) -#else -#define ARM_EXIT_KEEP(x) -#define ARM_EXIT_DISCARD(x) x -#endif +#include "vmlinux.lds.h" OUTPUT_ARCH(arm) ENTRY(stext) diff --git a/arch/arm/kernel/vmlinux.lds.h b/arch/arm/kernel/vmlinux.lds.h new file mode 100644 index 000000000000..0a86e8a1119e --- /dev/null +++ b/arch/arm/kernel/vmlinux.lds.h @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifdef CONFIG_HOTPLUG_CPU +#define ARM_CPU_DISCARD(x) +#define ARM_CPU_KEEP(x) x +#else +#define ARM_CPU_DISCARD(x) x +#define ARM_CPU_KEEP(x) +#endif + +#if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \ + defined(CONFIG_GENERIC_BUG) || defined(CONFIG_JUMP_LABEL) +#define ARM_EXIT_KEEP(x) x +#define ARM_EXIT_DISCARD(x) +#else +#define ARM_EXIT_KEEP(x) +#define ARM_EXIT_DISCARD(x) x +#endif + +#define PROC_INFO \ + . = ALIGN(4); \ + VMLINUX_SYMBOL(__proc_info_begin) = .; \ + *(.proc.info.init) \ + VMLINUX_SYMBOL(__proc_info_end) = .; + +#define HYPERVISOR_TEXT \ + VMLINUX_SYMBOL(__hyp_text_start) = .; \ + *(.hyp.text) \ + VMLINUX_SYMBOL(__hyp_text_end) = .; + +#define IDMAP_TEXT \ + ALIGN_FUNCTION(); \ + VMLINUX_SYMBOL(__idmap_text_start) = .; \ + *(.idmap.text) \ + VMLINUX_SYMBOL(__idmap_text_end) = .; \ + . = ALIGN(PAGE_SIZE); \ + VMLINUX_SYMBOL(__hyp_idmap_text_start) = .; \ + *(.hyp.idmap.text) \ + VMLINUX_SYMBOL(__hyp_idmap_text_end) = .; + From ab42fad00953301c0d25d71340bf194868bd3df9 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Mon, 5 Mar 2018 16:34:03 -0500 Subject: [PATCH 02/10] ARM: linker script: factor out stuff for the DISCARD section Move common entries to vmlinux.lds.h and leave XIP and non-XIP entries in their respective file. The ARM_NOMMU_KEEP() and ARM_NOMMU_DISCARD() macros are added to be usable within the definition of ARM_DISCARD macro. Signed-off-by: Nicolas Pitre Tested-by: Chris Brandt --- arch/arm/kernel/vmlinux-xip.lds.S | 19 +++---------------- arch/arm/kernel/vmlinux.lds.S | 18 ++---------------- arch/arm/kernel/vmlinux.lds.h | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+), 32 deletions(-) diff --git a/arch/arm/kernel/vmlinux-xip.lds.S b/arch/arm/kernel/vmlinux-xip.lds.S index 0a8922b61613..4bd422966d92 100644 --- a/arch/arm/kernel/vmlinux-xip.lds.S +++ b/arch/arm/kernel/vmlinux-xip.lds.S @@ -38,20 +38,9 @@ SECTIONS * unwind sections get included. */ /DISCARD/ : { - *(.ARM.exidx.exit.text) - *(.ARM.extab.exit.text) - ARM_CPU_DISCARD(*(.ARM.exidx.cpuexit.text)) - ARM_CPU_DISCARD(*(.ARM.extab.cpuexit.text)) - ARM_EXIT_DISCARD(EXIT_TEXT) - ARM_EXIT_DISCARD(EXIT_DATA) - EXIT_CALL -#ifndef CONFIG_MMU - *(.text.fixup) - *(__ex_table) -#endif + ARM_DISCARD *(.alt.smp.init) - *(.discard) - *(.discard.*) + *(.pv_table) } . = XIP_VIRT_ADDR(CONFIG_XIP_PHYS_ADDR); @@ -89,9 +78,7 @@ SECTIONS . = ALIGN(4); __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { __start___ex_table = .; -#ifdef CONFIG_MMU - *(__ex_table) -#endif + ARM_MMU_KEEP(*(__ex_table)) __stop___ex_table = .; } diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S index 6a6eb483d92c..b34fbafd543a 100644 --- a/arch/arm/kernel/vmlinux.lds.S +++ b/arch/arm/kernel/vmlinux.lds.S @@ -38,22 +38,10 @@ SECTIONS * unwind sections get included. */ /DISCARD/ : { - *(.ARM.exidx.exit.text) - *(.ARM.extab.exit.text) - ARM_CPU_DISCARD(*(.ARM.exidx.cpuexit.text)) - ARM_CPU_DISCARD(*(.ARM.extab.cpuexit.text)) - ARM_EXIT_DISCARD(EXIT_TEXT) - ARM_EXIT_DISCARD(EXIT_DATA) - EXIT_CALL -#ifndef CONFIG_MMU - *(.text.fixup) - *(__ex_table) -#endif + ARM_DISCARD #ifndef CONFIG_SMP_ON_UP *(.alt.smp.init) #endif - *(.discard) - *(.discard.*) } . = PAGE_OFFSET + TEXT_OFFSET; @@ -98,9 +86,7 @@ SECTIONS . = ALIGN(4); __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { __start___ex_table = .; -#ifdef CONFIG_MMU - *(__ex_table) -#endif + ARM_MMU_KEEP(*(__ex_table)) __stop___ex_table = .; } diff --git a/arch/arm/kernel/vmlinux.lds.h b/arch/arm/kernel/vmlinux.lds.h index 0a86e8a1119e..1258b66487b2 100644 --- a/arch/arm/kernel/vmlinux.lds.h +++ b/arch/arm/kernel/vmlinux.lds.h @@ -17,6 +17,14 @@ #define ARM_EXIT_DISCARD(x) x #endif +#ifdef CONFIG_MMU +#define ARM_MMU_KEEP(x) x +#define ARM_MMU_DISCARD(x) +#else +#define ARM_MMU_KEEP(x) +#define ARM_MMU_DISCARD(x) x +#endif + #define PROC_INFO \ . = ALIGN(4); \ VMLINUX_SYMBOL(__proc_info_begin) = .; \ @@ -38,3 +46,15 @@ *(.hyp.idmap.text) \ VMLINUX_SYMBOL(__hyp_idmap_text_end) = .; +#define ARM_DISCARD \ + *(.ARM.exidx.exit.text) \ + *(.ARM.extab.exit.text) \ + ARM_CPU_DISCARD(*(.ARM.exidx.cpuexit.text)) \ + ARM_CPU_DISCARD(*(.ARM.extab.cpuexit.text)) \ + ARM_EXIT_DISCARD(EXIT_TEXT) \ + ARM_EXIT_DISCARD(EXIT_DATA) \ + EXIT_CALL \ + ARM_MMU_DISCARD(*(.text.fixup)) \ + ARM_MMU_DISCARD(*(__ex_table)) \ + *(.discard) \ + *(.discard.*) From 47b4c77dc3565993e4925fb1c0cf00790f3b1eee Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Mon, 5 Mar 2018 16:34:03 -0500 Subject: [PATCH 03/10] ARM: linker script: factor out stuff for the .text section Move common entries to vmlinux.lds.h as ARM_TEXT. Signed-off-by: Nicolas Pitre Tested-by: Chris Brandt --- arch/arm/kernel/vmlinux-xip.lds.S | 19 +------------------ arch/arm/kernel/vmlinux.lds.S | 19 +------------------ arch/arm/kernel/vmlinux.lds.h | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+), 36 deletions(-) diff --git a/arch/arm/kernel/vmlinux-xip.lds.S b/arch/arm/kernel/vmlinux-xip.lds.S index 4bd422966d92..4ddb547b19b0 100644 --- a/arch/arm/kernel/vmlinux-xip.lds.S +++ b/arch/arm/kernel/vmlinux-xip.lds.S @@ -53,24 +53,7 @@ SECTIONS .text : { /* Real text segment */ _stext = .; /* Text and read-only data */ - IDMAP_TEXT - __entry_text_start = .; - *(.entry.text) - __entry_text_end = .; - IRQENTRY_TEXT - SOFTIRQENTRY_TEXT - TEXT_TEXT - SCHED_TEXT - CPUIDLE_TEXT - LOCK_TEXT - HYPERVISOR_TEXT - KPROBES_TEXT - *(.gnu.warning) - *(.glue_7) - *(.glue_7t) - . = ALIGN(4); - *(.got) /* Global offset table */ - ARM_CPU_KEEP(PROC_INFO) + ARM_TEXT } RO_DATA(PAGE_SIZE) diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S index b34fbafd543a..a02a96c651f6 100644 --- a/arch/arm/kernel/vmlinux.lds.S +++ b/arch/arm/kernel/vmlinux.lds.S @@ -56,24 +56,7 @@ SECTIONS .text : { /* Real text segment */ _stext = .; /* Text and read-only data */ - IDMAP_TEXT - __entry_text_start = .; - *(.entry.text) - __entry_text_end = .; - IRQENTRY_TEXT - SOFTIRQENTRY_TEXT - TEXT_TEXT - SCHED_TEXT - CPUIDLE_TEXT - LOCK_TEXT - HYPERVISOR_TEXT - KPROBES_TEXT - *(.gnu.warning) - *(.glue_7) - *(.glue_7t) - . = ALIGN(4); - *(.got) /* Global offset table */ - ARM_CPU_KEEP(PROC_INFO) + ARM_TEXT } #ifdef CONFIG_DEBUG_ALIGN_RODATA diff --git a/arch/arm/kernel/vmlinux.lds.h b/arch/arm/kernel/vmlinux.lds.h index 1258b66487b2..0ef86d75a001 100644 --- a/arch/arm/kernel/vmlinux.lds.h +++ b/arch/arm/kernel/vmlinux.lds.h @@ -58,3 +58,23 @@ ARM_MMU_DISCARD(*(__ex_table)) \ *(.discard) \ *(.discard.*) + +#define ARM_TEXT \ + IDMAP_TEXT \ + __entry_text_start = .; \ + *(.entry.text) \ + __entry_text_end = .; \ + IRQENTRY_TEXT \ + SOFTIRQENTRY_TEXT \ + TEXT_TEXT \ + SCHED_TEXT \ + CPUIDLE_TEXT \ + LOCK_TEXT \ + HYPERVISOR_TEXT \ + KPROBES_TEXT \ + *(.gnu.warning) \ + *(.glue_7) \ + *(.glue_7t) \ + . = ALIGN(4); \ + *(.got) /* Global offset table */ \ + ARM_CPU_KEEP(PROC_INFO) From d9a46e6e714178f6ce7fe2c536c59542a2964f6f Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Thu, 1 Mar 2018 17:32:28 -0500 Subject: [PATCH 04/10] ARM: linker script: factor out unwinding table sections Signed-off-by: Nicolas Pitre Tested-by: Chris Brandt --- arch/arm/kernel/vmlinux-xip.lds.S | 15 +-------------- arch/arm/kernel/vmlinux.lds.S | 15 +-------------- arch/arm/kernel/vmlinux.lds.h | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 28 deletions(-) diff --git a/arch/arm/kernel/vmlinux-xip.lds.S b/arch/arm/kernel/vmlinux-xip.lds.S index 4ddb547b19b0..65048708e4c6 100644 --- a/arch/arm/kernel/vmlinux-xip.lds.S +++ b/arch/arm/kernel/vmlinux-xip.lds.S @@ -66,20 +66,7 @@ SECTIONS } #ifdef CONFIG_ARM_UNWIND - /* - * Stack unwinding tables - */ - . = ALIGN(8); - .ARM.unwind_idx : { - __start_unwind_idx = .; - *(.ARM.exidx*) - __stop_unwind_idx = .; - } - .ARM.unwind_tab : { - __start_unwind_tab = .; - *(.ARM.extab*) - __stop_unwind_tab = .; - } + ARM_UNWIND_SECTIONS #endif NOTES diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S index a02a96c651f6..3b375d8ccb87 100644 --- a/arch/arm/kernel/vmlinux.lds.S +++ b/arch/arm/kernel/vmlinux.lds.S @@ -74,20 +74,7 @@ SECTIONS } #ifdef CONFIG_ARM_UNWIND - /* - * Stack unwinding tables - */ - . = ALIGN(8); - .ARM.unwind_idx : { - __start_unwind_idx = .; - *(.ARM.exidx*) - __stop_unwind_idx = .; - } - .ARM.unwind_tab : { - __start_unwind_tab = .; - *(.ARM.extab*) - __stop_unwind_tab = .; - } + ARM_UNWIND_SECTIONS #endif NOTES diff --git a/arch/arm/kernel/vmlinux.lds.h b/arch/arm/kernel/vmlinux.lds.h index 0ef86d75a001..566a7b42a02c 100644 --- a/arch/arm/kernel/vmlinux.lds.h +++ b/arch/arm/kernel/vmlinux.lds.h @@ -78,3 +78,17 @@ . = ALIGN(4); \ *(.got) /* Global offset table */ \ ARM_CPU_KEEP(PROC_INFO) + +/* Stack unwinding tables */ +#define ARM_UNWIND_SECTIONS \ + . = ALIGN(8); \ + .ARM.unwind_idx : { \ + __start_unwind_idx = .; \ + *(.ARM.exidx*) \ + __stop_unwind_idx = .; \ + } \ + .ARM.unwind_tab : { \ + __start_unwind_tab = .; \ + *(.ARM.extab*) \ + __stop_unwind_tab = .; \ + } From 9147095896fb321ae10ec5a5f789079318137ac9 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Thu, 1 Mar 2018 22:17:03 -0500 Subject: [PATCH 05/10] ARM: linker script: factor out vectors and stubs Signed-off-by: Nicolas Pitre Tested-by: Chris Brandt --- arch/arm/kernel/vmlinux-xip.lds.S | 21 +-------------------- arch/arm/kernel/vmlinux.lds.S | 21 +-------------------- arch/arm/kernel/vmlinux.lds.h | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+), 40 deletions(-) diff --git a/arch/arm/kernel/vmlinux-xip.lds.S b/arch/arm/kernel/vmlinux-xip.lds.S index 65048708e4c6..5a50a2a917f5 100644 --- a/arch/arm/kernel/vmlinux-xip.lds.S +++ b/arch/arm/kernel/vmlinux-xip.lds.S @@ -73,26 +73,7 @@ SECTIONS _etext = .; /* End of text and rodata section */ - /* - * The vectors and stubs are relocatable code, and the - * only thing that matters is their relative offsets - */ - __vectors_start = .; - .vectors 0xffff0000 : AT(__vectors_start) { - *(.vectors) - } - . = __vectors_start + SIZEOF(.vectors); - __vectors_end = .; - - __stubs_start = .; - .stubs ADDR(.vectors) + 0x1000 : AT(__stubs_start) { - *(.stubs) - } - . = __stubs_start + SIZEOF(.stubs); - __stubs_end = .; - - PROVIDE(vector_fiq_offset = vector_fiq - ADDR(.vectors)); - + ARM_VECTORS INIT_TEXT_SECTION(8) .exit.text : { ARM_EXIT_KEEP(EXIT_TEXT) diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S index 3b375d8ccb87..2b8936309061 100644 --- a/arch/arm/kernel/vmlinux.lds.S +++ b/arch/arm/kernel/vmlinux.lds.S @@ -86,26 +86,7 @@ SECTIONS #endif __init_begin = .; - /* - * The vectors and stubs are relocatable code, and the - * only thing that matters is their relative offsets - */ - __vectors_start = .; - .vectors 0xffff0000 : AT(__vectors_start) { - *(.vectors) - } - . = __vectors_start + SIZEOF(.vectors); - __vectors_end = .; - - __stubs_start = .; - .stubs ADDR(.vectors) + 0x1000 : AT(__stubs_start) { - *(.stubs) - } - . = __stubs_start + SIZEOF(.stubs); - __stubs_end = .; - - PROVIDE(vector_fiq_offset = vector_fiq - ADDR(.vectors)); - + ARM_VECTORS INIT_TEXT_SECTION(8) .exit.text : { ARM_EXIT_KEEP(EXIT_TEXT) diff --git a/arch/arm/kernel/vmlinux.lds.h b/arch/arm/kernel/vmlinux.lds.h index 566a7b42a02c..0a4682ecc4ac 100644 --- a/arch/arm/kernel/vmlinux.lds.h +++ b/arch/arm/kernel/vmlinux.lds.h @@ -92,3 +92,24 @@ *(.ARM.extab*) \ __stop_unwind_tab = .; \ } + +/* + * The vectors and stubs are relocatable code, and the + * only thing that matters is their relative offsets + */ +#define ARM_VECTORS \ + __vectors_start = .; \ + .vectors 0xffff0000 : AT(__vectors_start) { \ + *(.vectors) \ + } \ + . = __vectors_start + SIZEOF(.vectors); \ + __vectors_end = .; \ + \ + __stubs_start = .; \ + .stubs ADDR(.vectors) + 0x1000 : AT(__stubs_start) { \ + *(.stubs) \ + } \ + . = __stubs_start + SIZEOF(.stubs); \ + __stubs_end = .; \ + \ + PROVIDE(vector_fiq_offset = vector_fiq - ADDR(.vectors)); From c3146c43db4974f4571bd9d42b172ca03a9137c6 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Thu, 8 Mar 2018 20:19:48 -0500 Subject: [PATCH 06/10] ARM: linker script: factor out TCM bits This is a plain move with identical results, and therefore still broken in the XIP case. Signed-off-by: Nicolas Pitre Tested-by: Chris Brandt --- arch/arm/kernel/vmlinux-xip.lds.S | 55 +--------------------------- arch/arm/kernel/vmlinux.lds.S | 55 +--------------------------- arch/arm/kernel/vmlinux.lds.h | 60 +++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 108 deletions(-) diff --git a/arch/arm/kernel/vmlinux-xip.lds.S b/arch/arm/kernel/vmlinux-xip.lds.S index 5a50a2a917f5..c727c56f3cb2 100644 --- a/arch/arm/kernel/vmlinux-xip.lds.S +++ b/arch/arm/kernel/vmlinux-xip.lds.S @@ -144,60 +144,7 @@ SECTIONS __init_end = .; #ifdef CONFIG_HAVE_TCM - /* - * We align everything to a page boundary so we can - * free it after init has commenced and TCM contents have - * been copied to its destination. - */ - .tcm_start : { - . = ALIGN(PAGE_SIZE); - __tcm_start = .; - __itcm_start = .; - } - - /* - * Link these to the ITCM RAM - * Put VMA to the TCM address and LMA to the common RAM - * and we'll upload the contents from RAM to TCM and free - * the used RAM after that. - */ - .text_itcm ITCM_OFFSET : AT(__itcm_start) - { - __sitcm_text = .; - *(.tcm.text) - *(.tcm.rodata) - . = ALIGN(4); - __eitcm_text = .; - } - - /* - * Reset the dot pointer, this is needed to create the - * relative __dtcm_start below (to be used as extern in code). - */ - . = ADDR(.tcm_start) + SIZEOF(.tcm_start) + SIZEOF(.text_itcm); - - .dtcm_start : { - __dtcm_start = .; - } - - /* TODO: add remainder of ITCM as well, that can be used for data! */ - .data_dtcm DTCM_OFFSET : AT(__dtcm_start) - { - . = ALIGN(4); - __sdtcm_data = .; - *(.tcm.data) - . = ALIGN(4); - __edtcm_data = .; - } - - /* Reset the dot pointer or the linker gets confused */ - . = ADDR(.dtcm_start) + SIZEOF(.data_dtcm); - - /* End marker for freeing TCM copy in linked object */ - .tcm_end : AT(ADDR(.dtcm_start) + SIZEOF(.data_dtcm)){ - . = ALIGN(PAGE_SIZE); - __tcm_end = .; - } + ARM_TCM #endif BSS_SECTION(0, 0, 8) diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S index 2b8936309061..1e9f2a6b3d33 100644 --- a/arch/arm/kernel/vmlinux.lds.S +++ b/arch/arm/kernel/vmlinux.lds.S @@ -139,60 +139,7 @@ SECTIONS _edata = .; #ifdef CONFIG_HAVE_TCM - /* - * We align everything to a page boundary so we can - * free it after init has commenced and TCM contents have - * been copied to its destination. - */ - .tcm_start : { - . = ALIGN(PAGE_SIZE); - __tcm_start = .; - __itcm_start = .; - } - - /* - * Link these to the ITCM RAM - * Put VMA to the TCM address and LMA to the common RAM - * and we'll upload the contents from RAM to TCM and free - * the used RAM after that. - */ - .text_itcm ITCM_OFFSET : AT(__itcm_start) - { - __sitcm_text = .; - *(.tcm.text) - *(.tcm.rodata) - . = ALIGN(4); - __eitcm_text = .; - } - - /* - * Reset the dot pointer, this is needed to create the - * relative __dtcm_start below (to be used as extern in code). - */ - . = ADDR(.tcm_start) + SIZEOF(.tcm_start) + SIZEOF(.text_itcm); - - .dtcm_start : { - __dtcm_start = .; - } - - /* TODO: add remainder of ITCM as well, that can be used for data! */ - .data_dtcm DTCM_OFFSET : AT(__dtcm_start) - { - . = ALIGN(4); - __sdtcm_data = .; - *(.tcm.data) - . = ALIGN(4); - __edtcm_data = .; - } - - /* Reset the dot pointer or the linker gets confused */ - . = ADDR(.dtcm_start) + SIZEOF(.data_dtcm); - - /* End marker for freeing TCM copy in linked object */ - .tcm_end : AT(ADDR(.dtcm_start) + SIZEOF(.data_dtcm)){ - . = ALIGN(PAGE_SIZE); - __tcm_end = .; - } + ARM_TCM #endif BSS_SECTION(0, 0, 0) diff --git a/arch/arm/kernel/vmlinux.lds.h b/arch/arm/kernel/vmlinux.lds.h index 0a4682ecc4ac..cf9dabbdbde4 100644 --- a/arch/arm/kernel/vmlinux.lds.h +++ b/arch/arm/kernel/vmlinux.lds.h @@ -113,3 +113,63 @@ __stubs_end = .; \ \ PROVIDE(vector_fiq_offset = vector_fiq - ADDR(.vectors)); + +#define ARM_TCM \ + /* \ + * We align everything to a page boundary so we can \ + * free it after init has commenced and TCM contents have \ + * been copied to its destination. \ + */ \ + .tcm_start : { \ + . = ALIGN(PAGE_SIZE); \ + __tcm_start = .; \ + __itcm_start = .; \ + } \ + \ + /* \ + * Link these to the ITCM RAM \ + * \ + * Put VMA to the TCM address and LMA to the common RAM \ + * and we'll upload the contents from RAM to TCM and free \ + * the used RAM after that. \ + */ \ + .text_itcm ITCM_OFFSET : AT(__itcm_start) \ + { \ + __sitcm_text = .; \ + *(.tcm.text) \ + *(.tcm.rodata) \ + . = ALIGN(4); \ + __eitcm_text = .; \ + } \ + \ + /* \ + * Reset the dot pointer, this is needed to create the \ + * relative __dtcm_start below (to be used as extern in code). \ + */ \ + . = ADDR(.tcm_start) + SIZEOF(.tcm_start) + SIZEOF(.text_itcm); \ + \ + .dtcm_start : { \ + __dtcm_start = .; \ + } \ + \ + /* \ + * TODO: add remainder of ITCM as well, \ + * that can be used for data! \ + */ \ + .data_dtcm DTCM_OFFSET : AT(__dtcm_start) \ + { \ + . = ALIGN(4); \ + __sdtcm_data = .; \ + *(.tcm.data) \ + . = ALIGN(4); \ + __edtcm_data = .; \ + } \ + \ + /* Reset the dot pointer or the linker gets confused */ \ + . = ADDR(.dtcm_start) + SIZEOF(.data_dtcm); \ + \ + /* End marker for freeing TCM copy in linked object */ \ + .tcm_end : AT(ADDR(.dtcm_start) + SIZEOF(.data_dtcm)){ \ + . = ALIGN(PAGE_SIZE); \ + __tcm_end = .; \ + } From b54290e51accea4f696f5dacef8e609d0ccbe54a Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Thu, 8 Mar 2018 21:12:04 -0500 Subject: [PATCH 07/10] ARM: simplify and fix linker script for TCM Let's put the TCM stuff in the __init section directly. No need for a separately freed memory area. Remove redundant linker sections, as well as comments that were more confusing than no comments at all. Finally make it XIP compatible by using LOAD_OFFSET in the section LMA specification. Signed-off-by: Nicolas Pitre Tested-by: Chris Brandt --- arch/arm/kernel/vmlinux-xip.lds.S | 8 ++--- arch/arm/kernel/vmlinux.lds.S | 8 ++--- arch/arm/kernel/vmlinux.lds.h | 52 ++++--------------------------- arch/arm/mm/init.c | 11 ------- 4 files changed, 14 insertions(+), 65 deletions(-) diff --git a/arch/arm/kernel/vmlinux-xip.lds.S b/arch/arm/kernel/vmlinux-xip.lds.S index c727c56f3cb2..d32f5d35f602 100644 --- a/arch/arm/kernel/vmlinux-xip.lds.S +++ b/arch/arm/kernel/vmlinux-xip.lds.S @@ -132,6 +132,10 @@ SECTIONS PERCPU_SECTION(L1_CACHE_BYTES) #endif +#ifdef CONFIG_HAVE_TCM + ARM_TCM +#endif + /* * End of copied data. We need a dummy section to get its LMA. * Also located before final ALIGN() as trailing padding is not stored @@ -143,10 +147,6 @@ SECTIONS . = ALIGN(PAGE_SIZE); __init_end = .; -#ifdef CONFIG_HAVE_TCM - ARM_TCM -#endif - BSS_SECTION(0, 0, 8) _end = .; diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S index 1e9f2a6b3d33..b77dc675ae55 100644 --- a/arch/arm/kernel/vmlinux.lds.S +++ b/arch/arm/kernel/vmlinux.lds.S @@ -127,6 +127,10 @@ SECTIONS PERCPU_SECTION(L1_CACHE_BYTES) #endif +#ifdef CONFIG_HAVE_TCM + ARM_TCM +#endif + #ifdef CONFIG_STRICT_KERNEL_RWX . = ALIGN(1< Date: Tue, 6 Mar 2018 01:39:24 +0100 Subject: [PATCH 08/10] ARM: 8749/1: Kconfig: Add ARCH_HAS_FORTIFY_SOURCE CONFIG_FORTIFY_SOURCE detects various overflows at compile-time. (6974f0c4555e ("include/linux/string.h: add the option of fortified string.h functions) ARCH_HAS_FORTIFY_SOURCE means that the architecture can be built and run with CONFIG_FORTIFY_SOURCE. Since ARM can be built and run with that flag like other architectures, select ARCH_HAS_FORTIFY_SOURCE as default. Acked-by: Kees Cook Signed-off-by: Jinbum Park Signed-off-by: Russell King --- arch/arm/Kconfig | 1 + arch/arm/boot/compressed/misc.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 7e3d53575486..3765336e5ec6 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -7,6 +7,7 @@ config ARM select ARCH_HAS_DEBUG_VIRTUAL if MMU select ARCH_HAS_DEVMEM_IS_ALLOWED select ARCH_HAS_ELF_RANDOMIZE + select ARCH_HAS_FORTIFY_SOURCE select ARCH_HAS_SET_MEMORY select ARCH_HAS_PHYS_TO_DMA select ARCH_HAS_STRICT_KERNEL_RWX if MMU && !XIP_KERNEL diff --git a/arch/arm/boot/compressed/misc.c b/arch/arm/boot/compressed/misc.c index 16a8a804e958..4a247acd1b96 100644 --- a/arch/arm/boot/compressed/misc.c +++ b/arch/arm/boot/compressed/misc.c @@ -167,3 +167,8 @@ decompress_kernel(unsigned long output_start, unsigned long free_mem_ptr_p, else putstr(" done, booting the kernel.\n"); } + +void fortify_panic(const char *name) +{ + error("detected buffer overflow"); +} From 8aeaf4a0d22c6b3ab00003e3412e934852e7a112 Mon Sep 17 00:00:00 2001 From: Luca Scalabrino Date: Wed, 21 Mar 2018 14:38:21 +0100 Subject: [PATCH 09/10] ARM: 8751/1: Add support for Cortex-R8 processor Cortex-R8 has identical initialisation requirements to Cortex-R7, so hook it up in proc-v7.S in the same way. Signed-off-by: Luca Scalabrino Signed-off-by: Vladimir Murzin Signed-off-by: Russell King --- arch/arm/mm/proc-v7.S | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/arm/mm/proc-v7.S b/arch/arm/mm/proc-v7.S index d55d493f9a1e..b528a15f460d 100644 --- a/arch/arm/mm/proc-v7.S +++ b/arch/arm/mm/proc-v7.S @@ -272,6 +272,7 @@ ENDPROC(cpu_pj4b_do_resume) __v7_ca5mp_setup: __v7_ca9mp_setup: __v7_cr7mp_setup: +__v7_cr8mp_setup: mov r10, #(1 << 0) @ Cache/TLB ops broadcasting b 1f __v7_ca7mp_setup: @@ -641,6 +642,16 @@ __v7_cr7mp_proc_info: __v7_proc __v7_cr7mp_proc_info, __v7_cr7mp_setup .size __v7_cr7mp_proc_info, . - __v7_cr7mp_proc_info + /* + * ARM Ltd. Cortex R8 processor. + */ + .type __v7_cr8mp_proc_info, #object +__v7_cr8mp_proc_info: + .long 0x410fc180 + .long 0xff0ffff0 + __v7_proc __v7_cr8mp_proc_info, __v7_cr8mp_setup + .size __v7_cr8mp_proc_info, . - __v7_cr8mp_proc_info + /* * ARM Ltd. Cortex A7 processor. */ From 5f8d561fb019a3ebe073c019bf5f797f5b06c55e Mon Sep 17 00:00:00 2001 From: Russell King Date: Thu, 29 Mar 2018 11:59:17 +0100 Subject: [PATCH 10/10] ARM: decompressor: fix warning introduced in fortify patch Commit ee333554fed5 ("ARM: 8749/1: Kconfig: Add ARCH_HAS_FORTIFY_SOURCE") introduced a new warning: arch/arm/boot/compressed/misc.c: In function 'fortify_panic': arch/arm/boot/compressed/misc.c:167:1: error: 'noreturn' function does return [-Werror] The simple solution would be to make 'error' a noreturn function, but this causes a prototype mismatch as the function is prototyped in several .c files. So, move the function prototype to a new header. There are also a couple of variables that are also declared in several locations. Clean this up while we are here. Signed-off-by: Russell King --- arch/arm/boot/compressed/decompress.c | 5 +---- arch/arm/boot/compressed/misc.c | 2 +- arch/arm/boot/compressed/misc.h | 10 ++++++++++ 3 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 arch/arm/boot/compressed/misc.h diff --git a/arch/arm/boot/compressed/decompress.c b/arch/arm/boot/compressed/decompress.c index a2ac3fe7dbf8..c16c1829a5e4 100644 --- a/arch/arm/boot/compressed/decompress.c +++ b/arch/arm/boot/compressed/decompress.c @@ -6,10 +6,7 @@ #include /* for NULL */ #include #include - -extern unsigned long free_mem_ptr; -extern unsigned long free_mem_end_ptr; -extern void error(char *); +#include "misc.h" #define STATIC static #define STATIC_RW_DATA /* non-static please */ diff --git a/arch/arm/boot/compressed/misc.c b/arch/arm/boot/compressed/misc.c index 4a247acd1b96..79f56c5a9fe5 100644 --- a/arch/arm/boot/compressed/misc.c +++ b/arch/arm/boot/compressed/misc.c @@ -22,9 +22,9 @@ unsigned int __machine_arch_type; #include /* for inline */ #include #include +#include "misc.h" static void putstr(const char *ptr); -extern void error(char *x); #include CONFIG_UNCOMPRESS_INCLUDE diff --git a/arch/arm/boot/compressed/misc.h b/arch/arm/boot/compressed/misc.h new file mode 100644 index 000000000000..c958dccd1d97 --- /dev/null +++ b/arch/arm/boot/compressed/misc.h @@ -0,0 +1,10 @@ +#ifndef MISC_H +#define MISC_H + +#include + +void error(char *x) __noreturn; +extern unsigned long free_mem_ptr; +extern unsigned long free_mem_end_ptr; + +#endif