source
large_stringclasses
2 values
subject
large_stringclasses
112 values
code
large_stringclasses
112 values
critique
large_stringlengths
61
3.04M
metadata
dict
lkml
[PATCH v3 00/30] maple_tree: Replace big node with maple copy
The big node struct was created for simplicity of splitting, rebalancing, and spanning store operations by using a copy buffer to create the data necessary prior to breaking it up into 256B nodes. Certain operations were rather tricky due to the restriction of keeping NULL entries together and never at the end of a node (except the right-most node). The big node struct is incompatible with future features that are currently in development. Specifically different node types and different data type sizes for pivots. The big node struct was also a stack variable, which caused issues with certain configurations of kernel build. This series removes big node by introducing another node type which will never be written to the tree: maple_copy. The maple copy node operates more like a scatter/gather operation with a number of sources and destinations of allocated nodes. The sources are copied to the destinations, in turn, until the sources are exhausted. The destination is changed if it is filled or the split location is reached prior to the source data end. New data is inserted by using the maple copy node itself as a source with up to 3 slots and pivots. The data in the maple copy node is the data being written to the tree along with any fragment of the range(s) being overwritten. As with all nodes, the maple copy node is of size 256B. Using a node type allows for the copy operation to treat the new data stored in the maple copy node the same as any other source node. Analysis of the runtime shows no regression or benefit of removing the larger stack structure. The motivation is the ground work to use new node types and to help those with odd configurations that have had issues. The change was tested by myself using mm_tests on amd64 and by Suren on android (arm64). Limited testing on s390 qemu was also performed using stress-ng on the virtual memory, which should cover many corner cases. v1: https://lore.kernel.org/all/20260115193647.1695937-1-Liam.Howlett@oracle.com/ v2: https://lore.kernel.org/all/20260121164526.2093265-1-Liam.Howlett@oracle.com/ Changes since v2: - Whitespace fix in rebalance_data() - Added ma_init_slot() for cleaner casting during RCU_INIT_POINTER(). Thanks test robot & SK [1] - Fixed off-by-one in rebalance_data() which caused node overuse, reported by linux-next. Thanks Mark [2] - Added new patch to reproducer to test cases in userspace testing for the rebalance_data() off-by-one [1]. https://lore.kernel.org/all/20260122055516.69335-1-sj@kernel.org/ [2]. https://lore.kernel.org/all/bd1c3356-11a1-4d0b-bf58-47eb21bfd24d@sirena.org.uk/ Liam R. Howlett (30): maple_tree: Fix mas_dup_alloc() sparse warning maple_tree: Move mas_spanning_rebalance loop to function maple_tree: Extract use of big node from mas_wr_spanning_store() maple_tree: Remove unnecessary assignment of orig_l index maple_tree: inline mas_spanning_rebalance() into mas_wr_spanning_rebalance() maple_tree: Make ma_wr_states reliable for reuse in spanning store maple_tree: Remove l_wr_mas from mas_wr_spanning_rebalance maple_tree: Don't pass through height in mas_wr_spanning_store maple_tree: Move maple_subtree_state from mas_wr_spanning_store to mas_wr_spanning_rebalance maple_tree: Correct right ma_wr_state end pivot in mas_wr_spanning_store() maple_tree: Introduce maple_copy node and use it in mas_spanning_rebalance() maple_tree: Testing update for spanning store maple_tree: Inline mas_spanning_rebalance_loop() into mas_wr_spanning_rebalance() maple_tree: Change initial big node setup in mas_wr_spanning_rebalance() maple_tree: Introduce ma_leaf_max_gap() maple_tree: Add gap support, slot and pivot sizes for maple copy maple_tree: Start using maple copy node for destination maple_tree: inline mas_wr_spanning_rebalance() maple_tree: Remove unnecessary return statements maple_tree: Separate wr_split_store and wr_rebalance store type code path maple_tree: Add cp_is_new_root() helper maple_tree: Use maple copy node for mas_wr_rebalance() operation maple_tree: Add test for rebalance calculation off-by-one maple_tree: Add copy_tree_location() helper maple_tree: Add cp_converged() helper maple_tree: Use maple copy node for mas_wr_split() maple_tree: Remove maple big node and subtree structs maple_tree: Pass maple copy node to mas_wmb_replace() maple_tree: Don't pass end to mas_wr_append() maple_tree: Clean up mas_wr_node_store() include/linux/maple_tree.h | 42 + lib/maple_tree.c | 2134 +++++++++++++----------------- lib/test_maple_tree.c | 55 +- tools/testing/radix-tree/maple.c | 308 ++++- 4 files changed, 1340 insertions(+), 1199 deletions(-) -- 2.47.3
Functions do not need to state return at the end, unless skipping unwind. These can safely be dropped. Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com> --- lib/maple_tree.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index a10f71620e732..4a64b4f37aeb3 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -3294,7 +3294,6 @@ static void mas_spanning_rebalance_loop(struct ma_state *mas, mas->offset = mast->l->offset; mas_wmb_replace(mas, old_enode, new_height); mtree_range_walk(mas); - return; } /* @@ -3718,7 +3717,6 @@ static void mas_split(struct ma_state *mas, struct maple_big_node *b_node) mas->node = l_mas.node; mas_wmb_replace(mas, old, height); mtree_range_walk(mas); - return; } /* @@ -3779,7 +3777,6 @@ static inline void 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; } /* @@ -4051,8 +4048,6 @@ static inline void mas_new_root(struct ma_state *mas, void *entry) done: if (xa_is_node(root)) mte_destroy_walk(root, mas->tree); - - return; } /* * mas_wr_spanning_store() - Create a subtree with the store operation completed @@ -4215,7 +4210,6 @@ static inline void mas_wr_node_store(struct ma_wr_state *wr_mas, trace_ma_write(TP_FCT, mas, 0, wr_mas->entry); mas_update_gap(mas); mas->end = new_end; - return; } /* @@ -4263,8 +4257,6 @@ static inline void mas_wr_slot_store(struct ma_wr_state *wr_mas) */ if (!wr_mas->entry || gap) mas_update_gap(mas); - - return; } static inline void mas_wr_extend_null(struct ma_wr_state *wr_mas) @@ -4378,7 +4370,6 @@ static inline void mas_wr_append(struct ma_wr_state *wr_mas, mas->end = new_end; trace_ma_write(TP_FCT, mas, new_end, wr_mas->entry); - return; } /* @@ -4437,8 +4428,6 @@ static inline void mas_wr_store_entry(struct ma_wr_state *wr_mas) case wr_invalid: MT_BUG_ON(mas->tree, 1); } - - return; } static inline void mas_wr_prealloc_setup(struct ma_wr_state *wr_mas) -- 2.47.3
{ "author": "\"Liam R. Howlett\" <Liam.Howlett@oracle.com>", "date": "Fri, 30 Jan 2026 15:59:24 -0500", "thread_id": "20260202103154.ad1aa05611c79d21b070a861@linux-foundation.org.mbox.gz" }
lkml
[PATCH v3 00/30] maple_tree: Replace big node with maple copy
The big node struct was created for simplicity of splitting, rebalancing, and spanning store operations by using a copy buffer to create the data necessary prior to breaking it up into 256B nodes. Certain operations were rather tricky due to the restriction of keeping NULL entries together and never at the end of a node (except the right-most node). The big node struct is incompatible with future features that are currently in development. Specifically different node types and different data type sizes for pivots. The big node struct was also a stack variable, which caused issues with certain configurations of kernel build. This series removes big node by introducing another node type which will never be written to the tree: maple_copy. The maple copy node operates more like a scatter/gather operation with a number of sources and destinations of allocated nodes. The sources are copied to the destinations, in turn, until the sources are exhausted. The destination is changed if it is filled or the split location is reached prior to the source data end. New data is inserted by using the maple copy node itself as a source with up to 3 slots and pivots. The data in the maple copy node is the data being written to the tree along with any fragment of the range(s) being overwritten. As with all nodes, the maple copy node is of size 256B. Using a node type allows for the copy operation to treat the new data stored in the maple copy node the same as any other source node. Analysis of the runtime shows no regression or benefit of removing the larger stack structure. The motivation is the ground work to use new node types and to help those with odd configurations that have had issues. The change was tested by myself using mm_tests on amd64 and by Suren on android (arm64). Limited testing on s390 qemu was also performed using stress-ng on the virtual memory, which should cover many corner cases. v1: https://lore.kernel.org/all/20260115193647.1695937-1-Liam.Howlett@oracle.com/ v2: https://lore.kernel.org/all/20260121164526.2093265-1-Liam.Howlett@oracle.com/ Changes since v2: - Whitespace fix in rebalance_data() - Added ma_init_slot() for cleaner casting during RCU_INIT_POINTER(). Thanks test robot & SK [1] - Fixed off-by-one in rebalance_data() which caused node overuse, reported by linux-next. Thanks Mark [2] - Added new patch to reproducer to test cases in userspace testing for the rebalance_data() off-by-one [1]. https://lore.kernel.org/all/20260122055516.69335-1-sj@kernel.org/ [2]. https://lore.kernel.org/all/bd1c3356-11a1-4d0b-bf58-47eb21bfd24d@sirena.org.uk/ Liam R. Howlett (30): maple_tree: Fix mas_dup_alloc() sparse warning maple_tree: Move mas_spanning_rebalance loop to function maple_tree: Extract use of big node from mas_wr_spanning_store() maple_tree: Remove unnecessary assignment of orig_l index maple_tree: inline mas_spanning_rebalance() into mas_wr_spanning_rebalance() maple_tree: Make ma_wr_states reliable for reuse in spanning store maple_tree: Remove l_wr_mas from mas_wr_spanning_rebalance maple_tree: Don't pass through height in mas_wr_spanning_store maple_tree: Move maple_subtree_state from mas_wr_spanning_store to mas_wr_spanning_rebalance maple_tree: Correct right ma_wr_state end pivot in mas_wr_spanning_store() maple_tree: Introduce maple_copy node and use it in mas_spanning_rebalance() maple_tree: Testing update for spanning store maple_tree: Inline mas_spanning_rebalance_loop() into mas_wr_spanning_rebalance() maple_tree: Change initial big node setup in mas_wr_spanning_rebalance() maple_tree: Introduce ma_leaf_max_gap() maple_tree: Add gap support, slot and pivot sizes for maple copy maple_tree: Start using maple copy node for destination maple_tree: inline mas_wr_spanning_rebalance() maple_tree: Remove unnecessary return statements maple_tree: Separate wr_split_store and wr_rebalance store type code path maple_tree: Add cp_is_new_root() helper maple_tree: Use maple copy node for mas_wr_rebalance() operation maple_tree: Add test for rebalance calculation off-by-one maple_tree: Add copy_tree_location() helper maple_tree: Add cp_converged() helper maple_tree: Use maple copy node for mas_wr_split() maple_tree: Remove maple big node and subtree structs maple_tree: Pass maple copy node to mas_wmb_replace() maple_tree: Don't pass end to mas_wr_append() maple_tree: Clean up mas_wr_node_store() include/linux/maple_tree.h | 42 + lib/maple_tree.c | 2134 +++++++++++++----------------- lib/test_maple_tree.c | 55 +- tools/testing/radix-tree/maple.c | 308 ++++- 4 files changed, 1340 insertions(+), 1199 deletions(-) -- 2.47.3
Extract the copying of the tree location from one maple state to another into its own function. This is used more later. Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com> --- lib/maple_tree.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 0d5d68913de44..1e79dfbb024a0 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -3531,6 +3531,17 @@ static bool spanning_ascend(struct maple_copy *cp, struct ma_state *mas, return true; } +static inline +void copy_tree_location(const struct ma_state *src, struct ma_state *dst) +{ + dst->node = src->node; + dst->offset = src->offset; + dst->min = src->min; + dst->max = src->max; + dst->end = src->end; + dst->depth = src->depth; +} + /* * rebalance_ascend() - Ascend the tree and set up for the next loop - if * necessary @@ -3570,12 +3581,7 @@ static inline bool rebalance_ascend(struct maple_copy *cp, } cp->height++; - mas->node = parent->node; - mas->offset = parent->offset; - mas->min = parent->min; - mas->max = parent->max; - mas->end = parent->end; - mas->depth = parent->depth; + copy_tree_location(parent, mas); wr_mas_setup(wr_mas, mas); return true; } -- 2.47.3
{ "author": "\"Liam R. Howlett\" <Liam.Howlett@oracle.com>", "date": "Fri, 30 Jan 2026 15:59:29 -0500", "thread_id": "20260202103154.ad1aa05611c79d21b070a861@linux-foundation.org.mbox.gz" }
lkml
[PATCH v3 00/30] maple_tree: Replace big node with maple copy
The big node struct was created for simplicity of splitting, rebalancing, and spanning store operations by using a copy buffer to create the data necessary prior to breaking it up into 256B nodes. Certain operations were rather tricky due to the restriction of keeping NULL entries together and never at the end of a node (except the right-most node). The big node struct is incompatible with future features that are currently in development. Specifically different node types and different data type sizes for pivots. The big node struct was also a stack variable, which caused issues with certain configurations of kernel build. This series removes big node by introducing another node type which will never be written to the tree: maple_copy. The maple copy node operates more like a scatter/gather operation with a number of sources and destinations of allocated nodes. The sources are copied to the destinations, in turn, until the sources are exhausted. The destination is changed if it is filled or the split location is reached prior to the source data end. New data is inserted by using the maple copy node itself as a source with up to 3 slots and pivots. The data in the maple copy node is the data being written to the tree along with any fragment of the range(s) being overwritten. As with all nodes, the maple copy node is of size 256B. Using a node type allows for the copy operation to treat the new data stored in the maple copy node the same as any other source node. Analysis of the runtime shows no regression or benefit of removing the larger stack structure. The motivation is the ground work to use new node types and to help those with odd configurations that have had issues. The change was tested by myself using mm_tests on amd64 and by Suren on android (arm64). Limited testing on s390 qemu was also performed using stress-ng on the virtual memory, which should cover many corner cases. v1: https://lore.kernel.org/all/20260115193647.1695937-1-Liam.Howlett@oracle.com/ v2: https://lore.kernel.org/all/20260121164526.2093265-1-Liam.Howlett@oracle.com/ Changes since v2: - Whitespace fix in rebalance_data() - Added ma_init_slot() for cleaner casting during RCU_INIT_POINTER(). Thanks test robot & SK [1] - Fixed off-by-one in rebalance_data() which caused node overuse, reported by linux-next. Thanks Mark [2] - Added new patch to reproducer to test cases in userspace testing for the rebalance_data() off-by-one [1]. https://lore.kernel.org/all/20260122055516.69335-1-sj@kernel.org/ [2]. https://lore.kernel.org/all/bd1c3356-11a1-4d0b-bf58-47eb21bfd24d@sirena.org.uk/ Liam R. Howlett (30): maple_tree: Fix mas_dup_alloc() sparse warning maple_tree: Move mas_spanning_rebalance loop to function maple_tree: Extract use of big node from mas_wr_spanning_store() maple_tree: Remove unnecessary assignment of orig_l index maple_tree: inline mas_spanning_rebalance() into mas_wr_spanning_rebalance() maple_tree: Make ma_wr_states reliable for reuse in spanning store maple_tree: Remove l_wr_mas from mas_wr_spanning_rebalance maple_tree: Don't pass through height in mas_wr_spanning_store maple_tree: Move maple_subtree_state from mas_wr_spanning_store to mas_wr_spanning_rebalance maple_tree: Correct right ma_wr_state end pivot in mas_wr_spanning_store() maple_tree: Introduce maple_copy node and use it in mas_spanning_rebalance() maple_tree: Testing update for spanning store maple_tree: Inline mas_spanning_rebalance_loop() into mas_wr_spanning_rebalance() maple_tree: Change initial big node setup in mas_wr_spanning_rebalance() maple_tree: Introduce ma_leaf_max_gap() maple_tree: Add gap support, slot and pivot sizes for maple copy maple_tree: Start using maple copy node for destination maple_tree: inline mas_wr_spanning_rebalance() maple_tree: Remove unnecessary return statements maple_tree: Separate wr_split_store and wr_rebalance store type code path maple_tree: Add cp_is_new_root() helper maple_tree: Use maple copy node for mas_wr_rebalance() operation maple_tree: Add test for rebalance calculation off-by-one maple_tree: Add copy_tree_location() helper maple_tree: Add cp_converged() helper maple_tree: Use maple copy node for mas_wr_split() maple_tree: Remove maple big node and subtree structs maple_tree: Pass maple copy node to mas_wmb_replace() maple_tree: Don't pass end to mas_wr_append() maple_tree: Clean up mas_wr_node_store() include/linux/maple_tree.h | 42 + lib/maple_tree.c | 2134 +++++++++++++----------------- lib/test_maple_tree.c | 55 +- tools/testing/radix-tree/maple.c | 308 ++++- 4 files changed, 1340 insertions(+), 1199 deletions(-) -- 2.47.3
Instead of using the maple big node, use the maple copy node for reduced stack usage and aligning with mas_wr_rebalance() and mas_wr_spanning_store(). Splitting a node is similar to rebalancing, but a new evaluation of when to ascend is needed. The only other difference is that the data is pushed and never rebalanced at each level. The testing must also align with the changes to this commit to ensure the test suite continues to pass. Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com> --- lib/maple_tree.c | 99 ++++++++++++++++++++++++++++++-- lib/test_maple_tree.c | 55 ++++++++++++++---- tools/testing/radix-tree/maple.c | 11 ++++ 3 files changed, 149 insertions(+), 16 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index f04989f8a115e..5813ad17ea6fe 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -4542,19 +4542,106 @@ static inline void mas_wr_append(struct ma_wr_state *wr_mas, trace_ma_write(TP_FCT, mas, new_end, wr_mas->entry); } +/* + * split_ascend() - See if a split operation has to keep walking up the tree + * @cp: The maple_copy node + * @wr_mas: The maple write state + * @sib: the maple state of the sibling + * + * Return: true if another split operation on the next level is needed, false + * otherwise + */ +static inline bool split_ascend(struct maple_copy *cp, + struct ma_wr_state *wr_mas, struct ma_state *sib, + struct ma_state *parent) +{ + struct ma_state *mas; + unsigned long min, max; + + mas = wr_mas->mas; + min = mas->min; /* push right, or normal split */ + max = mas->max; + wr_mas->offset_end = parent->offset; + if (sib->end) { + if (sib->max < mas->min) { + min = sib->min; /* push left */ + parent->offset--; + } else { + max = sib->max; /* push right */ + wr_mas->offset_end++; + } + } + + cp_dst_to_slots(cp, min, max, mas); + if (cp_is_new_root(cp, mas)) + return false; + + if (cp_converged(cp, mas, sib)) + return false; + + cp->height++; + copy_tree_location(parent, mas); + wr_mas_setup(wr_mas, mas); + return true; +} + +/* + * split_data() - Calculate the @cp data, populate @sib if the data can be + * pushed into a sibling. + * @cp: The maple copy node + * @wr_mas: The left write maple state + * @sib: The maple state of the sibling. + * + * Note: @cp->data is a size and not indexed by 0. @sib->end may be set to 0 to + * indicate it will not be used. + * + */ +static inline void split_data(struct maple_copy *cp, + struct ma_wr_state *wr_mas, struct ma_state *sib, + struct ma_state *parent) +{ + cp_data_calc(cp, wr_mas, wr_mas); + if (cp->data <= mt_slots[wr_mas->type]) { + sib->end = 0; + return; + } + + push_data_sib(cp, wr_mas->mas, sib, parent); + if (sib->end) + cp->data += sib->end + 1; +} + /* * mas_wr_split() - Expand one node into two * @wr_mas: The write maple state */ -static noinline_for_kasan void mas_wr_split(struct ma_wr_state *wr_mas) +static void mas_wr_split(struct ma_wr_state *wr_mas) { - struct maple_big_node b_node; + struct maple_enode *old_enode; + struct ma_state parent; + struct ma_state *mas; + struct maple_copy cp; + struct ma_state sib; + mas = wr_mas->mas; trace_ma_write(TP_FCT, wr_mas->mas, 0, wr_mas->entry); - memset(&b_node, 0, sizeof(struct maple_big_node)); - mas_store_b_node(wr_mas, &b_node, wr_mas->offset_end); - WARN_ON_ONCE(wr_mas->mas->store_type != wr_split_store); - return mas_split(wr_mas->mas, &b_node); + parent = *mas; + cp_leaf_init(&cp, mas, wr_mas, wr_mas); + do { + if (!mte_is_root(parent.node)) { + mas_ascend(&parent); + parent.end = mas_data_end(&parent); + } + split_data(&cp, wr_mas, &sib, &parent); + multi_src_setup(&cp, wr_mas, wr_mas, &sib); + dst_setup(&cp, mas, wr_mas->type); + cp_data_write(&cp, mas); + } while (split_ascend(&cp, wr_mas, &sib, &parent)); + + old_enode = mas->node; + mas->node = mt_slot_locked(mas->tree, cp.slot, 0); + mas_wmb_replace(mas, old_enode, cp.height); + mtree_range_walk(mas); } /* diff --git a/lib/test_maple_tree.c b/lib/test_maple_tree.c index a182e48b5f5e6..434d8a2fdd99c 100644 --- a/lib/test_maple_tree.c +++ b/lib/test_maple_tree.c @@ -1024,6 +1024,7 @@ static noinline void __init check_ranges(struct maple_tree *mt) mt_set_non_kernel(10); check_store_range(mt, r[10], r[11], xa_mk_value(r[10]), 0); MT_BUG_ON(mt, !mt_height(mt)); + mt_validate(mt); mtree_destroy(mt); /* Create tree of 1-200 */ @@ -1031,11 +1032,13 @@ static noinline void __init check_ranges(struct maple_tree *mt) /* Store 45-168 */ check_store_range(mt, r[10], r[11], xa_mk_value(r[10]), 0); MT_BUG_ON(mt, !mt_height(mt)); + mt_validate(mt); mtree_destroy(mt); check_seq(mt, 30, false); check_store_range(mt, 6, 18, xa_mk_value(6), 0); MT_BUG_ON(mt, !mt_height(mt)); + mt_validate(mt); mtree_destroy(mt); /* Overwrite across multiple levels. */ @@ -1061,6 +1064,7 @@ static noinline void __init check_ranges(struct maple_tree *mt) check_load(mt, r[13] + 1, xa_mk_value(r[13] + 1)); check_load(mt, 135, NULL); check_load(mt, 140, NULL); + mt_validate(mt); mt_set_non_kernel(0); MT_BUG_ON(mt, !mt_height(mt)); mtree_destroy(mt); @@ -1285,14 +1289,20 @@ static noinline void __init check_ranges(struct maple_tree *mt) MT_BUG_ON(mt, mt_height(mt) >= 4); } /* Cause a 3 child split all the way up the tree. */ - for (i = 5; i < 215; i += 10) + for (i = 5; i < 215; i += 10) { check_store_range(mt, 11450 + i, 11450 + i + 1, NULL, 0); - for (i = 5; i < 65; i += 10) + mt_validate(mt); + } + for (i = 5; i < 65; i += 10) { check_store_range(mt, 11770 + i, 11770 + i + 1, NULL, 0); + mt_validate(mt); + } MT_BUG_ON(mt, mt_height(mt) >= 4); - for (i = 5; i < 45; i += 10) + for (i = 5; i < 45; i += 10) { check_store_range(mt, 11700 + i, 11700 + i + 1, NULL, 0); + mt_validate(mt); + } if (!MAPLE_32BIT) MT_BUG_ON(mt, mt_height(mt) < 4); mtree_destroy(mt); @@ -1304,17 +1314,42 @@ static noinline void __init check_ranges(struct maple_tree *mt) val2 = (i+1)*10; check_store_range(mt, val, val2, xa_mk_value(val), 0); MT_BUG_ON(mt, mt_height(mt) >= 4); + mt_validate(mt); + } + /* Fill parents and leaves before split. */ + val = 7660; + for (i = 5; i < 490; i += 5) { + val += 5; + check_store_range(mt, val, val + 1, NULL, 0); + mt_validate(mt); + MT_BUG_ON(mt, mt_height(mt) >= 4); } + + val = 9460; /* Fill parents and leaves before split. */ - for (i = 5; i < 455; i += 10) - check_store_range(mt, 7800 + i, 7800 + i + 1, NULL, 0); + for (i = 1; i < 10; i++) { + val++; + check_store_range(mt, val, val + 1, xa_mk_value(val), 0); + mt_validate(mt); + } - for (i = 1; i < 16; i++) - check_store_range(mt, 8185 + i, 8185 + i + 1, - xa_mk_value(8185+i), 0); - MT_BUG_ON(mt, mt_height(mt) >= 4); + val = 8000; + for (i = 1; i < 14; i++) { + val++; + check_store_range(mt, val, val + 1, xa_mk_value(val), 0); + mt_validate(mt); + } + + + check_store_range(mt, 8051, 8051, xa_mk_value(8081), 0); + check_store_range(mt, 8052, 8052, xa_mk_value(8082), 0); + check_store_range(mt, 8083, 8083, xa_mk_value(8083), 0); + check_store_range(mt, 8084, 8084, xa_mk_value(8084), 0); + check_store_range(mt, 8085, 8085, xa_mk_value(8085), 0); /* triple split across multiple levels. */ - check_store_range(mt, 8184, 8184, xa_mk_value(8184), 0); + check_store_range(mt, 8099, 8100, xa_mk_value(1), 0); + + mt_validate(mt); if (!MAPLE_32BIT) MT_BUG_ON(mt, mt_height(mt) != 4); } diff --git a/tools/testing/radix-tree/maple.c b/tools/testing/radix-tree/maple.c index 5ea45d67556a8..feedd5ab7058f 100644 --- a/tools/testing/radix-tree/maple.c +++ b/tools/testing/radix-tree/maple.c @@ -35406,7 +35406,18 @@ static noinline void __init check_spanning_write(struct maple_tree *mt) mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE); for (i = 0; i <= max; i++) mtree_test_store_range(mt, i * 10, i * 10 + 5, &i); + mtree_lock(mt); + if (MAPLE_32BIT) { + i = 47811; + do { + mas_set(&mas, i); + mas_store_gfp(&mas, check_spanning_write, GFP_KERNEL); + i++; + mas_ascend(&mas); + } while (mas_data_end(&mas) < mt_slot_count(mas.node) - 1); + } + mas_set(&mas, 47606); mas_store_gfp(&mas, check_spanning_write, GFP_KERNEL); mas_set(&mas, 47607); -- 2.47.3
{ "author": "\"Liam R. Howlett\" <Liam.Howlett@oracle.com>", "date": "Fri, 30 Jan 2026 15:59:31 -0500", "thread_id": "20260202103154.ad1aa05611c79d21b070a861@linux-foundation.org.mbox.gz" }
lkml
[PATCH v3 00/30] maple_tree: Replace big node with maple copy
The big node struct was created for simplicity of splitting, rebalancing, and spanning store operations by using a copy buffer to create the data necessary prior to breaking it up into 256B nodes. Certain operations were rather tricky due to the restriction of keeping NULL entries together and never at the end of a node (except the right-most node). The big node struct is incompatible with future features that are currently in development. Specifically different node types and different data type sizes for pivots. The big node struct was also a stack variable, which caused issues with certain configurations of kernel build. This series removes big node by introducing another node type which will never be written to the tree: maple_copy. The maple copy node operates more like a scatter/gather operation with a number of sources and destinations of allocated nodes. The sources are copied to the destinations, in turn, until the sources are exhausted. The destination is changed if it is filled or the split location is reached prior to the source data end. New data is inserted by using the maple copy node itself as a source with up to 3 slots and pivots. The data in the maple copy node is the data being written to the tree along with any fragment of the range(s) being overwritten. As with all nodes, the maple copy node is of size 256B. Using a node type allows for the copy operation to treat the new data stored in the maple copy node the same as any other source node. Analysis of the runtime shows no regression or benefit of removing the larger stack structure. The motivation is the ground work to use new node types and to help those with odd configurations that have had issues. The change was tested by myself using mm_tests on amd64 and by Suren on android (arm64). Limited testing on s390 qemu was also performed using stress-ng on the virtual memory, which should cover many corner cases. v1: https://lore.kernel.org/all/20260115193647.1695937-1-Liam.Howlett@oracle.com/ v2: https://lore.kernel.org/all/20260121164526.2093265-1-Liam.Howlett@oracle.com/ Changes since v2: - Whitespace fix in rebalance_data() - Added ma_init_slot() for cleaner casting during RCU_INIT_POINTER(). Thanks test robot & SK [1] - Fixed off-by-one in rebalance_data() which caused node overuse, reported by linux-next. Thanks Mark [2] - Added new patch to reproducer to test cases in userspace testing for the rebalance_data() off-by-one [1]. https://lore.kernel.org/all/20260122055516.69335-1-sj@kernel.org/ [2]. https://lore.kernel.org/all/bd1c3356-11a1-4d0b-bf58-47eb21bfd24d@sirena.org.uk/ Liam R. Howlett (30): maple_tree: Fix mas_dup_alloc() sparse warning maple_tree: Move mas_spanning_rebalance loop to function maple_tree: Extract use of big node from mas_wr_spanning_store() maple_tree: Remove unnecessary assignment of orig_l index maple_tree: inline mas_spanning_rebalance() into mas_wr_spanning_rebalance() maple_tree: Make ma_wr_states reliable for reuse in spanning store maple_tree: Remove l_wr_mas from mas_wr_spanning_rebalance maple_tree: Don't pass through height in mas_wr_spanning_store maple_tree: Move maple_subtree_state from mas_wr_spanning_store to mas_wr_spanning_rebalance maple_tree: Correct right ma_wr_state end pivot in mas_wr_spanning_store() maple_tree: Introduce maple_copy node and use it in mas_spanning_rebalance() maple_tree: Testing update for spanning store maple_tree: Inline mas_spanning_rebalance_loop() into mas_wr_spanning_rebalance() maple_tree: Change initial big node setup in mas_wr_spanning_rebalance() maple_tree: Introduce ma_leaf_max_gap() maple_tree: Add gap support, slot and pivot sizes for maple copy maple_tree: Start using maple copy node for destination maple_tree: inline mas_wr_spanning_rebalance() maple_tree: Remove unnecessary return statements maple_tree: Separate wr_split_store and wr_rebalance store type code path maple_tree: Add cp_is_new_root() helper maple_tree: Use maple copy node for mas_wr_rebalance() operation maple_tree: Add test for rebalance calculation off-by-one maple_tree: Add copy_tree_location() helper maple_tree: Add cp_converged() helper maple_tree: Use maple copy node for mas_wr_split() maple_tree: Remove maple big node and subtree structs maple_tree: Pass maple copy node to mas_wmb_replace() maple_tree: Don't pass end to mas_wr_append() maple_tree: Clean up mas_wr_node_store() include/linux/maple_tree.h | 42 + lib/maple_tree.c | 2134 +++++++++++++----------------- lib/test_maple_tree.c | 55 +- tools/testing/radix-tree/maple.c | 308 ++++- 4 files changed, 1340 insertions(+), 1199 deletions(-) -- 2.47.3
Stop using the maple big node for rebalance operations by changing to more align with spanning store. The rebalance operation needs its own data calculation in rebalance_data(). In the event of too much data, the rebalance tries to push the data using push_data_sib(). If there is insufficient data, the rebalance operation will rebalance against a sibling (found with rebalance_sib()). The rebalance starts at the leaf and works its way upward in the tree using rebalance_ascend(). Most of the code is shared with spanning store such as the copy node having a new root, but is fundamentally different in that the data must come from a sibling. A parent maple state is used to track the parent location to avoid multiple mas_ascend() calls. The maple state tree location is copied from the parent to the mas (child) in the ascend step. Ascending itself is done in the main loop. Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com> --- lib/maple_tree.c | 213 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 206 insertions(+), 7 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 42038e42a4c7e..0d5d68913de44 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -2305,6 +2305,19 @@ static inline void mte_mid_split_check(struct maple_enode **l, *split = mid_split; } +static inline void rebalance_sib(struct ma_state *parent, struct ma_state *sib) +{ + *sib = *parent; + /* Prioritize move right to pull data left */ + if (sib->offset < sib->end) + sib->offset++; + else + sib->offset--; + + mas_descend(sib); + sib->end = mas_data_end(sib); +} + static inline void spanning_sib(struct ma_wr_state *l_wr_mas, struct ma_wr_state *r_wr_mas, struct ma_state *nneighbour) @@ -2855,6 +2868,112 @@ static inline void cp_data_calc(struct maple_copy *cp, cp->data += r_wr_mas->mas->end - r_wr_mas->offset_end; } +static bool data_fits(struct ma_state *sib, struct ma_state *mas, + struct maple_copy *cp) +{ + unsigned char new_data; + enum maple_type type; + unsigned char space; + unsigned char end; + + type = mte_node_type(mas->node); + space = 2 * mt_slots[type]; + end = sib->end; + + new_data = end + 1 + cp->data; + if (new_data > space) + return false; + + /* + * This is off by one by design. The extra space is left to reduce + * jitter in operations that add then remove two entries. + * + * end is an index while new space and data are both sizes. Adding one + * to end to convert the index to a size means that the below + * calculation should be <=, but we want to keep an extra space in nodes + * to reduce jitter. + * + * Note that it is still possible to get a full node on the left by the + * NULL landing exactly on the split. The NULL ending of a node happens + * in the dst_setup() function, where we will either increase the split + * by one or decrease it by one, if possible. In the case of split + * (this case), it is always possible to shift the spilt by one - again + * because there is at least one slot free by the below checking. + */ + if (new_data < space) + return true; + + return false; +} + +static inline void push_data_sib(struct maple_copy *cp, struct ma_state *mas, + struct ma_state *sib, struct ma_state *parent) +{ + + if (mte_is_root(mas->node)) + goto no_push; + + + *sib = *parent; + if (sib->offset) { + sib->offset--; + mas_descend(sib); + sib->end = mas_data_end(sib); + if (data_fits(sib, mas, cp)) /* Push left */ + return; + + *sib = *parent; + } + + if (sib->offset >= sib->end) + goto no_push; + + sib->offset++; + mas_descend(sib); + sib->end = mas_data_end(sib); + if (data_fits(sib, mas, cp)) /* Push right*/ + return; + +no_push: + sib->end = 0; +} + +/* + * rebalance_data() - Calculate the @cp data, populate @sib if insufficient or + * if the data can be pushed into a sibling. + * @cp: The maple copy node + * @wr_mas: The left write maple state + * @sib: The maple state of the sibling. + * + * Note: @cp->data is a size and not indexed by 0. @sib->end may be set to 0 to + * indicate it will not be used. + * + */ +static inline void rebalance_data(struct maple_copy *cp, + struct ma_wr_state *wr_mas, struct ma_state *sib, + struct ma_state *parent) +{ + cp_data_calc(cp, wr_mas, wr_mas); + sib->end = 0; + if (cp->data > mt_slots[wr_mas->type]) { + push_data_sib(cp, wr_mas->mas, sib, parent); + if (sib->end) + goto use_sib; + } else if (cp->data <= mt_min_slots[wr_mas->type]) { + if ((wr_mas->mas->min != 0) || + (wr_mas->mas->max != ULONG_MAX)) { + rebalance_sib(parent, sib); + goto use_sib; + } + } + + return; + +use_sib: + + cp->data += sib->end + 1; +} + /* * spanning_data() - Calculate the @cp data and populate @sib if insufficient * @cp: The maple copy node @@ -3412,6 +3531,55 @@ static bool spanning_ascend(struct maple_copy *cp, struct ma_state *mas, return true; } +/* + * rebalance_ascend() - Ascend the tree and set up for the next loop - if + * necessary + * + * Return: True if there another rebalancing operation on the next level is + * needed, false otherwise. + */ +static inline bool rebalance_ascend(struct maple_copy *cp, + struct ma_wr_state *wr_mas, struct ma_state *sib, + struct ma_state *parent) +{ + struct ma_state *mas; + unsigned long min, max; + + mas = wr_mas->mas; + if (!sib->end) { + min = mas->min; + max = mas->max; + } else if (sib->min > mas->max) { /* Move right succeeded */ + min = mas->min; + max = sib->max; + wr_mas->offset_end = parent->offset + 1; + } else { + min = sib->min; + max = mas->max; + wr_mas->offset_end = parent->offset; + parent->offset--; + } + + cp_dst_to_slots(cp, min, max, mas); + if (cp_is_new_root(cp, mas)) + return false; + + if (cp->d_count == 1 && !sib->end) { + cp->dst[0].node->parent = ma_parent_ptr(mas_mn(mas)->parent); + return false; + } + + cp->height++; + mas->node = parent->node; + mas->offset = parent->offset; + mas->min = parent->min; + mas->max = parent->max; + mas->end = parent->end; + mas->depth = parent->depth; + wr_mas_setup(wr_mas, mas); + return true; +} + /* * mas_rebalance() - Rebalance a given node. * @mas: The maple state @@ -4379,16 +4547,47 @@ static noinline_for_kasan void mas_wr_split(struct ma_wr_state *wr_mas) * mas_wr_rebalance() - Insufficient data in one node needs to either get data * from a sibling or absorb a sibling all together. * @wr_mas: The write maple state + * + * Rebalance is different than a spanning store in that the write state is + * already at the leaf node that's being altered. */ -static noinline_for_kasan void mas_wr_rebalance(struct ma_wr_state *wr_mas) +static void mas_wr_rebalance(struct ma_wr_state *wr_mas) { - struct maple_big_node b_node; + struct maple_enode *old_enode; + struct ma_state parent; + struct ma_state *mas; + struct maple_copy cp; + struct ma_state sib; - trace_ma_write(__func__, wr_mas->mas, 0, wr_mas->entry); - memset(&b_node, 0, sizeof(struct maple_big_node)); - mas_store_b_node(wr_mas, &b_node, wr_mas->offset_end); - WARN_ON_ONCE(wr_mas->mas->store_type != wr_rebalance); - return mas_rebalance(wr_mas->mas, &b_node); + /* + * Rebalancing occurs if a node is insufficient. Data is rebalanced + * against the node to the right if it exists, otherwise the node to the + * left of this node is rebalanced against this node. If rebalancing + * causes just one node to be produced instead of two, then the parent + * is also examined and rebalanced if it is insufficient. Every level + * tries to combine the data in the same way. If one node contains the + * entire range of the tree, then that node is used as a new root node. + */ + + mas = wr_mas->mas; + trace_ma_op(TP_FCT, mas); + parent = *mas; + cp_leaf_init(&cp, mas, wr_mas, wr_mas); + do { + if (!mte_is_root(parent.node)) { + mas_ascend(&parent); + parent.end = mas_data_end(&parent); + } + rebalance_data(&cp, wr_mas, &sib, &parent); + multi_src_setup(&cp, wr_mas, wr_mas, &sib); + dst_setup(&cp, mas, wr_mas->type); + cp_data_write(&cp, mas); + } while (rebalance_ascend(&cp, wr_mas, &sib, &parent)); + + old_enode = mas->node; + mas->node = mt_slot_locked(mas->tree, cp.slot, 0); + mas_wmb_replace(mas, old_enode, cp.height); + mtree_range_walk(mas); } /* -- 2.47.3
{ "author": "\"Liam R. Howlett\" <Liam.Howlett@oracle.com>", "date": "Fri, 30 Jan 2026 15:59:27 -0500", "thread_id": "20260202103154.ad1aa05611c79d21b070a861@linux-foundation.org.mbox.gz" }
lkml
[PATCH v3 00/30] maple_tree: Replace big node with maple copy
The big node struct was created for simplicity of splitting, rebalancing, and spanning store operations by using a copy buffer to create the data necessary prior to breaking it up into 256B nodes. Certain operations were rather tricky due to the restriction of keeping NULL entries together and never at the end of a node (except the right-most node). The big node struct is incompatible with future features that are currently in development. Specifically different node types and different data type sizes for pivots. The big node struct was also a stack variable, which caused issues with certain configurations of kernel build. This series removes big node by introducing another node type which will never be written to the tree: maple_copy. The maple copy node operates more like a scatter/gather operation with a number of sources and destinations of allocated nodes. The sources are copied to the destinations, in turn, until the sources are exhausted. The destination is changed if it is filled or the split location is reached prior to the source data end. New data is inserted by using the maple copy node itself as a source with up to 3 slots and pivots. The data in the maple copy node is the data being written to the tree along with any fragment of the range(s) being overwritten. As with all nodes, the maple copy node is of size 256B. Using a node type allows for the copy operation to treat the new data stored in the maple copy node the same as any other source node. Analysis of the runtime shows no regression or benefit of removing the larger stack structure. The motivation is the ground work to use new node types and to help those with odd configurations that have had issues. The change was tested by myself using mm_tests on amd64 and by Suren on android (arm64). Limited testing on s390 qemu was also performed using stress-ng on the virtual memory, which should cover many corner cases. v1: https://lore.kernel.org/all/20260115193647.1695937-1-Liam.Howlett@oracle.com/ v2: https://lore.kernel.org/all/20260121164526.2093265-1-Liam.Howlett@oracle.com/ Changes since v2: - Whitespace fix in rebalance_data() - Added ma_init_slot() for cleaner casting during RCU_INIT_POINTER(). Thanks test robot & SK [1] - Fixed off-by-one in rebalance_data() which caused node overuse, reported by linux-next. Thanks Mark [2] - Added new patch to reproducer to test cases in userspace testing for the rebalance_data() off-by-one [1]. https://lore.kernel.org/all/20260122055516.69335-1-sj@kernel.org/ [2]. https://lore.kernel.org/all/bd1c3356-11a1-4d0b-bf58-47eb21bfd24d@sirena.org.uk/ Liam R. Howlett (30): maple_tree: Fix mas_dup_alloc() sparse warning maple_tree: Move mas_spanning_rebalance loop to function maple_tree: Extract use of big node from mas_wr_spanning_store() maple_tree: Remove unnecessary assignment of orig_l index maple_tree: inline mas_spanning_rebalance() into mas_wr_spanning_rebalance() maple_tree: Make ma_wr_states reliable for reuse in spanning store maple_tree: Remove l_wr_mas from mas_wr_spanning_rebalance maple_tree: Don't pass through height in mas_wr_spanning_store maple_tree: Move maple_subtree_state from mas_wr_spanning_store to mas_wr_spanning_rebalance maple_tree: Correct right ma_wr_state end pivot in mas_wr_spanning_store() maple_tree: Introduce maple_copy node and use it in mas_spanning_rebalance() maple_tree: Testing update for spanning store maple_tree: Inline mas_spanning_rebalance_loop() into mas_wr_spanning_rebalance() maple_tree: Change initial big node setup in mas_wr_spanning_rebalance() maple_tree: Introduce ma_leaf_max_gap() maple_tree: Add gap support, slot and pivot sizes for maple copy maple_tree: Start using maple copy node for destination maple_tree: inline mas_wr_spanning_rebalance() maple_tree: Remove unnecessary return statements maple_tree: Separate wr_split_store and wr_rebalance store type code path maple_tree: Add cp_is_new_root() helper maple_tree: Use maple copy node for mas_wr_rebalance() operation maple_tree: Add test for rebalance calculation off-by-one maple_tree: Add copy_tree_location() helper maple_tree: Add cp_converged() helper maple_tree: Use maple copy node for mas_wr_split() maple_tree: Remove maple big node and subtree structs maple_tree: Pass maple copy node to mas_wmb_replace() maple_tree: Don't pass end to mas_wr_append() maple_tree: Clean up mas_wr_node_store() include/linux/maple_tree.h | 42 + lib/maple_tree.c | 2134 +++++++++++++----------------- lib/test_maple_tree.c | 55 +- tools/testing/radix-tree/maple.c | 308 ++++- 4 files changed, 1340 insertions(+), 1199 deletions(-) -- 2.47.3
This is the same as mas_leaf_max_gap(), but the information necessary is known without a maple state in future code. Adding this function now simplifies the review for a subsequent patch. Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com> --- lib/maple_tree.c | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 0d6f810a4a1fc..499cae720251f 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -1315,26 +1315,14 @@ void wr_mas_setup(struct ma_wr_state *wr_mas, struct ma_state *mas) wr_mas->r_max = mas_safe_pivot(mas, wr_mas->pivots, mas->offset, wr_mas->type); } - -/* - * mas_leaf_max_gap() - Returns the largest gap in a leaf node - * @mas: the maple state - * - * Return: The maximum gap in the leaf. - */ -static unsigned long mas_leaf_max_gap(struct ma_state *mas) +static inline unsigned long ma_leaf_max_gap(struct maple_node *mn, + enum maple_type mt, unsigned long min, unsigned long max, + unsigned long *pivots, void __rcu **slots) { - enum maple_type mt; unsigned long pstart, gap, max_gap; - struct maple_node *mn; - unsigned long *pivots; - void __rcu **slots; unsigned char i; unsigned char max_piv; - mt = mte_node_type(mas->node); - mn = mas_mn(mas); - slots = ma_slots(mn, mt); max_gap = 0; if (unlikely(ma_is_dense(mt))) { gap = 0; @@ -1356,26 +1344,25 @@ static unsigned long mas_leaf_max_gap(struct ma_state *mas) * Check the first implied pivot optimizes the loop below and slot 1 may * be skipped if there is a gap in slot 0. */ - pivots = ma_pivots(mn, mt); if (likely(!slots[0])) { - max_gap = pivots[0] - mas->min + 1; + max_gap = pivots[0] - min + 1; i = 2; } else { i = 1; } /* reduce max_piv as the special case is checked before the loop */ - max_piv = ma_data_end(mn, mt, pivots, mas->max) - 1; + max_piv = ma_data_end(mn, mt, pivots, max) - 1; /* * Check end implied pivot which can only be a gap on the right most * node. */ - if (unlikely(mas->max == ULONG_MAX) && !slots[max_piv + 1]) { + if (unlikely(max == ULONG_MAX) && !slots[max_piv + 1]) { gap = ULONG_MAX - pivots[max_piv]; if (gap > max_gap) max_gap = gap; - if (max_gap > pivots[max_piv] - mas->min) + if (max_gap > pivots[max_piv] - min) return max_gap; } @@ -1395,6 +1382,27 @@ static unsigned long mas_leaf_max_gap(struct ma_state *mas) return max_gap; } +/* + * mas_leaf_max_gap() - Returns the largest gap in a leaf node + * @mas: the maple state + * + * Return: The maximum gap in the leaf. + */ +static inline unsigned long mas_leaf_max_gap(struct ma_state *mas) +{ + enum maple_type mt; + struct maple_node *mn; + unsigned long *pivots; + void __rcu **slots; + + mn = mas_mn(mas); + mt = mte_node_type(mas->node); + slots = ma_slots(mn, mt); + pivots = ma_pivots(mn, mt); + + return ma_leaf_max_gap(mn, mt, mas->min, mas->max, pivots, slots); +} + /* * ma_max_gap() - Get the maximum gap in a maple node (non-leaf) * @node: The maple node -- 2.47.3
{ "author": "\"Liam R. Howlett\" <Liam.Howlett@oracle.com>", "date": "Fri, 30 Jan 2026 15:59:20 -0500", "thread_id": "20260202103154.ad1aa05611c79d21b070a861@linux-foundation.org.mbox.gz" }
lkml
[PATCH v3 00/30] maple_tree: Replace big node with maple copy
The big node struct was created for simplicity of splitting, rebalancing, and spanning store operations by using a copy buffer to create the data necessary prior to breaking it up into 256B nodes. Certain operations were rather tricky due to the restriction of keeping NULL entries together and never at the end of a node (except the right-most node). The big node struct is incompatible with future features that are currently in development. Specifically different node types and different data type sizes for pivots. The big node struct was also a stack variable, which caused issues with certain configurations of kernel build. This series removes big node by introducing another node type which will never be written to the tree: maple_copy. The maple copy node operates more like a scatter/gather operation with a number of sources and destinations of allocated nodes. The sources are copied to the destinations, in turn, until the sources are exhausted. The destination is changed if it is filled or the split location is reached prior to the source data end. New data is inserted by using the maple copy node itself as a source with up to 3 slots and pivots. The data in the maple copy node is the data being written to the tree along with any fragment of the range(s) being overwritten. As with all nodes, the maple copy node is of size 256B. Using a node type allows for the copy operation to treat the new data stored in the maple copy node the same as any other source node. Analysis of the runtime shows no regression or benefit of removing the larger stack structure. The motivation is the ground work to use new node types and to help those with odd configurations that have had issues. The change was tested by myself using mm_tests on amd64 and by Suren on android (arm64). Limited testing on s390 qemu was also performed using stress-ng on the virtual memory, which should cover many corner cases. v1: https://lore.kernel.org/all/20260115193647.1695937-1-Liam.Howlett@oracle.com/ v2: https://lore.kernel.org/all/20260121164526.2093265-1-Liam.Howlett@oracle.com/ Changes since v2: - Whitespace fix in rebalance_data() - Added ma_init_slot() for cleaner casting during RCU_INIT_POINTER(). Thanks test robot & SK [1] - Fixed off-by-one in rebalance_data() which caused node overuse, reported by linux-next. Thanks Mark [2] - Added new patch to reproducer to test cases in userspace testing for the rebalance_data() off-by-one [1]. https://lore.kernel.org/all/20260122055516.69335-1-sj@kernel.org/ [2]. https://lore.kernel.org/all/bd1c3356-11a1-4d0b-bf58-47eb21bfd24d@sirena.org.uk/ Liam R. Howlett (30): maple_tree: Fix mas_dup_alloc() sparse warning maple_tree: Move mas_spanning_rebalance loop to function maple_tree: Extract use of big node from mas_wr_spanning_store() maple_tree: Remove unnecessary assignment of orig_l index maple_tree: inline mas_spanning_rebalance() into mas_wr_spanning_rebalance() maple_tree: Make ma_wr_states reliable for reuse in spanning store maple_tree: Remove l_wr_mas from mas_wr_spanning_rebalance maple_tree: Don't pass through height in mas_wr_spanning_store maple_tree: Move maple_subtree_state from mas_wr_spanning_store to mas_wr_spanning_rebalance maple_tree: Correct right ma_wr_state end pivot in mas_wr_spanning_store() maple_tree: Introduce maple_copy node and use it in mas_spanning_rebalance() maple_tree: Testing update for spanning store maple_tree: Inline mas_spanning_rebalance_loop() into mas_wr_spanning_rebalance() maple_tree: Change initial big node setup in mas_wr_spanning_rebalance() maple_tree: Introduce ma_leaf_max_gap() maple_tree: Add gap support, slot and pivot sizes for maple copy maple_tree: Start using maple copy node for destination maple_tree: inline mas_wr_spanning_rebalance() maple_tree: Remove unnecessary return statements maple_tree: Separate wr_split_store and wr_rebalance store type code path maple_tree: Add cp_is_new_root() helper maple_tree: Use maple copy node for mas_wr_rebalance() operation maple_tree: Add test for rebalance calculation off-by-one maple_tree: Add copy_tree_location() helper maple_tree: Add cp_converged() helper maple_tree: Use maple copy node for mas_wr_split() maple_tree: Remove maple big node and subtree structs maple_tree: Pass maple copy node to mas_wmb_replace() maple_tree: Don't pass end to mas_wr_append() maple_tree: Clean up mas_wr_node_store() include/linux/maple_tree.h | 42 + lib/maple_tree.c | 2134 +++++++++++++----------------- lib/test_maple_tree.c | 55 +- tools/testing/radix-tree/maple.c | 308 ++++- 4 files changed, 1340 insertions(+), 1199 deletions(-) -- 2.47.3
Add plumbing work for using maple copy as a normal node for a source of copy operations. This is needed later. Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com> --- include/linux/maple_tree.h | 1 + lib/maple_tree.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/include/linux/maple_tree.h b/include/linux/maple_tree.h index e99e16ac1c6da..db6a02788902a 100644 --- a/include/linux/maple_tree.h +++ b/include/linux/maple_tree.h @@ -165,6 +165,7 @@ struct maple_copy { } src[4]; /* Simulated node */ void __rcu *slot[3]; + unsigned long gap[3]; unsigned long min; union { unsigned long pivot[3]; diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 499cae720251f..9c701ee7412ca 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -101,6 +101,7 @@ static const unsigned long mt_max[] = { [maple_leaf_64] = ULONG_MAX, [maple_range_64] = ULONG_MAX, [maple_arange_64] = ULONG_MAX, + [maple_copy] = ULONG_MAX, }; #define mt_node_max(x) mt_max[mte_node_type(x)] #endif @@ -110,6 +111,7 @@ static const unsigned char mt_slots[] = { [maple_leaf_64] = MAPLE_RANGE64_SLOTS, [maple_range_64] = MAPLE_RANGE64_SLOTS, [maple_arange_64] = MAPLE_ARANGE64_SLOTS, + [maple_copy] = 3, }; #define mt_slot_count(x) mt_slots[mte_node_type(x)] @@ -118,6 +120,7 @@ static const unsigned char mt_pivots[] = { [maple_leaf_64] = MAPLE_RANGE64_SLOTS - 1, [maple_range_64] = MAPLE_RANGE64_SLOTS - 1, [maple_arange_64] = MAPLE_ARANGE64_SLOTS - 1, + [maple_copy] = 3, }; #define mt_pivot_count(x) mt_pivots[mte_node_type(x)] @@ -126,6 +129,7 @@ static const unsigned char mt_min_slots[] = { [maple_leaf_64] = (MAPLE_RANGE64_SLOTS / 2) - 2, [maple_range_64] = (MAPLE_RANGE64_SLOTS / 2) - 2, [maple_arange_64] = (MAPLE_ARANGE64_SLOTS / 2) - 1, + [maple_copy] = 1, /* Should never be used */ }; #define mt_min_slot_count(x) mt_min_slots[mte_node_type(x)] @@ -627,6 +631,7 @@ static inline unsigned long *ma_gaps(struct maple_node *node, case maple_arange_64: return node->ma64.gap; case maple_copy: + return node->cp.gap; case maple_range_64: case maple_leaf_64: case maple_dense: -- 2.47.3
{ "author": "\"Liam R. Howlett\" <Liam.Howlett@oracle.com>", "date": "Fri, 30 Jan 2026 15:59:21 -0500", "thread_id": "20260202103154.ad1aa05611c79d21b070a861@linux-foundation.org.mbox.gz" }
lkml
[PATCH v3 00/30] maple_tree: Replace big node with maple copy
The big node struct was created for simplicity of splitting, rebalancing, and spanning store operations by using a copy buffer to create the data necessary prior to breaking it up into 256B nodes. Certain operations were rather tricky due to the restriction of keeping NULL entries together and never at the end of a node (except the right-most node). The big node struct is incompatible with future features that are currently in development. Specifically different node types and different data type sizes for pivots. The big node struct was also a stack variable, which caused issues with certain configurations of kernel build. This series removes big node by introducing another node type which will never be written to the tree: maple_copy. The maple copy node operates more like a scatter/gather operation with a number of sources and destinations of allocated nodes. The sources are copied to the destinations, in turn, until the sources are exhausted. The destination is changed if it is filled or the split location is reached prior to the source data end. New data is inserted by using the maple copy node itself as a source with up to 3 slots and pivots. The data in the maple copy node is the data being written to the tree along with any fragment of the range(s) being overwritten. As with all nodes, the maple copy node is of size 256B. Using a node type allows for the copy operation to treat the new data stored in the maple copy node the same as any other source node. Analysis of the runtime shows no regression or benefit of removing the larger stack structure. The motivation is the ground work to use new node types and to help those with odd configurations that have had issues. The change was tested by myself using mm_tests on amd64 and by Suren on android (arm64). Limited testing on s390 qemu was also performed using stress-ng on the virtual memory, which should cover many corner cases. v1: https://lore.kernel.org/all/20260115193647.1695937-1-Liam.Howlett@oracle.com/ v2: https://lore.kernel.org/all/20260121164526.2093265-1-Liam.Howlett@oracle.com/ Changes since v2: - Whitespace fix in rebalance_data() - Added ma_init_slot() for cleaner casting during RCU_INIT_POINTER(). Thanks test robot & SK [1] - Fixed off-by-one in rebalance_data() which caused node overuse, reported by linux-next. Thanks Mark [2] - Added new patch to reproducer to test cases in userspace testing for the rebalance_data() off-by-one [1]. https://lore.kernel.org/all/20260122055516.69335-1-sj@kernel.org/ [2]. https://lore.kernel.org/all/bd1c3356-11a1-4d0b-bf58-47eb21bfd24d@sirena.org.uk/ Liam R. Howlett (30): maple_tree: Fix mas_dup_alloc() sparse warning maple_tree: Move mas_spanning_rebalance loop to function maple_tree: Extract use of big node from mas_wr_spanning_store() maple_tree: Remove unnecessary assignment of orig_l index maple_tree: inline mas_spanning_rebalance() into mas_wr_spanning_rebalance() maple_tree: Make ma_wr_states reliable for reuse in spanning store maple_tree: Remove l_wr_mas from mas_wr_spanning_rebalance maple_tree: Don't pass through height in mas_wr_spanning_store maple_tree: Move maple_subtree_state from mas_wr_spanning_store to mas_wr_spanning_rebalance maple_tree: Correct right ma_wr_state end pivot in mas_wr_spanning_store() maple_tree: Introduce maple_copy node and use it in mas_spanning_rebalance() maple_tree: Testing update for spanning store maple_tree: Inline mas_spanning_rebalance_loop() into mas_wr_spanning_rebalance() maple_tree: Change initial big node setup in mas_wr_spanning_rebalance() maple_tree: Introduce ma_leaf_max_gap() maple_tree: Add gap support, slot and pivot sizes for maple copy maple_tree: Start using maple copy node for destination maple_tree: inline mas_wr_spanning_rebalance() maple_tree: Remove unnecessary return statements maple_tree: Separate wr_split_store and wr_rebalance store type code path maple_tree: Add cp_is_new_root() helper maple_tree: Use maple copy node for mas_wr_rebalance() operation maple_tree: Add test for rebalance calculation off-by-one maple_tree: Add copy_tree_location() helper maple_tree: Add cp_converged() helper maple_tree: Use maple copy node for mas_wr_split() maple_tree: Remove maple big node and subtree structs maple_tree: Pass maple copy node to mas_wmb_replace() maple_tree: Don't pass end to mas_wr_append() maple_tree: Clean up mas_wr_node_store() include/linux/maple_tree.h | 42 + lib/maple_tree.c | 2134 +++++++++++++----------------- lib/test_maple_tree.c | 55 +- tools/testing/radix-tree/maple.c | 308 ++++- 4 files changed, 1340 insertions(+), 1199 deletions(-) -- 2.47.3
The split and rebalance store types both go through the same function that uses the big node. Separate the code paths so that each can be updated independently. No functional change intended Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com> --- lib/maple_tree.c | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 4a64b4f37aeb3..5280fa6d2d6ec 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -3719,24 +3719,6 @@ static void mas_split(struct ma_state *mas, struct maple_big_node *b_node) mtree_range_walk(mas); } -/* - * mas_commit_b_node() - Commit the big node into the tree. - * @wr_mas: The maple write state - * @b_node: The maple big node - */ -static noinline_for_kasan void mas_commit_b_node(struct ma_wr_state *wr_mas, - struct maple_big_node *b_node) -{ - enum store_type type = wr_mas->mas->store_type; - - WARN_ON_ONCE(type != wr_rebalance && type != wr_split_store); - - if (type == wr_rebalance) - return mas_rebalance(wr_mas->mas, b_node); - - return mas_split(wr_mas->mas, b_node); -} - /* * mas_root_expand() - Expand a root to a node * @mas: The maple state @@ -4373,19 +4355,34 @@ static inline void mas_wr_append(struct ma_wr_state *wr_mas, } /* - * mas_wr_bnode() - Slow path for a modification. + * mas_wr_split() - Expand one node into two * @wr_mas: The write maple state - * - * This is where split, rebalance end up. */ -static void mas_wr_bnode(struct ma_wr_state *wr_mas) +static noinline_for_kasan void mas_wr_split(struct ma_wr_state *wr_mas) { struct maple_big_node b_node; trace_ma_write(TP_FCT, wr_mas->mas, 0, wr_mas->entry); memset(&b_node, 0, sizeof(struct maple_big_node)); mas_store_b_node(wr_mas, &b_node, wr_mas->offset_end); - mas_commit_b_node(wr_mas, &b_node); + WARN_ON_ONCE(wr_mas->mas->store_type != wr_split_store); + return mas_split(wr_mas->mas, &b_node); +} + +/* + * mas_wr_rebalance() - Insufficient data in one node needs to either get data + * from a sibling or absorb a sibling all together. + * @wr_mas: The write maple state + */ +static noinline_for_kasan void mas_wr_rebalance(struct ma_wr_state *wr_mas) +{ + struct maple_big_node b_node; + + trace_ma_write(__func__, wr_mas->mas, 0, wr_mas->entry); + memset(&b_node, 0, sizeof(struct maple_big_node)); + mas_store_b_node(wr_mas, &b_node, wr_mas->offset_end); + WARN_ON_ONCE(wr_mas->mas->store_type != wr_rebalance); + return mas_rebalance(wr_mas->mas, &b_node); } /* @@ -4416,8 +4413,10 @@ static inline void mas_wr_store_entry(struct ma_wr_state *wr_mas) mas_wr_spanning_store(wr_mas); break; case wr_split_store: + mas_wr_split(wr_mas); + break; case wr_rebalance: - mas_wr_bnode(wr_mas); + mas_wr_rebalance(wr_mas); break; case wr_new_root: mas_new_root(mas, wr_mas->entry); -- 2.47.3
{ "author": "\"Liam R. Howlett\" <Liam.Howlett@oracle.com>", "date": "Fri, 30 Jan 2026 15:59:25 -0500", "thread_id": "20260202103154.ad1aa05611c79d21b070a861@linux-foundation.org.mbox.gz" }
lkml
[PATCH v3 00/30] maple_tree: Replace big node with maple copy
The big node struct was created for simplicity of splitting, rebalancing, and spanning store operations by using a copy buffer to create the data necessary prior to breaking it up into 256B nodes. Certain operations were rather tricky due to the restriction of keeping NULL entries together and never at the end of a node (except the right-most node). The big node struct is incompatible with future features that are currently in development. Specifically different node types and different data type sizes for pivots. The big node struct was also a stack variable, which caused issues with certain configurations of kernel build. This series removes big node by introducing another node type which will never be written to the tree: maple_copy. The maple copy node operates more like a scatter/gather operation with a number of sources and destinations of allocated nodes. The sources are copied to the destinations, in turn, until the sources are exhausted. The destination is changed if it is filled or the split location is reached prior to the source data end. New data is inserted by using the maple copy node itself as a source with up to 3 slots and pivots. The data in the maple copy node is the data being written to the tree along with any fragment of the range(s) being overwritten. As with all nodes, the maple copy node is of size 256B. Using a node type allows for the copy operation to treat the new data stored in the maple copy node the same as any other source node. Analysis of the runtime shows no regression or benefit of removing the larger stack structure. The motivation is the ground work to use new node types and to help those with odd configurations that have had issues. The change was tested by myself using mm_tests on amd64 and by Suren on android (arm64). Limited testing on s390 qemu was also performed using stress-ng on the virtual memory, which should cover many corner cases. v1: https://lore.kernel.org/all/20260115193647.1695937-1-Liam.Howlett@oracle.com/ v2: https://lore.kernel.org/all/20260121164526.2093265-1-Liam.Howlett@oracle.com/ Changes since v2: - Whitespace fix in rebalance_data() - Added ma_init_slot() for cleaner casting during RCU_INIT_POINTER(). Thanks test robot & SK [1] - Fixed off-by-one in rebalance_data() which caused node overuse, reported by linux-next. Thanks Mark [2] - Added new patch to reproducer to test cases in userspace testing for the rebalance_data() off-by-one [1]. https://lore.kernel.org/all/20260122055516.69335-1-sj@kernel.org/ [2]. https://lore.kernel.org/all/bd1c3356-11a1-4d0b-bf58-47eb21bfd24d@sirena.org.uk/ Liam R. Howlett (30): maple_tree: Fix mas_dup_alloc() sparse warning maple_tree: Move mas_spanning_rebalance loop to function maple_tree: Extract use of big node from mas_wr_spanning_store() maple_tree: Remove unnecessary assignment of orig_l index maple_tree: inline mas_spanning_rebalance() into mas_wr_spanning_rebalance() maple_tree: Make ma_wr_states reliable for reuse in spanning store maple_tree: Remove l_wr_mas from mas_wr_spanning_rebalance maple_tree: Don't pass through height in mas_wr_spanning_store maple_tree: Move maple_subtree_state from mas_wr_spanning_store to mas_wr_spanning_rebalance maple_tree: Correct right ma_wr_state end pivot in mas_wr_spanning_store() maple_tree: Introduce maple_copy node and use it in mas_spanning_rebalance() maple_tree: Testing update for spanning store maple_tree: Inline mas_spanning_rebalance_loop() into mas_wr_spanning_rebalance() maple_tree: Change initial big node setup in mas_wr_spanning_rebalance() maple_tree: Introduce ma_leaf_max_gap() maple_tree: Add gap support, slot and pivot sizes for maple copy maple_tree: Start using maple copy node for destination maple_tree: inline mas_wr_spanning_rebalance() maple_tree: Remove unnecessary return statements maple_tree: Separate wr_split_store and wr_rebalance store type code path maple_tree: Add cp_is_new_root() helper maple_tree: Use maple copy node for mas_wr_rebalance() operation maple_tree: Add test for rebalance calculation off-by-one maple_tree: Add copy_tree_location() helper maple_tree: Add cp_converged() helper maple_tree: Use maple copy node for mas_wr_split() maple_tree: Remove maple big node and subtree structs maple_tree: Pass maple copy node to mas_wmb_replace() maple_tree: Don't pass end to mas_wr_append() maple_tree: Clean up mas_wr_node_store() include/linux/maple_tree.h | 42 + lib/maple_tree.c | 2134 +++++++++++++----------------- lib/test_maple_tree.c | 55 +- tools/testing/radix-tree/maple.c | 308 ++++- 4 files changed, 1340 insertions(+), 1199 deletions(-) -- 2.47.3
Use the wr_mas instead of creating another variable on the stack. Take the opportunity to remove l_mas from being used anywhere but in the maple_subtree_state. Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com> --- lib/maple_tree.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index ab14876bebf7c..afa39bbd687c0 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -2751,7 +2751,7 @@ static void mas_spanning_rebalance(struct ma_state *mas, static noinline void mas_wr_spanning_rebalance(struct ma_state *mas, struct maple_subtree_state *mast, unsigned char height, - struct ma_wr_state *l_wr_mas) + struct ma_wr_state *wr_mas) { struct maple_big_node b_node; MA_STATE(l_mas, mas->tree, mas->index, mas->index); @@ -2760,7 +2760,7 @@ static noinline void mas_wr_spanning_rebalance(struct ma_state *mas, memset(&b_node, 0, sizeof(struct maple_big_node)); /* Copy l_mas and store the value in b_node. */ - mas_store_b_node(l_wr_mas, &b_node, mast->orig_l->end); + mas_store_b_node(wr_mas, &b_node, mast->orig_l->end); /* Copy r_mas into b_node if there is anything to copy. */ if (mast->orig_r->max > mast->orig_r->last) mas_mab_cp(mast->orig_r, mast->orig_r->offset, @@ -3454,7 +3454,6 @@ static void mas_wr_spanning_store(struct ma_wr_state *wr_mas) MA_STATE(l_mas, NULL, 0, 0); MA_STATE(r_mas, NULL, 0, 0); MA_WR_STATE(r_wr_mas, &r_mas, wr_mas->entry); - MA_WR_STATE(l_wr_mas, &l_mas, wr_mas->entry); /* * A store operation that spans multiple nodes is called a spanning @@ -3494,25 +3493,23 @@ static void mas_wr_spanning_store(struct ma_wr_state *wr_mas) r_mas.last = r_mas.index = mas->last; /* Set up left side. */ - l_mas = *mas; - mas_wr_walk_index(&l_wr_mas); + mas_wr_walk_index(wr_mas); if (!wr_mas->entry) { - mas_extend_spanning_null(&l_wr_mas, &r_wr_mas); - mas->offset = l_mas.offset; - mas->index = l_mas.index; - mas->last = l_mas.last = r_mas.last; + mas_extend_spanning_null(wr_mas, &r_wr_mas); + mas->last = r_mas.last; } /* expanding NULLs may make this cover the entire range */ - if (!l_mas.index && r_mas.last == ULONG_MAX) { + if (!mas->index && r_mas.last == ULONG_MAX) { mas_set_range(mas, 0, ULONG_MAX); return mas_new_root(mas, wr_mas->entry); } + l_mas = *mas; mast.orig_l = &l_mas; mast.orig_r = &r_mas; - mas_wr_spanning_rebalance(mas, &mast, height + 1, &l_wr_mas); + mas_wr_spanning_rebalance(mas, &mast, height + 1, wr_mas); } /* -- 2.47.3
{ "author": "\"Liam R. Howlett\" <Liam.Howlett@oracle.com>", "date": "Fri, 30 Jan 2026 15:59:12 -0500", "thread_id": "20260202103154.ad1aa05611c79d21b070a861@linux-foundation.org.mbox.gz" }
lkml
[PATCH v3 00/30] maple_tree: Replace big node with maple copy
The big node struct was created for simplicity of splitting, rebalancing, and spanning store operations by using a copy buffer to create the data necessary prior to breaking it up into 256B nodes. Certain operations were rather tricky due to the restriction of keeping NULL entries together and never at the end of a node (except the right-most node). The big node struct is incompatible with future features that are currently in development. Specifically different node types and different data type sizes for pivots. The big node struct was also a stack variable, which caused issues with certain configurations of kernel build. This series removes big node by introducing another node type which will never be written to the tree: maple_copy. The maple copy node operates more like a scatter/gather operation with a number of sources and destinations of allocated nodes. The sources are copied to the destinations, in turn, until the sources are exhausted. The destination is changed if it is filled or the split location is reached prior to the source data end. New data is inserted by using the maple copy node itself as a source with up to 3 slots and pivots. The data in the maple copy node is the data being written to the tree along with any fragment of the range(s) being overwritten. As with all nodes, the maple copy node is of size 256B. Using a node type allows for the copy operation to treat the new data stored in the maple copy node the same as any other source node. Analysis of the runtime shows no regression or benefit of removing the larger stack structure. The motivation is the ground work to use new node types and to help those with odd configurations that have had issues. The change was tested by myself using mm_tests on amd64 and by Suren on android (arm64). Limited testing on s390 qemu was also performed using stress-ng on the virtual memory, which should cover many corner cases. v1: https://lore.kernel.org/all/20260115193647.1695937-1-Liam.Howlett@oracle.com/ v2: https://lore.kernel.org/all/20260121164526.2093265-1-Liam.Howlett@oracle.com/ Changes since v2: - Whitespace fix in rebalance_data() - Added ma_init_slot() for cleaner casting during RCU_INIT_POINTER(). Thanks test robot & SK [1] - Fixed off-by-one in rebalance_data() which caused node overuse, reported by linux-next. Thanks Mark [2] - Added new patch to reproducer to test cases in userspace testing for the rebalance_data() off-by-one [1]. https://lore.kernel.org/all/20260122055516.69335-1-sj@kernel.org/ [2]. https://lore.kernel.org/all/bd1c3356-11a1-4d0b-bf58-47eb21bfd24d@sirena.org.uk/ Liam R. Howlett (30): maple_tree: Fix mas_dup_alloc() sparse warning maple_tree: Move mas_spanning_rebalance loop to function maple_tree: Extract use of big node from mas_wr_spanning_store() maple_tree: Remove unnecessary assignment of orig_l index maple_tree: inline mas_spanning_rebalance() into mas_wr_spanning_rebalance() maple_tree: Make ma_wr_states reliable for reuse in spanning store maple_tree: Remove l_wr_mas from mas_wr_spanning_rebalance maple_tree: Don't pass through height in mas_wr_spanning_store maple_tree: Move maple_subtree_state from mas_wr_spanning_store to mas_wr_spanning_rebalance maple_tree: Correct right ma_wr_state end pivot in mas_wr_spanning_store() maple_tree: Introduce maple_copy node and use it in mas_spanning_rebalance() maple_tree: Testing update for spanning store maple_tree: Inline mas_spanning_rebalance_loop() into mas_wr_spanning_rebalance() maple_tree: Change initial big node setup in mas_wr_spanning_rebalance() maple_tree: Introduce ma_leaf_max_gap() maple_tree: Add gap support, slot and pivot sizes for maple copy maple_tree: Start using maple copy node for destination maple_tree: inline mas_wr_spanning_rebalance() maple_tree: Remove unnecessary return statements maple_tree: Separate wr_split_store and wr_rebalance store type code path maple_tree: Add cp_is_new_root() helper maple_tree: Use maple copy node for mas_wr_rebalance() operation maple_tree: Add test for rebalance calculation off-by-one maple_tree: Add copy_tree_location() helper maple_tree: Add cp_converged() helper maple_tree: Use maple copy node for mas_wr_split() maple_tree: Remove maple big node and subtree structs maple_tree: Pass maple copy node to mas_wmb_replace() maple_tree: Don't pass end to mas_wr_append() maple_tree: Clean up mas_wr_node_store() include/linux/maple_tree.h | 42 + lib/maple_tree.c | 2134 +++++++++++++----------------- lib/test_maple_tree.c | 55 +- tools/testing/radix-tree/maple.c | 308 ++++- 4 files changed, 1340 insertions(+), 1199 deletions(-) -- 2.47.3
mas_extend_spanning_null() was not modifying the range min and range max of the resulting store operation. The result was that the maple write state no longer matched what the write was doing. This was not an issue as the values were previously not used, but to make the ma_wr_state usable in future changes, the range min/max stored in the ma_wr_state for left and right need to be consistent with the operation. Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com> --- lib/maple_tree.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index fb14ce4a49c3c..ab14876bebf7c 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -3319,6 +3319,7 @@ static inline void mas_extend_spanning_null(struct ma_wr_state *l_wr_mas, l_mas->index = l_mas->min; l_mas->offset = l_slot - 1; + l_wr_mas->r_min = l_mas->index; } if (!r_wr_mas->content) { @@ -3331,6 +3332,7 @@ static inline void mas_extend_spanning_null(struct ma_wr_state *l_wr_mas, r_mas->last = mas_safe_pivot(r_mas, r_wr_mas->pivots, r_wr_mas->type, r_mas->offset + 1); r_mas->offset++; + r_wr_mas->r_max = r_mas->last; } } -- 2.47.3
{ "author": "\"Liam R. Howlett\" <Liam.Howlett@oracle.com>", "date": "Fri, 30 Jan 2026 15:59:11 -0500", "thread_id": "20260202103154.ad1aa05611c79d21b070a861@linux-foundation.org.mbox.gz" }
lkml
[PATCH v3 00/30] maple_tree: Replace big node with maple copy
The big node struct was created for simplicity of splitting, rebalancing, and spanning store operations by using a copy buffer to create the data necessary prior to breaking it up into 256B nodes. Certain operations were rather tricky due to the restriction of keeping NULL entries together and never at the end of a node (except the right-most node). The big node struct is incompatible with future features that are currently in development. Specifically different node types and different data type sizes for pivots. The big node struct was also a stack variable, which caused issues with certain configurations of kernel build. This series removes big node by introducing another node type which will never be written to the tree: maple_copy. The maple copy node operates more like a scatter/gather operation with a number of sources and destinations of allocated nodes. The sources are copied to the destinations, in turn, until the sources are exhausted. The destination is changed if it is filled or the split location is reached prior to the source data end. New data is inserted by using the maple copy node itself as a source with up to 3 slots and pivots. The data in the maple copy node is the data being written to the tree along with any fragment of the range(s) being overwritten. As with all nodes, the maple copy node is of size 256B. Using a node type allows for the copy operation to treat the new data stored in the maple copy node the same as any other source node. Analysis of the runtime shows no regression or benefit of removing the larger stack structure. The motivation is the ground work to use new node types and to help those with odd configurations that have had issues. The change was tested by myself using mm_tests on amd64 and by Suren on android (arm64). Limited testing on s390 qemu was also performed using stress-ng on the virtual memory, which should cover many corner cases. v1: https://lore.kernel.org/all/20260115193647.1695937-1-Liam.Howlett@oracle.com/ v2: https://lore.kernel.org/all/20260121164526.2093265-1-Liam.Howlett@oracle.com/ Changes since v2: - Whitespace fix in rebalance_data() - Added ma_init_slot() for cleaner casting during RCU_INIT_POINTER(). Thanks test robot & SK [1] - Fixed off-by-one in rebalance_data() which caused node overuse, reported by linux-next. Thanks Mark [2] - Added new patch to reproducer to test cases in userspace testing for the rebalance_data() off-by-one [1]. https://lore.kernel.org/all/20260122055516.69335-1-sj@kernel.org/ [2]. https://lore.kernel.org/all/bd1c3356-11a1-4d0b-bf58-47eb21bfd24d@sirena.org.uk/ Liam R. Howlett (30): maple_tree: Fix mas_dup_alloc() sparse warning maple_tree: Move mas_spanning_rebalance loop to function maple_tree: Extract use of big node from mas_wr_spanning_store() maple_tree: Remove unnecessary assignment of orig_l index maple_tree: inline mas_spanning_rebalance() into mas_wr_spanning_rebalance() maple_tree: Make ma_wr_states reliable for reuse in spanning store maple_tree: Remove l_wr_mas from mas_wr_spanning_rebalance maple_tree: Don't pass through height in mas_wr_spanning_store maple_tree: Move maple_subtree_state from mas_wr_spanning_store to mas_wr_spanning_rebalance maple_tree: Correct right ma_wr_state end pivot in mas_wr_spanning_store() maple_tree: Introduce maple_copy node and use it in mas_spanning_rebalance() maple_tree: Testing update for spanning store maple_tree: Inline mas_spanning_rebalance_loop() into mas_wr_spanning_rebalance() maple_tree: Change initial big node setup in mas_wr_spanning_rebalance() maple_tree: Introduce ma_leaf_max_gap() maple_tree: Add gap support, slot and pivot sizes for maple copy maple_tree: Start using maple copy node for destination maple_tree: inline mas_wr_spanning_rebalance() maple_tree: Remove unnecessary return statements maple_tree: Separate wr_split_store and wr_rebalance store type code path maple_tree: Add cp_is_new_root() helper maple_tree: Use maple copy node for mas_wr_rebalance() operation maple_tree: Add test for rebalance calculation off-by-one maple_tree: Add copy_tree_location() helper maple_tree: Add cp_converged() helper maple_tree: Use maple copy node for mas_wr_split() maple_tree: Remove maple big node and subtree structs maple_tree: Pass maple copy node to mas_wmb_replace() maple_tree: Don't pass end to mas_wr_append() maple_tree: Clean up mas_wr_node_store() include/linux/maple_tree.h | 42 + lib/maple_tree.c | 2134 +++++++++++++----------------- lib/test_maple_tree.c | 55 +- tools/testing/radix-tree/maple.c | 308 ++++- 4 files changed, 1340 insertions(+), 1199 deletions(-) -- 2.47.3
Figure out the end internally. This is necessary for future cleanups. Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com> --- lib/maple_tree.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 064357a44906e..c9c63246f721c 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -3309,18 +3309,17 @@ static inline unsigned char mas_wr_new_end(struct ma_wr_state *wr_mas) /* * mas_wr_append: Attempt to append * @wr_mas: the maple write state - * @new_end: The end of the node after the modification * * This is currently unsafe in rcu mode since the end of the node may be cached * by readers while the node contents may be updated which could result in * inaccurate information. */ -static inline void mas_wr_append(struct ma_wr_state *wr_mas, - unsigned char new_end) +static inline void mas_wr_append(struct ma_wr_state *wr_mas) { struct ma_state *mas = wr_mas->mas; void __rcu **slots; unsigned char end = mas->end; + unsigned char new_end = mas_wr_new_end(wr_mas); if (new_end < mt_pivots[wr_mas->type]) { wr_mas->pivots[new_end] = wr_mas->pivots[end]; @@ -3513,7 +3512,7 @@ static inline void mas_wr_store_entry(struct ma_wr_state *wr_mas) mas_update_gap(mas); break; case wr_append: - mas_wr_append(wr_mas, new_end); + mas_wr_append(wr_mas); break; case wr_slot_store: mas_wr_slot_store(wr_mas); -- 2.47.3
{ "author": "\"Liam R. Howlett\" <Liam.Howlett@oracle.com>", "date": "Fri, 30 Jan 2026 15:59:34 -0500", "thread_id": "20260202103154.ad1aa05611c79d21b070a861@linux-foundation.org.mbox.gz" }
lkml
[PATCH v3 00/30] maple_tree: Replace big node with maple copy
The big node struct was created for simplicity of splitting, rebalancing, and spanning store operations by using a copy buffer to create the data necessary prior to breaking it up into 256B nodes. Certain operations were rather tricky due to the restriction of keeping NULL entries together and never at the end of a node (except the right-most node). The big node struct is incompatible with future features that are currently in development. Specifically different node types and different data type sizes for pivots. The big node struct was also a stack variable, which caused issues with certain configurations of kernel build. This series removes big node by introducing another node type which will never be written to the tree: maple_copy. The maple copy node operates more like a scatter/gather operation with a number of sources and destinations of allocated nodes. The sources are copied to the destinations, in turn, until the sources are exhausted. The destination is changed if it is filled or the split location is reached prior to the source data end. New data is inserted by using the maple copy node itself as a source with up to 3 slots and pivots. The data in the maple copy node is the data being written to the tree along with any fragment of the range(s) being overwritten. As with all nodes, the maple copy node is of size 256B. Using a node type allows for the copy operation to treat the new data stored in the maple copy node the same as any other source node. Analysis of the runtime shows no regression or benefit of removing the larger stack structure. The motivation is the ground work to use new node types and to help those with odd configurations that have had issues. The change was tested by myself using mm_tests on amd64 and by Suren on android (arm64). Limited testing on s390 qemu was also performed using stress-ng on the virtual memory, which should cover many corner cases. v1: https://lore.kernel.org/all/20260115193647.1695937-1-Liam.Howlett@oracle.com/ v2: https://lore.kernel.org/all/20260121164526.2093265-1-Liam.Howlett@oracle.com/ Changes since v2: - Whitespace fix in rebalance_data() - Added ma_init_slot() for cleaner casting during RCU_INIT_POINTER(). Thanks test robot & SK [1] - Fixed off-by-one in rebalance_data() which caused node overuse, reported by linux-next. Thanks Mark [2] - Added new patch to reproducer to test cases in userspace testing for the rebalance_data() off-by-one [1]. https://lore.kernel.org/all/20260122055516.69335-1-sj@kernel.org/ [2]. https://lore.kernel.org/all/bd1c3356-11a1-4d0b-bf58-47eb21bfd24d@sirena.org.uk/ Liam R. Howlett (30): maple_tree: Fix mas_dup_alloc() sparse warning maple_tree: Move mas_spanning_rebalance loop to function maple_tree: Extract use of big node from mas_wr_spanning_store() maple_tree: Remove unnecessary assignment of orig_l index maple_tree: inline mas_spanning_rebalance() into mas_wr_spanning_rebalance() maple_tree: Make ma_wr_states reliable for reuse in spanning store maple_tree: Remove l_wr_mas from mas_wr_spanning_rebalance maple_tree: Don't pass through height in mas_wr_spanning_store maple_tree: Move maple_subtree_state from mas_wr_spanning_store to mas_wr_spanning_rebalance maple_tree: Correct right ma_wr_state end pivot in mas_wr_spanning_store() maple_tree: Introduce maple_copy node and use it in mas_spanning_rebalance() maple_tree: Testing update for spanning store maple_tree: Inline mas_spanning_rebalance_loop() into mas_wr_spanning_rebalance() maple_tree: Change initial big node setup in mas_wr_spanning_rebalance() maple_tree: Introduce ma_leaf_max_gap() maple_tree: Add gap support, slot and pivot sizes for maple copy maple_tree: Start using maple copy node for destination maple_tree: inline mas_wr_spanning_rebalance() maple_tree: Remove unnecessary return statements maple_tree: Separate wr_split_store and wr_rebalance store type code path maple_tree: Add cp_is_new_root() helper maple_tree: Use maple copy node for mas_wr_rebalance() operation maple_tree: Add test for rebalance calculation off-by-one maple_tree: Add copy_tree_location() helper maple_tree: Add cp_converged() helper maple_tree: Use maple copy node for mas_wr_split() maple_tree: Remove maple big node and subtree structs maple_tree: Pass maple copy node to mas_wmb_replace() maple_tree: Don't pass end to mas_wr_append() maple_tree: Clean up mas_wr_node_store() include/linux/maple_tree.h | 42 + lib/maple_tree.c | 2134 +++++++++++++----------------- lib/test_maple_tree.c | 55 +- tools/testing/radix-tree/maple.c | 308 ++++- 4 files changed, 1340 insertions(+), 1199 deletions(-) -- 2.47.3
When the maple copy node converges into a single entry, then certain operations can stop ascending the tree. This is used more later. Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com> --- lib/maple_tree.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 1e79dfbb024a0..f04989f8a115e 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -3493,6 +3493,16 @@ static inline bool cp_is_new_root(struct maple_copy *cp, struct ma_state *mas) return true; } +static inline bool cp_converged(struct maple_copy *cp, struct ma_state *mas, + struct ma_state *sib) +{ + if (cp->d_count != 1 || sib->end) + return false; + + cp->dst[0].node->parent = ma_parent_ptr(mas_mn(mas)->parent); + return true; +} + /* * spanning_ascend() - See if a spanning store operation has to keep walking up * the tree @@ -3575,10 +3585,8 @@ static inline bool rebalance_ascend(struct maple_copy *cp, if (cp_is_new_root(cp, mas)) return false; - if (cp->d_count == 1 && !sib->end) { - cp->dst[0].node->parent = ma_parent_ptr(mas_mn(mas)->parent); + if (cp_converged(cp, mas, sib)) return false; - } cp->height++; copy_tree_location(parent, mas); -- 2.47.3
{ "author": "\"Liam R. Howlett\" <Liam.Howlett@oracle.com>", "date": "Fri, 30 Jan 2026 15:59:30 -0500", "thread_id": "20260202103154.ad1aa05611c79d21b070a861@linux-foundation.org.mbox.gz" }
lkml
[PATCH v3 00/30] maple_tree: Replace big node with maple copy
The big node struct was created for simplicity of splitting, rebalancing, and spanning store operations by using a copy buffer to create the data necessary prior to breaking it up into 256B nodes. Certain operations were rather tricky due to the restriction of keeping NULL entries together and never at the end of a node (except the right-most node). The big node struct is incompatible with future features that are currently in development. Specifically different node types and different data type sizes for pivots. The big node struct was also a stack variable, which caused issues with certain configurations of kernel build. This series removes big node by introducing another node type which will never be written to the tree: maple_copy. The maple copy node operates more like a scatter/gather operation with a number of sources and destinations of allocated nodes. The sources are copied to the destinations, in turn, until the sources are exhausted. The destination is changed if it is filled or the split location is reached prior to the source data end. New data is inserted by using the maple copy node itself as a source with up to 3 slots and pivots. The data in the maple copy node is the data being written to the tree along with any fragment of the range(s) being overwritten. As with all nodes, the maple copy node is of size 256B. Using a node type allows for the copy operation to treat the new data stored in the maple copy node the same as any other source node. Analysis of the runtime shows no regression or benefit of removing the larger stack structure. The motivation is the ground work to use new node types and to help those with odd configurations that have had issues. The change was tested by myself using mm_tests on amd64 and by Suren on android (arm64). Limited testing on s390 qemu was also performed using stress-ng on the virtual memory, which should cover many corner cases. v1: https://lore.kernel.org/all/20260115193647.1695937-1-Liam.Howlett@oracle.com/ v2: https://lore.kernel.org/all/20260121164526.2093265-1-Liam.Howlett@oracle.com/ Changes since v2: - Whitespace fix in rebalance_data() - Added ma_init_slot() for cleaner casting during RCU_INIT_POINTER(). Thanks test robot & SK [1] - Fixed off-by-one in rebalance_data() which caused node overuse, reported by linux-next. Thanks Mark [2] - Added new patch to reproducer to test cases in userspace testing for the rebalance_data() off-by-one [1]. https://lore.kernel.org/all/20260122055516.69335-1-sj@kernel.org/ [2]. https://lore.kernel.org/all/bd1c3356-11a1-4d0b-bf58-47eb21bfd24d@sirena.org.uk/ Liam R. Howlett (30): maple_tree: Fix mas_dup_alloc() sparse warning maple_tree: Move mas_spanning_rebalance loop to function maple_tree: Extract use of big node from mas_wr_spanning_store() maple_tree: Remove unnecessary assignment of orig_l index maple_tree: inline mas_spanning_rebalance() into mas_wr_spanning_rebalance() maple_tree: Make ma_wr_states reliable for reuse in spanning store maple_tree: Remove l_wr_mas from mas_wr_spanning_rebalance maple_tree: Don't pass through height in mas_wr_spanning_store maple_tree: Move maple_subtree_state from mas_wr_spanning_store to mas_wr_spanning_rebalance maple_tree: Correct right ma_wr_state end pivot in mas_wr_spanning_store() maple_tree: Introduce maple_copy node and use it in mas_spanning_rebalance() maple_tree: Testing update for spanning store maple_tree: Inline mas_spanning_rebalance_loop() into mas_wr_spanning_rebalance() maple_tree: Change initial big node setup in mas_wr_spanning_rebalance() maple_tree: Introduce ma_leaf_max_gap() maple_tree: Add gap support, slot and pivot sizes for maple copy maple_tree: Start using maple copy node for destination maple_tree: inline mas_wr_spanning_rebalance() maple_tree: Remove unnecessary return statements maple_tree: Separate wr_split_store and wr_rebalance store type code path maple_tree: Add cp_is_new_root() helper maple_tree: Use maple copy node for mas_wr_rebalance() operation maple_tree: Add test for rebalance calculation off-by-one maple_tree: Add copy_tree_location() helper maple_tree: Add cp_converged() helper maple_tree: Use maple copy node for mas_wr_split() maple_tree: Remove maple big node and subtree structs maple_tree: Pass maple copy node to mas_wmb_replace() maple_tree: Don't pass end to mas_wr_append() maple_tree: Clean up mas_wr_node_store() include/linux/maple_tree.h | 42 + lib/maple_tree.c | 2134 +++++++++++++----------------- lib/test_maple_tree.c | 55 +- tools/testing/radix-tree/maple.c | 308 ++++- 4 files changed, 1340 insertions(+), 1199 deletions(-) -- 2.47.3
During the big node removal, an incorrect rebalance step went too far up the tree causing insufficient nodes. Test the faulty condition by recreating the scenario in the userspace testing. Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com> --- tools/testing/radix-tree/maple.c | 125 +++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) diff --git a/tools/testing/radix-tree/maple.c b/tools/testing/radix-tree/maple.c index dfd7099f0d8ef..5ea45d67556a8 100644 --- a/tools/testing/radix-tree/maple.c +++ b/tools/testing/radix-tree/maple.c @@ -35888,6 +35888,127 @@ static __init int build_full_tree(struct maple_tree *mt, unsigned int flags, return ret; } +static noinline void __init check_erase_rebalance(struct maple_tree *mt) +{ + unsigned long val; + void *enode; + int ret; + + MA_STATE(mas, mt, 0, 0); + + /* + * During removal of big node, the rebalance started going too high, + * which resulted in too many nodes trying to be used. + * + * Create a rebalance which results in an exactly full parent (0-9) that + * does not need to be rebalanced. This required two full levels, + * followed by an insufficient level which will be rebalanced into two + * nodes, finally leaves that need to be rebalanced into one node. + * + * The bugs tree: + * root 4 Label R + * /\ /\ + * 9 X F + * /\ /\ / + * 9 X E + * /\ /\ /\ + * 4 8 C D + * /\ /\ + * 6 9 A B + * ^ becomes 5 with the write. + * + * Below, the reconstruction leaves the root with 2 entries, the setup + * uses the letter labels above. + */ + + ret = build_full_tree(mt, MT_FLAGS_ALLOC_RANGE, 4); + MT_BUG_ON(mt, ret); + + /* Cheap expansion to 5 levels */ + mtree_store(mt, ULONG_MAX, xa_mk_value(0), GFP_KERNEL); + /* rcu is used to ensure node use */ + mt_set_in_rcu(mt); + mas_lock(&mas); + + /* Node A had 6 entries */ + mas_walk(&mas); + MAS_BUG_ON(&mas, mas_data_end(&mas) < 6); + while (mas_data_end(&mas) > 6) { + mas_erase(&mas); + mas_next(&mas, ULONG_MAX); + } + + /* Move to Node B */ + enode = (void*) mas.node; + while (mas.node == enode) + mas_next(&mas, ULONG_MAX); + + /* Node B had 9 entries */ + MAS_BUG_ON(&mas, mas_data_end(&mas) < 9); + while (mas_data_end(&mas) > 9) { + mas_erase(&mas); + mas_next(&mas, ULONG_MAX); + } + + /* Move to Node C */ + mas_ascend(&mas); + val = mas.max; + /* Adjust entries to be 4 */ + while (mas_data_end(&mas) > 4) { + mas_set(&mas, val); + mas_erase(&mas); + mas_prev(&mas, 0); + val = mas.index; + mas_ascend(&mas); + } + + /* Move to Node D */ + mas_ascend(&mas); + mas.offset = 1; + mas_descend(&mas); + val = mas.max; + /* Adjust entries to be 8 */ + while (mas_data_end(&mas) < 8) { + mas_set(&mas, val--); + mas_store_gfp(&mas, &mas, GFP_KERNEL); + mas_ascend(&mas); + } + + /* Move to Node E */ + mas_ascend(&mas); + val = mas.max; + MAS_BUG_ON(&mas, mas_data_end(&mas) > 9); + /* Adjust Node E to 9 entries */ + while (mas_data_end(&mas) < 9) { + mas_set(&mas, val--); + mas_store_gfp(&mas, &mas, GFP_KERNEL); + mas_ascend(&mas); + mas_ascend(&mas); + } + + /* Move to Node F */ + mas_ascend(&mas); + val = mas.max; + MAS_BUG_ON(&mas, mas_data_end(&mas) > 9); + /* Adjust Node F to 9 entries */ + while (mas_data_end(&mas) < 9) { + mas_set(&mas, val--); + mas_store_gfp(&mas, &mas, GFP_KERNEL); + mas_ascend(&mas); + mas_ascend(&mas); + mas_ascend(&mas); + } + + /* Test is set up, walk to first entry */ + mas_set(&mas, 0); + mas_next(&mas, ULONG_MAX); + /* overwrite the entry to cause a rebalance, which was 1 too few */ + mas_set_range(&mas, 0, mas.last); + mas_preallocate(&mas, NULL, GFP_KERNEL); + mas_store_prealloc(&mas, NULL); + mas_unlock(&mas); +} + static noinline void __init check_mtree_dup(struct maple_tree *mt) { DEFINE_MTREE(new); @@ -36249,6 +36370,10 @@ void farmer_tests(void) check_mtree_dup(&tree); mtree_destroy(&tree); + mt_init_flags(&tree, MT_FLAGS_ALLOC_RANGE); + check_erase_rebalance(&tree); + mtree_destroy(&tree); + /* RCU testing */ mt_init_flags(&tree, 0); check_erase_testset(&tree); -- 2.47.3
{ "author": "\"Liam R. Howlett\" <Liam.Howlett@oracle.com>", "date": "Fri, 30 Jan 2026 15:59:28 -0500", "thread_id": "20260202103154.ad1aa05611c79d21b070a861@linux-foundation.org.mbox.gz" }
lkml
[PATCH v3 00/30] maple_tree: Replace big node with maple copy
The big node struct was created for simplicity of splitting, rebalancing, and spanning store operations by using a copy buffer to create the data necessary prior to breaking it up into 256B nodes. Certain operations were rather tricky due to the restriction of keeping NULL entries together and never at the end of a node (except the right-most node). The big node struct is incompatible with future features that are currently in development. Specifically different node types and different data type sizes for pivots. The big node struct was also a stack variable, which caused issues with certain configurations of kernel build. This series removes big node by introducing another node type which will never be written to the tree: maple_copy. The maple copy node operates more like a scatter/gather operation with a number of sources and destinations of allocated nodes. The sources are copied to the destinations, in turn, until the sources are exhausted. The destination is changed if it is filled or the split location is reached prior to the source data end. New data is inserted by using the maple copy node itself as a source with up to 3 slots and pivots. The data in the maple copy node is the data being written to the tree along with any fragment of the range(s) being overwritten. As with all nodes, the maple copy node is of size 256B. Using a node type allows for the copy operation to treat the new data stored in the maple copy node the same as any other source node. Analysis of the runtime shows no regression or benefit of removing the larger stack structure. The motivation is the ground work to use new node types and to help those with odd configurations that have had issues. The change was tested by myself using mm_tests on amd64 and by Suren on android (arm64). Limited testing on s390 qemu was also performed using stress-ng on the virtual memory, which should cover many corner cases. v1: https://lore.kernel.org/all/20260115193647.1695937-1-Liam.Howlett@oracle.com/ v2: https://lore.kernel.org/all/20260121164526.2093265-1-Liam.Howlett@oracle.com/ Changes since v2: - Whitespace fix in rebalance_data() - Added ma_init_slot() for cleaner casting during RCU_INIT_POINTER(). Thanks test robot & SK [1] - Fixed off-by-one in rebalance_data() which caused node overuse, reported by linux-next. Thanks Mark [2] - Added new patch to reproducer to test cases in userspace testing for the rebalance_data() off-by-one [1]. https://lore.kernel.org/all/20260122055516.69335-1-sj@kernel.org/ [2]. https://lore.kernel.org/all/bd1c3356-11a1-4d0b-bf58-47eb21bfd24d@sirena.org.uk/ Liam R. Howlett (30): maple_tree: Fix mas_dup_alloc() sparse warning maple_tree: Move mas_spanning_rebalance loop to function maple_tree: Extract use of big node from mas_wr_spanning_store() maple_tree: Remove unnecessary assignment of orig_l index maple_tree: inline mas_spanning_rebalance() into mas_wr_spanning_rebalance() maple_tree: Make ma_wr_states reliable for reuse in spanning store maple_tree: Remove l_wr_mas from mas_wr_spanning_rebalance maple_tree: Don't pass through height in mas_wr_spanning_store maple_tree: Move maple_subtree_state from mas_wr_spanning_store to mas_wr_spanning_rebalance maple_tree: Correct right ma_wr_state end pivot in mas_wr_spanning_store() maple_tree: Introduce maple_copy node and use it in mas_spanning_rebalance() maple_tree: Testing update for spanning store maple_tree: Inline mas_spanning_rebalance_loop() into mas_wr_spanning_rebalance() maple_tree: Change initial big node setup in mas_wr_spanning_rebalance() maple_tree: Introduce ma_leaf_max_gap() maple_tree: Add gap support, slot and pivot sizes for maple copy maple_tree: Start using maple copy node for destination maple_tree: inline mas_wr_spanning_rebalance() maple_tree: Remove unnecessary return statements maple_tree: Separate wr_split_store and wr_rebalance store type code path maple_tree: Add cp_is_new_root() helper maple_tree: Use maple copy node for mas_wr_rebalance() operation maple_tree: Add test for rebalance calculation off-by-one maple_tree: Add copy_tree_location() helper maple_tree: Add cp_converged() helper maple_tree: Use maple copy node for mas_wr_split() maple_tree: Remove maple big node and subtree structs maple_tree: Pass maple copy node to mas_wmb_replace() maple_tree: Don't pass end to mas_wr_append() maple_tree: Clean up mas_wr_node_store() include/linux/maple_tree.h | 42 + lib/maple_tree.c | 2134 +++++++++++++----------------- lib/test_maple_tree.c | 55 +- tools/testing/radix-tree/maple.c | 308 ++++- 4 files changed, 1340 insertions(+), 1199 deletions(-) -- 2.47.3
Instead of copying the data into the big node and finding out that the data may need to be moved or appended to, calculate the data space up front (in the maple copy node) and set up another source for the copy. The additional copy source is tracked in the maple state sib (short for sibling), and is put into the maple write states for future operations after the data is in the big node. To facilitate the newly moved node, some initial setup of the maple subtree state are relocated after the potential shift caused by the new way of rebalancing against a sibling. Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com> --- include/linux/maple_tree.h | 1 + lib/maple_tree.c | 175 ++++++++++++++++++++++++++++++++----- 2 files changed, 153 insertions(+), 23 deletions(-) diff --git a/include/linux/maple_tree.h b/include/linux/maple_tree.h index 9bc7fa89bc2ee..e99e16ac1c6da 100644 --- a/include/linux/maple_tree.h +++ b/include/linux/maple_tree.h @@ -177,6 +177,7 @@ struct maple_copy { /*Avoid passing these around */ unsigned char s_count; + unsigned char data; }; /** diff --git a/lib/maple_tree.c b/lib/maple_tree.c index a9b7e398c7dbd..0d6f810a4a1fc 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -1304,6 +1304,18 @@ static inline unsigned char mas_data_end(struct ma_state *mas) return mt_pivots[type]; } +static inline +void wr_mas_setup(struct ma_wr_state *wr_mas, struct ma_state *mas) +{ + wr_mas->node = mas_mn(mas); + wr_mas->type = mte_node_type(mas->node); + wr_mas->pivots = ma_pivots(wr_mas->node, wr_mas->type); + wr_mas->slots = ma_slots(wr_mas->node, wr_mas->type); + wr_mas->r_min = mas_safe_min(mas, wr_mas->pivots, mas->offset); + wr_mas->r_max = mas_safe_pivot(mas, wr_mas->pivots, mas->offset, + wr_mas->type); +} + /* * mas_leaf_max_gap() - Returns the largest gap in a leaf node * @mas: the maple state @@ -2258,6 +2270,44 @@ static inline void mte_mid_split_check(struct maple_enode **l, *split = mid_split; } +static inline +void spanning_sib(struct ma_wr_state *l_wr_mas, + struct ma_wr_state *r_wr_mas, struct ma_state *nneighbour) +{ + struct ma_state l_tmp = *l_wr_mas->mas; + struct ma_state r_tmp = *r_wr_mas->mas; + unsigned char depth = 0; + + do { + mas_ascend(&r_tmp); + mas_ascend(&l_tmp); + depth++; + if (r_tmp.offset < mas_data_end(&r_tmp)) { + r_tmp.offset++; + mas_descend(&r_tmp); + r_tmp.offset = 0; + while (--depth) + mas_descend(&r_tmp); + + r_tmp.end = mas_data_end(&r_tmp); + *nneighbour = r_tmp; + return; + } else if (l_tmp.offset) { + l_tmp.offset--; + do { + mas_descend(&l_tmp); + l_tmp.offset = mas_data_end(&l_tmp); + } while (--depth); + + l_tmp.end = l_tmp.offset; + *nneighbour = l_tmp; + return; + } + } while (!mte_is_root(r_tmp.node)); + + WARN_ON_ONCE(1); +} + /* * mast_set_split_parents() - Helper function to set three nodes parents. Slot * is taken from @mast->l. @@ -2642,6 +2692,49 @@ static inline void cp_leaf_init(struct maple_copy *cp, cp->end = end; } +/* + * cp_data_calc() - Calculate the size of the data (1 indexed). + * @cp: The maple copy struct with the new data populated. + * @l_wr_mas: The maple write state containing the data to the left of the write + * @r_wr_mas: The maple write state containing the data to the right of the + * write + * + * cp->data is a size (not indexed by 0). + */ +static inline void cp_data_calc(struct maple_copy *cp, + struct ma_wr_state *l_wr_mas, struct ma_wr_state *r_wr_mas) +{ + + /* Add 1 every time for the 0th element */ + cp->data = l_wr_mas->mas->offset; + /* Add the new data and any partial overwrites */ + cp->data += cp->end + 1; + /* Data from right (offset + 1 to end), +1 for zero */ + cp->data += r_wr_mas->mas->end - r_wr_mas->offset_end; +} + +static inline void append_mas_cp(struct maple_copy *cp, + struct ma_state *mas, unsigned char start, unsigned char end) +{ + struct maple_node *node; + enum maple_type mt; + unsigned char count; + + count = cp->s_count; + node = mas_mn(mas); + mt = mte_node_type(mas->node); + cp->src[count].node = node; + cp->src[count].mt = mt; + if (mas->end <= end) + cp->src[count].max = mas->max; + else + cp->src[count].max = ma_pivots(node, mt)[end]; + + cp->src[count].start = start; + cp->src[count].end = end; + cp->s_count++; +} + static inline void append_wr_mas_cp(struct maple_copy *cp, struct ma_wr_state *wr_mas, unsigned char start, unsigned char end) { @@ -2670,6 +2763,42 @@ static inline void init_cp_src(struct maple_copy *cp) cp->s_count++; } +/* + * multi_src_setup() - Set the @cp node up with multiple sources to copy from. + * @cp: The maple copy node + * @l_wr_mas: The left write maple state + * @r_wr_mas: The right write maple state + * @sib: The sibling maple state + * + * Note: @sib->end == 0 indicates no sibling will be used. + */ +static inline +void multi_src_setup(struct maple_copy *cp, struct ma_wr_state *l_wr_mas, + struct ma_wr_state *r_wr_mas, struct ma_state *sib) +{ + cp->s_count = 0; + if (sib->end && sib->max < l_wr_mas->mas->min) + append_mas_cp(cp, sib, 0, sib->end); + + /* Copy left 0 - offset */ + if (l_wr_mas->mas->offset) { + unsigned char off = l_wr_mas->mas->offset - 1; + + append_wr_mas_cp(cp, l_wr_mas, 0, off); + cp->src[cp->s_count - 1].max = cp->min - 1; + } + + init_cp_src(cp); + + /* Copy right either from offset or offset + 1 pending on r_max */ + if (r_wr_mas->mas->end != r_wr_mas->offset_end) + append_wr_mas_cp(cp, r_wr_mas, r_wr_mas->offset_end + 1, + r_wr_mas->mas->end); + + if (sib->end && sib->min > r_wr_mas->mas->max) + append_mas_cp(cp, sib, 0, sib->end); +} + static inline void cp_data_write(struct maple_copy *cp, struct maple_big_node *b_node) { @@ -2873,36 +3002,42 @@ static noinline void mas_wr_spanning_rebalance(struct ma_state *mas, struct maple_big_node b_node; struct maple_copy cp; unsigned char height; + struct ma_state sib; MA_STATE(l_mas, mas->tree, mas->index, mas->index); MA_STATE(r_mas, mas->tree, mas->index, mas->last); MA_STATE(m_mas, mas->tree, mas->index, mas->index); MA_STATE(mast_l_mas, NULL, 0, 0); - mast_l_mas = *mas; - mast.orig_l = &mast_l_mas; - mast.orig_r = r_wr_mas->mas; memset(&b_node, 0, sizeof(struct maple_big_node)); + mast_l_mas = *mas; cp.s_count = 0; cp_leaf_init(&cp, mas, l_wr_mas, r_wr_mas); - /* Copy left 0 - offset */ - if (l_wr_mas->mas->offset) { - unsigned char off = l_wr_mas->mas->offset - 1; - - append_wr_mas_cp(&cp, l_wr_mas, 0, off); - cp.src[cp.s_count - 1].max = cp.min - 1; + cp_data_calc(&cp, l_wr_mas, r_wr_mas); + if (((l_wr_mas->mas->min != 0) || (r_wr_mas->mas->max != ULONG_MAX)) && + (cp.data <= mt_min_slots[l_wr_mas->type])) { + spanning_sib(l_wr_mas, r_wr_mas, &sib); + cp.data += sib.end + 1; + } else { + sib.end = 0; } - init_cp_src(&cp); - - /* Copy right from offset_end + 1 to end */ - if (r_wr_mas->mas->end != r_wr_mas->offset_end) - append_wr_mas_cp(&cp, r_wr_mas, r_wr_mas->offset_end + 1, - r_wr_mas->mas->end); - - + multi_src_setup(&cp, l_wr_mas, r_wr_mas, &sib); b_node.type = l_wr_mas->type; cp_data_write(&cp, &b_node); + if (sib.end) { + if (sib.max < l_wr_mas->mas->min) { + *l_wr_mas->mas = sib; + wr_mas_setup(l_wr_mas, &sib); + mast_l_mas = sib; + } else { + *r_wr_mas->mas = sib; + wr_mas_setup(r_wr_mas, &sib); + } + } + + mast.orig_l = &mast_l_mas; + mast.orig_r = r_wr_mas->mas; /* Stop spanning searches by searching for just index. */ mast.orig_l->last = mas->index; @@ -2917,12 +3052,6 @@ static noinline void mas_wr_spanning_rebalance(struct ma_state *mas, mast.m = &m_mas; mast.r = &r_mas; l_mas.status = r_mas.status = m_mas.status = ma_none; - - /* Check if this is not root and has sufficient data. */ - if (((mast.orig_l->min != 0) || (mast.orig_r->max != ULONG_MAX)) && - unlikely(mast.bn->b_end <= mt_min_slots[mast.bn->type])) - mast_spanning_rebalance(&mast); - height = mas_mt_height(mas) + 1; /* -- 2.47.3
{ "author": "\"Liam R. Howlett\" <Liam.Howlett@oracle.com>", "date": "Fri, 30 Jan 2026 15:59:19 -0500", "thread_id": "20260202103154.ad1aa05611c79d21b070a861@linux-foundation.org.mbox.gz" }
lkml
[PATCH v3 00/30] maple_tree: Replace big node with maple copy
The big node struct was created for simplicity of splitting, rebalancing, and spanning store operations by using a copy buffer to create the data necessary prior to breaking it up into 256B nodes. Certain operations were rather tricky due to the restriction of keeping NULL entries together and never at the end of a node (except the right-most node). The big node struct is incompatible with future features that are currently in development. Specifically different node types and different data type sizes for pivots. The big node struct was also a stack variable, which caused issues with certain configurations of kernel build. This series removes big node by introducing another node type which will never be written to the tree: maple_copy. The maple copy node operates more like a scatter/gather operation with a number of sources and destinations of allocated nodes. The sources are copied to the destinations, in turn, until the sources are exhausted. The destination is changed if it is filled or the split location is reached prior to the source data end. New data is inserted by using the maple copy node itself as a source with up to 3 slots and pivots. The data in the maple copy node is the data being written to the tree along with any fragment of the range(s) being overwritten. As with all nodes, the maple copy node is of size 256B. Using a node type allows for the copy operation to treat the new data stored in the maple copy node the same as any other source node. Analysis of the runtime shows no regression or benefit of removing the larger stack structure. The motivation is the ground work to use new node types and to help those with odd configurations that have had issues. The change was tested by myself using mm_tests on amd64 and by Suren on android (arm64). Limited testing on s390 qemu was also performed using stress-ng on the virtual memory, which should cover many corner cases. v1: https://lore.kernel.org/all/20260115193647.1695937-1-Liam.Howlett@oracle.com/ v2: https://lore.kernel.org/all/20260121164526.2093265-1-Liam.Howlett@oracle.com/ Changes since v2: - Whitespace fix in rebalance_data() - Added ma_init_slot() for cleaner casting during RCU_INIT_POINTER(). Thanks test robot & SK [1] - Fixed off-by-one in rebalance_data() which caused node overuse, reported by linux-next. Thanks Mark [2] - Added new patch to reproducer to test cases in userspace testing for the rebalance_data() off-by-one [1]. https://lore.kernel.org/all/20260122055516.69335-1-sj@kernel.org/ [2]. https://lore.kernel.org/all/bd1c3356-11a1-4d0b-bf58-47eb21bfd24d@sirena.org.uk/ Liam R. Howlett (30): maple_tree: Fix mas_dup_alloc() sparse warning maple_tree: Move mas_spanning_rebalance loop to function maple_tree: Extract use of big node from mas_wr_spanning_store() maple_tree: Remove unnecessary assignment of orig_l index maple_tree: inline mas_spanning_rebalance() into mas_wr_spanning_rebalance() maple_tree: Make ma_wr_states reliable for reuse in spanning store maple_tree: Remove l_wr_mas from mas_wr_spanning_rebalance maple_tree: Don't pass through height in mas_wr_spanning_store maple_tree: Move maple_subtree_state from mas_wr_spanning_store to mas_wr_spanning_rebalance maple_tree: Correct right ma_wr_state end pivot in mas_wr_spanning_store() maple_tree: Introduce maple_copy node and use it in mas_spanning_rebalance() maple_tree: Testing update for spanning store maple_tree: Inline mas_spanning_rebalance_loop() into mas_wr_spanning_rebalance() maple_tree: Change initial big node setup in mas_wr_spanning_rebalance() maple_tree: Introduce ma_leaf_max_gap() maple_tree: Add gap support, slot and pivot sizes for maple copy maple_tree: Start using maple copy node for destination maple_tree: inline mas_wr_spanning_rebalance() maple_tree: Remove unnecessary return statements maple_tree: Separate wr_split_store and wr_rebalance store type code path maple_tree: Add cp_is_new_root() helper maple_tree: Use maple copy node for mas_wr_rebalance() operation maple_tree: Add test for rebalance calculation off-by-one maple_tree: Add copy_tree_location() helper maple_tree: Add cp_converged() helper maple_tree: Use maple copy node for mas_wr_split() maple_tree: Remove maple big node and subtree structs maple_tree: Pass maple copy node to mas_wmb_replace() maple_tree: Don't pass end to mas_wr_append() maple_tree: Clean up mas_wr_node_store() include/linux/maple_tree.h | 42 + lib/maple_tree.c | 2134 +++++++++++++----------------- lib/test_maple_tree.c | 55 +- tools/testing/radix-tree/maple.c | 308 ++++- 4 files changed, 1340 insertions(+), 1199 deletions(-) -- 2.47.3
Spanning store had some corner cases which showed up during rcu stress testing. Add explicit tests for those cases. At the same time add some locking for easier visibility of the rcu stress testing. Only a single dump of the tree will happen on the first detected issue instead of flooding the console with output. Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com> --- tools/testing/radix-tree/maple.c | 172 +++++++++++++++++++++++++++++-- 1 file changed, 163 insertions(+), 9 deletions(-) diff --git a/tools/testing/radix-tree/maple.c b/tools/testing/radix-tree/maple.c index 5c1b18e3ed210..85fb5616c133c 100644 --- a/tools/testing/radix-tree/maple.c +++ b/tools/testing/radix-tree/maple.c @@ -38,6 +38,7 @@ struct rcu_test_struct2 { unsigned long index[RCU_RANGE_COUNT]; unsigned long last[RCU_RANGE_COUNT]; + pthread_mutex_t dump; }; struct rcu_test_struct3 { @@ -33997,8 +33998,25 @@ static void *rcu_reader_fwd(void *ptr) } } - RCU_MT_BUG_ON(test, mas.index != r_start); - RCU_MT_BUG_ON(test, mas.last != r_end); + if (mas.index != r_start) { + if (pthread_mutex_trylock(&test->dump) != 0) { + rcu_read_unlock(); + goto quit; + } + printk("start is wrong: %lx (%lu) vs expected %lx (%lu)\n", + mas.index, mas.index, r_start, r_start); + RCU_MT_BUG_ON(test, mas.index != r_start); + } + + if (mas.last != r_end) { + if (pthread_mutex_trylock(&test->dump) != 0) { + rcu_read_unlock(); + goto quit; + } + printk("last is wrong: %lx (%lu) vs expected %lx (%lu)\n", + mas.last, mas.last, r_end, r_end); + RCU_MT_BUG_ON(test, mas.last != r_end); + } if (i == reader->flip) { alt = xa_mk_value(index + i + RCU_RANGE_COUNT); @@ -34014,7 +34032,8 @@ static void *rcu_reader_fwd(void *ptr) else if (entry == alt) toggled = true; else { - printk("!!%lu-%lu -> %p not %p or %p\n", mas.index, mas.last, entry, expected, alt); + printk("!!%lu-%lu -> %p not %p or %p\n", + mas.index, mas.last, entry, expected, alt); RCU_MT_BUG_ON(test, 1); } @@ -34047,9 +34066,11 @@ static void *rcu_reader_fwd(void *ptr) usleep(test->pause); } +quit: rcu_unregister_thread(); return NULL; } + /* RCU reader in decreasing index */ static void *rcu_reader_rev(void *ptr) { @@ -34119,13 +34140,17 @@ static void *rcu_reader_rev(void *ptr) line = __LINE__; if (mas.index != r_start) { + if (pthread_mutex_trylock(&test->dump) != 0) { + rcu_read_unlock(); + goto quit; + } + alt = xa_mk_value(index + i * 2 + 1 + RCU_RANGE_COUNT); mt_dump(test->mt, mt_dump_dec); - printk("Error: %lu-%lu %p != %lu-%lu %p %p line %d i %d\n", - mas.index, mas.last, entry, - r_start, r_end, expected, alt, - line, i); + printk("Error: %p %lu-%lu %p != %lu-%lu %p %p line %d i %d\n", + mas.node, mas.index, mas.last, entry, + r_start, r_end, expected, alt, line, i); } RCU_MT_BUG_ON(test, mas.index != r_start); RCU_MT_BUG_ON(test, mas.last != r_end); @@ -34180,6 +34205,7 @@ static void *rcu_reader_rev(void *ptr) usleep(test->pause); } +quit: rcu_unregister_thread(); return NULL; } @@ -34329,6 +34355,7 @@ static void rcu_stress(struct maple_tree *mt, bool forward) test.seen_modified = 0; test.thread_count = 0; test.start = test.stop = false; + pthread_mutex_init(&test.dump, NULL); seed = time(NULL); srand(seed); for (i = 0; i < RCU_RANGE_COUNT; i++) { @@ -34414,6 +34441,7 @@ struct rcu_test_struct { unsigned long removed; /* The index of the removed entry */ unsigned long added; /* The index of the removed entry */ unsigned long toggle; /* The index of the removed entry */ + pthread_mutex_t dump; }; static inline @@ -34506,7 +34534,9 @@ static void *rcu_loop(void *ptr) /* Out of the interesting range */ if (mas.index < test->index || mas.index > test->last) { if (entry != expected) { - printk("%lx - %lx = %p not %p\n", + if (pthread_mutex_trylock(&test->dump) != 0) + break; + printk("\nERROR: %lx - %lx = %p not %p\n", mas.index, mas.last, entry, expected); } MT_BUG_ON(test->mt, entry != expected); @@ -34854,6 +34884,7 @@ static noinline void __init check_rcu_threaded(struct maple_tree *mt) vals.range_end = ULONG_MAX; vals.seen_entry2 = 0; vals.seen_entry3 = 0; + pthread_mutex_init(&vals.dump, NULL); run_check_rcu(mt, &vals); mtree_destroy(mt); @@ -35250,6 +35281,8 @@ static noinline void __init check_spanning_write(struct maple_tree *mt) { unsigned long i, max = 5000; MA_STATE(mas, mt, 1200, 2380); + struct maple_enode *enode; + struct maple_node *pnode; for (i = 0; i <= max; i++) mtree_test_store_range(mt, i * 10, i * 10 + 5, &i); @@ -35410,6 +35443,128 @@ static noinline void __init check_spanning_write(struct maple_tree *mt) mas_set_range(&mas, 76, 875); mas_store_gfp(&mas, NULL, GFP_KERNEL); mtree_unlock(mt); + mtree_destroy(mt); + + mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE); + for (i = 0; i <= max; i++) + mtree_test_store_range(mt, i * 10, i * 10 + 5, &i); + + if (MAPLE_32BIT) + i = 49750; /* 0xC25B */ + else + i = 49835; /* 0xC2AB */ + + mtree_lock(mt); + /* Store a null across a boundary that ends in a null */ + mas_set(&mas, i); /* 0xC2AB */ + MT_BUG_ON(mt, mas_walk(&mas) == NULL); + MT_BUG_ON(mt, mas.end != mas.offset); + MT_BUG_ON(mt, mas_next_range(&mas, ULONG_MAX) != NULL); + mas_set_range(&mas, i, mas.last - 1); + mas_store_gfp(&mas, NULL, GFP_KERNEL); + mt_validate(mt); + + /* Store a null across a boundary that starts and ends in a null */ + mas_set(&mas, 49849); + MT_BUG_ON(mt, mas_walk(&mas) != NULL); + MT_BUG_ON(mt, mas.index != 49846); + mas_set(&mas, 49876); + MT_BUG_ON(mt, mas_walk(&mas) != NULL); + MT_BUG_ON(mt, mas.last != 49879); + mas_set_range(&mas, 49849, 49876); + mas_store_gfp(&mas, NULL, GFP_KERNEL); + /* Results in 49846-49879: (nil) */ + MT_BUG_ON(mt, mas.index != 49846); + MT_BUG_ON(mt, mas.last != 49879); + mt_validate(mt); + + /* Store a null across a boundary that starts and ends next to nulls */ + mas_set(&mas, 49800); + MT_BUG_ON(mt, mas_walk(&mas) == NULL); + MT_BUG_ON(mt, mas.index != 49800); + mas_set(&mas, 49815); + MT_BUG_ON(mt, mas_walk(&mas) == NULL); + MT_BUG_ON(mt, mas.last != 49815); + mas_set_range(&mas, 49800, 49815); + mas_store_gfp(&mas, NULL, GFP_KERNEL); + /* Results in 49846-49879: (nil) */ + MT_BUG_ON(mt, mas.index != 49796); + MT_BUG_ON(mt, mas.last != 49819); + mt_validate(mt); + + /* Store a value across a boundary that starts and ends in a null */ + mas_set(&mas, 49907); + MT_BUG_ON(mt, mas_walk(&mas) != NULL); + MT_BUG_ON(mt, mas.index != 49906); + mas_set(&mas, 49928); + MT_BUG_ON(mt, mas_walk(&mas) != NULL); + MT_BUG_ON(mt, mas.last != 49929); + mas_set_range(&mas, 49907, 49928); + mas_store_gfp(&mas, check_spanning_write, GFP_KERNEL); + MT_BUG_ON(mt, mas.index != 49907); + MT_BUG_ON(mt, mas.last != 49928); + mt_validate(mt); + + /* Store a value across a node boundary that causes a 3 way split */ + + if (MAPLE_32BIT) + i = 49590; /* 0xc1b6 */ + else + i = 49670; /* 0xC206 */ + + mas_set(&mas, i); + MT_BUG_ON(mt, mas_walk(&mas) == NULL); + MT_BUG_ON(mt, mas.index != i); + MT_BUG_ON(mt, mas.end != mt_slot_count(mas.node) - 1); + enode = mas.node; + MT_BUG_ON(mt, mas_next_range(&mas, ULONG_MAX) != NULL); + MT_BUG_ON(mt, mas.index != i + 6); + MT_BUG_ON(mt, mas.end != mt_slot_count(mas.node) - 1); + MT_BUG_ON(mt, enode == mas.node); + mas_set_range(&mas, i + 2, i + 7); + mas_store_gfp(&mas, check_spanning_write, GFP_KERNEL); + MT_BUG_ON(mt, mas.index != i + 2); + MT_BUG_ON(mt, mas.last != i + 7); + mt_validate(mt); + + /* 2 levels of basically the same testing */ + + if (MAPLE_32BIT) { + /* 32bit needs a bit more work to fill the nodes. + * The two parent nodes need to be filled (they have one space + * vacant) without causing a split at the store locations (or + * the siblings). + */ + i = 44426; + mas_set(&mas, i); + mas_store_gfp(&mas, check_spanning_write, GFP_KERNEL); + i = 45126; + mas_set(&mas, i); + mas_store_gfp(&mas, check_spanning_write, GFP_KERNEL); + i = 44790; + } else { + /* 48950 - 48955 => ptr, 48956 - 48959 => NULL */ + i = 48950; + + } + mas_set(&mas, i); + MT_BUG_ON(mt, mas_walk(&mas) == NULL); + MT_BUG_ON(mt, mas.index != i); + MT_BUG_ON(mt, mas.end != mt_slot_count(mas.node) - 1); + enode = mas.node; + pnode = mte_parent(enode); + MT_BUG_ON(mt, mas_next_range(&mas, ULONG_MAX) != NULL); + MT_BUG_ON(mt, mas.index != i + 6); + MT_BUG_ON(mt, mas.end != mt_slot_count(mas.node) - 1); + MT_BUG_ON(mt, enode == mas.node); + MT_BUG_ON(mt, pnode == mte_parent(mas.node)); + mas_set_range(&mas, i + 2, i + 8); + mas_store_gfp(&mas, NULL, GFP_KERNEL); + mt_validate(mt); + + mtree_unlock(mt); + mtree_destroy(mt); + rcu_barrier(); } /* End of spanning write testing */ @@ -36029,7 +36184,6 @@ static inline int check_vma_modification(struct maple_tree *mt) return 0; } - void farmer_tests(void) { struct maple_node *node; -- 2.47.3
{ "author": "\"Liam R. Howlett\" <Liam.Howlett@oracle.com>", "date": "Fri, 30 Jan 2026 15:59:17 -0500", "thread_id": "20260202103154.ad1aa05611c79d21b070a861@linux-foundation.org.mbox.gz" }
lkml
[PATCH v3 00/30] maple_tree: Replace big node with maple copy
The big node struct was created for simplicity of splitting, rebalancing, and spanning store operations by using a copy buffer to create the data necessary prior to breaking it up into 256B nodes. Certain operations were rather tricky due to the restriction of keeping NULL entries together and never at the end of a node (except the right-most node). The big node struct is incompatible with future features that are currently in development. Specifically different node types and different data type sizes for pivots. The big node struct was also a stack variable, which caused issues with certain configurations of kernel build. This series removes big node by introducing another node type which will never be written to the tree: maple_copy. The maple copy node operates more like a scatter/gather operation with a number of sources and destinations of allocated nodes. The sources are copied to the destinations, in turn, until the sources are exhausted. The destination is changed if it is filled or the split location is reached prior to the source data end. New data is inserted by using the maple copy node itself as a source with up to 3 slots and pivots. The data in the maple copy node is the data being written to the tree along with any fragment of the range(s) being overwritten. As with all nodes, the maple copy node is of size 256B. Using a node type allows for the copy operation to treat the new data stored in the maple copy node the same as any other source node. Analysis of the runtime shows no regression or benefit of removing the larger stack structure. The motivation is the ground work to use new node types and to help those with odd configurations that have had issues. The change was tested by myself using mm_tests on amd64 and by Suren on android (arm64). Limited testing on s390 qemu was also performed using stress-ng on the virtual memory, which should cover many corner cases. v1: https://lore.kernel.org/all/20260115193647.1695937-1-Liam.Howlett@oracle.com/ v2: https://lore.kernel.org/all/20260121164526.2093265-1-Liam.Howlett@oracle.com/ Changes since v2: - Whitespace fix in rebalance_data() - Added ma_init_slot() for cleaner casting during RCU_INIT_POINTER(). Thanks test robot & SK [1] - Fixed off-by-one in rebalance_data() which caused node overuse, reported by linux-next. Thanks Mark [2] - Added new patch to reproducer to test cases in userspace testing for the rebalance_data() off-by-one [1]. https://lore.kernel.org/all/20260122055516.69335-1-sj@kernel.org/ [2]. https://lore.kernel.org/all/bd1c3356-11a1-4d0b-bf58-47eb21bfd24d@sirena.org.uk/ Liam R. Howlett (30): maple_tree: Fix mas_dup_alloc() sparse warning maple_tree: Move mas_spanning_rebalance loop to function maple_tree: Extract use of big node from mas_wr_spanning_store() maple_tree: Remove unnecessary assignment of orig_l index maple_tree: inline mas_spanning_rebalance() into mas_wr_spanning_rebalance() maple_tree: Make ma_wr_states reliable for reuse in spanning store maple_tree: Remove l_wr_mas from mas_wr_spanning_rebalance maple_tree: Don't pass through height in mas_wr_spanning_store maple_tree: Move maple_subtree_state from mas_wr_spanning_store to mas_wr_spanning_rebalance maple_tree: Correct right ma_wr_state end pivot in mas_wr_spanning_store() maple_tree: Introduce maple_copy node and use it in mas_spanning_rebalance() maple_tree: Testing update for spanning store maple_tree: Inline mas_spanning_rebalance_loop() into mas_wr_spanning_rebalance() maple_tree: Change initial big node setup in mas_wr_spanning_rebalance() maple_tree: Introduce ma_leaf_max_gap() maple_tree: Add gap support, slot and pivot sizes for maple copy maple_tree: Start using maple copy node for destination maple_tree: inline mas_wr_spanning_rebalance() maple_tree: Remove unnecessary return statements maple_tree: Separate wr_split_store and wr_rebalance store type code path maple_tree: Add cp_is_new_root() helper maple_tree: Use maple copy node for mas_wr_rebalance() operation maple_tree: Add test for rebalance calculation off-by-one maple_tree: Add copy_tree_location() helper maple_tree: Add cp_converged() helper maple_tree: Use maple copy node for mas_wr_split() maple_tree: Remove maple big node and subtree structs maple_tree: Pass maple copy node to mas_wmb_replace() maple_tree: Don't pass end to mas_wr_append() maple_tree: Clean up mas_wr_node_store() include/linux/maple_tree.h | 42 + lib/maple_tree.c | 2134 +++++++++++++----------------- lib/test_maple_tree.c | 55 +- tools/testing/radix-tree/maple.c | 308 ++++- 4 files changed, 1340 insertions(+), 1199 deletions(-) -- 2.47.3
mas_wmb_replace() is called in three places with the same setup, move the setup into the function itself. The function needs to be relocated as it calls mtree_range_walk(). Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com> --- lib/maple_tree.c | 60 ++++++++++++++++++++---------------------------- 1 file changed, 25 insertions(+), 35 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 1cfbed6fac9f5..064357a44906e 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -1900,26 +1900,6 @@ static inline void mas_topiary_replace(struct ma_state *mas, mas_mat_destroy(mas, &subtrees); } -/* - * mas_wmb_replace() - Write memory barrier and replace - * @mas: The maple state - * @old_enode: The old maple encoded node that is being replaced. - * @new_height: The new height of the tree as a result of the operation - * - * Updates gap as necessary. - */ -static inline void mas_wmb_replace(struct ma_state *mas, - struct maple_enode *old_enode, unsigned char new_height) -{ - /* Insert the new data in the tree */ - mas_topiary_replace(mas, old_enode, new_height); - - if (mte_is_leaf(mas->node)) - return; - - mas_update_gap(mas); -} - /* * node_copy() - Copy from one node to another. * @@ -2086,6 +2066,28 @@ static inline void *mtree_range_walk(struct ma_state *mas) return NULL; } +/* + * mas_wmb_replace() - Write memory barrier and replace + * @mas: The maple state + * @cp: The maple copy node + * + * Updates gap as necessary. + */ +static inline void mas_wmb_replace(struct ma_state *mas, struct maple_copy *cp) +{ + struct maple_enode *old_enode; + + old_enode = mas->node; + mas->node = mt_slot_locked(mas->tree, cp->slot, 0); + /* Insert the new data in the tree */ + mas_topiary_replace(mas, old_enode, cp->height); + if (!mte_is_leaf(mas->node)) + mas_update_gap(mas); + + mtree_range_walk(mas); +} + + /* * cp_leaf_init() - Initialize a maple_copy node for the leaf level of a * spanning store @@ -3044,7 +3046,6 @@ static inline void mas_new_root(struct ma_state *mas, void *entry) */ static void mas_wr_spanning_store(struct ma_wr_state *wr_mas) { - struct maple_enode *old_enode; struct maple_copy cp; struct ma_state *mas; struct ma_state sib; @@ -3112,10 +3113,7 @@ static void mas_wr_spanning_store(struct ma_wr_state *wr_mas) cp_data_write(&cp, mas); } while (spanning_ascend(&cp, mas, wr_mas, &r_wr_mas, &sib)); - old_enode = mas->node; - mas->node = mt_slot_locked(mas->tree, cp.slot, 0); - mas_wmb_replace(mas, old_enode, cp.height); - mtree_range_walk(mas); + mas_wmb_replace(mas, &cp); } /* @@ -3433,7 +3431,6 @@ static inline void split_data(struct maple_copy *cp, */ static void mas_wr_split(struct ma_wr_state *wr_mas) { - struct maple_enode *old_enode; struct ma_state parent; struct ma_state *mas; struct maple_copy cp; @@ -3454,10 +3451,7 @@ static void mas_wr_split(struct ma_wr_state *wr_mas) cp_data_write(&cp, mas); } while (split_ascend(&cp, wr_mas, &sib, &parent)); - old_enode = mas->node; - mas->node = mt_slot_locked(mas->tree, cp.slot, 0); - mas_wmb_replace(mas, old_enode, cp.height); - mtree_range_walk(mas); + mas_wmb_replace(mas, &cp); } /* @@ -3470,7 +3464,6 @@ static void mas_wr_split(struct ma_wr_state *wr_mas) */ static void mas_wr_rebalance(struct ma_wr_state *wr_mas) { - struct maple_enode *old_enode; struct ma_state parent; struct ma_state *mas; struct maple_copy cp; @@ -3501,10 +3494,7 @@ static void mas_wr_rebalance(struct ma_wr_state *wr_mas) cp_data_write(&cp, mas); } while (rebalance_ascend(&cp, wr_mas, &sib, &parent)); - old_enode = mas->node; - mas->node = mt_slot_locked(mas->tree, cp.slot, 0); - mas_wmb_replace(mas, old_enode, cp.height); - mtree_range_walk(mas); + mas_wmb_replace(mas, &cp); } /* -- 2.47.3
{ "author": "\"Liam R. Howlett\" <Liam.Howlett@oracle.com>", "date": "Fri, 30 Jan 2026 15:59:33 -0500", "thread_id": "20260202103154.ad1aa05611c79d21b070a861@linux-foundation.org.mbox.gz" }
lkml
[PATCH v3 00/30] maple_tree: Replace big node with maple copy
The big node struct was created for simplicity of splitting, rebalancing, and spanning store operations by using a copy buffer to create the data necessary prior to breaking it up into 256B nodes. Certain operations were rather tricky due to the restriction of keeping NULL entries together and never at the end of a node (except the right-most node). The big node struct is incompatible with future features that are currently in development. Specifically different node types and different data type sizes for pivots. The big node struct was also a stack variable, which caused issues with certain configurations of kernel build. This series removes big node by introducing another node type which will never be written to the tree: maple_copy. The maple copy node operates more like a scatter/gather operation with a number of sources and destinations of allocated nodes. The sources are copied to the destinations, in turn, until the sources are exhausted. The destination is changed if it is filled or the split location is reached prior to the source data end. New data is inserted by using the maple copy node itself as a source with up to 3 slots and pivots. The data in the maple copy node is the data being written to the tree along with any fragment of the range(s) being overwritten. As with all nodes, the maple copy node is of size 256B. Using a node type allows for the copy operation to treat the new data stored in the maple copy node the same as any other source node. Analysis of the runtime shows no regression or benefit of removing the larger stack structure. The motivation is the ground work to use new node types and to help those with odd configurations that have had issues. The change was tested by myself using mm_tests on amd64 and by Suren on android (arm64). Limited testing on s390 qemu was also performed using stress-ng on the virtual memory, which should cover many corner cases. v1: https://lore.kernel.org/all/20260115193647.1695937-1-Liam.Howlett@oracle.com/ v2: https://lore.kernel.org/all/20260121164526.2093265-1-Liam.Howlett@oracle.com/ Changes since v2: - Whitespace fix in rebalance_data() - Added ma_init_slot() for cleaner casting during RCU_INIT_POINTER(). Thanks test robot & SK [1] - Fixed off-by-one in rebalance_data() which caused node overuse, reported by linux-next. Thanks Mark [2] - Added new patch to reproducer to test cases in userspace testing for the rebalance_data() off-by-one [1]. https://lore.kernel.org/all/20260122055516.69335-1-sj@kernel.org/ [2]. https://lore.kernel.org/all/bd1c3356-11a1-4d0b-bf58-47eb21bfd24d@sirena.org.uk/ Liam R. Howlett (30): maple_tree: Fix mas_dup_alloc() sparse warning maple_tree: Move mas_spanning_rebalance loop to function maple_tree: Extract use of big node from mas_wr_spanning_store() maple_tree: Remove unnecessary assignment of orig_l index maple_tree: inline mas_spanning_rebalance() into mas_wr_spanning_rebalance() maple_tree: Make ma_wr_states reliable for reuse in spanning store maple_tree: Remove l_wr_mas from mas_wr_spanning_rebalance maple_tree: Don't pass through height in mas_wr_spanning_store maple_tree: Move maple_subtree_state from mas_wr_spanning_store to mas_wr_spanning_rebalance maple_tree: Correct right ma_wr_state end pivot in mas_wr_spanning_store() maple_tree: Introduce maple_copy node and use it in mas_spanning_rebalance() maple_tree: Testing update for spanning store maple_tree: Inline mas_spanning_rebalance_loop() into mas_wr_spanning_rebalance() maple_tree: Change initial big node setup in mas_wr_spanning_rebalance() maple_tree: Introduce ma_leaf_max_gap() maple_tree: Add gap support, slot and pivot sizes for maple copy maple_tree: Start using maple copy node for destination maple_tree: inline mas_wr_spanning_rebalance() maple_tree: Remove unnecessary return statements maple_tree: Separate wr_split_store and wr_rebalance store type code path maple_tree: Add cp_is_new_root() helper maple_tree: Use maple copy node for mas_wr_rebalance() operation maple_tree: Add test for rebalance calculation off-by-one maple_tree: Add copy_tree_location() helper maple_tree: Add cp_converged() helper maple_tree: Use maple copy node for mas_wr_split() maple_tree: Remove maple big node and subtree structs maple_tree: Pass maple copy node to mas_wmb_replace() maple_tree: Don't pass end to mas_wr_append() maple_tree: Clean up mas_wr_node_store() include/linux/maple_tree.h | 42 + lib/maple_tree.c | 2134 +++++++++++++----------------- lib/test_maple_tree.c | 55 +- tools/testing/radix-tree/maple.c | 308 ++++- 4 files changed, 1340 insertions(+), 1199 deletions(-) -- 2.47.3
The new_end does not need to be passed in as the data is already being checked. This allows for other areas to skip getting the node new_end in the calling function. The type was incorrectly void * instead of void __rcu *, which isn't an issue but is technically incorrect. Move the variable assignment to after the declarations to clean up the initial setup. Ensure there is something to copy before calling memcpy(). Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com> --- lib/maple_tree.c | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index c9c63246f721c..af4554a23881d 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -3122,20 +3122,28 @@ static void mas_wr_spanning_store(struct ma_wr_state *wr_mas) * * Attempts to reuse the node, but may allocate. */ -static inline void mas_wr_node_store(struct ma_wr_state *wr_mas, - unsigned char new_end) +static inline void mas_wr_node_store(struct ma_wr_state *wr_mas) { - struct ma_state *mas = wr_mas->mas; - void __rcu **dst_slots; - unsigned long *dst_pivots; - unsigned char dst_offset, offset_end = wr_mas->offset_end; + unsigned char dst_offset, offset_end; + unsigned char copy_size, node_pivots; struct maple_node reuse, *newnode; - unsigned char copy_size, node_pivots = mt_pivots[wr_mas->type]; - bool in_rcu = mt_in_rcu(mas->tree); - unsigned char height = mas_mt_height(mas); + unsigned long *dst_pivots; + void __rcu **dst_slots; + unsigned char new_end; + struct ma_state *mas; + bool in_rcu; - if (mas->last == wr_mas->end_piv) + mas = wr_mas->mas; + trace_ma_op(TP_FCT, mas); + in_rcu = mt_in_rcu(mas->tree); + offset_end = wr_mas->offset_end; + node_pivots = mt_pivots[wr_mas->type]; + /* Assume last adds an entry */ + new_end = mas->end + 1 - offset_end + mas->offset; + if (mas->last == wr_mas->end_piv) { offset_end++; /* don't copy this offset */ + new_end--; + } /* set up node. */ if (in_rcu) { @@ -3149,13 +3157,16 @@ static inline void mas_wr_node_store(struct ma_wr_state *wr_mas, dst_pivots = ma_pivots(newnode, wr_mas->type); dst_slots = ma_slots(newnode, wr_mas->type); /* Copy from start to insert point */ - memcpy(dst_pivots, wr_mas->pivots, sizeof(unsigned long) * mas->offset); - memcpy(dst_slots, wr_mas->slots, sizeof(void *) * mas->offset); + if (mas->offset) { + memcpy(dst_pivots, wr_mas->pivots, sizeof(unsigned long) * mas->offset); + memcpy(dst_slots, wr_mas->slots, sizeof(void __rcu *) * mas->offset); + } /* Handle insert of new range starting after old range */ if (wr_mas->r_min < mas->index) { rcu_assign_pointer(dst_slots[mas->offset], wr_mas->content); dst_pivots[mas->offset++] = mas->index - 1; + new_end++; } /* Store the new entry and range end. */ @@ -3174,7 +3185,7 @@ static inline void mas_wr_node_store(struct ma_wr_state *wr_mas, /* Copy to the end of node if necessary. */ copy_size = mas->end - offset_end + 1; memcpy(dst_slots + dst_offset, wr_mas->slots + offset_end, - sizeof(void *) * copy_size); + sizeof(void __rcu *) * copy_size); memcpy(dst_pivots + dst_offset, wr_mas->pivots + offset_end, sizeof(unsigned long) * (copy_size - 1)); @@ -3187,7 +3198,7 @@ static inline void mas_wr_node_store(struct ma_wr_state *wr_mas, struct maple_enode *old_enode = mas->node; mas->node = mt_mk_node(newnode, wr_mas->type); - mas_replace_node(mas, old_enode, height); + mas_replace_node(mas, old_enode, mas_mt_height(mas)); } else { memcpy(wr_mas->node, newnode, sizeof(struct maple_node)); } @@ -3503,7 +3514,6 @@ static void mas_wr_rebalance(struct ma_wr_state *wr_mas) static inline void mas_wr_store_entry(struct ma_wr_state *wr_mas) { struct ma_state *mas = wr_mas->mas; - unsigned char new_end = mas_wr_new_end(wr_mas); switch (mas->store_type) { case wr_exact_fit: @@ -3518,7 +3528,7 @@ static inline void mas_wr_store_entry(struct ma_wr_state *wr_mas) mas_wr_slot_store(wr_mas); break; case wr_node_store: - mas_wr_node_store(wr_mas, new_end); + mas_wr_node_store(wr_mas); break; case wr_spanning_store: mas_wr_spanning_store(wr_mas); -- 2.47.3
{ "author": "\"Liam R. Howlett\" <Liam.Howlett@oracle.com>", "date": "Fri, 30 Jan 2026 15:59:35 -0500", "thread_id": "20260202103154.ad1aa05611c79d21b070a861@linux-foundation.org.mbox.gz" }
lkml
[PATCH v3 00/30] maple_tree: Replace big node with maple copy
The big node struct was created for simplicity of splitting, rebalancing, and spanning store operations by using a copy buffer to create the data necessary prior to breaking it up into 256B nodes. Certain operations were rather tricky due to the restriction of keeping NULL entries together and never at the end of a node (except the right-most node). The big node struct is incompatible with future features that are currently in development. Specifically different node types and different data type sizes for pivots. The big node struct was also a stack variable, which caused issues with certain configurations of kernel build. This series removes big node by introducing another node type which will never be written to the tree: maple_copy. The maple copy node operates more like a scatter/gather operation with a number of sources and destinations of allocated nodes. The sources are copied to the destinations, in turn, until the sources are exhausted. The destination is changed if it is filled or the split location is reached prior to the source data end. New data is inserted by using the maple copy node itself as a source with up to 3 slots and pivots. The data in the maple copy node is the data being written to the tree along with any fragment of the range(s) being overwritten. As with all nodes, the maple copy node is of size 256B. Using a node type allows for the copy operation to treat the new data stored in the maple copy node the same as any other source node. Analysis of the runtime shows no regression or benefit of removing the larger stack structure. The motivation is the ground work to use new node types and to help those with odd configurations that have had issues. The change was tested by myself using mm_tests on amd64 and by Suren on android (arm64). Limited testing on s390 qemu was also performed using stress-ng on the virtual memory, which should cover many corner cases. v1: https://lore.kernel.org/all/20260115193647.1695937-1-Liam.Howlett@oracle.com/ v2: https://lore.kernel.org/all/20260121164526.2093265-1-Liam.Howlett@oracle.com/ Changes since v2: - Whitespace fix in rebalance_data() - Added ma_init_slot() for cleaner casting during RCU_INIT_POINTER(). Thanks test robot & SK [1] - Fixed off-by-one in rebalance_data() which caused node overuse, reported by linux-next. Thanks Mark [2] - Added new patch to reproducer to test cases in userspace testing for the rebalance_data() off-by-one [1]. https://lore.kernel.org/all/20260122055516.69335-1-sj@kernel.org/ [2]. https://lore.kernel.org/all/bd1c3356-11a1-4d0b-bf58-47eb21bfd24d@sirena.org.uk/ Liam R. Howlett (30): maple_tree: Fix mas_dup_alloc() sparse warning maple_tree: Move mas_spanning_rebalance loop to function maple_tree: Extract use of big node from mas_wr_spanning_store() maple_tree: Remove unnecessary assignment of orig_l index maple_tree: inline mas_spanning_rebalance() into mas_wr_spanning_rebalance() maple_tree: Make ma_wr_states reliable for reuse in spanning store maple_tree: Remove l_wr_mas from mas_wr_spanning_rebalance maple_tree: Don't pass through height in mas_wr_spanning_store maple_tree: Move maple_subtree_state from mas_wr_spanning_store to mas_wr_spanning_rebalance maple_tree: Correct right ma_wr_state end pivot in mas_wr_spanning_store() maple_tree: Introduce maple_copy node and use it in mas_spanning_rebalance() maple_tree: Testing update for spanning store maple_tree: Inline mas_spanning_rebalance_loop() into mas_wr_spanning_rebalance() maple_tree: Change initial big node setup in mas_wr_spanning_rebalance() maple_tree: Introduce ma_leaf_max_gap() maple_tree: Add gap support, slot and pivot sizes for maple copy maple_tree: Start using maple copy node for destination maple_tree: inline mas_wr_spanning_rebalance() maple_tree: Remove unnecessary return statements maple_tree: Separate wr_split_store and wr_rebalance store type code path maple_tree: Add cp_is_new_root() helper maple_tree: Use maple copy node for mas_wr_rebalance() operation maple_tree: Add test for rebalance calculation off-by-one maple_tree: Add copy_tree_location() helper maple_tree: Add cp_converged() helper maple_tree: Use maple copy node for mas_wr_split() maple_tree: Remove maple big node and subtree structs maple_tree: Pass maple copy node to mas_wmb_replace() maple_tree: Don't pass end to mas_wr_append() maple_tree: Clean up mas_wr_node_store() include/linux/maple_tree.h | 42 + lib/maple_tree.c | 2134 +++++++++++++----------------- lib/test_maple_tree.c | 55 +- tools/testing/radix-tree/maple.c | 308 ++++- 4 files changed, 1340 insertions(+), 1199 deletions(-) -- 2.47.3
Stop using the maple subtree state and big node in favour of using three destinations in the maple copy node. That is, expand the way leaves were handled to all levels of the tree and use the maple copy node to track the new nodes. Extract out the sibling init into the data calculation since this is where the insufficient data can be detected. The remainder of the sibling code to shift the next iteration is moved to the spanning_ascend() function, since it is not always needed. Next introduce the dst_setup() function which will decide how many nodes are needed to contain the data at this level. Using the destination count, populate the copy node's dst array with the new nodes and set d_count to the correct value. Note that this can be tricky in the case of a leaf node with exactly enough room because of the rule against NULLs at the end of leaves. Once the destinations are ready, copy the data by altering the cp_data_write() function to copy from the sources to the destinations directly. This eliminates the use of the big node in this code path. On node completion, node_finalise() will zero out the remaining area and set the metadata, if necessary. spanning_ascend() is used to decide if the operation is complete. It may create a new root, converge into one destination, or continue upwards by ascending the left and right write maple states. One test case setup needed to be tweaked so that the targeted node was surrounded by full nodes. Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com> --- include/linux/maple_tree.h | 14 + lib/maple_tree.c | 624 ++++++++++++++++++++++--------- tools/testing/radix-tree/maple.c | 2 +- 3 files changed, 458 insertions(+), 182 deletions(-) diff --git a/include/linux/maple_tree.h b/include/linux/maple_tree.h index db6a02788902a..0c464eade1d66 100644 --- a/include/linux/maple_tree.h +++ b/include/linux/maple_tree.h @@ -156,6 +156,17 @@ enum store_type { }; struct maple_copy { + /* + * min, max, and pivots are values + * start, end, split are indexes into arrays + * data is a size + */ + + struct { + struct maple_node *node; + unsigned long max; + enum maple_type mt; + } dst[3]; struct { struct maple_node *node; unsigned long max; @@ -178,7 +189,10 @@ struct maple_copy { /*Avoid passing these around */ unsigned char s_count; + unsigned char d_count; + unsigned char split; unsigned char data; + unsigned char height; }; /** diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 9c701ee7412ca..e0929bf0cfa1a 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -353,6 +353,13 @@ static inline struct maple_enode *mt_mk_node(const struct maple_node *node, (type << MAPLE_ENODE_TYPE_SHIFT) | MAPLE_ENODE_NULL); } +static inline void ma_init_slot(void __rcu **slot, const struct maple_node *mn, + const enum maple_type mt) +{ + /* WARNING: this is unsafe if the slot is exposed to readers. */ + RCU_INIT_POINTER(*slot, (void *)mt_mk_node(mn, mt)); +} + static inline void *mte_mk_root(const struct maple_enode *node) { return (void *)((unsigned long)node | MAPLE_ROOT_NODE); @@ -1320,6 +1327,21 @@ void wr_mas_setup(struct ma_wr_state *wr_mas, struct ma_state *mas) wr_mas->r_max = mas_safe_pivot(mas, wr_mas->pivots, mas->offset, wr_mas->type); } + +static inline +void wr_mas_ascend(struct ma_wr_state *wr_mas) +{ + struct ma_state *mas = wr_mas->mas; + + mas_ascend(mas); + wr_mas_setup(wr_mas, mas); + mas->end = ma_data_end(wr_mas->node, wr_mas->type, wr_mas->pivots, + mas->max); + /* Careful, this may be wrong.. */ + wr_mas->end_piv = wr_mas->r_max; + wr_mas->offset_end = mas->offset; +} + static inline unsigned long ma_leaf_max_gap(struct maple_node *mn, enum maple_type mt, unsigned long min, unsigned long max, unsigned long *pivots, void __rcu **slots) @@ -2507,6 +2529,112 @@ static inline void mas_wmb_replace(struct ma_state *mas, mas_update_gap(mas); } +/* + * node_copy() - Copy from one node to another. + * + * @mas: The maple state + * @src: The source node + * @start: The offset into the src to start copying + * @size: The size to copy (non-zero) + * @s_max: The source node max + * @s_mt: The source maple node type + * @dst: The destination + * @d_start: The start location in the destination node + * @d_mt: The destination maple node type + */ +static inline +unsigned long node_copy(struct ma_state *mas, struct maple_node *src, + unsigned char start, unsigned char size, unsigned long s_max, + enum maple_type s_mt, struct maple_node *dst, unsigned char d_start, + enum maple_type d_mt) +{ + unsigned long *s_pivots, *d_pivots; + void __rcu **s_slots, **d_slots; + unsigned long *s_gaps, *d_gaps; + unsigned long d_max; + + d_slots = ma_slots(dst, d_mt) + d_start; + d_pivots = ma_pivots(dst, d_mt) + d_start; + s_slots = ma_slots(src, s_mt) + start; + s_pivots = ma_pivots(src, s_mt) + start; + memcpy(d_slots, s_slots, size * sizeof(void __rcu *)); + if (!ma_is_leaf(d_mt) && s_mt == maple_copy) { + struct maple_enode *edst = mt_mk_node(dst, d_mt); + + + for (int i = 0; i < size; i++) + mas_set_parent(mas, + mt_slot_locked(mas->tree, d_slots, i), + edst, d_start + i); + } + + d_gaps = ma_gaps(dst, d_mt); + if (d_gaps) { + s_gaps = ma_gaps(src, s_mt) + start; + d_gaps += d_start; + memcpy(d_gaps, s_gaps, size * sizeof(unsigned long)); + } + + if (start + size - 1 < mt_pivots[s_mt]) + d_max = s_pivots[size - 1]; + else + d_max = s_max; + + if (d_start + size <= mt_pivots[d_mt]) + d_pivots[size - 1] = d_max; + + size--; + if (size) + memcpy(d_pivots, s_pivots, size * sizeof(unsigned long)); + + return d_max; +} + +/* + * node_finalise() - Zero out unused area and populate metadata + * @node: The maple node + * @mt: The maple node type + * @end: The end of the used area + */ +static inline +void node_finalise(struct maple_node *node, enum maple_type mt, + unsigned char end) +{ + unsigned char max_end = mt_slots[mt]; + unsigned char size; + unsigned long *gaps; + unsigned char gap_slot; + + gaps = ma_gaps(node, mt); + if (end < max_end - 1) { + size = max_end - end; + memset(ma_slots(node, mt) + end, 0, size * sizeof(void *)); + + if (gaps) + memset(gaps + end, 0, size * sizeof(unsigned long)); + + if (--size) + memset(ma_pivots(node, mt) + end, 0, size * sizeof(unsigned long)); + } + + gap_slot = 0; + if (gaps && !ma_is_leaf(mt)) { + unsigned long max_gap; + + max_gap = 0; + for (int i = 0; i <= end; i++) + if (gaps[i] > max_gap) { + gap_slot = i; + max_gap = gaps[i]; + } + } + + if (mt == maple_arange_64) + ma_set_meta(node, mt, gap_slot, end - 1); + else if (end <= max_end - 1) + ma_set_meta(node, mt, gap_slot, end - 1); +} + /* * mast_cp_to_nodes() - Copy data out to nodes. * @mast: The maple subtree state @@ -2684,6 +2812,7 @@ static inline void cp_leaf_init(struct maple_copy *cp, * result in buggy code when a compiler reorders the instructions. */ + cp->height = 1; /* Create entries to insert including split entries to left and right */ if (l_wr_mas->r_min < mas->index) { end++; @@ -2726,6 +2855,100 @@ static inline void cp_data_calc(struct maple_copy *cp, cp->data += r_wr_mas->mas->end - r_wr_mas->offset_end; } +/* + * spanning_data() - Calculate the @cp data and populate @sib if insufficient + * @cp: The maple copy node + * @l_wr_mas: The left write maple state + * @r_wr_mas: The right write maple state + * @sib: The maple state of the sibling. + * + * Note: @cp->data is a size and not indexed by 0. @sib->end may be set to 0 to + * indicate it will not be used. + */ +static inline void spanning_data(struct maple_copy *cp, + struct ma_wr_state *l_wr_mas, struct ma_wr_state *r_wr_mas, + struct ma_state *sib) +{ + cp_data_calc(cp, l_wr_mas, r_wr_mas); + if (((l_wr_mas->mas->min != 0) || (r_wr_mas->mas->max != ULONG_MAX)) && + (cp->data <= mt_min_slots[l_wr_mas->type])) { + spanning_sib(l_wr_mas, r_wr_mas, sib); + cp->data += sib->end + 1; + } else { + sib->end = 0; + } +} + +/* + * dst_setup() - Set up one or more destinations for the new data. + * @cp: The maple copy node + * @mas: The maple state + * @mt: The source node type + */ +static inline +void dst_setup(struct maple_copy *cp, struct ma_state *mas, enum maple_type mt) +{ + /* Data is 1 indexed, every src has +1 added. */ + + if (cp->data <= mt_slots[mt]) { + cp->split = cp->data - 1; + cp->d_count = 1; + goto node_setup; + } + + cp->split = (cp->data - 1) / 2; + cp->d_count = 2; + if (cp->data < mt_slots[mt] * 2) + goto node_setup; + + if (cp->data == mt_slots[mt] * 2) { + unsigned char off; + unsigned char s; + + if (!ma_is_leaf(mt)) + goto node_setup; + + /* + * Leaf nodes are a bit tricky because we cannot assume the data + * can fit due to the NULL limitation on node ends. + */ + off = cp->split; + for (s = 0; s < cp->s_count; s++) { + unsigned char s_off; + + s_off = cp->src[s].end - cp->src[s].start; + if (s_off >= off) + break; + + s_off++; + off -= s_off; + } + + off += cp->src[s].start; + if (ma_slots(cp->src[s].node, cp->src[s].mt)[off]) + goto node_setup; + + cp->split++; + if (cp->split < mt_slots[mt]) + goto node_setup; + + cp->split -= 2; + if (cp->data - 2 - cp->split < mt_slots[mt]) + goto node_setup; + + } + + /* No other choice but to 3-way split the data */ + cp->split = (cp->data + 2) / 3; + cp->d_count = 3; + +node_setup: + for (int i = 0; i < cp->d_count; i++) { + cp->dst[i].mt = mt; + cp->dst[i].node = ma_mnode_ptr(mas_pop_node(mas)); + } +} + static inline void append_mas_cp(struct maple_copy *cp, struct ma_state *mas, unsigned char start, unsigned char end) { @@ -2813,38 +3036,153 @@ void multi_src_setup(struct maple_copy *cp, struct ma_wr_state *l_wr_mas, } static inline -void cp_data_write(struct maple_copy *cp, struct maple_big_node *b_node) +void cp_data_write(struct maple_copy *cp, struct ma_state *mas) { - struct maple_node *src; - unsigned char s; + struct maple_node *dst, *src; + unsigned char s, d; + unsigned char dst_offset; + unsigned char data_offset; unsigned char src_end, s_offset; - unsigned long *b_pivots, *cp_pivots; - void __rcu **b_slots, **cp_slots; - enum maple_type s_mt; + unsigned char split; + unsigned long s_max, d_max; + unsigned char dst_size; + enum maple_type s_mt, d_mt; + + data_offset = 0; + s = d = 0; + /* Readability help */ + src = cp->src[s].node; + dst = cp->dst[d].node; + s_offset = cp->src[s].start; + src_end = cp->src[s].end; + split = cp->split; + s_max = cp->src[s].max; + s_mt = cp->src[s].mt; + d_mt = cp->dst[d].mt; + do { + dst_offset = 0; + d_max = 0; + dst = cp->dst[d].node; + d_mt = cp->dst[d].mt; + dst_size = split + 1; - b_node->b_end = 0; + while (dst_size) { + unsigned char size; - s = 0; - b_pivots = b_node->pivot; - b_slots = (void __rcu **)b_node->slot; - do { - unsigned char size; - - src = cp->src[s].node; - s_mt = cp->src[s].mt; - s_offset = cp->src[s].start; - src_end = cp->src[s].end; - size = src_end - s_offset + 1; - cp_pivots = ma_pivots(src, s_mt) + s_offset; - cp_slots = ma_slots(src, s_mt) + s_offset; - memcpy(b_slots, cp_slots, size * sizeof(void __rcu *)); - if (size > 1) - memcpy(b_pivots, cp_pivots, (size - 1) * sizeof(unsigned long)); - b_pivots[size - 1] = cp->src[s].max; - b_pivots += size; - b_slots += size; - b_node->b_end += size; - } while (++s < cp->s_count); + if (src_end - s_offset + 1 < dst_size) + size = src_end - s_offset + 1; + else + size = dst_size; + + d_max = node_copy(mas, src, s_offset, size, s_max, s_mt, + dst, dst_offset, d_mt); + + dst_offset += size; + s_offset += size; + if (s_offset > src_end) { + /* This source is exhausted */ + s++; + if (s >= cp->s_count) { + cp->dst[d].max = d_max; + node_finalise(dst, d_mt, dst_offset); + return; + } + /* Reset local src */ + src = cp->src[s].node; + s_offset = cp->src[s].start; + src_end = cp->src[s].end; + s_max = cp->src[s].max; + s_mt = cp->src[s].mt; + } + + dst_size -= size; + data_offset += size; + } + + split = cp->split; + cp->dst[d].max = d_max; + /* Handle null entries */ + if (cp->dst[d].max != ULONG_MAX && + !ma_slots(dst, d_mt)[dst_offset - 1]) { + if (s_offset == cp->src[s].start) { + s--; + src = cp->src[s].node; + src_end = cp->src[s].end; + s_max = cp->src[s].max; + s_mt = cp->src[s].mt; + s_offset = src_end; + } else { + s_offset--; + } + /* Set dst max and clear pivot */ + split++; + data_offset--; + dst_offset--; + cp->dst[d].max = ma_pivots(dst, d_mt)[dst_offset - 1]; + } + + node_finalise(dst, d_mt, dst_offset); + ++d; /* Next destination */ + if (d == cp->d_count - 1) + split = cp->data - data_offset; + + if (d >= cp->d_count) { + WARN_ON(data_offset < cp->data); + return; + } + + } while (data_offset <= cp->data); +} + +/* + * cp_dst_to_slots() - Migrate the maple copy destination to the maple copy + * slots + * @cp: The maple copy node + * @min: The minimal value represented + * @max: The maximum value represented + * @mas: The maple state + */ +static inline void cp_dst_to_slots(struct maple_copy *cp, unsigned long min, + unsigned long max, struct ma_state *mas) +{ + unsigned char d; + unsigned long slot_min = min; + + for (d = 0; d < cp->d_count; d++) { + struct maple_node *mn = cp->dst[d].node; + enum maple_type mt = cp->dst[d].mt; + unsigned long slot_max = cp->dst[d].max; + + /* + * Warning, see cp_leaf_init() comment and rcu_assign_pointer() + * documentation. Since these are new nodes, there are no + * read-side operations that can view them until they are + * inserted into the tree after an rcu_assign_pointer() call. + */ + ma_init_slot(&cp->slot[d], mn, mt); + cp->pivot[d] = slot_max; + if (mt_is_alloc(mas->tree)) { + if (ma_is_leaf(mt)) { + cp->gap[d] = ma_leaf_max_gap(mn, mt, slot_min, + slot_max, ma_pivots(mn, mt), + ma_slots(mn, mt)); + } else { + unsigned long *gaps = ma_gaps(mn, mt); + + if (gaps) { + unsigned char gap_slot; + + gap_slot = ma_meta_gap(mn); + cp->gap[d] = gaps[gap_slot]; + } + } + } + slot_min = slot_max + 1; + } + + cp->end = cp->d_count - 1; + cp->min = min; + cp->max = max; } static void mas_spanning_rebalance_loop(struct ma_state *mas, @@ -3000,173 +3338,97 @@ static void mas_spanning_rebalance(struct ma_state *mas, mas_spanning_rebalance_loop(mas, mast, count); } - -static noinline void mas_wr_spanning_rebalance(struct ma_state *mas, - struct ma_wr_state *l_wr_mas, struct ma_wr_state *r_wr_mas) +/* + * spanning_ascend() - See if a spanning store operation has to keep walking up + * the tree + * @cp: The maple_copy node + * @l_wr_mas: The left maple write state + * @r_wr_mas: The right maple write state + * @sib: the maple state of the sibling + * + * Returns: True if another iteration is necessary. + */ +static bool spanning_ascend(struct maple_copy *cp, struct ma_state *mas, + struct ma_wr_state *l_wr_mas, struct ma_wr_state *r_wr_mas, + struct ma_state *sib) { - - unsigned char split, mid_split; - unsigned char slot = 0; - unsigned char new_height = 0; /* used if node is a new root */ - struct maple_enode *left = NULL, *middle = NULL, *right = NULL; - struct maple_enode *old_enode; - - struct maple_subtree_state mast; - struct maple_big_node b_node; - struct maple_copy cp; - unsigned char height; - struct ma_state sib; - MA_STATE(l_mas, mas->tree, mas->index, mas->index); - MA_STATE(r_mas, mas->tree, mas->index, mas->last); - MA_STATE(m_mas, mas->tree, mas->index, mas->index); - MA_STATE(mast_l_mas, NULL, 0, 0); - - - memset(&b_node, 0, sizeof(struct maple_big_node)); - mast_l_mas = *mas; - cp.s_count = 0; - cp_leaf_init(&cp, mas, l_wr_mas, r_wr_mas); - cp_data_calc(&cp, l_wr_mas, r_wr_mas); - if (((l_wr_mas->mas->min != 0) || (r_wr_mas->mas->max != ULONG_MAX)) && - (cp.data <= mt_min_slots[l_wr_mas->type])) { - spanning_sib(l_wr_mas, r_wr_mas, &sib); - cp.data += sib.end + 1; - } else { - sib.end = 0; - } - - multi_src_setup(&cp, l_wr_mas, r_wr_mas, &sib); - b_node.type = l_wr_mas->type; - cp_data_write(&cp, &b_node); - if (sib.end) { - if (sib.max < l_wr_mas->mas->min) { - *l_wr_mas->mas = sib; - wr_mas_setup(l_wr_mas, &sib); - mast_l_mas = sib; - } else { - *r_wr_mas->mas = sib; - wr_mas_setup(r_wr_mas, &sib); - } + if (sib->end) { + if (sib->max < l_wr_mas->mas->min) + *l_wr_mas->mas = *sib; + else + *r_wr_mas->mas = *sib; } - mast.orig_l = &mast_l_mas; - mast.orig_r = r_wr_mas->mas; - /* Stop spanning searches by searching for just index. */ - mast.orig_l->last = mas->index; + cp_dst_to_slots(cp, l_wr_mas->mas->min, r_wr_mas->mas->max, mas); + if (!cp->min && cp->max == ULONG_MAX) { + /* New root */ + if (cp->d_count != 1) { + enum maple_type mt = maple_arange_64; - mast.bn = &b_node; - /* Combine l_mas and r_mas and split them up evenly again. */ + if (!mt_is_alloc(mas->tree)) + mt = maple_range_64; - /* - * The tree needs to be rebalanced and leaves need to be kept at the same level. - * Rebalancing is done by use of the ``struct maple_topiary``. - */ - mast.l = &l_mas; - mast.m = &m_mas; - mast.r = &r_mas; - l_mas.status = r_mas.status = m_mas.status = ma_none; - height = mas_mt_height(mas) + 1; - - /* - * Each level of the tree is examined and balanced, pushing data to the left or - * right, or rebalancing against left or right nodes is employed to avoid - * rippling up the tree to limit the amount of churn. Once a new sub-section of - * the tree is created, there may be a mix of new and old nodes. The old nodes - * will have the incorrect parent pointers and currently be in two trees: the - * original tree and the partially new tree. To remedy the parent pointers in - * the old tree, the new data is swapped into the active tree and a walk down - * the tree is performed and the parent pointers are updated. - * See mas_topiary_replace() for more information. - */ - while (height--) { - mast.bn->b_end--; - mast.bn->type = mte_node_type(mast.orig_l->node); - split = mas_mab_to_node(mas, mast.bn, &left, &right, &middle, - &mid_split); - mast_set_split_parents(&mast, left, middle, right, split, - mid_split); - mast_cp_to_nodes(&mast, left, middle, right, split, mid_split); - new_height++; - - /* - * Copy data from next level in the tree to mast.bn from next - * iteration - */ - memset(mast.bn, 0, sizeof(struct maple_big_node)); - mast.bn->type = mte_node_type(left); - - /* Root already stored in l->node. */ - if (mas_is_root_limits(mast.l)) - goto new_root; - - mast_ascend(&mast); - mast_combine_cp_left(&mast); - mast.l->offset = mast.bn->b_end; - mab_set_b_end(mast.bn, mast.l, left); - mab_set_b_end(mast.bn, mast.m, middle); - mab_set_b_end(mast.bn, mast.r, right); - - /* Copy anything necessary out of the right node. */ - mast_combine_cp_right(&mast); - mast.orig_l->last = mast.orig_l->max; - - if (mast_sufficient(&mast)) { - if (mast_overflow(&mast)) - continue; - - if (mast.orig_l->node == mast.orig_r->node) { - /* - * The data in b_node should be stored in one - * node and in the tree - */ - slot = mast.l->offset; - break; - } - - continue; + cp->data = cp->d_count; + cp->s_count = 0; + dst_setup(cp, mas, mt); + init_cp_src(cp); + node_copy(mas, cp->src[0].node, 0, cp->data, cp->max, maple_copy, + cp->dst[0].node, 0, mt); + node_finalise(cp->dst[0].node, mt, cp->end + 1); + /* + * Warning, see cp_leaf_init() comment and rcu_assign_pointer() + * documentation. Since this is a new root, there are no + * read-side operations that can view it until it is insert into + * the tree after an rcu_assign_pointer() call. + */ + ma_init_slot(&cp->slot[0], cp->dst[0].node, mt); + cp->height++; } - - /* May be a new root stored in mast.bn */ - if (mas_is_root_limits(mast.orig_l)) - break; - - mast_spanning_rebalance(&mast); - - /* rebalancing from other nodes may require another loop. */ - if (!height) - height++; + WARN_ON_ONCE(cp->dst[0].node != mte_to_node( + mt_slot_locked(mas->tree, cp->slot, 0))); + cp->dst[0].node->parent = ma_parent_ptr(mas_tree_parent(mas)); + mas->min = 0; + mas->max = ULONG_MAX; + mas->depth = 0; + mas->node = mas_root_locked(mas); + return false; } - mast.l->node = mt_mk_node(ma_mnode_ptr(mas_pop_node(mas)), - mte_node_type(mast.orig_l->node)); + /* Converged and has a single destination */ + if ((cp->d_count == 1) && + (l_wr_mas->mas->node == r_wr_mas->mas->node)) { + cp->dst[0].node->parent = ma_parent_ptr(mas_mn(mas)->parent); + return false; + } - mab_mas_cp(mast.bn, 0, mt_slots[mast.bn->type] - 1, mast.l, true); - new_height++; - mas_set_parent(mas, left, mast.l->node, slot); - if (middle) - mas_set_parent(mas, middle, mast.l->node, ++slot); + cp->height++; + wr_mas_ascend(l_wr_mas); + wr_mas_ascend(r_wr_mas); + return true; +} - if (right) - mas_set_parent(mas, right, mast.l->node, ++slot); +static noinline void mas_wr_spanning_rebalance(struct ma_state *mas, + struct ma_wr_state *l_wr_mas, struct ma_wr_state *r_wr_mas) +{ - if (mas_is_root_limits(mast.l)) { -new_root: - mas_mn(mast.l)->parent = ma_parent_ptr(mas_tree_parent(mas)); - while (!mte_is_root(mast.orig_l->node)) - mast_ascend(&mast); - } else { - mas_mn(mast.l)->parent = mas_mn(mast.orig_l)->parent; - } + struct maple_enode *old_enode; + struct maple_copy cp; + struct ma_state sib; - old_enode = mast.orig_l->node; - mas->depth = mast.l->depth; - mas->node = mast.l->node; - mas->min = mast.l->min; - mas->max = mast.l->max; - mas->offset = mast.l->offset; - mas_wmb_replace(mas, old_enode, new_height); + cp_leaf_init(&cp, mas, l_wr_mas, r_wr_mas); + do { + spanning_data(&cp, l_wr_mas, r_wr_mas, &sib); + multi_src_setup(&cp, l_wr_mas, r_wr_mas, &sib); + dst_setup(&cp, mas, l_wr_mas->type); + cp_data_write(&cp, mas); + } while (spanning_ascend(&cp, mas, l_wr_mas, r_wr_mas, &sib)); + + old_enode = mas->node; + mas->node = mt_slot_locked(mas->tree, cp.slot, 0); + mas_wmb_replace(mas, old_enode, cp.height); mtree_range_walk(mas); } + /* * mas_rebalance() - Rebalance a given node. * @mas: The maple state diff --git a/tools/testing/radix-tree/maple.c b/tools/testing/radix-tree/maple.c index 85fb5616c133c..dfd7099f0d8ef 100644 --- a/tools/testing/radix-tree/maple.c +++ b/tools/testing/radix-tree/maple.c @@ -35508,7 +35508,7 @@ static noinline void __init check_spanning_write(struct maple_tree *mt) /* Store a value across a node boundary that causes a 3 way split */ if (MAPLE_32BIT) - i = 49590; /* 0xc1b6 */ + i = 49430; /* 0xc116 */ else i = 49670; /* 0xC206 */ -- 2.47.3
{ "author": "\"Liam R. Howlett\" <Liam.Howlett@oracle.com>", "date": "Fri, 30 Jan 2026 15:59:22 -0500", "thread_id": "20260202103154.ad1aa05611c79d21b070a861@linux-foundation.org.mbox.gz" }
lkml
[PATCH v3 00/30] maple_tree: Replace big node with maple copy
The big node struct was created for simplicity of splitting, rebalancing, and spanning store operations by using a copy buffer to create the data necessary prior to breaking it up into 256B nodes. Certain operations were rather tricky due to the restriction of keeping NULL entries together and never at the end of a node (except the right-most node). The big node struct is incompatible with future features that are currently in development. Specifically different node types and different data type sizes for pivots. The big node struct was also a stack variable, which caused issues with certain configurations of kernel build. This series removes big node by introducing another node type which will never be written to the tree: maple_copy. The maple copy node operates more like a scatter/gather operation with a number of sources and destinations of allocated nodes. The sources are copied to the destinations, in turn, until the sources are exhausted. The destination is changed if it is filled or the split location is reached prior to the source data end. New data is inserted by using the maple copy node itself as a source with up to 3 slots and pivots. The data in the maple copy node is the data being written to the tree along with any fragment of the range(s) being overwritten. As with all nodes, the maple copy node is of size 256B. Using a node type allows for the copy operation to treat the new data stored in the maple copy node the same as any other source node. Analysis of the runtime shows no regression or benefit of removing the larger stack structure. The motivation is the ground work to use new node types and to help those with odd configurations that have had issues. The change was tested by myself using mm_tests on amd64 and by Suren on android (arm64). Limited testing on s390 qemu was also performed using stress-ng on the virtual memory, which should cover many corner cases. v1: https://lore.kernel.org/all/20260115193647.1695937-1-Liam.Howlett@oracle.com/ v2: https://lore.kernel.org/all/20260121164526.2093265-1-Liam.Howlett@oracle.com/ Changes since v2: - Whitespace fix in rebalance_data() - Added ma_init_slot() for cleaner casting during RCU_INIT_POINTER(). Thanks test robot & SK [1] - Fixed off-by-one in rebalance_data() which caused node overuse, reported by linux-next. Thanks Mark [2] - Added new patch to reproducer to test cases in userspace testing for the rebalance_data() off-by-one [1]. https://lore.kernel.org/all/20260122055516.69335-1-sj@kernel.org/ [2]. https://lore.kernel.org/all/bd1c3356-11a1-4d0b-bf58-47eb21bfd24d@sirena.org.uk/ Liam R. Howlett (30): maple_tree: Fix mas_dup_alloc() sparse warning maple_tree: Move mas_spanning_rebalance loop to function maple_tree: Extract use of big node from mas_wr_spanning_store() maple_tree: Remove unnecessary assignment of orig_l index maple_tree: inline mas_spanning_rebalance() into mas_wr_spanning_rebalance() maple_tree: Make ma_wr_states reliable for reuse in spanning store maple_tree: Remove l_wr_mas from mas_wr_spanning_rebalance maple_tree: Don't pass through height in mas_wr_spanning_store maple_tree: Move maple_subtree_state from mas_wr_spanning_store to mas_wr_spanning_rebalance maple_tree: Correct right ma_wr_state end pivot in mas_wr_spanning_store() maple_tree: Introduce maple_copy node and use it in mas_spanning_rebalance() maple_tree: Testing update for spanning store maple_tree: Inline mas_spanning_rebalance_loop() into mas_wr_spanning_rebalance() maple_tree: Change initial big node setup in mas_wr_spanning_rebalance() maple_tree: Introduce ma_leaf_max_gap() maple_tree: Add gap support, slot and pivot sizes for maple copy maple_tree: Start using maple copy node for destination maple_tree: inline mas_wr_spanning_rebalance() maple_tree: Remove unnecessary return statements maple_tree: Separate wr_split_store and wr_rebalance store type code path maple_tree: Add cp_is_new_root() helper maple_tree: Use maple copy node for mas_wr_rebalance() operation maple_tree: Add test for rebalance calculation off-by-one maple_tree: Add copy_tree_location() helper maple_tree: Add cp_converged() helper maple_tree: Use maple copy node for mas_wr_split() maple_tree: Remove maple big node and subtree structs maple_tree: Pass maple copy node to mas_wmb_replace() maple_tree: Don't pass end to mas_wr_append() maple_tree: Clean up mas_wr_node_store() include/linux/maple_tree.h | 42 + lib/maple_tree.c | 2134 +++++++++++++----------------- lib/test_maple_tree.c | 55 +- tools/testing/radix-tree/maple.c | 308 ++++- 4 files changed, 1340 insertions(+), 1199 deletions(-) -- 2.47.3
Now that no one uses the structures and functions, drop the dead code. Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com> --- lib/maple_tree.c | 1184 ---------------------------------------------- 1 file changed, 1184 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 5813ad17ea6fe..1cfbed6fac9f5 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -133,45 +133,6 @@ static const unsigned char mt_min_slots[] = { }; #define mt_min_slot_count(x) mt_min_slots[mte_node_type(x)] -#define MAPLE_BIG_NODE_SLOTS (MAPLE_RANGE64_SLOTS * 2 + 2) -#define MAPLE_BIG_NODE_GAPS (MAPLE_ARANGE64_SLOTS * 2 + 1) - -struct maple_big_node { - unsigned long pivot[MAPLE_BIG_NODE_SLOTS - 1]; - union { - struct maple_enode *slot[MAPLE_BIG_NODE_SLOTS]; - struct { - unsigned long padding[MAPLE_BIG_NODE_GAPS]; - unsigned long gap[MAPLE_BIG_NODE_GAPS]; - }; - }; - unsigned char b_end; - enum maple_type type; -}; - -/* - * The maple_subtree_state is used to build a tree to replace a segment of an - * existing tree in a more atomic way. Any walkers of the older tree will hit a - * dead node and restart on updates. - */ -struct maple_subtree_state { - struct ma_state *orig_l; /* Original left side of subtree */ - struct ma_state *orig_r; /* Original right side of subtree */ - struct ma_state *l; /* New left side of subtree */ - struct ma_state *m; /* New middle of subtree (rare) */ - struct ma_state *r; /* New right side of subtree */ - struct ma_topiary *free; /* nodes to be freed */ - struct ma_topiary *destroy; /* Nodes to be destroyed (walked and freed) */ - struct maple_big_node *bn; -}; - -#ifdef CONFIG_KASAN_STACK -/* Prevent mas_wr_bnode() from exceeding the stack frame limit */ -#define noinline_for_kasan noinline_for_stack -#else -#define noinline_for_kasan inline -#endif - /* Functions */ static inline struct maple_node *mt_alloc_one(gfp_t gfp) { @@ -1669,169 +1630,6 @@ static inline bool mas_find_child(struct ma_state *mas, struct ma_state *child) return false; } -/* - * mab_shift_right() - Shift the data in mab right. Note, does not clean out the - * old data or set b_node->b_end. - * @b_node: the maple_big_node - * @shift: the shift count - */ -static inline void mab_shift_right(struct maple_big_node *b_node, - unsigned char shift) -{ - unsigned long size = b_node->b_end * sizeof(unsigned long); - - memmove(b_node->pivot + shift, b_node->pivot, size); - memmove(b_node->slot + shift, b_node->slot, size); - if (b_node->type == maple_arange_64) - memmove(b_node->gap + shift, b_node->gap, size); -} - -/* - * mab_middle_node() - Check if a middle node is needed (unlikely) - * @b_node: the maple_big_node that contains the data. - * @split: the potential split location - * @slot_count: the size that can be stored in a single node being considered. - * - * Return: true if a middle node is required. - */ -static inline bool mab_middle_node(struct maple_big_node *b_node, int split, - unsigned char slot_count) -{ - unsigned char size = b_node->b_end; - - if (size >= 2 * slot_count) - return true; - - if (!b_node->slot[split] && (size >= 2 * slot_count - 1)) - return true; - - return false; -} - -/* - * mab_no_null_split() - ensure the split doesn't fall on a NULL - * @b_node: the maple_big_node with the data - * @split: the suggested split location - * @slot_count: the number of slots in the node being considered. - * - * Return: the split location. - */ -static inline int mab_no_null_split(struct maple_big_node *b_node, - unsigned char split, unsigned char slot_count) -{ - if (!b_node->slot[split]) { - /* - * If the split is less than the max slot && the right side will - * still be sufficient, then increment the split on NULL. - */ - if ((split < slot_count - 1) && - (b_node->b_end - split) > (mt_min_slots[b_node->type])) - split++; - else - split--; - } - return split; -} - -/* - * mab_calc_split() - Calculate the split location and if there needs to be two - * splits. - * @mas: The maple state - * @bn: The maple_big_node with the data - * @mid_split: The second split, if required. 0 otherwise. - * - * Return: The first split location. The middle split is set in @mid_split. - */ -static inline int mab_calc_split(struct ma_state *mas, - struct maple_big_node *bn, unsigned char *mid_split) -{ - unsigned char b_end = bn->b_end; - int split = b_end / 2; /* Assume equal split. */ - unsigned char slot_count = mt_slots[bn->type]; - - /* - * To support gap tracking, all NULL entries are kept together and a node cannot - * end on a NULL entry, with the exception of the left-most leaf. The - * limitation means that the split of a node must be checked for this condition - * and be able to put more data in one direction or the other. - * - * Although extremely rare, it is possible to enter what is known as the 3-way - * split scenario. The 3-way split comes about by means of a store of a range - * that overwrites the end and beginning of two full nodes. The result is a set - * of entries that cannot be stored in 2 nodes. Sometimes, these two nodes can - * also be located in different parent nodes which are also full. This can - * carry upwards all the way to the root in the worst case. - */ - if (unlikely(mab_middle_node(bn, split, slot_count))) { - split = b_end / 3; - *mid_split = split * 2; - } else { - *mid_split = 0; - } - - /* Avoid ending a node on a NULL entry */ - split = mab_no_null_split(bn, split, slot_count); - - if (unlikely(*mid_split)) - *mid_split = mab_no_null_split(bn, *mid_split, slot_count); - - return split; -} - -/* - * mas_mab_cp() - Copy data from a maple state inclusively to a maple_big_node - * and set @b_node->b_end to the next free slot. - * @mas: The maple state - * @mas_start: The starting slot to copy - * @mas_end: The end slot to copy (inclusively) - * @b_node: The maple_big_node to place the data - * @mab_start: The starting location in maple_big_node to store the data. - */ -static inline void mas_mab_cp(struct ma_state *mas, unsigned char mas_start, - unsigned char mas_end, struct maple_big_node *b_node, - unsigned char mab_start) -{ - enum maple_type mt; - struct maple_node *node; - void __rcu **slots; - unsigned long *pivots, *gaps; - int i = mas_start, j = mab_start; - unsigned char piv_end; - - node = mas_mn(mas); - mt = mte_node_type(mas->node); - pivots = ma_pivots(node, mt); - if (!i) { - b_node->pivot[j] = pivots[i++]; - if (unlikely(i > mas_end)) - goto complete; - j++; - } - - piv_end = min(mas_end, mt_pivots[mt]); - for (; i < piv_end; i++, j++) { - b_node->pivot[j] = pivots[i]; - if (unlikely(!b_node->pivot[j])) - goto complete; - - if (unlikely(mas->max == b_node->pivot[j])) - goto complete; - } - - b_node->pivot[j] = mas_safe_pivot(mas, pivots, i, mt); - -complete: - b_node->b_end = ++j; - j -= mab_start; - slots = ma_slots(node, mt); - memcpy(b_node->slot + mab_start, slots + mas_start, sizeof(void *) * j); - if (!ma_is_leaf(mt) && mt_is_alloc(mas->tree)) { - gaps = ma_gaps(node, mt); - memcpy(b_node->gap + mab_start, gaps + mas_start, - sizeof(unsigned long) * j); - } -} - /* * mas_leaf_set_meta() - Set the metadata of a leaf if possible. * @node: The maple node @@ -1845,134 +1643,6 @@ static inline void mas_leaf_set_meta(struct maple_node *node, ma_set_meta(node, mt, 0, end); } -/* - * mab_mas_cp() - Copy data from maple_big_node to a maple encoded node. - * @b_node: the maple_big_node that has the data - * @mab_start: the start location in @b_node. - * @mab_end: The end location in @b_node (inclusively) - * @mas: The maple state with the maple encoded node. - */ -static inline void mab_mas_cp(struct maple_big_node *b_node, - unsigned char mab_start, unsigned char mab_end, - struct ma_state *mas, bool new_max) -{ - int i, j = 0; - enum maple_type mt = mte_node_type(mas->node); - struct maple_node *node = mte_to_node(mas->node); - void __rcu **slots = ma_slots(node, mt); - unsigned long *pivots = ma_pivots(node, mt); - unsigned long *gaps = NULL; - unsigned char end; - - if (mab_end - mab_start > mt_pivots[mt]) - mab_end--; - - if (!pivots[mt_pivots[mt] - 1]) - slots[mt_pivots[mt]] = NULL; - - i = mab_start; - do { - pivots[j++] = b_node->pivot[i++]; - } while (i <= mab_end && likely(b_node->pivot[i])); - - memcpy(slots, b_node->slot + mab_start, - sizeof(void *) * (i - mab_start)); - - if (new_max) - mas->max = b_node->pivot[i - 1]; - - end = j - 1; - if (likely(!ma_is_leaf(mt) && mt_is_alloc(mas->tree))) { - unsigned long max_gap = 0; - unsigned char offset = 0; - - gaps = ma_gaps(node, mt); - do { - gaps[--j] = b_node->gap[--i]; - if (gaps[j] > max_gap) { - offset = j; - max_gap = gaps[j]; - } - } while (j); - - ma_set_meta(node, mt, offset, end); - } else { - mas_leaf_set_meta(node, mt, end); - } -} - -/* - * mas_store_b_node() - Store an @entry into the b_node while also copying the - * data from a maple encoded node. - * @wr_mas: the maple write state - * @b_node: the maple_big_node to fill with data - * @offset_end: the offset to end copying - * - * Return: The actual end of the data stored in @b_node - */ -static noinline_for_kasan void mas_store_b_node(struct ma_wr_state *wr_mas, - struct maple_big_node *b_node, unsigned char offset_end) -{ - unsigned char slot; - unsigned char b_end; - /* Possible underflow of piv will wrap back to 0 before use. */ - unsigned long piv; - struct ma_state *mas = wr_mas->mas; - - b_node->type = wr_mas->type; - b_end = 0; - slot = mas->offset; - if (slot) { - /* Copy start data up to insert. */ - mas_mab_cp(mas, 0, slot - 1, b_node, 0); - b_end = b_node->b_end; - piv = b_node->pivot[b_end - 1]; - } else - piv = mas->min - 1; - - if (piv + 1 < mas->index) { - /* Handle range starting after old range */ - b_node->slot[b_end] = wr_mas->content; - if (!wr_mas->content) - b_node->gap[b_end] = mas->index - 1 - piv; - b_node->pivot[b_end++] = mas->index - 1; - } - - /* Store the new entry. */ - mas->offset = b_end; - b_node->slot[b_end] = wr_mas->entry; - b_node->pivot[b_end] = mas->last; - - /* Appended. */ - if (mas->last >= mas->max) - goto b_end; - - /* Handle new range ending before old range ends */ - piv = mas_safe_pivot(mas, wr_mas->pivots, offset_end, wr_mas->type); - if (piv > mas->last) { - if (offset_end != slot) - wr_mas->content = mas_slot_locked(mas, wr_mas->slots, - offset_end); - - b_node->slot[++b_end] = wr_mas->content; - if (!wr_mas->content) - b_node->gap[b_end] = piv - mas->last + 1; - b_node->pivot[b_end] = piv; - } - - slot = offset_end + 1; - if (slot > mas->end) - goto b_end; - - /* Copy end data to the end of the node. */ - mas_mab_cp(mas, slot, mas->end + 1, b_node, ++b_end); - b_node->b_end--; - return; - -b_end: - b_node->b_end = b_end; -} - /* * mas_prev_sibling() - Find the previous node with the same parent. * @mas: the maple state @@ -2017,25 +1687,6 @@ static inline bool mas_next_sibling(struct ma_state *mas) return true; } -/* - * mas_node_or_none() - Set the enode and state. - * @mas: the maple state - * @enode: The encoded maple node. - * - * Set the node to the enode and the status. - */ -static inline void mas_node_or_none(struct ma_state *mas, - struct maple_enode *enode) -{ - if (enode) { - mas->node = enode; - mas->status = ma_active; - } else { - mas->node = NULL; - mas->status = ma_none; - } -} - /* * mas_wr_node_walk() - Find the correct offset for the index in the @mas. * If @mas->index cannot be found within the containing @@ -2069,242 +1720,6 @@ static inline void mas_wr_node_walk(struct ma_wr_state *wr_mas) wr_mas->offset_end = mas->offset = offset; } -/* - * mast_rebalance_next() - Rebalance against the next node - * @mast: The maple subtree state - */ -static inline void mast_rebalance_next(struct maple_subtree_state *mast) -{ - unsigned char b_end = mast->bn->b_end; - - mas_mab_cp(mast->orig_r, 0, mt_slot_count(mast->orig_r->node), - mast->bn, b_end); - mast->orig_r->last = mast->orig_r->max; -} - -/* - * mast_rebalance_prev() - Rebalance against the previous node - * @mast: The maple subtree state - */ -static inline void mast_rebalance_prev(struct maple_subtree_state *mast) -{ - unsigned char end = mas_data_end(mast->orig_l) + 1; - unsigned char b_end = mast->bn->b_end; - - mab_shift_right(mast->bn, end); - mas_mab_cp(mast->orig_l, 0, end - 1, mast->bn, 0); - mast->l->min = mast->orig_l->min; - mast->orig_l->index = mast->orig_l->min; - mast->bn->b_end = end + b_end; - mast->l->offset += end; -} - -/* - * mast_spanning_rebalance() - Rebalance nodes with nearest neighbour favouring - * the node to the right. Checking the nodes to the right then the left at each - * level upwards until root is reached. - * Data is copied into the @mast->bn. - * @mast: The maple_subtree_state. - */ -static inline -bool mast_spanning_rebalance(struct maple_subtree_state *mast) -{ - struct ma_state r_tmp = *mast->orig_r; - struct ma_state l_tmp = *mast->orig_l; - unsigned char depth = 0; - - do { - mas_ascend(mast->orig_r); - mas_ascend(mast->orig_l); - depth++; - if (mast->orig_r->offset < mas_data_end(mast->orig_r)) { - mast->orig_r->offset++; - do { - mas_descend(mast->orig_r); - mast->orig_r->offset = 0; - } while (--depth); - - mast_rebalance_next(mast); - *mast->orig_l = l_tmp; - return true; - } else if (mast->orig_l->offset != 0) { - mast->orig_l->offset--; - do { - mas_descend(mast->orig_l); - mast->orig_l->offset = - mas_data_end(mast->orig_l); - } while (--depth); - - mast_rebalance_prev(mast); - *mast->orig_r = r_tmp; - return true; - } - } while (!mte_is_root(mast->orig_r->node)); - - *mast->orig_r = r_tmp; - *mast->orig_l = l_tmp; - return false; -} - -/* - * mast_ascend() - Ascend the original left and right maple states. - * @mast: the maple subtree state. - * - * Ascend the original left and right sides. Set the offsets to point to the - * data already in the new tree (@mast->l and @mast->r). - */ -static inline void mast_ascend(struct maple_subtree_state *mast) -{ - MA_WR_STATE(wr_mas, mast->orig_r, NULL); - mas_ascend(mast->orig_l); - mas_ascend(mast->orig_r); - - mast->orig_r->offset = 0; - mast->orig_r->index = mast->r->max; - /* last should be larger than or equal to index */ - if (mast->orig_r->last < mast->orig_r->index) - mast->orig_r->last = mast->orig_r->index; - - wr_mas.type = mte_node_type(mast->orig_r->node); - mas_wr_node_walk(&wr_mas); - /* Set up the left side of things */ - mast->orig_l->offset = 0; - mast->orig_l->index = mast->l->min; - wr_mas.mas = mast->orig_l; - wr_mas.type = mte_node_type(mast->orig_l->node); - mas_wr_node_walk(&wr_mas); - - mast->bn->type = wr_mas.type; -} - -/* - * mas_new_ma_node() - Create and return a new maple node. Helper function. - * @mas: the maple state with the allocations. - * @b_node: the maple_big_node with the type encoding. - * - * Use the node type from the maple_big_node to allocate a new node from the - * ma_state. This function exists mainly for code readability. - * - * Return: A new maple encoded node - */ -static inline struct maple_enode -*mas_new_ma_node(struct ma_state *mas, struct maple_big_node *b_node) -{ - return mt_mk_node(ma_mnode_ptr(mas_pop_node(mas)), b_node->type); -} - -/* - * mas_mab_to_node() - Set up right and middle nodes - * - * @mas: the maple state that contains the allocations. - * @b_node: the node which contains the data. - * @left: The pointer which will have the left node - * @right: The pointer which may have the right node - * @middle: the pointer which may have the middle node (rare) - * @mid_split: the split location for the middle node - * - * Return: the split of left. - */ -static inline unsigned char mas_mab_to_node(struct ma_state *mas, - struct maple_big_node *b_node, struct maple_enode **left, - struct maple_enode **right, struct maple_enode **middle, - unsigned char *mid_split) -{ - unsigned char split = 0; - unsigned char slot_count = mt_slots[b_node->type]; - - *left = mas_new_ma_node(mas, b_node); - *right = NULL; - *middle = NULL; - *mid_split = 0; - - if (b_node->b_end < slot_count) { - split = b_node->b_end; - } else { - split = mab_calc_split(mas, b_node, mid_split); - *right = mas_new_ma_node(mas, b_node); - } - - if (*mid_split) - *middle = mas_new_ma_node(mas, b_node); - - return split; - -} - -/* - * mab_set_b_end() - Add entry to b_node at b_node->b_end and increment the end - * pointer. - * @b_node: the big node to add the entry - * @mas: the maple state to get the pivot (mas->max) - * @entry: the entry to add, if NULL nothing happens. - */ -static inline void mab_set_b_end(struct maple_big_node *b_node, - struct ma_state *mas, - void *entry) -{ - if (!entry) - return; - - b_node->slot[b_node->b_end] = entry; - if (mt_is_alloc(mas->tree)) - b_node->gap[b_node->b_end] = mas_max_gap(mas); - b_node->pivot[b_node->b_end++] = mas->max; -} - -/* - * mas_set_split_parent() - combine_then_separate helper function. Sets the parent - * of @mas->node to either @left or @right, depending on @slot and @split - * - * @mas: the maple state with the node that needs a parent - * @left: possible parent 1 - * @right: possible parent 2 - * @slot: the slot the mas->node was placed - * @split: the split location between @left and @right - */ -static inline void mas_set_split_parent(struct ma_state *mas, - struct maple_enode *left, - struct maple_enode *right, - unsigned char *slot, unsigned char split) -{ - if (mas_is_none(mas)) - return; - - if ((*slot) <= split) - mas_set_parent(mas, mas->node, left, *slot); - else if (right) - mas_set_parent(mas, mas->node, right, (*slot) - split - 1); - - (*slot)++; -} - -/* - * mte_mid_split_check() - Check if the next node passes the mid-split - * @l: Pointer to left encoded maple node. - * @m: Pointer to middle encoded maple node. - * @r: Pointer to right encoded maple node. - * @slot: The offset - * @split: The split location. - * @mid_split: The middle split. - */ -static inline void mte_mid_split_check(struct maple_enode **l, - struct maple_enode **r, - struct maple_enode *right, - unsigned char slot, - unsigned char *split, - unsigned char mid_split) -{ - if (*r == right) - return; - - if (slot < mid_split) - return; - - *l = *r; - *r = right; - *split = mid_split; -} - static inline void rebalance_sib(struct ma_state *parent, struct ma_state *sib) { *sib = *parent; @@ -2356,43 +1771,6 @@ void spanning_sib(struct ma_wr_state *l_wr_mas, WARN_ON_ONCE(1); } -/* - * mast_set_split_parents() - Helper function to set three nodes parents. Slot - * is taken from @mast->l. - * @mast: the maple subtree state - * @left: the left node - * @right: the right node - * @split: the split location. - */ -static inline void mast_set_split_parents(struct maple_subtree_state *mast, - struct maple_enode *left, - struct maple_enode *middle, - struct maple_enode *right, - unsigned char split, - unsigned char mid_split) -{ - unsigned char slot; - struct maple_enode *l = left; - struct maple_enode *r = right; - - if (mas_is_none(mast->l)) - return; - - if (middle) - r = middle; - - slot = mast->l->offset; - - mte_mid_split_check(&l, &r, right, slot, &split, mid_split); - mas_set_split_parent(mast->l, l, r, &slot, split); - - mte_mid_split_check(&l, &r, right, slot, &split, mid_split); - mas_set_split_parent(mast->m, l, r, &slot, split); - - mte_mid_split_check(&l, &r, right, slot, &split, mid_split); - mas_set_split_parent(mast->r, l, r, &slot, split); -} - /* * mas_topiary_node() - Dispose of a single node * @mas: The maple state for pushing nodes @@ -2648,103 +2026,6 @@ void node_finalise(struct maple_node *node, enum maple_type mt, ma_set_meta(node, mt, gap_slot, end - 1); } -/* - * mast_cp_to_nodes() - Copy data out to nodes. - * @mast: The maple subtree state - * @left: The left encoded maple node - * @middle: The middle encoded maple node - * @right: The right encoded maple node - * @split: The location to split between left and (middle ? middle : right) - * @mid_split: The location to split between middle and right. - */ -static inline void mast_cp_to_nodes(struct maple_subtree_state *mast, - struct maple_enode *left, struct maple_enode *middle, - struct maple_enode *right, unsigned char split, unsigned char mid_split) -{ - bool new_lmax = true; - - mas_node_or_none(mast->l, left); - mas_node_or_none(mast->m, middle); - mas_node_or_none(mast->r, right); - - mast->l->min = mast->orig_l->min; - if (split == mast->bn->b_end) { - mast->l->max = mast->orig_r->max; - new_lmax = false; - } - - mab_mas_cp(mast->bn, 0, split, mast->l, new_lmax); - - if (middle) { - mab_mas_cp(mast->bn, 1 + split, mid_split, mast->m, true); - mast->m->min = mast->bn->pivot[split] + 1; - split = mid_split; - } - - mast->r->max = mast->orig_r->max; - if (right) { - mab_mas_cp(mast->bn, 1 + split, mast->bn->b_end, mast->r, false); - mast->r->min = mast->bn->pivot[split] + 1; - } -} - -/* - * mast_combine_cp_left - Copy in the original left side of the tree into the - * combined data set in the maple subtree state big node. - * @mast: The maple subtree state - */ -static inline void mast_combine_cp_left(struct maple_subtree_state *mast) -{ - unsigned char l_slot = mast->orig_l->offset; - - if (!l_slot) - return; - - mas_mab_cp(mast->orig_l, 0, l_slot - 1, mast->bn, 0); -} - -/* - * mast_combine_cp_right: Copy in the original right side of the tree into the - * combined data set in the maple subtree state big node. - * @mast: The maple subtree state - */ -static inline void mast_combine_cp_right(struct maple_subtree_state *mast) -{ - if (mast->bn->pivot[mast->bn->b_end - 1] >= mast->orig_r->max) - return; - - mas_mab_cp(mast->orig_r, mast->orig_r->offset + 1, - mt_slot_count(mast->orig_r->node), mast->bn, - mast->bn->b_end); - mast->orig_r->last = mast->orig_r->max; -} - -/* - * mast_sufficient: Check if the maple subtree state has enough data in the big - * node to create at least one sufficient node - * @mast: the maple subtree state - */ -static inline bool mast_sufficient(struct maple_subtree_state *mast) -{ - if (mast->bn->b_end > mt_min_slot_count(mast->orig_l->node)) - return true; - - return false; -} - -/* - * mast_overflow: Check if there is too much data in the subtree state for a - * single node. - * @mast: The maple subtree state - */ -static inline bool mast_overflow(struct maple_subtree_state *mast) -{ - if (mast->bn->b_end > mt_slot_count(mast->orig_l->node)) - return true; - - return false; -} - static inline void *mtree_range_walk(struct ma_state *mas) { unsigned long *pivots; @@ -3304,158 +2585,6 @@ static inline void cp_dst_to_slots(struct maple_copy *cp, unsigned long min, cp->max = max; } -static void mas_spanning_rebalance_loop(struct ma_state *mas, - struct maple_subtree_state *mast, unsigned char count) -{ - - unsigned char split, mid_split; - unsigned char slot = 0; - unsigned char new_height = 0; /* used if node is a new root */ - struct maple_enode *left = NULL, *middle = NULL, *right = NULL; - struct maple_enode *old_enode; - - /* - * Each level of the tree is examined and balanced, pushing data to the left or - * right, or rebalancing against left or right nodes is employed to avoid - * rippling up the tree to limit the amount of churn. Once a new sub-section of - * the tree is created, there may be a mix of new and old nodes. The old nodes - * will have the incorrect parent pointers and currently be in two trees: the - * original tree and the partially new tree. To remedy the parent pointers in - * the old tree, the new data is swapped into the active tree and a walk down - * the tree is performed and the parent pointers are updated. - * See mas_topiary_replace() for more information. - */ - while (count--) { - mast->bn->b_end--; - mast->bn->type = mte_node_type(mast->orig_l->node); - split = mas_mab_to_node(mas, mast->bn, &left, &right, &middle, - &mid_split); - mast_set_split_parents(mast, left, middle, right, split, - mid_split); - mast_cp_to_nodes(mast, left, middle, right, split, mid_split); - new_height++; - - /* - * Copy data from next level in the tree to mast->bn from next - * iteration - */ - memset(mast->bn, 0, sizeof(struct maple_big_node)); - mast->bn->type = mte_node_type(left); - - /* Root already stored in l->node. */ - if (mas_is_root_limits(mast->l)) - goto new_root; - - mast_ascend(mast); - mast_combine_cp_left(mast); - mast->l->offset = mast->bn->b_end; - mab_set_b_end(mast->bn, mast->l, left); - mab_set_b_end(mast->bn, mast->m, middle); - mab_set_b_end(mast->bn, mast->r, right); - - /* Copy anything necessary out of the right node. */ - mast_combine_cp_right(mast); - mast->orig_l->last = mast->orig_l->max; - - if (mast_sufficient(mast)) { - if (mast_overflow(mast)) - continue; - - if (mast->orig_l->node == mast->orig_r->node) { - /* - * The data in b_node should be stored in one - * node and in the tree - */ - slot = mast->l->offset; - break; - } - - continue; - } - - /* May be a new root stored in mast->bn */ - if (mas_is_root_limits(mast->orig_l)) - break; - - mast_spanning_rebalance(mast); - - /* rebalancing from other nodes may require another loop. */ - if (!count) - count++; - } - - mast->l->node = mt_mk_node(ma_mnode_ptr(mas_pop_node(mas)), - mte_node_type(mast->orig_l->node)); - - mab_mas_cp(mast->bn, 0, mt_slots[mast->bn->type] - 1, mast->l, true); - new_height++; - mas_set_parent(mas, left, mast->l->node, slot); - if (middle) - mas_set_parent(mas, middle, mast->l->node, ++slot); - - if (right) - mas_set_parent(mas, right, mast->l->node, ++slot); - - if (mas_is_root_limits(mast->l)) { -new_root: - mas_mn(mast->l)->parent = ma_parent_ptr(mas_tree_parent(mas)); - while (!mte_is_root(mast->orig_l->node)) - mast_ascend(mast); - } else { - mas_mn(mast->l)->parent = mas_mn(mast->orig_l)->parent; - } - - old_enode = mast->orig_l->node; - mas->depth = mast->l->depth; - mas->node = mast->l->node; - mas->min = mast->l->min; - mas->max = mast->l->max; - mas->offset = mast->l->offset; - mas_wmb_replace(mas, old_enode, new_height); - mtree_range_walk(mas); -} - -/* - * mas_spanning_rebalance() - Rebalance across two nodes which may not be peers. - * @mas: The starting maple state - * @mast: The maple_subtree_state, keeps track of 4 maple states. - * @count: The estimated count of iterations needed. - * - * Follow the tree upwards from @l_mas and @r_mas for @count, or until the root - * is hit. First @b_node is split into two entries which are inserted into the - * next iteration of the loop. @b_node is returned populated with the final - * iteration. @mas is used to obtain allocations. orig_l_mas keeps track of the - * nodes that will remain active by using orig_l_mas->index and orig_l_mas->last - * to account of what has been copied into the new sub-tree. The update of - * orig_l_mas->last is used in mas_consume to find the slots that will need to - * be either freed or destroyed. orig_l_mas->depth keeps track of the height of - * the new sub-tree in case the sub-tree becomes the full tree. - */ -static void mas_spanning_rebalance(struct ma_state *mas, - struct maple_subtree_state *mast, unsigned char count) -{ - - MA_STATE(l_mas, mas->tree, mas->index, mas->index); - MA_STATE(r_mas, mas->tree, mas->index, mas->last); - MA_STATE(m_mas, mas->tree, mas->index, mas->index); - - /* - * The tree needs to be rebalanced and leaves need to be kept at the same level. - * Rebalancing is done by use of the ``struct maple_topiary``. - */ - mast->l = &l_mas; - mast->m = &m_mas; - mast->r = &r_mas; - l_mas.status = r_mas.status = m_mas.status = ma_none; - - /* Check if this is not root and has sufficient data. */ - if (((mast->orig_l->min != 0) || (mast->orig_r->max != ULONG_MAX)) && - unlikely(mast->bn->b_end <= mt_min_slots[mast->bn->type])) - mast_spanning_rebalance(mast); - - mas_spanning_rebalance_loop(mas, mast, count); -} - static inline bool cp_is_new_root(struct maple_copy *cp, struct ma_state *mas) { if (cp->min || cp->max != ULONG_MAX) @@ -3594,319 +2723,6 @@ static inline bool rebalance_ascend(struct maple_copy *cp, return true; } -/* - * mas_rebalance() - Rebalance a given node. - * @mas: The maple state - * @b_node: The big maple node. - * - * Rebalance two nodes into a single node or two new nodes that are sufficient. - * Continue upwards until tree is sufficient. - */ -static inline void mas_rebalance(struct ma_state *mas, - struct maple_big_node *b_node) -{ - char empty_count = mas_mt_height(mas); - struct maple_subtree_state mast; - unsigned char shift, b_end = ++b_node->b_end; - - MA_STATE(l_mas, mas->tree, mas->index, mas->last); - MA_STATE(r_mas, mas->tree, mas->index, mas->last); - - trace_ma_op(TP_FCT, mas); - - /* - * Rebalancing occurs if a node is insufficient. Data is rebalanced - * against the node to the right if it exists, otherwise the node to the - * left of this node is rebalanced against this node. If rebalancing - * causes just one node to be produced instead of two, then the parent - * is also examined and rebalanced if it is insufficient. Every level - * tries to combine the data in the same way. If one node contains the - * entire range of the tree, then that node is used as a new root node. - */ - - mast.orig_l = &l_mas; - mast.orig_r = &r_mas; - mast.bn = b_node; - mast.bn->type = mte_node_type(mas->node); - - l_mas = r_mas = *mas; - - if (mas_next_sibling(&r_mas)) { - mas_mab_cp(&r_mas, 0, mt_slot_count(r_mas.node), b_node, b_end); - r_mas.last = r_mas.index = r_mas.max; - } else { - mas_prev_sibling(&l_mas); - shift = mas_data_end(&l_mas) + 1; - mab_shift_right(b_node, shift); - mas->offset += shift; - mas_mab_cp(&l_mas, 0, shift - 1, b_node, 0); - b_node->b_end = shift + b_end; - l_mas.index = l_mas.last = l_mas.min; - } - - return mas_spanning_rebalance(mas, &mast, empty_count); -} - -/* - * mas_split_final_node() - Split the final node in a subtree operation. - * @mast: the maple subtree state - * @mas: The maple state - */ -static inline void mas_split_final_node(struct maple_subtree_state *mast, - struct ma_state *mas) -{ - struct maple_enode *ancestor; - - if (mte_is_root(mas->node)) { - if (mt_is_alloc(mas->tree)) - mast->bn->type = maple_arange_64; - else - mast->bn->type = maple_range_64; - } - /* - * Only a single node is used here, could be root. - * The Big_node data should just fit in a single node. - */ - ancestor = mas_new_ma_node(mas, mast->bn); - mas_set_parent(mas, mast->l->node, ancestor, mast->l->offset); - mas_set_parent(mas, mast->r->node, ancestor, mast->r->offset); - mte_to_node(ancestor)->parent = mas_mn(mas)->parent; - - mast->l->node = ancestor; - mab_mas_cp(mast->bn, 0, mt_slots[mast->bn->type] - 1, mast->l, true); - mas->offset = mast->bn->b_end - 1; -} - -/* - * mast_fill_bnode() - Copy data into the big node in the subtree state - * @mast: The maple subtree state - * @mas: the maple state - * @skip: The number of entries to skip for new nodes insertion. - */ -static inline void mast_fill_bnode(struct maple_subtree_state *mast, - struct ma_state *mas, - unsigned char skip) -{ - bool cp = true; - unsigned char split; - - memset(mast->bn, 0, sizeof(struct maple_big_node)); - - if (mte_is_root(mas->node)) { - cp = false; - } else { - mas_ascend(mas); - mas->offset = mte_parent_slot(mas->node); - } - - if (cp && mast->l->offset) - mas_mab_cp(mas, 0, mast->l->offset - 1, mast->bn, 0); - - split = mast->bn->b_end; - mab_set_b_end(mast->bn, mast->l, mast->l->node); - mast->r->offset = mast->bn->b_end; - mab_set_b_end(mast->bn, mast->r, mast->r->node); - if (mast->bn->pivot[mast->bn->b_end - 1] == mas->max) - cp = false; - - if (cp) - mas_mab_cp(mas, split + skip, mt_slot_count(mas->node) - 1, - mast->bn, mast->bn->b_end); - - mast->bn->b_end--; - mast->bn->type = mte_node_type(mas->node); -} - -/* - * mast_split_data() - Split the data in the subtree state big node into regular - * nodes. - * @mast: The maple subtree state - * @mas: The maple state - * @split: The location to split the big node - */ -static inline void mast_split_data(struct maple_subtree_state *mast, - struct ma_state *mas, unsigned char split) -{ - unsigned char p_slot; - - mab_mas_cp(mast->bn, 0, split, mast->l, true); - mte_set_pivot(mast->r->node, 0, mast->r->max); - mab_mas_cp(mast->bn, split + 1, mast->bn->b_end, mast->r, false); - mast->l->offset = mte_parent_slot(mas->node); - mast->l->max = mast->bn->pivot[split]; - mast->r->min = mast->l->max + 1; - if (mte_is_leaf(mas->node)) - return; - - p_slot = mast->orig_l->offset; - mas_set_split_parent(mast->orig_l, mast->l->node, mast->r->node, - &p_slot, split); - mas_set_split_parent(mast->orig_r, mast->l->node, mast->r->node, - &p_slot, split); -} - -/* - * mas_push_data() - Instead of splitting a node, it is beneficial to push the - * data to the right or left node if there is room. - * @mas: The maple state - * @mast: The maple subtree state - * @left: Push left or not. - * - * Keeping the height of the tree low means faster lookups. - * - * Return: True if pushed, false otherwise. - */ -static inline bool mas_push_data(struct ma_state *mas, - struct maple_subtree_state *mast, bool left) -{ - unsigned char slot_total = mast->bn->b_end; - unsigned char end, space, split; - - MA_STATE(tmp_mas, mas->tree, mas->index, mas->last); - tmp_mas = *mas; - tmp_mas.depth = mast->l->depth; - - if (left && !mas_prev_sibling(&tmp_mas)) - return false; - else if (!left && !mas_next_sibling(&tmp_mas)) - return false; - - end = mas_data_end(&tmp_mas); - slot_total += end; - space = 2 * mt_slot_count(mas->node) - 2; - /* -2 instead of -1 to ensure there isn't a triple split */ - if (ma_is_leaf(mast->bn->type)) - space--; - - if (mas->max == ULONG_MAX) - space--; - - if (slot_total >= space) - return false; - - /* Get the data; Fill mast->bn */ - mast->bn->b_end++; - if (left) { - mab_shift_right(mast->bn, end + 1); - mas_mab_cp(&tmp_mas, 0, end, mast->bn, 0); - mast->bn->b_end = slot_total + 1; - } else { - mas_mab_cp(&tmp_mas, 0, end, mast->bn, mast->bn->b_end); - } - - /* Configure mast for splitting of mast->bn */ - split = mt_slots[mast->bn->type] - 2; - if (left) { - /* Switch mas to prev node */ - *mas = tmp_mas; - /* Start using mast->l for the left side. */ - tmp_mas.node = mast->l->node; - *mast->l = tmp_mas; - } else { - tmp_mas.node = mast->r->node; - *mast->r = tmp_mas; - split = slot_total - split; - } - split = mab_no_null_split(mast->bn, split, mt_slots[mast->bn->type]); - /* Update parent slot for split calculation. */ - if (left) - mast->orig_l->offset += end + 1; - - mast_split_data(mast, mas, split); - mast_fill_bnode(mast, mas, 2); - mas_split_final_node(mast, mas); - return true; -} - -/* - * mas_split() - Split data that is too big for one node into two. - * @mas: The maple state - * @b_node: The maple big node - */ -static void mas_split(struct ma_state *mas, struct maple_big_node *b_node) -{ - struct maple_subtree_state mast; - int height = 0; - unsigned int orig_height = mas_mt_height(mas); - unsigned char mid_split, split = 0; - struct maple_enode *old; - - /* - * Splitting is handled differently from any other B-tree; the Maple - * Tree splits upwards. Splitting up means that the split operation - * occurs when the walk of the tree hits the leaves and not on the way - * down. The reason for splitting up is that it is impossible to know - * how much space will be needed until the leaf is (or leaves are) - * reached. Since overwriting data is allowed and a range could - * overwrite more than one range or result in changing one entry into 3 - * entries, it is impossible to know if a split is required until the - * data is examined. - * - * Splitting is a balancing act between keeping allocations to a minimum - * and avoiding a 'jitter' event where a tree is expanded to make room - * for an entry followed by a contraction when the entry is removed. To - * accomplish the balance, there are empty slots remaining in both left - * and right nodes after a split. - */ - MA_STATE(l_mas, mas->tree, mas->index, mas->last); - MA_STATE(r_mas, mas->tree, mas->index, mas->last); - MA_STATE(prev_l_mas, mas->tree, mas->index, mas->last); - MA_STATE(prev_r_mas, mas->tree, mas->index, mas->last); - - trace_ma_op(TP_FCT, mas); - - mast.l = &l_mas; - mast.r = &r_mas; - mast.orig_l = &prev_l_mas; - mast.orig_r = &prev_r_mas; - mast.bn = b_node; - - while (height++ <= orig_height) { - if (mt_slots[b_node->type] > b_node->b_end) { - mas_split_final_node(&mast, mas); - break; - } - - l_mas = r_mas = *mas; - l_mas.node = mas_new_ma_node(mas, b_node); - r_mas.node = mas_new_ma_node(mas, b_node); - /* - * Another way that 'jitter' is avoided is to terminate a split up early if the - * left or right node has space to spare. This is referred to as "pushing left" - * or "pushing right" and is similar to the B* tree, except the nodes left or - * right can rarely be reused due to RCU, but the ripple upwards is halted which - * is a significant savings. - */ - /* Try to push left. */ - if (mas_push_data(mas, &mast, true)) { - height++; - break; - } - /* Try to push right. */ - if (mas_push_data(mas, &mast, false)) { - height++; - break; - } - - split = mab_calc_split(mas, b_node, &mid_split); - mast_split_data(&mast, mas, split); - /* - * Usually correct, mab_mas_cp in the above call overwrites - * r->max. - */ - mast.r->max = mas->max; - mast_fill_bnode(&mast, mas, 1); - prev_l_mas = *mast.l; - prev_r_mas = *mast.r; - } - - /* Set the original node as dead */ - old = mas->node; - mas->node = l_mas.node; - mas_wmb_replace(mas, old, height); - mtree_range_walk(mas); -} - /* * mas_root_expand() - Expand a root to a node * @mas: The maple state -- 2.47.3
{ "author": "\"Liam R. Howlett\" <Liam.Howlett@oracle.com>", "date": "Fri, 30 Jan 2026 15:59:32 -0500", "thread_id": "20260202103154.ad1aa05611c79d21b070a861@linux-foundation.org.mbox.gz" }
lkml
[PATCH v3 00/30] maple_tree: Replace big node with maple copy
The big node struct was created for simplicity of splitting, rebalancing, and spanning store operations by using a copy buffer to create the data necessary prior to breaking it up into 256B nodes. Certain operations were rather tricky due to the restriction of keeping NULL entries together and never at the end of a node (except the right-most node). The big node struct is incompatible with future features that are currently in development. Specifically different node types and different data type sizes for pivots. The big node struct was also a stack variable, which caused issues with certain configurations of kernel build. This series removes big node by introducing another node type which will never be written to the tree: maple_copy. The maple copy node operates more like a scatter/gather operation with a number of sources and destinations of allocated nodes. The sources are copied to the destinations, in turn, until the sources are exhausted. The destination is changed if it is filled or the split location is reached prior to the source data end. New data is inserted by using the maple copy node itself as a source with up to 3 slots and pivots. The data in the maple copy node is the data being written to the tree along with any fragment of the range(s) being overwritten. As with all nodes, the maple copy node is of size 256B. Using a node type allows for the copy operation to treat the new data stored in the maple copy node the same as any other source node. Analysis of the runtime shows no regression or benefit of removing the larger stack structure. The motivation is the ground work to use new node types and to help those with odd configurations that have had issues. The change was tested by myself using mm_tests on amd64 and by Suren on android (arm64). Limited testing on s390 qemu was also performed using stress-ng on the virtual memory, which should cover many corner cases. v1: https://lore.kernel.org/all/20260115193647.1695937-1-Liam.Howlett@oracle.com/ v2: https://lore.kernel.org/all/20260121164526.2093265-1-Liam.Howlett@oracle.com/ Changes since v2: - Whitespace fix in rebalance_data() - Added ma_init_slot() for cleaner casting during RCU_INIT_POINTER(). Thanks test robot & SK [1] - Fixed off-by-one in rebalance_data() which caused node overuse, reported by linux-next. Thanks Mark [2] - Added new patch to reproducer to test cases in userspace testing for the rebalance_data() off-by-one [1]. https://lore.kernel.org/all/20260122055516.69335-1-sj@kernel.org/ [2]. https://lore.kernel.org/all/bd1c3356-11a1-4d0b-bf58-47eb21bfd24d@sirena.org.uk/ Liam R. Howlett (30): maple_tree: Fix mas_dup_alloc() sparse warning maple_tree: Move mas_spanning_rebalance loop to function maple_tree: Extract use of big node from mas_wr_spanning_store() maple_tree: Remove unnecessary assignment of orig_l index maple_tree: inline mas_spanning_rebalance() into mas_wr_spanning_rebalance() maple_tree: Make ma_wr_states reliable for reuse in spanning store maple_tree: Remove l_wr_mas from mas_wr_spanning_rebalance maple_tree: Don't pass through height in mas_wr_spanning_store maple_tree: Move maple_subtree_state from mas_wr_spanning_store to mas_wr_spanning_rebalance maple_tree: Correct right ma_wr_state end pivot in mas_wr_spanning_store() maple_tree: Introduce maple_copy node and use it in mas_spanning_rebalance() maple_tree: Testing update for spanning store maple_tree: Inline mas_spanning_rebalance_loop() into mas_wr_spanning_rebalance() maple_tree: Change initial big node setup in mas_wr_spanning_rebalance() maple_tree: Introduce ma_leaf_max_gap() maple_tree: Add gap support, slot and pivot sizes for maple copy maple_tree: Start using maple copy node for destination maple_tree: inline mas_wr_spanning_rebalance() maple_tree: Remove unnecessary return statements maple_tree: Separate wr_split_store and wr_rebalance store type code path maple_tree: Add cp_is_new_root() helper maple_tree: Use maple copy node for mas_wr_rebalance() operation maple_tree: Add test for rebalance calculation off-by-one maple_tree: Add copy_tree_location() helper maple_tree: Add cp_converged() helper maple_tree: Use maple copy node for mas_wr_split() maple_tree: Remove maple big node and subtree structs maple_tree: Pass maple copy node to mas_wmb_replace() maple_tree: Don't pass end to mas_wr_append() maple_tree: Clean up mas_wr_node_store() include/linux/maple_tree.h | 42 + lib/maple_tree.c | 2134 +++++++++++++----------------- lib/test_maple_tree.c | 55 +- tools/testing/radix-tree/maple.c | 308 ++++- 4 files changed, 1340 insertions(+), 1199 deletions(-) -- 2.47.3
On Fri, 30 Jan 2026 15:59:05 -0500 "Liam R. Howlett" <Liam.Howlett@oracle.com> wrote: Updated, thanks. What are your thoughts on adding this to 6.19? I'd expect to move it into mm-stable Feb 17ish. Below is how v3 altered mm.git: --- a/lib/maple_tree.c~b +++ a/lib/maple_tree.c @@ -314,6 +314,13 @@ static inline struct maple_enode *mt_mk_ (type << MAPLE_ENODE_TYPE_SHIFT) | MAPLE_ENODE_NULL); } +static inline void ma_init_slot(void __rcu **slot, const struct maple_node *mn, + const enum maple_type mt) +{ + /* WARNING: this is unsafe if the slot is exposed to readers. */ + RCU_INIT_POINTER(*slot, (void *)mt_mk_node(mn, mt)); +} + static inline void *mte_mk_root(const struct maple_enode *node) { return (void *)((unsigned long)node | MAPLE_ROOT_NODE); @@ -2231,7 +2238,7 @@ static inline void rebalance_data(struct { cp_data_calc(cp, wr_mas, wr_mas); sib->end = 0; - if (cp->data >= mt_slots[wr_mas->type]) { + if (cp->data > mt_slots[wr_mas->type]) { push_data_sib(cp, wr_mas->mas, sib, parent); if (sib->end) goto use_sib; @@ -2246,7 +2253,8 @@ static inline void rebalance_data(struct return; use_sib: - cp->data += sib->end + 1; + + cp->data += sib->end + 1; } /* @@ -2553,7 +2561,7 @@ static inline void cp_dst_to_slots(struc * read-side operations that can view them until they are * inserted into the tree after an rcu_assign_pointer() call. */ - RCU_INIT_POINTER(cp->slot[d], (void *)mt_mk_node(mn, mt)); + ma_init_slot(&cp->slot[d], mn, mt); cp->pivot[d] = slot_max; if (mt_is_alloc(mas->tree)) { if (ma_is_leaf(mt)) { @@ -2603,8 +2611,7 @@ static inline bool cp_is_new_root(struct * read-side operations that can view it until it is insert into * the tree after an rcu_assign_pointer() call. */ - RCU_INIT_POINTER(cp->slot[0], - (void *)mt_mk_node(cp->dst[0].node, mt)); + RCU_INIT_POINTER(cp->slot[0], mt_mk_node(cp->dst[0].node, mt)); cp->height++; } WARN_ON_ONCE(cp->dst[0].node != mte_to_node( --- a/tools/testing/radix-tree/maple.c~b +++ a/tools/testing/radix-tree/maple.c @@ -35899,6 +35899,127 @@ unlock: return ret; } +static noinline void __init check_erase_rebalance(struct maple_tree *mt) +{ + unsigned long val; + void *enode; + int ret; + + MA_STATE(mas, mt, 0, 0); + + /* + * During removal of big node, the rebalance started going too high, + * which resulted in too many nodes trying to be used. + * + * Create a rebalance which results in an exactly full parent (0-9) that + * does not need to be rebalanced. This required two full levels, + * followed by an insufficient level which will be rebalanced into two + * nodes, finally leaves that need to be rebalanced into one node. + * + * The bugs tree: + * root 4 Label R + * /\ /\ + * 9 X F + * /\ /\ / + * 9 X E + * /\ /\ /\ + * 4 8 C D + * /\ /\ + * 6 9 A B + * ^ becomes 5 with the write. + * + * Below, the reconstruction leaves the root with 2 entries, the setup + * uses the letter labels above. + */ + + ret = build_full_tree(mt, MT_FLAGS_ALLOC_RANGE, 4); + MT_BUG_ON(mt, ret); + + /* Cheap expansion to 5 levels */ + mtree_store(mt, ULONG_MAX, xa_mk_value(0), GFP_KERNEL); + /* rcu is used to ensure node use */ + mt_set_in_rcu(mt); + mas_lock(&mas); + + /* Node A had 6 entries */ + mas_walk(&mas); + MAS_BUG_ON(&mas, mas_data_end(&mas) < 6); + while (mas_data_end(&mas) > 6) { + mas_erase(&mas); + mas_next(&mas, ULONG_MAX); + } + + /* Move to Node B */ + enode = (void*) mas.node; + while (mas.node == enode) + mas_next(&mas, ULONG_MAX); + + /* Node B had 9 entries */ + MAS_BUG_ON(&mas, mas_data_end(&mas) < 9); + while (mas_data_end(&mas) > 9) { + mas_erase(&mas); + mas_next(&mas, ULONG_MAX); + } + + /* Move to Node C */ + mas_ascend(&mas); + val = mas.max; + /* Adjust entries to be 4 */ + while (mas_data_end(&mas) > 4) { + mas_set(&mas, val); + mas_erase(&mas); + mas_prev(&mas, 0); + val = mas.index; + mas_ascend(&mas); + } + + /* Move to Node D */ + mas_ascend(&mas); + mas.offset = 1; + mas_descend(&mas); + val = mas.max; + /* Adjust entries to be 8 */ + while (mas_data_end(&mas) < 8) { + mas_set(&mas, val--); + mas_store_gfp(&mas, &mas, GFP_KERNEL); + mas_ascend(&mas); + } + + /* Move to Node E */ + mas_ascend(&mas); + val = mas.max; + MAS_BUG_ON(&mas, mas_data_end(&mas) > 9); + /* Adjust Node E to 9 entries */ + while (mas_data_end(&mas) < 9) { + mas_set(&mas, val--); + mas_store_gfp(&mas, &mas, GFP_KERNEL); + mas_ascend(&mas); + mas_ascend(&mas); + } + + /* Move to Node F */ + mas_ascend(&mas); + val = mas.max; + MAS_BUG_ON(&mas, mas_data_end(&mas) > 9); + /* Adjust Node F to 9 entries */ + while (mas_data_end(&mas) < 9) { + mas_set(&mas, val--); + mas_store_gfp(&mas, &mas, GFP_KERNEL); + mas_ascend(&mas); + mas_ascend(&mas); + mas_ascend(&mas); + } + + /* Test is set up, walk to first entry */ + mas_set(&mas, 0); + mas_next(&mas, ULONG_MAX); + /* overwrite the entry to cause a rebalance, which was 1 too few */ + mas_set_range(&mas, 0, mas.last); + mas_preallocate(&mas, NULL, GFP_KERNEL); + mas_store_prealloc(&mas, NULL); + mas_unlock(&mas); +} + static noinline void __init check_mtree_dup(struct maple_tree *mt) { DEFINE_MTREE(new); @@ -36260,6 +36381,10 @@ void farmer_tests(void) check_mtree_dup(&tree); mtree_destroy(&tree); + mt_init_flags(&tree, MT_FLAGS_ALLOC_RANGE); + check_erase_rebalance(&tree); + mtree_destroy(&tree); + /* RCU testing */ mt_init_flags(&tree, 0); check_erase_testset(&tree); _
{ "author": "Andrew Morton <akpm@linux-foundation.org>", "date": "Sat, 31 Jan 2026 12:27:24 -0800", "thread_id": "20260202103154.ad1aa05611c79d21b070a861@linux-foundation.org.mbox.gz" }
lkml
[PATCH v3 00/30] maple_tree: Replace big node with maple copy
The big node struct was created for simplicity of splitting, rebalancing, and spanning store operations by using a copy buffer to create the data necessary prior to breaking it up into 256B nodes. Certain operations were rather tricky due to the restriction of keeping NULL entries together and never at the end of a node (except the right-most node). The big node struct is incompatible with future features that are currently in development. Specifically different node types and different data type sizes for pivots. The big node struct was also a stack variable, which caused issues with certain configurations of kernel build. This series removes big node by introducing another node type which will never be written to the tree: maple_copy. The maple copy node operates more like a scatter/gather operation with a number of sources and destinations of allocated nodes. The sources are copied to the destinations, in turn, until the sources are exhausted. The destination is changed if it is filled or the split location is reached prior to the source data end. New data is inserted by using the maple copy node itself as a source with up to 3 slots and pivots. The data in the maple copy node is the data being written to the tree along with any fragment of the range(s) being overwritten. As with all nodes, the maple copy node is of size 256B. Using a node type allows for the copy operation to treat the new data stored in the maple copy node the same as any other source node. Analysis of the runtime shows no regression or benefit of removing the larger stack structure. The motivation is the ground work to use new node types and to help those with odd configurations that have had issues. The change was tested by myself using mm_tests on amd64 and by Suren on android (arm64). Limited testing on s390 qemu was also performed using stress-ng on the virtual memory, which should cover many corner cases. v1: https://lore.kernel.org/all/20260115193647.1695937-1-Liam.Howlett@oracle.com/ v2: https://lore.kernel.org/all/20260121164526.2093265-1-Liam.Howlett@oracle.com/ Changes since v2: - Whitespace fix in rebalance_data() - Added ma_init_slot() for cleaner casting during RCU_INIT_POINTER(). Thanks test robot & SK [1] - Fixed off-by-one in rebalance_data() which caused node overuse, reported by linux-next. Thanks Mark [2] - Added new patch to reproducer to test cases in userspace testing for the rebalance_data() off-by-one [1]. https://lore.kernel.org/all/20260122055516.69335-1-sj@kernel.org/ [2]. https://lore.kernel.org/all/bd1c3356-11a1-4d0b-bf58-47eb21bfd24d@sirena.org.uk/ Liam R. Howlett (30): maple_tree: Fix mas_dup_alloc() sparse warning maple_tree: Move mas_spanning_rebalance loop to function maple_tree: Extract use of big node from mas_wr_spanning_store() maple_tree: Remove unnecessary assignment of orig_l index maple_tree: inline mas_spanning_rebalance() into mas_wr_spanning_rebalance() maple_tree: Make ma_wr_states reliable for reuse in spanning store maple_tree: Remove l_wr_mas from mas_wr_spanning_rebalance maple_tree: Don't pass through height in mas_wr_spanning_store maple_tree: Move maple_subtree_state from mas_wr_spanning_store to mas_wr_spanning_rebalance maple_tree: Correct right ma_wr_state end pivot in mas_wr_spanning_store() maple_tree: Introduce maple_copy node and use it in mas_spanning_rebalance() maple_tree: Testing update for spanning store maple_tree: Inline mas_spanning_rebalance_loop() into mas_wr_spanning_rebalance() maple_tree: Change initial big node setup in mas_wr_spanning_rebalance() maple_tree: Introduce ma_leaf_max_gap() maple_tree: Add gap support, slot and pivot sizes for maple copy maple_tree: Start using maple copy node for destination maple_tree: inline mas_wr_spanning_rebalance() maple_tree: Remove unnecessary return statements maple_tree: Separate wr_split_store and wr_rebalance store type code path maple_tree: Add cp_is_new_root() helper maple_tree: Use maple copy node for mas_wr_rebalance() operation maple_tree: Add test for rebalance calculation off-by-one maple_tree: Add copy_tree_location() helper maple_tree: Add cp_converged() helper maple_tree: Use maple copy node for mas_wr_split() maple_tree: Remove maple big node and subtree structs maple_tree: Pass maple copy node to mas_wmb_replace() maple_tree: Don't pass end to mas_wr_append() maple_tree: Clean up mas_wr_node_store() include/linux/maple_tree.h | 42 + lib/maple_tree.c | 2134 +++++++++++++----------------- lib/test_maple_tree.c | 55 +- tools/testing/radix-tree/maple.c | 308 ++++- 4 files changed, 1340 insertions(+), 1199 deletions(-) -- 2.47.3
Hello, On Fri, 30 Jan 2026 15:59:26 -0500 "Liam R. Howlett" <Liam.Howlett@oracle.com> wrote: I just found the above makes my build test using an old version compiler fails. Fortunately, seems it is same to the one we discussed before [1], and same mitigation like below attached patch works, at least for my test setup. [1] https://lore.kernel.org/dwhxxuil4zkesmyj6xviyyyfedrcd65h6qd4bplmcrsg36purj@f523i7t6nxag Thanks, SJ [...] === >8 === From: SeongJae Park <sj@kernel.org> Date: Sat, 31 Jan 2026 16:02:56 -0800 Subject: [PATCH] lib/mape_tree: temporal build fix Without the fix, build with old compilers fails like below: CC lib/maple_tree.o In file included from .../arch/arm64/include/asm/rwonce.h:67, from .../include/linux/compiler.h:380, from .../include/linux/array_size.h:5, from .../include/linux/kernel.h:16, from .../include/linux/maple_tree.h:11, from .../lib/maple_tree.c:56: .../lib/maple_tree.c: In function 'cp_is_new_root': .../include/linux/rcupdate.h:555:36: error: dereferencing pointer to incomplete type 'struct maple_enode' 555 | #define RCU_INITIALIZER(v) (typeof(*(v)) __force __rcu *)(v) | ^~~~ .../include/asm-generic/rwonce.h:55:33: note: in definition of macro '__WRITE_ONCE' 55 | *(volatile typeof(x) *)&(x) = (val); \ | ^~~ .../include/linux/rcupdate.h:1046:3: note: in expansion of macro 'WRITE_ONCE' 1046 | WRITE_ONCE(p, RCU_INITIALIZER(v)); \ | ^~~~~~~~~~ .../include/linux/rcupdate.h:1046:17: note: in expansion of macro 'RCU_INITIALIZER' 1046 | WRITE_ONCE(p, RCU_INITIALIZER(v)); \ | ^~~~~~~~~~~~~~~ .../lib/maple_tree.c:3364:3: note: in expansion of macro 'RCU_INIT_POINTER' 3364 | RCU_INIT_POINTER(cp->slot[0], mt_mk_node(cp->dst[0].node, mt)); | ^~~~~~~~~~~~~~~~ Signed-off-by: SeongJae Park <sj@kernel.org> --- lib/maple_tree.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index c522419e99f4e..eb2855269332a 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -3361,7 +3361,8 @@ static inline bool cp_is_new_root(struct maple_copy *cp, struct ma_state *mas) * read-side operations that can view it until it is insert into * the tree after an rcu_assign_pointer() call. */ - RCU_INIT_POINTER(cp->slot[0], mt_mk_node(cp->dst[0].node, mt)); + RCU_INIT_POINTER(cp->slot[0], + (void *)mt_mk_node(cp->dst[0].node, mt)); cp->height++; } WARN_ON_ONCE(cp->dst[0].node != mte_to_node( -- 2.47.3
{ "author": "SeongJae Park <sj@kernel.org>", "date": "Sat, 31 Jan 2026 16:10:42 -0800", "thread_id": "20260202103154.ad1aa05611c79d21b070a861@linux-foundation.org.mbox.gz" }
lkml
[PATCH v3 00/30] maple_tree: Replace big node with maple copy
The big node struct was created for simplicity of splitting, rebalancing, and spanning store operations by using a copy buffer to create the data necessary prior to breaking it up into 256B nodes. Certain operations were rather tricky due to the restriction of keeping NULL entries together and never at the end of a node (except the right-most node). The big node struct is incompatible with future features that are currently in development. Specifically different node types and different data type sizes for pivots. The big node struct was also a stack variable, which caused issues with certain configurations of kernel build. This series removes big node by introducing another node type which will never be written to the tree: maple_copy. The maple copy node operates more like a scatter/gather operation with a number of sources and destinations of allocated nodes. The sources are copied to the destinations, in turn, until the sources are exhausted. The destination is changed if it is filled or the split location is reached prior to the source data end. New data is inserted by using the maple copy node itself as a source with up to 3 slots and pivots. The data in the maple copy node is the data being written to the tree along with any fragment of the range(s) being overwritten. As with all nodes, the maple copy node is of size 256B. Using a node type allows for the copy operation to treat the new data stored in the maple copy node the same as any other source node. Analysis of the runtime shows no regression or benefit of removing the larger stack structure. The motivation is the ground work to use new node types and to help those with odd configurations that have had issues. The change was tested by myself using mm_tests on amd64 and by Suren on android (arm64). Limited testing on s390 qemu was also performed using stress-ng on the virtual memory, which should cover many corner cases. v1: https://lore.kernel.org/all/20260115193647.1695937-1-Liam.Howlett@oracle.com/ v2: https://lore.kernel.org/all/20260121164526.2093265-1-Liam.Howlett@oracle.com/ Changes since v2: - Whitespace fix in rebalance_data() - Added ma_init_slot() for cleaner casting during RCU_INIT_POINTER(). Thanks test robot & SK [1] - Fixed off-by-one in rebalance_data() which caused node overuse, reported by linux-next. Thanks Mark [2] - Added new patch to reproducer to test cases in userspace testing for the rebalance_data() off-by-one [1]. https://lore.kernel.org/all/20260122055516.69335-1-sj@kernel.org/ [2]. https://lore.kernel.org/all/bd1c3356-11a1-4d0b-bf58-47eb21bfd24d@sirena.org.uk/ Liam R. Howlett (30): maple_tree: Fix mas_dup_alloc() sparse warning maple_tree: Move mas_spanning_rebalance loop to function maple_tree: Extract use of big node from mas_wr_spanning_store() maple_tree: Remove unnecessary assignment of orig_l index maple_tree: inline mas_spanning_rebalance() into mas_wr_spanning_rebalance() maple_tree: Make ma_wr_states reliable for reuse in spanning store maple_tree: Remove l_wr_mas from mas_wr_spanning_rebalance maple_tree: Don't pass through height in mas_wr_spanning_store maple_tree: Move maple_subtree_state from mas_wr_spanning_store to mas_wr_spanning_rebalance maple_tree: Correct right ma_wr_state end pivot in mas_wr_spanning_store() maple_tree: Introduce maple_copy node and use it in mas_spanning_rebalance() maple_tree: Testing update for spanning store maple_tree: Inline mas_spanning_rebalance_loop() into mas_wr_spanning_rebalance() maple_tree: Change initial big node setup in mas_wr_spanning_rebalance() maple_tree: Introduce ma_leaf_max_gap() maple_tree: Add gap support, slot and pivot sizes for maple copy maple_tree: Start using maple copy node for destination maple_tree: inline mas_wr_spanning_rebalance() maple_tree: Remove unnecessary return statements maple_tree: Separate wr_split_store and wr_rebalance store type code path maple_tree: Add cp_is_new_root() helper maple_tree: Use maple copy node for mas_wr_rebalance() operation maple_tree: Add test for rebalance calculation off-by-one maple_tree: Add copy_tree_location() helper maple_tree: Add cp_converged() helper maple_tree: Use maple copy node for mas_wr_split() maple_tree: Remove maple big node and subtree structs maple_tree: Pass maple copy node to mas_wmb_replace() maple_tree: Don't pass end to mas_wr_append() maple_tree: Clean up mas_wr_node_store() include/linux/maple_tree.h | 42 + lib/maple_tree.c | 2134 +++++++++++++----------------- lib/test_maple_tree.c | 55 +- tools/testing/radix-tree/maple.c | 308 ++++- 4 files changed, 1340 insertions(+), 1199 deletions(-) -- 2.47.3
* SeongJae Park <sj@kernel.org> [260131 19:10]: Thanks SJ. This is still with gcc 8.1.0? I thought debian stable would be old enough. Thanks, Liam
{ "author": "\"Liam R. Howlett\" <Liam.Howlett@oracle.com>", "date": "Mon, 2 Feb 2026 09:58:31 -0500", "thread_id": "20260202103154.ad1aa05611c79d21b070a861@linux-foundation.org.mbox.gz" }
lkml
[PATCH v3 00/30] maple_tree: Replace big node with maple copy
The big node struct was created for simplicity of splitting, rebalancing, and spanning store operations by using a copy buffer to create the data necessary prior to breaking it up into 256B nodes. Certain operations were rather tricky due to the restriction of keeping NULL entries together and never at the end of a node (except the right-most node). The big node struct is incompatible with future features that are currently in development. Specifically different node types and different data type sizes for pivots. The big node struct was also a stack variable, which caused issues with certain configurations of kernel build. This series removes big node by introducing another node type which will never be written to the tree: maple_copy. The maple copy node operates more like a scatter/gather operation with a number of sources and destinations of allocated nodes. The sources are copied to the destinations, in turn, until the sources are exhausted. The destination is changed if it is filled or the split location is reached prior to the source data end. New data is inserted by using the maple copy node itself as a source with up to 3 slots and pivots. The data in the maple copy node is the data being written to the tree along with any fragment of the range(s) being overwritten. As with all nodes, the maple copy node is of size 256B. Using a node type allows for the copy operation to treat the new data stored in the maple copy node the same as any other source node. Analysis of the runtime shows no regression or benefit of removing the larger stack structure. The motivation is the ground work to use new node types and to help those with odd configurations that have had issues. The change was tested by myself using mm_tests on amd64 and by Suren on android (arm64). Limited testing on s390 qemu was also performed using stress-ng on the virtual memory, which should cover many corner cases. v1: https://lore.kernel.org/all/20260115193647.1695937-1-Liam.Howlett@oracle.com/ v2: https://lore.kernel.org/all/20260121164526.2093265-1-Liam.Howlett@oracle.com/ Changes since v2: - Whitespace fix in rebalance_data() - Added ma_init_slot() for cleaner casting during RCU_INIT_POINTER(). Thanks test robot & SK [1] - Fixed off-by-one in rebalance_data() which caused node overuse, reported by linux-next. Thanks Mark [2] - Added new patch to reproducer to test cases in userspace testing for the rebalance_data() off-by-one [1]. https://lore.kernel.org/all/20260122055516.69335-1-sj@kernel.org/ [2]. https://lore.kernel.org/all/bd1c3356-11a1-4d0b-bf58-47eb21bfd24d@sirena.org.uk/ Liam R. Howlett (30): maple_tree: Fix mas_dup_alloc() sparse warning maple_tree: Move mas_spanning_rebalance loop to function maple_tree: Extract use of big node from mas_wr_spanning_store() maple_tree: Remove unnecessary assignment of orig_l index maple_tree: inline mas_spanning_rebalance() into mas_wr_spanning_rebalance() maple_tree: Make ma_wr_states reliable for reuse in spanning store maple_tree: Remove l_wr_mas from mas_wr_spanning_rebalance maple_tree: Don't pass through height in mas_wr_spanning_store maple_tree: Move maple_subtree_state from mas_wr_spanning_store to mas_wr_spanning_rebalance maple_tree: Correct right ma_wr_state end pivot in mas_wr_spanning_store() maple_tree: Introduce maple_copy node and use it in mas_spanning_rebalance() maple_tree: Testing update for spanning store maple_tree: Inline mas_spanning_rebalance_loop() into mas_wr_spanning_rebalance() maple_tree: Change initial big node setup in mas_wr_spanning_rebalance() maple_tree: Introduce ma_leaf_max_gap() maple_tree: Add gap support, slot and pivot sizes for maple copy maple_tree: Start using maple copy node for destination maple_tree: inline mas_wr_spanning_rebalance() maple_tree: Remove unnecessary return statements maple_tree: Separate wr_split_store and wr_rebalance store type code path maple_tree: Add cp_is_new_root() helper maple_tree: Use maple copy node for mas_wr_rebalance() operation maple_tree: Add test for rebalance calculation off-by-one maple_tree: Add copy_tree_location() helper maple_tree: Add cp_converged() helper maple_tree: Use maple copy node for mas_wr_split() maple_tree: Remove maple big node and subtree structs maple_tree: Pass maple copy node to mas_wmb_replace() maple_tree: Don't pass end to mas_wr_append() maple_tree: Clean up mas_wr_node_store() include/linux/maple_tree.h | 42 + lib/maple_tree.c | 2134 +++++++++++++----------------- lib/test_maple_tree.c | 55 +- tools/testing/radix-tree/maple.c | 308 ++++- 4 files changed, 1340 insertions(+), 1199 deletions(-) -- 2.47.3
* Andrew Morton <akpm@linux-foundation.org> [260131 15:27]: I think the chance of making 6.19 has passed. Can we please target getting this into testing in linux-next as soon as 6.19 ships? The priority for me is to ensure this is rock-solid prior to release. My concerns are corner cases and arch specific issues, which I can only do so much to mitigate on my own. My hope is that linux-next exposure will help with those concerns. So, at this point, I think the right call is delaying until after next Sunday. This looks correct. I did check my git diff here between my two branches and it is identical to what you sent out. ... I especially like the ASCII art in the test, totally worth the wait. Thanks, Liam
{ "author": "\"Liam R. Howlett\" <Liam.Howlett@oracle.com>", "date": "Mon, 2 Feb 2026 10:40:06 -0500", "thread_id": "20260202103154.ad1aa05611c79d21b070a861@linux-foundation.org.mbox.gz" }
lkml
[PATCH v3 00/30] maple_tree: Replace big node with maple copy
The big node struct was created for simplicity of splitting, rebalancing, and spanning store operations by using a copy buffer to create the data necessary prior to breaking it up into 256B nodes. Certain operations were rather tricky due to the restriction of keeping NULL entries together and never at the end of a node (except the right-most node). The big node struct is incompatible with future features that are currently in development. Specifically different node types and different data type sizes for pivots. The big node struct was also a stack variable, which caused issues with certain configurations of kernel build. This series removes big node by introducing another node type which will never be written to the tree: maple_copy. The maple copy node operates more like a scatter/gather operation with a number of sources and destinations of allocated nodes. The sources are copied to the destinations, in turn, until the sources are exhausted. The destination is changed if it is filled or the split location is reached prior to the source data end. New data is inserted by using the maple copy node itself as a source with up to 3 slots and pivots. The data in the maple copy node is the data being written to the tree along with any fragment of the range(s) being overwritten. As with all nodes, the maple copy node is of size 256B. Using a node type allows for the copy operation to treat the new data stored in the maple copy node the same as any other source node. Analysis of the runtime shows no regression or benefit of removing the larger stack structure. The motivation is the ground work to use new node types and to help those with odd configurations that have had issues. The change was tested by myself using mm_tests on amd64 and by Suren on android (arm64). Limited testing on s390 qemu was also performed using stress-ng on the virtual memory, which should cover many corner cases. v1: https://lore.kernel.org/all/20260115193647.1695937-1-Liam.Howlett@oracle.com/ v2: https://lore.kernel.org/all/20260121164526.2093265-1-Liam.Howlett@oracle.com/ Changes since v2: - Whitespace fix in rebalance_data() - Added ma_init_slot() for cleaner casting during RCU_INIT_POINTER(). Thanks test robot & SK [1] - Fixed off-by-one in rebalance_data() which caused node overuse, reported by linux-next. Thanks Mark [2] - Added new patch to reproducer to test cases in userspace testing for the rebalance_data() off-by-one [1]. https://lore.kernel.org/all/20260122055516.69335-1-sj@kernel.org/ [2]. https://lore.kernel.org/all/bd1c3356-11a1-4d0b-bf58-47eb21bfd24d@sirena.org.uk/ Liam R. Howlett (30): maple_tree: Fix mas_dup_alloc() sparse warning maple_tree: Move mas_spanning_rebalance loop to function maple_tree: Extract use of big node from mas_wr_spanning_store() maple_tree: Remove unnecessary assignment of orig_l index maple_tree: inline mas_spanning_rebalance() into mas_wr_spanning_rebalance() maple_tree: Make ma_wr_states reliable for reuse in spanning store maple_tree: Remove l_wr_mas from mas_wr_spanning_rebalance maple_tree: Don't pass through height in mas_wr_spanning_store maple_tree: Move maple_subtree_state from mas_wr_spanning_store to mas_wr_spanning_rebalance maple_tree: Correct right ma_wr_state end pivot in mas_wr_spanning_store() maple_tree: Introduce maple_copy node and use it in mas_spanning_rebalance() maple_tree: Testing update for spanning store maple_tree: Inline mas_spanning_rebalance_loop() into mas_wr_spanning_rebalance() maple_tree: Change initial big node setup in mas_wr_spanning_rebalance() maple_tree: Introduce ma_leaf_max_gap() maple_tree: Add gap support, slot and pivot sizes for maple copy maple_tree: Start using maple copy node for destination maple_tree: inline mas_wr_spanning_rebalance() maple_tree: Remove unnecessary return statements maple_tree: Separate wr_split_store and wr_rebalance store type code path maple_tree: Add cp_is_new_root() helper maple_tree: Use maple copy node for mas_wr_rebalance() operation maple_tree: Add test for rebalance calculation off-by-one maple_tree: Add copy_tree_location() helper maple_tree: Add cp_converged() helper maple_tree: Use maple copy node for mas_wr_split() maple_tree: Remove maple big node and subtree structs maple_tree: Pass maple copy node to mas_wmb_replace() maple_tree: Don't pass end to mas_wr_append() maple_tree: Clean up mas_wr_node_store() include/linux/maple_tree.h | 42 + lib/maple_tree.c | 2134 +++++++++++++----------------- lib/test_maple_tree.c | 55 +- tools/testing/radix-tree/maple.c | 308 ++++- 4 files changed, 1340 insertions(+), 1199 deletions(-) -- 2.47.3
On Mon, 2 Feb 2026 09:58:31 -0500 "Liam R. Howlett" <Liam.Howlett@oracle.com> wrote: My pleasure :) Yes. The test code is available at GitHub [1]. Nonetheless, another test [2] that is using 9.3.0 was also failing. [1] https://github.com/damonitor/damon-tests/blob/master/corr/tests/build_m68k.sh [2] https://github.com/damonitor/damon-tests/blob/master/corr/tests/build_arm64.sh Thanks, SJ [...]
{ "author": "SeongJae Park <sj@kernel.org>", "date": "Mon, 2 Feb 2026 07:56:26 -0800", "thread_id": "20260202103154.ad1aa05611c79d21b070a861@linux-foundation.org.mbox.gz" }
lkml
[PATCH v3 00/30] maple_tree: Replace big node with maple copy
The big node struct was created for simplicity of splitting, rebalancing, and spanning store operations by using a copy buffer to create the data necessary prior to breaking it up into 256B nodes. Certain operations were rather tricky due to the restriction of keeping NULL entries together and never at the end of a node (except the right-most node). The big node struct is incompatible with future features that are currently in development. Specifically different node types and different data type sizes for pivots. The big node struct was also a stack variable, which caused issues with certain configurations of kernel build. This series removes big node by introducing another node type which will never be written to the tree: maple_copy. The maple copy node operates more like a scatter/gather operation with a number of sources and destinations of allocated nodes. The sources are copied to the destinations, in turn, until the sources are exhausted. The destination is changed if it is filled or the split location is reached prior to the source data end. New data is inserted by using the maple copy node itself as a source with up to 3 slots and pivots. The data in the maple copy node is the data being written to the tree along with any fragment of the range(s) being overwritten. As with all nodes, the maple copy node is of size 256B. Using a node type allows for the copy operation to treat the new data stored in the maple copy node the same as any other source node. Analysis of the runtime shows no regression or benefit of removing the larger stack structure. The motivation is the ground work to use new node types and to help those with odd configurations that have had issues. The change was tested by myself using mm_tests on amd64 and by Suren on android (arm64). Limited testing on s390 qemu was also performed using stress-ng on the virtual memory, which should cover many corner cases. v1: https://lore.kernel.org/all/20260115193647.1695937-1-Liam.Howlett@oracle.com/ v2: https://lore.kernel.org/all/20260121164526.2093265-1-Liam.Howlett@oracle.com/ Changes since v2: - Whitespace fix in rebalance_data() - Added ma_init_slot() for cleaner casting during RCU_INIT_POINTER(). Thanks test robot & SK [1] - Fixed off-by-one in rebalance_data() which caused node overuse, reported by linux-next. Thanks Mark [2] - Added new patch to reproducer to test cases in userspace testing for the rebalance_data() off-by-one [1]. https://lore.kernel.org/all/20260122055516.69335-1-sj@kernel.org/ [2]. https://lore.kernel.org/all/bd1c3356-11a1-4d0b-bf58-47eb21bfd24d@sirena.org.uk/ Liam R. Howlett (30): maple_tree: Fix mas_dup_alloc() sparse warning maple_tree: Move mas_spanning_rebalance loop to function maple_tree: Extract use of big node from mas_wr_spanning_store() maple_tree: Remove unnecessary assignment of orig_l index maple_tree: inline mas_spanning_rebalance() into mas_wr_spanning_rebalance() maple_tree: Make ma_wr_states reliable for reuse in spanning store maple_tree: Remove l_wr_mas from mas_wr_spanning_rebalance maple_tree: Don't pass through height in mas_wr_spanning_store maple_tree: Move maple_subtree_state from mas_wr_spanning_store to mas_wr_spanning_rebalance maple_tree: Correct right ma_wr_state end pivot in mas_wr_spanning_store() maple_tree: Introduce maple_copy node and use it in mas_spanning_rebalance() maple_tree: Testing update for spanning store maple_tree: Inline mas_spanning_rebalance_loop() into mas_wr_spanning_rebalance() maple_tree: Change initial big node setup in mas_wr_spanning_rebalance() maple_tree: Introduce ma_leaf_max_gap() maple_tree: Add gap support, slot and pivot sizes for maple copy maple_tree: Start using maple copy node for destination maple_tree: inline mas_wr_spanning_rebalance() maple_tree: Remove unnecessary return statements maple_tree: Separate wr_split_store and wr_rebalance store type code path maple_tree: Add cp_is_new_root() helper maple_tree: Use maple copy node for mas_wr_rebalance() operation maple_tree: Add test for rebalance calculation off-by-one maple_tree: Add copy_tree_location() helper maple_tree: Add cp_converged() helper maple_tree: Use maple copy node for mas_wr_split() maple_tree: Remove maple big node and subtree structs maple_tree: Pass maple copy node to mas_wmb_replace() maple_tree: Don't pass end to mas_wr_append() maple_tree: Clean up mas_wr_node_store() include/linux/maple_tree.h | 42 + lib/maple_tree.c | 2134 +++++++++++++----------------- lib/test_maple_tree.c | 55 +- tools/testing/radix-tree/maple.c | 308 ++++- 4 files changed, 1340 insertions(+), 1199 deletions(-) -- 2.47.3
* SeongJae Park <sj@kernel.org> [260202 10:56]: You have two failures: one in 8.1 and one in 9.3? I was planning to test 7.5.0 and ensure everything works, but this implies my plan will not catch everything?
{ "author": "\"Liam R. Howlett\" <Liam.Howlett@oracle.com>", "date": "Mon, 2 Feb 2026 12:01:53 -0500", "thread_id": "20260202103154.ad1aa05611c79d21b070a861@linux-foundation.org.mbox.gz" }
lkml
[PATCH v3 00/30] maple_tree: Replace big node with maple copy
The big node struct was created for simplicity of splitting, rebalancing, and spanning store operations by using a copy buffer to create the data necessary prior to breaking it up into 256B nodes. Certain operations were rather tricky due to the restriction of keeping NULL entries together and never at the end of a node (except the right-most node). The big node struct is incompatible with future features that are currently in development. Specifically different node types and different data type sizes for pivots. The big node struct was also a stack variable, which caused issues with certain configurations of kernel build. This series removes big node by introducing another node type which will never be written to the tree: maple_copy. The maple copy node operates more like a scatter/gather operation with a number of sources and destinations of allocated nodes. The sources are copied to the destinations, in turn, until the sources are exhausted. The destination is changed if it is filled or the split location is reached prior to the source data end. New data is inserted by using the maple copy node itself as a source with up to 3 slots and pivots. The data in the maple copy node is the data being written to the tree along with any fragment of the range(s) being overwritten. As with all nodes, the maple copy node is of size 256B. Using a node type allows for the copy operation to treat the new data stored in the maple copy node the same as any other source node. Analysis of the runtime shows no regression or benefit of removing the larger stack structure. The motivation is the ground work to use new node types and to help those with odd configurations that have had issues. The change was tested by myself using mm_tests on amd64 and by Suren on android (arm64). Limited testing on s390 qemu was also performed using stress-ng on the virtual memory, which should cover many corner cases. v1: https://lore.kernel.org/all/20260115193647.1695937-1-Liam.Howlett@oracle.com/ v2: https://lore.kernel.org/all/20260121164526.2093265-1-Liam.Howlett@oracle.com/ Changes since v2: - Whitespace fix in rebalance_data() - Added ma_init_slot() for cleaner casting during RCU_INIT_POINTER(). Thanks test robot & SK [1] - Fixed off-by-one in rebalance_data() which caused node overuse, reported by linux-next. Thanks Mark [2] - Added new patch to reproducer to test cases in userspace testing for the rebalance_data() off-by-one [1]. https://lore.kernel.org/all/20260122055516.69335-1-sj@kernel.org/ [2]. https://lore.kernel.org/all/bd1c3356-11a1-4d0b-bf58-47eb21bfd24d@sirena.org.uk/ Liam R. Howlett (30): maple_tree: Fix mas_dup_alloc() sparse warning maple_tree: Move mas_spanning_rebalance loop to function maple_tree: Extract use of big node from mas_wr_spanning_store() maple_tree: Remove unnecessary assignment of orig_l index maple_tree: inline mas_spanning_rebalance() into mas_wr_spanning_rebalance() maple_tree: Make ma_wr_states reliable for reuse in spanning store maple_tree: Remove l_wr_mas from mas_wr_spanning_rebalance maple_tree: Don't pass through height in mas_wr_spanning_store maple_tree: Move maple_subtree_state from mas_wr_spanning_store to mas_wr_spanning_rebalance maple_tree: Correct right ma_wr_state end pivot in mas_wr_spanning_store() maple_tree: Introduce maple_copy node and use it in mas_spanning_rebalance() maple_tree: Testing update for spanning store maple_tree: Inline mas_spanning_rebalance_loop() into mas_wr_spanning_rebalance() maple_tree: Change initial big node setup in mas_wr_spanning_rebalance() maple_tree: Introduce ma_leaf_max_gap() maple_tree: Add gap support, slot and pivot sizes for maple copy maple_tree: Start using maple copy node for destination maple_tree: inline mas_wr_spanning_rebalance() maple_tree: Remove unnecessary return statements maple_tree: Separate wr_split_store and wr_rebalance store type code path maple_tree: Add cp_is_new_root() helper maple_tree: Use maple copy node for mas_wr_rebalance() operation maple_tree: Add test for rebalance calculation off-by-one maple_tree: Add copy_tree_location() helper maple_tree: Add cp_converged() helper maple_tree: Use maple copy node for mas_wr_split() maple_tree: Remove maple big node and subtree structs maple_tree: Pass maple copy node to mas_wmb_replace() maple_tree: Don't pass end to mas_wr_append() maple_tree: Clean up mas_wr_node_store() include/linux/maple_tree.h | 42 + lib/maple_tree.c | 2134 +++++++++++++----------------- lib/test_maple_tree.c | 55 +- tools/testing/radix-tree/maple.c | 308 ++++- 4 files changed, 1340 insertions(+), 1199 deletions(-) -- 2.47.3
On Mon, 2 Feb 2026 12:01:53 -0500 "Liam R. Howlett" <Liam.Howlett@oracle.com> wrote: Yes. FYI, I picked the compiler versions for no good reason but just because there were reports of DAMON build failures on the compilers in the past. building kernel is 8.1. So gcc 7.5.0 might not need to be ensured for? I have no good expertise on planning tests, though. Thanks, SJ [...]
{ "author": "SeongJae Park <sj@kernel.org>", "date": "Mon, 2 Feb 2026 09:53:53 -0800", "thread_id": "20260202103154.ad1aa05611c79d21b070a861@linux-foundation.org.mbox.gz" }
lkml
[PATCH v3 00/30] maple_tree: Replace big node with maple copy
The big node struct was created for simplicity of splitting, rebalancing, and spanning store operations by using a copy buffer to create the data necessary prior to breaking it up into 256B nodes. Certain operations were rather tricky due to the restriction of keeping NULL entries together and never at the end of a node (except the right-most node). The big node struct is incompatible with future features that are currently in development. Specifically different node types and different data type sizes for pivots. The big node struct was also a stack variable, which caused issues with certain configurations of kernel build. This series removes big node by introducing another node type which will never be written to the tree: maple_copy. The maple copy node operates more like a scatter/gather operation with a number of sources and destinations of allocated nodes. The sources are copied to the destinations, in turn, until the sources are exhausted. The destination is changed if it is filled or the split location is reached prior to the source data end. New data is inserted by using the maple copy node itself as a source with up to 3 slots and pivots. The data in the maple copy node is the data being written to the tree along with any fragment of the range(s) being overwritten. As with all nodes, the maple copy node is of size 256B. Using a node type allows for the copy operation to treat the new data stored in the maple copy node the same as any other source node. Analysis of the runtime shows no regression or benefit of removing the larger stack structure. The motivation is the ground work to use new node types and to help those with odd configurations that have had issues. The change was tested by myself using mm_tests on amd64 and by Suren on android (arm64). Limited testing on s390 qemu was also performed using stress-ng on the virtual memory, which should cover many corner cases. v1: https://lore.kernel.org/all/20260115193647.1695937-1-Liam.Howlett@oracle.com/ v2: https://lore.kernel.org/all/20260121164526.2093265-1-Liam.Howlett@oracle.com/ Changes since v2: - Whitespace fix in rebalance_data() - Added ma_init_slot() for cleaner casting during RCU_INIT_POINTER(). Thanks test robot & SK [1] - Fixed off-by-one in rebalance_data() which caused node overuse, reported by linux-next. Thanks Mark [2] - Added new patch to reproducer to test cases in userspace testing for the rebalance_data() off-by-one [1]. https://lore.kernel.org/all/20260122055516.69335-1-sj@kernel.org/ [2]. https://lore.kernel.org/all/bd1c3356-11a1-4d0b-bf58-47eb21bfd24d@sirena.org.uk/ Liam R. Howlett (30): maple_tree: Fix mas_dup_alloc() sparse warning maple_tree: Move mas_spanning_rebalance loop to function maple_tree: Extract use of big node from mas_wr_spanning_store() maple_tree: Remove unnecessary assignment of orig_l index maple_tree: inline mas_spanning_rebalance() into mas_wr_spanning_rebalance() maple_tree: Make ma_wr_states reliable for reuse in spanning store maple_tree: Remove l_wr_mas from mas_wr_spanning_rebalance maple_tree: Don't pass through height in mas_wr_spanning_store maple_tree: Move maple_subtree_state from mas_wr_spanning_store to mas_wr_spanning_rebalance maple_tree: Correct right ma_wr_state end pivot in mas_wr_spanning_store() maple_tree: Introduce maple_copy node and use it in mas_spanning_rebalance() maple_tree: Testing update for spanning store maple_tree: Inline mas_spanning_rebalance_loop() into mas_wr_spanning_rebalance() maple_tree: Change initial big node setup in mas_wr_spanning_rebalance() maple_tree: Introduce ma_leaf_max_gap() maple_tree: Add gap support, slot and pivot sizes for maple copy maple_tree: Start using maple copy node for destination maple_tree: inline mas_wr_spanning_rebalance() maple_tree: Remove unnecessary return statements maple_tree: Separate wr_split_store and wr_rebalance store type code path maple_tree: Add cp_is_new_root() helper maple_tree: Use maple copy node for mas_wr_rebalance() operation maple_tree: Add test for rebalance calculation off-by-one maple_tree: Add copy_tree_location() helper maple_tree: Add cp_converged() helper maple_tree: Use maple copy node for mas_wr_split() maple_tree: Remove maple big node and subtree structs maple_tree: Pass maple copy node to mas_wmb_replace() maple_tree: Don't pass end to mas_wr_append() maple_tree: Clean up mas_wr_node_store() include/linux/maple_tree.h | 42 + lib/maple_tree.c | 2134 +++++++++++++----------------- lib/test_maple_tree.c | 55 +- tools/testing/radix-tree/maple.c | 308 ++++- 4 files changed, 1340 insertions(+), 1199 deletions(-) -- 2.47.3
On Mon, 2 Feb 2026 10:40:06 -0500 "Liam R. Howlett" <Liam.Howlett@oracle.com> wrote: Sounds good, I'll push this back into mm-new until -rc1.
{ "author": "Andrew Morton <akpm@linux-foundation.org>", "date": "Mon, 2 Feb 2026 10:31:54 -0800", "thread_id": "20260202103154.ad1aa05611c79d21b070a861@linux-foundation.org.mbox.gz" }
lkml
[PATCH v4 00/13] Enable I2C on SA8255p Qualcomm platforms
The Qualcomm automotive SA8255p SoC relies on firmware to configure platform resources, including clocks, interconnects and TLMM. The driver requests resources operations over SCMI using power and performance protocols. The SCMI power protocol enables or disables resources like clocks, interconnect paths, and TLMM (GPIOs) using runtime PM framework APIs, such as resume/suspend, to control power states(on/off). The SCMI performance protocol manages I2C frequency, with each frequency rate represented by a performance level. The driver uses geni_se_set_perf_opp() API to request the desired frequency rate.. As part of geni_se_set_perf_opp(), the OPP for the requested frequency is obtained using dev_pm_opp_find_freq_floor() and the performance level is set using dev_pm_opp_set_opp(). Praveen Talari (13): soc: qcom: geni-se: Refactor geni_icc_get() and make qup-memory ICC path optional soc: qcom: geni-se: Add geni_icc_set_bw_ab() function soc: qcom: geni-se: Introduce helper API for resource initialization soc: qcom: geni-se: Handle core clk in geni_se_clks_off() and geni_se_clks_on() soc: qcom: geni-se: Add resources activation/deactivation helpers soc: qcom: geni-se: Introduce helper API for attaching power domains soc: qcom: geni-se: Introduce helper APIs for performance control dt-bindings: i2c: Describe SA8255p i2c: qcom-geni: Isolate serial engine setup i2c: qcom-geni: Move resource initialization to separate function i2c: qcom-geni: Use resources helper APIs in runtime PM functions i2c: qcom-geni: Store of_device_id data in driver private struct i2c: qcom-geni: Enable I2C on SA8255p Qualcomm platforms --- v3->v4 - Added a new patch(4/13) to handle core clk as part of geni_se_clks_off/on(). --- .../bindings/i2c/qcom,sa8255p-geni-i2c.yaml | 64 ++++ drivers/i2c/busses/i2c-qcom-geni.c | 303 +++++++++--------- drivers/soc/qcom/qcom-geni-se.c | 265 +++++++++++++-- include/linux/soc/qcom/geni-se.h | 19 ++ 4 files changed, 476 insertions(+), 175 deletions(-) create mode 100644 Documentation/devicetree/bindings/i2c/qcom,sa8255p-geni-i2c.yaml base-commit: 193579fe01389bc21aff0051d13f24e8ea95b47d -- 2.34.1
The "qup-memory" interconnect path is optional and may not be defined in all device trees. Unroll the loop-based ICC path initialization to allow specific error handling for each path type. The "qup-core" and "qup-config" paths remain mandatory and will fail probe if missing, while "qup-memory" is now handled as optional and skipped when not present in the device tree. Co-developed-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> Signed-off-by: Praveen Talari <praveen.talari@oss.qualcomm.com> --- v1->v2: Bjorn: - Updated commit text. - Used local variable for more readable. --- drivers/soc/qcom/qcom-geni-se.c | 36 +++++++++++++++++---------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/drivers/soc/qcom/qcom-geni-se.c b/drivers/soc/qcom/qcom-geni-se.c index cd1779b6a91a..b6167b968ef6 100644 --- a/drivers/soc/qcom/qcom-geni-se.c +++ b/drivers/soc/qcom/qcom-geni-se.c @@ -899,30 +899,32 @@ EXPORT_SYMBOL_GPL(geni_se_rx_dma_unprep); int geni_icc_get(struct geni_se *se, const char *icc_ddr) { - int i, err; - const char *icc_names[] = {"qup-core", "qup-config", icc_ddr}; + struct geni_icc_path *icc_paths = se->icc_paths; if (has_acpi_companion(se->dev)) return 0; - for (i = 0; i < ARRAY_SIZE(se->icc_paths); i++) { - if (!icc_names[i]) - continue; - - se->icc_paths[i].path = devm_of_icc_get(se->dev, icc_names[i]); - if (IS_ERR(se->icc_paths[i].path)) - goto err; + icc_paths[GENI_TO_CORE].path = devm_of_icc_get(se->dev, "qup-core"); + if (IS_ERR(icc_paths[GENI_TO_CORE].path)) + return dev_err_probe(se->dev, PTR_ERR(icc_paths[GENI_TO_CORE].path), + "Failed to get 'qup-core' ICC path\n"); + + icc_paths[CPU_TO_GENI].path = devm_of_icc_get(se->dev, "qup-config"); + if (IS_ERR(icc_paths[CPU_TO_GENI].path)) + return dev_err_probe(se->dev, PTR_ERR(icc_paths[CPU_TO_GENI].path), + "Failed to get 'qup-config' ICC path\n"); + + /* The DDR path is optional, depending on protocol and hw capabilities */ + icc_paths[GENI_TO_DDR].path = devm_of_icc_get(se->dev, "qup-memory"); + if (IS_ERR(icc_paths[GENI_TO_DDR].path)) { + if (PTR_ERR(icc_paths[GENI_TO_DDR].path) == -ENODATA) + icc_paths[GENI_TO_DDR].path = NULL; + else + return dev_err_probe(se->dev, PTR_ERR(icc_paths[GENI_TO_DDR].path), + "Failed to get 'qup-memory' ICC path\n"); } return 0; - -err: - err = PTR_ERR(se->icc_paths[i].path); - if (err != -EPROBE_DEFER) - dev_err_ratelimited(se->dev, "Failed to get ICC path '%s': %d\n", - icc_names[i], err); - return err; - } EXPORT_SYMBOL_GPL(geni_icc_get); -- 2.34.1
{ "author": "Praveen Talari <praveen.talari@oss.qualcomm.com>", "date": "Mon, 2 Feb 2026 23:39:10 +0530", "thread_id": "20260202180922.1692428-13-praveen.talari@oss.qualcomm.com.mbox.gz" }
lkml
[PATCH v4 00/13] Enable I2C on SA8255p Qualcomm platforms
The Qualcomm automotive SA8255p SoC relies on firmware to configure platform resources, including clocks, interconnects and TLMM. The driver requests resources operations over SCMI using power and performance protocols. The SCMI power protocol enables or disables resources like clocks, interconnect paths, and TLMM (GPIOs) using runtime PM framework APIs, such as resume/suspend, to control power states(on/off). The SCMI performance protocol manages I2C frequency, with each frequency rate represented by a performance level. The driver uses geni_se_set_perf_opp() API to request the desired frequency rate.. As part of geni_se_set_perf_opp(), the OPP for the requested frequency is obtained using dev_pm_opp_find_freq_floor() and the performance level is set using dev_pm_opp_set_opp(). Praveen Talari (13): soc: qcom: geni-se: Refactor geni_icc_get() and make qup-memory ICC path optional soc: qcom: geni-se: Add geni_icc_set_bw_ab() function soc: qcom: geni-se: Introduce helper API for resource initialization soc: qcom: geni-se: Handle core clk in geni_se_clks_off() and geni_se_clks_on() soc: qcom: geni-se: Add resources activation/deactivation helpers soc: qcom: geni-se: Introduce helper API for attaching power domains soc: qcom: geni-se: Introduce helper APIs for performance control dt-bindings: i2c: Describe SA8255p i2c: qcom-geni: Isolate serial engine setup i2c: qcom-geni: Move resource initialization to separate function i2c: qcom-geni: Use resources helper APIs in runtime PM functions i2c: qcom-geni: Store of_device_id data in driver private struct i2c: qcom-geni: Enable I2C on SA8255p Qualcomm platforms --- v3->v4 - Added a new patch(4/13) to handle core clk as part of geni_se_clks_off/on(). --- .../bindings/i2c/qcom,sa8255p-geni-i2c.yaml | 64 ++++ drivers/i2c/busses/i2c-qcom-geni.c | 303 +++++++++--------- drivers/soc/qcom/qcom-geni-se.c | 265 +++++++++++++-- include/linux/soc/qcom/geni-se.h | 19 ++ 4 files changed, 476 insertions(+), 175 deletions(-) create mode 100644 Documentation/devicetree/bindings/i2c/qcom,sa8255p-geni-i2c.yaml base-commit: 193579fe01389bc21aff0051d13f24e8ea95b47d -- 2.34.1
Add a new function geni_icc_set_bw_ab() that allows callers to set average bandwidth values for all ICC (Interconnect) paths in a single call. This function takes separate parameters for core, config, and DDR average bandwidth values and applies them to the respective ICC paths. This provides a more convenient API for drivers that need to configure specific average bandwidth values. Co-developed-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> Signed-off-by: Praveen Talari <praveen.talari@oss.qualcomm.com> --- drivers/soc/qcom/qcom-geni-se.c | 22 ++++++++++++++++++++++ include/linux/soc/qcom/geni-se.h | 1 + 2 files changed, 23 insertions(+) diff --git a/drivers/soc/qcom/qcom-geni-se.c b/drivers/soc/qcom/qcom-geni-se.c index b6167b968ef6..b0542f836453 100644 --- a/drivers/soc/qcom/qcom-geni-se.c +++ b/drivers/soc/qcom/qcom-geni-se.c @@ -946,6 +946,28 @@ int geni_icc_set_bw(struct geni_se *se) } EXPORT_SYMBOL_GPL(geni_icc_set_bw); +/** + * geni_icc_set_bw_ab() - Set average bandwidth for all ICC paths and apply + * @se: Pointer to the concerned serial engine. + * @core_ab: Average bandwidth in kBps for GENI_TO_CORE path. + * @cfg_ab: Average bandwidth in kBps for CPU_TO_GENI path. + * @ddr_ab: Average bandwidth in kBps for GENI_TO_DDR path. + * + * Sets bandwidth values for all ICC paths and applies them. DDR path is + * optional and only set if it exists. + * + * Return: 0 on success, negative error code on failure. + */ +int geni_icc_set_bw_ab(struct geni_se *se, u32 core_ab, u32 cfg_ab, u32 ddr_ab) +{ + se->icc_paths[GENI_TO_CORE].avg_bw = core_ab; + se->icc_paths[CPU_TO_GENI].avg_bw = cfg_ab; + se->icc_paths[GENI_TO_DDR].avg_bw = ddr_ab; + + return geni_icc_set_bw(se); +} +EXPORT_SYMBOL_GPL(geni_icc_set_bw_ab); + void geni_icc_set_tag(struct geni_se *se, u32 tag) { int i; diff --git a/include/linux/soc/qcom/geni-se.h b/include/linux/soc/qcom/geni-se.h index 0a984e2579fe..980aabea2157 100644 --- a/include/linux/soc/qcom/geni-se.h +++ b/include/linux/soc/qcom/geni-se.h @@ -528,6 +528,7 @@ void geni_se_rx_dma_unprep(struct geni_se *se, dma_addr_t iova, size_t len); int geni_icc_get(struct geni_se *se, const char *icc_ddr); int geni_icc_set_bw(struct geni_se *se); +int geni_icc_set_bw_ab(struct geni_se *se, u32 core_ab, u32 cfg_ab, u32 ddr_ab); void geni_icc_set_tag(struct geni_se *se, u32 tag); int geni_icc_enable(struct geni_se *se); -- 2.34.1
{ "author": "Praveen Talari <praveen.talari@oss.qualcomm.com>", "date": "Mon, 2 Feb 2026 23:39:11 +0530", "thread_id": "20260202180922.1692428-13-praveen.talari@oss.qualcomm.com.mbox.gz" }
lkml
[PATCH v4 00/13] Enable I2C on SA8255p Qualcomm platforms
The Qualcomm automotive SA8255p SoC relies on firmware to configure platform resources, including clocks, interconnects and TLMM. The driver requests resources operations over SCMI using power and performance protocols. The SCMI power protocol enables or disables resources like clocks, interconnect paths, and TLMM (GPIOs) using runtime PM framework APIs, such as resume/suspend, to control power states(on/off). The SCMI performance protocol manages I2C frequency, with each frequency rate represented by a performance level. The driver uses geni_se_set_perf_opp() API to request the desired frequency rate.. As part of geni_se_set_perf_opp(), the OPP for the requested frequency is obtained using dev_pm_opp_find_freq_floor() and the performance level is set using dev_pm_opp_set_opp(). Praveen Talari (13): soc: qcom: geni-se: Refactor geni_icc_get() and make qup-memory ICC path optional soc: qcom: geni-se: Add geni_icc_set_bw_ab() function soc: qcom: geni-se: Introduce helper API for resource initialization soc: qcom: geni-se: Handle core clk in geni_se_clks_off() and geni_se_clks_on() soc: qcom: geni-se: Add resources activation/deactivation helpers soc: qcom: geni-se: Introduce helper API for attaching power domains soc: qcom: geni-se: Introduce helper APIs for performance control dt-bindings: i2c: Describe SA8255p i2c: qcom-geni: Isolate serial engine setup i2c: qcom-geni: Move resource initialization to separate function i2c: qcom-geni: Use resources helper APIs in runtime PM functions i2c: qcom-geni: Store of_device_id data in driver private struct i2c: qcom-geni: Enable I2C on SA8255p Qualcomm platforms --- v3->v4 - Added a new patch(4/13) to handle core clk as part of geni_se_clks_off/on(). --- .../bindings/i2c/qcom,sa8255p-geni-i2c.yaml | 64 ++++ drivers/i2c/busses/i2c-qcom-geni.c | 303 +++++++++--------- drivers/soc/qcom/qcom-geni-se.c | 265 +++++++++++++-- include/linux/soc/qcom/geni-se.h | 19 ++ 4 files changed, 476 insertions(+), 175 deletions(-) create mode 100644 Documentation/devicetree/bindings/i2c/qcom,sa8255p-geni-i2c.yaml base-commit: 193579fe01389bc21aff0051d13f24e8ea95b47d -- 2.34.1
The GENI Serial Engine drivers (I2C, SPI, and SERIAL) currently duplicate code for initializing shared resources such as clocks and interconnect paths. Introduce a new helper API, geni_se_resources_init(), to centralize this initialization logic, improving modularity and simplifying the probe function. Signed-off-by: Praveen Talari <praveen.talari@oss.qualcomm.com> --- v1 -> v2: - Updated proper return value for devm_pm_opp_set_clkname() --- drivers/soc/qcom/qcom-geni-se.c | 47 ++++++++++++++++++++++++++++++++ include/linux/soc/qcom/geni-se.h | 6 ++++ 2 files changed, 53 insertions(+) diff --git a/drivers/soc/qcom/qcom-geni-se.c b/drivers/soc/qcom/qcom-geni-se.c index b0542f836453..75e722cd1a94 100644 --- a/drivers/soc/qcom/qcom-geni-se.c +++ b/drivers/soc/qcom/qcom-geni-se.c @@ -19,6 +19,7 @@ #include <linux/of_platform.h> #include <linux/pinctrl/consumer.h> #include <linux/platform_device.h> +#include <linux/pm_opp.h> #include <linux/soc/qcom/geni-se.h> /** @@ -1012,6 +1013,52 @@ int geni_icc_disable(struct geni_se *se) } EXPORT_SYMBOL_GPL(geni_icc_disable); +/** + * geni_se_resources_init() - Initialize resources for a GENI SE device. + * @se: Pointer to the geni_se structure representing the GENI SE device. + * + * This function initializes various resources required by the GENI Serial Engine + * (SE) device, including clock resources (core and SE clocks), interconnect + * paths for communication. + * It retrieves optional and mandatory clock resources, adds an OF-based + * operating performance point (OPP) table, and sets up interconnect paths + * with default bandwidths. The function also sets a flag (`has_opp`) to + * indicate whether OPP support is available for the device. + * + * Return: 0 on success, or a negative errno on failure. + */ +int geni_se_resources_init(struct geni_se *se) +{ + int ret; + + se->core_clk = devm_clk_get_optional(se->dev, "core"); + if (IS_ERR(se->core_clk)) + return dev_err_probe(se->dev, PTR_ERR(se->core_clk), + "Failed to get optional core clk\n"); + + se->clk = devm_clk_get(se->dev, "se"); + if (IS_ERR(se->clk) && !has_acpi_companion(se->dev)) + return dev_err_probe(se->dev, PTR_ERR(se->clk), + "Failed to get SE clk\n"); + + ret = devm_pm_opp_set_clkname(se->dev, "se"); + if (ret) + return ret; + + ret = devm_pm_opp_of_add_table(se->dev); + if (ret && ret != -ENODEV) + return dev_err_probe(se->dev, ret, "Failed to add OPP table\n"); + + se->has_opp = (ret == 0); + + ret = geni_icc_get(se, "qup-memory"); + if (ret) + return ret; + + return geni_icc_set_bw_ab(se, GENI_DEFAULT_BW, GENI_DEFAULT_BW, GENI_DEFAULT_BW); +} +EXPORT_SYMBOL_GPL(geni_se_resources_init); + /** * geni_find_protocol_fw() - Locate and validate SE firmware for a protocol. * @dev: Pointer to the device structure. diff --git a/include/linux/soc/qcom/geni-se.h b/include/linux/soc/qcom/geni-se.h index 980aabea2157..c182dd0f0bde 100644 --- a/include/linux/soc/qcom/geni-se.h +++ b/include/linux/soc/qcom/geni-se.h @@ -60,18 +60,22 @@ struct geni_icc_path { * @dev: Pointer to the Serial Engine device * @wrapper: Pointer to the parent QUP Wrapper core * @clk: Handle to the core serial engine clock + * @core_clk: Auxiliary clock, which may be required by a protocol * @num_clk_levels: Number of valid clock levels in clk_perf_tbl * @clk_perf_tbl: Table of clock frequency input to serial engine clock * @icc_paths: Array of ICC paths for SE + * @has_opp: Indicates if OPP is supported */ struct geni_se { void __iomem *base; struct device *dev; struct geni_wrapper *wrapper; struct clk *clk; + struct clk *core_clk; unsigned int num_clk_levels; unsigned long *clk_perf_tbl; struct geni_icc_path icc_paths[3]; + bool has_opp; }; /* Common SE registers */ @@ -535,6 +539,8 @@ int geni_icc_enable(struct geni_se *se); int geni_icc_disable(struct geni_se *se); +int geni_se_resources_init(struct geni_se *se); + int geni_load_se_firmware(struct geni_se *se, enum geni_se_protocol_type protocol); #endif #endif -- 2.34.1
{ "author": "Praveen Talari <praveen.talari@oss.qualcomm.com>", "date": "Mon, 2 Feb 2026 23:39:12 +0530", "thread_id": "20260202180922.1692428-13-praveen.talari@oss.qualcomm.com.mbox.gz" }
lkml
[PATCH v4 00/13] Enable I2C on SA8255p Qualcomm platforms
The Qualcomm automotive SA8255p SoC relies on firmware to configure platform resources, including clocks, interconnects and TLMM. The driver requests resources operations over SCMI using power and performance protocols. The SCMI power protocol enables or disables resources like clocks, interconnect paths, and TLMM (GPIOs) using runtime PM framework APIs, such as resume/suspend, to control power states(on/off). The SCMI performance protocol manages I2C frequency, with each frequency rate represented by a performance level. The driver uses geni_se_set_perf_opp() API to request the desired frequency rate.. As part of geni_se_set_perf_opp(), the OPP for the requested frequency is obtained using dev_pm_opp_find_freq_floor() and the performance level is set using dev_pm_opp_set_opp(). Praveen Talari (13): soc: qcom: geni-se: Refactor geni_icc_get() and make qup-memory ICC path optional soc: qcom: geni-se: Add geni_icc_set_bw_ab() function soc: qcom: geni-se: Introduce helper API for resource initialization soc: qcom: geni-se: Handle core clk in geni_se_clks_off() and geni_se_clks_on() soc: qcom: geni-se: Add resources activation/deactivation helpers soc: qcom: geni-se: Introduce helper API for attaching power domains soc: qcom: geni-se: Introduce helper APIs for performance control dt-bindings: i2c: Describe SA8255p i2c: qcom-geni: Isolate serial engine setup i2c: qcom-geni: Move resource initialization to separate function i2c: qcom-geni: Use resources helper APIs in runtime PM functions i2c: qcom-geni: Store of_device_id data in driver private struct i2c: qcom-geni: Enable I2C on SA8255p Qualcomm platforms --- v3->v4 - Added a new patch(4/13) to handle core clk as part of geni_se_clks_off/on(). --- .../bindings/i2c/qcom,sa8255p-geni-i2c.yaml | 64 ++++ drivers/i2c/busses/i2c-qcom-geni.c | 303 +++++++++--------- drivers/soc/qcom/qcom-geni-se.c | 265 +++++++++++++-- include/linux/soc/qcom/geni-se.h | 19 ++ 4 files changed, 476 insertions(+), 175 deletions(-) create mode 100644 Documentation/devicetree/bindings/i2c/qcom,sa8255p-geni-i2c.yaml base-commit: 193579fe01389bc21aff0051d13f24e8ea95b47d -- 2.34.1
Currently, core clk is handled individually in protocol drivers like the I2C driver. Move this clock management to the common clock APIs (geni_se_clks_on/off) that are already present in the common GENI SE driver to maintain consistency across all protocol drivers. Core clk is now properly managed alongside the other clocks (se->clk and wrapper clocks) in the fundamental clock control functions, eliminating the need for individual protocol drivers to handle this clock separately. Signed-off-by: Praveen Talari <praveen.talari@oss.qualcomm.com> --- drivers/soc/qcom/qcom-geni-se.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/soc/qcom/qcom-geni-se.c b/drivers/soc/qcom/qcom-geni-se.c index 75e722cd1a94..2e41595ff912 100644 --- a/drivers/soc/qcom/qcom-geni-se.c +++ b/drivers/soc/qcom/qcom-geni-se.c @@ -583,6 +583,7 @@ static void geni_se_clks_off(struct geni_se *se) clk_disable_unprepare(se->clk); clk_bulk_disable_unprepare(wrapper->num_clks, wrapper->clks); + clk_disable_unprepare(se->core_clk); } /** @@ -619,7 +620,18 @@ static int geni_se_clks_on(struct geni_se *se) ret = clk_prepare_enable(se->clk); if (ret) - clk_bulk_disable_unprepare(wrapper->num_clks, wrapper->clks); + goto err_bulk_clks; + + ret = clk_prepare_enable(se->core_clk); + if (ret) + goto err_se_clk; + + return 0; + +err_se_clk: + clk_disable_unprepare(se->clk); +err_bulk_clks: + clk_bulk_disable_unprepare(wrapper->num_clks, wrapper->clks); return ret; } -- 2.34.1
{ "author": "Praveen Talari <praveen.talari@oss.qualcomm.com>", "date": "Mon, 2 Feb 2026 23:39:13 +0530", "thread_id": "20260202180922.1692428-13-praveen.talari@oss.qualcomm.com.mbox.gz" }
lkml
[PATCH v4 00/13] Enable I2C on SA8255p Qualcomm platforms
The Qualcomm automotive SA8255p SoC relies on firmware to configure platform resources, including clocks, interconnects and TLMM. The driver requests resources operations over SCMI using power and performance protocols. The SCMI power protocol enables or disables resources like clocks, interconnect paths, and TLMM (GPIOs) using runtime PM framework APIs, such as resume/suspend, to control power states(on/off). The SCMI performance protocol manages I2C frequency, with each frequency rate represented by a performance level. The driver uses geni_se_set_perf_opp() API to request the desired frequency rate.. As part of geni_se_set_perf_opp(), the OPP for the requested frequency is obtained using dev_pm_opp_find_freq_floor() and the performance level is set using dev_pm_opp_set_opp(). Praveen Talari (13): soc: qcom: geni-se: Refactor geni_icc_get() and make qup-memory ICC path optional soc: qcom: geni-se: Add geni_icc_set_bw_ab() function soc: qcom: geni-se: Introduce helper API for resource initialization soc: qcom: geni-se: Handle core clk in geni_se_clks_off() and geni_se_clks_on() soc: qcom: geni-se: Add resources activation/deactivation helpers soc: qcom: geni-se: Introduce helper API for attaching power domains soc: qcom: geni-se: Introduce helper APIs for performance control dt-bindings: i2c: Describe SA8255p i2c: qcom-geni: Isolate serial engine setup i2c: qcom-geni: Move resource initialization to separate function i2c: qcom-geni: Use resources helper APIs in runtime PM functions i2c: qcom-geni: Store of_device_id data in driver private struct i2c: qcom-geni: Enable I2C on SA8255p Qualcomm platforms --- v3->v4 - Added a new patch(4/13) to handle core clk as part of geni_se_clks_off/on(). --- .../bindings/i2c/qcom,sa8255p-geni-i2c.yaml | 64 ++++ drivers/i2c/busses/i2c-qcom-geni.c | 303 +++++++++--------- drivers/soc/qcom/qcom-geni-se.c | 265 +++++++++++++-- include/linux/soc/qcom/geni-se.h | 19 ++ 4 files changed, 476 insertions(+), 175 deletions(-) create mode 100644 Documentation/devicetree/bindings/i2c/qcom,sa8255p-geni-i2c.yaml base-commit: 193579fe01389bc21aff0051d13f24e8ea95b47d -- 2.34.1
The GENI SE protocol drivers (I2C, SPI, UART) implement similar resource activation/deactivation sequences independently, leading to code duplication. Introduce geni_se_resources_activate()/geni_se_resources_deactivate() to power on/off resources.The activate function enables ICC, clocks, and TLMM whereas the deactivate function disables resources in reverse order including OPP rate reset, clocks, ICC and TLMM. Signed-off-by: Praveen Talari <praveen.talari@oss.qualcomm.com> --- v3 -> v4 Konrad - Removed core clk. v2 -> v3 - Added export symbol for new APIs. v1 -> v2 Bjorn - Updated commit message based code changes. - Removed geni_se_resource_state() API. - Utilized code snippet from geni_se_resources_off() --- drivers/soc/qcom/qcom-geni-se.c | 67 ++++++++++++++++++++++++++++++++ include/linux/soc/qcom/geni-se.h | 4 ++ 2 files changed, 71 insertions(+) diff --git a/drivers/soc/qcom/qcom-geni-se.c b/drivers/soc/qcom/qcom-geni-se.c index 2e41595ff912..17ab5bbeb621 100644 --- a/drivers/soc/qcom/qcom-geni-se.c +++ b/drivers/soc/qcom/qcom-geni-se.c @@ -1025,6 +1025,73 @@ int geni_icc_disable(struct geni_se *se) } EXPORT_SYMBOL_GPL(geni_icc_disable); +/** + * geni_se_resources_deactivate() - Deactivate GENI SE device resources + * @se: Pointer to the geni_se structure + * + * Deactivates device resources for power saving: OPP rate to 0, pin control + * to sleep state, turns off clocks, and disables interconnect. Skips ACPI devices. + * + * Return: 0 on success, negative error code on failure + */ +int geni_se_resources_deactivate(struct geni_se *se) +{ + int ret; + + if (has_acpi_companion(se->dev)) + return 0; + + if (se->has_opp) + dev_pm_opp_set_rate(se->dev, 0); + + ret = pinctrl_pm_select_sleep_state(se->dev); + if (ret) + return ret; + + geni_se_clks_off(se); + + return geni_icc_disable(se); +} +EXPORT_SYMBOL_GPL(geni_se_resources_deactivate); + +/** + * geni_se_resources_activate() - Activate GENI SE device resources + * @se: Pointer to the geni_se structure + * + * Activates device resources for operation: enables interconnect, prepares clocks, + * and sets pin control to default state. Includes error cleanup. Skips ACPI devices. + * + * Return: 0 on success, negative error code on failure + */ +int geni_se_resources_activate(struct geni_se *se) +{ + int ret; + + if (has_acpi_companion(se->dev)) + return 0; + + ret = geni_icc_enable(se); + if (ret) + return ret; + + ret = geni_se_clks_on(se); + if (ret) + goto out_icc_disable; + + ret = pinctrl_pm_select_default_state(se->dev); + if (ret) { + geni_se_clks_off(se); + goto out_icc_disable; + } + + return ret; + +out_icc_disable: + geni_icc_disable(se); + return ret; +} +EXPORT_SYMBOL_GPL(geni_se_resources_activate); + /** * geni_se_resources_init() - Initialize resources for a GENI SE device. * @se: Pointer to the geni_se structure representing the GENI SE device. diff --git a/include/linux/soc/qcom/geni-se.h b/include/linux/soc/qcom/geni-se.h index c182dd0f0bde..36a68149345c 100644 --- a/include/linux/soc/qcom/geni-se.h +++ b/include/linux/soc/qcom/geni-se.h @@ -541,6 +541,10 @@ int geni_icc_disable(struct geni_se *se); int geni_se_resources_init(struct geni_se *se); +int geni_se_resources_activate(struct geni_se *se); + +int geni_se_resources_deactivate(struct geni_se *se); + int geni_load_se_firmware(struct geni_se *se, enum geni_se_protocol_type protocol); #endif #endif -- 2.34.1
{ "author": "Praveen Talari <praveen.talari@oss.qualcomm.com>", "date": "Mon, 2 Feb 2026 23:39:14 +0530", "thread_id": "20260202180922.1692428-13-praveen.talari@oss.qualcomm.com.mbox.gz" }
lkml
[PATCH v4 00/13] Enable I2C on SA8255p Qualcomm platforms
The Qualcomm automotive SA8255p SoC relies on firmware to configure platform resources, including clocks, interconnects and TLMM. The driver requests resources operations over SCMI using power and performance protocols. The SCMI power protocol enables or disables resources like clocks, interconnect paths, and TLMM (GPIOs) using runtime PM framework APIs, such as resume/suspend, to control power states(on/off). The SCMI performance protocol manages I2C frequency, with each frequency rate represented by a performance level. The driver uses geni_se_set_perf_opp() API to request the desired frequency rate.. As part of geni_se_set_perf_opp(), the OPP for the requested frequency is obtained using dev_pm_opp_find_freq_floor() and the performance level is set using dev_pm_opp_set_opp(). Praveen Talari (13): soc: qcom: geni-se: Refactor geni_icc_get() and make qup-memory ICC path optional soc: qcom: geni-se: Add geni_icc_set_bw_ab() function soc: qcom: geni-se: Introduce helper API for resource initialization soc: qcom: geni-se: Handle core clk in geni_se_clks_off() and geni_se_clks_on() soc: qcom: geni-se: Add resources activation/deactivation helpers soc: qcom: geni-se: Introduce helper API for attaching power domains soc: qcom: geni-se: Introduce helper APIs for performance control dt-bindings: i2c: Describe SA8255p i2c: qcom-geni: Isolate serial engine setup i2c: qcom-geni: Move resource initialization to separate function i2c: qcom-geni: Use resources helper APIs in runtime PM functions i2c: qcom-geni: Store of_device_id data in driver private struct i2c: qcom-geni: Enable I2C on SA8255p Qualcomm platforms --- v3->v4 - Added a new patch(4/13) to handle core clk as part of geni_se_clks_off/on(). --- .../bindings/i2c/qcom,sa8255p-geni-i2c.yaml | 64 ++++ drivers/i2c/busses/i2c-qcom-geni.c | 303 +++++++++--------- drivers/soc/qcom/qcom-geni-se.c | 265 +++++++++++++-- include/linux/soc/qcom/geni-se.h | 19 ++ 4 files changed, 476 insertions(+), 175 deletions(-) create mode 100644 Documentation/devicetree/bindings/i2c/qcom,sa8255p-geni-i2c.yaml base-commit: 193579fe01389bc21aff0051d13f24e8ea95b47d -- 2.34.1
The GENI Serial Engine drivers (I2C, SPI, and SERIAL) currently handle the attachment of power domains. This often leads to duplicated code logic across different driver probe functions. Introduce a new helper API, geni_se_domain_attach(), to centralize the logic for attaching "power" and "perf" domains to the GENI SE device. Signed-off-by: Praveen Talari <praveen.talari@oss.qualcomm.com> --- v3->v4 Konrad - Updated function documentation --- drivers/soc/qcom/qcom-geni-se.c | 29 +++++++++++++++++++++++++++++ include/linux/soc/qcom/geni-se.h | 4 ++++ 2 files changed, 33 insertions(+) diff --git a/drivers/soc/qcom/qcom-geni-se.c b/drivers/soc/qcom/qcom-geni-se.c index 17ab5bbeb621..d80ae6c36582 100644 --- a/drivers/soc/qcom/qcom-geni-se.c +++ b/drivers/soc/qcom/qcom-geni-se.c @@ -19,6 +19,7 @@ #include <linux/of_platform.h> #include <linux/pinctrl/consumer.h> #include <linux/platform_device.h> +#include <linux/pm_domain.h> #include <linux/pm_opp.h> #include <linux/soc/qcom/geni-se.h> @@ -1092,6 +1093,34 @@ int geni_se_resources_activate(struct geni_se *se) } EXPORT_SYMBOL_GPL(geni_se_resources_activate); +/** + * geni_se_domain_attach() - Attach power domains to a GENI SE device. + * @se: Pointer to the geni_se structure representing the GENI SE device. + * + * This function attaches the power domains ("power" and "perf") required + * in the SCMI auto-VM environment to the GENI Serial Engine device. It + * initializes se->pd_list with the attached domains. + * + * Return: 0 on success, or a negative error code on failure. + */ +int geni_se_domain_attach(struct geni_se *se) +{ + struct dev_pm_domain_attach_data pd_data = { + .pd_flags = PD_FLAG_DEV_LINK_ON, + .pd_names = (const char*[]) { "power", "perf" }, + .num_pd_names = 2, + }; + int ret; + + ret = dev_pm_domain_attach_list(se->dev, + &pd_data, &se->pd_list); + if (ret <= 0) + return -EINVAL; + + return 0; +} +EXPORT_SYMBOL_GPL(geni_se_domain_attach); + /** * geni_se_resources_init() - Initialize resources for a GENI SE device. * @se: Pointer to the geni_se structure representing the GENI SE device. diff --git a/include/linux/soc/qcom/geni-se.h b/include/linux/soc/qcom/geni-se.h index 36a68149345c..5f75159c5531 100644 --- a/include/linux/soc/qcom/geni-se.h +++ b/include/linux/soc/qcom/geni-se.h @@ -64,6 +64,7 @@ struct geni_icc_path { * @num_clk_levels: Number of valid clock levels in clk_perf_tbl * @clk_perf_tbl: Table of clock frequency input to serial engine clock * @icc_paths: Array of ICC paths for SE + * @pd_list: Power domain list for managing power domains * @has_opp: Indicates if OPP is supported */ struct geni_se { @@ -75,6 +76,7 @@ struct geni_se { unsigned int num_clk_levels; unsigned long *clk_perf_tbl; struct geni_icc_path icc_paths[3]; + struct dev_pm_domain_list *pd_list; bool has_opp; }; @@ -546,5 +548,7 @@ int geni_se_resources_activate(struct geni_se *se); int geni_se_resources_deactivate(struct geni_se *se); int geni_load_se_firmware(struct geni_se *se, enum geni_se_protocol_type protocol); + +int geni_se_domain_attach(struct geni_se *se); #endif #endif -- 2.34.1
{ "author": "Praveen Talari <praveen.talari@oss.qualcomm.com>", "date": "Mon, 2 Feb 2026 23:39:15 +0530", "thread_id": "20260202180922.1692428-13-praveen.talari@oss.qualcomm.com.mbox.gz" }
lkml
[PATCH v4 00/13] Enable I2C on SA8255p Qualcomm platforms
The Qualcomm automotive SA8255p SoC relies on firmware to configure platform resources, including clocks, interconnects and TLMM. The driver requests resources operations over SCMI using power and performance protocols. The SCMI power protocol enables or disables resources like clocks, interconnect paths, and TLMM (GPIOs) using runtime PM framework APIs, such as resume/suspend, to control power states(on/off). The SCMI performance protocol manages I2C frequency, with each frequency rate represented by a performance level. The driver uses geni_se_set_perf_opp() API to request the desired frequency rate.. As part of geni_se_set_perf_opp(), the OPP for the requested frequency is obtained using dev_pm_opp_find_freq_floor() and the performance level is set using dev_pm_opp_set_opp(). Praveen Talari (13): soc: qcom: geni-se: Refactor geni_icc_get() and make qup-memory ICC path optional soc: qcom: geni-se: Add geni_icc_set_bw_ab() function soc: qcom: geni-se: Introduce helper API for resource initialization soc: qcom: geni-se: Handle core clk in geni_se_clks_off() and geni_se_clks_on() soc: qcom: geni-se: Add resources activation/deactivation helpers soc: qcom: geni-se: Introduce helper API for attaching power domains soc: qcom: geni-se: Introduce helper APIs for performance control dt-bindings: i2c: Describe SA8255p i2c: qcom-geni: Isolate serial engine setup i2c: qcom-geni: Move resource initialization to separate function i2c: qcom-geni: Use resources helper APIs in runtime PM functions i2c: qcom-geni: Store of_device_id data in driver private struct i2c: qcom-geni: Enable I2C on SA8255p Qualcomm platforms --- v3->v4 - Added a new patch(4/13) to handle core clk as part of geni_se_clks_off/on(). --- .../bindings/i2c/qcom,sa8255p-geni-i2c.yaml | 64 ++++ drivers/i2c/busses/i2c-qcom-geni.c | 303 +++++++++--------- drivers/soc/qcom/qcom-geni-se.c | 265 +++++++++++++-- include/linux/soc/qcom/geni-se.h | 19 ++ 4 files changed, 476 insertions(+), 175 deletions(-) create mode 100644 Documentation/devicetree/bindings/i2c/qcom,sa8255p-geni-i2c.yaml base-commit: 193579fe01389bc21aff0051d13f24e8ea95b47d -- 2.34.1
The GENI Serial Engine (SE) drivers (I2C, SPI, and SERIAL) currently manage performance levels and operating points directly. This resulting in code duplication across drivers. such as configuring a specific level or find and apply an OPP based on a clock frequency. Introduce two new helper APIs, geni_se_set_perf_level() and geni_se_set_perf_opp(), addresses this issue by providing a streamlined method for the GENI Serial Engine (SE) drivers to find and set the OPP based on the desired performance level, thereby eliminating redundancy. Signed-off-by: Praveen Talari <praveen.talari@oss.qualcomm.com> --- drivers/soc/qcom/qcom-geni-se.c | 50 ++++++++++++++++++++++++++++++++ include/linux/soc/qcom/geni-se.h | 4 +++ 2 files changed, 54 insertions(+) diff --git a/drivers/soc/qcom/qcom-geni-se.c b/drivers/soc/qcom/qcom-geni-se.c index d80ae6c36582..2241d1487031 100644 --- a/drivers/soc/qcom/qcom-geni-se.c +++ b/drivers/soc/qcom/qcom-geni-se.c @@ -282,6 +282,12 @@ struct se_fw_hdr { #define geni_setbits32(_addr, _v) writel(readl(_addr) | (_v), _addr) #define geni_clrbits32(_addr, _v) writel(readl(_addr) & ~(_v), _addr) +enum domain_idx { + DOMAIN_IDX_POWER, + DOMAIN_IDX_PERF, + DOMAIN_IDX_MAX +}; + /** * geni_se_get_qup_hw_version() - Read the QUP wrapper Hardware version * @se: Pointer to the corresponding serial engine. @@ -1093,6 +1099,50 @@ int geni_se_resources_activate(struct geni_se *se) } EXPORT_SYMBOL_GPL(geni_se_resources_activate); +/** + * geni_se_set_perf_level() - Set performance level for GENI SE. + * @se: Pointer to the struct geni_se instance. + * @level: The desired performance level. + * + * Sets the performance level by directly calling dev_pm_opp_set_level + * on the performance device associated with the SE. + * + * Return: 0 on success, or a negative error code on failure. + */ +int geni_se_set_perf_level(struct geni_se *se, unsigned long level) +{ + return dev_pm_opp_set_level(se->pd_list->pd_devs[DOMAIN_IDX_PERF], level); +} +EXPORT_SYMBOL_GPL(geni_se_set_perf_level); + +/** + * geni_se_set_perf_opp() - Set performance OPP for GENI SE by frequency. + * @se: Pointer to the struct geni_se instance. + * @clk_freq: The requested clock frequency. + * + * Finds the nearest operating performance point (OPP) for the given + * clock frequency and applies it to the SE's performance device. + * + * Return: 0 on success, or a negative error code on failure. + */ +int geni_se_set_perf_opp(struct geni_se *se, unsigned long clk_freq) +{ + struct device *perf_dev = se->pd_list->pd_devs[DOMAIN_IDX_PERF]; + struct dev_pm_opp *opp; + int ret; + + opp = dev_pm_opp_find_freq_floor(perf_dev, &clk_freq); + if (IS_ERR(opp)) { + dev_err(se->dev, "failed to find opp for freq %lu\n", clk_freq); + return PTR_ERR(opp); + } + + ret = dev_pm_opp_set_opp(perf_dev, opp); + dev_pm_opp_put(opp); + return ret; +} +EXPORT_SYMBOL_GPL(geni_se_set_perf_opp); + /** * geni_se_domain_attach() - Attach power domains to a GENI SE device. * @se: Pointer to the geni_se structure representing the GENI SE device. diff --git a/include/linux/soc/qcom/geni-se.h b/include/linux/soc/qcom/geni-se.h index 5f75159c5531..c5e6ab85df09 100644 --- a/include/linux/soc/qcom/geni-se.h +++ b/include/linux/soc/qcom/geni-se.h @@ -550,5 +550,9 @@ int geni_se_resources_deactivate(struct geni_se *se); int geni_load_se_firmware(struct geni_se *se, enum geni_se_protocol_type protocol); int geni_se_domain_attach(struct geni_se *se); + +int geni_se_set_perf_level(struct geni_se *se, unsigned long level); + +int geni_se_set_perf_opp(struct geni_se *se, unsigned long clk_freq); #endif #endif -- 2.34.1
{ "author": "Praveen Talari <praveen.talari@oss.qualcomm.com>", "date": "Mon, 2 Feb 2026 23:39:16 +0530", "thread_id": "20260202180922.1692428-13-praveen.talari@oss.qualcomm.com.mbox.gz" }
lkml
[PATCH v4 00/13] Enable I2C on SA8255p Qualcomm platforms
The Qualcomm automotive SA8255p SoC relies on firmware to configure platform resources, including clocks, interconnects and TLMM. The driver requests resources operations over SCMI using power and performance protocols. The SCMI power protocol enables or disables resources like clocks, interconnect paths, and TLMM (GPIOs) using runtime PM framework APIs, such as resume/suspend, to control power states(on/off). The SCMI performance protocol manages I2C frequency, with each frequency rate represented by a performance level. The driver uses geni_se_set_perf_opp() API to request the desired frequency rate.. As part of geni_se_set_perf_opp(), the OPP for the requested frequency is obtained using dev_pm_opp_find_freq_floor() and the performance level is set using dev_pm_opp_set_opp(). Praveen Talari (13): soc: qcom: geni-se: Refactor geni_icc_get() and make qup-memory ICC path optional soc: qcom: geni-se: Add geni_icc_set_bw_ab() function soc: qcom: geni-se: Introduce helper API for resource initialization soc: qcom: geni-se: Handle core clk in geni_se_clks_off() and geni_se_clks_on() soc: qcom: geni-se: Add resources activation/deactivation helpers soc: qcom: geni-se: Introduce helper API for attaching power domains soc: qcom: geni-se: Introduce helper APIs for performance control dt-bindings: i2c: Describe SA8255p i2c: qcom-geni: Isolate serial engine setup i2c: qcom-geni: Move resource initialization to separate function i2c: qcom-geni: Use resources helper APIs in runtime PM functions i2c: qcom-geni: Store of_device_id data in driver private struct i2c: qcom-geni: Enable I2C on SA8255p Qualcomm platforms --- v3->v4 - Added a new patch(4/13) to handle core clk as part of geni_se_clks_off/on(). --- .../bindings/i2c/qcom,sa8255p-geni-i2c.yaml | 64 ++++ drivers/i2c/busses/i2c-qcom-geni.c | 303 +++++++++--------- drivers/soc/qcom/qcom-geni-se.c | 265 +++++++++++++-- include/linux/soc/qcom/geni-se.h | 19 ++ 4 files changed, 476 insertions(+), 175 deletions(-) create mode 100644 Documentation/devicetree/bindings/i2c/qcom,sa8255p-geni-i2c.yaml base-commit: 193579fe01389bc21aff0051d13f24e8ea95b47d -- 2.34.1
Add DT bindings for the QUP GENI I2C controller on sa8255p platforms. SA8255p platform abstracts resources such as clocks, interconnect and GPIO pins configuration in Firmware. SCMI power and perf protocol are utilized to request resource configurations. SA8255p platform does not require the Serial Engine (SE) common properties as the SE firmware is loaded and managed by the TrustZone (TZ) secure environment. Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com> Co-developed-by: Nikunj Kela <quic_nkela@quicinc.com> Signed-off-by: Nikunj Kela <quic_nkela@quicinc.com> Signed-off-by: Praveen Talari <praveen.talari@oss.qualcomm.com> --- v2->v3: - Added Reviewed-by tag v1->v2: Krzysztof: - Added dma properties in example node - Removed minItems from power-domains property - Added in commit text about common property --- .../bindings/i2c/qcom,sa8255p-geni-i2c.yaml | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/qcom,sa8255p-geni-i2c.yaml diff --git a/Documentation/devicetree/bindings/i2c/qcom,sa8255p-geni-i2c.yaml b/Documentation/devicetree/bindings/i2c/qcom,sa8255p-geni-i2c.yaml new file mode 100644 index 000000000000..a61e40b5cbc1 --- /dev/null +++ b/Documentation/devicetree/bindings/i2c/qcom,sa8255p-geni-i2c.yaml @@ -0,0 +1,64 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/i2c/qcom,sa8255p-geni-i2c.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Qualcomm SA8255p QUP GENI I2C Controller + +maintainers: + - Praveen Talari <praveen.talari@oss.qualcomm.com> + +properties: + compatible: + const: qcom,sa8255p-geni-i2c + + reg: + maxItems: 1 + + dmas: + maxItems: 2 + + dma-names: + items: + - const: tx + - const: rx + + interrupts: + maxItems: 1 + + power-domains: + maxItems: 2 + + power-domain-names: + items: + - const: power + - const: perf + +required: + - compatible + - reg + - interrupts + - power-domains + +allOf: + - $ref: /schemas/i2c/i2c-controller.yaml# + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + #include <dt-bindings/dma/qcom-gpi.h> + + i2c@a90000 { + compatible = "qcom,sa8255p-geni-i2c"; + reg = <0xa90000 0x4000>; + interrupts = <GIC_SPI 357 IRQ_TYPE_LEVEL_HIGH>; + dmas = <&gpi_dma0 0 0 QCOM_GPI_I2C>, + <&gpi_dma0 1 0 QCOM_GPI_I2C>; + dma-names = "tx", "rx"; + power-domains = <&scmi0_pd 0>, <&scmi0_dvfs 0>; + power-domain-names = "power", "perf"; + }; +... -- 2.34.1
{ "author": "Praveen Talari <praveen.talari@oss.qualcomm.com>", "date": "Mon, 2 Feb 2026 23:39:17 +0530", "thread_id": "20260202180922.1692428-13-praveen.talari@oss.qualcomm.com.mbox.gz" }
lkml
[PATCH v4 00/13] Enable I2C on SA8255p Qualcomm platforms
The Qualcomm automotive SA8255p SoC relies on firmware to configure platform resources, including clocks, interconnects and TLMM. The driver requests resources operations over SCMI using power and performance protocols. The SCMI power protocol enables or disables resources like clocks, interconnect paths, and TLMM (GPIOs) using runtime PM framework APIs, such as resume/suspend, to control power states(on/off). The SCMI performance protocol manages I2C frequency, with each frequency rate represented by a performance level. The driver uses geni_se_set_perf_opp() API to request the desired frequency rate.. As part of geni_se_set_perf_opp(), the OPP for the requested frequency is obtained using dev_pm_opp_find_freq_floor() and the performance level is set using dev_pm_opp_set_opp(). Praveen Talari (13): soc: qcom: geni-se: Refactor geni_icc_get() and make qup-memory ICC path optional soc: qcom: geni-se: Add geni_icc_set_bw_ab() function soc: qcom: geni-se: Introduce helper API for resource initialization soc: qcom: geni-se: Handle core clk in geni_se_clks_off() and geni_se_clks_on() soc: qcom: geni-se: Add resources activation/deactivation helpers soc: qcom: geni-se: Introduce helper API for attaching power domains soc: qcom: geni-se: Introduce helper APIs for performance control dt-bindings: i2c: Describe SA8255p i2c: qcom-geni: Isolate serial engine setup i2c: qcom-geni: Move resource initialization to separate function i2c: qcom-geni: Use resources helper APIs in runtime PM functions i2c: qcom-geni: Store of_device_id data in driver private struct i2c: qcom-geni: Enable I2C on SA8255p Qualcomm platforms --- v3->v4 - Added a new patch(4/13) to handle core clk as part of geni_se_clks_off/on(). --- .../bindings/i2c/qcom,sa8255p-geni-i2c.yaml | 64 ++++ drivers/i2c/busses/i2c-qcom-geni.c | 303 +++++++++--------- drivers/soc/qcom/qcom-geni-se.c | 265 +++++++++++++-- include/linux/soc/qcom/geni-se.h | 19 ++ 4 files changed, 476 insertions(+), 175 deletions(-) create mode 100644 Documentation/devicetree/bindings/i2c/qcom,sa8255p-geni-i2c.yaml base-commit: 193579fe01389bc21aff0051d13f24e8ea95b47d -- 2.34.1
Moving the serial engine setup to geni_i2c_init() API for a cleaner probe function and utilizes the PM runtime API to control resources instead of direct clock-related APIs for better resource management. Enables reusability of the serial engine initialization like hibernation and deep sleep features where hardware context is lost. Acked-by: Viken Dadhaniya <viken.dadhaniya@oss.qualcomm.com> Signed-off-by: Praveen Talari <praveen.talari@oss.qualcomm.com> --- v3->v4: viken: - Added Acked-by tag - Removed extra space before invoke of geni_i2c_init(). v1->v2: Bjorn: - Updated commit text. --- drivers/i2c/busses/i2c-qcom-geni.c | 158 ++++++++++++++--------------- 1 file changed, 75 insertions(+), 83 deletions(-) diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c index ae609bdd2ec4..81ed1596ac9f 100644 --- a/drivers/i2c/busses/i2c-qcom-geni.c +++ b/drivers/i2c/busses/i2c-qcom-geni.c @@ -977,10 +977,77 @@ static int setup_gpi_dma(struct geni_i2c_dev *gi2c) return ret; } +static int geni_i2c_init(struct geni_i2c_dev *gi2c) +{ + const struct geni_i2c_desc *desc = NULL; + u32 proto, tx_depth; + bool fifo_disable; + int ret; + + ret = pm_runtime_resume_and_get(gi2c->se.dev); + if (ret < 0) { + dev_err(gi2c->se.dev, "error turning on device :%d\n", ret); + return ret; + } + + proto = geni_se_read_proto(&gi2c->se); + if (proto == GENI_SE_INVALID_PROTO) { + ret = geni_load_se_firmware(&gi2c->se, GENI_SE_I2C); + if (ret) { + dev_err_probe(gi2c->se.dev, ret, "i2c firmware load failed ret: %d\n", ret); + goto err; + } + } else if (proto != GENI_SE_I2C) { + ret = dev_err_probe(gi2c->se.dev, -ENXIO, "Invalid proto %d\n", proto); + goto err; + } + + desc = device_get_match_data(gi2c->se.dev); + if (desc && desc->no_dma_support) { + fifo_disable = false; + gi2c->no_dma = true; + } else { + fifo_disable = readl_relaxed(gi2c->se.base + GENI_IF_DISABLE_RO) & FIFO_IF_DISABLE; + } + + if (fifo_disable) { + /* FIFO is disabled, so we can only use GPI DMA */ + gi2c->gpi_mode = true; + ret = setup_gpi_dma(gi2c); + if (ret) + goto err; + + dev_dbg(gi2c->se.dev, "Using GPI DMA mode for I2C\n"); + } else { + gi2c->gpi_mode = false; + tx_depth = geni_se_get_tx_fifo_depth(&gi2c->se); + + /* I2C Master Hub Serial Elements doesn't have the HW_PARAM_0 register */ + if (!tx_depth && desc) + tx_depth = desc->tx_fifo_depth; + + if (!tx_depth) { + ret = dev_err_probe(gi2c->se.dev, -EINVAL, + "Invalid TX FIFO depth\n"); + goto err; + } + + gi2c->tx_wm = tx_depth - 1; + geni_se_init(&gi2c->se, gi2c->tx_wm, tx_depth); + geni_se_config_packing(&gi2c->se, BITS_PER_BYTE, + PACKING_BYTES_PW, true, true, true); + + dev_dbg(gi2c->se.dev, "i2c fifo/se-dma mode. fifo depth:%d\n", tx_depth); + } + +err: + pm_runtime_put(gi2c->se.dev); + return ret; +} + static int geni_i2c_probe(struct platform_device *pdev) { struct geni_i2c_dev *gi2c; - u32 proto, tx_depth, fifo_disable; int ret; struct device *dev = &pdev->dev; const struct geni_i2c_desc *desc = NULL; @@ -1060,102 +1127,27 @@ static int geni_i2c_probe(struct platform_device *pdev) if (ret) return ret; - ret = clk_prepare_enable(gi2c->core_clk); - if (ret) - return ret; - - ret = geni_se_resources_on(&gi2c->se); - if (ret) { - dev_err_probe(dev, ret, "Error turning on resources\n"); - goto err_clk; - } - proto = geni_se_read_proto(&gi2c->se); - if (proto == GENI_SE_INVALID_PROTO) { - ret = geni_load_se_firmware(&gi2c->se, GENI_SE_I2C); - if (ret) { - dev_err_probe(dev, ret, "i2c firmware load failed ret: %d\n", ret); - goto err_resources; - } - } else if (proto != GENI_SE_I2C) { - ret = dev_err_probe(dev, -ENXIO, "Invalid proto %d\n", proto); - goto err_resources; - } - - if (desc && desc->no_dma_support) { - fifo_disable = false; - gi2c->no_dma = true; - } else { - fifo_disable = readl_relaxed(gi2c->se.base + GENI_IF_DISABLE_RO) & FIFO_IF_DISABLE; - } - - if (fifo_disable) { - /* FIFO is disabled, so we can only use GPI DMA */ - gi2c->gpi_mode = true; - ret = setup_gpi_dma(gi2c); - if (ret) - goto err_resources; - - dev_dbg(dev, "Using GPI DMA mode for I2C\n"); - } else { - gi2c->gpi_mode = false; - tx_depth = geni_se_get_tx_fifo_depth(&gi2c->se); - - /* I2C Master Hub Serial Elements doesn't have the HW_PARAM_0 register */ - if (!tx_depth && desc) - tx_depth = desc->tx_fifo_depth; - - if (!tx_depth) { - ret = dev_err_probe(dev, -EINVAL, - "Invalid TX FIFO depth\n"); - goto err_resources; - } - - gi2c->tx_wm = tx_depth - 1; - geni_se_init(&gi2c->se, gi2c->tx_wm, tx_depth); - geni_se_config_packing(&gi2c->se, BITS_PER_BYTE, - PACKING_BYTES_PW, true, true, true); - - dev_dbg(dev, "i2c fifo/se-dma mode. fifo depth:%d\n", tx_depth); - } - - clk_disable_unprepare(gi2c->core_clk); - ret = geni_se_resources_off(&gi2c->se); - if (ret) { - dev_err_probe(dev, ret, "Error turning off resources\n"); - goto err_dma; - } - - ret = geni_icc_disable(&gi2c->se); - if (ret) - goto err_dma; - gi2c->suspended = 1; pm_runtime_set_suspended(gi2c->se.dev); pm_runtime_set_autosuspend_delay(gi2c->se.dev, I2C_AUTO_SUSPEND_DELAY); pm_runtime_use_autosuspend(gi2c->se.dev); pm_runtime_enable(gi2c->se.dev); + ret = geni_i2c_init(gi2c); + if (ret < 0) { + pm_runtime_disable(gi2c->se.dev); + return ret; + } + ret = i2c_add_adapter(&gi2c->adap); if (ret) { dev_err_probe(dev, ret, "Error adding i2c adapter\n"); pm_runtime_disable(gi2c->se.dev); - goto err_dma; + return ret; } dev_dbg(dev, "Geni-I2C adaptor successfully added\n"); - return ret; - -err_resources: - geni_se_resources_off(&gi2c->se); -err_clk: - clk_disable_unprepare(gi2c->core_clk); - - return ret; - -err_dma: - release_gpi_dma(gi2c); - return ret; } -- 2.34.1
{ "author": "Praveen Talari <praveen.talari@oss.qualcomm.com>", "date": "Mon, 2 Feb 2026 23:39:18 +0530", "thread_id": "20260202180922.1692428-13-praveen.talari@oss.qualcomm.com.mbox.gz" }
lkml
[PATCH v4 00/13] Enable I2C on SA8255p Qualcomm platforms
The Qualcomm automotive SA8255p SoC relies on firmware to configure platform resources, including clocks, interconnects and TLMM. The driver requests resources operations over SCMI using power and performance protocols. The SCMI power protocol enables or disables resources like clocks, interconnect paths, and TLMM (GPIOs) using runtime PM framework APIs, such as resume/suspend, to control power states(on/off). The SCMI performance protocol manages I2C frequency, with each frequency rate represented by a performance level. The driver uses geni_se_set_perf_opp() API to request the desired frequency rate.. As part of geni_se_set_perf_opp(), the OPP for the requested frequency is obtained using dev_pm_opp_find_freq_floor() and the performance level is set using dev_pm_opp_set_opp(). Praveen Talari (13): soc: qcom: geni-se: Refactor geni_icc_get() and make qup-memory ICC path optional soc: qcom: geni-se: Add geni_icc_set_bw_ab() function soc: qcom: geni-se: Introduce helper API for resource initialization soc: qcom: geni-se: Handle core clk in geni_se_clks_off() and geni_se_clks_on() soc: qcom: geni-se: Add resources activation/deactivation helpers soc: qcom: geni-se: Introduce helper API for attaching power domains soc: qcom: geni-se: Introduce helper APIs for performance control dt-bindings: i2c: Describe SA8255p i2c: qcom-geni: Isolate serial engine setup i2c: qcom-geni: Move resource initialization to separate function i2c: qcom-geni: Use resources helper APIs in runtime PM functions i2c: qcom-geni: Store of_device_id data in driver private struct i2c: qcom-geni: Enable I2C on SA8255p Qualcomm platforms --- v3->v4 - Added a new patch(4/13) to handle core clk as part of geni_se_clks_off/on(). --- .../bindings/i2c/qcom,sa8255p-geni-i2c.yaml | 64 ++++ drivers/i2c/busses/i2c-qcom-geni.c | 303 +++++++++--------- drivers/soc/qcom/qcom-geni-se.c | 265 +++++++++++++-- include/linux/soc/qcom/geni-se.h | 19 ++ 4 files changed, 476 insertions(+), 175 deletions(-) create mode 100644 Documentation/devicetree/bindings/i2c/qcom,sa8255p-geni-i2c.yaml base-commit: 193579fe01389bc21aff0051d13f24e8ea95b47d -- 2.34.1
Refactor the resource initialization in geni_i2c_probe() by introducing a new geni_i2c_resources_init() function and utilizing the common geni_se_resources_init() framework and clock frequency mapping, making the probe function cleaner. Acked-by: Viken Dadhaniya <viken.dadhaniya@oss.qualcomm.com> Signed-off-by: Praveen Talari <praveen.talari@oss.qualcomm.com> --- v3->v4: - Added Acked-by tag. v1->v2: - Updated commit text. --- drivers/i2c/busses/i2c-qcom-geni.c | 53 ++++++++++++------------------ 1 file changed, 21 insertions(+), 32 deletions(-) diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c index 81ed1596ac9f..56eebefda75f 100644 --- a/drivers/i2c/busses/i2c-qcom-geni.c +++ b/drivers/i2c/busses/i2c-qcom-geni.c @@ -1045,6 +1045,23 @@ static int geni_i2c_init(struct geni_i2c_dev *gi2c) return ret; } +static int geni_i2c_resources_init(struct geni_i2c_dev *gi2c) +{ + int ret; + + ret = geni_se_resources_init(&gi2c->se); + if (ret) + return ret; + + ret = geni_i2c_clk_map_idx(gi2c); + if (ret) + return dev_err_probe(gi2c->se.dev, ret, "Invalid clk frequency %d Hz\n", + gi2c->clk_freq_out); + + return geni_icc_set_bw_ab(&gi2c->se, GENI_DEFAULT_BW, GENI_DEFAULT_BW, + Bps_to_icc(gi2c->clk_freq_out)); +} + static int geni_i2c_probe(struct platform_device *pdev) { struct geni_i2c_dev *gi2c; @@ -1064,16 +1081,6 @@ static int geni_i2c_probe(struct platform_device *pdev) desc = device_get_match_data(&pdev->dev); - if (desc && desc->has_core_clk) { - gi2c->core_clk = devm_clk_get(dev, "core"); - if (IS_ERR(gi2c->core_clk)) - return PTR_ERR(gi2c->core_clk); - } - - gi2c->se.clk = devm_clk_get(dev, "se"); - if (IS_ERR(gi2c->se.clk) && !has_acpi_companion(dev)) - return PTR_ERR(gi2c->se.clk); - ret = device_property_read_u32(dev, "clock-frequency", &gi2c->clk_freq_out); if (ret) { @@ -1088,16 +1095,15 @@ static int geni_i2c_probe(struct platform_device *pdev) if (gi2c->irq < 0) return gi2c->irq; - ret = geni_i2c_clk_map_idx(gi2c); - if (ret) - return dev_err_probe(dev, ret, "Invalid clk frequency %d Hz\n", - gi2c->clk_freq_out); - gi2c->adap.algo = &geni_i2c_algo; init_completion(&gi2c->done); spin_lock_init(&gi2c->lock); platform_set_drvdata(pdev, gi2c); + ret = geni_i2c_resources_init(gi2c); + if (ret) + return ret; + /* Keep interrupts disabled initially to allow for low-power modes */ ret = devm_request_irq(dev, gi2c->irq, geni_i2c_irq, IRQF_NO_AUTOEN, dev_name(dev), gi2c); @@ -1110,23 +1116,6 @@ static int geni_i2c_probe(struct platform_device *pdev) gi2c->adap.dev.of_node = dev->of_node; strscpy(gi2c->adap.name, "Geni-I2C", sizeof(gi2c->adap.name)); - ret = geni_icc_get(&gi2c->se, desc ? desc->icc_ddr : "qup-memory"); - if (ret) - return ret; - /* - * Set the bus quota for core and cpu to a reasonable value for - * register access. - * Set quota for DDR based on bus speed. - */ - gi2c->se.icc_paths[GENI_TO_CORE].avg_bw = GENI_DEFAULT_BW; - gi2c->se.icc_paths[CPU_TO_GENI].avg_bw = GENI_DEFAULT_BW; - if (!desc || desc->icc_ddr) - gi2c->se.icc_paths[GENI_TO_DDR].avg_bw = Bps_to_icc(gi2c->clk_freq_out); - - ret = geni_icc_set_bw(&gi2c->se); - if (ret) - return ret; - gi2c->suspended = 1; pm_runtime_set_suspended(gi2c->se.dev); pm_runtime_set_autosuspend_delay(gi2c->se.dev, I2C_AUTO_SUSPEND_DELAY); -- 2.34.1
{ "author": "Praveen Talari <praveen.talari@oss.qualcomm.com>", "date": "Mon, 2 Feb 2026 23:39:19 +0530", "thread_id": "20260202180922.1692428-13-praveen.talari@oss.qualcomm.com.mbox.gz" }
lkml
[PATCH v4 00/13] Enable I2C on SA8255p Qualcomm platforms
The Qualcomm automotive SA8255p SoC relies on firmware to configure platform resources, including clocks, interconnects and TLMM. The driver requests resources operations over SCMI using power and performance protocols. The SCMI power protocol enables or disables resources like clocks, interconnect paths, and TLMM (GPIOs) using runtime PM framework APIs, such as resume/suspend, to control power states(on/off). The SCMI performance protocol manages I2C frequency, with each frequency rate represented by a performance level. The driver uses geni_se_set_perf_opp() API to request the desired frequency rate.. As part of geni_se_set_perf_opp(), the OPP for the requested frequency is obtained using dev_pm_opp_find_freq_floor() and the performance level is set using dev_pm_opp_set_opp(). Praveen Talari (13): soc: qcom: geni-se: Refactor geni_icc_get() and make qup-memory ICC path optional soc: qcom: geni-se: Add geni_icc_set_bw_ab() function soc: qcom: geni-se: Introduce helper API for resource initialization soc: qcom: geni-se: Handle core clk in geni_se_clks_off() and geni_se_clks_on() soc: qcom: geni-se: Add resources activation/deactivation helpers soc: qcom: geni-se: Introduce helper API for attaching power domains soc: qcom: geni-se: Introduce helper APIs for performance control dt-bindings: i2c: Describe SA8255p i2c: qcom-geni: Isolate serial engine setup i2c: qcom-geni: Move resource initialization to separate function i2c: qcom-geni: Use resources helper APIs in runtime PM functions i2c: qcom-geni: Store of_device_id data in driver private struct i2c: qcom-geni: Enable I2C on SA8255p Qualcomm platforms --- v3->v4 - Added a new patch(4/13) to handle core clk as part of geni_se_clks_off/on(). --- .../bindings/i2c/qcom,sa8255p-geni-i2c.yaml | 64 ++++ drivers/i2c/busses/i2c-qcom-geni.c | 303 +++++++++--------- drivers/soc/qcom/qcom-geni-se.c | 265 +++++++++++++-- include/linux/soc/qcom/geni-se.h | 19 ++ 4 files changed, 476 insertions(+), 175 deletions(-) create mode 100644 Documentation/devicetree/bindings/i2c/qcom,sa8255p-geni-i2c.yaml base-commit: 193579fe01389bc21aff0051d13f24e8ea95b47d -- 2.34.1
To manage GENI serial engine resources during runtime power management, drivers currently need to call functions for ICC, clock, and SE resource operations in both suspend and resume paths, resulting in code duplication across drivers. The new geni_se_resources_activate() and geni_se_resources_deactivate() helper APIs addresses this issue by providing a streamlined method to enable or disable all resources based, thereby eliminating redundancy across drivers. Acked-by: Viken Dadhaniya <viken.dadhaniya@oss.qualcomm.com> Signed-off-by: Praveen Talari <praveen.talari@oss.qualcomm.com> --- v3->v4: - Added Acked-by tag. v1->v2: Bjorn: - Remove geni_se_resources_state() API. - Used geni_se_resources_activate() and geni_se_resources_deactivate() to enable/disable resources. --- drivers/i2c/busses/i2c-qcom-geni.c | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c index 56eebefda75f..4ff84bb0fff5 100644 --- a/drivers/i2c/busses/i2c-qcom-geni.c +++ b/drivers/i2c/busses/i2c-qcom-geni.c @@ -1163,18 +1163,15 @@ static int __maybe_unused geni_i2c_runtime_suspend(struct device *dev) struct geni_i2c_dev *gi2c = dev_get_drvdata(dev); disable_irq(gi2c->irq); - ret = geni_se_resources_off(&gi2c->se); + + ret = geni_se_resources_deactivate(&gi2c->se); if (ret) { enable_irq(gi2c->irq); return ret; - - } else { - gi2c->suspended = 1; } - clk_disable_unprepare(gi2c->core_clk); - - return geni_icc_disable(&gi2c->se); + gi2c->suspended = 1; + return ret; } static int __maybe_unused geni_i2c_runtime_resume(struct device *dev) @@ -1182,28 +1179,13 @@ static int __maybe_unused geni_i2c_runtime_resume(struct device *dev) int ret; struct geni_i2c_dev *gi2c = dev_get_drvdata(dev); - ret = geni_icc_enable(&gi2c->se); + ret = geni_se_resources_activate(&gi2c->se); if (ret) return ret; - ret = clk_prepare_enable(gi2c->core_clk); - if (ret) - goto out_icc_disable; - - ret = geni_se_resources_on(&gi2c->se); - if (ret) - goto out_clk_disable; - enable_irq(gi2c->irq); gi2c->suspended = 0; - return 0; - -out_clk_disable: - clk_disable_unprepare(gi2c->core_clk); -out_icc_disable: - geni_icc_disable(&gi2c->se); - return ret; } -- 2.34.1
{ "author": "Praveen Talari <praveen.talari@oss.qualcomm.com>", "date": "Mon, 2 Feb 2026 23:39:20 +0530", "thread_id": "20260202180922.1692428-13-praveen.talari@oss.qualcomm.com.mbox.gz" }
lkml
[PATCH v4 00/13] Enable I2C on SA8255p Qualcomm platforms
The Qualcomm automotive SA8255p SoC relies on firmware to configure platform resources, including clocks, interconnects and TLMM. The driver requests resources operations over SCMI using power and performance protocols. The SCMI power protocol enables or disables resources like clocks, interconnect paths, and TLMM (GPIOs) using runtime PM framework APIs, such as resume/suspend, to control power states(on/off). The SCMI performance protocol manages I2C frequency, with each frequency rate represented by a performance level. The driver uses geni_se_set_perf_opp() API to request the desired frequency rate.. As part of geni_se_set_perf_opp(), the OPP for the requested frequency is obtained using dev_pm_opp_find_freq_floor() and the performance level is set using dev_pm_opp_set_opp(). Praveen Talari (13): soc: qcom: geni-se: Refactor geni_icc_get() and make qup-memory ICC path optional soc: qcom: geni-se: Add geni_icc_set_bw_ab() function soc: qcom: geni-se: Introduce helper API for resource initialization soc: qcom: geni-se: Handle core clk in geni_se_clks_off() and geni_se_clks_on() soc: qcom: geni-se: Add resources activation/deactivation helpers soc: qcom: geni-se: Introduce helper API for attaching power domains soc: qcom: geni-se: Introduce helper APIs for performance control dt-bindings: i2c: Describe SA8255p i2c: qcom-geni: Isolate serial engine setup i2c: qcom-geni: Move resource initialization to separate function i2c: qcom-geni: Use resources helper APIs in runtime PM functions i2c: qcom-geni: Store of_device_id data in driver private struct i2c: qcom-geni: Enable I2C on SA8255p Qualcomm platforms --- v3->v4 - Added a new patch(4/13) to handle core clk as part of geni_se_clks_off/on(). --- .../bindings/i2c/qcom,sa8255p-geni-i2c.yaml | 64 ++++ drivers/i2c/busses/i2c-qcom-geni.c | 303 +++++++++--------- drivers/soc/qcom/qcom-geni-se.c | 265 +++++++++++++-- include/linux/soc/qcom/geni-se.h | 19 ++ 4 files changed, 476 insertions(+), 175 deletions(-) create mode 100644 Documentation/devicetree/bindings/i2c/qcom,sa8255p-geni-i2c.yaml base-commit: 193579fe01389bc21aff0051d13f24e8ea95b47d -- 2.34.1
To avoid repeatedly fetching and checking platform data across various functions, store the struct of_device_id data directly in the i2c private structure. This change enhances code maintainability and reduces redundancy. Acked-by: Viken Dadhaniya <viken.dadhaniya@oss.qualcomm.com> Signed-off-by: Praveen Talari <praveen.talari@oss.qualcomm.com> --- v3->v4 - Added Acked-by tag. Konrad - Removed icc_ddr from platfrom data struct --- drivers/i2c/busses/i2c-qcom-geni.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c index 4ff84bb0fff5..8fd62d659c2a 100644 --- a/drivers/i2c/busses/i2c-qcom-geni.c +++ b/drivers/i2c/busses/i2c-qcom-geni.c @@ -77,6 +77,12 @@ enum geni_i2c_err_code { #define XFER_TIMEOUT HZ #define RST_TIMEOUT HZ +struct geni_i2c_desc { + bool has_core_clk; + bool no_dma_support; + unsigned int tx_fifo_depth; +}; + #define QCOM_I2C_MIN_NUM_OF_MSGS_MULTI_DESC 2 /** @@ -122,13 +128,7 @@ struct geni_i2c_dev { bool is_tx_multi_desc_xfer; u32 num_msgs; struct geni_i2c_gpi_multi_desc_xfer i2c_multi_desc_config; -}; - -struct geni_i2c_desc { - bool has_core_clk; - char *icc_ddr; - bool no_dma_support; - unsigned int tx_fifo_depth; + const struct geni_i2c_desc *dev_data; }; struct geni_i2c_err_log { @@ -979,7 +979,6 @@ static int setup_gpi_dma(struct geni_i2c_dev *gi2c) static int geni_i2c_init(struct geni_i2c_dev *gi2c) { - const struct geni_i2c_desc *desc = NULL; u32 proto, tx_depth; bool fifo_disable; int ret; @@ -1002,8 +1001,7 @@ static int geni_i2c_init(struct geni_i2c_dev *gi2c) goto err; } - desc = device_get_match_data(gi2c->se.dev); - if (desc && desc->no_dma_support) { + if (gi2c->dev_data->no_dma_support) { fifo_disable = false; gi2c->no_dma = true; } else { @@ -1023,8 +1021,8 @@ static int geni_i2c_init(struct geni_i2c_dev *gi2c) tx_depth = geni_se_get_tx_fifo_depth(&gi2c->se); /* I2C Master Hub Serial Elements doesn't have the HW_PARAM_0 register */ - if (!tx_depth && desc) - tx_depth = desc->tx_fifo_depth; + if (!tx_depth && gi2c->dev_data->has_core_clk) + tx_depth = gi2c->dev_data->tx_fifo_depth; if (!tx_depth) { ret = dev_err_probe(gi2c->se.dev, -EINVAL, @@ -1067,7 +1065,6 @@ static int geni_i2c_probe(struct platform_device *pdev) struct geni_i2c_dev *gi2c; int ret; struct device *dev = &pdev->dev; - const struct geni_i2c_desc *desc = NULL; gi2c = devm_kzalloc(dev, sizeof(*gi2c), GFP_KERNEL); if (!gi2c) @@ -1079,7 +1076,7 @@ static int geni_i2c_probe(struct platform_device *pdev) if (IS_ERR(gi2c->se.base)) return PTR_ERR(gi2c->se.base); - desc = device_get_match_data(&pdev->dev); + gi2c->dev_data = device_get_match_data(&pdev->dev); ret = device_property_read_u32(dev, "clock-frequency", &gi2c->clk_freq_out); @@ -1218,15 +1215,16 @@ static const struct dev_pm_ops geni_i2c_pm_ops = { NULL) }; +static const struct geni_i2c_desc geni_i2c = {}; + static const struct geni_i2c_desc i2c_master_hub = { .has_core_clk = true, - .icc_ddr = NULL, .no_dma_support = true, .tx_fifo_depth = 16, }; static const struct of_device_id geni_i2c_dt_match[] = { - { .compatible = "qcom,geni-i2c" }, + { .compatible = "qcom,geni-i2c", .data = &geni_i2c }, { .compatible = "qcom,geni-i2c-master-hub", .data = &i2c_master_hub }, {} }; -- 2.34.1
{ "author": "Praveen Talari <praveen.talari@oss.qualcomm.com>", "date": "Mon, 2 Feb 2026 23:39:21 +0530", "thread_id": "20260202180922.1692428-13-praveen.talari@oss.qualcomm.com.mbox.gz" }
lkml
[PATCH v4 00/13] Enable I2C on SA8255p Qualcomm platforms
The Qualcomm automotive SA8255p SoC relies on firmware to configure platform resources, including clocks, interconnects and TLMM. The driver requests resources operations over SCMI using power and performance protocols. The SCMI power protocol enables or disables resources like clocks, interconnect paths, and TLMM (GPIOs) using runtime PM framework APIs, such as resume/suspend, to control power states(on/off). The SCMI performance protocol manages I2C frequency, with each frequency rate represented by a performance level. The driver uses geni_se_set_perf_opp() API to request the desired frequency rate.. As part of geni_se_set_perf_opp(), the OPP for the requested frequency is obtained using dev_pm_opp_find_freq_floor() and the performance level is set using dev_pm_opp_set_opp(). Praveen Talari (13): soc: qcom: geni-se: Refactor geni_icc_get() and make qup-memory ICC path optional soc: qcom: geni-se: Add geni_icc_set_bw_ab() function soc: qcom: geni-se: Introduce helper API for resource initialization soc: qcom: geni-se: Handle core clk in geni_se_clks_off() and geni_se_clks_on() soc: qcom: geni-se: Add resources activation/deactivation helpers soc: qcom: geni-se: Introduce helper API for attaching power domains soc: qcom: geni-se: Introduce helper APIs for performance control dt-bindings: i2c: Describe SA8255p i2c: qcom-geni: Isolate serial engine setup i2c: qcom-geni: Move resource initialization to separate function i2c: qcom-geni: Use resources helper APIs in runtime PM functions i2c: qcom-geni: Store of_device_id data in driver private struct i2c: qcom-geni: Enable I2C on SA8255p Qualcomm platforms --- v3->v4 - Added a new patch(4/13) to handle core clk as part of geni_se_clks_off/on(). --- .../bindings/i2c/qcom,sa8255p-geni-i2c.yaml | 64 ++++ drivers/i2c/busses/i2c-qcom-geni.c | 303 +++++++++--------- drivers/soc/qcom/qcom-geni-se.c | 265 +++++++++++++-- include/linux/soc/qcom/geni-se.h | 19 ++ 4 files changed, 476 insertions(+), 175 deletions(-) create mode 100644 Documentation/devicetree/bindings/i2c/qcom,sa8255p-geni-i2c.yaml base-commit: 193579fe01389bc21aff0051d13f24e8ea95b47d -- 2.34.1
The Qualcomm automotive SA8255p SoC relies on firmware to configure platform resources, including clocks, interconnects and TLMM. The driver requests resources operations over SCMI using power and performance protocols. The SCMI power protocol enables or disables resources like clocks, interconnect paths, and TLMM (GPIOs) using runtime PM framework APIs, such as resume/suspend, to control power on/off. The SCMI performance protocol manages I2C frequency, with each frequency rate represented by a performance level. The driver uses geni_se_set_perf_opp() API to request the desired frequency rate.. As part of geni_se_set_perf_opp(), the OPP for the requested frequency is obtained using dev_pm_opp_find_freq_floor() and the performance level is set using dev_pm_opp_set_opp(). Acked-by: Viken Dadhaniya <viken.dadhaniya@oss.qualcomm.com> Signed-off-by: Praveen Talari <praveen.talari@oss.qualcomm.com> --- v3->v4: - Added Acked-by tag. V1->v2: - Initialized ret to "0" in resume/suspend callbacks. Bjorn: - Used seperate APIs for the resouces enable/disable. --- drivers/i2c/busses/i2c-qcom-geni.c | 56 ++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c index 8fd62d659c2a..2ad31e412b96 100644 --- a/drivers/i2c/busses/i2c-qcom-geni.c +++ b/drivers/i2c/busses/i2c-qcom-geni.c @@ -81,6 +81,10 @@ struct geni_i2c_desc { bool has_core_clk; bool no_dma_support; unsigned int tx_fifo_depth; + int (*resources_init)(struct geni_se *se); + int (*set_rate)(struct geni_se *se, unsigned long freq); + int (*power_on)(struct geni_se *se); + int (*power_off)(struct geni_se *se); }; #define QCOM_I2C_MIN_NUM_OF_MSGS_MULTI_DESC 2 @@ -203,8 +207,9 @@ static int geni_i2c_clk_map_idx(struct geni_i2c_dev *gi2c) return -EINVAL; } -static void qcom_geni_i2c_conf(struct geni_i2c_dev *gi2c) +static int qcom_geni_i2c_conf(struct geni_se *se, unsigned long freq) { + struct geni_i2c_dev *gi2c = dev_get_drvdata(se->dev); const struct geni_i2c_clk_fld *itr = gi2c->clk_fld; u32 val; @@ -217,6 +222,7 @@ static void qcom_geni_i2c_conf(struct geni_i2c_dev *gi2c) val |= itr->t_low_cnt << LOW_COUNTER_SHFT; val |= itr->t_cycle_cnt; writel_relaxed(val, gi2c->se.base + SE_I2C_SCL_COUNTERS); + return 0; } static void geni_i2c_err_misc(struct geni_i2c_dev *gi2c) @@ -908,7 +914,9 @@ static int geni_i2c_xfer(struct i2c_adapter *adap, return ret; } - qcom_geni_i2c_conf(gi2c); + ret = gi2c->dev_data->set_rate(&gi2c->se, gi2c->clk_freq_out); + if (ret) + return ret; if (gi2c->gpi_mode) ret = geni_i2c_gpi_xfer(gi2c, msgs, num); @@ -1043,8 +1051,9 @@ static int geni_i2c_init(struct geni_i2c_dev *gi2c) return ret; } -static int geni_i2c_resources_init(struct geni_i2c_dev *gi2c) +static int geni_i2c_resources_init(struct geni_se *se) { + struct geni_i2c_dev *gi2c = dev_get_drvdata(se->dev); int ret; ret = geni_se_resources_init(&gi2c->se); @@ -1097,7 +1106,7 @@ static int geni_i2c_probe(struct platform_device *pdev) spin_lock_init(&gi2c->lock); platform_set_drvdata(pdev, gi2c); - ret = geni_i2c_resources_init(gi2c); + ret = gi2c->dev_data->resources_init(&gi2c->se); if (ret) return ret; @@ -1156,15 +1165,17 @@ static void geni_i2c_shutdown(struct platform_device *pdev) static int __maybe_unused geni_i2c_runtime_suspend(struct device *dev) { - int ret; + int ret = 0; struct geni_i2c_dev *gi2c = dev_get_drvdata(dev); disable_irq(gi2c->irq); - ret = geni_se_resources_deactivate(&gi2c->se); - if (ret) { - enable_irq(gi2c->irq); - return ret; + if (gi2c->dev_data->power_off) { + ret = gi2c->dev_data->power_off(&gi2c->se); + if (ret) { + enable_irq(gi2c->irq); + return ret; + } } gi2c->suspended = 1; @@ -1173,12 +1184,14 @@ static int __maybe_unused geni_i2c_runtime_suspend(struct device *dev) static int __maybe_unused geni_i2c_runtime_resume(struct device *dev) { - int ret; + int ret = 0; struct geni_i2c_dev *gi2c = dev_get_drvdata(dev); - ret = geni_se_resources_activate(&gi2c->se); - if (ret) - return ret; + if (gi2c->dev_data->power_on) { + ret = gi2c->dev_data->power_on(&gi2c->se); + if (ret) + return ret; + } enable_irq(gi2c->irq); gi2c->suspended = 0; @@ -1215,17 +1228,32 @@ static const struct dev_pm_ops geni_i2c_pm_ops = { NULL) }; -static const struct geni_i2c_desc geni_i2c = {}; +static const struct geni_i2c_desc geni_i2c = { + .resources_init = geni_i2c_resources_init, + .set_rate = qcom_geni_i2c_conf, + .power_on = geni_se_resources_activate, + .power_off = geni_se_resources_deactivate, +}; static const struct geni_i2c_desc i2c_master_hub = { .has_core_clk = true, .no_dma_support = true, .tx_fifo_depth = 16, + .resources_init = geni_i2c_resources_init, + .set_rate = qcom_geni_i2c_conf, + .power_on = geni_se_resources_activate, + .power_off = geni_se_resources_deactivate, +}; + +static const struct geni_i2c_desc sa8255p_geni_i2c = { + .resources_init = geni_se_domain_attach, + .set_rate = geni_se_set_perf_opp, }; static const struct of_device_id geni_i2c_dt_match[] = { { .compatible = "qcom,geni-i2c", .data = &geni_i2c }, { .compatible = "qcom,geni-i2c-master-hub", .data = &i2c_master_hub }, + { .compatible = "qcom,sa8255p-geni-i2c", .data = &sa8255p_geni_i2c }, {} }; MODULE_DEVICE_TABLE(of, geni_i2c_dt_match); -- 2.34.1
{ "author": "Praveen Talari <praveen.talari@oss.qualcomm.com>", "date": "Mon, 2 Feb 2026 23:39:22 +0530", "thread_id": "20260202180922.1692428-13-praveen.talari@oss.qualcomm.com.mbox.gz" }
lkml
[PATCH] mm/zswap: remove SWP_SYNCHRONOUS_IO swapcache bypass workaround
From: Kairui Song <kasong@tencent.com> Since commit f1879e8a0c60 ("mm, swap: never bypass the swap cache even for SWP_SYNCHRONOUS_IO"), all swap-in operations go through the swap cache, including those from SWP_SYNCHRONOUS_IO devices like zram. Which means the workaround for swap cache bypassing introduced by commit 25cd241408a2 ("mm: zswap: fix data loss on SWP_SYNCHRONOUS_IO devices") is no longer needed. Remove it, but keep the comments that are still helpful. Suggested-by: Yosry Ahmed <yosry.ahmed@linux.dev> Signed-off-by: Kairui Song <kasong@tencent.com> --- mm/zswap.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 3d2d59ac3f9c..8cd61603ff79 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1589,11 +1589,11 @@ int zswap_load(struct folio *folio) { swp_entry_t swp = folio->swap; pgoff_t offset = swp_offset(swp); - bool swapcache = folio_test_swapcache(folio); struct xarray *tree = swap_zswap_tree(swp); struct zswap_entry *entry; VM_WARN_ON_ONCE(!folio_test_locked(folio)); + VM_WARN_ON_ONCE(!folio_test_swapcache(folio)); if (zswap_never_enabled()) return -ENOENT; @@ -1624,22 +1624,15 @@ int zswap_load(struct folio *folio) count_objcg_events(entry->objcg, ZSWPIN, 1); /* - * When reading into the swapcache, invalidate our entry. The - * swapcache can be the authoritative owner of the page and + * We are reading into the swapcache, invalidate zswap entry. + * The swapcache is the authoritative owner of the page and * its mappings, and the pressure that results from having two * in-memory copies outweighs any benefits of caching the * compression work. - * - * (Most swapins go through the swapcache. The notable - * exception is the singleton fault on SWP_SYNCHRONOUS_IO - * files, which reads into a private page and may free it if - * the fault fails. We remain the primary owner of the entry.) */ - if (swapcache) { - folio_mark_dirty(folio); - xa_erase(tree, offset); - zswap_entry_free(entry); - } + folio_mark_dirty(folio); + xa_erase(tree, offset); + zswap_entry_free(entry); folio_unlock(folio); return 0; --- base-commit: 2c263046cbe6d9d5fce3dfeba063f199f7e6298f change-id: 20251226-zswap-syncio-cleanup-a05b7fc6180f Best regards, -- Kairui Song <kasong@tencent.com>
On Mon, Feb 2, 2026 at 1:47 AM Kairui Song <ryncsn@gmail.com> wrote: LGTM, thanks! Reviewed-by: Barry Song <baohua@kernel.org>
{ "author": "Barry Song <21cnbao@gmail.com>", "date": "Mon, 2 Feb 2026 00:46:32 +0800", "thread_id": "CACePvbUQaAw5Upz86kV0Wc9E71UHEm6MATYPAPajy2X2O=eWew@mail.gmail.com.mbox.gz" }
lkml
[PATCH] mm/zswap: remove SWP_SYNCHRONOUS_IO swapcache bypass workaround
From: Kairui Song <kasong@tencent.com> Since commit f1879e8a0c60 ("mm, swap: never bypass the swap cache even for SWP_SYNCHRONOUS_IO"), all swap-in operations go through the swap cache, including those from SWP_SYNCHRONOUS_IO devices like zram. Which means the workaround for swap cache bypassing introduced by commit 25cd241408a2 ("mm: zswap: fix data loss on SWP_SYNCHRONOUS_IO devices") is no longer needed. Remove it, but keep the comments that are still helpful. Suggested-by: Yosry Ahmed <yosry.ahmed@linux.dev> Signed-off-by: Kairui Song <kasong@tencent.com> --- mm/zswap.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 3d2d59ac3f9c..8cd61603ff79 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1589,11 +1589,11 @@ int zswap_load(struct folio *folio) { swp_entry_t swp = folio->swap; pgoff_t offset = swp_offset(swp); - bool swapcache = folio_test_swapcache(folio); struct xarray *tree = swap_zswap_tree(swp); struct zswap_entry *entry; VM_WARN_ON_ONCE(!folio_test_locked(folio)); + VM_WARN_ON_ONCE(!folio_test_swapcache(folio)); if (zswap_never_enabled()) return -ENOENT; @@ -1624,22 +1624,15 @@ int zswap_load(struct folio *folio) count_objcg_events(entry->objcg, ZSWPIN, 1); /* - * When reading into the swapcache, invalidate our entry. The - * swapcache can be the authoritative owner of the page and + * We are reading into the swapcache, invalidate zswap entry. + * The swapcache is the authoritative owner of the page and * its mappings, and the pressure that results from having two * in-memory copies outweighs any benefits of caching the * compression work. - * - * (Most swapins go through the swapcache. The notable - * exception is the singleton fault on SWP_SYNCHRONOUS_IO - * files, which reads into a private page and may free it if - * the fault fails. We remain the primary owner of the entry.) */ - if (swapcache) { - folio_mark_dirty(folio); - xa_erase(tree, offset); - zswap_entry_free(entry); - } + folio_mark_dirty(folio); + xa_erase(tree, offset); + zswap_entry_free(entry); folio_unlock(folio); return 0; --- base-commit: 2c263046cbe6d9d5fce3dfeba063f199f7e6298f change-id: 20251226-zswap-syncio-cleanup-a05b7fc6180f Best regards, -- Kairui Song <kasong@tencent.com>
On Sun, Feb 1, 2026 at 9:47 AM Kairui Song <ryncsn@gmail.com> wrote: Acked-by: Chris Li <chrisl@kernel.org> Chris
{ "author": "Chris Li <chrisl@kernel.org>", "date": "Mon, 2 Feb 2026 10:22:45 -0800", "thread_id": "CACePvbUQaAw5Upz86kV0Wc9E71UHEm6MATYPAPajy2X2O=eWew@mail.gmail.com.mbox.gz" }
lkml
[PATCH] mm/zswap: remove SWP_SYNCHRONOUS_IO swapcache bypass workaround
From: Kairui Song <kasong@tencent.com> Since commit f1879e8a0c60 ("mm, swap: never bypass the swap cache even for SWP_SYNCHRONOUS_IO"), all swap-in operations go through the swap cache, including those from SWP_SYNCHRONOUS_IO devices like zram. Which means the workaround for swap cache bypassing introduced by commit 25cd241408a2 ("mm: zswap: fix data loss on SWP_SYNCHRONOUS_IO devices") is no longer needed. Remove it, but keep the comments that are still helpful. Suggested-by: Yosry Ahmed <yosry.ahmed@linux.dev> Signed-off-by: Kairui Song <kasong@tencent.com> --- mm/zswap.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 3d2d59ac3f9c..8cd61603ff79 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1589,11 +1589,11 @@ int zswap_load(struct folio *folio) { swp_entry_t swp = folio->swap; pgoff_t offset = swp_offset(swp); - bool swapcache = folio_test_swapcache(folio); struct xarray *tree = swap_zswap_tree(swp); struct zswap_entry *entry; VM_WARN_ON_ONCE(!folio_test_locked(folio)); + VM_WARN_ON_ONCE(!folio_test_swapcache(folio)); if (zswap_never_enabled()) return -ENOENT; @@ -1624,22 +1624,15 @@ int zswap_load(struct folio *folio) count_objcg_events(entry->objcg, ZSWPIN, 1); /* - * When reading into the swapcache, invalidate our entry. The - * swapcache can be the authoritative owner of the page and + * We are reading into the swapcache, invalidate zswap entry. + * The swapcache is the authoritative owner of the page and * its mappings, and the pressure that results from having two * in-memory copies outweighs any benefits of caching the * compression work. - * - * (Most swapins go through the swapcache. The notable - * exception is the singleton fault on SWP_SYNCHRONOUS_IO - * files, which reads into a private page and may free it if - * the fault fails. We remain the primary owner of the entry.) */ - if (swapcache) { - folio_mark_dirty(folio); - xa_erase(tree, offset); - zswap_entry_free(entry); - } + folio_mark_dirty(folio); + xa_erase(tree, offset); + zswap_entry_free(entry); folio_unlock(folio); return 0; --- base-commit: 2c263046cbe6d9d5fce3dfeba063f199f7e6298f change-id: 20251226-zswap-syncio-cleanup-a05b7fc6180f Best regards, -- Kairui Song <kasong@tencent.com>
On Mon, Feb 02, 2026 at 01:47:32AM +0800, Kairui Song wrote: Acked-by: Yosry Ahmed <yosry.ahmed@linux.dev> Thanks!
{ "author": "Yosry Ahmed <yosry.ahmed@linux.dev>", "date": "Mon, 2 Feb 2026 18:32:04 +0000", "thread_id": "CACePvbUQaAw5Upz86kV0Wc9E71UHEm6MATYPAPajy2X2O=eWew@mail.gmail.com.mbox.gz" }
lkml
[PATCH v2] ext4: publish jinode after initialization
ext4_inode_attach_jinode() publishes ei->jinode to concurrent users. It used to set ei->jinode before jbd2_journal_init_jbd_inode(), allowing a reader to observe a non-NULL jinode with i_vfs_inode still unset. The fast commit flush path can then pass this jinode to jbd2_wait_inode_data(), which dereferences i_vfs_inode->i_mapping and may crash. Below is the crash I observe: ``` BUG: unable to handle page fault for address: 000000010beb47f4 PGD 110e51067 P4D 110e51067 PUD 0 Oops: Oops: 0000 [#1] SMP NOPTI CPU: 1 UID: 0 PID: 4850 Comm: fc_fsync_bench_ Not tainted 6.18.0-00764-g795a690c06a5 #1 PREEMPT(voluntary) Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Arch Linux 1.17.0-2-2 04/01/2014 RIP: 0010:xas_find_marked+0x3d/0x2e0 Code: e0 03 48 83 f8 02 0f 84 f0 01 00 00 48 8b 47 08 48 89 c3 48 39 c6 0f 82 fd 01 00 00 48 85 c9 74 3d 48 83 f9 03 77 63 4c 8b 0f <49> 8b 71 08 48 c7 47 18 00 00 00 00 48 89 f1 83 e1 03 48 83 f9 02 RSP: 0018:ffffbbee806e7bf0 EFLAGS: 00010246 RAX: 000000000010beb4 RBX: 000000000010beb4 RCX: 0000000000000003 RDX: 0000000000000001 RSI: 0000002000300000 RDI: ffffbbee806e7c10 RBP: 0000000000000001 R08: 0000002000300000 R09: 000000010beb47ec R10: ffff9ea494590090 R11: 0000000000000000 R12: 0000002000300000 R13: ffffbbee806e7c90 R14: ffff9ea494513788 R15: ffffbbee806e7c88 FS: 00007fc2f9e3e6c0(0000) GS:ffff9ea6b1444000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 000000010beb47f4 CR3: 0000000119ac5000 CR4: 0000000000750ef0 PKRU: 55555554 Call Trace: <TASK> filemap_get_folios_tag+0x87/0x2a0 __filemap_fdatawait_range+0x5f/0xd0 ? srso_alias_return_thunk+0x5/0xfbef5 ? __schedule+0x3e7/0x10c0 ? srso_alias_return_thunk+0x5/0xfbef5 ? srso_alias_return_thunk+0x5/0xfbef5 ? srso_alias_return_thunk+0x5/0xfbef5 ? preempt_count_sub+0x5f/0x80 ? srso_alias_return_thunk+0x5/0xfbef5 ? cap_safe_nice+0x37/0x70 ? srso_alias_return_thunk+0x5/0xfbef5 ? preempt_count_sub+0x5f/0x80 ? srso_alias_return_thunk+0x5/0xfbef5 filemap_fdatawait_range_keep_errors+0x12/0x40 ext4_fc_commit+0x697/0x8b0 ? ext4_file_write_iter+0x64b/0x950 ? srso_alias_return_thunk+0x5/0xfbef5 ? preempt_count_sub+0x5f/0x80 ? srso_alias_return_thunk+0x5/0xfbef5 ? vfs_write+0x356/0x480 ? srso_alias_return_thunk+0x5/0xfbef5 ? preempt_count_sub+0x5f/0x80 ext4_sync_file+0xf7/0x370 do_fsync+0x3b/0x80 ? syscall_trace_enter+0x108/0x1d0 __x64_sys_fdatasync+0x16/0x20 do_syscall_64+0x62/0x2c0 entry_SYSCALL_64_after_hwframe+0x76/0x7e ... ``` Fix this by initializing the jbd2_inode first. Use smp_wmb() and WRITE_ONCE() to publish ei->jinode after initialization. Readers use READ_ONCE() to fetch the pointer. Fixes: a361293f5fede ("jbd2: Fix oops in jbd2_journal_file_inode()") Cc: stable@vger.kernel.org Signed-off-by: Li Chen <me@linux.beauty> --- Changes since v1: - Publish EXT4_I(inode)->jinode with smp_wmb() + WRITE_ONCE(), and fetch it with READ_ONCE() (instead of smp_store_release()/smp_load_acquire()), as suggeted by Jan. fs/ext4/ext4_jbd2.h | 16 ++++++++++++---- fs/ext4/fast_commit.c | 7 +++++-- fs/ext4/inode.c | 15 +++++++++++---- fs/ext4/super.c | 11 +++++++---- 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/fs/ext4/ext4_jbd2.h b/fs/ext4/ext4_jbd2.h index 63d17c5201b5..2d5343441b71 100644 --- a/fs/ext4/ext4_jbd2.h +++ b/fs/ext4/ext4_jbd2.h @@ -336,18 +336,26 @@ static inline int ext4_journal_force_commit(journal_t *journal) static inline int ext4_jbd2_inode_add_write(handle_t *handle, struct inode *inode, loff_t start_byte, loff_t length) { - if (ext4_handle_valid(handle)) + if (ext4_handle_valid(handle)) { + struct jbd2_inode *jinode; + + jinode = READ_ONCE(EXT4_I(inode)->jinode); return jbd2_journal_inode_ranged_write(handle, - EXT4_I(inode)->jinode, start_byte, length); + jinode, start_byte, length); + } return 0; } static inline int ext4_jbd2_inode_add_wait(handle_t *handle, struct inode *inode, loff_t start_byte, loff_t length) { - if (ext4_handle_valid(handle)) + if (ext4_handle_valid(handle)) { + struct jbd2_inode *jinode; + + jinode = READ_ONCE(EXT4_I(inode)->jinode); return jbd2_journal_inode_ranged_wait(handle, - EXT4_I(inode)->jinode, start_byte, length); + jinode, start_byte, length); + } return 0; } diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index f575751f1cae..a80ed2d6df81 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -972,16 +972,19 @@ static int ext4_fc_flush_data(journal_t *journal) struct super_block *sb = journal->j_private; struct ext4_sb_info *sbi = EXT4_SB(sb); struct ext4_inode_info *ei; + struct jbd2_inode *jinode; int ret = 0; list_for_each_entry(ei, &sbi->s_fc_q[FC_Q_MAIN], i_fc_list) { - ret = jbd2_submit_inode_data(journal, ei->jinode); + jinode = READ_ONCE(ei->jinode); + ret = jbd2_submit_inode_data(journal, jinode); if (ret) return ret; } list_for_each_entry(ei, &sbi->s_fc_q[FC_Q_MAIN], i_fc_list) { - ret = jbd2_wait_inode_data(journal, ei->jinode); + jinode = READ_ONCE(ei->jinode); + ret = jbd2_wait_inode_data(journal, jinode); if (ret) return ret; } diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index da96db5f2345..d99296d7315f 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -128,6 +128,8 @@ void ext4_inode_csum_set(struct inode *inode, struct ext4_inode *raw, static inline int ext4_begin_ordered_truncate(struct inode *inode, loff_t new_size) { + struct jbd2_inode *jinode = READ_ONCE(EXT4_I(inode)->jinode); + trace_ext4_begin_ordered_truncate(inode, new_size); /* * If jinode is zero, then we never opened the file for @@ -135,10 +137,10 @@ static inline int ext4_begin_ordered_truncate(struct inode *inode, * jbd2_journal_begin_ordered_truncate() since there's no * outstanding writes we need to flush. */ - if (!EXT4_I(inode)->jinode) + if (!jinode) return 0; return jbd2_journal_begin_ordered_truncate(EXT4_JOURNAL(inode), - EXT4_I(inode)->jinode, + jinode, new_size); } @@ -4478,8 +4480,13 @@ int ext4_inode_attach_jinode(struct inode *inode) spin_unlock(&inode->i_lock); return -ENOMEM; } - ei->jinode = jinode; - jbd2_journal_init_jbd_inode(ei->jinode, inode); + jbd2_journal_init_jbd_inode(jinode, inode); + /* + * Publish ->jinode only after it is fully initialized so that + * readers never observe a partially initialized jbd2_inode. + */ + smp_wmb(); + WRITE_ONCE(ei->jinode, jinode); jinode = NULL; } spin_unlock(&inode->i_lock); diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 69eb63dde983..5cf6c2b54bbb 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -1526,17 +1526,20 @@ static void destroy_inodecache(void) void ext4_clear_inode(struct inode *inode) { + struct jbd2_inode *jinode; + ext4_fc_del(inode); invalidate_inode_buffers(inode); clear_inode(inode); ext4_discard_preallocations(inode); ext4_es_remove_extent(inode, 0, EXT_MAX_BLOCKS); dquot_drop(inode); - if (EXT4_I(inode)->jinode) { + jinode = READ_ONCE(EXT4_I(inode)->jinode); + if (jinode) { jbd2_journal_release_jbd_inode(EXT4_JOURNAL(inode), - EXT4_I(inode)->jinode); - jbd2_free_inode(EXT4_I(inode)->jinode); - EXT4_I(inode)->jinode = NULL; + jinode); + jbd2_free_inode(jinode); + WRITE_ONCE(EXT4_I(inode)->jinode, NULL); } fscrypt_put_encryption_info(inode); fsverity_cleanup_inode(inode); -- 2.52.0
On Fri 30-01-26 10:53:38, Li Chen wrote: Looks pretty good. Some small comments below. ... After some thought these two are guaranteed to be called about EXT4_I(inode)->jinode is set and once set jinode never changes so I don't think we need to change anything here (and it's actually somewhat confusing because if jinode could be changing jbd2_journal_inode_ranged_wait() could crash...). Perhaps we don't need the intermediate variable here and can just write: ret = jbd2_submit_inode_data(journal, READ_ONCE(ei->jinode)); and similarly with jbd2_wait_inode_data(). These cannot ever race with anybody as by the time ext4_clear_inode() we are the exclusive owners of the inode. So there's no point in changing this code. Honza -- Jan Kara <jack@suse.com> SUSE Labs, CR
{ "author": "Jan Kara <jack@suse.cz>", "date": "Mon, 2 Feb 2026 17:37:48 +0100", "thread_id": "vrtwp467z7npa2uppdntauxfzexgaa4vja3nueqdcn7z6e7zll@hj3tjryw2dst.mbox.gz" }
lkml
[RFC PATCH 0/8] Fix TCSR representation on SM8750
As sparked by this thread: <20260112151725.2308971-1-mukesh.ojha@oss.qualcomm.com> The current representation of TCSR is wrong. On platforms post and including SM8550, the TCSR had a sub-block in it, containing gate clocks used for distributing the XO output to various consumers. This is what we refer to as TCSR_CC upstream. SM8750 however, is notably different. That same set of tunables had been moved to the TLMM register space. This is made worse, as the sm8750-tcsrcc driver consumes the qcom,sm8750-tcsr compatible. This hardware change had been undone with the generation following 8750. This series attempts to unwind that. It's difficult to merge, both for bindings and functional reasons.. I think it goes without saying this breaks backwards compatibility, but it has to be done to represent TCSR at all. The patches are ordered in a least-destructive order.. I gave this a quick spin on (remote) hw, the UFS (one of the consumers) still works, but more testing would be greatly appreciated. Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> --- Konrad Dybcio (8): dt-bindings: Move qcom,sm8750-tcsr from clock/tcsr to mfd/tcsr dt-bindings: pinctrl: qcom,sm8750-tlmm: Allow clocks/clock-cells pinctrl: qcom: Allow exposing reference clocks living in TLMM reg space pinctrl: qcom: sm8750: Expose reference clocks arm64: dts: qcom: Remove inexistent TCSR_CC clk: qcom: Remove tcsrcc-sm8750 arm64: dts: qcom: sm8750: Describe TCSR arm64: defconfig: Remove CONFIG_SM_TCSRCC_8750 .../bindings/clock/qcom,sm8550-tcsr.yaml | 2 - .../devicetree/bindings/mfd/qcom,tcsr.yaml | 1 + .../bindings/pinctrl/qcom,sm8750-tlmm.yaml | 12 ++ arch/arm64/boot/dts/qcom/sm8750.dtsi | 27 ++-- arch/arm64/configs/defconfig | 1 - drivers/clk/qcom/Kconfig | 8 -- drivers/clk/qcom/Makefile | 1 - drivers/clk/qcom/tcsrcc-sm8750.c | 141 --------------------- drivers/pinctrl/qcom/pinctrl-msm.c | 92 ++++++++++++++ drivers/pinctrl/qcom/pinctrl-msm.h | 14 ++ drivers/pinctrl/qcom/pinctrl-sm8750.c | 31 +++++ 11 files changed, 163 insertions(+), 167 deletions(-) --- base-commit: 4c87cdd0328495759f6e9f9f4e1e53ef8032a76f change-id: 20260202-topic-8750_tcsr-e2dafc2f11d1 Best regards, -- Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
From: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> The TCSR block is described in two places: clock/qcom,sm8550-tcsr.yaml and mfd/qcom,tcsr.yaml. The former refers to the version of the block containing various gate clocks, downstream from the main system refclk. The latter refers to a version lacking that, instead only providing various general tunables. The clock gates on SM8750 specifically (unlike a generation preceding and following it) do NOT live in TCSR, but in the TLMM (pinmux/cfg IP) register space instead. Move it to the mfd/tcsr binding to represent that. Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> --- Documentation/devicetree/bindings/clock/qcom,sm8550-tcsr.yaml | 2 -- Documentation/devicetree/bindings/mfd/qcom,tcsr.yaml | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/clock/qcom,sm8550-tcsr.yaml b/Documentation/devicetree/bindings/clock/qcom,sm8550-tcsr.yaml index 784fef830681..8da8f44fc8a5 100644 --- a/Documentation/devicetree/bindings/clock/qcom,sm8550-tcsr.yaml +++ b/Documentation/devicetree/bindings/clock/qcom,sm8550-tcsr.yaml @@ -18,7 +18,6 @@ description: | - include/dt-bindings/clock/qcom,glymur-tcsr.h - include/dt-bindings/clock/qcom,sm8550-tcsr.h - include/dt-bindings/clock/qcom,sm8650-tcsr.h - - include/dt-bindings/clock/qcom,sm8750-tcsr.h properties: compatible: @@ -30,7 +29,6 @@ properties: - qcom,sar2130p-tcsr - qcom,sm8550-tcsr - qcom,sm8650-tcsr - - qcom,sm8750-tcsr - qcom,x1e80100-tcsr - const: syscon diff --git a/Documentation/devicetree/bindings/mfd/qcom,tcsr.yaml b/Documentation/devicetree/bindings/mfd/qcom,tcsr.yaml index 14ae3f00ef7e..1a1fa2b79476 100644 --- a/Documentation/devicetree/bindings/mfd/qcom,tcsr.yaml +++ b/Documentation/devicetree/bindings/mfd/qcom,tcsr.yaml @@ -39,6 +39,7 @@ properties: - qcom,sm8250-tcsr - qcom,sm8350-tcsr - qcom,sm8450-tcsr + - qcom,sm8750-tcsr - qcom,tcsr-apq8064 - qcom,tcsr-apq8084 - qcom,tcsr-ipq5018 -- 2.52.0
{ "author": "Konrad Dybcio <konradybcio@kernel.org>", "date": "Mon, 02 Feb 2026 15:57:33 +0100", "thread_id": "20260202181917.imo5lk3smwott2ue@hu-mojha-hyd.qualcomm.com.mbox.gz" }
lkml
[RFC PATCH 0/8] Fix TCSR representation on SM8750
As sparked by this thread: <20260112151725.2308971-1-mukesh.ojha@oss.qualcomm.com> The current representation of TCSR is wrong. On platforms post and including SM8550, the TCSR had a sub-block in it, containing gate clocks used for distributing the XO output to various consumers. This is what we refer to as TCSR_CC upstream. SM8750 however, is notably different. That same set of tunables had been moved to the TLMM register space. This is made worse, as the sm8750-tcsrcc driver consumes the qcom,sm8750-tcsr compatible. This hardware change had been undone with the generation following 8750. This series attempts to unwind that. It's difficult to merge, both for bindings and functional reasons.. I think it goes without saying this breaks backwards compatibility, but it has to be done to represent TCSR at all. The patches are ordered in a least-destructive order.. I gave this a quick spin on (remote) hw, the UFS (one of the consumers) still works, but more testing would be greatly appreciated. Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> --- Konrad Dybcio (8): dt-bindings: Move qcom,sm8750-tcsr from clock/tcsr to mfd/tcsr dt-bindings: pinctrl: qcom,sm8750-tlmm: Allow clocks/clock-cells pinctrl: qcom: Allow exposing reference clocks living in TLMM reg space pinctrl: qcom: sm8750: Expose reference clocks arm64: dts: qcom: Remove inexistent TCSR_CC clk: qcom: Remove tcsrcc-sm8750 arm64: dts: qcom: sm8750: Describe TCSR arm64: defconfig: Remove CONFIG_SM_TCSRCC_8750 .../bindings/clock/qcom,sm8550-tcsr.yaml | 2 - .../devicetree/bindings/mfd/qcom,tcsr.yaml | 1 + .../bindings/pinctrl/qcom,sm8750-tlmm.yaml | 12 ++ arch/arm64/boot/dts/qcom/sm8750.dtsi | 27 ++-- arch/arm64/configs/defconfig | 1 - drivers/clk/qcom/Kconfig | 8 -- drivers/clk/qcom/Makefile | 1 - drivers/clk/qcom/tcsrcc-sm8750.c | 141 --------------------- drivers/pinctrl/qcom/pinctrl-msm.c | 92 ++++++++++++++ drivers/pinctrl/qcom/pinctrl-msm.h | 14 ++ drivers/pinctrl/qcom/pinctrl-sm8750.c | 31 +++++ 11 files changed, 163 insertions(+), 167 deletions(-) --- base-commit: 4c87cdd0328495759f6e9f9f4e1e53ef8032a76f change-id: 20260202-topic-8750_tcsr-e2dafc2f11d1 Best regards, -- Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
From: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> On SM8750 specifically, the TLMM block register space contains a number of gates that forward the system XO (reference) clock to various IP blocks. Allow '#clock-cells' (since it provides clocks) and 'clocks' (so that the parent clock may be consumed and linked with the clocks provided). Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> --- .../devicetree/bindings/pinctrl/qcom,sm8750-tlmm.yaml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Documentation/devicetree/bindings/pinctrl/qcom,sm8750-tlmm.yaml b/Documentation/devicetree/bindings/pinctrl/qcom,sm8750-tlmm.yaml index 7aecc97745a8..136366d89290 100644 --- a/Documentation/devicetree/bindings/pinctrl/qcom,sm8750-tlmm.yaml +++ b/Documentation/devicetree/bindings/pinctrl/qcom,sm8750-tlmm.yaml @@ -19,6 +19,10 @@ properties: compatible: const: qcom,sm8750-tlmm + clocks: + items: + - description: RPMh XO clock + reg: maxItems: 1 @@ -32,6 +36,9 @@ properties: gpio-line-names: maxItems: 215 + '#clock-cells': + const: 1 + patternProperties: "-state$": oneOf: @@ -100,6 +107,8 @@ $defs: required: - compatible - reg + - clocks + - '#clock-cells' unevaluatedProperties: false @@ -109,6 +118,7 @@ examples: tlmm: pinctrl@f100000 { compatible = "qcom,sm8750-tlmm"; reg = <0x0f100000 0x300000>; + clocks = <&rpmhcc_xo>; gpio-controller; #gpio-cells = <2>; gpio-ranges = <&tlmm 0 0 216>; @@ -116,6 +126,8 @@ examples: #interrupt-cells = <2>; interrupts = <GIC_SPI 208 IRQ_TYPE_LEVEL_HIGH>; + #clock-cells = <1>; + gpio-wo-state { pins = "gpio1"; function = "gpio"; -- 2.52.0
{ "author": "Konrad Dybcio <konradybcio@kernel.org>", "date": "Mon, 02 Feb 2026 15:57:34 +0100", "thread_id": "20260202181917.imo5lk3smwott2ue@hu-mojha-hyd.qualcomm.com.mbox.gz" }
lkml
[RFC PATCH 0/8] Fix TCSR representation on SM8750
As sparked by this thread: <20260112151725.2308971-1-mukesh.ojha@oss.qualcomm.com> The current representation of TCSR is wrong. On platforms post and including SM8550, the TCSR had a sub-block in it, containing gate clocks used for distributing the XO output to various consumers. This is what we refer to as TCSR_CC upstream. SM8750 however, is notably different. That same set of tunables had been moved to the TLMM register space. This is made worse, as the sm8750-tcsrcc driver consumes the qcom,sm8750-tcsr compatible. This hardware change had been undone with the generation following 8750. This series attempts to unwind that. It's difficult to merge, both for bindings and functional reasons.. I think it goes without saying this breaks backwards compatibility, but it has to be done to represent TCSR at all. The patches are ordered in a least-destructive order.. I gave this a quick spin on (remote) hw, the UFS (one of the consumers) still works, but more testing would be greatly appreciated. Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> --- Konrad Dybcio (8): dt-bindings: Move qcom,sm8750-tcsr from clock/tcsr to mfd/tcsr dt-bindings: pinctrl: qcom,sm8750-tlmm: Allow clocks/clock-cells pinctrl: qcom: Allow exposing reference clocks living in TLMM reg space pinctrl: qcom: sm8750: Expose reference clocks arm64: dts: qcom: Remove inexistent TCSR_CC clk: qcom: Remove tcsrcc-sm8750 arm64: dts: qcom: sm8750: Describe TCSR arm64: defconfig: Remove CONFIG_SM_TCSRCC_8750 .../bindings/clock/qcom,sm8550-tcsr.yaml | 2 - .../devicetree/bindings/mfd/qcom,tcsr.yaml | 1 + .../bindings/pinctrl/qcom,sm8750-tlmm.yaml | 12 ++ arch/arm64/boot/dts/qcom/sm8750.dtsi | 27 ++-- arch/arm64/configs/defconfig | 1 - drivers/clk/qcom/Kconfig | 8 -- drivers/clk/qcom/Makefile | 1 - drivers/clk/qcom/tcsrcc-sm8750.c | 141 --------------------- drivers/pinctrl/qcom/pinctrl-msm.c | 92 ++++++++++++++ drivers/pinctrl/qcom/pinctrl-msm.h | 14 ++ drivers/pinctrl/qcom/pinctrl-sm8750.c | 31 +++++ 11 files changed, 163 insertions(+), 167 deletions(-) --- base-commit: 4c87cdd0328495759f6e9f9f4e1e53ef8032a76f change-id: 20260202-topic-8750_tcsr-e2dafc2f11d1 Best regards, -- Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
From: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> Certain platforms (at least SM8750) had a number of registers (responsible for gating refclk output to various consumers) moved to TLMM. They're simple on/off toggles. Expose them from the msm-pinctrl driver to allow for a reasonable DT representation. Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> --- drivers/pinctrl/qcom/pinctrl-msm.c | 92 ++++++++++++++++++++++++++++++++++++++ drivers/pinctrl/qcom/pinctrl-msm.h | 14 ++++++ 2 files changed, 106 insertions(+) diff --git a/drivers/pinctrl/qcom/pinctrl-msm.c b/drivers/pinctrl/qcom/pinctrl-msm.c index e99871b90ab9..1a52431a8605 100644 --- a/drivers/pinctrl/qcom/pinctrl-msm.c +++ b/drivers/pinctrl/qcom/pinctrl-msm.c @@ -4,6 +4,7 @@ * Copyright (c) 2013, The Linux Foundation. All rights reserved. */ +#include <linux/clk-provider.h> #include <linux/delay.h> #include <linux/err.h> #include <linux/gpio/driver.h> @@ -16,6 +17,7 @@ #include <linux/pm.h> #include <linux/firmware/qcom/qcom_scm.h> #include <linux/reboot.h> +#include <linux/regmap.h> #include <linux/seq_file.h> #include <linux/slab.h> #include <linux/spinlock.h> @@ -80,6 +82,7 @@ struct msm_pinctrl { const struct msm_pinctrl_soc_data *soc; void __iomem *regs[MAX_NR_TILES]; u32 phys_base[MAX_NR_TILES]; + struct ref_clk ref_clks[]; }; #define MSM_ACCESSOR(name) \ @@ -1525,9 +1528,69 @@ SIMPLE_DEV_PM_OPS(msm_pinctrl_dev_pm_ops, msm_pinctrl_suspend, EXPORT_SYMBOL(msm_pinctrl_dev_pm_ops); +static int clkref_enable(struct clk_hw *hw) +{ + struct ref_clk *rclk = container_of(hw, struct ref_clk, hw); + u32 val; + + regmap_write(rclk->regmap, rclk->init.offset, BIT(0)); + udelay(10); + + regmap_read(rclk->regmap, rclk->init.offset, &val); + + return (val & BIT(0)) ? 0 : -EINVAL; +} + +static void clkref_disable(struct clk_hw *hw) +{ + struct ref_clk *rclk = container_of(hw, struct ref_clk, hw); + + regmap_write(rclk->regmap, rclk->init.offset, 0); + + udelay(10); +} + +static int clkref_is_enabled(struct clk_hw *hw) +{ + struct ref_clk *rclk = container_of(hw, struct ref_clk, hw); + u32 val; + + regmap_read(rclk->regmap, rclk->init.offset, &val); + + return !!val; +} + +static const struct clk_ops clkref_ops = { + .enable = clkref_enable, + .disable = clkref_disable, + .is_enabled = clkref_is_enabled, +}; + +static struct clk_hw *msm_pinctrl_clk_get(struct of_phandle_args *clkspec, void *data) +{ + struct msm_pinctrl *pctrl = data; + u32 idx = clkspec->args[0]; + + if (idx >= pctrl->soc->num_ref_clks) + return ERR_PTR(-EINVAL); + + return &pctrl->ref_clks[idx].hw; +} + +static const struct clk_parent_data clkref_parent_data = { + .index = 0, /* RPM(h) XO clock */ +}; + +static const struct regmap_config clkref_regmap_config = { + .reg_bits = 32, + .reg_stride = 4, + .val_bits = 32, +}; + int msm_pinctrl_probe(struct platform_device *pdev, const struct msm_pinctrl_soc_data *soc_data) { + struct device *dev = &pdev->dev; const struct pinfunction *func; struct msm_pinctrl *pctrl; struct resource *res; @@ -1595,6 +1658,35 @@ int msm_pinctrl_probe(struct platform_device *pdev, if (ret) return ret; + if (soc_data->num_ref_clks) { + struct regmap *regmap = devm_regmap_init_mmio(dev, pctrl->regs[0], + &clkref_regmap_config); + if (IS_ERR(regmap)) + return PTR_ERR(regmap); + + for (int i = 0; i < soc_data->num_ref_clks; i++) { + struct clk_hw *hw = &pctrl->ref_clks[i].hw; + struct clk_init_data init = { }; + + init.name = pctrl->soc->ref_clks[i]->name; + init.parent_data = &clkref_parent_data; + init.num_parents = 1; + init.ops = &clkref_ops; + hw->init = &init; + + ret = devm_clk_hw_register(dev, hw); + if (ret) + return dev_err_probe(dev, ret, "Couldn't register clock %s\n", + init.name); + + pctrl->ref_clks[i].regmap = regmap; + } + + ret = devm_of_clk_add_hw_provider(dev, msm_pinctrl_clk_get, pctrl); + if (ret) + return dev_err_probe(dev, ret, "Couldn't register clk provider\n"); + } + platform_set_drvdata(pdev, pctrl); dev_dbg(&pdev->dev, "Probed Qualcomm pinctrl driver\n"); diff --git a/drivers/pinctrl/qcom/pinctrl-msm.h b/drivers/pinctrl/qcom/pinctrl-msm.h index 4625fa5320a9..213cc789711d 100644 --- a/drivers/pinctrl/qcom/pinctrl-msm.h +++ b/drivers/pinctrl/qcom/pinctrl-msm.h @@ -5,6 +5,7 @@ #ifndef __PINCTRL_MSM_H__ #define __PINCTRL_MSM_H__ +#include <linux/clk-provider.h> #include <linux/pm.h> #include <linux/types.h> @@ -129,6 +130,17 @@ struct msm_gpio_wakeirq_map { unsigned int wakeirq; }; +struct ref_clk_init_data { + const char * const name; + u32 offset; +}; + +struct ref_clk { + struct clk_hw hw; + struct regmap *regmap; + struct ref_clk_init_data init; +}; + /** * struct msm_pinctrl_soc_data - Qualcomm pin controller driver configuration * @pins: An array describing all pins the pin controller affects. @@ -170,6 +182,8 @@ struct msm_pinctrl_soc_data { bool wakeirq_dual_edge_errata; unsigned int gpio_func; unsigned int egpio_func; + const struct ref_clk_init_data **ref_clks; + unsigned int num_ref_clks; }; extern const struct dev_pm_ops msm_pinctrl_dev_pm_ops; -- 2.52.0
{ "author": "Konrad Dybcio <konradybcio@kernel.org>", "date": "Mon, 02 Feb 2026 15:57:35 +0100", "thread_id": "20260202181917.imo5lk3smwott2ue@hu-mojha-hyd.qualcomm.com.mbox.gz" }
lkml
[RFC PATCH 0/8] Fix TCSR representation on SM8750
As sparked by this thread: <20260112151725.2308971-1-mukesh.ojha@oss.qualcomm.com> The current representation of TCSR is wrong. On platforms post and including SM8550, the TCSR had a sub-block in it, containing gate clocks used for distributing the XO output to various consumers. This is what we refer to as TCSR_CC upstream. SM8750 however, is notably different. That same set of tunables had been moved to the TLMM register space. This is made worse, as the sm8750-tcsrcc driver consumes the qcom,sm8750-tcsr compatible. This hardware change had been undone with the generation following 8750. This series attempts to unwind that. It's difficult to merge, both for bindings and functional reasons.. I think it goes without saying this breaks backwards compatibility, but it has to be done to represent TCSR at all. The patches are ordered in a least-destructive order.. I gave this a quick spin on (remote) hw, the UFS (one of the consumers) still works, but more testing would be greatly appreciated. Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> --- Konrad Dybcio (8): dt-bindings: Move qcom,sm8750-tcsr from clock/tcsr to mfd/tcsr dt-bindings: pinctrl: qcom,sm8750-tlmm: Allow clocks/clock-cells pinctrl: qcom: Allow exposing reference clocks living in TLMM reg space pinctrl: qcom: sm8750: Expose reference clocks arm64: dts: qcom: Remove inexistent TCSR_CC clk: qcom: Remove tcsrcc-sm8750 arm64: dts: qcom: sm8750: Describe TCSR arm64: defconfig: Remove CONFIG_SM_TCSRCC_8750 .../bindings/clock/qcom,sm8550-tcsr.yaml | 2 - .../devicetree/bindings/mfd/qcom,tcsr.yaml | 1 + .../bindings/pinctrl/qcom,sm8750-tlmm.yaml | 12 ++ arch/arm64/boot/dts/qcom/sm8750.dtsi | 27 ++-- arch/arm64/configs/defconfig | 1 - drivers/clk/qcom/Kconfig | 8 -- drivers/clk/qcom/Makefile | 1 - drivers/clk/qcom/tcsrcc-sm8750.c | 141 --------------------- drivers/pinctrl/qcom/pinctrl-msm.c | 92 ++++++++++++++ drivers/pinctrl/qcom/pinctrl-msm.h | 14 ++ drivers/pinctrl/qcom/pinctrl-sm8750.c | 31 +++++ 11 files changed, 163 insertions(+), 167 deletions(-) --- base-commit: 4c87cdd0328495759f6e9f9f4e1e53ef8032a76f change-id: 20260202-topic-8750_tcsr-e2dafc2f11d1 Best regards, -- Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
From: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> The gating toggles were moved to the TLMM register space on this platform. They lived inside TCSR a generation prior and are back there again a generation after. Expose them, so that they can be consumed by other blocks. Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> --- drivers/pinctrl/qcom/pinctrl-sm8750.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/drivers/pinctrl/qcom/pinctrl-sm8750.c b/drivers/pinctrl/qcom/pinctrl-sm8750.c index 6f92f176edd4..1d29cc89e72f 100644 --- a/drivers/pinctrl/qcom/pinctrl-sm8750.c +++ b/drivers/pinctrl/qcom/pinctrl-sm8750.c @@ -9,6 +9,8 @@ #include "pinctrl-msm.h" +#include <dt-bindings/clock/qcom,sm8750-tcsr.h> + #define REG_SIZE 0x1000 #define PINGROUP(id, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11) \ @@ -1682,6 +1684,33 @@ static const struct msm_gpio_wakeirq_map sm8750_pdc_map[] = { { 204, 158 }, { 205, 107 }, { 209, 159 }, }; +static const struct ref_clk_init_data pcie_0_refclk = { + .name = "pcie_0_clkref", + .offset = 0x104008, +}; + +static const struct ref_clk_init_data ufs_refclk = { + .name = "ufs_clkref", + .offset = 0x105008, +}; + +static const struct ref_clk_init_data usb2_refclk = { + .name = "usb2_clkref", + .offset = 0x106008, +}; + +static const struct ref_clk_init_data usb3_refclk = { + .name = "usb3_clkref", + .offset = 0x107008, +}; + +static const struct ref_clk_init_data *sm8750_ref_clks[] = { + [TCSR_PCIE_0_CLKREF_EN] = &pcie_0_refclk, + [TCSR_UFS_CLKREF_EN] = &ufs_refclk, + [TCSR_USB2_CLKREF_EN] = &usb2_refclk, + [TCSR_USB3_CLKREF_EN] = &usb3_refclk, +}; + static const struct msm_pinctrl_soc_data sm8750_tlmm = { .pins = sm8750_pins, .npins = ARRAY_SIZE(sm8750_pins), @@ -1693,6 +1722,8 @@ static const struct msm_pinctrl_soc_data sm8750_tlmm = { .wakeirq_map = sm8750_pdc_map, .nwakeirq_map = ARRAY_SIZE(sm8750_pdc_map), .egpio_func = 11, + .ref_clks = sm8750_ref_clks, + .num_ref_clks = ARRAY_SIZE(sm8750_ref_clks), }; static int sm8750_tlmm_probe(struct platform_device *pdev) -- 2.52.0
{ "author": "Konrad Dybcio <konradybcio@kernel.org>", "date": "Mon, 02 Feb 2026 15:57:36 +0100", "thread_id": "20260202181917.imo5lk3smwott2ue@hu-mojha-hyd.qualcomm.com.mbox.gz" }
lkml
[RFC PATCH 0/8] Fix TCSR representation on SM8750
As sparked by this thread: <20260112151725.2308971-1-mukesh.ojha@oss.qualcomm.com> The current representation of TCSR is wrong. On platforms post and including SM8550, the TCSR had a sub-block in it, containing gate clocks used for distributing the XO output to various consumers. This is what we refer to as TCSR_CC upstream. SM8750 however, is notably different. That same set of tunables had been moved to the TLMM register space. This is made worse, as the sm8750-tcsrcc driver consumes the qcom,sm8750-tcsr compatible. This hardware change had been undone with the generation following 8750. This series attempts to unwind that. It's difficult to merge, both for bindings and functional reasons.. I think it goes without saying this breaks backwards compatibility, but it has to be done to represent TCSR at all. The patches are ordered in a least-destructive order.. I gave this a quick spin on (remote) hw, the UFS (one of the consumers) still works, but more testing would be greatly appreciated. Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> --- Konrad Dybcio (8): dt-bindings: Move qcom,sm8750-tcsr from clock/tcsr to mfd/tcsr dt-bindings: pinctrl: qcom,sm8750-tlmm: Allow clocks/clock-cells pinctrl: qcom: Allow exposing reference clocks living in TLMM reg space pinctrl: qcom: sm8750: Expose reference clocks arm64: dts: qcom: Remove inexistent TCSR_CC clk: qcom: Remove tcsrcc-sm8750 arm64: dts: qcom: sm8750: Describe TCSR arm64: defconfig: Remove CONFIG_SM_TCSRCC_8750 .../bindings/clock/qcom,sm8550-tcsr.yaml | 2 - .../devicetree/bindings/mfd/qcom,tcsr.yaml | 1 + .../bindings/pinctrl/qcom,sm8750-tlmm.yaml | 12 ++ arch/arm64/boot/dts/qcom/sm8750.dtsi | 27 ++-- arch/arm64/configs/defconfig | 1 - drivers/clk/qcom/Kconfig | 8 -- drivers/clk/qcom/Makefile | 1 - drivers/clk/qcom/tcsrcc-sm8750.c | 141 --------------------- drivers/pinctrl/qcom/pinctrl-msm.c | 92 ++++++++++++++ drivers/pinctrl/qcom/pinctrl-msm.h | 14 ++ drivers/pinctrl/qcom/pinctrl-sm8750.c | 31 +++++ 11 files changed, 163 insertions(+), 167 deletions(-) --- base-commit: 4c87cdd0328495759f6e9f9f4e1e53ef8032a76f change-id: 20260202-topic-8750_tcsr-e2dafc2f11d1 Best regards, -- Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
From: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> On SM8750 specifically, the block which provides various reference clocks does *NOT* live inside TCSR, but rather TLMM. With the former now being able to properly expose them, switch over to the proper source. Now, the TCSR still exists as a block for various tunables and switches, however the prior misuse resulted in its 8750-specifc compatible being already in use. With it freed up, it is now free again to be described properly. Fixes: 068c3d3c83be ("arm64: dts: qcom: Add base SM8750 dtsi") Cc: <stable+noautosel@kernel.org> # complex dependencies, no immediate gain Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> --- arch/arm64/boot/dts/qcom/sm8750.dtsi | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/arch/arm64/boot/dts/qcom/sm8750.dtsi b/arch/arm64/boot/dts/qcom/sm8750.dtsi index f56b1f889b85..0c034ba0517f 100644 --- a/arch/arm64/boot/dts/qcom/sm8750.dtsi +++ b/arch/arm64/boot/dts/qcom/sm8750.dtsi @@ -2727,7 +2727,7 @@ usb_hsphy: phy@88e3000 { compatible = "qcom,sm8750-m31-eusb2-phy"; reg = <0x0 0x88e3000 0x0 0x29c>; - clocks = <&tcsrcc TCSR_USB2_CLKREF_EN>; + clocks = <&tlmm TCSR_USB2_CLKREF_EN>; clock-names = "ref"; resets = <&gcc GCC_QUSB2PHY_PRIM_BCR>; @@ -2742,7 +2742,7 @@ usb_dp_qmpphy: phy@88e8000 { reg = <0x0 0x088e8000 0x0 0x4000>; clocks = <&gcc GCC_USB3_PRIM_PHY_AUX_CLK>, - <&tcsrcc TCSR_USB3_CLKREF_EN>, + <&tlmm TCSR_USB3_CLKREF_EN>, <&gcc GCC_USB3_PRIM_PHY_COM_AUX_CLK>, <&gcc GCC_USB3_PRIM_PHY_PIPE_CLK>; clock-names = "aux", @@ -3063,6 +3063,8 @@ tlmm: pinctrl@f100000 { compatible = "qcom,sm8750-tlmm"; reg = <0x0 0x0f100000 0x0 0x102000>; + clocks = <&rpmhcc RPMH_CXO_CLK>; + interrupts = <GIC_SPI 208 IRQ_TYPE_LEVEL_HIGH>; gpio-controller; @@ -3074,6 +3076,8 @@ tlmm: pinctrl@f100000 { gpio-ranges = <&tlmm 0 0 216>; wakeup-parent = <&pdc>; + #clock-cells = <1>; + hub_i2c0_data_clk: hub-i2c0-data-clk-state { /* SDA, SCL */ pins = "gpio64", "gpio65"; @@ -3564,16 +3568,6 @@ data-pins { }; }; - tcsrcc: clock-controller@f204008 { - compatible = "qcom,sm8750-tcsr", "syscon"; - reg = <0x0 0x0f204008 0x0 0x3004>; - - clocks = <&rpmhcc RPMH_CXO_CLK>; - - #clock-cells = <1>; - #reset-cells = <1>; - }; - stm@10002000 { compatible = "arm,coresight-stm", "arm,primecell"; reg = <0x0 0x10002000 0x0 0x1000>, @@ -4818,7 +4812,7 @@ pcie0_phy: phy@1c06000 { clocks = <&gcc GCC_PCIE_0_AUX_CLK>, <&gcc GCC_PCIE_0_CFG_AHB_CLK>, - <&tcsrcc TCSR_PCIE_0_CLKREF_EN>, + <&tlmm TCSR_PCIE_0_CLKREF_EN>, <&gcc GCC_PCIE_0_PHY_RCHNG_CLK>, <&gcc GCC_PCIE_0_PIPE_CLK>; clock-names = "aux", @@ -4849,7 +4843,7 @@ ufs_mem_phy: phy@1d80000 { clocks = <&rpmhcc RPMH_CXO_CLK>, <&gcc GCC_UFS_PHY_PHY_AUX_CLK>, - <&tcsrcc TCSR_UFS_CLKREF_EN>; + <&tlmm TCSR_UFS_CLKREF_EN>; clock-names = "ref", "ref_aux", -- 2.52.0
{ "author": "Konrad Dybcio <konradybcio@kernel.org>", "date": "Mon, 02 Feb 2026 15:57:37 +0100", "thread_id": "20260202181917.imo5lk3smwott2ue@hu-mojha-hyd.qualcomm.com.mbox.gz" }
lkml
[RFC PATCH 0/8] Fix TCSR representation on SM8750
As sparked by this thread: <20260112151725.2308971-1-mukesh.ojha@oss.qualcomm.com> The current representation of TCSR is wrong. On platforms post and including SM8550, the TCSR had a sub-block in it, containing gate clocks used for distributing the XO output to various consumers. This is what we refer to as TCSR_CC upstream. SM8750 however, is notably different. That same set of tunables had been moved to the TLMM register space. This is made worse, as the sm8750-tcsrcc driver consumes the qcom,sm8750-tcsr compatible. This hardware change had been undone with the generation following 8750. This series attempts to unwind that. It's difficult to merge, both for bindings and functional reasons.. I think it goes without saying this breaks backwards compatibility, but it has to be done to represent TCSR at all. The patches are ordered in a least-destructive order.. I gave this a quick spin on (remote) hw, the UFS (one of the consumers) still works, but more testing would be greatly appreciated. Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> --- Konrad Dybcio (8): dt-bindings: Move qcom,sm8750-tcsr from clock/tcsr to mfd/tcsr dt-bindings: pinctrl: qcom,sm8750-tlmm: Allow clocks/clock-cells pinctrl: qcom: Allow exposing reference clocks living in TLMM reg space pinctrl: qcom: sm8750: Expose reference clocks arm64: dts: qcom: Remove inexistent TCSR_CC clk: qcom: Remove tcsrcc-sm8750 arm64: dts: qcom: sm8750: Describe TCSR arm64: defconfig: Remove CONFIG_SM_TCSRCC_8750 .../bindings/clock/qcom,sm8550-tcsr.yaml | 2 - .../devicetree/bindings/mfd/qcom,tcsr.yaml | 1 + .../bindings/pinctrl/qcom,sm8750-tlmm.yaml | 12 ++ arch/arm64/boot/dts/qcom/sm8750.dtsi | 27 ++-- arch/arm64/configs/defconfig | 1 - drivers/clk/qcom/Kconfig | 8 -- drivers/clk/qcom/Makefile | 1 - drivers/clk/qcom/tcsrcc-sm8750.c | 141 --------------------- drivers/pinctrl/qcom/pinctrl-msm.c | 92 ++++++++++++++ drivers/pinctrl/qcom/pinctrl-msm.h | 14 ++ drivers/pinctrl/qcom/pinctrl-sm8750.c | 31 +++++ 11 files changed, 163 insertions(+), 167 deletions(-) --- base-commit: 4c87cdd0328495759f6e9f9f4e1e53ef8032a76f change-id: 20260202-topic-8750_tcsr-e2dafc2f11d1 Best regards, -- Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
From: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> This is now handled from within the pinctrl subsystem, since there is no "CC" block inside SM8750's TCSR, as the corresponding hardware is present within TLMM. Remove the leftovers. Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> --- drivers/clk/qcom/Kconfig | 8 --- drivers/clk/qcom/Makefile | 1 - drivers/clk/qcom/tcsrcc-sm8750.c | 141 --------------------------------------- 3 files changed, 150 deletions(-) diff --git a/drivers/clk/qcom/Kconfig b/drivers/clk/qcom/Kconfig index a8a86ea6bb74..f3ed33173ef6 100644 --- a/drivers/clk/qcom/Kconfig +++ b/drivers/clk/qcom/Kconfig @@ -1506,14 +1506,6 @@ config SM_TCSRCC_8650 Support for the TCSR clock controller on SM8650 devices. Say Y if you want to use peripheral devices such as SD/UFS. -config SM_TCSRCC_8750 - tristate "SM8750 TCSR Clock Controller" - depends on ARM64 || COMPILE_TEST - select QCOM_GDSC - help - Support for the TCSR clock controller on SM8750 devices. - Say Y if you want to use peripheral devices such as UFS/USB/PCIe. - config SA_VIDEOCC_8775P tristate "SA8775P Video Clock Controller" depends on ARM64 || COMPILE_TEST diff --git a/drivers/clk/qcom/Makefile b/drivers/clk/qcom/Makefile index 6b0ad8832b55..f8c81844ee48 100644 --- a/drivers/clk/qcom/Makefile +++ b/drivers/clk/qcom/Makefile @@ -184,7 +184,6 @@ obj-$(CONFIG_SM_GPUCC_MILOS) += gpucc-milos.o obj-$(CONFIG_SM_LPASSCC_6115) += lpasscc-sm6115.o obj-$(CONFIG_SM_TCSRCC_8550) += tcsrcc-sm8550.o obj-$(CONFIG_SM_TCSRCC_8650) += tcsrcc-sm8650.o -obj-$(CONFIG_SM_TCSRCC_8750) += tcsrcc-sm8750.o obj-$(CONFIG_SM_VIDEOCC_6350) += videocc-sm6350.o obj-$(CONFIG_SM_VIDEOCC_7150) += videocc-sm7150.o obj-$(CONFIG_SM_VIDEOCC_8150) += videocc-sm8150.o diff --git a/drivers/clk/qcom/tcsrcc-sm8750.c b/drivers/clk/qcom/tcsrcc-sm8750.c deleted file mode 100644 index 242e320986ef..000000000000 --- a/drivers/clk/qcom/tcsrcc-sm8750.c +++ /dev/null @@ -1,141 +0,0 @@ -// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) -/* - * Copyright (c) 2024, Qualcomm Innovation Center, Inc. All rights reserved. - */ - -#include <linux/clk-provider.h> -#include <linux/module.h> -#include <linux/of.h> -#include <linux/platform_device.h> -#include <linux/regmap.h> - -#include <dt-bindings/clock/qcom,sm8750-tcsr.h> - -#include "clk-branch.h" -#include "clk-regmap.h" -#include "clk-regmap-divider.h" -#include "clk-regmap-mux.h" -#include "common.h" - -enum { - DT_BI_TCXO_PAD, -}; - -static struct clk_branch tcsr_pcie_0_clkref_en = { - .halt_reg = 0x0, - .halt_check = BRANCH_HALT_DELAY, - .clkr = { - .enable_reg = 0x0, - .enable_mask = BIT(0), - .hw.init = &(const struct clk_init_data) { - .name = "tcsr_pcie_0_clkref_en", - .ops = &clk_branch2_ops, - }, - }, -}; - -static struct clk_branch tcsr_ufs_clkref_en = { - .halt_reg = 0x1000, - .halt_check = BRANCH_HALT_DELAY, - .clkr = { - .enable_reg = 0x1000, - .enable_mask = BIT(0), - .hw.init = &(const struct clk_init_data) { - .name = "tcsr_ufs_clkref_en", - .parent_data = &(const struct clk_parent_data){ - .index = DT_BI_TCXO_PAD, - }, - .num_parents = 1, - .ops = &clk_branch2_ops, - }, - }, -}; - -static struct clk_branch tcsr_usb2_clkref_en = { - .halt_reg = 0x2000, - .halt_check = BRANCH_HALT_DELAY, - .clkr = { - .enable_reg = 0x2000, - .enable_mask = BIT(0), - .hw.init = &(const struct clk_init_data) { - .name = "tcsr_usb2_clkref_en", - .parent_data = &(const struct clk_parent_data){ - .index = DT_BI_TCXO_PAD, - }, - .num_parents = 1, - .ops = &clk_branch2_ops, - }, - }, -}; - -static struct clk_branch tcsr_usb3_clkref_en = { - .halt_reg = 0x3000, - .halt_check = BRANCH_HALT_DELAY, - .clkr = { - .enable_reg = 0x3000, - .enable_mask = BIT(0), - .hw.init = &(const struct clk_init_data) { - .name = "tcsr_usb3_clkref_en", - .parent_data = &(const struct clk_parent_data){ - .index = DT_BI_TCXO_PAD, - }, - .num_parents = 1, - .ops = &clk_branch2_ops, - }, - }, -}; - -static struct clk_regmap *tcsr_cc_sm8750_clocks[] = { - [TCSR_PCIE_0_CLKREF_EN] = &tcsr_pcie_0_clkref_en.clkr, - [TCSR_UFS_CLKREF_EN] = &tcsr_ufs_clkref_en.clkr, - [TCSR_USB2_CLKREF_EN] = &tcsr_usb2_clkref_en.clkr, - [TCSR_USB3_CLKREF_EN] = &tcsr_usb3_clkref_en.clkr, -}; - -static const struct regmap_config tcsr_cc_sm8750_regmap_config = { - .reg_bits = 32, - .reg_stride = 4, - .val_bits = 32, - .max_register = 0x3000, - .fast_io = true, -}; - -static const struct qcom_cc_desc tcsr_cc_sm8750_desc = { - .config = &tcsr_cc_sm8750_regmap_config, - .clks = tcsr_cc_sm8750_clocks, - .num_clks = ARRAY_SIZE(tcsr_cc_sm8750_clocks), -}; - -static const struct of_device_id tcsr_cc_sm8750_match_table[] = { - { .compatible = "qcom,sm8750-tcsr" }, - { } -}; -MODULE_DEVICE_TABLE(of, tcsr_cc_sm8750_match_table); - -static int tcsr_cc_sm8750_probe(struct platform_device *pdev) -{ - return qcom_cc_probe(pdev, &tcsr_cc_sm8750_desc); -} - -static struct platform_driver tcsr_cc_sm8750_driver = { - .probe = tcsr_cc_sm8750_probe, - .driver = { - .name = "tcsr_cc-sm8750", - .of_match_table = tcsr_cc_sm8750_match_table, - }, -}; - -static int __init tcsr_cc_sm8750_init(void) -{ - return platform_driver_register(&tcsr_cc_sm8750_driver); -} -subsys_initcall(tcsr_cc_sm8750_init); - -static void __exit tcsr_cc_sm8750_exit(void) -{ - platform_driver_unregister(&tcsr_cc_sm8750_driver); -} -module_exit(tcsr_cc_sm8750_exit); - -MODULE_DESCRIPTION("QTI TCSR_CC SM8750 Driver"); -MODULE_LICENSE("GPL"); -- 2.52.0
{ "author": "Konrad Dybcio <konradybcio@kernel.org>", "date": "Mon, 02 Feb 2026 15:57:38 +0100", "thread_id": "20260202181917.imo5lk3smwott2ue@hu-mojha-hyd.qualcomm.com.mbox.gz" }
lkml
[RFC PATCH 0/8] Fix TCSR representation on SM8750
As sparked by this thread: <20260112151725.2308971-1-mukesh.ojha@oss.qualcomm.com> The current representation of TCSR is wrong. On platforms post and including SM8550, the TCSR had a sub-block in it, containing gate clocks used for distributing the XO output to various consumers. This is what we refer to as TCSR_CC upstream. SM8750 however, is notably different. That same set of tunables had been moved to the TLMM register space. This is made worse, as the sm8750-tcsrcc driver consumes the qcom,sm8750-tcsr compatible. This hardware change had been undone with the generation following 8750. This series attempts to unwind that. It's difficult to merge, both for bindings and functional reasons.. I think it goes without saying this breaks backwards compatibility, but it has to be done to represent TCSR at all. The patches are ordered in a least-destructive order.. I gave this a quick spin on (remote) hw, the UFS (one of the consumers) still works, but more testing would be greatly appreciated. Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> --- Konrad Dybcio (8): dt-bindings: Move qcom,sm8750-tcsr from clock/tcsr to mfd/tcsr dt-bindings: pinctrl: qcom,sm8750-tlmm: Allow clocks/clock-cells pinctrl: qcom: Allow exposing reference clocks living in TLMM reg space pinctrl: qcom: sm8750: Expose reference clocks arm64: dts: qcom: Remove inexistent TCSR_CC clk: qcom: Remove tcsrcc-sm8750 arm64: dts: qcom: sm8750: Describe TCSR arm64: defconfig: Remove CONFIG_SM_TCSRCC_8750 .../bindings/clock/qcom,sm8550-tcsr.yaml | 2 - .../devicetree/bindings/mfd/qcom,tcsr.yaml | 1 + .../bindings/pinctrl/qcom,sm8750-tlmm.yaml | 12 ++ arch/arm64/boot/dts/qcom/sm8750.dtsi | 27 ++-- arch/arm64/configs/defconfig | 1 - drivers/clk/qcom/Kconfig | 8 -- drivers/clk/qcom/Makefile | 1 - drivers/clk/qcom/tcsrcc-sm8750.c | 141 --------------------- drivers/pinctrl/qcom/pinctrl-msm.c | 92 ++++++++++++++ drivers/pinctrl/qcom/pinctrl-msm.h | 14 ++ drivers/pinctrl/qcom/pinctrl-sm8750.c | 31 +++++ 11 files changed, 163 insertions(+), 167 deletions(-) --- base-commit: 4c87cdd0328495759f6e9f9f4e1e53ef8032a76f change-id: 20260202-topic-8750_tcsr-e2dafc2f11d1 Best regards, -- Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
From: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> SM8750 features a TCSR block (like any other Qualcomm platform), however unlike its sibling platforms, it most notably does NOT contain a clock controller, where XO-fed gates would reside. Describe it. Cc: <stable+noautosel@kernel.org> # complex dependencies, no immediate gain Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> --- arch/arm64/boot/dts/qcom/sm8750.dtsi | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/arm64/boot/dts/qcom/sm8750.dtsi b/arch/arm64/boot/dts/qcom/sm8750.dtsi index 0c034ba0517f..7ccbc3ad212b 100644 --- a/arch/arm64/boot/dts/qcom/sm8750.dtsi +++ b/arch/arm64/boot/dts/qcom/sm8750.dtsi @@ -2124,6 +2124,11 @@ tcsr_mutex: hwlock@1f40000 { #hwlock-cells = <1>; }; + tcsr: clock-controller@1fc0000 { + compatible = "qcom,sm8750-tcsr", "syscon"; + reg = <0x0 0x01fc0000 0x0 0x30000>; + }; + remoteproc_mpss: remoteproc@4080000 { compatible = "qcom,sm8750-mpss-pas"; reg = <0x0 0x04080000 0x0 0x10000>; -- 2.52.0
{ "author": "Konrad Dybcio <konradybcio@kernel.org>", "date": "Mon, 02 Feb 2026 15:57:39 +0100", "thread_id": "20260202181917.imo5lk3smwott2ue@hu-mojha-hyd.qualcomm.com.mbox.gz" }
lkml
[RFC PATCH 0/8] Fix TCSR representation on SM8750
As sparked by this thread: <20260112151725.2308971-1-mukesh.ojha@oss.qualcomm.com> The current representation of TCSR is wrong. On platforms post and including SM8550, the TCSR had a sub-block in it, containing gate clocks used for distributing the XO output to various consumers. This is what we refer to as TCSR_CC upstream. SM8750 however, is notably different. That same set of tunables had been moved to the TLMM register space. This is made worse, as the sm8750-tcsrcc driver consumes the qcom,sm8750-tcsr compatible. This hardware change had been undone with the generation following 8750. This series attempts to unwind that. It's difficult to merge, both for bindings and functional reasons.. I think it goes without saying this breaks backwards compatibility, but it has to be done to represent TCSR at all. The patches are ordered in a least-destructive order.. I gave this a quick spin on (remote) hw, the UFS (one of the consumers) still works, but more testing would be greatly appreciated. Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> --- Konrad Dybcio (8): dt-bindings: Move qcom,sm8750-tcsr from clock/tcsr to mfd/tcsr dt-bindings: pinctrl: qcom,sm8750-tlmm: Allow clocks/clock-cells pinctrl: qcom: Allow exposing reference clocks living in TLMM reg space pinctrl: qcom: sm8750: Expose reference clocks arm64: dts: qcom: Remove inexistent TCSR_CC clk: qcom: Remove tcsrcc-sm8750 arm64: dts: qcom: sm8750: Describe TCSR arm64: defconfig: Remove CONFIG_SM_TCSRCC_8750 .../bindings/clock/qcom,sm8550-tcsr.yaml | 2 - .../devicetree/bindings/mfd/qcom,tcsr.yaml | 1 + .../bindings/pinctrl/qcom,sm8750-tlmm.yaml | 12 ++ arch/arm64/boot/dts/qcom/sm8750.dtsi | 27 ++-- arch/arm64/configs/defconfig | 1 - drivers/clk/qcom/Kconfig | 8 -- drivers/clk/qcom/Makefile | 1 - drivers/clk/qcom/tcsrcc-sm8750.c | 141 --------------------- drivers/pinctrl/qcom/pinctrl-msm.c | 92 ++++++++++++++ drivers/pinctrl/qcom/pinctrl-msm.h | 14 ++ drivers/pinctrl/qcom/pinctrl-sm8750.c | 31 +++++ 11 files changed, 163 insertions(+), 167 deletions(-) --- base-commit: 4c87cdd0328495759f6e9f9f4e1e53ef8032a76f change-id: 20260202-topic-8750_tcsr-e2dafc2f11d1 Best regards, -- Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
From: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> The driver and the config option have been removed. Clean it up. Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> --- arch/arm64/configs/defconfig | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/arm64/configs/defconfig b/arch/arm64/configs/defconfig index b67d5b1fc45b..dd37285e223d 100644 --- a/arch/arm64/configs/defconfig +++ b/arch/arm64/configs/defconfig @@ -1552,7 +1552,6 @@ CONFIG_SM_GPUCC_8550=m CONFIG_SM_GPUCC_8650=m CONFIG_SM_TCSRCC_8550=y CONFIG_SM_TCSRCC_8650=y -CONFIG_SM_TCSRCC_8750=m CONFIG_SA_VIDEOCC_8775P=m CONFIG_SM_VIDEOCC_6350=m CONFIG_SM_VIDEOCC_MILOS=m -- 2.52.0
{ "author": "Konrad Dybcio <konradybcio@kernel.org>", "date": "Mon, 02 Feb 2026 15:57:40 +0100", "thread_id": "20260202181917.imo5lk3smwott2ue@hu-mojha-hyd.qualcomm.com.mbox.gz" }
lkml
[RFC PATCH 0/8] Fix TCSR representation on SM8750
As sparked by this thread: <20260112151725.2308971-1-mukesh.ojha@oss.qualcomm.com> The current representation of TCSR is wrong. On platforms post and including SM8550, the TCSR had a sub-block in it, containing gate clocks used for distributing the XO output to various consumers. This is what we refer to as TCSR_CC upstream. SM8750 however, is notably different. That same set of tunables had been moved to the TLMM register space. This is made worse, as the sm8750-tcsrcc driver consumes the qcom,sm8750-tcsr compatible. This hardware change had been undone with the generation following 8750. This series attempts to unwind that. It's difficult to merge, both for bindings and functional reasons.. I think it goes without saying this breaks backwards compatibility, but it has to be done to represent TCSR at all. The patches are ordered in a least-destructive order.. I gave this a quick spin on (remote) hw, the UFS (one of the consumers) still works, but more testing would be greatly appreciated. Signed-off-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> --- Konrad Dybcio (8): dt-bindings: Move qcom,sm8750-tcsr from clock/tcsr to mfd/tcsr dt-bindings: pinctrl: qcom,sm8750-tlmm: Allow clocks/clock-cells pinctrl: qcom: Allow exposing reference clocks living in TLMM reg space pinctrl: qcom: sm8750: Expose reference clocks arm64: dts: qcom: Remove inexistent TCSR_CC clk: qcom: Remove tcsrcc-sm8750 arm64: dts: qcom: sm8750: Describe TCSR arm64: defconfig: Remove CONFIG_SM_TCSRCC_8750 .../bindings/clock/qcom,sm8550-tcsr.yaml | 2 - .../devicetree/bindings/mfd/qcom,tcsr.yaml | 1 + .../bindings/pinctrl/qcom,sm8750-tlmm.yaml | 12 ++ arch/arm64/boot/dts/qcom/sm8750.dtsi | 27 ++-- arch/arm64/configs/defconfig | 1 - drivers/clk/qcom/Kconfig | 8 -- drivers/clk/qcom/Makefile | 1 - drivers/clk/qcom/tcsrcc-sm8750.c | 141 --------------------- drivers/pinctrl/qcom/pinctrl-msm.c | 92 ++++++++++++++ drivers/pinctrl/qcom/pinctrl-msm.h | 14 ++ drivers/pinctrl/qcom/pinctrl-sm8750.c | 31 +++++ 11 files changed, 163 insertions(+), 167 deletions(-) --- base-commit: 4c87cdd0328495759f6e9f9f4e1e53ef8032a76f change-id: 20260202-topic-8750_tcsr-e2dafc2f11d1 Best regards, -- Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
On Mon, Feb 02, 2026 at 03:57:32PM +0100, Konrad Dybcio wrote: Thanks Konrad for taking this forward, while I was also working on your suggestion to make tlmm a clock provider. -- -Mukesh Ojha
{ "author": "Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>", "date": "Mon, 2 Feb 2026 23:49:17 +0530", "thread_id": "20260202181917.imo5lk3smwott2ue@hu-mojha-hyd.qualcomm.com.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
From: David Laight <david.laight.linux@gmail.com> Change '(x - 1) + x' to '2 * (x - 1) + 1' to avoid expanding the non-trivial __type_half_max() twice. Signed-off-by: David Laight <david.laight.linux@gmail.com> --- include/linux/overflow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/overflow.h b/include/linux/overflow.h index 736f633b2d5f..4f014d55ab25 100644 --- a/include/linux/overflow.h +++ b/include/linux/overflow.h @@ -31,7 +31,7 @@ * credit to Christian Biere. */ #define __type_half_max(type) ((type)1 << (8*sizeof(type) - 1 - is_signed_type(type))) -#define __type_max(T) ((T)((__type_half_max(T) - 1) + __type_half_max(T))) +#define __type_max(T) ((T)(2 * (__type_half_max(T) - 1) + 1)) #define type_max(t) __type_max(typeof(t)) #define __type_min(T) ((T)((T)-type_max(T)-(T)1)) #define type_min(t) __type_min(typeof(t)) -- 2.39.5
{ "author": "david.laight.linux@gmail.com", "date": "Wed, 21 Jan 2026 14:57:18 +0000", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
From: David Laight <david.laight.linux@gmail.com> Since the type is always unsigned (T)-1 is always the correct value so there is no need to use type_max(). Signed-off-by: David Laight <david.laight.linux@gmail.com> --- include/linux/bits.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/linux/bits.h b/include/linux/bits.h index a40cc861b3a7..697318f2a47d 100644 --- a/include/linux/bits.h +++ b/include/linux/bits.h @@ -45,8 +45,7 @@ */ #define GENMASK_TYPE(t, h, l) \ ((t)(GENMASK_INPUT_CHECK(h, l) + \ - (type_max(t) << (l) & \ - type_max(t) >> (BITS_PER_TYPE(t) - 1 - (h))))) + ((t)-1 << (l) & (t)-1 >> (BITS_PER_TYPE(t) - 1 - (h))))) #define GENMASK(h, l) GENMASK_TYPE(unsigned long, h, l) #define GENMASK_ULL(h, l) GENMASK_TYPE(unsigned long long, h, l) -- 2.39.5
{ "author": "david.laight.linux@gmail.com", "date": "Wed, 21 Jan 2026 14:57:25 +0000", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
From: David Laight <david.laight.linux@gmail.com> Compile-time tests being added to BIT() make it an 'integer constant expression' rather than a pre-processor expression for W=1 builds. Change the BIT(PLANE_INDEX_BITS) != VIDEO_MAX_PLANES test to use static_assert() so the code compiles. Signed-off-by: David Laight <david.laight.linux@gmail.com> --- drivers/media/common/videobuf2/videobuf2-core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 2df566f409b6..90dedab2aeb2 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -37,9 +37,9 @@ #define MAX_BUFFER_INDEX BIT_MASK(30 - PLANE_INDEX_SHIFT) #define BUFFER_INDEX_MASK (MAX_BUFFER_INDEX - 1) -#if BIT(PLANE_INDEX_BITS) != VIDEO_MAX_PLANES -#error PLANE_INDEX_BITS order must be equal to VIDEO_MAX_PLANES -#endif + +static_assert(BIT(PLANE_INDEX_BITS) == VIDEO_MAX_PLANES, + "PLANE_INDEX_BITS order must be equal to VIDEO_MAX_PLANES"); static int debug; module_param(debug, int, 0644); -- 2.39.5
{ "author": "david.laight.linux@gmail.com", "date": "Wed, 21 Jan 2026 14:57:20 +0000", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
From: David Laight <david.laight.linux@gmail.com> The check for invalid 'compile time constant' parameters can easily be changed to return 'failed' rather than generating a compile time error. Add some tests for negative, swapped and overlarge values. Signed-off-by: David Laight <david.laight.linux@gmail.com> --- lib/tests/test_bits.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/tests/test_bits.c b/lib/tests/test_bits.c index 4d3a895f490c..9642c55f5487 100644 --- a/lib/tests/test_bits.c +++ b/lib/tests/test_bits.c @@ -144,6 +144,22 @@ static void genmask_input_check_test(struct kunit *test) BUILD_BUG_ON(GENMASK_INPUT_CHECK(100, 80, 128) != 0); BUILD_BUG_ON(GENMASK_INPUT_CHECK(110, 65, 128) != 0); BUILD_BUG_ON(GENMASK_INPUT_CHECK(127, 0, 128) != 0); + + /* + * Invalid input + * Change GENMASK_INPUT_CHECK() return 'fail' rather than + * generating a compile-time error. + */ +#define GENMASK_INPUT_CHECK_FAIL() 1 + z = 0; + BUILD_BUG_ON(GENMASK_INPUT_CHECK(z + 31, -1, 32) == 0); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(z + 0, 1, 32) == 0); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(z + 8, 0, 8) == 0); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(z + 16, 0, 16) == 0); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(z + 32, 0, 32) == 0); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(z + 64, 0, 64) == 0); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(z + 128, 0, 128) == 0); +#undef GENMASK_INPUT_CHECK_FAIL } -- 2.39.5
{ "author": "david.laight.linux@gmail.com", "date": "Wed, 21 Jan 2026 14:57:31 +0000", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
From: David Laight <david.laight.linux@gmail.com> Some compile time checks significantly bloat the pre-processor output (particularly when the get nested). Since the checks aren't really needed on every compilation enable with W=c (adds -DKBUILD_EXTRA_WARNc) so the checks can be enabled per-build. Make W=1 imply W=c so the build-bot includes the checks. As well as reducing the bloat from existing checks (like those in GENMASK() and FIELD_PREP()) it lets additional checks be added while there are still 'false positives' without breaking normal builds. Signed-off-by: David Laight <david.laight.linux@gmail.com> --- scripts/Makefile.warn | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/Makefile.warn b/scripts/Makefile.warn index 68e6fafcb80c..e8a799850973 100644 --- a/scripts/Makefile.warn +++ b/scripts/Makefile.warn @@ -2,8 +2,9 @@ # ========================================================================== # make W=... settings # -# There are four warning groups enabled by W=1, W=2, W=3, and W=e -# They are independent, and can be combined like W=12 or W=123e. +# There are five warning groups enabled by W=c, W=1, W=2, W=3, and W=e +# They are independent, and can be combined like W=12 or W=123e, +# except that W=1 implies W=c. # ========================================================================== # Default set of warnings, always enabled @@ -109,6 +110,13 @@ KBUILD_CFLAGS += $(call cc-option,-Wenum-conversion) KBUILD_CFLAGS += -Wunused +# +# W=c - Expensive compile-time checks, implied by W=1 +# +ifneq ($(findstring c, $(KBUILD_EXTRA_WARN))$(findstring 1, $(KBUILD_EXTRA_WARN)),) +KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARNc +endif + # # W=1 - warnings which may be relevant and do not occur too often # -- 2.39.5
{ "author": "david.laight.linux@gmail.com", "date": "Wed, 21 Jan 2026 14:57:19 +0000", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
From: David Laight <david.laight.linux@gmail.com> Compile-time tests being added to BIT() make it an 'integer constant expression' rather than a pre-processor expression for W=1 builds. Change the FRAC_ACC != BDS_UNIT test to use static_assert() so the code compiles. Signed-off-by: David Laight <david.laight.linux@gmail.com> --- .../kernels/fixedbds/fixedbds_1.0/ia_css_fixedbds_param.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/staging/media/atomisp/pci/isp/kernels/fixedbds/fixedbds_1.0/ia_css_fixedbds_param.h b/drivers/staging/media/atomisp/pci/isp/kernels/fixedbds/fixedbds_1.0/ia_css_fixedbds_param.h index f7e5669d5125..31bce7b2650e 100644 --- a/drivers/staging/media/atomisp/pci/isp/kernels/fixedbds/fixedbds_1.0/ia_css_fixedbds_param.h +++ b/drivers/staging/media/atomisp/pci/isp/kernels/fixedbds/fixedbds_1.0/ia_css_fixedbds_param.h @@ -13,9 +13,8 @@ #define BDS_UNIT 8 #define FRAC_LOG 3 #define FRAC_ACC BIT(FRAC_LOG) -#if FRAC_ACC != BDS_UNIT -#error "FRAC_ACC and BDS_UNIT need to be merged into one define" -#endif +static_assert(FRAC_ACC == BDS_UNIT, + "FRAC_ACC and BDS_UNIT need to be merged into one define"); struct sh_css_isp_bds_params { int baf_strength; -- 2.39.5
{ "author": "david.laight.linux@gmail.com", "date": "Wed, 21 Jan 2026 14:57:21 +0000", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
From: David Laight <david.laight.linux@gmail.com> asm/tlb.h isn't part of the vdso, use the linux/bits.h header. Signed-off-by: David Laight <david.laight.linux@gmail.com> --- arch/x86/include/asm/tlb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/include/asm/tlb.h b/arch/x86/include/asm/tlb.h index 866ea78ba156..e61c6de73e70 100644 --- a/arch/x86/include/asm/tlb.h +++ b/arch/x86/include/asm/tlb.h @@ -7,7 +7,7 @@ static inline void tlb_flush(struct mmu_gather *tlb); #include <asm-generic/tlb.h> #include <linux/kernel.h> -#include <vdso/bits.h> +#include <linux/bits.h> #include <vdso/page.h> static inline void tlb_flush(struct mmu_gather *tlb) -- 2.39.5
{ "author": "david.laight.linux@gmail.com", "date": "Wed, 21 Jan 2026 14:57:24 +0000", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
From: David Laight <david.laight.linux@gmail.com> Casting the value of BIT_U*() and GENMASK_U8() to (u8) is pointless. Although it changes what typeof(BIT_U8()) returns the value will always be promoted to 'signed int' before it is used. Instead force the expression to be an unsigned type. Avoids unexpected sign extension from, for example: u64 v = BIT_U8(7) << 24; Fix the KUNIT tests to match. Signed-off-by: David Laight <david.laight.linux@gmail.com> --- include/linux/bits.h | 6 +++--- lib/tests/test_bits.c | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/linux/bits.h b/include/linux/bits.h index 697318f2a47d..23bc94815569 100644 --- a/include/linux/bits.h +++ b/include/linux/bits.h @@ -44,8 +44,8 @@ * - GENMASK_U32(33, 15): doesn't fit in a u32 */ #define GENMASK_TYPE(t, h, l) \ - ((t)(GENMASK_INPUT_CHECK(h, l) + \ - ((t)-1 << (l) & (t)-1 >> (BITS_PER_TYPE(t) - 1 - (h))))) + ((unsigned int)GENMASK_INPUT_CHECK(h, l) + \ + ((t)-1 << (l) & (t)-1 >> (BITS_PER_TYPE(t) - 1 - (h)))) #define GENMASK(h, l) GENMASK_TYPE(unsigned long, h, l) #define GENMASK_ULL(h, l) GENMASK_TYPE(unsigned long long, h, l) @@ -67,7 +67,7 @@ #define BIT_INPUT_CHECK(type, nr) \ BUILD_BUG_ON_ZERO(const_true((nr) >= BITS_PER_TYPE(type))) -#define BIT_TYPE(type, nr) ((type)(BIT_INPUT_CHECK(type, nr) + BIT_ULL(nr))) +#define BIT_TYPE(type, nr) ((unsigned int)BIT_INPUT_CHECK(type, nr) + ((type)1 << (nr))) #define BIT_U8(nr) BIT_TYPE(u8, nr) #define BIT_U16(nr) BIT_TYPE(u16, nr) diff --git a/lib/tests/test_bits.c b/lib/tests/test_bits.c index ab88e50d2edf..55be8230f9e7 100644 --- a/lib/tests/test_bits.c +++ b/lib/tests/test_bits.c @@ -9,20 +9,20 @@ #define assert_type(t, x) _Generic(x, t: x, default: 0) -static_assert(assert_type(u8, BIT_U8(0)) == 1u); -static_assert(assert_type(u16, BIT_U16(0)) == 1u); +static_assert(assert_type(unsigned int, BIT_U8(0)) == 1u); +static_assert(assert_type(unsigned int, BIT_U16(0)) == 1u); static_assert(assert_type(u32, BIT_U32(0)) == 1u); static_assert(assert_type(u64, BIT_U64(0)) == 1ull); -static_assert(assert_type(u8, BIT_U8(7)) == 0x80u); -static_assert(assert_type(u16, BIT_U16(15)) == 0x8000u); +static_assert(assert_type(unsigned int, BIT_U8(7)) == 0x80u); +static_assert(assert_type(unsigned int, BIT_U16(15)) == 0x8000u); static_assert(assert_type(u32, BIT_U32(31)) == 0x80000000u); static_assert(assert_type(u64, BIT_U64(63)) == 0x8000000000000000ull); static_assert(assert_type(unsigned long, GENMASK(31, 0)) == U32_MAX); static_assert(assert_type(unsigned long long, GENMASK_ULL(63, 0)) == U64_MAX); -static_assert(assert_type(u8, GENMASK_U8(7, 0)) == U8_MAX); -static_assert(assert_type(u16, GENMASK_U16(15, 0)) == U16_MAX); +static_assert(assert_type(unsigned int, GENMASK_U8(7, 0)) == U8_MAX); +static_assert(assert_type(unsigned int, GENMASK_U16(15, 0)) == U16_MAX); static_assert(assert_type(u32, GENMASK_U32(31, 0)) == U32_MAX); static_assert(assert_type(u64, GENMASK_U64(63, 0)) == U64_MAX); -- 2.39.5
{ "author": "david.laight.linux@gmail.com", "date": "Wed, 21 Jan 2026 14:57:26 +0000", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
From: David Laight <david.laight.linux@gmail.com> thread_info_tif.h isn't part of the vdso, use the linux/bits.h header. Signed-off-by: David Laight <david.laight.linux@gmail.com> --- include/asm-generic/thread_info_tif.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/asm-generic/thread_info_tif.h b/include/asm-generic/thread_info_tif.h index da1610a78f92..afdc23204674 100644 --- a/include/asm-generic/thread_info_tif.h +++ b/include/asm-generic/thread_info_tif.h @@ -2,7 +2,7 @@ #ifndef _ASM_GENERIC_THREAD_INFO_TIF_H_ #define _ASM_GENERIC_THREAD_INFO_TIF_H_ -#include <vdso/bits.h> +#include <linux/bits.h> /* Bits 16-31 are reserved for architecture specific purposes */ -- 2.39.5
{ "author": "david.laight.linux@gmail.com", "date": "Wed, 21 Jan 2026 14:57:23 +0000", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
From: David Laight <david.laight.linux@gmail.com> The assembler only supports one type of signed integers, so expressions using BITS_PER_LONG (etc) cannot be guaranteed to be correct. Use ((2 << (h)) - (1 << (l))) for all assembler GENMASK() expansions and add definitions of BIT_Uxx() as (1 << (nr)). Note that 64bit results are (probably) only correct for 64bit builds and 128bits results will never be valid. Signed-off-by: David Laight <david.laight.linux@gmail.com> --- include/linux/bits.h | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/include/linux/bits.h b/include/linux/bits.h index 23bc94815569..43631a334314 100644 --- a/include/linux/bits.h +++ b/include/linux/bits.h @@ -19,14 +19,6 @@ */ #if !defined(__ASSEMBLY__) -/* - * Missing asm support - * - * GENMASK_U*() and BIT_U*() depend on BITS_PER_TYPE() which relies on sizeof(), - * something not available in asm. Nevertheless, fixed width integers is a C - * concept. Assembly code can rely on the long and long long versions instead. - */ - #include <linux/build_bug.h> #include <linux/compiler.h> #include <linux/overflow.h> @@ -46,6 +38,7 @@ #define GENMASK_TYPE(t, h, l) \ ((unsigned int)GENMASK_INPUT_CHECK(h, l) + \ ((t)-1 << (l) & (t)-1 >> (BITS_PER_TYPE(t) - 1 - (h)))) +#endif #define GENMASK(h, l) GENMASK_TYPE(unsigned long, h, l) #define GENMASK_ULL(h, l) GENMASK_TYPE(unsigned long long, h, l) @@ -56,9 +49,10 @@ #define GENMASK_U64(h, l) GENMASK_TYPE(u64, h, l) #define GENMASK_U128(h, l) GENMASK_TYPE(u128, h, l) +#if !defined(__ASSEMBLY__) /* - * Fixed-type variants of BIT(), with additional checks like GENMASK_TYPE(). The - * following examples generate compiler warnings due to -Wshift-count-overflow: + * Fixed-type variants of BIT(), with additional checks like GENMASK_TYPE(). + * The following examples generate compiler warnings from BIT_INPUT_CHECK(). * * - BIT_U8(8) * - BIT_U32(-1) @@ -68,21 +62,28 @@ BUILD_BUG_ON_ZERO(const_true((nr) >= BITS_PER_TYPE(type))) #define BIT_TYPE(type, nr) ((unsigned int)BIT_INPUT_CHECK(type, nr) + ((type)1 << (nr))) +#endif /* defined(__ASSEMBLY__) */ #define BIT_U8(nr) BIT_TYPE(u8, nr) #define BIT_U16(nr) BIT_TYPE(u16, nr) #define BIT_U32(nr) BIT_TYPE(u32, nr) #define BIT_U64(nr) BIT_TYPE(u64, nr) -#else /* defined(__ASSEMBLY__) */ +#if defined(__ASSEMBLY__) /* - * BUILD_BUG_ON_ZERO is not available in h files included from asm files, - * disable the input check if that is the case. + * The assmebler only supports one size of signed integer rather than + * the fixed width integer types of C. + * There is also no method for reported invalid input. + * Error in .h files will usually be picked up when compiled into C files. + * + * Define type-size agnostic definitions that generate the correct value + * provided it can be represented by the assembler. */ -#define GENMASK(h, l) __GENMASK(h, l) -#define GENMASK_ULL(h, l) __GENMASK_ULL(h, l) -#endif /* !defined(__ASSEMBLY__) */ +#define GENMASK_TYPE(t, h, l) ((2 << (h)) - (1 << (l))) +#define BIT_TYPE(type, nr) (1 << (nr)) + +#endif /* defined(__ASSEMBLY__) */ #endif /* __LINUX_BITS_H */ -- 2.39.5
{ "author": "david.laight.linux@gmail.com", "date": "Wed, 21 Jan 2026 14:57:27 +0000", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
From: David Laight <david.laight.linux@gmail.com> Compile-time tests being added to BIT() make it an 'integer constant expression' rather than a pre-processor expression for W=1 builds. This means BIT() can't be used in pre-processor conditional that checks 'PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD'. Change to use a normal 'if' statement, the compiler will optimise away the unwanted code. Signed-off-by: David Laight <david.laight.linux@gmail.com> --- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c index d5ce20f47def..65dd5834d0cf 100644 --- a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +++ b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c @@ -4166,9 +4166,6 @@ static int ixgbevf_xmit_frame_ring(struct sk_buff *skb, u32 tx_flags = 0; u16 count = TXD_USE_COUNT(skb_headlen(skb)); struct ixgbevf_ipsec_tx_data ipsec_tx = { 0 }; -#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD - unsigned short f; -#endif u8 hdr_len = 0; u8 *dst_mac = skb_header_pointer(skb, 0, 0, NULL); @@ -4183,15 +4180,15 @@ static int ixgbevf_xmit_frame_ring(struct sk_buff *skb, * + 1 desc for context descriptor, * otherwise try next time */ -#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD - for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) { - skb_frag_t *frag = &skb_shinfo(skb)->frags[f]; + if (PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD) { + for (unsigned int f = 0; f < skb_shinfo(skb)->nr_frags; f++) { + skb_frag_t *frag = &skb_shinfo(skb)->frags[f]; - count += TXD_USE_COUNT(skb_frag_size(frag)); + count += TXD_USE_COUNT(skb_frag_size(frag)); + } + } else { + count += skb_shinfo(skb)->nr_frags; } -#else - count += skb_shinfo(skb)->nr_frags; -#endif if (ixgbevf_maybe_stop_tx(tx_ring, count + 3)) { tx_ring->tx_stats.tx_busy++; return NETDEV_TX_BUSY; -- 2.39.5
{ "author": "david.laight.linux@gmail.com", "date": "Wed, 21 Jan 2026 14:57:22 +0000", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
From: David Laight <david.laight.linux@gmail.com> The current checks in GENMASK/BIT (eg reversed high/low) only work for 'integer constant expressions' not 'compile-time constants'. This is true for const_true() and -Wshift-count-overflow/negative. While compile-time constants may be unusual, they can happen through function inlining. This isn't too bad with gcc, but if clang detects a negative/over-large shift it treats it as 'undefined behaviour' and silently discards all code that would use the result, so: int f(u32 x) {int n = 32; return x >> n; } generates a function that just contains a 'return' instruction. If 'n' was a variable that happened to be 32, most modern cpu mask the count - so would return 'x', some might return 0. Add extra checks for arguments that pass __builtin_constant_p() but are not 'integer constant expressions. __builtin_choose_expr() isn't strong enough to allow _Static_assert() or ({ ... }) in the other branch so non-standard schemes are used to report the errors. To reduce pre-processor bloat the checks are only enabled for W=c (implied by W=1) builds (where they are errors). Update the unit tests to match. Signed-off-by: David Laight <david.laight.linux@gmail.com> --- include/linux/bits.h | 45 +++++++++++++++++++++++++++++++++---------- lib/tests/test_bits.c | 34 +++++++++++++++++++------------- 2 files changed, 56 insertions(+), 23 deletions(-) diff --git a/include/linux/bits.h b/include/linux/bits.h index 43631a334314..0f559038981d 100644 --- a/include/linux/bits.h +++ b/include/linux/bits.h @@ -23,20 +23,35 @@ #include <linux/compiler.h> #include <linux/overflow.h> -#define GENMASK_INPUT_CHECK(h, l) BUILD_BUG_ON_ZERO(const_true((l) > (h))) +#ifndef KBUILD_EXTRA_WARNc +#define GENMASK_INPUT_CHECK(h, l, width) 0 +#else +int GENMASK_INPUT_CHECK_FAIL(void) __compiletime_error("Invalid bit numbers"); +#define GENMASK_INPUT_CHECK(h, l, width) \ + (__builtin_choose_expr(__is_constexpr((l) > (h)), \ + sizeof(struct { char low_bit_greater_than_high[-((l) > (h))];}), \ + __builtin_constant_p((l) | (h)) && \ + ((l) < 0 || (l) > (h) || (h) >= width) && \ + GENMASK_INPUT_CHECK_FAIL())) +#endif /* - * Generate a mask for the specified type @t. Additional checks are made to - * guarantee the value returned fits in that type, relying on - * -Wshift-count-overflow compiler check to detect incompatible arguments. + * Generate a mask for the specified type @t. + * Checks are made to guarantee the value returned fits in that type. + * The compiler's -Wshift-count-overflow/negative check detects invalid values + * from 'constant integer expressions' but not other compile time constants. + * Clang treats out of value constants as 'undefined behaviour' and stops + * generating code - so explicit checks are needed. + * Neither BUILD_BUG() nor BUILD_BUG_ON_ZERO() can be used. + * * For example, all these create build errors or warnings: * * - GENMASK(15, 20): wrong argument order * - GENMASK(72, 15): doesn't fit unsigned long * - GENMASK_U32(33, 15): doesn't fit in a u32 */ -#define GENMASK_TYPE(t, h, l) \ - ((unsigned int)GENMASK_INPUT_CHECK(h, l) + \ +#define GENMASK_TYPE(t, h, l) \ + ((unsigned int)GENMASK_INPUT_CHECK(h, l, BITS_PER_TYPE(t)) + \ ((t)-1 << (l) & (t)-1 >> (BITS_PER_TYPE(t) - 1 - (h)))) #endif @@ -52,16 +67,26 @@ #if !defined(__ASSEMBLY__) /* * Fixed-type variants of BIT(), with additional checks like GENMASK_TYPE(). - * The following examples generate compiler warnings from BIT_INPUT_CHECK(). + * The following examples generate compiler errors from BIT_INPUT_CHECK(). * * - BIT_U8(8) * - BIT_U32(-1) * - BIT_U32(40) */ -#define BIT_INPUT_CHECK(type, nr) \ - BUILD_BUG_ON_ZERO(const_true((nr) >= BITS_PER_TYPE(type))) -#define BIT_TYPE(type, nr) ((unsigned int)BIT_INPUT_CHECK(type, nr) + ((type)1 << (nr))) +#ifndef KBUILD_EXTRA_WARNc +#define BIT_INPUT_CHECK(nr, width) 0 +#else +int BIT_INPUT_CHECK_FAIL(void) __compiletime_error("Bit number out of range"); +#define BIT_INPUT_CHECK(nr, width) \ + (__builtin_choose_expr(__is_constexpr(nr), \ + sizeof(struct { char bit_number_too_big[-((nr) >= (width))];}), \ + __builtin_constant_p(nr) && ((nr) < 0 || (nr) >= width) && \ + BIT_INPUT_CHECK_FAIL())) +#endif + +#define BIT_TYPE(type, nr) \ + ((unsigned int)BIT_INPUT_CHECK(+(nr), BITS_PER_TYPE(type)) + ((type)1 << (nr))) #endif /* defined(__ASSEMBLY__) */ #define BIT_U8(nr) BIT_TYPE(u8, nr) diff --git a/lib/tests/test_bits.c b/lib/tests/test_bits.c index 55be8230f9e7..36eb4661e78b 100644 --- a/lib/tests/test_bits.c +++ b/lib/tests/test_bits.c @@ -3,6 +3,8 @@ * Test cases for functions and macros in bits.h */ +#define KBUILD_EXTRA_WARNc 1 + #include <kunit/test.h> #include <linux/bits.h> #include <linux/types.h> @@ -118,24 +120,30 @@ static void genmask_u128_test(struct kunit *test) static void genmask_input_check_test(struct kunit *test) { - unsigned int x, y; - int z, w; + unsigned int x = 1, y = 2; + int z = 1, w = 2; + + OPTIMIZER_HIDE_VAR(x); + OPTIMIZER_HIDE_VAR(y); + OPTIMIZER_HIDE_VAR(z); + OPTIMIZER_HIDE_VAR(w); /* Unknown input */ - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(x, 0)); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(0, x)); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(x, y)); + KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(x, 0, 32)); + KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(0, x, 32)); + KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(x, y, 32)); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(z, 0)); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(0, z)); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(z, w)); + KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(z, 0, 32)); + KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(0, z, 32)); + KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(z, w, 32)); /* Valid input */ - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(1, 1)); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(39, 21)); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(100, 80)); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(110, 65)); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(127, 0)); + KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(1, 1, 32)); + KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(39, 21, 64)); + + KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(100, 80, 128)); + KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(110, 65, 128)); + KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(127, 0, 128)); } -- 2.39.5
{ "author": "david.laight.linux@gmail.com", "date": "Wed, 21 Jan 2026 14:57:28 +0000", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
From: David Laight <david.laight.linux@gmail.com> Since all the GENMASK() values are compile-time constants they can be tested with BUILD_BUG_ON() rather than KUNIT_EXPECT_EQ(). Signed-off-by: David Laight <david.laight.linux@gmail.com> --- lib/tests/test_bits.c | 90 +++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/lib/tests/test_bits.c b/lib/tests/test_bits.c index 36eb4661e78b..4d3a895f490c 100644 --- a/lib/tests/test_bits.c +++ b/lib/tests/test_bits.c @@ -32,30 +32,30 @@ static_assert(assert_type(u64, GENMASK_U64(63, 0)) == U64_MAX); static void __genmask_test(struct kunit *test) { - KUNIT_EXPECT_EQ(test, 1ul, __GENMASK(0, 0)); - KUNIT_EXPECT_EQ(test, 3ul, __GENMASK(1, 0)); - KUNIT_EXPECT_EQ(test, 6ul, __GENMASK(2, 1)); - KUNIT_EXPECT_EQ(test, 0xFFFFFFFFul, __GENMASK(31, 0)); + BUILD_BUG_ON(__GENMASK(0, 0) != 1ul); + BUILD_BUG_ON(__GENMASK(1, 0) != 3ul); + BUILD_BUG_ON(__GENMASK(2, 1) != 6ul); + BUILD_BUG_ON(__GENMASK(31, 0) != 0xFFFFFFFFul); } static void __genmask_ull_test(struct kunit *test) { - KUNIT_EXPECT_EQ(test, 1ull, __GENMASK_ULL(0, 0)); - KUNIT_EXPECT_EQ(test, 3ull, __GENMASK_ULL(1, 0)); - KUNIT_EXPECT_EQ(test, 0x000000ffffe00000ull, __GENMASK_ULL(39, 21)); - KUNIT_EXPECT_EQ(test, 0xffffffffffffffffull, __GENMASK_ULL(63, 0)); + BUILD_BUG_ON(__GENMASK_ULL(0, 0) != 1ull); + BUILD_BUG_ON(__GENMASK_ULL(1, 0) != 3ull); + BUILD_BUG_ON(__GENMASK_ULL(39, 21) != 0x000000ffffe00000ull); + BUILD_BUG_ON(__GENMASK_ULL(63, 0) != 0xffffffffffffffffull); } static void genmask_test(struct kunit *test) { - KUNIT_EXPECT_EQ(test, 1ul, GENMASK(0, 0)); - KUNIT_EXPECT_EQ(test, 3ul, GENMASK(1, 0)); - KUNIT_EXPECT_EQ(test, 6ul, GENMASK(2, 1)); - KUNIT_EXPECT_EQ(test, 0xFFFFFFFFul, GENMASK(31, 0)); + BUILD_BUG_ON(GENMASK(0, 0) != 1ul); + BUILD_BUG_ON(GENMASK(1, 0) != 3ul); + BUILD_BUG_ON(GENMASK(2, 1) != 6ul); + BUILD_BUG_ON(GENMASK(31, 0) != 0xFFFFFFFFul); - KUNIT_EXPECT_EQ(test, 1u, GENMASK_U8(0, 0)); - KUNIT_EXPECT_EQ(test, 3u, GENMASK_U16(1, 0)); - KUNIT_EXPECT_EQ(test, 0x10000, GENMASK_U32(16, 16)); + BUILD_BUG_ON(GENMASK_U8(0, 0) != 1u); + BUILD_BUG_ON(GENMASK_U16(1, 0) != 3u); + BUILD_BUG_ON(GENMASK_U32(16, 16) != 0x10000); #ifdef TEST_GENMASK_FAILURES /* these should fail compilation */ @@ -75,10 +75,10 @@ static void genmask_test(struct kunit *test) static void genmask_ull_test(struct kunit *test) { - KUNIT_EXPECT_EQ(test, 1ull, GENMASK_ULL(0, 0)); - KUNIT_EXPECT_EQ(test, 3ull, GENMASK_ULL(1, 0)); - KUNIT_EXPECT_EQ(test, 0x000000ffffe00000ull, GENMASK_ULL(39, 21)); - KUNIT_EXPECT_EQ(test, 0xffffffffffffffffull, GENMASK_ULL(63, 0)); + BUILD_BUG_ON(GENMASK_ULL(0, 0) != 1ull); + BUILD_BUG_ON(GENMASK_ULL(1, 0) != 3ull); + BUILD_BUG_ON(GENMASK_ULL(39, 21) != 0x000000ffffe00000ull); + BUILD_BUG_ON(GENMASK_ULL(63, 0) != 0xffffffffffffffffull); #ifdef TEST_GENMASK_FAILURES /* these should fail compilation */ @@ -92,23 +92,23 @@ static void genmask_u128_test(struct kunit *test) { #ifdef CONFIG_ARCH_SUPPORTS_INT128 /* Below 64 bit masks */ - KUNIT_EXPECT_EQ(test, 0x0000000000000001ull, GENMASK_U128(0, 0)); - KUNIT_EXPECT_EQ(test, 0x0000000000000003ull, GENMASK_U128(1, 0)); - KUNIT_EXPECT_EQ(test, 0x0000000000000006ull, GENMASK_U128(2, 1)); - KUNIT_EXPECT_EQ(test, 0x00000000ffffffffull, GENMASK_U128(31, 0)); - KUNIT_EXPECT_EQ(test, 0x000000ffffe00000ull, GENMASK_U128(39, 21)); - KUNIT_EXPECT_EQ(test, 0xffffffffffffffffull, GENMASK_U128(63, 0)); + BUILD_BUG_ON(GENMASK_U128(0, 0) != 0x0000000000000001ull); + BUILD_BUG_ON(GENMASK_U128(1, 0) != 0x0000000000000003ull); + BUILD_BUG_ON(GENMASK_U128(2, 1) != 0x0000000000000006ull); + BUILD_BUG_ON(GENMASK_U128(31, 0) != 0x00000000ffffffffull); + BUILD_BUG_ON(GENMASK_U128(39, 21) != 0x000000ffffe00000ull); + BUILD_BUG_ON(GENMASK_U128(63, 0) != 0xffffffffffffffffull); /* Above 64 bit masks - only 64 bit portion can be validated once */ - KUNIT_EXPECT_EQ(test, 0xffffffffffffffffull, GENMASK_U128(64, 0) >> 1); - KUNIT_EXPECT_EQ(test, 0x00000000ffffffffull, GENMASK_U128(81, 50) >> 50); - KUNIT_EXPECT_EQ(test, 0x0000000000ffffffull, GENMASK_U128(87, 64) >> 64); - KUNIT_EXPECT_EQ(test, 0x0000000000ff0000ull, GENMASK_U128(87, 80) >> 64); - - KUNIT_EXPECT_EQ(test, 0xffffffffffffffffull, GENMASK_U128(127, 0) >> 64); - KUNIT_EXPECT_EQ(test, 0xffffffffffffffffull, (u64)GENMASK_U128(127, 0)); - KUNIT_EXPECT_EQ(test, 0x0000000000000003ull, GENMASK_U128(127, 126) >> 126); - KUNIT_EXPECT_EQ(test, 0x0000000000000001ull, GENMASK_U128(127, 127) >> 127); + BUILD_BUG_ON(GENMASK_U128(64, 0) >> 1 != 0xffffffffffffffffull); + BUILD_BUG_ON(GENMASK_U128(81, 50) >> 50 != 0x00000000ffffffffull); + BUILD_BUG_ON(GENMASK_U128(87, 64) >> 64 != 0x0000000000ffffffull); + BUILD_BUG_ON(GENMASK_U128(87, 80) >> 64 != 0x0000000000ff0000ull); + + BUILD_BUG_ON(GENMASK_U128(127, 0) >> 64 != 0xffffffffffffffffull); + BUILD_BUG_ON((u64)GENMASK_U128(127, 0) != 0xffffffffffffffffull); + BUILD_BUG_ON(GENMASK_U128(127, 126) >> 126 != 0x0000000000000003ull); + BUILD_BUG_ON(GENMASK_U128(127, 127) >> 127 != 0x0000000000000001ull); #ifdef TEST_GENMASK_FAILURES /* these should fail compilation */ GENMASK_U128(0, 1); @@ -129,21 +129,21 @@ static void genmask_input_check_test(struct kunit *test) OPTIMIZER_HIDE_VAR(w); /* Unknown input */ - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(x, 0, 32)); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(0, x, 32)); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(x, y, 32)); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(x, 0, 32) != 0); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(0, x, 32) != 0); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(x, y, 32) != 0); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(z, 0, 32)); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(0, z, 32)); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(z, w, 32)); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(z, 0, 32) != 0); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(0, z, 32) != 0); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(z, w, 32) != 0); /* Valid input */ - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(1, 1, 32)); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(39, 21, 64)); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(1, 1, 32) != 0); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(39, 21, 64) != 0); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(100, 80, 128)); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(110, 65, 128)); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(127, 0, 128)); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(100, 80, 128) != 0); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(110, 65, 128) != 0); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(127, 0, 128) != 0); } -- 2.39.5
{ "author": "david.laight.linux@gmail.com", "date": "Wed, 21 Jan 2026 14:57:30 +0000", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
From: David Laight <david.laight.linux@gmail.com> The definition of BIT() was moved from linux/bits.h to vdso/bits.h to isolate the vdso from 'normal' kernel headers. BIT_ULL() was then moved to be defined in the same place for consistency. Since then linux/bits.h had gained BIT_Unn() and it really makes sense for BIT() and BIT_ULL() to be defined in the same place. Move BIT_ULL() and make code that include both headers use the definition of BIT() from linux/bits.h Add BIT_U128() for completness. This lets BIT() pick up the extra compile time checks for W=[1c] builds that detect errors like: long foo(void) { int x = 64; return BIT(x); } For which clang (silently) just generates a 'return' instruction. Note that nothing the the x86-64 build relies on the definition in vdso/bits.h, linux/bits.h is always included. Signed-off-by: David Laight <david.laight.linux@gmail.com> --- include/linux/bits.h | 7 ++++++- include/vdso/bits.h | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/linux/bits.h b/include/linux/bits.h index 0f559038981d..3dd32b9eef35 100644 --- a/include/linux/bits.h +++ b/include/linux/bits.h @@ -2,7 +2,6 @@ #ifndef __LINUX_BITS_H #define __LINUX_BITS_H -#include <vdso/bits.h> #include <uapi/linux/bits.h> #define BIT_MASK(nr) (UL(1) << ((nr) % BITS_PER_LONG)) @@ -89,10 +88,16 @@ int BIT_INPUT_CHECK_FAIL(void) __compiletime_error("Bit number out of range"); ((unsigned int)BIT_INPUT_CHECK(+(nr), BITS_PER_TYPE(type)) + ((type)1 << (nr))) #endif /* defined(__ASSEMBLY__) */ +/* Prefer this definition of BIT() to the one in vdso/bits.h */ +#undef BIT +#define __VDSO_BITS_H +#define BIT(nr) BIT_TYPE(unsigned long, nr) +#define BIT_ULL(nr) BIT_TYPE(unsigned long long, nr) #define BIT_U8(nr) BIT_TYPE(u8, nr) #define BIT_U16(nr) BIT_TYPE(u16, nr) #define BIT_U32(nr) BIT_TYPE(u32, nr) #define BIT_U64(nr) BIT_TYPE(u64, nr) +#define BIT_U128(nr) BIT_TYPE(u128, nr) #if defined(__ASSEMBLY__) diff --git a/include/vdso/bits.h b/include/vdso/bits.h index 388b212088ea..a6ac1e6b637c 100644 --- a/include/vdso/bits.h +++ b/include/vdso/bits.h @@ -4,7 +4,7 @@ #include <vdso/const.h> +/* Most code picks up BIT() from linux/bits.h */ #define BIT(nr) (UL(1) << (nr)) -#define BIT_ULL(nr) (ULL(1) << (nr)) #endif /* __VDSO_BITS_H */ -- 2.39.5
{ "author": "david.laight.linux@gmail.com", "date": "Wed, 21 Jan 2026 14:57:29 +0000", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Wed, Jan 21, 2026 at 02:57:29PM +0000, david.laight.linux@gmail.com wrote: This is ugly. Why can't the vDSO code make use of those checks, too? Or use _BITUL() from the UAPI in the vDSO and remove vdso/bits.h.
{ "author": "Thomas =?utf-8?Q?Wei=C3=9Fschuh?= <thomas.weissschuh@linutronix.de>", "date": "Wed, 21 Jan 2026 16:17:18 +0100", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On 21/01/2026 at 15:57, david.laight.linux@gmail.com wrote: Did those new checks actually found any real problem in the code? This adds a lot of complexity so I am not sure whether this is a winning trade-off. But then, you only solve that shift problem for GENMASK() and BIT(). Any other usage of the left/right shifts are not diagnosed unless your check get copy pasted all over the place. I think that such a check belongs to a static analyzer. Speaking of which: $ cat test.c typedef unsigned int u32; static int f(u32 x) {int n = 32; return x >> n; } $ sparse test.c test.c:2:46: warning: shift too big (32) for type unsigned int$ cat test.c So here, I would rather keep relying on sparse rather that introducing the W=c logic and all that macro complexity. Yours sincerely, Vincent Mailhol
{ "author": "Vincent Mailhol <mailhol@kernel.org>", "date": "Wed, 21 Jan 2026 19:43:07 +0100", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Wed, 21 Jan 2026 19:43:07 +0100 Vincent Mailhol <mailhol@kernel.org> wrote: Not in an x86-64 allmodconfig build. They might in a 32bit one where there have definitely been issues. I suspect the compiler test will find more than sparse. I liked getting that to work, but maybe it is OTT. But the W=c is more generally useful. As well as removing all the compile-time tests from GENMASK() and (in another patch FIELD_PREP()) which really do bloat the .i file, I'd like to add some new tests to min/max/clamp to try to get rid of the more dodgy (and likely buggy) cases without breaking everyone's build - just failing the W=1 builds is better. Using a separate flag means you can use W=ce to stop the build, doing a W=1e build is hopeless. David
{ "author": "David Laight <david.laight.linux@gmail.com>", "date": "Wed, 21 Jan 2026 19:14:48 +0000", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Wed, 21 Jan 2026 16:17:18 +0100 Thomas Weißschuh <thomas.weissschuh@linutronix.de> wrote: It works :-) I could have put an #ifndef BIT in vdso/bits.h instead. I didn't actually find anything that just needed vdso/bits.h linux/bits.h would get included - eg (IIRC) because of warn_on_once(). I'm not that sure why it got separated, it isn't as though it defines anything that is code version specific. David
{ "author": "David Laight <david.laight.linux@gmail.com>", "date": "Wed, 21 Jan 2026 19:24:51 +0000", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Wed, Jan 21, 2026 at 02:57:18PM +0000, david.laight.linux@gmail.com wrote: Sure! Reviewed-by: Kees Cook <kees@kernel.org> -- Kees Cook
{ "author": "Kees Cook <kees@kernel.org>", "date": "Wed, 21 Jan 2026 12:59:36 -0800", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
Hi, kernel test robot noticed the following build errors: [auto build test ERROR on next-20260120] url: https://github.com/intel-lab-lkp/linux/commits/david-laight-linux-gmail-com/overflow-Reduce-expansion-of-__type_max/20260122-013456 base: next-20260120 patch link: https://lore.kernel.org/r/20260121145731.3623-13-david.laight.linux%40gmail.com patch subject: [PATCH next 12/14] bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h config: arm-allnoconfig (https://download.01.org/0day-ci/archive/20260122/202601220832.NJbHlnXC-lkp@intel.com/config) compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 9b8addffa70cee5b2acc5454712d9cf78ce45710) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260122/202601220832.NJbHlnXC-lkp@intel.com/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 <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202601220832.NJbHlnXC-lkp@intel.com/ All errors (new ones prefixed by >>): 163 | _SIG_SET_BINOP(sigandnsets, _sig_andn) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/signal.h:139:8: note: expanded from macro '_SIG_SET_BINOP' 139 | b3 = b->sig[3]; b2 = b->sig[2]; \ | ^ ~ arch/arm/include/asm/signal.h:17:2: note: array 'sig' declared here 17 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from arch/arm/kernel/asm-offsets.c:14: In file included from include/linux/mm.h:36: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:6: include/linux/signal.h:163:1: warning: array index 2 is past the end of the array (that has type 'const unsigned long[2]') [-Warray-bounds] 163 | _SIG_SET_BINOP(sigandnsets, _sig_andn) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/signal.h:139:24: note: expanded from macro '_SIG_SET_BINOP' 139 | b3 = b->sig[3]; b2 = b->sig[2]; \ | ^ ~ arch/arm/include/asm/signal.h:17:2: note: array 'sig' declared here 17 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from arch/arm/kernel/asm-offsets.c:14: In file included from include/linux/mm.h:36: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:6: include/linux/signal.h:163:1: warning: array index 3 is past the end of the array (that has type 'unsigned long[2]') [-Warray-bounds] 163 | _SIG_SET_BINOP(sigandnsets, _sig_andn) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/signal.h:140:3: note: expanded from macro '_SIG_SET_BINOP' 140 | r->sig[3] = op(a3, b3); \ | ^ ~ arch/arm/include/asm/signal.h:17:2: note: array 'sig' declared here 17 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from arch/arm/kernel/asm-offsets.c:14: In file included from include/linux/mm.h:36: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:6: include/linux/signal.h:163:1: warning: array index 2 is past the end of the array (that has type 'unsigned long[2]') [-Warray-bounds] 163 | _SIG_SET_BINOP(sigandnsets, _sig_andn) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/signal.h:141:3: note: expanded from macro '_SIG_SET_BINOP' 141 | r->sig[2] = op(a2, b2); \ | ^ ~ arch/arm/include/asm/signal.h:17:2: note: array 'sig' declared here 17 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from arch/arm/kernel/asm-offsets.c:14: In file included from include/linux/mm.h:36: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:6: include/linux/signal.h:187:1: warning: array index 3 is past the end of the array (that has type 'unsigned long[2]') [-Warray-bounds] 187 | _SIG_SET_OP(signotset, _sig_not) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/signal.h:174:27: note: expanded from macro '_SIG_SET_OP' 174 | case 4: set->sig[3] = op(set->sig[3]); \ | ^ ~ arch/arm/include/asm/signal.h:17:2: note: array 'sig' declared here 17 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from arch/arm/kernel/asm-offsets.c:14: In file included from include/linux/mm.h:36: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:6: include/linux/signal.h:187:1: warning: array index 3 is past the end of the array (that has type 'unsigned long[2]') [-Warray-bounds] 187 | _SIG_SET_OP(signotset, _sig_not) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/signal.h:174:10: note: expanded from macro '_SIG_SET_OP' 174 | case 4: set->sig[3] = op(set->sig[3]); \ | ^ ~ arch/arm/include/asm/signal.h:17:2: note: array 'sig' declared here 17 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from arch/arm/kernel/asm-offsets.c:14: In file included from include/linux/mm.h:36: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:6: include/linux/signal.h:187:1: warning: array index 2 is past the end of the array (that has type 'unsigned long[2]') [-Warray-bounds] 187 | _SIG_SET_OP(signotset, _sig_not) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/signal.h:175:20: note: expanded from macro '_SIG_SET_OP' 175 | set->sig[2] = op(set->sig[2]); \ | ^ ~ arch/arm/include/asm/signal.h:17:2: note: array 'sig' declared here 17 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from arch/arm/kernel/asm-offsets.c:14: In file included from include/linux/mm.h:36: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:6: include/linux/signal.h:187:1: warning: array index 2 is past the end of the array (that has type 'unsigned long[2]') [-Warray-bounds] 187 | _SIG_SET_OP(signotset, _sig_not) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/signal.h:175:3: note: expanded from macro '_SIG_SET_OP' 175 | set->sig[2] = op(set->sig[2]); \ | ^ ~ arch/arm/include/asm/signal.h:17:2: note: array 'sig' declared here 17 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from arch/arm/kernel/asm-offsets.c:14: 994 | const vm_flags_t mask = BIT((__force int)bit); | ^ include/linux/bits.h:94:18: note: expanded from macro 'BIT' 94 | #define BIT(nr) BIT_TYPE(unsigned long, nr) | ^ include/linux/bits.h:88:17: note: expanded from macro 'BIT_TYPE' 88 | ((unsigned int)BIT_INPUT_CHECK(+(nr), BITS_PER_TYPE(type)) + ((type)1 << (nr))) | ^ include/linux/bits.h:82:24: note: expanded from macro 'BIT_INPUT_CHECK' 82 | sizeof(struct { char bit_number_too_big[-((nr) >= (width))];}), \ | ^ 28 warnings and 16 errors generated. make[3]: *** [scripts/Makefile.build:182: arch/arm/kernel/asm-offsets.s] Error 1 make[3]: Target 'prepare' not remade because of errors. make[2]: *** [Makefile:1330: prepare0] Error 2 make[2]: Target 'prepare' not remade because of errors. make[1]: *** [Makefile:248: __sub-make] Error 2 make[1]: Target 'prepare' not remade because of errors. make: *** [Makefile:248: __sub-make] Error 2 make: Target 'prepare' not remade because of errors. vim +994 include/linux/mm.h bc292ab00f6c7a6 Suren Baghdasaryan 2023-01-26 990 568822502383acd Lorenzo Stoakes 2025-11-18 991 static inline bool __vma_flag_atomic_valid(struct vm_area_struct *vma, 2b6a3f061f11372 Lorenzo Stoakes 2025-11-25 992 vma_flag_t bit) 568822502383acd Lorenzo Stoakes 2025-11-18 993 { 2b6a3f061f11372 Lorenzo Stoakes 2025-11-25 @994 const vm_flags_t mask = BIT((__force int)bit); 568822502383acd Lorenzo Stoakes 2025-11-18 995 568822502383acd Lorenzo Stoakes 2025-11-18 996 /* Only specific flags are permitted */ 568822502383acd Lorenzo Stoakes 2025-11-18 997 if (WARN_ON_ONCE(!(mask & VM_ATOMIC_SET_ALLOWED))) 568822502383acd Lorenzo Stoakes 2025-11-18 998 return false; 568822502383acd Lorenzo Stoakes 2025-11-18 999 568822502383acd Lorenzo Stoakes 2025-11-18 1000 return true; 568822502383acd Lorenzo Stoakes 2025-11-18 1001 } 568822502383acd Lorenzo Stoakes 2025-11-18 1002 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
{ "author": "kernel test robot <lkp@intel.com>", "date": "Thu, 22 Jan 2026 08:50:22 +0800", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
Hi, kernel test robot noticed the following build errors: [auto build test ERROR on next-20260120] url: https://github.com/intel-lab-lkp/linux/commits/david-laight-linux-gmail-com/overflow-Reduce-expansion-of-__type_max/20260122-013456 base: next-20260120 patch link: https://lore.kernel.org/r/20260121145731.3623-12-david.laight.linux%40gmail.com patch subject: [PATCH next 11/14] bit: Strengthen compile-time tests in GENMASK() and BIT() config: s390-randconfig-001-20260122 (https://download.01.org/0day-ci/archive/20260122/202601220829.MgTMeqqN-lkp@intel.com/config) compiler: s390-linux-gcc (GCC) 8.5.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260122/202601220829.MgTMeqqN-lkp@intel.com/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 <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202601220829.MgTMeqqN-lkp@intel.com/ All errors (new ones prefixed by >>): In file included from arch/s390/include/asm/bug.h:60, from include/linux/bug.h:5, from include/linux/mmdebug.h:5, from arch/s390/include/asm/cmpxchg.h:11, from arch/s390/include/asm/atomic.h:16, from include/linux/atomic.h:7, from include/asm-generic/bitops/atomic.h:5, from arch/s390/include/asm/bitops.h:75, from include/linux/bitops.h:67, from include/linux/kernel.h:23, from net/core/page_pool.c:10: In function 'netmem_clear_pp_magic', inlined from 'page_pool_clear_pp_info' at net/core/page_pool.c:721:2: GENMASK_INPUT_CHECK_FAIL())) ^~~~~~~~~~~~~~~~~~~~~~~~~~ include/asm-generic/bug.h:120:25: note: in definition of macro 'WARN_ON_ONCE' int __ret_warn_on = !!(condition); \ ^~~~~~~~~ include/linux/bits.h:54:17: note: in expansion of macro 'GENMASK_INPUT_CHECK' ((unsigned int)GENMASK_INPUT_CHECK(h, l, BITS_PER_TYPE(t)) + \ ^~~~~~~~~~~~~~~~~~~ include/linux/bits.h:58:24: note: in expansion of macro 'GENMASK_TYPE' #define GENMASK(h, l) GENMASK_TYPE(unsigned long, h, l) ^~~~~~~~~~~~ include/linux/mm.h:4641:27: note: in expansion of macro 'GENMASK' #define PP_DMA_INDEX_MASK GENMASK(PP_DMA_INDEX_BITS + PP_DMA_INDEX_SHIFT - 1, \ ^~~~~~~ net/core/netmem_priv.h:18:52: note: in expansion of macro 'PP_DMA_INDEX_MASK' WARN_ON_ONCE(netmem_to_nmdesc(netmem)->pp_magic & PP_DMA_INDEX_MASK); ^~~~~~~~~~~~~~~~~ -- In file included from include/linux/bitops.h:6, from arch/s390/include/asm/machine.h:25, from arch/s390/include/asm/lowcore.h:13, from arch/s390/include/asm/current.h:13, from arch/s390/include/asm/preempt.h:5, from include/linux/preempt.h:79, from arch/s390/include/asm/timex.h:13, from include/linux/timex.h:67, from include/linux/time32.h:13, from include/linux/time.h:60, from include/linux/stat.h:19, from include/linux/module.h:13, from net/core/skbuff.c:37: In function 'netmem_get_pp_magic', inlined from 'netmem_is_pp' at net/core/netmem_priv.h:25:10, inlined from 'napi_pp_put_page' at net/core/skbuff.c:1027:6: GENMASK_INPUT_CHECK_FAIL())) ^~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/bits.h:54:17: note: in expansion of macro 'GENMASK_INPUT_CHECK' ((unsigned int)GENMASK_INPUT_CHECK(h, l, BITS_PER_TYPE(t)) + \ ^~~~~~~~~~~~~~~~~~~ include/linux/bits.h:58:24: note: in expansion of macro 'GENMASK_TYPE' #define GENMASK(h, l) GENMASK_TYPE(unsigned long, h, l) ^~~~~~~~~~~~ include/linux/mm.h:4641:27: note: in expansion of macro 'GENMASK' #define PP_DMA_INDEX_MASK GENMASK(PP_DMA_INDEX_BITS + PP_DMA_INDEX_SHIFT - 1, \ ^~~~~~~ net/core/netmem_priv.h:8:47: note: in expansion of macro 'PP_DMA_INDEX_MASK' return netmem_to_nmdesc(netmem)->pp_magic & ~PP_DMA_INDEX_MASK; ^~~~~~~~~~~~~~~~~ In function 'netmem_is_pp', inlined from 'napi_pp_put_page' at net/core/skbuff.c:1027:6: GENMASK_INPUT_CHECK_FAIL())) ^~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/bits.h:54:17: note: in expansion of macro 'GENMASK_INPUT_CHECK' ((unsigned int)GENMASK_INPUT_CHECK(h, l, BITS_PER_TYPE(t)) + \ ^~~~~~~~~~~~~~~~~~~ include/linux/bits.h:58:24: note: in expansion of macro 'GENMASK_TYPE' #define GENMASK(h, l) GENMASK_TYPE(unsigned long, h, l) ^~~~~~~~~~~~ include/linux/mm.h:4641:27: note: in expansion of macro 'GENMASK' #define PP_DMA_INDEX_MASK GENMASK(PP_DMA_INDEX_BITS + PP_DMA_INDEX_SHIFT - 1, \ ^~~~~~~ include/linux/mm.h:4650:25: note: in expansion of macro 'PP_DMA_INDEX_MASK' #define PP_MAGIC_MASK ~(PP_DMA_INDEX_MASK | 0x3UL) ^~~~~~~~~~~~~~~~~ net/core/netmem_priv.h:25:40: note: in expansion of macro 'PP_MAGIC_MASK' return (netmem_get_pp_magic(netmem) & PP_MAGIC_MASK) == PP_SIGNATURE; ^~~~~~~~~~~~~ In function 'netmem_get_pp_magic', inlined from 'netmem_is_pp' at net/core/netmem_priv.h:25:10, inlined from 'napi_pp_put_page' at net/core/skbuff.c:1027:6: GENMASK_INPUT_CHECK_FAIL())) ^~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/bits.h:54:17: note: in expansion of macro 'GENMASK_INPUT_CHECK' ((unsigned int)GENMASK_INPUT_CHECK(h, l, BITS_PER_TYPE(t)) + \ ^~~~~~~~~~~~~~~~~~~ include/linux/bits.h:58:24: note: in expansion of macro 'GENMASK_TYPE' #define GENMASK(h, l) GENMASK_TYPE(unsigned long, h, l) ^~~~~~~~~~~~ include/linux/mm.h:4641:27: note: in expansion of macro 'GENMASK' #define PP_DMA_INDEX_MASK GENMASK(PP_DMA_INDEX_BITS + PP_DMA_INDEX_SHIFT - 1, \ ^~~~~~~ net/core/netmem_priv.h:8:47: note: in expansion of macro 'PP_DMA_INDEX_MASK' return netmem_to_nmdesc(netmem)->pp_magic & ~PP_DMA_INDEX_MASK; ^~~~~~~~~~~~~~~~~ In function 'netmem_is_pp', inlined from 'napi_pp_put_page' at net/core/skbuff.c:1027:6: GENMASK_INPUT_CHECK_FAIL())) ^~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/bits.h:54:17: note: in expansion of macro 'GENMASK_INPUT_CHECK' ((unsigned int)GENMASK_INPUT_CHECK(h, l, BITS_PER_TYPE(t)) + \ ^~~~~~~~~~~~~~~~~~~ include/linux/bits.h:58:24: note: in expansion of macro 'GENMASK_TYPE' #define GENMASK(h, l) GENMASK_TYPE(unsigned long, h, l) ^~~~~~~~~~~~ include/linux/mm.h:4641:27: note: in expansion of macro 'GENMASK' #define PP_DMA_INDEX_MASK GENMASK(PP_DMA_INDEX_BITS + PP_DMA_INDEX_SHIFT - 1, \ ^~~~~~~ include/linux/mm.h:4650:25: note: in expansion of macro 'PP_DMA_INDEX_MASK' #define PP_MAGIC_MASK ~(PP_DMA_INDEX_MASK | 0x3UL) ^~~~~~~~~~~~~~~~~ net/core/netmem_priv.h:25:40: note: in expansion of macro 'PP_MAGIC_MASK' return (netmem_get_pp_magic(netmem) & PP_MAGIC_MASK) == PP_SIGNATURE; ^~~~~~~~~~~~~ In function 'netmem_get_pp_magic', inlined from 'netmem_is_pp' at net/core/netmem_priv.h:25:10, inlined from 'skb_pp_frag_ref' at net/core/skbuff.c:1067:7, inlined from 'skb_try_coalesce' at net/core/skbuff.c:6203:6: GENMASK_INPUT_CHECK_FAIL())) ^~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/bits.h:54:17: note: in expansion of macro 'GENMASK_INPUT_CHECK' ((unsigned int)GENMASK_INPUT_CHECK(h, l, BITS_PER_TYPE(t)) + \ ^~~~~~~~~~~~~~~~~~~ include/linux/bits.h:58:24: note: in expansion of macro 'GENMASK_TYPE' #define GENMASK(h, l) GENMASK_TYPE(unsigned long, h, l) ^~~~~~~~~~~~ include/linux/mm.h:4641:27: note: in expansion of macro 'GENMASK' #define PP_DMA_INDEX_MASK GENMASK(PP_DMA_INDEX_BITS + PP_DMA_INDEX_SHIFT - 1, \ ^~~~~~~ net/core/netmem_priv.h:8:47: note: in expansion of macro 'PP_DMA_INDEX_MASK' return netmem_to_nmdesc(netmem)->pp_magic & ~PP_DMA_INDEX_MASK; ^~~~~~~~~~~~~~~~~ In function 'netmem_is_pp', inlined from 'skb_pp_frag_ref' at net/core/skbuff.c:1067:7, inlined from 'skb_try_coalesce' at net/core/skbuff.c:6203:6: GENMASK_INPUT_CHECK_FAIL())) ^~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/bits.h:54:17: note: in expansion of macro 'GENMASK_INPUT_CHECK' ((unsigned int)GENMASK_INPUT_CHECK(h, l, BITS_PER_TYPE(t)) + \ ^~~~~~~~~~~~~~~~~~~ include/linux/bits.h:58:24: note: in expansion of macro 'GENMASK_TYPE' #define GENMASK(h, l) GENMASK_TYPE(unsigned long, h, l) ^~~~~~~~~~~~ include/linux/mm.h:4641:27: note: in expansion of macro 'GENMASK' #define PP_DMA_INDEX_MASK GENMASK(PP_DMA_INDEX_BITS + PP_DMA_INDEX_SHIFT - 1, \ ^~~~~~~ include/linux/mm.h:4650:25: note: in expansion of macro 'PP_DMA_INDEX_MASK' #define PP_MAGIC_MASK ~(PP_DMA_INDEX_MASK | 0x3UL) ^~~~~~~~~~~~~~~~~ net/core/netmem_priv.h:25:40: note: in expansion of macro 'PP_MAGIC_MASK' return (netmem_get_pp_magic(netmem) & PP_MAGIC_MASK) == PP_SIGNATURE; ^~~~~~~~~~~~~ In function 'netmem_get_pp_magic', inlined from 'netmem_is_pp' at net/core/netmem_priv.h:25:10, inlined from 'skb_pp_frag_ref' at net/core/skbuff.c:1067:7, inlined from 'skb_try_coalesce' at net/core/skbuff.c:6203:6: GENMASK_INPUT_CHECK_FAIL())) ^~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/bits.h:54:17: note: in expansion of macro 'GENMASK_INPUT_CHECK' ((unsigned int)GENMASK_INPUT_CHECK(h, l, BITS_PER_TYPE(t)) + \ ^~~~~~~~~~~~~~~~~~~ include/linux/bits.h:58:24: note: in expansion of macro 'GENMASK_TYPE' #define GENMASK(h, l) GENMASK_TYPE(unsigned long, h, l) ^~~~~~~~~~~~ include/linux/mm.h:4641:27: note: in expansion of macro 'GENMASK' #define PP_DMA_INDEX_MASK GENMASK(PP_DMA_INDEX_BITS + PP_DMA_INDEX_SHIFT - 1, \ ^~~~~~~ net/core/netmem_priv.h:8:47: note: in expansion of macro 'PP_DMA_INDEX_MASK' return netmem_to_nmdesc(netmem)->pp_magic & ~PP_DMA_INDEX_MASK; ^~~~~~~~~~~~~~~~~ In function 'netmem_is_pp', inlined from 'skb_pp_frag_ref' at net/core/skbuff.c:1067:7, inlined from 'skb_try_coalesce' at net/core/skbuff.c:6203:6: GENMASK_INPUT_CHECK_FAIL())) ^~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/bits.h:54:17: note: in expansion of macro 'GENMASK_INPUT_CHECK' ((unsigned int)GENMASK_INPUT_CHECK(h, l, BITS_PER_TYPE(t)) + \ ^~~~~~~~~~~~~~~~~~~ include/linux/bits.h:58:24: note: in expansion of macro 'GENMASK_TYPE' #define GENMASK(h, l) GENMASK_TYPE(unsigned long, h, l) ^~~~~~~~~~~~ include/linux/mm.h:4641:27: note: in expansion of macro 'GENMASK' #define PP_DMA_INDEX_MASK GENMASK(PP_DMA_INDEX_BITS + PP_DMA_INDEX_SHIFT - 1, \ ^~~~~~~ include/linux/mm.h:4650:25: note: in expansion of macro 'PP_DMA_INDEX_MASK' #define PP_MAGIC_MASK ~(PP_DMA_INDEX_MASK | 0x3UL) ^~~~~~~~~~~~~~~~~ net/core/netmem_priv.h:25:40: note: in expansion of macro 'PP_MAGIC_MASK' return (netmem_get_pp_magic(netmem) & PP_MAGIC_MASK) == PP_SIGNATURE; ^~~~~~~~~~~~~ vim +/GENMASK_INPUT_CHECK_FAIL +35 include/linux/bits.h 25 26 #ifndef KBUILD_EXTRA_WARNc 27 #define GENMASK_INPUT_CHECK(h, l, width) 0 28 #else 29 int GENMASK_INPUT_CHECK_FAIL(void) __compiletime_error("Invalid bit numbers"); 30 #define GENMASK_INPUT_CHECK(h, l, width) \ 31 (__builtin_choose_expr(__is_constexpr((l) > (h)), \ 32 sizeof(struct { char low_bit_greater_than_high[-((l) > (h))];}), \ 33 __builtin_constant_p((l) | (h)) && \ 34 ((l) < 0 || (l) > (h) || (h) >= width) && \ > 35 GENMASK_INPUT_CHECK_FAIL())) 36 #endif 37 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
{ "author": "kernel test robot <lkp@intel.com>", "date": "Thu, 22 Jan 2026 09:11:53 +0800", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
Hi, kernel test robot noticed the following build errors: [auto build test ERROR on next-20260120] url: https://github.com/intel-lab-lkp/linux/commits/david-laight-linux-gmail-com/overflow-Reduce-expansion-of-__type_max/20260122-013456 base: next-20260120 patch link: https://lore.kernel.org/r/20260121145731.3623-13-david.laight.linux%40gmail.com patch subject: [PATCH next 12/14] bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h config: arm64-allmodconfig (https://download.01.org/0day-ci/archive/20260122/202601220951.7C4YG7hB-lkp@intel.com/config) compiler: clang version 19.1.7 (https://github.com/llvm/llvm-project cd708029e0b2869e80abe31ddb175f7c35361f90) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260122/202601220951.7C4YG7hB-lkp@intel.com/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 <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202601220951.7C4YG7hB-lkp@intel.com/ All error/warnings (new ones prefixed by >>): In file included from kernel/bounds.c:14: In file included from include/linux/log2.h:12: In file included from include/linux/bitops.h:28: In file included from include/asm-generic/bitops/generic-non-atomic.h:7: In file included from arch/arm64/include/asm/barrier.h:14: 18 | #if ARM64_NCAPS >= ARM64_CB_BIT | ^ arch/arm64/include/asm/alternative-macros.h:16:22: note: expanded from macro 'ARM64_CB_BIT' 16 | #define ARM64_CB_BIT BIT(ARM64_CB_SHIFT) | ^ include/linux/bits.h:94:18: note: expanded from macro 'BIT' 94 | #define BIT(nr) BIT_TYPE(unsigned long, nr) | ^ include/linux/bits.h:88:4: note: expanded from macro 'BIT_TYPE' 88 | ((unsigned int)BIT_INPUT_CHECK(+(nr), BITS_PER_TYPE(type)) + ((type)1 << (nr))) | ^ In file included from kernel/bounds.c:14: In file included from include/linux/log2.h:12: In file included from include/linux/bitops.h:28: In file included from include/asm-generic/bitops/generic-non-atomic.h:7: In file included from arch/arm64/include/asm/barrier.h:14: 18 | #if ARM64_NCAPS >= ARM64_CB_BIT | ^~~~~~~~~~~~ arch/arm64/include/asm/alternative-macros.h:16:22: note: expanded from macro 'ARM64_CB_BIT' 16 | #define ARM64_CB_BIT BIT(ARM64_CB_SHIFT) | ^~~~~~~~~~~~~~~~~~~ include/linux/bits.h:94:18: note: expanded from macro 'BIT' 94 | #define BIT(nr) BIT_TYPE(unsigned long, nr) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/bits.h:88:13: note: expanded from macro 'BIT_TYPE' 88 | ((unsigned int)BIT_INPUT_CHECK(+(nr), BITS_PER_TYPE(type)) + ((type)1 << (nr))) | ~~~~~~~~ ^ 1 warning and 1 error generated. make[3]: *** [scripts/Makefile.build:182: kernel/bounds.s] Error 1 make[3]: Target 'prepare' not remade because of errors. make[2]: *** [Makefile:1330: prepare0] Error 2 make[2]: Target 'prepare' not remade because of errors. make[1]: *** [Makefile:248: __sub-make] Error 2 make[1]: Target 'prepare' not remade because of errors. make: *** [Makefile:248: __sub-make] Error 2 make: Target 'prepare' not remade because of errors. vim +18 arch/arm64/include/asm/alternative-macros.h 4c0bd995d73ed8 Mark Rutland 2022-09-12 17 4c0bd995d73ed8 Mark Rutland 2022-09-12 @18 #if ARM64_NCAPS >= ARM64_CB_BIT 4c0bd995d73ed8 Mark Rutland 2022-09-12 19 #error "cpucaps have overflown ARM64_CB_BIT" 4c0bd995d73ed8 Mark Rutland 2022-09-12 20 #endif 7cda23da52ad79 Will Deacon 2020-06-30 21 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
{ "author": "kernel test robot <lkp@intel.com>", "date": "Thu, 22 Jan 2026 09:23:16 +0800", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
Hi, kernel test robot noticed the following build warnings: [auto build test WARNING on next-20260120] url: https://github.com/intel-lab-lkp/linux/commits/david-laight-linux-gmail-com/overflow-Reduce-expansion-of-__type_max/20260122-013456 base: next-20260120 patch link: https://lore.kernel.org/r/20260121145731.3623-12-david.laight.linux%40gmail.com patch subject: [PATCH next 11/14] bit: Strengthen compile-time tests in GENMASK() and BIT() config: mips-randconfig-r132-20260122 (https://download.01.org/0day-ci/archive/20260122/202601221237.soiAkwkN-lkp@intel.com/config) compiler: mips64-linux-gcc (GCC) 10.5.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260122/202601221237.soiAkwkN-lkp@intel.com/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 <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202601221237.soiAkwkN-lkp@intel.com/ sparse warnings: (new ones prefixed by >>) kernel/kthread.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): -- kernel/reboot.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): -- lib/idr.c: note: in included file (through include/linux/bitmap.h): include/linux/find.h:188:32: sparse: sparse: Variable length array is used. include/linux/find.h:388:46: sparse: sparse: Variable length array is used. include/linux/find.h:69:31: sparse: sparse: Variable length array is used. -- lib/xarray.c: note: in included file (through include/linux/bitmap.h): include/linux/find.h:69:31: sparse: sparse: Variable length array is used. lib/xarray.c: note: in included file: lib/xarray.c: note: in included file (through include/linux/bitmap.h): -- lib/find_bit.c: note: in included file (through include/linux/bitmap.h): include/linux/find.h:69:31: sparse: sparse: Variable length array is used. include/linux/find.h:238:46: sparse: sparse: Variable length array is used. -- lib/bitmap-str.c: note: in included file: include/linux/bitmap.h:488:25: sparse: sparse: Variable length array is used. lib/bitmap-str.c: note: in included file (through include/linux/bitmap.h): include/linux/find.h:69:31: sparse: sparse: Variable length array is used. -- lib/genalloc.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): include/linux/find.h:69:31: sparse: sparse: Variable length array is used. -- mm/oom_kill.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): -- mm/vmscan.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): -- mm/shmem.c: note: in included file (through include/linux/cpumask.h, include/linux/smp.h, arch/mips/include/asm/cpu-type.h, ...): include/linux/bitmap.h:488:25: sparse: sparse: Variable length array is used. -- mm/percpu.c: note: in included file (through include/linux/bitmap.h): include/linux/find.h:409:45: sparse: sparse: Variable length array is used. include/linux/find.h:188:32: sparse: sparse: Variable length array is used. include/linux/find.h:69:31: sparse: sparse: Variable length array is used. mm/percpu.c: note: in included file: include/linux/bitmap.h:488:25: sparse: sparse: Variable length array is used. -- mm/vmalloc.c: note: in included file (through arch/mips/include/asm/page.h, include/linux/shm.h, include/linux/sched.h, ...): include/asm-generic/memory_model.h:30:23: sparse: sparse: unsigned value that used to be signed checked against zero? mm/vmalloc.c:554:21: sparse: signed value source mm/vmalloc.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): include/linux/find.h:69:31: sparse: sparse: Variable length array is used. mm/vmalloc.c: note: in included file (through include/linux/cpumask.h, arch/mips/include/asm/processor.h, arch/mips/include/asm/thread_info.h, ...): include/linux/bitmap.h:488:25: sparse: sparse: Variable length array is used. mm/vmalloc.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): include/linux/find.h:188:32: sparse: sparse: Variable length array is used. -- mm/slub.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): -- mm/hugetlb.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): include/linux/find.h:69:31: sparse: sparse: Variable length array is used. -- mm/huge_memory.c: note: in included file (through include/linux/cpumask.h, arch/mips/include/asm/processor.h, arch/mips/include/asm/thread_info.h, ...): include/linux/bitmap.h:488:25: sparse: sparse: Variable length array is used. -- arch/mips/kernel/cmpxchg.c:61:16: sparse: sparse: Variable length array is used. -- arch/mips/kernel/cpu-probe.c:712:45: sparse: sparse: Variable length array is used. arch/mips/kernel/cpu-probe.c:214:9: sparse: sparse: cast truncates bits from constant value (3fffffffffffe000 becomes ffffe000) arch/mips/kernel/cpu-probe.c:214:9: sparse: sparse: cast truncates bits from constant value (3fffffffffffe000 becomes ffffe000) -- -- net/ethtool/ioctl.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, include/linux/smp.h, ...): include/linux/find.h:69:31: sparse: sparse: Variable length array is used. -- net/ethtool/bitset.c: note: in included file (through include/linux/ethtool.h, include/uapi/linux/ethtool_netlink.h, include/linux/ethtool_netlink.h): -- net/ethtool/linkmodes.c: note: in included file (through include/linux/bitmap.h, include/linux/ethtool.h, include/uapi/linux/ethtool_netlink.h, ...): -- net/ethtool/fec.c: note: in included file (through include/linux/bitmap.h, include/linux/ethtool.h, include/uapi/linux/ethtool_netlink.h, ...): -- drivers/clk/clk-multiplier.c:141:17: sparse: sparse: Variable length array is used. -- drivers/clk/clk-fractional-divider.c:90:17: sparse: sparse: Variable length array is used. drivers/clk/clk-fractional-divider.c:146:25: sparse: sparse: Variable length array is used. drivers/clk/clk-fractional-divider.c:147:25: sparse: sparse: Variable length array is used. drivers/clk/clk-fractional-divider.c:195:25: sparse: sparse: Variable length array is used. drivers/clk/clk-fractional-divider.c:196:25: sparse: sparse: Variable length array is used. drivers/clk/clk-fractional-divider.c:205:17: sparse: sparse: Variable length array is used. drivers/clk/clk-fractional-divider.c:206:17: sparse: sparse: Variable length array is used. -- -- -- drivers/clocksource/ingenic-timer.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): include/linux/find.h:188:32: sparse: sparse: Variable length array is used. -- -- drivers/base/regmap/regcache-rbtree.c: note: in included file (through include/linux/cpumask.h, include/linux/smp.h, arch/mips/include/asm/cpu-type.h, ...): -- drivers/base/regmap/regcache-flat.c: note: in included file: -- drivers/crypto/marvell/octeontx/otx_cptpf_ucode.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): include/linux/find.h:69:31: sparse: sparse: Variable length array is used. drivers/crypto/marvell/octeontx/otx_cptpf_ucode.c: note: in included file (through include/linux/cpumask.h, arch/mips/include/asm/processor.h, arch/mips/include/asm/thread_info.h, ...): include/linux/bitmap.h:488:25: sparse: sparse: Variable length array is used. drivers/crypto/marvell/octeontx/otx_cptpf_ucode.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): drivers/crypto/marvell/octeontx/otx_cptpf_ucode.c: note: in included file (through include/linux/cpumask.h, arch/mips/include/asm/processor.h, arch/mips/include/asm/thread_info.h, ...): -- -- -- drivers/gpio/gpiolib.c: note: in included file (through include/linux/cpumask.h, arch/mips/include/asm/processor.h, arch/mips/include/asm/thread_info.h, ...): drivers/gpio/gpiolib.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): include/linux/find.h:69:31: sparse: sparse: Variable length array is used. include/linux/find.h:388:46: sparse: sparse: Variable length array is used. include/linux/find.h:188:32: sparse: sparse: Variable length array is used. drivers/gpio/gpiolib.c: note: in included file (through include/linux/cpumask.h, arch/mips/include/asm/processor.h, arch/mips/include/asm/thread_info.h, ...): include/linux/bitmap.h:488:25: sparse: sparse: Variable length array is used. -- drivers/gpio/gpio-nomadik.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): include/linux/find.h:69:31: sparse: sparse: Variable length array is used. -- kernel/sched/build_utility.c: note: in included file: kernel/sched/debug.c:624:17: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct sched_domain *[assigned] sd @@ got struct sched_domain [noderef] __rcu *parent @@ kernel/sched/debug.c:624:17: sparse: expected struct sched_domain *[assigned] sd kernel/sched/debug.c:624:17: sparse: got struct sched_domain [noderef] __rcu *parent kernel/sched/debug.c:952:9: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct task_struct *tsk @@ got struct task_struct [noderef] __rcu *curr @@ kernel/sched/debug.c:952:9: sparse: expected struct task_struct *tsk kernel/sched/debug.c:952:9: sparse: got struct task_struct [noderef] __rcu *curr kernel/sched/debug.c:952:9: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct task_struct *tsk @@ got struct task_struct [noderef] __rcu *curr @@ kernel/sched/debug.c:952:9: sparse: expected struct task_struct *tsk kernel/sched/debug.c:952:9: sparse: got struct task_struct [noderef] __rcu *curr kernel/sched/build_utility.c: note: in included file: kernel/sched/topology.c:115:56: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct sched_domain *sd @@ got struct sched_domain [noderef] __rcu *child @@ kernel/sched/topology.c:115:56: sparse: expected struct sched_domain *sd kernel/sched/topology.c:115:56: sparse: got struct sched_domain [noderef] __rcu *child kernel/sched/topology.c:134:60: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct sched_domain *sd @@ got struct sched_domain [noderef] __rcu *parent @@ kernel/sched/topology.c:134:60: sparse: expected struct sched_domain *sd kernel/sched/topology.c:134:60: sparse: got struct sched_domain [noderef] __rcu *parent kernel/sched/topology.c:157:20: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct sched_domain *sd @@ got struct sched_domain [noderef] __rcu *parent @@ kernel/sched/topology.c:157:20: sparse: expected struct sched_domain *sd kernel/sched/topology.c:157:20: sparse: got struct sched_domain [noderef] __rcu *parent kernel/sched/topology.c:468:19: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct perf_domain *pd @@ got struct perf_domain [noderef] __rcu *pd @@ kernel/sched/topology.c:468:19: sparse: expected struct perf_domain *pd kernel/sched/topology.c:468:19: sparse: got struct perf_domain [noderef] __rcu *pd kernel/sched/topology.c:638:49: sparse: sparse: incorrect type in initializer (different address spaces) @@ expected struct sched_domain *parent @@ got struct sched_domain [noderef] __rcu *parent @@ kernel/sched/topology.c:638:49: sparse: expected struct sched_domain *parent kernel/sched/topology.c:638:49: sparse: got struct sched_domain [noderef] __rcu *parent kernel/sched/topology.c:723:50: sparse: sparse: incorrect type in initializer (different address spaces) @@ expected struct sched_domain *parent @@ got struct sched_domain [noderef] __rcu *parent @@ kernel/sched/topology.c:723:50: sparse: expected struct sched_domain *parent kernel/sched/topology.c:723:50: sparse: got struct sched_domain [noderef] __rcu *parent kernel/sched/topology.c:731:55: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct sched_domain [noderef] __rcu *[noderef] __rcu child @@ got struct sched_domain *[assigned] tmp @@ kernel/sched/topology.c:731:55: sparse: expected struct sched_domain [noderef] __rcu *[noderef] __rcu child kernel/sched/topology.c:731:55: sparse: got struct sched_domain *[assigned] tmp kernel/sched/topology.c:744:29: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct sched_domain *[assigned] tmp @@ got struct sched_domain [noderef] __rcu *parent @@ kernel/sched/topology.c:744:29: sparse: expected struct sched_domain *[assigned] tmp kernel/sched/topology.c:744:29: sparse: got struct sched_domain [noderef] __rcu *parent kernel/sched/topology.c:749:20: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct sched_domain *sd @@ got struct sched_domain [noderef] __rcu *parent @@ kernel/sched/topology.c:749:20: sparse: expected struct sched_domain *sd kernel/sched/topology.c:749:20: sparse: got struct sched_domain [noderef] __rcu *parent kernel/sched/topology.c:770:13: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct sched_domain *[assigned] tmp @@ got struct sched_domain [noderef] __rcu *sd @@ kernel/sched/topology.c:770:13: sparse: expected struct sched_domain *[assigned] tmp kernel/sched/topology.c:770:13: sparse: got struct sched_domain [noderef] __rcu *sd kernel/sched/topology.c:932:70: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct sched_domain *sd @@ got struct sched_domain [noderef] __rcu *child @@ kernel/sched/topology.c:932:70: sparse: expected struct sched_domain *sd kernel/sched/topology.c:932:70: sparse: got struct sched_domain [noderef] __rcu *child kernel/sched/topology.c:961:59: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct sched_domain *sd @@ got struct sched_domain [noderef] __rcu *child @@ kernel/sched/topology.c:961:59: sparse: expected struct sched_domain *sd kernel/sched/topology.c:961:59: sparse: got struct sched_domain [noderef] __rcu *child kernel/sched/topology.c:1007:57: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct sched_domain *sd @@ got struct sched_domain [noderef] __rcu *child @@ kernel/sched/topology.c:1007:57: sparse: expected struct sched_domain *sd kernel/sched/topology.c:1007:57: sparse: got struct sched_domain [noderef] __rcu *child kernel/sched/topology.c:1009:25: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct sched_domain *sibling @@ got struct sched_domain [noderef] __rcu *child @@ kernel/sched/topology.c:1009:25: sparse: expected struct sched_domain *sibling kernel/sched/topology.c:1009:25: sparse: got struct sched_domain [noderef] __rcu *child kernel/sched/topology.c:1017:55: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct sched_domain *sd @@ got struct sched_domain [noderef] __rcu *child @@ kernel/sched/topology.c:1017:55: sparse: expected struct sched_domain *sd kernel/sched/topology.c:1017:55: sparse: got struct sched_domain [noderef] __rcu *child kernel/sched/topology.c:1019:25: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct sched_domain *sibling @@ got struct sched_domain [noderef] __rcu *child @@ kernel/sched/topology.c:1019:25: sparse: expected struct sched_domain *sibling kernel/sched/topology.c:1019:25: sparse: got struct sched_domain [noderef] __rcu *child kernel/sched/topology.c:1089:62: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct sched_domain *sd @@ got struct sched_domain [noderef] __rcu *child @@ kernel/sched/topology.c:1089:62: sparse: expected struct sched_domain *sd kernel/sched/topology.c:1089:62: sparse: got struct sched_domain [noderef] __rcu *child kernel/sched/topology.c:1193:40: sparse: sparse: incorrect type in initializer (different address spaces) @@ expected struct sched_domain *child @@ got struct sched_domain [noderef] __rcu *child @@ kernel/sched/topology.c:1193:40: sparse: expected struct sched_domain *child kernel/sched/topology.c:1193:40: sparse: got struct sched_domain [noderef] __rcu *child kernel/sched/topology.c:1331:9: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct sched_domain *[assigned] sd @@ got struct sched_domain [noderef] __rcu *parent @@ kernel/sched/topology.c:1331:9: sparse: expected struct sched_domain *[assigned] sd kernel/sched/topology.c:1331:9: sparse: got struct sched_domain [noderef] __rcu *parent kernel/sched/topology.c:1680:43: sparse: sparse: incorrect type in initializer (different address spaces) @@ expected struct sched_domain [noderef] __rcu *child @@ got struct sched_domain *child @@ kernel/sched/topology.c:1680:43: sparse: expected struct sched_domain [noderef] __rcu *child kernel/sched/topology.c:1680:43: sparse: got struct sched_domain *child kernel/sched/topology.c:2470:31: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct sched_domain [noderef] __rcu *parent @@ got struct sched_domain *sd @@ kernel/sched/topology.c:2470:31: sparse: expected struct sched_domain [noderef] __rcu *parent kernel/sched/topology.c:2470:31: sparse: got struct sched_domain *sd kernel/sched/topology.c:2591:57: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct sched_domain *[assigned] sd @@ got struct sched_domain [noderef] __rcu *parent @@ kernel/sched/topology.c:2591:57: sparse: expected struct sched_domain *[assigned] sd kernel/sched/topology.c:2591:57: sparse: got struct sched_domain [noderef] __rcu *parent kernel/sched/topology.c:2612:56: sparse: sparse: incorrect type in initializer (different address spaces) @@ expected struct sched_domain *child @@ got struct sched_domain [noderef] __rcu *child @@ kernel/sched/topology.c:2612:56: sparse: expected struct sched_domain *child kernel/sched/topology.c:2612:56: sparse: got struct sched_domain [noderef] __rcu *child kernel/sched/topology.c:2611:57: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct sched_domain *[assigned] sd @@ got struct sched_domain [noderef] __rcu *parent @@ kernel/sched/topology.c:2611:57: sparse: expected struct sched_domain *[assigned] sd kernel/sched/topology.c:2611:57: sparse: got struct sched_domain [noderef] __rcu *parent kernel/sched/topology.c:2666:57: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct sched_domain *[assigned] sd @@ got struct sched_domain [noderef] __rcu *parent @@ kernel/sched/topology.c:2666:57: sparse: expected struct sched_domain *[assigned] sd kernel/sched/topology.c:2666:57: sparse: got struct sched_domain [noderef] __rcu *parent kernel/sched/build_utility.c: note: in included file: kernel/sched/build_utility.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, include/linux/smp.h, ...): include/linux/find.h:69:31: sparse: sparse: Variable length array is used. kernel/sched/build_utility.c: note: in included file: kernel/sched/sched.h:2360:25: sparse: sparse: incompatible types in comparison expression (different address spaces): kernel/sched/sched.h:2360:25: sparse: struct task_struct [noderef] __rcu * kernel/sched/sched.h:2360:25: sparse: struct task_struct * -- drivers/clk/ingenic/cgu.c:97:42: sparse: sparse: Variable length array is used. drivers/clk/ingenic/cgu.c:102:27: sparse: sparse: Variable length array is used. drivers/clk/ingenic/cgu.c:224:18: sparse: sparse: Variable length array is used. drivers/clk/ingenic/cgu.c:227:18: sparse: sparse: Variable length array is used. drivers/clk/ingenic/cgu.c:231:26: sparse: sparse: Variable length array is used. drivers/clk/ingenic/cgu.c:345:26: sparse: sparse: Variable length array is used. drivers/clk/ingenic/cgu.c:389:24: sparse: sparse: Variable length array is used. drivers/clk/ingenic/cgu.c:423:31: sparse: sparse: Variable length array is used. drivers/clk/ingenic/cgu.c:553:24: sparse: sparse: Variable length array is used. -- kernel/irq/chip.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): -- kernel/irq/irq_sim.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): include/linux/find.h:69:31: sparse: sparse: Variable length array is used. -- drivers/input/rmi4/rmi_driver.c: note: in included file (through include/linux/bitmap.h): include/linux/find.h:69:31: sparse: sparse: Variable length array is used. drivers/input/rmi4/rmi_driver.c: note: in included file: include/linux/bitmap.h:488:25: sparse: sparse: Variable length array is used. drivers/input/rmi4/rmi_driver.c: note: in included file (through include/linux/bitmap.h): -- -- drivers/mfd/atmel-smc.c:57:32: sparse: sparse: Variable length array is used. drivers/mfd/atmel-smc.c:120:27: sparse: sparse: Variable length array is used. drivers/mfd/atmel-smc.c:159:25: sparse: sparse: Variable length array is used. drivers/mfd/atmel-smc.c:198:25: sparse: sparse: Variable length array is used. drivers/mfd/atmel-smc.c:236:25: sparse: sparse: Variable length array is used. -- -- drivers/mtd/nand/bbt.c:111:38: sparse: sparse: Variable length array is used. drivers/mtd/nand/bbt.c:116:20: sparse: sparse: Variable length array is used. drivers/mtd/nand/bbt.c:122:28: sparse: sparse: Variable length array is used. -- drivers/opp/cpu.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): include/linux/find.h:69:31: sparse: sparse: Variable length array is used. -- drivers/pci/pci.c:1157:36: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted pci_power_t [usertype] current_state @@ got int @@ drivers/pci/pci.c:1157:36: sparse: expected restricted pci_power_t [usertype] current_state drivers/pci/pci.c:1157:36: sparse: got int drivers/pci/pci.c:1336:15: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted pci_power_t [assigned] [usertype] state @@ got int @@ drivers/pci/pci.c:1336:15: sparse: expected restricted pci_power_t [assigned] [usertype] state drivers/pci/pci.c:1336:15: sparse: got int drivers/pci/pci.c:1338:50: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:1338:69: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:1391:28: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted pci_power_t [usertype] current_state @@ got int @@ drivers/pci/pci.c:1391:28: sparse: expected restricted pci_power_t [usertype] current_state drivers/pci/pci.c:1391:28: sparse: got int drivers/pci/pci.c:1481:16: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:1481:35: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:1481:52: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:1481:70: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:1506:15: sparse: sparse: invalid assignment: |= drivers/pci/pci.c:1506:15: sparse: left side has type unsigned short drivers/pci/pci.c:1506:15: sparse: right side has type restricted pci_power_t drivers/pci/pci.c:1518:28: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted pci_power_t [usertype] current_state @@ got int @@ drivers/pci/pci.c:1518:28: sparse: expected restricted pci_power_t [usertype] current_state drivers/pci/pci.c:1518:28: sparse: got int drivers/pci/pci.c:1535:13: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:1535:21: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:1537:18: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:1537:26: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:1560:13: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:1560:22: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:1865:38: sparse: sparse: array of flexible structures drivers/pci/pci.c:2343:44: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:2662:60: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:2663:30: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:2834:20: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:2834:38: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:2857:49: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:2857:67: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:4486:13: sparse: sparse: invalid assignment: |= drivers/pci/pci.c:4486:13: sparse: left side has type unsigned short drivers/pci/pci.c:4486:13: sparse: right side has type restricted pci_power_t drivers/pci/pci.c:4491:13: sparse: sparse: invalid assignment: |= drivers/pci/pci.c:4491:13: sparse: left side has type unsigned short drivers/pci/pci.c:4491:13: sparse: right side has type restricted pci_power_t drivers/pci/pci.c:1112:24: sparse: sparse: incorrect type in return expression (different base types) @@ expected int @@ got restricted pci_power_t [usertype] @@ drivers/pci/pci.c:1112:24: sparse: expected int drivers/pci/pci.c:1112:24: sparse: got restricted pci_power_t [usertype] drivers/pci/pci.c:1112:24: sparse: sparse: incorrect type in return expression (different base types) @@ expected int @@ got restricted pci_power_t [usertype] @@ drivers/pci/pci.c:1112:24: sparse: expected int drivers/pci/pci.c:1112:24: sparse: got restricted pci_power_t [usertype] drivers/pci/pci.c: note: in included file (through include/linux/cpumask.h, arch/mips/include/asm/processor.h, arch/mips/include/asm/thread_info.h, ...): include/linux/bitmap.h:488:25: sparse: sparse: Variable length array is used. -- drivers/perf/xgene_pmu.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): include/linux/find.h:388:46: sparse: sparse: Variable length array is used. include/linux/find.h:69:31: sparse: sparse: Variable length array is used. -- -- -- drivers/mtd/nand/raw/nand_macronix.c: note: in included file (through include/linux/cpumask.h, arch/mips/include/asm/processor.h, arch/mips/include/asm/thread_info.h, ...): include/linux/bitmap.h:488:25: sparse: sparse: Variable length array is used. -- drivers/clk/spacemit/ccu_mix.c:193:16: sparse: sparse: Variable length array is used. -- -- -- drivers/clk/sprd/pll.c:116:13: sparse: sparse: Variable length array is used. drivers/clk/sprd/pll.c:120:34: sparse: sparse: Variable length array is used. drivers/clk/sprd/pll.c:121:31: sparse: sparse: Variable length array is used. drivers/clk/sprd/pll.c:124:14: sparse: sparse: Variable length array is used. drivers/clk/sprd/pll.c:125:32: sparse: sparse: Variable length array is used. drivers/clk/sprd/pll.c:127:24: sparse: sparse: Variable length array is used. drivers/clk/sprd/pll.c:128:21: sparse: sparse: Variable length array is used. drivers/clk/sprd/pll.c:129:32: sparse: sparse: Variable length array is used. drivers/clk/sprd/pll.c:131:24: sparse: sparse: Variable length array is used. drivers/clk/sprd/pll.c:164:16: sparse: sparse: Variable length array is used. drivers/clk/sprd/pll.c:170:16: sparse: sparse: Variable length array is used. drivers/clk/sprd/pll.c:181:16: sparse: sparse: Variable length array is used. drivers/clk/sprd/pll.c:186:16: sparse: sparse: Variable length array is used. drivers/clk/sprd/pll.c:192:16: sparse: sparse: Variable length array is used. drivers/clk/sprd/pll.c:198:16: sparse: sparse: Variable length array is used. drivers/clk/sprd/pll.c:210:16: sparse: sparse: Variable length array is used. -- -- drivers/pinctrl/renesas/core.c:942:34: sparse: sparse: Variable length array is used. drivers/pinctrl/renesas/core.c:1241:34: sparse: sparse: Variable length array is used. -- drivers/pinctrl/renesas/pinctrl.c:527:17: sparse: sparse: Variable length array is used. -- drivers/pci/controller/pcie-xilinx-dma-pl.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): include/linux/find.h:69:31: sparse: sparse: Variable length array is used. drivers/pci/controller/pcie-xilinx-dma-pl.c: note: in included file (through include/linux/cpumask.h, arch/mips/include/asm/processor.h, arch/mips/include/asm/thread_info.h, ...): include/linux/bitmap.h:488:25: sparse: sparse: Variable length array is used. -- drivers/pci/controller/dwc/pcie-designware-host.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, include/linux/smp.h, ...): include/linux/find.h:69:31: sparse: sparse: Variable length array is used. drivers/pci/controller/dwc/pcie-designware-host.c: note: in included file (through include/linux/cpumask.h, include/linux/smp.h, arch/mips/include/asm/cpu-type.h, ...): include/linux/bitmap.h:488:25: sparse: sparse: Variable length array is used. vim +209 include/linux/find.h c56f97c5c71f17 include/linux/find.h Yury Norov [NVIDIA] 2025-06-19 48 19de85ef574c3a include/asm-generic/bitops/find.h Akinobu Mita 2011-05-26 49 #ifndef find_next_bit d852a6afd91fc9 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 50 /** d852a6afd91fc9 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 51 * find_next_bit - find the next set bit in a memory region d852a6afd91fc9 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 52 * @addr: The address to base the search on d852a6afd91fc9 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 53 * @size: The bitmap size in bits 6d7131bd52b3e0 include/linux/find.h Anna-Maria Behnsen 2022-04-11 54 * @offset: The bitnumber to start searching at ec778edf97dcaa include/asm-generic/bitops/find.h Cody P Schafer 2013-11-12 55 * ec778edf97dcaa include/asm-generic/bitops/find.h Cody P Schafer 2013-11-12 56 * Returns the bit number for the next set bit ec778edf97dcaa include/asm-generic/bitops/find.h Cody P Schafer 2013-11-12 57 * If no bits are set, returns @size. d852a6afd91fc9 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 58 */ fda1dd3c54ef3c include/linux/find.h Yury Norov 2024-07-18 59 static __always_inline 5c88af59f9abc2 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 60 unsigned long find_next_bit(const unsigned long *addr, unsigned long size, 5c88af59f9abc2 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 61 unsigned long offset) 5c88af59f9abc2 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 62 { 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 63 if (small_const_nbits(size)) { 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 64 unsigned long val; 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 65 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 66 if (unlikely(offset >= size)) 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 67 return size; 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 68 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 @69 val = *addr & GENMASK(size - 1, offset); 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 70 return val ? __ffs(val) : size; 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 71 } 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 72 e79864f3164c57 include/linux/find.h Yury Norov 2022-09-14 73 return _find_next_bit(addr, size, offset); 5c88af59f9abc2 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 74 } 19de85ef574c3a include/asm-generic/bitops/find.h Akinobu Mita 2011-05-26 75 #endif c7f612cdf091de include/asm-generic/bitops/find.h Akinobu Mita 2006-03-26 76 0ade34c37012ea include/asm-generic/bitops/find.h Clement Courbet 2018-02-06 77 #ifndef find_next_and_bit 0ade34c37012ea include/asm-generic/bitops/find.h Clement Courbet 2018-02-06 78 /** 0ade34c37012ea include/asm-generic/bitops/find.h Clement Courbet 2018-02-06 79 * find_next_and_bit - find the next set bit in both memory regions 0ade34c37012ea include/asm-generic/bitops/find.h Clement Courbet 2018-02-06 80 * @addr1: The first address to base the search on 0ade34c37012ea include/asm-generic/bitops/find.h Clement Courbet 2018-02-06 81 * @addr2: The second address to base the search on 0ade34c37012ea include/asm-generic/bitops/find.h Clement Courbet 2018-02-06 82 * @size: The bitmap size in bits 6d7131bd52b3e0 include/linux/find.h Anna-Maria Behnsen 2022-04-11 83 * @offset: The bitnumber to start searching at 0ade34c37012ea include/asm-generic/bitops/find.h Clement Courbet 2018-02-06 84 * 0ade34c37012ea include/asm-generic/bitops/find.h Clement Courbet 2018-02-06 85 * Returns the bit number for the next set bit 0ade34c37012ea include/asm-generic/bitops/find.h Clement Courbet 2018-02-06 86 * If no bits are set, returns @size. 0ade34c37012ea include/asm-generic/bitops/find.h Clement Courbet 2018-02-06 87 */ fda1dd3c54ef3c include/linux/find.h Yury Norov 2024-07-18 88 static __always_inline 5c88af59f9abc2 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 89 unsigned long find_next_and_bit(const unsigned long *addr1, 0ade34c37012ea include/asm-generic/bitops/find.h Clement Courbet 2018-02-06 90 const unsigned long *addr2, unsigned long size, 5c88af59f9abc2 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 91 unsigned long offset) 5c88af59f9abc2 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 92 { 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 93 if (small_const_nbits(size)) { 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 94 unsigned long val; 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 95 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 96 if (unlikely(offset >= size)) 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 97 return size; 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 98 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 99 val = *addr1 & *addr2 & GENMASK(size - 1, offset); 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 100 return val ? __ffs(val) : size; 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 101 } 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 102 e79864f3164c57 include/linux/find.h Yury Norov 2022-09-14 103 return _find_next_and_bit(addr1, addr2, size, offset); 5c88af59f9abc2 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 104 } 0ade34c37012ea include/asm-generic/bitops/find.h Clement Courbet 2018-02-06 105 #endif 0ade34c37012ea include/asm-generic/bitops/find.h Clement Courbet 2018-02-06 106 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 107 #ifndef find_next_andnot_bit 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 108 /** 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 109 * find_next_andnot_bit - find the next set bit in *addr1 excluding all the bits 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 110 * in *addr2 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 111 * @addr1: The first address to base the search on 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 112 * @addr2: The second address to base the search on 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 113 * @size: The bitmap size in bits 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 114 * @offset: The bitnumber to start searching at 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 115 * 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 116 * Returns the bit number for the next set bit 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 117 * If no bits are set, returns @size. 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 118 */ fda1dd3c54ef3c include/linux/find.h Yury Norov 2024-07-18 119 static __always_inline 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 120 unsigned long find_next_andnot_bit(const unsigned long *addr1, 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 121 const unsigned long *addr2, unsigned long size, 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 122 unsigned long offset) 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 123 { 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 124 if (small_const_nbits(size)) { 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 125 unsigned long val; 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 126 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 127 if (unlikely(offset >= size)) 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 128 return size; 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 129 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 130 val = *addr1 & ~*addr2 & GENMASK(size - 1, offset); 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 131 return val ? __ffs(val) : size; 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 132 } 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 133 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 134 return _find_next_andnot_bit(addr1, addr2, size, offset); 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 135 } 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 136 #endif 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 137 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 138 #ifndef find_next_or_bit 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 139 /** 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 140 * find_next_or_bit - find the next set bit in either memory regions 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 141 * @addr1: The first address to base the search on 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 142 * @addr2: The second address to base the search on 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 143 * @size: The bitmap size in bits 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 144 * @offset: The bitnumber to start searching at 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 145 * 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 146 * Returns the bit number for the next set bit 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 147 * If no bits are set, returns @size. 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 148 */ fda1dd3c54ef3c include/linux/find.h Yury Norov 2024-07-18 149 static __always_inline 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 150 unsigned long find_next_or_bit(const unsigned long *addr1, 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 151 const unsigned long *addr2, unsigned long size, 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 152 unsigned long offset) 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 153 { 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 154 if (small_const_nbits(size)) { 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 155 unsigned long val; 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 156 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 157 if (unlikely(offset >= size)) 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 158 return size; 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 159 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 160 val = (*addr1 | *addr2) & GENMASK(size - 1, offset); 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 161 return val ? __ffs(val) : size; 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 162 } 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 163 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 164 return _find_next_or_bit(addr1, addr2, size, offset); 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 165 } 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 166 #endif 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 167 19de85ef574c3a include/asm-generic/bitops/find.h Akinobu Mita 2011-05-26 168 #ifndef find_next_zero_bit d852a6afd91fc9 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 169 /** d852a6afd91fc9 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 170 * find_next_zero_bit - find the next cleared bit in a memory region d852a6afd91fc9 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 171 * @addr: The address to base the search on d852a6afd91fc9 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 172 * @size: The bitmap size in bits 6d7131bd52b3e0 include/linux/find.h Anna-Maria Behnsen 2022-04-11 173 * @offset: The bitnumber to start searching at ec778edf97dcaa include/asm-generic/bitops/find.h Cody P Schafer 2013-11-12 174 * ec778edf97dcaa include/asm-generic/bitops/find.h Cody P Schafer 2013-11-12 175 * Returns the bit number of the next zero bit ec778edf97dcaa include/asm-generic/bitops/find.h Cody P Schafer 2013-11-12 176 * If no bits are zero, returns @size. d852a6afd91fc9 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 177 */ fda1dd3c54ef3c include/linux/find.h Yury Norov 2024-07-18 178 static __always_inline 5c88af59f9abc2 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 179 unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size, 5c88af59f9abc2 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 180 unsigned long offset) 5c88af59f9abc2 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 181 { 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 182 if (small_const_nbits(size)) { 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 183 unsigned long val; 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 184 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 185 if (unlikely(offset >= size)) 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 186 return size; 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 187 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 188 val = *addr | ~GENMASK(size - 1, offset); 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 189 return val == ~0UL ? size : ffz(val); 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 190 } 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 191 e79864f3164c57 include/linux/find.h Yury Norov 2022-09-14 192 return _find_next_zero_bit(addr, size, offset); 5c88af59f9abc2 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 193 } 19de85ef574c3a include/asm-generic/bitops/find.h Akinobu Mita 2011-05-26 194 #endif c7f612cdf091de include/asm-generic/bitops/find.h Akinobu Mita 2006-03-26 195 b7ec62d7ee0f0b include/asm-generic/bitops/find.h Yury Norov 2021-08-14 196 #ifndef find_first_bit 708ff2a0097b02 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 197 /** 708ff2a0097b02 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 198 * find_first_bit - find the first set bit in a memory region 708ff2a0097b02 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 199 * @addr: The address to start the search at ec778edf97dcaa include/asm-generic/bitops/find.h Cody P Schafer 2013-11-12 200 * @size: The maximum number of bits to search 708ff2a0097b02 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 201 * 708ff2a0097b02 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 202 * Returns the bit number of the first set bit. ec778edf97dcaa include/asm-generic/bitops/find.h Cody P Schafer 2013-11-12 203 * If no bits are set, returns @size. 708ff2a0097b02 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 204 */ fda1dd3c54ef3c include/linux/find.h Yury Norov 2024-07-18 205 static __always_inline 2cc7b6a44ac21d include/asm-generic/bitops/find.h Yury Norov 2021-05-06 206 unsigned long find_first_bit(const unsigned long *addr, unsigned long size) 2cc7b6a44ac21d include/asm-generic/bitops/find.h Yury Norov 2021-05-06 207 { 2cc7b6a44ac21d include/asm-generic/bitops/find.h Yury Norov 2021-05-06 208 if (small_const_nbits(size)) { 2cc7b6a44ac21d include/asm-generic/bitops/find.h Yury Norov 2021-05-06 @209 unsigned long val = *addr & GENMASK(size - 1, 0); 2cc7b6a44ac21d include/asm-generic/bitops/find.h Yury Norov 2021-05-06 210 2cc7b6a44ac21d include/asm-generic/bitops/find.h Yury Norov 2021-05-06 211 return val ? __ffs(val) : size; 2cc7b6a44ac21d include/asm-generic/bitops/find.h Yury Norov 2021-05-06 212 } 2cc7b6a44ac21d include/asm-generic/bitops/find.h Yury Norov 2021-05-06 213 2cc7b6a44ac21d include/asm-generic/bitops/find.h Yury Norov 2021-05-06 214 return _find_first_bit(addr, size); 2cc7b6a44ac21d include/asm-generic/bitops/find.h Yury Norov 2021-05-06 215 } b7ec62d7ee0f0b include/asm-generic/bitops/find.h Yury Norov 2021-08-14 216 #endif 708ff2a0097b02 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 217 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
{ "author": "kernel test robot <lkp@intel.com>", "date": "Thu, 22 Jan 2026 12:41:22 +0800", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Wed, Jan 21, 2026 at 07:24:51PM +0000, David Laight wrote: The #ifndef in vdso/bits.h is not much better IMO. Given that there a multiple nicer options why not use on of those? That is a bug. The vdso code should only include the vdso/ namespace. Right now the inclusions are all over the place. I'd like to clean that up at some point. I don't understand "code version specific". There are various issues with including normal kernel headers from the vDSO. Symbols defined in terms of kconfig options, like BITS_PER_LONG using CONFIG_64BIT are wrong in a compat vDSO.
{ "author": "Thomas =?utf-8?Q?Wei=C3=9Fschuh?= <thomas.weissschuh@linutronix.de>", "date": "Thu, 22 Jan 2026 08:39:42 +0100", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Thu, 22 Jan 2026 09:11:53 +0800 kernel test robot <lkp@intel.com> wrote: ... This might be a real bug. The bit of mm.h is: #define PP_DMA_INDEX_SHIFT (1 + __fls(PP_SIGNATURE - POISON_POINTER_DELTA)) #if POISON_POINTER_DELTA > 0 /* PP_SIGNATURE includes POISON_POINTER_DELTA, so limit the size of the DMA * index to not overlap with that if set */ #define PP_DMA_INDEX_BITS MIN(32, __ffs(POISON_POINTER_DELTA) - PP_DMA_INDEX_SHIFT) #else /* Use the lowest bit of PAGE_OFFSET if there's at least 8 bits available; see above */ #define PP_DMA_INDEX_MIN_OFFSET (1 << (PP_DMA_INDEX_SHIFT + 8)) #define PP_DMA_INDEX_BITS ((__builtin_constant_p(PAGE_OFFSET) && \ PAGE_OFFSET >= PP_DMA_INDEX_MIN_OFFSET && \ !(PAGE_OFFSET & (PP_DMA_INDEX_MIN_OFFSET - 1))) ? \ MIN(32, __ffs(PAGE_OFFSET) - PP_DMA_INDEX_SHIFT) : 0) #endif #define PP_DMA_INDEX_MASK GENMASK(PP_DMA_INDEX_BITS + PP_DMA_INDEX_SHIFT - 1, \ PP_DMA_INDEX_SHIFT) I've no idea what the values are, but the 'hi' bit number must exceed that of 'long'. The __ffs() probably stop it being an 'integer constant expression' making it just a 'compile time constant' - which I added a test for. David
{ "author": "David Laight <david.laight.linux@gmail.com>", "date": "Thu, 22 Jan 2026 10:25:54 +0000", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Thu, 22 Jan 2026 09:23:16 +0800 kernel test robot <lkp@intel.com> wrote: ... Unless I change BIT() back I'll change that to a static_assert(). David
{ "author": "David Laight <david.laight.linux@gmail.com>", "date": "Thu, 22 Jan 2026 10:30:29 +0000", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Thu, 22 Jan 2026 12:41:22 +0800 kernel test robot <lkp@intel.com> wrote: Can we stop sparse complaining about sizeof(VLA) ? David
{ "author": "David Laight <david.laight.linux@gmail.com>", "date": "Thu, 22 Jan 2026 10:33:37 +0000", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Thu, Jan 22, 2026 at 10:33:37AM +0000, David Laight wrote: First of all, the LKP should install the fork of sparse by Al Viro. That will fix tons of warnings that are related to modules and speed up the process itself. -- With Best Regards, Andy Shevchenko
{ "author": "Andy Shevchenko <andriy.shevchenko@linux.intel.com>", "date": "Thu, 22 Jan 2026 16:26:44 +0200", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Thu, 22 Jan 2026 16:26:44 +0200 Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote: The problem I have is I want to generate a compile time error inside: __builtin_choose_expr(__is_constexpr(x), x && error_a(), statically_true(y) && error_b()); Neither static_assert() nor a negative bitfield can be used in error_a() because they are errors when x isn't isn't a 'constexpr', There is less of a problem for error_b() it can contain a function call, but can't contain {( ...)}. One of the compiler complained about sizeof (char [-!!(expr)]) as well. I'm not sure of anything else that can be use to get an error. I could use 0 >> -1 but that is only a warning, at least the error message is related to the bug. Any other ideas? David
{ "author": "David Laight <david.laight.linux@gmail.com>", "date": "Thu, 22 Jan 2026 14:55:56 +0000", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Thu, 22 Jan 2026 10:25:54 +0000 David Laight <david.laight.linux@gmail.com> wrote: I've managed to do an s390 cross build. It is all quite obvious really. For s390 PAGE_OFFSET is usually zero (I think kernel and user mappings are separate?). This make PP_DMA_INDEX_BITS 0. PP_SIGNATURE is 64 - so PP_DMA_INDEX_SHIFT is 7. So it is doing GENMASK(6, 7) and, I think, expecting to get zero. But that is taken a mistyped GENMASK(7, 6) and treated as an error. If I rewrite __fls() and __ffs() to return 'integer constant expressions' when the input is one I think it would always have failed. A comment a few lines higher suggests that the code expects the mask to be zero in this case - and handles it properly. David
{ "author": "David Laight <david.laight.linux@gmail.com>", "date": "Thu, 22 Jan 2026 20:10:20 +0000", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Thu, Jan 22, 2026 at 10:33:37AM +0000, David Laight wrote: Got it, we will avoid the direct report this 'sparse: Variable length array is used' warning.
{ "author": "Philip Li <philip.li@intel.com>", "date": "Fri, 23 Jan 2026 09:24:50 +0800", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Thu, Jan 22, 2026 at 04:26:44PM +0200, Andy Shevchenko wrote: Thanks Andy, i will switch to the repo from Al Viro for sparse.
{ "author": "Philip Li <philip.li@intel.com>", "date": "Fri, 23 Jan 2026 09:25:36 +0800", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
Adding the relevant parties to the discussion: +To: Al Viro +To: Chris Li On 23/01/2026 at 02:25, Philip Li wrote: Al Viro's fork just adds 8 commit on top of the upstream sparse repo. Wouldn't it be possible to just merge those? That would be much less confusing. Yours sincerely, Vincent Mailhol
{ "author": "Vincent Mailhol <mailhol@kernel.org>", "date": "Fri, 23 Jan 2026 09:01:04 +0100", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Fri, Jan 23, 2026 at 09:01:04AM +0100, Vincent Mailhol wrote: Ideally yes, but you also should kick the distro's asses to update it, and the sparse should bump its version... Seems Al become a sparse maintainer de facto :-) -- With Best Regards, Andy Shevchenko
{ "author": "Andy Shevchenko <andriy.shevchenko@linux.intel.com>", "date": "Fri, 23 Jan 2026 10:11:19 +0200", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Fri, Jan 23, 2026 at 10:11:19AM +0200, Andy Shevchenko wrote: Huh? What happened to Chris? FWIW, I do have some followups to that series sitting locally; need to get that finished (mostly for proper __VA_OPT__ handling; that got stalled on the lovely corner cases where the interplay with side effects of macro expansion is really nasty - gcc and clang do not agree and gcc is arguably buggy) and posted. I've done quite a bit of sparse work over the years, but I would rather prefer somebody else as overall maintainer, TYVM...
{ "author": "Al Viro <viro@zeniv.linux.org.uk>", "date": "Fri, 23 Jan 2026 08:20:27 +0000", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Fri, Jan 23, 2026 at 08:20:27AM +0000, Al Viro wrote: I don't know, but upstream sparse haven't applied any solution for MODULE*("FOO") stuff, nor reaction on my ping in that discussion (I did it like week or so ago). Thanks for doing all this! -- With Best Regards, Andy Shevchenko
{ "author": "Andy Shevchenko <andriy.shevchenko@linux.intel.com>", "date": "Fri, 23 Jan 2026 10:24:01 +0200", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On 23/01/2026 at 09:24, Andy Shevchenko wrote: After the project hiatus, I can imagine that there is some confusion :) But Chris is back in his role of maintainer since September 2025. See: - https://lore.kernel.org/linux-sparse/CACePvbXDO1ZybDu3RaFhED9D-9gC6LTMpWrxoh5xD+ZO5SLdzA@mail.gmail.com/ - https://git.kernel.org/pub/scm/devel/sparse/sparse.git/commit/?id=67f0a03cee4637e495151c48a02be642a158cbbb I am out of context here, but were the correct people CCed? Yours sincerely, Vincent Mailhol
{ "author": "Vincent Mailhol <mailhol@kernel.org>", "date": "Fri, 23 Jan 2026 09:32:39 +0100", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Fri, Jan 23, 2026 at 09:32:39AM +0100, Vincent Mailhol wrote: ... My ping: https://lore.kernel.org/all/aV9vo7_turBr84bs@black.igk.intel.com/ But now I realised that there was another version of the series, and Chris seems active there. https://lore.kernel.org/all/CACePvbU5Pqo=bw_j8arOq16o1JBOSwPtuMZBVozy4FV7YsSLGw@mail.gmail.com/ I dunno. -- With Best Regards, Andy Shevchenko
{ "author": "Andy Shevchenko <andriy.shevchenko@linux.intel.com>", "date": "Fri, 23 Jan 2026 10:46:37 +0200", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Wed, Jan 21, 2026 at 02:57:22PM +0000, david.laight.linux@gmail.com wrote: Thanks David, Other than the motivation above, I appreciate that this removes two #ifdefs, improving readability (subjective) and compile coverage (objective) of this code. As an aside: I'm Not sure what your merge plan is for this patchset, and only it and the cover letter hit my inbox, so I'm missing context. But from a Networking PoV it seems that it could be sent as a stand-alone patch to the iwl tree. Regardless, feel free to add: Reviewed-by: Simon Horman <horms@kernel.org> ...
{ "author": "Simon Horman <horms@kernel.org>", "date": "Fri, 23 Jan 2026 15:44:25 +0000", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Wed, Jan 21, 2026 at 02:57:18PM +0000, david.laight.linux@gmail.com wrote: Thanks! Reviewed-by: Yury Norov <ynorov@nvidia.com>
{ "author": "Yury Norov <ynorov@nvidia.com>", "date": "Mon, 2 Feb 2026 11:45:28 -0500", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Wed, Jan 21, 2026 at 02:57:19PM +0000, david.laight.linux@gmail.com wrote: Honestly I don't understand this. AFAIU, you've outlined a list of compiler warnings that slow the compilation down, and you group them under 'W=c' option. What is the use case for it outside of your series. I think, a typical user would find more value in an option that enables some warnings but doesn't sacrifices performance. Can you consider flipping the 'W=c' behavior? Can you please explicitly mention warnings included in W=c vs W=1? Can you report compilation time for W=0, W=1 and W=c? What if one needs to enable fast/slow warnings from 2nd or 3rd level? Would W=2c or W=3c work in this case? What does this 'c' stands for? Thanks, Yury
{ "author": "Yury Norov <ynorov@nvidia.com>", "date": "Mon, 2 Feb 2026 13:33:22 -0500", "thread_id": "aYDUqBEnevBJLU53@yury.mbox.gz" }
lkml
[PATCH] staging: sm750fb: rename Bpp to bpp
Rename the Bpp parameter to bpp to avoid CamelCase, as reported by checkpatch.pl. Signed-off-by: yehudis9982 <y0533159982@gmail.com> --- drivers/staging/sm750fb/sm750_accel.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/staging/sm750fb/sm750_accel.c b/drivers/staging/sm750fb/sm750_accel.c index 046b9282b..866b12c2a 100644 --- a/drivers/staging/sm750fb/sm750_accel.c +++ b/drivers/staging/sm750fb/sm750_accel.c @@ -85,7 +85,7 @@ void sm750_hw_set2dformat(struct lynx_accel *accel, int fmt) } int sm750_hw_fillrect(struct lynx_accel *accel, - u32 base, u32 pitch, u32 Bpp, + u32 base, u32 pitch, u32 bpp, u32 x, u32 y, u32 width, u32 height, u32 color, u32 rop) { @@ -102,14 +102,14 @@ int sm750_hw_fillrect(struct lynx_accel *accel, write_dpr(accel, DE_WINDOW_DESTINATION_BASE, base); /* dpr40 */ write_dpr(accel, DE_PITCH, - ((pitch / Bpp << DE_PITCH_DESTINATION_SHIFT) & + ((pitch / bpp << DE_PITCH_DESTINATION_SHIFT) & DE_PITCH_DESTINATION_MASK) | - (pitch / Bpp & DE_PITCH_SOURCE_MASK)); /* dpr10 */ + (pitch / bpp & DE_PITCH_SOURCE_MASK)); /* dpr10 */ write_dpr(accel, DE_WINDOW_WIDTH, - ((pitch / Bpp << DE_WINDOW_WIDTH_DST_SHIFT) & + ((pitch / bpp << DE_WINDOW_WIDTH_DST_SHIFT) & DE_WINDOW_WIDTH_DST_MASK) | - (pitch / Bpp & DE_WINDOW_WIDTH_SRC_MASK)); /* dpr44 */ + (pitch / bpp & DE_WINDOW_WIDTH_SRC_MASK)); /* dpr44 */ write_dpr(accel, DE_FOREGROUND, color); /* DPR14 */ @@ -138,7 +138,7 @@ int sm750_hw_fillrect(struct lynx_accel *accel, * @sy: Starting y coordinate of source surface * @dBase: Address of destination: offset in frame buffer * @dPitch: Pitch value of destination surface in BYTE - * @Bpp: Color depth of destination surface + * @bpp: Color depth of destination surface * @dx: Starting x coordinate of destination surface * @dy: Starting y coordinate of destination surface * @width: width of rectangle in pixel value @@ -149,7 +149,7 @@ int sm750_hw_copyarea(struct lynx_accel *accel, unsigned int sBase, unsigned int sPitch, unsigned int sx, unsigned int sy, unsigned int dBase, unsigned int dPitch, - unsigned int Bpp, unsigned int dx, unsigned int dy, + unsigned int bpp, unsigned int dx, unsigned int dy, unsigned int width, unsigned int height, unsigned int rop2) { @@ -249,9 +249,9 @@ int sm750_hw_copyarea(struct lynx_accel *accel, * pixel values. Need Byte to pixel conversion. */ write_dpr(accel, DE_PITCH, - ((dPitch / Bpp << DE_PITCH_DESTINATION_SHIFT) & + ((dPitch / bpp << DE_PITCH_DESTINATION_SHIFT) & DE_PITCH_DESTINATION_MASK) | - (sPitch / Bpp & DE_PITCH_SOURCE_MASK)); /* dpr10 */ + (sPitch / bpp & DE_PITCH_SOURCE_MASK)); /* dpr10 */ /* * Screen Window width in Pixels. @@ -259,9 +259,9 @@ int sm750_hw_copyarea(struct lynx_accel *accel, * for a given point. */ write_dpr(accel, DE_WINDOW_WIDTH, - ((dPitch / Bpp << DE_WINDOW_WIDTH_DST_SHIFT) & + ((dPitch / bpp << DE_WINDOW_WIDTH_DST_SHIFT) & DE_WINDOW_WIDTH_DST_MASK) | - (sPitch / Bpp & DE_WINDOW_WIDTH_SRC_MASK)); /* dpr3c */ + (sPitch / bpp & DE_WINDOW_WIDTH_SRC_MASK)); /* dpr3c */ if (accel->de_wait() != 0) return -1; -- 2.43.0
On Mon, Feb 02, 2026 at 04:54:13PM +0200, yehudis9982 wrote: What does "bpp" stand for? Perhaps spell it out further? thanks, greg k-h
{ "author": "Greg KH <gregkh@linuxfoundation.org>", "date": "Mon, 2 Feb 2026 16:01:17 +0100", "thread_id": "20260202145413.132435-1-y0533159982@gmail.com.mbox.gz" }
lkml
[PATCH] staging: sm750fb: rename Bpp to bpp
Rename the Bpp parameter to bpp to avoid CamelCase, as reported by checkpatch.pl. Signed-off-by: yehudis9982 <y0533159982@gmail.com> --- drivers/staging/sm750fb/sm750_accel.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/staging/sm750fb/sm750_accel.c b/drivers/staging/sm750fb/sm750_accel.c index 046b9282b..866b12c2a 100644 --- a/drivers/staging/sm750fb/sm750_accel.c +++ b/drivers/staging/sm750fb/sm750_accel.c @@ -85,7 +85,7 @@ void sm750_hw_set2dformat(struct lynx_accel *accel, int fmt) } int sm750_hw_fillrect(struct lynx_accel *accel, - u32 base, u32 pitch, u32 Bpp, + u32 base, u32 pitch, u32 bpp, u32 x, u32 y, u32 width, u32 height, u32 color, u32 rop) { @@ -102,14 +102,14 @@ int sm750_hw_fillrect(struct lynx_accel *accel, write_dpr(accel, DE_WINDOW_DESTINATION_BASE, base); /* dpr40 */ write_dpr(accel, DE_PITCH, - ((pitch / Bpp << DE_PITCH_DESTINATION_SHIFT) & + ((pitch / bpp << DE_PITCH_DESTINATION_SHIFT) & DE_PITCH_DESTINATION_MASK) | - (pitch / Bpp & DE_PITCH_SOURCE_MASK)); /* dpr10 */ + (pitch / bpp & DE_PITCH_SOURCE_MASK)); /* dpr10 */ write_dpr(accel, DE_WINDOW_WIDTH, - ((pitch / Bpp << DE_WINDOW_WIDTH_DST_SHIFT) & + ((pitch / bpp << DE_WINDOW_WIDTH_DST_SHIFT) & DE_WINDOW_WIDTH_DST_MASK) | - (pitch / Bpp & DE_WINDOW_WIDTH_SRC_MASK)); /* dpr44 */ + (pitch / bpp & DE_WINDOW_WIDTH_SRC_MASK)); /* dpr44 */ write_dpr(accel, DE_FOREGROUND, color); /* DPR14 */ @@ -138,7 +138,7 @@ int sm750_hw_fillrect(struct lynx_accel *accel, * @sy: Starting y coordinate of source surface * @dBase: Address of destination: offset in frame buffer * @dPitch: Pitch value of destination surface in BYTE - * @Bpp: Color depth of destination surface + * @bpp: Color depth of destination surface * @dx: Starting x coordinate of destination surface * @dy: Starting y coordinate of destination surface * @width: width of rectangle in pixel value @@ -149,7 +149,7 @@ int sm750_hw_copyarea(struct lynx_accel *accel, unsigned int sBase, unsigned int sPitch, unsigned int sx, unsigned int sy, unsigned int dBase, unsigned int dPitch, - unsigned int Bpp, unsigned int dx, unsigned int dy, + unsigned int bpp, unsigned int dx, unsigned int dy, unsigned int width, unsigned int height, unsigned int rop2) { @@ -249,9 +249,9 @@ int sm750_hw_copyarea(struct lynx_accel *accel, * pixel values. Need Byte to pixel conversion. */ write_dpr(accel, DE_PITCH, - ((dPitch / Bpp << DE_PITCH_DESTINATION_SHIFT) & + ((dPitch / bpp << DE_PITCH_DESTINATION_SHIFT) & DE_PITCH_DESTINATION_MASK) | - (sPitch / Bpp & DE_PITCH_SOURCE_MASK)); /* dpr10 */ + (sPitch / bpp & DE_PITCH_SOURCE_MASK)); /* dpr10 */ /* * Screen Window width in Pixels. @@ -259,9 +259,9 @@ int sm750_hw_copyarea(struct lynx_accel *accel, * for a given point. */ write_dpr(accel, DE_WINDOW_WIDTH, - ((dPitch / Bpp << DE_WINDOW_WIDTH_DST_SHIFT) & + ((dPitch / bpp << DE_WINDOW_WIDTH_DST_SHIFT) & DE_WINDOW_WIDTH_DST_MASK) | - (sPitch / Bpp & DE_WINDOW_WIDTH_SRC_MASK)); /* dpr3c */ + (sPitch / bpp & DE_WINDOW_WIDTH_SRC_MASK)); /* dpr3c */ if (accel->de_wait() != 0) return -1; -- 2.43.0
Rename the Bpp parameter to bytes_per_pixel for clarity and to avoid CamelCase, as reported by checkpatch.pl. Signed-off-by: yehudis9982 <y0533159982@gmail.com> --- drivers/staging/sm750fb/sm750_accel.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/staging/sm750fb/sm750_accel.c b/drivers/staging/sm750fb/sm750_accel.c index 046b9282b..3fe9429e1 100644 --- a/drivers/staging/sm750fb/sm750_accel.c +++ b/drivers/staging/sm750fb/sm750_accel.c @@ -48,7 +48,7 @@ void sm750_hw_de_init(struct lynx_accel *accel) DE_STRETCH_FORMAT_ADDRESSING_MASK | DE_STRETCH_FORMAT_SOURCE_HEIGHT_MASK; - /* DE_STRETCH bpp format need be initialized in setMode routine */ + /* DE_STRETCH bytes_per_pixel format need be initialized in setMode routine */ write_dpr(accel, DE_STRETCH_FORMAT, (read_dpr(accel, DE_STRETCH_FORMAT) & ~clr) | reg); @@ -76,7 +76,7 @@ void sm750_hw_set2dformat(struct lynx_accel *accel, int fmt) { u32 reg; - /* fmt=0,1,2 for 8,16,32,bpp on sm718/750/502 */ + /* fmt=0,1,2 for 8,16,32,bytes_per_pixel on sm718/750/502 */ reg = read_dpr(accel, DE_STRETCH_FORMAT); reg &= ~DE_STRETCH_FORMAT_PIXEL_FORMAT_MASK; reg |= ((fmt << DE_STRETCH_FORMAT_PIXEL_FORMAT_SHIFT) & @@ -85,7 +85,7 @@ void sm750_hw_set2dformat(struct lynx_accel *accel, int fmt) } int sm750_hw_fillrect(struct lynx_accel *accel, - u32 base, u32 pitch, u32 Bpp, + u32 base, u32 pitch, u32 bytes_per_pixel, u32 x, u32 y, u32 width, u32 height, u32 color, u32 rop) { @@ -102,14 +102,14 @@ int sm750_hw_fillrect(struct lynx_accel *accel, write_dpr(accel, DE_WINDOW_DESTINATION_BASE, base); /* dpr40 */ write_dpr(accel, DE_PITCH, - ((pitch / Bpp << DE_PITCH_DESTINATION_SHIFT) & + ((pitch / bytes_per_pixel << DE_PITCH_DESTINATION_SHIFT) & DE_PITCH_DESTINATION_MASK) | - (pitch / Bpp & DE_PITCH_SOURCE_MASK)); /* dpr10 */ + (pitch / bytes_per_pixel & DE_PITCH_SOURCE_MASK)); /* dpr10 */ write_dpr(accel, DE_WINDOW_WIDTH, - ((pitch / Bpp << DE_WINDOW_WIDTH_DST_SHIFT) & + ((pitch / bytes_per_pixel << DE_WINDOW_WIDTH_DST_SHIFT) & DE_WINDOW_WIDTH_DST_MASK) | - (pitch / Bpp & DE_WINDOW_WIDTH_SRC_MASK)); /* dpr44 */ + (pitch / bytes_per_pixel & DE_WINDOW_WIDTH_SRC_MASK)); /* dpr44 */ write_dpr(accel, DE_FOREGROUND, color); /* DPR14 */ @@ -138,7 +138,7 @@ int sm750_hw_fillrect(struct lynx_accel *accel, * @sy: Starting y coordinate of source surface * @dBase: Address of destination: offset in frame buffer * @dPitch: Pitch value of destination surface in BYTE - * @Bpp: Color depth of destination surface + * @bytes_per_pixel: Bytes per pixel (color depth / 8) of destination surface * @dx: Starting x coordinate of destination surface * @dy: Starting y coordinate of destination surface * @width: width of rectangle in pixel value @@ -149,7 +149,7 @@ int sm750_hw_copyarea(struct lynx_accel *accel, unsigned int sBase, unsigned int sPitch, unsigned int sx, unsigned int sy, unsigned int dBase, unsigned int dPitch, - unsigned int Bpp, unsigned int dx, unsigned int dy, + unsigned int bytes_per_pixel, unsigned int dx, unsigned int dy, unsigned int width, unsigned int height, unsigned int rop2) { @@ -249,9 +249,9 @@ int sm750_hw_copyarea(struct lynx_accel *accel, * pixel values. Need Byte to pixel conversion. */ write_dpr(accel, DE_PITCH, - ((dPitch / Bpp << DE_PITCH_DESTINATION_SHIFT) & + ((dPitch / bytes_per_pixel << DE_PITCH_DESTINATION_SHIFT) & DE_PITCH_DESTINATION_MASK) | - (sPitch / Bpp & DE_PITCH_SOURCE_MASK)); /* dpr10 */ + (sPitch / bytes_per_pixel & DE_PITCH_SOURCE_MASK)); /* dpr10 */ /* * Screen Window width in Pixels. @@ -259,9 +259,9 @@ int sm750_hw_copyarea(struct lynx_accel *accel, * for a given point. */ write_dpr(accel, DE_WINDOW_WIDTH, - ((dPitch / Bpp << DE_WINDOW_WIDTH_DST_SHIFT) & + ((dPitch / bytes_per_pixel << DE_WINDOW_WIDTH_DST_SHIFT) & DE_WINDOW_WIDTH_DST_MASK) | - (sPitch / Bpp & DE_WINDOW_WIDTH_SRC_MASK)); /* dpr3c */ + (sPitch / bytes_per_pixel & DE_WINDOW_WIDTH_SRC_MASK)); /* dpr3c */ if (accel->de_wait() != 0) return -1; -- 2.43.0
{ "author": "yehudis9982 <y0533159982@gmail.com>", "date": "Mon, 2 Feb 2026 18:46:45 +0200", "thread_id": "20260202145413.132435-1-y0533159982@gmail.com.mbox.gz" }
lkml
[PATCH] staging: sm750fb: rename Bpp to bpp
Rename the Bpp parameter to bpp to avoid CamelCase, as reported by checkpatch.pl. Signed-off-by: yehudis9982 <y0533159982@gmail.com> --- drivers/staging/sm750fb/sm750_accel.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/staging/sm750fb/sm750_accel.c b/drivers/staging/sm750fb/sm750_accel.c index 046b9282b..866b12c2a 100644 --- a/drivers/staging/sm750fb/sm750_accel.c +++ b/drivers/staging/sm750fb/sm750_accel.c @@ -85,7 +85,7 @@ void sm750_hw_set2dformat(struct lynx_accel *accel, int fmt) } int sm750_hw_fillrect(struct lynx_accel *accel, - u32 base, u32 pitch, u32 Bpp, + u32 base, u32 pitch, u32 bpp, u32 x, u32 y, u32 width, u32 height, u32 color, u32 rop) { @@ -102,14 +102,14 @@ int sm750_hw_fillrect(struct lynx_accel *accel, write_dpr(accel, DE_WINDOW_DESTINATION_BASE, base); /* dpr40 */ write_dpr(accel, DE_PITCH, - ((pitch / Bpp << DE_PITCH_DESTINATION_SHIFT) & + ((pitch / bpp << DE_PITCH_DESTINATION_SHIFT) & DE_PITCH_DESTINATION_MASK) | - (pitch / Bpp & DE_PITCH_SOURCE_MASK)); /* dpr10 */ + (pitch / bpp & DE_PITCH_SOURCE_MASK)); /* dpr10 */ write_dpr(accel, DE_WINDOW_WIDTH, - ((pitch / Bpp << DE_WINDOW_WIDTH_DST_SHIFT) & + ((pitch / bpp << DE_WINDOW_WIDTH_DST_SHIFT) & DE_WINDOW_WIDTH_DST_MASK) | - (pitch / Bpp & DE_WINDOW_WIDTH_SRC_MASK)); /* dpr44 */ + (pitch / bpp & DE_WINDOW_WIDTH_SRC_MASK)); /* dpr44 */ write_dpr(accel, DE_FOREGROUND, color); /* DPR14 */ @@ -138,7 +138,7 @@ int sm750_hw_fillrect(struct lynx_accel *accel, * @sy: Starting y coordinate of source surface * @dBase: Address of destination: offset in frame buffer * @dPitch: Pitch value of destination surface in BYTE - * @Bpp: Color depth of destination surface + * @bpp: Color depth of destination surface * @dx: Starting x coordinate of destination surface * @dy: Starting y coordinate of destination surface * @width: width of rectangle in pixel value @@ -149,7 +149,7 @@ int sm750_hw_copyarea(struct lynx_accel *accel, unsigned int sBase, unsigned int sPitch, unsigned int sx, unsigned int sy, unsigned int dBase, unsigned int dPitch, - unsigned int Bpp, unsigned int dx, unsigned int dy, + unsigned int bpp, unsigned int dx, unsigned int dy, unsigned int width, unsigned int height, unsigned int rop2) { @@ -249,9 +249,9 @@ int sm750_hw_copyarea(struct lynx_accel *accel, * pixel values. Need Byte to pixel conversion. */ write_dpr(accel, DE_PITCH, - ((dPitch / Bpp << DE_PITCH_DESTINATION_SHIFT) & + ((dPitch / bpp << DE_PITCH_DESTINATION_SHIFT) & DE_PITCH_DESTINATION_MASK) | - (sPitch / Bpp & DE_PITCH_SOURCE_MASK)); /* dpr10 */ + (sPitch / bpp & DE_PITCH_SOURCE_MASK)); /* dpr10 */ /* * Screen Window width in Pixels. @@ -259,9 +259,9 @@ int sm750_hw_copyarea(struct lynx_accel *accel, * for a given point. */ write_dpr(accel, DE_WINDOW_WIDTH, - ((dPitch / Bpp << DE_WINDOW_WIDTH_DST_SHIFT) & + ((dPitch / bpp << DE_WINDOW_WIDTH_DST_SHIFT) & DE_WINDOW_WIDTH_DST_MASK) | - (sPitch / Bpp & DE_WINDOW_WIDTH_SRC_MASK)); /* dpr3c */ + (sPitch / bpp & DE_WINDOW_WIDTH_SRC_MASK)); /* dpr3c */ if (accel->de_wait() != 0) return -1; -- 2.43.0
Rename the Bpp parameter to bytes_per_pixel for clarity and to avoid CamelCase, as reported by checkpatch.pl. Signed-off-by: yehudis9982 <y0533159982@gmail.com> --- drivers/staging/sm750fb/sm750_accel.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/staging/sm750fb/sm750_accel.c b/drivers/staging/sm750fb/sm750_accel.c index 046b9282b..3fe9429e1 100644 --- a/drivers/staging/sm750fb/sm750_accel.c +++ b/drivers/staging/sm750fb/sm750_accel.c @@ -48,7 +48,7 @@ void sm750_hw_de_init(struct lynx_accel *accel) DE_STRETCH_FORMAT_ADDRESSING_MASK | DE_STRETCH_FORMAT_SOURCE_HEIGHT_MASK; - /* DE_STRETCH bpp format need be initialized in setMode routine */ + /* DE_STRETCH bytes_per_pixel format need be initialized in setMode routine */ write_dpr(accel, DE_STRETCH_FORMAT, (read_dpr(accel, DE_STRETCH_FORMAT) & ~clr) | reg); @@ -76,7 +76,7 @@ void sm750_hw_set2dformat(struct lynx_accel *accel, int fmt) { u32 reg; - /* fmt=0,1,2 for 8,16,32,bpp on sm718/750/502 */ + /* fmt=0,1,2 for 8,16,32,bytes_per_pixel on sm718/750/502 */ reg = read_dpr(accel, DE_STRETCH_FORMAT); reg &= ~DE_STRETCH_FORMAT_PIXEL_FORMAT_MASK; reg |= ((fmt << DE_STRETCH_FORMAT_PIXEL_FORMAT_SHIFT) & @@ -85,7 +85,7 @@ void sm750_hw_set2dformat(struct lynx_accel *accel, int fmt) } int sm750_hw_fillrect(struct lynx_accel *accel, - u32 base, u32 pitch, u32 Bpp, + u32 base, u32 pitch, u32 bytes_per_pixel, u32 x, u32 y, u32 width, u32 height, u32 color, u32 rop) { @@ -102,14 +102,14 @@ int sm750_hw_fillrect(struct lynx_accel *accel, write_dpr(accel, DE_WINDOW_DESTINATION_BASE, base); /* dpr40 */ write_dpr(accel, DE_PITCH, - ((pitch / Bpp << DE_PITCH_DESTINATION_SHIFT) & + ((pitch / bytes_per_pixel << DE_PITCH_DESTINATION_SHIFT) & DE_PITCH_DESTINATION_MASK) | - (pitch / Bpp & DE_PITCH_SOURCE_MASK)); /* dpr10 */ + (pitch / bytes_per_pixel & DE_PITCH_SOURCE_MASK)); /* dpr10 */ write_dpr(accel, DE_WINDOW_WIDTH, - ((pitch / Bpp << DE_WINDOW_WIDTH_DST_SHIFT) & + ((pitch / bytes_per_pixel << DE_WINDOW_WIDTH_DST_SHIFT) & DE_WINDOW_WIDTH_DST_MASK) | - (pitch / Bpp & DE_WINDOW_WIDTH_SRC_MASK)); /* dpr44 */ + (pitch / bytes_per_pixel & DE_WINDOW_WIDTH_SRC_MASK)); /* dpr44 */ write_dpr(accel, DE_FOREGROUND, color); /* DPR14 */ @@ -138,7 +138,7 @@ int sm750_hw_fillrect(struct lynx_accel *accel, * @sy: Starting y coordinate of source surface * @dBase: Address of destination: offset in frame buffer * @dPitch: Pitch value of destination surface in BYTE - * @Bpp: Color depth of destination surface + * @bytes_per_pixel: Bytes per pixel (color depth / 8) of destination surface * @dx: Starting x coordinate of destination surface * @dy: Starting y coordinate of destination surface * @width: width of rectangle in pixel value @@ -149,7 +149,7 @@ int sm750_hw_copyarea(struct lynx_accel *accel, unsigned int sBase, unsigned int sPitch, unsigned int sx, unsigned int sy, unsigned int dBase, unsigned int dPitch, - unsigned int Bpp, unsigned int dx, unsigned int dy, + unsigned int bytes_per_pixel, unsigned int dx, unsigned int dy, unsigned int width, unsigned int height, unsigned int rop2) { @@ -249,9 +249,9 @@ int sm750_hw_copyarea(struct lynx_accel *accel, * pixel values. Need Byte to pixel conversion. */ write_dpr(accel, DE_PITCH, - ((dPitch / Bpp << DE_PITCH_DESTINATION_SHIFT) & + ((dPitch / bytes_per_pixel << DE_PITCH_DESTINATION_SHIFT) & DE_PITCH_DESTINATION_MASK) | - (sPitch / Bpp & DE_PITCH_SOURCE_MASK)); /* dpr10 */ + (sPitch / bytes_per_pixel & DE_PITCH_SOURCE_MASK)); /* dpr10 */ /* * Screen Window width in Pixels. @@ -259,9 +259,9 @@ int sm750_hw_copyarea(struct lynx_accel *accel, * for a given point. */ write_dpr(accel, DE_WINDOW_WIDTH, - ((dPitch / Bpp << DE_WINDOW_WIDTH_DST_SHIFT) & + ((dPitch / bytes_per_pixel << DE_WINDOW_WIDTH_DST_SHIFT) & DE_WINDOW_WIDTH_DST_MASK) | - (sPitch / Bpp & DE_WINDOW_WIDTH_SRC_MASK)); /* dpr3c */ + (sPitch / bytes_per_pixel & DE_WINDOW_WIDTH_SRC_MASK)); /* dpr3c */ if (accel->de_wait() != 0) return -1; -- 2.43.0
{ "author": "yehudis9982 <y0533159982@gmail.com>", "date": "Mon, 2 Feb 2026 18:57:18 +0200", "thread_id": "20260202145413.132435-1-y0533159982@gmail.com.mbox.gz" }
lkml
[PATCH] staging: sm750fb: rename Bpp to bpp
Rename the Bpp parameter to bpp to avoid CamelCase, as reported by checkpatch.pl. Signed-off-by: yehudis9982 <y0533159982@gmail.com> --- drivers/staging/sm750fb/sm750_accel.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/staging/sm750fb/sm750_accel.c b/drivers/staging/sm750fb/sm750_accel.c index 046b9282b..866b12c2a 100644 --- a/drivers/staging/sm750fb/sm750_accel.c +++ b/drivers/staging/sm750fb/sm750_accel.c @@ -85,7 +85,7 @@ void sm750_hw_set2dformat(struct lynx_accel *accel, int fmt) } int sm750_hw_fillrect(struct lynx_accel *accel, - u32 base, u32 pitch, u32 Bpp, + u32 base, u32 pitch, u32 bpp, u32 x, u32 y, u32 width, u32 height, u32 color, u32 rop) { @@ -102,14 +102,14 @@ int sm750_hw_fillrect(struct lynx_accel *accel, write_dpr(accel, DE_WINDOW_DESTINATION_BASE, base); /* dpr40 */ write_dpr(accel, DE_PITCH, - ((pitch / Bpp << DE_PITCH_DESTINATION_SHIFT) & + ((pitch / bpp << DE_PITCH_DESTINATION_SHIFT) & DE_PITCH_DESTINATION_MASK) | - (pitch / Bpp & DE_PITCH_SOURCE_MASK)); /* dpr10 */ + (pitch / bpp & DE_PITCH_SOURCE_MASK)); /* dpr10 */ write_dpr(accel, DE_WINDOW_WIDTH, - ((pitch / Bpp << DE_WINDOW_WIDTH_DST_SHIFT) & + ((pitch / bpp << DE_WINDOW_WIDTH_DST_SHIFT) & DE_WINDOW_WIDTH_DST_MASK) | - (pitch / Bpp & DE_WINDOW_WIDTH_SRC_MASK)); /* dpr44 */ + (pitch / bpp & DE_WINDOW_WIDTH_SRC_MASK)); /* dpr44 */ write_dpr(accel, DE_FOREGROUND, color); /* DPR14 */ @@ -138,7 +138,7 @@ int sm750_hw_fillrect(struct lynx_accel *accel, * @sy: Starting y coordinate of source surface * @dBase: Address of destination: offset in frame buffer * @dPitch: Pitch value of destination surface in BYTE - * @Bpp: Color depth of destination surface + * @bpp: Color depth of destination surface * @dx: Starting x coordinate of destination surface * @dy: Starting y coordinate of destination surface * @width: width of rectangle in pixel value @@ -149,7 +149,7 @@ int sm750_hw_copyarea(struct lynx_accel *accel, unsigned int sBase, unsigned int sPitch, unsigned int sx, unsigned int sy, unsigned int dBase, unsigned int dPitch, - unsigned int Bpp, unsigned int dx, unsigned int dy, + unsigned int bpp, unsigned int dx, unsigned int dy, unsigned int width, unsigned int height, unsigned int rop2) { @@ -249,9 +249,9 @@ int sm750_hw_copyarea(struct lynx_accel *accel, * pixel values. Need Byte to pixel conversion. */ write_dpr(accel, DE_PITCH, - ((dPitch / Bpp << DE_PITCH_DESTINATION_SHIFT) & + ((dPitch / bpp << DE_PITCH_DESTINATION_SHIFT) & DE_PITCH_DESTINATION_MASK) | - (sPitch / Bpp & DE_PITCH_SOURCE_MASK)); /* dpr10 */ + (sPitch / bpp & DE_PITCH_SOURCE_MASK)); /* dpr10 */ /* * Screen Window width in Pixels. @@ -259,9 +259,9 @@ int sm750_hw_copyarea(struct lynx_accel *accel, * for a given point. */ write_dpr(accel, DE_WINDOW_WIDTH, - ((dPitch / Bpp << DE_WINDOW_WIDTH_DST_SHIFT) & + ((dPitch / bpp << DE_WINDOW_WIDTH_DST_SHIFT) & DE_WINDOW_WIDTH_DST_MASK) | - (sPitch / Bpp & DE_WINDOW_WIDTH_SRC_MASK)); /* dpr3c */ + (sPitch / bpp & DE_WINDOW_WIDTH_SRC_MASK)); /* dpr3c */ if (accel->de_wait() != 0) return -1; -- 2.43.0
Rename the Bpp parameter to bytes_per_pixel for clarity and to avoid CamelCase, as reported by checkpatch.pl. Signed-off-by: yehudis9982 <y0533159982@gmail.com> --- drivers/staging/sm750fb/sm750_accel.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/staging/sm750fb/sm750_accel.c b/drivers/staging/sm750fb/sm750_accel.c index 046b9282b..3fe9429e1 100644 --- a/drivers/staging/sm750fb/sm750_accel.c +++ b/drivers/staging/sm750fb/sm750_accel.c @@ -48,7 +48,7 @@ void sm750_hw_de_init(struct lynx_accel *accel) DE_STRETCH_FORMAT_ADDRESSING_MASK | DE_STRETCH_FORMAT_SOURCE_HEIGHT_MASK; - /* DE_STRETCH bpp format need be initialized in setMode routine */ + /* DE_STRETCH bytes_per_pixel format need be initialized in setMode routine */ write_dpr(accel, DE_STRETCH_FORMAT, (read_dpr(accel, DE_STRETCH_FORMAT) & ~clr) | reg); @@ -76,7 +76,7 @@ void sm750_hw_set2dformat(struct lynx_accel *accel, int fmt) { u32 reg; - /* fmt=0,1,2 for 8,16,32,bpp on sm718/750/502 */ + /* fmt=0,1,2 for 8,16,32,bytes_per_pixel on sm718/750/502 */ reg = read_dpr(accel, DE_STRETCH_FORMAT); reg &= ~DE_STRETCH_FORMAT_PIXEL_FORMAT_MASK; reg |= ((fmt << DE_STRETCH_FORMAT_PIXEL_FORMAT_SHIFT) & @@ -85,7 +85,7 @@ void sm750_hw_set2dformat(struct lynx_accel *accel, int fmt) } int sm750_hw_fillrect(struct lynx_accel *accel, - u32 base, u32 pitch, u32 Bpp, + u32 base, u32 pitch, u32 bytes_per_pixel, u32 x, u32 y, u32 width, u32 height, u32 color, u32 rop) { @@ -102,14 +102,14 @@ int sm750_hw_fillrect(struct lynx_accel *accel, write_dpr(accel, DE_WINDOW_DESTINATION_BASE, base); /* dpr40 */ write_dpr(accel, DE_PITCH, - ((pitch / Bpp << DE_PITCH_DESTINATION_SHIFT) & + ((pitch / bytes_per_pixel << DE_PITCH_DESTINATION_SHIFT) & DE_PITCH_DESTINATION_MASK) | - (pitch / Bpp & DE_PITCH_SOURCE_MASK)); /* dpr10 */ + (pitch / bytes_per_pixel & DE_PITCH_SOURCE_MASK)); /* dpr10 */ write_dpr(accel, DE_WINDOW_WIDTH, - ((pitch / Bpp << DE_WINDOW_WIDTH_DST_SHIFT) & + ((pitch / bytes_per_pixel << DE_WINDOW_WIDTH_DST_SHIFT) & DE_WINDOW_WIDTH_DST_MASK) | - (pitch / Bpp & DE_WINDOW_WIDTH_SRC_MASK)); /* dpr44 */ + (pitch / bytes_per_pixel & DE_WINDOW_WIDTH_SRC_MASK)); /* dpr44 */ write_dpr(accel, DE_FOREGROUND, color); /* DPR14 */ @@ -138,7 +138,7 @@ int sm750_hw_fillrect(struct lynx_accel *accel, * @sy: Starting y coordinate of source surface * @dBase: Address of destination: offset in frame buffer * @dPitch: Pitch value of destination surface in BYTE - * @Bpp: Color depth of destination surface + * @bytes_per_pixel: Bytes per pixel (color depth / 8) of destination surface * @dx: Starting x coordinate of destination surface * @dy: Starting y coordinate of destination surface * @width: width of rectangle in pixel value @@ -149,7 +149,7 @@ int sm750_hw_copyarea(struct lynx_accel *accel, unsigned int sBase, unsigned int sPitch, unsigned int sx, unsigned int sy, unsigned int dBase, unsigned int dPitch, - unsigned int Bpp, unsigned int dx, unsigned int dy, + unsigned int bytes_per_pixel, unsigned int dx, unsigned int dy, unsigned int width, unsigned int height, unsigned int rop2) { @@ -249,9 +249,9 @@ int sm750_hw_copyarea(struct lynx_accel *accel, * pixel values. Need Byte to pixel conversion. */ write_dpr(accel, DE_PITCH, - ((dPitch / Bpp << DE_PITCH_DESTINATION_SHIFT) & + ((dPitch / bytes_per_pixel << DE_PITCH_DESTINATION_SHIFT) & DE_PITCH_DESTINATION_MASK) | - (sPitch / Bpp & DE_PITCH_SOURCE_MASK)); /* dpr10 */ + (sPitch / bytes_per_pixel & DE_PITCH_SOURCE_MASK)); /* dpr10 */ /* * Screen Window width in Pixels. @@ -259,9 +259,9 @@ int sm750_hw_copyarea(struct lynx_accel *accel, * for a given point. */ write_dpr(accel, DE_WINDOW_WIDTH, - ((dPitch / Bpp << DE_WINDOW_WIDTH_DST_SHIFT) & + ((dPitch / bytes_per_pixel << DE_WINDOW_WIDTH_DST_SHIFT) & DE_WINDOW_WIDTH_DST_MASK) | - (sPitch / Bpp & DE_WINDOW_WIDTH_SRC_MASK)); /* dpr3c */ + (sPitch / bytes_per_pixel & DE_WINDOW_WIDTH_SRC_MASK)); /* dpr3c */ if (accel->de_wait() != 0) return -1; -- 2.43.0
{ "author": "yehudis9982 <y0533159982@gmail.com>", "date": "Mon, 2 Feb 2026 19:12:43 +0200", "thread_id": "20260202145413.132435-1-y0533159982@gmail.com.mbox.gz" }
lkml
[syzbot] [hfs?] kernel BUG in may_open (3)
Hello, syzbot found the following issue on: HEAD commit: b6151c4e60e5 Merge tag 'erofs-for-6.19-rc5-fixes' of git:/.. git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=15d45922580000 kernel config: https://syzkaller.appspot.com/x/.config?x=7b058fb1d7dbe6b1 dashboard link: https://syzkaller.appspot.com/bug?extid=f98189ed18c1f5f32e00 compiler: Debian clang version 20.1.8 (++20250708063551+0c9f909b7976-1~exp1~20250708183702.136), Debian LLD 20.1.8 syz repro: https://syzkaller.appspot.com/x/repro.syz?x=14a7d19a580000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=16a2f19a580000 Downloadable assets: disk image: https://storage.googleapis.com/syzbot-assets/6eb5179ada01/disk-b6151c4e.raw.xz vmlinux: https://storage.googleapis.com/syzbot-assets/bc48d1a68ed0/vmlinux-b6151c4e.xz kernel image: https://storage.googleapis.com/syzbot-assets/061d4fb696a7/bzImage-b6151c4e.xz mounted in repro: https://storage.googleapis.com/syzbot-assets/df739de73585/mount_0.gz IMPORTANT: if you fix the issue, please add the following tag to the commit: Reported-by: syzbot+f98189ed18c1f5f32e00@syzkaller.appspotmail.com loop0: detected capacity change from 0 to 1024 VFS_BUG_ON_INODE(!IS_ANON_FILE(inode)) encountered for inode ffff8880384b01e0 fs hfsplus mode 0 opflags 0x4 flags 0x0 state 0x70 count 2 ------------[ cut here ]------------ kernel BUG at fs/namei.c:4210! Oops: invalid opcode: 0000 [#1] SMP KASAN PTI CPU: 1 UID: 0 PID: 6062 Comm: syz.0.17 Not tainted syzkaller #0 PREEMPT_{RT,(full)} Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/25/2025 RIP: 0010:may_open+0x4b1/0x4c0 fs/namei.c:4210 Code: 38 c1 0f 8c 1e fd ff ff 4c 89 e7 e8 c9 ec ef ff e9 11 fd ff ff e8 df b3 8d ff 4c 89 f7 48 c7 c6 80 53 f9 8a e8 10 eb f5 fe 90 <0f> 0b 66 66 66 66 2e 0f 1f 84 00 00 00 00 00 90 90 90 90 90 90 90 RSP: 0018:ffffc90003ba78e0 EFLAGS: 00010282 RAX: 0000000000000088 RBX: dffffc0000000000 RCX: b41eda36b1e3ff00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000008241 R08: 0000000000000000 R09: 0000000000000000 R10: dffffc0000000000 R11: fffff52000774ec1 R12: 0000000000000000 R13: ffffffff8d709d80 R14: ffff8880384b01e0 R15: 0000000000000002 FS: 000055557d7cd500(0000) GS:ffff888126def000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f01916a5890 CR3: 0000000040598000 CR4: 00000000003526f0 Call Trace: <TASK> do_open fs/namei.c:4635 [inline] path_openat+0x32a8/0x3df0 fs/namei.c:4796 do_filp_open+0x1fa/0x410 fs/namei.c:4823 do_sys_openat2+0x121/0x200 fs/open.c:1430 do_sys_open fs/open.c:1436 [inline] __do_sys_creat fs/open.c:1514 [inline] __se_sys_creat fs/open.c:1508 [inline] __x64_sys_creat+0x8f/0xc0 fs/open.c:1508 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0xec/0xf80 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f739c0cf749 Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007ffd4aa21ce8 EFLAGS: 00000246 ORIG_RAX: 0000000000000055 RAX: ffffffffffffffda RBX: 00007f739c325fa0 RCX: 00007f739c0cf749 RDX: 0000000000000000 RSI: 0000000000000006 RDI: 0000200000000140 RBP: 00007f739c153f91 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007f739c325fa0 R14: 00007f739c325fa0 R15: 0000000000000002 </TASK> Modules linked in: ---[ end trace 0000000000000000 ]--- RIP: 0010:may_open+0x4b1/0x4c0 fs/namei.c:4210 Code: 38 c1 0f 8c 1e fd ff ff 4c 89 e7 e8 c9 ec ef ff e9 11 fd ff ff e8 df b3 8d ff 4c 89 f7 48 c7 c6 80 53 f9 8a e8 10 eb f5 fe 90 <0f> 0b 66 66 66 66 2e 0f 1f 84 00 00 00 00 00 90 90 90 90 90 90 90 RSP: 0018:ffffc90003ba78e0 EFLAGS: 00010282 RAX: 0000000000000088 RBX: dffffc0000000000 RCX: b41eda36b1e3ff00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000008241 R08: 0000000000000000 R09: 0000000000000000 R10: dffffc0000000000 R11: fffff52000774ec1 R12: 0000000000000000 R13: ffffffff8d709d80 R14: ffff8880384b01e0 R15: 0000000000000002 FS: 000055557d7cd500(0000) GS:ffff888126def000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f01916a5890 CR3: 0000000040598000 CR4: 00000000003526f0 --- This report is generated by a bot. It may contain errors. See https://goo.gl/tpsmEJ for more information about syzbot. syzbot engineers can be reached at syzkaller@googlegroups.com. syzbot will keep track of this issue. See: https://goo.gl/tpsmEJ#status for how to communicate with syzbot. If the report is already addressed, let syzbot know by replying with: #syz fix: exact-commit-title If you want syzbot to run the reproducer, reply with: #syz test: git://repo/address.git branch-or-commit-hash If you attach or paste a git patch, syzbot will apply it before testing. If you want to overwrite report's subsystems, reply with: #syz set subsystems: new-subsystem (See the list of subsystem names on the web dashboard) If the report is a duplicate of another one, reply with: #syz dup: exact-subject-of-another-report If you want to undo deduplication, reply with: #syz undup
On Mon, Jan 12, 2026 at 12:51:33AM -0800, syzbot wrote: This is hfsplus adding inodes with a non-valid mode.
{ "author": "Christian Brauner <brauner@kernel.org>", "date": "Mon, 12 Jan 2026 10:27:14 +0100", "thread_id": "de541759cfa4d216e342bf15b07f93a21f46498b.camel@ibm.com.mbox.gz" }
lkml
[syzbot] [hfs?] kernel BUG in may_open (3)
Hello, syzbot found the following issue on: HEAD commit: b6151c4e60e5 Merge tag 'erofs-for-6.19-rc5-fixes' of git:/.. git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=15d45922580000 kernel config: https://syzkaller.appspot.com/x/.config?x=7b058fb1d7dbe6b1 dashboard link: https://syzkaller.appspot.com/bug?extid=f98189ed18c1f5f32e00 compiler: Debian clang version 20.1.8 (++20250708063551+0c9f909b7976-1~exp1~20250708183702.136), Debian LLD 20.1.8 syz repro: https://syzkaller.appspot.com/x/repro.syz?x=14a7d19a580000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=16a2f19a580000 Downloadable assets: disk image: https://storage.googleapis.com/syzbot-assets/6eb5179ada01/disk-b6151c4e.raw.xz vmlinux: https://storage.googleapis.com/syzbot-assets/bc48d1a68ed0/vmlinux-b6151c4e.xz kernel image: https://storage.googleapis.com/syzbot-assets/061d4fb696a7/bzImage-b6151c4e.xz mounted in repro: https://storage.googleapis.com/syzbot-assets/df739de73585/mount_0.gz IMPORTANT: if you fix the issue, please add the following tag to the commit: Reported-by: syzbot+f98189ed18c1f5f32e00@syzkaller.appspotmail.com loop0: detected capacity change from 0 to 1024 VFS_BUG_ON_INODE(!IS_ANON_FILE(inode)) encountered for inode ffff8880384b01e0 fs hfsplus mode 0 opflags 0x4 flags 0x0 state 0x70 count 2 ------------[ cut here ]------------ kernel BUG at fs/namei.c:4210! Oops: invalid opcode: 0000 [#1] SMP KASAN PTI CPU: 1 UID: 0 PID: 6062 Comm: syz.0.17 Not tainted syzkaller #0 PREEMPT_{RT,(full)} Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/25/2025 RIP: 0010:may_open+0x4b1/0x4c0 fs/namei.c:4210 Code: 38 c1 0f 8c 1e fd ff ff 4c 89 e7 e8 c9 ec ef ff e9 11 fd ff ff e8 df b3 8d ff 4c 89 f7 48 c7 c6 80 53 f9 8a e8 10 eb f5 fe 90 <0f> 0b 66 66 66 66 2e 0f 1f 84 00 00 00 00 00 90 90 90 90 90 90 90 RSP: 0018:ffffc90003ba78e0 EFLAGS: 00010282 RAX: 0000000000000088 RBX: dffffc0000000000 RCX: b41eda36b1e3ff00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000008241 R08: 0000000000000000 R09: 0000000000000000 R10: dffffc0000000000 R11: fffff52000774ec1 R12: 0000000000000000 R13: ffffffff8d709d80 R14: ffff8880384b01e0 R15: 0000000000000002 FS: 000055557d7cd500(0000) GS:ffff888126def000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f01916a5890 CR3: 0000000040598000 CR4: 00000000003526f0 Call Trace: <TASK> do_open fs/namei.c:4635 [inline] path_openat+0x32a8/0x3df0 fs/namei.c:4796 do_filp_open+0x1fa/0x410 fs/namei.c:4823 do_sys_openat2+0x121/0x200 fs/open.c:1430 do_sys_open fs/open.c:1436 [inline] __do_sys_creat fs/open.c:1514 [inline] __se_sys_creat fs/open.c:1508 [inline] __x64_sys_creat+0x8f/0xc0 fs/open.c:1508 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0xec/0xf80 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f739c0cf749 Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007ffd4aa21ce8 EFLAGS: 00000246 ORIG_RAX: 0000000000000055 RAX: ffffffffffffffda RBX: 00007f739c325fa0 RCX: 00007f739c0cf749 RDX: 0000000000000000 RSI: 0000000000000006 RDI: 0000200000000140 RBP: 00007f739c153f91 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007f739c325fa0 R14: 00007f739c325fa0 R15: 0000000000000002 </TASK> Modules linked in: ---[ end trace 0000000000000000 ]--- RIP: 0010:may_open+0x4b1/0x4c0 fs/namei.c:4210 Code: 38 c1 0f 8c 1e fd ff ff 4c 89 e7 e8 c9 ec ef ff e9 11 fd ff ff e8 df b3 8d ff 4c 89 f7 48 c7 c6 80 53 f9 8a e8 10 eb f5 fe 90 <0f> 0b 66 66 66 66 2e 0f 1f 84 00 00 00 00 00 90 90 90 90 90 90 90 RSP: 0018:ffffc90003ba78e0 EFLAGS: 00010282 RAX: 0000000000000088 RBX: dffffc0000000000 RCX: b41eda36b1e3ff00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000008241 R08: 0000000000000000 R09: 0000000000000000 R10: dffffc0000000000 R11: fffff52000774ec1 R12: 0000000000000000 R13: ffffffff8d709d80 R14: ffff8880384b01e0 R15: 0000000000000002 FS: 000055557d7cd500(0000) GS:ffff888126def000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f01916a5890 CR3: 0000000040598000 CR4: 00000000003526f0 --- This report is generated by a bot. It may contain errors. See https://goo.gl/tpsmEJ for more information about syzbot. syzbot engineers can be reached at syzkaller@googlegroups.com. syzbot will keep track of this issue. See: https://goo.gl/tpsmEJ#status for how to communicate with syzbot. If the report is already addressed, let syzbot know by replying with: #syz fix: exact-commit-title If you want syzbot to run the reproducer, reply with: #syz test: git://repo/address.git branch-or-commit-hash If you attach or paste a git patch, syzbot will apply it before testing. If you want to overwrite report's subsystems, reply with: #syz set subsystems: new-subsystem (See the list of subsystem names on the web dashboard) If the report is a duplicate of another one, reply with: #syz dup: exact-subject-of-another-report If you want to undo deduplication, reply with: #syz undup
For archival purposes, forwarding an incoming command email to linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com. *** Subject: Private message regarding: [syzbot] [hfs?] kernel BUG in may_open (3) Author: kapoorarnav43@gmail.com #syz test From: Arnav Kapoor <kapoorarnav43@gmail.com> Date: Sun, 12 Jan 2026 14:36:00 +0000 Subject: [PATCH] hfsplus: ensure valid file mode in hfsplus_get_perms Syzbot reported a kernel BUG in may_open() triggered by: VFS_BUG_ON_INODE(!IS_ANON_FILE(inode), inode) This occurs when an inode's i_mode doesn't match any standard file type (S_IFREG, S_IFDIR, S_IFLNK, S_IFBLK, S_IFCHR, S_IFIFO, S_IFSOCK). The crash happens when opening a file on a corrupted HFS+ filesystem where the on-disk permissions structure has only file type bits set without any permission bits. In hfsplus_get_perms(), for directories, the code properly masks and rebuilds the mode: mode = (mode & S_IALLUGO) | S_IFDIR However, for files with non-zero mode from disk, it directly assigns the validated mode without ensuring permission bits are present. If the on-disk mode is something like S_IFREG (0x8000) with no permission bits, the inode ends up with i_mode lacking rwx bits entirely. While such a mode passes the S_IFMT validation in the switch statement, it creates an inode that can't be properly opened since it has no access permissions. Fix this by adding a check in the file path: if mode is non-zero and valid but lacks any permission/attribute bits (S_IALLUGO mask), add default read/write permissions like we do for the mode==0 case. This ensures inodes always have sensible permission bits even when reading from corrupted filesystems. Reported-by: syzbot+f98189ed18c1f5f32e00@syzkaller.appspotmail.com Tested-by: syzbot+f98189ed18c1f5f32e00@syzkaller.appspotmail.com Link: https://syzkaller.appspot.com/bug?extid=f98189ed18c1f5f32e00 Signed-off-by: Arnav Kapoor <kapoorarnav43@gmail.com> --- fs/hfsplus/inode.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c index 000000000000..111111111111 100644 --- a/fs/hfsplus/inode.c +++ b/fs/hfsplus/inode.c @@ -214,10 +214,18 @@ static int hfsplus_get_perms(struct inode *inode, inode->i_gid = sbi->gid; if (dir) { + /* For directories, strip file type bits and rebuild */ mode = mode ? (mode & S_IALLUGO) : (S_IRWXUGO & ~(sbi->umask)); mode |= S_IFDIR; - } else if (!mode) + } else if (!mode) { + /* For files with no mode, use default */ mode = S_IFREG | ((S_IRUGO|S_IWUGO) & ~(sbi->umask)); + } else { + /* For files with mode, ensure we have permission bits */ + if (!(mode & S_IALLUGO)) + mode |= (S_IRUGO|S_IWUGO) & ~(sbi->umask); + } + inode->i_mode = mode; HFSPLUS_I(inode)->userflags = perms->userflags; -- 2.43.0 On Monday, 12 January 2026 at 14:21:35 UTC+5:30 syzbot wrote: Hello, syzbot found the following issue on: HEAD commit: b6151c4e60e5 Merge tag 'erofs-for-6.19-rc5-fixes' of git:/.. git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=15d45922580000 kernel config: https://syzkaller.appspot.com/x/.config?x=7b058fb1d7dbe6b1 dashboard link: https://syzkaller.appspot.com/bug?extid=f98189ed18c1f5f32e00 compiler: Debian clang version 20.1.8 (++20250708063551+0c9f909b7976-1~exp1~20250708183702.136), Debian LLD 20.1.8 syz repro: https://syzkaller.appspot.com/x/repro.syz?x=14a7d19a580000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=16a2f19a580000 Downloadable assets: disk image: https://storage.googleapis.com/syzbot-assets/6eb5179ada01/disk-b6151c4e.raw.xz vmlinux: https://storage.googleapis.com/syzbot-assets/bc48d1a68ed0/vmlinux-b6151c4e.xz kernel image: https://storage.googleapis.com/syzbot-assets/061d4fb696a7/bzImage-b6151c4e.xz mounted in repro: https://storage.googleapis.com/syzbot-assets/df739de73585/mount_0.gz IMPORTANT: if you fix the issue, please add the following tag to the commit: Reported-by: syzbot+f98189...@syzkaller.appspotmail.com loop0: detected capacity change from 0 to 1024 VFS_BUG_ON_INODE(!IS_ANON_FILE(inode)) encountered for inode ffff8880384b01e0 fs hfsplus mode 0 opflags 0x4 flags 0x0 state 0x70 count 2 ------------[ cut here ]------------ kernel BUG at fs/namei.c:4210! Oops: invalid opcode: 0000 [#1] SMP KASAN PTI CPU: 1 UID: 0 PID: 6062 Comm: syz.0.17 Not tainted syzkaller #0 PREEMPT_{RT,(full)} Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/25/2025 RIP: 0010:may_open+0x4b1/0x4c0 fs/namei.c:4210 Code: 38 c1 0f 8c 1e fd ff ff 4c 89 e7 e8 c9 ec ef ff e9 11 fd ff ff e8 df b3 8d ff 4c 89 f7 48 c7 c6 80 53 f9 8a e8 10 eb f5 fe 90 <0f> 0b 66 66 66 66 2e 0f 1f 84 00 00 00 00 00 90 90 90 90 90 90 90 RSP: 0018:ffffc90003ba78e0 EFLAGS: 00010282 RAX: 0000000000000088 RBX: dffffc0000000000 RCX: b41eda36b1e3ff00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000008241 R08: 0000000000000000 R09: 0000000000000000 R10: dffffc0000000000 R11: fffff52000774ec1 R12: 0000000000000000 R13: ffffffff8d709d80 R14: ffff8880384b01e0 R15: 0000000000000002 FS: 000055557d7cd500(0000) GS:ffff888126def000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f01916a5890 CR3: 0000000040598000 CR4: 00000000003526f0 Call Trace: <TASK> do_open fs/namei.c:4635 [inline] path_openat+0x32a8/0x3df0 fs/namei.c:4796 do_filp_open+0x1fa/0x410 fs/namei.c:4823 do_sys_openat2+0x121/0x200 fs/open.c:1430 do_sys_open fs/open.c:1436 [inline] __do_sys_creat fs/open.c:1514 [inline] __se_sys_creat fs/open.c:1508 [inline] __x64_sys_creat+0x8f/0xc0 fs/open.c:1508 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0xec/0xf80 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f739c0cf749 Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007ffd4aa21ce8 EFLAGS: 00000246 ORIG_RAX: 0000000000000055 RAX: ffffffffffffffda RBX: 00007f739c325fa0 RCX: 00007f739c0cf749 RDX: 0000000000000000 RSI: 0000000000000006 RDI: 0000200000000140 RBP: 00007f739c153f91 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007f739c325fa0 R14: 00007f739c325fa0 R15: 0000000000000002 </TASK> Modules linked in: ---[ end trace 0000000000000000 ]--- RIP: 0010:may_open+0x4b1/0x4c0 fs/namei.c:4210 Code: 38 c1 0f 8c 1e fd ff ff 4c 89 e7 e8 c9 ec ef ff e9 11 fd ff ff e8 df b3 8d ff 4c 89 f7 48 c7 c6 80 53 f9 8a e8 10 eb f5 fe 90 <0f> 0b 66 66 66 66 2e 0f 1f 84 00 00 00 00 00 90 90 90 90 90 90 90 RSP: 0018:ffffc90003ba78e0 EFLAGS: 00010282 RAX: 0000000000000088 RBX: dffffc0000000000 RCX: b41eda36b1e3ff00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000008241 R08: 0000000000000000 R09: 0000000000000000 R10: dffffc0000000000 R11: fffff52000774ec1 R12: 0000000000000000 R13: ffffffff8d709d80 R14: ffff8880384b01e0 R15: 0000000000000002 FS: 000055557d7cd500(0000) GS:ffff888126def000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f01916a5890 CR3: 0000000040598000 CR4: 00000000003526f0 --- This report is generated by a bot. It may contain errors. See https://goo.gl/tpsmEJ for more information about syzbot. syzbot engineers can be reached at syzk...@googlegroups.com. syzbot will keep track of this issue. See: https://goo.gl/tpsmEJ#status for how to communicate with syzbot. If the report is already addressed, let syzbot know by replying with: #syz fix: exact-commit-title If you want syzbot to run the reproducer, reply with: #syz test: git://repo/address.git branch-or-commit-hash If you attach or paste a git patch, syzbot will apply it before testing. If you want to overwrite report's subsystems, reply with: #syz set subsystems: new-subsystem (See the list of subsystem names on the web dashboard) If the report is a duplicate of another one, reply with: #syz dup: exact-subject-of-another-report If you want to undo deduplication, reply with: #syz undup
{ "author": "syzbot <syzbot+f98189ed18c1f5f32e00@syzkaller.appspotmail.com>", "date": "Mon, 12 Jan 2026 01:31:21 -0800", "thread_id": "de541759cfa4d216e342bf15b07f93a21f46498b.camel@ibm.com.mbox.gz" }
lkml
[syzbot] [hfs?] kernel BUG in may_open (3)
Hello, syzbot found the following issue on: HEAD commit: b6151c4e60e5 Merge tag 'erofs-for-6.19-rc5-fixes' of git:/.. git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=15d45922580000 kernel config: https://syzkaller.appspot.com/x/.config?x=7b058fb1d7dbe6b1 dashboard link: https://syzkaller.appspot.com/bug?extid=f98189ed18c1f5f32e00 compiler: Debian clang version 20.1.8 (++20250708063551+0c9f909b7976-1~exp1~20250708183702.136), Debian LLD 20.1.8 syz repro: https://syzkaller.appspot.com/x/repro.syz?x=14a7d19a580000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=16a2f19a580000 Downloadable assets: disk image: https://storage.googleapis.com/syzbot-assets/6eb5179ada01/disk-b6151c4e.raw.xz vmlinux: https://storage.googleapis.com/syzbot-assets/bc48d1a68ed0/vmlinux-b6151c4e.xz kernel image: https://storage.googleapis.com/syzbot-assets/061d4fb696a7/bzImage-b6151c4e.xz mounted in repro: https://storage.googleapis.com/syzbot-assets/df739de73585/mount_0.gz IMPORTANT: if you fix the issue, please add the following tag to the commit: Reported-by: syzbot+f98189ed18c1f5f32e00@syzkaller.appspotmail.com loop0: detected capacity change from 0 to 1024 VFS_BUG_ON_INODE(!IS_ANON_FILE(inode)) encountered for inode ffff8880384b01e0 fs hfsplus mode 0 opflags 0x4 flags 0x0 state 0x70 count 2 ------------[ cut here ]------------ kernel BUG at fs/namei.c:4210! Oops: invalid opcode: 0000 [#1] SMP KASAN PTI CPU: 1 UID: 0 PID: 6062 Comm: syz.0.17 Not tainted syzkaller #0 PREEMPT_{RT,(full)} Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/25/2025 RIP: 0010:may_open+0x4b1/0x4c0 fs/namei.c:4210 Code: 38 c1 0f 8c 1e fd ff ff 4c 89 e7 e8 c9 ec ef ff e9 11 fd ff ff e8 df b3 8d ff 4c 89 f7 48 c7 c6 80 53 f9 8a e8 10 eb f5 fe 90 <0f> 0b 66 66 66 66 2e 0f 1f 84 00 00 00 00 00 90 90 90 90 90 90 90 RSP: 0018:ffffc90003ba78e0 EFLAGS: 00010282 RAX: 0000000000000088 RBX: dffffc0000000000 RCX: b41eda36b1e3ff00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000008241 R08: 0000000000000000 R09: 0000000000000000 R10: dffffc0000000000 R11: fffff52000774ec1 R12: 0000000000000000 R13: ffffffff8d709d80 R14: ffff8880384b01e0 R15: 0000000000000002 FS: 000055557d7cd500(0000) GS:ffff888126def000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f01916a5890 CR3: 0000000040598000 CR4: 00000000003526f0 Call Trace: <TASK> do_open fs/namei.c:4635 [inline] path_openat+0x32a8/0x3df0 fs/namei.c:4796 do_filp_open+0x1fa/0x410 fs/namei.c:4823 do_sys_openat2+0x121/0x200 fs/open.c:1430 do_sys_open fs/open.c:1436 [inline] __do_sys_creat fs/open.c:1514 [inline] __se_sys_creat fs/open.c:1508 [inline] __x64_sys_creat+0x8f/0xc0 fs/open.c:1508 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0xec/0xf80 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f739c0cf749 Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007ffd4aa21ce8 EFLAGS: 00000246 ORIG_RAX: 0000000000000055 RAX: ffffffffffffffda RBX: 00007f739c325fa0 RCX: 00007f739c0cf749 RDX: 0000000000000000 RSI: 0000000000000006 RDI: 0000200000000140 RBP: 00007f739c153f91 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007f739c325fa0 R14: 00007f739c325fa0 R15: 0000000000000002 </TASK> Modules linked in: ---[ end trace 0000000000000000 ]--- RIP: 0010:may_open+0x4b1/0x4c0 fs/namei.c:4210 Code: 38 c1 0f 8c 1e fd ff ff 4c 89 e7 e8 c9 ec ef ff e9 11 fd ff ff e8 df b3 8d ff 4c 89 f7 48 c7 c6 80 53 f9 8a e8 10 eb f5 fe 90 <0f> 0b 66 66 66 66 2e 0f 1f 84 00 00 00 00 00 90 90 90 90 90 90 90 RSP: 0018:ffffc90003ba78e0 EFLAGS: 00010282 RAX: 0000000000000088 RBX: dffffc0000000000 RCX: b41eda36b1e3ff00 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000008241 R08: 0000000000000000 R09: 0000000000000000 R10: dffffc0000000000 R11: fffff52000774ec1 R12: 0000000000000000 R13: ffffffff8d709d80 R14: ffff8880384b01e0 R15: 0000000000000002 FS: 000055557d7cd500(0000) GS:ffff888126def000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f01916a5890 CR3: 0000000040598000 CR4: 00000000003526f0 --- This report is generated by a bot. It may contain errors. See https://goo.gl/tpsmEJ for more information about syzbot. syzbot engineers can be reached at syzkaller@googlegroups.com. syzbot will keep track of this issue. See: https://goo.gl/tpsmEJ#status for how to communicate with syzbot. If the report is already addressed, let syzbot know by replying with: #syz fix: exact-commit-title If you want syzbot to run the reproducer, reply with: #syz test: git://repo/address.git branch-or-commit-hash If you attach or paste a git patch, syzbot will apply it before testing. If you want to overwrite report's subsystems, reply with: #syz set subsystems: new-subsystem (See the list of subsystem names on the web dashboard) If the report is a duplicate of another one, reply with: #syz dup: exact-subject-of-another-report If you want to undo deduplication, reply with: #syz undup
Since commit af153bb63a33 ("vfs: catch invalid modes in may_open()") requires any inode be one of S_IFDIR/S_IFLNK/S_IFREG/S_IFCHR/S_IFBLK/ S_IFIFO/S_IFSOCK type, use S_IFREG for special inodes. Reported-by: syzbot <syzbot+f98189ed18c1f5f32e00@syzkaller.appspotmail.com> Closes: https://syzkaller.appspot.com/bug?extid=f98189ed18c1f5f32e00 Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Reviewed-by: Viacheslav Dubeyko <slava@dubeyko.com> --- https://lkml.kernel.org/r/d0a07b1b-8b73-4002-8e29-e2bd56871262@I-love.SAKURA.ne.jp was a bit too late to append to previous bug report. ;-) fs/hfsplus/super.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c index aaffa9e060a0..7f327b777ece 100644 --- a/fs/hfsplus/super.c +++ b/fs/hfsplus/super.c @@ -53,6 +53,12 @@ static int hfsplus_system_read_inode(struct inode *inode) return -EIO; } + /* + * Assign a dummy file type, for may_open() requires that + * an inode has a valid file type. + */ + inode->i_mode = S_IFREG; + return 0; } -- 2.47.3
{ "author": "Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>", "date": "Mon, 12 Jan 2026 18:39:23 +0900", "thread_id": "de541759cfa4d216e342bf15b07f93a21f46498b.camel@ibm.com.mbox.gz" }