linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v5 mips-next 0/9] MIPS: vmlinux.lds.S sections fixes & cleanup
@ 2021-01-10 11:53 Alexander Lobakin
  2021-01-10 11:56 ` [PATCH v5 mips-next 1/9] MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section Alexander Lobakin
                   ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: Alexander Lobakin @ 2021-01-10 11:53 UTC (permalink / raw)
  To: Thomas Bogendoerfer
  Cc: Arnd Bergmann, Nathan Chancellor, Nick Desaulniers, Huacai Chen,
	Pei Huang, Kees Cook, Alexander Lobakin, Fangrui Song,
	Jiaxun Yang, Ralf Baechle, Corey Minyard, linux-mips,
	linux-kernel, linux-arch, stable, clang-built-linux

This series hunts the problems discovered after manual enabling of
ARCH_WANT_LD_ORPHAN_WARN. Notably:
 - adds the missing PAGE_ALIGNED_DATA() section affecting VDSO
   placement (marked for stable);
 - stops blind catching of orphan text sections with .text.*
   directive;
 - properly stops .eh_frame section generation.

Compile and runtime tested on MIPS32R2 CPS board with no issues
using two different toolkits:
 - Binutils 2.35.1, GCC 10.2.1 (with Alpine patches);
 - LLVM stack: 11.0.0 and from latest Git snapshot.

Since v4 [3]:
 - new: drop redundant .text.cps-vec creation and blind inclusion
   of orphan text sections via .text.* directive in vmlinux.lds.S;
 - don't assert SIZEOF(.rel.dyn) as it's reported that it may be not
   empty on certain machines and compilers (Thomas);
 - align GOT table like it's done for ARM64;
 - new: catch UBSAN's "unnamed data" sections in generic definitions
   when building with LD_DEAD_CODE_DATA_ELIMINATION;
 - collect Reviewed-bys (Kees, Nathan).

Since v3 [2]:
 - fix the third patch as GNU stack emits .rel.dyn into VDSO for
   some reason if .cfi_sections is specified.

Since v2 [1]:
 - stop discarding .eh_frame and just prevent it from generating
   (Kees);
 - drop redundant sections assertions (Fangrui);
 - place GOT table in .text instead of asserting as it's not empty
   when building with LLVM (Nathan);
 - catch compound literals in generic definitions when building with
   LD_DEAD_CODE_DATA_ELIMINATION (Kees);
 - collect two Reviewed-bys (Kees).

Since v1 [0]:
 - catch .got entries too as LLD may produce it (Nathan);
 - check for unwanted sections to be zero-sized instead of
   discarding (Fangrui).

[0] https://lore.kernel.org/linux-mips/20210104121729.46981-1-alobakin@pm.me
[1] https://lore.kernel.org/linux-mips/20210106200713.31840-1-alobakin@pm.me
[2] https://lore.kernel.org/linux-mips/20210107115120.281008-1-alobakin@pm.me
[3] https://lore.kernel.org/linux-mips/20210107123331.354075-1-alobakin@pm.me

Alexander Lobakin (9):
  MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section
  MIPS: CPS: don't create redundant .text.cps-vec section
  MIPS: vmlinux.lds.S: add ".gnu.attributes" to DISCARDS
  MIPS: properly stop .eh_frame generation
  MIPS: vmlinux.lds.S: explicitly catch .rel.dyn symbols
  MIPS: vmlinux.lds.S: explicitly declare .got table
  vmlinux.lds.h: catch compound literals into data and BSS
  vmlinux.lds.h: catch UBSAN's "unnamed data" into data
  MIPS: select ARCH_WANT_LD_ORPHAN_WARN

 arch/mips/Kconfig                 |  1 +
 arch/mips/include/asm/asm.h       | 18 ++++++++++++++++++
 arch/mips/kernel/cps-vec.S        |  1 -
 arch/mips/kernel/vmlinux.lds.S    | 11 +++++++++--
 include/asm-generic/vmlinux.lds.h |  6 +++---
 5 files changed, 31 insertions(+), 6 deletions(-)

-- 
2.30.0



^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v5 mips-next 1/9] MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section
  2021-01-10 11:53 [PATCH v5 mips-next 0/9] MIPS: vmlinux.lds.S sections fixes & cleanup Alexander Lobakin
@ 2021-01-10 11:56 ` Alexander Lobakin
  2021-01-10 11:56   ` [PATCH v5 mips-next 2/9] MIPS: CPS: don't create redundant .text.cps-vec section Alexander Lobakin
                     ` (7 more replies)
  2021-01-11 19:53 ` [PATCH v5 mips-next 0/9] MIPS: vmlinux.lds.S sections fixes & cleanup Kees Cook
  2021-01-15 14:40 ` Thomas Bogendoerfer
  2 siblings, 8 replies; 17+ messages in thread
From: Alexander Lobakin @ 2021-01-10 11:56 UTC (permalink / raw)
  To: Thomas Bogendoerfer
  Cc: Arnd Bergmann, Nathan Chancellor, Nick Desaulniers, Huacai Chen,
	Pei Huang, Kees Cook, Alexander Lobakin, Fangrui Song,
	Jiaxun Yang, Ralf Baechle, Corey Minyard, linux-mips,
	linux-kernel, linux-arch, stable, clang-built-linux

MIPS uses its own declaration of rwdata, and thus it should be kept
in sync with the asm-generic one. Currently PAGE_ALIGNED_DATA() is
missing from the linker script, which emits the following ld
warnings:

mips-alpine-linux-musl-ld: warning: orphan section
`.data..page_aligned' from `arch/mips/kernel/vdso.o' being placed
in section `.data..page_aligned'
mips-alpine-linux-musl-ld: warning: orphan section
`.data..page_aligned' from `arch/mips/vdso/vdso-image.o' being placed
in section `.data..page_aligned'

Add the necessary declaration, so the mentioned structures will be
placed in vmlinux as intended:

ffffffff80630580 D __end_once
ffffffff80630580 D __start___dyndbg
ffffffff80630580 D __start_once
ffffffff80630580 D __stop___dyndbg
ffffffff80634000 d mips_vdso_data
ffffffff80638000 d vdso_data
ffffffff80638580 D _gp
ffffffff8063c000 T __init_begin
ffffffff8063c000 D _edata
ffffffff8063c000 T _sinittext

->

ffffffff805a4000 D __end_init_task
ffffffff805a4000 D __nosave_begin
ffffffff805a4000 D __nosave_end
ffffffff805a4000 d mips_vdso_data
ffffffff805a8000 d vdso_data
ffffffff805ac000 D mmlist_lock
ffffffff805ac080 D tasklist_lock

Fixes: ebb5e78cc634 ("MIPS: Initial implementation of a VDSO")
Cc: stable@vger.kernel.org # 4.4+
Signed-off-by: Alexander Lobakin <alobakin@pm.me>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
---
 arch/mips/kernel/vmlinux.lds.S | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S
index 5e97e9d02f98..83e27a181206 100644
--- a/arch/mips/kernel/vmlinux.lds.S
+++ b/arch/mips/kernel/vmlinux.lds.S
@@ -90,6 +90,7 @@ SECTIONS
 
 		INIT_TASK_DATA(THREAD_SIZE)
 		NOSAVE_DATA
+		PAGE_ALIGNED_DATA(PAGE_SIZE)
 		CACHELINE_ALIGNED_DATA(1 << CONFIG_MIPS_L1_CACHE_SHIFT)
 		READ_MOSTLY_DATA(1 << CONFIG_MIPS_L1_CACHE_SHIFT)
 		DATA_DATA
-- 
2.30.0



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v5 mips-next 2/9] MIPS: CPS: don't create redundant .text.cps-vec section
  2021-01-10 11:56 ` [PATCH v5 mips-next 1/9] MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section Alexander Lobakin
@ 2021-01-10 11:56   ` Alexander Lobakin
  2021-01-10 11:56   ` [PATCH v5 mips-next 3/9] MIPS: vmlinux.lds.S: add ".gnu.attributes" to DISCARDS Alexander Lobakin
                     ` (6 subsequent siblings)
  7 siblings, 0 replies; 17+ messages in thread
From: Alexander Lobakin @ 2021-01-10 11:56 UTC (permalink / raw)
  To: Thomas Bogendoerfer
  Cc: Arnd Bergmann, Nathan Chancellor, Nick Desaulniers, Huacai Chen,
	Pei Huang, Kees Cook, Alexander Lobakin, Fangrui Song,
	Jiaxun Yang, Ralf Baechle, Corey Minyard, linux-mips,
	linux-kernel, linux-arch, stable, clang-built-linux

A number of symbols from arch/mips/kernel/cps-vec.S is explicitly
placed into '.text.cps-vec' section.
There are no direct references to this section, so there's no need
to form it. '.balign 0x1000' directive will work anyway.

Moreover, this section was being placed in vmlinux differently
depending on CONFIG_LD_DEAD_CODE_DATA_ELIMINATION:
 - with this option enabled, '.text.cps-vec' was being caught
   by '.text.[0-9a-zA-Z_]*' from include/asm-generic/vmlinux.lds.h;
 - without this option, '.text.cps-vec' was being caught
   by discouraging '.text.*' from arch/mips/kernel/vmlinux.lds.S.

'.text.*' should not be used in vmlinux linker scripts at all as it
silently catches any orphan text sections.
So, remove both '.section .text.cps-vec' and '.text.*' from cps-vec.S
and vmlinux.lds.S respectively. As said, this does not affect related
functions alignment:

80116000 T mips_cps_core_entry
80116028 t not_nmi
80116200 T excep_tlbfill
80116280 T excep_xtlbfill
80116300 T excep_cache
80116380 T excep_genex
80116400 T excep_intex
80116480 T excep_ejtag
80116490 T mips_cps_core_init

Signed-off-by: Alexander Lobakin <alobakin@pm.me>
---
 arch/mips/kernel/cps-vec.S     | 1 -
 arch/mips/kernel/vmlinux.lds.S | 1 -
 2 files changed, 2 deletions(-)

diff --git a/arch/mips/kernel/cps-vec.S b/arch/mips/kernel/cps-vec.S
index 4db7ff055c9f..975343240148 100644
--- a/arch/mips/kernel/cps-vec.S
+++ b/arch/mips/kernel/cps-vec.S
@@ -91,7 +91,6 @@
 	.set	pop
 	.endm
 
-.section .text.cps-vec
 .balign 0x1000
 
 LEAF(mips_cps_core_entry)
diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S
index 83e27a181206..ae1d0b4bdd60 100644
--- a/arch/mips/kernel/vmlinux.lds.S
+++ b/arch/mips/kernel/vmlinux.lds.S
@@ -66,7 +66,6 @@ SECTIONS
 		KPROBES_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
-		*(.text.*)
 		*(.fixup)
 		*(.gnu.warning)
 	} :text = 0
-- 
2.30.0



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v5 mips-next 3/9] MIPS: vmlinux.lds.S: add ".gnu.attributes" to DISCARDS
  2021-01-10 11:56 ` [PATCH v5 mips-next 1/9] MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section Alexander Lobakin
  2021-01-10 11:56   ` [PATCH v5 mips-next 2/9] MIPS: CPS: don't create redundant .text.cps-vec section Alexander Lobakin
@ 2021-01-10 11:56   ` Alexander Lobakin
  2021-01-10 11:56   ` [PATCH v5 mips-next 4/9] MIPS: properly stop .eh_frame generation Alexander Lobakin
                     ` (5 subsequent siblings)
  7 siblings, 0 replies; 17+ messages in thread
From: Alexander Lobakin @ 2021-01-10 11:56 UTC (permalink / raw)
  To: Thomas Bogendoerfer
  Cc: Arnd Bergmann, Nathan Chancellor, Nick Desaulniers, Huacai Chen,
	Pei Huang, Kees Cook, Alexander Lobakin, Fangrui Song,
	Jiaxun Yang, Ralf Baechle, Corey Minyard, linux-mips,
	linux-kernel, linux-arch, stable, clang-built-linux

Discard GNU attributes (MIPS FP type, GNU Hash etc.) at link time
as kernel doesn't use it at all.
Solves a dozen of the following ld warnings (one per every file):

mips-alpine-linux-musl-ld: warning: orphan section `.gnu.attributes'
from `arch/mips/kernel/head.o' being placed in section
`.gnu.attributes'
mips-alpine-linux-musl-ld: warning: orphan section `.gnu.attributes'
from `init/main.o' being placed in section `.gnu.attributes'

Signed-off-by: Alexander Lobakin <alobakin@pm.me>
Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
---
 arch/mips/kernel/vmlinux.lds.S | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S
index ae1d0b4bdd60..09669a8fddec 100644
--- a/arch/mips/kernel/vmlinux.lds.S
+++ b/arch/mips/kernel/vmlinux.lds.S
@@ -220,6 +220,7 @@ SECTIONS
 		/* ABI crap starts here */
 		*(.MIPS.abiflags)
 		*(.MIPS.options)
+		*(.gnu.attributes)
 		*(.options)
 		*(.pdr)
 		*(.reginfo)
-- 
2.30.0



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v5 mips-next 4/9] MIPS: properly stop .eh_frame generation
  2021-01-10 11:56 ` [PATCH v5 mips-next 1/9] MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section Alexander Lobakin
  2021-01-10 11:56   ` [PATCH v5 mips-next 2/9] MIPS: CPS: don't create redundant .text.cps-vec section Alexander Lobakin
  2021-01-10 11:56   ` [PATCH v5 mips-next 3/9] MIPS: vmlinux.lds.S: add ".gnu.attributes" to DISCARDS Alexander Lobakin
@ 2021-01-10 11:56   ` Alexander Lobakin
  2021-01-10 11:56   ` [PATCH v5 mips-next 5/9] MIPS: vmlinux.lds.S: explicitly catch .rel.dyn symbols Alexander Lobakin
                     ` (4 subsequent siblings)
  7 siblings, 0 replies; 17+ messages in thread
From: Alexander Lobakin @ 2021-01-10 11:56 UTC (permalink / raw)
  To: Thomas Bogendoerfer
  Cc: Arnd Bergmann, Nathan Chancellor, Nick Desaulniers, Huacai Chen,
	Pei Huang, Kees Cook, Alexander Lobakin, Fangrui Song,
	Jiaxun Yang, Ralf Baechle, Corey Minyard, linux-mips,
	linux-kernel, linux-arch, stable, clang-built-linux

Commit 866b6a89c6d1 ("MIPS: Add DWARF unwinding to assembly") added
-fno-asynchronous-unwind-tables to KBUILD_CFLAGS to prevent compiler
from emitting .eh_frame symbols.
However, as MIPS heavily uses CFI, that's not enough. Use the
approach taken for x86 (as it also uses CFI) and explicitly put CFI
symbols into the .debug_frame section (except for VDSO).
This allows us to drop .eh_frame from DISCARDS as it's no longer
being generated.

Fixes: 866b6a89c6d1 ("MIPS: Add DWARF unwinding to assembly")
Suggested-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Alexander Lobakin <alobakin@pm.me>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
---
 arch/mips/include/asm/asm.h    | 18 ++++++++++++++++++
 arch/mips/kernel/vmlinux.lds.S |  1 -
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/arch/mips/include/asm/asm.h b/arch/mips/include/asm/asm.h
index 3682d1a0bb80..ea4b62ece336 100644
--- a/arch/mips/include/asm/asm.h
+++ b/arch/mips/include/asm/asm.h
@@ -20,10 +20,27 @@
 #include <asm/sgidefs.h>
 #include <asm/asm-eva.h>
 
+#ifndef __VDSO__
+/*
+ * Emit CFI data in .debug_frame sections, not .eh_frame sections.
+ * We don't do DWARF unwinding at runtime, so only the offline DWARF
+ * information is useful to anyone. Note we should change this if we
+ * ever decide to enable DWARF unwinding at runtime.
+ */
+#define CFI_SECTIONS	.cfi_sections .debug_frame
+#else
+ /*
+  * For the vDSO, emit both runtime unwind information and debug
+  * symbols for the .dbg file.
+  */
+#define CFI_SECTIONS
+#endif
+
 /*
  * LEAF - declare leaf routine
  */
 #define LEAF(symbol)					\
+		CFI_SECTIONS;				\
 		.globl	symbol;				\
 		.align	2;				\
 		.type	symbol, @function;		\
@@ -36,6 +53,7 @@ symbol:		.frame	sp, 0, ra;			\
  * NESTED - declare nested routine entry point
  */
 #define NESTED(symbol, framesize, rpc)			\
+		CFI_SECTIONS;				\
 		.globl	symbol;				\
 		.align	2;				\
 		.type	symbol, @function;		\
diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S
index 09669a8fddec..10d8f0dcb76b 100644
--- a/arch/mips/kernel/vmlinux.lds.S
+++ b/arch/mips/kernel/vmlinux.lds.S
@@ -224,6 +224,5 @@ SECTIONS
 		*(.options)
 		*(.pdr)
 		*(.reginfo)
-		*(.eh_frame)
 	}
 }
-- 
2.30.0



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v5 mips-next 5/9] MIPS: vmlinux.lds.S: explicitly catch .rel.dyn symbols
  2021-01-10 11:56 ` [PATCH v5 mips-next 1/9] MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section Alexander Lobakin
                     ` (2 preceding siblings ...)
  2021-01-10 11:56   ` [PATCH v5 mips-next 4/9] MIPS: properly stop .eh_frame generation Alexander Lobakin
@ 2021-01-10 11:56   ` Alexander Lobakin
  2021-01-11  1:28     ` Nathan Chancellor
  2021-01-10 11:56   ` [PATCH v5 mips-next 6/9] MIPS: vmlinux.lds.S: explicitly declare .got table Alexander Lobakin
                     ` (3 subsequent siblings)
  7 siblings, 1 reply; 17+ messages in thread
From: Alexander Lobakin @ 2021-01-10 11:56 UTC (permalink / raw)
  To: Thomas Bogendoerfer
  Cc: Arnd Bergmann, Nathan Chancellor, Nick Desaulniers, Huacai Chen,
	Pei Huang, Kees Cook, Alexander Lobakin, Fangrui Song,
	Jiaxun Yang, Ralf Baechle, Corey Minyard, linux-mips,
	linux-kernel, linux-arch, stable, clang-built-linux

According to linker warnings, both GCC and LLVM generate '.rel.dyn'
symbols:

mips-alpine-linux-musl-ld: warning: orphan section `.rel.dyn'
from `init/main.o' being placed in section `.rel.dyn'

Link-time assertion shows that this section is sometimes empty,
sometimes not, depending on machine bitness and the compiler [0]:

  LD      .tmp_vmlinux.kallsyms1
mips64-linux-gnu-ld: Unexpected run-time relocations (.rel) detected!

Just use the ARM64 approach and declare it in vmlinux.lds.S closer
to __init_end.

[0] https://lore.kernel.org/linux-mips/20210109111259.GA4213@alpha.franken.de

Reported-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Signed-off-by: Alexander Lobakin <alobakin@pm.me>
---
 arch/mips/kernel/vmlinux.lds.S | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S
index 10d8f0dcb76b..70bba1ff08da 100644
--- a/arch/mips/kernel/vmlinux.lds.S
+++ b/arch/mips/kernel/vmlinux.lds.S
@@ -137,6 +137,11 @@ SECTIONS
 	PERCPU_SECTION(1 << CONFIG_MIPS_L1_CACHE_SHIFT)
 #endif
 
+	.rel.dyn : ALIGN(8) {
+		*(.rel)
+		*(.rel*)
+	}
+
 #ifdef CONFIG_MIPS_ELF_APPENDED_DTB
 	.appended_dtb : AT(ADDR(.appended_dtb) - LOAD_OFFSET) {
 		*(.appended_dtb)
-- 
2.30.0



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v5 mips-next 6/9] MIPS: vmlinux.lds.S: explicitly declare .got table
  2021-01-10 11:56 ` [PATCH v5 mips-next 1/9] MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section Alexander Lobakin
                     ` (3 preceding siblings ...)
  2021-01-10 11:56   ` [PATCH v5 mips-next 5/9] MIPS: vmlinux.lds.S: explicitly catch .rel.dyn symbols Alexander Lobakin
@ 2021-01-10 11:56   ` Alexander Lobakin
  2021-01-10 11:56   ` [PATCH v5 mips-next 7/9] vmlinux.lds.h: catch compound literals into data and BSS Alexander Lobakin
                     ` (2 subsequent siblings)
  7 siblings, 0 replies; 17+ messages in thread
From: Alexander Lobakin @ 2021-01-10 11:56 UTC (permalink / raw)
  To: Thomas Bogendoerfer
  Cc: Arnd Bergmann, Nathan Chancellor, Nick Desaulniers, Huacai Chen,
	Pei Huang, Kees Cook, Alexander Lobakin, Fangrui Song,
	Jiaxun Yang, Ralf Baechle, Corey Minyard, linux-mips,
	linux-kernel, linux-arch, stable, clang-built-linux

LLVM stack generates GOT table when building the kernel:

ld.lld: warning: <internal>:(.got) is being placed in '.got'

According to the debug assertions, it's not zero-sized and thus can't
be handled the way it's done for x86.
Also use the ARM64 path here and place it at the end of .text section.

Reported-by: Nathan Chancellor <natechancellor@gmail.com>
Signed-off-by: Alexander Lobakin <alobakin@pm.me>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
---
 arch/mips/kernel/vmlinux.lds.S | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S
index 70bba1ff08da..c1c345be04ff 100644
--- a/arch/mips/kernel/vmlinux.lds.S
+++ b/arch/mips/kernel/vmlinux.lds.S
@@ -68,6 +68,8 @@ SECTIONS
 		SOFTIRQENTRY_TEXT
 		*(.fixup)
 		*(.gnu.warning)
+		. = ALIGN(16);
+		*(.got)	/* Global offset table */
 	} :text = 0
 	_etext = .;	/* End of text section */
 
-- 
2.30.0



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v5 mips-next 7/9] vmlinux.lds.h: catch compound literals into data and BSS
  2021-01-10 11:56 ` [PATCH v5 mips-next 1/9] MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section Alexander Lobakin
                     ` (4 preceding siblings ...)
  2021-01-10 11:56   ` [PATCH v5 mips-next 6/9] MIPS: vmlinux.lds.S: explicitly declare .got table Alexander Lobakin
@ 2021-01-10 11:56   ` Alexander Lobakin
  2021-01-10 11:56   ` [PATCH v5 mips-next 8/9] vmlinux.lds.h: catch UBSAN's "unnamed data" into data Alexander Lobakin
  2021-01-10 11:57   ` [PATCH v5 mips-next 9/9] MIPS: select ARCH_WANT_LD_ORPHAN_WARN Alexander Lobakin
  7 siblings, 0 replies; 17+ messages in thread
From: Alexander Lobakin @ 2021-01-10 11:56 UTC (permalink / raw)
  To: Thomas Bogendoerfer
  Cc: Arnd Bergmann, Nathan Chancellor, Nick Desaulniers, Huacai Chen,
	Pei Huang, Kees Cook, Alexander Lobakin, Fangrui Song,
	Jiaxun Yang, Ralf Baechle, Corey Minyard, linux-mips,
	linux-kernel, linux-arch, stable, clang-built-linux,
	Sami Tolvanen

When building kernel with LD_DEAD_CODE_DATA_ELIMINATION, LLVM stack
generates separate sections for compound literals, just like in case
with enabled LTO [0]:

ld.lld: warning: drivers/built-in.a(mtd/nand/spi/gigadevice.o):
(.data..compoundliteral.14) is being placed in
'.data..compoundliteral.14'
ld.lld: warning: drivers/built-in.a(mtd/nand/spi/gigadevice.o):
(.data..compoundliteral.15) is being placed in
'.data..compoundliteral.15'
ld.lld: warning: drivers/built-in.a(mtd/nand/spi/gigadevice.o):
(.data..compoundliteral.16) is being placed in
'.data..compoundliteral.16'
ld.lld: warning: drivers/built-in.a(mtd/nand/spi/gigadevice.o):
(.data..compoundliteral.17) is being placed in
'.data..compoundliteral.17'

[...]

Handle this by adding the related sections to generic definitions
as suggested by Sami [0].

[0] https://lore.kernel.org/lkml/20201211184633.3213045-3-samitolvanen@google.com

Suggested-by: Sami Tolvanen <samitolvanen@google.com>
Suggested-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Alexander Lobakin <alobakin@pm.me>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
---
 include/asm-generic/vmlinux.lds.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index b2b3d81b1535..5f2f5b1db84f 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -95,10 +95,10 @@
  */
 #ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
 #define TEXT_MAIN .text .text.[0-9a-zA-Z_]*
-#define DATA_MAIN .data .data.[0-9a-zA-Z_]* .data..LPBX*
+#define DATA_MAIN .data .data.[0-9a-zA-Z_]* .data..L* .data..compoundliteral*
 #define SDATA_MAIN .sdata .sdata.[0-9a-zA-Z_]*
-#define RODATA_MAIN .rodata .rodata.[0-9a-zA-Z_]*
-#define BSS_MAIN .bss .bss.[0-9a-zA-Z_]*
+#define RODATA_MAIN .rodata .rodata.[0-9a-zA-Z_]* .rodata..L*
+#define BSS_MAIN .bss .bss.[0-9a-zA-Z_]* .bss..compoundliteral*
 #define SBSS_MAIN .sbss .sbss.[0-9a-zA-Z_]*
 #else
 #define TEXT_MAIN .text
-- 
2.30.0



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v5 mips-next 8/9] vmlinux.lds.h: catch UBSAN's "unnamed data" into data
  2021-01-10 11:56 ` [PATCH v5 mips-next 1/9] MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section Alexander Lobakin
                     ` (5 preceding siblings ...)
  2021-01-10 11:56   ` [PATCH v5 mips-next 7/9] vmlinux.lds.h: catch compound literals into data and BSS Alexander Lobakin
@ 2021-01-10 11:56   ` Alexander Lobakin
  2021-01-11  2:05     ` Nathan Chancellor
  2021-01-10 11:57   ` [PATCH v5 mips-next 9/9] MIPS: select ARCH_WANT_LD_ORPHAN_WARN Alexander Lobakin
  7 siblings, 1 reply; 17+ messages in thread
From: Alexander Lobakin @ 2021-01-10 11:56 UTC (permalink / raw)
  To: Thomas Bogendoerfer
  Cc: Arnd Bergmann, Nathan Chancellor, Nick Desaulniers, Huacai Chen,
	Pei Huang, Kees Cook, Alexander Lobakin, Fangrui Song,
	Jiaxun Yang, Ralf Baechle, Corey Minyard, linux-mips,
	linux-kernel, linux-arch, stable, clang-built-linux

When building kernel with both LD_DEAD_CODE_DATA_ELIMINATION and
UBSAN, LLVM stack generates lots of "unnamed data" sections:

ld.lld: warning: net/built-in.a(netfilter/utils.o): (.data.$__unnamed_2)
is being placed in '.data.$__unnamed_2'
ld.lld: warning: net/built-in.a(netfilter/utils.o): (.data.$__unnamed_3)
is being placed in '.data.$__unnamed_3'
ld.lld: warning: net/built-in.a(netfilter/utils.o): (.data.$__unnamed_4)
is being placed in '.data.$__unnamed_4'
ld.lld: warning: net/built-in.a(netfilter/utils.o): (.data.$__unnamed_5)
is being placed in '.data.$__unnamed_5'

[...]

Also handle this by adding the related sections to generic definitions.

Signed-off-by: Alexander Lobakin <alobakin@pm.me>
---
 include/asm-generic/vmlinux.lds.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 5f2f5b1db84f..cc659e77fcb0 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -95,7 +95,7 @@
  */
 #ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
 #define TEXT_MAIN .text .text.[0-9a-zA-Z_]*
-#define DATA_MAIN .data .data.[0-9a-zA-Z_]* .data..L* .data..compoundliteral*
+#define DATA_MAIN .data .data.[0-9a-zA-Z_]* .data..L* .data..compoundliteral* .data.$__unnamed_*
 #define SDATA_MAIN .sdata .sdata.[0-9a-zA-Z_]*
 #define RODATA_MAIN .rodata .rodata.[0-9a-zA-Z_]* .rodata..L*
 #define BSS_MAIN .bss .bss.[0-9a-zA-Z_]* .bss..compoundliteral*
-- 
2.30.0



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v5 mips-next 9/9] MIPS: select ARCH_WANT_LD_ORPHAN_WARN
  2021-01-10 11:56 ` [PATCH v5 mips-next 1/9] MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section Alexander Lobakin
                     ` (6 preceding siblings ...)
  2021-01-10 11:56   ` [PATCH v5 mips-next 8/9] vmlinux.lds.h: catch UBSAN's "unnamed data" into data Alexander Lobakin
@ 2021-01-10 11:57   ` Alexander Lobakin
  7 siblings, 0 replies; 17+ messages in thread
From: Alexander Lobakin @ 2021-01-10 11:57 UTC (permalink / raw)
  To: Thomas Bogendoerfer
  Cc: Arnd Bergmann, Nathan Chancellor, Nick Desaulniers, Huacai Chen,
	Pei Huang, Kees Cook, Alexander Lobakin, Fangrui Song,
	Jiaxun Yang, Ralf Baechle, Corey Minyard, linux-mips,
	linux-kernel, linux-arch, stable, clang-built-linux

Now, after that all the sections are explicitly described and
declared in vmlinux.lds.S, we can enable ld orphan warnings to
prevent from missing any new sections in future.

Signed-off-by: Alexander Lobakin <alobakin@pm.me>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
---
 arch/mips/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index d68df1febd25..d3e64cc0932b 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -18,6 +18,7 @@ config MIPS
 	select ARCH_USE_QUEUED_SPINLOCKS
 	select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT if MMU
 	select ARCH_WANT_IPC_PARSE_VERSION
+	select ARCH_WANT_LD_ORPHAN_WARN
 	select BUILDTIME_TABLE_SORT
 	select CLONE_BACKWARDS
 	select CPU_NO_EFFICIENT_FFS if (TARGET_ISA_REV < 1)
-- 
2.30.0



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH v5 mips-next 5/9] MIPS: vmlinux.lds.S: explicitly catch .rel.dyn symbols
  2021-01-10 11:56   ` [PATCH v5 mips-next 5/9] MIPS: vmlinux.lds.S: explicitly catch .rel.dyn symbols Alexander Lobakin
@ 2021-01-11  1:28     ` Nathan Chancellor
  0 siblings, 0 replies; 17+ messages in thread
From: Nathan Chancellor @ 2021-01-11  1:28 UTC (permalink / raw)
  To: Alexander Lobakin
  Cc: Thomas Bogendoerfer, Arnd Bergmann, Nick Desaulniers,
	Huacai Chen, Pei Huang, Kees Cook, Fangrui Song, Jiaxun Yang,
	Ralf Baechle, Corey Minyard, linux-mips, linux-kernel,
	linux-arch, stable, clang-built-linux

On Sun, Jan 10, 2021 at 11:56:34AM +0000, Alexander Lobakin wrote:
> According to linker warnings, both GCC and LLVM generate '.rel.dyn'
> symbols:
> 
> mips-alpine-linux-musl-ld: warning: orphan section `.rel.dyn'
> from `init/main.o' being placed in section `.rel.dyn'
> 
> Link-time assertion shows that this section is sometimes empty,
> sometimes not, depending on machine bitness and the compiler [0]:
> 
>   LD      .tmp_vmlinux.kallsyms1
> mips64-linux-gnu-ld: Unexpected run-time relocations (.rel) detected!
> 
> Just use the ARM64 approach and declare it in vmlinux.lds.S closer
> to __init_end.
> 
> [0] https://lore.kernel.org/linux-mips/20210109111259.GA4213@alpha.franken.de
> 
> Reported-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
> Signed-off-by: Alexander Lobakin <alobakin@pm.me>

Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>

> ---
>  arch/mips/kernel/vmlinux.lds.S | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S
> index 10d8f0dcb76b..70bba1ff08da 100644
> --- a/arch/mips/kernel/vmlinux.lds.S
> +++ b/arch/mips/kernel/vmlinux.lds.S
> @@ -137,6 +137,11 @@ SECTIONS
>  	PERCPU_SECTION(1 << CONFIG_MIPS_L1_CACHE_SHIFT)
>  #endif
>  
> +	.rel.dyn : ALIGN(8) {
> +		*(.rel)
> +		*(.rel*)
> +	}
> +
>  #ifdef CONFIG_MIPS_ELF_APPENDED_DTB
>  	.appended_dtb : AT(ADDR(.appended_dtb) - LOAD_OFFSET) {
>  		*(.appended_dtb)
> -- 
> 2.30.0
> 
> 

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v5 mips-next 8/9] vmlinux.lds.h: catch UBSAN's "unnamed data" into data
  2021-01-10 11:56   ` [PATCH v5 mips-next 8/9] vmlinux.lds.h: catch UBSAN's "unnamed data" into data Alexander Lobakin
@ 2021-01-11  2:05     ` Nathan Chancellor
  0 siblings, 0 replies; 17+ messages in thread
From: Nathan Chancellor @ 2021-01-11  2:05 UTC (permalink / raw)
  To: Alexander Lobakin
  Cc: Thomas Bogendoerfer, Arnd Bergmann, Nick Desaulniers,
	Huacai Chen, Pei Huang, Kees Cook, Fangrui Song, Jiaxun Yang,
	Ralf Baechle, Corey Minyard, linux-mips, linux-kernel,
	linux-arch, stable, clang-built-linux

On Sun, Jan 10, 2021 at 11:56:54AM +0000, Alexander Lobakin wrote:
> When building kernel with both LD_DEAD_CODE_DATA_ELIMINATION and
> UBSAN, LLVM stack generates lots of "unnamed data" sections:
> 
> ld.lld: warning: net/built-in.a(netfilter/utils.o): (.data.$__unnamed_2)
> is being placed in '.data.$__unnamed_2'
> ld.lld: warning: net/built-in.a(netfilter/utils.o): (.data.$__unnamed_3)
> is being placed in '.data.$__unnamed_3'
> ld.lld: warning: net/built-in.a(netfilter/utils.o): (.data.$__unnamed_4)
> is being placed in '.data.$__unnamed_4'
> ld.lld: warning: net/built-in.a(netfilter/utils.o): (.data.$__unnamed_5)
> is being placed in '.data.$__unnamed_5'
> 
> [...]
> 
> Also handle this by adding the related sections to generic definitions.
> 
> Signed-off-by: Alexander Lobakin <alobakin@pm.me>

Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>

> ---
>  include/asm-generic/vmlinux.lds.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
> index 5f2f5b1db84f..cc659e77fcb0 100644
> --- a/include/asm-generic/vmlinux.lds.h
> +++ b/include/asm-generic/vmlinux.lds.h
> @@ -95,7 +95,7 @@
>   */
>  #ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
>  #define TEXT_MAIN .text .text.[0-9a-zA-Z_]*
> -#define DATA_MAIN .data .data.[0-9a-zA-Z_]* .data..L* .data..compoundliteral*
> +#define DATA_MAIN .data .data.[0-9a-zA-Z_]* .data..L* .data..compoundliteral* .data.$__unnamed_*
>  #define SDATA_MAIN .sdata .sdata.[0-9a-zA-Z_]*
>  #define RODATA_MAIN .rodata .rodata.[0-9a-zA-Z_]* .rodata..L*
>  #define BSS_MAIN .bss .bss.[0-9a-zA-Z_]* .bss..compoundliteral*
> -- 
> 2.30.0
> 
> 

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v5 mips-next 0/9] MIPS: vmlinux.lds.S sections fixes & cleanup
  2021-01-10 11:53 [PATCH v5 mips-next 0/9] MIPS: vmlinux.lds.S sections fixes & cleanup Alexander Lobakin
  2021-01-10 11:56 ` [PATCH v5 mips-next 1/9] MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section Alexander Lobakin
@ 2021-01-11 19:53 ` Kees Cook
  2021-01-11 20:57   ` Alexander Lobakin
  2021-01-15 14:40 ` Thomas Bogendoerfer
  2 siblings, 1 reply; 17+ messages in thread
From: Kees Cook @ 2021-01-11 19:53 UTC (permalink / raw)
  To: Alexander Lobakin
  Cc: Thomas Bogendoerfer, Arnd Bergmann, Nathan Chancellor,
	Nick Desaulniers, Huacai Chen, Pei Huang, Fangrui Song,
	Jiaxun Yang, Ralf Baechle, Corey Minyard, linux-mips,
	linux-kernel, linux-arch, stable, clang-built-linux

On Sun, Jan 10, 2021 at 11:53:50AM +0000, Alexander Lobakin wrote:
> This series hunts the problems discovered after manual enabling of
> ARCH_WANT_LD_ORPHAN_WARN. Notably:
>  - adds the missing PAGE_ALIGNED_DATA() section affecting VDSO
>    placement (marked for stable);
>  - stops blind catching of orphan text sections with .text.*
>    directive;
>  - properly stops .eh_frame section generation.
> 
> Compile and runtime tested on MIPS32R2 CPS board with no issues
> using two different toolkits:
>  - Binutils 2.35.1, GCC 10.2.1 (with Alpine patches);
>  - LLVM stack: 11.0.0 and from latest Git snapshot.
> 
> Since v4 [3]:
>  - new: drop redundant .text.cps-vec creation and blind inclusion
>    of orphan text sections via .text.* directive in vmlinux.lds.S;
>  - don't assert SIZEOF(.rel.dyn) as it's reported that it may be not
>    empty on certain machines and compilers (Thomas);
>  - align GOT table like it's done for ARM64;
>  - new: catch UBSAN's "unnamed data" sections in generic definitions
>    when building with LD_DEAD_CODE_DATA_ELIMINATION;
>  - collect Reviewed-bys (Kees, Nathan).

Looks good; which tree will this land through?

-Kees

> 
> Since v3 [2]:
>  - fix the third patch as GNU stack emits .rel.dyn into VDSO for
>    some reason if .cfi_sections is specified.
> 
> Since v2 [1]:
>  - stop discarding .eh_frame and just prevent it from generating
>    (Kees);
>  - drop redundant sections assertions (Fangrui);
>  - place GOT table in .text instead of asserting as it's not empty
>    when building with LLVM (Nathan);
>  - catch compound literals in generic definitions when building with
>    LD_DEAD_CODE_DATA_ELIMINATION (Kees);
>  - collect two Reviewed-bys (Kees).
> 
> Since v1 [0]:
>  - catch .got entries too as LLD may produce it (Nathan);
>  - check for unwanted sections to be zero-sized instead of
>    discarding (Fangrui).
> 
> [0] https://lore.kernel.org/linux-mips/20210104121729.46981-1-alobakin@pm.me
> [1] https://lore.kernel.org/linux-mips/20210106200713.31840-1-alobakin@pm.me
> [2] https://lore.kernel.org/linux-mips/20210107115120.281008-1-alobakin@pm.me
> [3] https://lore.kernel.org/linux-mips/20210107123331.354075-1-alobakin@pm.me
> 
> Alexander Lobakin (9):
>   MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section
>   MIPS: CPS: don't create redundant .text.cps-vec section
>   MIPS: vmlinux.lds.S: add ".gnu.attributes" to DISCARDS
>   MIPS: properly stop .eh_frame generation
>   MIPS: vmlinux.lds.S: explicitly catch .rel.dyn symbols
>   MIPS: vmlinux.lds.S: explicitly declare .got table
>   vmlinux.lds.h: catch compound literals into data and BSS
>   vmlinux.lds.h: catch UBSAN's "unnamed data" into data
>   MIPS: select ARCH_WANT_LD_ORPHAN_WARN
> 
>  arch/mips/Kconfig                 |  1 +
>  arch/mips/include/asm/asm.h       | 18 ++++++++++++++++++
>  arch/mips/kernel/cps-vec.S        |  1 -
>  arch/mips/kernel/vmlinux.lds.S    | 11 +++++++++--
>  include/asm-generic/vmlinux.lds.h |  6 +++---
>  5 files changed, 31 insertions(+), 6 deletions(-)
> 
> -- 
> 2.30.0
> 
> 

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v5 mips-next 0/9] MIPS: vmlinux.lds.S sections fixes & cleanup
  2021-01-11 19:53 ` [PATCH v5 mips-next 0/9] MIPS: vmlinux.lds.S sections fixes & cleanup Kees Cook
@ 2021-01-11 20:57   ` Alexander Lobakin
  2021-01-11 22:43     ` Thomas Bogendoerfer
  0 siblings, 1 reply; 17+ messages in thread
From: Alexander Lobakin @ 2021-01-11 20:57 UTC (permalink / raw)
  To: Kees Cook
  Cc: Alexander Lobakin, Thomas Bogendoerfer, Arnd Bergmann,
	Nathan Chancellor, Nick Desaulniers, Huacai Chen, Pei Huang,
	Fangrui Song, Jiaxun Yang, Ralf Baechle, Corey Minyard,
	linux-mips, linux-kernel, linux-arch, stable, clang-built-linux

From: Kees Cook <keescook@chromium.org>
Date: Mon, 11 Jan 2021 11:53:39 -0800

> On Sun, Jan 10, 2021 at 11:53:50AM +0000, Alexander Lobakin wrote:
>> This series hunts the problems discovered after manual enabling of
>> ARCH_WANT_LD_ORPHAN_WARN. Notably:
>>  - adds the missing PAGE_ALIGNED_DATA() section affecting VDSO
>>    placement (marked for stable);
>>  - stops blind catching of orphan text sections with .text.*
>>    directive;
>>  - properly stops .eh_frame section generation.
>>
>> Compile and runtime tested on MIPS32R2 CPS board with no issues
>> using two different toolkits:
>>  - Binutils 2.35.1, GCC 10.2.1 (with Alpine patches);
>>  - LLVM stack: 11.0.0 and from latest Git snapshot.
>>
>> Since v4 [3]:
>>  - new: drop redundant .text.cps-vec creation and blind inclusion
>>    of orphan text sections via .text.* directive in vmlinux.lds.S;
>>  - don't assert SIZEOF(.rel.dyn) as it's reported that it may be not
>>    empty on certain machines and compilers (Thomas);
>>  - align GOT table like it's done for ARM64;
>>  - new: catch UBSAN's "unnamed data" sections in generic definitions
>>    when building with LD_DEAD_CODE_DATA_ELIMINATION;
>>  - collect Reviewed-bys (Kees, Nathan).
>
> Looks good; which tree will this land through?

linux-mips/mips-next I guess, since 7 of 9 patches are related only
to this architecture.
This might need Arnd's Acked-bys or Reviewed-by for the two that
refer include/asm-generic, let's see what Thomas think.

> -Kees
>
>>
>> Since v3 [2]:
>>  - fix the third patch as GNU stack emits .rel.dyn into VDSO for
>>    some reason if .cfi_sections is specified.
>>
>> Since v2 [1]:
>>  - stop discarding .eh_frame and just prevent it from generating
>>    (Kees);
>>  - drop redundant sections assertions (Fangrui);
>>  - place GOT table in .text instead of asserting as it's not empty
>>    when building with LLVM (Nathan);
>>  - catch compound literals in generic definitions when building with
>>    LD_DEAD_CODE_DATA_ELIMINATION (Kees);
>>  - collect two Reviewed-bys (Kees).
>>
>> Since v1 [0]:
>>  - catch .got entries too as LLD may produce it (Nathan);
>>  - check for unwanted sections to be zero-sized instead of
>>    discarding (Fangrui).
>>
>> [0] https://lore.kernel.org/linux-mips/20210104121729.46981-1-alobakin@pm.me
>> [1] https://lore.kernel.org/linux-mips/20210106200713.31840-1-alobakin@pm.me
>> [2] https://lore.kernel.org/linux-mips/20210107115120.281008-1-alobakin@pm.me
>> [3] https://lore.kernel.org/linux-mips/20210107123331.354075-1-alobakin@pm.me
>>
>> Alexander Lobakin (9):
>>   MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section
>>   MIPS: CPS: don't create redundant .text.cps-vec section
>>   MIPS: vmlinux.lds.S: add ".gnu.attributes" to DISCARDS
>>   MIPS: properly stop .eh_frame generation
>>   MIPS: vmlinux.lds.S: explicitly catch .rel.dyn symbols
>>   MIPS: vmlinux.lds.S: explicitly declare .got table
>>   vmlinux.lds.h: catch compound literals into data and BSS
>>   vmlinux.lds.h: catch UBSAN's "unnamed data" into data
>>   MIPS: select ARCH_WANT_LD_ORPHAN_WARN
>>
>>  arch/mips/Kconfig                 |  1 +
>>  arch/mips/include/asm/asm.h       | 18 ++++++++++++++++++
>>  arch/mips/kernel/cps-vec.S        |  1 -
>>  arch/mips/kernel/vmlinux.lds.S    | 11 +++++++++--
>>  include/asm-generic/vmlinux.lds.h |  6 +++---
>>  5 files changed, 31 insertions(+), 6 deletions(-)
>>
>> --
>> 2.30.0
>>
>>
>
> --
> Kees Cook

Al


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v5 mips-next 0/9] MIPS: vmlinux.lds.S sections fixes & cleanup
  2021-01-11 20:57   ` Alexander Lobakin
@ 2021-01-11 22:43     ` Thomas Bogendoerfer
  2021-01-15 11:15       ` Arnd Bergmann
  0 siblings, 1 reply; 17+ messages in thread
From: Thomas Bogendoerfer @ 2021-01-11 22:43 UTC (permalink / raw)
  To: Alexander Lobakin
  Cc: Kees Cook, Arnd Bergmann, Nathan Chancellor, Nick Desaulniers,
	Huacai Chen, Pei Huang, Fangrui Song, Jiaxun Yang, Ralf Baechle,
	Corey Minyard, linux-mips, linux-kernel, linux-arch, stable,
	clang-built-linux

On Mon, Jan 11, 2021 at 08:57:25PM +0000, Alexander Lobakin wrote:
> From: Kees Cook <keescook@chromium.org>
> Date: Mon, 11 Jan 2021 11:53:39 -0800
> 
> > On Sun, Jan 10, 2021 at 11:53:50AM +0000, Alexander Lobakin wrote:
> >> This series hunts the problems discovered after manual enabling of
> >> ARCH_WANT_LD_ORPHAN_WARN. Notably:
> >>  - adds the missing PAGE_ALIGNED_DATA() section affecting VDSO
> >>    placement (marked for stable);
> >>  - stops blind catching of orphan text sections with .text.*
> >>    directive;
> >>  - properly stops .eh_frame section generation.
> >>
> >> Compile and runtime tested on MIPS32R2 CPS board with no issues
> >> using two different toolkits:
> >>  - Binutils 2.35.1, GCC 10.2.1 (with Alpine patches);
> >>  - LLVM stack: 11.0.0 and from latest Git snapshot.
> >>
> >> Since v4 [3]:
> >>  - new: drop redundant .text.cps-vec creation and blind inclusion
> >>    of orphan text sections via .text.* directive in vmlinux.lds.S;
> >>  - don't assert SIZEOF(.rel.dyn) as it's reported that it may be not
> >>    empty on certain machines and compilers (Thomas);
> >>  - align GOT table like it's done for ARM64;
> >>  - new: catch UBSAN's "unnamed data" sections in generic definitions
> >>    when building with LD_DEAD_CODE_DATA_ELIMINATION;
> >>  - collect Reviewed-bys (Kees, Nathan).
> >
> > Looks good; which tree will this land through?
> 
> linux-mips/mips-next I guess, since 7 of 9 patches are related only
> to this architecture.
> This might need Arnd's Acked-bys or Reviewed-by for the two that
> refer include/asm-generic, let's see what Thomas think.

Looks good from my side and I have it already sitting in branch for
submission.

Arnd, are you ok with the changes in include/asm-generic ?

Thomas.

-- 
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v5 mips-next 0/9] MIPS: vmlinux.lds.S sections fixes & cleanup
  2021-01-11 22:43     ` Thomas Bogendoerfer
@ 2021-01-15 11:15       ` Arnd Bergmann
  0 siblings, 0 replies; 17+ messages in thread
From: Arnd Bergmann @ 2021-01-15 11:15 UTC (permalink / raw)
  To: Thomas Bogendoerfer
  Cc: Alexander Lobakin, Kees Cook, Arnd Bergmann, Nathan Chancellor,
	Nick Desaulniers, Huacai Chen, Pei Huang, Fangrui Song,
	Jiaxun Yang, Ralf Baechle, Corey Minyard,
	open list:BROADCOM NVRAM DRIVER, linux-kernel, linux-arch,
	# 3.4.x, clang-built-linux

On Mon, Jan 11, 2021 at 11:44 PM Thomas Bogendoerfer
<tsbogend@alpha.franken.de> wrote:
> On Mon, Jan 11, 2021 at 08:57:25PM +0000, Alexander Lobakin wrote:
> > From: Kees Cook <keescook@chromium.org>
> > Date: Mon, 11 Jan 2021 11:53:39 -0800
> >
> > > On Sun, Jan 10, 2021 at 11:53:50AM +0000, Alexander Lobakin wrote:
> > >> This series hunts the problems discovered after manual enabling of
> > >> ARCH_WANT_LD_ORPHAN_WARN. Notably:
> > >>  - adds the missing PAGE_ALIGNED_DATA() section affecting VDSO
> > >>    placement (marked for stable);
> > >>  - stops blind catching of orphan text sections with .text.*
> > >>    directive;
> > >>  - properly stops .eh_frame section generation.
> > >>
> > >> Compile and runtime tested on MIPS32R2 CPS board with no issues
> > >> using two different toolkits:
> > >>  - Binutils 2.35.1, GCC 10.2.1 (with Alpine patches);
> > >>  - LLVM stack: 11.0.0 and from latest Git snapshot.
> > >>
> > >> Since v4 [3]:
> > >>  - new: drop redundant .text.cps-vec creation and blind inclusion
> > >>    of orphan text sections via .text.* directive in vmlinux.lds.S;
> > >>  - don't assert SIZEOF(.rel.dyn) as it's reported that it may be not
> > >>    empty on certain machines and compilers (Thomas);
> > >>  - align GOT table like it's done for ARM64;
> > >>  - new: catch UBSAN's "unnamed data" sections in generic definitions
> > >>    when building with LD_DEAD_CODE_DATA_ELIMINATION;
> > >>  - collect Reviewed-bys (Kees, Nathan).
> > >
> > > Looks good; which tree will this land through?
> >
> > linux-mips/mips-next I guess, since 7 of 9 patches are related only
> > to this architecture.
> > This might need Arnd's Acked-bys or Reviewed-by for the two that
> > refer include/asm-generic, let's see what Thomas think.
>
> Looks good from my side and I have it already sitting in branch for
> submission.
>
> Arnd, are you ok with the changes in include/asm-generic ?

Yes, I'm never quite sure about what to make of linker script changes,
but I trust Kees on the review. For merging it through your tree:

Acked-by: Arnd Bergmann <arnd@arndb.de>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v5 mips-next 0/9] MIPS: vmlinux.lds.S sections fixes & cleanup
  2021-01-10 11:53 [PATCH v5 mips-next 0/9] MIPS: vmlinux.lds.S sections fixes & cleanup Alexander Lobakin
  2021-01-10 11:56 ` [PATCH v5 mips-next 1/9] MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section Alexander Lobakin
  2021-01-11 19:53 ` [PATCH v5 mips-next 0/9] MIPS: vmlinux.lds.S sections fixes & cleanup Kees Cook
@ 2021-01-15 14:40 ` Thomas Bogendoerfer
  2 siblings, 0 replies; 17+ messages in thread
From: Thomas Bogendoerfer @ 2021-01-15 14:40 UTC (permalink / raw)
  To: Alexander Lobakin
  Cc: Arnd Bergmann, Nathan Chancellor, Nick Desaulniers, Huacai Chen,
	Pei Huang, Kees Cook, Fangrui Song, Jiaxun Yang, Ralf Baechle,
	Corey Minyard, linux-mips, linux-kernel, linux-arch, stable,
	clang-built-linux

On Sun, Jan 10, 2021 at 11:53:50AM +0000, Alexander Lobakin wrote:
> This series hunts the problems discovered after manual enabling of
> ARCH_WANT_LD_ORPHAN_WARN. Notably:
>  - adds the missing PAGE_ALIGNED_DATA() section affecting VDSO
>    placement (marked for stable);
>  - stops blind catching of orphan text sections with .text.*
>    directive;
>  - properly stops .eh_frame section generation.
> 
> Compile and runtime tested on MIPS32R2 CPS board with no issues
> using two different toolkits:
>  - Binutils 2.35.1, GCC 10.2.1 (with Alpine patches);
>  - LLVM stack: 11.0.0 and from latest Git snapshot.
> 
> Since v4 [3]:
>  - new: drop redundant .text.cps-vec creation and blind inclusion
>    of orphan text sections via .text.* directive in vmlinux.lds.S;
>  - don't assert SIZEOF(.rel.dyn) as it's reported that it may be not
>    empty on certain machines and compilers (Thomas);
>  - align GOT table like it's done for ARM64;
>  - new: catch UBSAN's "unnamed data" sections in generic definitions
>    when building with LD_DEAD_CODE_DATA_ELIMINATION;
>  - collect Reviewed-bys (Kees, Nathan).
> 
> Since v3 [2]:
>  - fix the third patch as GNU stack emits .rel.dyn into VDSO for
>    some reason if .cfi_sections is specified.
> 
> Since v2 [1]:
>  - stop discarding .eh_frame and just prevent it from generating
>    (Kees);
>  - drop redundant sections assertions (Fangrui);
>  - place GOT table in .text instead of asserting as it's not empty
>    when building with LLVM (Nathan);
>  - catch compound literals in generic definitions when building with
>    LD_DEAD_CODE_DATA_ELIMINATION (Kees);
>  - collect two Reviewed-bys (Kees).
> 
> Since v1 [0]:
>  - catch .got entries too as LLD may produce it (Nathan);
>  - check for unwanted sections to be zero-sized instead of
>    discarding (Fangrui).
> 
> [0] https://lore.kernel.org/linux-mips/20210104121729.46981-1-alobakin@pm.me
> [1] https://lore.kernel.org/linux-mips/20210106200713.31840-1-alobakin@pm.me
> [2] https://lore.kernel.org/linux-mips/20210107115120.281008-1-alobakin@pm.me
> [3] https://lore.kernel.org/linux-mips/20210107123331.354075-1-alobakin@pm.me
> 
> Alexander Lobakin (9):
>   MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section
>   MIPS: CPS: don't create redundant .text.cps-vec section
>   MIPS: vmlinux.lds.S: add ".gnu.attributes" to DISCARDS
>   MIPS: properly stop .eh_frame generation
>   MIPS: vmlinux.lds.S: explicitly catch .rel.dyn symbols
>   MIPS: vmlinux.lds.S: explicitly declare .got table
>   vmlinux.lds.h: catch compound literals into data and BSS
>   vmlinux.lds.h: catch UBSAN's "unnamed data" into data
>   MIPS: select ARCH_WANT_LD_ORPHAN_WARN
> 
>  arch/mips/Kconfig                 |  1 +
>  arch/mips/include/asm/asm.h       | 18 ++++++++++++++++++
>  arch/mips/kernel/cps-vec.S        |  1 -
>  arch/mips/kernel/vmlinux.lds.S    | 11 +++++++++--
>  include/asm-generic/vmlinux.lds.h |  6 +++---
>  5 files changed, 31 insertions(+), 6 deletions(-)

applied to mips-next.

Thoomas.

-- 
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2021-01-15 14:48 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-10 11:53 [PATCH v5 mips-next 0/9] MIPS: vmlinux.lds.S sections fixes & cleanup Alexander Lobakin
2021-01-10 11:56 ` [PATCH v5 mips-next 1/9] MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section Alexander Lobakin
2021-01-10 11:56   ` [PATCH v5 mips-next 2/9] MIPS: CPS: don't create redundant .text.cps-vec section Alexander Lobakin
2021-01-10 11:56   ` [PATCH v5 mips-next 3/9] MIPS: vmlinux.lds.S: add ".gnu.attributes" to DISCARDS Alexander Lobakin
2021-01-10 11:56   ` [PATCH v5 mips-next 4/9] MIPS: properly stop .eh_frame generation Alexander Lobakin
2021-01-10 11:56   ` [PATCH v5 mips-next 5/9] MIPS: vmlinux.lds.S: explicitly catch .rel.dyn symbols Alexander Lobakin
2021-01-11  1:28     ` Nathan Chancellor
2021-01-10 11:56   ` [PATCH v5 mips-next 6/9] MIPS: vmlinux.lds.S: explicitly declare .got table Alexander Lobakin
2021-01-10 11:56   ` [PATCH v5 mips-next 7/9] vmlinux.lds.h: catch compound literals into data and BSS Alexander Lobakin
2021-01-10 11:56   ` [PATCH v5 mips-next 8/9] vmlinux.lds.h: catch UBSAN's "unnamed data" into data Alexander Lobakin
2021-01-11  2:05     ` Nathan Chancellor
2021-01-10 11:57   ` [PATCH v5 mips-next 9/9] MIPS: select ARCH_WANT_LD_ORPHAN_WARN Alexander Lobakin
2021-01-11 19:53 ` [PATCH v5 mips-next 0/9] MIPS: vmlinux.lds.S sections fixes & cleanup Kees Cook
2021-01-11 20:57   ` Alexander Lobakin
2021-01-11 22:43     ` Thomas Bogendoerfer
2021-01-15 11:15       ` Arnd Bergmann
2021-01-15 14:40 ` Thomas Bogendoerfer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).