From patchwork Thu Mar 12 04:44:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Balbi X-Patchwork-Id: 5990641 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 80A17BF90F for ; Thu, 12 Mar 2015 04:45:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 84D052038F for ; Thu, 12 Mar 2015 04:45:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 96D5120384 for ; Thu, 12 Mar 2015 04:45:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751274AbbCLEpv (ORCPT ); Thu, 12 Mar 2015 00:45:51 -0400 Received: from devils.ext.ti.com ([198.47.26.153]:47150 "EHLO devils.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751260AbbCLEpt (ORCPT ); Thu, 12 Mar 2015 00:45:49 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id t2C4jRgN012082; Wed, 11 Mar 2015 23:45:27 -0500 Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id t2C4jPfC031532; Wed, 11 Mar 2015 23:45:25 -0500 Received: from dlep32.itg.ti.com (157.170.170.100) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.224.2; Wed, 11 Mar 2015 23:45:25 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id t2C4jO9e025859; Wed, 11 Mar 2015 23:45:25 -0500 Date: Wed, 11 Mar 2015 23:44:49 -0500 From: Felipe Balbi To: yoshihiro shimoda CC: Geert Uytterhoeven , Greg KH , Felipe Balbi , Rob Herring , Pawel Moll , Mark Rutland , Ian Campbell , Kumar Gala , USB list , Linux-sh list , "devicetree@vger.kernel.org" Subject: Re: [PATCH v2 1/4] usb: renesas_usbhs: fix spinlock suspected in a gadget complete function Message-ID: <20150312044449.GA29718@saruman.tx.rr.com> Reply-To: References: <1424051579-5060-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> <1424051579-5060-2-git-send-email-yoshihiro.shimoda.uh@renesas.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, T_TVD_MIME_EPI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi, On Thu, Mar 12, 2015 at 04:33:41AM +0000, yoshihiro shimoda wrote: > Hi Geert-san again, > > > Hi Geert-san, > > > > Thank you for the reply again! > > > > > Hi Shimoda-san, > > > > > > On Mon, Feb 16, 2015 at 2:52 AM, Yoshihiro Shimoda > > > wrote: > > > > According to the gadget.h, a "complete" function will always be called > > > > with interrupts disabled. However, sometimes usbhsg_queue_pop() function > > > > is called with interrupts enabled. So, this function should calls > > > > local_irq_save() before this calls the usb_gadget_giveback_request(). > > > > Otherwise, there is possible to cause a spinlock suspected in a gadget > > > > complete function. > > > > > > I still feel uneasy about adding the call to local_irq_save(), as the need for > > > this is usually an indicator of another locking problem. > > > > I also think that I would like to avoid using local_irq_save(). > > But, I have no idea to resolve this issue for now. > > After I modified usb-dmac driver to use a tasklet instead of a kthread, > this issue disappeared. > > My understanding is the followings: > - According to the backtrace below, during usbhsf_dma_complete() was running, > a softirq happened. After ncm_tx_tasklet() was called, the issue happened. > http://thread.gmane.org/gmane.linux.usb.general/122023/focus=43729 > > - This means that usbhsf_dma_complete() ran on a kthread. So, ncm driver is able > to do the ncm_tx_tasklet(). > > - After the current usb-dmac driver, since usbhsf_dma_complete() runs on a tasklet, > ncm driver is not able to do the ncm_tx_tasklet during usbhsf_dma_complete() was running. > > > So, I would like to recall this patch and I will resubmit this patch series as v3. try something like below: then, for cases where lock is already held you call __usbhsg_queue_pop() and for all other cases, call usbhsg_queue_pop(). diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c b/drivers/usb/renesas_usbhs/mod_gadget.c index e0384af77e56..e9d75d85be59 100644 --- a/drivers/usb/renesas_usbhs/mod_gadget.c +++ b/drivers/usb/renesas_usbhs/mod_gadget.c @@ -119,7 +119,7 @@ struct usbhsg_recip_handle { /* * queue push/pop */ -static void usbhsg_queue_pop(struct usbhsg_uep *uep, +static void __usbhsg_queue_pop(struct usbhsg_uep *uep, struct usbhsg_request *ureq, int status) { @@ -133,6 +133,15 @@ static void usbhsg_queue_pop(struct usbhsg_uep *uep, usb_gadget_giveback_request(&uep->ep, &ureq->req); } +static void usbhsg_queue_pop(struct usbhsg_uep *uep, + struct usbhsg_request *ureq, + int status) +{ + usbhs_lock(priv, flags); + __usbhsg_queue_pop(uep, ureq, status); + usbhs_unlock(priv, flags); +} + static void usbhsg_queue_done(struct usbhs_priv *priv, struct usbhs_pkt *pkt) { struct usbhs_pipe *pipe = pkt->pipe;