From nobody Mon Nov 13 15:20:21 2023 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4STY5d65QKz515pM; Mon, 13 Nov 2023 15:20:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4STY5d4nq3z3TFK; Mon, 13 Nov 2023 15:20:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1699888821; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=IDOLAWhdnmQ2QkC56MXASswV70cPeYCdNuOQwrlGtx8=; b=mwWmgJd6DsJbEUZIh7P/jYwQXsjKVpnE4fDMG6E5IRnAj/EL/dvQJzvKQPUiA+AJDb4NXZ 33zzXFYlMgHnr114w1i7CeguvlZu7iNk/i/QSCYt11XO6VfvXWC0aFYeQwoVPgsU95GfSL Br9yPwNg/Y+e2gYZ4SRAFIl0MbBV3UzAHTadfZc8E3i3M/0D7BAiNvglVyUZQll9coubhq PfNAUvJU86oMdsU/8ZqoNHfa1ZPPRY+JyJH3FOxPO1Y5mVYrkYhsZVpDrC0im8eWV3Z71U gEWmeV4sg/O6MyUmj3C94tEPR4UgI56Hrl2VEpOgjkDtojgmk0OkoZ0EYxMN2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1699888821; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=IDOLAWhdnmQ2QkC56MXASswV70cPeYCdNuOQwrlGtx8=; b=VWTsdCe2pt8r/xxhH+lyYnXgIiNG/+xGVMVU+i750zLSnJnhWy37t1x0qOvg3D0OdMR5QE cbphwi9w9IVj8NrYomed6BDuA9Hc9Nu0JhWS6QOlKFEBQZoVg42eZFR8T/5igLAH3fFqby T1fSELQCQiWeb4/BT/q8OiZYBpPAByjQqllCWjn9ad6RsySE80fK3Xlm2rDZITH2R66HxT V7yexNO1HZ/tjJ22qUA2qpPuzn218/zI9mJXyQZnp3oGWvnr1m0DSJzmI4if1rmUzCvq+3 e6QcKpuruCQ87l8cz/NYNbi0WP8g8IFoZrLoUvCgNJyWrVbLkwRveJzrV3WbdQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1699888821; a=rsa-sha256; cv=none; b=emPLoflBACQrDOi6igca8ARThP4IQMr5NWEhBnI1azESLV9ePm5tZsKhJClAgAkFFr3CJe ate3hhcufalcq2ZvvsBbtGs71wwXyDOI9rAcf0pATNsghWtdtvFFoNl9d/mCtmNutrTi8w dKS7NyXXdh0xkrKlulP+G+/K33YT/QtTtCoSZ08jiwzNBPjPr6JsnlVbqvJ/pwxVJEvhKp UaNiTeObYLQ9V4ftpYmvE5AkEylHwaKtEwdTyHuO9HlvIkuR2kR4Jq+HN7mH3cbzY0I13J cZUbiucnyddnXyWDYP0+AMrRwGnzZUZRdOPj5yqmSfB2vsmPvtCCUTR2Ago8hw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4STY5d3sdgz19KM; Mon, 13 Nov 2023 15:20:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3ADFKLvl052457; Mon, 13 Nov 2023 15:20:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3ADFKL4n052454; Mon, 13 Nov 2023 15:20:21 GMT (envelope-from git) Date: Mon, 13 Nov 2023 15:20:21 GMT Message-Id: <202311131520.3ADFKL4n052454@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 766cceba19fe - stable/14 - e6000sw: Fix locking in miibus_{read,write}reg implementations List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 766cceba19fe05095d81994e930a489ad545d42b Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=766cceba19fe05095d81994e930a489ad545d42b commit 766cceba19fe05095d81994e930a489ad545d42b Author: Mark Johnston AuthorDate: 2023-11-06 19:57:56 +0000 Commit: Mark Johnston CommitDate: 2023-11-13 14:41:50 +0000 e6000sw: Fix locking in miibus_{read,write}reg implementations Commit 469290648005e13b819a19353032ca53dda4378f made e6000sw's implementation of miibus_(read|write)reg assume that the softc lock is held. I presume that is to avoid lock recursion in e6000sw_attach() -> e6000sw_attach_miibus() -> mii_attach() -> MIIBUS_READREG(). However, the lock assertion in e6000sw_readphy_locked() can fail if a different driver uses the interface to probe registers. Work around the problem by providing implementations which lock the softc if it is not already locked. PR: 274795 Fixes: 469290648005 ("e6000sw: add readphy and writephy wrappers") Reviewed by: kp, imp MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D42466 (cherry picked from commit 725962a9f4c050b21488edd58d317e87c76d6f66) --- sys/dev/etherswitch/e6000sw/e6000sw.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/sys/dev/etherswitch/e6000sw/e6000sw.c b/sys/dev/etherswitch/e6000sw/e6000sw.c index 768d1b927e3e..95f1a2e96db6 100644 --- a/sys/dev/etherswitch/e6000sw/e6000sw.c +++ b/sys/dev/etherswitch/e6000sw/e6000sw.c @@ -66,6 +66,7 @@ MALLOC_DEFINE(M_E6000SW, "e6000sw", "e6000sw switch"); #define E6000SW_UNLOCK(_sc) sx_unlock(&(_sc)->sx) #define E6000SW_LOCK_ASSERT(_sc, _what) sx_assert(&(_sc)->sx, (_what)) #define E6000SW_TRYLOCK(_sc) sx_tryxlock(&(_sc)->sx) +#define E6000SW_LOCKED(_sc) sx_xlocked(&(_sc)->sx) #define E6000SW_WAITREADY(_sc, _reg, _bit) \ e6000sw_waitready((_sc), REG_GLOBAL, (_reg), (_bit)) #define E6000SW_WAITREADY2(_sc, _reg, _bit) \ @@ -169,8 +170,8 @@ static device_method_t e6000sw_methods[] = { DEVMETHOD(bus_add_child, device_add_child_ordered), /* mii interface */ - DEVMETHOD(miibus_readreg, e6000sw_readphy_locked), - DEVMETHOD(miibus_writereg, e6000sw_writephy_locked), + DEVMETHOD(miibus_readreg, e6000sw_readphy), + DEVMETHOD(miibus_writereg, e6000sw_writephy), /* etherswitch interface */ DEVMETHOD(etherswitch_getinfo, e6000sw_getinfo), @@ -744,17 +745,20 @@ e6000sw_write_xmdio(device_t dev, int phy, int devaddr, int devreg, int val) return (0); } -static int e6000sw_readphy(device_t dev, int phy, int reg) +static int +e6000sw_readphy(device_t dev, int phy, int reg) { e6000sw_softc_t *sc; - int ret; + int locked, ret; sc = device_get_softc(dev); - E6000SW_LOCK_ASSERT(sc, SA_UNLOCKED); - E6000SW_LOCK(sc); + locked = E6000SW_LOCKED(sc); + if (!locked) + E6000SW_LOCK(sc); ret = e6000sw_readphy_locked(dev, phy, reg); - E6000SW_UNLOCK(sc); + if (!locked) + E6000SW_UNLOCK(sc); return (ret); } @@ -795,17 +799,20 @@ e6000sw_readphy_locked(device_t dev, int phy, int reg) return (val & PHY_DATA_MASK); } -static int e6000sw_writephy(device_t dev, int phy, int reg, int data) +static int +e6000sw_writephy(device_t dev, int phy, int reg, int data) { e6000sw_softc_t *sc; - int ret; + int locked, ret; sc = device_get_softc(dev); - E6000SW_LOCK_ASSERT(sc, SA_UNLOCKED); - E6000SW_LOCK(sc); + locked = E6000SW_LOCKED(sc); + if (!locked) + E6000SW_LOCK(sc); ret = e6000sw_writephy_locked(dev, phy, reg, data); - E6000SW_UNLOCK(sc); + if (!locked) + E6000SW_UNLOCK(sc); return (ret); }