Skip to contentSkip to conversation

refine storing null

PATCH Applied Wei Yang 4 participants 16 messages Oct 31, 2024 – Nov 3, 2024

Subsystems (3)
lore
Share & tools
lore

Wei Yang

author
#0 lore raw

v5 cover refine storing null

The original thread[1] thoughts it is a problem in mas_new_root(). But after discussion, this should be an improvement on storing NULL.

Patch 1/2 preparation for refine.

Patch 3 remove redundant check in mas_new_root().

Patch 4 refine mas_store_root() to improve memory efficiency and remove possible consecutive NULL slot.

Patch 5 adds a test for storing NULL.

[1]: https://lkml.kernel.org/r/[email protected]

v5:
rebase on akpm mm-unstable
fix a build warning on xa_is_node() in patch 5

v4:
patch 3 add a WARN_ON_ONCE()
patch 4 add a comment and simplify the logic a little

v3:
patch 4 move the change into mas_store_root()
patch 5 move test into lib/test_maple_tree.c

Wei Yang (5):
maple_tree: print empty for an empty tree on mt_dump()
maple_tree: the return value of mas_root_expand() is not used
maple_tree: not necessary to check index/last again
maple_tree: refine mas_store_root() on storing NULL
maple_tree: add a test checking storing null

 lib/maple_tree.c      | 29 ++++++++++----
 lib/test_maple_tree.c | 90 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 112 insertions(+), 7 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v5 1/5 maple_tree: print empty for an empty tree on mt_dump()

Currently for an empty tree, it would print:

maple_tree(0x7ffcd02c6ee0) flags 1, height 0 root (nil) 0: (nil)

This is a little misleading.

Let's print (empty) for an empty tree.

CC Liam R. Howlett <[email protected]>
CC Sidhartha Kumar <[email protected]>
CC Lorenzo Stoakes <[email protected]>
---
 lib/maple_tree.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
lib/maple_tree.c +5 -3
index 38aa8abf8eb8..523355fb2bbe 100644
@@ -7273,10 +7273,12 @@ void mt_dump(const struct maple_tree *mt, enum mt_dump_format format)
 
 	pr_info("maple_tree(" PTR_FMT ") flags %X, height %u root " PTR_FMT "\n",
 		 mt, mt->ma_flags, mt_height(mt), entry);
-	if (!xa_is_node(entry))
-		mt_dump_entry(entry, 0, 0, 0, format);
-	else if (entry)
+	if (xa_is_node(entry))
 		mt_dump_node(mt, entry, 0, mt_node_max(entry), 0, format);
+	else if (entry)
+		mt_dump_entry(entry, 0, 0, 0, format);
+	else
+		pr_info("(empty)\n");
 }
 EXPORT_SYMBOL_GPL(mt_dump);
 
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH v5 2/5 maple_tree: the return value of mas_root_expand() is not used

In reply to Wei Yang

No user of the return value now, just remove it.

CC Liam R. Howlett <[email protected]>
CC Sidhartha Kumar <[email protected]>
CC Lorenzo Stoakes <[email protected]>
---
 lib/maple_tree.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/maple_tree.c +2 -2
index 523355fb2bbe..071d3055f1fa 100644
@@ -3408,7 +3408,7 @@ static noinline_for_kasan void mas_commit_b_node(struct ma_wr_state *wr_mas,
  * @mas: The maple state
  * @entry: The entry to store into the tree
  */
-static inline int mas_root_expand(struct ma_state *mas, void *entry)
+static inline void mas_root_expand(struct ma_state *mas, void *entry)
 {
 	void *contents = mas_root_locked(mas);
 	enum maple_type type = maple_leaf_64;
@@ -3444,7 +3444,7 @@ static inline int mas_root_expand(struct ma_state *mas, void *entry)
 	ma_set_meta(node, maple_leaf_64, 0, slot);
 	/* swap the new root into the tree */
 	rcu_assign_pointer(mas->tree->ma_root, mte_mk_root(mas->node));
-	return slot;
+	return;
 }
 
 static inline void mas_store_root(struct ma_state *mas, void *entry)
Signature · 1 line
2.34.1
author
#3 lore raw

PATCH v5 3/5 maple_tree: not necessary to check index/last again

In reply to Wei Yang

Before calling mas_new_root(), the range has been checked.

CC Liam R. Howlett <[email protected]>
CC Sidhartha Kumar <[email protected]>
CC Lorenzo Stoakes <[email protected]>

---
v4: add WARN_ON_ONCE() to check mis-usage.

---
 lib/maple_tree.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/maple_tree.c +3 -1
index 071d3055f1fa..4900f182e99d 100644
@@ -3670,7 +3670,9 @@ static inline void mas_new_root(struct ma_state *mas, void *entry)
 	void __rcu **slots;
 	unsigned long *pivots;
 
-	if (!entry && !mas->index && mas->last == ULONG_MAX) {
+	WARN_ON_ONCE(mas->index || mas->last != ULONG_MAX);
+
+	if (!entry) {
 		mas->depth = 0;
 		mas_set_height(mas);
 		rcu_assign_pointer(mas->tree->ma_root, entry);
Signature · 1 line
2.34.1
author
#4 lore raw

PATCH v5 4/5 maple_tree: refine mas_store_root() on storing NULL

In reply to Wei Yang

Currently, when storing NULL on mas_store_root(), the behavior could be improved.

For example possible cases are:

* store NULL at any range result a new node
* store NULL at range [m, n] where m > 0 to a single entry tree result a new node with range [m, n] set to NULL
* store NULL at range [m, n] where m > 0 to an empty tree result consecutive NULL slot
* it allows for multiple NULL entries by expanding root
to store NULLs to an empty tree

This patch tries to improve in:

* memory efficient by setting to empty tree instead of using a node
* remove the possibility of consecutive NULL slot which will prohibit extended null in later operation

CC Liam R. Howlett <[email protected]>
CC Sidhartha Kumar <[email protected]>
CC Lorenzo Stoakes <[email protected]>

---
v3: move change into mas_store_root()
v4: add a comment and simplify the logic a little
adjust the change log a little

---
 lib/maple_tree.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
lib/maple_tree.c +12 -1
index 4900f182e99d..d0ae808f3a14 100644
@@ -3447,9 +3447,20 @@ static inline void mas_root_expand(struct ma_state *mas, void *entry)
 	return;
 }
 
+/*
+ * mas_store_root() - Storing value into root.
+ * @mas: The maple state
+ * @entry: The entry to store.
+ *
+ * There is no root node now and we are storing a value into the root - this
+ * function either assigns the pointer or expands into a node.
+ */
 static inline void mas_store_root(struct ma_state *mas, void *entry)
 {
-	if (likely((mas->last != 0) || (mas->index != 0)))
+	if (!entry) {
+		if (!mas->index)
+			rcu_assign_pointer(mas->tree->ma_root, NULL);
+	} else if (likely((mas->last != 0) || (mas->index != 0)))
 		mas_root_expand(mas, entry);
 	else if (((unsigned long) (entry) & 3) == 2)
 		mas_root_expand(mas, entry);
Signature · 1 line
2.34.1
#5 lore raw

Re: [PATCH v5 4/5] maple_tree: refine mas_store_root() on storing NULL

Quoted 2 lines · Wei Yang

Currently, when storing NULL on mas_store_root(), the behavior could be improved.

Storing NULLs over the entire tree may result in a node being used to store a single range. Further stores of NULL may cause the node and tree to be corrupt and cause incorrect behaviour. Fixing the store to the root null fixes the issue by ensuring that a range of 0 - ULONG_MAX results in an empty tree.

Users of the tree may experience incorrect values returned if the tree was expanded to store values, then overwritten by all NULLS, then continued to store NULLs over the empty area.

Quoted 17 lines

For example possible cases are:

* store NULL at any range result a new node
* store NULL at range [m, n] where m > 0 to a single entry tree result a new node with range [m, n] set to NULL
* store NULL at range [m, n] where m > 0 to an empty tree result consecutive NULL slot
* it allows for multiple NULL entries by expanding root
to store NULLs to an empty tree

This patch tries to improve in:

* memory efficient by setting to empty tree instead of using a node
* remove the possibility of consecutive NULL slot which will prohibit extended null in later operation

Quoted 5 lines
CC Liam R. Howlett <[email protected]>
CC Sidhartha Kumar <[email protected]>
CC Lorenzo Stoakes <[email protected]>

Please add stable to Cc list, and fixes tag. This needs to be backported, probably to v6.1

Quoted 38 lines

---
v3: move change into mas_store_root()
v4: add a comment and simplify the logic a little
adjust the change log a little

---
 lib/maple_tree.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
lib/maple_tree.c +12 -1
index 4900f182e99d..d0ae808f3a14 100644
@@ -3447,9 +3447,20 @@ static inline void mas_root_expand(struct ma_state *mas, void *entry)
 	return;
 }
 
+/*
+ * mas_store_root() - Storing value into root.
+ * @mas: The maple state
+ * @entry: The entry to store.
+ *
+ * There is no root node now and we are storing a value into the root - this
+ * function either assigns the pointer or expands into a node.
+ */
 static inline void mas_store_root(struct ma_state *mas, void *entry)
 {
-	if (likely((mas->last != 0) || (mas->index != 0)))
+	if (!entry) {
+		if (!mas->index)
+			rcu_assign_pointer(mas->tree->ma_root, NULL);
+	} else if (likely((mas->last != 0) || (mas->index != 0)))
 		mas_root_expand(mas, entry);
 	else if (((unsigned long) (entry) & 3) == 2)
 		mas_root_expand(mas, entry);
Signature · 1 line
2.34.1
maintainer
#6 lore raw

Re: [PATCH v5 4/5] maple_tree: refine mas_store_root() on storing NULL

Quoted 10 lines · On Fri, 1 Nov 2024 10:59:24 -0400 "Liam R. Howlett" <[email protected]>…
Quoted 2 lines · Wei Yang

Currently, when storing NULL on mas_store_root(), the behavior could be improved.

Storing NULLs over the entire tree may result in a node being used to store a single range. Further stores of NULL may cause the node and tree to be corrupt and cause incorrect behaviour. Fixing the store to the root null fixes the issue by ensuring that a range of 0 - ULONG_MAX results in an empty tree.

Quoted 3 lines

Users of the tree may experience incorrect values returned if the tree was expanded to store values, then overwritten by all NULLS, then continued to store NULLs over the empty area.

I pasted that into the changelog.

Quoted 17 lines
Quoted 17 lines

For example possible cases are:

* store NULL at any range result a new node
* store NULL at range [m, n] where m > 0 to a single entry tree result a new node with range [m, n] set to NULL
* store NULL at range [m, n] where m > 0 to an empty tree result consecutive NULL slot
* it allows for multiple NULL entries by expanding root
to store NULLs to an empty tree

This patch tries to improve in:

* memory efficient by setting to empty tree instead of using a node
* remove the possibility of consecutive NULL slot which will prohibit extended null in later operation

Quoted 8 lines
Quoted 5 lines
CC Liam R. Howlett <[email protected]>
CC Sidhartha Kumar <[email protected]>
CC Lorenzo Stoakes <[email protected]>

Please add stable to Cc list, and fixes tag. This needs to be backported, probably to v6.1

I added

Fixes 54a611b60590 ("Maple Tree: add new data structure")
author
#7 lore raw

PATCH v5 5/5 maple_tree: add a test checking storing null

In reply to Wei Yang

Add a test to assert that, when storing null to am empty tree or a single entry tree it will not result into:

* a root node with range [0, ULONG_MAX] set to NULL
* a root node with consecutive slot set to NULL

CC Liam R. Howlett <[email protected]>
CC Sidhartha Kumar <[email protected]>
CC Lorenzo Stoakes <[email protected]>

---
v3: move test into lib/test_maple_tree.c
v5: fix a build warning on xa_is_node()

---
 lib/test_maple_tree.c | 90 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)
lib/test_maple_tree.c +90 -0
index 31561e0e1a0d..6f76093170bb 100644
@@ -1387,6 +1387,92 @@ static noinline void __init check_prev_entry(struct maple_tree *mt)
 	mas_unlock(&mas);
 }
 
+static noinline void __init check_store_null(struct maple_tree *mt)
+{
+	MA_STATE(mas, mt, 0, ULONG_MAX);
+
+	/*
+	 * Store NULL at range [0, ULONG_MAX] to an empty tree should result
+	 * in an empty tree
+	 */
+	mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
+	mas_lock(&mas);
+	mas_store_gfp(&mas, NULL, GFP_KERNEL);
+	MT_BUG_ON(mt, !mtree_empty(mt));
+	mas_unlock(&mas);
+	mtree_destroy(mt);
+
+	/*
+	 * Store NULL at any range to an empty tree should result in an empty
+	 * tree
+	 */
+	mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
+	mas_lock(&mas);
+	mas_set_range(&mas, 3, 10);
+	mas_store_gfp(&mas, NULL, GFP_KERNEL);
+	MT_BUG_ON(mt, !mtree_empty(mt));
+	mas_unlock(&mas);
+	mtree_destroy(mt);
+
+	/*
+	 * Store NULL at range [0, ULONG_MAX] to a single entry tree should
+	 * result in an empty tree
+	 */
+	mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
+	mas_lock(&mas);
+	mas_set(&mas, 0);
+	mas_store_gfp(&mas, &mas, GFP_KERNEL);
+	mas_set_range(&mas, 0, ULONG_MAX);
+	mas_store_gfp(&mas, NULL, GFP_KERNEL);
+	MT_BUG_ON(mt, !mtree_empty(mt));
+	mas_unlock(&mas);
+	mtree_destroy(mt);
+
+	/*
+	 * Store NULL at range [0, n] to a single entry tree should
+	 * result in an empty tree
+	 */
+	mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
+	mas_lock(&mas);
+	mas_set(&mas, 0);
+	mas_store_gfp(&mas, &mas, GFP_KERNEL);
+	mas_set_range(&mas, 0, 5);
+	mas_store_gfp(&mas, NULL, GFP_KERNEL);
+	MT_BUG_ON(mt, !mtree_empty(mt));
+	mas_unlock(&mas);
+	mtree_destroy(mt);
+
+	/*
+	 * Store NULL at range [m, n] where m > 0 to a single entry tree
+	 * should still be a single entry tree
+	 */
+	mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
+	mas_lock(&mas);
+	mas_set(&mas, 0);
+	mas_store_gfp(&mas, &mas, GFP_KERNEL);
+	mas_set_range(&mas, 2, 5);
+	mas_store_gfp(&mas, NULL, GFP_KERNEL);
+	MT_BUG_ON(mt, mtree_empty(mt));
+	MT_BUG_ON(mt, xa_is_node(mas_root(&mas)));
+	mas_unlock(&mas);
+	mtree_destroy(mt);
+
+	/*
+	 * Store NULL at range [0, ULONG_MAX] to a tree with node should
+	 * result in an empty tree
+	 */
+	mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
+	mas_lock(&mas);
+	mas_set_range(&mas, 1, 3);
+	mas_store_gfp(&mas, &mas, GFP_KERNEL);
+	MT_BUG_ON(mt, !xa_is_node(mas_root(&mas)));
+	mas_set_range(&mas, 0, ULONG_MAX);
+	mas_store_gfp(&mas, NULL, GFP_KERNEL);
+	MT_BUG_ON(mt, !mtree_empty(mt));
+	mas_unlock(&mas);
+	mtree_destroy(mt);
+}
+
 static noinline void __init check_root_expand(struct maple_tree *mt)
 {
 	MA_STATE(mas, mt, 0, 0);
@@ -3710,6 +3796,10 @@ static int __init maple_tree_seed(void)
 	goto skip;
 #endif
 
+	mt_init_flags(&tree, MT_FLAGS_ALLOC_RANGE);
+	check_store_null(&tree);
+	mtree_destroy(&tree);
+
 	mt_init_flags(&tree, MT_FLAGS_ALLOC_RANGE);
 	check_root_expand(&tree);
 	mtree_destroy(&tree);
Signature · 1 line
2.34.1
maintainer
#8 lore raw

Re: [PATCH v5 5/5] maple_tree: add a test checking storing null

Quoted 6 lines · On Thu, 31 Oct 2024 23:16:27 +0000 Wei Yang <[email protected]> wrote:

Add a test to assert that, when storing null to am empty tree or a single entry tree it will not result into:

* a root node with range [0, ULONG_MAX] set to NULL
* a root node with consecutive slot set to NULL

I don't get it.

Quoted 6 lines
lib/test_maple_tree.c +0 -0
@@ -1387,6 +1387,92 @@ static noinline void __init check_prev_entry(struct maple_tree *mt)
 	mas_unlock(&mas);
 }

lib/test_maple_tree.c static noinline void __init check_prev_entry(struct maple_tree *mt)

Quoted 10 lines
lib/test_maple_tree.c +5 -0
 
+static noinline void __init check_store_null(struct maple_tree *mt)
+{
+	MA_STATE(mas, mt, 0, ULONG_MAX);
+
 
...
 
+	MT_BUG_ON(mt, !xa_is_node(mas_root(&mas)));
...

mas_root() is private to lib/maple_tree.c. I'll do this for now:

lib/test_maple_tree.c renamed from lib/test_maple_tree.c~maple_tree-add-a-test-checking-storing-null-fix +2 -2
@@ -1453,7 +1453,7 @@ static noinline void __init check_store_
 	mas_set_range(&mas, 2, 5);
 	mas_store_gfp(&mas, NULL, GFP_KERNEL);
 	MT_BUG_ON(mt, mtree_empty(mt));
-	MT_BUG_ON(mt, xa_is_node(mas_root(&mas)));
+//	MT_BUG_ON(mt, xa_is_node(mas_root(&mas)));
 	mas_unlock(&mas);
 	mtree_destroy(mt);
 
@@ -1465,7 +1465,7 @@ static noinline void __init check_store_
 	mas_lock(&mas);
 	mas_set_range(&mas, 1, 3);
 	mas_store_gfp(&mas, &mas, GFP_KERNEL);
-	MT_BUG_ON(mt, !xa_is_node(mas_root(&mas)));
+//	MT_BUG_ON(mt, !xa_is_node(mas_root(&mas)));
 	mas_set_range(&mas, 0, ULONG_MAX);
 	mas_store_gfp(&mas, NULL, GFP_KERNEL);
 	MT_BUG_ON(mt, !mtree_empty(mt));

_

author
#9 lore raw

Re: [PATCH v5 5/5] maple_tree: add a test checking storing null

Quoted 11 lines · Andrew Morton
Quoted 6 lines · On Thu, 31 Oct 2024 23:16:27 +0000 Wei Yang <[email protected]> wrote:

Add a test to assert that, when storing null to am empty tree or a single entry tree it will not result into:

* a root node with range [0, ULONG_MAX] set to NULL
* a root node with consecutive slot set to NULL

I don't get it.

For example, if we store NULL to [3, 10] currently, we will have a root node like this.

maple_tree(0x7fff2b797170) flags 5, height 1 root 0x615000000d0e
0-18446744073709551615: node 0x615000000d00 depth 0 type 1 parent 0x7fff2b797171 contents: (nil) 2 (nil) 10 (nil) 18446744073709551615 (nil) 0 (nil) 0 (nil) 0 (nil) 0 (nil) 0 (nil) 0 (nil) 0 (nil) 0 (nil) 0 (nil) 0 (nil) 0 (nil) 0 0x2
0-2: (nil)
3-10: (nil)
11-18446744073709551615: (nil)

Slot 0, 1 is consecutively set to NULL. This is not expected.

Quoted 11 lines
Quoted 11 lines
lib/test_maple_tree.c +4 -0
@@ -1387,6 +1387,92 @@ static noinline void __init check_prev_entry(struct maple_tree *mt)
 	mas_unlock(&mas);
 }
 
+static noinline void __init check_store_null(struct maple_tree *mt)
+{
+	MA_STATE(mas, mt, 0, ULONG_MAX);
+
 
Quoted 7 lines

lib/test_maple_tree.c

Quoted 5 lines

...

lib/test_maple_tree.c +1 -0
+	MT_BUG_ON(mt, !xa_is_node(mas_root(&mas)));
...

mas_root() is private to lib/maple_tree.c. I'll do this for now:

Oh, thanks.

Quoted 22 lines
lib/test_maple_tree.c renamed from lib/test_maple_tree.c~maple_tree-add-a-test-checking-storing-null-fix +2 -2
@@ -1453,7 +1453,7 @@ static noinline void __init check_store_
 	mas_set_range(&mas, 2, 5);
 	mas_store_gfp(&mas, NULL, GFP_KERNEL);
 	MT_BUG_ON(mt, mtree_empty(mt));
-	MT_BUG_ON(mt, xa_is_node(mas_root(&mas)));
+//	MT_BUG_ON(mt, xa_is_node(mas_root(&mas)));
 	mas_unlock(&mas);
 	mtree_destroy(mt);
 
@@ -1465,7 +1465,7 @@ static noinline void __init check_store_
 	mas_lock(&mas);
 	mas_set_range(&mas, 1, 3);
 	mas_store_gfp(&mas, &mas, GFP_KERNEL);
-	MT_BUG_ON(mt, !xa_is_node(mas_root(&mas)));
+//	MT_BUG_ON(mt, !xa_is_node(mas_root(&mas)));
 	mas_set_range(&mas, 0, ULONG_MAX);
 	mas_store_gfp(&mas, NULL, GFP_KERNEL);
 	MT_BUG_ON(mt, !mtree_empty(mt));

_

Signature · 2 lines
Wei Yang
Help you, Help me
#10 lore raw

Re: [PATCH v5 5/5] maple_tree: add a test checking storing null

In reply to Wei Yang
kernel test robot noticed the following build errors:

Hi Wei,

kernel test robot noticed the following build errors:

[auto build test ERROR on akpm-mm/mm-everything]
[also build test ERROR on linus/master v6.12-rc5 next-20241101] [cannot apply to akpm-mm/mm-nonmm-unstable]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Wei-Yang/maple_tree-print-empty-for-an-empty-tree-on-mt_dump/20241101-071827
base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link:    https://lore.kernel.org/r/20241031231627.14316-6-richard.weiyang%40gmail.com
patch subject: [PATCH v5 5/5] maple_tree: add a test checking storing null
config: arm-randconfig-002-20241102 (https://download.01.org/0day-ci/archive/20241102/[email protected]/config)
compiler: arm-linux-gnueabi-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241102/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

In file included from lib/test_maple_tree.c:10:
lib/test_maple_tree.c: In function 'check_store_null':

>> lib/test_maple_tree.c:1456:34: error: implicit declaration of function 'mas_root' [-Wimplicit-function-declaration]
    1456 |         MT_BUG_ON(mt, xa_is_node(mas_root(&mas)));
         |                                  ^~~~~~~~
   include/linux/maple_tree.h:625:13: note: in definition of macro 'MT_BUG_ON'
     625 |         if (__x) {                                                      \
         |             ^~~
>> lib/test_maple_tree.c:1456:34: error: passing argument 1 of 'xa_is_node' makes pointer from integer without a cast [-Wint-conversion]
    1456 |         MT_BUG_ON(mt, xa_is_node(mas_root(&mas)));
         |                                  ^~~~~~~~~~~~~~
         |                                  |
         |                                  int
   include/linux/maple_tree.h:625:13: note: in definition of macro 'MT_BUG_ON'
     625 |         if (__x) {                                                      \
         |             ^~~
   In file included from include/linux/radix-tree.h:21,
                    from include/linux/idr.h:15,
                    from include/linux/kernfs.h:12,
                    from include/linux/sysfs.h:16,
                    from include/linux/kobject.h:20,
                    from include/linux/module.h:21,
                    from lib/test_maple_tree.c:11:
   include/linux/xarray.h:1262:43: note: expected 'const void *' but argument is of type 'int'
    1262 | static inline bool xa_is_node(const void *entry)
         |                               ~~~~~~~~~~~~^~~~~
   In file included from include/linux/kernel.h:31,
                    from include/linux/maple_tree.h:11:
>> lib/test_maple_tree.c:1456:34: error: passing argument 1 of 'xa_is_node' makes pointer from integer without a cast [-Wint-conversion]
    1456 |         MT_BUG_ON(mt, xa_is_node(mas_root(&mas)));
         |                                  ^~~~~~~~~~~~~~
         |                                  |
         |                                  int
   include/linux/printk.h:462:33: note: in definition of macro 'printk_index_wrap'
     462 |                 _p_func(_fmt, ##__VA_ARGS__);                           \
         |                                 ^~~~~~~~~~~
   include/linux/printk.h:563:9: note: in expansion of macro 'printk'
     563 |         printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
         |         ^~~~~~
   include/linux/maple_tree.h:626:17: note: in expansion of macro 'pr_info'
     626 |                 pr_info("BUG at %s:%d (%u)\n",                          \
         |                 ^~~~~~~
   lib/test_maple_tree.c:1456:9: note: in expansion of macro 'MT_BUG_ON'
    1456 |         MT_BUG_ON(mt, xa_is_node(mas_root(&mas)));
         |         ^~~~~~~~~
   include/linux/xarray.h:1262:43: note: expected 'const void *' but argument is of type 'int'
    1262 | static inline bool xa_is_node(const void *entry)
         |                               ~~~~~~~~~~~~^~~~~
   lib/test_maple_tree.c:1468:35: error: passing argument 1 of 'xa_is_node' makes pointer from integer without a cast [-Wint-conversion]
    1468 |         MT_BUG_ON(mt, !xa_is_node(mas_root(&mas)));
         |                                   ^~~~~~~~~~~~~~
         |                                   |
         |                                   int
   include/linux/maple_tree.h:625:13: note: in definition of macro 'MT_BUG_ON'
     625 |         if (__x) {                                                      \
         |             ^~~
   include/linux/xarray.h:1262:43: note: expected 'const void *' but argument is of type 'int'
    1262 | static inline bool xa_is_node(const void *entry)
         |                               ~~~~~~~~~~~~^~~~~
   lib/test_maple_tree.c:1468:35: error: passing argument 1 of 'xa_is_node' makes pointer from integer without a cast [-Wint-conversion]
    1468 |         MT_BUG_ON(mt, !xa_is_node(mas_root(&mas)));
         |                                   ^~~~~~~~~~~~~~
         |                                   |
         |                                   int
   include/linux/printk.h:462:33: note: in definition of macro 'printk_index_wrap'
     462 |                 _p_func(_fmt, ##__VA_ARGS__);                           \
         |                                 ^~~~~~~~~~~
   include/linux/printk.h:563:9: note: in expansion of macro 'printk'
     563 |         printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
         |         ^~~~~~
   include/linux/maple_tree.h:626:17: note: in expansion of macro 'pr_info'
     626 |                 pr_info("BUG at %s:%d (%u)\n",                          \
         |                 ^~~~~~~
   lib/test_maple_tree.c:1468:9: note: in expansion of macro 'MT_BUG_ON'
    1468 |         MT_BUG_ON(mt, !xa_is_node(mas_root(&mas)));
         |         ^~~~~~~~~

include/linux/xarray.h:1262:43: note: expected 'const void *' but argument is of type 'int'
1262 | static inline bool xa_is_node(const void *entry)
| ~~~~~~~~~~~~^~~~~

vim +/mas_root +1456 lib/test_maple_tree.c

1389
1390 static noinline void __init check_store_null(struct maple_tree *mt)
1391 {
1392 MA_STATE(mas, mt, 0, ULONG_MAX);
1393
1394 /*
1395 * Store NULL at range [0, ULONG_MAX] to an empty tree should result
1396 * in an empty tree
1397 */
1398 mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
1399 mas_lock(&mas);
1400 mas_store_gfp(&mas, NULL, GFP_KERNEL);
1401 MT_BUG_ON(mt, !mtree_empty(mt));
1402 mas_unlock(&mas);
1403 mtree_destroy(mt);
1404
1405 /*
1406 * Store NULL at any range to an empty tree should result in an empty
1407 * tree
1408 */
1409 mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
1410 mas_lock(&mas);
1411 mas_set_range(&mas, 3, 10);
1412 mas_store_gfp(&mas, NULL, GFP_KERNEL);
1413 MT_BUG_ON(mt, !mtree_empty(mt));
1414 mas_unlock(&mas);
1415 mtree_destroy(mt);
1416
1417 /*
1418 * Store NULL at range [0, ULONG_MAX] to a single entry tree should
1419 * result in an empty tree
1420 */
1421 mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
1422 mas_lock(&mas);
1423 mas_set(&mas, 0);
1424 mas_store_gfp(&mas, &mas, GFP_KERNEL);
1425 mas_set_range(&mas, 0, ULONG_MAX);
1426 mas_store_gfp(&mas, NULL, GFP_KERNEL);
1427 MT_BUG_ON(mt, !mtree_empty(mt));
1428 mas_unlock(&mas);
1429 mtree_destroy(mt);
1430
1431 /*
1432 * Store NULL at range [0, n] to a single entry tree should
1433 * result in an empty tree
1434 */
1435 mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
1436 mas_lock(&mas);
1437 mas_set(&mas, 0);
1438 mas_store_gfp(&mas, &mas, GFP_KERNEL);
1439 mas_set_range(&mas, 0, 5);
1440 mas_store_gfp(&mas, NULL, GFP_KERNEL);
1441 MT_BUG_ON(mt, !mtree_empty(mt));
1442 mas_unlock(&mas);
1443 mtree_destroy(mt);
1444
1445 /*
1446 * Store NULL at range [m, n] where m > 0 to a single entry tree
1447 * should still be a single entry tree
1448 */
1449 mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
1450 mas_lock(&mas);
1451 mas_set(&mas, 0);
1452 mas_store_gfp(&mas, &mas, GFP_KERNEL);
1453 mas_set_range(&mas, 2, 5);
1454 mas_store_gfp(&mas, NULL, GFP_KERNEL);
1455 MT_BUG_ON(mt, mtree_empty(mt));

> 1456		MT_BUG_ON(mt, xa_is_node(mas_root(&mas)));

1457 mas_unlock(&mas);
1458 mtree_destroy(mt);
1459
1460 /*
1461 * Store NULL at range [0, ULONG_MAX] to a tree with node should
1462 * result in an empty tree
1463 */
1464 mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
1465 mas_lock(&mas);
1466 mas_set_range(&mas, 1, 3);
1467 mas_store_gfp(&mas, &mas, GFP_KERNEL);
1468 MT_BUG_ON(mt, !xa_is_node(mas_root(&mas)));
1469 mas_set_range(&mas, 0, ULONG_MAX);
1470 mas_store_gfp(&mas, NULL, GFP_KERNEL);
1471 MT_BUG_ON(mt, !mtree_empty(mt));
1472 mas_unlock(&mas);
1473 mtree_destroy(mt);
1474 }
1475

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#11 lore raw

Re: [PATCH v5 5/5] maple_tree: add a test checking storing null

In reply to Wei Yang
kernel test robot noticed the following build warnings:

Hi Wei,

kernel test robot noticed the following build warnings:

[auto build test WARNING on akpm-mm/mm-everything]
[also build test WARNING on linus/master v6.12-rc5 next-20241101] [cannot apply to akpm-mm/mm-nonmm-unstable]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Wei-Yang/maple_tree-print-empty-for-an-empty-tree-on-mt_dump/20241101-071827
base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link:    https://lore.kernel.org/r/20241031231627.14316-6-richard.weiyang%40gmail.com
patch subject: [PATCH v5 5/5] maple_tree: add a test checking storing null
config: m68k-amiga_defconfig (https://download.01.org/0day-ci/archive/20241102/[email protected]/config)
compiler: m68k-linux-gcc (GCC) 13.3.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241102/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

lib/test_maple_tree.c: In function 'check_store_null':
lib/test_maple_tree.c:1456:34: error: implicit declaration of function 'mas_root' [-Werror=implicit-function-declaration]

    1456 |         MT_BUG_ON(mt, xa_is_node(mas_root(&mas)));
         |                                  ^~~~~~~~
   lib/test_maple_tree.c:30:13: note: in definition of macro 'MT_BUG_ON'
      30 |         if (__x) {                                                      \
         |             ^~~
>> lib/test_maple_tree.c:1456:34: warning: passing argument 1 of 'xa_is_node' makes pointer from integer without a cast [-Wint-conversion]
    1456 |         MT_BUG_ON(mt, xa_is_node(mas_root(&mas)));
         |                                  ^~~~~~~~~~~~~~
         |                                  |
         |                                  int
   lib/test_maple_tree.c:30:13: note: in definition of macro 'MT_BUG_ON'
      30 |         if (__x) {                                                      \
         |             ^~~
   In file included from include/linux/radix-tree.h:21,
                    from include/linux/idr.h:15,
                    from include/linux/kernfs.h:12,
                    from include/linux/sysfs.h:16,
                    from include/linux/kobject.h:20,
                    from include/linux/module.h:21,
                    from lib/test_maple_tree.c:11:
   include/linux/xarray.h:1262:43: note: expected 'const void *' but argument is of type 'int'
    1262 | static inline bool xa_is_node(const void *entry)
         |                               ~~~~~~~~~~~~^~~~~
   In file included from include/linux/kernel.h:31,
                    from include/linux/maple_tree.h:11,
                    from lib/test_maple_tree.c:10:
>> lib/test_maple_tree.c:1456:34: warning: passing argument 1 of 'xa_is_node' makes pointer from integer without a cast [-Wint-conversion]
    1456 |         MT_BUG_ON(mt, xa_is_node(mas_root(&mas)));
         |                                  ^~~~~~~~~~~~~~
         |                                  |
         |                                  int
   include/linux/printk.h:462:33: note: in definition of macro 'printk_index_wrap'
     462 |                 _p_func(_fmt, ##__VA_ARGS__);                           \
         |                                 ^~~~~~~~~~~
   include/linux/printk.h:563:9: note: in expansion of macro 'printk'
     563 |         printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
         |         ^~~~~~
   lib/test_maple_tree.c:31:17: note: in expansion of macro 'pr_info'
      31 |                 pr_info("BUG at %s:%d (%u)\n",                          \
         |                 ^~~~~~~
   lib/test_maple_tree.c:1456:9: note: in expansion of macro 'MT_BUG_ON'
    1456 |         MT_BUG_ON(mt, xa_is_node(mas_root(&mas)));
         |         ^~~~~~~~~
   include/linux/xarray.h:1262:43: note: expected 'const void *' but argument is of type 'int'
    1262 | static inline bool xa_is_node(const void *entry)
         |                               ~~~~~~~~~~~~^~~~~
   lib/test_maple_tree.c:1468:35: warning: passing argument 1 of 'xa_is_node' makes pointer from integer without a cast [-Wint-conversion]
    1468 |         MT_BUG_ON(mt, !xa_is_node(mas_root(&mas)));
         |                                   ^~~~~~~~~~~~~~
         |                                   |
         |                                   int
   lib/test_maple_tree.c:30:13: note: in definition of macro 'MT_BUG_ON'
      30 |         if (__x) {                                                      \
         |             ^~~
   include/linux/xarray.h:1262:43: note: expected 'const void *' but argument is of type 'int'
    1262 | static inline bool xa_is_node(const void *entry)
         |                               ~~~~~~~~~~~~^~~~~
   lib/test_maple_tree.c:1468:35: warning: passing argument 1 of 'xa_is_node' makes pointer from integer without a cast [-Wint-conversion]
    1468 |         MT_BUG_ON(mt, !xa_is_node(mas_root(&mas)));
         |                                   ^~~~~~~~~~~~~~
         |                                   |
         |                                   int
   include/linux/printk.h:462:33: note: in definition of macro 'printk_index_wrap'
     462 |                 _p_func(_fmt, ##__VA_ARGS__);                           \
         |                                 ^~~~~~~~~~~
   include/linux/printk.h:563:9: note: in expansion of macro 'printk'
     563 |         printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
         |         ^~~~~~
   lib/test_maple_tree.c:31:17: note: in expansion of macro 'pr_info'
      31 |                 pr_info("BUG at %s:%d (%u)\n",                          \
         |                 ^~~~~~~
   lib/test_maple_tree.c:1468:9: note: in expansion of macro 'MT_BUG_ON'
    1468 |         MT_BUG_ON(mt, !xa_is_node(mas_root(&mas)));
         |         ^~~~~~~~~

include/linux/xarray.h:1262:43: note: expected 'const void *' but argument is of type 'int'
1262 | static inline bool xa_is_node(const void *entry)
| ~~~~~~~~~~~~^~~~~
cc1: some warnings being treated as errors

vim +/xa_is_node +1456 lib/test_maple_tree.c

1389
1390 static noinline void __init check_store_null(struct maple_tree *mt)
1391 {
1392 MA_STATE(mas, mt, 0, ULONG_MAX);
1393
1394 /*
1395 * Store NULL at range [0, ULONG_MAX] to an empty tree should result
1396 * in an empty tree
1397 */
1398 mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
1399 mas_lock(&mas);
1400 mas_store_gfp(&mas, NULL, GFP_KERNEL);
1401 MT_BUG_ON(mt, !mtree_empty(mt));
1402 mas_unlock(&mas);
1403 mtree_destroy(mt);
1404
1405 /*
1406 * Store NULL at any range to an empty tree should result in an empty
1407 * tree
1408 */
1409 mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
1410 mas_lock(&mas);
1411 mas_set_range(&mas, 3, 10);
1412 mas_store_gfp(&mas, NULL, GFP_KERNEL);
1413 MT_BUG_ON(mt, !mtree_empty(mt));
1414 mas_unlock(&mas);
1415 mtree_destroy(mt);
1416
1417 /*
1418 * Store NULL at range [0, ULONG_MAX] to a single entry tree should
1419 * result in an empty tree
1420 */
1421 mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
1422 mas_lock(&mas);
1423 mas_set(&mas, 0);
1424 mas_store_gfp(&mas, &mas, GFP_KERNEL);
1425 mas_set_range(&mas, 0, ULONG_MAX);
1426 mas_store_gfp(&mas, NULL, GFP_KERNEL);
1427 MT_BUG_ON(mt, !mtree_empty(mt));
1428 mas_unlock(&mas);
1429 mtree_destroy(mt);
1430
1431 /*
1432 * Store NULL at range [0, n] to a single entry tree should
1433 * result in an empty tree
1434 */
1435 mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
1436 mas_lock(&mas);
1437 mas_set(&mas, 0);
1438 mas_store_gfp(&mas, &mas, GFP_KERNEL);
1439 mas_set_range(&mas, 0, 5);
1440 mas_store_gfp(&mas, NULL, GFP_KERNEL);
1441 MT_BUG_ON(mt, !mtree_empty(mt));
1442 mas_unlock(&mas);
1443 mtree_destroy(mt);
1444
1445 /*
1446 * Store NULL at range [m, n] where m > 0 to a single entry tree
1447 * should still be a single entry tree
1448 */
1449 mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
1450 mas_lock(&mas);
1451 mas_set(&mas, 0);
1452 mas_store_gfp(&mas, &mas, GFP_KERNEL);
1453 mas_set_range(&mas, 2, 5);
1454 mas_store_gfp(&mas, NULL, GFP_KERNEL);
1455 MT_BUG_ON(mt, mtree_empty(mt));

> 1456		MT_BUG_ON(mt, xa_is_node(mas_root(&mas)));

1457 mas_unlock(&mas);
1458 mtree_destroy(mt);
1459
1460 /*
1461 * Store NULL at range [0, ULONG_MAX] to a tree with node should
1462 * result in an empty tree
1463 */
1464 mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
1465 mas_lock(&mas);
1466 mas_set_range(&mas, 1, 3);
1467 mas_store_gfp(&mas, &mas, GFP_KERNEL);
1468 MT_BUG_ON(mt, !xa_is_node(mas_root(&mas)));
1469 mas_set_range(&mas, 0, ULONG_MAX);
1470 mas_store_gfp(&mas, NULL, GFP_KERNEL);
1471 MT_BUG_ON(mt, !mtree_empty(mt));
1472 mas_unlock(&mas);
1473 mtree_destroy(mt);
1474 }
1475

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#12 lore raw

Re: [PATCH v5 5/5] maple_tree: add a test checking storing null

In reply to Wei Yang
kernel test robot noticed the following build errors:

Hi Wei,

kernel test robot noticed the following build errors:

[auto build test ERROR on akpm-mm/mm-everything]
[also build test ERROR on linus/master v6.12-rc5 next-20241101] [cannot apply to akpm-mm/mm-nonmm-unstable]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Wei-Yang/maple_tree-print-empty-for-an-empty-tree-on-mt_dump/20241101-071827
base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link:    https://lore.kernel.org/r/20241031231627.14316-6-richard.weiyang%40gmail.com
patch subject: [PATCH v5 5/5] maple_tree: add a test checking storing null
config: arm64-randconfig-r072-20241102 (https://download.01.org/0day-ci/archive/20241102/[email protected]/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241102/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All error/warnings (new ones prefixed by >>):

>> lib/test_maple_tree.c:1456:27: error: implicit declaration of function 'mas_root' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
           MT_BUG_ON(mt, xa_is_node(mas_root(&mas)));
                                    ^
>> lib/test_maple_tree.c:1456:27: warning: incompatible integer to pointer conversion passing 'int' to parameter of type 'const void *' [-Wint-conversion]
           MT_BUG_ON(mt, xa_is_node(mas_root(&mas)));
                                    ^~~~~~~~~~~~~~
   include/linux/maple_tree.h:625:6: note: expanded from macro 'MT_BUG_ON'
           if (__x) {                                                      \
               ^~~
   include/linux/compiler.h:55:47: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                                                 ^~~~
   include/linux/compiler.h:57:52: note: expanded from macro '__trace_if_var'
   #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                                      ^~~~
   include/linux/xarray.h:1262:43: note: passing argument to parameter 'entry' here
   static inline bool xa_is_node(const void *entry)
                                             ^
>> lib/test_maple_tree.c:1456:27: warning: incompatible integer to pointer conversion passing 'int' to parameter of type 'const void *' [-Wint-conversion]
           MT_BUG_ON(mt, xa_is_node(mas_root(&mas)));
                                    ^~~~~~~~~~~~~~
   include/linux/maple_tree.h:625:6: note: expanded from macro 'MT_BUG_ON'
           if (__x) {                                                      \
               ^~~
   include/linux/compiler.h:55:47: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                                                 ^~~~
   include/linux/compiler.h:57:61: note: expanded from macro '__trace_if_var'
   #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                                               ^~~~
   include/linux/xarray.h:1262:43: note: passing argument to parameter 'entry' here
   static inline bool xa_is_node(const void *entry)
                                             ^
>> lib/test_maple_tree.c:1456:27: warning: incompatible integer to pointer conversion passing 'int' to parameter of type 'const void *' [-Wint-conversion]
           MT_BUG_ON(mt, xa_is_node(mas_root(&mas)));
                                    ^~~~~~~~~~~~~~
   include/linux/maple_tree.h:625:6: note: expanded from macro 'MT_BUG_ON'
           if (__x) {                                                      \
               ^~~
   include/linux/compiler.h:55:47: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                                                 ^~~~
   include/linux/compiler.h:57:86: note: expanded from macro '__trace_if_var'
   #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                                                                        ^~~~
   include/linux/compiler.h:68:3: note: expanded from macro '__trace_if_value'
           (cond) ?                                        \
            ^~~~
   include/linux/xarray.h:1262:43: note: passing argument to parameter 'entry' here
   static inline bool xa_is_node(const void *entry)
                                             ^
>> lib/test_maple_tree.c:1456:27: warning: incompatible integer to pointer conversion passing 'int' to parameter of type 'const void *' [-Wint-conversion]
           MT_BUG_ON(mt, xa_is_node(mas_root(&mas)));
                                    ^~~~~~~~~~~~~~
   include/linux/maple_tree.h:627:23: note: expanded from macro 'MT_BUG_ON'
                   __func__, __LINE__, __x);                               \
                                       ^~~
   include/linux/printk.h:563:34: note: expanded from macro 'pr_info'
           printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
                                           ^~~~~~~~~~~
   include/linux/printk.h:490:60: note: expanded from macro 'printk'
   #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__)
                                                              ^~~~~~~~~~~
   include/linux/printk.h:462:19: note: expanded from macro 'printk_index_wrap'
                   _p_func(_fmt, ##__VA_ARGS__);                           \
                                   ^~~~~~~~~~~
   include/linux/xarray.h:1262:43: note: passing argument to parameter 'entry' here
   static inline bool xa_is_node(const void *entry)
                                             ^
   lib/test_maple_tree.c:1468:28: error: implicit declaration of function 'mas_root' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
           MT_BUG_ON(mt, !xa_is_node(mas_root(&mas)));
                                     ^
   lib/test_maple_tree.c:1468:28: warning: incompatible integer to pointer conversion passing 'int' to parameter of type 'const void *' [-Wint-conversion]
           MT_BUG_ON(mt, !xa_is_node(mas_root(&mas)));
                                     ^~~~~~~~~~~~~~
   include/linux/maple_tree.h:625:6: note: expanded from macro 'MT_BUG_ON'
           if (__x) {                                                      \
               ^~~
   include/linux/compiler.h:55:47: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                                                 ^~~~
   include/linux/compiler.h:57:52: note: expanded from macro '__trace_if_var'
   #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                                      ^~~~
   include/linux/xarray.h:1262:43: note: passing argument to parameter 'entry' here
   static inline bool xa_is_node(const void *entry)
                                             ^
   lib/test_maple_tree.c:1468:28: warning: incompatible integer to pointer conversion passing 'int' to parameter of type 'const void *' [-Wint-conversion]
           MT_BUG_ON(mt, !xa_is_node(mas_root(&mas)));
                                     ^~~~~~~~~~~~~~
   include/linux/maple_tree.h:625:6: note: expanded from macro 'MT_BUG_ON'
           if (__x) {                                                      \
               ^~~
   include/linux/compiler.h:55:47: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                                                 ^~~~
   include/linux/compiler.h:57:61: note: expanded from macro '__trace_if_var'
   #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                                               ^~~~
   include/linux/xarray.h:1262:43: note: passing argument to parameter 'entry' here
   static inline bool xa_is_node(const void *entry)
                                             ^
   lib/test_maple_tree.c:1468:28: warning: incompatible integer to pointer conversion passing 'int' to parameter of type 'const void *' [-Wint-conversion]
           MT_BUG_ON(mt, !xa_is_node(mas_root(&mas)));
                                     ^~~~~~~~~~~~~~
   include/linux/maple_tree.h:625:6: note: expanded from macro 'MT_BUG_ON'
           if (__x) {                                                      \
               ^~~
   include/linux/compiler.h:55:47: note: expanded from macro 'if'
   #define if(cond, ...) if ( __trace_if_var( !!(cond , ## __VA_ARGS__) ) )
                                                 ^~~~
   include/linux/compiler.h:57:86: note: expanded from macro '__trace_if_var'
   #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
                                                                                        ^~~~
   include/linux/compiler.h:68:3: note: expanded from macro '__trace_if_value'
           (cond) ?                                        \
            ^~~~
   include/linux/xarray.h:1262:43: note: passing argument to parameter 'entry' here
   static inline bool xa_is_node(const void *entry)
                                             ^
   lib/test_maple_tree.c:1468:28: warning: incompatible integer to pointer conversion passing 'int' to parameter of type 'const void *' [-Wint-conversion]
           MT_BUG_ON(mt, !xa_is_node(mas_root(&mas)));
                                     ^~~~~~~~~~~~~~
   include/linux/maple_tree.h:627:23: note: expanded from macro 'MT_BUG_ON'
                   __func__, __LINE__, __x);                               \
                                       ^~~
   include/linux/printk.h:563:34: note: expanded from macro 'pr_info'
           printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
                                           ^~~~~~~~~~~
   include/linux/printk.h:490:60: note: expanded from macro 'printk'
   #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__)
                                                              ^~~~~~~~~~~
   include/linux/printk.h:462:19: note: expanded from macro 'printk_index_wrap'
                   _p_func(_fmt, ##__VA_ARGS__);                           \
                                   ^~~~~~~~~~~
   include/linux/xarray.h:1262:43: note: passing argument to parameter 'entry' here
   static inline bool xa_is_node(const void *entry)
                                             ^

8 warnings and 2 errors generated.

vim +/mas_root +1456 lib/test_maple_tree.c

1389
1390 static noinline void __init check_store_null(struct maple_tree *mt)
1391 {
1392 MA_STATE(mas, mt, 0, ULONG_MAX);
1393
1394 /*
1395 * Store NULL at range [0, ULONG_MAX] to an empty tree should result
1396 * in an empty tree
1397 */
1398 mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
1399 mas_lock(&mas);
1400 mas_store_gfp(&mas, NULL, GFP_KERNEL);
1401 MT_BUG_ON(mt, !mtree_empty(mt));
1402 mas_unlock(&mas);
1403 mtree_destroy(mt);
1404
1405 /*
1406 * Store NULL at any range to an empty tree should result in an empty
1407 * tree
1408 */
1409 mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
1410 mas_lock(&mas);
1411 mas_set_range(&mas, 3, 10);
1412 mas_store_gfp(&mas, NULL, GFP_KERNEL);
1413 MT_BUG_ON(mt, !mtree_empty(mt));
1414 mas_unlock(&mas);
1415 mtree_destroy(mt);
1416
1417 /*
1418 * Store NULL at range [0, ULONG_MAX] to a single entry tree should
1419 * result in an empty tree
1420 */
1421 mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
1422 mas_lock(&mas);
1423 mas_set(&mas, 0);
1424 mas_store_gfp(&mas, &mas, GFP_KERNEL);
1425 mas_set_range(&mas, 0, ULONG_MAX);
1426 mas_store_gfp(&mas, NULL, GFP_KERNEL);
1427 MT_BUG_ON(mt, !mtree_empty(mt));
1428 mas_unlock(&mas);
1429 mtree_destroy(mt);
1430
1431 /*
1432 * Store NULL at range [0, n] to a single entry tree should
1433 * result in an empty tree
1434 */
1435 mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
1436 mas_lock(&mas);
1437 mas_set(&mas, 0);
1438 mas_store_gfp(&mas, &mas, GFP_KERNEL);
1439 mas_set_range(&mas, 0, 5);
1440 mas_store_gfp(&mas, NULL, GFP_KERNEL);
1441 MT_BUG_ON(mt, !mtree_empty(mt));
1442 mas_unlock(&mas);
1443 mtree_destroy(mt);
1444
1445 /*
1446 * Store NULL at range [m, n] where m > 0 to a single entry tree
1447 * should still be a single entry tree
1448 */
1449 mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
1450 mas_lock(&mas);
1451 mas_set(&mas, 0);
1452 mas_store_gfp(&mas, &mas, GFP_KERNEL);
1453 mas_set_range(&mas, 2, 5);
1454 mas_store_gfp(&mas, NULL, GFP_KERNEL);
1455 MT_BUG_ON(mt, mtree_empty(mt));

> 1456		MT_BUG_ON(mt, xa_is_node(mas_root(&mas)));

1457 mas_unlock(&mas);
1458 mtree_destroy(mt);
1459
1460 /*
1461 * Store NULL at range [0, ULONG_MAX] to a tree with node should
1462 * result in an empty tree
1463 */
1464 mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
1465 mas_lock(&mas);
1466 mas_set_range(&mas, 1, 3);
1467 mas_store_gfp(&mas, &mas, GFP_KERNEL);
1468 MT_BUG_ON(mt, !xa_is_node(mas_root(&mas)));
1469 mas_set_range(&mas, 0, ULONG_MAX);
1470 mas_store_gfp(&mas, NULL, GFP_KERNEL);
1471 MT_BUG_ON(mt, !mtree_empty(mt));
1472 mas_unlock(&mas);
1473 mtree_destroy(mt);
1474 }
1475

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
maintainer
#13 lore raw
In reply to Wei Yang
Quoted 2 lines · On Thu, 31 Oct 2024 23:16:22 +0000 Wei Yang <[email protected]> wrote:

The original thread[1] thoughts it is a problem in mas_new_root(). But after discussion, this should be an improvement on storing NULL.

I hate to be a bureaucrat, but that isn't a very satisfying [0/N].

Quoted 2 lines

[1]: https://lkml.kernel.org/r/[email protected]

From here I extracted "When overwriting the whole range with NULL, current behavior is not correct", but that's still very thin. What is incorrect about it and what is the impact of all of this to Linux users?

#14 lore raw
Quoted 5 lines · Andrew Morton
Quoted 2 lines · On Thu, 31 Oct 2024 23:16:22 +0000 Wei Yang <[email protected]> wrote:

The original thread[1] thoughts it is a problem in mas_new_root(). But after discussion, this should be an improvement on storing NULL.

Quoted 9 lines

I hate to be a bureaucrat, but that isn't a very satisfying [0/N].

Quoted 2 lines

[1]: https://lkml.kernel.org/r/[email protected]

From here I extracted "When overwriting the whole range with NULL, current behavior is not correct", but that's still very thin. What is incorrect about it and what is the impact of all of this to Linux users?

An empty tree is represented by having the tree point to NULL directly. An empty tree indicates the entire range (0-ULONG_MAX) is NULL.

A store operation into an existing node that causes 0 - ULONG_MAX to be equal to NULL may not be restored to an empty state - a node is used to store the single range instead. This is wasteful and different from the initial setup of the tree.

Once the tree is using a single node to store 0 - ULONG_MAX, problems may arise when storing more values into a tree with the unexpected state of 0 - ULONG being a single range in a node.

User visible issues may mean a corrupt tree and incorrect storage of information within the tree. This would be limited to users who create and then empty a tree by overwriting all values, then try to store more NULLs into the empty tree.

I cannot come up with an example of any user doing this (users usually destroy the tree and generally don't keep trying to store NULLs over NULLs), but patch 4/5 "maple_tree: refine mas_store_root() on storing NULL" should be backported just in case.

I said patch 4/5 needed to be backported in v3 [1], but stable didn't get added to the Cc list and I missed it on review of v4. I added to the confusion by stating in an earlier version that it did not need to be backported [2]. At the time the issue of corrupting the node wasn't in the description. It should go back to v6.1.

I will be more clear in my communication on Cc'ing stable in the future. The description of 4/5 is inadequate and I'll respond there as well.

[1] https://lore.kernel.org/all/jo4wjti235pqmzd6qaziexzjsavt53vmtyzyvw4htrcwpuxf4n@ctyucxk5avrc/
[2] https://lore.kernel.org/all/ia7qdjv5c5hmg6yds3tz2x5to5u65k47ssgudiayxjqrowu4fm@i5la2j7kpe5k/

Thanks,
Liam

author
#15 lore raw
Quoted 24 lines · Liam R. Howlett
Quoted 5 lines · Andrew Morton
Quoted 2 lines · On Thu, 31 Oct 2024 23:16:22 +0000 Wei Yang <[email protected]> wrote:

The original thread[1] thoughts it is a problem in mas_new_root(). But after discussion, this should be an improvement on storing NULL.

Quoted 9 lines

I hate to be a bureaucrat, but that isn't a very satisfying [0/N].

Quoted 2 lines

[1]: https://lkml.kernel.org/r/[email protected]

From here I extracted "When overwriting the whole range with NULL, current behavior is not correct", but that's still very thin. What is incorrect about it and what is the impact of all of this to Linux users?

An empty tree is represented by having the tree point to NULL directly. An empty tree indicates the entire range (0-ULONG_MAX) is NULL.

A store operation into an existing node that causes 0 - ULONG_MAX to be equal to NULL may not be restored to an empty state - a node is used to store the single range instead. This is wasteful and different from the initial setup of the tree.

Quoted 8 lines

Once the tree is using a single node to store 0 - ULONG_MAX, problems may arise when storing more values into a tree with the unexpected state of 0 - ULONG being a single range in a node.

User visible issues may mean a corrupt tree and incorrect storage of information within the tree. This would be limited to users who create and then empty a tree by overwriting all values, then try to store more NULLs into the empty tree.

Thanks for the detailed explanation.

Quoted 6 lines

I cannot come up with an example of any user doing this (users usually destroy the tree and generally don't keep trying to store NULLs over NULLs), but patch 4/5 "maple_tree: refine mas_store_root() on storing NULL" should be backported just in case.

Quoted 8 lines

I said patch 4/5 needed to be backported in v3 [1], but stable didn't get added to the Cc list and I missed it on review of v4. I added to the confusion by stating in an earlier version that it did not need to be backported [2]. At the time the issue of corrupting the node wasn't in the description. It should go back to v6.1.

I will be more clear in my communication on Cc'ing stable in the future. The description of 4/5 is inadequate and I'll respond there as well.

I will be more careful for this next time.

Quoted 6 lines

[1] https://lore.kernel.org/all/jo4wjti235pqmzd6qaziexzjsavt53vmtyzyvw4htrcwpuxf4n@ctyucxk5avrc/
[2] https://lore.kernel.org/all/ia7qdjv5c5hmg6yds3tz2x5to5u65k47ssgudiayxjqrowu4fm@i5la2j7kpe5k/

Thanks,
Liam

Signature · 2 lines
Wei Yang
Help you, Help me