Skip to content
  1. Apr 17, 2024
    • Steven Rostedt (Google)'s avatar
      ring-buffer: Only update pages_touched when a new page is touched · 53e494b7
      Steven Rostedt (Google) authored
      commit ffe3986f upstream.
      
      The "buffer_percent" logic that is used by the ring buffer splice code to
      only wake up the tasks when there's no data after the buffer is filled to
      the percentage of the "buffer_percent" file is dependent on three
      variables that determine the amount of data that is in the ring buffer:
      
       1) pages_read - incremented whenever a new sub-buffer is consumed
       2) pages_lost - incremented every time a writer overwrites a sub-buffer
       3) pages_touched - incremented when a write goes to a new sub-buffer
      
      The percentage is the calculation of:
      
        (pages_touched - (pages_lost + pages_read)) / nr_pages
      
      Basically, the amount of data is the total number of sub-bufs that have been
      touched, minus the number of sub-bufs lost and sub-bufs consumed. This is
      divided by the total count to give the buffer percentage. When the
      percentage is greater than the value in the "buffer_percent" file, it
      wakes up splice readers waiting for that amount.
      
      It was observed that over time, the amount read from the splice was
      constantly decreasing the longer the trace was running. That is, if one
      asked for 60%, it would read over 60% when it first starts tracing, but
      then it would be woken up at under 60% and would slowly decrease the
      amount of data read after being woken up, where the amount becomes much
      less than the buffer percent.
      
      This was due to an accounting of the pages_touched incrementation. This
      value is incremented whenever a writer transfers to a new sub-buffer. But
      the place where it was incremented was incorrect. If a writer overflowed
      the current sub-buffer it would go to the next one. If it gets preempted
      by an interrupt at that time, and the interrupt performs a trace, it too
      will end up going to the next sub-buffer. But only one should increment
      the counter. Unfortunately, that was not the case.
      
      Change the cmpxchg() that does the real switch of the tail-page into a
      try_cmpxchg(), and on success, perform the increment of pages_touched. This
      will only increment the counter once for when the writer moves to a new
      sub-buffer, and not when there's a race and is incremented for when a
      writer and its preempting writer both move to the same new sub-buffer.
      
      Link: https://lore.kernel.org/linux-trace-kernel/20240409151309.0d0e5056@gandalf.local.home
      
      
      
      Cc: stable@vger.kernel.org
      Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
      Fixes: 2c2b0a78 ("ring-buffer: Add percentage of ring buffer full to wake up reader")
      Acked-by: default avatarMasami Hiramatsu (Google) <mhiramat@kernel.org>
      Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      53e494b7
    • Sven Eckelmann's avatar
      batman-adv: Avoid infinite loop trying to resize local TT · 87b6af1a
      Sven Eckelmann authored
      
      
      commit b1f532a3 upstream.
      
      If the MTU of one of an attached interface becomes too small to transmit
      the local translation table then it must be resized to fit inside all
      fragments (when enabled) or a single packet.
      
      But if the MTU becomes too low to transmit even the header + the VLAN
      specific part then the resizing of the local TT will never succeed. This
      can for example happen when the usable space is 110 bytes and 11 VLANs are
      on top of batman-adv. In this case, at least 116 byte would be needed.
      There will just be an endless spam of
      
         batman_adv: batadv0: Forced to purge local tt entries to fit new maximum fragment MTU (110)
      
      in the log but the function will never finish. Problem here is that the
      timeout will be halved all the time and will then stagnate at 0 and
      therefore never be able to reduce the table even more.
      
      There are other scenarios possible with a similar result. The number of
      BATADV_TT_CLIENT_NOPURGE entries in the local TT can for example be too
      high to fit inside a packet. Such a scenario can therefore happen also with
      only a single VLAN + 7 non-purgable addresses - requiring at least 120
      bytes.
      
      While this should be handled proactively when:
      
      * interface with too low MTU is added
      * VLAN is added
      * non-purgeable local mac is added
      * MTU of an attached interface is reduced
      * fragmentation setting gets disabled (which most likely requires dropping
        attached interfaces)
      
      not all of these scenarios can be prevented because batman-adv is only
      consuming events without the the possibility to prevent these actions
      (non-purgable MAC address added, MTU of an attached interface is reduced).
      It is therefore necessary to also make sure that the code is able to handle
      also the situations when there were already incompatible system
      configuration are present.
      
      Cc: stable@vger.kernel.org
      Fixes: a19d3d85 ("batman-adv: limit local translation table max size")
      Reported-by: default avatar <syzbot+a6a4b5bb3da165594cff@syzkaller.appspotmail.com>
      Signed-off-by: default avatarSven Eckelmann <sven@narfation.org>
      Signed-off-by: default avatarSimon Wunderlich <sw@simonwunderlich.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      87b6af1a
  2. Apr 13, 2024