From patchwork Mon Sep 10 09:19:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 10593743 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3EC176CB for ; Mon, 10 Sep 2018 09:20:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3218128E16 for ; Mon, 10 Sep 2018 09:20:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 17F5728CAA; Mon, 10 Sep 2018 09:20:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB76228E16 for ; Mon, 10 Sep 2018 09:20:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728016AbeIJONO (ORCPT ); Mon, 10 Sep 2018 10:13:14 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:38755 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726081AbeIJONN (ORCPT ); Mon, 10 Sep 2018 10:13:13 -0400 Received: from localhost ([127.0.0.1] helo=bazinga.breakpoint.cc) by Galois.linutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1fzIMW-0003a3-Tc; Mon, 10 Sep 2018 11:20:05 +0200 From: Sebastian Andrzej Siewior To: linux-media@vger.kernel.org, linux-usb@vger.kernel.org Cc: Mauro Carvalho Chehab , Greg Kroah-Hartman , tglx@linutronix.de, Sebastian Andrzej Siewior Subject: [PATCH 1/3] media: em28xx-audio: use irqsave() in USB's complete callback Date: Mon, 10 Sep 2018 11:19:58 +0200 Message-Id: <20180910092000.14693-2-bigeasy@linutronix.de> X-Mailer: git-send-email 2.19.0.rc2 In-Reply-To: <20180910092000.14693-1-bigeasy@linutronix.de> References: <20180910092000.14693-1-bigeasy@linutronix.de> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The USB completion callback does not disable interrupts while acquiring the lock. We want to remove the local_irq_disable() invocation from __usb_hcd_giveback_urb() and therefore it is required for the callback handler to disable the interrupts while acquiring the lock. The callback may be invoked either in IRQ or BH context depending on the USB host controller. Use the _irqsave() variant of the locking primitives. Cc: Mauro Carvalho Chehab Signed-off-by: Sebastian Andrzej Siewior --- drivers/media/usb/em28xx/em28xx-audio.c | 5 +++-- drivers/media/usb/em28xx/em28xx-core.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/media/usb/em28xx/em28xx-audio.c b/drivers/media/usb/em28xx/em28xx-audio.c index 8e799ae1df692..67481fc824458 100644 --- a/drivers/media/usb/em28xx/em28xx-audio.c +++ b/drivers/media/usb/em28xx/em28xx-audio.c @@ -116,6 +116,7 @@ static void em28xx_audio_isocirq(struct urb *urb) stride = runtime->frame_bits >> 3; for (i = 0; i < urb->number_of_packets; i++) { + unsigned long flags; int length = urb->iso_frame_desc[i].actual_length / stride; cp = (unsigned char *)urb->transfer_buffer + @@ -137,7 +138,7 @@ static void em28xx_audio_isocirq(struct urb *urb) length * stride); } - snd_pcm_stream_lock(substream); + snd_pcm_stream_lock_irqsave(substream, flags); dev->adev.hwptr_done_capture += length; if (dev->adev.hwptr_done_capture >= @@ -153,7 +154,7 @@ static void em28xx_audio_isocirq(struct urb *urb) period_elapsed = 1; } - snd_pcm_stream_unlock(substream); + snd_pcm_stream_unlock_irqrestore(substream, flags); } if (period_elapsed) snd_pcm_period_elapsed(substream); diff --git a/drivers/media/usb/em28xx/em28xx-core.c b/drivers/media/usb/em28xx/em28xx-core.c index 5657f8710ca6b..2b8c84a5c9a8e 100644 --- a/drivers/media/usb/em28xx/em28xx-core.c +++ b/drivers/media/usb/em28xx/em28xx-core.c @@ -777,6 +777,7 @@ EXPORT_SYMBOL_GPL(em28xx_set_mode); static void em28xx_irq_callback(struct urb *urb) { struct em28xx *dev = urb->context; + unsigned long flags; int i; switch (urb->status) { @@ -793,9 +794,9 @@ static void em28xx_irq_callback(struct urb *urb) } /* Copy data from URB */ - spin_lock(&dev->slock); + spin_lock_irqsave(&dev->slock, flags); dev->usb_ctl.urb_data_copy(dev, urb); - spin_unlock(&dev->slock); + spin_unlock_irqrestore(&dev->slock, flags); /* Reset urb buffers */ for (i = 0; i < urb->number_of_packets; i++) { From patchwork Mon Sep 10 09:19:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 10593749 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D211514BD for ; Mon, 10 Sep 2018 09:20:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C06F328E11 for ; Mon, 10 Sep 2018 09:20:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B200A28E1C; Mon, 10 Sep 2018 09:20:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8CAC428E1A for ; Mon, 10 Sep 2018 09:20:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728032AbeIJONO (ORCPT ); Mon, 10 Sep 2018 10:13:14 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:38757 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727861AbeIJONO (ORCPT ); Mon, 10 Sep 2018 10:13:14 -0400 Received: from localhost ([127.0.0.1] helo=bazinga.breakpoint.cc) by Galois.linutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1fzIMX-0003a3-HZ; Mon, 10 Sep 2018 11:20:05 +0200 From: Sebastian Andrzej Siewior To: linux-media@vger.kernel.org, linux-usb@vger.kernel.org Cc: Mauro Carvalho Chehab , Greg Kroah-Hartman , tglx@linutronix.de, Sebastian Andrzej Siewior Subject: [PATCH 2/3] media: tm6000: use irqsave() in USB's complete callback Date: Mon, 10 Sep 2018 11:19:59 +0200 Message-Id: <20180910092000.14693-3-bigeasy@linutronix.de> X-Mailer: git-send-email 2.19.0.rc2 In-Reply-To: <20180910092000.14693-1-bigeasy@linutronix.de> References: <20180910092000.14693-1-bigeasy@linutronix.de> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The USB completion callback does not disable interrupts while acquiring the lock. We want to remove the local_irq_disable() invocation from __usb_hcd_giveback_urb() and therefore it is required for the callback handler to disable the interrupts while acquiring the lock. The callback may be invoked either in IRQ or BH context depending on the USB host controller. Use the _irqsave() variant of the locking primitives. Cc: Mauro Carvalho Chehab Signed-off-by: Sebastian Andrzej Siewior --- drivers/media/usb/tm6000/tm6000-video.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/tm6000/tm6000-video.c b/drivers/media/usb/tm6000/tm6000-video.c index 96055de6e8ce2..7d268f2404e19 100644 --- a/drivers/media/usb/tm6000/tm6000-video.c +++ b/drivers/media/usb/tm6000/tm6000-video.c @@ -419,6 +419,7 @@ static void tm6000_irq_callback(struct urb *urb) { struct tm6000_dmaqueue *dma_q = urb->context; struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq); + unsigned long flags; int i; switch (urb->status) { @@ -436,9 +437,9 @@ static void tm6000_irq_callback(struct urb *urb) break; } - spin_lock(&dev->slock); + spin_lock_irqsave(&dev->slock, flags); tm6000_isoc_copy(urb); - spin_unlock(&dev->slock); + spin_unlock_irqrestore(&dev->slock, flags); /* Reset urb buffers */ for (i = 0; i < urb->number_of_packets; i++) { From patchwork Mon Sep 10 09:20:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 10593753 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 89DD46CB for ; Mon, 10 Sep 2018 09:20:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C0D828E11 for ; Mon, 10 Sep 2018 09:20:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7078428E16; Mon, 10 Sep 2018 09:20:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7CFB828E23 for ; Mon, 10 Sep 2018 09:20:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728020AbeIJONO (ORCPT ); Mon, 10 Sep 2018 10:13:14 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:38760 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727867AbeIJONO (ORCPT ); Mon, 10 Sep 2018 10:13:14 -0400 Received: from localhost ([127.0.0.1] helo=bazinga.breakpoint.cc) by Galois.linutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1fzIMY-0003a3-5M; Mon, 10 Sep 2018 11:20:06 +0200 From: Sebastian Andrzej Siewior To: linux-media@vger.kernel.org, linux-usb@vger.kernel.org Cc: Mauro Carvalho Chehab , Greg Kroah-Hartman , tglx@linutronix.de, Sebastian Andrzej Siewior , Alan Stern Subject: [PATCH 3/3] usb: core: remove local_irq_save() around ->complete() handler Date: Mon, 10 Sep 2018 11:20:00 +0200 Message-Id: <20180910092000.14693-4-bigeasy@linutronix.de> X-Mailer: git-send-email 2.19.0.rc2 In-Reply-To: <20180910092000.14693-1-bigeasy@linutronix.de> References: <20180910092000.14693-1-bigeasy@linutronix.de> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The core disabled interrupts before invocation the ->complete handler because the handler might have expected that interrupts are disabled. All handlers were audited and use proper locking now. With it, the core code no longer needs to disable interrupts before invoking the ->complete handler. Remove local_irq_save() statement before invoking the ->complete handler. Cc: Alan Stern Signed-off-by: Sebastian Andrzej Siewior Acked-by: Alan Stern --- drivers/usb/core/hcd.c | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index 1c21955fe7c00..f985d2303095c 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c @@ -1755,20 +1755,7 @@ static void __usb_hcd_giveback_urb(struct urb *urb) /* pass ownership to the completion handler */ urb->status = status; - - /* - * We disable local IRQs here 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. - */ - local_irq_save(flags); urb->complete(urb); - local_irq_restore(flags); usb_anchor_resume_wakeups(anchor); atomic_dec(&urb->use_count);