Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 20 Mar 2021 09:59:43 GMT
From:      Kristof Provost <kp@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: f11b9574cd18 - stable/12 - pf: Fully remove interrupt events on vnet cleanup
Message-ID:  <202103200959.12K9xhNm064227@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/12 has been updated by kp:

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

commit f11b9574cd186762c4883e8819896c6475be3027
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2021-03-10 21:56:11 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2021-03-19 22:42:27 +0000

    pf: Fully remove interrupt events on vnet cleanup
    
    swi_remove() removes the software interrupt handler but does not remove
    the associated interrupt event.
    This is visible when creating and remove a vnet jail in `procstat -t
    12`.
    
    We can remove it manually with intr_event_destroy().
    
    PR:             254171
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D29211
    
    (cherry picked from commit cecfaf9bede9665d6a10f1e575cd5d575450cff7)
---
 sys/net/pfvar.h            |  2 ++
 sys/netpfil/pf/if_pfsync.c | 10 ++++++++--
 sys/netpfil/pf/pf.c        |  1 +
 sys/netpfil/pf/pf_ioctl.c  |  9 ++++++---
 4 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h
index ef25bfc85605..a5ffba6c9d93 100644
--- a/sys/net/pfvar.h
+++ b/sys/net/pfvar.h
@@ -1389,6 +1389,8 @@ VNET_DECLARE(struct pf_srchash *, pf_srchash);
 
 VNET_DECLARE(void *, pf_swi_cookie);
 #define V_pf_swi_cookie	VNET(pf_swi_cookie)
+VNET_DECLARE(struct intr_event *, pf_swi_ie);
+#define	V_pf_swi_ie	VNET(pf_swi_ie)
 
 VNET_DECLARE(uint64_t, pf_stateid[MAXCPU]);
 #define	V_pf_stateid	VNET(pf_stateid)
diff --git a/sys/netpfil/pf/if_pfsync.c b/sys/netpfil/pf/if_pfsync.c
index 0f55dacd18ad..dc149ff486d5 100644
--- a/sys/netpfil/pf/if_pfsync.c
+++ b/sys/netpfil/pf/if_pfsync.c
@@ -254,6 +254,8 @@ VNET_DEFINE_STATIC(struct pfsync_softc	*, pfsyncif) = NULL;
 #define	V_pfsyncif		VNET(pfsyncif)
 VNET_DEFINE_STATIC(void *, pfsync_swi_cookie) = NULL;
 #define	V_pfsync_swi_cookie	VNET(pfsync_swi_cookie)
+VNET_DEFINE_STATIC(struct intr_event *, pfsync_swi_ie);
+#define	V_pfsync_swi_ie		VNET(pfsync_swi_ie)
 VNET_DEFINE_STATIC(struct pfsyncstats, pfsyncstats);
 #define	V_pfsyncstats		VNET(pfsyncstats)
 VNET_DEFINE_STATIC(int, pfsync_carp_adj) = CARP_MAXSKEW;
@@ -2469,7 +2471,7 @@ vnet_pfsync_init(const void *unused __unused)
 
 	V_pfsync_cloner = if_clone_simple(pfsyncname,
 	    pfsync_clone_create, pfsync_clone_destroy, 1);
-	error = swi_add(NULL, pfsyncname, pfsyncintr, V_pfsyncif,
+	error = swi_add(&V_pfsync_swi_ie, pfsyncname, pfsyncintr, V_pfsyncif,
 	    SWI_NET, INTR_MPSAFE, &V_pfsync_swi_cookie);
 	if (error) {
 		if_clone_detach(V_pfsync_cloner);
@@ -2484,11 +2486,15 @@ VNET_SYSINIT(vnet_pfsync_init, SI_SUB_PROTO_FIREWALL, SI_ORDER_ANY,
 static void
 vnet_pfsync_uninit(const void *unused __unused)
 {
+	int ret;
 
 	pfsync_pointers_uninit();
 
 	if_clone_detach(V_pfsync_cloner);
-	swi_remove(V_pfsync_swi_cookie);
+	ret = swi_remove(V_pfsync_swi_cookie);
+	MPASS(ret == 0);
+	ret = intr_event_destroy(V_pfsync_swi_ie);
+	MPASS(ret == 0);
 }
 
 VNET_SYSUNINIT(vnet_pfsync_uninit, SI_SUB_PROTO_FIREWALL, SI_ORDER_FOURTH,
diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c
index 3422cdea1e2e..9ad45ff9607e 100644
--- a/sys/netpfil/pf/pf.c
+++ b/sys/netpfil/pf/pf.c
@@ -388,6 +388,7 @@ SYSCTL_ULONG(_net_pf, OID_AUTO, request_maxcount, CTLFLAG_RWTUN,
     &pf_ioctl_maxcount, 0, "Maximum number of tables, addresses, ... in a single ioctl() call");
 
 VNET_DEFINE(void *, pf_swi_cookie);
+VNET_DEFINE(struct intr_event *, pf_swi_ie);
 
 VNET_DEFINE(uint32_t, pf_hashseed);
 #define	V_pf_hashseed	VNET(pf_hashseed)
diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c
index c50904e28dc6..d5e09ea1c443 100644
--- a/sys/netpfil/pf/pf_ioctl.c
+++ b/sys/netpfil/pf/pf_ioctl.c
@@ -331,7 +331,7 @@ pfattach_vnet(void)
 	for (int i = 0; i < SCNT_MAX; i++)
 		V_pf_status.scounters[i] = counter_u64_alloc(M_WAITOK);
 
-	if (swi_add(NULL, "pf send", pf_intr, curvnet, SWI_NET,
+	if (swi_add(&V_pf_swi_ie, "pf send", pf_intr, curvnet, SWI_NET,
 	    INTR_MPSAFE, &V_pf_swi_cookie) != 0)
 		/* XXXGL: leaked all above. */
 		return;
@@ -4669,7 +4669,7 @@ pf_load(void)
 static void
 pf_unload_vnet(void)
 {
-	int error;
+	int error, ret;
 
 	V_pf_vnet_active = 0;
 	V_pf_status.running = 0;
@@ -4688,7 +4688,10 @@ pf_unload_vnet(void)
 	shutdown_pf();
 	PF_RULES_WUNLOCK();
 
-	swi_remove(V_pf_swi_cookie);
+	ret = swi_remove(V_pf_swi_cookie);
+	MPASS(ret == 0);
+	ret = intr_event_destroy(V_pf_swi_ie);
+	MPASS(ret == 0);
 
 	pf_unload_vnet_purge();
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202103200959.12K9xhNm064227>