Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3404005rdg; Tue, 17 Oct 2023 13:44:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF5HTBBmvdsn4aHoCVQK0BgxDOFLJr3kyQ1PdJYMGkS9MLohyUQGCKmlojq8BOG/zQvtQKy X-Received: by 2002:a05:6a20:3950:b0:17b:40:cccd with SMTP id r16-20020a056a20395000b0017b0040cccdmr3304464pzg.6.1697575455965; Tue, 17 Oct 2023 13:44:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697575455; cv=none; d=google.com; s=arc-20160816; b=ZtjGUkaviqUpGvwpvp2nFDB8FUa3ototN+7+siIuQUb15ArWhwNif8NaQgsvWqrJ+S oqkBiAoUjfmdWA7JvlAjSZuL4jkhPyTpDqJ/usPUyBPcxAGW+B1Nsqf6INVNyCY4tI3C RC6ZXIBfJyjr6j5WXK+6vipXPKwU3SBlgTlN9fFa5xs0RDuED3IGIiKfehpf2HnZqKmo /dqkpzzjSNGJNk6kASLIy3JW6mvGF0jsMZEMJlv3X+OwXj4Pqqw0tHAgAquUnaAP8sIf wulV8dbtMGogSEky24joLNATAPZP39v5NXmzoz0QCbKOoWrmawbKavzZC77P1Aej9LgK k+Fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-signature; bh=p5fLX8JO6Krqn3ZhfzqwrxUCB5Ay2IYiUwSqIeixl6I=; fh=rAVPRSozvapYtCzJfjExHFoRIMgiHbRLb1+VO62SAkw=; b=i6gpHKCpwNI7GkrofTTyQQNR6c6DSaOmS5JSpCqQCb6r5xk+Vj1GlIKfuxN5cE8WSM u4TwIkWQDrLW3AVAnLXuKGKqf1E3lqXns7OGrSbBW2npEIuH6MhY/UwGYWUH1Z3OGxRG 1Kwakx3ckGA7LvY1Sozew9GCoTQ0PDSHZwdXvESd+fZu/O7y6xslg47Gs10+Zt8xl45s s0tLQC8NJOcM4X2AUrYVgV71TPEcIUDVqb/w+jRrdndp9+PpkxCFSsgF1u7/OFBNRMTO tNPvBr9ztRdUTuhgMQNtyudhLzx4ci31u1Qn/y58lchm0Uy3adLuv6T1S+Olc5tbhHBB s+NQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@alu.unizg.hr header.s=mail header.b=IxXnZqiO; dkim=fail header.i=@alu.unizg.hr header.s=mail header.b=upAsRbHF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alu.unizg.hr Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id b3-20020a6567c3000000b005acb3613ba9si539901pgs.432.2023.10.17.13.44.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 13:44:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=fail header.i=@alu.unizg.hr header.s=mail header.b=IxXnZqiO; dkim=fail header.i=@alu.unizg.hr header.s=mail header.b=upAsRbHF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alu.unizg.hr Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id DD26480BB56A; Tue, 17 Oct 2023 13:44:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231149AbjJQUoA (ORCPT + 99 others); Tue, 17 Oct 2023 16:44:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232770AbjJQUn5 (ORCPT ); Tue, 17 Oct 2023 16:43:57 -0400 Received: from domac.alu.hr (domac.alu.unizg.hr [IPv6:2001:b68:2:2800::3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B73792; Tue, 17 Oct 2023 13:43:53 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by domac.alu.hr (Postfix) with ESMTP id 274CF60174; Tue, 17 Oct 2023 22:43:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=alu.unizg.hr; s=mail; t=1697575429; bh=JUBD9sFg6gvWejh9DwTAaOrqXlxrXwgq3KheNQfZO8I=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=IxXnZqiOMQYOhBd2Ar0GQ+jYggFnGnghwG8AkKw5qUw/Boi5G8Q6dugd8zxtn7RnR 9GwSu9NHWSKbxEW/FSsMYOhn0e62WsGN/Z+rbY7ckTTHRIwjyscYVI4IzPM9Kr/60D LLYLufqvkaHAjIlxn55Qrpb5E6UOiQ9yWFZOsUGJCBN/sHK4UiP3o6iEq+uCAVSeg5 f3lFPxy5DmmsiG/tbV3ACO+kiVVnUG6z4FjYpvY2d3H3aLHQrE8fQPMz+eD49Tlgc7 7rUeNItQSnvlZNSyz7YWa1L1lBgToXDCZyfbz8HkLvMVdeVVV/RYNzzCq46CUzMpLx u5Z0Tc+J+uDJw== X-Virus-Scanned: Debian amavisd-new at domac.alu.hr Received: from domac.alu.hr ([127.0.0.1]) by localhost (domac.alu.hr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9gsXl7XC6Y2V; Tue, 17 Oct 2023 22:43:38 +0200 (CEST) Received: from [192.168.1.6] (78-0-136-77.adsl.net.t-com.hr [78.0.136.77]) by domac.alu.hr (Postfix) with ESMTPSA id 646035FD95; Tue, 17 Oct 2023 22:43:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=alu.unizg.hr; s=mail; t=1697575418; bh=JUBD9sFg6gvWejh9DwTAaOrqXlxrXwgq3KheNQfZO8I=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=upAsRbHFMNjM4mBoNTk3F/pixfpKaIMm4pFPoXTSkyEnA48BJnwIkHB4AqKK8uait Gr57NtZMz3YHRZ+E5JNSHSblCeakHJHDkZbbc1hCWDm4qXYjddiKareulvvvlpoG0t pwyXCOuMQoDpP6TghxVs+aWCbyID518txf+XFAWglcY3Ss81aFZejyFEcuijnCtvj3 nCapve3ZyZz/nD601EZUurEj1BOEAewo9khbHk8nhT7kyeQWFE6ZqTi9T3TWmYAvn8 7zgaFiQ7qRG9EceSZlKaTYiBkc/aqaciWXoE5kT2y3NyUaxrZi2WBeDH9bvpOVRLo7 lFGwFw5CePjKQ== Message-ID: <992dcaf7-2b24-4e91-8c69-a5471da209ae@alu.unizg.hr> Date: Tue, 17 Oct 2023 22:43:36 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 3/3] r8169: fix the KCSAN reported data-race in rtl_tx while reading TxDescArray[entry].opts1 Content-Language: en-US To: Simon Horman 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 , Marco Elver References: <20231016214753.175097-1-mirsad.todorovac@alu.unizg.hr> <20231016214753.175097-3-mirsad.todorovac@alu.unizg.hr> <20231017200138.GB1940501@kernel.org> From: Mirsad Todorovac In-Reply-To: <20231017200138.GB1940501@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.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 (groat.vger.email [0.0.0.0]); Tue, 17 Oct 2023 13:44:13 -0700 (PDT) On 10/17/23 22:01, Simon Horman wrote: > On Mon, Oct 16, 2023 at 11:47:56PM +0200, Mirsad Goran Todorovac wrote: >> KCSAN reported the following data-race: >> >> ================================================================== >> 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 interrupt 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 (discriminator 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-kcsan-00143-gb5cbe7c00aa0 #41 >> Hardware name: ASRock X670E PG Lightning/X670E PG Lightning, BIOS 1.21 04/26/2023 >> ================================================================== >> >> The read side is in >> >> drivers/net/ethernet/realtek/r8169_main.c >> ========================================= >> 4355 static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp, >> 4356 int budget) >> 4357 { >> 4358 unsigned int dirty_tx, bytes_compl = 0, pkts_compl = 0; >> 4359 struct sk_buff *skb; >> 4360 >> 4361 dirty_tx = tp->dirty_tx; >> 4362 >> 4363 while (READ_ONCE(tp->cur_tx) != dirty_tx) { >> 4364 unsigned int entry = dirty_tx % NUM_TX_DESC; >> 4365 u32 status; >> 4366 >> → 4367 status = le32_to_cpu(tp->TxDescArray[entry].opts1); >> 4368 if (status & DescOwn) >> 4369 break; >> 4370 >> 4371 skb = tp->tx_skb[entry].skb; >> 4372 rtl8169_unmap_tx_skb(tp, entry); >> 4373 >> 4374 if (skb) { >> 4375 pkts_compl++; >> 4376 bytes_compl += skb->len; >> 4377 napi_consume_skb(skb, budget); >> 4378 } >> 4379 dirty_tx++; >> 4380 } >> 4381 >> 4382 if (tp->dirty_tx != dirty_tx) { >> 4383 dev_sw_netstats_tx_add(dev, pkts_compl, bytes_compl); >> 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 Tx 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 not 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 transmitted. >> 4396 */ >> 4397 if (READ_ONCE(tp->cur_tx) != dirty_tx && skb) >> 4398 rtl8169_doorbell(tp); >> 4399 } >> 4400 } >> >> tp->TxDescArray[entry].opts1 is reported to have a data-race and READ_ONCE() fixes >> this KCSAN warning. >> >> 4366 >> → 4367 status = le32_to_cpu(READ_ONCE(tp->TxDescArray[entry].opts1)); >> 4368 if (status & DescOwn) >> 4369 break; >> 4370 >> >> Fixes: ^1da177e4c3f4 ("initial git repository build") > > Hi Mirsad, > > The fixes tag above seems wrong. Hi, Simon, It is taken directly from "git blame" as you can check for yourself. It is supposed to tag the commits prior to the introduction of git. If you have a better idea how to denote those, I will be happy to learn, but I have no better clue than what "git blame" gives ... Best regards, Mirsad Todorovac >> 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@alu.unizg.hr/ >> Signed-off-by: Mirsad Goran Todorovac >> Acked-by: Marco Elver > > ...