linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: f.fainelli@gmail.com (Florian Fainelli)
To: linux-arm-kernel@lists.infradead.org
Subject: [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@n2100.arm.linux.org.uk>

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@gmail.com>

Thanks!
-- 
Florian

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

Thread overview: 22+ 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
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  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
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@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.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).