Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp42107rdb; Fri, 5 Jan 2024 01:59:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IFrv4SBpOrMoRvF27LdxUIn++XjZxXTH6vfkF2vSPs1oGo7AdTsHLQsZxTXon01Or2I1dqy X-Received: by 2002:a05:620a:c54:b0:77f:5803:e00d with SMTP id u20-20020a05620a0c5400b0077f5803e00dmr2118592qki.145.1704448745734; Fri, 05 Jan 2024 01:59:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704448745; cv=none; d=google.com; s=arc-20160816; b=QNieDnmSYgO0BafifFsDPHHD23Pi1mH888i4s7IsDHUaBAwW7fT/FwzjRImjdbDZdn AsHXPPtRUN7P42ellu2aTZZ5mBHQMfTEJrou6uBskR4HvaYbq+GoPHRCdaV7LKU0SW1n hjh+3w4Tg4bv9d3X5f083EEqdtVHCIB2pl1F2zH9zoxcIKgVP6UIS13kBojqnpyyNfxm GEtz2ibN8hoOlYoP/FPtp8gb0V5N5yynvLjtKnwDm9eVh6A3YB5XBUw/bRnlH4VgGQdH pLW+TnJdzAO/b0vZtm7j7tNDUJpwqn0Jbj44ogzFk0FsHwRqYEo1YakZLNkoLsrMRMKV mzHw== ARC-Message-Signature: i=1; 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=5s2WgUp2uwUQXzqO9cBgyU5Zr8leiFxlRGNJ1vYv0Dw=; fh=2ehLvpuOQxmG3IotsGWpzpPeKD+waspD0omE3TLwPXc=; b=y32KP1Q6e/W/7SfwxzekarqLkh0I/38Ie+Pkr7osKavHms5o9+/VbV0B4znE/u13Iy HWitBE/w9uKA+GqbkDwPYjRCVkun2Xznqb1H0ZykfONa5AOZLLzryo9u92IVj6YKq5G7 +FtOmM0vrX77Ug5Yzefhm08pqt6q2L780mjU0gxLI1mrQHuFDa/T90YaF81gWU+sxRct SOdDH96EBmr1SCPt1y5agACeB5MFptB5cr8xtviM10PcCYdK7rJ3FGFCYamMe/ZJVew2 TlGDRZ2N+AfO2kYKwFAau63pYxFR5vUy5EqCqbVeyXA5DH1DgbKfpkqvy+a88M01EL/y apvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=wgHgGLPF; spf=pass (google.com: domain of linux-kernel+bounces-17702-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17702-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id h22-20020a05620a245600b007811da862ecsi1422379qkn.83.2024.01.05.01.59.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 01:59:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17702-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=@google.com header.s=20230601 header.b=wgHgGLPF; spf=pass (google.com: domain of linux-kernel+bounces-17702-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17702-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 3C7DB1C21525 for ; Fri, 5 Jan 2024 09:59:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ADF5F24B44; Fri, 5 Jan 2024 09:58:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="wgHgGLPF" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.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 65D8824A05 for ; Fri, 5 Jan 2024 09:58:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-55679552710so6455a12.1 for ; Fri, 05 Jan 2024 01:58:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704448736; x=1705053536; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=5s2WgUp2uwUQXzqO9cBgyU5Zr8leiFxlRGNJ1vYv0Dw=; b=wgHgGLPF/4pmwqtpKGyRRzEUDBNVHsanWh+stIS1absDp5cjbmXjY6Geg0HjrdIl0E 9aeMtYtKAtx4ihKOhAfumLucu+I7rRr94TZT4D/5wZ54L9J3nxwX2CgXrR9Sg8nuiNtM v0WzhRBM+z+OOptCIZ4CThp9GPnh1ij2cQubuOz0bxs8ieSW3SAnqEeOcf+B06sUgyUa 0+OIIAF2zZyTxlz+zYoEmga/9fpTFbj+z/vDOzhsMJ26/SKM1fpb44G8ATwQEMlJnQ5R mVrBE6+T7Dcpp052gjtqvSlT9bWs+DVtOgpjv02EQIAwCFl+PVibdFXzUYDtAZheL2JS 0ekA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704448736; x=1705053536; 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=5s2WgUp2uwUQXzqO9cBgyU5Zr8leiFxlRGNJ1vYv0Dw=; b=BiBnjeG+K5Ox0sbNxndy8vNtvGD0tXwC7vwM6t5hOs+e2m3zTz/0ePzd/2hzWZzcbM Rxnbg81TbmyBZU9xzrjijwq8ZJo4rgBF1jlYPKy7i+yKwiL1HUiLBNLozbDwsFZ8q465 inqkjkeNmE90cYWtXxw5fUekMNKqwFYKvaNyEu6QlDiS5HPLaw5AQ4/x5BoLiaOGO1Vt qLM9bfMUn2sH8UPil3cbU985c8Dd03OzxO5X4iSxHpArqobLyunIiXuY6IfzwmXW+ukJ zGbhAzm+udvUc2WlYPvPutYLq4+c9oB2pFIYabj8AjnIrUTX/zOBhuretJcCzeetqPCG NyLg== X-Gm-Message-State: AOJu0YwaCYub9cNlWp0z8BmqfF1mI/RkZjK/M0kVm3AReO/kmhEWy6mp 6sazU68G3dAmaf5UYjos+bCmg/j5DhsUUTTL1euDEfLiGpoC X-Received: by 2002:a05:6402:35d4:b0:557:3c8a:7242 with SMTP id z20-20020a05640235d400b005573c8a7242mr22196edc.3.1704448735539; Fri, 05 Jan 2024 01:58:55 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240105091556.15516-1-petr@tesarici.cz> In-Reply-To: <20240105091556.15516-1-petr@tesarici.cz> From: Eric Dumazet Date: Fri, 5 Jan 2024 10:58:42 +0100 Message-ID: Subject: Re: [PATCH] net: stmmac: protect statistics updates with a spinlock To: Petr Tesarik Cc: Alexandre Torgue , Jose Abreu , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , "open list:STMMAC ETHERNET DRIVER" , "moderated list:ARM/STM32 ARCHITECTURE" , "moderated list:ARM/STM32 ARCHITECTURE" , open list , "open list:ARM/Allwinner sunXi SoC support" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Jan 5, 2024 at 10:16=E2=80=AFAM Petr Tesarik wro= te: > > Add a spinlock to fix race conditions while updating Tx/Rx statistics. > > As explained by a comment in , write side of stru= ct > u64_stats_sync must ensure mutual exclusion, or one seqcount update could > be lost on 32-bit platforms, thus blocking readers forever. > > Such lockups have been actually observed on 32-bit Arm after stmmac_xmit(= ) > on one core raced with stmmac_napi_poll_tx() on another core. > > Signed-off-by: Petr Tesarik This is going to add more costs to 64bit platforms ? It seems to me that the same syncp can be used from two different threads : hard irq and napi poller... At this point, I do not see why you keep linux/u64_stats_sync.h if you decide to go for a spinlock... Alternative would use atomic64_t fields for the ones where there is no mutual exclusion. RX : napi poll is definitely safe (protected by an atomic bit) TX : each TX queue is also safe (protected by an atomic exclusion for non LLTX drivers) This leaves the fields updated from hardware interrupt context ?