Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3384633rdg; Tue, 17 Oct 2023 13:02:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFPzHt20N6mKBTeRej4LSRwtXCHajR8jaH2q9leES8FdotPlGLFTQ9N8/sYr/1DFBgnxySw X-Received: by 2002:a05:6602:2c49:b0:79f:9edb:6e2d with SMTP id x9-20020a0566022c4900b0079f9edb6e2dmr3664113iov.18.1697572924695; Tue, 17 Oct 2023 13:02:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697572924; cv=none; d=google.com; s=arc-20160816; b=rlVKRYwpJdMxj5HpyQWwGfT9/c2w2hMYWe0YBbwill0C1X6q+yOGuXztmIVrE7aT3W nZIPyVVFprD4gvcLwI0ExqXv5wxwLn9JGRtv3QjTGBWW2FVfxSjqHbaohXh6LieqJF/S EtpFV32SVldx/hcrBUMCuNByQLqlsPvvxUzBRUynH2cbCT6x3z7xMH9QlqhL1Rch3aKi vkfi/8dkqL+zkrR4X9kxwMhSVAX0/3KCk2h6y5/Vv427tmPKaOMwO+FJJyACprrtAbvu 74H7GDowWQ1BYwbRjbwT6kIJSp3W3woM4nPgLWJNgYHayWZS1UyqMTPM3wl0dIj2jEB7 DKPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=k0niwsoCLakkldmlgaCUoWShmCriNOeZc9iL1T4F6P4=; fh=WGuxsrrIFLvPEKF5r+WXA/XenY0YZ41arZ3Pqkm0jyU=; b=J6zElbUVFlcd0GNp/2/LtaamF1HqFAUaDCwpT6aZJBKDB2ov3pM3xBmhLw83Z2UuJu BlGqaNE8sBv2QeIfUhUgBcVxh3Pk42o+w+mPWv/I/Vk7KezC0z7KLObkvXRzGNHLCBk4 bwbfQXIAhQO28dzs09oMQDNoCdgL2HyJJ1/2ANZRba6JeTBtiXSfVAmtRvsiV/1mI8sG qPQp6RCsC5IdBeU4LbviQz1mAs3pKooC7nCsh0iGAO2mhGITavnIOj9LoOlUXQIRgSmw gGFjIigEqIP1xA4cZAyk5KvjTw8Nuk4orlyQifVmSxZht9ChdiC47qHppIMT0bdXs7um X1hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RM9PeEN1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id bz14-20020a056a02060e00b0056c55eb251csi548161pgb.123.2023.10.17.13.02.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 13:02:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RM9PeEN1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 32C4B80286A2; Tue, 17 Oct 2023 13:01:58 -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 S232198AbjJQUBq (ORCPT + 99 others); Tue, 17 Oct 2023 16:01:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229459AbjJQUBp (ORCPT ); Tue, 17 Oct 2023 16:01:45 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC69DC4 for ; Tue, 17 Oct 2023 13:01:43 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A7A1C43395; Tue, 17 Oct 2023 20:01:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697572903; bh=RZbkItK1Di4f+MlX4v1ZpvBgrpQvo9FmlwmViYyTx5Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=RM9PeEN1qS1zEnfQr9XB88kMFdDl5b9H0sywRT5963OsfbkQNlSSKZIBvP015deLN XpbJJm3R1BLri8ZoD3GzKvRAT4WeU9UfLJ8e0iJljt9XdlX3FevkA/qo0EvKs26ZrB V8QD5CTau1xh1LHaj2Alvirca3h3bfwQi2js5rWFLpj/UnR3YKyy2zuPQACSpWe5U2 w5wTOCGKYvP8vcPyiG9Iw2tVHccDKZHBMP4o6zLnuuLg1TEICH+6eKzm2whjhlfFhD uGGGvpVZwtFUn40TKUxwDByFHrcLgOOjbZMkr7PyDcu2uEdXT9mfGXIiK7jrywZv7V d4QtHjp8Ih8MQ== Date: Tue, 17 Oct 2023 22:01:38 +0200 From: Simon Horman 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 , Marco Elver Subject: Re: [PATCH v2 3/3] r8169: fix the KCSAN reported data-race in rtl_tx while reading TxDescArray[entry].opts1 Message-ID: <20231017200138.GB1940501@kernel.org> References: <20231016214753.175097-1-mirsad.todorovac@alu.unizg.hr> <20231016214753.175097-3-mirsad.todorovac@alu.unizg.hr> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20231016214753.175097-3-mirsad.todorovac@alu.unizg.hr> X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 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]); Tue, 17 Oct 2023 13:01:58 -0700 (PDT) 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. > 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 ...