1. 27 10月, 2016 1 次提交
  2. 10 10月, 2016 1 次提交
    • L
      printk: reinstate KERN_CONT for printing continuation lines · 4bcc595c
      Linus Torvalds 提交于
      Long long ago the kernel log buffer was a buffered stream of bytes, very
      much like stdio in user space.  It supported log levels by scanning the
      stream and noticing the log level markers at the beginning of each line,
      but if you wanted to print a partial line in multiple chunks, you just
      did multiple printk() calls, and it just automatically worked.
      
      Except when it didn't, and you had very confusing output when different
      lines got all mixed up with each other.  Then you got fragment lines
      mixing with each other, or with non-fragment lines, because it was
      traditionally impossible to tell whether a printk() call was a
      continuation or not.
      
      To at least help clarify the issue of continuation lines, we added a
      KERN_CONT marker back in 2007 to mark continuation lines:
      
        47492527 ("printk: add KERN_CONT annotation").
      
      That continuation marker was initially an empty string, and didn't
      actuall make any semantic difference.  But it at least made it possible
      to annotate the source code, and have check-patch notice that a printk()
      didn't need or want a log level marker, because it was a continuation of
      a previous line.
      
      To avoid the ambiguity between a continuation line that had that
      KERN_CONT marker, and a printk with no level information at all, we then
      in 2009 made KERN_CONT be a real log level marker which meant that we
      could now reliably tell the difference between the two cases.
      
        5fd29d6c ("printk: clean up handling of log-levels and newlines")
      
      and we could take advantage of that to make sure we didn't mix up
      continuation lines with lines that just didn't have any loglevel at all.
      
      Then, in 2012, the kernel log buffer was changed to be a "record" based
      log, where each line was a record that has a loglevel and a timestamp.
      
      You can see the beginning of that conversion in commits
      
        e11fea92 ("kmsg: export printk records to the /dev/kmsg interface")
        7ff9554b ("printk: convert byte-buffer to variable-length record buffer")
      
      with a number of follow-up commits to fix some painful fallout from that
      conversion.  Over all, it took a couple of months to sort out most of
      it.  But the upside was that you could have concurrent readers (and
      writers) of the kernel log and not have lines with mixed output in them.
      
      And one particular pain-point for the record-based kernel logging was
      exactly the fragmentary lines that are generated in smaller chunks.  In
      order to still log them as one recrod, the continuation lines need to be
      attached to the previous record properly.
      
      However the explicit continuation record marker that is actually useful
      for this exact case was actually removed in aroundm the same time by commit
      
        61e99ab8 ("printk: remove the now unnecessary "C" annotation for KERN_CONT")
      
      due to the incorrect belief that KERN_CONT wasn't meaningful.  The
      ambiguity between "is this a continuation line" or "is this a plain
      printk with no log level information" was reintroduced, and in fact
      became an even bigger pain point because there was now the whole
      record-level merging of kernel messages going on.
      
      This patch reinstates the KERN_CONT as a real non-empty string marker,
      so that the ambiguity is fixed once again.
      
      But it's not a plain revert of that original removal: in the four years
      since we made KERN_CONT an empty string again, not only has the format
      of the log level markers changed, we've also had some usage changes in
      this area.
      
      For example, some ACPI code seems to use KERN_CONT _together_ with a log
      level, and now uses both the KERN_CONT marker and (for example) a
      KERN_INFO marker to show that it's an informational continuation of a
      line.
      
      Which is actually not a bad idea - if the continuation line cannot be
      attached to its predecessor, without the log level information we don't
      know what log level to assign to it (and we traditionally just assigned
      it the default loglevel).  So having both a log level and the KERN_CONT
      marker is not necessarily a bad idea, but it does mean that we need to
      actually iterate over potentially multiple markers, rather than just a
      single one.
      
      Also, since KERN_CONT was still conceptually needed, and encouraged, but
      didn't actually _do_ anything, we've also had the reverse problem:
      rather than having too many annotations it has too few, and there is bit
      rot with code that no longer marks the continuation lines with the
      KERN_CONT marker.
      
      So this patch not only re-instates the non-empty KERN_CONT marker, it
      also fixes up the cases of bit-rot I noticed in my own logs.
      
      There are probably other cases where KERN_CONT will be needed to be
      added, either because it is new code that never dealt with the need for
      KERN_CONT, or old code that has bitrotted without anybody noticing.
      
      That said, we should strive to avoid the need for KERN_CONT.  It does
      result in real problems for logging, and should generally not be seen as
      a good feature.  If we some day can get rid of the feature entirely,
      because nobody does any fragmented printk calls, that would be lovely.
      
      But until that point, let's at mark the code that relies on the hacky
      multi-fragment kernel printk's.  Not only does it avoid the ambiguity,
      it also annotates code as "maybe this would be good to fix some day".
      
      (That said, particularly during single-threaded bootup, the downsides of
      KERN_CONT are very limited.  Things get much hairier when you have
      multiple threads going on and user level reading and writing logs too).
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      4bcc595c
  3. 22 9月, 2016 5 次提交
  4. 26 6月, 2016 12 次提交
  5. 04 5月, 2016 2 次提交
  6. 01 5月, 2016 4 次提交
  7. 07 2月, 2016 1 次提交
    • M
      tty: vt: initialize softcursor_original correctly · e882f715
      Melchior FRANZ 提交于
      add_softcursor() stores the contents of the text buffer position in this
      variable before drawing the softcursor, whereas hide_softcursor() writes
      the value back. A value of -1 means that no cursor has been drawn and
      therefore no character is to be restored. softcursor_original, however,
      is only implicitly initialized with 0. Therefore, when hide_softcursor
      is called for the first time (console_init -> con_init -> redraw_screen
      -> hide_cursor), it wrongly writes 0x0000 in the top left corner of
      the text buffer. Normally, this is just as black as the rest of the
      screen (vc_video_erase_char) and can't be seen, but it appears as a
      black cursor rectangle on non-black backgrounds e.g. with boot option
      "vt.global_cursor_default=0 vt.color=0xf0". softcursor_original needs
      to be initialized with -1.
      Signed-off-by: NMelchior FRANZ <mfranz@aon.at>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e882f715
  8. 29 1月, 2016 1 次提交
  9. 14 12月, 2015 1 次提交
  10. 24 7月, 2015 1 次提交
    • D
      tty/vt: Fix the memory leak in visual_init · 08b33249
      Dongxing Zhang 提交于
      If vc->vc_uni_pagedir_loc is not NULL, its refcount needs to be
      decreased before vc_uni_pagedir_loc is re-assigned.
      
      unreferenced object 0xffff88002cdd13b0 (size 512):
        comm "setfont", pid 503, jiffies 4294896503 (age 722.828s)
        hex dump (first 32 bytes):
          40 92 61 2b 00 88 ff ff 00 00 00 00 00 00 00 00  @.a+............
          00 00 00 00 00 00 00 00 a0 ad 61 2b 00 88 ff ff  ..........a+....
        backtrace:
          [<ffffffff817b755e>] kmemleak_alloc+0x4e/0xb0
          [<ffffffff811d4898>] kmem_cache_alloc_trace+0x1c8/0x240
          [<ffffffff814ae7d3>] con_do_clear_unimap.isra.2+0x83/0xe0
          [<ffffffff814ae9b2>] con_clear_unimap+0x22/0x40
          [<ffffffff814a8db8>] vt_ioctl+0xeb8/0x1170
          [<ffffffff8149b458>] tty_ioctl+0x208/0xca0
          [<ffffffff81207858>] do_vfs_ioctl+0x2f8/0x510
          [<ffffffff81207af1>] SyS_ioctl+0x81/0xa0
          [<ffffffff817ca2b2>] system_call_fastpath+0x16/0x75
          [<ffffffffffffffff>] 0xffffffffffffffff
      unreferenced object 0xffff88002b619240 (size 256):
        comm "setfont", pid 503, jiffies 4294896503 (age 722.828s)
        hex dump (first 32 bytes):
          90 bc 84 d5 00 88 ff ff 58 85 84 d5 00 88 ff ff  ........X.......
          88 ac 84 d5 00 88 ff ff e0 b1 84 d5 00 88 ff ff  ................
        backtrace:
          [<ffffffff817b755e>] kmemleak_alloc+0x4e/0xb0
          [<ffffffff811d4898>] kmem_cache_alloc_trace+0x1c8/0x240
          [<ffffffff814ae286>] con_insert_unipair+0x86/0x170
          [<ffffffff814af107>] con_set_unimap+0x1b7/0x280
          [<ffffffff814a8d65>] vt_ioctl+0xe65/0x1170
          [<ffffffff8149b458>] tty_ioctl+0x208/0xca0
          [<ffffffff81207858>] do_vfs_ioctl+0x2f8/0x510
          [<ffffffff81207af1>] SyS_ioctl+0x81/0xa0
          [<ffffffff817ca2b2>] system_call_fastpath+0x16/0x75
          [<ffffffffffffffff>] 0xffffffffffffffff
      Signed-off-by: NDongxing Zhang <dongxing.zhang@intel.com>
      Signed-off-by: NXiaoming Wang <xiaoming.wang@intel.com>
      Reviewed-by: NPeter Hurley <peter@hurleysoftware.com>
      Tested-by: NKonstantin Khlebnikov <khlebnikov@yandex-team.ru>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      08b33249
  11. 11 5月, 2015 3 次提交
    • D
      vt: Don't check KD_GRAPHICS when binding/unbinding · 77232f79
      Daniel Vetter 提交于
      This was introduced in
      
      commit 6db4063c
      Author: Antonino A. Daplas <adaplas@gmail.com>
      Date:   Mon Jun 26 00:27:12 2006 -0700
      
          [PATCH] VT binding: Add sysfs control to the VT layer
      
      with the justification
      
          "In addition, if any of the consoles are in KD_GRAPHICS mode, binding and
          unbinding will not succeed.  KD_GRAPHICS mode usually indicates that the
          underlying console hardware is used for other purposes other than displaying
          text (ie X).  This feature should prevent binding/unbinding from interfering
          with a graphics application using the VT."
      
      I think we should lift this artificial restriction though:
      - KD_GRAPHICS doesn't get cleaned up automatically, which means it's
        easy to have terminals stuck in KD_GRAPHICS when hacking around on
        X.
      - X doesn't really care, especially with drm where kms already blocks
        fbdev (and hence fbcon) when there's an active compositor.
      - This is a root-only interface with a separate .config option and
        it's possible to hang your machine already anyway if you
        unload/reload drivers and don't know what you're doing.
      
      With this patch i915.ko module reloading works again reliably,
      something in the recent fedora upgrades broke things.
      
      Cc: Antonino A. Daplas <adaplas@gmail.com>
      Cc: Peter Hurley <peter@hurleysoftware.com>
      Cc: Imre Deak <imre.deak@intel.com>
      Signed-off-by: NDaniel Vetter <daniel.vetter@intel.com>
      Acked-by: NDavid Herrmann <dh.herrmann@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      77232f79
    • I
      vt: fix console lock vs. kernfs s_active lock order · d364b5c3
      Imre Deak 提交于
      Currently there is a lock order problem between the console lock and the
      kernfs s_active lock of the console driver's bind sysfs entry. When
      writing to the sysfs entry the lock order is first s_active then console
      lock, when unregistering the console driver via
      do_unregister_con_driver() the order is the opposite. See the below
      bugzilla reference for one instance of a lockdep backtrace.
      
      Fix this by unregistering the console driver from a deferred work, where
      we can safely drop the console lock while unregistering the device and
      corresponding sysfs entries (which in turn acquire s_active). Note that
      we have to keep the console driver slot in the registered_con_driver
      array reserved for the driver that's being unregistered until it's fully
      removed. Otherwise a concurrent call to do_register_con_driver could
      try to reuse the same slot and fail when registering the corresponding
      device with a minor index that's still in use.
      
      Note that the referenced bug report contains two dmesg logs with two
      distinct lockdep reports: [1] is about a locking scenario involving
      s_active, console_lock and the fb_notifier list lock, while [2] is
      about a locking scenario involving only s_active and console_lock.
      In [1] locking fb_notifier triggers the lockdep warning only because
      of its dependence on console_lock, otherwise case [1] is the same
      s_active<->console_lock dependency problem fixed by this patch.
      Before this change we have the following locking scenarios involving
      the 3 locks:
      
      a) via do_unregister_framebuffer()->...->do_unregister_con_driver():
         1. console lock 2. fb_notifier lock 3. s_active lock
      b) for example via give_up_console()->do_unregister_con_driver():
         1. console lock 2. s_active lock
      c) via vt_bind()/vt_unbind():
         1. s_active lock 2. console lock
      
      Since c) is the console bind sysfs entry's write code path we can't
      change the locking order there. We can only fix this issue by removing
      s_active's dependence on the other two locks in a) and b). We can do
      this only in the vt code which owns the corresponding sysfs entry, so
      that after the change we have:
      
      a) 1. console lock 2. fb_notifier lock
      b) 1. console lock
      c) 1. s_active lock 2. console lock
      d) in the new con_driver_unregister_callback():
         1. s_active lock
      
      [1] https://bugs.freedesktop.org/attachment.cgi?id=87716
      [2] https://bugs.freedesktop.org/attachment.cgi?id=107602
      
      v2:
      - get console_lock earlier in con_driver_unregister_callback(), so we
        protect the following console driver field assignments there
      - add code coment explaining the reason for deferring the sysfs entry
        removal
      - add a third paragraph to the commit message explaining why there are
        two distinct lockdep reports and that this issue is independent of
        fb/fbcon. (Peter Hurley)
      v3:
      - clarify further the third paragraph
      v4:
      - rebased on v4 of patch 1/3
      Signed-off-by: NImre Deak <imre.deak@intel.com>
      Reviewed-by: NDaniel Vetter <daniel.vetter@ffwll.ch>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d364b5c3
    • S
      vt: add cursor blink interval escape sequence · bd63364c
      Scot Doyle 提交于
      Add an escape sequence to specify the current console's cursor blink
      interval. The interval is specified as a number of milliseconds until
      the next cursor display state toggle, from 50 to 65535. /proc/loadavg
      did not show a difference with a one msec interval, but the lower
      bound is set to 50 msecs since slower hardware wasn't tested.
      
      Store the interval in the vc_data structure for later access by fbcon,
      initializing the value to fbcon's current hardcoded value of 200 msecs.
      Signed-off-by: NScot Doyle <lkml14@scotdoyle.com>
      Acked-by: NPavel Machek <pavel@ucw.cz>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bd63364c
  12. 26 3月, 2015 1 次提交
  13. 07 3月, 2015 2 次提交
  14. 03 2月, 2015 1 次提交
  15. 10 1月, 2015 2 次提交
    • I
      vt: fix locking around vt_bind/vt_unbind · 4c215fe8
      Imre Deak 提交于
      Currently vt_bind and vt_unbind access at least the con_driver object
      and registered_con_driver array without holding the console lock. Fix
      this by locking around the whole function in each case.
      Signed-off-by: NImre Deak <imre.deak@intel.com>
      Reviewed-by: NPeter Hurley <peter@hurleysoftware.com>
      Reviewed-by: NDaniel Vetter <daniel.vetter@ffwll.ch>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4c215fe8
    • I
      vt: fix check for system/busy console drivers when unregistering them · 2cf30f75
      Imre Deak 提交于
      The default console driver (conswitchp) and busy drivers bound to a
      console (as reported by con_is_bound()) shouldn't be unregistered.
      System console drivers (without the CON_DRIVER_FLAG_MODULE flag) can be
      unregistered, provided they are neither default nor busy. The current
      code checks for the CON_DRIVER_FLAG_INIT flag but this doesn't make
      sense: this flag is set for a driver whenever its associated console's
      con_startup() function is called, which first happens when the console
      driver is registered (so before the console gets bound) and gets cleared
      when the console gets unbound. The purpose of this flag is to show if we
      need to call con_startup() on a console before we use it.
      
      Based on the above, do_unregister_con_driver() in its current form will
      allow unregistering a console driver only if it was never bound, but
      will refuse to unregister one that was bound and later unbound.
      
      Fix this by dropping the CON_DRIVER_FLAG_INIT check, allowing
      unregistering of any console driver provided that it's not the default
      one and it's not busy.
      
      v2:
      - reword the third paragraph to clarify how the fix works (Peter Hurley)
      v3:
      - unchanged
      v4:
      - Allow unregistering a system console driver too, needed by i915 to
        unregister vgacon. Update commit description accordingly. (Daniel)
      Signed-off-by: NImre Deak <imre.deak@intel.com>
      Reviewed-by: NDaniel Vetter <daniel.vetter@ffwll.ch>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2cf30f75
  16. 26 11月, 2014 1 次提交
  17. 22 11月, 2014 1 次提交