From nobody Thu Jun 20 17:55:48 2024 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 4W4p7S4z7Bz5PCk1; Thu, 20 Jun 2024 17:55:48 +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 4W4p7S4GkXz50bQ; Thu, 20 Jun 2024 17:55:48 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1718906148; 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=e5PHcZTHqZ8MONPt/c35vuf9cuIfWSBJ0Cr42aGR2cM=; b=t4zxB44xu/7xupYQe2jzt7RIUkROUXxUBQ+knGGGmiPcOwS/9OzjHKfTKJPX9CtHh3tjsl oNQkxIYwxA01AXXuVh1Iss3YyRmEkWkzNgVZZnc2kF4f5Ty1ThTMGvwe92AJ3univx8QAC HG+5B/BWL4lHVNHhkqMlY/ms1W8inoh/SEKnswvUWFeli78uv/VHAkJK2a7mIMma3C1Oqw 8R2l1Z13EzAtlShJacH1FTPZFprThkGVPWKvMOj6GbrMYCT71tuujKAzyF7NBG8MFrrYtb TJXKYFfgSgxMm/HXmS6IbtvfPv+XcDpDjNkcwPHzP9y12YcA4VnbQnifzKKoMA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1718906148; a=rsa-sha256; cv=none; b=LPkZR3ieJHyUYEWRnWmz4oGG9wWjZA4jLHZr6wbjHD0CfHqkVFwErb7Sm75XDwCYSnKu2W GJz8DHdi4uli8Tlh37mYLpWBD+7zuiFZKjX85r22DKqR0viAB0nykjtiUAOwtpQiETLn53 l/0N9XtQtlH+SGKNjFDWkp0Oohp3x1uSpy4W/ohlqrLHGF5KiIaEnJuHkL7LKlvWlBhajL LjyBd9nOeBsvIAspi8gq80b2ZfyFmcUuTOlcY6C+UPQOhs6bpM+ln/8FcWR0MLxIsMMCSM dHRqueWNbr8WM1XQLd5djCuutDHPdQTWdAg57oIsj3y2m52Ny8ekbSu/ZvpKpA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1718906148; 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=e5PHcZTHqZ8MONPt/c35vuf9cuIfWSBJ0Cr42aGR2cM=; b=AgeEwq0f4Dv2zfNC7NrfblNR7/RbqXZEBa0T/r8hIwt/rHcekJy/+rjLs5c7MQQUuzHfdt 4yp3GAy+5Sx2VQiavuMQjejPg7ha5M2Cj6jsndBXKzTeX4JyzZuKKtvYE0bxJ6fnNOSPpT xzkXfVGn9mE24llILJ2XL3P4mSU9EPBL3Yj2XlyppDRubeMbCKZafAzymL/niQA83eXy4l YErr8fjAtFoiaxL4JjqaPK8rpVfd51TzqxtY8xtGOV9ioE+DTwMsYM4UIAz9/vWeguz3W3 WtvCghuU5XHl/MJHONtyzO2V30h482eq2B2Fy0kpmIG1X2c/af87NZaUStFlKA== 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 4W4p7S3ZVWzb3s; Thu, 20 Jun 2024 17:55:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 45KHtmOC066442; Thu, 20 Jun 2024 17:55:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 45KHtmG1066439; Thu, 20 Jun 2024 17:55:48 GMT (envelope-from git) Date: Thu, 20 Jun 2024 17:55:48 GMT Message-Id: <202406201755.45KHtmG1066439@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: b6196537b012 - main - pf: fix the "keepcounters" to stop truncating to 32-bit 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: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org 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: b6196537b0125c50f25bd64ed60e1cdd635ecd34 Auto-Submitted: auto-generated The branch main has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=b6196537b0125c50f25bd64ed60e1cdd635ecd34 commit b6196537b0125c50f25bd64ed60e1cdd635ecd34 Author: Mateusz Guzik AuthorDate: 2024-06-20 17:48:52 +0000 Commit: Mateusz Guzik CommitDate: 2024-06-20 17:55:43 +0000 pf: fix the "keepcounters" to stop truncating to 32-bit The machinery to support 64-bit counters even on 32-bit kernels had a bug where it would unitentionally truncate the value back to 32-bits when transferring to a new counter. This resulted in buggy be behavior on 64-bit kernels as well. Sponsored by: Rubicon Communications, LLC ("Netgate") --- sys/net/pfvar.h | 15 +++++++++++++++ sys/netpfil/pf/pf_ioctl.c | 10 +++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h index d6d01c9b5970..62c367fe6a29 100644 --- a/sys/net/pfvar.h +++ b/sys/net/pfvar.h @@ -127,6 +127,14 @@ pf_counter_u64_critical_exit(void) critical_exit(); } +static inline void +pf_counter_u64_rollup_protected(struct pf_counter_u64 *pfcu64, uint64_t n) +{ + + MPASS(curthread->td_critnest > 0); + pfcu64->pfcu64_value += n; +} + static inline void pf_counter_u64_add_protected(struct pf_counter_u64 *pfcu64, uint32_t n) { @@ -250,6 +258,13 @@ pf_counter_u64_critical_exit(void) } +static inline void +pf_counter_u64_rollup_protected(struct pf_counter_u64 *pfcu64, uint64_t n) +{ + + counter_u64_add(pfcu64->counter, n); +} + static inline void pf_counter_u64_add_protected(struct pf_counter_u64 *pfcu64, uint32_t n) { diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c index f801afd9da80..2cb6923e1e69 100644 --- a/sys/netpfil/pf/pf_ioctl.c +++ b/sys/netpfil/pf/pf_ioctl.c @@ -1408,15 +1408,15 @@ pf_commit_rules(u_int32_t ticket, int rs_num, char *anchor) continue; } pf_counter_u64_critical_enter(); - pf_counter_u64_add_protected(&rule->evaluations, + pf_counter_u64_rollup_protected(&rule->evaluations, pf_counter_u64_fetch(&old_rule->evaluations)); - pf_counter_u64_add_protected(&rule->packets[0], + pf_counter_u64_rollup_protected(&rule->packets[0], pf_counter_u64_fetch(&old_rule->packets[0])); - pf_counter_u64_add_protected(&rule->packets[1], + pf_counter_u64_rollup_protected(&rule->packets[1], pf_counter_u64_fetch(&old_rule->packets[1])); - pf_counter_u64_add_protected(&rule->bytes[0], + pf_counter_u64_rollup_protected(&rule->bytes[0], pf_counter_u64_fetch(&old_rule->bytes[0])); - pf_counter_u64_add_protected(&rule->bytes[1], + pf_counter_u64_rollup_protected(&rule->bytes[1], pf_counter_u64_fetch(&old_rule->bytes[1])); pf_counter_u64_critical_exit(); }