Skip to content

x86/entry: Entry/exception code rework, preparatory patches

Thomas Gleixner lkml 1 version Applied

Status from this message: The following commit has been merged into the locking/kcsan branch of tip:

Get series with b4
b4 am [email protected]

Versions newest first

  1. v4 Latest36 patches 109 repliesApplied

Patches in v4 Applied

#Subject and filesSizeRepliesApplied
1/36rcu: Add comments marking transitions between RCU watching and notkernel/rcu/tree.c+25 -40 replies
2/36x86/hw_breakpoint: Prevent data breakpoints on cpu_entry_areaarch/x86/kernel/hw_breakpoint.c+25 -05 replies
3/36sched: Clean up scheduler_ipi()kernel/sched/core.c kernel/sched/fair.c kernel/sched/sched.h+36 -3910 replies
4/36sched: Make scheduler_ipi inlineinclude/linux/sched.h kernel/sched/core.c+9 -111 reply
5/36x86/entry: Flip _TIF_SIGPENDING and _TIF_NOTIFY_RESUME handlingarch/x86/entry/common.c+4 -415 replies
6/36compiler: Simple READ/WRITE_ONCE() implementationsinclude/linux/compiler.h+8 -04 replies
7/36locking/atomics: Flip fallbacks and instrumentationarch/arm64/include/asm/atomic.h arch/x86/include/asm/atomic.h arch/x86/include/asm/atomic64_32.h +25 more+2403 -823 replies
8/36x86/doublefault: Remove memmove() callarch/x86/kernel/traps.c+6 -11 reply
9/36x86/entry/64: Avoid pointless code when CONTEXT_TRACKING=narch/x86/entry/entry_64.S+2 -00 replies
10/36x86/entry: Remove the unused LOCKDEP_SYSEXIT cruftarch/x86/entry/thunk_64.S arch/x86/include/asm/irqflags.h+0 -291 reply
11/36x86/kvm: Handle async page faults directly through do_page_fault()arch/x86/entry/entry_32.S arch/x86/entry/entry_64.S arch/x86/include/asm/kvm_para.h +5 more+57 -372 replies
12/36x86/kvm: Sanitize kvm_async_pf_task_wait()arch/x86/include/asm/kvm_para.h arch/x86/kernel/kvm.c arch/x86/kvm/mmu/mmu.c+144 -635 replies
13/36x86/kvm: Restrict ASYNC_PF to user spacearch/x86/kernel/kvm.c+7 -932 replies
14/36x86/entry: Get rid of ist_begin/end_non_atomic()arch/x86/include/asm/traps.h arch/x86/kernel/cpu/mce/core.c arch/x86/kernel/traps.c+4 -416 replies
15/36kprobes: Lock kprobe_mutex while showing kprobe_blacklistkernel/kprobes.c+7 -11 reply
16/36kprobes: Support __kprobes blacklist in modulesinclude/linux/module.h kernel/kprobes.c kernel/module.c+50 -01 reply
17/36kprobes: Support NOKPROBE_SYMBOL() in modulesinclude/linux/module.h kernel/kprobes.c kernel/module.c+22 -01 reply
18/36samples/kprobes: Add __kprobes and NOKPROBE_SYMBOL() for handlers.samples/kprobes/kprobe_example.c samples/kprobes/kretprobe_example.c+6 -21 reply
19/36x86/entry: Exclude low level entry code from sanitizingarch/x86/entry/Makefile+8 -04 replies
20/36vmlinux.lds.h: Create section for protection against instrumentationinclude/asm-generic/sections.h include/asm-generic/vmlinux.lds.h include/linux/compiler.h +2 more+29 -13 replies
21/36kprobes: Prevent probes in .noinstr.text sectioninclude/linux/module.h kernel/kprobes.c kernel/module.c+23 -01 reply
22/36tracing: Provide lockdep less trace_hardirqs_on/off() variantsinclude/linux/irqflags.h kernel/trace/trace_preemptirq.c+41 -02 replies
23/36bug: Annotate WARN/BUG/stackfail as noinstr safearch/x86/include/asm/bug.h include/asm-generic/bug.h kernel/panic.c+13 -31 reply
24/36lockdep: Prepare for noinstr sectionsinclude/linux/irqflags.h include/linux/sched.h kernel/locking/lockdep.c +2 more+59 -182 replies
25/36rcu/tree: Mark the idle relevant functions noinstrkernel/rcu/tree.c kernel/rcu/tree_plugin.h kernel/rcu/update.c+52 -448 replies
26/36printk: Prepare for nested printk_nmi_enter()kernel/printk/internal.h kernel/printk/printk_safe.c+7 -50 replies
27/36arm64: Prepare arch_nmi_enter() for recursionarch/arm64/include/asm/hardirq.h+59 -196 replies
28/36hardirq/nmi: Allow nested nmi_enter()arch/arm64/kernel/sdei.c arch/arm64/kernel/traps.c arch/powerpc/kernel/traps.c +2 more+16 -370 replies
29/36x86/mce: Send #MC singal from task workarch/x86/kernel/cpu/mce/core.c include/linux/sched.h+37 -2512 replies
30/36lockdep: Always inline lockdep_{off,on}()include/linux/lockdep.h kernel/locking/lockdep.c+21 -211 reply
31/36printk: Disallow instrumenting print_nmi_enter()kernel/printk/printk_safe.c+3 -20 replies
32/36sh/ftrace: Move arch_ftrace_nmi_{enter,exit} into nmi exceptionDocumentation/trace/ftrace-design.rst arch/sh/Kconfig arch/sh/kernel/traps.c +2 more+12 -301 reply
33/36x86,tracing: Robustify ftrace_nmi_enter()arch/x86/include/asm/paravirt.h arch/x86/kernel/tsc.c include/linux/ftrace_irq.h +2 more+8 -71 reply
34/36sched,rcu,tracing: Avoid tracing before in_nmi() is correctinclude/linux/hardirq.h+11 -20 replies
35/36x86: Replace ist_enter() with nmi_enter()arch/x86/include/asm/traps.h arch/x86/kernel/cpu/mce/core.c arch/x86/kernel/cpu/mce/p5.c +2 more+24 -655 replies
36/36rcu: Make RCU IRQ enter/exit functions rely on in_nmi()kernel/rcu/tree.c+15 -322 replies

Reviews trailers per patch

26 of 36 patches have a Reviewed-by or Acked-by.

PatchAlexandre ChartreFrederic WeisbeckerAndy LutomirskiSteven Rostedt (VMware)Marc ZyngierWill DeaconMark RutlandPaul E. McKenneyPaolo BonziniBorislav PetkovMasami HiramatsuLai JiangshanJoel Fernandes (Google)Peter Zijlstra (Intel)
1/36
2/36R-b R-b R-b
3/36R-b
4/36R-b
5/36R-b
6/36R-b
7/36A-b
8/36R-b A-b
9/36R-b A-b A-b
10/36R-b
11/36R-b A-b
12/36R-b A-b
13/36R-b A-b
14/36R-b
15/36R-b
16/36R-b
17/36R-b
18/36R-b
19/36R-b
20/36
21/36A-b
22/36
23/36
24/36
25/36A-b R-b A-b
26/36
27/36
28/36A-b A-b
29/36R-b R-b
30/36
31/36
32/36A-b
33/36A-b R-b
34/36R-b
35/36
36/36R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 14 reviewers.

Read the v4 thread

Cover letter [patch V4 part 1 00/36] x86/entry: Entry/exception code rework, preparatory patches

Folks!

This is the hopefully final version of the rework of the entry and exception code to ensure that instrumentation cannot touch the fragile parts of the hardware induced entry and exception code trainwreck. It further ensures correctness vs. RCU and moves quite some code out of the assembly code into C.

V3 can befound here:

https://lore.kernel.org/r/[email protected]

The protection against instrumentation is based on moving the fragile code parts into a special text section: .noinstr.text which is excluded from any form of instrumentation

The correctness is validated via objtool extensions. The necessary updates to objtool are available here:

git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git objtool/core

The series has a total of 138 patches and is split into 5 parts. It's based on v5.7-rc3 with the objtool/core and the locking/kcsan branches of the tip tree merged on top. The base tree is available here:

git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git entry-base

The full series with all parts applied is available here:

git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git entry-v4-part-5

The first part, i.e. this series is available from:

git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git entry-v4-part-1

This part contains preparatory patches and fixes of various sorts which have been either developed in course of this project or have been collected from previous versions and related discussions about the whole entry vs. RCU vs. instrumentation correctness problem.

- Prevention of breakpoints in the entry code
- Splitting the scheduler IPI
- Correct ordering of user space exit work
- Cleanup and restriction of the async page fault handling
- Kprobes support for noinstr sections in built-in and modules code
- The introduction of noinstr.text section
- Preparatory work in tracing, lockdep and RCU
- The nmi_enter() consolidation
- Atomic fallback interaction

The largest patch of this series is the atomic fallback rework which is necessary to address the interaction with KCSAN and pending work from Will Deacon in that area. The header file is autogenerated, but actually included in tree because regenerating on every build is too expensive.

The objtool check for the noinstr.text correctness is not yet added to the build machinery and has to be invoked manually for now:

objtool check -fal vmlinux.o

The checking only works for builtin code as objtool cannot do a combined analysis of vmlinux.o and a module.o

Thanks,

tglx

8<----------

 Documentation/trace/ftrace-design.rst        |    8 
 arch/arm64/include/asm/atomic.h              |    6 
 arch/arm64/include/asm/hardirq.h             |   78 
 arch/arm64/kernel/sdei.c                     |   14 
 arch/arm64/kernel/traps.c                    |    8 
 arch/powerpc/kernel/traps.c                  |   22 
 arch/sh/Kconfig                              |    1 
 arch/sh/kernel/traps.c                       |   12 
 arch/x86/entry/Makefile                      |    8 
 arch/x86/entry/common.c                      |    8 
 arch/x86/entry/entry_32.S                    |    8 
 arch/x86/entry/entry_64.S                    |    6 
 arch/x86/entry/thunk_64.S                    |    5 
 arch/x86/include/asm/atomic.h                |   17 
 arch/x86/include/asm/atomic64_32.h           |    9 
 arch/x86/include/asm/atomic64_64.h           |   15 
 arch/x86/include/asm/bug.h                   |    3 
 arch/x86/include/asm/irqflags.h              |   24 
 arch/x86/include/asm/kvm_para.h              |   23 
 arch/x86/include/asm/paravirt.h              |    2 
 arch/x86/include/asm/traps.h                 |    5 
 arch/x86/include/asm/x86_init.h              |    2 
 arch/x86/kernel/cpu/mce/core.c               |   65 
 arch/x86/kernel/cpu/mce/p5.c                 |    5 
 arch/x86/kernel/cpu/mce/winchip.c            |    5 
 arch/x86/kernel/hw_breakpoint.c              |   25 
 arch/x86/kernel/kvm.c                        |  158 -
 arch/x86/kernel/traps.c                      |  117 -
 arch/x86/kernel/tsc.c                        |    4 
 arch/x86/kernel/x86_init.c                   |    1 
 arch/x86/kvm/mmu/mmu.c                       |    2 
 arch/x86/mm/fault.c                          |   19 
 include/asm-generic/bug.h                    |    9 
 include/asm-generic/sections.h               |    3 
 include/asm-generic/vmlinux.lds.h            |    4 
 include/linux/atomic-arch-fallback.h         | 2291 +++++++++++++++++++++++++++
 include/linux/atomic-fallback.h              |    8 
 include/linux/atomic.h                       |   11 
 include/linux/compiler.h                     |   25 
 include/linux/compiler_types.h               |    4 
 include/linux/ftrace_irq.h                   |   15 
 include/linux/hardirq.h                      |   18 
 include/linux/irqflags.h                     |    6 
 include/linux/lockdep.h                      |   23 
 include/linux/module.h                       |    8 
 include/linux/preempt.h                      |    4 
 include/linux/sched.h                        |   17 
 kernel/kprobes.c                             |   85 -
 kernel/locking/lockdep.c                     |   89 -
 kernel/module.c                              |   10 
 kernel/panic.c                               |    4 
 kernel/printk/internal.h                     |    8 
 kernel/printk/printk_safe.c                  |    9 
 kernel/rcu/tree.c                            |  139 -
 kernel/rcu/tree_plugin.h                     |    4 
 kernel/rcu/update.c                          |    7 
 kernel/sched/core.c                          |   66 
 kernel/sched/fair.c                          |    5 
 kernel/sched/sched.h                         |    6 
 kernel/trace/Kconfig                         |   10 
 kernel/trace/trace_clock.c                   |    3 
 kernel/trace/trace_hwlat.c                   |    2 
 kernel/trace/trace_preemptirq.c              |   39 
 lib/debug_locks.c                            |    2 
 samples/kprobes/kprobe_example.c             |    6 
 samples/kprobes/kretprobe_example.c          |    2 
 scripts/atomic/fallbacks/acquire             |    4 
 scripts/atomic/fallbacks/add_negative        |    6 
 scripts/atomic/fallbacks/add_unless          |    6 
 scripts/atomic/fallbacks/andnot              |    4 
 scripts/atomic/fallbacks/dec                 |    4 
 scripts/atomic/fallbacks/dec_and_test        |    6 
 scripts/atomic/fallbacks/dec_if_positive     |    6 
 scripts/atomic/fallbacks/dec_unless_positive |    6 
 scripts/atomic/fallbacks/fence               |    4 
 scripts/atomic/fallbacks/fetch_add_unless    |    8 
 scripts/atomic/fallbacks/inc                 |    4 
 scripts/atomic/fallbacks/inc_and_test        |    6 
 scripts/atomic/fallbacks/inc_not_zero        |    6 
 scripts/atomic/fallbacks/inc_unless_negative |    6 
 scripts/atomic/fallbacks/read_acquire        |    2 
 scripts/atomic/fallbacks/release             |    4 
 scripts/atomic/fallbacks/set_release         |    2 
 scripts/atomic/fallbacks/sub_and_test        |    6 
 scripts/atomic/fallbacks/try_cmpxchg         |    4 
 scripts/atomic/gen-atomic-fallback.sh        |   29 
 scripts/atomic/gen-atomics.sh                |    5 
 scripts/mod/modpost.c                        |    2 
 88 files changed, 3146 insertions(+), 611 deletions(-)