From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f52.google.com (mail-ot1-f52.google.com [209.85.210.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60C7032E12E for ; Fri, 29 May 2026 13:15:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780060534; cv=none; b=V7PywfhjwMlrexf9DZNZyvZZjxXlBa4xktLj1XC59kvFOLd7cxwihE3J5+6SeMDf+2O8QjEUV0/UHW/eQ7MQSNtjYM9Xm9o9q91dpcJCKWW3BXHe72ZP/BcF3KZoRj7cOVUpC33hgDwxd2aoEK2AKkO2tbRrqhdpCx33H6V2u7A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780060534; c=relaxed/simple; bh=T8zML60x/WQFS05OCSI9D268p+fmn0DGrZ40YL0GmeE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LkLHxg9uA90UsYv07PHR41SMWMD+CnhsPzjGQ4F1PwidmpXA0PiyTg6abao8Q33MHJo6nmUislfiAAbnYG1MPkvQdNJxXIm/UQ5h3UjMYY0OywuEePbe43AZaasAC0+A6f6TvcH37hHLBZux1lXkRpK+AigCS2DLhtMN8J/pI/A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XpTBGtiv; arc=none smtp.client-ip=209.85.210.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XpTBGtiv" Received: by mail-ot1-f52.google.com with SMTP id 46e09a7af769-7e685ddb3b0so1256482a34.1 for ; Fri, 29 May 2026 06:15:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780060532; x=1780665332; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=5gpuXxi7i/5t+I/g5icZzBea2HRtsO6XMTgF5cBNBQg=; b=XpTBGtivyqgqGydVRr+AXX6zZLJyTFOd5h6QmkcgPBBT3T/Otfrktb7ljjGMi3JYPG mHlAOkFJay6BZ0aldOZUdoCShEeWFyOYQNYvtLXYNGWqoriohKalRazqKZVpl/xpaW7O OazbHJueNwdj5aVSK5xT2hOpLmJnvIP9qVxzzsGOpChqYPu96h4wvGm0ZBi3GN5RqiPU CJOjSdb+ThsJRYewEcR65LYrim+BaEzTQjIoXWbNjV0yaNGHgzvxrV73QAzPT76VEMik 3jbW/gTbMhw8LuglDhFZPZrej8rNySHV6mUgRF/ZAMqPyZI8d0y8IJsxm/fBKE8W/hZQ mAWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780060532; x=1780665332; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=5gpuXxi7i/5t+I/g5icZzBea2HRtsO6XMTgF5cBNBQg=; b=aeoT2pK87nZvrSsXpuidaH850SFmghnFBmdeAR5YupC7ANYjbDyVV1e0n6eEOBsceo VIQrmnSaYeTHHigm9AeqpKqApDTsfXiM+fzH6/MkjzatF0udDZ6XDaaCjsmGWucdPgXq BKPQbJx7jqXhud+ckQTbYJwC724wuunlEfBcORzMSZgrT0vHn8o6Jz6aHf15xTk0zs6L 6xWG6ETu1ouJ6ILIzjZgWPjaFq5G+nGexP4s58/hvadiLmNEa5TfuzRvEbHMbfB7CVec Or0nm8qHtEOUFp055nTa/QCi5jw3cHoaBxtO7kLDRXgjwX/v2tHmnA8bKrjpy98dWUFr t+5g== X-Forwarded-Encrypted: i=1; AFNElJ8TZ4LxvYVIz44si4HLfNw7QSZbKcOaBpodKB2fdmtZPgVjnXhhzEeNyUY+RmVXInvBPo56ML/QzdY7Spk=@vger.kernel.org X-Gm-Message-State: AOJu0YxFn7cuYMY8fbMtIDBNRiE4mBBf0f3scHuxb2XoheTBtFr0s36I DstmMLdggxuFIK6F44QSGmqEGK6pgWyZqDQCqixSzUy6G01Tik1Kobaz X-Gm-Gg: Acq92OEGnik301b5WcD9EPzLLowg5RP1ggWzEQYbZufDgW2Dy3zGqfP1ArqrMcZyX2U Pn/6y5UGmXv6T7ZIA0ThYSKUEZ/gzdqYjg1+5AbqCt/ghs/v6Ps/vQjInYnX+Mu5BYO4CC9+sIm svKHO/8p4EAcQWb1F2pWvXM0Gf07zJ0gUnLY8k3TUbvXjTXw4zczaMosAQ5Ed1l6ophBLHw1cMi qnnSCHf4txKZiL2TRSdHrgfnSBbUtKvVLKCPOK5tnLJ/JbWMAkNcAiPC/OPP4UTOK7VQ3vxdsfo nlKf2TWPKvUCFgdgdBwdTHWuHBsbCTb7Iy/NoiOLW5LPK2QqZFzyS6ywv4KC8lvAdsdwH8CDCqP VuLzb5jq9q2bNs/BgJW9UgUf7PPbuSRHJpmk1zKruIAvyGYQYOF7ZLWL42RyeF21VVmr+teKfGP EfcxGFpa39RhbnbgSCReKvcjpU8N/mww0= X-Received: by 2002:a05:6830:6081:b0:7dd:9b19:a87b with SMTP id 46e09a7af769-7e694c20e6dmr1950613a34.4.1780060532432; Fri, 29 May 2026 06:15:32 -0700 (PDT) Received: from localhost ([2a03:2880:10ff:59::]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e695d918cfsm1427015a34.26.2026.05.29.06.15.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2026 06:15:32 -0700 (PDT) From: Daniel Zahka Date: Fri, 29 May 2026 06:15:28 -0700 Subject: [PATCH net v2 2/2] netdevsim: psp: use atomic64 for psp stats counters Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260529-fix-psp-stats-v2-2-3a194eacf18e@gmail.com> References: <20260529-fix-psp-stats-v2-0-3a194eacf18e@gmail.com> In-Reply-To: <20260529-fix-psp-stats-v2-0-3a194eacf18e@gmail.com> To: Jakub Kicinski , Andrew Lunn , "David S. Miller" , Eric Dumazet , Paolo Abeni , Willem de Bruijn Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.13.0 The existing u64_stats_t-based psp counters had two preexisting api usage bugs: u64_stats_init() was never called on the syncp object, and the writer side of the u64_stats_update_begin()/end() api was not serialized. Switch the counters to atomic64_t instead. Atomics need no initialization and are inherently safe against concurrent writers, eliminating both bugs at once. Use atomic64_t rather than atomic_long_t so byte counters don't wrap at 4 GiB on 32-bit builds. Fixes: 178f0763c5f3 ("netdevsim: implement psp device stats") Assisted-by: Codex:gpt-5.5 Signed-off-by: Daniel Zahka --- drivers/net/netdevsim/netdevsim.h | 10 ++++------ drivers/net/netdevsim/psp.c | 24 ++++++++---------------- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index d909c4160ea1..4c9cc96dcec3 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -115,11 +114,10 @@ struct netdevsim { int rq_reset_mode; struct { - u64_stats_t rx_packets; - u64_stats_t rx_bytes; - u64_stats_t tx_packets; - u64_stats_t tx_bytes; - struct u64_stats_sync syncp; + atomic64_t rx_packets; + atomic64_t rx_bytes; + atomic64_t tx_packets; + atomic64_t tx_bytes; struct psp_dev __rcu *dev; struct dentry *rereg; struct mutex rereg_lock; diff --git a/drivers/net/netdevsim/psp.c b/drivers/net/netdevsim/psp.c index afe58b21041a..1c415b3d6f1a 100644 --- a/drivers/net/netdevsim/psp.c +++ b/drivers/net/netdevsim/psp.c @@ -50,10 +50,8 @@ nsim_do_psp(struct sk_buff *skb, struct netdevsim *ns, } psp_len = skb->len - skb_inner_transport_offset(skb); - u64_stats_update_begin(&ns->psp.syncp); - u64_stats_inc(&ns->psp.tx_packets); - u64_stats_add(&ns->psp.tx_bytes, psp_len); - u64_stats_update_end(&ns->psp.syncp); + atomic64_inc(&ns->psp.tx_packets); + atomic64_add(psp_len, &ns->psp.tx_bytes); /* Now pretend we just received this frame */ peer_psd = rcu_dereference(peer_ns->psp.dev); @@ -79,10 +77,8 @@ nsim_do_psp(struct sk_buff *skb, struct netdevsim *ns, refcount_inc(&(*psp_ext)->refcnt); skb->decrypted = 1; - u64_stats_update_begin(&peer_ns->psp.syncp); - u64_stats_inc(&peer_ns->psp.rx_packets); - u64_stats_add(&peer_ns->psp.rx_bytes, psp_len); - u64_stats_update_end(&peer_ns->psp.syncp); + atomic64_inc(&peer_ns->psp.rx_packets); + atomic64_add(psp_len, &peer_ns->psp.rx_bytes); } else { struct ipv6hdr *ip6h __maybe_unused; struct iphdr *iph; @@ -180,20 +176,16 @@ static void nsim_assoc_del(struct psp_dev *psd, struct psp_assoc *pas) static void nsim_get_stats(struct psp_dev *psd, struct psp_dev_stats *stats) { struct netdevsim *ns = psd->drv_priv; - unsigned int start; /* WARNING: do *not* blindly zero stats in real drivers! * All required stats must be reported by the device! */ memset(stats, 0, sizeof(struct psp_dev_stats)); - do { - start = u64_stats_fetch_begin(&ns->psp.syncp); - stats->rx_bytes = u64_stats_read(&ns->psp.rx_bytes); - stats->rx_packets = u64_stats_read(&ns->psp.rx_packets); - stats->tx_bytes = u64_stats_read(&ns->psp.tx_bytes); - stats->tx_packets = u64_stats_read(&ns->psp.tx_packets); - } while (u64_stats_fetch_retry(&ns->psp.syncp, start)); + stats->rx_bytes = atomic64_read(&ns->psp.rx_bytes); + stats->rx_packets = atomic64_read(&ns->psp.rx_packets); + stats->tx_bytes = atomic64_read(&ns->psp.tx_bytes); + stats->tx_packets = atomic64_read(&ns->psp.tx_packets); } static struct psp_dev_ops nsim_psp_ops = { -- 2.52.0