From owner-dev-commits-src-all@freebsd.org Mon Jun 28 15:49:25 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 1217365805F; Mon, 28 Jun 2021 15:49:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4GDBqm6wbVz3PpL; Mon, 28 Jun 2021 15:49:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id D5E9A4D; Mon, 28 Jun 2021 15:49:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 15SFnOtD016052; Mon, 28 Jun 2021 15:49:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 15SFnOvQ016051; Mon, 28 Jun 2021 15:49:24 GMT (envelope-from git) Date: Mon, 28 Jun 2021 15:49:24 GMT Message-Id: <202106281549.15SFnOvQ016051@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mateusz Guzik Subject: git: d09388d01330 - main - pf: add pf_release_staten and use it in pf_unlink_state MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d09388d013300fc4aa1ee1a6bc24260cd400aff3 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Jun 2021 15:49:25 -0000 The branch main has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=d09388d013300fc4aa1ee1a6bc24260cd400aff3 commit d09388d013300fc4aa1ee1a6bc24260cd400aff3 Author: Mateusz Guzik AuthorDate: 2021-06-28 12:18:43 +0000 Commit: Mateusz Guzik CommitDate: 2021-06-28 15:49:20 +0000 pf: add pf_release_staten and use it in pf_unlink_state Saves one atomic op. Reviewed by: kp Sponsored by: Rubicon Communications, LLC ("Netgate") --- sys/net/pfvar.h | 11 +++++++++++ sys/netpfil/pf/pf.c | 7 ++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h index e07016f7b66c..9578ec0a701f 100644 --- a/sys/net/pfvar.h +++ b/sys/net/pfvar.h @@ -1510,6 +1510,17 @@ pf_release_state(struct pf_state *s) return (0); } +static __inline int +pf_release_staten(struct pf_state *s, u_int n) +{ + + if (refcount_releasen(&s->refs, n)) { + pf_free_state(s); + return (1); + } else + return (0); +} + extern struct pf_state *pf_find_state_byid(uint64_t, uint32_t); extern struct pf_state *pf_find_state_all(struct pf_state_key_cmp *, u_int, int *); diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 7e187a358783..02d0809f738d 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -1732,11 +1732,8 @@ pf_unlink_state(struct pf_state *s, u_int flags) PF_HASHROW_UNLOCK(ih); pf_detach_state(s); - /* pf_state_insert() initialises refs to 2, so we can never release the - * last reference here, only in pf_release_state(). */ - (void)refcount_release(&s->refs); - - return (pf_release_state(s)); + /* pf_state_insert() initialises refs to 2 */ + return (pf_release_staten(s, 2)); } void