Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

nstree: use guards for ns_tree_lock

Make use of the guard infrastructure for ns_tree_lock.

Link: https://patch.msgid.link/20251110-work-namespace-nstree-fixes-v1-7-e8a9264e0fb9@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>

+13 -7
+13 -7
kernel/nstree.c
··· 10 10 11 11 static __cacheline_aligned_in_smp DEFINE_SEQLOCK(ns_tree_lock); 12 12 13 + DEFINE_LOCK_GUARD_0(ns_tree_writer, 14 + write_seqlock(&ns_tree_lock), 15 + write_sequnlock(&ns_tree_lock)) 16 + 17 + DEFINE_LOCK_GUARD_0(ns_tree_locked_reader, 18 + read_seqlock_excl(&ns_tree_lock), 19 + read_sequnlock_excl(&ns_tree_lock)) 20 + 13 21 static struct ns_tree_root ns_unified_root = { /* protected by ns_tree_lock */ 14 22 .ns_rb = RB_ROOT, 15 23 .ns_list_head = LIST_HEAD_INIT(ns_unified_root.ns_list_head), ··· 201 193 202 194 VFS_WARN_ON_ONCE(!ns->ns_id); 203 195 204 - write_seqlock(&ns_tree_lock); 196 + guard(ns_tree_writer)(); 205 197 206 198 /* Add to per-type tree and list */ 207 199 node = ns_tree_node_add(&ns->ns_tree_node, ns_tree, ns_cmp); ··· 226 218 VFS_WARN_ON_ONCE(ns != to_ns_common(&init_user_ns)); 227 219 } 228 220 } 229 - write_sequnlock(&ns_tree_lock); 230 221 231 222 VFS_WARN_ON_ONCE(node); 232 223 } ··· 468 461 469 462 VFS_WARN_ON_ONCE(owner->ns_type != CLONE_NEWUSER); 470 463 471 - read_seqlock_excl(&ns_tree_lock); 472 - node = owner->ns_owner_root.ns_rb.rb_node; 464 + guard(ns_tree_locked_reader)(); 473 465 466 + node = owner->ns_owner_root.ns_rb.rb_node; 474 467 while (node) { 475 468 struct ns_common *ns; 476 469 ··· 487 480 488 481 if (ret) 489 482 ret = ns_get_unless_inactive(ret); 490 - read_sequnlock_excl(&ns_tree_lock); 491 483 return ret; 492 484 } 493 485 ··· 654 648 return NULL; 655 649 } 656 650 657 - read_seqlock_excl(&ns_tree_lock); 651 + guard(ns_tree_locked_reader)(); 652 + 658 653 if (ns_tree) 659 654 node = ns_tree->ns_rb.rb_node; 660 655 else ··· 684 677 685 678 if (ret) 686 679 ret = ns_get_unless_inactive(ret); 687 - read_sequnlock_excl(&ns_tree_lock); 688 680 return ret; 689 681 } 690 682