From patchwork Fri Jun 28 09:07:51 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 2797751 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 F02749F3C3 for ; Fri, 28 Jun 2013 09:11:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B7358200F4 for ; Fri, 28 Jun 2013 09:11:11 +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 99020200D5 for ; Fri, 28 Jun 2013 09:11:09 +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 1UsUgP-0007lk-KB; Fri, 28 Jun 2013 09:09:34 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UsUfv-0007ez-OI; Fri, 28 Jun 2013 09:09:03 +0000 Received: from mail-pb0-f43.google.com ([209.85.160.43]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UsUfj-0007cw-Or for linux-arm-kernel@lists.infradead.org; Fri, 28 Jun 2013 09:08:53 +0000 Received: by mail-pb0-f43.google.com with SMTP id md12so2030049pbc.2 for ; Fri, 28 Jun 2013 02:08:30 -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=ru3GTN+CnkQX/MuuTVscv9u1nSWvfInpEXkDub/Pzi0=; b=FBMZ191R5RrBOQPuf0OlRwX8UppuaTTDjdpJIC03Frpt2aInZcm9QgZuDaB5343UH7 DHFVLm9qwU9B0VKnMcg4Eb3HbGaVIuDnhIEL3+94cc6hjIvf6e/UepvhFFxchfIc88pb bqM/dlx3QO345DJ00KGpP83o06pzrvy/hau+1837q22GBcjSILuQPQEP1ha+Kln4tLgZ MvZRXyHSjb6qgcSvw36MebFPY+0tiu0VgHxx5q/c9yZpyYYStQZ6k1/iwHfqr7mKkVmr 7pVNCPz6tmHWyMfY7pJko/polvQtlCtty1hxS7D0+k9VoswRp0ZIqr1CQvpDH+mf8Xb+ nqGQ== X-Received: by 10.66.163.99 with SMTP id yh3mr10479071pab.22.1372410510285; Fri, 28 Jun 2013 02:08:30 -0700 (PDT) Received: from localhost ([183.37.203.121]) by mx.google.com with ESMTPSA id dg3sm7210591pbc.24.2013.06.28.02.08.25 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 28 Jun 2013 02:08:29 -0700 (PDT) From: Ming Lei To: Greg Kroah-Hartman Subject: [PATCH v3 2/4] USB: URB documentation: claim complete() will be run with IRQs enabled Date: Fri, 28 Jun 2013 17:07:51 +0800 Message-Id: <1372410473-30920-3-git-send-email-ming.lei@canonical.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1372410473-30920-1-git-send-email-ming.lei@canonical.com> References: <1372410473-30920-1-git-send-email-ming.lei@canonical.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130628_050851_942003_9CE5AD3D X-CRM114-Status: GOOD ( 14.66 ) X-Spam-Score: -2.6 (--) 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.5 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 There is no good reason to run complete() in hard interrupt disabled context. After switch to run complete() in tasklet, we will enable local IRQs when calling complete() since we can do it at that time. Even though we still disable IRQs now when calling complete() in tasklet, the URB documentation is updated to claim complete() will be run in tasklet context and local IRQs will be enabled, so that USB drivers can know the change and avoid one deadlock caused by: assume IRQs disabled in complete() and call spin_lock() to hold lock which might be acquired in interrupt context. Current spin_lock() usages in drivers' complete() will be cleaned up at the same time, and once the cleanup is finished, local IRQs will be enabled when calling complete() in tasklet. Also fix description about type of usb_complete_t, and remove the advice of running completion handler in tasklet for decreasing system latency. Cc: Oliver Neukum Acked-by: Alan Stern Signed-off-by: Ming Lei --- Documentation/usb/URB.txt | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/Documentation/usb/URB.txt b/Documentation/usb/URB.txt index 00d2c64..50da0d4 100644 --- a/Documentation/usb/URB.txt +++ b/Documentation/usb/URB.txt @@ -195,13 +195,12 @@ by the completion handler. The handler is of the following type: - typedef void (*usb_complete_t)(struct urb *, struct pt_regs *) + typedef void (*usb_complete_t)(struct urb *) -I.e., it gets the URB that caused the completion call, plus the -register values at the time of the corresponding interrupt (if any). -In the completion handler, you should have a look at urb->status to -detect any USB errors. Since the context parameter is included in the URB, -you can pass information to the completion handler. +I.e., it gets the URB that caused the completion call. In the completion +handler, you should have a look at urb->status to detect any USB errors. +Since the context parameter is included in the URB, you can pass +information to the completion handler. Note that even when an error (or unlink) is reported, data may have been transferred. That's because USB transfers are packetized; it might take @@ -210,12 +209,12 @@ have transferred successfully before the completion was called. NOTE: ***** WARNING ***** -NEVER SLEEP IN A COMPLETION HANDLER. These are normally called -during hardware interrupt processing. If you can, defer substantial -work to a tasklet (bottom half) to keep system latencies low. You'll -probably need to use spinlocks to protect data structures you manipulate -in completion handlers. +NEVER SLEEP IN A COMPLETION HANDLER. These are often called in atomic +context. +In the current kernel, completion handlers run with local interrupts +disabled, but in the future this will be changed, so don't assume that +local IRQs are always disabled inside completion handlers. 1.8. How to do isochronous (ISO) transfers?