Skip to contentSkip to conversation

kprobes updates for v5.8

GIT PULL Applied Ingo Molnar 5 participants 8 messages Jun 1, 2020 – Jul 24, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

Linus,

Please pull the latest core/kprobes git tree from:

git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git core-kprobes-2020-06-01

# HEAD: 66e9b0717102507e64f638790eaece88765cc9e5 kprobes: Prevent probes in .noinstr.text section

Various kprobes updates, mostly centered around cleaning up the no-instrumentation logic, instead of the current per debug facility blacklist, use the more generic .noinstr.text approach, combined with a 'noinstr' marker for functions.

Also add instrumentation_begin()/end() to better manage the exact place in entry code where instrumentation may be used.

Also add a kprobes blacklist for modules.

Thanks,

Ingo

------------------>
Masami Hiramatsu (4):
kprobes: Lock kprobe_mutex while showing kprobe_blacklist
kprobes: Support __kprobes blacklist in modules
kprobes: Support NOKPROBE_SYMBOL() in modules samples/kprobes: Add __kprobes and NOKPROBE_SYMBOL() for handlers.

Thomas Gleixner (2):
vmlinux.lds.h: Create section for protection against instrumentation
kprobes: Prevent probes in .noinstr.text section

 arch/powerpc/kernel/vmlinux.lds.S   |  1 +
 include/asm-generic/sections.h      |  3 ++
 include/asm-generic/vmlinux.lds.h   | 10 +++++
 include/linux/compiler.h            | 53 +++++++++++++++++++++++
 include/linux/compiler_types.h      |  4 ++
 include/linux/module.h              |  8 ++++
 kernel/kprobes.c                    | 85 ++++++++++++++++++++++++++++++++++++-
 kernel/module.c                     | 10 +++++
 samples/kprobes/kprobe_example.c    |  6 ++-
 samples/kprobes/kretprobe_example.c |  2 +
 scripts/mod/modpost.c               |  2 +-
 11 files changed, 180 insertions(+), 4 deletions(-)
#1 lore raw
Quoted 2 lines · Ingo Molnar
 include/linux/compiler.h            | 53 +++++++++++++++++++++++

I have pulled this, but do we really want to add this to a header file that is _so_ core that it gets included for basically every single file built?

I don't even see those instrumentation_begin/end() things used anywhere right now.

It seems excessive. That 53 lines is maybe not a lot, but it pushed that header file to over 12kB, and while it's mostly comments, it's extra IO and parsing basically for _every_ single file compiled in the kernel.

For what appears to be absolutely zero upside right now, and I really don't see why this should be in such a core header file!

I don't even see this as having anything at all to do with "compiler.h" in the first place.

I really think we should think twice about making core header files bigger like this. No, we're nowhere the disaster that C++ project headers are, but tokenization and parsing is actually a pretty big part of the build costs (which may surprise some people who think it's all the fancy optimizations that cost a lot of CPU time).

Linus

#2 lore raw

PATCH 1/1 compiler.h: Move instrumentation_begin()/end() into new <linux/instrumentation.h> header

Quoted 19 lines · Linus Torvalds
Quoted 2 lines · Ingo Molnar
 include/linux/compiler.h            | 53 +++++++++++++++++++++++

I have pulled this, but do we really want to add this to a header file that is _so_ core that it gets included for basically every single file built?

I don't even see those instrumentation_begin/end() things used anywhere right now.

It seems excessive. That 53 lines is maybe not a lot, but it pushed that header file to over 12kB, and while it's mostly comments, it's extra IO and parsing basically for _every_ single file compiled in the kernel.

For what appears to be absolutely zero upside right now, and I really don't see why this should be in such a core header file!

Quoted 8 lines

I don't even see this as having anything at all to do with "compiler.h" in the first place.

I really think we should think twice about making core header files bigger like this. No, we're nowhere the disaster that C++ project headers are, but tokenization and parsing is actually a pretty big part of the build costs (which may surprise some people who think it's all the fancy optimizations that cost a lot of CPU time).

Fully agreed - and I made the attached patch to address this.

The code got cleaner and better structured, but it didn't help much in terms of inclusion count:

2616 total .o files

   2447  <linux/types.h>
   2436  <linux/compiler.h>
   2404  <linux/bug.h>

The reason is that <linux/bug.h> is included almost everywhere as well, and the instrumentation_begin()/end() annotations affect the BUG*() and WARN*() primitives as well.

At least non-x86 would have less instrumentation related noise, for now at least.

Thanks,

Ingo

==========================>
From: Ingo Molnar <[email protected]>
Date: Thu, 4 Jun 2020 08:36:22 +0200
Subject: [PATCH] compiler.h: Move instrumentation_begin()/end() into new <linux/instrumentation.h> header

Linus pointed out that compiler.h - which is a key header that gets included in every single of the 28,000+ kernel files files being built - was unnecessarily bloated in:

655389666643: ("vmlinux.lds.h: Create section for protection against instrumentation")

Move these primitives into a new header: <linux/instrumentation.h>, and include that header in context_tracking.h and x86/asm/bug.h, which makes use of it.

---
 arch/x86/include/asm/bug.h       |  1 +
 include/linux/compiler.h         | 53 -------------------------------------
 include/linux/context_tracking.h |  2 ++
 include/linux/instrumentation.h  | 57 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 60 insertions(+), 53 deletions(-)
arch/x86/include/asm/bug.h +1 -0
index facba9bc30ca..37e4480dba75 100644
@@ -3,6 +3,7 @@
 #define _ASM_X86_BUG_H
 
 #include <linux/stringify.h>
+#include <linux/instrumentation.h>
 
 /*
  * Despite that some emulators terminate on UD2, we use it for WARN().
include/linux/compiler.h +0 -53

65 lines not on this page · raw message

include/linux/context_tracking.h +2 -0
index 8cac62ee6add..ad6241c8003d 100644
@@ -5,6 +5,8 @@
 #include <linux/sched.h>
 #include <linux/vtime.h>
 #include <linux/context_tracking_state.h>
+#include <linux/instrumentation.h>
+
 #include <asm/ptrace.h>
 
 
include/linux/instrumentation.h new file +57 -0

57 lines not on this page · raw message

#3 lore raw

Re: [PATCH] compiler.h: Move instrumentation_begin()/end() into new <linux/instrumentation.h> header

Quoted 46 lines · Ingo Molnar
Quoted 19 lines · Linus Torvalds
Quoted 2 lines · Ingo Molnar
 include/linux/compiler.h            | 53 +++++++++++++++++++++++

I have pulled this, but do we really want to add this to a header file that is _so_ core that it gets included for basically every single file built?

I don't even see those instrumentation_begin/end() things used anywhere right now.

It seems excessive. That 53 lines is maybe not a lot, but it pushed that header file to over 12kB, and while it's mostly comments, it's extra IO and parsing basically for _every_ single file compiled in the kernel.

For what appears to be absolutely zero upside right now, and I really don't see why this should be in such a core header file!

Quoted 8 lines

I don't even see this as having anything at all to do with "compiler.h" in the first place.

I really think we should think twice about making core header files bigger like this. No, we're nowhere the disaster that C++ project headers are, but tokenization and parsing is actually a pretty big part of the build costs (which may surprise some people who think it's all the fancy optimizations that cost a lot of CPU time).

Fully agreed - and I made the attached patch to address this.

The code got cleaner and better structured, but it didn't help much in terms of inclusion count:

   2616  total .o files

   2447  <linux/types.h>
   2436  <linux/compiler.h>
   2404  <linux/bug.h>

The reason is that <linux/bug.h> is included almost everywhere as well, and the instrumentation_begin()/end() annotations affect the BUG*() and WARN*() primitives as well.

Quoted 8 lines

At least non-x86 would have less instrumentation related noise, for now at least.

 arch/x86/include/asm/bug.h       |  1 +
 include/linux/compiler.h         | 53 -------------------------------------
 include/linux/context_tracking.h |  2 ++
 include/linux/instrumentation.h  | 57 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 60 insertions(+), 53 deletions(-)

The tested v2 version of the patch also needed the include in asm-generic/bug.h (see the fix attached below), because for completeness the generic version was annotated as well - even though only x86 has objtool support for now.

The readability improvement is real though.

Thanks,

Ingo

include/asm-generic/bug.h +1 -0
index 384b5c835ced..c43b5906e0dc 100644
@@ -3,6 +3,7 @@
 #define _ASM_GENERIC_BUG_H
 
 #include <linux/compiler.h>
+#include <linux/instrumentation.h>
 
 #define CUT_HERE		"------------[ cut here ]------------\n"
 
#4 lore raw

Re: [PATCH] compiler.h: Move instrumentation_begin()/end() into new <linux/instrumentation.h> header

Quoted 4 lines · Ingo Molnar

The tested v2 version of the patch also needed the include in asm-generic/bug.h (see the fix attached below), because for completeness the generic version was annotated as well - even though only x86 has objtool support for now.

x86/asm/bug.h includes asm-generic/bug.h.

x86 uses the generic bug infrastructure.

#5 lore raw

Re: [PATCH] compiler.h: Move instrumentation_begin()/end() into new <linux/instrumentation.h> header

Quoted 9 lines · Peter Zijlstra
Quoted 4 lines · Ingo Molnar

The tested v2 version of the patch also needed the include in asm-generic/bug.h (see the fix attached below), because for completeness the generic version was annotated as well - even though only x86 has objtool support for now.

x86/asm/bug.h includes asm-generic/bug.h.

x86 uses the generic bug infrastructure.

Yes, indeed. No change to the patch required (other than the changelog), both asm-generic/bug.h and x86/asm/bug.h make use of instrumentation_begin()/end(), so they both need the #include.

Thanks,

Ingo

merge bot Applied
#6 lore raw

[tip: core/headers] compiler.h: Move instrumentation_begin()/end() to new <linux/instrumentation.h> header

In reply to Ingo Molnar
The following commit has been merged into the core/headers branch of tip:

The following commit has been merged into the core/headers branch of tip:

Commit-ID:     d19e789f068b3d633cbac430764962f404198022
Gitweb:        https://git.kernel.org/tip/d19e789f068b3d633cbac430764962f404198022
Author:        Ingo Molnar <[email protected]>
AuthorDate:    Fri, 24 Jul 2020 13:50:25 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Fri, 24 Jul 2020 13:56:23 +02:00

compiler.h: Move instrumentation_begin()/end() to new <linux/instrumentation.h> header

Linus pointed out that compiler.h - which is a key header that gets included in every single one of the 28,000+ kernel files during a kernel build - was bloated in:

655389666643: ("vmlinux.lds.h: Create section for protection against instrumentation")

Linus noted:

Quoted 7 lines

I have pulled this, but do we really want to add this to a header file that is _so_ core that it gets included for basically every single file built?

I don't even see those instrumentation_begin/end() things used anywhere right now.

Quoted 7 lines

It seems excessive. That 53 lines is maybe not a lot, but it pushed that header file to over 12kB, and while it's mostly comments, it's extra IO and parsing basically for _every_ single file compiled in the kernel.

For what appears to be absolutely zero upside right now, and I really don't see why this should be in such a core header file!

Move these primitives into a new header: <linux/instrumentation.h>, and include that header in the headers that make use of it.

Unfortunately one of these headers is asm-generic/bug.h, which does get included in a lot of places, similarly to compiler.h. So the de-bloating effect isn't as good as we'd like it to be - but at least the interfaces are defined separately.

No change to functionality intended.

---
 arch/x86/include/asm/bug.h       |  1 +-
 include/asm-generic/bug.h        |  1 +-
 include/linux/compiler.h         | 53 +-----------------------------
 include/linux/context_tracking.h |  2 +-
 include/linux/instrumentation.h  | 57 +++++++++++++++++++++++++++++++-
 5 files changed, 61 insertions(+), 53 deletions(-)
 create mode 100644 include/linux/instrumentation.h
arch/x86/include/asm/bug.h +1 -0
index 0281895..297fa12 100644
@@ -3,6 +3,7 @@
 #define _ASM_X86_BUG_H
 
 #include <linux/stringify.h>
+#include <linux/instrumentation.h>
 
 /*
  * Despite that some emulators terminate on UD2, we use it for WARN().
include/asm-generic/bug.h +1 -0
index c94e33a..18b0f4e 100644
@@ -3,6 +3,7 @@
 #define _ASM_GENERIC_BUG_H
 
 #include <linux/compiler.h>
+#include <linux/instrumentation.h>
 
 #define CUT_HERE		"------------[ cut here ]------------\n"
 
include/linux/compiler.h +0 -53

65 lines not on this page · raw message

include/linux/context_tracking.h +2 -0
index 981b880..d53cd33 100644
@@ -5,6 +5,8 @@
 #include <linux/sched.h>
 #include <linux/vtime.h>
 #include <linux/context_tracking_state.h>
+#include <linux/instrumentation.h>
+
 #include <asm/ptrace.h>
 
 
include/linux/instrumentation.h new file +57 -0

57 lines not on this page · raw message

merge bot Merged
#7 lore raw
In reply to Ingo Molnar
The pull request you sent on Mon, 1 Jun 2020 15:08:06 +0200:

The pull request you sent on Mon, 1 Jun 2020 15:08:06 +0200:

Quoted 1 line

git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git core-kprobes-2020-06-01

has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/0bd957eb11cfeef23fcc240edde6dfe431731e69

Thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.wiki.kernel.org/userdoc/prtracker