From: Andrew Lunn <andrew@lunn.ch>
To: Florian Fainelli <f.fainelli@gmail.com>
Cc: David Miller <davem@davemloft.net>,
netdev <netdev@vger.kernel.org>,
Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Subject: Re: [PATCH net-next] net: phy: mdio-boardinfo: Allow recursive mdiobus_register()
Date: Thu, 19 Apr 2018 02:33:18 +0200 [thread overview]
Message-ID: <20180419003318.GA16866@lunn.ch> (raw)
In-Reply-To: <5966673b-f091-a180-71b1-96d35f845e17@gmail.com>
On Wed, Apr 18, 2018 at 05:14:36PM -0700, Florian Fainelli wrote:
> On 04/18/2018 05:00 PM, Andrew Lunn wrote:
> > mdiobus_register will search for any mdiobus board info registered for
> > the bus being registered. If found, it will probe devices on the bus.
> > That device, if for example it is an ethernet switch, may then try to
> > register an mdio bus. Thus we need to allow recursive calls to
> > mdiobus_register.
> >
> > Holding the mdio_board_lock will cause a deadlock during this
> > recursion. Release the lock and use list_for_each_entry_safe.
> >
> > Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> > ---
> > drivers/net/phy/mdio-boardinfo.c | 5 ++++-
> > 1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/net/phy/mdio-boardinfo.c b/drivers/net/phy/mdio-boardinfo.c
> > index 1861f387820d..863496fa5d13 100644
> > --- a/drivers/net/phy/mdio-boardinfo.c
> > +++ b/drivers/net/phy/mdio-boardinfo.c
> > @@ -30,17 +30,20 @@ void mdiobus_setup_mdiodev_from_board_info(struct mii_bus *bus,
> > struct mdio_board_info *bi))
> > {
> > struct mdio_board_entry *be;
> > + struct mdio_board_entry *tmp;
> > struct mdio_board_info *bi;
> > int ret;
> >
> > mutex_lock(&mdio_board_lock);
>
> Don't you need to drop that lock here?
>
> > - list_for_each_entry(be, &mdio_board_list, list) {
> > + list_for_each_entry_safe(be, tmp, &mdio_board_list, list) {
> > bi = &be->board_info;
> >
> > if (strcmp(bus->id, bi->bus_id))
> > continue;
> >
> > + mutex_unlock(&mdio_board_lock);
> > ret = cb(bus, bi);
> > + mutex_lock(&mdio_board_lock);
> > if (ret)
> > continue;
> >
>
> And conversely drop the unlock from the end of this function?
No. The recursion happens inside the ret = cb(bus, bi). We need the
lock to be available during that. The lock itself is protecting the
list, so we need to hold the lock while using the list.
> Also, would you rather target "net" for this change since this appears
> to be a bug fix?
As far as i know, there is no in tree driver which can trigger
this. It requires the use of a switch instantiated using mdio_board
info, and the switch then needs to add another mdio bus in its probe
function. The only in tree code doing anything like this is dsa_loop,
and it does not register an mdio bus.
However, later this cycle i plan to add support for Zodiac's SCU3, and
it does trigger this deadlock. So net-next is sufficient for my.
Andrew
next prev parent reply other threads:[~2018-04-19 0:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-19 0:00 [PATCH net-next] net: phy: mdio-boardinfo: Allow recursive mdiobus_register() Andrew Lunn
2018-04-19 0:14 ` Florian Fainelli
2018-04-19 0:33 ` Andrew Lunn [this message]
2018-04-20 14:34 ` David Miller
2018-04-20 21:59 ` Andrew Lunn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180419003318.GA16866@lunn.ch \
--to=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=f.fainelli@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=vivien.didelot@savoirfairelinux.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).