Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp778791rwl; Fri, 24 Mar 2023 01:40:34 -0700 (PDT) X-Google-Smtp-Source: AKy350Z9jg7FCK15dtbRanvH4Am1EseoK8W9iCOL74a4AMciNFSuoL+jBJde0sdqrP8yF4TCyM8D X-Received: by 2002:a17:902:d2c3:b0:19c:be03:d1ba with SMTP id n3-20020a170902d2c300b0019cbe03d1bamr2231196plc.6.1679647233879; Fri, 24 Mar 2023 01:40:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679647233; cv=none; d=google.com; s=arc-20160816; b=nzZ9VwCTOm24jlzceQ3Z2s9VuElW8puh0ZRung6UEcPOnjLH9tRHDDVgS0W9yPJUIH /5QiKvf7921DtWSJ8SPWBYNZ2zkmPUygQIWPuKoqsf1ZWUAJKkktPvkVcqpEEf9JDnT3 WjEgESzxin8dH1xWwi9U5/1slgmFoi4lslLOxOkAMqaSotvfeBUEHHzmivRFeBgn93Gt AD0O/dWRDhNkLqR+rgqNadsi1FR9BjymuGLE1zjTASFl6Mv+RVzZFIwASEWc+MJ3b5rU NOTAb9KKfz1kJ8gfjtTzOvqFMJn9M/csXf6uJiYzZ+GuWxfZmeYgUbHr/DpdLMO4Xrg/ RN8A== 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 :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id; bh=Z2prpVn6BNZMFoZAR5+q0DkyXfqW6a2kk2kp5ZOOO6I=; b=oMRrbZT0chTHuPhOhcqgAz+EhMMNzlMq5o9scIHBnxNnwooHeu31TGtEAclNNlxkU2 ovevT2u9v8rIdxfXjoX/LRcT+o+KzPMty7LJAwvC+EfVzuv6MjSyWz2RJtaZq+TSsWw/ G9K1XjXFHXuJlkNlbGNkZi8RgAMeA1N9LSS+eYeJjG5c4sUh78loQorrfSF1+5x/99kr Ka7Bpa7F04XI3oJU+r4zy8njCv8HiZSkY8+UUuKCK+dFxzDa+YnFBEt+caX+jRX4xU/4 BR8gdHCWncT2RCirWmaSgWe9CqfAKC3s9GI/3lrKNIOoksT+GVjQ16NFnfBj3BmpcpbN 2jLQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i9-20020a17090332c900b001a1a252c4b1si22269207plr.13.2023.03.24.01.40.22; Fri, 24 Mar 2023 01:40:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231693AbjCXIbt (ORCPT + 99 others); Fri, 24 Mar 2023 04:31:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230157AbjCXIbr (ORCPT ); Fri, 24 Mar 2023 04:31:47 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29E5B1499C; Fri, 24 Mar 2023 01:31:45 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id DD52DB822DC; Fri, 24 Mar 2023 08:31:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 069FAC433D2; Fri, 24 Mar 2023 08:31:36 +0000 (UTC) Message-ID: Date: Fri, 24 Mar 2023 09:31:35 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [PATCH v2 2/8] media: videobuf2: Make bufs array dynamic allocated To: Benjamin Gaignard , Dan Carpenter , oe-kbuild@lists.linux.dev, tfiga@chromium.org, m.szyprowski@samsung.com, mchehab@kernel.org, ming.qian@nxp.com, shijie.qin@nxp.com, eagle.zhou@nxp.com, bin.liu@mediatek.com, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, tiffany.lin@mediatek.com, andrew-ct.chen@mediatek.com, yunfei.dong@mediatek.com, stanimir.k.varbanov@gmail.com, quic_vgarodia@quicinc.com, agross@kernel.org, andersson@kernel.org, konrad.dybcio@linaro.org, ezequiel@vanguardiasur.com.ar, p.zabel@pengutronix.de, daniel.almeida@collabora.com, laurent.pinchart@ideasonboard.com Cc: lkp@intel.com, oe-kbuild-all@lists.linux.dev, 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, kernel@collabora.com References: <4e2cb832-de83-4ba6-bd8a-119a19038cfe@kili.mountain> Content-Language: en-US From: Hans Verkuil In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, NICE_REPLY_A,RCVD_IN_DNSWL_MED,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 24/03/2023 09:11, Benjamin Gaignard wrote: > > Le 24/03/2023 à 06:01, Dan Carpenter a écrit : >> Hi Benjamin, >> >> https://git-scm.com/docs/git-format-patch#_base_tree_information] >> >> url:    https://github.com/intel-lab-lkp/linux/commits/Benjamin-Gaignard/media-videobuf2-Access-vb2_queue-bufs-array-through-helper-functions/20230321-183154 >> base:   git://linuxtv.org/media_tree.git master >> patch link:    https://lore.kernel.org/r/20230321102855.346732-3-benjamin.gaignard%40collabora.com >> patch subject: [PATCH v2 2/8] media: videobuf2: Make bufs array dynamic allocated >> config: arm64-randconfig-m041-20230319 (https://download.01.org/0day-ci/archive/20230324/202303240148.lKRnUqW9-lkp@intel.com/config) >> compiler: aarch64-linux-gcc (GCC) 12.1.0 >> >> If you fix the issue, kindly add following tag where applicable >> | Reported-by: kernel test robot >> | Reported-by: Dan Carpenter >> | Link: https://lore.kernel.org/r/202303240148.lKRnUqW9-lkp@intel.com/ >> >> smatch warnings: >> include/media/videobuf2-core.h:1272 vb2_queue_add_buffer() warn: sleeping in atomic context >> drivers/media/common/videobuf2/videobuf2-core.c:2456 vb2_core_queue_init() warn: Please consider using kcalloc instead of kmalloc_array >> >> vim +1272 include/media/videobuf2-core.h >> >> 625d46c1c1fe8e Benjamin Gaignard 2023-03-21  1263  static inline bool vb2_queue_add_buffer(struct vb2_queue *q, struct vb2_buffer *vb) >> 625d46c1c1fe8e Benjamin Gaignard 2023-03-21  1264  { >> 487d3f14d12ecf Benjamin Gaignard 2023-03-21  1265      bool ret = false; >> 487d3f14d12ecf Benjamin Gaignard 2023-03-21  1266 >> 487d3f14d12ecf Benjamin Gaignard 2023-03-21  1267      spin_lock(&q->bufs_lock); >>                                                          ^^^^^^^^^^^^^^^^^^^^^^^ >> Holding a spin lock. >> >> 487d3f14d12ecf Benjamin Gaignard 2023-03-21  1268 >> 487d3f14d12ecf Benjamin Gaignard 2023-03-21  1269      if (vb->index >= q->max_num_bufs) { >> 487d3f14d12ecf Benjamin Gaignard 2023-03-21  1270          struct vb2_buffer **tmp; >> 487d3f14d12ecf Benjamin Gaignard 2023-03-21  1271 >> 487d3f14d12ecf Benjamin Gaignard 2023-03-21 @1272          tmp = krealloc_array(q->bufs, q->max_num_bufs * 2, sizeof(*q->bufs), GFP_KERNEL); >>                                                                                                                                       ^^^^^^^^^^ >> Sleeping allocation.  GFP_ATOMIC?  Or is there a way to move the >> allocation outside the lock? > > I will add GFP_ATOMIC flag in next version. No need. Instead, don't use realloc here, just allocate a new array, copy over all the data from the old, and then switch q->bufs with the spinlock held. Then you can free the old one. It's only when you update q->bufs that you need the lock. Regards, Hans > > Thanks for your help, > Benjamin > >> >> 487d3f14d12ecf Benjamin Gaignard 2023-03-21  1273          if (!tmp) >> 487d3f14d12ecf Benjamin Gaignard 2023-03-21  1274              goto realloc_failed; >> 487d3f14d12ecf Benjamin Gaignard 2023-03-21  1275 >> 487d3f14d12ecf Benjamin Gaignard 2023-03-21  1276          q->max_num_bufs *= 2; >> 487d3f14d12ecf Benjamin Gaignard 2023-03-21  1277          q->bufs = tmp; >> 487d3f14d12ecf Benjamin Gaignard 2023-03-21  1278      } >> 487d3f14d12ecf Benjamin Gaignard 2023-03-21  1279 >> 487d3f14d12ecf Benjamin Gaignard 2023-03-21  1280      if (vb->index < q->max_num_bufs) { >> 625d46c1c1fe8e Benjamin Gaignard 2023-03-21  1281          q->bufs[vb->index] = vb; >> 487d3f14d12ecf Benjamin Gaignard 2023-03-21  1282          ret = true; >> 625d46c1c1fe8e Benjamin Gaignard 2023-03-21  1283      } >> 625d46c1c1fe8e Benjamin Gaignard 2023-03-21  1284 >> 487d3f14d12ecf Benjamin Gaignard 2023-03-21  1285  realloc_failed: >> 487d3f14d12ecf Benjamin Gaignard 2023-03-21  1286      spin_unlock(&q->bufs_lock); >> 487d3f14d12ecf Benjamin Gaignard 2023-03-21  1287 >> 487d3f14d12ecf Benjamin Gaignard 2023-03-21  1288      return ret; >> 625d46c1c1fe8e Benjamin Gaignard 2023-03-21  1289  } >>