Received: by 2002:a17:90b:8d0:0:0:0:0 with SMTP id ds16csp4861040pjb; Mon, 27 Jul 2020 07:04:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpUsi7XJnAlpQgLbvogS9h04nD78vjb0m0pS80cVPDR77p4i/2cjyqAjthu8fOe0PF5RMA X-Received: by 2002:a17:906:351a:: with SMTP id r26mr14807388eja.526.1595858678749; Mon, 27 Jul 2020 07:04:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595858678; cv=none; d=google.com; s=arc-20160816; b=Cv1gcdQK1jno7Twdymbr1dDiJWlL4Pr9ZTbmr3E36Z8H9sIzJkEGhNucMDpoVPnTvD pPEyIfI2koKi6x55LxGiMeFFiJEaXgLPw0FGuOQJ+6VzlJMKLyWx7pMr53zqNzN4Fr1Q ttkNuyXYyTtQYyowU2NYPeiJR96gvbaFarMrQgPGkxPVld4IxyWcZq9+bwJOckBvkmRj jvkWPALpM8qvu23jOOkxIDvo0v762Sr52SrPBstIq5dFXRtZLxPtl6WY6vIZ+HAHhxrp F0toYfDi2/+QLF1hHvoDpRzKSKJkZchTjdAg57p9914uIkwDB5bYV1oDShoC7I6GnT62 46jA== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=5nrJGkR5gzoJoAzFw0QkQIZLHmzb77Jw0yeZu9JZot4=; b=GlhlBDYk4mB7hUydkBPTjE/SfnCq/dMEe1s0sWeGQr/j6IcIqz0TbzF7W8ZVzrL6gQ eBNElO7nZcTS7qXrFFIPz0Kx1Z9na6Y1bisuAKo5OW36vmVdJozAIT9wJgXhoeciAR79 t3TR00PbqjLJwjCwENhhATNhadsPBKARSts6SeeNQHfpQb8UqLI7gaNSKDmi0o0ZzWXh oVvx8ey8sBpHbXky4nRY0NzoOtGkUQ0u/Wj6xRlrh9kZaMAvZau401omDVk/28/fRbWO LasTp1gVCSWC18jAVyfzar3s8DBTXxiFZEuq/uP7g80+CwG7yeGpQHXAfvSspPB43m2E dLBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=dFtmj2Pf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j7si5989875ejm.538.2020.07.27.07.04.15; Mon, 27 Jul 2020 07:04:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=dFtmj2Pf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729191AbgG0NtX (ORCPT + 99 others); Mon, 27 Jul 2020 09:49:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729167AbgG0NtN (ORCPT ); Mon, 27 Jul 2020 09:49:13 -0400 Received: from mail-ed1-x541.google.com (mail-ed1-x541.google.com [IPv6:2a00:1450:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC4DCC0619D5 for ; Mon, 27 Jul 2020 06:49:12 -0700 (PDT) Received: by mail-ed1-x541.google.com with SMTP id by13so12155610edb.11 for ; Mon, 27 Jul 2020 06:49:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=5nrJGkR5gzoJoAzFw0QkQIZLHmzb77Jw0yeZu9JZot4=; b=dFtmj2Pf6AsbS3ZvrmOl3FfSHcXv98akIbtsWzzmClw206P7VO9+ayWWQx9sByRB4h IvdlzRxURd8G6ieLgdpRGeBUc1taiMQV3jsbSXZC2A1tKVunmUZsw/k3TKGTTsczi9M8 hr6HisxYH5uZ1vlNHNfdpSAqCLg7wwALQkKrs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=5nrJGkR5gzoJoAzFw0QkQIZLHmzb77Jw0yeZu9JZot4=; b=hDeunqFft+L53E+T3vHUo1qDz6ksHxJF0jT1+MzWT4hpPFJnqmvtlv7tbzxafl81GS C2DgkXg0zYlaipYTSXBTafUrNmsSIDkgHaSIUfcJjTevSgY0lbxv9uskHVxUFJNRgccU nL6drykYyHnHHZZ4WPfeRdhd3ED3OoLzzFk0ZOlEZB+BsQ05GOmvdgsGQJYOTgKWbHnn 0bsnfy8tFY4Ex4ObmlVwI6ZvboAorvAHkrsiX8iJyrK1+zBNu59FCl/b5nUiFyhtg53v rOI42kufhmGJvDDMHnnkWoAdX7BnrgxRUcl73zi+B8tlrcbz7t9fOo8wXTjHBzmVCzNJ mf9Q== X-Gm-Message-State: AOAM533SZMd6hFehs/ByBy4jVqUoPlFBpkPFClxe+88OjFnqQuHP5dlQ Y2sVsvuIZGdujiOB8RBud0DAiLQfao1xYw== X-Received: by 2002:aa7:d45a:: with SMTP id q26mr5237059edr.95.1595857751109; Mon, 27 Jul 2020 06:49:11 -0700 (PDT) Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com. [209.85.221.53]) by smtp.gmail.com with ESMTPSA id br25sm6014837ejb.25.2020.07.27.06.49.09 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 27 Jul 2020 06:49:09 -0700 (PDT) Received: by mail-wr1-f53.google.com with SMTP id r4so12001807wrx.9 for ; Mon, 27 Jul 2020 06:49:09 -0700 (PDT) X-Received: by 2002:adf:82b2:: with SMTP id 47mr19927685wrc.17.1595857749000; Mon, 27 Jul 2020 06:49:09 -0700 (PDT) MIME-Version: 1.0 References: <20200426022650.10355-1-xc-racer2@live.ca> <20200707184412.GJ2621465@chromium.org> In-Reply-To: From: Tomasz Figa Date: Mon, 27 Jul 2020 15:48:57 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 10/11] media: exynos4-is: Prevent duplicate call to media_pipeline_stop To: Jonathan Bakker Cc: Kyungmin Park , Sylwester Nawrocki , Mauro Carvalho Chehab , kgene@kernel.org, Krzysztof Kozlowski , Linux Media Mailing List , "list@263.net:IOMMU DRIVERS" , Joerg Roedel , "list@263.net:IOMMU DRIVERS , Joerg Roedel ," , linux-samsung-soc , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jul 25, 2020 at 1:46 AM Jonathan Bakker wrote: > > Hi Tomasz, > > On 2020-07-20 6:10 a.m., Tomasz Figa wrote: > > On Sat, Jul 11, 2020 at 8:17 PM Jonathan Bakker wro= te: > >> > >> Hi Tomasz, > >> > >> On 2020-07-07 11:44 a.m., Tomasz Figa wrote: > >>> Hi Jonathan, > >>> > >>> On Sat, Apr 25, 2020 at 07:26:49PM -0700, Jonathan Bakker wrote: > >>>> media_pipeline_stop can be called from both release and streamoff, > >>>> so make sure they're both protected under the streaming flag and > >>>> not just one of them. > >>> > >>> First of all, thanks for the patch. > >>> > >>> Shouldn't it be that release calls streamoff, so that only streamoff > >>> is supposed to have the call to media_pipeline_stop()? > >>> > >> > >> I can't say that I understand the whole media subsystem enough to know= :) > >> Since media_pipeline_start is called in streamon, it makes sense that = streamoff > >> should have the media_pipeline_stop call. However, even after removin= g the call > >> in fimc_capture_release I'm still getting a backtrace such as > >> > >> [ 73.843117] ------------[ cut here ]------------ > >> [ 73.843251] WARNING: CPU: 0 PID: 1575 at drivers/media/mc/mc-entity= .c:554 media_pipeline_stop+0x20/0x2c [mc] > >> [ 73.843265] Modules linked in: s5p_fimc v4l2_fwnode exynos4_is_comm= on videobuf2_dma_contig pvrsrvkm_s5pv210_sgx540_120 videobuf2_memops v4l2_m= em2mem brcmfmac videobuf2_v4l2 videobuf2_common hci_uart sha256_generic lib= sha256 btbcm bluetooth cfg80211 brcmutil ecdh_generic ecc ce147 libaes s5ka= 3dfx videodev atmel_mxt_ts mc pwm_vibra rtc_max8998 > >> [ 73.843471] CPU: 0 PID: 1575 Comm: v4l2-ctl Not tainted 5.7.0-14534= -g2b33418b254e-dirty #669 > >> [ 73.843487] Hardware name: Samsung S5PC110/S5PV210-based board > >> [ 73.843562] [] (unwind_backtrace) from [] (show= _stack+0x10/0x14) > >> [ 73.843613] [] (show_stack) from [] (__warn+0xb= c/0xd4) > >> [ 73.843661] [] (__warn) from [] (warn_slowpath_= fmt+0x60/0xb8) > >> [ 73.843734] [] (warn_slowpath_fmt) from [] (med= ia_pipeline_stop+0x20/0x2c [mc]) > >> [ 73.843867] [] (media_pipeline_stop [mc]) from [] (fimc_cap_streamoff+0x38/0x48 [s5p_fimc]) > >> [ 73.844109] [] (fimc_cap_streamoff [s5p_fimc]) from [] (__video_do_ioctl+0x220/0x448 [videodev]) > >> [ 73.844308] [] (__video_do_ioctl [videodev]) from [] (video_usercopy+0x114/0x498 [videodev]) > >> [ 73.844438] [] (video_usercopy [videodev]) from [] (ksys_ioctl+0x20c/0xa10) > >> [ 73.844484] [] (ksys_ioctl) from [] (ret_fast_s= yscall+0x0/0x54) > >> [ 73.844505] Exception stack(0xe5083fa8 to 0xe5083ff0) > >> [ 73.844546] 3fa0: 0049908d bef8f8c0 00000003 4004= 5613 bef8d5ac 004c1d16 > >> [ 73.844590] 3fc0: 0049908d bef8f8c0 bef8f8c0 00000036 bef8d5ac 0000= 0000 b6d6b320 bef8faf8 > >> [ 73.844620] 3fe0: 004e3ed4 bef8c718 004990bb b6f00d0a > >> [ 73.844642] ---[ end trace e6a4a8b2f20addd4 ]--- > >> > >> The command I'm using for testing is > >> > >> v4l2-ctl --verbose -d 1 --stream-mmap=3D3 --stream-skip=3D2 --stream-t= o=3D./test.yuv --stream-count=3D1 > >> > >> Since I noticed that the streaming flag was being checked fimc_capture= _release > >> but not in fimc_cap_streamoff, I assumed that it was simply a missed c= heck. Comparing > >> with other drivers, they seem to call media_pipeline_stop in their vb2= _ops stop_streaming > >> callback. > > > > vb2 does a lot of state handling internally and makes sure that driver > > ops are not called when unnecessary, preventing double calls for > > example. I suppose it could be a better place to stop the pipeline > > indeed. However, ... > > > >> > >> I'm willing to test various options > >> > > > > I think it could make sense to add something like WARN_ON(1) inside > > media_pipeline_stop() and then check where the first call came from. > > Here's the results of that: > > [ 69.876823] ------------[ cut here ]------------ > [ 69.876962] WARNING: CPU: 0 PID: 1566 at drivers/media/mc/mc-entity.c:= 550 __media_pipeline_stop+0x24/0xfc [mc] > [ 69.876976] Modules linked in: s5p_fimc v4l2_fwnode exynos4_is_common = videobuf2_dma_contig videobuf2_memops v4l2_mem2mem brcmfmac videobuf2_v4l2 = pvrsrvkm_s5pv210_sgx540_120 videobuf2_common hci_uart sha256_generic btbcm = libsha256 bluetooth cfg80211 ce147 brcmutil s5ka3dfx ecdh_generic ecc libae= s videodev atmel_mxt_ts mc pwm_vibra rtc_max8998 > [ 69.877182] CPU: 0 PID: 1566 Comm: v4l2-ctl Not tainted 5.7.0-14540-gb= 1220848c797-dirty #681 > [ 69.877198] Hardware name: Samsung S5PC110/S5PV210-based board > [ 69.877274] [] (unwind_backtrace) from [] (show_st= ack+0x10/0x14) > [ 69.877326] [] (show_stack) from [] (__warn+0xbc/0= xd4) > [ 69.877375] [] (__warn) from [] (warn_slowpath_fmt= +0x60/0xb8) > [ 69.877448] [] (warn_slowpath_fmt) from [] (__medi= a_pipeline_stop+0x24/0xfc [mc]) > [ 69.877540] [] (__media_pipeline_stop [mc]) from [= ] (media_pipeline_stop+0x20/0x2c [mc]) > [ 69.877663] [] (media_pipeline_stop [mc]) from [] = (fimc_cap_streamoff+0x38/0x48 [s5p_fimc]) > [ 69.877904] [] (fimc_cap_streamoff [s5p_fimc]) from [] (__video_do_ioctl+0x220/0x448 [videodev]) > [ 69.878105] [] (__video_do_ioctl [videodev]) from [] (video_usercopy+0x114/0x498 [videodev]) > [ 69.878234] [] (video_usercopy [videodev]) from []= (ksys_ioctl+0x20c/0xa10) > [ 69.878281] [] (ksys_ioctl) from [] (ret_fast_sysc= all+0x0/0x54) > [ 69.878301] Exception stack(0xe50c1fa8 to 0xe50c1ff0) > [ 69.878342] 1fa0: 004ef08d 00539d0c 00000003 4004561= 3 bec1578c 00517d16 > [ 69.878386] 1fc0: 004ef08d 00539d0c bec188c0 00000036 bec165ac 0000000= 0 b6def320 bec18af8 > [ 69.878415] 1fe0: 00539ed4 bec15730 004ef0bb b6f84d0a > [ 69.878436] ---[ end trace d004ab573a72c329 ]--- > [ 69.879704] ------------[ cut here ]------------ > [ 69.879794] WARNING: CPU: 0 PID: 1566 at drivers/media/mc/mc-entity.c:= 550 __media_pipeline_stop+0x24/0xfc [mc] > [ 69.879806] Modules linked in: s5p_fimc v4l2_fwnode exynos4_is_common = videobuf2_dma_contig videobuf2_memops v4l2_mem2mem brcmfmac videobuf2_v4l2 = pvrsrvkm_s5pv210_sgx540_120 videobuf2_common hci_uart sha256_generic btbcm = libsha256 bluetooth cfg80211 ce147 brcmutil s5ka3dfx ecdh_generic ecc libae= s videodev atmel_mxt_ts mc pwm_vibra rtc_max8998 > [ 69.880002] CPU: 0 PID: 1566 Comm: v4l2-ctl Tainted: G W = 5.7.0-14540-gb1220848c797-dirty #681 > [ 69.880016] Hardware name: Samsung S5PC110/S5PV210-based board > [ 69.880071] [] (unwind_backtrace) from [] (show_st= ack+0x10/0x14) > [ 69.880115] [] (show_stack) from [] (__warn+0xbc/0= xd4) > [ 69.880161] [] (__warn) from [] (warn_slowpath_fmt= +0x60/0xb8) > [ 69.880231] [] (warn_slowpath_fmt) from [] (__medi= a_pipeline_stop+0x24/0xfc [mc]) > [ 69.880318] [] (__media_pipeline_stop [mc]) from [= ] (media_pipeline_stop+0x20/0x2c [mc]) > [ 69.880419] [] (media_pipeline_stop [mc]) from [] = (fimc_cap_streamoff+0x38/0x48 [s5p_fimc]) > [ 69.880582] [] (fimc_cap_streamoff [s5p_fimc]) from [] (__video_do_ioctl+0x220/0x448 [videodev]) > [ 69.880776] [] (__video_do_ioctl [videodev]) from [] (video_usercopy+0x114/0x498 [videodev]) > [ 69.880895] [] (video_usercopy [videodev]) from []= (ksys_ioctl+0x20c/0xa10) > [ 69.880939] [] (ksys_ioctl) from [] (ret_fast_sysc= all+0x0/0x54) > [ 69.880958] Exception stack(0xe50c1fa8 to 0xe50c1ff0) > [ 69.880997] 1fa0: 004ef08d bec188c0 00000003 4004561= 3 bec165ac 00517d16 > [ 69.881040] 1fc0: 004ef08d bec188c0 bec188c0 00000036 bec165ac 0000000= 0 b6def320 bec18af8 > [ 69.881070] 1fe0: 00539ed4 bec15718 004ef0bb b6f84d0a > [ 69.881089] ---[ end trace d004ab573a72c32a ]--- > [ 69.881102] ------------[ cut here ]------------ > [ 69.881163] WARNING: CPU: 0 PID: 1566 at drivers/media/mc/mc-entity.c:= 556 media_pipeline_stop+0x20/0x2c [mc] > [ 69.881174] Modules linked in: s5p_fimc v4l2_fwnode exynos4_is_common = videobuf2_dma_contig videobuf2_memops v4l2_mem2mem brcmfmac videobuf2_v4l2 = pvrsrvkm_s5pv210_sgx540_120 videobuf2_common hci_uart sha256_generic btbcm = libsha256 bluetooth cfg80211 ce147 brcmutil s5ka3dfx ecdh_generic ecc libae= s videodev atmel_mxt_ts mc pwm_vibra rtc_max8998 > [ 69.881367] CPU: 0 PID: 1566 Comm: v4l2-ctl Tainted: G W = 5.7.0-14540-gb1220848c797-dirty #681 > [ 69.881381] Hardware name: Samsung S5PC110/S5PV210-based board > [ 69.881424] [] (unwind_backtrace) from [] (show_st= ack+0x10/0x14) > [ 69.881465] [] (show_stack) from [] (__warn+0xbc/0= xd4) > [ 69.881511] [] (__warn) from [] (warn_slowpath_fmt= +0x60/0xb8) > [ 69.881580] [] (warn_slowpath_fmt) from [] (media_= pipeline_stop+0x20/0x2c [mc]) > [ 69.881683] [] (media_pipeline_stop [mc]) from [] = (fimc_cap_streamoff+0x38/0x48 [s5p_fimc]) > [ 69.881834] [] (fimc_cap_streamoff [s5p_fimc]) from [] (__video_do_ioctl+0x220/0x448 [videodev]) > [ 69.882025] [] (__video_do_ioctl [videodev]) from [] (video_usercopy+0x114/0x498 [videodev]) > [ 69.882246] [] (video_usercopy [videodev]) from []= (ksys_ioctl+0x20c/0xa10) > [ 69.882291] [] (ksys_ioctl) from [] (ret_fast_sysc= all+0x0/0x54) > [ 69.882309] Exception stack(0xe50c1fa8 to 0xe50c1ff0) > [ 69.882348] 1fa0: 004ef08d bec188c0 00000003 4004561= 3 bec165ac 00517d16 > [ 69.882391] 1fc0: 004ef08d bec188c0 bec188c0 00000036 bec165ac 0000000= 0 b6def320 bec18af8 > [ 69.882420] 1fe0: 00539ed4 bec15718 004ef0bb b6f84d0a > [ 69.882439] ---[ end trace d004ab573a72c32b ]--- > > With the final trace being the original one that I was having. > > So it looks to me as if streamoff is being called twice. Is this a possi= bility for all drivers > or is there a different bug that I should be trying to track down? In an= y event, my patch does > prevent the warning (although my reasoning was wrong as I thought it was = being stopped on the > call to release). It certainly is possible for the userspace call STREAMOFF twice and the driver needs to ensure that the second call is essentially a no-op, as per [1]. FWIW, if the driver defers the stream start/stop operation entirely to the vb2 .start/stop_streaming callback, then vb2 would handle this automatically. [1] https://www.kernel.org/doc/html/latest/userspace-api/media/v4l/vidioc-s= treamon.html#description Best regards, Tomasz