From patchwork Mon Apr 26 04:20:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qingfang Deng X-Patchwork-Id: 1470200 X-Patchwork-Delegate: hauke@hauke-m.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1:d65d:64ff:fe57:4e05; helo=desiato.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=HYf6M1cn; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=FA7qB6xF; dkim-atps=neutral Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FTBZC2mZmz9sWH for ; Mon, 26 Apr 2021 14:22:27 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To:From: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=d8fV8os92IGgN3L1qAStapoeYZMapPgmiGX+iJM9zi4=; b=HYf6M1cn3Dlqfw DtX8kD7IFdMAjrGM5CY0menka408vZErmsNeR5G6OUeIRC87hVVDCT8cqrWCNckqMaLs9iJ0X5Xp9 nyIoFgj9jKJ145kjr6v9iDTf//uuJQJHdjX2OKtrclCiJXKiInBDuX4bLRaSvHGtwn4ARyExFvub/ AXsgwg2hgb0O3881OiLbeMnl0Uw6BFWk8YipG72vpS0YzYT6t4Lo4VJHxoBM3J6BM/9MRM15pQl5H rn9llPVI9QAE1HGse0+udAh6neW4YpwnliLYhqu2HJrmSkjujij0jEG6jAL73qV7uIwJdwnAnZJYZ SZXVnREfxgA8pEuRXrHg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lasjd-006rwT-3o; Mon, 26 Apr 2021 04:20:37 +0000 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lasjY-006rvb-CF for openwrt-devel@lists.openwrt.org; Mon, 26 Apr 2021 04:20:34 +0000 Received: by mail-pj1-x1032.google.com with SMTP id f6-20020a17090a6546b029015088cf4a1eso4506842pjs.2 for ; Sun, 25 Apr 2021 21:20:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=QRO38Ow0UyPlbQJi3g7dYULbAmOC0/7iirklV0H+iug=; b=FA7qB6xFUleGnP19VYyth1Ieg9/uz7pjMto1/cUHIMUxgV/8fWUTBjPFswCc/WflOH 3xC5kcC7nAcEUjmEOhYWul1rmQW8g8ae/NirAR8SnPvKKZ9Zx/bVMb9FNlu4NFTwx5ri 52fcaCiTcULZqy7A6pZcq91cRlr1YFohQ8cWjnLaqdhjn3zQWChW++edhY9hVOTXWy/U ANmqbJ8vbrEo6NEQ/jm59YsuMeRzTxSeJaz37+clTk/kbKKbcnq9Sq9pO2vgSXYl19/7 fxXZYx21LD0cgA4yTFTH7ROKPJKJK4S+uSZ42HPY91hkrYPRpMi7tWsbGFtqqYpkrWcS DNbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=QRO38Ow0UyPlbQJi3g7dYULbAmOC0/7iirklV0H+iug=; b=n4yaVbKwg0GSMsSOmH0YdbYTrwvUHgtlM4Yku5XsT3MnrtcMbar57aJEVJzsh1k+ib 2LaS8TJYW1LQOkM1fCK6VVdQiNK7JOG6vDTCk2rpmntbA4Q70k91F/faqDfTZgmgTRt/ G2+DunDHPJ98Cp9orVs9dJhXivUnxEztzbV1qERSCg4RQSGsZpArHcR8tXBRirdT8hjA MPrant0A5OPINJeiygl+CejxEcPX33u62JnhxXXixmx1Lxxz9yEUKzui9+W5EAFFCocc RkE/EvmxwULtD3LkFeN1+ZlIMK7wJlREG8G0oaqtReETDisOWClF7HG2VgfDt6w90wdl VD2g== X-Gm-Message-State: AOAM532rDAdIGz/c/kqMloJLj7bD5as3Wi84HF4QGHUICJ51yZ6gr2ux qRN1DZtWiuCzxrkilRjAMxx0Hlb4EjslnRXI X-Google-Smtp-Source: ABdhPJyZaYK9EtCFYCtDfu//H3VraHNyolXcm+Kp1MO7BO1wVspGXpmzwxnYUbmkIR4nlZPdnFC0Pw== X-Received: by 2002:a17:90a:d903:: with SMTP id c3mr11173836pjv.154.1619410829483; Sun, 25 Apr 2021 21:20:29 -0700 (PDT) Received: from localhost.localdomain ([138.197.212.246]) by smtp.gmail.com with ESMTPSA id h17sm10191010pfo.54.2021.04.25.21.20.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Apr 2021 21:20:28 -0700 (PDT) From: DENG Qingfang To: openwrt-devel@lists.openwrt.org Subject: [PATCH 19.07] ramips: mt7530 swconfig: fix race condition in register access Date: Mon, 26 Apr 2021 12:20:24 +0800 Message-Id: <20210426042024.4862-1-dqfext@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210426_052032_554369_4A0F495F X-CRM114-Status: GOOD ( 10.20 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: [ Upstream commit f99c9cd9c4d4c49a676d678327546fd41690fe2a ] The mt7530_{r,w}32 operation over MDIO uses 3 mdiobus operations and does not hold a lock, which causes a race condition when multiple threads try to access a register, they may get unexpected results [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [dqfext[at]gmail.com] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:1032 listed in] [list.dnswl.org] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org [ Upstream commit f99c9cd9c4d4c49a676d678327546fd41690fe2a ] The mt7530_{r,w}32 operation over MDIO uses 3 mdiobus operations and does not hold a lock, which causes a race condition when multiple threads try to access a register, they may get unexpected results. To avoid this, handle the MDIO lock manually, and use the unlocked __mdiobus_{read,write} in the critical section. This fixes the "Ghost VLAN" artifact[1] in MT7530/7621 when the VLAN operation and the swconfig LED link status poll race between each other. [1] https://forum.openwrt.org/t/mysterious-vlan-ids-on-mt7621-device/64495 Signed-off-by: DENG Qingfang --- .../drivers/net/ethernet/mediatek/mt7530.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/target/linux/ramips/files-4.14/drivers/net/ethernet/mediatek/mt7530.c b/target/linux/ramips/files-4.14/drivers/net/ethernet/mediatek/mt7530.c index 5216cb5..7fb76fc 100644 --- a/target/linux/ramips/files-4.14/drivers/net/ethernet/mediatek/mt7530.c +++ b/target/linux/ramips/files-4.14/drivers/net/ethernet/mediatek/mt7530.c @@ -310,9 +310,11 @@ mt7530_r32(struct mt7530_priv *priv, u32 reg) if (priv->bus) { u16 high, low; - mdiobus_write(priv->bus, 0x1f, 0x1f, (reg >> 6) & 0x3ff); - low = mdiobus_read(priv->bus, 0x1f, (reg >> 2) & 0xf); - high = mdiobus_read(priv->bus, 0x1f, 0x10); + mutex_lock(&priv->bus->mdio_lock); + __mdiobus_write(priv->bus, 0x1f, 0x1f, (reg >> 6) & 0x3ff); + low = __mdiobus_read(priv->bus, 0x1f, (reg >> 2) & 0xf); + high = __mdiobus_read(priv->bus, 0x1f, 0x10); + mutex_unlock(&priv->bus->mdio_lock); return (high << 16) | (low & 0xffff); } @@ -327,9 +329,11 @@ static void mt7530_w32(struct mt7530_priv *priv, u32 reg, u32 val) { if (priv->bus) { - mdiobus_write(priv->bus, 0x1f, 0x1f, (reg >> 6) & 0x3ff); - mdiobus_write(priv->bus, 0x1f, (reg >> 2) & 0xf, val & 0xffff); - mdiobus_write(priv->bus, 0x1f, 0x10, val >> 16); + mutex_lock(&priv->bus->mdio_lock); + __mdiobus_write(priv->bus, 0x1f, 0x1f, (reg >> 6) & 0x3ff); + __mdiobus_write(priv->bus, 0x1f, (reg >> 2) & 0xf, val & 0xffff); + __mdiobus_write(priv->bus, 0x1f, 0x10, val >> 16); + mutex_unlock(&priv->bus->mdio_lock); return; }