06 Oct, 2020

1 commit


21 Sep, 2020

1 commit


11 Sep, 2020

1 commit


15 Aug, 2020

2 commits

  • This remoes the code from the COW path to call debug_dma_assert_idle(),
    which was added many years ago.

    Google shows that it hasn't caught anything in the 6+ years we've had it
    apart from a false positive, and Hugh just noticed how it had a very
    unfortunate spinlock serialization in the COW path.

    He fixed that issue the previous commit (a85ffd59bd36: "dma-debug: fix
    debug_dma_assert_idle(), use rcu_read_lock()"), but let's see if anybody
    even notices when we remove this function entirely.

    NOTE! We keep the dma tracking infrastructure that was added by the
    commit that introduced it. Partly to make it easier to resurrect this
    debug code if we ever deside to, and partly because that tracking by pfn
    and offset looks quite reasonable.

    The problem with this debug code was simply that it was expensive and
    didn't seem worth it, not that it was wrong per se.

    Acked-by: Dan Williams
    Acked-by: Christoph Hellwig
    Signed-off-by: Linus Torvalds

    Linus Torvalds
     
  • Since commit 2a9127fcf229 ("mm: rewrite wait_on_page_bit_common()
    logic") improved unlock_page(), it has become more noticeable how
    cow_user_page() in a kernel with CONFIG_DMA_API_DEBUG=y can create and
    suffer from heavy contention on DMA debug's radix_lock in
    debug_dma_assert_idle().

    It is only doing a lookup: use rcu_read_lock() and rcu_read_unlock()
    instead; though that does require the static ents[] to be moved
    onstack...

    ...but, hold on, isn't that radix_tree_gang_lookup() and loop doing
    quite the wrong thing: searching CACHELINES_PER_PAGE entries for an
    exact match with the first cacheline of the page in question?
    radix_tree_gang_lookup() is the right tool for the job, but we need
    nothing more than to check the first entry it can find, reporting if
    that falls anywhere within the page.

    (Is RCU safe here? As safe as using the spinlock was. The entries are
    never freed, so don't need to be freed by RCU. They may be reused, and
    there is a faint chance of a race, with an offending entry reused while
    printing its error info; but the spinlock did not prevent that either,
    and I agree that it's not worth worrying about. ]

    [ Side noe: this patch is a clear improvement to the status quo, but the
    next patch will be removing this debug function entirely.

    But just in case we decide we want to resurrect the debugging code
    some day, I'm first applying this improvement patch so that it doesn't
    get lost - Linus ]

    Fixes: 3b7a6418c749 ("dma debug: account for cachelines and read-only mappings in overlap tracking")
    Signed-off-by: Hugh Dickins
    Acked-by: Dan Williams
    Acked-by: Christoph Hellwig
    Signed-off-by: Linus Torvalds

    Hugh Dickins
     

05 Aug, 2020

2 commits

  • Pull documentation updates from Jonathan Corbet:
    "It's been a busy cycle for documentation - hopefully the busiest for a
    while to come. Changes include:

    - Some new Chinese translations

    - Progress on the battle against double words words and non-HTTPS
    URLs

    - Some block-mq documentation

    - More RST conversions from Mauro. At this point, that task is
    essentially complete, so we shouldn't see this kind of churn again
    for a while. Unless we decide to switch to asciidoc or
    something...:)

    - Lots of typo fixes, warning fixes, and more"

    * tag 'docs-5.9' of git://git.lwn.net/linux: (195 commits)
    scripts/kernel-doc: optionally treat warnings as errors
    docs: ia64: correct typo
    mailmap: add entry for
    doc/zh_CN: add cpu-load Chinese version
    Documentation/admin-guide: tainted-kernels: fix spelling mistake
    MAINTAINERS: adjust kprobes.rst entry to new location
    devices.txt: document rfkill allocation
    PCI: correct flag name
    docs: filesystems: vfs: correct flag name
    docs: filesystems: vfs: correct sync_mode flag names
    docs: path-lookup: markup fixes for emphasis
    docs: path-lookup: more markup fixes
    docs: path-lookup: fix HTML entity mojibake
    CREDITS: Replace HTTP links with HTTPS ones
    docs: process: Add an example for creating a fixes tag
    doc/zh_CN: add Chinese translation prefer section
    doc/zh_CN: add clearing-warn-once Chinese version
    doc/zh_CN: add admin-guide index
    doc:it_IT: process: coding-style.rst: Correct __maybe_unused compiler label
    futex: MAINTAINERS: Re-add selftests directory
    ...

    Linus Torvalds
     
  • Pull dma-mapping updates from Christoph Hellwig:

    - make support for dma_ops optional

    - move more code out of line

    - add generic support for a dma_ops bypass mode

    - misc cleanups

    * tag 'dma-mapping-5.9' of git://git.infradead.org/users/hch/dma-mapping:
    dma-contiguous: cleanup dma_alloc_contiguous
    dma-debug: use named initializers for dir2name
    powerpc: use the generic dma_ops_bypass mode
    dma-mapping: add a dma_ops_bypass flag to struct device
    dma-mapping: make support for dma ops optional
    dma-mapping: inline the fast path dma-direct calls
    dma-mapping: move the remaining DMA API calls out of line

    Linus Torvalds
     

19 Jul, 2020

1 commit


17 Jul, 2020

1 commit

  • Using uninitialized_var() is dangerous as it papers over real bugs[1]
    (or can in the future), and suppresses unrelated compiler warnings
    (e.g. "unused variable"). If the compiler thinks it is uninitialized,
    either simply initialize the variable or make compiler changes.

    In preparation for removing[2] the[3] macro[4], remove all remaining
    needless uses with the following script:

    git grep '\buninitialized_var\b' | cut -d: -f1 | sort -u | \
    xargs perl -pi -e \
    's/\buninitialized_var\(([^\)]+)\)/\1/g;
    s:\s*/\* (GCC be quiet|to make compiler happy) \*/$::g;'

    drivers/video/fbdev/riva/riva_hw.c was manually tweaked to avoid
    pathological white-space.

    No outstanding warnings were found building allmodconfig with GCC 9.3.0
    for x86_64, i386, arm64, arm, powerpc, powerpc64le, s390x, mips, sparc64,
    alpha, and m68k.

    [1] https://lore.kernel.org/lkml/20200603174714.192027-1-glider@google.com/
    [2] https://lore.kernel.org/lkml/CA+55aFw+Vbj0i=1TGqCR5vQkCzWJ0QxK6CernOU6eedsudAixw@mail.gmail.com/
    [3] https://lore.kernel.org/lkml/CA+55aFwgbgqhbp1fkxvRKEpzyR5J8n1vKT1VZdz9knmPuXhOeg@mail.gmail.com/
    [4] https://lore.kernel.org/lkml/CA+55aFz2500WfbKXAx8s67wrm9=yVJu65TpLgN_ybYNv0VEOKA@mail.gmail.com/

    Reviewed-by: Leon Romanovsky # drivers/infiniband and mlx4/mlx5
    Acked-by: Jason Gunthorpe # IB
    Acked-by: Kalle Valo # wireless drivers
    Reviewed-by: Chao Yu # erofs
    Signed-off-by: Kees Cook

    Kees Cook
     

27 Jun, 2020

1 commit


20 Apr, 2020

1 commit


09 Apr, 2020

1 commit

  • The commit 2e05ea5cdc1a ("dma-mapping: implement dma_map_single_attrs using
    dma_map_page_attrs") removed "dma_debug_page" enum, but missed to update
    type2name string table. This causes incorrect displaying of dma allocation
    type.
    Fix it by removing "page" string from type2name string table and switch to
    use named initializers.

    Before (dma_alloc_coherent()):
    k3-ringacc 4b800000.ringacc: scather-gather idx 2208 P=d1140000 N=d114 D=d1140000 L=40 DMA_BIDIRECTIONAL dma map error check not applicable
    k3-ringacc 4b800000.ringacc: scather-gather idx 2216 P=d1150000 N=d115 D=d1150000 L=40 DMA_BIDIRECTIONAL dma map error check not applicable

    After:
    k3-ringacc 4b800000.ringacc: coherent idx 2208 P=d1140000 N=d114 D=d1140000 L=40 DMA_BIDIRECTIONAL dma map error check not applicable
    k3-ringacc 4b800000.ringacc: coherent idx 2216 P=d1150000 N=d115 D=d1150000 L=40 DMA_BIDIRECTIONAL dma map error check not applicable

    Fixes: 2e05ea5cdc1a ("dma-mapping: implement dma_map_single_attrs using dma_map_page_attrs")
    Signed-off-by: Grygorii Strashko
    Signed-off-by: Christoph Hellwig

    Grygorii Strashko
     

29 Nov, 2019

1 commit

  • …linux; tag 'dma-mapping-5.5' of git://git.infradead.org/users/hch/dma-mapping

    Pull dma-mapping updates from Christoph Hellwig:

    - improve dma-debug scalability (Eric Dumazet)

    - tiny dma-debug cleanup (Dan Carpenter)

    - check for vmap memory in dma_map_single (Kees Cook)

    - check for dma_addr_t overflows in dma-direct when using DMA offsets
    (Nicolas Saenz Julienne)

    - switch the x86 sta2x11 SOC to use more generic DMA code (Nicolas
    Saenz Julienne)

    - fix arm-nommu dma-ranges handling (Vladimir Murzin)

    - use __initdata in CMA (Shyam Saini)

    - replace the bus dma mask with a limit (Nicolas Saenz Julienne)

    - merge the remapping helpers into the main dma-direct flow (me)

    - switch xtensa to the generic dma remap handling (me)

    - various cleanups around dma_capable (me)

    - remove unused dev arguments to various dma-noncoherent helpers (me)

    * 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux:

    * tag 'dma-mapping-5.5' of git://git.infradead.org/users/hch/dma-mapping: (22 commits)
    dma-mapping: treat dev->bus_dma_mask as a DMA limit
    dma-direct: exclude dma_direct_map_resource from the min_low_pfn check
    dma-direct: don't check swiotlb=force in dma_direct_map_resource
    dma-debug: clean up put_hash_bucket()
    powerpc: remove support for NULL dev in __phys_to_dma / __dma_to_phys
    dma-direct: avoid a forward declaration for phys_to_dma
    dma-direct: unify the dma_capable definitions
    dma-mapping: drop the dev argument to arch_sync_dma_for_*
    x86/PCI: sta2x11: use default DMA address translation
    dma-direct: check for overflows on 32 bit DMA addresses
    dma-debug: increase HASH_SIZE
    dma-debug: reorder struct dma_debug_entry fields
    xtensa: use the generic uncached segment support
    dma-mapping: merge the generic remapping helpers into dma-direct
    dma-direct: provide mmap and get_sgtable method overrides
    dma-direct: remove the dma_handle argument to __dma_direct_alloc_pages
    dma-direct: remove __dma_direct_free_pages
    usb: core: Remove redundant vmap checks
    kernel: dma-contiguous: mark CMA parameters __initdata/__initconst
    dma-debug: add a schedule point in debug_dma_dump_mappings()
    ...

    Linus Torvalds
     

21 Nov, 2019

1 commit


11 Nov, 2019

2 commits

  • With modern NIC, it is not unusual having about ~256,000 active dma
    mappings and a hash size of 1024 buckets is too small.

    Forcing full cache line per bucket does not seem useful, especially now
    that we have contention on free_entries_lock for allocations and freeing
    of entries. Better use the space to fit more buckets.

    Signed-off-by: Eric Dumazet
    Signed-off-by: Christoph Hellwig

    Eric Dumazet
     
  • Move all fields used during exact match lookups to the first cache line.
    This makes debug_dma_mapping_error() and friends about 50% faster.

    Since it removes two 32bit holes, force a cacheline alignment on struct
    dma_debug_entry.

    Signed-off-by: Eric Dumazet
    Signed-off-by: Christoph Hellwig

    Eric Dumazet
     

31 Oct, 2019

1 commit

  • 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

    Eric Dumazet
     

18 Oct, 2019

1 commit

  • As said in commit f2c2cbcc35d4 ("powerpc: Use pr_warn instead of
    pr_warning"), removing pr_warning so all logging messages use a
    consistent _warn style. Let's do it.

    Link: http://lkml.kernel.org/r/20191018031850.48498-25-wangkefeng.wang@huawei.com
    To: linux-kernel@vger.kernel.org
    Cc: Christoph Hellwig
    Cc: Marek Szyprowski
    Cc: Robin Murphy
    Signed-off-by: Kefeng Wang
    Reviewed-by: Sergey Senozhatsky
    Signed-off-by: Petr Mladek

    Kefeng Wang
     

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