Pedro Falcato contacted me on IRC with an mprotect regression which was
bisected back to the iterator changes for maple tree. Root cause
analysis showed the mas_prev() running off the end of the VMA space
(previous from 0) followed by mas_find(), would skip the first value.
This patch set introduces maple state underflow/overflow so the sequence
of calls on the maple state will return what the user expects.
Liam R. Howlett (2):
maple_tree: Add mas_active() to detect in-tree walks
maple_tree: Add MAS_UNDERFLOW and MAS_OVERFLOW states
include/linux/maple_tree.h | 11 ++
lib/maple_tree.c | 221 +++++++++++++++++++++++++++----------
lib/test_maple_tree.c | 87 ++++++++++++---
3 files changed, 246 insertions(+), 73 deletions(-)
--
2.39.2
Instead of constantly checking each possibility of the maple state,
create a fast path that will skip over checking unlikely states.
Signed-off-by: Liam R. Howlett <[email protected]>
---
include/linux/maple_tree.h | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/include/linux/maple_tree.h b/include/linux/maple_tree.h
index e41c70ac7744..f66f5f78f8cf 100644
--- a/include/linux/maple_tree.h
+++ b/include/linux/maple_tree.h
@@ -511,6 +511,15 @@ static inline bool mas_is_paused(const struct ma_state *mas)
return mas->node == MAS_PAUSE;
}
+/* Check if the mas is pointing to a node or not */
+static inline bool mas_is_active(struct ma_state *mas)
+{
+ if ((unsigned long)mas->node >= MAPLE_RESERVED_RANGE)
+ return true;
+
+ return false;
+}
+
/**
* mas_reset() - Reset a Maple Tree operation state.
* @mas: Maple Tree operation state.
--
2.39.2