Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
  1. Jul 28, 2024
    • Linus Torvalds's avatar
      minmax: make generic MIN() and MAX() macros available everywhere · 1a251f52
      Linus Torvalds authored
      This just standardizes the use of MIN() and MAX() macros, with the very
      traditional semantics.  The goal is to use these for C constant
      expressions and for top-level / static initializers, and so be able to
      simplify the min()/max() macros.
      
      These macro names were used by various kernel code - they are very
      traditional, after all - and all such users have been fixed up, with a
      few different approaches:
      
       - trivial duplicated macro definitions have been removed
      
         Note that 'trivial' here means that it's obviously kernel code that
         already included all the major kernel headers, and thus gets the new
         generic MIN/MAX macros automatically.
      
       - non-trivial duplicated macro definitions are guarded with #ifndef
      
         This is the "yes, they define their own versions, but no, the include
         situation is not entirely obvious, and maybe they don't get the
         generic version automatically" case.
      
       - strange use case #1
      
         A couple of drivers decided...
      1a251f52
  2. Jul 26, 2024
  3. Jul 25, 2024
  4. Jul 24, 2024
  5. Jul 23, 2024
  6. Jul 22, 2024
  7. Jul 20, 2024
  8. Jul 19, 2024
    • Jason A. Donenfeld's avatar
      selftests/vDSO: add tests for vgetrandom · 4920a259
      Jason A. Donenfeld authored
      
      This adds two tests for vgetrandom. The first one, vdso_test_chacha,
      simply checks that the assembly implementation of chacha20 matches that
      of libsodium, a basic sanity check that should catch most errors. The
      second, vdso_test_getrandom, is a full "libc-like" implementation of the
      userspace side of vgetrandom() support. It's meant to be used also as
      example code for libcs that might be integrating this.
      
      Cc: linux-kselftest@vger.kernel.org
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      4920a259
    • Jason A. Donenfeld's avatar
      mm: add MAP_DROPPABLE for designating always lazily freeable mappings · 9651fced
      Jason A. Donenfeld authored
      
      The vDSO getrandom() implementation works with a buffer allocated with a
      new system call that has certain requirements:
      
      - It shouldn't be written to core dumps.
        * Easy: VM_DONTDUMP.
      - It should be zeroed on fork.
        * Easy: VM_WIPEONFORK.
      
      - It shouldn't be written to swap.
        * Uh-oh: mlock is rlimited.
        * Uh-oh: mlock isn't inherited by forks.
      
      - It shouldn't reserve actual memory, but it also shouldn't crash when
        page faulting in memory if none is available
        * Uh-oh: VM_NORESERVE means segfaults.
      
      It turns out that the vDSO getrandom() function has three really nice
      characteristics that we can exploit to solve this problem:
      
      1) Due to being wiped during fork(), the vDSO code is already robust to
         having the contents of the pages it reads zeroed out midway through
         the function's execution.
      
      2) In the absolute worst case of whatever contingency we're coding for,
         we have the option to fallback to the getrandom() syscall, and
         everything is fine.
      
      3) The buffers the function uses are only ever useful for a maximum of
         60 seconds -- a sort of cache, rather than a long term allocation.
      
      These characteristics mean that we can introduce VM_DROPPABLE, which
      has the following semantics:
      
      a) It never is written out to swap.
      b) Under memory pressure, mm can just drop the pages (so that they're
         zero when read back again).
      c) It is inherited by fork.
      d) It doesn't count against the mlock budget, since nothing is locked.
      e) If there's not enough memory to service a page fault, it's not fatal,
         and no signal is sent.
      
      This way, allocations used by vDSO getrandom() can use:
      
          VM_DROPPABLE | VM_DONTDUMP | VM_WIPEONFORK | VM_NORESERVE
      
      And there will be no problem with OOMing, crashing on overcommitment,
      using memory when not in use, not wiping on fork(), coredumps, or
      writing out to swap.
      
      In order to let vDSO getrandom() use this, expose these via mmap(2) as
      MAP_DROPPABLE.
      
      Note that this involves removing the MADV_FREE special case from
      sort_folio(), which according to Yu Zhao is unnecessary and will simply
      result in an extra call to shrink_folio_list() in the worst case. The
      chunk removed reenables the swapbacked flag, which we don't want for
      VM_DROPPABLE, and we can't conditionalize it here because there isn't a
      vma reference available.
      
      Finally, the provided self test ensures that this is working as desired.
      
      Cc: linux-mm@kvack.org
      Acked-by: default avatarDavid Hildenbrand <david@redhat.com>
      Signed-off-by: default avatarJason A. Donenfeld <Jason@zx2c4.com>
      9651fced
  9. Jul 18, 2024
    • Mark Brown's avatar
      kselftest/alsa: Log the PCM ID in pcm-test · 4594d26f
      Mark Brown authored
      
      Drivers report a string with a name for each PCM, log it during startup of
      pcm-test as a diagnostic aid.
      
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Link: https://patch.msgid.link/20240716-alsa-kselftest-board-name-v2-2-60f1acdde096@kernel.org
      
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      4594d26f
    • Mark Brown's avatar
      kselftest/alsa: Use card name rather than number in test names · b1a7b97a
      Mark Brown authored
      
      Currently for the PCM and mixer tests we report test names which identify
      the card being tested with the card number. This ensures we have unique
      names but since card numbers are dynamically assigned at runtime the names
      we end up with will often not be stable on systems with multiple cards
      especially where those cards are provided by separate modules loeaded at
      runtime. This makes it difficult for automated systems and UIs to relate
      test results between runs on affected platforms.
      
      Address this by replacing our use of card numbers with card names which are
      more likely to be stable across runs. We use the card ID since it is
      guaranteed to be unique by default, unlike the long name. There is still
      some vulnerability to ordering issues if multiple cards with the same base
      ID are present in the system but have separate dependencies but not all
      drivers put distinguishing information in their long names.
      
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Link: https://patch.msgid.link/20240716-alsa-kselftest-board-name-v2-1-60f1acdde096@kernel.org
      
      
      Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      b1a7b97a
    • Ido Schimmel's avatar
      ipv4: Fix incorrect TOS in fibmatch route get reply · f036e682
      Ido Schimmel authored
      The TOS value that is returned to user space in the route get reply is
      the one with which the lookup was performed ('fl4->flowi4_tos'). This is
      fine when the matched route is configured with a TOS as it would not
      match if its TOS value did not match the one with which the lookup was
      performed.
      
      However, matching on TOS is only performed when the route's TOS is not
      zero. It is therefore possible to have the kernel incorrectly return a
      non-zero TOS:
      
       # ip link add name dummy1 up type dummy
       # ip address add 192.0.2.1/24 dev dummy1
       # ip route get fibmatch 192.0.2.2 tos 0xfc
       192.0.2.0/24 tos 0x1c dev dummy1 proto kernel scope link src 192.0.2.1
      
      Fix by instead returning the DSCP field from the FIB result structure
      which was populated during the route lookup.
      
      Output after the patch:
      
       # ip link add name dummy1 up type dummy
       # ip address add 192.0.2.1/24 dev dummy1
       # ip route get fibmatch 192.0.2.2 tos 0xfc
       192.0.2.0/24 dev dummy1 proto kernel scope link src 192.0.2.1
      
      Extend the existing selftests to not only verify that the correct route
      is returned, but that it is also returned with correct "tos" value (or
      without it).
      
      Fixes: b6179813
      
       ("net: ipv4: RTM_GETROUTE: return matched fib result when requested")
      Signed-off-by: default avatarIdo Schimmel <idosch@nvidia.com>
      Reviewed-by: default avatarDavid Ahern <dsahern@kernel.org>
      Reviewed-by: default avatarGuillaume Nault <gnault@redhat.com>
      Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
      f036e682
  10. Jul 17, 2024