From patchwork Tue Jun 18 15:03:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 2742841 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 695FF9F8E1 for ; Tue, 18 Jun 2013 15:07:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BCB1C2049C for ; Tue, 18 Jun 2013 15:07:23 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7EB012049B for ; Tue, 18 Jun 2013 15:07:22 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UoxTY-0005Mu-KH; Tue, 18 Jun 2013 15:05:42 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UoxSs-0002fU-VR; Tue, 18 Jun 2013 15:04:58 +0000 Received: from mail-pa0-x234.google.com ([2607:f8b0:400e:c03::234]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UoxSj-0002d4-Gg for linux-arm-kernel@lists.infradead.org; Tue, 18 Jun 2013 15:04:51 +0000 Received: by mail-pa0-f52.google.com with SMTP id kq13so4086712pab.39 for ; Tue, 18 Jun 2013 08:04:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=z/x20oAxqN3spis42kkk3MTjZGzNb1PTewyCkNbkjmc=; b=SNxHv6/ISEm9zf+78iZhakxvw+KFV7BKMJshNi5mAgseRNoiR75o9nv5FCI2b88Wol CU6eZLQSj5Z/nISPg6GYQvBlBHKjI3GrjF1gfTijR51bmmlpOWJP5nYCymnwp/V77sSc X4J6pDKH4yRYaBDQn+8nkKdxWYZh/d5JnyeeeGWGVAyHpRcAx3cU14zSdJA8eOjni3Y6 5CeyJ36NJedZIlrlYkLPMEFOQYlCsZcDPX0hmgF+KL2EF02fVUxEDOIwDhbtiypKeN+e AbGp2kFzw6JPHO84lpIRtVoUbsIbPKrbj573AHzXo3yFJIpKc8c7FREOpFXKigzl8nn9 s5gQ== X-Received: by 10.66.219.38 with SMTP id pl6mr2561553pac.59.1371567867694; Tue, 18 Jun 2013 08:04:27 -0700 (PDT) Received: from localhost ([183.37.201.115]) by mx.google.com with ESMTPSA id o10sm18616137pbq.39.2013.06.18.08.04.22 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 18 Jun 2013 08:04:26 -0700 (PDT) From: Ming Lei To: Greg Kroah-Hartman Subject: [RFC PATCH v1 2/6] USB: disable IRQs deliberately when calling complete() Date: Tue, 18 Jun 2013 23:03:48 +0800 Message-Id: <1371567833-9077-3-git-send-email-ming.lei@canonical.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1371567833-9077-1-git-send-email-ming.lei@canonical.com> References: <1371567833-9077-1-git-send-email-ming.lei@canonical.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130618_110450_435986_D8EDC9E8 X-CRM114-Status: GOOD ( 12.63 ) X-Spam-Score: -1.9 (-) Cc: Oliver Neukum , Ming Lei , linux-usb@vger.kernel.org, Steven Rostedt , Alan Stern , Thomas Gleixner , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, 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 We disable local IRQs here in case of running complete() by tasklet to avoid possible deadlock because drivers may call spin_lock() to hold lock which might be acquired in one hard interrupt handler. The local_irq_save()/local_irq_restore() around complete() will be removed if current USB drivers have been cleaned up and no one may trigger the above deadlock situation when running complete() in tasklet. Cc: Oliver Neukum Cc: Alan Stern Signed-off-by: Ming Lei --- drivers/usb/core/hcd.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index a272968..09a8263 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c @@ -1673,7 +1673,28 @@ static void __usb_hcd_giveback_urb(struct urb *urb) /* pass ownership to the completion handler */ urb->status = status; - urb->complete (urb); + + /* + * We disable local IRQs here in case of running complete() by + * tasklet to avoid possible deadlock because drivers may call + * spin_lock() to hold lock which might be acquired in one hard + * interrupt handler. + * + * The local_irq_save()/local_irq_restore() around complete() + * will be removed if current USB drivers have been cleaned up + * and no one may trigger the above deadlock situation when + * running complete() in tasklet. + */ + if (hcd_giveback_urb_in_bh(hcd)) { + unsigned long flags; + + local_irq_save(flags); + urb->complete (urb); + local_irq_restore(flags); + } else { + urb->complete (urb); + } + atomic_dec (&urb->use_count); if (unlikely(atomic_read(&urb->reject))) wake_up (&usb_kill_urb_queue);