Commit Graph

22 Commits

Author SHA1 Message Date
Rafael Aquini 879f2cef85 maple_tree: don't find node end in mtree_lookup_walk()
JIRA: https://issues.redhat.com/browse/RHEL-27745

This patch is a backport of the following upstream commit:
commit 24662decdd44645e8f027d7912be962dd461d1aa
Author: Liam R. Howlett <Liam.Howlett@oracle.com>
Date:   Wed Nov 1 13:16:28 2023 -0400

    maple_tree: don't find node end in mtree_lookup_walk()

    Since the pivot being set is now reliable, the optimized loop no longer
    needs to find the node end.  The redundant check for a dead node can also
    be avoided as there is no danger of using the wrong pivot since the
    results will be thrown out in the case of a dead node by the later check.

    This patch also adds a benchmark test for the function to the maple tree
    test framework.  The benchmark shows an average increase performance of
    5.98% over 3 runs with this commit.

    Link: https://lkml.kernel.org/r/20231101171629.3612299-12-Liam.Howlett@oracle.com
    Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
    Cc: Peng Zhang <zhangpeng.00@bytedance.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Signed-off-by: Rafael Aquini <raquini@redhat.com>
2024-12-09 12:23:48 -05:00
Rafael Aquini cf948a15b2 maple_tree: separate ma_state node from status
JIRA: https://issues.redhat.com/browse/RHEL-27745

This patch is a backport of the following upstream commit:
commit 067311d33e650adfe7ae23765959ddcc1ba18510
Author: Liam R. Howlett <Liam.Howlett@oracle.com>
Date:   Wed Nov 1 13:16:25 2023 -0400

    maple_tree: separate ma_state node from status

    The maple tree node is overloaded to keep status as well as the active
    node.  This, unfortunately, results in a re-walk on underflow or overflow.
    Since the maple state has room, the status can be placed in its own enum
    in the structure.  Once an underflow/overflow is detected, certain modes
    can restore the status to active and others may need to re-walk just that
    one node to see the entry.

    The status being an enum has the benefit of detecting unhandled status in
    switch statements.

    [Liam.Howlett@oracle.com: fix comments about MAS_*]
      Link: https://lkml.kernel.org/r/20231106154124.614247-1-Liam.Howlett@oracle.com
    [Liam.Howlett@oracle.com: update forking to separate maple state and node]
      Link: https://lkml.kernel.org/r/20231106154551.615042-1-Liam.Howlett@oracle.com
    [Liam.Howlett@oracle.com: fix mas_prev() state separation code]
      Link: https://lkml.kernel.org/r/20231207193319.4025462-1-Liam.Howlett@oracle.com
    Link: https://lkml.kernel.org/r/20231101171629.3612299-9-Liam.Howlett@oracle.com
    Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
    Cc: Peng Zhang <zhangpeng.00@bytedance.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Signed-off-by: Rafael Aquini <raquini@redhat.com>
2024-12-09 12:23:46 -05:00
Rafael Aquini 421a7d2a4c maple_tree: update check_forking() and bench_forking()
JIRA: https://issues.redhat.com/browse/RHEL-27745

This patch is a backport of the following upstream commit:
commit 446e1867e6df3cbdd19af6be8f8f4ed56176adb4
Author: Peng Zhang <zhangpeng.00@bytedance.com>
Date:   Fri Oct 27 11:38:43 2023 +0800

    maple_tree: update check_forking() and bench_forking()

    Updated check_forking() and bench_forking() to use __mt_dup() to duplicate
    maple tree.

    Link: https://lkml.kernel.org/r/20231027033845.90608-9-zhangpeng.00@bytedance.com
    Signed-off-by: Peng Zhang <zhangpeng.00@bytedance.com>
    Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com>
    Cc: Christian Brauner <brauner@kernel.org>
    Cc: Jonathan Corbet <corbet@lwn.net>
    Cc: Mateusz Guzik <mjguzik@gmail.com>
    Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
    Cc: Matthew Wilcox <willy@infradead.org>
    Cc: Michael S. Tsirkin <mst@redhat.com>
    Cc: Mike Christie <michael.christie@oracle.com>
    Cc: Nicholas Piggin <npiggin@gmail.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Suren Baghdasaryan <surenb@google.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Signed-off-by: Rafael Aquini <raquini@redhat.com>
2024-12-09 12:23:32 -05:00
Rafael Aquini c159206979 maple_tree: skip other tests when BENCH is enabled
JIRA: https://issues.redhat.com/browse/RHEL-27745

This patch is a backport of the following upstream commit:
commit f670fa1caadb4ea532a89012c5451e4c6789bfcc
Author: Peng Zhang <zhangpeng.00@bytedance.com>
Date:   Fri Oct 27 11:38:42 2023 +0800

    maple_tree: skip other tests when BENCH is enabled

    Skip other tests when BENCH is enabled so that performance can be measured
    in user space.

    Link: https://lkml.kernel.org/r/20231027033845.90608-8-zhangpeng.00@bytedance.com
    Signed-off-by: Peng Zhang <zhangpeng.00@bytedance.com>
    Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com>
    Cc: Christian Brauner <brauner@kernel.org>
    Cc: Jonathan Corbet <corbet@lwn.net>
    Cc: Mateusz Guzik <mjguzik@gmail.com>
    Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
    Cc: Matthew Wilcox <willy@infradead.org>
    Cc: Michael S. Tsirkin <mst@redhat.com>
    Cc: Mike Christie <michael.christie@oracle.com>
    Cc: Nicholas Piggin <npiggin@gmail.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Suren Baghdasaryan <surenb@google.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Signed-off-by: Rafael Aquini <raquini@redhat.com>
2024-12-09 12:23:31 -05:00
Rafael Aquini 92a933dce3 maple_tree: add GFP_KERNEL to allocations in mas_expected_entries()
JIRA: https://issues.redhat.com/browse/RHEL-27745

This patch is a backport of the following upstream commit:
commit 099d7439ce03d0e7bc8f0c3d7878b562f3a48d3d
Author: Liam R. Howlett <Liam.Howlett@oracle.com>
Date:   Thu Oct 12 11:52:33 2023 -0400

    maple_tree: add GFP_KERNEL to allocations in mas_expected_entries()

    Users complained about OOM errors during fork without triggering
    compaction.  This can be fixed by modifying the flags used in
    mas_expected_entries() so that the compaction will be triggered in low
    memory situations.  Since mas_expected_entries() is only used during fork,
    the extra argument does not need to be passed through.

    Additionally, the two test_maple_tree test cases and one benchmark test
    were altered to use the correct locking type so that allocations would not
    trigger sleeping and thus fail.  Testing was completed with lockdep atomic
    sleep detection.

    The additional locking change requires rwsem support additions to the
    tools/ directory through the use of pthreads pthread_rwlock_t.  With this
    change test_maple_tree works in userspace, as a module, and in-kernel.

    Users may notice that the system gave up early on attempting to start new
    processes instead of attempting to reclaim memory.

    Link: https://lkml.kernel.org/r/20230915093243epcms1p46fa00bbac1ab7b7dca94acb66c44c456@epcms1p4
    Link: https://lkml.kernel.org/r/20231012155233.2272446-1-Liam.Howlett@oracle.com
    Fixes: 54a611b60590 ("Maple Tree: add new data structure")
    Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
    Reviewed-by: Peng Zhang <zhangpeng.00@bytedance.com>
    Cc: <jason.sim@samsung.com>
    Cc: <stable@vger.kernel.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Signed-off-by: Rafael Aquini <raquini@redhat.com>
2024-12-09 12:22:38 -05:00
Rafael Aquini 78da632e69 maple_tree: add MAS_UNDERFLOW and MAS_OVERFLOW states
JIRA: https://issues.redhat.com/browse/RHEL-27745

This patch is a backport of the following upstream commit:
commit a8091f039c1ebf5cb0d5261e3613f18eb2a5d8b7
Author: Liam R. Howlett <Liam.Howlett@oracle.com>
Date:   Thu Sep 21 14:12:36 2023 -0400

    maple_tree: add MAS_UNDERFLOW and MAS_OVERFLOW states

    When updating the maple tree iterator to avoid rewalks, an issue was
    introduced when shifting beyond the limits.  This can be seen by trying to
    go to the previous address of 0, which would set the maple node to
    MAS_NONE and keep the range as the last entry.

    Subsequent calls to mas_find() would then search upwards from mas->last
    and skip the value at mas->index/mas->last.  This showed up as a bug in
    mprotect which skips the actual VMA at the current range after attempting
    to go to the previous VMA from 0.

    Since MAS_NONE may already be set when searching for a value that isn't
    contained within a node, changing the handling of MAS_NONE in mas_find()
    would make the code more complicated and error prone.  Furthermore, there
    was no way to tell which limit was hit, and thus which action to take
    (next or the entry at the current range).

    This solution is to add two states to track what happened with the
    previous iterator action.  This allows for the expected behaviour of the
    next command to return the correct item (either the item at the range
    requested, or the next/previous).

    Tests are also added and updated accordingly.

    Link: https://lkml.kernel.org/r/20230921181236.509072-3-Liam.Howlett@oracle.com
    Link: https://gist.github.com/heatd/85d2971fae1501b55b6ea401fbbe485b
    Link: https://lore.kernel.org/linux-mm/20230921181236.509072-1-Liam.Howlett@oracle.com/
    Fixes: 39193685d585 ("maple_tree: try harder to keep active node with mas_prev()")
    Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
    Reported-by: Pedro Falcato <pedro.falcato@gmail.com>
    Closes: https://gist.github.com/heatd/85d2971fae1501b55b6ea401fbbe485b
    Closes: https://bugs.archlinux.org/task/79656
    Cc: <stable@vger.kernel.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Signed-off-by: Rafael Aquini <raquini@redhat.com>
2024-12-09 12:22:03 -05:00
Rafael Aquini 2129b52e0e maple_tree: add test for mas_wr_modify() fast path
JIRA: https://issues.redhat.com/browse/RHEL-27745

This patch is a backport of the following upstream commit:
commit d6e8d0dc19a3ebea185cd8e99f2e960d81b153ad
Author: Peng Zhang <zhangpeng.00@bytedance.com>
Date:   Wed Jun 28 15:36:54 2023 +0800

    maple_tree: add test for mas_wr_modify() fast path

    Patch series "Optimize the fast path of mas_store()", v4.

    Add fast paths for mas_wr_append() and mas_wr_slot_store() respectively.
    The newly added fast path of mas_wr_append() is used in fork() and how
    much it benefits fork() depends on how many VMAs are duplicated.

    Thanks Liam for the review.

    This patch (of 4):

    Add tests for all cases of mas_wr_append() and mas_wr_slot_store().

    Link: https://lkml.kernel.org/r/20230628073657.75314-1-zhangpeng.00@bytedance.com
    Link: https://lkml.kernel.org/r/20230628073657.75314-2-zhangpeng.00@bytedance.com
    Signed-off-by: Peng Zhang <zhangpeng.00@bytedance.com>
    Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Signed-off-by: Rafael Aquini <raquini@redhat.com>
2024-12-09 12:21:44 -05:00
Rafael Aquini 7aaef99792 maple_tree: add benchmarking for mas_prev()
JIRA: https://issues.redhat.com/browse/RHEL-27743

This patch is a backport of the following upstream commit:
commit 8c314f3b55fbc42284ea1367bb2807f2accad8ae
Author: Liam R. Howlett <Liam.Howlett@oracle.com>
Date:   Mon Jul 24 14:31:44 2023 -0400

    maple_tree: add benchmarking for mas_prev()

    Add some benchmarking functions in testing for mas_prev().  This is
    useful to ensure there are no regressions added during modifications.

    Link: https://lkml.kernel.org/r/20230724183157.3939892-3-Liam.Howlett@oracle.com
    Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
    Cc: Peng Zhang <zhangpeng.00@bytedance.com>
    Cc: Suren Baghdasaryan <surenb@google.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Signed-off-by: Rafael Aquini <raquini@redhat.com>
2024-10-01 11:19:23 -04:00
Rafael Aquini 8899eef621 maple_tree: add benchmarking for mas_for_each
JIRA: https://issues.redhat.com/browse/RHEL-27743

This patch is a backport of the following upstream commit:
commit 361c678be709f67a5b609ec3666ff5fec7eb8baf
Author: Liam R. Howlett <Liam.Howlett@oracle.com>
Date:   Mon Jul 24 14:31:43 2023 -0400

    maple_tree: add benchmarking for mas_for_each

    Patch series "Reduce preallocations for maple tree", v3.

    Initial work on preallocations showed no regression in performance during
    testing, but recently some users (both on [1] and off [android] list) have
    reported that preallocating the worst-case number of nodes has caused some
    slow down.  This patch set addresses the number of allocations in a few
    ways.

    During munmap() most munmap() operations will remove a single VMA, so
    leverage the fact that the maple tree can place a single pointer at range
    0 - 0 without allocating.  This is done by changing the index of the VMAs
    to be indexed by the count, starting at 0.

    Re-introduce the entry argument to mas_preallocate() so that a more
    intelligent guess of the node count can be made.

    Implement the more intelligent guess of the node count, although there is
    more work to be done.

    During development of v2 of this patch set, I also noticed that the number
    of nodes being allocated for a rebalance was beyond what could possibly be
    needed.  This is addressed in patch 0008.

    This patch (of 15):

    Add a way to test the speed of mas_for_each() to the testing code.

    Link: https://lkml.kernel.org/r/20230724183157.3939892-1-Liam.Howlett@oracle.com
    Link: https://lkml.kernel.org/r/20230724183157.3939892-2-Liam.Howlett@oracle.com
    Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
    Cc: Peng Zhang <zhangpeng.00@bytedance.com>
    Cc: Suren Baghdasaryan <surenb@google.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Signed-off-by: Rafael Aquini <raquini@redhat.com>
2024-10-01 11:19:23 -04:00
Nico Pache 34b8209a72 maple_tree: fix 32 bit mas_next testing
commit 7a93c71a6714ca1a9c03d70432dac104b0cfb815
Author: Liam R. Howlett <Liam.Howlett@oracle.com>
Date:   Wed Jul 12 13:39:15 2023 -0400

    maple_tree: fix 32 bit mas_next testing

    The test setup of mas_next is dependent on node entry size to create a 2
    level tree, but the tests did not account for this in the expected value
    when shifting beyond the scope of the tree.

    Fix this by setting up the test to succeed depending on the node entries
    which is dependent on the 32/64 bit setup.

    Link: https://lkml.kernel.org/r/20230712173916.168805-1-Liam.Howlett@oracle.com
    Fixes: 120b116208a0 ("maple_tree: reorganize testing to restore module testing")
    Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
    Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
      Closes: https://lore.kernel.org/linux-mm/CAMuHMdV4T53fOw7VPoBgPR7fP6RYqf=CBhD_y_vOg53zZX_DnA@mail.gmail.com/
    Tested-by: Geert Uytterhoeven <geert@linux-m68k.org>
    Cc: <stable@vger.kernel.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

JIRA: https://issues.redhat.com/browse/RHEL-5619
Signed-off-by: Nico Pache <npache@redhat.com>
2024-04-30 17:51:26 -06:00
Nico Pache 9d39d99cbe maple_tree: update testing code for mas_{next,prev,walk}
commit eb2e817f38cafbf776ffec9b273aaada6ffc274d
Author: Liam R. Howlett <Liam.Howlett@oracle.com>
Date:   Thu May 18 10:55:42 2023 -0400

    maple_tree: update testing code for mas_{next,prev,walk}

    Now that the functions have changed the limits, update the testing of the
    maple tree to test these new settings.

    Link: https://lkml.kernel.org/r/20230518145544.1722059-34-Liam.Howlett@oracle.com
    Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
    Cc: David Binderman <dcb314@hotmail.com>
    Cc: Peng Zhang <zhangpeng.00@bytedance.com>
    Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
    Cc: Vernon Yang <vernon2gm@gmail.com>
    Cc: Wei Yang <richard.weiyang@gmail.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

JIRA: https://issues.redhat.com/browse/RHEL-5595
Signed-off-by: Nico Pache <npache@redhat.com>
2023-09-26 10:23:42 -06:00
Nico Pache 4933eaceb8 maple_tree: fix testing mas_empty_area()
commit 17e7436bd327364d46f75d40fd093120ca533b7e
Author: Liam R. Howlett <Liam.Howlett@oracle.com>
Date:   Thu May 18 10:55:35 2023 -0400

    maple_tree: fix testing mas_empty_area()

    Empty area will return -EINVAL if the search window is smaller than the
    requested size.  Fix the test case to check for this error code.

    Link: https://lkml.kernel.org/r/20230518145544.1722059-27-Liam.Howlett@oracle.com
    Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
    Cc: David Binderman <dcb314@hotmail.com>
    Cc: Peng Zhang <zhangpeng.00@bytedance.com>
    Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
    Cc: Vernon Yang <vernon2gm@gmail.com>
    Cc: Wei Yang <richard.weiyang@gmail.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

JIRA: https://issues.redhat.com/browse/RHEL-5595
Signed-off-by: Nico Pache <npache@redhat.com>
2023-09-26 10:23:42 -06:00
Nico Pache 07710eb7cc maple_tree: revise limit checks in mas_empty_area{_rev}()
commit ba9972121ab26a53c917ddb141738aa0e559685e
Author: Liam R. Howlett <Liam.Howlett@oracle.com>
Date:   Thu May 18 10:55:34 2023 -0400

    maple_tree: revise limit checks in mas_empty_area{_rev}()

    Since the maple tree is inclusive in range, ensure that a range of 1 (min
    = max) works for searching for a gap in either direction, and make sure
    the size is at least 1 but not larger than the delta between min and max.

    This commit also updates the testing.  Unfortunately there isn't a way to
    safely update the tests and code without a test failure.

    Link: https://lkml.kernel.org/r/20230518145544.1722059-26-Liam.Howlett@oracle.com
    Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
    Suggested-by: Peng Zhang <zhangpeng.00@bytedance.com>
    Cc: David Binderman <dcb314@hotmail.com>
    Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
    Cc: Vernon Yang <vernon2gm@gmail.com>
    Cc: Wei Yang <richard.weiyang@gmail.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

JIRA: https://issues.redhat.com/browse/RHEL-5595
Signed-off-by: Nico Pache <npache@redhat.com>
2023-09-26 10:23:41 -06:00
Nico Pache cd7e62fbf5 maple_tree: add __init and __exit to test module
commit eaf9790d3bc6e157a2134c01c7d707a5a712fab1
Author: Liam R. Howlett <Liam.Howlett@oracle.com>
Date:   Thu May 18 10:55:28 2023 -0400

    maple_tree: add __init and __exit to test module

    The test functions are not needed after the module is removed, so mark
    them as such.  Add __exit to the module removal function.  Some other
    variables have been marked as const static as well.

    Link: https://lkml.kernel.org/r/20230518145544.1722059-20-Liam.Howlett@oracle.com
    Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
    Suggested-by: Andrew Morton <akpm@linux-foundation.org>
    Cc: David Binderman <dcb314@hotmail.com>
    Cc: Peng Zhang <zhangpeng.00@bytedance.com>
    Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
    Cc: Vernon Yang <vernon2gm@gmail.com>
    Cc: Wei Yang <richard.weiyang@gmail.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

JIRA: https://issues.redhat.com/browse/RHEL-5595
Signed-off-by: Nico Pache <npache@redhat.com>
2023-09-26 10:23:41 -06:00
Nico Pache 692b01cecb maple_tree: make test code work without debug enabled
commit a5199577b1ddae696528d7e4e7a406d5a8f23a7b
Author: Liam R. Howlett <Liam.Howlett@oracle.com>
Date:   Thu May 18 10:55:25 2023 -0400

    maple_tree: make test code work without debug enabled

    The test code is less useful without debug, but can still do general
    validations.  Define mt_dump(), mas_dump() and mas_wr_dump() as a noop if
    debug is not enabled and document it in the test module information that
    more information can be obtained with another kernel config option.

    MT_BUG_ON() will report a failures without tree dumps, and the output will
    be less useful.

    Link: https://lkml.kernel.org/r/20230518145544.1722059-17-Liam.Howlett@oracle.com
    Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
    Cc: David Binderman <dcb314@hotmail.com>
    Cc: Peng Zhang <zhangpeng.00@bytedance.com>
    Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
    Cc: Vernon Yang <vernon2gm@gmail.com>
    Cc: Wei Yang <richard.weiyang@gmail.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

JIRA: https://issues.redhat.com/browse/RHEL-5595
Signed-off-by: Nico Pache <npache@redhat.com>
2023-09-26 10:23:41 -06:00
Nico Pache e5893a811d maple_tree: add format option to mt_dump()
Conflicts: drop MM folder changes as we dont use MT in MM yet
       mm/internal.h
       mm/mmap.c

commit 89f499f35c11af61ba7075ddc23209d10805a25a
Author: Liam R. Howlett <Liam.Howlett@Oracle.com>
Date:   Thu May 18 10:55:14 2023 -0400

    maple_tree: add format option to mt_dump()

    Allow different formatting strings to be used when dumping the tree.
    Currently supports hex and decimal.

    Link: https://lkml.kernel.org/r/20230518145544.1722059-6-Liam.Howlett@oracle.com
    Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
    Cc: David Binderman <dcb314@hotmail.com>
    Cc: Peng Zhang <zhangpeng.00@bytedance.com>
    Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
    Cc: Vernon Yang <vernon2gm@gmail.com>
    Cc: Wei Yang <richard.weiyang@gmail.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

JIRA: https://issues.redhat.com/browse/RHEL-5595
Signed-off-by: Nico Pache <npache@redhat.com>
2023-09-26 10:23:40 -06:00
Nico Pache 2516b5201f test_maple_tree: add more testing for mas_empty_area()
commit 4bd6dded6318dc8e2514d74868c1f8fb38b61a60
Author: Liam R. Howlett <Liam.Howlett@oracle.com>
Date:   Tue Mar 7 13:02:47 2023 -0500

    test_maple_tree: add more testing for mas_empty_area()

    Test robust filling of an entire area of the tree, then test one beyond.
    This is to test the walking back up the tree at the end of nodes and error
    condition.  Test inspired by the reproducer code provided by Snild Dolkow.

    The last test in the function tests for the case of a corrupted maple
    state caused by the incorrect limits set during mas_skip_node().  There
    needs to be a gap in the second last child and last child, but the search
    must rule out the second last child's gap.  This would avoid correcting
    the maple state to the correct max limit and return an error.

    Link: https://lkml.kernel.org/r/20230307180247.2220303-3-Liam.Howlett@oracle.com
    Cc: Snild Dolkow <snild@sony.com>
    Link: https://lore.kernel.org/linux-mm/cb8dc31a-fef2-1d09-f133-e9f7b9f9e77a@sony.com/
    Fixes: e15e06a83923 ("lib/test_maple_tree: add testing for maple tree")
    Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
    Cc: Peng Zhang <zhangpeng.00@bytedance.com>
    Cc: <stable@vger.kernel.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

JIRA: https://issues.redhat.com/browse/RHEL-5595
Signed-off-by: Nico Pache <npache@redhat.com>
2023-09-26 10:23:39 -06:00
Nico Pache 135e54d37d test_maple_tree: test modifications while iterating
commit 5159d64b335401fa83f18c27e2267f1eafc41bd3
Author: Liam R. Howlett <Liam.Howlett@Oracle.com>
Date:   Fri Jan 20 11:26:05 2023 -0500

    test_maple_tree: test modifications while iterating

    Add a testcase to ensure the iterator detects bad states on modifications
    and does what the user expects

    Link: https://lkml.kernel.org/r/20230120162650.984577-5-Liam.Howlett@oracle.com
    Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2166668
Signed-off-by: Nico Pache <npache@redhat.com>
2023-03-07 01:40:57 -07:00
Nico Pache dc7b3331af maple_tree: fix mas_empty_area_rev() lower bound validation
commit 7327e8111adb315423035fb5233533016dfd3f2e
Author: Liam Howlett <liam.howlett@oracle.com>
Date:   Wed Jan 11 20:02:07 2023 +0000

    maple_tree: fix mas_empty_area_rev() lower bound validation

    mas_empty_area_rev() was not correctly validating the start of a gap
    against the lower limit.  This could lead to the range starting lower than
    the requested minimum.

    Fix the issue by better validating a gap once one is found.

    This commit also adds tests to the maple tree test suite for this issue
    and tests the mas_empty_area() function for similar bound checking.

    Link: https://lkml.kernel.org/r/20230111200136.1851322-1-Liam.Howlett@oracle.com
    Link: https://bugzilla.kernel.org/show_bug.cgi?id=216911
    Fixes: 54a611b60590 ("Maple Tree: add new data structure")
    Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
    Reported-by: <amanieu@gmail.com>
      Link: https://lore.kernel.org/linux-mm/0b9f5425-08d4-8013-aa4c-e620c3b10bb2@leemhuis.info/
    Tested-by: Holger Hoffsttte <holger@applied-asynchrony.com>
    Cc: <stable@vger.kernel.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2166668
Signed-off-by: Nico Pache <npache@redhat.com>
2023-03-07 01:40:56 -07:00
Nico Pache b5f102923a test_maple_tree: add test for mas_spanning_rebalance() on insufficient data
commit c5651b31f51584bd1199b3a552c8211a8523d6e1
Author: Liam Howlett <liam.howlett@oracle.com>
Date:   Mon Dec 19 16:20:15 2022 +0000

    test_maple_tree: add test for mas_spanning_rebalance() on insufficient data

    Add a test to the maple tree test suite for the spanning rebalance
    insufficient node issue does not go undetected again.

    Link: https://lkml.kernel.org/r/20221219161922.2708732-3-Liam.Howlett@oracle.com
    Fixes: 54a611b60590 ("Maple Tree: add new data structure")
    Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
    Cc: Andrei Vagin <avagin@gmail.com>
    Cc: Mike Rapoport <rppt@kernel.org>
    Cc: Muhammad Usama Anjum <usama.anjum@collabora.com>
    Cc: <stable@vger.kernel.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2166668
Signed-off-by: Nico Pache <npache@redhat.com>
2023-03-07 01:23:55 -07:00
Nico Pache d5392be061 maple_tree: reorganize testing to restore module testing
Conflicts:
       lib/Kconfig.debug: was not expecting TEST_XARRAY config

commit 120b116208a0877227fc82e3f0df81e7a3ed4ab1
Author: Liam Howlett <liam.howlett@oracle.com>
Date:   Fri Oct 28 18:04:30 2022 +0000

    maple_tree: reorganize testing to restore module testing

    Along the development cycle, the testing code support for module/in-kernel
    compiles was removed.  Restore this functionality by moving any internal
    API tests to the userspace side, as well as threading tests.  Fix the
    lockdep issues and add a way to reduce memory usage so the tests can
    complete with KASAN + memleak detection.  Make the tests work on 32 bit
    hosts where possible and detect 32 bit hosts in the radix test suite.

    [akpm@linux-foundation.org: fix module export]
    [akpm@linux-foundation.org: fix it some more]
    [liam.howlett@oracle.com: fix compile warnings on 32bit build in check_find()]
      Link: https://lkml.kernel.org/r/20221107203816.1260327-1-Liam.Howlett@oracle.com
    Link: https://lkml.kernel.org/r/20221028180415.3074673-1-Liam.Howlett@oracle.com
    Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2166668
Signed-off-by: Nico Pache <npache@redhat.com>
2023-03-07 01:23:55 -07:00
Nico Pache 4c0633e6f6 lib/test_maple_tree: add testing for maple tree
commit e15e06a8392321a19d8ebdbdd7643b7fa8874c17
Author: Liam R. Howlett <Liam.Howlett@Oracle.com>
Date:   Tue Sep 6 19:48:45 2022 +0000

    lib/test_maple_tree: add testing for maple tree

    This is a test suite that uses the radix test infrastructure.  It has been
    split into its own commit to allow for easier review of the maple tree
    code.

    The testing includes:
    - Allocation of nodes
    - gfp flag allocation checks
    - Expansion & contraction of tree
    - preallocation checks
    - tree navigation by next/prev
    - tree navigation by iterators (mas_for_each, etc)
    - Number of nodes for a given number of entries
    - Generic tree construction tests
    - Addition and removal of entries in forward and reverse numerical indexes
    - gap searching both forward and reverse
    - Combining gaps by overwriting entries in different ways
    - splitting right-most node
    - splitting left-most node
    - overwriting multiple slots
    - overwriting across different levels of the tree
    - overwriting the middle of a tree
    - causing a 3-way split up to the root by overwriting the last slot and
      first slot of different nodes and spanning different levels
    - RCU stress testing of the tree with threads
    - Duplication of the tree by entry count
    - Tests which were generated by fuzzers have been added.
    - A large number of tests which come from recording crashing in a VM and
      reconstructing the tree (see check_erase2_set())

    Link: https://lkml.kernel.org/r/20220906194824.2110408-8-Liam.Howlett@oracle.com
    Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
    Tested-by: Yu Zhao <yuzhao@google.com>
    Cc: Catalin Marinas <catalin.marinas@arm.com>
    Cc: David Hildenbrand <david@redhat.com>
    Cc: David Howells <dhowells@redhat.com>
    Cc: Davidlohr Bueso <dave@stgolabs.net>
    Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
    Cc: SeongJae Park <sj@kernel.org>
    Cc: Sven Schnelle <svens@linux.ibm.com>
    Cc: Vlastimil Babka <vbabka@suse.cz>
    Cc: Will Deacon <will@kernel.org>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2166668
Signed-off-by: Nico Pache <npache@redhat.com>
2023-03-07 01:23:55 -07:00