Date: Sun, 25 Jul 2021 07:03:07 GMT From: Mateusz Guzik <mjg@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 6ee77aab15a5 - stable/13 - pf: embed a pointer to the lock in struct pf_kstate Message-ID: <202107250703.16P737a9050482@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=6ee77aab15a5351898e1ccafc2575fe602ce1af8 commit 6ee77aab15a5351898e1ccafc2575fe602ce1af8 Author: Mateusz Guzik <mjg@FreeBSD.org> AuthorDate: 2021-07-19 12:40:25 +0000 Commit: Mateusz Guzik <mjg@FreeBSD.org> 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)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202107250703.16P737a9050482>