Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4856399rdb; Tue, 12 Dec 2023 11:07:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IHp7cc2JPy8GvtO7F2l0se1FKrIbSA+/WTAv6dpKKQEzGx6cOIuAMpqXDLVmmfzzEMPvg+W X-Received: by 2002:a17:902:ecc1:b0:1d0:60cc:7ebb with SMTP id a1-20020a170902ecc100b001d060cc7ebbmr8030028plh.25.1702408035353; Tue, 12 Dec 2023 11:07:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702408035; cv=none; d=google.com; s=arc-20160816; b=SkXbMGlXMc7P69DbgbPv3FcilX62gSzT0bUJ/mN5AtochXvmg2RjLlJDiLgjKaIvAi GHFMOKEVwD4raqFyZwH3Rz8kKSVbUDYK+Ig+kq+3I91XzGVVjBzKTz6AY26s5cn23UeL 7nusbKEbkgAl9f4IcZfv7N6t7Ta0Wu41ArIGTLDCTmUxw33nP+b4wBDs/SwOrS2/2M2H 4Uff5io7HxBpxQ+J+hexgsWHrl2rN2gtBMgHpCIFPYbxJH5NDSgVP7BFrVSV4G0CRURg tC+l6ud5IJmF18nAfdOmUilHb9iO2yFGc+o4a5TuM3dAcbi9/gFNTeYnOnT0sadnx/pT fX0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=WDyfD09PAON4LZuIakiggNErHuklPdxdPhsExRCINO0=; fh=0CjR/P59gkS3RoA1MzYD3TAB1GMUolY2z17tQE+puF0=; b=q6ukAVsU0hk0hqVNX3YE3+BcASFXs/+57V+P0Wc0dHynOWfTNz1MTZN1lqEqar0CIm DUX0t182cz5hkpStsFrdYgbJXzOMIul0q0pcpt/7e7p7zvd5YmOmKFuDdFA1xFWI0rm8 gwV9QDL62FYXFMJCd/GFyQrcU5wRFbYSMFAkC9YtLgoXs1yAWfqAOMVzCifS4n53UQt4 79vY8Y/6SPPgCt2/aFnD/tBSRFoqNWfQMTO61F6s8WJtGs01t8AfBHQ00CMJ04Bzn5PE kKg0WUoHLDpBwfiVq+4XO8AJcgGn3CuTOlADUDy3Y1CwYDBpqkPxwlVAgTzJuh+JPzJr nMNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=vMLMHfKu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id y15-20020a17090322cf00b001d08cfd3933si8374013plg.394.2023.12.12.11.07.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 11:07:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=vMLMHfKu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id B74F180486B6; Tue, 12 Dec 2023 11:07:13 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376678AbjLLTHC (ORCPT + 99 others); Tue, 12 Dec 2023 14:07:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230181AbjLLTHA (ORCPT ); Tue, 12 Dec 2023 14:07:00 -0500 Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [IPv6:2001:4d48:ad52:32c8:5054:ff:fe00:142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DE3491; Tue, 12 Dec 2023 11:07:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=WDyfD09PAON4LZuIakiggNErHuklPdxdPhsExRCINO0=; b=vMLMHfKuWjpOeCgqj+OLSIbKsG WCGncmPzax+s7ErnI8PlwoAcxDgi7JafMKVhEz++U+ZVQ0XP+ohiULCrVXD/1dsSQSk5yjcm0zHBK XJSYcF2axTnD1zNtKD5UhlW9zlwLRjW3JYr1H0mjXegUeu0pkeLE3MwLfePZ5fVAWlL23Am0I3PL5 NT+gIKBnCPzCh8jjkzWC4o0487W4InM+Or5UWQfd6BDMvNIV9pIIIE1jc+pWQizWWt+hHLFeDOT09 rdDi0N33mI6WDlJ+FmCYpG7ErF4HC1LSmRNgAAZM97w65nNqWkVz7kUwz5Y9zFE6ftvqJdadzd2vK vwdMQbbQ==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:35082) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rD85g-0007Hq-0s; Tue, 12 Dec 2023 19:06:48 +0000 Received: from linux by shell.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1rD85e-0000gA-UH; Tue, 12 Dec 2023 19:06:46 +0000 Date: Tue, 12 Dec 2023 19:06:46 +0000 From: "Russell King (Oracle)" To: Serge Semin Cc: Andrew Lunn , Heiner Kallweit , Alexandre Torgue , Jose Abreu , Jose Abreu , Maxime Chevallier , Tomer Maimon , Rob Herring , Krzysztof Kozlowski , Conor Dooley , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , openbmc@lists.ozlabs.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net-next 06/16] net: pcs: xpcs: Avoid creating dummy XPCS MDIO device Message-ID: References: <20231205103559.9605-1-fancer.lancer@gmail.com> <20231205103559.9605-7-fancer.lancer@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: Russell King (Oracle) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Tue, 12 Dec 2023 11:07:13 -0800 (PST) On Tue, Dec 12, 2023 at 06:26:16PM +0300, Serge Semin wrote: > I would have used in the first place if it was externally visible, but > it's defined as static. Do you suggest to make it global or ... That would be one option - I didn't make it visible when I introduced it beacuse there were no users for it. > > At some point, we should implement > > mdiobus_get_mdiodev() which also deals with the refcount. > > ... create mdiobus_get_mdiodev() instead? > > * Note in the commit message I mentioned that having a getter would be > * better than directly touching the mii_bus instance guts. What I'm thinking is: /** * mdiobus_get_mdiodev() - get a mdiodev for the specified bus * @bus: mii_bus to get mdio device from * @addr: mdio address of mdio device * * Return the struct mdio_device attached to the MII bus @bus at MDIO * address @addr. On success, the refcount on the device will be * increased, which must be dropped using mdio_device_put(), and the * mdio device returned. Otherwise, returns NULL. */ struct mdio_device *mdiobus_get_mdiodev(struct mii_bus *bus, int addr) { struct mdio_device *mdiodev; mdiodev = mdiobus_find_device(bus, addr); if (mdiodev) get_device(&mdiodev->dev); return mdiodev; } EXPORT_SYMBOL(mdiobus_get_mdiodev); should do it, and will hold a reference on the mdiodev structure (which won't be freed) and also on the mii_bus (since this device is a child of the bus device, the parent can't be released until the child has been, so struct mii_bus should at least stay around.) What would help the "the bus driver has been unbound" situation is if we took the mdio_lock on the bus, and then set the {read,write}{,_c45} functions to dummy stubs when the bus is being unregistered which then return e.g. -ENXIO. That will probably make unbinding/unloading all MDIO bus drivers safe from kernel oops, although phylib will spit out a non-useful backtrace if it tries an access. I don't think there's much which can be done about that - I did propose a patch to change that behaviour but apparently folk like having it! It isn't perfect - it's racy, but then accessing mdio_map[] is inherently racy due to no locking with mdiobus_.*register_device(). At least if we have everyone using a proper getter function rather than directly fiddling with bus->mdio_map[]. We only have one driver that accesses it directly at the moment (mscc_ptp): dev = phydev->mdio.bus->mdio_map[vsc8531->ts_base_addr]; phydev = container_of(dev, struct phy_device, mdio); return phydev->priv; and that should really be using mdiobus_get_phy(). -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!