From 46f38a6dedb1b474f04b7c2b072825fda5d7bd5a Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Thu, 21 Nov 2024 18:55:35 +0000 Subject: [PATCH] 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. --- sys/netgraph/ng_base.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sys/netgraph/ng_base.c b/sys/netgraph/ng_base.c index 5bff0663e03..77c7cb0d3c0 100644 --- a/sys/netgraph/ng_base.c +++ b/sys/netgraph/ng_base.c @@ -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);