linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [GIT PULL] objtool fixes
@ 2017-02-28  7:53 Ingo Molnar
  2017-03-01  1:55 ` Linus Torvalds
  0 siblings, 1 reply; 12+ messages in thread
From: Ingo Molnar @ 2017-02-28  7:53 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: linux-kernel, Josh Poimboeuf, Thomas Gleixner, H. Peter Anvin,
	Peter Zijlstra

Linus,

Please pull the latest core-urgent-for-linus git tree from:

   git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git core-urgent-for-linus

   # HEAD: 4e4636cf981b5b629fbfb78aa9f232e015f7d521 objtool: Enclose contents of unreachable() macro in a block

A handful of objtool fixes related to unreachable code, plus a build fix for out 
of tree modules.

 Thanks,

	Ingo

------------------>
Josh Poimboeuf (4):
      objtool: Fix CONFIG_STACK_VALIDATION=y warning for out-of-tree modules
      objtool: Improve detection of BUG() and other dead ends
      objtool: Prevent GCC from merging annotate_unreachable()
      objtool: Enclose contents of unreachable() macro in a block


 Makefile                        | 24 ++++++++---------
 arch/x86/kernel/vmlinux.lds.S   |  1 +
 include/linux/compiler-gcc.h    | 14 +++++++++-
 tools/objtool/arch.h            |  5 ++--
 tools/objtool/arch/x86/decode.c |  3 ---
 tools/objtool/builtin-check.c   | 60 ++++++++++++++++++++++++++++++++++++++---
 6 files changed, 84 insertions(+), 23 deletions(-)

diff --git a/Makefile b/Makefile
index f1e6a02a0c19..32c84577aa93 100644
--- a/Makefile
+++ b/Makefile
@@ -908,6 +908,18 @@ mod_sign_cmd = true
 endif
 export mod_sign_cmd
 
+ifdef CONFIG_STACK_VALIDATION
+  has_libelf := $(call try-run,\
+		echo "int main() {}" | $(HOSTCC) -xc -o /dev/null -lelf -,1,0)
+  ifeq ($(has_libelf),1)
+    objtool_target := tools/objtool FORCE
+  else
+    $(warning "Cannot use CONFIG_STACK_VALIDATION, please install libelf-dev, libelf-devel or elfutils-libelf-devel")
+    SKIP_STACK_VALIDATION := 1
+    export SKIP_STACK_VALIDATION
+  endif
+endif
+
 
 ifeq ($(KBUILD_EXTMOD),)
 core-y		+= kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/
@@ -1035,18 +1047,6 @@ prepare0: archprepare gcc-plugins
 # All the preparing..
 prepare: prepare0 prepare-objtool
 
-ifdef CONFIG_STACK_VALIDATION
-  has_libelf := $(call try-run,\
-		echo "int main() {}" | $(HOSTCC) -xc -o /dev/null -lelf -,1,0)
-  ifeq ($(has_libelf),1)
-    objtool_target := tools/objtool FORCE
-  else
-    $(warning "Cannot use CONFIG_STACK_VALIDATION, please install libelf-dev, libelf-devel or elfutils-libelf-devel")
-    SKIP_STACK_VALIDATION := 1
-    export SKIP_STACK_VALIDATION
-  endif
-endif
-
 PHONY += prepare-objtool
 prepare-objtool: $(objtool_target)
 
diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index e79f15f108a8..ad0118fbce90 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -346,6 +346,7 @@ SECTIONS
 	/DISCARD/ : {
 		*(.eh_frame)
 		*(__func_stack_frame_non_standard)
+		*(__unreachable)
 	}
 }
 
diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index 0444b1336268..f457b520ead6 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -195,6 +195,17 @@
 #endif
 #endif
 
+#ifdef CONFIG_STACK_VALIDATION
+#define annotate_unreachable() ({					\
+	asm("%c0:\t\n"							\
+	    ".pushsection __unreachable, \"a\"\t\n"			\
+	    ".long %c0b\t\n"						\
+	    ".popsection\t\n" : : "i" (__LINE__));			\
+})
+#else
+#define annotate_unreachable()
+#endif
+
 /*
  * Mark a position in code as unreachable.  This can be used to
  * suppress control flow warnings after asm blocks that transfer
@@ -204,7 +215,8 @@
  * this in the preprocessor, but we can live with this because they're
  * unreleased.  Really, we need to have autoconf for the kernel.
  */
-#define unreachable() __builtin_unreachable()
+#define unreachable() \
+	do { annotate_unreachable(); __builtin_unreachable(); } while (0)
 
 /* Mark a function definition as prohibited from being cloned. */
 #define __noclone	__attribute__((__noclone__, __optimize__("no-tracer")))
diff --git a/tools/objtool/arch.h b/tools/objtool/arch.h
index f7350fcedc70..a59e061c0b4a 100644
--- a/tools/objtool/arch.h
+++ b/tools/objtool/arch.h
@@ -31,9 +31,8 @@
 #define INSN_CALL_DYNAMIC	8
 #define INSN_RETURN		9
 #define INSN_CONTEXT_SWITCH	10
-#define INSN_BUG		11
-#define INSN_NOP		12
-#define INSN_OTHER		13
+#define INSN_NOP		11
+#define INSN_OTHER		12
 #define INSN_LAST		INSN_OTHER
 
 int arch_decode_instruction(struct elf *elf, struct section *sec,
diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decode.c
index 039636ffb6c8..6ac99e3266eb 100644
--- a/tools/objtool/arch/x86/decode.c
+++ b/tools/objtool/arch/x86/decode.c
@@ -118,9 +118,6 @@ int arch_decode_instruction(struct elf *elf, struct section *sec,
 			 op2 == 0x35)
 			/* sysenter, sysret */
 			*type = INSN_CONTEXT_SWITCH;
-		else if (op2 == 0x0b || op2 == 0xb9)
-			/* ud2 */
-			*type = INSN_BUG;
 		else if (op2 == 0x0d || op2 == 0x1f)
 			/* nopl/nopw */
 			*type = INSN_NOP;
diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c
index e8a1f699058a..5fc52ee3264c 100644
--- a/tools/objtool/builtin-check.c
+++ b/tools/objtool/builtin-check.c
@@ -51,7 +51,7 @@ struct instruction {
 	unsigned int len, state;
 	unsigned char type;
 	unsigned long immediate;
-	bool alt_group, visited;
+	bool alt_group, visited, dead_end;
 	struct symbol *call_dest;
 	struct instruction *jump_dest;
 	struct list_head alts;
@@ -330,6 +330,54 @@ static int decode_instructions(struct objtool_file *file)
 }
 
 /*
+ * Find all uses of the unreachable() macro, which are code path dead ends.
+ */
+static int add_dead_ends(struct objtool_file *file)
+{
+	struct section *sec;
+	struct rela *rela;
+	struct instruction *insn;
+	bool found;
+
+	sec = find_section_by_name(file->elf, ".rela__unreachable");
+	if (!sec)
+		return 0;
+
+	list_for_each_entry(rela, &sec->rela_list, list) {
+		if (rela->sym->type != STT_SECTION) {
+			WARN("unexpected relocation symbol type in .rela__unreachable");
+			return -1;
+		}
+		insn = find_insn(file, rela->sym->sec, rela->addend);
+		if (insn)
+			insn = list_prev_entry(insn, list);
+		else if (rela->addend == rela->sym->sec->len) {
+			found = false;
+			list_for_each_entry_reverse(insn, &file->insn_list, list) {
+				if (insn->sec == rela->sym->sec) {
+					found = true;
+					break;
+				}
+			}
+
+			if (!found) {
+				WARN("can't find unreachable insn at %s+0x%x",
+				     rela->sym->sec->name, rela->addend);
+				return -1;
+			}
+		} else {
+			WARN("can't find unreachable insn at %s+0x%x",
+			     rela->sym->sec->name, rela->addend);
+			return -1;
+		}
+
+		insn->dead_end = true;
+	}
+
+	return 0;
+}
+
+/*
  * Warnings shouldn't be reported for ignored functions.
  */
 static void add_ignores(struct objtool_file *file)
@@ -843,6 +891,10 @@ static int decode_sections(struct objtool_file *file)
 	if (ret)
 		return ret;
 
+	ret = add_dead_ends(file);
+	if (ret)
+		return ret;
+
 	add_ignores(file);
 
 	ret = add_jump_destinations(file);
@@ -1037,13 +1089,13 @@ static int validate_branch(struct objtool_file *file,
 
 			return 0;
 
-		case INSN_BUG:
-			return 0;
-
 		default:
 			break;
 		}
 
+		if (insn->dead_end)
+			return 0;
+
 		insn = next_insn_same_sec(file, insn);
 		if (!insn) {
 			WARN("%s: unexpected end of section", sec->name);

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

* Re: [GIT PULL] objtool fixes
  2017-02-28  7:53 [GIT PULL] objtool fixes Ingo Molnar
@ 2017-03-01  1:55 ` Linus Torvalds
  2017-03-01  6:05   ` Josh Poimboeuf
  0 siblings, 1 reply; 12+ messages in thread
From: Linus Torvalds @ 2017-03-01  1:55 UTC (permalink / raw)
  To: Ingo Molnar, Josh Poimboeuf
  Cc: Linux Kernel Mailing List, Thomas Gleixner, H. Peter Anvin,
	Peter Zijlstra

Guys,
 the recent 'objtool' pull request broke things.

I haven't bisected it, but I'm pretty sure that this part is pure garbage:

On Mon, Feb 27, 2017 at 11:53 PM, Ingo Molnar <mingo@kernel.org> wrote:
>
> diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
> index e79f15f108a8..ad0118fbce90 100644
> --- a/arch/x86/kernel/vmlinux.lds.S
> +++ b/arch/x86/kernel/vmlinux.lds.S
> @@ -346,6 +346,7 @@ SECTIONS
>         /DISCARD/ : {
>                 *(.eh_frame)
>                 *(__func_stack_frame_non_standard)
> +               *(__unreachable)
>         }
>  }
>
> diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
> index 0444b1336268..f457b520ead6 100644
> --- a/include/linux/compiler-gcc.h
> +++ b/include/linux/compiler-gcc.h
> @@ -195,6 +195,17 @@
>  #endif
>  #endif
>
> +#ifdef CONFIG_STACK_VALIDATION
> +#define annotate_unreachable() ({                                      \
> +       asm("%c0:\t\n"                                                  \
> +           ".pushsection __unreachable, \"a\"\t\n"                     \
> +           ".long %c0b\t\n"                                            \
> +           ".popsection\t\n" : : "i" (__LINE__));                      \
> +})
> +#else
> +#define annotate_unreachable()
> +#endif

and I think the above is what breaks module loading for me right now
on my laptop.

I get this during bootup:

    module: overflow in relocation type 10 val ffffffffc02afc81
    module: 'nvme' likely not compiled with -mcmodel=kernel

(and similar errors for other modules too), but those modules very
much *are* compiled with all the normal kernel build flags, including
-mcmodel=kernel.

Now, relocation type 10 is R_X86_64_32, so the warning is very true:
that address would fit in a _signed_ 32-bit value, but that's
supposedly a 32-bit unsigned relocation.

Trying to figure out what the hell is going on, I do:

    objdump -r nvme.ko | grep 64_32

and what do I find? I find

  RELOCATION RECORDS FOR [__unreachable]:
  OFFSET           TYPE              VALUE
  0000000000000000 R_X86_64_32       .text+0x0000000000000c81
  0000000000000004 R_X86_64_32       .text+0x0000000000000cb5
  0000000000000008 R_X86_64_32       .text+0x0000000000001a18
  000000000000000c R_X86_64_32       .text+0x0000000000001a36
  0000000000000010 R_X86_64_32       .text+0x0000000000001e38
  0000000000000014 R_X86_64_32       .text+0x0000000000001ec2
  0000000000000018 R_X86_64_32       .text+0x00000000000034e2
  000000000000001c R_X86_64_32       .text+0x0000000000003536

and then when I look more closely (objdump --disassemble), I see that
the offset 000c81 in the module refers to this:

  0000000000000c60 <nvme_admin_init_request>:
        ....
     c7f:       0f 0b                   ud2
     c81:       0f 1f 44 00 00          nopl   0x0(%rax,%rax,1)

so it very much looks like those relocations are still around on
modules, and so module loading fails.

Anyway, those annotations are completely bogus anyway, it looks. You
guys should use relative offsets in order to be able to specify a
kernel address. So doing

    .long %c0

is garbage - either it needs to be a .quad, or it needs to be relative
to the text section to fit in a .long.

Hmm? Revert or fix, but please quickly...

                   Linus

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

* Re: [GIT PULL] objtool fixes
  2017-03-01  1:55 ` Linus Torvalds
@ 2017-03-01  6:05   ` Josh Poimboeuf
  2017-03-01  8:10     ` [tip:core/urgent] objtool: Fix __unreachable section relocation size tip-bot for Josh Poimboeuf
                       ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Josh Poimboeuf @ 2017-03-01  6:05 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: Ingo Molnar, Linux Kernel Mailing List, Thomas Gleixner,
	H. Peter Anvin, Peter Zijlstra

On Tue, Feb 28, 2017 at 05:55:11PM -0800, Linus Torvalds wrote:
> Guys,
>  the recent 'objtool' pull request broke things.
> 
> I haven't bisected it, but I'm pretty sure that this part is pure garbage:
> 
> On Mon, Feb 27, 2017 at 11:53 PM, Ingo Molnar <mingo@kernel.org> wrote:
> >
> > diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
> > index e79f15f108a8..ad0118fbce90 100644
> > --- a/arch/x86/kernel/vmlinux.lds.S
> > +++ b/arch/x86/kernel/vmlinux.lds.S
> > @@ -346,6 +346,7 @@ SECTIONS
> >         /DISCARD/ : {
> >                 *(.eh_frame)
> >                 *(__func_stack_frame_non_standard)
> > +               *(__unreachable)
> >         }
> >  }
> >
> > diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
> > index 0444b1336268..f457b520ead6 100644
> > --- a/include/linux/compiler-gcc.h
> > +++ b/include/linux/compiler-gcc.h
> > @@ -195,6 +195,17 @@
> >  #endif
> >  #endif
> >
> > +#ifdef CONFIG_STACK_VALIDATION
> > +#define annotate_unreachable() ({                                      \
> > +       asm("%c0:\t\n"                                                  \
> > +           ".pushsection __unreachable, \"a\"\t\n"                     \
> > +           ".long %c0b\t\n"                                            \
> > +           ".popsection\t\n" : : "i" (__LINE__));                      \
> > +})
> > +#else
> > +#define annotate_unreachable()
> > +#endif
> 
> and I think the above is what breaks module loading for me right now
> on my laptop.
> 
> I get this during bootup:
> 
>     module: overflow in relocation type 10 val ffffffffc02afc81
>     module: 'nvme' likely not compiled with -mcmodel=kernel
> 
> (and similar errors for other modules too), but those modules very
> much *are* compiled with all the normal kernel build flags, including
> -mcmodel=kernel.
> 
> Now, relocation type 10 is R_X86_64_32, so the warning is very true:
> that address would fit in a _signed_ 32-bit value, but that's
> supposedly a 32-bit unsigned relocation.
> 
> Trying to figure out what the hell is going on, I do:
> 
>     objdump -r nvme.ko | grep 64_32
> 
> and what do I find? I find
> 
>   RELOCATION RECORDS FOR [__unreachable]:
>   OFFSET           TYPE              VALUE
>   0000000000000000 R_X86_64_32       .text+0x0000000000000c81
>   0000000000000004 R_X86_64_32       .text+0x0000000000000cb5
>   0000000000000008 R_X86_64_32       .text+0x0000000000001a18
>   000000000000000c R_X86_64_32       .text+0x0000000000001a36
>   0000000000000010 R_X86_64_32       .text+0x0000000000001e38
>   0000000000000014 R_X86_64_32       .text+0x0000000000001ec2
>   0000000000000018 R_X86_64_32       .text+0x00000000000034e2
>   000000000000001c R_X86_64_32       .text+0x0000000000003536
> 
> and then when I look more closely (objdump --disassemble), I see that
> the offset 000c81 in the module refers to this:
> 
>   0000000000000c60 <nvme_admin_init_request>:
>         ....
>      c7f:       0f 0b                   ud2
>      c81:       0f 1f 44 00 00          nopl   0x0(%rax,%rax,1)
> 
> so it very much looks like those relocations are still around on
> modules, and so module loading fails.
> 
> Anyway, those annotations are completely bogus anyway, it looks. You
> guys should use relative offsets in order to be able to specify a
> kernel address. So doing
> 
>     .long %c0
> 
> is garbage - either it needs to be a .quad, or it needs to be relative
> to the text section to fit in a .long.
> 
> Hmm? Revert or fix, but please quickly...

Yuck, sorry about that.  Patch to fix it below.

This also highlights another (minor) issue: the '__unreachable' section
is meant to be a compile-time-only thing.  It's supposed to be discarded
at link time, but apparently that isn't happening for modules.

I tried excluding it from linking with the .pushsection "e" flag, but no
luck.  I'll try to figure out how to fix that shortly.

In the meantime, here's the fix you need.  It now uses X86_64_64
relocations.

----

From: Josh Poimboeuf <jpoimboe@redhat.com>
Subject: [PATCH] objtool: fix __unreachable section relocation size

Linus reported the following commit broke module loading on his laptop:

  d1091c7fa3d5 ("objtool: Improve detection of BUG() and other dead ends")

It showed errors like the following:

  module: overflow in relocation type 10 val ffffffffc02afc81
  module: 'nvme' likely not compiled with -mcmodel=kernel

The problem is that the __unreachable section addresses are stored using
the '.long' asm directive, which isn't big enough for .text section
relative kernel addresses.  Use '.quad' instead.

Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Fixes: d1091c7fa3d5 ("objtool: Improve detection of BUG() and other dead ends")
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 include/linux/compiler-gcc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index f457b520..7bd21e8 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -199,7 +199,7 @@
 #define annotate_unreachable() ({					\
 	asm("%c0:\t\n"							\
 	    ".pushsection __unreachable, \"a\"\t\n"			\
-	    ".long %c0b\t\n"						\
+	    ".quad %c0b\t\n"						\
 	    ".popsection\t\n" : : "i" (__LINE__));			\
 })
 #else
-- 
2.7.4

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

* [tip:core/urgent] objtool: Fix __unreachable section relocation size
  2017-03-01  6:05   ` Josh Poimboeuf
@ 2017-03-01  8:10     ` tip-bot for Josh Poimboeuf
  2017-03-01  8:15       ` hpa
  2017-03-01 10:37       ` [tip:core/urgent] objtool: " Ingo Molnar
  2017-03-01 12:45     ` [tip:core/urgent] objtool, compiler.h: " tip-bot for Josh Poimboeuf
  2017-03-01 13:24     ` tip-bot for Josh Poimboeuf
  2 siblings, 2 replies; 12+ messages in thread
From: tip-bot for Josh Poimboeuf @ 2017-03-01  8:10 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: a.p.zijlstra, torvalds, jpoimboe, tglx, linux-kernel, peterz, mingo, hpa

Commit-ID:  90a7e63a31b8f7d630d12ef0d8d37d3ab87f76e5
Gitweb:     http://git.kernel.org/tip/90a7e63a31b8f7d630d12ef0d8d37d3ab87f76e5
Author:     Josh Poimboeuf <jpoimboe@redhat.com>
AuthorDate: Wed, 1 Mar 2017 00:05:04 -0600
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 1 Mar 2017 07:38:25 +0100

objtool: Fix __unreachable section relocation size

Linus reported the following commit broke module loading on his laptop:

  d1091c7fa3d5 ("objtool: Improve detection of BUG() and other dead ends")

It showed errors like the following:

  module: overflow in relocation type 10 val ffffffffc02afc81
  module: 'nvme' likely not compiled with -mcmodel=kernel

The problem is that the __unreachable section addresses are stored using
the '.long' asm directive, which isn't big enough for .text section
relative kernel addresses.  Use '.quad' instead.

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Fixes: d1091c7fa3d5 ("objtool: Improve detection of BUG() and other dead ends")
Link: http://lkml.kernel.org/r/20170301060504.oltm3iws6fmubnom@treble
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 include/linux/compiler-gcc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index 76e28c2..91a77a5 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -201,7 +201,7 @@
 #define annotate_unreachable() ({					\
 	asm("%c0:\t\n"							\
 	    ".pushsection __unreachable, \"a\"\t\n"			\
-	    ".long %c0b\t\n"						\
+	    ".quad %c0b\t\n"						\
 	    ".popsection\t\n" : : "i" (__LINE__));			\
 })
 #else

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

* Re: [tip:core/urgent] objtool: Fix __unreachable section relocation size
  2017-03-01  8:10     ` [tip:core/urgent] objtool: Fix __unreachable section relocation size tip-bot for Josh Poimboeuf
@ 2017-03-01  8:15       ` hpa
  2017-03-01 12:41         ` Josh Poimboeuf
  2017-03-01 10:37       ` [tip:core/urgent] objtool: " Ingo Molnar
  1 sibling, 1 reply; 12+ messages in thread
From: hpa @ 2017-03-01  8:15 UTC (permalink / raw)
  To: linux-tip-commits, tip-bot for Josh Poimboeuf
  Cc: a.p.zijlstra, torvalds, jpoimboe, tglx, linux-kernel, peterz, mingo

On March 1, 2017 12:10:59 AM PST, tip-bot for Josh Poimboeuf <tipbot@zytor.com> wrote:
>Commit-ID:  90a7e63a31b8f7d630d12ef0d8d37d3ab87f76e5
>Gitweb:    
>http://git.kernel.org/tip/90a7e63a31b8f7d630d12ef0d8d37d3ab87f76e5
>Author:     Josh Poimboeuf <jpoimboe@redhat.com>
>AuthorDate: Wed, 1 Mar 2017 00:05:04 -0600
>Committer:  Ingo Molnar <mingo@kernel.org>
>CommitDate: Wed, 1 Mar 2017 07:38:25 +0100
>
>objtool: Fix __unreachable section relocation size
>
>Linus reported the following commit broke module loading on his laptop:
>
>d1091c7fa3d5 ("objtool: Improve detection of BUG() and other dead
>ends")
>
>It showed errors like the following:
>
>  module: overflow in relocation type 10 val ffffffffc02afc81
>  module: 'nvme' likely not compiled with -mcmodel=kernel
>
>The problem is that the __unreachable section addresses are stored
>using
>the '.long' asm directive, which isn't big enough for .text section
>relative kernel addresses.  Use '.quad' instead.
>
>Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
>Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
>Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
>Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
>Cc: Peter Zijlstra <peterz@infradead.org>
>Cc: Thomas Gleixner <tglx@linutronix.de>
>Fixes: d1091c7fa3d5 ("objtool: Improve detection of BUG() and other
>dead ends")
>Link: http://lkml.kernel.org/r/20170301060504.oltm3iws6fmubnom@treble
>Signed-off-by: Ingo Molnar <mingo@kernel.org>
>---
> include/linux/compiler-gcc.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/include/linux/compiler-gcc.h
>b/include/linux/compiler-gcc.h
>index 76e28c2..91a77a5 100644
>--- a/include/linux/compiler-gcc.h
>+++ b/include/linux/compiler-gcc.h
>@@ -201,7 +201,7 @@
> #define annotate_unreachable() ({					\
> 	asm("%c0:\t\n"							\
> 	    ".pushsection __unreachable, \"a\"\t\n"			\
>-	    ".long %c0b\t\n"						\
>+	    ".quad %c0b\t\n"						\
> 	    ".popsection\t\n" : : "i" (__LINE__));			\
> })
> #else

Or perhaps better use relative addresses, so:

.long foo - (.+4)


-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.

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

* Re: [tip:core/urgent] objtool: Fix __unreachable section relocation size
  2017-03-01  8:10     ` [tip:core/urgent] objtool: Fix __unreachable section relocation size tip-bot for Josh Poimboeuf
  2017-03-01  8:15       ` hpa
@ 2017-03-01 10:37       ` Ingo Molnar
  2017-03-01 12:43         ` Josh Poimboeuf
  1 sibling, 1 reply; 12+ messages in thread
From: Ingo Molnar @ 2017-03-01 10:37 UTC (permalink / raw)
  To: linux-kernel, tglx, jpoimboe, a.p.zijlstra, torvalds, peterz, hpa
  Cc: linux-tip-commits


* tip-bot for Josh Poimboeuf <tipbot@zytor.com> wrote:

> Commit-ID:  90a7e63a31b8f7d630d12ef0d8d37d3ab87f76e5
> Gitweb:     http://git.kernel.org/tip/90a7e63a31b8f7d630d12ef0d8d37d3ab87f76e5
> Author:     Josh Poimboeuf <jpoimboe@redhat.com>
> AuthorDate: Wed, 1 Mar 2017 00:05:04 -0600
> Committer:  Ingo Molnar <mingo@kernel.org>
> CommitDate: Wed, 1 Mar 2017 07:38:25 +0100
> 
> objtool: Fix __unreachable section relocation size
> 
> Linus reported the following commit broke module loading on his laptop:
> 
>   d1091c7fa3d5 ("objtool: Improve detection of BUG() and other dead ends")
> 
> It showed errors like the following:
> 
>   module: overflow in relocation type 10 val ffffffffc02afc81
>   module: 'nvme' likely not compiled with -mcmodel=kernel

BTW., beyond inadequate testing, another mistake I failed to notice during review 
is that the title of the patch was actively misleading: an "objtool: " prefix 
suggests a change that only affects objtool, while the changes here were to 
compiler-gcc.h, affecting pretty much everyone...

So a better, more informative commit title would have been:

   objtool, compiler.h: Improve detection of BUG() and other dead ends

... to at least warn people about the wider impact. (To be honest I personally 
probably would still not have noticed the bug, but maybe others.)

Along the same lines I'll fix the title of this fix patch as well, once a final 
version has been reached.

Thanks,

	Ingo

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

* Re: [tip:core/urgent] objtool: Fix __unreachable section relocation size
  2017-03-01  8:15       ` hpa
@ 2017-03-01 12:41         ` Josh Poimboeuf
  2017-03-01 12:44           ` [PATCH] objtool, compiler.h: " Ingo Molnar
  0 siblings, 1 reply; 12+ messages in thread
From: Josh Poimboeuf @ 2017-03-01 12:41 UTC (permalink / raw)
  To: hpa
  Cc: linux-tip-commits, tip-bot for Josh Poimboeuf, a.p.zijlstra,
	torvalds, tglx, linux-kernel, peterz, mingo

On Wed, Mar 01, 2017 at 12:15:38AM -0800, hpa@zytor.com wrote:
> On March 1, 2017 12:10:59 AM PST, tip-bot for Josh Poimboeuf <tipbot@zytor.com> wrote:
> >Commit-ID:  90a7e63a31b8f7d630d12ef0d8d37d3ab87f76e5
> >Gitweb:    
> >http://git.kernel.org/tip/90a7e63a31b8f7d630d12ef0d8d37d3ab87f76e5
> >Author:     Josh Poimboeuf <jpoimboe@redhat.com>
> >AuthorDate: Wed, 1 Mar 2017 00:05:04 -0600
> >Committer:  Ingo Molnar <mingo@kernel.org>
> >CommitDate: Wed, 1 Mar 2017 07:38:25 +0100
> >
> >objtool: Fix __unreachable section relocation size
> >
> >Linus reported the following commit broke module loading on his laptop:
> >
> >d1091c7fa3d5 ("objtool: Improve detection of BUG() and other dead
> >ends")
> >
> >It showed errors like the following:
> >
> >  module: overflow in relocation type 10 val ffffffffc02afc81
> >  module: 'nvme' likely not compiled with -mcmodel=kernel
> >
> >The problem is that the __unreachable section addresses are stored
> >using
> >the '.long' asm directive, which isn't big enough for .text section
> >relative kernel addresses.  Use '.quad' instead.
> >
> >Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
> >Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
> >Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
> >Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
> >Cc: Peter Zijlstra <peterz@infradead.org>
> >Cc: Thomas Gleixner <tglx@linutronix.de>
> >Fixes: d1091c7fa3d5 ("objtool: Improve detection of BUG() and other
> >dead ends")
> >Link: http://lkml.kernel.org/r/20170301060504.oltm3iws6fmubnom@treble
> >Signed-off-by: Ingo Molnar <mingo@kernel.org>
> >---
> > include/linux/compiler-gcc.h | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> >diff --git a/include/linux/compiler-gcc.h
> >b/include/linux/compiler-gcc.h
> >index 76e28c2..91a77a5 100644
> >--- a/include/linux/compiler-gcc.h
> >+++ b/include/linux/compiler-gcc.h
> >@@ -201,7 +201,7 @@
> > #define annotate_unreachable() ({					\
> > 	asm("%c0:\t\n"							\
> > 	    ".pushsection __unreachable, \"a\"\t\n"			\
> >-	    ".long %c0b\t\n"						\
> >+	    ".quad %c0b\t\n"						\
> > 	    ".popsection\t\n" : : "i" (__LINE__));			\
> > })
> > #else
> 
> Or perhaps better use relative addresses, so:
> 
> .long foo - (.+4)

Hm, yeah, something like that would indeed be better as it only needs 4
bytes instead of 8.  For this use case, the following seems to work:

  ".long %c0b - .\t\n"

It produces the same relocation section+addend as before but with a
X86_64_PC32 relocation.

It looks like the above patch was already merged so I'll add that change
to the TODO list unless Ingo can squash it with the above patch.

-- 
Josh

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

* Re: [tip:core/urgent] objtool: Fix __unreachable section relocation size
  2017-03-01 10:37       ` [tip:core/urgent] objtool: " Ingo Molnar
@ 2017-03-01 12:43         ` Josh Poimboeuf
  0 siblings, 0 replies; 12+ messages in thread
From: Josh Poimboeuf @ 2017-03-01 12:43 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, tglx, a.p.zijlstra, torvalds, peterz, hpa,
	linux-tip-commits

On Wed, Mar 01, 2017 at 11:37:12AM +0100, Ingo Molnar wrote:
> 
> * tip-bot for Josh Poimboeuf <tipbot@zytor.com> wrote:
> 
> > Commit-ID:  90a7e63a31b8f7d630d12ef0d8d37d3ab87f76e5
> > Gitweb:     http://git.kernel.org/tip/90a7e63a31b8f7d630d12ef0d8d37d3ab87f76e5
> > Author:     Josh Poimboeuf <jpoimboe@redhat.com>
> > AuthorDate: Wed, 1 Mar 2017 00:05:04 -0600
> > Committer:  Ingo Molnar <mingo@kernel.org>
> > CommitDate: Wed, 1 Mar 2017 07:38:25 +0100
> > 
> > objtool: Fix __unreachable section relocation size
> > 
> > Linus reported the following commit broke module loading on his laptop:
> > 
> >   d1091c7fa3d5 ("objtool: Improve detection of BUG() and other dead ends")
> > 
> > It showed errors like the following:
> > 
> >   module: overflow in relocation type 10 val ffffffffc02afc81
> >   module: 'nvme' likely not compiled with -mcmodel=kernel
> 
> BTW., beyond inadequate testing, another mistake I failed to notice during review 
> is that the title of the patch was actively misleading: an "objtool: " prefix 
> suggests a change that only affects objtool, while the changes here were to 
> compiler-gcc.h, affecting pretty much everyone...
> 
> So a better, more informative commit title would have been:
> 
>    objtool, compiler.h: Improve detection of BUG() and other dead ends
> 
> ... to at least warn people about the wider impact. (To be honest I personally 
> probably would still not have noticed the bug, but maybe others.)
> 
> Along the same lines I'll fix the title of this fix patch as well, once a final 
> version has been reached.

Yeah, that would have been a more informative title indeed.

For what seemed (to me) like a straightforward improvement, which was
90% objtool and 10% kernel, that commit introduced a surprising number
of subtle bugs in the kernel.

-- 
Josh

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

* [PATCH] objtool, compiler.h: Fix __unreachable section relocation size
  2017-03-01 12:41         ` Josh Poimboeuf
@ 2017-03-01 12:44           ` Ingo Molnar
  2017-03-01 12:56             ` Josh Poimboeuf
  0 siblings, 1 reply; 12+ messages in thread
From: Ingo Molnar @ 2017-03-01 12:44 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: hpa, linux-tip-commits, tip-bot for Josh Poimboeuf, a.p.zijlstra,
	torvalds, tglx, linux-kernel, peterz


* Josh Poimboeuf <jpoimboe@redhat.com> wrote:

> On Wed, Mar 01, 2017 at 12:15:38AM -0800, hpa@zytor.com wrote:
> > On March 1, 2017 12:10:59 AM PST, tip-bot for Josh Poimboeuf <tipbot@zytor.com> wrote:
> > >Commit-ID:  90a7e63a31b8f7d630d12ef0d8d37d3ab87f76e5
> > >Gitweb:    
> > >http://git.kernel.org/tip/90a7e63a31b8f7d630d12ef0d8d37d3ab87f76e5
> > >Author:     Josh Poimboeuf <jpoimboe@redhat.com>
> > >AuthorDate: Wed, 1 Mar 2017 00:05:04 -0600
> > >Committer:  Ingo Molnar <mingo@kernel.org>
> > >CommitDate: Wed, 1 Mar 2017 07:38:25 +0100
> > >
> > >objtool: Fix __unreachable section relocation size
> > >
> > >Linus reported the following commit broke module loading on his laptop:
> > >
> > >d1091c7fa3d5 ("objtool: Improve detection of BUG() and other dead
> > >ends")
> > >
> > >It showed errors like the following:
> > >
> > >  module: overflow in relocation type 10 val ffffffffc02afc81
> > >  module: 'nvme' likely not compiled with -mcmodel=kernel
> > >
> > >The problem is that the __unreachable section addresses are stored
> > >using
> > >the '.long' asm directive, which isn't big enough for .text section
> > >relative kernel addresses.  Use '.quad' instead.
> > >
> > >Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
> > >Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
> > >Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
> > >Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
> > >Cc: Peter Zijlstra <peterz@infradead.org>
> > >Cc: Thomas Gleixner <tglx@linutronix.de>
> > >Fixes: d1091c7fa3d5 ("objtool: Improve detection of BUG() and other
> > >dead ends")
> > >Link: http://lkml.kernel.org/r/20170301060504.oltm3iws6fmubnom@treble
> > >Signed-off-by: Ingo Molnar <mingo@kernel.org>
> > >---
> > > include/linux/compiler-gcc.h | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > >diff --git a/include/linux/compiler-gcc.h
> > >b/include/linux/compiler-gcc.h
> > >index 76e28c2..91a77a5 100644
> > >--- a/include/linux/compiler-gcc.h
> > >+++ b/include/linux/compiler-gcc.h
> > >@@ -201,7 +201,7 @@
> > > #define annotate_unreachable() ({					\
> > > 	asm("%c0:\t\n"							\
> > > 	    ".pushsection __unreachable, \"a\"\t\n"			\
> > >-	    ".long %c0b\t\n"						\
> > >+	    ".quad %c0b\t\n"						\
> > > 	    ".popsection\t\n" : : "i" (__LINE__));			\
> > > })
> > > #else
> > 
> > Or perhaps better use relative addresses, so:
> > 
> > .long foo - (.+4)
> 
> Hm, yeah, something like that would indeed be better as it only needs 4
> bytes instead of 8.  For this use case, the following seems to work:
> 
>   ".long %c0b - .\t\n"
> 
> It produces the same relocation section+addend as before but with a
> X86_64_PC32 relocation.
> 
> It looks like the above patch was already merged so I'll add that change
> to the TODO list unless Ingo can squash it with the above patch.

I've squashed it - attached the latest version. Does this look good to everyone?

Thanks,

	Ingo

================>
>From a6ae17f553bf9b4a0c7f8534e5f0f983bc7955c7 Mon Sep 17 00:00:00 2001
From: Josh Poimboeuf <jpoimboe@redhat.com>
Date: Wed, 1 Mar 2017 00:05:04 -0600
Subject: [PATCH] objtool, compiler.h: Fix __unreachable section relocation size

Linus reported the following commit broke module loading on his laptop:

  d1091c7fa3d5 ("objtool: Improve detection of BUG() and other dead ends")

It showed errors like the following:

  module: overflow in relocation type 10 val ffffffffc02afc81
  module: 'nvme' likely not compiled with -mcmodel=kernel

The problem is that the __unreachable section addresses are stored using
the '.long' asm directive, which isn't big enough for .text section
relative kernel addresses.  Use relative addresses instead:

  ".long %c0b - .\t\n"

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Fixes: d1091c7fa3d5 ("objtool: Improve detection of BUG() and other dead ends")
Link: http://lkml.kernel.org/r/20170301060504.oltm3iws6fmubnom@treble
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 include/linux/compiler-gcc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index 76e28c229805..b6bb9019d87f 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -201,7 +201,7 @@
 #define annotate_unreachable() ({					\
 	asm("%c0:\t\n"							\
 	    ".pushsection __unreachable, \"a\"\t\n"			\
-	    ".long %c0b\t\n"						\
+	    ".long %c0b - .\t\n"					\
 	    ".popsection\t\n" : : "i" (__LINE__));			\
 })
 #else

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

* [tip:core/urgent] objtool, compiler.h: Fix __unreachable section relocation size
  2017-03-01  6:05   ` Josh Poimboeuf
  2017-03-01  8:10     ` [tip:core/urgent] objtool: Fix __unreachable section relocation size tip-bot for Josh Poimboeuf
@ 2017-03-01 12:45     ` tip-bot for Josh Poimboeuf
  2017-03-01 13:24     ` tip-bot for Josh Poimboeuf
  2 siblings, 0 replies; 12+ messages in thread
From: tip-bot for Josh Poimboeuf @ 2017-03-01 12:45 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, tglx, torvalds, hpa, a.p.zijlstra, jpoimboe, peterz, mingo

Commit-ID:  a6ae17f553bf9b4a0c7f8534e5f0f983bc7955c7
Gitweb:     http://git.kernel.org/tip/a6ae17f553bf9b4a0c7f8534e5f0f983bc7955c7
Author:     Josh Poimboeuf <jpoimboe@redhat.com>
AuthorDate: Wed, 1 Mar 2017 00:05:04 -0600
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 1 Mar 2017 13:43:05 +0100

objtool, compiler.h: Fix __unreachable section relocation size

Linus reported the following commit broke module loading on his laptop:

  d1091c7fa3d5 ("objtool: Improve detection of BUG() and other dead ends")

It showed errors like the following:

  module: overflow in relocation type 10 val ffffffffc02afc81
  module: 'nvme' likely not compiled with -mcmodel=kernel

The problem is that the __unreachable section addresses are stored using
the '.long' asm directive, which isn't big enough for .text section
relative kernel addresses.  Use relative addresses instead:

  ".long %c0b - .\t\n"

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Fixes: d1091c7fa3d5 ("objtool: Improve detection of BUG() and other dead ends")
Link: http://lkml.kernel.org/r/20170301060504.oltm3iws6fmubnom@treble
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 include/linux/compiler-gcc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index 76e28c2..b6bb901 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -201,7 +201,7 @@
 #define annotate_unreachable() ({					\
 	asm("%c0:\t\n"							\
 	    ".pushsection __unreachable, \"a\"\t\n"			\
-	    ".long %c0b\t\n"						\
+	    ".long %c0b - .\t\n"					\
 	    ".popsection\t\n" : : "i" (__LINE__));			\
 })
 #else

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

* Re: [PATCH] objtool, compiler.h: Fix __unreachable section relocation size
  2017-03-01 12:44           ` [PATCH] objtool, compiler.h: " Ingo Molnar
@ 2017-03-01 12:56             ` Josh Poimboeuf
  0 siblings, 0 replies; 12+ messages in thread
From: Josh Poimboeuf @ 2017-03-01 12:56 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: hpa, linux-tip-commits, tip-bot for Josh Poimboeuf, a.p.zijlstra,
	torvalds, tglx, linux-kernel, peterz

On Wed, Mar 01, 2017 at 01:44:01PM +0100, Ingo Molnar wrote:
> 
> * Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> 
> > On Wed, Mar 01, 2017 at 12:15:38AM -0800, hpa@zytor.com wrote:
> > > On March 1, 2017 12:10:59 AM PST, tip-bot for Josh Poimboeuf <tipbot@zytor.com> wrote:
> > > >Commit-ID:  90a7e63a31b8f7d630d12ef0d8d37d3ab87f76e5
> > > >Gitweb:    
> > > >http://git.kernel.org/tip/90a7e63a31b8f7d630d12ef0d8d37d3ab87f76e5
> > > >Author:     Josh Poimboeuf <jpoimboe@redhat.com>
> > > >AuthorDate: Wed, 1 Mar 2017 00:05:04 -0600
> > > >Committer:  Ingo Molnar <mingo@kernel.org>
> > > >CommitDate: Wed, 1 Mar 2017 07:38:25 +0100
> > > >
> > > >objtool: Fix __unreachable section relocation size
> > > >
> > > >Linus reported the following commit broke module loading on his laptop:
> > > >
> > > >d1091c7fa3d5 ("objtool: Improve detection of BUG() and other dead
> > > >ends")
> > > >
> > > >It showed errors like the following:
> > > >
> > > >  module: overflow in relocation type 10 val ffffffffc02afc81
> > > >  module: 'nvme' likely not compiled with -mcmodel=kernel
> > > >
> > > >The problem is that the __unreachable section addresses are stored
> > > >using
> > > >the '.long' asm directive, which isn't big enough for .text section
> > > >relative kernel addresses.  Use '.quad' instead.
> > > >
> > > >Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
> > > >Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
> > > >Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
> > > >Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
> > > >Cc: Peter Zijlstra <peterz@infradead.org>
> > > >Cc: Thomas Gleixner <tglx@linutronix.de>
> > > >Fixes: d1091c7fa3d5 ("objtool: Improve detection of BUG() and other
> > > >dead ends")
> > > >Link: http://lkml.kernel.org/r/20170301060504.oltm3iws6fmubnom@treble
> > > >Signed-off-by: Ingo Molnar <mingo@kernel.org>
> > > >---
> > > > include/linux/compiler-gcc.h | 2 +-
> > > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > > >
> > > >diff --git a/include/linux/compiler-gcc.h
> > > >b/include/linux/compiler-gcc.h
> > > >index 76e28c2..91a77a5 100644
> > > >--- a/include/linux/compiler-gcc.h
> > > >+++ b/include/linux/compiler-gcc.h
> > > >@@ -201,7 +201,7 @@
> > > > #define annotate_unreachable() ({					\
> > > > 	asm("%c0:\t\n"							\
> > > > 	    ".pushsection __unreachable, \"a\"\t\n"			\
> > > >-	    ".long %c0b\t\n"						\
> > > >+	    ".quad %c0b\t\n"						\
> > > > 	    ".popsection\t\n" : : "i" (__LINE__));			\
> > > > })
> > > > #else
> > > 
> > > Or perhaps better use relative addresses, so:
> > > 
> > > .long foo - (.+4)
> > 
> > Hm, yeah, something like that would indeed be better as it only needs 4
> > bytes instead of 8.  For this use case, the following seems to work:
> > 
> >   ".long %c0b - .\t\n"
> > 
> > It produces the same relocation section+addend as before but with a
> > X86_64_PC32 relocation.
> > 
> > It looks like the above patch was already merged so I'll add that change
> > to the TODO list unless Ingo can squash it with the above patch.
> 
> I've squashed it - attached the latest version. Does this look good to everyone?
> 
> Thanks,
> 
> 	Ingo
> 
> ================>
> From a6ae17f553bf9b4a0c7f8534e5f0f983bc7955c7 Mon Sep 17 00:00:00 2001
> From: Josh Poimboeuf <jpoimboe@redhat.com>
> Date: Wed, 1 Mar 2017 00:05:04 -0600
> Subject: [PATCH] objtool, compiler.h: Fix __unreachable section relocation size
> 
> Linus reported the following commit broke module loading on his laptop:
> 
>   d1091c7fa3d5 ("objtool: Improve detection of BUG() and other dead ends")
> 
> It showed errors like the following:
> 
>   module: overflow in relocation type 10 val ffffffffc02afc81
>   module: 'nvme' likely not compiled with -mcmodel=kernel
> 
> The problem is that the __unreachable section addresses are stored using
> the '.long' asm directive, which isn't big enough for .text section
> relative kernel addresses.  Use relative addresses instead:

Maybe remove the first "relative" in the last line.  Otherwise it looks
good to me.  Thanks Ingo!

-- 
Josh

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

* [tip:core/urgent] objtool, compiler.h: Fix __unreachable section relocation size
  2017-03-01  6:05   ` Josh Poimboeuf
  2017-03-01  8:10     ` [tip:core/urgent] objtool: Fix __unreachable section relocation size tip-bot for Josh Poimboeuf
  2017-03-01 12:45     ` [tip:core/urgent] objtool, compiler.h: " tip-bot for Josh Poimboeuf
@ 2017-03-01 13:24     ` tip-bot for Josh Poimboeuf
  2 siblings, 0 replies; 12+ messages in thread
From: tip-bot for Josh Poimboeuf @ 2017-03-01 13:24 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tglx, mingo, peterz, hpa, linux-kernel, a.p.zijlstra, jpoimboe, torvalds

Commit-ID:  55149d06534ae2a7ba5f7a078353deb89b3fe891
Gitweb:     http://git.kernel.org/tip/55149d06534ae2a7ba5f7a078353deb89b3fe891
Author:     Josh Poimboeuf <jpoimboe@redhat.com>
AuthorDate: Wed, 1 Mar 2017 00:05:04 -0600
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 1 Mar 2017 14:20:18 +0100

objtool, compiler.h: Fix __unreachable section relocation size

Linus reported the following commit broke module loading on his laptop:

  d1091c7fa3d5 ("objtool: Improve detection of BUG() and other dead ends")

It showed errors like the following:

  module: overflow in relocation type 10 val ffffffffc02afc81
  module: 'nvme' likely not compiled with -mcmodel=kernel

The problem is that the __unreachable section addresses are stored using
the '.long' asm directive, which isn't big enough for .text section
kernel addresses.  Use relative addresses instead:

  ".long %c0b - .\t\n"

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Fixes: d1091c7fa3d5 ("objtool: Improve detection of BUG() and other dead ends")
Link: http://lkml.kernel.org/r/20170301060504.oltm3iws6fmubnom@treble
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 include/linux/compiler-gcc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index 76e28c2..b6bb901 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -201,7 +201,7 @@
 #define annotate_unreachable() ({					\
 	asm("%c0:\t\n"							\
 	    ".pushsection __unreachable, \"a\"\t\n"			\
-	    ".long %c0b\t\n"						\
+	    ".long %c0b - .\t\n"					\
 	    ".popsection\t\n" : : "i" (__LINE__));			\
 })
 #else

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

end of thread, other threads:[~2017-03-01 14:30 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-28  7:53 [GIT PULL] objtool fixes Ingo Molnar
2017-03-01  1:55 ` Linus Torvalds
2017-03-01  6:05   ` Josh Poimboeuf
2017-03-01  8:10     ` [tip:core/urgent] objtool: Fix __unreachable section relocation size tip-bot for Josh Poimboeuf
2017-03-01  8:15       ` hpa
2017-03-01 12:41         ` Josh Poimboeuf
2017-03-01 12:44           ` [PATCH] objtool, compiler.h: " Ingo Molnar
2017-03-01 12:56             ` Josh Poimboeuf
2017-03-01 10:37       ` [tip:core/urgent] objtool: " Ingo Molnar
2017-03-01 12:43         ` Josh Poimboeuf
2017-03-01 12:45     ` [tip:core/urgent] objtool, compiler.h: " tip-bot for Josh Poimboeuf
2017-03-01 13:24     ` tip-bot for Josh Poimboeuf

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).