2023-04-21 14:03:08

by Liam R. Howlett

[permalink] [raw]
Subject: [PATCH v3 0/4] Fix mas_empty_area() search

mas_empty_area() search could potentially return a sub-optimal position
for a VMAs as it is coded. This patch set is to address the issue by
altering the maple tree search and the mmap call into that search.

Changes from v2:
- Addressed Peng Zhang's concerns around limit checking.
- Updated testing code to work with size of 1 and added tests for this
case.

v2: https://lore.kernel.org/linux-mm/[email protected]/
v1: https://lore.kernel.org/linux-mm/[email protected]/

Liam R. Howlett (4):
maple_tree: Make maple state reusable after mas_empty_area_rev()
maple_tree: Update mtree_alloc_rrange() and mtree_alloc_range()
testing
maple_tree: Fix mas_empty_area() search
mm/mmap: Regression fix for unmapped_area{_topdown}

lib/maple_tree.c | 61 ++++++++++++++++++++++++-------------------
lib/test_maple_tree.c | 27 ++++++++++++++-----
mm/mmap.c | 48 ++++++++++++++++++++++++++++++----
3 files changed, 97 insertions(+), 39 deletions(-)

--
2.39.2


2023-04-21 14:04:49

by Liam R. Howlett

[permalink] [raw]
Subject: [PATCH v3 3/4] maple_tree: Fix mas_empty_area() search

The internal function of mas_awalk() was incorrectly skipping the last
entry in a node, which could potentially be NULL. This is only a
problem for the left-most node in the tree - otherwise that NULL would
not exist.

Fix mas_awalk() by using the metadata to obtain the end of the node for
the loop and the logical pivot as apposed to the raw pivot value.

Fixes: 54a611b60590 ("Maple Tree: add new data structure")
Signed-off-by: Liam R. Howlett <[email protected]>
---
lib/maple_tree.c | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/lib/maple_tree.c b/lib/maple_tree.c
index cf4f6cdcaad38..51910c74d4895 100644
--- a/lib/maple_tree.c
+++ b/lib/maple_tree.c
@@ -5029,10 +5029,10 @@ static inline bool mas_anode_descend(struct ma_state *mas, unsigned long size)
{
enum maple_type type = mte_node_type(mas->node);
unsigned long pivot, min, gap = 0;
- unsigned char offset;
- unsigned long *gaps;
- unsigned long *pivots = ma_pivots(mas_mn(mas), type);
- void __rcu **slots = ma_slots(mas_mn(mas), type);
+ unsigned char offset, data_end;
+ unsigned long *gaps, *pivots;
+ void __rcu **slots;
+ struct maple_node *node;
bool found = false;

if (ma_is_dense(type)) {
@@ -5040,13 +5040,15 @@ static inline bool mas_anode_descend(struct ma_state *mas, unsigned long size)
return true;
}

- gaps = ma_gaps(mte_to_node(mas->node), type);
+ node = mas_mn(mas);
+ pivots = ma_pivots(node, type);
+ slots = ma_slots(node, type);
+ gaps = ma_gaps(node, type);
offset = mas->offset;
min = mas_safe_min(mas, pivots, offset);
- for (; offset < mt_slots[type]; offset++) {
- pivot = mas_safe_pivot(mas, pivots, offset, type);
- if (offset && !pivot)
- break;
+ data_end = ma_data_end(node, type, pivots, mas->max);
+ for (; offset <= data_end; offset++) {
+ pivot = mas_logical_pivot(mas, pivots, offset, type);

/* Not within lower bounds */
if (mas->index > pivot)
--
2.39.2