From patchwork Sat Oct 14 03:13:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mirsad Todorovac X-Patchwork-Id: 152889 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2278757vqb; Fri, 13 Oct 2023 20:17:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHBVnvdkuH7vvG0l2W5FilQ5+KLZA7pH6lBXf2eHXbHUzRzcSprkO+k8csWViEbhyAoOlPE X-Received: by 2002:a05:6a20:7d85:b0:163:57ba:2ad4 with SMTP id v5-20020a056a207d8500b0016357ba2ad4mr33674256pzj.2.1697253434294; Fri, 13 Oct 2023 20:17:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697253434; cv=none; d=google.com; s=arc-20160816; b=W55L794sLZ9mZQgUNd5UAKTekPVpq7gra+QuRPhwb0XsvpWAyX9vTCuUjYJPpoMnnB zHn/e0giXABCBPpthCjxxWh4ohXRyUnRMmS3Ej0lhs7YLoF890mSXUEcPxTOwJzA1rVs 3a6bwuKzurjIUlLOWpc3fM0y8aWpGokskD9dh+YE5p37qMIEDK4qQ4BUnZYwrZLKCIDk ILGNOXFJHo3Qlx76bhk9u0QEIy3nn5bwZzU96yYQZF8FM6ui2N6kyAr8/Fw4fkf0HQKO Y4cPEJ4OMsvE+Gk8mnvJobdwbiaSuYJ5HM1EEZpGAymWX0dsTHZ2fPbFz3zS3skpJqhD QePw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=+kahk+1GBXctX075cXAihS0Utq69kOCAGWnWTNHbEQI=; fh=7SsncGRbN74Z5AHCSqGaWZ8qQBPFU2OgoSp70ZMB+sA=; b=ZgIwQC/IRjwHUj3andshanvxDDcd3OG837sSc5SAaeTdGFPeN2deoTrw4eaWramtf4 H+ZpTsGEzEsvJaQWwmDTO9NCJ28Mzymgy/57XKTLPoY53N7vacH4Q06ix12URVHKzF2S 9mVtYd8xvsaIqZtw3RmSflzVtYIazL9C2CWEZ5aF9TXREHUJHOfuj42yV5E8uq8Nk1+i YgDsLirEVntiALTRVu+WljJ+Fiw05NCr2W5vwu7O291P9j2lchW4tLh7mr0282H6WKUA L8ffsRALceMItFtpWkMbO4ykd9Dqy+qmUY09KjaIWG0fDfWv7A8q64NWM4yhPTGhxBTR if7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@alu.unizg.hr header.s=mail header.b="f+p/rckt"; dkim=fail header.i=@alu.unizg.hr header.s=mail header.b=n9fyNiZF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id y19-20020a63ce13000000b00566058702e8si5866527pgf.236.2023.10.13.20.17.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 20:17:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=fail header.i=@alu.unizg.hr header.s=mail header.b="f+p/rckt"; dkim=fail header.i=@alu.unizg.hr header.s=mail header.b=n9fyNiZF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id 3DABC80C841D; Fri, 13 Oct 2023 20:17:06 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232799AbjJNDQf (ORCPT + 20 others); Fri, 13 Oct 2023 23:16:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232834AbjJNDQ2 (ORCPT ); Fri, 13 Oct 2023 23:16:28 -0400 Received: from domac.alu.hr (domac.alu.unizg.hr [IPv6:2001:b68:2:2800::3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F12AEB; Fri, 13 Oct 2023 20:16:26 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by domac.alu.hr (Postfix) with ESMTP id 0601660152; Sat, 14 Oct 2023 05:16:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=alu.unizg.hr; s=mail; t=1697253385; bh=SwhrpCal8ipGqLtP/4ZpVWC2b261mDXg4ooT66eGQv4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f+p/rcktS56TWtGa9rXxDvsonlQN1KNvorvNnoGTzdrBT+iB/8GPsitwIrs/W15Uj Jwqn+QIDiY69Lx1P+dakUPLb2ZxkhRPZgVhFRemGg5v2dTnYck8iuFHNplbajC2xMW z6pW4dF9SoB3Z8WjOchVIgkmtiZ1AXK17dDe0h3YmRtr8Uijj4mfaUZhEkE8Z9+LOt AbacSDV7Gz2bd778FudRp/xlXDCsae9c2njapdzqpXVyMFHY13mS8S3jkQ/+FaMP63 IInxsNn2VRVn1pxbcgD1y8hfBGsfKG1wtbMufk68j5sYBBfrNjjG7dEpwjPl6cGgMP oHjt9VWd01ubw== 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 1d7Q1rcixTo6; Sat, 14 Oct 2023 05:16:22 +0200 (CEST) Received: from defiant.home (78-2-88-84.adsl.net.t-com.hr [78.2.88.84]) by domac.alu.hr (Postfix) with ESMTPSA id 792166013C; Sat, 14 Oct 2023 05:16:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=alu.unizg.hr; s=mail; t=1697253382; bh=SwhrpCal8ipGqLtP/4ZpVWC2b261mDXg4ooT66eGQv4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n9fyNiZFoXALzeKAyyflbXFpE9QWuKv3lfASlgvkhXMknnqQWRqjQzDF/gElU2qhR w5EpWAZNh+y/X+i7YO8Fsb1JNcf+mrv3kAhwrjz4NFOTULIGNYg/Qc3rItubIveCnd JVjjFNee0wtG1dy7pJbG9E6irJfLb4H3CWZ/68ITNdLMXrSN8F4Yq+v6Cpue7O1D9w A0ToupKTBxVe3wsq62XTcGCAAFwsG9WJQqS+RJaSM6AhCpJdoGBJpZY32ozvGnyPi8 BIN825ukev6ikcjNwkJraDk81PvulnEZNsmT09crguoxJnFbz+C+fbA/vPZjqsm802 T1+VwU4WC7omw== From: Mirsad Goran Todorovac To: Heiner Kallweit , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: nic_swsd@realtek.com, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Mirsad Goran Todorovac , Marco Elver Subject: [PATCH v1 3/3] r8169: fix the KCSAN reported data race in rtl_rx while reading desc->opts1 Date: Sat, 14 Oct 2023 05:13:00 +0200 Message-Id: <20231014031257.178630-3-mirsad.todorovac@alu.unizg.hr> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231014031257.178630-1-mirsad.todorovac@alu.unizg.hr> References: <20231014031257.178630-1-mirsad.todorovac@alu.unizg.hr> MIME-Version: 1.0 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 fry.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 (fry.vger.email [0.0.0.0]); Fri, 13 Oct 2023 20:17:06 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779699216833792623 X-GMAIL-MSGID: 1779699216833792623 KCSAN reported the following data-race bug: ================================================================== BUG: KCSAN: data-race in rtl8169_poll (drivers/net/ethernet/realtek/r8169_main.c:4430 drivers/net/ethernet/realtek/r8169_main.c:4583) r8169 race at unknown origin, with read to 0xffff888117e43510 of 4 bytes by interrupt on cpu 21: rtl8169_poll (drivers/net/ethernet/realtek/r8169_main.c:4430 drivers/net/ethernet/realtek/r8169_main.c:4583) 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: 0x80003fff -> 0x3402805f 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 ================================================================== drivers/net/ethernet/realtek/r8169_main.c: ========================================== 4429 → 4430 status = le32_to_cpu(desc->opts1); 4431 if (status & DescOwn) 4432 break; 4433 4434 /* This barrier is needed to keep us from reading 4435 * any other fields out of the Rx descriptor until 4436 * we know the status of DescOwn 4437 */ 4438 dma_rmb(); 4439 4440 if (unlikely(status & RxRES)) { 4441 if (net_ratelimit()) 4442 netdev_warn(dev, "Rx ERROR. status = %08x\n", Marco Elver explained that dma_rmb() doesn't prevent the compiler to tear up the access to desc->opts1 which can be written to concurrently. READ_ONCE() should prevent that from happening: 4429 → 4430 status = le32_to_cpu(READ_ONCE(desc->opts1)); 4431 if (status & DescOwn) 4432 break; 4433 As the consequence of this fix, this KCSAN warning was eliminated. Fixes: 6202806e7c03a ("r8169: drop member opts1_mask from struct rtl8169_private") Suggested-by: Marco Elver Cc: Heiner Kallweit Cc: nic_swsd@realtek.com Cc: "David S. Miller" Cc: Eric Dumazet Cc: Jakub Kicinski Cc: Paolo Abeni 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 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/ethernet/realtek/r8169_main.c index 281aaa851847..81be6085a480 100644 --- a/drivers/net/ethernet/realtek/r8169_main.c +++ b/drivers/net/ethernet/realtek/r8169_main.c @@ -4427,7 +4427,7 @@ static int rtl_rx(struct net_device *dev, struct rtl8169_private *tp, int budget dma_addr_t addr; u32 status; - status = le32_to_cpu(desc->opts1); + status = le32_to_cpu(READ_ONCE(desc->opts1)); if (status & DescOwn) break;