Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1976271imu; Tue, 6 Nov 2018 07:15:03 -0800 (PST) X-Google-Smtp-Source: AJdET5emVmwMT2w20z22IStfMEkvSvN0DaRBMMp8h3N7+5bLaRl00ad4fb4HOl0a5gOZou4qUZYD X-Received: by 2002:a62:6e47:: with SMTP id j68-v6mr26404641pfc.197.1541517303153; Tue, 06 Nov 2018 07:15:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541517303; cv=none; d=google.com; s=arc-20160816; b=IZxSxJhaIqfnNtfA/127lTO7lpb+hh3XDWTj8LKm+FUR8YCuMZ1CxqQXIxu+dhgnd5 oM44fFxPQ5LelVM/yH/7ThWwB9qyMYtlhItvhtpftTAYNoWunxwA2okbx0Yu5SHtyH+6 7XUft9movcy9NfWOiR6yA/Qo+pg/PQ9kSft71iTf77ddxPCFpZOknkSx8vxAi86U+JZm Xv+mGE4TqSjXCjIl1nhZblMa2RPaIbx0KA9T2ZseAXjlzkvjaSoSV6yswoiNoKDrMXSP JipbR8TEDmg2mCWmti69mlV/IYlJrctFo9vMoZSES+66TnAHl1cze+R2+HTETGdcltua xx9w== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:autocrypt:openpgp:from:references:cc:to :subject:reply-to:dkim-signature; bh=uxms2vfhdZnvPRy5zFOkCuRryeqCAsXMgL1lYv4ZEIM=; b=hb2ANA+8TWRAr/99FBQI7n2q1dgXVnjyxSxZMtRxwhurkHcPp0IecOfr/W0wYad2A3 9E0LptMvysh71jDNeeA8hk2ToAEm5Hr2+s3BymnFNNsqSu2OzHfND9PF/gYdIBkzo2CO gV+f3BtftLpxUAvRBeZ4V/onH4XEpib78cMWIXpBjTLqCCrJIEmwdixRcuvXfzEGbVxj UCT8el15TH2ye/aDEjv64pk2RiJ7k3Uy0We6vyxtOklB1ipLrLk1MqncA6bG1Dw/OHto jxHYDfdeYRUg6lO6LdmEy2qZqzWJz1okVYdIJV918xP774lZSop9AL2+0mbLrolvaGFh t42w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=nqh+ce3l; 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 z126-v6si26816463pfb.280.2018.11.06.07.14.35; Tue, 06 Nov 2018 07:15:03 -0800 (PST) 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=nqh+ce3l; 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 S1730801AbeKGAjl (ORCPT + 99 others); Tue, 6 Nov 2018 19:39:41 -0500 Received: from perceval.ideasonboard.com ([213.167.242.64]:51402 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729574AbeKGAjl (ORCPT ); Tue, 6 Nov 2018 19:39:41 -0500 Received: from [192.168.0.21] (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 90FCD526; Tue, 6 Nov 2018 16:13:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1541517239; bh=9XJYKE+ziBeg5DUckAR7CYuS7aMn5b8CC3FXp9pOkjk=; h=Reply-To:Subject:To:Cc:References:From:Date:In-Reply-To:From; b=nqh+ce3lTOdJUZtzQo0qcOGYEm2pGlFX/FgB9fQRFkbTnRcAKG9B/G2z/VfMzGbcp NYslWCQRH9iRpZlwUWnTdLo4fPX4Mys5nZjfnfQWW7xYpH5s40RcI1AH6zW5r+U3gg ZsRpdqVxUIWxDJaMXT2XGCu4QAU4skuRXNW5Yq+M= Reply-To: kieran.bingham@ideasonboard.com Subject: Re: [PATCH v4 6/6] media: uvcvideo: Move decode processing to process context To: Tomasz Figa Cc: Laurent Pinchart , 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 References: From: Kieran Bingham Openpgp: preference=signencrypt Autocrypt: addr=kieran.bingham@ideasonboard.com; keydata= xsFNBFYE/WYBEACs1PwjMD9rgCu1hlIiUA1AXR4rv2v+BCLUq//vrX5S5bjzxKAryRf0uHat V/zwz6hiDrZuHUACDB7X8OaQcwhLaVlq6byfoBr25+hbZG7G3+5EUl9cQ7dQEdvNj6V6y/SC rRanWfelwQThCHckbobWiQJfK9n7rYNcPMq9B8e9F020LFH7Kj6YmO95ewJGgLm+idg1Kb3C potzWkXc1xmPzcQ1fvQMOfMwdS+4SNw4rY9f07Xb2K99rjMwZVDgESKIzhsDB5GY465sCsiQ cSAZRxqE49RTBq2+EQsbrQpIc8XiffAB8qexh5/QPzCmR4kJgCGeHIXBtgRj+nIkCJPZvZtf Kr2EAbc6tgg6DkAEHJb+1okosV09+0+TXywYvtEop/WUOWQ+zo+Y/OBd+8Ptgt1pDRyOBzL8 RXa8ZqRf0Mwg75D+dKntZeJHzPRJyrlfQokngAAs4PaFt6UfS+ypMAF37T6CeDArQC41V3ko lPn1yMsVD0p+6i3DPvA/GPIksDC4owjnzVX9kM8Zc5Cx+XoAN0w5Eqo4t6qEVbuettxx55gq 8K8FieAjgjMSxngo/HST8TpFeqI5nVeq0/lqtBRQKumuIqDg+Bkr4L1V/PSB6XgQcOd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5oh15O018z3ZLztFJKR3RD42VKVsrnNDKnoY0f4U0z7eJv2NeF8xHMuiU RCIzqxX1GVYaNkKTnb/Qja8hnYnkUzY1Lc+OtwiGmXTwYsPZjjAaDX35J/RSKAoy5wGo/YFA JxB1gWThL4kOTbsqqXj9GLcyOImkW0lJGGR3o/fV91Zh63S5TKnf2YGGGzxki+ADdxVQAm+Q sbsRB8KNNvVXBOVNwko86rQqF9drZuw= Organization: Ideas on Board Message-ID: <4fa1b96d-912c-ec07-f08e-d8de164a0186@ideasonboard.com> Date: Tue, 6 Nov 2018 15:13:55 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Tomasz, On 07/08/2018 10:54, Tomasz Figa wrote: > Hi Kieran, > > 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. > > The following diff seems to take care of it: Thank you for this. After discussing with Laurent, I have gone with the approach of keeping the workqueue for the lifetime of the stream, rather than the lifetime of the streamon. > > 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 > > Best regards, > Tomasz > -- Regards -- Kieran