WITNESS reports the sx_slock() and a contended lock would sleep in an epoch section.
PR: 299737
Differential D61462
net: traverse interface groups under the network epoch Authored by seuros on Thu, Nov 12, 1:31 PM.
Details
Diff Detail
Event TimelineComment Actions As I understand it, writers hold IFNET_WLOCK, but readers don't need it. if_groups, ifg_members and ifg_head have been CK lists since 4f6c66cc9c75, and _if_delgroup_locked() unlinks under the write lock, drops it and does NET_EPOCH_WAIT() before freeing the ifg_list, ifg_member and ifg_group. pfi_kkif_match() already walks ifp->if_groups per packet in the net epoch without the ifnet lock, fwiw. @kp The read lock is reached from every rt_ifmsg(), so ifnet_sx ends up taken under whatever the caller of if_setflag() holds. That was 9d59ca793f70 (PR 298121), and with CARP it closes an in_control -> carp_sx -> ifnet_sx -> in_control cycle; trace and reproducer are in D62077. The epoch walk does mean the callback can't sleep. dump_group_cb() is the only consumer and its writers are all M_NOWAIT. I'll abandon D62077 in favour of this one; it might be worth taking the comment above if_foreach_group() and the Fixes: 2f8f892ca344 line from it. Regards, Comment Actions That's my understanding as well. The CK_* structures are safe for concurrent readers and a single writer, but not safe for concurrent writers. In other words: we can read without any lock, but need to take a lock to change the CK_*.
As above, that's safe because it's not modifying the CK_STAILQ here (and is in NET_EPOCH). Comment Actions https://reviews.freebsd.org/D15409 seems to be where if_groups was changed to be protected by epoch, so yes, this change is correct, but I really wish we'd document our locking requirements for structures. Comment Actions For reference, this diff fixes https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=299737 Comment Actions Can we please add a comment to the function explaining why RLOCK isn't used here, so we don't forget? Comment Actions Okay, since now we have only one consumer of this KPI (netlink) that already runs in non-sleepable context, and since we marked this KPI as subject to change, such change is fine. |