* [PATCH 0/2] Fix mas_alloc_cyclic retry
@ 2024-12-16 19:01 Liam R. Howlett
2024-12-16 19:01 ` [PATCH 1/2] maple_tree: Fix mas_alloc_cyclic() second search Liam R. Howlett
2024-12-16 19:01 ` [PATCH 2/2] test_maple_tree: Test exhausted upper limit of mtree_alloc_cyclic() Liam R. Howlett
0 siblings, 2 replies; 5+ messages in thread
From: Liam R. Howlett @ 2024-12-16 19:01 UTC (permalink / raw)
To: Andrew Morton
Cc: maple-tree, linux-mm, linux-kernel, Yang Erkun, chuck.lever,
brauner, Liam R. Howlett
This is a follow-up patch and test for Yang Erkun. lore seems to have
eaten the original email [1], so I'll add akpm's link as well [2].
Patch 1 applies on top of Yang Erkun's fix, so feel free to squash it
in.
Patch 2 adds a test to the maple tree infrastructure that will catch the
issue if it comes back.
[1] https://lore.kernel.org/all/20241214093005.72284-1-yangerkun@huaweicloud.com/T/#u
[2] https://lore.kernel.org/all/20241216060600.287B4C4CED0@smtp.kernel.org/
Liam R. Howlett (2):
maple_tree: Fix mas_alloc_cyclic() second search
test_maple_tree: Test exhausted upper limit of mtree_alloc_cyclic()
lib/maple_tree.c | 3 +--
lib/test_maple_tree.c | 28 ++++++++++++++++++++++++++++
2 files changed, 29 insertions(+), 2 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] maple_tree: Fix mas_alloc_cyclic() second search
2024-12-16 19:01 [PATCH 0/2] Fix mas_alloc_cyclic retry Liam R. Howlett
@ 2024-12-16 19:01 ` Liam R. Howlett
2024-12-17 11:27 ` yangerkun
2024-12-16 19:01 ` [PATCH 2/2] test_maple_tree: Test exhausted upper limit of mtree_alloc_cyclic() Liam R. Howlett
1 sibling, 1 reply; 5+ messages in thread
From: Liam R. Howlett @ 2024-12-16 19:01 UTC (permalink / raw)
To: Andrew Morton
Cc: maple-tree, linux-mm, linux-kernel, Yang Erkun, chuck.lever,
brauner, Liam R. Howlett
From: "Liam R. Howlett" <Liam.Howlett@Oracle.com>
The first search may leave the maple state in an error state. Reset the
maple state before the second search so that the search has a chance of
executing correctly after an exhausted first search.
Link: https://lore.kernel.org/all/20241216060600.287B4C4CED0@smtp.kernel.org/
Fixes: 9b6713cc7522 ("maple_tree: Add mtree_alloc_cyclic()")
Cc: Yang Erkun <yangerkun@huaweicloud.com>
Cc: chuck.lever@oracle.com
Cc: brauner@kernel.org
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
---
lib/maple_tree.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/lib/maple_tree.c b/lib/maple_tree.c
index 940d30653407b..f7153ade1be5f 100644
--- a/lib/maple_tree.c
+++ b/lib/maple_tree.c
@@ -4335,7 +4335,6 @@ int mas_alloc_cyclic(struct ma_state *mas, unsigned long *startp,
{
unsigned long min = range_lo;
int ret = 0;
- struct ma_state m = *mas;
range_lo = max(min, *next);
ret = mas_empty_area(mas, range_lo, range_hi, 1);
@@ -4344,7 +4343,7 @@ int mas_alloc_cyclic(struct ma_state *mas, unsigned long *startp,
ret = 1;
}
if (ret < 0 && range_lo > min) {
- *mas = m;
+ mas_reset(mas);
ret = mas_empty_area(mas, min, range_hi, 1);
if (ret == 0)
ret = 1;
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/2] test_maple_tree: Test exhausted upper limit of mtree_alloc_cyclic()
2024-12-16 19:01 [PATCH 0/2] Fix mas_alloc_cyclic retry Liam R. Howlett
2024-12-16 19:01 ` [PATCH 1/2] maple_tree: Fix mas_alloc_cyclic() second search Liam R. Howlett
@ 2024-12-16 19:01 ` Liam R. Howlett
2024-12-17 11:41 ` yangerkun
1 sibling, 1 reply; 5+ messages in thread
From: Liam R. Howlett @ 2024-12-16 19:01 UTC (permalink / raw)
To: Andrew Morton
Cc: maple-tree, linux-mm, linux-kernel, Yang Erkun, chuck.lever,
brauner, Liam R. Howlett
From: "Liam R. Howlett" <Liam.Howlett@Oracle.com>
When the upper bound of the search is exhausted, the maple state may be
returned in an error state of -EBUSY. This means maple state needs to
be reset before the second search in mas_alloc_cylic() to ensure the
search happens. This test ensures the issue is not recreated.
Cc: Yang Erkun <yangerkun@huaweicloud.com>
Cc: chuck.lever@oracle.com
Cc: brauner@kernel.org
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
---
lib/test_maple_tree.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/lib/test_maple_tree.c b/lib/test_maple_tree.c
index 72bda304b5952..13e2a10d7554d 100644
--- a/lib/test_maple_tree.c
+++ b/lib/test_maple_tree.c
@@ -3738,6 +3738,34 @@ static noinline void __init alloc_cyclic_testing(struct maple_tree *mt)
}
mtree_destroy(mt);
+
+ /*
+ * Issue with reverse search was discovered
+ * https://lore.kernel.org/all/20241216060600.287B4C4CED0@smtp.kernel.org/
+ * Exhausting the allocation area and forcing the search to wrap needs a
+ * mas_reset() in mas_alloc_cyclic().
+ */
+ next = 0;
+ mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
+ for (int i = 0; i < 1023; i++) {
+ mtree_alloc_cyclic(mt, &location, mt, 2, 1024, &next, GFP_KERNEL);
+ MT_BUG_ON(mt, i != location - 2);
+ MT_BUG_ON(mt, i != next - 3);
+ MT_BUG_ON(mt, mtree_load(mt, location) != mt);
+ }
+ mtree_erase(mt, 123);
+ MT_BUG_ON(mt, mtree_load(mt, 123) != NULL);
+ mtree_alloc_cyclic(mt, &location, mt, 2, 1024, &next, GFP_KERNEL);
+ MT_BUG_ON(mt, 123 != location);
+ MT_BUG_ON(mt, 124 != next);
+ MT_BUG_ON(mt, mtree_load(mt, location) != mt);
+ mtree_erase(mt, 100);
+ mtree_alloc_cyclic(mt, &location, mt, 2, 1024, &next, GFP_KERNEL);
+ MT_BUG_ON(mt, 100 != location);
+ MT_BUG_ON(mt, 101 != next);
+ MT_BUG_ON(mt, mtree_load(mt, location) != mt);
+ mtree_destroy(mt);
+
/* Overflow test */
next = ULONG_MAX - 1;
ret = mtree_alloc_cyclic(mt, &location, mt, 2, ULONG_MAX, &next, GFP_KERNEL);
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] maple_tree: Fix mas_alloc_cyclic() second search
2024-12-16 19:01 ` [PATCH 1/2] maple_tree: Fix mas_alloc_cyclic() second search Liam R. Howlett
@ 2024-12-17 11:27 ` yangerkun
0 siblings, 0 replies; 5+ messages in thread
From: yangerkun @ 2024-12-17 11:27 UTC (permalink / raw)
To: Liam R. Howlett, Andrew Morton
Cc: maple-tree, linux-mm, linux-kernel, chuck.lever, brauner
在 2024/12/17 3:01, Liam R. Howlett 写道:
> From: "Liam R. Howlett" <Liam.Howlett@Oracle.com>
>
> The first search may leave the maple state in an error state. Reset the
> maple state before the second search so that the search has a chance of
> executing correctly after an exhausted first search.
>
> Link: https://lore.kernel.org/all/20241216060600.287B4C4CED0@smtp.kernel.org/
> Fixes: 9b6713cc7522 ("maple_tree: Add mtree_alloc_cyclic()")
> Cc: Yang Erkun <yangerkun@huaweicloud.com>
> Cc: chuck.lever@oracle.com
> Cc: brauner@kernel.org
> Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
> ---
> lib/maple_tree.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
This looks more clear!
Reviewed-by: Yang Erkun <yangerkun@huawei.com>
>
> diff --git a/lib/maple_tree.c b/lib/maple_tree.c
> index 940d30653407b..f7153ade1be5f 100644
> --- a/lib/maple_tree.c
> +++ b/lib/maple_tree.c
> @@ -4335,7 +4335,6 @@ int mas_alloc_cyclic(struct ma_state *mas, unsigned long *startp,
> {
> unsigned long min = range_lo;
> int ret = 0;
> - struct ma_state m = *mas;
>
> range_lo = max(min, *next);
> ret = mas_empty_area(mas, range_lo, range_hi, 1);
> @@ -4344,7 +4343,7 @@ int mas_alloc_cyclic(struct ma_state *mas, unsigned long *startp,
> ret = 1;
> }
> if (ret < 0 && range_lo > min) {
> - *mas = m;
> + mas_reset(mas);
> ret = mas_empty_area(mas, min, range_hi, 1);
> if (ret == 0)
> ret = 1;
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] test_maple_tree: Test exhausted upper limit of mtree_alloc_cyclic()
2024-12-16 19:01 ` [PATCH 2/2] test_maple_tree: Test exhausted upper limit of mtree_alloc_cyclic() Liam R. Howlett
@ 2024-12-17 11:41 ` yangerkun
0 siblings, 0 replies; 5+ messages in thread
From: yangerkun @ 2024-12-17 11:41 UTC (permalink / raw)
To: Liam R. Howlett, Andrew Morton
Cc: maple-tree, linux-mm, linux-kernel, chuck.lever, brauner
在 2024/12/17 3:01, Liam R. Howlett 写道:
> From: "Liam R. Howlett" <Liam.Howlett@Oracle.com>
>
> When the upper bound of the search is exhausted, the maple state may be
> returned in an error state of -EBUSY. This means maple state needs to
> be reset before the second search in mas_alloc_cylic() to ensure the
> search happens. This test ensures the issue is not recreated.
>
> Cc: Yang Erkun <yangerkun@huaweicloud.com>
> Cc: chuck.lever@oracle.com
> Cc: brauner@kernel.org
> Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
> ---
> lib/test_maple_tree.c | 28 ++++++++++++++++++++++++++++
> 1 file changed, 28 insertions(+)
>
Thanks for the testcase!
Reviewed-by: Yang Erkun <yangerkun@huawei.com>
> diff --git a/lib/test_maple_tree.c b/lib/test_maple_tree.c
> index 72bda304b5952..13e2a10d7554d 100644
> --- a/lib/test_maple_tree.c
> +++ b/lib/test_maple_tree.c
> @@ -3738,6 +3738,34 @@ static noinline void __init alloc_cyclic_testing(struct maple_tree *mt)
> }
>
> mtree_destroy(mt);
> +
> + /*
> + * Issue with reverse search was discovered
> + * https://lore.kernel.org/all/20241216060600.287B4C4CED0@smtp.kernel.org/
> + * Exhausting the allocation area and forcing the search to wrap needs a
> + * mas_reset() in mas_alloc_cyclic().
> + */
> + next = 0;
> + mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
> + for (int i = 0; i < 1023; i++) {
> + mtree_alloc_cyclic(mt, &location, mt, 2, 1024, &next, GFP_KERNEL);
> + MT_BUG_ON(mt, i != location - 2);
> + MT_BUG_ON(mt, i != next - 3);
> + MT_BUG_ON(mt, mtree_load(mt, location) != mt);
> + }
> + mtree_erase(mt, 123);
> + MT_BUG_ON(mt, mtree_load(mt, 123) != NULL);
> + mtree_alloc_cyclic(mt, &location, mt, 2, 1024, &next, GFP_KERNEL);
> + MT_BUG_ON(mt, 123 != location);
> + MT_BUG_ON(mt, 124 != next);
> + MT_BUG_ON(mt, mtree_load(mt, location) != mt);
> + mtree_erase(mt, 100);
> + mtree_alloc_cyclic(mt, &location, mt, 2, 1024, &next, GFP_KERNEL);
> + MT_BUG_ON(mt, 100 != location);
> + MT_BUG_ON(mt, 101 != next);
> + MT_BUG_ON(mt, mtree_load(mt, location) != mt);
> + mtree_destroy(mt);
> +
> /* Overflow test */
> next = ULONG_MAX - 1;
> ret = mtree_alloc_cyclic(mt, &location, mt, 2, ULONG_MAX, &next, GFP_KERNEL);
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-12-17 11:42 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-16 19:01 [PATCH 0/2] Fix mas_alloc_cyclic retry Liam R. Howlett
2024-12-16 19:01 ` [PATCH 1/2] maple_tree: Fix mas_alloc_cyclic() second search Liam R. Howlett
2024-12-17 11:27 ` yangerkun
2024-12-16 19:01 ` [PATCH 2/2] test_maple_tree: Test exhausted upper limit of mtree_alloc_cyclic() Liam R. Howlett
2024-12-17 11:41 ` yangerkun
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox