git: 1882bdd192bc - stable/13 - pf: getstates: avoid taking the hashrow lock if the row is empty

Kristof Provost kp at FreeBSD.org
Fri Jul 9 13:24:27 UTC 2021


The branch stable/13 has been updated by kp:

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

commit 1882bdd192bc406459dda00dda7246bb2f56b66c
Author:     Kristof Provost <kp at FreeBSD.org>
AuthorDate: 2021-06-29 09:34:49 +0000
Commit:     Kristof Provost <kp at FreeBSD.org>
CommitDate: 2021-07-09 08:08:32 +0000

    pf: getstates: avoid taking the hashrow lock if the row is empty
    
    Reviewed by:    mjg
    MFC after:      1 week
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
    Differential Revision:  https://reviews.freebsd.org/D30946
    
    (cherry picked from commit a19ff8ce9b58548a5f965db2c46eb03c38b15edb)
---
 sys/netpfil/pf/pf_ioctl.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c
index 0097d8b0f6b6..2e332156a488 100644
--- a/sys/netpfil/pf/pf_ioctl.c
+++ b/sys/netpfil/pf/pf_ioctl.c
@@ -5055,6 +5055,10 @@ pf_getstates(struct pfioc_nv *nv)
 	for (int i = 0; i < pf_hashmask; i++) {
 		struct pf_idhash *ih = &V_pf_idhash[i];
 
+		/* Avoid taking the lock if there are no states in the row. */
+		if (LIST_EMPTY(&ih->states))
+			continue;
+
 		PF_HASHROW_LOCK(ih);
 		LIST_FOREACH(s, &ih->states, entry) {
 			if (s->timeout == PFTM_UNLINKED)


More information about the dev-commits-src-all mailing list