1. 27 1月, 2023 1 次提交
  2. 21 12月, 2022 1 次提交
  3. 21 11月, 2022 1 次提交
    • C
      ALSA: memalloc: don't pass bogus GFP_ flags to dma_alloc_* · 3306877a
      Christoph Hellwig 提交于
      dma_alloc_coherent/dma_alloc_wc is an opaque allocator that only uses
      the GFP_ flags for allocation context control.  Don't pass __GFP_COMP
      which makes no sense for an allocation that can't in any way be
      converted to a page pointer.
      
      Note that for dma_alloc_noncoherent and dma_alloc_noncontigous in
      combination with the DMA mmap helpers __GFP_COMP looks sketchy as well,
      so I would suggest to drop that as well after a careful audit.
      Signed-off-by: NChristoph Hellwig <hch@lst.de>
      3306877a
  4. 16 11月, 2022 1 次提交
    • T
      ALSA: memalloc: Allocate more contiguous pages for fallback case · cc265163
      Takashi Iwai 提交于
      Currently the fallback SG allocation tries to allocate each single
      page, and this tends to result in the reverse order of memory
      addresses when large space is available at boot, as the kernel takes a
      free page from the top to the bottom in the zone.  The end result
      looks as if non-contiguous (although it actually is).  What's worse is
      that it leads to an overflow of BDL entries for HD-audio.
      
      For avoiding such a problem, this patch modifies the allocation code
      slightly; now it tries to allocate the larger contiguous chunks as
      much as possible, then reduces to the smaller chunks only if the
      allocation failed -- a similar strategy as the existing
      snd_dma_alloc_pages_fallback() function.
      
      Along with the trick, drop the unused address array from
      snd_dma_sg_fallback object.  It was needed in the past when
      dma_alloc_coherent() was used, but with the standard page allocator,
      it became superfluous and never referred.
      
      Fixes: a8d302a0 ("ALSA: memalloc: Revive x86-specific WC page allocations again")
      Reviewed-by: NKai Vehmanen <kai.vehmanen@linux.intel.com>
      Link: https://lore.kernel.org/r/20221114141658.29620-1-tiwai@suse.deSigned-off-by: NTakashi Iwai <tiwai@suse.de>
      cc265163
  5. 12 11月, 2022 1 次提交
  6. 10 11月, 2022 1 次提交
  7. 26 9月, 2022 1 次提交
    • K
      ALSA: memalloc: use __GFP_RETRY_MAYFAIL for DMA mem allocs · a61c7d88
      Kai Vehmanen 提交于
      Use __GFP_RETRY_MAYFAIL instead of __GFP__NORETRY in
      snd_dma_dev_alloc(), snd_dma_wc_alloc() and friends, to allocate pages
      for device memory. The MAYFAIL flag retains the semantics of not
      triggering the OOM killer, but lowers the risk of alloc failure.
      
      MAYFAIL flag was added in commit dcda9b04 ("mm, tree wide: replace
      __GFP_REPEAT by __GFP_RETRY_MAYFAIL with more useful semantic").
      
      This change addresses recurring failures with SOF audio driver in test
      cases where a system suspend-resume stress test is run, combined with an
      active high memory-load use-case. The failure typically shows up as:
      
      [ 379.480229] sof-audio-pci-intel-tgl 0000:00:1f.3: booting DSP firmware
      [ 379.484803] sof-audio-pci-intel-tgl 0000:00:1f.3: error: memory alloc failed: -12
      [ 379.484810] sof-audio-pci-intel-tgl 0000:00:1f.3: error: dma prepare for ICCMAX stream failed
      
      Multiple fixes to reduce the memory usage of DSP boot have been
      identified in SOF driver, but even with those fixes, debug on affected
      systems has shown that even a single page alloc may fail with
      __GFP_NORETRY. When this occurs, system is under significant load on
      physical memory, but a lot of reclaimable pages are available, so the
      system has not run out of memory. With __GFP_RETRY_MAYFAIL, the errors
      are not hit in these stress tests.
      
      The alloc failure is severe as audio capability is completely lost if
      alloc failure is hit at system resume.
      
      An alternative solution was considered where the resources for DSP boot
      would be kept allocated until driver is unbound. This would avoid the
      allocation failure, but consume memory that is only needed temporarily
      at probe and resume time. It seems better to not hang on to the memory,
      but rather work a bit harder for allocating the pages at resume.
      
      BugLink: https://github.com/thesofproject/linux/issues/3844Signed-off-by: NKai Vehmanen <kai.vehmanen@linux.intel.com>
      Reviewed-by: NPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
      Link: https://lore.kernel.org/r/20220923153501.3326041-1-kai.vehmanen@linux.intel.comSigned-off-by: NTakashi Iwai <tiwai@suse.de>
      a61c7d88
  8. 06 9月, 2022 1 次提交
  9. 24 8月, 2022 1 次提交
  10. 22 8月, 2022 1 次提交
  11. 13 7月, 2022 1 次提交
  12. 20 6月, 2022 1 次提交
  13. 13 4月, 2022 1 次提交
    • T
      ALSA: memalloc: Add fallback SG-buffer allocations for x86 · 925ca893
      Takashi Iwai 提交于
      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: NTakashi Iwai <tiwai@suse.de>
      925ca893
  14. 10 2月, 2022 2 次提交
  15. 16 11月, 2021 1 次提交
  16. 10 11月, 2021 1 次提交
  17. 09 11月, 2021 1 次提交
  18. 08 11月, 2021 1 次提交
  19. 05 11月, 2021 2 次提交
  20. 19 10月, 2021 1 次提交
  21. 18 10月, 2021 3 次提交
    • T
      ALSA: memalloc: Convert x86 SG-buffer handling with non-contiguous type · 2d9ea399
      Takashi Iwai 提交于
      We've had an x86-specific SG-buffer handling code, but now it can be
      merged gracefully with the standard non-contiguous DMA pages.
      
      After the migration, SNDRV_DMA_TYPE_DMA_SG becomes identical with
      SNDRV_DMA_TYPE_NONCONTIG on x86, while others still fall back to
      SNDRV_DMA_TYPE_DEV.
      
      The remaining problem is about the SG-buffer with WC pages: the DMA
      core stuff on x86 doesn't treat it well, so we still need some special
      handling to manipulate the page attribute manually.  The mmap handler
      for SNDRV_DMA_TYPE_DEV_SG_WC still returns -ENOENT intentionally for
      the fallback to the default handler.
      
      Link: https://lore.kernel.org/r/20211017074859.24112-4-tiwai@suse.deSigned-off-by: NTakashi Iwai <tiwai@suse.de>
      2d9ea399
    • T
      ALSA: memalloc: Support for non-coherent page allocation · 73325f60
      Takashi Iwai 提交于
      Following to the addition of non-contiguous pages, this patch adds the
      new contiguous non-coherent page allocation to the standard memalloc
      helper.  Like the previous non-contig type, this non-coherent type is
      also directional and requires the explicit sync, too.  Hence the
      driver using this type of buffer may need to set
      SNDRV_PCM_INFO_EXPLICIT_SYNC flag to the PCM hardware.info as well,
      unless it's set up in the managed mode.
      
      Link: https://lore.kernel.org/r/20211017074859.24112-3-tiwai@suse.deSigned-off-by: NTakashi Iwai <tiwai@suse.de>
      73325f60
    • T
      ALSA: memalloc: Support for non-contiguous page allocation · a25684a9
      Takashi Iwai 提交于
      This patch adds the support for allocation of non-contiguous DMA pages
      in the common memalloc helper.  It's another SG-buffer type, but
      unlike the existing one, this is directional and requires the explicit
      sync / invalidation of dirty pages on non-coherent architectures.
      
      For this enhancement, the following points are changed:
      - snd_dma_device stores the DMA direction.
      - snd_dma_device stores need_sync flag indicating whether the explicit
        sync is required or not.
      - A new variant of helper functions, snd_dma_alloc_dir_pages() and
        *_all() are introduced; the old snd_dma_alloc_pages() and *_all()
        kept as just wrappers with DMA_BIDIRECTIONAL.
      - A new helper snd_dma_buffer_sync() is introduced; this gets called
        in the appropriate places.
      - A new allocation type, SNDRV_DMA_TYPE_NONCONTIG, is introduced.
      
      When the driver allocates pages with this new type, and it may require
      the SNDRV_PCM_INFO_EXPLICIT_SYNC flag set to the PCM hardware.info for
      taking the full control of PCM applptr and hwptr changes (that implies
      disabling the mmap of control/status data).  When the buffer
      allocation is managed by snd_pcm_set_managed_buffer(), this flag is
      automatically set depending on the result of dma_need_sync()
      internally.  Otherwise, if the buffer is managed manually, the driver
      has to set the flag explicitly, too.
      
      The explicit sync between CPU and device for non-coherent memory is
      performed at the points before and after read/write transfer as well
      as the applptr/hwptr syncptr ioctl.  In the case of mmap mode,
      user-space is supposed to call the syncptr ioctl with the hwptr flag
      to update and fetch the status at first; this corresponds to CPU-sync.
      Then user-space advances the applptr via syncptr ioctl again with
      applptr flag, and this corresponds to the device sync with flushing.
      
      Other than the DMA direction and the explicit sync, the usage of this
      new buffer type is almost equivalent with the existing
      SNDRV_DMA_TYPE_DEV_SG; you can get the page and the address via
      snd_sgbuf_get_page() and snd_sgbuf_get_addr(), also calculate the
      continuous pages via snd_sgbuf_get_chunk_size().
      
      For those SG-page handling, the non-contig type shares the same ops
      with the vmalloc handler.  As we do always vmap the SG pages at first,
      the actual address can be deduced from the vmapped address easily
      without iterating the SG-list.
      
      Link: https://lore.kernel.org/r/20211017074859.24112-2-tiwai@suse.deSigned-off-by: NTakashi Iwai <tiwai@suse.de>
      a25684a9
  22. 13 8月, 2021 1 次提交
    • T
      ALSA: memalloc: Count continuous pages in vmalloc buffer handler · bda36b0f
      Takashi Iwai 提交于
      This is an enhancement for the SG-style page handling in vmalloc
      buffer handler to calculate the continuous pages.
      When snd_sgbuf_get_chunk_size() is called for a vmalloc buffer,
      currently we return only the size that fits into a single page.
      However, this API call is rather supposed for obtaining the continuous
      pages and most of vmalloc or noncontig buffers do have lots of
      continuous pages indeed.  So, in this patch, the callback now
      calculates the possibly continuous pages up to the given size limit.
      
      Note that the end address in the function is calculated from the last
      byte, hence it's one byte shorter.  This is because ofs + size can be
      above the actual buffer size boundary.
      
      Until now, this feature isn't really used, but it'll become useful in
      a later patch that adds the non-contiguous buffer type that shares the
      same callback function as vmalloc.
      
      Link: https://lore.kernel.org/r/20210812113818.6479-1-tiwai@suse.de
      Link: https://lore.kernel.org/r/20210813081645.4680-1-tiwai@suse.deSigned-off-by: NTakashi Iwai <tiwai@suse.de>
      bda36b0f
  23. 04 8月, 2021 5 次提交
  24. 02 8月, 2021 1 次提交
  25. 19 7月, 2021 1 次提交
    • T
      ALSA: core: Add device-managed page allocator helper · 427ae268
      Takashi Iwai 提交于
      This is a preparation for allowing devres usages more widely in
      various sound drivers.  As a first step, this patch adds a new
      allocator function, snd_devm_alloc_pages(), to manage the allocated
      pages via devres, so that the pages will be automagically released as
      device unbinding.
      
      Unlike the old snd_dma_alloc_pages(), the new function returns
      directly the snd_dma_buffer pointer.  The caller needs NULL-check for
      the allocation error appropriately.
      
      Also, since a real device pointer is mandatory for devres,
      SNDRV_DMA_TYPE_CONTINUOUS or SNDRV_DMA_TYPE_VMALLOC type can't be used
      for this function.
      
      Link: https://lore.kernel.org/r/20210715075941.23332-2-tiwai@suse.deSigned-off-by: NTakashi Iwai <tiwai@suse.de>
      427ae268
  26. 10 6月, 2021 3 次提交
  27. 19 12月, 2020 1 次提交
    • T
      ALSA: memalloc: Align buffer allocations in page size · 5c1733e3
      Takashi Iwai 提交于
      Currently the standard memory allocator (snd_dma_malloc_pages*())
      passes the byte size to allocate as is.  Most of the backends
      allocates real pages, hence the actual allocations are aligned in page
      size.  However, the genalloc doesn't seem assuring the size alignment,
      hence it may result in the access outside the buffer when the whole
      memory pages are exposed via mmap.
      
      For avoiding such inconsistencies, this patch makes the allocation
      size always to be aligned in page size.
      
      Note that, after this change, snd_dma_buffer.bytes field contains the
      aligned size, not the originally requested size.  This value is also
      used for releasing the pages in return.
      Reviewed-by: NLars-Peter Clausen <lars@metafoo.de>
      Link: https://lore.kernel.org/r/20201218145625.2045-2-tiwai@suse.deSigned-off-by: NTakashi Iwai <tiwai@suse.de>
      5c1733e3
  28. 17 12月, 2020 1 次提交
  29. 03 9月, 2020 1 次提交
  30. 09 7月, 2020 1 次提交