Skip to content
Snippets Groups Projects
  1. Nov 04, 2020
  2. May 30, 2019
  3. Oct 19, 2017
  4. Jun 13, 2017
  5. Oct 14, 2015
  6. Jun 26, 2015
    • Tejun Heo's avatar
      netconsole: implement extended console support · e2f15f9a
      Tejun Heo authored
      
      printk logbuf keeps various metadata and optional key=value dictionary for
      structured messages, both of which are stripped when messages are handed
      to regular console drivers.
      
      It can be useful to have this metadata and dictionary available to
      netconsole consumers.  This obviously makes logging via netconsole more
      complete and the sequence number in particular is useful in environments
      where messages may be lost or reordered in transit - e.g.  when netconsole
      is used to collect messages in a large cluster where packets may have to
      travel congested hops to reach the aggregator.  The lost and reordered
      messages can easily be identified and handled accordingly using the
      sequence numbers.
      
      printk recently added extended console support which can be selected by
      setting CON_EXTENDED flag.  From console driver side, not much changes.
      The only difference is that the text passed to the write callback is
      formatted the same way as /dev/kmsg.
      
      This patch implements extended console support for netconsole which can be
      enabled by either prepending "+" to a netconsole boot param entry or
      echoing 1 to "extended" file in configfs.  When enabled, netconsole
      transmits extended log messages with headers identical to /dev/kmsg
      output.
      
      There's one complication due to message fragments.  netconsole limits the
      maximum message size to 1k and messages longer than that are split into
      multiple fragments.  As all extended console messages should carry
      matching headers and be uniquely identifiable, each extended message
      fragment carries full copy of the metadata and an extra header field to
      identify the specific fragment.  The optional header is of the form
      "ncfrag=OFF/LEN" where OFF is the byte offset into the message body and
      LEN is the total length.
      
      To avoid unnecessarily making printk format extended messages, Extended
      netconsole is registered with printk when the first extended netconsole is
      configured.
      
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Cc: David Miller <davem@davemloft.net>
      Cc: Kay Sievers <kay@vrfy.org>
      Cc: Petr Mladek <pmladek@suse.cz>
      Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      e2f15f9a
    • Tejun Heo's avatar
      netconsole: make all dynamic netconsoles share a mutex · 369e5a88
      Tejun Heo authored
      
      Currently, each dynamic netconsole_target uses its own separate mutex to
      synchronize the configuration operations.
      
      This patch replaces the per-netconsole_target mutexes with a single
      mutex - dynamic_netconsole_mutex.  The reduced granularity doesn't hurt
      anything, the code is minutely simpler and this'd allow adding
      operations which should be synchronized across all dynamic netconsoles.
      
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Cc: David Miller <davem@davemloft.net>
      Cc: Kay Sievers <kay@vrfy.org>
      Cc: Petr Mladek <pmladek@suse.cz>
      Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      369e5a88
    • Tejun Heo's avatar
      netconsole: make netconsole_target->enabled a bool · 698cf1c6
      Tejun Heo authored
      
      netconsole uses both bool and int for boolean values.  Let's convert
      nt->enabled to bool for consistency.
      
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Cc: David Miller <davem@davemloft.net>
      Cc: Kay Sievers <kay@vrfy.org>
      Cc: Petr Mladek <pmladek@suse.cz>
      Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      698cf1c6
    • Tejun Heo's avatar
      netconsole: remove unnecessary netconsole_target_get/out() from write_msg() · a6d403ac
      Tejun Heo authored
      
      write_msg() grabs target_list_lock and walks target_list invoking
      netpool_send_udp() on each target.  Curiously, it protects each iteration
      with netconsole_target_get/put() even though it never releases
      target_list_lock which protects all the members.
      
      While this doesn't harm anything, it doesn't serve any purpose either.
      The items on the list can't go away while target_list_lock is held.
      Remove the unnecessary get/put pair.
      
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Cc: David Miller <davem@davemloft.net>
      Cc: Kay Sievers <kay@vrfy.org>
      Cc: Petr Mladek <pmladek@suse.cz>
      Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      a6d403ac
  7. Mar 03, 2015
  8. Oct 29, 2013
  9. Oct 25, 2013
    • Nikolay Aleksandrov's avatar
      netconsole: fix multiple race conditions · c7c6effd
      Nikolay Aleksandrov authored
      
      In every netconsole option that can be set through configfs there's a
      race when checking for nt->enabled since it can be modified at the same
      time. Probably the most damage can be done by store_enabled when racing
      with another instance of itself. Fix all the races with one stone by
      moving the mutex lock around the ->store call for all options.
      
      Signed-off-by: default avatarNikolay Aleksandrov <nikolay@redhat.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      c7c6effd
    • Nikolay Aleksandrov's avatar
      netconsole: fix NULL pointer dereference · 45e526e8
      Nikolay Aleksandrov authored
      
      We need to disable the netconsole (enabled = 0) before setting nt->np.dev
      to NULL because otherwise we might still have users after the
      netpoll_cleanup() since nt->enabled is set afterwards and we can
      have a message which will result in a NULL pointer dereference.
      It is very easy to hit dereferences all over the netpoll_send_udp function
      by running the following two loops in parallel:
      while [ 1 ]; do echo 1 > enabled; echo 0 > enabled; done;
      while [ 1 ]; do echo 00:11:22:33:44:55 > remote_mac; done;
      (the second loop is to generate messages, it can be done by anything)
      
      We're safe to set nt->np.dev = NULL and nt->enabled = 0 with the spinlock
      since it's required in the write_msg() function.
      
      Signed-off-by: default avatarNikolay Aleksandrov <nikolay@redhat.com>
      Reviewed-by: default avatarVeacelsav Falico <vfalico@redhat.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      45e526e8
  10. Sep 19, 2013
  11. Sep 04, 2013
    • Dan Aloni's avatar
      netconsole: avoid a crash with multiple sysfs writers · 7a163bfb
      Dan Aloni authored
      
      When my 'ifup eth' script was fired multiple times and ran concurrent on
      my laptop, for some obscure /etc scripting reason, it was revealed
      that the store_enabled() function in netconsole doesn't handle it nicely,
      as recorded by the Oops below (a syslog paste, but not mangled too much
      to prevent from discerning the traceback).
      
      On Linux 3.10.4, this patch seeks to remedy the problem, and it has been
      running stable on my laptop for a few days.
      
      [52608.609325] BUG: unable to handle kernel NULL pointer dereference at 00000000000003e0
      [52608.609331] IP: [<ffffffff81532a17>] __netpoll_cleanup+0x27/0xe0
      [52608.609339] PGD 15e51a067 PUD 15433e067 PMD 0
      [52608.609343] Oops: 0000 [#1] SMP re firewire_ohci firewire_core crc_itu_t [last unloaded: kvm_intel]
      [52608.609347] Modules linked in: kvm_intel tun vfat fat ppdev parport_pc parport fuse ipt_MASQUERADE usb_storage nf_conntrack_netbios_ns nf_conn [..garbled..]
      [52608.609433] RAX: 0000000000000000 RBX: ffff880210bbcc68 RCX: 0000000000000000
      [52608.609435] RDX: 0000000000000000 RSI: ffff8801ba447da0 RDI: ffff880210bbcc68
      [52608.609437] RBP: ffff8801ba447e18 R08: 0000000000000000 R09: 0000000000000001
      [52608.609439] R10: 000000000000000a R11: f000000000000000 R12: ffff880210bbcc68
      [52608.609441] R13: ffff88020bc41000 R14: 0000000000000002 R15: 000000000000000200000000000
      [52608.609443] FS:  00007f38d7bff740(0000) GS:ffff88021dc40000(0000) knlGS:0000000000000000
      [52608.609446] CS:  0010 DS: 0000 ES: 0000 CR0: 000000008005003300000000001427e0
      [52608.609448] CR2: 00000000000003e0 CR3: 0000000154103000 CR4: 00000000001427e0
      [52608.609450] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
      [52608.609452] netpoll: netconsole: local port 6665ess 10.0.0.27
      [52608.609454] netpoll: netconsole: local IPv4 address 10.0.0.27
      [52608.609456] netpoll: netconsole: interface 'em1'
      [52608.609457] netpoll: netconsole: remote port 514ress 10.0.0.15
      [52608.609459] netpoll: netconsole: remote IPv4 address 10.0.0.15:65:a8:9a:c7
      [52608.609461] netpoll: netconsole: remote ethernet address 1c:6f:65:a8:9a:c7
      [52608.609463] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
      [52608.609464] Stack:801ba447e08 ffff880210bbcc68 ffffffffffffffea ffff88020bc41000
      [52608.609466]  ffff8801ba447e08 ffff880210bbcc68 ffffffffffffffea ffff88020bc41000
      [52608.609471]  0000000000000002 0000000000000002 ffff8801ba447e38 ffffffff81532af4
      [52608.609475]  0000000000000000 ffff880210bbcc00 ffff8801ba447e78 ffffffff81420e7c
      [52608.609479] Call Trace:
      [52608.609484]  [<ffffffff81532af4>] netpoll_cleanup+0x24/0x50
      [52608.609489]  [<ffffffff81420e7c>] store_enabled+0x5c/0xe0
      [52608.609492]  [<ffffffff81420abe>] netconsole_target_attr_store+0x2e/0x40
      [52608.609498]  [<ffffffff811ff2a2>] configfs_write_file+0xd2/0x130
      [52608.609503]  [<ffffffff81188f95>] vfs_write+0xc5/0x1f0
      [52608.609506]  [<ffffffff81189482>] SyS_write+0x52/0xa0/0x10
      [52608.609511]  [<ffffffff81628c2e>] ? do_page_fault+0xe/0x10
      [52608.609516]  [<ffffffff8162d402>] system_call_fastpath+0x16/0x1b
      [52608.609517] Code: 1f 44 00 00 0f 1f 44 00 00 55 48 89 e5 48 83 ec 30 4c 89 65 e0 48 89 5d d8 49 89 fc 4c 89 6d e8 4c 89 75 f0 4c 89 7d f8 48 8 [..garbled..]
      [52608.609559] RIP  [<ffffffff81532a17>] __netpoll_cleanup+0x27/0xe0
      [52608.609563]  RSP <ffff8801ba447de8>
      [52608.609564] CR2: 00000000000003e0
      [52608.609567] ---[ end trace d25ec343349b61d2 ]---
      
      Signed-off-by: default avatarDan Aloni <alonid@postram.com>
      Signed-off-by: default avatarNeil Horman <nhorman@tuxdriver.com>
      CC: David S. Miller <davem@davemloft.net>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      7a163bfb
  12. Jun 05, 2013
  13. May 28, 2013
  14. Mar 12, 2013
  15. Jan 09, 2013
  16. Nov 09, 2012
  17. Aug 20, 2012
  18. Aug 14, 2012
  19. Jan 31, 2012
  20. Oct 19, 2011
  21. Sep 20, 2011
  22. May 23, 2011
  23. May 09, 2011
  24. Apr 22, 2011
    • Neil Horman's avatar
      netconsole: fix deadlock when removing net driver that netconsole is using (v2) · 13f172ff
      Neil Horman authored
      
      A deadlock was reported to me recently that occured when netconsole was being
      used in a virtual guest.  If the virtio_net driver was removed while netconsole
      was setup to use an interface that was driven by that driver, the guest
      deadlocked.  No backtrace was provided because netconsole was the only console
      configured, but it became clear pretty quickly what the problem was.  In
      netconsole_netdev_event, if we get an unregister event, we call
      __netpoll_cleanup with the target_list_lock held and irqs disabled.
      __netpoll_cleanup can, if pending netpoll packets are waiting call
      cancel_delayed_work_sync, which is a sleeping path.  the might_sleep call in
      that path gets triggered, causing a console warning to be issued.  The
      netconsole write handler of course tries to take the target_list_lock again,
      which we already hold, causing deadlock.
      
      The fix is pretty striaghtforward.  Simply drop the target_list_lock and
      re-enable irqs prior to calling __netpoll_cleanup, the re-acquire the lock, and
      restart the loop.  Confirmed by myself to fix the problem reported.
      
      Signed-off-by: default avatarNeil Horman <nhorman@tuxdriver.com>
      CC: "David S. Miller" <davem@davemloft.net>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      13f172ff
  25. Jan 06, 2011
  26. Oct 18, 2010
  27. May 06, 2010
    • WANG Cong's avatar
      netpoll: add generic support for bridge and bonding devices · 0e34e931
      WANG Cong authored
      
      This whole patchset is for adding netpoll support to bridge and bonding
      devices. I already tested it for bridge, bonding, bridge over bonding,
      and bonding over bridge. It looks fine now.
      
      To make bridge and bonding support netpoll, we need to adjust
      some netpoll generic code. This patch does the following things:
      
      1) introduce two new priv_flags for struct net_device:
         IFF_IN_NETPOLL which identifies we are processing a netpoll;
         IFF_DISABLE_NETPOLL is used to disable netpoll support for a device
         at run-time;
      
      2) introduce one new method for netdev_ops:
         ->ndo_netpoll_cleanup() is used to clean up netpoll when a device is
           removed.
      
      3) introduce netpoll_poll_dev() which takes a struct net_device * parameter;
         export netpoll_send_skb() and netpoll_poll_dev() which will be used later;
      
      4) hide a pointer to struct netpoll in struct netpoll_info, ditto.
      
      5) introduce ->real_dev for struct netpoll.
      
      6) introduce a new status NETDEV_BONDING_DESLAE, which is used to disable
         netconsole before releasing a slave, to avoid deadlocks.
      
      Cc: David Miller <davem@davemloft.net>
      Cc: Neil Horman <nhorman@tuxdriver.com>
      Signed-off-by: default avatarWANG Cong <amwang@redhat.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      0e34e931
  28. Mar 30, 2010
    • Tejun Heo's avatar
      include cleanup: Update gfp.h and slab.h includes to prepare for breaking... · 5a0e3ad6
      Tejun Heo authored
      include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
      
      percpu.h is included by sched.h and module.h and thus ends up being
      included when building most .c files.  percpu.h includes slab.h which
      in turn includes gfp.h making everything defined by the two files
      universally available and complicating inclusion dependencies.
      
      percpu.h -> slab.h dependency is about to be removed.  Prepare for
      this change by updating users of gfp and slab facilities include those
      headers directly instead of assuming availability.  As this conversion
      needs to touch large number of source files, the following script is
      used as the basis of conversion.
      
        http://userweb.kernel.org/~tj/misc/slabh-sweep.py
      
      
      
      The script does the followings.
      
      * Scan files for gfp and slab usages and update includes such that
        only the necessary includes are there.  ie. if only gfp is used,
        gfp.h, if slab is used, slab.h.
      
      * When the script inserts a new include, it looks at the include
        blocks and try to put the new include such that its order conforms
        to its surrounding.  It's put in the include block which contains
        core kernel includes, in the same order that the rest are ordered -
        alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
        doesn't seem to be any matching order.
      
      * If the script can't find a place to put a new include (mostly
        because the file doesn't have fitting include block), it prints out
        an error message indicating which .h file needs to be added to the
        file.
      
      The conversion was done in the following steps.
      
      1. The initial automatic conversion of all .c files updated slightly
         over 4000 files, deleting around 700 includes and adding ~480 gfp.h
         and ~3000 slab.h inclusions.  The script emitted errors for ~400
         files.
      
      2. Each error was manually checked.  Some didn't need the inclusion,
         some needed manual addition while adding it to implementation .h or
         embedding .c file was more appropriate for others.  This step added
         inclusions to around 150 files.
      
      3. The script was run again and the output was compared to the edits
         from #2 to make sure no file was left behind.
      
      4. Several build tests were done and a couple of problems were fixed.
         e.g. lib/decompress_*.c used malloc/free() wrappers around slab
         APIs requiring slab.h to be added manually.
      
      5. The script was run on all .h files but without automatically
         editing them as sprinkling gfp.h and slab.h inclusions around .h
         files could easily lead to inclusion dependency hell.  Most gfp.h
         inclusion directives were ignored as stuff from gfp.h was usually
         wildly available and often used in preprocessor macros.  Each
         slab.h inclusion directive was examined and added manually as
         necessary.
      
      6. percpu.h was updated not to include slab.h.
      
      7. Build test were done on the following configurations and failures
         were fixed.  CONFIG_GCOV_KERNEL was turned off for all tests (as my
         distributed build env didn't work with gcov compiles) and a few
         more options had to be turned off depending on archs to make things
         build (like ipr on powerpc/64 which failed due to missing writeq).
      
         * x86 and x86_64 UP and SMP allmodconfig and a custom test config.
         * powerpc and powerpc64 SMP allmodconfig
         * sparc and sparc64 SMP allmodconfig
         * ia64 SMP allmodconfig
         * s390 SMP allmodconfig
         * alpha SMP allmodconfig
         * um on x86_64 SMP allmodconfig
      
      8. percpu.h modifications were reverted so that it could be applied as
         a separate patch and serve as bisection point.
      
      Given the fact that I had only a couple of failures from tests on step
      6, I'm fairly confident about the coverage of this conversion patch.
      If there is a breakage, it's likely to be something in one of the arch
      headers which should be easily discoverable easily on most builds of
      the specific arch.
      
      Signed-off-by: default avatarTejun Heo <tj@kernel.org>
      Guess-its-ok-by: default avatarChristoph Lameter <cl@linux-foundation.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
      5a0e3ad6
  29. May 01, 2009
    • Bruno Prémont's avatar
      netconsole: take care of NETDEV_UNREGISTER event · 2382b15b
      Bruno Prémont authored
      
      When netconsole is loaded and a network interface fades away (e.g. on
      rmmod $interface_driver_module) the rmmod remains stuck and some locks
      are taken that prevent any additional module loading/unloading as well
      as interface up/down changes.
      In addition kernel logs (and console) get flooded at 10s interval with
      
      [  122.464065] unregister_netdevice: waiting for eth0 to become free. Usage count = 1
      [  132.704059] unregister_netdevice: waiting for eth0 to become free. Usage count = 1
      
      This patch lets netconsole take NETDEV_UNREGISTER event into account
      and release the affected interface if it was in use.
      
      Signed-off-by: default avatarBruno Prémont <bonbons@linux-vserver.org>
      Acked-by: default avatarMatt Mackall <mpm@selenic.com>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      2382b15b
  30. Mar 29, 2009
  31. Oct 28, 2008
  32. Aug 01, 2008
Loading