1. 28 6月, 2018 1 次提交
  2. 25 4月, 2018 1 次提交
    • S
      printk: wake up klogd in vprintk_emit · 43a17111
      Sergey Senozhatsky 提交于
      We wake up klogd very late - only when current console_sem owner
      is done pushing pending kernel messages to the serial/net consoles.
      In some cases this results in lost syslog messages, because kernel
      log buffer is a circular buffer and if we don't wakeup syslog long
      enough there are chances that logbuf simply will wrap around.
      
      The patch moves the klogd wake up call to vprintk_emit(), which is
      the only legit way for a kernel message to appear in the logbuf,
      right after the attempt to handle consoles. As a result, klogd
      will get waken either after flushing the new message to consoles
      or immediately when consoles are still busy with older messages.
      
      Link: http://lkml.kernel.org/r/20180419014250.5692-1-sergey.senozhatsky@gmail.com
      To: Steven Rostedt <rostedt@goodmis.org>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Tejun Heo <tj@kernel.org>
      Cc: linux-kernel@vger.kernel.org
      Signed-off-by: NSergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Signed-off-by: NPetr Mladek <pmladek@suse.com>
      43a17111
  3. 06 4月, 2018 1 次提交
  4. 23 3月, 2018 1 次提交
  5. 15 3月, 2018 1 次提交
  6. 27 2月, 2018 1 次提交
    • P
      printk: Wake klogd when passing console_lock owner · c14376de
      Petr Mladek 提交于
      wake_klogd is a local variable in console_unlock(). The information
      is lost when the console_lock owner using the busy wait added by
      the commit dbdda842 ("printk: Add console owner and waiter
      logic to load balance console writes"). The following race is
      possible:
      
      CPU0				CPU1
      console_unlock()
      
        for (;;)
           /* calling console for last message */
      
      				printk()
      				  log_store()
      				    log_next_seq++;
      
           /* see new message */
           if (seen_seq != log_next_seq) {
      	wake_klogd = true;
      	seen_seq = log_next_seq;
           }
      
           console_lock_spinning_enable();
      
      				  if (console_trylock_spinning())
      				     /* spinning */
      
           if (console_lock_spinning_disable_and_check()) {
      	printk_safe_exit_irqrestore(flags);
      	return;
      
      				  console_unlock()
      				    if (seen_seq != log_next_seq) {
      				    /* already seen */
      				    /* nothing to do */
      
      Result: Nobody would wakeup klogd.
      
      One solution would be to make a global variable from wake_klogd.
      But then we would need to manipulate it under a lock or so.
      
      This patch wakes klogd also when console_lock is passed to the
      spinning waiter. It looks like the right way to go. Also userspace
      should have a chance to see and store any "flood" of messages.
      
      Note that the very late klogd wake up was a historic solution.
      It made sense on single CPU systems or when sys_syslog() operations
      were synchronized using the big kernel lock like in v2.1.113.
      But it is questionable these days.
      
      Fixes: dbdda842 ("printk: Add console owner and waiter logic to load balance console writes")
      Link: http://lkml.kernel.org/r/20180226155734.dzwg3aovqnwtvkoy@pathway.suse.cz
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: linux-kernel@vger.kernel.org
      Cc: Tejun Heo <tj@kernel.org>
      Suggested-by: NSergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Reviewed-by: NSergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Signed-off-by: NPetr Mladek <pmladek@suse.com>
      c14376de
  7. 12 2月, 2018 1 次提交
    • L
      vfs: do bulk POLL* -> EPOLL* replacement · a9a08845
      Linus Torvalds 提交于
      This is the mindless scripted replacement of kernel use of POLL*
      variables as described by Al, done by this script:
      
          for V in IN OUT PRI ERR RDNORM RDBAND WRNORM WRBAND HUP RDHUP NVAL MSG; do
              L=`git grep -l -w POLL$V | grep -v '^t' | grep -v /um/ | grep -v '^sa' | grep -v '/poll.h$'|grep -v '^D'`
              for f in $L; do sed -i "-es/^\([^\"]*\)\(\<POLL$V\>\)/\\1E\\2/" $f; done
          done
      
      with de-mangling cleanups yet to come.
      
      NOTE! On almost all architectures, the EPOLL* constants have the same
      values as the POLL* constants do.  But they keyword here is "almost".
      For various bad reasons they aren't the same, and epoll() doesn't
      actually work quite correctly in some cases due to this on Sparc et al.
      
      The next patch from Al will sort out the final differences, and we
      should be all done.
      Scripted-by: NAl Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      a9a08845
  8. 08 2月, 2018 1 次提交
  9. 22 1月, 2018 1 次提交
  10. 17 1月, 2018 3 次提交
    • S
      printk: Never set console_may_schedule in console_trylock() · fd5f7cde
      Sergey Senozhatsky 提交于
      This patch, basically, reverts commit 6b97a20d ("printk:
      set may_schedule for some of console_trylock() callers").
      That commit was a mistake, it introduced a big dependency
      on the scheduler, by enabling preemption under console_sem
      in printk()->console_unlock() path, which is rather too
      critical. The patch did not significantly reduce the
      possibilities of printk() lockups, but made it possible to
      stall printk(), as has been reported by Tetsuo Handa [1].
      
      Another issues is that preemption under console_sem also
      messes up with Steven Rostedt's hand off scheme, by making
      it possible to sleep with console_sem both in console_unlock()
      and in vprintk_emit(), after acquiring the console_sem
      ownership (anywhere between printk_safe_exit_irqrestore() in
      console_trylock_spinning() and printk_safe_enter_irqsave()
      in console_unlock()). This makes hand off less likely and,
      at the same time, may result in a significant amount of
      pending logbuf messages. Preempted console_sem owner makes
      it impossible for other CPUs to emit logbuf messages, but
      does not make it impossible for other CPUs to append new
      messages to the logbuf.
      
      Reinstate the old behavior and make printk() non-preemptible.
      Should any printk() lockup reports arrive they must be handled
      in a different way.
      
      [1] http://lkml.kernel.org/r/201603022101.CAH73907.OVOOMFHFFtQJSL%20()%20I-love%20!%20SAKURA%20!%20ne%20!%20jp
      Fixes: 6b97a20d ("printk: set may_schedule for some of console_trylock() callers")
      Link: http://lkml.kernel.org/r/20180116044716.GE6607@jagdpanzerIV
      To: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Cc: Tejun Heo <tj@kernel.org>
      Cc: akpm@linux-foundation.org
      Cc: linux-mm@kvack.org
      Cc: Cong Wang <xiyou.wangcong@gmail.com>
      Cc: Dave Hansen <dave.hansen@intel.com>
      Cc: Johannes Weiner <hannes@cmpxchg.org>
      Cc: Mel Gorman <mgorman@suse.de>
      Cc: Michal Hocko <mhocko@kernel.org>
      Cc: Vlastimil Babka <vbabka@suse.cz>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Jan Kara <jack@suse.cz>
      Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
      Cc: Byungchul Park <byungchul.park@lge.com>
      Cc: Pavel Machek <pavel@ucw.cz>
      Cc: linux-kernel@vger.kernel.org
      Signed-off-by: NSergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Reported-by: NTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      Reviewed-by: NSteven Rostedt (VMware) <rostedt@goodmis.org>
      Signed-off-by: NPetr Mladek <pmladek@suse.com>
      fd5f7cde
    • P
      printk: Hide console waiter logic into helpers · c162d5b4
      Petr Mladek 提交于
      The commit ("printk: Add console owner and waiter logic to load balance
      console writes") made vprintk_emit() and console_unlock() even more
      complicated.
      
      This patch extracts the new code into 3 helper functions. They should
      help to keep it rather self-contained. It will be easier to use and
      maintain.
      
      This patch just shuffles the existing code. It does not change
      the functionality.
      
      Link: http://lkml.kernel.org/r/20180112160837.GD24497@linux.suse
      Cc: akpm@linux-foundation.org
      Cc: linux-mm@kvack.org
      Cc: Cong Wang <xiyou.wangcong@gmail.com>
      Cc: Dave Hansen <dave.hansen@intel.com>
      Cc: Johannes Weiner <hannes@cmpxchg.org>
      Cc: Mel Gorman <mgorman@suse.de>
      Cc: Michal Hocko <mhocko@kernel.org>
      Cc: Vlastimil Babka <vbabka@suse.cz>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Jan Kara <jack@suse.cz>
      Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
      Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      Cc: rostedt@home.goodmis.org
      Cc: Byungchul Park <byungchul.park@lge.com>
      Cc: Tejun Heo <tj@kernel.org>
      Cc: Pavel Machek <pavel@ucw.cz>
      Cc: linux-kernel@vger.kernel.org
      Reviewed-by: NSteven Rostedt (VMware) <rostedt@goodmis.org>
      Acked-by: NSergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Signed-off-by: NPetr Mladek <pmladek@suse.com>
      c162d5b4
    • S
      printk: Add console owner and waiter logic to load balance console writes · dbdda842
      Steven Rostedt (VMware) 提交于
      This patch implements what I discussed in Kernel Summit. I added
      lockdep annotation (hopefully correctly), and it hasn't had any splats
      (since I fixed some bugs in the first iterations). It did catch
      problems when I had the owner covering too much. But now that the owner
      is only set when actively calling the consoles, lockdep has stayed
      quiet.
      
      Here's the design again:
      
      I added a "console_owner" which is set to a task that is actively
      writing to the consoles. It is *not* the same as the owner of the
      console_lock. It is only set when doing the calls to the console
      functions. It is protected by a console_owner_lock which is a raw spin
      lock.
      
      There is a console_waiter. This is set when there is an active console
      owner that is not current, and waiter is not set. This too is protected
      by console_owner_lock.
      
      In printk() when it tries to write to the consoles, we have:
      
      	if (console_trylock())
      		console_unlock();
      
      Now I added an else, which will check if there is an active owner, and
      no current waiter. If that is the case, then console_waiter is set, and
      the task goes into a spin until it is no longer set.
      
      When the active console owner finishes writing the current message to
      the consoles, it grabs the console_owner_lock and sees if there is a
      waiter, and clears console_owner.
      
      If there is a waiter, then it breaks out of the loop, clears the waiter
      flag (because that will release the waiter from its spin), and exits.
      Note, it does *not* release the console semaphore. Because it is a
      semaphore, there is no owner. Another task may release it. This means
      that the waiter is guaranteed to be the new console owner! Which it
      becomes.
      
      Then the waiter calls console_unlock() and continues to write to the
      consoles.
      
      If another task comes along and does a printk() it too can become the
      new waiter, and we wash rinse and repeat!
      
      By Petr Mladek about possible new deadlocks:
      
      The thing is that we move console_sem only to printk() call
      that normally calls console_unlock() as well. It means that
      the transferred owner should not bring new type of dependencies.
      As Steven said somewhere: "If there is a deadlock, it was
      there even before."
      
      We could look at it from this side. The possible deadlock would
      look like:
      
      CPU0                            CPU1
      
      console_unlock()
      
        console_owner = current;
      
      				spin_lockA()
      				  printk()
      				    spin = true;
      				    while (...)
      
          call_console_drivers()
            spin_lockA()
      
      This would be a deadlock. CPU0 would wait for the lock A.
      While CPU1 would own the lockA and would wait for CPU0
      to finish calling the console drivers and pass the console_sem
      owner.
      
      But if the above is true than the following scenario was
      already possible before:
      
      CPU0
      
      spin_lockA()
        printk()
          console_unlock()
            call_console_drivers()
      	spin_lockA()
      
      By other words, this deadlock was there even before. Such
      deadlocks are prevented by using printk_deferred() in
      the sections guarded by the lock A.
      
      By Steven Rostedt:
      
      To demonstrate the issue, this module has been shown to lock up a
      system with 4 CPUs and a slow console (like a serial console). It is
      also able to lock up a 8 CPU system with only a fast (VGA) console, by
      passing in "loops=100". The changes in this commit prevent this module
      from locking up the system.
      
       #include <linux/module.h>
       #include <linux/delay.h>
       #include <linux/sched.h>
       #include <linux/mutex.h>
       #include <linux/workqueue.h>
       #include <linux/hrtimer.h>
      
       static bool stop_testing;
       static unsigned int loops = 1;
      
       static void preempt_printk_workfn(struct work_struct *work)
       {
       	int i;
      
       	while (!READ_ONCE(stop_testing)) {
       		for (i = 0; i < loops && !READ_ONCE(stop_testing); i++) {
       			preempt_disable();
       			pr_emerg("%5d%-75s\n", smp_processor_id(),
       				 " XXX NOPREEMPT");
       			preempt_enable();
       		}
       		msleep(1);
       	}
       }
      
       static struct work_struct __percpu *works;
      
       static void finish(void)
       {
       	int cpu;
      
       	WRITE_ONCE(stop_testing, true);
       	for_each_online_cpu(cpu)
       		flush_work(per_cpu_ptr(works, cpu));
       	free_percpu(works);
       }
      
       static int __init test_init(void)
       {
       	int cpu;
      
       	works = alloc_percpu(struct work_struct);
       	if (!works)
       		return -ENOMEM;
      
       	/*
       	 * This is just a test module. This will break if you
       	 * do any CPU hot plugging between loading and
       	 * unloading the module.
       	 */
      
       	for_each_online_cpu(cpu) {
       		struct work_struct *work = per_cpu_ptr(works, cpu);
      
       		INIT_WORK(work, &preempt_printk_workfn);
       		schedule_work_on(cpu, work);
       	}
      
       	return 0;
       }
      
       static void __exit test_exit(void)
       {
       	finish();
       }
      
       module_param(loops, uint, 0);
       module_init(test_init);
       module_exit(test_exit);
       MODULE_LICENSE("GPL");
      
      Link: http://lkml.kernel.org/r/20180110132418.7080-2-pmladek@suse.com
      Cc: akpm@linux-foundation.org
      Cc: linux-mm@kvack.org
      Cc: Cong Wang <xiyou.wangcong@gmail.com>
      Cc: Dave Hansen <dave.hansen@intel.com>
      Cc: Johannes Weiner <hannes@cmpxchg.org>
      Cc: Mel Gorman <mgorman@suse.de>
      Cc: Michal Hocko <mhocko@kernel.org>
      Cc: Vlastimil Babka <vbabka@suse.cz>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Jan Kara <jack@suse.cz>
      Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
      Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      Cc: Byungchul Park <byungchul.park@lge.com>
      Cc: Tejun Heo <tj@kernel.org>
      Cc: Pavel Machek <pavel@ucw.cz>
      Cc: linux-kernel@vger.kernel.org
      Signed-off-by: NSteven Rostedt (VMware) <rostedt@goodmis.org>
      [pmladek@suse.com: Commit message about possible deadlocks]
      Acked-by: NSergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Signed-off-by: NPetr Mladek <pmladek@suse.com>
      dbdda842
  11. 04 1月, 2018 1 次提交
    • S
      printk: add console_msg_format command line option · cca10d58
      Sergey Senozhatsky 提交于
      0day and kernelCI automatically parse kernel log - basically some sort
      of grepping using the pre-defined text patterns - in order to detect
      and report regressions/errors. There are several sources they get the
      kernel logs from:
      
      a) dmesg or /proc/ksmg
      
         This is the preferred way. Because `dmesg --raw' (see later Note)
         and /proc/kmsg output contains facility and log level, which greatly
         simplifies grepping for EMERG/ALERT/CRIT/ERR messages.
      
      b) serial consoles
      
         This option is harder to maintain, because serial console messages
         don't contain facility and log level.
      
      This patch introduces a `console_msg_format=' command line option,
      to switch between different message formatting on serial consoles.
      For the time being we have just two options - default and syslog.
      The "default" option just keeps the existing format. While the
      "syslog" option makes serial console messages to appear in syslog
      format [syslog() syscall], matching the `dmesg -S --raw' and
      `cat /proc/kmsg' output formats:
      
      - facility and log level
      - time stamp (depends on printk_time/PRINTK_TIME)
      - message
      
      	<%u>[time stamp] text\n
      
      NOTE: while Kevin and Fengguang talk about "dmesg --raw", it's actually
      "dmesg -S --raw" that always prints messages in syslog format [per
      Petr Mladek]. Running "dmesg --raw" may produce output in non-syslog
      format sometimes. console_msg_format=syslog enables syslog format,
      thus in documentation we mention "dmesg -S --raw", not "dmesg --raw".
      
      Per Kevin Hilman:
      
      : Right now we can get this info from a "dmesg --raw" after bootup,
      : but it would be really nice in certain automation frameworks to
      : have a kernel command-line option to enable printing of loglevels
      : in default boot log.
      :
      : This is especially useful when ingesting kernel logs into advanced
      : search/analytics frameworks (I'm playing with and ELK stack: Elastic
      : Search, Logstash, Kibana).
      :
      : The other important reason for having this on the command line is that
      : for testing linux-next (and other bleeding edge developer branches),
      : it's common that we never make it to userspace, so can't even run
      : "dmesg --raw" (or equivalent.)  So we really want this on the primary
      : boot (serial) console.
      
      Per Fengguang Wu, 0day scripts should quickly benefit from that
      feature, because they will be able to switch to a more reliable
      parsing, based on messages' facility and log levels [1]:
      
      `#{grep} -a -E -e '^<[0123]>' -e '^kern  :(err   |crit  |alert |emerg )'
      
      instead of doing text pattern matching
      
      `#{grep} -a -F -f /lkp/printk-error-messages #{kmsg_file} |
            grep -a -v -E -f #{LKP_SRC}/etc/oops-pattern |
            grep -a -v -F -f #{LKP_SRC}/etc/kmsg-blacklist`
      
      [1] https://github.com/fengguang/lkp-tests/blob/master/lib/dmesg.rb
      
      Link: http://lkml.kernel.org/r/20171221054149.4398-1-sergey.senozhatsky@gmail.com
      To: Steven Rostedt <rostedt@goodmis.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Fengguang Wu <fengguang.wu@intel.com>
      Cc: Kevin Hilman <khilman@baylibre.com>
      Cc: Mark Brown <broonie@kernel.org>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: LKML <linux-kernel@vger.kernel.org>
      Signed-off-by: NSergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Reviewed-by: NFengguang Wu <fengguang.wu@intel.com>
      Reviewed-by: NKevin Hilman <khilman@baylibre.com>
      Tested-by: NKevin Hilman <khilman@baylibre.com>
      Signed-off-by: NPetr Mladek <pmladek@suse.com>
      cca10d58
  12. 06 12月, 2017 1 次提交
  13. 28 11月, 2017 1 次提交
  14. 30 10月, 2017 1 次提交
  15. 18 8月, 2017 1 次提交
  16. 15 8月, 2017 1 次提交
  17. 27 7月, 2017 3 次提交
    • P
      printk/console: Enhance the check for consoles using init memory · 5a814231
      Petr Mladek 提交于
      printk_late_init() is responsible for disabling boot consoles that
      use init memory. It checks the address of struct console for this.
      
      But this is not enough. For example, there are several early
      consoles that have write() method in the init section and
      struct console in the normal section. They are not disabled
      and could cause fancy and hard to debug system states.
      
      It is even more complicated by the macros EARLYCON_DECLARE() and
      OF_EARLYCON_DECLARE() where various struct members are set at
      runtime by the provided setup() function.
      
      I have tried to reproduce this problem and forced the classic uart
      early console to stay using keep_bootcon parameter. In particular
      I used earlycon=uart,io,0x3f8 keep_bootcon console=ttyS0,115200.
      The system did not boot:
      
      [    1.570496] PM: Image not found (code -22)
      [    1.570496] PM: Image not found (code -22)
      [    1.571886] PM: Hibernation image not present or could not be loaded.
      [    1.571886] PM: Hibernation image not present or could not be loaded.
      [    1.576407] Freeing unused kernel memory: 2528K
      [    1.577244] kernel tried to execute NX-protected page - exploit attempt? (uid: 0)
      
      The double lines are caused by having both early uart console and
      ttyS0 console enabled at the same time. The early console stopped
      working when the init memory was freed. Fortunately, the invalid
      call was caught by the NX-protexted page check and did not cause
      any silent fancy problems.
      
      This patch adds a check for many other addresses stored in
      struct console. It omits setup() and match() that are used
      only when the console is registered. Therefore they have
      already been used at this point and there is no reason
      to use them again.
      
      Link: http://lkml.kernel.org/r/1500036673-7122-3-git-send-email-pmladek@suse.com
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Matt Redfearn <matt.redfearn@imgtec.com>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Jiri Slaby <jslaby@suse.com>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Alan Cox <gnomes@lxorguk.ukuu.org.uk>
      Cc: "Fabio M. Di Nitto" <fdinitto@redhat.com>
      Cc: linux-serial@vger.kernel.org
      Cc: linux-kernel@vger.kernel.org
      Reviewed-by: NSergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Signed-off-by: NPetr Mladek <pmladek@suse.com>
      5a814231
    • M
      printk/console: Always disable boot consoles that use init memory before it is freed · 2b1be689
      Matt Redfearn 提交于
      Commit 4c30c6f5 ("kernel/printk: do not turn off bootconsole in
      printk_late_init() if keep_bootcon") added a check on keep_bootcon to
      ensure that boot consoles were kept around until the real console is
      registered.
      
      This can lead to problems if the boot console data and code are in the
      init section, since it can be freed before the boot console is
      unregistered.
      
      Commit 81cc26f2 ("printk: only unregister boot consoles when
      necessary") fixed this a better way. It allowed to keep boot consoles
      that did not use init data. Unfortunately it did not remove the check
      of keep_bootcon.
      
      This can lead to crashes and weird panics when the bootconsole is
      accessed after free, especially if page poisoning is in use and the
      code / data have been overwritten with a poison value.
      
      To prevent this, always free the boot console if it is within the init
      section. In addition, print a warning about that the console is removed
      prematurely.
      
      Finally there is a new comment how to avoid the warning. It replaced
      an explanation that duplicated a more comprehensive function
      description few lines above.
      
      Fixes: 4c30c6f5 ("kernel/printk: do not turn off bootconsole in printk_late_init() if keep_bootcon")
      Link: http://lkml.kernel.org/r/1500036673-7122-2-git-send-email-pmladek@suse.com
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Jiri Slaby <jslaby@suse.com>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Alan Cox <gnomes@lxorguk.ukuu.org.uk>
      Cc: "Fabio M. Di Nitto" <fdinitto@redhat.com>
      Cc: linux-serial@vger.kernel.org
      Cc: linux-kernel@vger.kernel.org
      Signed-off-by: NMatt Redfearn <matt.redfearn@imgtec.com>
      [pmladek@suse.com: print the warning, code and comments clean up]
      Reviewed-by: NSergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Signed-off-by: NPetr Mladek <pmladek@suse.com>
      2b1be689
    • P
      printk: Modify operators of printed_len and text_len · aec47caa
      Pierre Kuo 提交于
      With commit <ddb9baa8> ("printk: report lost messages in printk
      safe/nmi contexts") and commit <8b1742c9> ("printk: remove zap_locks()
      function"), it seems we can remove initialization, "=0", of text_len and
      directly assign result of log_output to printed_len.
      
      Link: http://lkml.kernel.org/r/1499755255-6258-1-git-send-email-vichy.kuo@gmail.com
      Cc: rostedt@goodmis.org
      Cc: linux-kernel@vger.kernel.org
      Cc: joe@perches.com
      Signed-off-by: NPierre Kuo <vichy.kuo@gmail.com>
      Reviewed-by: NSergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Signed-off-by: NPetr Mladek <pmladek@suse.com>
      aec47caa
  18. 08 6月, 2017 1 次提交
    • P
      Revert "printk: fix double printing with earlycon" · dac8bbba
      Petr Mladek 提交于
      This reverts commit cf39bf58.
      
      The commit regression to users that define both console=ttyS1
      and console=ttyS0 on the command line, see
      https://lkml.kernel.org/r/20170509082915.GA13236@bistromath.localdomain
      
      The kernel log messages always appeared only on one serial port. It is
      even documented in Documentation/admin-guide/serial-console.rst:
      
      "Note that you can only define one console per device type (serial,
      video)."
      
      The above mentioned commit changed the order in which the command line
      parameters are searched. As a result, the kernel log messages go to
      the last mentioned ttyS* instead of the first one.
      
      We long thought that using two console=ttyS* on the command line
      did not make sense. But then we realized that console= parameters
      were handled also by systemd, see
      http://0pointer.de/blog/projects/serial-console.html
      
      "By default systemd will instantiate one serial-getty@.service on
      the main kernel console, if it is not a virtual terminal."
      
      where
      
      "[4] If multiple kernel consoles are used simultaneously, the main
      console is the one listed first in /sys/class/tty/console/active,
      which is the last one listed on the kernel command line."
      
      This puts the original report into another light. The system is running
      in qemu. The first serial port is used to store the messages into a file.
      The second one is used to login to the system via a socket. It depends
      on systemd and the historic kernel behavior.
      
      By other words, systemd causes that it makes sense to define both
      console=ttyS1 console=ttyS0 on the command line. The kernel fix
      caused regression related to userspace (systemd) and need to be
      reverted.
      
      In addition, it went out that the fix helped only partially.
      The messages still were duplicated when the boot console was
      removed early by late_initcall(printk_late_init). Then the entire
      log was replayed when the same console was registered as a normal one.
      
      Link: 20170606160339.GC7604@pathway.suse.cz
      Cc: Aleksey Makarov <aleksey.makarov@linaro.org>
      Cc: Sabrina Dubroca <sd@queasysnail.net>
      Cc: Sudeep Holla <sudeep.holla@arm.com>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Peter Hurley <peter@hurleysoftware.com>
      Cc: Jiri Slaby <jslaby@suse.com>
      Cc: Robin Murphy <robin.murphy@arm.com>,
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: "Nair, Jayachandran" <Jayachandran.Nair@cavium.com>
      Cc: linux-serial@vger.kernel.org
      Cc: linux-kernel@vger.kernel.org
      Reported-by: NSabrina Dubroca <sd@queasysnail.net>
      Acked-by: NSergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Signed-off-by: NPetr Mladek <pmladek@suse.com>
      dac8bbba
  19. 23 5月, 2017 1 次提交
  20. 19 5月, 2017 1 次提交
    • P
      printk: Use the main logbuf in NMI when logbuf_lock is available · 719f6a70
      Petr Mladek 提交于
      The commit 42a0bb3f ("printk/nmi: generic solution for safe
      printk in NMI") caused that printk stores messages into a temporary
      buffer in NMI context.
      
      The buffer is per-CPU and therefore the size is rather limited.
      It works quite well for NMI backtraces. But there are longer logs
      that might get printed in NMI context, for example, lockdep
      warnings, ftrace_dump_on_oops.
      
      The temporary buffer is used to avoid deadlocks caused by
      logbuf_lock. Also it is needed to avoid races with the other
      temporary buffer that is used when PRINTK_SAFE_CONTEXT is entered.
      But the main buffer can be used in NMI if the lock is available
      and we did not interrupt PRINTK_SAFE_CONTEXT.
      
      The lock is checked using raw_spin_is_locked(). It might cause
      false negatives when the lock is taken on another CPU and
      this CPU is in the safe context from other reasons. Note that
      the safe context is used also to get console semaphore or when
      calling console drivers. For this reason, we do the check in
      printk_nmi_enter(). It makes the handling consistent for
      the entire NMI handler and avoids reshuffling of the messages.
      
      The patch also defines special printk context that allows
      to use printk_deferred() in NMI. Note that we could not flush
      the messages to the consoles because console drivers might use
      many other internal locks.
      
      The newly created vprintk_deferred() disables the preemption
      only around the irq work handling. It is needed there to keep
      the consistency between the two per-CPU variables. But there
      is no reason to disable preemption around vprintk_emit().
      
      Finally, the patch puts back explicit serialization of the NMI
      backtraces from different CPUs. It was removed by the
      commit a9edc880 ("x86/nmi: Perform a safe
      NMI stack trace on all CPUs"). It was not needed because
      the flushing of the temporary per-CPU buffers was serialized.
      
      Link: http://lkml.kernel.org/r/1493912763-24873-1-git-send-email-pmladek@suse.com
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Russell King <rack+kernel@arm.linux.org.uk>
      Cc: Daniel Thompson <daniel.thompson@linaro.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Chris Metcalf <cmetcalf@ezchip.com>
      Cc: x86@kernel.org
      Cc: linux-arm-kernel@lists.infradead.org
      Cc: linux-kernel@vger.kernel.org
      Suggested-by: NSergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Acked-by: NSergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Signed-off-by: NPetr Mladek <pmladek@suse.com>
      719f6a70
  21. 09 5月, 2017 1 次提交
    • H
      crash: move crashkernel parsing and vmcore related code under CONFIG_CRASH_CORE · 692f66f2
      Hari Bathini 提交于
      Patch series "kexec/fadump: remove dependency with CONFIG_KEXEC and
      reuse crashkernel parameter for fadump", v4.
      
      Traditionally, kdump is used to save vmcore in case of a crash.  Some
      architectures like powerpc can save vmcore using architecture specific
      support instead of kexec/kdump mechanism.  Such architecture specific
      support also needs to reserve memory, to be used by dump capture kernel.
      crashkernel parameter can be a reused, for memory reservation, by such
      architecture specific infrastructure.
      
      This patchset removes dependency with CONFIG_KEXEC for crashkernel
      parameter and vmcoreinfo related code as it can be reused without kexec
      support.  Also, crashkernel parameter is reused instead of
      fadump_reserve_mem to reserve memory for fadump.
      
      The first patch moves crashkernel parameter parsing and vmcoreinfo
      related code under CONFIG_CRASH_CORE instead of CONFIG_KEXEC_CORE.  The
      second patch reuses the definitions of append_elf_note() & final_note()
      functions under CONFIG_CRASH_CORE in IA64 arch code.  The third patch
      removes dependency on CONFIG_KEXEC for firmware-assisted dump (fadump)
      in powerpc.  The next patch reuses crashkernel parameter for reserving
      memory for fadump, instead of the fadump_reserve_mem parameter.  This
      has the advantage of using all syntaxes crashkernel parameter supports,
      for fadump as well.  The last patch updates fadump kernel documentation
      about use of crashkernel parameter.
      
      This patch (of 5):
      
      Traditionally, kdump is used to save vmcore in case of a crash.  Some
      architectures like powerpc can save vmcore using architecture specific
      support instead of kexec/kdump mechanism.  Such architecture specific
      support also needs to reserve memory, to be used by dump capture kernel.
      crashkernel parameter can be a reused, for memory reservation, by such
      architecture specific infrastructure.
      
      But currently, code related to vmcoreinfo and parsing of crashkernel
      parameter is built under CONFIG_KEXEC_CORE.  This patch introduces
      CONFIG_CRASH_CORE and moves the above mentioned code under this config,
      allowing code reuse without dependency on CONFIG_KEXEC.  There is no
      functional change with this patch.
      
      Link: http://lkml.kernel.org/r/149035338104.6881.4550894432615189948.stgit@hbathini.in.ibm.comSigned-off-by: NHari Bathini <hbathini@linux.vnet.ibm.com>
      Acked-by: NDave Young <dyoung@redhat.com>
      Cc: Fenghua Yu <fenghua.yu@intel.com>
      Cc: Tony Luck <tony.luck@intel.com>
      Cc: Eric Biederman <ebiederm@xmission.com>
      Cc: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
      Cc: Vivek Goyal <vgoyal@redhat.com>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      692f66f2
  22. 19 4月, 2017 1 次提交
  23. 12 4月, 2017 3 次提交
  24. 04 4月, 2017 1 次提交
    • P
      printk: Correctly handle preemption in console_unlock() · 257ab443
      Petr Mladek 提交于
      Some console drivers code calls console_conditional_schedule()
      that looks at @console_may_schedule. The value must be cleared
      when the drivers are called from console_unlock() with
      interrupts disabled. But rescheduling is fine when the same
      code is called, for example, from tty operations where the
      console semaphore is taken via console_lock().
      
      This is why @console_may_schedule is cleared before calling console
      drivers. The original value is stored to decide if we could sleep
      between lines.
      
      Now, @console_may_schedule is not cleared when we call
      console_trylock() and jump back to the "again" goto label.
      This has become a problem, since the commit 6b97a20d
      ("printk: set may_schedule for some of console_trylock() callers").
      @console_may_schedule might get enabled now.
      
      There is also the opposite problem. console_lock() can be called
      only from preemptive context. It can always enable scheduling in
      the console code. But console_trylock() is not able to detect it
      when CONFIG_PREEMPT_COUNT is disabled. Therefore we should use the
      original @console_may_schedule value after re-acquiring
      the console semaphore in console_unlock().
      
      This patch solves both problems by moving the "again" goto label.
      
      Alternative solution was to clear and restore the value around
      call_console_drivers(). Then console_conditional_schedule() could
      be used also inside console_unlock(). But there was a potential race
      with console_flush_on_panic() as reported by Sergey Senozhatsky.
      That function should be called only where there is only one CPU
      and with interrupts disabled. But better be on the safe side
      because stopping CPUs might fail.
      
      Fixes: 6b97a20d ("printk: set may_schedule for some of console_trylock() callers")
      Link: http://lkml.kernel.org/r/1490372045-22288-1-git-send-email-pmladek@suse.comSuggested-by: NTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Jiri Slaby <jslaby@suse.cz>
      Cc: linux-fbdev@vger.kernel.org
      Cc: linux-kernel@vger.kernel.org
      Reviewed-by: NSergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Signed-off-by: NPetr Mladek <pmladek@suse.com>
      257ab443
  25. 24 3月, 2017 1 次提交
    • S
      printk: use console_trylock() in console_cpu_notify() · 64ca752d
      Sergey Senozhatsky 提交于
      There is no need to always call blocking console_lock() in
      console_cpu_notify(), it's quite possible that console_sem can
      be locked by other CPU on the system, either already printing
      or soon to begin printing the messages. console_lock() in this
      case can simply block CPU hotplug for unknown period of time
      (console_unlock() is time unbound). Not that hotplug is very
      fast, but still, with other CPUs being online and doing
      printk() console_cpu_notify() can stuck.
      
      Use console_trylock() instead and opt-out if console_sem is
      already acquired from another CPU, since that CPU will do
      the printing for us.
      
      Link: http://lkml.kernel.org/r/20170121104729.8585-1-sergey.senozhatsky@gmail.com
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: linux-kernel@vger.kernel.org
      Signed-off-by: NSergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Signed-off-by: NPetr Mladek <pmladek@suse.com>
      64ca752d
  26. 02 3月, 2017 3 次提交
  27. 19 2月, 2017 1 次提交
    • S
      printk: use rcuidle console tracepoint · fc98c3c8
      Sergey Senozhatsky 提交于
      Use rcuidle console tracepoint because, apparently, it may be issued
      from an idle CPU:
      
        hw-breakpoint: Failed to enable monitor mode on CPU 0.
        hw-breakpoint: CPU 0 failed to disable vector catch
      
        ===============================
        [ ERR: suspicious RCU usage.  ]
        4.10.0-rc8-next-20170215+ #119 Not tainted
        -------------------------------
        ./include/trace/events/printk.h:32 suspicious rcu_dereference_check() usage!
      
        other info that might help us debug this:
      
        RCU used illegally from idle CPU!
        rcu_scheduler_active = 2, debug_locks = 0
        RCU used illegally from extended quiescent state!
        2 locks held by swapper/0/0:
         #0:  (cpu_pm_notifier_lock){......}, at: [<c0237e2c>] cpu_pm_exit+0x10/0x54
         #1:  (console_lock){+.+.+.}, at: [<c01ab350>] vprintk_emit+0x264/0x474
      
        stack backtrace:
        CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.10.0-rc8-next-20170215+ #119
        Hardware name: Generic OMAP4 (Flattened Device Tree)
          console_unlock
          vprintk_emit
          vprintk_default
          printk
          reset_ctrl_regs
          dbg_cpu_pm_notify
          notifier_call_chain
          cpu_pm_exit
          omap_enter_idle_coupled
          cpuidle_enter_state
          cpuidle_enter_state_coupled
          do_idle
          cpu_startup_entry
          start_kernel
      
      This RCU warning, however, is suppressed by lockdep_off() in printk().
      lockdep_off() increments the ->lockdep_recursion counter and thus
      disables RCU_LOCKDEP_WARN() and debug_lockdep_rcu_enabled(), which want
      lockdep to be enabled "current->lockdep_recursion == 0".
      
      Link: http://lkml.kernel.org/r/20170217015932.11898-1-sergey.senozhatsky@gmail.comSigned-off-by: NSergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Reported-by: NTony Lindgren <tony@atomide.com>
      Tested-by: NTony Lindgren <tony@atomide.com>
      Acked-by: NPaul E. McKenney <paulmck@linux.vnet.ibm.com>
      Acked-by: NSteven Rostedt (VMware) <rostedt@goodmis.org>
      Cc: Petr Mladek <pmladek@suse.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Tony Lindgren <tony@atomide.com>
      Cc: Russell King <rmk@armlinux.org.uk>
      Cc: <stable@vger.kernel.org> [3.4+]
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      fc98c3c8
  28. 08 2月, 2017 5 次提交
    • S
      printk: drop call_console_drivers() unused param · d9c23523
      Sergey Senozhatsky 提交于
      We do suppress_message_printing() check before we call
      call_console_drivers() now, so `level' param is not needed
      anymore.
      
      Link: http://lkml.kernel.org/r/20161224140902.1962-2-sergey.senozhatsky@gmail.com
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: Peter Hurley <peter@hurleysoftware.com>
      Cc: linux-kernel@vger.kernel.org
      Signed-off-by: NSergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Signed-off-by: NPetr Mladek <pmladek@suse.com>
      d9c23523
    • S
      printk: convert the rest to printk-safe · de6fcbdb
      Sergey Senozhatsky 提交于
      This patch converts the rest of logbuf users (which are
      out of printk recursion case, but can deadlock in printk).
      To make printk-safe usage easier the patch introduces 4
      helper macros:
      - logbuf_lock_irq()/logbuf_unlock_irq()
        lock/unlock the logbuf lock and disable/enable local IRQ
      
      - logbuf_lock_irqsave(flags)/logbuf_unlock_irqrestore(flags)
        lock/unlock the logbuf lock and saves/restores local IRQ state
      
      Link: http://lkml.kernel.org/r/20161227141611.940-9-sergey.senozhatsky@gmail.com
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: Jan Kara <jack@suse.cz>
      Cc: Tejun Heo <tj@kernel.org>
      Cc: Calvin Owens <calvinowens@fb.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Peter Hurley <peter@hurleysoftware.com>
      Cc: linux-kernel@vger.kernel.org
      Signed-off-by: NSergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Signed-off-by: NPetr Mladek <pmladek@suse.com>
      de6fcbdb
    • S
      printk: remove zap_locks() function · 8b1742c9
      Sergey Senozhatsky 提交于
      We use printk-safe now which makes printk-recursion detection code
      in vprintk_emit() unreachable. The tricky thing here is that, apart
      from detecting and reporting printk recursions, that code also used
      to zap_locks() in case of panic() from the same CPU. However,
      zap_locks() does not look to be needed anymore:
      
      1) Since commit 08d78658 ("panic: release stale console lock to
         always get the logbuf printed out") panic flushing of `logbuf' to
         console ignores the state of `console_sem' by doing
         	panic()
      		console_trylock();
      		console_unlock();
      
      2) Since commit cf9b1106 ("printk/nmi: flush NMI messages on the
         system panic") panic attempts to zap the `logbuf_lock' spin_lock to
         successfully flush nmi messages to `logbuf'.
      
      Basically, it seems that we either already do what zap_locks() used to
      do but in other places or we ignore the state of the lock. The only
      reaming difference is that we don't re-init the console semaphore in
      printk_safe_flush_on_panic(), but this is not necessary because we
      don't call console drivers from printk_safe_flush_on_panic() due to
      the fact that we are using a deferred printk() version (as was
      suggested by Petr Mladek).
      
      Link: http://lkml.kernel.org/r/20161227141611.940-8-sergey.senozhatsky@gmail.com
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: Jan Kara <jack@suse.cz>
      Cc: Tejun Heo <tj@kernel.org>
      Cc: Calvin Owens <calvinowens@fb.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Peter Hurley <peter@hurleysoftware.com>
      Cc: linux-kernel@vger.kernel.org
      Signed-off-by: NSergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Signed-off-by: NPetr Mladek <pmladek@suse.com>
      8b1742c9
    • S
      printk: use printk_safe buffers in printk · f975237b
      Sergey Senozhatsky 提交于
      Use printk_safe per-CPU buffers in printk recursion-prone blocks:
      -- around logbuf_lock protected sections in vprintk_emit() and
         console_unlock()
      -- around down_trylock_console_sem() and up_console_sem()
      
      Note that this solution addresses deadlocks caused by printk()
      recursive calls only. That is vprintk_emit() and console_unlock().
      The rest will be converted in a followup patch.
      
      Another thing to note is that we now keep lockdep enabled in printk,
      because we are protected against the printk recursion caused by
      lockdep in vprintk_emit() by the printk-safe mechanism - we first
      switch to per-CPU buffers and only then access the deadlock-prone
      locks.
      
      Examples:
      
      1) printk() from logbuf_lock spin_lock section
      
      Assume the following code:
        printk()
          raw_spin_lock(&logbuf_lock);
          WARN_ON(1);
          raw_spin_unlock(&logbuf_lock);
      
      which now produces:
      
       ------------[ cut here ]------------
       WARNING: CPU: 0 PID: 366 at kernel/printk/printk.c:1811 vprintk_emit
       CPU: 0 PID: 366 Comm: bash
       Call Trace:
         warn_slowpath_null+0x1d/0x1f
         vprintk_emit+0x1cd/0x438
         vprintk_default+0x1d/0x1f
         printk+0x48/0x50
        [..]
      
      2) printk() from semaphore sem->lock spin_lock section
      
      Assume the following code
      
        printk()
          console_trylock()
            down_trylock()
              raw_spin_lock_irqsave(&sem->lock, flags);
              WARN_ON(1);
              raw_spin_unlock_irqrestore(&sem->lock, flags);
      
      which now produces:
      
       ------------[ cut here ]------------
       WARNING: CPU: 1 PID: 363 at kernel/locking/semaphore.c:141 down_trylock
       CPU: 1 PID: 363 Comm: bash
       Call Trace:
         warn_slowpath_null+0x1d/0x1f
         down_trylock+0x3d/0x62
         ? vprintk_emit+0x3f9/0x414
         console_trylock+0x31/0xeb
         vprintk_emit+0x3f9/0x414
         vprintk_default+0x1d/0x1f
         printk+0x48/0x50
        [..]
      
      3) printk() from console_unlock()
      
      Assume the following code:
      
        printk()
          console_unlock()
            raw_spin_lock(&logbuf_lock);
            WARN_ON(1);
            raw_spin_unlock(&logbuf_lock);
      
      which now produces:
      
       ------------[ cut here ]------------
       WARNING: CPU: 1 PID: 329 at kernel/printk/printk.c:2384 console_unlock
       CPU: 1 PID: 329 Comm: bash
       Call Trace:
         warn_slowpath_null+0x18/0x1a
         console_unlock+0x12d/0x559
         ? trace_hardirqs_on_caller+0x16d/0x189
         ? trace_hardirqs_on+0xd/0xf
         vprintk_emit+0x363/0x374
         vprintk_default+0x18/0x1a
         printk+0x43/0x4b
        [..]
      
      4) printk() from try_to_wake_up()
      
      Assume the following code:
      
        printk()
          console_unlock()
            up()
              try_to_wake_up()
                raw_spin_lock_irqsave(&p->pi_lock, flags);
                WARN_ON(1);
                raw_spin_unlock_irqrestore(&p->pi_lock, flags);
      
      which now produces:
      
       ------------[ cut here ]------------
       WARNING: CPU: 3 PID: 363 at kernel/sched/core.c:2028 try_to_wake_up
       CPU: 3 PID: 363 Comm: bash
       Call Trace:
         warn_slowpath_null+0x1d/0x1f
         try_to_wake_up+0x7f/0x4f7
         wake_up_process+0x15/0x17
         __up.isra.0+0x56/0x63
         up+0x32/0x42
         __up_console_sem+0x37/0x55
         console_unlock+0x21e/0x4c2
         vprintk_emit+0x41c/0x462
         vprintk_default+0x1d/0x1f
         printk+0x48/0x50
        [..]
      
      5) printk() from call_console_drivers()
      
      Assume the following code:
        printk()
          console_unlock()
            call_console_drivers()
            ...
                WARN_ON(1);
      
      which now produces:
      
       ------------[ cut here ]------------
       WARNING: CPU: 2 PID: 305 at kernel/printk/printk.c:1604 call_console_drivers
       CPU: 2 PID: 305 Comm: bash
       Call Trace:
         warn_slowpath_null+0x18/0x1a
         call_console_drivers.isra.6.constprop.16+0x3a/0xb0
         console_unlock+0x471/0x48e
         vprintk_emit+0x1f4/0x206
         vprintk_default+0x18/0x1a
         vprintk_func+0x6e/0x70
         printk+0x3e/0x46
        [..]
      
      6) unsupported placeholder in printk() format now prints an actual
         warning from vscnprintf(), instead of
         	'BUG: recent printk recursion!'.
      
       ------------[ cut here ]------------
       WARNING: CPU: 5 PID: 337 at lib/vsprintf.c:1900 format_decode
       Please remove unsupported %
        in format string
       CPU: 5 PID: 337 Comm: bash
       Call Trace:
         dump_stack+0x4f/0x65
         __warn+0xc2/0xdd
         warn_slowpath_fmt+0x4b/0x53
         format_decode+0x22c/0x308
         vsnprintf+0x89/0x3b7
         vscnprintf+0xd/0x26
         vprintk_emit+0xb4/0x238
         vprintk_default+0x1d/0x1f
         vprintk_func+0x6c/0x73
         printk+0x43/0x4b
        [..]
      
      Link: http://lkml.kernel.org/r/20161227141611.940-7-sergey.senozhatsky@gmail.com
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Jan Kara <jack@suse.cz>
      Cc: Tejun Heo <tj@kernel.org>
      Cc: Calvin Owens <calvinowens@fb.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Peter Hurley <peter@hurleysoftware.com>
      Cc: linux-kernel@vger.kernel.org
      Signed-off-by: NSergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Signed-off-by: NPetr Mladek <pmladek@suse.com>
      Reviewed-by: NSteven Rostedt (VMware) <rostedt@goodmis.org>
      f975237b
    • S
      printk: report lost messages in printk safe/nmi contexts · ddb9baa8
      Sergey Senozhatsky 提交于
      Account lost messages in pritk-safe and printk-safe-nmi
      contexts and report those numbers during printk_safe_flush().
      
      The patch also moves lost message counter to struct
      `printk_safe_seq_buf' instead of having dedicated static
      counters - this simplifies the code.
      
      Link: http://lkml.kernel.org/r/20161227141611.940-6-sergey.senozhatsky@gmail.com
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Steven Rostedt <rostedt@goodmis.org>
      Cc: Jan Kara <jack@suse.cz>
      Cc: Tejun Heo <tj@kernel.org>
      Cc: Calvin Owens <calvinowens@fb.com>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Andy Lutomirski <luto@kernel.org>
      Cc: Peter Hurley <peter@hurleysoftware.com>
      Cc: linux-kernel@vger.kernel.org
      Signed-off-by: NSergey Senozhatsky <sergey.senozhatsky@gmail.com>
      Signed-off-by: NPetr Mladek <pmladek@suse.com>
      ddb9baa8