From patchwork Thu Aug 22 10:18:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pablo Neira Ayuso X-Patchwork-Id: 13773178 X-Patchwork-Delegate: kuba@kernel.org Received: from mail.netfilter.org (mail.netfilter.org [217.70.188.207]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B0A5D171088; Thu, 22 Aug 2024 10:18:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.188.207 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724321932; cv=none; b=O1r04IwDYVP+Hec6wVukYMTZuZYh4uqOwjwFtf6VvTteZQIO77APFCsj3VCxz1QP01pI3+CnA0j8GJ7BHnihJkK3pbElfaC3rNleAUjhKn40umhkiONdKtS0gzDiZ5SB+lI3zkR9ZWc6MVL2o/kKzi/6JViYagrqMJrYBAcaPgE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724321932; c=relaxed/simple; bh=etJO3Ha7lLG9pn1A/BVGGok6ikAhRfZhc0BKw5J7844=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Nwm/PlVkC/nJBqR34wqRA4N6Kxu1w/InfOfQ6Ha1hIxKHtIhLX+Xvh4HTH+we7EoAV5SqPfrWRKBJXnEglhe0gonkxfeinWVZLCkMnZsIh1l9PBZ+lKABzO/8FACMX8+tbfoeS/4c3R9niwmqCxyl/wKt003WzKsrn7e+TAITCs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=netfilter.org; spf=pass smtp.mailfrom=netfilter.org; arc=none smtp.client-ip=217.70.188.207 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=netfilter.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=netfilter.org From: Pablo Neira Ayuso To: netfilter-devel@vger.kernel.org Cc: davem@davemloft.net, netdev@vger.kernel.org, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, fw@strlen.de Subject: [PATCH net 2/3] netfilter: nft_counter: Synchronize nft_counter_reset() against reader. Date: Thu, 22 Aug 2024 12:18:41 +0200 Message-Id: <20240822101842.4234-3-pablo@netfilter.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240822101842.4234-1-pablo@netfilter.org> References: <20240822101842.4234-1-pablo@netfilter.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Sebastian Andrzej Siewior nft_counter_reset() resets the counter by subtracting the previously retrieved value from the counter. This is a write operation on the counter and as such it requires to be performed with a write sequence of nft_counter_seq to serialize against its possible reader. Update the packets/ bytes within write-sequence of nft_counter_seq. Fixes: d84701ecbcd6a ("netfilter: nft_counter: rework atomic dump and reset") Signed-off-by: Sebastian Andrzej Siewior Reviewed-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nft_counter.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/netfilter/nft_counter.c b/net/netfilter/nft_counter.c index 16f40b503d37..eab0dc66bee6 100644 --- a/net/netfilter/nft_counter.c +++ b/net/netfilter/nft_counter.c @@ -107,11 +107,16 @@ static void nft_counter_reset(struct nft_counter_percpu_priv *priv, struct nft_counter *total) { struct nft_counter *this_cpu; + seqcount_t *myseq; local_bh_disable(); this_cpu = this_cpu_ptr(priv->counter); + myseq = this_cpu_ptr(&nft_counter_seq); + + write_seqcount_begin(myseq); this_cpu->packets -= total->packets; this_cpu->bytes -= total->bytes; + write_seqcount_end(myseq); local_bh_enable(); }