git: 8b29ab3aff13 - stable/14 - ipfilter: Avoid holding a lock while stopping

From: Jose Luis Duran <jlduran_at_FreeBSD.org>
Date: Tue, 19 Nov 2024 02:39:03 UTC
The branch stable/14 has been updated by jlduran:

URL: https://cgit.FreeBSD.org/src/commit/?id=8b29ab3aff13366f1032ec28611db5200e3badf5

commit 8b29ab3aff13366f1032ec28611db5200e3badf5
Author:     Jose Luis Duran <jlduran@FreeBSD.org>
AuthorDate: 2024-11-02 17:58:59 +0000
Commit:     Jose Luis Duran <jlduran@FreeBSD.org>
CommitDate: 2024-11-19 02:32:59 +0000

    ipfilter: Avoid holding a lock while stopping
    
    Avoid calling _callout_stop_safe with a non-sleepable lock held when
    detaching by initializing callout_init_rw() with CALLOUT_SHAREDLOCK, and
    avoiding re-initialization inside the timer function.
    
    PR:             282478
    Reviewed by:    cy, emaste, jhb, markj
    Tested by:      cy
    Approved by:    emaste (mentor)
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D47530
    
    (cherry picked from commit 1fa6daaafd74c1a457dcfe26e0a5943b5441dc9d)
    (cherry picked from commit a0618fbe19dfedcdf01b4c232fe6669ae19505c4)
    (cherry picked from commit 650900cc2f607458d32d333bd7ab0aa10be13ba4)
---
 sys/netpfil/ipfilter/netinet/ip_fil_freebsd.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/sys/netpfil/ipfilter/netinet/ip_fil_freebsd.c b/sys/netpfil/ipfilter/netinet/ip_fil_freebsd.c
index 95f9fa1dd278..2a6ff68649b9 100644
--- a/sys/netpfil/ipfilter/netinet/ip_fil_freebsd.c
+++ b/sys/netpfil/ipfilter/netinet/ip_fil_freebsd.c
@@ -172,7 +172,6 @@ ipf_timer_func(void *arg)
 	SPL_INT(s);
 
 	SPL_NET(s);
-	READ_ENTER(&softc->ipf_global);
 
 	if (softc->ipf_running > 0)
 		ipf_slowtimer(softc);
@@ -181,12 +180,10 @@ ipf_timer_func(void *arg)
 #if 0
 		softc->ipf_slow_ch = timeout(ipf_timer_func, softc, hz/2);
 #endif
-		callout_init(&softc->ipf_slow_ch, 1);
 		callout_reset(&softc->ipf_slow_ch,
 			(hz / IPF_HZ_DIVIDE) * IPF_HZ_MULT,
 			ipf_timer_func, softc);
 	}
-	RWLOCK_EXIT(&softc->ipf_global);
 	SPL_X(s);
 }
 
@@ -221,7 +218,7 @@ ipfattach(ipf_main_softc_t *softc)
 	softc->ipf_slow_ch = timeout(ipf_timer_func, softc,
 				     (hz / IPF_HZ_DIVIDE) * IPF_HZ_MULT);
 #endif
-	callout_init(&softc->ipf_slow_ch, 1);
+	callout_init_rw(&softc->ipf_slow_ch, &softc->ipf_global.ipf_lk, CALLOUT_SHAREDLOCK);
 	callout_reset(&softc->ipf_slow_ch, (hz / IPF_HZ_DIVIDE) * IPF_HZ_MULT,
 		ipf_timer_func, softc);
 	return (0);