netgraph: Exit the net epoch to handle control messages

In general, in the direct dispatch case netgraph only enters the net
epoch to send data messages, but this was inconsistent with the netgraph
thread, which also entered the net epoch to send fn and fn2 messages to
nodes.  Some handlers, e.g., ng_bridge_newhook(), may sleep, and so
cannot be called in epoch context; the netgraph tests occasionally panic
due to this problem.

Make ngthread() consistent with the direct dispatch path.

Discussed with:	afedorov (in D44615)
MFC after:	2 weeks
Sponsored by:	Klara, Inc.
This commit is contained in:
Mark Johnston 2024-11-21 18:55:35 +00:00
parent 30cafaa961
commit 46f38a6ded

View File

@ -3440,10 +3440,13 @@ ngthread(void *arg)
NG_QUEUE_UNLOCK(&node->nd_input_queue);
NGI_GET_NODE(item, node); /* zaps stored node */
if ((item->el_flags & NGQF_TYPE) == NGQF_MESG) {
if ((item->el_flags & NGQF_TYPE) != NGQF_DATA) {
/*
* NGQF_MESG items should never be processed in
* NET_EPOCH context. So, temporary exit from EPOCH.
* NGQF_MESG, NGQF_FN and NGQF_FN2 items
* should never be processed in
* NET_EPOCH context; they generally
* require heavier synchronization and
* may sleep. So, temporarily exit.
*/
NET_EPOCH_EXIT(et);
ng_apply_item(node, item, rw);