devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Fainelli <f.fainelli-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Russell King - ARM Linux <linux-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org>
Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	"Frank Rowand"
	<frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	"Grant Likely"
	<grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
	"Iyappan Subramanian" <isubramanian-qTEPVZfXA3Y@public.gmane.org>,
	"Keyur Chudgar" <kchudgar-qTEPVZfXA3Y@public.gmane.org>,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linuxppc-dev-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org,
	"Li Yang" <leoli-KZfg59tc24xl57MIdRCFDg@public.gmane.org>,
	"Michal Simek"
	<michal.simek-gjFFaj9aHVfQT0dZR+AlfA@public.gmane.org>,
	netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	"Robert Richter" <rric-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	"Rob Herring" <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	"Sören Brinkmann"
	<soren.brinkmann-gjFFaj9aHVfQT0dZR+AlfA@public.gmane.org>,
	"Sunil Goutham"
	<sgoutham-YGCgFSpz5w/QT0dZR+AlfA@public.gmane.org>,
	"Thomas Petazzoni"
	<thomas.petazzoni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
Subject: Re: [PATCH 0/7] Phy and mdiobus fixes
Date: Sat, 19 Sep 2015 13:49:35 -0700	[thread overview]
Message-ID: <55FDCA5F.9090604@gmail.com> (raw)
In-Reply-To: <20150918094625.GB21084-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org>

Le 09/18/15 02:46, Russell King - ARM Linux a écrit :
> Hi,
> 
> While looking at the phy code, I identified a number of weaknesses
> where refcounting on device structures was being leaked, where
> modules could be removed while in-use, and where the fixed-phy could
> end up having unintended consequences caused by incorrect calls to
> fixed_phy_update_state().
> 
> This patch series resolves those issues, some of which were discovered
> with testing on an Armada 388 board.  Not all patches are fully tested,
> particularly the one which touches several network drivers.
> 
> When resolving the struct device refcounting problems, several different
> solutions were considered before settling on the implementation here -
> one of the considerations was to avoid touching many network drivers.
> The solution here is:
> 
> 	phy_attach*() - takes a refcount
> 	phy_detach*() - drops the phy_attach refcount
> 
> Provided drivers always attach and detach their phys, which they should
> already be doing, this should change nothing, even if they leak a refcount.
> 
> 	of_phy_find_device() and of_* functions which use that take
> 	a refcount.  Arrange for this refcount to be dropped once
> 	the phy is attached.
> 
> This is the reason why the previous change is important - we can't drop
> this refcount taken by of_phy_find_device() until something else holds
> a reference on the device.  This resolves the leaked refcount caused by
> using of_phy_connect() or of_phy_attach().
> 
> Even without the above changes, these drivers are leaking by calling
> of_phy_find_device().  These drivers are addressed by adding the
> appropriate release of that refcount.
> 
> The mdiobus code also suffered from the same kind of leak, but thankfully
> this only happened in one place - the mdio-mux code.
> 
> I also found that the try_module_get() in the phy layer code was utterly
> useless: phydev->dev.driver was guaranteed to always be NULL, so
> try_module_get() was always being called with a NULL argument.  I proved
> this with my SFP code, which declares its own MDIO bus - the module use
> count was never incremented irrespective of how I set the MDIO bus up.
> This allowed the MDIO bus code to be removed from the kernel while there
> were still PHYs attached to it.
> 
> One other bug was discovered: while using in-band-status with mvneta, it
> was found that if a real phy is attached with in-band-status enabled,
> and another ethernet interface is using the fixed-phy infrastructure, the
> interface using the fixed-phy infrastructure is configured according to
> the other interface using the in-band-status - which is caused by the
> fixed-phy code not verifying that the phy_device passed in is actually
> a fixed-phy device, rather than a real MDIO phy.
> 
> Lastly, having mdio_bus reversing phy_device_register() internals seems
> like a layering violation - it's trivial to move that code to the phy
> device layer.

Reviewed-by: Florian Fainelli <f.fainelli-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

Thanks!
-- 
Florian
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

      parent reply	other threads:[~2015-09-19 20:49 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-18  9:46 [PATCH 0/7] Phy and mdiobus fixes Russell King - ARM Linux
2015-09-18  9:47 ` [PATCH 1/7] phy: fix of_mdio_find_bus() device refcount leak Russell King
2015-09-18  9:47 ` [PATCH 2/7] phy: fix mdiobus module safety Russell King
2015-09-18  9:47 ` [PATCH 3/7] phy: add proper phy struct device refcounting Russell King
2015-09-18  9:47 ` [PATCH 4/7] of_mdio: fix MDIO phy " Russell King
2015-09-18  9:47 ` [PATCH 5/7] net: fix phy refcounting in a bunch of drivers Russell King
2015-09-18  9:47 ` [PATCH 6/7] phy: fixed-phy: properly validate phy in fixed_phy_update_state() Russell King
2015-09-18  9:47 ` [PATCH 7/7] phy: add phy_device_remove() Russell King
2015-09-18  9:54 ` [PATCH 1/7] phy: fix of_mdio_find_bus() device refcount leak Russell King
2015-09-21 19:01   ` David Miller
     [not found]     ` <20150921.120159.326170798236851436.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2015-09-21 19:32       ` Russell King - ARM Linux
2015-09-21 22:08         ` David Miller
2015-09-18  9:55 ` [PATCH 2/7] phy: fix mdiobus module safety Russell King
2015-09-18  9:55 ` [PATCH 3/7] phy: add proper phy struct device refcounting Russell King
2015-09-18  9:55 ` [PATCH 4/7] of_mdio: fix MDIO phy " Russell King
2015-09-18 14:40   ` Rob Herring
2015-09-18  9:55 ` [PATCH 5/7] net: fix phy refcounting in a bunch of drivers Russell King
2015-09-18  9:55 ` [PATCH 6/7] phy: fixed-phy: properly validate phy in fixed_phy_update_state() Russell King
2015-09-18  9:55 ` [PATCH 7/7] phy: add phy_device_remove() Russell King
     [not found] ` <20150918094625.GB21084-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org>
2015-09-18  9:56   ` [PATCH 0/7] Phy and mdiobus fixes Russell King - ARM Linux
2015-09-18 15:01     ` Sören Brinkmann
2015-09-18 15:20       ` Russell King - ARM Linux
2015-09-19 20:49   ` Florian Fainelli [this message]

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=55FDCA5F.9090604@gmail.com \
    --to=f.fainelli-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=grant.likely-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
    --cc=isubramanian-qTEPVZfXA3Y@public.gmane.org \
    --cc=kchudgar-qTEPVZfXA3Y@public.gmane.org \
    --cc=leoli-KZfg59tc24xl57MIdRCFDg@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org \
    --cc=linuxppc-dev-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org \
    --cc=michal.simek-gjFFaj9aHVfQT0dZR+AlfA@public.gmane.org \
    --cc=netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=rric-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=sgoutham-YGCgFSpz5w/QT0dZR+AlfA@public.gmane.org \
    --cc=soren.brinkmann-gjFFaj9aHVfQT0dZR+AlfA@public.gmane.org \
    --cc=thomas.petazzoni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org \
    /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).