Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp531256lqr; Wed, 5 Jun 2024 13:02:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUxvz8n8ctXiFltS36onyKFalZCgMAmErAU6PvFnwNpCQ9a+T/CdU4snxJqB41bggEoz3nPtfIiRZBKs5ja4reYqDMQOi4Bm/RBSu7QYg== X-Google-Smtp-Source: AGHT+IGQIhcZQti9CY1hgKnEVy4W2XsIeh3Br9GT2yy3oHNlh4LPSTrPxARU47H5zyJOtANdqAJy X-Received: by 2002:a17:906:ee89:b0:a68:379d:d623 with SMTP id a640c23a62f3a-a699fac0c4amr261795866b.36.1717617768951; Wed, 05 Jun 2024 13:02:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717617768; cv=pass; d=google.com; s=arc-20160816; b=laUGOgcbl6SRn4gMiD2CwsgdlS8yn6LaTGI+0oOG2gHmmUrAv8X81iplUOEVVi3uvX 14YnEquqmkiU1JZkmT1kWhaHk46DdxA3+aDOFFyZAMX97nheRhN4RLu5hPFruigq4v9H nUA5Opj0M+MojmrivdxIOO5nJA5dPJbjSPZjmVtFPEhE15WgL0Ik0ClKJp5uZLEwz9Sk w0TyvDa7kRqCw0JvOnrfKA16tIH3Lp7Emd7yx56bqv8SshrToHuZn/egx0/m2XeweiNv a+/XHMeldntCF9GNvj77U/NgbIt3OgG2nNKxF8Uo9tKeNExOzQYt9333Q3xkUtbp+wTn R1FQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=R/hTIr21CahD0Nu7VkQW1QMjCpyJixUIEnztFvdZHlg=; fh=Wnniliyve/4d2/f50svpiATBoWVgTQAN5Mi6JCtPBoA=; b=vUpy0BDySjQx41SuTbB7Y2dDB0NyWu0/+If7Nx7OEYC20AwbrJOvCwK6JzGZguxNIT ybDt//uZip4r5uSAx8+w/waY3sCGgumJ6+0ZFlID/KS3w8rq6WGN2i4yAeZvBv4Ghpjh FNWkMaeLOyhXCmalp3ugZwRebRKkIPLXeYoszetD0Jvrg8KwpXtrg5G/a99tQkOaSvMq EoUKW//0LR7M6pBupwIYwTw5ZPiZbyyfcUgzG5X2RK+jy4HUvRhmLtTV0po13SAje95h JsUVBGjg+pf/Ro2GRER/RX8pS3B5wUTkMr9u2sxHYQwhaiLIIWwq7dHkRokzV54EIJC2 i0KA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@datenfreihafen.org header.s=2021 header.b=MW3QTbSw; arc=pass (i=1 spf=pass spfdomain=datenfreihafen.org dkim=pass dkdomain=datenfreihafen.org); spf=pass (google.com: domain of linux-kernel+bounces-203142-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-203142-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a68b701d69csi511860466b.518.2024.06.05.13.02.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 13:02:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-203142-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@datenfreihafen.org header.s=2021 header.b=MW3QTbSw; arc=pass (i=1 spf=pass spfdomain=datenfreihafen.org dkim=pass dkdomain=datenfreihafen.org); spf=pass (google.com: domain of linux-kernel+bounces-203142-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-203142-linux.lists.archive=gmail.com@vger.kernel.org" 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 am.mirrors.kernel.org (Postfix) with ESMTPS id A4DA91F24BFF for ; Wed, 5 Jun 2024 20:02:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 073B3156F55; Wed, 5 Jun 2024 20:02:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=datenfreihafen.org header.i=@datenfreihafen.org header.b="MW3QTbSw" Received: from proxima.lasnet.de (proxima.lasnet.de [78.47.171.185]) (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 4875D156F26; Wed, 5 Jun 2024 20:02:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=78.47.171.185 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717617758; cv=none; b=nbGhG/yCTI9NKyUBNZuC+YD8ODAnQ51ffVzLQww2sW8wlqCxYFrvtHt2h95tRyF4qYztT6EJI0zM1dYihcPA7ADPboikwrf9yUYxFA+9P43aFzGpR3MPlvgQID9qmLISslQYTzE3cztIU3/l5lEnUcY+UUTwTOCactuIZpBYSeY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717617758; c=relaxed/simple; bh=YeRz+r/JijIpAJ9ruGEWph6mEWllUl61ky5cVumLtiE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Cm0Pu9YxzK49A+2NDjKc0dse2zsClnBvKbWrgT10kZK05PtupMMKplHv40oNAdc/iNT1NrQgx0I82eeNelJFSeGBAI7ygCHbk+sEy+K5w/ukPvBTUEB9NKfZ3vIdhtPr/ZdnUhf52Gf0Sw9jP3AtxpjbMmgnJwDPBUk2LBNxTdY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=datenfreihafen.org; spf=pass smtp.mailfrom=datenfreihafen.org; dkim=pass (2048-bit key) header.d=datenfreihafen.org header.i=@datenfreihafen.org header.b=MW3QTbSw; arc=none smtp.client-ip=78.47.171.185 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=datenfreihafen.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=datenfreihafen.org Received: from [192.168.2.51] (unknown [45.118.184.53]) (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) (No client certificate requested) (Authenticated sender: stefan@datenfreihafen.org) by proxima.lasnet.de (Postfix) with ESMTPSA id 9275AC01B9; Wed, 5 Jun 2024 22:02:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=datenfreihafen.org; s=2021; t=1717617744; 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=R/hTIr21CahD0Nu7VkQW1QMjCpyJixUIEnztFvdZHlg=; b=MW3QTbSw5RFmQk0yUd1gvedDSjOrE+GXsBFHmpd81TdF7fqhTyGKK9djxwi3Lw0ZDQOmXD nS8T+ea3/rTqJbXbjJp5RgMJegtAK2CzBUWCRtDidVpJKO1GtFYslXjx4gM4GrMeJSWOxq kCpmfCDWiwLxuR3Z/BD65l/1B07HHQuo7bWnhfdC+E+HTnjoNQr1SlAcwz9uhxo4uBZ2lD TQyAawcChPXxzj6exXDWixa+TCQb3j0X9gberzwNpbggtfZ3uiPgFv1N+PpAimxhY+ecwB q0pUdRVtmnIEDPIbxFuQZVArPpysBnu6GsfkkJZw2Q8mGAocthAXJy9dmIQxbw== Message-ID: Date: Wed, 5 Jun 2024 22:02:24 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] net: mac802154: Fix racy device stats updates by DEV_STATS_INC() and DEV_STATS_ADD() To: Alexander Aring , Jakub Kicinski Cc: 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 References: <20240531080739.2608969-1-jiangyunshui@kylinos.cn> <41e4b0e3-ecc0-43ca-a6cd-4a6beb0ceb8f@datenfreihafen.org> <20240603165543.46c7d3b4@kernel.org> Content-Language: en-US From: Stefan Schmidt In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hello Jakub, Alex, On 04.06.24 15:52, Alexander Aring wrote: > Hi, > > On Mon, Jun 3, 2024 at 7:56 PM 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. Therefore >>>> these counters should be updated atomically. Adopt SMP safe DEV_STATS_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_struct *work) >>>> if (res) >>>> goto err_tx; >>>> >>>> - dev->stats.tx_packets++; >>>> - dev->stats.tx_bytes += 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, struct sk_buff *skb) >>>> if (ret) >>>> goto err_wake_netif_queue; >>>> >>>> - dev->stats.tx_packets++; >>>> - dev->stats.tx_bytes += len; >>>> + DEV_STATS_INC(dev, tx_packets); >>>> + DEV_STATS_ADD(dev, tx_bytes, len); >>>> } else { >>>> local->tx_skb = 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-fWUUYFYjM1Uw@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? regards Stefan Schmidt