[Devel] [PATCH vz10 1/7] lib/kmapset: annotate the kmapset_lookup rcu-list walk with the held lock

Mirian Shilakadze mirian.shilakadze at virtuozzo.com
Sun Jun 28 12:25:59 MSK 2026


kmapset_lookup() walks map->links with hlist_for_each_entry_rcu() and its
own comment states the contract: the caller holds kmapset_lock (the set
mutex) or rcu_read_lock. Its readers take rcu_read_lock and its writers
(kmapset_set_value, kmapset_del_value) hold kmapset_lock, so callers that
honour the contract are serialised correctly. The macro carried no lockdep
condition though, so with CONFIG_PROVE_RCU_LIST the writer path trips:

  lib/kmapset.c:236 RCU-list traversed in non-reader section!!
   kmapset_lookup
   kmapset_del_value
   kernfs_perms_set

Pass lockdep_is_held(&map->set->mutex) so the checker accepts both the
rcu_read_lock readers and the kmapset_lock writers. No functional change.

Fixes: 8e1c907a00e8 ("kmapset: set of key-value mappings with build-in")
Signed-off-by: Mirian Shilakadze <mirian.shilakadze at virtuozzo.com>
---
 lib/kmapset.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/kmapset.c b/lib/kmapset.c
index c7a1e57ad3a5..a479134b9793 100644
--- a/lib/kmapset.c
+++ b/lib/kmapset.c
@@ -233,7 +233,8 @@ kmapset_lookup(struct kmapset_map *map, struct kmapset_key *key)
 {
 	struct kmapset_link *link;
 
-	hlist_for_each_entry_rcu(link, &map->links, map_link) {
+	hlist_for_each_entry_rcu(link, &map->links, map_link,
+				 lockdep_is_held(&map->set->mutex)) {
 		if (link->key == key)
 			return link;
 		if (link->key > key)
-- 
2.43.0



More information about the Devel mailing list