Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp2630444rwa; Mon, 22 Aug 2022 10:44:50 -0700 (PDT) X-Google-Smtp-Source: AA6agR6v5j3G294v4569yrpy4jngNyKOOCHk64z+BjMmV6VVffSLEYae0+BzvtyEFrKHVhz8PSV0 X-Received: by 2002:a17:90a:8b82:b0:1fa:973c:1d34 with SMTP id z2-20020a17090a8b8200b001fa973c1d34mr30052057pjn.31.1661190290368; Mon, 22 Aug 2022 10:44:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661190290; cv=none; d=google.com; s=arc-20160816; b=OYaAcar2U5etQzJI4RpePupNCRlLK82+mBuPhz+0eUFiGap03uMIbIe56lOoPwAgRK 3PL/jPYt8GfJTbtX31dqLBHdxRiRV1WGj7iGf24nravYfPiZrhNXJVMfjYL2+qnotNIo z4YSb1OxJTMYxXKq+CsW/8tvISEWEkcN84fo+7hGa91K+8bEYL4zrr5XyGNnFyEf83LE AxvhtZDDCeWgKkCruMFVSlql3RXqxMkSo9uAKjPmgglROibvc00YVwLBVzz6FdeMbjUC +tmhWGyo/+qYTjs9Gt1Il5C10EstlKO/vCBSr0U5hupH3IIbVVyEm+G7x5iXRI86Ut31 BmWA== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=GfKp3f5Ymjt+SyhQzhhn3iVb0y52yLjbBLoTgaA5xs4=; b=Stiotzb6i4OKRvdrMJTks0flQvxpNUsm7cvux6cUekEj5rY+dd6kDvI//XvU6W7huh oDH1dx1/oswl/RTNzyf+oI17oI1hPZYrwOgJMgo0DnljGrgkSY0LpA/mx1igiGdH61Vm uJXlnN/hjN/CfBCEkgKbiCaAA8jIevIBD7JaO7czorzPxbw/tTeWmplj4N6Lmr5vYBIs IDyi6E+ouwHRpvxEpLR+iqnXP9fS962AHv4BWB+HYHLuIn0M3JZheOQuEloe/5oN00Nt YAIsVvvF+/KBMevqBu07IGUnOUnof0tPrOQS3Wwm81c7jauz6DEmj1qn6Ey9lrjxzQkT Aywg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b=uLIU1bPi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nv13-20020a17090b1b4d00b001fb4b3f63f0si2162094pjb.146.2022.08.22.10.44.38; Mon, 22 Aug 2022 10:44:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b=uLIU1bPi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235637AbiHVRKz (ORCPT + 99 others); Mon, 22 Aug 2022 13:10:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237175AbiHVRKF (ORCPT ); Mon, 22 Aug 2022 13:10:05 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [185.16.172.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D578D12080; Mon, 22 Aug 2022 10:09:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=In-Reply-To:Content-Disposition:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:From:Sender:Reply-To:Subject: Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=GfKp3f5Ymjt+SyhQzhhn3iVb0y52yLjbBLoTgaA5xs4=; b=uLIU1bPiItlu2CDatqKOvToPOH nbgk39pNb19R5/5maF372B1mztcC+7Mjyx0KZysUxfFVvNDJz+zvwWox+cpv1B/5LWeghFG8BX2DV PpbEGAbKGfRcfx7aN2glwSt4K+8/tJoZOxsThRjcPJ/AurT2ZEU3tTYeOUsQzTm7OmKU=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1oQAvV-00EFF2-Gk; Mon, 22 Aug 2022 19:09:25 +0200 Date: Mon, 22 Aug 2022 19:09:25 +0200 From: Andrew Lunn To: Sean Anderson Cc: "Russell King (Oracle)" , Jakub Kicinski , Heiner Kallweit , netdev@vger.kernel.org, Paolo Abeni , "David S . Miller" , linux-kernel@vger.kernel.org, Eric Dumazet , Vladimir Oltean Subject: Re: [PATCH net] net: phy: Warn if phy is attached when removing Message-ID: References: <20220816163701.1578850-1-sean.anderson@seco.com> <20220819164519.2c71823e@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, 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 > In the last thread I posted this snippet: > > diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c > index a74b320f5b27..05894e1c3e59 100644 > --- a/drivers/net/phy/phy_device.c > +++ b/drivers/net/phy/phy_device.c > @@ -27,6 +27,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -3111,6 +3112,13 @@ static int phy_remove(struct device *dev) > { > struct phy_device *phydev = to_phy_device(dev); > > + // I'm pretty sure this races with multiple unbinds... > + rtnl_lock(); > + device_unlock(dev); > + dev_close(phydev->attached_dev); > + device_lock(dev); > + rtnl_unlock(); > + WARN_ON(phydev->attached_dev); > + > cancel_delayed_work_sync(&phydev->state_queue); > > mutex_lock(&phydev->lock); > --- > > Would this be acceptable? Can the locking be fixed? Code like this should not be hidden in the PHY layer. If we decide to go down this path it probably should be in net/core/dev.c. I suggest you talk to the maintainers of that file, probably Eric Dumazet, give him a clear explanation of the problem, and see what he suggests. Andrew