From patchwork Thu Jun 5 06:57:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 894364 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4174F2C3242 for ; Thu, 5 Jun 2025 07:05:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749107147; cv=none; b=AyDz7uTaQwcgI3C0zzzUafet+MMNw2LySeXYNKCHyqpsSdlgfoCMTkCOq07iA1ehxTRIS+ZWq8zDbIt+YvwykEHgMpIl0viCaX8N/VGSQD/43AGbA76AVzfO8QLxfT8XxAOQCgAWuurwSG9FPhrRQWaXq7Osf3A6/SnysZg+4mY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749107147; c=relaxed/simple; bh=YXA+mp+j9JF82EH8XyDAfv7iPP+EN8RFjstK02cKPxE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z5isF86fptHv92guqlszzCXnQGihPgkAzICphgO9pxb9ZDNNjPc9rrA54kxaVnaQDM+8MDS0SxGbYajY4cny5xXDG/vB4xjG++jwnITFKLCbkjMIpNIyGkrnstzt8T1VIdb3AqjNISd2bfDWtZce7kKctxzKi8Ov/tBLmHeCqv4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF6CDC4CEF0; Thu, 5 Jun 2025 07:05:45 +0000 (UTC) From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Mauro Carvalho Chehab , Hans Verkuil Subject: [PATCH 2/5] media: dvb-core/dmxdev: drop locks around mmap() Date: Thu, 5 Jun 2025 08:57:36 +0200 Message-ID: X-Mailer: git-send-email 2.47.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 vb2 no longer requires locking around mmap since commit f035eb4e976e ("[media] videobuf2: fix lockdep warning"). Since the streaming I/O mode for DVB support is by default off, and the dvb utilities were never updated with streaming support, and we never had regression tests for this streaming mode, this was never noticed before. Signed-off-by: Hans Verkuil --- drivers/media/dvb-core/dmxdev.c | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/drivers/media/dvb-core/dmxdev.c b/drivers/media/dvb-core/dmxdev.c index e4cf5e6bb542..ffeedb0c0950 100644 --- a/drivers/media/dvb-core/dmxdev.c +++ b/drivers/media/dvb-core/dmxdev.c @@ -1216,24 +1216,11 @@ static int dvb_demux_mmap(struct file *file, struct vm_area_struct *vma) { struct dmxdev_filter *dmxdevfilter = file->private_data; struct dmxdev *dmxdev = dmxdevfilter->dev; - int ret; if (!dmxdev->may_do_mmap) return -ENOTTY; - if (mutex_lock_interruptible(&dmxdev->mutex)) - return -ERESTARTSYS; - - if (mutex_lock_interruptible(&dmxdevfilter->mutex)) { - mutex_unlock(&dmxdev->mutex); - return -ERESTARTSYS; - } - ret = dvb_vb2_mmap(&dmxdevfilter->vb2_ctx, vma); - - mutex_unlock(&dmxdevfilter->mutex); - mutex_unlock(&dmxdev->mutex); - - return ret; + return dvb_vb2_mmap(&dmxdevfilter->vb2_ctx, vma); } #endif @@ -1366,7 +1353,6 @@ static int dvb_dvr_mmap(struct file *file, struct vm_area_struct *vma) { struct dvb_device *dvbdev = file->private_data; struct dmxdev *dmxdev = dvbdev->priv; - int ret; if (!dmxdev->may_do_mmap) return -ENOTTY; @@ -1374,12 +1360,7 @@ static int dvb_dvr_mmap(struct file *file, struct vm_area_struct *vma) if (dmxdev->exit) return -ENODEV; - if (mutex_lock_interruptible(&dmxdev->mutex)) - return -ERESTARTSYS; - - ret = dvb_vb2_mmap(&dmxdev->dvr_vb2_ctx, vma); - mutex_unlock(&dmxdev->mutex); - return ret; + return dvb_vb2_mmap(&dmxdev->dvr_vb2_ctx, vma); } #endif From patchwork Thu Jun 5 06:57:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 894363 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 71E422C3242 for ; Thu, 5 Jun 2025 07:05:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749107149; cv=none; b=Yq8J6CzWBsZqMi9luD2Icz5ALl0AA2OvgEcCQZEaemNZEsTFWuxwrlJOphKMClTn7tCQOxBB/aaC1cKC+wWH8V+v7SO+DcUP8Bce0mS2ZNcLaa+IYlu+b2gxEWroyCvjOlGit+Ydx98U9kl0li6+5cRPymMCCEBsr6pjupnhuEg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749107149; c=relaxed/simple; bh=jkC/D8Endlg1um3xAdGze0ThIkLvebFclT19aTclBGQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V869632he/8hOozXDMD8+6Oj9+MrCh9BEDPYfdjIfjpNsxDlWbxXmuuV+HwQWRhiD5sFZbXphXt0VP88LsHwe4Q5qH8w3rrsh28wLdLCCDpy3gVk9c8viUHSldQtykeX3yBXx4utxTILPmATf6EBEzm2hj2RvzLC2vXJoxrIEi0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7115DC4CEEB; Thu, 5 Jun 2025 07:05:48 +0000 (UTC) From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Mauro Carvalho Chehab , Hans Verkuil Subject: [PATCH 4/5] media: vb2: remove vb2_ops_wait_prepare/finish helpers Date: Thu, 5 Jun 2025 08:57:38 +0200 Message-ID: <3da514ec5172f643d40e7aa0b3d8560bfd7f6b63.1749106659.git.hverkuil@xs4all.nl> X-Mailer: git-send-email 2.47.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Since vb2 now relies on the presence of the vb2_queue lock field and there are no more drivers that use these helpers, it is safe to drop them. Signed-off-by: Hans Verkuil --- Documentation/driver-api/media/v4l2-dev.rst | 8 ++++---- .../media/common/videobuf2/videobuf2-v4l2.c | 14 -------------- include/media/videobuf2-v4l2.h | 18 ------------------ 3 files changed, 4 insertions(+), 36 deletions(-) diff --git a/Documentation/driver-api/media/v4l2-dev.rst b/Documentation/driver-api/media/v4l2-dev.rst index d5cb19b21a9f..dd239ad42051 100644 --- a/Documentation/driver-api/media/v4l2-dev.rst +++ b/Documentation/driver-api/media/v4l2-dev.rst @@ -157,10 +157,10 @@ changing the e.g. exposure of the webcam. Of course, you can always do all the locking yourself by leaving both lock pointers at ``NULL``. -In the case of :ref:`videobuf2 ` you will need to implement the -``wait_prepare()`` and ``wait_finish()`` callbacks to unlock/lock if applicable. -If you use the ``queue->lock`` pointer, then you can use the helper functions -:c:func:`vb2_ops_wait_prepare` and :c:func:`vb2_ops_wait_finish`. +In the case of :ref:`videobuf2 ` you must set the ``queue->lock`` +pointer to the lock you use to serialize the queuing ioctls. This ensures that +that lock is released while waiting in ``VIDIOC_DQBUF`` for a buffer to arrive, +and it is retaken afterwards. The implementation of a hotplug disconnect should also take the lock from :c:type:`video_device` before calling v4l2_device_disconnect. If you are also diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index 1cd26faee503..c16e920b752b 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -1301,20 +1301,6 @@ void vb2_video_unregister_device(struct video_device *vdev) } EXPORT_SYMBOL_GPL(vb2_video_unregister_device); -/* vb2_ops helpers. Only use if vq->lock is non-NULL. */ - -void vb2_ops_wait_prepare(struct vb2_queue *vq) -{ - mutex_unlock(vq->lock); -} -EXPORT_SYMBOL_GPL(vb2_ops_wait_prepare); - -void vb2_ops_wait_finish(struct vb2_queue *vq) -{ - mutex_lock(vq->lock); -} -EXPORT_SYMBOL_GPL(vb2_ops_wait_finish); - /* * Note that this function is called during validation time and * thus the req_queue_mutex is held to ensure no request objects diff --git a/include/media/videobuf2-v4l2.h b/include/media/videobuf2-v4l2.h index 77ce8238ab30..71d2864fb235 100644 --- a/include/media/videobuf2-v4l2.h +++ b/include/media/videobuf2-v4l2.h @@ -367,24 +367,6 @@ unsigned long vb2_fop_get_unmapped_area(struct file *file, unsigned long addr, */ void vb2_video_unregister_device(struct video_device *vdev); -/** - * vb2_ops_wait_prepare - helper function to lock a struct &vb2_queue - * - * @vq: pointer to &struct vb2_queue - * - * ..note:: only use if vq->lock is non-NULL. - */ -void vb2_ops_wait_prepare(struct vb2_queue *vq); - -/** - * vb2_ops_wait_finish - helper function to unlock a struct &vb2_queue - * - * @vq: pointer to &struct vb2_queue - * - * ..note:: only use if vq->lock is non-NULL. - */ -void vb2_ops_wait_finish(struct vb2_queue *vq); - struct media_request; int vb2_request_validate(struct media_request *req); void vb2_request_queue(struct media_request *req);