Path: csiph.com!news.redatomik.org!aioe.org!bofh.it!news.nic.it!robomod From: Ben Hutchings Newsgroups: linux.kernel Subject: [PATCH 3.16 042/306] phy: sun4i-usb: Use spinlock to guard phyctl register access Date: Thu, 16 Feb 2017 01:10:02 +0100 Message-ID: References: X-Original-To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 X-Mailer: LinuxStableQueue (scripts by bwh) X-Sa-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-Sa-Exim-Mail-From: ben@decadent.org.uk X-Sa-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: robomod@news.nic.it List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Approved: robomod@news.nic.it Lines: 95 Organization: linux.* mail to news gateway X-Original-Cc: akpm@linux-foundation.org, "Kishon Vijay Abraham I" , "Hans de Goede" , "Chen-Yu Tsai" X-Original-Date: Wed, 15 Feb 2017 22:41:40 +0000 X-Original-Message-ID: X-Original-References: X-Original-Sender: linux-kernel-owner@vger.kernel.org Xref: csiph.com linux.kernel:1582078 3.16.40-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Chen-Yu Tsai commit 919ab2524c52e5f801d8873f09145ce822cdd43a upstream. The musb driver calls into this phy driver to disable/enable squelch detection. This function was introduced in 24fe86a617c5 ("phy: sun4i-usb: Add a sunxi specific function for setting squelch-detect"). This function in turn calls sun4i_usb_phy_write, which uses a mutex to guard the common access register. Unfortunately musb does this in atomic context, which results in the following warning with lock debugging enabled: BUG: sleeping function called from invalid context at kernel/locking/mutex.c:97 in_atomic(): 1, irqs_disabled(): 128, pid: 96, name: kworker/0:2 CPU: 0 PID: 96 Comm: kworker/0:2 Not tainted 4.8.0-rc4-00181-gd502f8ad1c3e #13 Hardware name: Allwinner sun8i Family Workqueue: events musb_deassert_reset [] (unwind_backtrace) from [] (show_stack+0xb/0xc) [] (show_stack) from [] (dump_stack+0x67/0x74) [] (dump_stack) from [] (mutex_lock+0x15/0x2c) [] (mutex_lock) from [] (sun4i_usb_phy_write+0x39/0xec) [] (sun4i_usb_phy_write) from [] (musb_port_reset+0xfb/0x184) [] (musb_port_reset) from [] (musb_deassert_reset+0x1f/0x2c) [] (musb_deassert_reset) from [] (process_one_work+0x129/0x2b8) [] (process_one_work) from [] (worker_thread+0xf3/0x424) [] (worker_thread) from [] (kthread+0xa1/0xb8) [] (kthread) from [] (ret_from_fork+0x11/0x20) Since the register access is mmio, we can use a spinlock to guard this specific access, rather than the mutex that guards the entire phy. Fixes: ba4bdc9e1dc0 ("PHY: sunxi: Add driver for sunxi usb phy") Cc: Hans de Goede Signed-off-by: Chen-Yu Tsai Reviewed-by: Hans de Goede Signed-off-by: Kishon Vijay Abraham I Signed-off-by: Ben Hutchings --- drivers/phy/phy-sun4i-usb.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) --- a/drivers/phy/phy-sun4i-usb.c +++ b/drivers/phy/phy-sun4i-usb.c @@ -32,6 +32,7 @@ #include #include #include +#include #define REG_ISCR 0x00 #define REG_PHYCTL 0x04 @@ -62,7 +63,7 @@ struct sun4i_usb_phy_data { void __iomem *base; - struct mutex mutex; + spinlock_t reg_lock; /* guard access to phyctl reg */ int num_phys; u32 disc_thresh; struct sun4i_usb_phy { @@ -83,9 +84,10 @@ static void sun4i_usb_phy_write(struct s { struct sun4i_usb_phy_data *phy_data = to_sun4i_usb_phy_data(phy); u32 temp, usbc_bit = BIT(phy->index * 2); + unsigned long flags; int i; - mutex_lock(&phy_data->mutex); + spin_lock_irqsave(&phy_data->reg_lock, flags); for (i = 0; i < len; i++) { temp = readl(phy_data->base + REG_PHYCTL); @@ -117,7 +119,8 @@ static void sun4i_usb_phy_write(struct s data >>= 1; } - mutex_unlock(&phy_data->mutex); + + spin_unlock_irqrestore(&phy_data->reg_lock, flags); } static void sun4i_usb_phy_passby(struct sun4i_usb_phy *phy, int enable) @@ -232,7 +235,7 @@ static int sun4i_usb_phy_probe(struct pl if (!data) return -ENOMEM; - mutex_init(&data->mutex); + spin_lock_init(&data->reg_lock); if (of_device_is_compatible(np, "allwinner,sun5i-a13-usb-phy")) data->num_phys = 2;