05 Jan, 2020

1 commit

  • [ Upstream commit 9ff6aa027dbb98755f0265695354f2dd07c0d1ce ]

    debug_dma_dump_mappings() can take a lot of cpu cycles :

    lpk43:/# time wc -l /sys/kernel/debug/dma-api/dump
    163435 /sys/kernel/debug/dma-api/dump

    real 0m0.463s
    user 0m0.003s
    sys 0m0.459s

    Let's add a cond_resched() to avoid holding cpu for too long.

    Signed-off-by: Eric Dumazet
    Cc: Corentin Labbe
    Cc: Christoph Hellwig
    Cc: Marek Szyprowski
    Signed-off-by: Christoph Hellwig
    Signed-off-by: Sasha Levin

    Eric Dumazet
     

05 Jun, 2019

1 commit

  • Based on 1 normalized pattern(s):

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license version 2 as
    published by the free software foundation this program is
    distributed in the hope that it will be useful but without any
    warranty without even the implied warranty of merchantability or
    fitness for a particular purpose see the gnu general public license
    for more details you should have received a copy of the gnu general
    public license along with this program if not write to the free
    software foundation inc 59 temple place suite 330 boston ma 02111
    1307 usa

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-only

    has been chosen to replace the boilerplate/reference in 136 file(s).

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Alexios Zavras
    Reviewed-by: Allison Randal
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190530000436.384967451@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

29 Apr, 2019

1 commit

  • Replace the indirection through struct stack_trace with an invocation of
    the storage array based interface.

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Christoph Hellwig
    Reviewed-by: Josh Poimboeuf
    Cc: Andy Lutomirski
    Cc: iommu@lists.linux-foundation.org
    Cc: Robin Murphy
    Cc: Marek Szyprowski
    Cc: Steven Rostedt
    Cc: Alexander Potapenko
    Cc: Alexey Dobriyan
    Cc: Andrew Morton
    Cc: Christoph Lameter
    Cc: Pekka Enberg
    Cc: linux-mm@kvack.org
    Cc: David Rientjes
    Cc: Catalin Marinas
    Cc: Dmitry Vyukov
    Cc: Andrey Ryabinin
    Cc: kasan-dev@googlegroups.com
    Cc: Mike Rapoport
    Cc: Akinobu Mita
    Cc: Johannes Thumshirn
    Cc: David Sterba
    Cc: Chris Mason
    Cc: Josef Bacik
    Cc: linux-btrfs@vger.kernel.org
    Cc: dm-devel@redhat.com
    Cc: Mike Snitzer
    Cc: Alasdair Kergon
    Cc: Daniel Vetter
    Cc: intel-gfx@lists.freedesktop.org
    Cc: Joonas Lahtinen
    Cc: Maarten Lankhorst
    Cc: dri-devel@lists.freedesktop.org
    Cc: David Airlie
    Cc: Jani Nikula
    Cc: Rodrigo Vivi
    Cc: Tom Zanussi
    Cc: Miroslav Benes
    Cc: linux-arch@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190425094802.248658135@linutronix.de

    Thomas Gleixner
     

12 Apr, 2019

1 commit

  • With skip set to 1, I get a traceback like this:

    [ 106.867637] DMA-API: Mapped at:
    [ 106.870784] afu_dma_map_region+0x2cd/0x4f0 [dfl_afu]
    [ 106.875839] afu_ioctl+0x258/0x380 [dfl_afu]
    [ 106.880108] do_vfs_ioctl+0xa9/0x720
    [ 106.883688] ksys_ioctl+0x60/0x90
    [ 106.887007] __x64_sys_ioctl+0x16/0x20

    With the previous value of 2, afu_dma_map_region was being omitted. I
    suspect that the code paths have simply changed since the value of 2 was
    chosen a decade ago, but it's also possible that it varies based on which
    mapping function was used, compiler inlining choices, etc. In any case,
    it's best to err on the side of skipping less.

    Signed-off-by: Scott Wood
    Signed-off-by: Christoph Hellwig

    Scott Wood
     

01 Feb, 2019

2 commits

  • While debugging a DMA mapping leak, I needed to access
    debug_dma_dump_mappings() but easily from user space.

    This patch adds a /sys/kernel/debug/dma-api/dump file which contain all
    current DMA mapping.

    Signed-off-by: Corentin Labbe
    Signed-off-by: Christoph Hellwig

    Corentin Labbe
     
  • When calling debugfs functions, there is no need to ever check the
    return value. The function can work or not, but the code logic should
    never do something different based on this.

    Also delete the variables for the file dentries for the debugfs entries
    as they are never used at all once they are created.

    Signed-off-by: Greg Kroah-Hartman
    Reviewed-by: Robin Murphy
    [hch: moved dma_debug_dent to function scope and renamed it]
    Signed-off-by: Christoph Hellwig

    Greg Kroah-Hartman
     

04 Jan, 2019

2 commits

  • Now that the slow path DMA API calls are implemented out of line a few
    helpers only used by them don't need to be exported anymore.

    Signed-off-by: Christoph Hellwig

    Christoph Hellwig
     
  • And also switch the way we implement the unmap side around to stay
    consistent. This ensures dma-debug works again because it records which
    function we used for mapping to ensure it is also used for unmapping,
    and also reduces further code duplication. Last but not least this
    also officially allows calling dma_sync_single_* for mappings created
    using dma_map_page, which is perfectly fine given that the sync calls
    only take a dma_addr_t, but not a virtual address or struct page.

    Fixes: 7f0fee242e ("dma-mapping: merge dma_unmap_page_attrs and dma_unmap_single_attrs")
    Signed-off-by: Christoph Hellwig
    Tested-by: LABBE Corentin

    Christoph Hellwig
     

14 Dec, 2018

1 commit


11 Dec, 2018

6 commits

  • DMA debug entries are one of those things which aren't that useful
    individually - we will always want some larger quantity of them - and
    which we don't really need to manage the exact number of - we only care
    about having 'enough'. In that regard, the current behaviour of creating
    them one-by-one leads to a lot of unwarranted function call overhead and
    memory wasted on alignment padding.

    Now that we don't have to worry about freeing anything via
    dma_debug_resize_entries(), we can optimise the allocation behaviour by
    grabbing whole pages at once, which will save considerably on the
    aforementioned overheads, and probably offer a little more cache/TLB
    locality benefit for traversing the lists under normal operation. This
    should also give even less reason for an architecture-level override of
    the preallocation size, so make the definition unconditional - if there
    is still any desire to change the compile-time value for some platforms
    it would be better off as a Kconfig option anyway.

    Since freeing a whole page of entries at once becomes enough of a
    challenge that it's not really worth complicating dma_debug_init(), we
    may as well tweak the preallocation behaviour such that as long as we
    manage to allocate *some* pages, we can leave debugging enabled on a
    best-effort basis rather than otherwise wasting them.

    Signed-off-by: Robin Murphy
    Tested-by: Qian Cai
    Signed-off-by: Christoph Hellwig

    Robin Murphy
     
  • With the only caller now gone, we can clean up this part of dma-debug's
    exposed internals and make way to tweak the allocation behaviour.

    Signed-off-by: Robin Murphy
    Tested-by: Qian Cai
    Signed-off-by: Christoph Hellwig

    Robin Murphy
     
  • Now that we can dynamically allocate DMA debug entries to cope with
    drivers maintaining excessively large numbers of live mappings, a driver
    which *does* actually have a bug leaking mappings (and is not unloaded)
    will no longer trigger the "DMA-API: debugging out of memory - disabling"
    message until it gets to actual kernel OOM conditions, which means it
    could go unnoticed for a while. To that end, let's inform the user each
    time the pool has grown to a multiple of its initial size, which should
    make it apparent that they either have a leak or might want to increase
    the preallocation size.

    Signed-off-by: Robin Murphy
    Tested-by: Qian Cai
    Signed-off-by: Christoph Hellwig

    Robin Murphy
     
  • Certain drivers such as large multi-queue network adapters can use pools
    of mapped DMA buffers larger than the default dma_debug_entry pool of
    65536 entries, with the result that merely probing such a device can
    cause DMA debug to disable itself during boot unless explicitly given an
    appropriate "dma_debug_entries=..." option.

    Developers trying to debug some other driver on such a system may not be
    immediately aware of this, and at worst it can hide bugs if they fail to
    realise that dma-debug has already disabled itself unexpectedly by the
    time their code of interest gets to run. Even once they do realise, it
    can be a bit of a pain to emprirically determine a suitable number of
    preallocated entries to configure, short of massively over-allocating.

    There's really no need for such a static limit, though, since we can
    quite easily expand the pool at runtime in those rare cases that the
    preallocated entries are insufficient, which is arguably the least
    surprising and most useful behaviour. To that end, refactor the
    prealloc_memory() logic a little bit to generalise it for runtime
    reallocations as well.

    Signed-off-by: Robin Murphy
    Tested-by: Qian Cai
    Signed-off-by: Christoph Hellwig

    Robin Murphy
     
  • Use pr_fmt() to generate the "DMA-API: " prefix consistently. This
    results in it being added to a couple of pr_*() messages which were
    missing it before, and for the err_printk() calls moves it to the actual
    start of the message instead of somewhere in the middle.

    Signed-off-by: Robin Murphy
    Tested-by: Qian Cai
    Signed-off-by: Christoph Hellwig

    Robin Murphy
     
  • Expose nr_total_entries in debugfs, so that {num,min}_free_entries
    become even more meaningful to users interested in current/maximum
    utilisation. This becomes even more relevant once nr_total_entries
    may change at runtime beyond just the existing AMD GART debug code.

    Suggested-by: John Garry
    Signed-off-by: Robin Murphy
    Tested-by: Qian Cai
    Signed-off-by: Christoph Hellwig

    Robin Murphy
     

08 Oct, 2018

1 commit

  • I recently debugged a DMA mapping oops where a driver was trying to map
    a buffer returned from request_firmware() with dma_map_single(). Memory
    returned from request_firmware() is mapped into the vmalloc region and
    this isn't a valid region to map with dma_map_single() per the DMA
    documentation's "What memory is DMA'able?" section.

    Unfortunately, we don't really check that in the DMA debugging code, so
    enabling DMA debugging doesn't help catch this problem. Let's add a new
    DMA debug function to check for a vmalloc address or an invalid virtual
    address and print a warning if this happens. This makes it a little
    easier to debug these sorts of problems, instead of seeing odd behavior
    or crashes when drivers attempt to map the vmalloc space for DMA.

    Cc: Marek Szyprowski
    Reviewed-by: Robin Murphy
    Signed-off-by: Stephen Boyd
    Signed-off-by: Christoph Hellwig

    Stephen Boyd
     

14 Jun, 2018

1 commit

  • Currently the code is split over various files with dma- prefixes in the
    lib/ and drives/base directories, and the number of files keeps growing.
    Move them into a single directory to keep the code together and remove
    the file name prefixes. To match the irq infrastructure this directory
    is placed under the kernel/ directory.

    Signed-off-by: Christoph Hellwig

    Christoph Hellwig