Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp850721imm; Wed, 8 Aug 2018 06:51:16 -0700 (PDT) X-Google-Smtp-Source: AA+uWPw6V6npoYm0DFSSQRA8nSn1/X5SA54CloAMJej2yz46pokEJNqkXUSE/mLhS7A6jNWVXx4y X-Received: by 2002:aa7:8591:: with SMTP id w17-v6mr3087121pfn.77.1533736276845; Wed, 08 Aug 2018 06:51:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533736276; cv=none; d=google.com; s=arc-20160816; b=xGkZ1Uv4vUTAQaXhmrMmmfNHJGPU3lv1NBZJvrgZiBVk5ck8JBVSQYdumIVqwFslwI iCtaY/NxZ9IoIUhNtAPosCXyrm2DFszt4FmaVvpmOTNwmDYLxwb2jucVOc2oMgslqz35 kNU6VYVw/n+ee99lNi01VC6c+nnbOjAtKOKnCI5gCQ+CHScViyuRfQjtYP6oZahJZVA4 evelFbGVUoEn/yjt7qnK6RXbot9u9r4ErRn78gJ25XUi9IjXtqrAV90wKRqE8+cjpM1D lQIyajs7XC34E/EPrFMlZFKFRENV65JfJv3S00Jcdf53ltGWCRX2Qi8MeZ0S9duWY7Ih C/ZA== 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:arc-authentication-results; bh=fizkvtzjWWUXx2rFQWxBUxudxawn6SKGlOXylJYEYJ0=; b=j9lME9u60YU76y4Rl+TkuGfU+OTqMh8gzeMdWkKE1DzrD30jHtHSGSKhJNnhue8yRa 00GbmIrMQfWPZy9huo46Eku4vB8PjXxrB1ZKRYNXzLYsJpgQzCkdH9PVlm6P83+RNk1u mzP9X7JN50hvN+30jp/SfG6mbsJZ/Kslq7ofMLh3MPzi3HqK5FSoUcZPtAUY1q2El4eP p/3u8fB4/2vfGYcfhOaLD58Lf7zsNPcheVvCDxOD0GCJc+zBwQOOPhuyRXHJDFVX31a0 zTtslf72b4jIE5TAONwrfwi4cgjiSxSr7iuN4+LaSPdLoMzuhWkeltjH/tIS1OLl0oGf /ahQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=PsmMvPrf; 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 o5-v6si3482683plk.95.2018.08.08.06.51.02; Wed, 08 Aug 2018 06:51:16 -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=PsmMvPrf; 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 S1727288AbeHHQJX (ORCPT + 99 others); Wed, 8 Aug 2018 12:09:23 -0400 Received: from perceval.ideasonboard.com ([213.167.242.64]:59272 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726869AbeHHQJX (ORCPT ); Wed, 8 Aug 2018 12:09:23 -0400 Received: from [192.168.0.67] (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C074C57; Wed, 8 Aug 2018 15:49:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1533736175; bh=MkIZzjvCsp4pRt0NmJ9D5nN6+jnA+HlImudrZXFDlrU=; h=Reply-To:Subject:To:Cc:References:From:Date:In-Reply-To:From; b=PsmMvPrfmshXh9zJtQqfVzWTNlVeJLSoYI/OkMpbpADoS2hobiv1WtYNf3/0ngFC/ rV4su7jWSOXMcfDmBwTj5R9M4GDme+A4IH3n4GwoH/DAwbw5O2FsPDkivnYRIKy6Cs Jy4TP83g9bKoFC60ex0xs2heied5dYTKmFWriRHY= 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/lqtBRQKumuI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9SYyvp8 O0g6CpxEwyHUQtF5oh15O018z3ZLztFJKR3RD42VKVsrnNDKnoY0f4U0z7eJv2NeF8xHMuiU RCIzqxX1GVYaNkKTnb/Qja8hnYnkUzY1Lc+OtwiGmXTwYsPZjjAaDX35J/RSKAoy5wGo/YFA JxB1gWThL4kOTbsqqXj9GLcyOImkW0lJGGR3o/fV91Zh63S5TKnf2YGGGzxki+ADdxVQAm+Q sbsRB8KNNvVXBOVNwko86rQqF9drZuw= Organization: Ideas on Board Message-ID: <2b71a365-ce3b-8eaa-67d7-7577bac2d5b0@ideasonboard.com> Date: Wed, 8 Aug 2018 14:49:32 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Tomasz, On 07/08/18 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 the investigation and patch report ;D I think moving the workqueue allocation might be a reasonable option as suggested by Laurent in his review. I'll look further into this when I get to another spin of the series. > > 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