From patchwork Thu Jul 29 13:36:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 489035 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51D8CC4320E for ; Thu, 29 Jul 2021 13:36:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 31C3F60F46 for ; Thu, 29 Jul 2021 13:36:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237559AbhG2Ngi (ORCPT ); Thu, 29 Jul 2021 09:36:38 -0400 Received: from lb3-smtp-cloud8.xs4all.net ([194.109.24.29]:50367 "EHLO lb3-smtp-cloud8.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237585AbhG2Ngf (ORCPT ); Thu, 29 Jul 2021 09:36:35 -0400 Received: from cust-b5b5937f ([IPv6:fc0c:c16d:66b8:757f:c639:739b:9d66:799d]) by smtp-cloud8.xs4all.net with ESMTPA id 96D5mV4p4XTlc96D6mWuNK; Thu, 29 Jul 2021 15:36:28 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xs4all.nl; s=s2; t=1627565788; bh=OwMw1SnB0FvNy7NkyLwMP52QS8Hi/dGXZSI4slqI8cI=; h=From:To:Subject:Date:Message-Id:MIME-Version:From:Subject; b=qiG0/Z4ed8xeqHfDtb0ZMAiAsuSv1lPm8kjEMkgzS0BjRrodE7Dn5XkssTmZ0edmt Xht4lCojt+yAgvzr5LQuIVM9OMdMDfmcNXJyM1z333R9FSepZmRnvLOb2ur3s/yI2J j0Ua517eg3fZjmzkh9Ne8H86EnKrLBLAI6en1VNN+hM88PENwu5TA0hAyFtzJqpYnu ZN/yv1TzICCqjuVSZXxRJzV8xpVbm28XJp+IIajvDSLYas1cFkkJU0DTb6DMbfrTlE BNPMWj66cR+61TlcD6njsjz131SW1jYbwkAJsKrOTKA62YitCFmSedQ+oxv4bXnt3F fLqfjYr7x66fQ== From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Hans Verkuil Subject: [PATCH 2/3] vivid: add module option to set request support mode Date: Thu, 29 Jul 2021 15:36:26 +0200 Message-Id: <20210729133627.1592672-3-hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210729133627.1592672-1-hverkuil-cisco@xs4all.nl> References: <20210729133627.1592672-1-hverkuil-cisco@xs4all.nl> MIME-Version: 1.0 X-CMAE-Envelope: MS4xfGO50jq3zq15EklNILRdBPqiw3bRBKS+KTHcK5dj5eI2gxDuY+hjCkw5SSO5mN490Q939bLx8p8FD5SUNfS8NVrDTi2JiqDDJMYKH1QZ+VTOXGbILlq8 RG4j1C/sA6iK2rsLmCsjMWxHRRLpMtyE00+TFKsoDpregSTXXCdpw+aGQJHDIapUHDo/x2XM1cNrKiFwv3UbgCzWFdWln3Yj5m0I2CRraxCzk6e4pmxu0+Fl SYlATkBNTsgwAFX2OH7HdqMtDDwEIjE/skEGUig8ICNou5lf7E9xr7/JmyMiQIVV4xHs3aqISGTkLISX8xDD5w== Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Currently vivid supports the Request API, but it also sets min_buffers_needed in the vb2 queue. But the combination of support_requests and min_buffers_needed is not allowed due to the fact that vb2_core_qbuf() isn't supposed to fail when called from the request framework. And if min_buffers_needed > 0, then is can call start_streaming() which definitely can fail. With the new module option you can control if requests are not allowed (min_buffers_needed is 2 in that case), optionally allowed or are required. In the latter two cases min_buffers_needed is set to 0. Signed-off-by: Hans Verkuil --- drivers/media/test-drivers/vivid/vivid-core.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/media/test-drivers/vivid/vivid-core.c b/drivers/media/test-drivers/vivid/vivid-core.c index d2bd2653cf54..87f27c7524ec 100644 --- a/drivers/media/test-drivers/vivid/vivid-core.c +++ b/drivers/media/test-drivers/vivid/vivid-core.c @@ -177,6 +177,15 @@ MODULE_PARM_DESC(cache_hints, " user-space cache hints, default is 0.\n" "\t\t 0 == forbid\n" "\t\t 1 == allow"); +static unsigned int supports_requests[VIVID_MAX_DEVS] = { + [0 ... (VIVID_MAX_DEVS - 1)] = 1 +}; +module_param_array(supports_requests, uint, NULL, 0444); +MODULE_PARM_DESC(supports_requests, " support for requests, default is 1.\n" + "\t\t 0 == no support\n" + "\t\t 1 == supports requests\n" + "\t\t 2 == requires requests"); + static struct vivid_dev *vivid_devs[VIVID_MAX_DEVS]; const struct v4l2_rect vivid_min_rect = { @@ -883,10 +892,11 @@ static int vivid_create_queue(struct vivid_dev *dev, q->mem_ops = allocators[dev->inst] == 1 ? &vb2_dma_contig_memops : &vb2_vmalloc_memops; q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; - q->min_buffers_needed = min_buffers_needed; + q->min_buffers_needed = supports_requests[dev->inst] ? 0 : min_buffers_needed; q->lock = &dev->mutex; q->dev = dev->v4l2_dev.dev; - q->supports_requests = true; + q->supports_requests = supports_requests[dev->inst]; + q->requires_requests = supports_requests[dev->inst] >= 2; q->allow_cache_hints = (cache_hints[dev->inst] == 1); return vb2_queue_init(q); From patchwork Thu Jul 29 13:36:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 489036 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86481C4320A for ; Thu, 29 Jul 2021 13:36:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5FE3460F23 for ; Thu, 29 Jul 2021 13:36:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234314AbhG2Ngh (ORCPT ); Thu, 29 Jul 2021 09:36:37 -0400 Received: from lb3-smtp-cloud8.xs4all.net ([194.109.24.29]:57879 "EHLO lb3-smtp-cloud8.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237569AbhG2Ngf (ORCPT ); Thu, 29 Jul 2021 09:36:35 -0400 Received: from cust-b5b5937f ([IPv6:fc0c:c16d:66b8:757f:c639:739b:9d66:799d]) by smtp-cloud8.xs4all.net with ESMTPA id 96D5mV4p4XTlc96D6mWuNO; Thu, 29 Jul 2021 15:36:28 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xs4all.nl; s=s2; t=1627565788; bh=zONAtePxRAqoT/SF1ePsWsWoQYDFACX6TfzVmWlASF4=; h=From:To:Subject:Date:Message-Id:MIME-Version:From:Subject; b=oeDWfabecqVZ+crZPoiHyDpsqo37WoRcnzvU03uNiS3yAr73uiZj1Hdl5rMosKCt3 3rJjADbRfarBi+QCg2DqM7ltZ+QenzhLLN4yMtf2/gN3pxagIrG6GoSYy/yxsoclY+ QPaktgQtT2FVueh3U8iK3qLHgAmIHZ2eCgnoiONqNsGNxsRMHdyLtA7oEHDGivUOiD 5R2BXngGHzFa9ubTeC0LDasJ2MlkBNtpxRPSXDJZBlZn3QnBWfibiUDYUI2L0snwN5 DXN5mbeJ3pnF8lFXIPGmWxs6ZuXJ9WmRjJkodj/pu9MyiTvGh3mSrNZtD4P8EueW9z Zg10O1pirQNhg== From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Hans Verkuil , Ezequiel Garcia , Paul Kocialkowski Subject: [PATCH 3/3] videobuf2-core: sanity checks for requests and qbuf Date: Thu, 29 Jul 2021 15:36:27 +0200 Message-Id: <20210729133627.1592672-4-hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210729133627.1592672-1-hverkuil-cisco@xs4all.nl> References: <20210729133627.1592672-1-hverkuil-cisco@xs4all.nl> MIME-Version: 1.0 X-CMAE-Envelope: MS4xfGO50jq3zq15EklNILRdBPqiw3bRBKS+KTHcK5dj5eI2gxDuY+hjCkw5SSO5mN490Q939bLx8p8FD5SUNfS8NVrDTi2JiqDDJMYKH1QZ+VTOXGbILlq8 RG4j1C/sA6iK2rsLmCsjMWxHRRLpMtyE00+TFKsoDpregSTXXCdpw+aGQJHDIapUHDo/x2XM1cNrKlrNXWAzbWeP0aEjHW5uxjNA8166MZRcqMHJ4jBgdgqj D3/wq0A+nSevuypcSzy1syzmPcZSyY0FP1MG+rTt6xLV/el6Tv/gLVGbQCq3UGDVW83NWK7mIzxLjguJZk1U4wuAOWswDo6OyM3Wfl7hv8jRPRQB64SdkjCW irUDwhZrTlG1zdljlkHnv1aNkPzQDQ== Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The combination of supports_requests == 1 and min_buffers_needed > 0 is not allowed, WARN on that and return an error. Also check that if vb2_core_qbuf() is called from req_queue, that it doesn't return an error, unless it is -EIO. Signed-off-by: Hans Verkuil Cc: Ezequiel Garcia Cc: Paul Kocialkowski Reviewed-by: Ezequiel Garcia --- .../media/common/videobuf2/videobuf2-core.c | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 02281d13505f..3f0e816472d8 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -1421,9 +1421,19 @@ int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb, static void vb2_req_queue(struct media_request_object *obj) { struct vb2_buffer *vb = container_of(obj, struct vb2_buffer, req_obj); + int err; mutex_lock(vb->vb2_queue->lock); - vb2_core_qbuf(vb->vb2_queue, vb->index, NULL, NULL); + /* + * There is no method to propagate an error from vb2_core_qbuf(), + * so if this returns a non-0 value, then WARN. + * + * The only exception is -EIO which is returned if q->error is + * set. We just ignore that, and expect this will be caught the + * next time vb2_req_prepare() is called. + */ + err = vb2_core_qbuf(vb->vb2_queue, vb->index, NULL, NULL); + WARN_ON_ONCE(err && err != -EIO); mutex_unlock(vb->vb2_queue->lock); } @@ -2331,6 +2341,17 @@ int vb2_core_queue_init(struct vb2_queue *q) if (WARN_ON(q->requires_requests && !q->supports_requests)) return -EINVAL; + /* + * This combination is not allowed since a non-zero value of + * q->min_buffers_needed can cause vb2_core_qbuf() to fail if + * it has to call start_streaming(), and the Request API expects + * that queueing a request (and thus queueing a buffer contained + * in that request) will always succeed. There is no method of + * propagating an error back to userspace. + */ + if (WARN_ON(q->supports_requests && q->min_buffers_needed)) + return -EINVAL; + INIT_LIST_HEAD(&q->queued_list); INIT_LIST_HEAD(&q->done_list); spin_lock_init(&q->done_lock);