Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp161500imm; Tue, 7 Aug 2018 16:06:28 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyCCrAAvKCuR7tqGICNJWq75CyEEA23f7m1jyVnbu6x1LlvqGqw6Tr1HAiRHivG8F6jN+rb X-Received: by 2002:a62:2ac8:: with SMTP id q191-v6mr320889pfq.139.1533683188424; Tue, 07 Aug 2018 16:06:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533683188; cv=none; d=google.com; s=arc-20160816; b=iIhoHt3bDwgh2RHWOfN+N5r+OsEbkl5LhdCaCGOBfo3ewkjVnDnY69YPF4a+dQBC2O 2RKMugaiwKMG/EckshiMYZgwwr3rbF6irdm/JTFmcQIyGgjBSXx8OUGZ1yuMTIJPzV1S rUgPtJ4vBB8RQwvjzwQAe3aSKkmyfz9L3Bft7bN19472l3n2ukmwJz9WUAsggbkKjTxg unP5tOs5ZtdlhPHe8nokW39Stv4ya4dNeZMyda+gkom8i7e4ZEG4RTaWuNk1YB0Zzjdx 45IbZ2sKelV5WfzRlvkg/Zw3D9ZimEq9DNfAabDyqsotYoeoQulmvhjBbBZ21fHb9UJM LkPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:organization:message-id:date:subject:cc:to :from:dkim-signature:arc-authentication-results; bh=9aK0mjxaUXNgR268qmIorKvY1NY7Z2IA5DMox0P5Pks=; b=O0wV94NxNjq2TKANp+DRi9wBkUoUgnXDHw0xbBhNE5E7pAHqdKvrMzSskVfcuI8VUx vHjV3JSy6XXUsj74a/Jr/OkyfbF3nur8IP/TCw4oWaJJV4VsuO4DWVRDCUcAV2/H/iBP xEavA2iOyMIQgog7FvMUwI110TOvSHPOzILSduuvuY212RLi4SduHWqnpOKAvujZ6CSb H5e4dxkHVgBGQMDM8SxCR/rcXh4lhYzzQmht92zsg6RZ/fLw2C8o3asNj+wnj04hPy3X /kc60CZic8YL/VOlWZat+wEz5/WUHMCcoNgSiUPZ3i/8kXt28FF+ksLbbXFOLBaUBIUA luEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=uqSRmNTG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d4-v6si2551614pfc.219.2018.08.07.16.06.13; Tue, 07 Aug 2018 16:06:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=uqSRmNTG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726979AbeHHBWE (ORCPT + 99 others); Tue, 7 Aug 2018 21:22:04 -0400 Received: from perceval.ideasonboard.com ([213.167.242.64]:39782 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726579AbeHHBWE (ORCPT ); Tue, 7 Aug 2018 21:22:04 -0400 Received: from avalon.localnet (dfj612ybrt5fhg77mgycy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:2e86:4862:ef6a:2804]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6FC5857; Wed, 8 Aug 2018 01:05:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1533683122; bh=aSmI6Thq7ef7i8qWoN90v4CuJkqRiSQHac1JWKPQG60=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uqSRmNTGqKG/KpP8SBlvDglGW4PEB/Djnnv07TrFtVdoaADzoKq6k1zoeqV6g2pNH pQzD2e7WgHts4yi0MKqQXQuBq+V8VXlvSXfCbXdvUUyrZVffNUegDAnZ3NZdjEMAIx OqheDlJig+bhs31hImVYk2LPxHcFiCLaCChEicxg= From: Laurent Pinchart To: Tomasz Figa Cc: Kieran Bingham , Linux Media Mailing List , g.liakhovetski@gmx.de, olivier.braun@stereolabs.com, troy.kisky@boundarydevices.com, Randy Dunlap , philipp.zabel@gmail.com, Mauro Carvalho Chehab , Linux Kernel Mailing List Subject: Re: [PATCH v4 6/6] media: uvcvideo: Move decode processing to process context Date: Wed, 08 Aug 2018 02:06:05 +0300 Message-ID: <7279894.ANCCylJ6YF@avalon> Organization: Ideas on Board Oy In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Tomasz, On Tuesday, 7 August 2018 12:54:02 EEST Tomasz Figa wrote: > On Wed, Mar 28, 2018 at 1:47 AM Kieran Bingham wrote: > [snip] > > > @@ -1544,25 +1594,29 @@ static int uvc_alloc_urb_buffers(struct > > uvc_streaming *stream, > > */ > > > > static void uvc_uninit_video(struct uvc_streaming *stream, int > > free_buffers) > > { > > - struct urb *urb; > > - unsigned int i; > > + struct uvc_urb *uvc_urb; > > > > uvc_video_stats_stop(stream); > > > > - for (i = 0; i < UVC_URBS; ++i) { > > - struct uvc_urb *uvc_urb = &stream->uvc_urb[i]; > > + /* > > + * We must poison the URBs rather than kill them to ensure that > > even > > + * after the completion handler returns, any asynchronous > > workqueues > > + * will be prevented from resubmitting the URBs > > + */ > > + for_each_uvc_urb(uvc_urb, stream) > > + usb_poison_urb(uvc_urb->urb); > > > > - urb = uvc_urb->urb; > > - if (urb == NULL) > > - continue; > > + flush_workqueue(stream->async_wq); > > > > - usb_kill_urb(urb); > > - usb_free_urb(urb); > > + for_each_uvc_urb(uvc_urb, stream) { > > + usb_free_urb(uvc_urb->urb); > > uvc_urb->urb = NULL; > > } > > > > if (free_buffers) > > uvc_free_urb_buffers(stream); > > + > > + destroy_workqueue(stream->async_wq); > > In our testing, this function ends up being called twice, if before > suspend the camera is streaming and if the camera disconnects between > suspend and resume. This is because uvc_video_suspend() calls this > function (with free_buffers = 0), but uvc_video_resume() wouldn't call > uvc_init_video() due to an earlier failure and uvc_v4l2_release() > would end up calling this function again, while the workqueue is > already destroyed. This makes me wonder, as stated in my review, whether we shouldn't keep the work queue alive for the whole lifetime of the device instead of creating and destroying it at stream start and stop. > The following diff seems to take care of it: > > 8<~~~ > diff --git a/drivers/media/usb/uvc/uvc_video.c > b/drivers/media/usb/uvc/uvc_video.c > index c5e0ab564b1a..6fb890c8ba67 100644 > --- a/drivers/media/usb/uvc/uvc_video.c > +++ b/drivers/media/usb/uvc/uvc_video.c > @@ -1493,10 +1493,11 @@ static void uvc_uninit_video(struct > uvc_streaming *stream, int free_buffers) > uvc_urb->urb = NULL; > } > > - if (free_buffers) > + if (free_buffers) { > uvc_free_urb_buffers(stream); > - > - destroy_workqueue(stream->async_wq); > + destroy_workqueue(stream->async_wq); > + stream->async_wq = NULL; > + } > } > > /* > @@ -1648,10 +1649,12 @@ static int uvc_init_video(struct uvc_streaming > *stream, gfp_t gfp_flags) > > uvc_video_stats_start(stream); > > - stream->async_wq = alloc_workqueue("uvcvideo", WQ_UNBOUND | > WQ_HIGHPRI, - 0); > - if (!stream->async_wq) > - return -ENOMEM; > + if (!stream->async_wq) { > + stream->async_wq = alloc_workqueue("uvcvideo", > + WQ_UNBOUND | WQ_HIGHPRI, > 0); + if (!stream->async_wq) > + return -ENOMEM; > + } > > if (intf->num_altsetting > 1) { > struct usb_host_endpoint *best_ep = NULL; > ~~~>8 -- Regards, Laurent Pinchart