public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Documentation: maple_tree: Improve statements on reserved values
@ 2026-05-04 16:57 Wei-Lin Chang
  2026-05-04 16:57 ` [PATCH 1/2] Documentation: maple_tree: Point out constraint when using xa_{mk, to}_value Wei-Lin Chang
  2026-05-04 16:57 ` [PATCH 2/2] Documentation: maple_tree: Clarify behavior when using reserved values Wei-Lin Chang
  0 siblings, 2 replies; 4+ messages in thread
From: Wei-Lin Chang @ 2026-05-04 16:57 UTC (permalink / raw)
  To: maple-tree, linux-mm, linux-doc, linux-kernel
  Cc: Liam R . Howlett, Alice Ryhl, Andrew Ballance, Jonathan Corbet,
	Shuah Khan, Wei-Lin Chang

Hi,

This is another version of [1], where I improved wording.

While using the maple tree and reading its documentation, I found a few
bits confusing, mainly about the reserved values. So here are some
changes hoping to make things clearer.

I am not familiar with the implementation, so if I got something wrong
please let me know.

While looking at the code I also found that although the doc claims the
normal API blocks reserved value stores, the code checks this using
xa_is_advanced(), which only blocks values up to 1026, not up to the max
maple tree reserved value 4094. For this part I am not sure whether the
code needs to be changed or we can also improve the doc.

Any feedback is appreciated, thanks!

[1]: https://lore.kernel.org/linux-mm/20260418204754.120405-1-weilin.chang@arm.com/

Wei-Lin Chang (2):
  Documentation: maple_tree: Point out constraint when using xa_{mk,
    to}_value
  Documentation: maple_tree: Clarify behavior when using reserved values

 Documentation/core-api/maple_tree.rst | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] Documentation: maple_tree: Point out constraint when using xa_{mk, to}_value
  2026-05-04 16:57 [PATCH 0/2] Documentation: maple_tree: Improve statements on reserved values Wei-Lin Chang
@ 2026-05-04 16:57 ` Wei-Lin Chang
  2026-05-04 20:32   ` Matthew Wilcox
  2026-05-04 16:57 ` [PATCH 2/2] Documentation: maple_tree: Clarify behavior when using reserved values Wei-Lin Chang
  1 sibling, 1 reply; 4+ messages in thread
From: Wei-Lin Chang @ 2026-05-04 16:57 UTC (permalink / raw)
  To: maple-tree, linux-mm, linux-doc, linux-kernel
  Cc: Liam R . Howlett, Alice Ryhl, Andrew Ballance, Jonathan Corbet,
	Shuah Khan, Wei-Lin Chang

Using xa_{mk, to}_value when storing values loses the information of
the top bit from the left shift, point that out in the doc.

Signed-off-by: Wei-Lin Chang <weilin.chang@arm.com>
---
 Documentation/core-api/maple_tree.rst | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/Documentation/core-api/maple_tree.rst b/Documentation/core-api/maple_tree.rst
index ccdd1615cf97..87020a30ba69 100644
--- a/Documentation/core-api/maple_tree.rst
+++ b/Documentation/core-api/maple_tree.rst
@@ -29,8 +29,9 @@ The Maple Tree can store values between ``0`` and ``ULONG_MAX``.  The Maple
 Tree reserves values with the bottom two bits set to '10' which are below 4096
 (ie 2, 6, 10 .. 4094) for internal use.  If the entries may use reserved
 entries then the users can convert the entries using xa_mk_value() and convert
-them back by calling xa_to_value().  If the user needs to use a reserved
-value, then the user can convert the value when using the
+them back by calling xa_to_value().  Note that xa_{mk, to}_value() bit shifts
+the given data, so the top bit will be lost.  If the user needs to use a
+reserved value, then the user can convert the value when using the
 :ref:`maple-tree-advanced-api`, but are blocked by the normal API.
 
 The Maple Tree can also be configured to support searching for a gap of a given
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] Documentation: maple_tree: Clarify behavior when using reserved values
  2026-05-04 16:57 [PATCH 0/2] Documentation: maple_tree: Improve statements on reserved values Wei-Lin Chang
  2026-05-04 16:57 ` [PATCH 1/2] Documentation: maple_tree: Point out constraint when using xa_{mk, to}_value Wei-Lin Chang
@ 2026-05-04 16:57 ` Wei-Lin Chang
  1 sibling, 0 replies; 4+ messages in thread
From: Wei-Lin Chang @ 2026-05-04 16:57 UTC (permalink / raw)
  To: maple-tree, linux-mm, linux-doc, linux-kernel
  Cc: Liam R . Howlett, Alice Ryhl, Andrew Ballance, Jonathan Corbet,
	Shuah Khan, Wei-Lin Chang

It doesn't matter whether the normal or the advanced API is used if the
user uses xa_{mk, to}_value when storing and retrieving the values. Just
specify that the normal API blocks usages of reserved values while the
advanced API does not.

Signed-off-by: Wei-Lin Chang <weilin.chang@arm.com>
---
 Documentation/core-api/maple_tree.rst | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/Documentation/core-api/maple_tree.rst b/Documentation/core-api/maple_tree.rst
index 87020a30ba69..e5ccafb84804 100644
--- a/Documentation/core-api/maple_tree.rst
+++ b/Documentation/core-api/maple_tree.rst
@@ -30,9 +30,9 @@ Tree reserves values with the bottom two bits set to '10' which are below 4096
 (ie 2, 6, 10 .. 4094) for internal use.  If the entries may use reserved
 entries then the users can convert the entries using xa_mk_value() and convert
 them back by calling xa_to_value().  Note that xa_{mk, to}_value() bit shifts
-the given data, so the top bit will be lost.  If the user needs to use a
-reserved value, then the user can convert the value when using the
-:ref:`maple-tree-advanced-api`, but are blocked by the normal API.
+the given data, so the top bit will be lost.  Usage of reserved values is
+blocked by the normal API, and will cause undefined behavior if used with the
+:ref:`maple-tree-advanced-api`.
 
 The Maple Tree can also be configured to support searching for a gap of a given
 size (or larger).
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] Documentation: maple_tree: Point out constraint when using xa_{mk, to}_value
  2026-05-04 16:57 ` [PATCH 1/2] Documentation: maple_tree: Point out constraint when using xa_{mk, to}_value Wei-Lin Chang
@ 2026-05-04 20:32   ` Matthew Wilcox
  0 siblings, 0 replies; 4+ messages in thread
From: Matthew Wilcox @ 2026-05-04 20:32 UTC (permalink / raw)
  To: Wei-Lin Chang
  Cc: maple-tree, linux-mm, linux-doc, linux-kernel, Liam R . Howlett,
	Alice Ryhl, Andrew Ballance, Jonathan Corbet, Shuah Khan

On Mon, May 04, 2026 at 05:57:45PM +0100, Wei-Lin Chang wrote:
> Using xa_{mk, to}_value when storing values loses the information of
> the top bit from the left shift, point that out in the doc.

I don't know if that's necessary ... it's obvious when looking at the
function:

static inline void *xa_mk_value(unsigned long v)
{
        WARN_ON((long)v < 0);
        return (void *)((v << 1) | 1);
}

and if you ignore it, you'll find out.  But if this needs to be
documented anywhere, it's in the kernel-doc for xa_mk_value()
and not in the maple tree docs.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-05-04 20:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-04 16:57 [PATCH 0/2] Documentation: maple_tree: Improve statements on reserved values Wei-Lin Chang
2026-05-04 16:57 ` [PATCH 1/2] Documentation: maple_tree: Point out constraint when using xa_{mk, to}_value Wei-Lin Chang
2026-05-04 20:32   ` Matthew Wilcox
2026-05-04 16:57 ` [PATCH 2/2] Documentation: maple_tree: Clarify behavior when using reserved values Wei-Lin Chang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox