From owner-dev-commits-src-main@freebsd.org Tue Jul 20 16:53:49 2021 Return-Path: Delivered-To: dev-commits-src-main@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 6660566F9C6; Tue, 20 Jul 2021 16:53:49 +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 4GTlCx2JGpz57N5; Tue, 20 Jul 2021 16:53:49 +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 2BE7B651F; Tue, 20 Jul 2021 16:53:49 +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 16KGrnnP008617; Tue, 20 Jul 2021 16:53:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 16KGrnJ3008616; Tue, 20 Jul 2021 16:53:49 GMT (envelope-from git) Date: Tue, 20 Jul 2021 16:53:49 GMT Message-Id: <202107201653.16KGrnJ3008616@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: 907257d6967d - main - 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/main X-Git-Reftype: branch X-Git-Commit: 907257d6967dd23506e69042c55bb1edc983c0ba Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Jul 2021 16:53:49 -0000 The branch main has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=907257d6967dd23506e69042c55bb1edc983c0ba commit 907257d6967dd23506e69042c55bb1edc983c0ba Author: Mateusz Guzik AuthorDate: 2021-07-19 12:40:25 +0000 Commit: Mateusz Guzik CommitDate: 2021-07-20 16:11:31 +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") --- 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 35f906a8cbb2..70fde0aa7380 100644 --- a/sys/net/pfvar.h +++ b/sys/net/pfvar.h @@ -99,22 +99,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 */ @@ -602,6 +612,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 6fdeab517792..4729e7a5c19f 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -1045,6 +1045,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)