1. 13 Apr, 2022 2 commits
    • Takashi Iwai's avatar
      ALSA: usb-audio: Limit max buffer and period sizes per time · 24d0c9f0
      Takashi Iwai authored
      In the previous fix, we increased the max buffer bytes from 1MB to 4MB
      so that we can use bigger buffers for the modern HiFi devices with
      higher rates, more channels and wider formats.  OTOH, extending this
      has a concern that too big buffer is allowed for the lower rates, less
      channels and narrower formats; when an application tries to allocate
      as big buffer as possible, it'll lead to unexpectedly too huge size.
      
      Also, we had a problem about the inconsistent max buffer and period
      bytes for the implicit feedback mode when both streams have different
      channels.  This was fixed by the (relatively complex) patch to reduce
      the max buffer and period bytes accordingly.
      
      This is an alternative fix for those, a patch to kill two birds with
      one stone (*): instead of increasing the max buffer bytes blindly and
      applying the reduction per channels, we simply use the hw constraints
      for the buffer and period "time".  Meanwhile the max buffer and period
      bytes are set unlimited instead.
      
      Since the inconsistency of buffer (and period) bytes comes from the
      difference of the channels in the tied streams, as long as we care
      only about the buffer (and period) time, it doesn't matter; the buffer
      time is same for different channels, although we still allow higher
      buffer size.  Similarly, this will allow more buffer bytes for HiFi
      devices while it also keeps the reasonable size for the legacy
      devices, too.
      
      As of this patch, the max period and buffer time are set to 1 and 2
      seconds, which should be large enough for all possible use cases.
      
      (*) No animals were harmed in the making of this patch.
      
      Fixes: 98c27add ("ALSA: usb-audio: Cap upper limits of buffer/period bytes for implicit fb")
      Fixes: fee2ec8c ("ALSA: usb-audio: Increase max buffer size")
      Link: https://lore.kernel.org/r/20220412130740.18933-1-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      24d0c9f0
    • Takashi Iwai's avatar
      ALSA: memalloc: Add fallback SG-buffer allocations for x86 · 925ca893
      Takashi Iwai authored
      The recent change for memory allocator replaced the SG-buffer handling
      helper for x86 with the standard non-contiguous page handler.  This
      works for most cases, but there is a corner case I obviously
      overlooked, namely, the fallback of non-contiguous handler without
      IOMMU.  When the system runs without IOMMU, the core handler tries to
      use the continuous pages with a single SGL entry.  It works nicely for
      most cases, but when the system memory gets fragmented, the large
      allocation may fail frequently.
      
      Ideally the non-contig handler could deal with the proper SG pages,
      it's cumbersome to extend for now.  As a workaround, here we add new
      types for (minimalistic) SG allocations, instead, so that the
      allocator falls back to those types automatically when the allocation
      with the standard API failed.
      
      BTW, one better (but pretty minor) improvement from the previous
      SG-buffer code is that this provides the proper mmap support without
      the PCM's page fault handling.
      
      Fixes: 2c95b92e ("ALSA: memalloc: Unify x86 SG-buffer handling (take#3)")
      BugLink: https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/2272
      BugLink: https://bugzilla.suse.com/show_bug.cgi?id=1198248
      Cc: <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20220413054808.7547-1-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
      925ca893
  2. 12 Apr, 2022 38 commits