Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp6018rdh; Tue, 13 Feb 2024 07:53:31 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVznGevOQ4rrmcju3iXu7r5oAmpd4bMg0fssEO9Kji7kQ2RYUJcxXgB6nMeDZqWeXTfw6GiQeM7pCg1BXKVF9YMcmO9vu/rWmpXvhSJ+A== X-Google-Smtp-Source: AGHT+IH186IkTTCcX/7y6KjuIeZZj1VG2Cu+VkpBSreMH5Hu8VAhcilZkjxOsmAA/vO3kSqCTD3Q X-Received: by 2002:a05:622a:144e:b0:42b:ff78:2033 with SMTP id v14-20020a05622a144e00b0042bff782033mr13581203qtx.56.1707839611665; Tue, 13 Feb 2024 07:53:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707839611; cv=pass; d=google.com; s=arc-20160816; b=cBigwOo2ybLXWor5bzfgO1CcQJlUzVHvuOQsBw09ew0q29S1i3PoORoRgTDPoUEeKx VmE/AC68mNSW6hx5VK7HL+TxrpjVTlPxHNVd0RqOxU2Rk96vK18gajtvl7qgamHocfuq Etyuj/uVRwQZkjuoSqwv2bE9SJw/4+hjsduTqdwXyfYMSJ6GiQXU2R5NgTxJz3x5/OgS ywUmXq2+boSKVZU4+oJbaiuO5nV7/SC1294lTA8VgxRLw0m0Iqf7bRb2V9j1qCQApDES MbenkKkssXfYUbP2sQ63pc/981gGJWF5Uz5o3QHK0KJPpGqL4PXxERP57ryq8Dx5uW1J ki3Q== 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=XBXU1a0C1GpqZ/Yh6XHCPcPsqtZQLKwjO20TKE3Arqc=; fh=7fTeYMo/zWfii7Hih8Rcf6806FWOyzJ88eBZeqLhgSA=; b=pZHZwQGpq4+KSnyLv4PBI3F4VIOyuklcfjtI7FkKXr1hrbeMmvdZe6UAhD2aQs8IkS 7DDf8puqdda7uiMKKPs/XXqCgHYfXWlkCICqd/EyZxD03+ZVSBGmgtlklawNQXSX9UfX nR7YqZPBf8nTOmcduw4jHkRFuVXNAzxFtTWs7gfAPDNHNrFhZh57/7F83VAE1DgSlp0E B8cAwf1jxhVnWsq+ydUCBNUmP/XcwVjV7gTxp1a0N15Mt0WuLQOeOJ825d2uMhbO2lK8 vHWyjPCXSa21UAXrrmrRHoZap7WKYq6UAkclKbb7N9+GqptQDVQ4N/2N42vruHkm4Dyo ot2A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=MtvDxhL+; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-63837-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63837-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCW6Aqnhmja3ykGr2IfkCmxM3PR1WDYrFAZ48Ga+n67qfaC8DtleedYv891gu84aT7dR9iCIUHPyqKcsnPaQz1+S69AbVRxmvtNpqeAn4g== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id y21-20020ac85255000000b0042c6442fafdsi2935683qtn.412.2024.02.13.07.53.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 07:53:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-63837-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=MtvDxhL+; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-63837-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63837-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 68EDD1C22D04 for ; Tue, 13 Feb 2024 15:53:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BFD855F85B; Tue, 13 Feb 2024 15:53:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="MtvDxhL+" Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (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 0EFF65F575 for ; Tue, 13 Feb 2024 15:53:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707839587; cv=none; b=tzhw9GBf+JRwOztSw+zV0m+m9XQ6j6Z1xd1Ry0CtRYpr8LrMAh6gE5XIE0aV5YWgEyvTcbSk+ZamP1aSs6cRS4R/OVBszzCb39oQaP9Kvv1ZPgEgKBaVsoVpv4sMq5jhUdb+msWntq/Bs3jPhYIWAHYDXleHo3f8ERNcHYxw2Yw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707839587; c=relaxed/simple; bh=9A1aL1knmmwJVorj88nXW9OtdjLYNUKnXWl0BQKd3Ks=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=GkFykBAP86DxmyaZCEUYVc9zGnPrJ7BpML6XooIR+2EPgOl8ZGOrRgKrOPguEGBq8IMMgoobQNN/v/br3tuZcJjE9wlH+t12Gbsnp+k55l7lBg3urMwWiODz6CBfJtmPs2wOHWhh3wLbYrVUu+/RTniTL1TC3qEwKPJ/eeuzeo4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=MtvDxhL+; arc=none smtp.client-ip=209.85.208.50 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-f50.google.com with SMTP id 4fb4d7f45d1cf-561f0f116ecso11269a12.0 for ; Tue, 13 Feb 2024 07:53:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707839583; x=1708444383; 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=XBXU1a0C1GpqZ/Yh6XHCPcPsqtZQLKwjO20TKE3Arqc=; b=MtvDxhL+Dv+2hyfcuuBkK78bTBhM8FfextBcZIxytdEiWQEgC1Y99i1cSR6iB6zg/D RnxU8E4b/Db3z3FT1Hok1qS2/uQSWTTb5oHtD4U1uyVO8xREFmEx6AxUJ6cPK/2OJEbM gZUpawNo1bC37nabqUOreN1Zl1FwIlu2qHbGAoA5KeONGYsgBBWkm2uz9a4N7osjuFYO IBraaTw+pVYTgCwuFLeL7+QmkkVtOkzy6LCUhV2rhEkQCHW0N/41NnQAQ8Xeax4xJY5k f2wFuRjRoOobP01Upx3WGkKOHJZRvimLdssbJvGtORWgAqHVBbt1dA0MiQqV5CNd96HQ kw6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707839583; x=1708444383; 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=XBXU1a0C1GpqZ/Yh6XHCPcPsqtZQLKwjO20TKE3Arqc=; b=JjxzezJocT3c/esKxCkTKDSd+ZSD7Iwv0/m3ynTWuFxy5Ktm+ViIW8S8MaUIJcieIj zeWk6Xy5U2JTTA4qqugWUz/2S2QQjr61AQbk0cIX4JWx/c/GH1QFOK/daw8cEDG8C88f eZCw92hRVWQg0v0/JNllMU7zDOuw+B7eZbj4nyaauxGbylilAapqeXW/XIreI48KJfc1 XLDU8vlvNdMoDvNHjwKvS8UUD4SZIlLqfyRc53XtCYVJxTQ6VOqHi6sjEPhwGNgRO7qS 0UOHhGEYhJ1+DLfMBkBrPftXBjdFBx48pAmwMOpDKEEJCmO9YgkeWwpNYy6HFBL1QJUb El0g== X-Forwarded-Encrypted: i=1; AJvYcCVGT2f8EleJaRp8rYYgp5D7FU0dr3fBBdFv7AvPxXKiqFDTvkalBy1/xec/KcR4k8Y0VNuWJwZzVHRH/VPZpw3AWryfMoZqYyxbMP/8 X-Gm-Message-State: AOJu0YwOVVLg4xN3v1PusDfvX+BEQoIoqoSFxqQVZ7/6Bb3Q5DJG7I2M NqcEamS1FV1D1z9l5kkI4vGSAZIw0ashOEheHid7j46ZU9Tu4njSYmw4k5kiI3M3q+bSLOvy+B2 KbgEsBRxAU9RVbTU7drpez384yEvhIQ9FG75+ X-Received: by 2002:a50:9f08:0:b0:561:e7d8:50a8 with SMTP id b8-20020a509f08000000b00561e7d850a8mr5534edf.0.1707839583026; Tue, 13 Feb 2024 07:53:03 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240203190927.19669-1-petr@tesarici.cz> <20d94512-c4f2-49f7-ac97-846dc24a6730@roeck-us.net> In-Reply-To: <20d94512-c4f2-49f7-ac97-846dc24a6730@roeck-us.net> From: Eric Dumazet Date: Tue, 13 Feb 2024 16:52:52 +0100 Message-ID: Subject: Re: [PATCH net v3] net: stmmac: protect updates of 64-bit statistics counters To: Guenter Roeck Cc: Jisheng Zhang , Petr Tesarik , 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" , Marc Haber , Andrew Lunn , Florian Fainelli , stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Feb 13, 2024 at 4:26=E2=80=AFPM Guenter Roeck = wrote: > > On Tue, Feb 13, 2024 at 03:51:35PM +0100, Eric Dumazet wrote: > > On Tue, Feb 13, 2024 at 3:29=E2=80=AFPM Jisheng Zhang wrote: > > > > > > On Sun, Feb 11, 2024 at 08:30:21PM -0800, Guenter Roeck wrote: > > > > Hi, > > > > > > > > On Sat, Feb 03, 2024 at 08:09:27PM +0100, Petr Tesarik wrote: > > > > > As explained by a comment in , write side= of struct > > > > > u64_stats_sync must ensure mutual exclusion, or one seqcount upda= te could > > > > > be lost on 32-bit platforms, thus blocking readers forever. Such = lockups > > > > > have been observed in real world after stmmac_xmit() on one CPU r= aced with > > > > > stmmac_napi_poll_tx() on another CPU. > > > > > > > > > > To fix the issue without introducing a new lock, split the static= s into > > > > > three parts: > > > > > > > > > > 1. fields updated only under the tx queue lock, > > > > > 2. fields updated only during NAPI poll, > > > > > 3. fields updated only from interrupt context, > > > > > > > > > > Updates to fields in the first two groups are already serialized = through > > > > > other locks. It is sufficient to split the existing struct u64_st= ats_sync > > > > > so that each group has its own. > > > > > > > > > > Note that tx_set_ic_bit is updated from both contexts. Split this= counter > > > > > so that each context gets its own, and calculate their sum to get= the total > > > > > value in stmmac_get_ethtool_stats(). > > > > > > > > > > For the third group, multiple interrupts may be processed by diff= erent CPUs > > > > > at the same time, but interrupts on the same CPU will not nest. M= ove fields > > > > > from this group to a newly created per-cpu struct stmmac_pcpu_sta= ts. > > > > > > > > > > Fixes: 133466c3bbe1 ("net: stmmac: use per-queue 64 bit statistic= s where necessary") > > > > > Link: https://lore.kernel.org/netdev/Za173PhviYg-1qIn@torres.zugs= chlus.de/t/ > > > > > Cc: stable@vger.kernel.org > > > > > Signed-off-by: Petr Tesarik > > > > > > > > This patch results in a lockdep splat. Backtrace and bisect results= attached. > > > > > > > > Guenter > > > > > > > > --- > > > > [ 33.736728] =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > > > [ 33.736805] WARNING: inconsistent lock state > > > > [ 33.736953] 6.8.0-rc4 #1 Tainted: G N > > > > [ 33.737080] -------------------------------- > > > > [ 33.737155] inconsistent {HARDIRQ-ON-W} -> {IN-HARDIRQ-W} usage. > > > > [ 33.737309] kworker/0:2/39 [HC1[1]:SC0[2]:HE0:SE0] takes: > > > > [ 33.737459] ef792074 (&syncp->seq#2){?...}-{0:0}, at: sun8i_dwma= c_dma_interrupt+0x9c/0x28c > > > > [ 33.738206] {HARDIRQ-ON-W} state was registered at: > > > > [ 33.738318] lock_acquire+0x11c/0x368 > > > > [ 33.738431] __u64_stats_update_begin+0x104/0x1ac > > > > [ 33.738525] stmmac_xmit+0x4d0/0xc58 > > > > > > interesting lockdep splat... > > > stmmac_xmit() operates on txq_stats->q_syncp, while the > > > sun8i_dwmac_dma_interrupt() operates on pcpu's priv->xstats.pcpu_stat= s > > > they are different syncp. so how does lockdep splat happen. > > > > Right, I do not see anything obvious yet. > > Wild guess: I think it maybe saying that due to > > inconsistent {HARDIRQ-ON-W} -> {IN-HARDIRQ-W} usage. > > the critical code may somehow be interrupted and, while handling the > interrupt, try to acquire the same lock again. This should not happen, the 'syncp' are different. They have different lockdep classes. One is exclusively used from hard irq context. The second one only used from BH context.