1. 20 6月, 2022 1 次提交
  2. 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
  3. 10 2月, 2022 2 次提交
  4. 16 11月, 2021 1 次提交
  5. 10 11月, 2021 1 次提交
  6. 09 11月, 2021 1 次提交
  7. 08 11月, 2021 1 次提交
  8. 05 11月, 2021 2 次提交
  9. 19 10月, 2021 1 次提交
  10. 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
  11. 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
  12. 04 8月, 2021 5 次提交
  13. 02 8月, 2021 1 次提交
  14. 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
  15. 10 6月, 2021 3 次提交
  16. 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
  17. 17 12月, 2020 1 次提交
  18. 03 9月, 2020 1 次提交
  19. 09 7月, 2020 1 次提交
  20. 16 6月, 2020 1 次提交
  21. 03 6月, 2020 1 次提交
    • C
      mm: remove the pgprot argument to __vmalloc · 88dca4ca
      Christoph Hellwig 提交于
      The pgprot argument to __vmalloc is always PAGE_KERNEL now, so remove it.
      Signed-off-by: NChristoph Hellwig <hch@lst.de>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Reviewed-by: Michael Kelley <mikelley@microsoft.com> [hyperv]
      Acked-by: Gao Xiang <xiang@kernel.org> [erofs]
      Acked-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
      Acked-by: NWei Liu <wei.liu@kernel.org>
      Cc: Christian Borntraeger <borntraeger@de.ibm.com>
      Cc: Christophe Leroy <christophe.leroy@c-s.fr>
      Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
      Cc: David Airlie <airlied@linux.ie>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Haiyang Zhang <haiyangz@microsoft.com>
      Cc: Johannes Weiner <hannes@cmpxchg.org>
      Cc: "K. Y. Srinivasan" <kys@microsoft.com>
      Cc: Laura Abbott <labbott@redhat.com>
      Cc: Mark Rutland <mark.rutland@arm.com>
      Cc: Minchan Kim <minchan@kernel.org>
      Cc: Nitin Gupta <ngupta@vflare.org>
      Cc: Robin Murphy <robin.murphy@arm.com>
      Cc: Sakari Ailus <sakari.ailus@linux.intel.com>
      Cc: Stephen Hemminger <sthemmin@microsoft.com>
      Cc: Sumit Semwal <sumit.semwal@linaro.org>
      Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
      Cc: Paul Mackerras <paulus@ozlabs.org>
      Cc: Vasily Gorbik <gor@linux.ibm.com>
      Cc: Will Deacon <will@kernel.org>
      Link: http://lkml.kernel.org/r/20200414131348.444715-22-hch@lst.deSigned-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      88dca4ca
  22. 06 11月, 2019 2 次提交
  23. 31 5月, 2019 1 次提交
  24. 28 3月, 2019 1 次提交
    • T
      ALSA: Replace snd_malloc_pages() and snd_free_pages() with standard helpers, take#2 · 734b5a0b
      Takashi Iwai 提交于
      snd_malloc_pages() and snd_free_pages() are merely thin wrappers of
      the standard page allocator / free functions.  Even the arguments are
      compatible with some standard helpers, so there is little merit of
      keeping these wrappers.
      
      This patch replaces the all existing callers of snd_malloc_pages() and
      snd_free_pages() with the direct calls of the standard helper
      functions.  In this version, we use a recently introduced one,
      alloc_pages_exact(), which suits better than the old
      snd_malloc_pages() implementation for our purposes.  Then we can avoid
      the waste of pages by alignment to power-of-two.
      
      Since alloc_pages_exact() does split pages, we need no longer
      __GFP_COMP flag; or better to say, we must not pass __GFP_COMP to
      alloc_pages_exact().  So the former unconditional addition of
      __GFP_COMP flag in snd_malloc_pages() is dropped, as well as in most
      other places.
      Reviewed-by: NTakashi Sakamoto <o-takashi@sakamocchi.jp>
      Acked-by: NMichal Hocko <mhocko@suse.com>
      Signed-off-by: NTakashi Iwai <tiwai@suse.de>
      734b5a0b
  25. 05 2月, 2019 1 次提交
  26. 12 10月, 2018 1 次提交
  27. 28 8月, 2018 3 次提交
    • T
      ALSA: memalloc: Add non-cached buffer type · 42e748a0
      Takashi Iwai 提交于
      In some cases (mainly for x86), we need the DMA coherent buffer with
      non-cached pages.  Although this has been done in each driver side
      like HD-audio and intel8x0, it can be done cleaner in the core memory
      allocator.
      
      This patch adds the new types, SNDRV_DMA_TYPE_DEV_UC and
      SNDRV_DMA_TYPE_DEV_UC_SG, for allocating such non-cached buffer
      pages.  On non-x86 architectures, they work as same as the standard
      SNDRV_DMA_TYPE_DEV and *_SG.
      
      One additional change by this move is that we can assure to pass the
      non-cached pgprot to the vmapped buffer, too.  It eventually fixes the
      case like non-snoop mode without mmap access on HD-audio.
      Signed-off-by: NTakashi Iwai <tiwai@suse.de>
      42e748a0
    • T
      ALSA: memalloc: Simplify snd_malloc_dev_pages() calls · 28f3f4f6
      Takashi Iwai 提交于
      snd_malloc_dev_pages() and snd_free_dev_pages() are local functions
      and the parameters passed there are all contained in snd_dma_buffer
      object.  As a code-simplification, pass snd_dma_buffer object and
      assign the address there like other allocators do (except for
      snd_malloc_pages() which is called from outside, hence we can't change
      easily).
      
      Only code refactoring, no functional changes.
      Signed-off-by: NTakashi Iwai <tiwai@suse.de>
      28f3f4f6
    • T
      ALSA: memalloc: Don't align the size to power-of-two · 03486830
      Takashi Iwai 提交于
      The size passed to dma_alloc_coherent() doesn't have to be aligned
      with power-of-two, rather it should be the raw size.  As a minor
      optimization, remove the size adjustment in the current code.
      Signed-off-by: NTakashi Iwai <tiwai@suse.de>
      03486830