11 Jul, 2020

1 commit

  • debugfs_create_u32_array() allocates a small structure to wrap
    the data and size information about the array. If users ever
    try to remove the file this leads to a leak since nothing ever
    frees this wrapper.

    That said there are no upstream users of debugfs_create_u32_array()
    that'd remove a u32 array file (we only have one u32 array user in
    CMA), so there is no real bug here.

    Make callers pass a wrapper they allocated. This way the lifetime
    management of the wrapper is on the caller, and we can avoid the
    potential leak in debugfs.

    CC: Chucheng Luo
    Signed-off-by: Jakub Kicinski
    Reviewed-by: Greg Kroah-Hartman
    Signed-off-by: David S. Miller

    Jakub Kicinski
     

02 Dec, 2019

1 commit

  • It is more clear to use DEFINE_DEBUGFS_ATTRIBUTE to define debugfs file
    operation rather than DEFINE_SIMPLE_ATTRIBUTE.

    Link: http://lkml.kernel.org/r/1572348687-9951-1-git-send-email-zhongjiang@huawei.com
    Signed-off-by: zhong jiang
    Reviewed-by: Andrew Morton
    Cc: Yue Hu
    Cc: Greg Kroah-Hartman
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    zhong jiang
     

15 May, 2019

1 commit

  • If not find zero bit in find_next_zero_bit(), it will return the size
    parameter passed in, so the start bit should be compared with bitmap_maxno
    rather than cma->count. Although getting maxchunk is working fine due to
    zero value of order_per_bit currently, the operation will be stuck if
    order_per_bit is set as non-zero.

    Link: http://lkml.kernel.org/r/20190319092734.276-1-zbestahu@gmail.com
    Signed-off-by: Yue Hu
    Reviewed-by: Andrew Morton
    Cc: Michal Hocko
    Cc: Joe Perches
    Cc: David Rientjes
    Cc: Dmitry Safonov
    Cc: Joonsoo Kim
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Yue Hu
     

06 Mar, 2019

2 commits

  • Currently cma_debugfs_root is static storage. That is unnecessary since
    it will be only used by next cma_debugfs_add_one(). We can just pass it
    to following calling to save thisspace. Also remove useless idx
    parameter.

    Link: http://lkml.kernel.org/r/20190221040130.8940-1-zbestahu@gmail.com
    Signed-off-by: Yue Hu
    Reviewed-by: Andrew Morton
    Cc: Michal Hocko
    Cc: David Rientjes
    Cc: Joe Perches
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Yue Hu
     
  • 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.

    Link: http://lkml.kernel.org/r/20190122152151.16139-14-gregkh@linuxfoundation.org
    Signed-off-by: Greg Kroah-Hartman
    Cc: Michal Hocko
    Cc: Vlastimil Babka
    Cc: David Rientjes
    Cc: Laura Abbott
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Greg Kroah-Hartman
     

18 Aug, 2018

1 commit

  • cma_alloc() doesn't really support gfp flags other than __GFP_NOWARN, so
    convert gfp_mask parameter to boolean no_warn parameter.

    This will help to avoid giving false feeling that this function supports
    standard gfp flags and callers can pass __GFP_ZERO to get zeroed buffer,
    what has already been an issue: see commit dd65a941f6ba ("arm64:
    dma-mapping: clear buffers allocated with FORCE_CONTIGUOUS flag").

    Link: http://lkml.kernel.org/r/20180709122019eucas1p2340da484acfcc932537e6014f4fd2c29~-sqTPJKij2939229392eucas1p2j@eucas1p2.samsung.com
    Signed-off-by: Marek Szyprowski
    Acked-by: Michal Hocko
    Acked-by: Michał Nazarewicz
    Acked-by: Laura Abbott
    Acked-by: Vlastimil Babka
    Reviewed-by: Christoph Hellwig
    Cc: Joonsoo Kim
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Marek Szyprowski
     

15 Jun, 2018

1 commit

  • mm/*.c files use symbolic and octal styles for permissions.

    Using octal and not symbolic permissions is preferred by many as more
    readable.

    https://lkml.org/lkml/2016/8/2/1945

    Prefer the direct use of octal for permissions.

    Done using
    $ scripts/checkpatch.pl -f --types=SYMBOLIC_PERMS --fix-inplace mm/*.c
    and some typing.

    Before: $ git grep -P -w "0[0-7]{3,3}" mm | wc -l
    44
    After: $ git grep -P -w "0[0-7]{3,3}" mm | wc -l
    86

    Miscellanea:

    o Whitespace neatening around these conversions.

    Link: http://lkml.kernel.org/r/2e032ef111eebcd4c5952bae86763b541d373469.1522102887.git.joe@perches.com
    Signed-off-by: Joe Perches
    Acked-by: David Rientjes
    Acked-by: Michal Hocko
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Joe Perches
     

02 Nov, 2017

1 commit

  • Many source files in the tree are missing licensing information, which
    makes it harder for compliance tools to determine the correct license.

    By default all files without license information are under the default
    license of the kernel, which is GPL version 2.

    Update the files which contain no license information with the 'GPL-2.0'
    SPDX license identifier. The SPDX identifier is a legally binding
    shorthand, which can be used instead of the full boiler plate text.

    This patch is based on work done by Thomas Gleixner and Kate Stewart and
    Philippe Ombredanne.

    How this work was done:

    Patches were generated and checked against linux-4.14-rc6 for a subset of
    the use cases:
    - file had no licensing information it it.
    - file was a */uapi/* one with no licensing information in it,
    - file was a */uapi/* one with existing licensing information,

    Further patches will be generated in subsequent months to fix up cases
    where non-standard license headers were used, and references to license
    had to be inferred by heuristics based on keywords.

    The analysis to determine which SPDX License Identifier to be applied to
    a file was done in a spreadsheet of side by side results from of the
    output of two independent scanners (ScanCode & Windriver) producing SPDX
    tag:value files created by Philippe Ombredanne. Philippe prepared the
    base worksheet, and did an initial spot review of a few 1000 files.

    The 4.13 kernel was the starting point of the analysis with 60,537 files
    assessed. Kate Stewart did a file by file comparison of the scanner
    results in the spreadsheet to determine which SPDX license identifier(s)
    to be applied to the file. She confirmed any determination that was not
    immediately clear with lawyers working with the Linux Foundation.

    Criteria used to select files for SPDX license identifier tagging was:
    - Files considered eligible had to be source code files.
    - Make and config files were included as candidates if they contained >5
    lines of source
    - File already had some variant of a license header in it (even if
    Reviewed-by: Philippe Ombredanne
    Reviewed-by: Thomas Gleixner
    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     

19 Aug, 2017

1 commit

  • name[] in cma_debugfs_add_one() can only accommodate 16 chars including
    NULL to store sprintf output. It's common for cma device name to be
    larger than 15 chars. This can cause stack corrpution. If the gcc
    stack protector is turned on, this can cause a panic due to stack
    corruption.

    Below is one example trace:

    Kernel panic - not syncing: stack-protector: Kernel stack is corrupted in:
    ffffff8e69a75730
    Call trace:
    dump_backtrace+0x0/0x2c4
    show_stack+0x20/0x28
    dump_stack+0xb8/0xf4
    panic+0x154/0x2b0
    print_tainted+0x0/0xc0
    cma_debugfs_init+0x274/0x290
    do_one_initcall+0x5c/0x168
    kernel_init_freeable+0x1c8/0x280

    Fix the short sprintf buffer in cma_debugfs_add_one() by using
    scnprintf() instead of sprintf().

    Link: http://lkml.kernel.org/r/1502446217-21840-1-git-send-email-guptap@codeaurora.org
    Fixes: f318dd083c81 ("cma: Store a name in the cma structure")
    Signed-off-by: Prakash Gupta
    Acked-by: Laura Abbott
    Cc: Greg Kroah-Hartman
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Prakash Gupta
     

19 Apr, 2017

1 commit


25 Feb, 2017

1 commit

  • Most users of this interface just want to use it with the default
    GFP_KERNEL flags, but for cases where DMA memory is allocated it may be
    called from a different context.

    No functional change yet, just passing through the flag to the
    underlying alloc_contig_range function.

    Link: http://lkml.kernel.org/r/20170127172328.18574-2-l.stach@pengutronix.de
    Signed-off-by: Lucas Stach
    Acked-by: Vlastimil Babka
    Acked-by: Michal Hocko
    Cc: Radim Krcmar
    Cc: Catalin Marinas
    Cc: Will Deacon
    Cc: Chris Zankel
    Cc: Ralf Baechle
    Cc: Paolo Bonzini
    Cc: Alexander Graf
    Cc: Joonsoo Kim
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Lucas Stach
     

18 Jul, 2015

2 commits

  • In CMA, 1 bit in bitmap means 1 << order_per_bits pages so size of
    bitmap is cma->count >> order_per_bits rather than just cma->count.
    This patch fixes it.

    Signed-off-by: Joonsoo Kim
    Acked-by: Michal Nazarewicz
    Cc: Sasha Levin
    Cc: Stefan Strogin
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Joonsoo Kim
     
  • CMA has alloc/free interface for debugging. It is intended that
    alloc/free occurs in specific CMA region, but, currently, alloc/free
    interface is on root dir due to the bug so we can't select CMA region
    where alloc/free happens.

    This patch fixes this problem by making alloc/free interface per CMA
    region.

    Signed-off-by: Joonsoo Kim
    Acked-by: Michal Nazarewicz
    Cc: Sasha Levin
    Cc: Stefan Strogin
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Joonsoo Kim
     

16 Apr, 2015

2 commits

  • Like EXPORT_SYMBOL(): the positioning communicates that the macro pertains
    to the immediately preceding function.

    Cc: Dmitry Safonov
    Cc: Michal Nazarewicz
    Cc: Stefan Strogin
    Cc: Marek Szyprowski
    Cc: Joonsoo Kim
    Cc: Pintu Kumar
    Cc: Weijie Yang
    Cc: Laurent Pinchart
    Cc: Vyacheslav Tyrtov
    Cc: Aleksei Mateosian
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andrew Morton
     
  • Here are two functions that provide interface to compute/get used size and
    size of biggest free chunk in cma region. Add that information to
    debugfs.

    [akpm@linux-foundation.org: move debug code from cma.c into cma_debug.c]
    [stefan.strogin@gmail.com: move code from cma_get_used() and cma_get_maxchunk() to cma_used_get() and cma_maxchunk_get()]
    Signed-off-by: Dmitry Safonov
    Signed-off-by: Stefan Strogin
    Acked-by: Michal Nazarewicz
    Cc: Marek Szyprowski
    Cc: Joonsoo Kim
    Cc: Pintu Kumar
    Cc: Weijie Yang
    Cc: Laurent Pinchart
    Cc: Vyacheslav Tyrtov
    Cc: Aleksei Mateosian
    Signed-off-by: Stefan Strogin
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Dmitry Safonov
     

15 Apr, 2015

4 commits

  • s/CONFIG_CMA_ALIGNMENT/0/, per Joonsoo

    Cc: Joonsoo Kim
    Cc: Konrad Rzeszutek Wilk
    Cc: Laura Abbott
    Cc: Marek Szyprowski
    Cc: Sasha Levin
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andrew Morton
     
  • Provides a userspace interface to trigger a CMA release.

    Usage:

    echo [pages] > free

    This would provide testing/fuzzing access to the CMA release paths.

    [akpm@linux-foundation.org: coding-style fixes]
    [mhocko@suse.cz: fix build]
    Signed-off-by: Sasha Levin
    Acked-by: Joonsoo Kim
    Cc: Marek Szyprowski
    Cc: Laura Abbott
    Cc: Konrad Rzeszutek Wilk
    Signed-off-by: Michal Hocko
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Sasha Levin
     
  • Provides a userspace interface to trigger a CMA allocation.

    Usage:

    echo [pages] > alloc

    This would provide testing/fuzzing access to the CMA allocation paths.

    Signed-off-by: Sasha Levin
    Acked-by: Joonsoo Kim
    Cc: Marek Szyprowski
    Cc: Laura Abbott
    Cc: Konrad Rzeszutek Wilk
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Sasha Levin
     
  • I've noticed that there is no interfaces exposed by CMA which would let me
    fuzz what's going on in there.

    This small patchset exposes some information out to userspace, plus adds
    the ability to trigger allocation and freeing from userspace.

    This patch (of 3):

    Implement a simple debugfs interface to expose information about CMA areas
    in the system.

    Useful for testing/sanity checks for CMA since it was impossible to
    previously retrieve this information in userspace.

    Signed-off-by: Sasha Levin
    Acked-by: Joonsoo Kim
    Cc: Marek Szyprowski
    Cc: Laura Abbott
    Cc: Konrad Rzeszutek Wilk
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Sasha Levin