From nobody Sat Oct 08 16:41:29 2022 X-Original-To: dev-commits-src-main@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 4Ml9tK4ryQz4V4vb; Sat, 8 Oct 2022 16:41:29 +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 4Ml9tK4PTmz42vD; Sat, 8 Oct 2022 16:41:29 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1665247289; 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=8Qe1e0Rnt7NxJFjj2zE/grLiVOyCSu1gH/UF3Ubx8hA=; b=XWIyt/mvKVl657xvTo8KdJp+L5esANxmS14yUxwbW59EUdH7oHFsIlHRkVrlPIx2ckTyKX 7EwA5Ka2Rpx6PRy+oFGLjrwS4i52oyLpFmwODRw5s6pYgFt2a1ejx1FV7dkGH/gqtl9yTY XLTLGWxb4KzIte0TJdmthb5cycOmjsLCvD/m6cn1WJ1dBwSdm2FAAVho33GailIUIOPluG k3KoCS2vq99dG0VlbcvPoImoRRdLIJzu2fF1Xf9Yigu5F/EXqssbj0ORNXhbTSYWQrjgEc r6vnhvmk78zuVn3PqsCBwdEBU5/t3x4ggWbteHRuOKmvHJTAScT4blUq6xDmnQ== 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 4Ml9tK3TkLz10w2; Sat, 8 Oct 2022 16:41:29 +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 298GfTnO036985; Sat, 8 Oct 2022 16:41:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 298GfT2F036984; Sat, 8 Oct 2022 16:41:29 GMT (envelope-from git) Date: Sat, 8 Oct 2022 16:41:29 GMT Message-Id: <202210081641.298GfT2F036984@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: 133935d26f20 - main - pf: atomically increment state ids List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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: 133935d26f20c0b9c433da9a2b32bcbe562bc2c5 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1665247289; 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=8Qe1e0Rnt7NxJFjj2zE/grLiVOyCSu1gH/UF3Ubx8hA=; b=cYtl32He3mEfNwazAK38lyjcjTHMAbUNnUBtgJduc684koX707W9bSwfTxDIHlVdJbIypT PZ5br3OlW3ygxDxjypgnZDdTY1jrCiFFFVsLGpi7fovhTJk4TXALxy8JH3vGl6WnAw2cZQ ngMOH170RjZtLTWou12tnP9G/0ZQI1L99FKXjJww8LJWTskbv7iW34DkSJ3iTz7/sXzvCA Kfd1+Ck497MeuT6kw+kY2bQqkIvRP1pEMBv9QbgQdzpaHStoFqrj8UTj1u63PV7av8CGhN Ck/Qm5BBdsan7ucE9pjsTt+gv0HMkMQLzJziptIKWEfTGORXWU7agj0/D2PAOQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1665247289; a=rsa-sha256; cv=none; b=yRGs19Ct3SLB5ixB7kZaVYqWypicRTpHiQwQTBJkUVJhgc5GoK69NqAZdfvyDiYMvF6iy+ 5LfINyHf6YTc0y/cVIQAI0a/1ECJueQBc5Pdzylzo6/WCpm9NF5DI0G1zS4L69FAmbPcEv latMoA2FArXs8bdJAPqTbKCS0jaEzmlq/m6gbJ+8tAxO549lKXz7CE4UGJjZoae4aVxukI UT4b2KlOvxNoaGuF/bQYqNAKLMVQ8ZTmktus8stWr7uQJBnKo8QH9eHjy1tjoAym7wmk7y ZdPx7ZG4cje8vgTg8DplvH1nQj/oyFSOEGYb69Y+dQID/4IxxlDRs2ZiN9yXWQ== 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=133935d26f20c0b9c433da9a2b32bcbe562bc2c5 commit 133935d26f20c0b9c433da9a2b32bcbe562bc2c5 Author: Kristof Provost AuthorDate: 2022-10-07 17:17:06 +0000 Commit: Kristof Provost CommitDate: 2022-10-08 16:27:29 +0000 pf: atomically increment state ids Rather than using a per-cpu state counter, and adding in the CPU id we can atomically increment the number. This has the advantage of removing the assumption that the CPU ID fits in 8 bits. Event: Aberdeen Hackathon 2022 Reviewed by: mjg Differential Revision: https://reviews.freebsd.org/D36915 --- sys/net/pfvar.h | 2 +- sys/netpfil/pf/pf.c | 12 ++---------- sys/netpfil/pf/pf_ioctl.c | 6 +----- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h index 16ee0b55e2e8..3773a797776d 100644 --- a/sys/net/pfvar.h +++ b/sys/net/pfvar.h @@ -1987,7 +1987,7 @@ VNET_DECLARE(void *, pf_swi_cookie); VNET_DECLARE(struct intr_event *, pf_swi_ie); #define V_pf_swi_ie VNET(pf_swi_ie) -VNET_DECLARE(uint64_t, pf_stateid[MAXCPU]); +VNET_DECLARE(struct unrhdr64, pf_stateid); #define V_pf_stateid VNET(pf_stateid) TAILQ_HEAD(pf_altqqueue, pf_altq); diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index 33ef5119ee3c..2a6efbfe6e7d 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -249,12 +249,7 @@ uma_zone_t pf_mtag_z; VNET_DEFINE(uma_zone_t, pf_state_z); VNET_DEFINE(uma_zone_t, pf_state_key_z); -VNET_DEFINE(uint64_t, pf_stateid[MAXCPU]); -#define PFID_CPUBITS 8 -#define PFID_CPUSHIFT (sizeof(uint64_t) * NBBY - PFID_CPUBITS) -#define PFID_CPUMASK ((uint64_t)((1 << PFID_CPUBITS) - 1) << PFID_CPUSHIFT) -#define PFID_MAXID (~PFID_CPUMASK) -CTASSERT((1 << PFID_CPUBITS) >= MAXCPU); +VNET_DEFINE(struct unrhdr64, pf_stateid); static void pf_src_tree_remove_state(struct pf_kstate *); static void pf_init_threshold(struct pf_threshold *, u_int32_t, @@ -1416,10 +1411,7 @@ pf_state_insert(struct pfi_kkif *kif, struct pfi_kkif *orig_kif, s->orig_kif = orig_kif; if (s->id == 0 && s->creatorid == 0) { - /* XXX: should be atomic, but probability of collision low */ - if ((s->id = V_pf_stateid[curcpu]++) == PFID_MAXID) - V_pf_stateid[curcpu] = 1; - s->id |= (uint64_t )curcpu << PFID_CPUSHIFT; + s->id = alloc_unr64(&V_pf_stateid); s->id = htobe64(s->id); s->creatorid = V_pf_status.hostid; } diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c index 67422cc43997..e7a5bb084ee5 100644 --- a/sys/netpfil/pf/pf_ioctl.c +++ b/sys/netpfil/pf/pf_ioctl.c @@ -2595,16 +2595,12 @@ pfioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flags, struct thread *td if (V_pf_status.running) error = EEXIST; else { - int cpu; - hook_pf(); if (! TAILQ_EMPTY(V_pf_keth->active.rules)) hook_pf_eth(); V_pf_status.running = 1; V_pf_status.since = time_second; - - CPU_FOREACH(cpu) - V_pf_stateid[cpu] = time_second; + new_unrhdr64(&V_pf_stateid, time_second); DPFPRINTF(PF_DEBUG_MISC, ("pf: started\n")); }