From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (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 18C943EBF04; Wed, 10 Jun 2026 14:34:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781102063; cv=none; b=BD2u+GhO61EbQTUaZoIFu3Vjpadke7u3cDCJRrVWUsXdcp4k7mowwalo4S5z2Y7pOcnVVPD+C464cGMCm/s8bXUtTXYnCJmaFpvAJLW5qpy36SAC62lh8F7G6nkauVs6iBvNX9EaBNwUwUNHDn1G2PmEvh7C6xhpdmc+zNKQSAE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781102063; c=relaxed/simple; bh=HyWTbyGJ/YxiyOxTmP3CmKvqM9AIBkFvj7FncysHdAU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZuG0J9P95oerRLhRsHt35AbBostjrDyEEqlueIiy503ztZInCCho1Zh2iSeouXSmhiwQuPBw/hIfjf8+iyyDY1BH5GohGcWThe1ICS9ddMGXaJOH7ZQXVWshKE1eA8+C6EiBumEXjoZAysVnjhJf6bPtpoZjF8F+qC2JoEkn8mA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=IfVmDkwA; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="IfVmDkwA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1781102056; bh=HyWTbyGJ/YxiyOxTmP3CmKvqM9AIBkFvj7FncysHdAU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=IfVmDkwAqc9AuJSpvM75+MHT2eLaD4v72NesicHD/NAj39vPLvXfSntFvPn/0OjWA PvQPGi8wjaZDg4mTJbkCtEkZGAYoROBbbRdggn3o2KRu7E6Tupgb1p+d55rryYzTCD 4KAoGF4R1pHSCm2PagoxV1d1IE8D9tLK1E/5d3Lxt326Kxe5a0R8+NN7QN1VoZ6wph Zv2QnG6qiuqsQYu+NweViL0jSM+rgtivGGbUSGAm1vaLDLeLVl1sOHWLcXuw9T6siO 74F2J7JEgp3jriSfTkLtt7Oj6xRcO8n6znQHdxJHY3pOHz7k+PhyLbpkj6Bldvgg43 liljoxado1rQA== Received: from [192.168.0.15] (unknown [100.64.0.170]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: detlev) by bali.collaboradmins.com (Postfix) with ESMTPSA id 3996F17E0DE1; Wed, 10 Jun 2026 16:34:14 +0200 (CEST) From: Detlev Casanova Date: Wed, 10 Jun 2026 10:33:33 -0400 Subject: [PATCH v2 3/9] media: Add tgid and fd fields in v4l2_fh struct Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260610-v4l2-add-ftrace-v2-3-9756edf72ac1@collabora.com> References: <20260610-v4l2-add-ftrace-v2-0-9756edf72ac1@collabora.com> In-Reply-To: <20260610-v4l2-add-ftrace-v2-0-9756edf72ac1@collabora.com> To: Daniel Almeida , Mauro Carvalho Chehab , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Nicolas Dufresne , Benjamin Gaignard , Philipp Zabel , Heiko Stuebner Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, kernel@collabora.com, Detlev Casanova X-Mailer: b4 0.15.2 These fields will be used in traces to help userspace tracing tools identify streams. The tgid field will keep the PID of the process that opened the video file. That is needed because trace calls can happen in IRQs, for which there is no current PID. The fd field helps identify the context in case the same process opens the video device multiple times. Note that the fd field is set in the __video_do_ioctl() function. That is because the file descriptor has not been allocated yet when v4l2_open() is called. Signed-off-by: Detlev Casanova Reviewed-by: Nicolas Dufresne --- drivers/media/v4l2-core/v4l2-fh.c | 1 + drivers/media/v4l2-core/v4l2-ioctl.c | 17 +++++++++++++++++ include/media/v4l2-fh.h | 4 ++++ 3 files changed, 22 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-fh.c b/drivers/media/v4l2-core/v4l2-fh.c index b184bed8aca9..9c2ddd1c2137 100644 --- a/drivers/media/v4l2-core/v4l2-fh.c +++ b/drivers/media/v4l2-core/v4l2-fh.c @@ -37,6 +37,7 @@ void v4l2_fh_init(struct v4l2_fh *fh, struct video_device *vdev) INIT_LIST_HEAD(&fh->available); INIT_LIST_HEAD(&fh->subscribed); fh->sequence = -1; + fh->tgid = current->tgid; mutex_init(&fh->subscribe_lock); } EXPORT_SYMBOL_GPL(v4l2_fh_init); diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c index a2b650f4ec3c..c8746a1637f5 100644 --- a/drivers/media/v4l2-core/v4l2-ioctl.c +++ b/drivers/media/v4l2-core/v4l2-ioctl.c @@ -9,6 +9,7 @@ */ #include +#include #include #include #include @@ -3061,6 +3062,16 @@ void v4l_printk_ioctl(const char *prefix, unsigned int cmd) } EXPORT_SYMBOL(v4l_printk_ioctl); +static int _file_iterate(const void *priv, struct file *filp, unsigned int fd) +{ + const struct file *fh_filp = priv; + + if (fh_filp == filp) + return fd; + + return 0; +} + static long __video_do_ioctl(struct file *file, unsigned int cmd, void *arg) { @@ -3081,6 +3092,12 @@ static long __video_do_ioctl(struct file *file, return ret; } + if (unlikely(!vfh->fd)) { + vfh->fd = iterate_fd(current->files, 0, _file_iterate, file); + if (!vfh->fd) + vfh->fd = -1; + } + /* * We need to serialize streamon/off/reqbufs with queueing new requests. * These ioctls may trigger the cancellation of a streaming diff --git a/include/media/v4l2-fh.h b/include/media/v4l2-fh.h index aad4b3689d7e..4ef4e58ab8d1 100644 --- a/include/media/v4l2-fh.h +++ b/include/media/v4l2-fh.h @@ -28,6 +28,8 @@ struct v4l2_ctrl_handler; * @vdev: pointer to &struct video_device * @ctrl_handler: pointer to &struct v4l2_ctrl_handler * @prio: priority of the file handler, as defined by &enum v4l2_priority + * @tgid: process id that initialized the v4l2_fh + * @fd: file descriptor associated to this v4l2_fh for the process id in tgid * * @wait: event' s wait queue * @subscribe_lock: serialise changes to the subscribed list; guarantee that @@ -44,6 +46,8 @@ struct v4l2_fh { struct video_device *vdev; struct v4l2_ctrl_handler *ctrl_handler; enum v4l2_priority prio; + uint32_t tgid; + int fd; /* Events */ wait_queue_head_t wait; -- 2.54.0