Received: by 2002:ab2:744d:0:b0:1fb:9c95:a417 with SMTP id f13csp560305lqn; Wed, 5 Jun 2024 14:55:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXI9xkLhUZj2aOTQPGWjNlEUKWetRcBVEmJKHbm5tXUX9gOPDUVJb/tmNfndIhfYzqV77W74DRmnCqICUE70Vo0Sx1UL3m2uCExAeWH7w== X-Google-Smtp-Source: AGHT+IEPIRjvJIQM7st1YWPWvaKI3WOLXvbTAroX8si0DkDZNXTMmHdL5pHqGdMH2I2tNXjUJvFZ X-Received: by 2002:ac8:58d0:0:b0:43a:d7ca:ce9d with SMTP id d75a77b69052e-4402b5f4501mr37599641cf.27.1717624531687; Wed, 05 Jun 2024 14:55:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717624531; cv=pass; d=google.com; s=arc-20160816; b=ZbhBCW1r7HqYMDHpFBBp2aTTeDNKFxkdxHGT+UEk9NI01wluogJBgBFDFgUhuapOOm GD/PJ4Kl85J1MECLvwsXf9PRrkkFYKeFtk904a48U6SLXxs0Q7aeuO2h7lDqCfjrCjLZ VxGpApe0A85u+Pl8VbqupoXTthbHflgMGcZvL7wRIJ2ZXYlNTacq11ugprb8BL+7FNO3 DmaL6xZG2stVt6XGKJ6Lw0Jfa6msTdVeDl24j+nx1AMNLTVGzwRn6VeORB2bA34ejDOG Tz9lb/LlWXX6LgjN/s+4gHBkcf7/MymQSABQEDHa2oABds+TgiTX5XmUh4CEPpm3vHoI 7YWQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=ZV6Lkl8TnoF8BuIaryKVon5GWIOQyEZj6XsfC7CIoHI=; fh=QZlbTHUUZbxTOCOJVVm5UBu9mrJ1Y8li+hV2ofMLWhc=; b=NgiwPKnXzNqTPuUtAV0pPLRskpGESw21oCtwC4m1FwjwnCkEFaVauL1izVXoVR1v9W Sf8O1qqgUVq7umPX9ZQU5KAd4/qeTcxxE4G4sZmvcGcCu9Z3z9QAwM6Fi4rSpZtYAR3d YwbcRZJTdcjwow+jn1SR8E4elecf505+TBBZqeUyjohpmLN6nRVJ8N91VbCIKdWmxH5U 0Mx6b8vsr7yB7zLWPHI33o9kjPfEQey82Et/Unw9hsqhUvRiARqCtmFTLwFhKs444ZYH u5y9mVjGkJwFwz25keOhcy6MQBcP17+6A5qUBZBwfQqvHkzFRQCTFP/QDCxM89xrfC2P 4xqA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EtPtG6Nx; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-203327-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-203327-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-44038a6dadasi872151cf.118.2024.06.05.14.55.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 14:55:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-203327-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EtPtG6Nx; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-203327-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-203327-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 4256C1C223BA for ; Wed, 5 Jun 2024 21:55:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 61D6515FA81; Wed, 5 Jun 2024 21:55:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EtPtG6Nx" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B34C71581E2 for ; Wed, 5 Jun 2024 21:55:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717624517; cv=none; b=ja4tLGBzC6/ekCkgC+sWZQR6l/X1Kk/2daGG1VWsuf2EyDYBwCZuuWulNNZ5vI2UPCPp0xJ5lioE/+dLzTslbTtQp7/Rpa+T6BZ0Zcm/eaIzHjua1Q3FD4rJNHs8VSSLw1cft1uKvDuOxcme58KlBpSaCFah3s3jRKvJk6ie2IE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717624517; c=relaxed/simple; bh=UZPbW0IR5w36PFk3ukWzR4v3+jjQ/ha9eGYPOLhBOWo=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=kNr+sLAQmI7AD2Ga9j9NVSP4mbFx95HXR9L+GI0L9BXj0A/BtsgHUJYjPscn/+12tfmnH+wH+3jvq45rRgNyuLM/icg61ewZ1/ZbjiUmulSk03IZZXBm1RIjhOqWLbyJ6vQxH9P7r19Hc9H0jxrw77NBFcaeUy2KEp5J50NSe20= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=EtPtG6Nx; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717624514; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZV6Lkl8TnoF8BuIaryKVon5GWIOQyEZj6XsfC7CIoHI=; b=EtPtG6Nx7YmutKEgnMOg5l5TCw73CjITfEsGhwlE+CWZJkxtpVT2TUhnW5oGZFZjUZHTQ+ GIMhmkrBDLco44aGYPlLE0TbYJPPgk3netlaNxHt2VJdc/ydadoxnvVst/wYtzaa8/kVbh /JFllWzv5BsEcWyF6NKAiuq6rvkfaL4= Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-303-D44O-iXYMpqSm3GPLGRqZg-1; Wed, 05 Jun 2024 17:55:12 -0400 X-MC-Unique: D44O-iXYMpqSm3GPLGRqZg-1 Received: by mail-lf1-f70.google.com with SMTP id 2adb3069b0e04-52b84359026so216764e87.0 for ; Wed, 05 Jun 2024 14:55:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717624511; x=1718229311; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZV6Lkl8TnoF8BuIaryKVon5GWIOQyEZj6XsfC7CIoHI=; b=FqvVfiOkVaNHLBMHnSNs9FYDal4Rdk/aYMENPzq7JgolgdqH7udTtL94Ha81bNCJVb wAOFXjQjmfoX2AHlKqALzrPskqcx7JPWLdHAfxgkfgp/3t7dihvyj8IWUPCBdaHv7U4U 4Bztm/ShAklH/yU3mr5GfGnwWnDtftuhXLoigwQ+KYR3GMsqoO791zM3Rwkb0Uhc/HD8 GwYKaR536c1XAax8ztZ0kDVYjoXEmP/EF3vjW5ffHtzPxzFxdQssRvCK6nJSv98O81af TCRyLVrdjerrPXfeQ4kPF7WdPUTeDzWEFblo4yGTLRWZQQZvQZJcPTu50RXJP7NIxvj3 Sbjw== X-Forwarded-Encrypted: i=1; AJvYcCWXVSzIVN84pe9w7i/s0NbhOONF2DaTzu9Re6bxFuFK1Wccw4i8MS33W/jisOXXxussECZUccvzwL0xJ9Sa9JvCz5VuPe+a5xMKqDpR X-Gm-Message-State: AOJu0YypQ1xeG2jL4R+8bgLaWexbjA2D7NCDKMo3Ajnq45L/Xk0elwBW Gnlui5h8BjBImZn9jjCJTw7UZBm8h0OZ/3I/fW99gogmZ9ncVPD2DhwZW1TOjNjv9vvHC1ACHiw cLsH7sS5N1ny6J1ZOPQfP6WT49IoG+oIJv/IJ7frCGlEH57wuJndbLXQVW02UioAA6Wo5DtALQo R6t32mmXNWY+E1T2rM7ASbp++s49fyFYr2VDw+R1opd/LJ X-Received: by 2002:a2e:b0cd:0:b0:2e0:aaaa:e551 with SMTP id 38308e7fff4ca-2eac7a526fbmr24710251fa.37.1717624510868; Wed, 05 Jun 2024 14:55:10 -0700 (PDT) X-Received: by 2002:a2e:b0cd:0:b0:2e0:aaaa:e551 with SMTP id 38308e7fff4ca-2eac7a526fbmr24710171fa.37.1717624510451; Wed, 05 Jun 2024 14:55:10 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240531080739.2608969-1-jiangyunshui@kylinos.cn> <41e4b0e3-ecc0-43ca-a6cd-4a6beb0ceb8f@datenfreihafen.org> <20240603165543.46c7d3b4@kernel.org> In-Reply-To: From: Alexander Aring Date: Wed, 5 Jun 2024 17:54:59 -0400 Message-ID: Subject: Re: [PATCH] net: mac802154: Fix racy device stats updates by DEV_STATS_INC() and DEV_STATS_ADD() To: Stefan Schmidt Cc: Jakub Kicinski , Yunshui Jiang , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-wpan@vger.kernel.org, alex.aring@gmail.com, miquel.raynal@bootlin.com, davem@davemloft.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, On Wed, Jun 5, 2024 at 4:02=E2=80=AFPM Stefan Schmidt wrote: > > Hello Jakub, Alex, > > On 04.06.24 15:52, Alexander Aring wrote: > > Hi, > > > > On Mon, Jun 3, 2024 at 7:56=E2=80=AFPM Jakub Kicinski = wrote: > >> > >> On Mon, 3 Jun 2024 11:33:28 +0200 Stefan Schmidt wrote: > >>> Hello. > >>> > >>> On 31.05.24 10:07, Yunshui Jiang wrote: > >>>> mac802154 devices update their dev->stats fields locklessly. Therefo= re > >>>> these counters should be updated atomically. Adopt SMP safe DEV_STAT= S_INC() > >>>> and DEV_STATS_ADD() to achieve this. > >>>> > >>>> Signed-off-by: Yunshui Jiang > >>>> --- > >>>> net/mac802154/tx.c | 8 ++++---- > >>>> 1 file changed, 4 insertions(+), 4 deletions(-) > >>>> > >>>> diff --git a/net/mac802154/tx.c b/net/mac802154/tx.c > >>>> index 2a6f1ed763c9..6fbed5bb5c3e 100644 > >>>> --- a/net/mac802154/tx.c > >>>> +++ b/net/mac802154/tx.c > >>>> @@ -34,8 +34,8 @@ void ieee802154_xmit_sync_worker(struct work_struc= t *work) > >>>> if (res) > >>>> goto err_tx; > >>>> > >>>> - dev->stats.tx_packets++; > >>>> - dev->stats.tx_bytes +=3D skb->len; > >>>> + DEV_STATS_INC(dev, tx_packets); > >>>> + DEV_STATS_ADD(dev, tx_bytes, skb->len); > >>>> > >>>> ieee802154_xmit_complete(&local->hw, skb, false); > >>>> > >>>> @@ -90,8 +90,8 @@ ieee802154_tx(struct ieee802154_local *local, stru= ct sk_buff *skb) > >>>> if (ret) > >>>> goto err_wake_netif_queue; > >>>> > >>>> - dev->stats.tx_packets++; > >>>> - dev->stats.tx_bytes +=3D len; > >>>> + DEV_STATS_INC(dev, tx_packets); > >>>> + DEV_STATS_ADD(dev, tx_bytes, len); > >>>> } else { > >>>> local->tx_skb =3D skb; > >>>> queue_work(local->workqueue, &local->sync_tx_work); > >>> > >>> This patch has been applied to the wpan tree and will be > >>> part of the next pull request to net. Thanks! > >> > >> Hi! I haven't looked in detail, but FWIW > >> > >> $ git grep LLTX net/mac802154/ > >> $ > >> > >> and similar patch from this author has been rejected: > >> > >> https://lore.kernel.org/all/CANn89iLPYoOjMxNjBVHY7GwPFBGuxwRoM9gZZ-fWU= UYFYjM1Uw@mail.gmail.com/ > > > > In the case of ieee802154_tx() yes the tx lock is held so it's like > > what the mentioned link says. The workqueue is an ordered workqueue > > and you either have the driver async xmit option (the preferred > > option) or the driver sync xmit callback on a per driver (implies per > > interface) basis. > > When I reviewed and applied this I did indeed not realize the ordered > workqueue making this unnecessary. > > > I also don't see why there is currently a problem with the current > > non-atomic way. > > For me this looks more like a wrapper that could avoid future problems > for no cost. I would not mind if the patch stays. But you are right, its > not strictly needed. Want me to back it out again? it's fine for me. I think atomic ops, depending on $ARCH will mess up your pipelines in some kind of way but it is better than using locks of course (but locks are here required for other things). - Alex