Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2337463rdg; Mon, 16 Oct 2023 00:36:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH7KFUQ3G154aCPpXHqhJz8W/b9aefMVCqAofVDTqkPBRB+1UkMczFYE3kr6Flxqo67vtxg X-Received: by 2002:a17:903:110f:b0:1c5:d0ba:429 with SMTP id n15-20020a170903110f00b001c5d0ba0429mr35380309plh.4.1697441768481; Mon, 16 Oct 2023 00:36:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697441768; cv=none; d=google.com; s=arc-20160816; b=JuR8q6IodgwBvvVynqERVrB9xnpx0sf9HtzWE+5YIQOlHvLAlKQozvDtXmHivc6hbS i0tP1P7Z0b86WejmtEmzSZBdPG4B2dTbWAsuvJsXvOmsHrUNwfj4l6Z0RUNYBMyJCASU nQqXHROMKDeSlqGJOE7p9I2rbiiVrxHY4jftA6CDAC77LekmPBuS3eJ1r+xEaEyhubs0 7IoiHMo+j6vfQeAuf6zjCj6bhmH402EUHADEXXXmY0dHoMZ6CNFOmYNnE9uw7oIRB8+B mH5q8ESmyG9hpFyrqqshoB0tf2ZOBcaVU3zlh01Ea3MESSCtme0M0e3PJtLKovtb/YlI AbNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=uZWxgydpZppRV3uFhpO46+mr4KRDGo1ndeXPvO+3cY4=; fh=9zqLgA8CfAS2QGNSf3c7WeEpqEMBFYmV93cRSeop+AE=; b=0JkRlMUxXqJloXF9tVdcNRwUFeDUA2r7zZS9Kk+0qvit/TPVkM8jfkWn3uLdcNbK6d eMeo9lBrZ6A2s+6yR6r2LTPn7AjOUYLsMhmtQogeeVKo1pWXo5O79lrsmsRH051uwydd ZZFgdPBFyElRPjlHMqsxGDpj0RZZzILNRMaC8ga9bv95ya6v1rKMLVUYZQRZf+0KF5u4 77BNDyv2E126ZG+BL1txDNfEPaLh+r0ZWn09sH6fVXcxKSbkPE2e/pnfd8ZhsBIfN8TN mQy/XMNLKzORpnRPo7fGQ66ImUY7lgvUJo0s2HWXVcC3iv1ph6YHGa0Jgt4er7BP5PNy XuLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=MC5DhabG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id g22-20020a170902869600b001b3d6c68bd1si9710843plo.643.2023.10.16.00.36.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 00:36:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=MC5DhabG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id B233A807C863; Mon, 16 Oct 2023 00:36:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232025AbjJPHfy (ORCPT + 99 others); Mon, 16 Oct 2023 03:35:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232133AbjJPHfw (ORCPT ); Mon, 16 Oct 2023 03:35:52 -0400 Received: from mail-vs1-xe32.google.com (mail-vs1-xe32.google.com [IPv6:2607:f8b0:4864:20::e32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4724E5 for ; Mon, 16 Oct 2023 00:35:50 -0700 (PDT) Received: by mail-vs1-xe32.google.com with SMTP id ada2fe7eead31-457c7177a42so1065089137.2 for ; Mon, 16 Oct 2023 00:35:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697441750; x=1698046550; 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=uZWxgydpZppRV3uFhpO46+mr4KRDGo1ndeXPvO+3cY4=; b=MC5DhabGSH3oNOgExQJVgI1sPVP5qpfD7NY/IpKxbNnUp9VZZIZAf96WKcVhgJ26RW L55yvsjepwpLl2D6P1DU+wUnshNjUaCX+1FJ/YlRHsRExZbYRKzz4Qujzs6IaarKMSkX HVIs7raJSDtmPkrRmboeXb6nraf6IowVNqRK3ZT0UT9Sd2LG41mgS1QgMgS8mz+nXXAk CEteDF2eoNtnt9ITBEtKKtbk1wffbwkKHCOpgmHv9DeqMoTof88ZFrDXX88Z/0UzO8FY JZB8fAin8owLw0H8Drxt57dnhVm8BtjWWlYYED9qGMBs8H8gfccCQFeQd6wpq6YHOGtX Nxww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697441750; x=1698046550; 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=uZWxgydpZppRV3uFhpO46+mr4KRDGo1ndeXPvO+3cY4=; b=aJuTe4lGFhvqkDS8/0R0lNdq/Z6XPren6iZ5G28EH54G8BVbH5D5n6Z37ehdgtDXHH kGULj2lSuvD6usUnD2Sl48YqESa90t6U2aNWI70g3NSsQxQm6Rc1bScF0LYtf7ymu2gt livaEt9Hxbzy41CBWFDUJKjfZbO7P38YZKYO9uvxB34s2QQI0udW4ABPHgcLRxDcAJUb m1PAvkHkRODpEobC8YhMHTtwGFP9wkXlOraInsAdtjAhtyfq9FFljOqVAQk064MqiMdF 8NnW0Shq3JrVcY4gYLRc5wMycbAZ7+c9Y+WBJjJDlAY13YPxeUjkptdEYnB30wFF6+Zw w2bQ== X-Gm-Message-State: AOJu0Yz3owcHTkbES4DrQEJ5XipwUrXBEiC9auL9h3lcVA89h2qgDONW tqA1jlpUaS4gTo0vZNt996ZbT5mpt1lPTqh00dihWA== X-Received: by 2002:a67:a64b:0:b0:457:d207:4328 with SMTP id r11-20020a67a64b000000b00457d2074328mr3902554vsh.23.1697441749420; Mon, 16 Oct 2023 00:35:49 -0700 (PDT) MIME-Version: 1.0 References: <20231014031257.178630-1-mirsad.todorovac@alu.unizg.hr> <20231014031257.178630-2-mirsad.todorovac@alu.unizg.hr> In-Reply-To: <20231014031257.178630-2-mirsad.todorovac@alu.unizg.hr> From: Marco Elver Date: Mon, 16 Oct 2023 09:35:13 +0200 Message-ID: Subject: Re: [PATCH v1 2/3] r8169: fix the KCSAN reported data-race in rtl_tx while reading TxDescArray[entry].opts1 To: Mirsad Goran Todorovac Cc: Heiner Kallweit , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, nic_swsd@realtek.com, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Mon, 16 Oct 2023 00:36:04 -0700 (PDT) On Sat, 14 Oct 2023 at 05:16, Mirsad Goran Todorovac wrote: > > KCSAN reported the following data-race: > > =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=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=3D=3D > BUG: KCSAN: data-race in rtl8169_poll (drivers/net/ethernet/realtek/r8169= _main.c:4368 drivers/net/ethernet/realtek/r8169_main.c:4581) r8169 > > race at unknown origin, with read to 0xffff888140d37570 of 4 bytes by int= errupt on cpu 21: > rtl8169_poll (drivers/net/ethernet/realtek/r8169_main.c:4368 drivers/net/= ethernet/realtek/r8169_main.c:4581) r8169 > __napi_poll (net/core/dev.c:6527) > net_rx_action (net/core/dev.c:6596 net/core/dev.c:6727) > __do_softirq (kernel/softirq.c:553) > __irq_exit_rcu (kernel/softirq.c:427 kernel/softirq.c:632) > irq_exit_rcu (kernel/softirq.c:647) > sysvec_apic_timer_interrupt (arch/x86/kernel/apic/apic.c:1074 (discrimina= tor 14)) > asm_sysvec_apic_timer_interrupt (./arch/x86/include/asm/idtentry.h:645) > cpuidle_enter_state (drivers/cpuidle/cpuidle.c:291) > cpuidle_enter (drivers/cpuidle/cpuidle.c:390) > call_cpuidle (kernel/sched/idle.c:135) > do_idle (kernel/sched/idle.c:219 kernel/sched/idle.c:282) > cpu_startup_entry (kernel/sched/idle.c:378 (discriminator 1)) > start_secondary (arch/x86/kernel/smpboot.c:210 arch/x86/kernel/smpboot.c:= 294) > secondary_startup_64_no_verify (arch/x86/kernel/head_64.S:433) > > value changed: 0xb0000042 -> 0x00000000 > > Reported by Kernel Concurrency Sanitizer on: > CPU: 21 PID: 0 Comm: swapper/21 Tainted: G L 6.6.0-rc2-kc= san-00143-gb5cbe7c00aa0 #41 > Hardware name: ASRock X670E PG Lightning/X670E PG Lightning, BIOS 1.21 04= /26/2023 > =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=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=3D=3D > > The read side is in > > drivers/net/ethernet/realtek/r8169_main.c > =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=3D=3D=3D=3D=3D=3D=3D=3D=3D > 4355 static void rtl_tx(struct net_device *dev, struct rtl8169_private= *tp, > 4356 int budget) > 4357 { > 4358 unsigned int dirty_tx, bytes_compl =3D 0, pkts_compl =3D = 0; > 4359 struct sk_buff *skb; > 4360 > 4361 dirty_tx =3D tp->dirty_tx; > 4362 > 4363 while (READ_ONCE(tp->cur_tx) !=3D dirty_tx) { > 4364 unsigned int entry =3D dirty_tx % NUM_TX_DESC; > 4365 u32 status; > 4366 > =E2=86=92 4367 status =3D le32_to_cpu(tp->TxDescArray[en= try].opts1); > 4368 if (status & DescOwn) > 4369 break; > 4370 > 4371 skb =3D tp->tx_skb[entry].skb; > 4372 rtl8169_unmap_tx_skb(tp, entry); > 4373 > 4374 if (skb) { > 4375 pkts_compl++; > 4376 bytes_compl +=3D skb->len; > 4377 napi_consume_skb(skb, budget); > 4378 } > 4379 dirty_tx++; > 4380 } > 4381 > 4382 if (tp->dirty_tx !=3D dirty_tx) { > 4383 dev_sw_netstats_tx_add(dev, pkts_compl, bytes_com= pl); > 4384 WRITE_ONCE(tp->dirty_tx, dirty_tx); > 4385 > 4386 netif_subqueue_completed_wake(dev, 0, pkts_compl,= bytes_compl, > 4387 rtl_tx_slots_avail(= tp), > 4388 R8169_TX_START_THRS= ); > 4389 /* > 4390 * 8168 hack: TxPoll requests are lost when the T= x packets are > 4391 * too close. Let's kick an extra TxPoll request = when a burst > 4392 * of start_xmit activity is detected (if it is n= ot detected, > 4393 * it is slow enough). -- FR > 4394 * If skb is NULL then we come here again once a = tx irq is > 4395 * triggered after the last fragment is marked tr= ansmitted. > 4396 */ > 4397 if (READ_ONCE(tp->cur_tx) !=3D dirty_tx && skb) > 4398 rtl8169_doorbell(tp); > 4399 } > 4400 } > > tp->TxDescArray[entry].opts1 is reported to have a data-race and READ_ONC= E() fixes > this KCSAN warning. > > 4366 > =E2=86=92 4367 status =3D le32_to_cpu(READ_ONCE(tp->TxDe= scArray[entry].opts1)); > 4368 if (status & DescOwn) > 4369 break; > 4370 > > Fixes: ^1da177e4c3f4 ("initial git repository build") > Cc: Heiner Kallweit > Cc: nic_swsd@realtek.com > Cc: "David S. Miller" > Cc: Eric Dumazet > Cc: Jakub Kicinski > Cc: Paolo Abeni > Cc: Marco Elver > Cc: netdev@vger.kernel.org > Link: https://lore.kernel.org/lkml/dc7fc8fa-4ea4-e9a9-30a6-7c83e6b53188@a= lu.unizg.hr/ > Signed-off-by: Mirsad Goran Todorovac Acked-by: Marco Elver > --- > drivers/net/ethernet/realtek/r8169_main.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethe= rnet/realtek/r8169_main.c > index 81be6085a480..361b90007148 100644 > --- a/drivers/net/ethernet/realtek/r8169_main.c > +++ b/drivers/net/ethernet/realtek/r8169_main.c > @@ -4364,7 +4364,7 @@ static void rtl_tx(struct net_device *dev, struct r= tl8169_private *tp, > unsigned int entry =3D dirty_tx % NUM_TX_DESC; > u32 status; > > - status =3D le32_to_cpu(tp->TxDescArray[entry].opts1); > + status =3D le32_to_cpu(READ_ONCE(tp->TxDescArray[entry].o= pts1)); > if (status & DescOwn) > break; > > -- > 2.34.1 >