Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2278264rdb; Thu, 21 Sep 2023 13:51:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH2PwToZu0mQcfy27HooxLW6vUTWbdtvL+fQDml1T/kI66QgWn8tGazKo5mF2zWEWFcvxzi X-Received: by 2002:a05:6a00:e88:b0:68a:48e7:9deb with SMTP id bo8-20020a056a000e8800b0068a48e79debmr986847pfb.2.1695329488064; Thu, 21 Sep 2023 13:51:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695329488; cv=none; d=google.com; s=arc-20160816; b=a15ztIGAnyH9ugYMGI/BCQVMC2wlAuCXQ9EhwMY3FqntloIr2lzjO0MihYrSWWaNhE oHF2Lgvwzh1piOLQZ9Ns3hV2/0/ZPp0YaYy/nY+g35/7sJUvE7YyOWIGytOyMw6wDUfa bxqsidKyrKJnEGWlLjx7FSLpU+QArqXkH0zxZ5e/6JxMcpBMckGUbPn/IeaGZtxyIu2a AaPLlkgGyAjMsoKl/reX7Ax0txHRYEAndGGv0pDTDI0BxvKl1uRALa6l6eZfsKB8v18L FdhKHQx4EeX70NVc0+pirArwdmJF7QF5S+fVYYkGZ72I5wVDk5Mg+DrO4qsOARUljmZK 72BQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=9JMy6MY4JfmQdnZsJ+HEEtnKkAs4zFOI9Fa4yFABy0s=; fh=rvfjkWKWQ7H3dxwU/Mrzlf1SBsZ3Tuo/EBElQFetDNM=; b=l3R8paTinyI97qLtXkQfPn9S1hb/wie4aRGnxo23fvHS0d87TBtoD+xQGH3zoQ4WQF +q+WJX4gEe6aUe9D9k673yDFKDoOsB5dJjKwG3vXmWVoBDUjBlspxTIkwxt5xyXcJOEW 7IA5gKcSeKVnGywfLAmylheXSD9OST+Z0BO7kkuT27boFRcR3Y1z7bHb5brhysrGJotk 6a8D/rPLwC8kzSA95zt0zaz+7J1AZUgktDNaWDd1vGMr5lPcRqtm1VrmRE7iM7CO1XsW mgptHfpUl1/wz8cNktKAR89vcjzW46eiDJHOYLNzExMJOdvO+UmM0jR2IE6Ln9oOPC5b aPjA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id l3-20020a056a00140300b0068e4037c5f7si2289746pfu.388.2023.09.21.13.51.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 13:51:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 3B75C80FD8BB; Thu, 21 Sep 2023 13:37:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231700AbjIUUgl (ORCPT + 99 others); Thu, 21 Sep 2023 16:36:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232854AbjIUUfu (ORCPT ); Thu, 21 Sep 2023 16:35:50 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8865180FBA; Thu, 21 Sep 2023 10:36:57 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4979C32794; Thu, 21 Sep 2023 10:24:10 +0000 (UTC) Message-ID: Date: Thu, 21 Sep 2023 12:24:08 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v7 45/49] media: core: Add bitmap manage bufs array entries Content-Language: en-US, nl To: Benjamin Gaignard , mchehab@kernel.org, tfiga@chromium.org, m.szyprowski@samsung.com, ming.qian@nxp.com, ezequiel@vanguardiasur.com.ar, p.zabel@pengutronix.de, gregkh@linuxfoundation.org, nicolas.dufresne@collabora.com Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-staging@lists.linux.dev, kernel@collabora.com References: <20230914133323.198857-1-benjamin.gaignard@collabora.com> <20230914133323.198857-46-benjamin.gaignard@collabora.com> <1142bbb4-b8f1-44ec-962e-9347a231782f@xs4all.nl> <20b6b93e-eef8-3d7b-a3c2-795f220059d4@collabora.com> <470682b4-c14b-4237-bc46-fddfdd085026@xs4all.nl> <31f298ec-6280-d21b-3d8a-c7bf1c9c0c30@collabora.com> From: Hans Verkuil In-Reply-To: <31f298ec-6280-d21b-3d8a-c7bf1c9c0c30@collabora.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 21 Sep 2023 13:37:15 -0700 (PDT) On 21/09/2023 11:28, Benjamin Gaignard wrote: > > Le 20/09/2023 à 16:56, Hans Verkuil a écrit : >> On 20/09/2023 16:30, Benjamin Gaignard wrote: >> >> >>>>>        num_buffers = min_t(unsigned int, num_buffers, >>>>>                    q->max_allowed_buffers - vb2_get_num_buffers(q)); >>>>>    -    first_index = vb2_get_num_buffers(q); >>>>> +    first_index = bitmap_find_next_zero_area(q->bufs_map, q->max_allowed_buffers, >>>>> +                         0, num_buffers, 0); >>>>>          if (first_index >= q->max_allowed_buffers) >>>>>            return 0; >>>>> @@ -675,7 +678,13 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) >>>>>      struct vb2_buffer *vb2_get_buffer(struct vb2_queue *q, unsigned int index) >>>>>    { >>>>> -    if (index < q->num_buffers) >>>>> +    if (!q->bufs_map || !q->bufs) >>>>> +        return NULL; >>>> I don't think this can ever happen. >>> I got kernel crash without them. >>> I will keep them. >> What is the backtrace? How can this happen? It feels wrong that this can be >> called with a vb2_queue that apparently is not properly initialized. > > I have this log when adding dump_stack() in vb2_get_buffer() if !q->bufs_bitmap: > > [   18.924627] Call trace: > [   18.927090]  dump_backtrace+0x94/0xec > [   18.930787]  show_stack+0x18/0x24 > [   18.934137]  dump_stack_lvl+0x48/0x60 > [   18.937833]  dump_stack+0x18/0x24 > [   18.941166]  __vb2_queue_cancel+0x23c/0x2f0 > [   18.945365]  vb2_core_queue_release+0x24/0x6c > [   18.949740]  vb2_queue_release+0x10/0x1c > [   18.953677]  v4l2_m2m_ctx_release+0x20/0x40 > [   18.957892]  hantro_release+0x20/0x54 > [   18.961584]  v4l2_release+0x74/0xec > [   18.965110]  __fput+0xb4/0x274 > [   18.968205]  __fput_sync+0x50/0x5c > [   18.971626]  __arm64_sys_close+0x38/0x7c > [   18.975562]  invoke_syscall+0x48/0x114 > [   18.979329]  el0_svc_common.constprop.0+0xc0/0xe0 > [   18.984068]  do_el0_svc+0x1c/0x28 > [   18.987402]  el0_svc+0x40/0xe8 > [   18.990470]  el0t_64_sync_handler+0x100/0x12c > [   18.994842]  el0t_64_sync+0x190/0x194 > > This happen at boot time when hantro driver is open and close without other actions. Ah, now I see the problem. q->bufs and q->bufs_map are allocated in vb2_core_create_bufs and vb2_core_reqbufs, but they should be allocated in vb2_queue_init: that's the counterpart of vb2_core_queue_release. With that change you shouldn't have to check for q->bufs/bufs_map anymore. Regards, Hans >     >> >>>>> + >>>>> +    return (bitmap_weight(q->bufs_map, q->max_allowed_buffers) > 0); >>>> How about: >>>> >>>>      return vb2_get_num_buffers(q) > 0; >>> vb2_get_num_buffers is defined in videobuf2-core.c, I'm not sure that >>> an inline function could depend of a module function. >> Not a problem. E.g. v4l2-ctrls.h is full of such static inlines. >> >> Regards, >> >>     Hans >>