1. 07 12月, 2021 2 次提交
    • E
      net: add net device refcount tracker infrastructure · 4d92b95f
      Eric Dumazet 提交于
      net device are refcounted. Over the years we had numerous bugs
      caused by imbalanced dev_hold() and dev_put() calls.
      
      The general idea is to be able to precisely pair each decrement with
      a corresponding prior increment. Both share a cookie, basically
      a pointer to private data storing stack traces.
      
      This patch adds dev_hold_track() and dev_put_track().
      
      To use these helpers, each data structure owning a refcount
      should also use a "netdevice_tracker" to pair the hold and put.
      
      netdevice_tracker dev_tracker;
      ...
      dev_hold_track(dev, &dev_tracker, GFP_ATOMIC);
      ...
      dev_put_track(dev, &dev_tracker);
      
      Whenever a leak happens, we will get precise stack traces
      of the point dev_hold_track() happened, at device dismantle phase.
      
      We will also get a stack trace if too many dev_put_track() for the same
      netdevice_tracker are attempted.
      
      This is guarded by CONFIG_NET_DEV_REFCNT_TRACKER option.
      Signed-off-by: NEric Dumazet <edumazet@google.com>
      Signed-off-by: NJakub Kicinski <kuba@kernel.org>
      4d92b95f
    • E
      lib: add tests for reference tracker · 914a7b50
      Eric Dumazet 提交于
      This module uses reference tracker, forcing two issues.
      
      1) Double free of a tracker
      
      2) leak of two trackers, one being allocated from softirq context.
      
      "modprobe test_ref_tracker" would emit the following traces.
      (Use scripts/decode_stacktrace.sh if necessary)
      
      [  171.648681] reference already released.
      [  171.653213] allocated in:
      [  171.656523]  alloctest_ref_tracker_alloc2+0x1c/0x20 [test_ref_tracker]
      [  171.656526]  init_module+0x86/0x1000 [test_ref_tracker]
      [  171.656528]  do_one_initcall+0x9c/0x220
      [  171.656532]  do_init_module+0x60/0x240
      [  171.656536]  load_module+0x32b5/0x3610
      [  171.656538]  __do_sys_init_module+0x148/0x1a0
      [  171.656540]  __x64_sys_init_module+0x1d/0x20
      [  171.656542]  do_syscall_64+0x4a/0xb0
      [  171.656546]  entry_SYSCALL_64_after_hwframe+0x44/0xae
      [  171.656549] freed in:
      [  171.659520]  alloctest_ref_tracker_free+0x13/0x20 [test_ref_tracker]
      [  171.659522]  init_module+0xec/0x1000 [test_ref_tracker]
      [  171.659523]  do_one_initcall+0x9c/0x220
      [  171.659525]  do_init_module+0x60/0x240
      [  171.659527]  load_module+0x32b5/0x3610
      [  171.659529]  __do_sys_init_module+0x148/0x1a0
      [  171.659532]  __x64_sys_init_module+0x1d/0x20
      [  171.659534]  do_syscall_64+0x4a/0xb0
      [  171.659536]  entry_SYSCALL_64_after_hwframe+0x44/0xae
      [  171.659575] ------------[ cut here ]------------
      [  171.659576] WARNING: CPU: 5 PID: 13016 at lib/ref_tracker.c:112 ref_tracker_free+0x224/0x270
      [  171.659581] Modules linked in: test_ref_tracker(+)
      [  171.659591] CPU: 5 PID: 13016 Comm: modprobe Tainted: G S                5.16.0-smp-DEV #290
      [  171.659595] RIP: 0010:ref_tracker_free+0x224/0x270
      [  171.659599] Code: 5e 41 5f 5d c3 48 c7 c7 04 9c 74 a6 31 c0 e8 62 ee 67 00 83 7b 14 00 75 1a 83 7b 18 00 75 30 4c 89 ff 4c 89 f6 e8 9c 00 69 00 <0f> 0b bb ea ff ff ff eb ae 48 c7 c7 3a 0a 77 a6 31 c0 e8 34 ee 67
      [  171.659601] RSP: 0018:ffff89058ba0bbd0 EFLAGS: 00010286
      [  171.659603] RAX: 0000000000000029 RBX: ffff890586b19780 RCX: 08895bff57c7d100
      [  171.659604] RDX: c0000000ffff7fff RSI: 0000000000000282 RDI: ffffffffc0407000
      [  171.659606] RBP: ffff89058ba0bc88 R08: 0000000000000000 R09: ffffffffa6f342e0
      [  171.659607] R10: 00000000ffff7fff R11: 0000000000000000 R12: 000000008f000000
      [  171.659608] R13: 0000000000000014 R14: 0000000000000282 R15: ffffffffc0407000
      [  171.659609] FS:  00007f97ea29d740(0000) GS:ffff8923ff940000(0000) knlGS:0000000000000000
      [  171.659611] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      [  171.659613] CR2: 00007f97ea299000 CR3: 0000000186b4a004 CR4: 00000000001706e0
      [  171.659614] Call Trace:
      [  171.659615]  <TASK>
      [  171.659631]  ? alloctest_ref_tracker_free+0x13/0x20 [test_ref_tracker]
      [  171.659633]  ? init_module+0x105/0x1000 [test_ref_tracker]
      [  171.659636]  ? do_one_initcall+0x9c/0x220
      [  171.659638]  ? do_init_module+0x60/0x240
      [  171.659641]  ? load_module+0x32b5/0x3610
      [  171.659644]  ? __do_sys_init_module+0x148/0x1a0
      [  171.659646]  ? __x64_sys_init_module+0x1d/0x20
      [  171.659649]  ? do_syscall_64+0x4a/0xb0
      [  171.659652]  ? entry_SYSCALL_64_after_hwframe+0x44/0xae
      [  171.659656]  ? 0xffffffffc040a000
      [  171.659658]  alloctest_ref_tracker_free+0x13/0x20 [test_ref_tracker]
      [  171.659660]  init_module+0x105/0x1000 [test_ref_tracker]
      [  171.659663]  do_one_initcall+0x9c/0x220
      [  171.659666]  do_init_module+0x60/0x240
      [  171.659669]  load_module+0x32b5/0x3610
      [  171.659672]  __do_sys_init_module+0x148/0x1a0
      [  171.659676]  __x64_sys_init_module+0x1d/0x20
      [  171.659678]  do_syscall_64+0x4a/0xb0
      [  171.659694]  ? exc_page_fault+0x6e/0x140
      [  171.659696]  entry_SYSCALL_64_after_hwframe+0x44/0xae
      [  171.659698] RIP: 0033:0x7f97ea3dbe7a
      [  171.659700] Code: 48 8b 0d 61 8d 06 00 f7 d8 64 89 01 48 83 c8 ff c3 cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc 49 89 ca b8 af 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 2e 8d 06 00 f7 d8 64 89 01 48
      [  171.659701] RSP: 002b:00007ffea67ce608 EFLAGS: 00000246 ORIG_RAX: 00000000000000af
      [  171.659703] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f97ea3dbe7a
      [  171.659704] RDX: 00000000013a0ba0 RSI: 0000000000002808 RDI: 00007f97ea299000
      [  171.659705] RBP: 00007ffea67ce670 R08: 0000000000000003 R09: 0000000000000000
      [  171.659706] R10: 0000000000000000 R11: 0000000000000246 R12: 00000000013a1048
      [  171.659707] R13: 00000000013a0ba0 R14: 0000000001399930 R15: 00000000013a1030
      [  171.659709]  </TASK>
      [  171.659710] ---[ end trace f5dbd6afa41e60a9 ]---
      [  171.659712] leaked reference.
      [  171.663393]  alloctest_ref_tracker_alloc0+0x1c/0x20 [test_ref_tracker]
      [  171.663395]  test_ref_tracker_timer_func+0x9/0x20 [test_ref_tracker]
      [  171.663397]  call_timer_fn+0x31/0x140
      [  171.663401]  expire_timers+0x46/0x110
      [  171.663403]  __run_timers+0x16f/0x1b0
      [  171.663404]  run_timer_softirq+0x1d/0x40
      [  171.663406]  __do_softirq+0x148/0x2d3
      [  171.663408] leaked reference.
      [  171.667101]  alloctest_ref_tracker_alloc1+0x1c/0x20 [test_ref_tracker]
      [  171.667103]  init_module+0x81/0x1000 [test_ref_tracker]
      [  171.667104]  do_one_initcall+0x9c/0x220
      [  171.667106]  do_init_module+0x60/0x240
      [  171.667108]  load_module+0x32b5/0x3610
      [  171.667111]  __do_sys_init_module+0x148/0x1a0
      [  171.667113]  __x64_sys_init_module+0x1d/0x20
      [  171.667115]  do_syscall_64+0x4a/0xb0
      [  171.667117]  entry_SYSCALL_64_after_hwframe+0x44/0xae
      [  171.667131] ------------[ cut here ]------------
      [  171.667132] WARNING: CPU: 5 PID: 13016 at lib/ref_tracker.c:30 ref_tracker_dir_exit+0x104/0x130
      [  171.667136] Modules linked in: test_ref_tracker(+)
      [  171.667144] CPU: 5 PID: 13016 Comm: modprobe Tainted: G S      W         5.16.0-smp-DEV #290
      [  171.667147] RIP: 0010:ref_tracker_dir_exit+0x104/0x130
      [  171.667150] Code: 01 00 00 00 00 ad de 48 89 03 4c 89 63 08 48 89 df e8 20 a0 d5 ff 4c 89 f3 4d 39 ee 75 a8 4c 89 ff 48 8b 75 d0 e8 7c 05 69 00 <0f> 0b eb 0c 4c 89 ff 48 8b 75 d0 e8 6c 05 69 00 41 8b 47 08 83 f8
      [  171.667151] RSP: 0018:ffff89058ba0bc68 EFLAGS: 00010286
      [  171.667154] RAX: 08895bff57c7d100 RBX: ffffffffc0407010 RCX: 000000000000003b
      [  171.667156] RDX: 000000000000003c RSI: 0000000000000282 RDI: ffffffffc0407000
      [  171.667157] RBP: ffff89058ba0bc98 R08: 0000000000000000 R09: ffffffffa6f342e0
      [  171.667159] R10: 00000000ffff7fff R11: 0000000000000000 R12: dead000000000122
      [  171.667160] R13: ffffffffc0407010 R14: ffffffffc0407010 R15: ffffffffc0407000
      [  171.667162] FS:  00007f97ea29d740(0000) GS:ffff8923ff940000(0000) knlGS:0000000000000000
      [  171.667164] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      [  171.667166] CR2: 00007f97ea299000 CR3: 0000000186b4a004 CR4: 00000000001706e0
      [  171.667169] Call Trace:
      [  171.667170]  <TASK>
      [  171.667171]  ? 0xffffffffc040a000
      [  171.667173]  init_module+0x126/0x1000 [test_ref_tracker]
      [  171.667175]  do_one_initcall+0x9c/0x220
      [  171.667179]  do_init_module+0x60/0x240
      [  171.667182]  load_module+0x32b5/0x3610
      [  171.667186]  __do_sys_init_module+0x148/0x1a0
      [  171.667189]  __x64_sys_init_module+0x1d/0x20
      [  171.667192]  do_syscall_64+0x4a/0xb0
      [  171.667194]  ? exc_page_fault+0x6e/0x140
      [  171.667196]  entry_SYSCALL_64_after_hwframe+0x44/0xae
      [  171.667199] RIP: 0033:0x7f97ea3dbe7a
      [  171.667200] Code: 48 8b 0d 61 8d 06 00 f7 d8 64 89 01 48 83 c8 ff c3 cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc 49 89 ca b8 af 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 2e 8d 06 00 f7 d8 64 89 01 48
      [  171.667201] RSP: 002b:00007ffea67ce608 EFLAGS: 00000246 ORIG_RAX: 00000000000000af
      [  171.667203] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f97ea3dbe7a
      [  171.667204] RDX: 00000000013a0ba0 RSI: 0000000000002808 RDI: 00007f97ea299000
      [  171.667205] RBP: 00007ffea67ce670 R08: 0000000000000003 R09: 0000000000000000
      [  171.667206] R10: 0000000000000000 R11: 0000000000000246 R12: 00000000013a1048
      [  171.667207] R13: 00000000013a0ba0 R14: 0000000001399930 R15: 00000000013a1030
      [  171.667209]  </TASK>
      [  171.667210] ---[ end trace f5dbd6afa41e60aa ]---
      Signed-off-by: NEric Dumazet <edumazet@google.com>
      Signed-off-by: NJakub Kicinski <kuba@kernel.org>
      914a7b50
  2. 22 11月, 2021 1 次提交
  3. 07 11月, 2021 1 次提交
  4. 22 10月, 2021 1 次提交
  5. 19 10月, 2021 1 次提交
  6. 25 9月, 2021 1 次提交
  7. 17 9月, 2021 1 次提交
    • P
      objtool: Support pv_opsindirect calls for noinstr · db2b0c5d
      Peter Zijlstra 提交于
      Normally objtool will now follow indirect calls; there is no need.
      
      However, this becomes a problem with noinstr validation; if there's an
      indirect call from noinstr code, we very much need to know it is to
      another noinstr function. Luckily there aren't many indirect calls in
      entry code with the obvious exception of paravirt. As such, noinstr
      validation didn't work with paravirt kernels.
      
      In order to track pv_ops[] call targets, objtool reads the static
      pv_ops[] tables as well as direct assignments to the pv_ops[] array,
      provided the compiler makes them a single instruction like:
      
        bf87:       48 c7 05 00 00 00 00 00 00 00 00        movq   $0x0,0x0(%rip)
          bf92 <xen_init_spinlocks+0x5f>
          bf8a: R_X86_64_PC32     pv_ops+0x268
      
      There are, as of yet, no warnings for when this goes wrong :/
      
      Using the functions found with the above means, all pv_ops[] calls are
      now subject to noinstr validation.
      Signed-off-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
      Link: https://lore.kernel.org/r/20210624095149.118815755@infradead.org
      db2b0c5d
  8. 14 9月, 2021 1 次提交
  9. 09 9月, 2021 3 次提交
  10. 03 9月, 2021 1 次提交
    • N
      Makefile: remove stale cc-option checks · 7d73c3e9
      Nick Desaulniers 提交于
      cc-option, cc-option-yn, and cc-disable-warning all invoke the compiler
      during build time, and can slow down the build when these checks become
      stale for our supported compilers, whose minimally supported versions
      increases over time. See Documentation/process/changes.rst for the
      current supported minimal versions (GCC 4.9+, clang 10.0.1+). Compiler
      version support for these flags may be verified on godbolt.org.
      
      The following flags are GCC only and supported since at least GCC 4.9.
      Remove cc-option and cc-disable-warning tests.
      * -fno-tree-loop-im
      * -Wno-maybe-uninitialized
      * -fno-reorder-blocks
      * -fno-ipa-cp-clone
      * -fno-partial-inlining
      * -femit-struct-debug-baseonly
      * -fno-inline-functions-called-once
      * -fconserve-stack
      
      The following flags are supported by all supported versions of GCC and
      Clang. Remove their cc-option, cc-option-yn, and cc-disable-warning tests.
      * -fno-delete-null-pointer-checks
      * -fno-var-tracking
      * -Wno-array-bounds
      
      The following configs are made dependent on GCC, since they use GCC
      specific flags.
      * READABLE_ASM
      * DEBUG_SECTION_MISMATCH
      
      -mfentry was not supported by s390-linux-gnu-gcc until gcc-9+, add a
      comment.
      
      --param=allow-store-data-races=0 was renamed to -fno-allow-store-data-races
      in the GCC 10 release; add a comment.
      
      -Wmaybe-uninitialized (GCC specific) was being added for CONFIG_GCOV,
      then again unconditionally; add it only once.
      
      Also, base RETPOLINE_CFLAGS and RETPOLINE_VDSO_CFLAGS on CONFIC_CC_IS_*
      then remove cc-option tests for Clang.
      
      Link: https://github.com/ClangBuiltLinux/linux/issues/1436Acked-by: NMiguel Ojeda <ojeda@kernel.org>
      Reviewed-by: NNathan Chancellor <nathan@kernel.org>
      Signed-off-by: NNick Desaulniers <ndesaulniers@google.com>
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      7d73c3e9
  11. 30 8月, 2021 1 次提交
  12. 24 8月, 2021 1 次提交
  13. 21 8月, 2021 1 次提交
  14. 18 8月, 2021 1 次提交
  15. 31 7月, 2021 1 次提交
  16. 11 7月, 2021 1 次提交
  17. 09 7月, 2021 2 次提交
    • S
      dump_stack: add vmlinux build ID to stack traces · 22f4e66d
      Stephen Boyd 提交于
      Add the running kernel's build ID[1] to the stacktrace information header.
      This makes it simpler for developers to locate the vmlinux with full
      debuginfo for a particular kernel stacktrace.  Combined with
      scripts/decode_stracktrace.sh, a developer can download the correct
      vmlinux from a debuginfod[2] server and find the exact file and line
      number for the functions plus offsets in a stacktrace.
      
      This is especially useful for pstore crash debugging where the kernel
      crashes are recorded in the pstore logs and the recovery kernel is
      different or the debuginfo doesn't exist on the device due to space
      concerns (the data can be large and a security concern).  The stacktrace
      can be analyzed after the crash by using the build ID to find the matching
      vmlinux and understand where in the function something went wrong.
      
      Example stacktrace from lkdtm:
      
       WARNING: CPU: 4 PID: 3255 at drivers/misc/lkdtm/bugs.c:83 lkdtm_WARNING+0x28/0x30 [lkdtm]
       Modules linked in: lkdtm rfcomm algif_hash algif_skcipher af_alg xt_cgroup uinput xt_MASQUERADE
       CPU: 4 PID: 3255 Comm: bash Not tainted 5.11 #3 aa23f7a1231c229de205662d5a9e0d4c580f19a1
       Hardware name: Google Lazor (rev3+) with KB Backlight (DT)
       pstate: 00400009 (nzcv daif +PAN -UAO -TCO BTYPE=--)
       pc : lkdtm_WARNING+0x28/0x30 [lkdtm]
      
      The hex string aa23f7a1231c229de205662d5a9e0d4c580f19a1 is the build ID,
      following the kernel version number. Put it all behind a config option,
      STACKTRACE_BUILD_ID, so that kernel developers can remove this
      information if they decide it is too much.
      
      Link: https://lkml.kernel.org/r/20210511003845.2429846-5-swboyd@chromium.org
      Link: https://fedoraproject.org/wiki/Releases/FeatureBuildId [1]
      Link: https://sourceware.org/elfutils/Debuginfod.html [2]
      Signed-off-by: NStephen Boyd <swboyd@chromium.org>
      Cc: Jiri Olsa <jolsa@kernel.org>
      Cc: Alexei Starovoitov <ast@kernel.org>
      Cc: Jessica Yu <jeyu@kernel.org>
      Cc: Evan Green <evgreen@chromium.org>
      Cc: Hsin-Yi Wang <hsinyi@chromium.org>
      Cc: Petr Mladek <pmladek@suse.com>
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
      Cc: Matthew Wilcox <willy@infradead.org>
      Cc: Baoquan He <bhe@redhat.com>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Dave Young <dyoung@redhat.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
      Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
      Cc: Sasha Levin <sashal@kernel.org>
      Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Vivek Goyal <vgoyal@redhat.com>
      Cc: Will Deacon <will@kernel.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      22f4e66d
    • Z
      lib: fix spelling mistakes · 9dbbc3b9
      Zhen Lei 提交于
      Fix some spelling mistakes in comments:
      permanentely ==> permanently
      wont ==> won't
      remaning ==> remaining
      succed ==> succeed
      shouldnt ==> shouldn't
      alpha-numeric ==> alphanumeric
      storeing ==> storing
      funtion ==> function
      documenation ==> documentation
      Determin ==> Determine
      intepreted ==> interpreted
      ammount ==> amount
      obious ==> obvious
      interupts ==> interrupts
      occured ==> occurred
      asssociated ==> associated
      taking into acount ==> taking into account
      squence ==> sequence
      stil ==> still
      contiguos ==> contiguous
      matchs ==> matches
      
      Link: https://lkml.kernel.org/r/20210607072555.12416-1-thunder.leizhen@huawei.comSigned-off-by: NZhen Lei <thunder.leizhen@huawei.com>
      Reviewed-by: NJacob Keller <jacob.e.keller@intel.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      9dbbc3b9
  18. 02 7月, 2021 1 次提交
  19. 30 6月, 2021 2 次提交
  20. 26 6月, 2021 1 次提交
    • D
      lib/test: convert lib/test_list_sort.c to use KUnit · ebd09577
      Daniel Latypov 提交于
      Functionally, this just means that the test output will be slightly
      changed and it'll now depend on CONFIG_KUNIT=y/m.
      
      It'll still run at boot time and can still be built as a loadable
      module.
      
      There was a pre-existing patch to convert this test that I found later,
      here [1]. Compared to [1], this patch doesn't rename files and uses
      KUnit features more heavily (i.e. does more than converting pr_err()
      calls to KUNIT_FAIL()).
      
      What this conversion gives us:
      * a shorter test thanks to KUnit's macros
      * a way to run this a bit more easily via kunit.py (and
      CONFIG_KUNIT_ALL_TESTS=y) [2]
      * a structured way of reporting pass/fail
      * uses kunit-managed allocations to avoid the risk of memory leaks
      * more descriptive error messages:
        * i.e. it prints out which fields are invalid, what the expected
        values are, etc.
      
      What this conversion does not do:
      * change the name of the file (and thus the name of the module)
      * change the name of the config option
      
      Leaving these as-is for now to minimize the impact to people wanting to
      run this test. IMO, that concern trumps following KUnit's style guide
      for both names, at least for now.
      
      [1] https://lore.kernel.org/linux-kselftest/20201015014616.309000-1-vitor@massaru.org/
      [2] Can be run via
      $ ./tools/testing/kunit/kunit.py run --kunitconfig /dev/stdin <<EOF
      CONFIG_KUNIT=y
      CONFIG_TEST_LIST_SORT=y
      EOF
      
      [16:55:56] Configuring KUnit Kernel ...
      [16:55:56] Building KUnit Kernel ...
      [16:56:29] Starting KUnit Kernel ...
      [16:56:32] ============================================================
      [16:56:32] ======== [PASSED] list_sort ========
      [16:56:32] [PASSED] list_sort_test
      [16:56:32] ============================================================
      [16:56:32] Testing complete. 1 tests run. 0 failed. 0 crashed.
      [16:56:32] Elapsed time: 35.668s total, 0.001s configuring, 32.725s building, 0.000s running
      
      Note: the build time is as after a `make mrproper`.
      Signed-off-by: NDaniel Latypov <dlatypov@google.com>
      Tested-by: NDavid Gow <davidgow@google.com>
      Acked-by: NBrendan Higgins <brendanhiggins@google.com>
      Signed-off-by: NShuah Khan <skhan@linuxfoundation.org>
      ebd09577
  21. 22 6月, 2021 1 次提交
    • P
      clocksource: Provide kernel module to test clocksource watchdog · 1253b9b8
      Paul E. McKenney 提交于
      When the clocksource watchdog marks a clock as unstable, this might
      be due to that clock being unstable or it might be due to delays that
      happen to occur between the reads of the two clocks.  It would be good
      to have a way of testing the clocksource watchdog's ability to
      distinguish between these two causes of clock skew and instability.
      
      Therefore, provide a new clocksource-wdtest module selected by a new
      TEST_CLOCKSOURCE_WATCHDOG Kconfig option.  This module has a single module
      parameter named "holdoff" that provides the number of seconds of delay
      before testing should start, which defaults to zero when built as a module
      and to 10 seconds when built directly into the kernel.  Very large systems
      that boot slowly may need to increase the value of this module parameter.
      
      This module uses hand-crafted clocksource structures to do its testing,
      thus avoiding messing up timing for the rest of the kernel and for user
      applications.  This module first verifies that the ->uncertainty_margin
      field of the clocksource structures are set sanely.  It then tests the
      delay-detection capability of the clocksource watchdog, increasing the
      number of consecutive delays injected, first provoking console messages
      complaining about the delays and finally forcing a clock-skew event.
      Unexpected test results cause at least one WARN_ON_ONCE() console splat.
      If there are no splats, the test has passed.  Finally, it fuzzes the
      value returned from a clocksource to test the clocksource watchdog's
      ability to detect time skew.
      
      This module checks the state of its clocksource after each test, and
      uses WARN_ON_ONCE() to emit a console splat if there are any failures.
      This should enable all types of test frameworks to detect any such
      failures.
      
      This facility is intended for diagnostic use only, and should be avoided
      on production systems.
      Reported-by: NChris Mason <clm@fb.com>
      Suggested-by: NThomas Gleixner <tglx@linutronix.de>
      Signed-off-by: NPaul E. McKenney <paulmck@kernel.org>
      Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
      Tested-by: NFeng Tang <feng.tang@intel.com>
      Link: https://lore.kernel.org/r/20210527190124.440372-5-paulmck@kernel.org
      1253b9b8
  22. 31 5月, 2021 1 次提交
    • R
      locking/lockdep: Reduce LOCKDEP dependency list · b8e00abe
      Randy Dunlap 提交于
      Some arches (um, sparc64, riscv, xtensa) cause a Kconfig warning for
      LOCKDEP.
      These arch-es select LOCKDEP_SUPPORT but they are not listed as one
      of the arch-es that LOCKDEP depends on.
      
      Since (16) arch-es define the Kconfig symbol LOCKDEP_SUPPORT if they
      intend to have LOCKDEP support, replace the awkward list of
      arch-es that LOCKDEP depends on with the LOCKDEP_SUPPORT symbol.
      
      But wait. LOCKDEP_SUPPORT is included in LOCK_DEBUGGING_SUPPORT,
      which is already a dependency here, so LOCKDEP_SUPPORT is redundant
      and not needed.
      That leaves the FRAME_POINTER dependency, but it is part of an
      expression like this:
      	depends on (A && B) && (FRAME_POINTER || B')
      where B' is a dependency of B so if B is true then B' is true
      and the value of FRAME_POINTER does not matter.
      Thus we can also delete the FRAME_POINTER dependency.
      
      Fixes this kconfig warning: (for um, sparc64, riscv, xtensa)
      
      WARNING: unmet direct dependencies detected for LOCKDEP
        Depends on [n]: DEBUG_KERNEL [=y] && LOCK_DEBUGGING_SUPPORT [=y] && (FRAME_POINTER [=n] || MIPS || PPC || S390 || MICROBLAZE || ARM || ARC || X86)
        Selected by [y]:
        - PROVE_LOCKING [=y] && DEBUG_KERNEL [=y] && LOCK_DEBUGGING_SUPPORT [=y]
        - LOCK_STAT [=y] && DEBUG_KERNEL [=y] && LOCK_DEBUGGING_SUPPORT [=y]
        - DEBUG_LOCK_ALLOC [=y] && DEBUG_KERNEL [=y] && LOCK_DEBUGGING_SUPPORT [=y]
      
      Fixes: 7d37cb2c ("lib: fix kconfig dependency on ARCH_WANT_FRAME_POINTERS")
      Signed-off-by: NRandy Dunlap <rdunlap@infradead.org>
      Signed-off-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
      Acked-by: NWaiman Long <longman@redhat.com>
      Link: https://lkml.kernel.org/r/20210524224150.8009-1-rdunlap@infradead.org
      b8e00abe
  23. 24 5月, 2021 1 次提交
  24. 19 5月, 2021 1 次提交
  25. 01 5月, 2021 1 次提交
  26. 25 4月, 2021 2 次提交
  27. 21 4月, 2021 1 次提交
    • M
      lib/math: Add a `do_div' test module · 5086ea4b
      Maciej W. Rozycki 提交于
      Implement a module for correctness and performance evaluation for the
      `do_div' function, often handled in an optimised manner by platform
      code.  Use a somewhat randomly generated set of inputs that is supposed
      to be representative, using the same set of divisors twice, expressed as
      a constant and as a variable each, so as to verify the implementation
      for both cases should they be handled by different code execution paths.
      Reference results were produced with GNU bc.
      
      At the conclusion output the total execution time elapsed.
      Signed-off-by: NMaciej W. Rozycki <macro@orcam.me.uk>
      Signed-off-by: NThomas Bogendoerfer <tsbogend@alpha.franken.de>
      5086ea4b
  28. 16 4月, 2021 1 次提交
  29. 10 4月, 2021 1 次提交
  30. 05 4月, 2021 1 次提交
  31. 27 2月, 2021 1 次提交
    • A
      mm: add Kernel Electric-Fence infrastructure · 0ce20dd8
      Alexander Potapenko 提交于
      Patch series "KFENCE: A low-overhead sampling-based memory safety error detector", v7.
      
      This adds the Kernel Electric-Fence (KFENCE) infrastructure. KFENCE is a
      low-overhead sampling-based memory safety error detector of heap
      use-after-free, invalid-free, and out-of-bounds access errors.  This
      series enables KFENCE for the x86 and arm64 architectures, and adds
      KFENCE hooks to the SLAB and SLUB allocators.
      
      KFENCE is designed to be enabled in production kernels, and has near
      zero performance overhead. Compared to KASAN, KFENCE trades performance
      for precision. The main motivation behind KFENCE's design, is that with
      enough total uptime KFENCE will detect bugs in code paths not typically
      exercised by non-production test workloads. One way to quickly achieve a
      large enough total uptime is when the tool is deployed across a large
      fleet of machines.
      
      KFENCE objects each reside on a dedicated page, at either the left or
      right page boundaries. The pages to the left and right of the object
      page are "guard pages", whose attributes are changed to a protected
      state, and cause page faults on any attempted access to them. Such page
      faults are then intercepted by KFENCE, which handles the fault
      gracefully by reporting a memory access error.
      
      Guarded allocations are set up based on a sample interval (can be set
      via kfence.sample_interval). After expiration of the sample interval,
      the next allocation through the main allocator (SLAB or SLUB) returns a
      guarded allocation from the KFENCE object pool. At this point, the timer
      is reset, and the next allocation is set up after the expiration of the
      interval.
      
      To enable/disable a KFENCE allocation through the main allocator's
      fast-path without overhead, KFENCE relies on static branches via the
      static keys infrastructure. The static branch is toggled to redirect the
      allocation to KFENCE.
      
      The KFENCE memory pool is of fixed size, and if the pool is exhausted no
      further KFENCE allocations occur. The default config is conservative
      with only 255 objects, resulting in a pool size of 2 MiB (with 4 KiB
      pages).
      
      We have verified by running synthetic benchmarks (sysbench I/O,
      hackbench) and production server-workload benchmarks that a kernel with
      KFENCE (using sample intervals 100-500ms) is performance-neutral
      compared to a non-KFENCE baseline kernel.
      
      KFENCE is inspired by GWP-ASan [1], a userspace tool with similar
      properties. The name "KFENCE" is a homage to the Electric Fence Malloc
      Debugger [2].
      
      For more details, see Documentation/dev-tools/kfence.rst added in the
      series -- also viewable here:
      
      	https://raw.githubusercontent.com/google/kasan/kfence/Documentation/dev-tools/kfence.rst
      
      [1] http://llvm.org/docs/GwpAsan.html
      [2] https://linux.die.net/man/3/efence
      
      This patch (of 9):
      
      This adds the Kernel Electric-Fence (KFENCE) infrastructure. KFENCE is a
      low-overhead sampling-based memory safety error detector of heap
      use-after-free, invalid-free, and out-of-bounds access errors.
      
      KFENCE is designed to be enabled in production kernels, and has near
      zero performance overhead. Compared to KASAN, KFENCE trades performance
      for precision. The main motivation behind KFENCE's design, is that with
      enough total uptime KFENCE will detect bugs in code paths not typically
      exercised by non-production test workloads. One way to quickly achieve a
      large enough total uptime is when the tool is deployed across a large
      fleet of machines.
      
      KFENCE objects each reside on a dedicated page, at either the left or
      right page boundaries. The pages to the left and right of the object
      page are "guard pages", whose attributes are changed to a protected
      state, and cause page faults on any attempted access to them. Such page
      faults are then intercepted by KFENCE, which handles the fault
      gracefully by reporting a memory access error. To detect out-of-bounds
      writes to memory within the object's page itself, KFENCE also uses
      pattern-based redzones. The following figure illustrates the page
      layout:
      
        ---+-----------+-----------+-----------+-----------+-----------+---
           | xxxxxxxxx | O :       | xxxxxxxxx |       : O | xxxxxxxxx |
           | xxxxxxxxx | B :       | xxxxxxxxx |       : B | xxxxxxxxx |
           | x GUARD x | J : RED-  | x GUARD x | RED-  : J | x GUARD x |
           | xxxxxxxxx | E :  ZONE | xxxxxxxxx |  ZONE : E | xxxxxxxxx |
           | xxxxxxxxx | C :       | xxxxxxxxx |       : C | xxxxxxxxx |
           | xxxxxxxxx | T :       | xxxxxxxxx |       : T | xxxxxxxxx |
        ---+-----------+-----------+-----------+-----------+-----------+---
      
      Guarded allocations are set up based on a sample interval (can be set
      via kfence.sample_interval). After expiration of the sample interval, a
      guarded allocation from the KFENCE object pool is returned to the main
      allocator (SLAB or SLUB). At this point, the timer is reset, and the
      next allocation is set up after the expiration of the interval.
      
      To enable/disable a KFENCE allocation through the main allocator's
      fast-path without overhead, KFENCE relies on static branches via the
      static keys infrastructure. The static branch is toggled to redirect the
      allocation to KFENCE. To date, we have verified by running synthetic
      benchmarks (sysbench I/O, hackbench) that a kernel compiled with KFENCE
      is performance-neutral compared to the non-KFENCE baseline.
      
      For more details, see Documentation/dev-tools/kfence.rst (added later in
      the series).
      
      [elver@google.com: fix parameter description for kfence_object_start()]
        Link: https://lkml.kernel.org/r/20201106092149.GA2851373@elver.google.com
      [elver@google.com: avoid stalling work queue task without allocations]
        Link: https://lkml.kernel.org/r/CADYN=9J0DQhizAGB0-jz4HOBBh+05kMBXb4c0cXMS7Qi5NAJiw@mail.gmail.com
        Link: https://lkml.kernel.org/r/20201110135320.3309507-1-elver@google.com
      [elver@google.com: fix potential deadlock due to wake_up()]
        Link: https://lkml.kernel.org/r/000000000000c0645805b7f982e4@google.com
        Link: https://lkml.kernel.org/r/20210104130749.1768991-1-elver@google.com
      [elver@google.com: add option to use KFENCE without static keys]
        Link: https://lkml.kernel.org/r/20210111091544.3287013-1-elver@google.com
      [elver@google.com: add missing copyright and description headers]
        Link: https://lkml.kernel.org/r/20210118092159.145934-1-elver@google.com
      
      Link: https://lkml.kernel.org/r/20201103175841.3495947-2-elver@google.comSigned-off-by: NMarco Elver <elver@google.com>
      Signed-off-by: NAlexander Potapenko <glider@google.com>
      Reviewed-by: NDmitry Vyukov <dvyukov@google.com>
      Reviewed-by: NSeongJae Park <sjpark@amazon.de>
      Co-developed-by: NMarco Elver <elver@google.com>
      Reviewed-by: NJann Horn <jannh@google.com>
      Cc: "H. Peter Anvin" <hpa@zytor.com>
      Cc: Paul E. McKenney <paulmck@kernel.org>
      Cc: Andrey Konovalov <andreyknvl@google.com>
      Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Christopher Lameter <cl@linux.com>
      Cc: Dave Hansen <dave.hansen@linux.intel.com>
      Cc: David Rientjes <rientjes@google.com>
      Cc: Eric Dumazet <edumazet@google.com>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Hillf Danton <hdanton@sina.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Jonathan Corbet <corbet@lwn.net>
      Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
      Cc: Joern Engel <joern@purestorage.com>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Pekka Enberg <penberg@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Vlastimil Babka <vbabka@suse.cz>
      Cc: Will Deacon <will@kernel.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      0ce20dd8
  32. 16 2月, 2021 2 次提交
    • N
      Kconfig: allow explicit opt in to DWARF v5 · 98cd6f52
      Nick Desaulniers 提交于
      DWARF v5 is the latest standard of the DWARF debug info format. GCC 11
      will change the implicit default DWARF version, if left unspecified, to
      DWARF v5.
      
      Allow users of Clang and older versions of GCC that have not changed the
      implicit default DWARF version to DWARF v5 to opt in. This can help
      testing consumers of DWARF debug info in preparation of v5 becoming more
      widespread, as well as result in significant binary size savings of the
      pre-stripped vmlinux image.
      
      DWARF5 wins significantly in terms of size when mixed with compression
      (CONFIG_DEBUG_INFO_COMPRESSED).
      
      363M    vmlinux.clang12.dwarf5.compressed
      434M    vmlinux.clang12.dwarf4.compressed
      439M    vmlinux.clang12.dwarf2.compressed
      457M    vmlinux.clang12.dwarf5
      536M    vmlinux.clang12.dwarf4
      548M    vmlinux.clang12.dwarf2
      
      515M    vmlinux.gcc10.2.dwarf5.compressed
      599M    vmlinux.gcc10.2.dwarf4.compressed
      624M    vmlinux.gcc10.2.dwarf2.compressed
      630M    vmlinux.gcc10.2.dwarf5
      765M    vmlinux.gcc10.2.dwarf4
      809M    vmlinux.gcc10.2.dwarf2
      
      Though the quality of debug info is harder to quantify; size is not a
      proxy for quality.
      
      Jakub notes:
        One thing is GCC DWARF-5 support, that is whether the compiler will
        support -gdwarf-5 flag, and that support should be there from GCC 7
        onwards.
      
        All [GCC] 5.1 - 6.x did was start accepting -gdwarf-5 as experimental
        option that enabled some small DWARF subset (initially only a few
        DW_LANG_* codes newly added to DWARF5 drafts).  Only GCC 7 (released
        after DWARF 5 has been finalized) started emitting DWARF5 section
        headers and got most of the DWARF5 changes in...
      
        Another separate thing is whether the assembler does support
        the -gdwarf-5 option (i.e. if you can compile assembler files
        with -Wa,-gdwarf-5) ... That option is about whether the assembler
        will emit DWARF5 or DWARF2 .debug_line.  It is fine to compile C sources
        with -gdwarf-5 and use DWARF2 .debug_line for assembler files if as
        doesn't support it.
      
      Version check GCC so that we don't need to worry about the difference in
      command line args between GNU readelf and llvm-readelf/llvm-dwarfdump to
      validate the DWARF Version in the assembler feature detection script.
      
      Most issues with clang produced assembler were fixed in binutils 2.35.1,
      but 2.35.2 fixed issues related to requiring the flag -Wa,-gdwarf-5
      explicitly. The added shell script test checks for the latter, and is
      only required when using clang without its integrated assembler, though
      we use for clang regardless as we do not yet have a way to query the
      assembler from Kconfig.
      
      Disabled for now if CONFIG_DEBUG_INFO_BTF is set; pahole doesn't yet
      recognize the new additions to the DWARF debug info.
      
      This only modifies the DWARF version emitted by the compiler, not the
      assembler.
      
      The DWARF version of a binary can be validated with:
      $ llvm-dwarfdump <object file> | head -n 4 | grep version
      or
      $ readelf --debug-dump=info <object file> 2>/dev/null | grep Version
      
      Parts of the tree don't reuse DEBUG_CFLAGS as they should; such cleanup
      is left as a follow up.
      
      Link: http://www.dwarfstd.org/doc/DWARF5.pdf
      Link: https://bugzilla.redhat.com/show_bug.cgi?id=1922707Reported-by: NSedat Dilek <sedat.dilek@gmail.com>
      Suggested-by: NArvind Sankar <nivedita@alum.mit.edu>
      Suggested-by: NCaroline Tice <cmtice@google.com>
      Suggested-by: NFangrui Song <maskray@google.com>
      Suggested-by: NJakub Jelinek <jakub@redhat.com>
      Suggested-by: NMasahiro Yamada <masahiroy@kernel.org>
      Suggested-by: NNathan Chancellor <natechancellor@gmail.com>
      Signed-off-by: NNick Desaulniers <ndesaulniers@google.com>
      Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM/Clang v12.0.0-rc1 x86-64
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      98cd6f52
    • N
      Kbuild: make DWARF version a choice · a66049e2
      Nick Desaulniers 提交于
      Adds a default CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT which allows
      the implicit default version of DWARF emitted by the toolchain to
      progress over time.
      
      Modifies CONFIG_DEBUG_INFO_DWARF4 to be a member of a choice, making it
      mutually exclusive with CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT. Users
      may want to select this if they are using a newer toolchain, but have
      consumers of the DWARF debug info that aren't yet ready for newer DWARF
      versions' debug info.
      
      Does so in a way that's forward compatible with existing
      configs, and makes adding future versions more straightforward. This
      patch does not change the current behavior or selection of DWARF
      version for users upgrading to kernels with this patch.
      
      GCC since ~4.8 has defaulted to DWARF v4 implicitly, and GCC 11 has
      bumped this to v5.
      
      Remove the Kconfig help text  about DWARF v4 being larger.  It's
      empirically false for the latest toolchains for x86_64 defconfig, has no
      point of reference (I suspect it was DWARF v2 but that's stil
      empirically false), and debug info size is not a qualatative measure.
      Suggested-by: NArvind Sankar <nivedita@alum.mit.edu>
      Suggested-by: NFangrui Song <maskray@google.com>
      Suggested-by: NJakub Jelinek <jakub@redhat.com>
      Suggested-by: NMark Wielaard <mark@klomp.org>
      Suggested-by: NMasahiro Yamada <masahiroy@kernel.org>
      Suggested-by: NNathan Chancellor <nathan@kernel.org>
      Tested-by: NSedat Dilek <sedat.dilek@gmail.com>
      Signed-off-by: NNick Desaulniers <ndesaulniers@google.com>
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      a66049e2
  33. 12 2月, 2021 1 次提交