From nobody Mon Dec 06 12:25:48 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 70B1318CA4FA; Mon, 6 Dec 2021 12:25: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 4J72hX31bZz3GgF; Mon, 6 Dec 2021 12:25:48 +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 2BEA03B67; Mon, 6 Dec 2021 12:25:48 +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 1B6CPm3P048189; Mon, 6 Dec 2021 12:25:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1B6CPmPc048188; Mon, 6 Dec 2021 12:25:48 GMT (envelope-from git) Date: Mon, 6 Dec 2021 12:25:48 GMT Message-Id: <202112061225.1B6CPmPc048188@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: 41c4f1987243 - main - pfsync: locking fixes List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 41c4f1987243cefe81adcc31d5401e7a80a0428c Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1638793548; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ZiiW9JrPIaFcy4UTmeO9yQ4cJSXQMPhCsl2zb1+OMwA=; b=bzOImAbzUVoTbj83SH6RjS6TNCatX22UeJI4a2srz4TdqWwDuNfadObCMImvYegXUMI4cr N0IieGQ/2GG6xmhVjITjW2vgliLWAq7aJnXDDUEnrCR/GSKVJ21RF5SDo0Ub7r2auH8t0i nOzfRIYbDFbaN0c6AinNm4N3N3h9SzBZ6g0eft5NQVF+9Pyr2QM+skp2I3B4kXviwFW+XI R1CUVsmy34trOSgIUS1k4djoPjKy3y9JamYde+DrtdSgooKP/fAgtIoj5Od5UH6qvgoW5P lIrJCzDaFkummUZaxg3moxOvy+R8qSZLNs2IeClH5ebno6ReqF2P+tRv3YvWRw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1638793548; a=rsa-sha256; cv=none; b=Fo99hAmCi6AMJ+jgqaaa5wD0prmV2XtZ1VZ7yiG/HFcI//wLOyxQy9B9bYslYJi//ceCzx us2WUKWXE/0Hu2oJPlfqzZ41wLgwGKvz9OYnlgtORqukBY63/61Y9Pg5zyUI9FSDLy2zse RqMkiNjPRgkve5UpBPFfchG9/Q9GGQGV/Y+9raxnRfGnWDvN9T1ixVp5Wh80+iF4oa/ywZ sNUcv1ZUBtqaC0qZmyPnEGj/7jEjROp9ZZYjefr/kgG8zmysqVj0tKUyGloxC4s/o1I/ca UdqyMIRIQ47/agzRPmnu4ArDNJIgDldtf1q5YE4X6g5lLIhTTPrVniXr78tAQg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=41c4f1987243cefe81adcc31d5401e7a80a0428c commit 41c4f1987243cefe81adcc31d5401e7a80a0428c Author: Kristof Provost AuthorDate: 2021-12-02 16:42:56 +0000 Commit: Kristof Provost CommitDate: 2021-12-06 12:25:14 +0000 pfsync: locking fixes * Ensure we unlock the pfsync lock in pfsync_defer() * We must hold the bucket lock when calling pfsync_push() * The pfsync_defer_tmo() callout locks the bucket lock, not the pfsync lock Reviewed by: glebius MFC after: 1 week Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D33243 --- sys/netpfil/pf/if_pfsync.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sys/netpfil/pf/if_pfsync.c b/sys/netpfil/pf/if_pfsync.c index 244e619bbe46..918516940ee8 100644 --- a/sys/netpfil/pf/if_pfsync.c +++ b/sys/netpfil/pf/if_pfsync.c @@ -1751,12 +1751,17 @@ pfsync_defer(struct pf_kstate *st, struct mbuf *m) return (0); } + PFSYNC_BUCKET_LOCK(b); + PFSYNC_UNLOCK(sc); + if (b->b_deferred >= 128) pfsync_undefer(TAILQ_FIRST(&b->b_deferrals), 0); pd = malloc(sizeof(*pd), M_PFSYNC, M_NOWAIT); - if (pd == NULL) + if (pd == NULL) { + PFSYNC_BUCKET_UNLOCK(b); return (0); + } b->b_deferred++; m->m_flags |= M_SKIP_FIREWALL; @@ -1773,6 +1778,7 @@ pfsync_defer(struct pf_kstate *st, struct mbuf *m) callout_reset(&pd->pd_tmo, PFSYNC_DEFER_TIMEOUT, pfsync_defer_tmo, pd); pfsync_push(b); + PFSYNC_BUCKET_UNLOCK(b); return (1); } @@ -1821,7 +1827,7 @@ pfsync_defer_tmo(void *arg) pd->pd_st->state_flags &= ~PFSTATE_ACK; /* XXX: locking! */ if (pd->pd_refs == 0) free(pd, M_PFSYNC); - PFSYNC_UNLOCK(sc); + PFSYNC_BUCKET_UNLOCK(b); ip_output(m, NULL, NULL, 0, NULL, NULL);