From owner-dev-commits-src-branches@freebsd.org Sun Jul 25 07:03:08 2021 Return-Path: Delivered-To: dev-commits-src-branches@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 3A9F7653C60; Sun, 25 Jul 2021 07:03:08 +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 4GXYt36jw9z3HVx; Sun, 25 Jul 2021 07:03:07 +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 51CBC1F531; Sun, 25 Jul 2021 07:03:07 +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 16P737I1050483; Sun, 25 Jul 2021 07:03:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 16P737a9050482; Sun, 25 Jul 2021 07:03:07 GMT (envelope-from git) Date: Sun, 25 Jul 2021 07:03:07 GMT Message-Id: <202107250703.16P737a9050482@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Guzik Subject: git: 6ee77aab15a5 - stable/13 - pf: embed a pointer to the lock in struct pf_kstate 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/stable/13 X-Git-Reftype: branch X-Git-Commit: 6ee77aab15a5351898e1ccafc2575fe602ce1af8 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 25 Jul 2021 07:03:08 -0000 The branch stable/13 has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=6ee77aab15a5351898e1ccafc2575fe602ce1af8 commit 6ee77aab15a5351898e1ccafc2575fe602ce1af8 Author: Mateusz Guzik AuthorDate: 2021-07-19 12:40:25 +0000 Commit: Mateusz Guzik CommitDate: 2021-07-25 07:00:37 +0000 pf: embed a pointer to the lock in struct pf_kstate This shaves calculation which in particular helps on arm. Note using the & hack instead would still be more work. Reviewed by: kp Sponsored by: Rubicon Communications, LLC ("Netgate") (cherry picked from commit 907257d6967dd23506e69042c55bb1edc983c0ba) --- sys/net/pfvar.h | 23 +++++++++++++++++------ sys/netpfil/pf/pf.c | 3 +++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h index 609709fbd6c5..73f3168aa31f 100644 --- a/sys/net/pfvar.h +++ b/sys/net/pfvar.h @@ -96,22 +96,32 @@ struct pfi_dynaddr { #define PF_HASHROW_LOCK(h) mtx_lock(&(h)->lock) #define PF_HASHROW_UNLOCK(h) mtx_unlock(&(h)->lock) +#ifdef INVARIANTS #define PF_STATE_LOCK(s) \ do { \ - struct pf_idhash *_ih = &V_pf_idhash[PF_IDHASH(s)]; \ - PF_HASHROW_LOCK(_ih); \ + struct pf_kstate *_s = (s); \ + struct pf_idhash *_ih = &V_pf_idhash[PF_IDHASH(_s)]; \ + MPASS(_s->lock == &_ih->lock); \ + mtx_lock(_s->lock); \ } while (0) - #define PF_STATE_UNLOCK(s) \ do { \ - struct pf_idhash *_ih = &V_pf_idhash[PF_IDHASH((s))]; \ - PF_HASHROW_UNLOCK(_ih); \ + struct pf_kstate *_s = (s); \ + struct pf_idhash *_ih = &V_pf_idhash[PF_IDHASH(_s)]; \ + MPASS(_s->lock == &_ih->lock); \ + mtx_unlock(_s->lock); \ } while (0) +#else +#define PF_STATE_LOCK(s) mtx_lock(s->lock) +#define PF_STATE_UNLOCK(s) mtx_unlock(s->lock) +#endif #ifdef INVARIANTS #define PF_STATE_LOCK_ASSERT(s) \ do { \ - struct pf_idhash *_ih = &V_pf_idhash[PF_IDHASH(s)]; \ + struct pf_kstate *_s = (s); \ + struct pf_idhash *_ih = &V_pf_idhash[PF_IDHASH(_s)]; \ + MPASS(_s->lock == &_ih->lock); \ PF_HASHROW_ASSERT(_ih); \ } while (0) #else /* !INVARIANTS */ @@ -594,6 +604,7 @@ struct pf_kstate { u_int8_t sync_state; /* PFSYNC_S_x */ u_int8_t sync_updates; /* XXX */ u_int refs; + struct mtx *lock; TAILQ_ENTRY(pf_kstate) sync_list; TAILQ_ENTRY(pf_kstate) key_list[2]; LIST_ENTRY(pf_kstate) entry; diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 7b4c99c9a799..c47a0098550d 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -1058,6 +1058,9 @@ pf_state_key_attach(struct pf_state_key *skw, struct pf_state_key *sks, kh = khw; idx = PF_SK_WIRE; + MPASS(s->lock == NULL); + s->lock = &V_pf_idhash[PF_IDHASH(s)].lock; + keyattach: LIST_FOREACH(cur, &kh->keys, entry) if (bcmp(cur, sk, sizeof(struct pf_state_key_cmp)) == 0)