* [PATCH v5 0/4] media: uvcvideo: Introduce V4L2_META_FMT_UVC_MSXU_1_5 + other meta fixes
@ 2025-04-04 6:37 Ricardo Ribalda
2025-04-04 6:37 ` [PATCH v5 1/4] media: uvcvideo: Do not mark valid metadata as invalid Ricardo Ribalda
` (4 more replies)
0 siblings, 5 replies; 18+ messages in thread
From: Ricardo Ribalda @ 2025-04-04 6:37 UTC (permalink / raw)
To: Laurent Pinchart, Hans de Goede, Mauro Carvalho Chehab,
Guennadi Liakhovetski
Cc: linux-media, linux-kernel, Ricardo Ribalda, stable
This series introduces a new metadata format for UVC cameras and adds a
couple of improvements to the UVC metadata handling.
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
---
Changes in v5:
- Fix codestyle and kerneldoc warnings reported by media-ci
- Link to v4: https://lore.kernel.org/r/20250403-uvc-meta-v4-0-877aa6475975@chromium.org
Changes in v4:
- Rename format to V4L2_META_FMT_UVC_MSXU_1_5 (Thanks Mauro)
- Flag the new format with a quirk.
- Autodetect MSXU devices.
- Link to v3: https://lore.kernel.org/linux-media/20250313-uvc-metadata-v3-0-c467af869c60@chromium.org/
Changes in v3:
- Fix doc syntax errors.
- Link to v2: https://lore.kernel.org/r/20250306-uvc-metadata-v2-0-7e939857cad5@chromium.org
Changes in v2:
- Add metadata invalid fix
- Move doc note to a separate patch
- Introuce V4L2_META_FMT_UVC_CUSTOM (thanks HdG!).
- Link to v1: https://lore.kernel.org/r/20250226-uvc-metadata-v1-1-6cd6fe5ec2cb@chromium.org
---
Ricardo Ribalda (4):
media: uvcvideo: Do not mark valid metadata as invalid
media: Documentation: Add note about UVCH length field
media: uvcvideo: Introduce V4L2_META_FMT_UVC_MSXU_1_5
media: uvcvideo: Auto-set UVC_QUIRK_MSXU_META
.../userspace-api/media/v4l/meta-formats.rst | 1 +
.../media/v4l/metafmt-uvc-msxu-1-5.rst | 23 +++++
.../userspace-api/media/v4l/metafmt-uvc.rst | 4 +-
MAINTAINERS | 1 +
drivers/media/usb/uvc/uvc_metadata.c | 97 ++++++++++++++++++++--
drivers/media/usb/uvc/uvc_video.c | 12 +--
drivers/media/usb/uvc/uvcvideo.h | 1 +
drivers/media/v4l2-core/v4l2-ioctl.c | 1 +
include/linux/usb/uvc.h | 3 +
include/uapi/linux/videodev2.h | 1 +
10 files changed, 131 insertions(+), 13 deletions(-)
---
base-commit: 4e82c87058f45e79eeaa4d5bcc3b38dd3dce7209
change-id: 20250403-uvc-meta-e556773d12ae
Best regards,
--
Ricardo Ribalda <ribalda@chromium.org>
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v5 1/4] media: uvcvideo: Do not mark valid metadata as invalid
2025-04-04 6:37 [PATCH v5 0/4] media: uvcvideo: Introduce V4L2_META_FMT_UVC_MSXU_1_5 + other meta fixes Ricardo Ribalda
@ 2025-04-04 6:37 ` Ricardo Ribalda
2025-05-26 13:12 ` Hans de Goede
2025-05-26 13:46 ` Laurent Pinchart
2025-04-04 6:37 ` [PATCH v5 2/4] media: Documentation: Add note about UVCH length field Ricardo Ribalda
` (3 subsequent siblings)
4 siblings, 2 replies; 18+ messages in thread
From: Ricardo Ribalda @ 2025-04-04 6:37 UTC (permalink / raw)
To: Laurent Pinchart, Hans de Goede, Mauro Carvalho Chehab,
Guennadi Liakhovetski
Cc: linux-media, linux-kernel, Ricardo Ribalda, stable
Currently, the driver performs a length check of the metadata buffer
before the actual metadata size is known and before the metadata is
decided to be copied. This results in valid metadata buffers being
incorrectly marked as invalid.
Move the length check to occur after the metadata size is determined and
is decided to be copied.
Cc: stable@vger.kernel.org
Fixes: 088ead255245 ("media: uvcvideo: Add a metadata device node")
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
---
drivers/media/usb/uvc/uvc_video.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
index e3567aeb0007c1f0a766f331e4e744359e95a863..b113297dac61f1b2eecd72c36ea61ef2c1e7d28a 100644
--- a/drivers/media/usb/uvc/uvc_video.c
+++ b/drivers/media/usb/uvc/uvc_video.c
@@ -1433,12 +1433,6 @@ static void uvc_video_decode_meta(struct uvc_streaming *stream,
if (!meta_buf || length == 2)
return;
- if (meta_buf->length - meta_buf->bytesused <
- length + sizeof(meta->ns) + sizeof(meta->sof)) {
- meta_buf->error = 1;
- return;
- }
-
has_pts = mem[1] & UVC_STREAM_PTS;
has_scr = mem[1] & UVC_STREAM_SCR;
@@ -1459,6 +1453,12 @@ static void uvc_video_decode_meta(struct uvc_streaming *stream,
!memcmp(scr, stream->clock.last_scr, 6)))
return;
+ if (meta_buf->length - meta_buf->bytesused <
+ length + sizeof(meta->ns) + sizeof(meta->sof)) {
+ meta_buf->error = 1;
+ return;
+ }
+
meta = (struct uvc_meta_buf *)((u8 *)meta_buf->mem + meta_buf->bytesused);
local_irq_save(flags);
time = uvc_video_get_time();
--
2.49.0.504.g3bcea36a83-goog
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v5 2/4] media: Documentation: Add note about UVCH length field
2025-04-04 6:37 [PATCH v5 0/4] media: uvcvideo: Introduce V4L2_META_FMT_UVC_MSXU_1_5 + other meta fixes Ricardo Ribalda
2025-04-04 6:37 ` [PATCH v5 1/4] media: uvcvideo: Do not mark valid metadata as invalid Ricardo Ribalda
@ 2025-04-04 6:37 ` Ricardo Ribalda
2025-05-26 13:12 ` Hans de Goede
2025-05-26 13:49 ` Laurent Pinchart
2025-04-04 6:37 ` [PATCH v5 3/4] media: uvcvideo: Introduce V4L2_META_FMT_UVC_MSXU_1_5 Ricardo Ribalda
` (2 subsequent siblings)
4 siblings, 2 replies; 18+ messages in thread
From: Ricardo Ribalda @ 2025-04-04 6:37 UTC (permalink / raw)
To: Laurent Pinchart, Hans de Goede, Mauro Carvalho Chehab,
Guennadi Liakhovetski
Cc: linux-media, linux-kernel, Ricardo Ribalda
The documentation currently describes the UVC length field as the "length
of the rest of the block", which can be misleading. The driver limits the
data copied to a maximum of 12 bytes.
This change adds a clarifying sentence to the documentation to make this
restriction explicit.
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
---
Documentation/userspace-api/media/v4l/metafmt-uvc.rst | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/Documentation/userspace-api/media/v4l/metafmt-uvc.rst b/Documentation/userspace-api/media/v4l/metafmt-uvc.rst
index 784346d14bbdbf28348262084d5b0646d30bd1da..42599875331c0066cf529153caccb731148023b9 100644
--- a/Documentation/userspace-api/media/v4l/metafmt-uvc.rst
+++ b/Documentation/userspace-api/media/v4l/metafmt-uvc.rst
@@ -44,7 +44,9 @@ Each individual block contains the following fields:
them
* - :cspan:`1` *The rest is an exact copy of the UVC payload header:*
* - __u8 length;
- - length of the rest of the block, including this field
+ - length of the rest of the block, including this field. Please note that
+ regardless of the this value, for V4L2_META_FMT_UVC the kernel will
+ never copy more than 2-12 bytes.
* - __u8 flags;
- Flags, indicating presence of other standard UVC fields
* - __u8 buf[];
--
2.49.0.504.g3bcea36a83-goog
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v5 3/4] media: uvcvideo: Introduce V4L2_META_FMT_UVC_MSXU_1_5
2025-04-04 6:37 [PATCH v5 0/4] media: uvcvideo: Introduce V4L2_META_FMT_UVC_MSXU_1_5 + other meta fixes Ricardo Ribalda
2025-04-04 6:37 ` [PATCH v5 1/4] media: uvcvideo: Do not mark valid metadata as invalid Ricardo Ribalda
2025-04-04 6:37 ` [PATCH v5 2/4] media: Documentation: Add note about UVCH length field Ricardo Ribalda
@ 2025-04-04 6:37 ` Ricardo Ribalda
2025-05-26 13:16 ` Hans de Goede
2025-05-26 13:53 ` Laurent Pinchart
2025-04-04 6:37 ` [PATCH v5 4/4] media: uvcvideo: Auto-set UVC_QUIRK_MSXU_META Ricardo Ribalda
2025-05-05 9:06 ` [PATCH v5 0/4] media: uvcvideo: Introduce V4L2_META_FMT_UVC_MSXU_1_5 + other meta fixes Ricardo Ribalda
4 siblings, 2 replies; 18+ messages in thread
From: Ricardo Ribalda @ 2025-04-04 6:37 UTC (permalink / raw)
To: Laurent Pinchart, Hans de Goede, Mauro Carvalho Chehab,
Guennadi Liakhovetski
Cc: linux-media, linux-kernel, Ricardo Ribalda
The UVC driver provides two metadata types V4L2_META_FMT_UVC, and
V4L2_META_FMT_D4XX. The only difference between the two of them is that
V4L2_META_FMT_UVC only copies PTS, SCR, size and flags, and
V4L2_META_FMT_D4XX copies the whole metadata section.
Now we only enable V4L2_META_FMT_D4XX for the Intel D4xx family of
devices, but it is useful to have the whole metadata section for any
device where vendors include other metadata, such as the one described by
Microsoft:
https://learn.microsoft.com/en-us/windows-hardware/drivers/stream/mf-capture-metadata
This patch introduces a new format V4L2_META_FMT_UVC_MSXU_1_5, that is
identical to V4L2_META_FMT_D4XX.
For now, flag this format with a new quirk.
Suggested-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
---
.../userspace-api/media/v4l/meta-formats.rst | 1 +
.../media/v4l/metafmt-uvc-msxu-1-5.rst | 23 ++++++++++++
MAINTAINERS | 1 +
drivers/media/usb/uvc/uvc_metadata.c | 43 +++++++++++++++++++---
drivers/media/usb/uvc/uvcvideo.h | 1 +
drivers/media/v4l2-core/v4l2-ioctl.c | 1 +
include/uapi/linux/videodev2.h | 1 +
7 files changed, 65 insertions(+), 6 deletions(-)
diff --git a/Documentation/userspace-api/media/v4l/meta-formats.rst b/Documentation/userspace-api/media/v4l/meta-formats.rst
index 86ffb3bc8ade2e0c563dd84441572ecea1a571a6..4de0d094e0702068be0c59154458c9dfecbfe28d 100644
--- a/Documentation/userspace-api/media/v4l/meta-formats.rst
+++ b/Documentation/userspace-api/media/v4l/meta-formats.rst
@@ -19,6 +19,7 @@ These formats are used for the :ref:`metadata` interface only.
metafmt-pisp-fe
metafmt-rkisp1
metafmt-uvc
+ metafmt-uvc-msxu-1-5
metafmt-vivid
metafmt-vsp1-hgo
metafmt-vsp1-hgt
diff --git a/Documentation/userspace-api/media/v4l/metafmt-uvc-msxu-1-5.rst b/Documentation/userspace-api/media/v4l/metafmt-uvc-msxu-1-5.rst
new file mode 100644
index 0000000000000000000000000000000000000000..e6f95a88c0ff061df0b066b12cefc30f946b60aa
--- /dev/null
+++ b/Documentation/userspace-api/media/v4l/metafmt-uvc-msxu-1-5.rst
@@ -0,0 +1,23 @@
+.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
+
+.. _v4l2-meta-fmt-uvc-msxu-1-5:
+
+***********************************
+V4L2_META_FMT_UVC_MSXU_1_5 ('UVCM')
+***********************************
+
+Microsoft(R)'s UVC Payload Metadata.
+
+
+Description
+===========
+
+V4L2_META_FMT_UVC_MSXU_1_5 buffers follow the metadata buffer layout of
+V4L2_META_FMT_UVC with the only difference that it includes all the UVC
+metadata, not just the first 2-12 bytes.
+
+For more details check the documentation from Microsoft(R) [1].
+
+.. _1:
+
+[1] https://docs.microsoft.com/en-us/windows-hardware/drivers/stream/uvc-extensions-1-5
diff --git a/MAINTAINERS b/MAINTAINERS
index 306b1384eb6d4cb7a310ada44605eaeb88cc732f..a07ed31ab057b98cf801d919b5bbec5ee334c9ac 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -25059,6 +25059,7 @@ S: Maintained
W: http://www.ideasonboard.org/uvc/
T: git git://linuxtv.org/media.git
F: Documentation/userspace-api/media/drivers/uvcvideo.rst
+F: Documentation/userspace-api/media/v4l/metafmt-uvc-msxu-1-5.rst
F: Documentation/userspace-api/media/v4l/metafmt-uvc.rst
F: drivers/media/common/uvc.c
F: drivers/media/usb/uvc/
diff --git a/drivers/media/usb/uvc/uvc_metadata.c b/drivers/media/usb/uvc/uvc_metadata.c
index 82de7781f5b6b70c5ba16bcba9e0741231231904..fe2678fc795d7fd5a64e8113199012f34c419176 100644
--- a/drivers/media/usb/uvc/uvc_metadata.c
+++ b/drivers/media/usb/uvc/uvc_metadata.c
@@ -63,15 +63,21 @@ static int uvc_meta_v4l2_try_format(struct file *file, void *fh,
struct uvc_streaming *stream = video_get_drvdata(vfh->vdev);
struct uvc_device *dev = stream->dev;
struct v4l2_meta_format *fmt = &format->fmt.meta;
- u32 fmeta = fmt->dataformat;
+ u32 fmeta;
+
+ if (fmt->dataformat == dev->info->meta_format)
+ fmeta = dev->info->meta_format;
+ else if (fmt->dataformat == V4L2_META_FMT_UVC_MSXU_1_5)
+ fmeta = V4L2_META_FMT_UVC_MSXU_1_5;
+ else
+ fmeta = V4L2_META_FMT_UVC;
if (format->type != vfh->vdev->queue->type)
return -EINVAL;
memset(fmt, 0, sizeof(*fmt));
- fmt->dataformat = fmeta == dev->info->meta_format
- ? fmeta : V4L2_META_FMT_UVC;
+ fmt->dataformat = fmeta;
fmt->buffersize = UVC_METADATA_BUF_SIZE;
return 0;
@@ -106,6 +112,27 @@ static int uvc_meta_v4l2_set_format(struct file *file, void *fh,
return ret;
}
+static u32 uvc_meta_idx_to_fmeta(struct uvc_device *dev, u32 index)
+{
+ switch (index) {
+ case 0:
+ return V4L2_META_FMT_UVC;
+ case 1:
+ if (dev->info->meta_format)
+ return dev->info->meta_format;
+ if (dev->quirks & UVC_QUIRK_MSXU_META)
+ return V4L2_META_FMT_UVC_MSXU_1_5;
+ return 0;
+ case 2:
+ if (dev->info->meta_format &&
+ dev->quirks & UVC_QUIRK_MSXU_META)
+ return V4L2_META_FMT_UVC_MSXU_1_5;
+ return 0;
+ }
+
+ return 0;
+}
+
static int uvc_meta_v4l2_enum_formats(struct file *file, void *fh,
struct v4l2_fmtdesc *fdesc)
{
@@ -113,16 +140,20 @@ static int uvc_meta_v4l2_enum_formats(struct file *file, void *fh,
struct uvc_streaming *stream = video_get_drvdata(vfh->vdev);
struct uvc_device *dev = stream->dev;
u32 index = fdesc->index;
+ u32 fmeta;
+
+ if (fdesc->type != vfh->vdev->queue->type)
+ return -EINVAL;
- if (fdesc->type != vfh->vdev->queue->type ||
- index > 1U || (index && !dev->info->meta_format))
+ fmeta = uvc_meta_idx_to_fmeta(dev, fdesc->index);
+ if (!fmeta)
return -EINVAL;
memset(fdesc, 0, sizeof(*fdesc));
fdesc->type = vfh->vdev->queue->type;
fdesc->index = index;
- fdesc->pixelformat = index ? dev->info->meta_format : V4L2_META_FMT_UVC;
+ fdesc->pixelformat = fmeta;
return 0;
}
diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
index b4ee701835fc016474d2cd2a0b67b2aa915c1c60..123446683e22589f23b5228a00240e54f00ae6f1 100644
--- a/drivers/media/usb/uvc/uvcvideo.h
+++ b/drivers/media/usb/uvc/uvcvideo.h
@@ -77,6 +77,7 @@
#define UVC_QUIRK_DISABLE_AUTOSUSPEND 0x00008000
#define UVC_QUIRK_INVALID_DEVICE_SOF 0x00010000
#define UVC_QUIRK_MJPEG_NO_EOF 0x00020000
+#define UVC_QUIRK_MSXU_META 0x00040000
/* Format flags */
#define UVC_FMT_FLAG_COMPRESSED 0x00000001
diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
index a16fb44c7246e35f3710306fde5dfc15329b4d95..12f1232e5ca3acdefede8f9751f9e7191eeae58b 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1457,6 +1457,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
case V4L2_META_FMT_VSP1_HGO: descr = "R-Car VSP1 1-D Histogram"; break;
case V4L2_META_FMT_VSP1_HGT: descr = "R-Car VSP1 2-D Histogram"; break;
case V4L2_META_FMT_UVC: descr = "UVC Payload Header Metadata"; break;
+ case V4L2_META_FMT_UVC_MSXU_1_5: descr = "UVC MSXU Metadata"; break;
case V4L2_META_FMT_D4XX: descr = "Intel D4xx UVC Metadata"; break;
case V4L2_META_FMT_VIVID: descr = "Vivid Metadata"; break;
case V4L2_META_FMT_RK_ISP1_PARAMS: descr = "Rockchip ISP1 3A Parameters"; break;
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index c8cb2796130f8d1b864d669267d2b31f73b839aa..0cf6885a5dc8752326bd10a893d5d09d47993c21 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -851,6 +851,7 @@ struct v4l2_pix_format {
#define V4L2_META_FMT_VSP1_HGT v4l2_fourcc('V', 'S', 'P', 'T') /* R-Car VSP1 2-D Histogram */
#define V4L2_META_FMT_UVC v4l2_fourcc('U', 'V', 'C', 'H') /* UVC Payload Header metadata */
#define V4L2_META_FMT_D4XX v4l2_fourcc('D', '4', 'X', 'X') /* D4XX Payload Header metadata */
+#define V4L2_META_FMT_UVC_MSXU_1_5 v4l2_fourcc('U', 'V', 'C', 'M') /* UVC MSXU metadata */
#define V4L2_META_FMT_VIVID v4l2_fourcc('V', 'I', 'V', 'D') /* Vivid Metadata */
/* Vendor specific - used for RK_ISP1 camera sub-system */
--
2.49.0.504.g3bcea36a83-goog
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH v5 4/4] media: uvcvideo: Auto-set UVC_QUIRK_MSXU_META
2025-04-04 6:37 [PATCH v5 0/4] media: uvcvideo: Introduce V4L2_META_FMT_UVC_MSXU_1_5 + other meta fixes Ricardo Ribalda
` (2 preceding siblings ...)
2025-04-04 6:37 ` [PATCH v5 3/4] media: uvcvideo: Introduce V4L2_META_FMT_UVC_MSXU_1_5 Ricardo Ribalda
@ 2025-04-04 6:37 ` Ricardo Ribalda
2025-05-26 13:19 ` Hans de Goede
2025-05-26 14:02 ` Laurent Pinchart
2025-05-05 9:06 ` [PATCH v5 0/4] media: uvcvideo: Introduce V4L2_META_FMT_UVC_MSXU_1_5 + other meta fixes Ricardo Ribalda
4 siblings, 2 replies; 18+ messages in thread
From: Ricardo Ribalda @ 2025-04-04 6:37 UTC (permalink / raw)
To: Laurent Pinchart, Hans de Goede, Mauro Carvalho Chehab,
Guennadi Liakhovetski
Cc: linux-media, linux-kernel, Ricardo Ribalda
If the camera supports the MSXU_CONTROL_METADATA control, auto set the
MSXU_META quirk.
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
---
drivers/media/usb/uvc/uvc_metadata.c | 54 ++++++++++++++++++++++++++++++++++++
include/linux/usb/uvc.h | 3 ++
2 files changed, 57 insertions(+)
diff --git a/drivers/media/usb/uvc/uvc_metadata.c b/drivers/media/usb/uvc/uvc_metadata.c
index fe2678fc795d7fd5a64e8113199012f34c419176..776d280f34afad515594a873acf075acf0438304 100644
--- a/drivers/media/usb/uvc/uvc_metadata.c
+++ b/drivers/media/usb/uvc/uvc_metadata.c
@@ -10,6 +10,7 @@
#include <linux/list.h>
#include <linux/module.h>
#include <linux/usb.h>
+#include <linux/usb/uvc.h>
#include <linux/videodev2.h>
#include <media/v4l2-ioctl.h>
@@ -187,11 +188,64 @@ static const struct v4l2_file_operations uvc_meta_fops = {
.mmap = vb2_fop_mmap,
};
+static const u8 uvc_msxu_guid[16] = UVC_GUID_MSXU_1_5;
+
+#define MSXU_CONTROL_METADATA 0x9
+static int uvc_enable_msxu(struct uvc_device *dev)
+{
+ u32 *data __free(kfree) = NULL;
+ struct uvc_entity *entity;
+
+ list_for_each_entry(entity, &dev->entities, list) {
+ int ret;
+
+ if (memcmp(entity->guid, uvc_msxu_guid, sizeof(entity->guid)))
+ continue;
+
+ if (!data)
+ data = kmalloc(sizeof(*data), GFP_KERNEL);
+ if (!data)
+ return -ENOMEM;
+
+ ret = uvc_query_ctrl(dev, UVC_GET_CUR, entity->id,
+ dev->intfnum, MSXU_CONTROL_METADATA,
+ data, sizeof(*data));
+ if (ret)
+ continue;
+
+ if (*data) {
+ dev->quirks |= UVC_QUIRK_MSXU_META;
+ return 0;
+ }
+
+ ret = uvc_query_ctrl(dev, UVC_GET_MAX, entity->id,
+ dev->intfnum, MSXU_CONTROL_METADATA,
+ data, sizeof(*data));
+ if (ret || !*data)
+ continue;
+
+ ret = uvc_query_ctrl(dev, UVC_SET_CUR, entity->id,
+ dev->intfnum, MSXU_CONTROL_METADATA,
+ data, sizeof(*data));
+ if (!ret) {
+ dev->quirks |= UVC_QUIRK_MSXU_META;
+ return 0;
+ }
+ }
+
+ return 0;
+}
+
int uvc_meta_register(struct uvc_streaming *stream)
{
struct uvc_device *dev = stream->dev;
struct video_device *vdev = &stream->meta.vdev;
struct uvc_video_queue *queue = &stream->meta.queue;
+ int ret;
+
+ ret = uvc_enable_msxu(dev);
+ if (ret)
+ return ret;
stream->meta.format = V4L2_META_FMT_UVC;
diff --git a/include/linux/usb/uvc.h b/include/linux/usb/uvc.h
index bce95153e5a65613a710d7316fc17cf5462b5bce..ee19e9f915b8370c333c426dc1ee4202c7b75c5b 100644
--- a/include/linux/usb/uvc.h
+++ b/include/linux/usb/uvc.h
@@ -29,6 +29,9 @@
#define UVC_GUID_EXT_GPIO_CONTROLLER \
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03}
+#define UVC_GUID_MSXU_1_5 \
+ {0xdc, 0x95, 0x3f, 0x0f, 0x32, 0x26, 0x4e, 0x4c, \
+ 0x92, 0xc9, 0xa0, 0x47, 0x82, 0xf4, 0x3b, 0xc8}
#define UVC_GUID_FORMAT_MJPEG \
{ 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \
--
2.49.0.504.g3bcea36a83-goog
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [PATCH v5 0/4] media: uvcvideo: Introduce V4L2_META_FMT_UVC_MSXU_1_5 + other meta fixes
2025-04-04 6:37 [PATCH v5 0/4] media: uvcvideo: Introduce V4L2_META_FMT_UVC_MSXU_1_5 + other meta fixes Ricardo Ribalda
` (3 preceding siblings ...)
2025-04-04 6:37 ` [PATCH v5 4/4] media: uvcvideo: Auto-set UVC_QUIRK_MSXU_META Ricardo Ribalda
@ 2025-05-05 9:06 ` Ricardo Ribalda
4 siblings, 0 replies; 18+ messages in thread
From: Ricardo Ribalda @ 2025-05-05 9:06 UTC (permalink / raw)
To: Laurent Pinchart, Hans de Goede, Mauro Carvalho Chehab,
Guennadi Liakhovetski
Cc: linux-media, linux-kernel, stable
Hi Mauro, Hi Laurent, Hi Hans
Do you have any comments about this version?
Thanks!
On Fri, 4 Apr 2025 at 08:37, Ricardo Ribalda <ribalda@chromium.org> wrote:
>
> This series introduces a new metadata format for UVC cameras and adds a
> couple of improvements to the UVC metadata handling.
>
> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> ---
> Changes in v5:
> - Fix codestyle and kerneldoc warnings reported by media-ci
> - Link to v4: https://lore.kernel.org/r/20250403-uvc-meta-v4-0-877aa6475975@chromium.org
>
> Changes in v4:
> - Rename format to V4L2_META_FMT_UVC_MSXU_1_5 (Thanks Mauro)
> - Flag the new format with a quirk.
> - Autodetect MSXU devices.
> - Link to v3: https://lore.kernel.org/linux-media/20250313-uvc-metadata-v3-0-c467af869c60@chromium.org/
>
> Changes in v3:
> - Fix doc syntax errors.
> - Link to v2: https://lore.kernel.org/r/20250306-uvc-metadata-v2-0-7e939857cad5@chromium.org
>
> Changes in v2:
> - Add metadata invalid fix
> - Move doc note to a separate patch
> - Introuce V4L2_META_FMT_UVC_CUSTOM (thanks HdG!).
> - Link to v1: https://lore.kernel.org/r/20250226-uvc-metadata-v1-1-6cd6fe5ec2cb@chromium.org
>
> ---
> Ricardo Ribalda (4):
> media: uvcvideo: Do not mark valid metadata as invalid
> media: Documentation: Add note about UVCH length field
> media: uvcvideo: Introduce V4L2_META_FMT_UVC_MSXU_1_5
> media: uvcvideo: Auto-set UVC_QUIRK_MSXU_META
>
> .../userspace-api/media/v4l/meta-formats.rst | 1 +
> .../media/v4l/metafmt-uvc-msxu-1-5.rst | 23 +++++
> .../userspace-api/media/v4l/metafmt-uvc.rst | 4 +-
> MAINTAINERS | 1 +
> drivers/media/usb/uvc/uvc_metadata.c | 97 ++++++++++++++++++++--
> drivers/media/usb/uvc/uvc_video.c | 12 +--
> drivers/media/usb/uvc/uvcvideo.h | 1 +
> drivers/media/v4l2-core/v4l2-ioctl.c | 1 +
> include/linux/usb/uvc.h | 3 +
> include/uapi/linux/videodev2.h | 1 +
> 10 files changed, 131 insertions(+), 13 deletions(-)
> ---
> base-commit: 4e82c87058f45e79eeaa4d5bcc3b38dd3dce7209
> change-id: 20250403-uvc-meta-e556773d12ae
>
> Best regards,
> --
> Ricardo Ribalda <ribalda@chromium.org>
>
--
Ricardo Ribalda
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v5 1/4] media: uvcvideo: Do not mark valid metadata as invalid
2025-04-04 6:37 ` [PATCH v5 1/4] media: uvcvideo: Do not mark valid metadata as invalid Ricardo Ribalda
@ 2025-05-26 13:12 ` Hans de Goede
2025-05-26 13:46 ` Laurent Pinchart
1 sibling, 0 replies; 18+ messages in thread
From: Hans de Goede @ 2025-05-26 13:12 UTC (permalink / raw)
To: Ricardo Ribalda, Laurent Pinchart, Mauro Carvalho Chehab,
Guennadi Liakhovetski
Cc: linux-media, linux-kernel, stable
Hi,
On 4-Apr-25 08:37, Ricardo Ribalda wrote:
> Currently, the driver performs a length check of the metadata buffer
> before the actual metadata size is known and before the metadata is
> decided to be copied. This results in valid metadata buffers being
> incorrectly marked as invalid.
>
> Move the length check to occur after the metadata size is determined and
> is decided to be copied.
>
> Cc: stable@vger.kernel.org
> Fixes: 088ead255245 ("media: uvcvideo: Add a metadata device node")
> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
Thanks, patch looks good to me:
Reviewed-by: Hans de Goede <hansg@kernel.org>
Regards,
Hans
> ---
> drivers/media/usb/uvc/uvc_video.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
> index e3567aeb0007c1f0a766f331e4e744359e95a863..b113297dac61f1b2eecd72c36ea61ef2c1e7d28a 100644
> --- a/drivers/media/usb/uvc/uvc_video.c
> +++ b/drivers/media/usb/uvc/uvc_video.c
> @@ -1433,12 +1433,6 @@ static void uvc_video_decode_meta(struct uvc_streaming *stream,
> if (!meta_buf || length == 2)
> return;
>
> - if (meta_buf->length - meta_buf->bytesused <
> - length + sizeof(meta->ns) + sizeof(meta->sof)) {
> - meta_buf->error = 1;
> - return;
> - }
> -
> has_pts = mem[1] & UVC_STREAM_PTS;
> has_scr = mem[1] & UVC_STREAM_SCR;
>
> @@ -1459,6 +1453,12 @@ static void uvc_video_decode_meta(struct uvc_streaming *stream,
> !memcmp(scr, stream->clock.last_scr, 6)))
> return;
>
> + if (meta_buf->length - meta_buf->bytesused <
> + length + sizeof(meta->ns) + sizeof(meta->sof)) {
> + meta_buf->error = 1;
> + return;
> + }
> +
> meta = (struct uvc_meta_buf *)((u8 *)meta_buf->mem + meta_buf->bytesused);
> local_irq_save(flags);
> time = uvc_video_get_time();
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v5 2/4] media: Documentation: Add note about UVCH length field
2025-04-04 6:37 ` [PATCH v5 2/4] media: Documentation: Add note about UVCH length field Ricardo Ribalda
@ 2025-05-26 13:12 ` Hans de Goede
2025-05-26 13:49 ` Laurent Pinchart
1 sibling, 0 replies; 18+ messages in thread
From: Hans de Goede @ 2025-05-26 13:12 UTC (permalink / raw)
To: Ricardo Ribalda, Laurent Pinchart, Mauro Carvalho Chehab,
Guennadi Liakhovetski
Cc: linux-media, linux-kernel
Hi,
On 4-Apr-25 08:37, Ricardo Ribalda wrote:
> The documentation currently describes the UVC length field as the "length
> of the rest of the block", which can be misleading. The driver limits the
> data copied to a maximum of 12 bytes.
>
> This change adds a clarifying sentence to the documentation to make this
> restriction explicit.
>
> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
Thanks, patch looks good to me:
Reviewed-by: Hans de Goede <hansg@kernel.org>
Regards,
Hans
> ---
> Documentation/userspace-api/media/v4l/metafmt-uvc.rst | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/userspace-api/media/v4l/metafmt-uvc.rst b/Documentation/userspace-api/media/v4l/metafmt-uvc.rst
> index 784346d14bbdbf28348262084d5b0646d30bd1da..42599875331c0066cf529153caccb731148023b9 100644
> --- a/Documentation/userspace-api/media/v4l/metafmt-uvc.rst
> +++ b/Documentation/userspace-api/media/v4l/metafmt-uvc.rst
> @@ -44,7 +44,9 @@ Each individual block contains the following fields:
> them
> * - :cspan:`1` *The rest is an exact copy of the UVC payload header:*
> * - __u8 length;
> - - length of the rest of the block, including this field
> + - length of the rest of the block, including this field. Please note that
> + regardless of the this value, for V4L2_META_FMT_UVC the kernel will
> + never copy more than 2-12 bytes.
> * - __u8 flags;
> - Flags, indicating presence of other standard UVC fields
> * - __u8 buf[];
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v5 3/4] media: uvcvideo: Introduce V4L2_META_FMT_UVC_MSXU_1_5
2025-04-04 6:37 ` [PATCH v5 3/4] media: uvcvideo: Introduce V4L2_META_FMT_UVC_MSXU_1_5 Ricardo Ribalda
@ 2025-05-26 13:16 ` Hans de Goede
2025-05-26 13:53 ` Laurent Pinchart
1 sibling, 0 replies; 18+ messages in thread
From: Hans de Goede @ 2025-05-26 13:16 UTC (permalink / raw)
To: Ricardo Ribalda, Laurent Pinchart, Mauro Carvalho Chehab,
Guennadi Liakhovetski
Cc: linux-media, linux-kernel
Hi,
On 4-Apr-25 08:37, Ricardo Ribalda wrote:
> The UVC driver provides two metadata types V4L2_META_FMT_UVC, and
> V4L2_META_FMT_D4XX. The only difference between the two of them is that
> V4L2_META_FMT_UVC only copies PTS, SCR, size and flags, and
> V4L2_META_FMT_D4XX copies the whole metadata section.
>
> Now we only enable V4L2_META_FMT_D4XX for the Intel D4xx family of
> devices, but it is useful to have the whole metadata section for any
> device where vendors include other metadata, such as the one described by
> Microsoft:
> https://learn.microsoft.com/en-us/windows-hardware/drivers/stream/mf-capture-metadata
>
> This patch introduces a new format V4L2_META_FMT_UVC_MSXU_1_5, that is
> identical to V4L2_META_FMT_D4XX.
>
> For now, flag this format with a new quirk.
>
> Suggested-by: Hans de Goede <hdegoede@redhat.com>
> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
Thanks, patch looks good to me:
Reviewed-by: Hans de Goede <hansg@kernel.org>
Regards,
Hans
> ---
> .../userspace-api/media/v4l/meta-formats.rst | 1 +
> .../media/v4l/metafmt-uvc-msxu-1-5.rst | 23 ++++++++++++
> MAINTAINERS | 1 +
> drivers/media/usb/uvc/uvc_metadata.c | 43 +++++++++++++++++++---
> drivers/media/usb/uvc/uvcvideo.h | 1 +
> drivers/media/v4l2-core/v4l2-ioctl.c | 1 +
> include/uapi/linux/videodev2.h | 1 +
> 7 files changed, 65 insertions(+), 6 deletions(-)
>
> diff --git a/Documentation/userspace-api/media/v4l/meta-formats.rst b/Documentation/userspace-api/media/v4l/meta-formats.rst
> index 86ffb3bc8ade2e0c563dd84441572ecea1a571a6..4de0d094e0702068be0c59154458c9dfecbfe28d 100644
> --- a/Documentation/userspace-api/media/v4l/meta-formats.rst
> +++ b/Documentation/userspace-api/media/v4l/meta-formats.rst
> @@ -19,6 +19,7 @@ These formats are used for the :ref:`metadata` interface only.
> metafmt-pisp-fe
> metafmt-rkisp1
> metafmt-uvc
> + metafmt-uvc-msxu-1-5
> metafmt-vivid
> metafmt-vsp1-hgo
> metafmt-vsp1-hgt
> diff --git a/Documentation/userspace-api/media/v4l/metafmt-uvc-msxu-1-5.rst b/Documentation/userspace-api/media/v4l/metafmt-uvc-msxu-1-5.rst
> new file mode 100644
> index 0000000000000000000000000000000000000000..e6f95a88c0ff061df0b066b12cefc30f946b60aa
> --- /dev/null
> +++ b/Documentation/userspace-api/media/v4l/metafmt-uvc-msxu-1-5.rst
> @@ -0,0 +1,23 @@
> +.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
> +
> +.. _v4l2-meta-fmt-uvc-msxu-1-5:
> +
> +***********************************
> +V4L2_META_FMT_UVC_MSXU_1_5 ('UVCM')
> +***********************************
> +
> +Microsoft(R)'s UVC Payload Metadata.
> +
> +
> +Description
> +===========
> +
> +V4L2_META_FMT_UVC_MSXU_1_5 buffers follow the metadata buffer layout of
> +V4L2_META_FMT_UVC with the only difference that it includes all the UVC
> +metadata, not just the first 2-12 bytes.
> +
> +For more details check the documentation from Microsoft(R) [1].
> +
> +.. _1:
> +
> +[1] https://docs.microsoft.com/en-us/windows-hardware/drivers/stream/uvc-extensions-1-5
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 306b1384eb6d4cb7a310ada44605eaeb88cc732f..a07ed31ab057b98cf801d919b5bbec5ee334c9ac 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -25059,6 +25059,7 @@ S: Maintained
> W: http://www.ideasonboard.org/uvc/
> T: git git://linuxtv.org/media.git
> F: Documentation/userspace-api/media/drivers/uvcvideo.rst
> +F: Documentation/userspace-api/media/v4l/metafmt-uvc-msxu-1-5.rst
> F: Documentation/userspace-api/media/v4l/metafmt-uvc.rst
> F: drivers/media/common/uvc.c
> F: drivers/media/usb/uvc/
> diff --git a/drivers/media/usb/uvc/uvc_metadata.c b/drivers/media/usb/uvc/uvc_metadata.c
> index 82de7781f5b6b70c5ba16bcba9e0741231231904..fe2678fc795d7fd5a64e8113199012f34c419176 100644
> --- a/drivers/media/usb/uvc/uvc_metadata.c
> +++ b/drivers/media/usb/uvc/uvc_metadata.c
> @@ -63,15 +63,21 @@ static int uvc_meta_v4l2_try_format(struct file *file, void *fh,
> struct uvc_streaming *stream = video_get_drvdata(vfh->vdev);
> struct uvc_device *dev = stream->dev;
> struct v4l2_meta_format *fmt = &format->fmt.meta;
> - u32 fmeta = fmt->dataformat;
> + u32 fmeta;
> +
> + if (fmt->dataformat == dev->info->meta_format)
> + fmeta = dev->info->meta_format;
> + else if (fmt->dataformat == V4L2_META_FMT_UVC_MSXU_1_5)
> + fmeta = V4L2_META_FMT_UVC_MSXU_1_5;
> + else
> + fmeta = V4L2_META_FMT_UVC;
>
> if (format->type != vfh->vdev->queue->type)
> return -EINVAL;
>
> memset(fmt, 0, sizeof(*fmt));
>
> - fmt->dataformat = fmeta == dev->info->meta_format
> - ? fmeta : V4L2_META_FMT_UVC;
> + fmt->dataformat = fmeta;
> fmt->buffersize = UVC_METADATA_BUF_SIZE;
>
> return 0;
> @@ -106,6 +112,27 @@ static int uvc_meta_v4l2_set_format(struct file *file, void *fh,
> return ret;
> }
>
> +static u32 uvc_meta_idx_to_fmeta(struct uvc_device *dev, u32 index)
> +{
> + switch (index) {
> + case 0:
> + return V4L2_META_FMT_UVC;
> + case 1:
> + if (dev->info->meta_format)
> + return dev->info->meta_format;
> + if (dev->quirks & UVC_QUIRK_MSXU_META)
> + return V4L2_META_FMT_UVC_MSXU_1_5;
> + return 0;
> + case 2:
> + if (dev->info->meta_format &&
> + dev->quirks & UVC_QUIRK_MSXU_META)
> + return V4L2_META_FMT_UVC_MSXU_1_5;
> + return 0;
> + }
> +
> + return 0;
> +}
> +
> static int uvc_meta_v4l2_enum_formats(struct file *file, void *fh,
> struct v4l2_fmtdesc *fdesc)
> {
> @@ -113,16 +140,20 @@ static int uvc_meta_v4l2_enum_formats(struct file *file, void *fh,
> struct uvc_streaming *stream = video_get_drvdata(vfh->vdev);
> struct uvc_device *dev = stream->dev;
> u32 index = fdesc->index;
> + u32 fmeta;
> +
> + if (fdesc->type != vfh->vdev->queue->type)
> + return -EINVAL;
>
> - if (fdesc->type != vfh->vdev->queue->type ||
> - index > 1U || (index && !dev->info->meta_format))
> + fmeta = uvc_meta_idx_to_fmeta(dev, fdesc->index);
> + if (!fmeta)
> return -EINVAL;
>
> memset(fdesc, 0, sizeof(*fdesc));
>
> fdesc->type = vfh->vdev->queue->type;
> fdesc->index = index;
> - fdesc->pixelformat = index ? dev->info->meta_format : V4L2_META_FMT_UVC;
> + fdesc->pixelformat = fmeta;
>
> return 0;
> }
> diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
> index b4ee701835fc016474d2cd2a0b67b2aa915c1c60..123446683e22589f23b5228a00240e54f00ae6f1 100644
> --- a/drivers/media/usb/uvc/uvcvideo.h
> +++ b/drivers/media/usb/uvc/uvcvideo.h
> @@ -77,6 +77,7 @@
> #define UVC_QUIRK_DISABLE_AUTOSUSPEND 0x00008000
> #define UVC_QUIRK_INVALID_DEVICE_SOF 0x00010000
> #define UVC_QUIRK_MJPEG_NO_EOF 0x00020000
> +#define UVC_QUIRK_MSXU_META 0x00040000
>
> /* Format flags */
> #define UVC_FMT_FLAG_COMPRESSED 0x00000001
> diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
> index a16fb44c7246e35f3710306fde5dfc15329b4d95..12f1232e5ca3acdefede8f9751f9e7191eeae58b 100644
> --- a/drivers/media/v4l2-core/v4l2-ioctl.c
> +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
> @@ -1457,6 +1457,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
> case V4L2_META_FMT_VSP1_HGO: descr = "R-Car VSP1 1-D Histogram"; break;
> case V4L2_META_FMT_VSP1_HGT: descr = "R-Car VSP1 2-D Histogram"; break;
> case V4L2_META_FMT_UVC: descr = "UVC Payload Header Metadata"; break;
> + case V4L2_META_FMT_UVC_MSXU_1_5: descr = "UVC MSXU Metadata"; break;
> case V4L2_META_FMT_D4XX: descr = "Intel D4xx UVC Metadata"; break;
> case V4L2_META_FMT_VIVID: descr = "Vivid Metadata"; break;
> case V4L2_META_FMT_RK_ISP1_PARAMS: descr = "Rockchip ISP1 3A Parameters"; break;
> diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
> index c8cb2796130f8d1b864d669267d2b31f73b839aa..0cf6885a5dc8752326bd10a893d5d09d47993c21 100644
> --- a/include/uapi/linux/videodev2.h
> +++ b/include/uapi/linux/videodev2.h
> @@ -851,6 +851,7 @@ struct v4l2_pix_format {
> #define V4L2_META_FMT_VSP1_HGT v4l2_fourcc('V', 'S', 'P', 'T') /* R-Car VSP1 2-D Histogram */
> #define V4L2_META_FMT_UVC v4l2_fourcc('U', 'V', 'C', 'H') /* UVC Payload Header metadata */
> #define V4L2_META_FMT_D4XX v4l2_fourcc('D', '4', 'X', 'X') /* D4XX Payload Header metadata */
> +#define V4L2_META_FMT_UVC_MSXU_1_5 v4l2_fourcc('U', 'V', 'C', 'M') /* UVC MSXU metadata */
> #define V4L2_META_FMT_VIVID v4l2_fourcc('V', 'I', 'V', 'D') /* Vivid Metadata */
>
> /* Vendor specific - used for RK_ISP1 camera sub-system */
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v5 4/4] media: uvcvideo: Auto-set UVC_QUIRK_MSXU_META
2025-04-04 6:37 ` [PATCH v5 4/4] media: uvcvideo: Auto-set UVC_QUIRK_MSXU_META Ricardo Ribalda
@ 2025-05-26 13:19 ` Hans de Goede
2025-05-26 14:02 ` Laurent Pinchart
1 sibling, 0 replies; 18+ messages in thread
From: Hans de Goede @ 2025-05-26 13:19 UTC (permalink / raw)
To: Ricardo Ribalda, Laurent Pinchart, Mauro Carvalho Chehab,
Guennadi Liakhovetski
Cc: linux-media, linux-kernel
Hi,
On 4-Apr-25 08:37, Ricardo Ribalda wrote:
> If the camera supports the MSXU_CONTROL_METADATA control, auto set the
> MSXU_META quirk.
>
> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
Thanks, patch looks good to me:
Reviewed-by: Hans de Goede <hansg@kernel.org>
Regards,
Hans
> ---
> drivers/media/usb/uvc/uvc_metadata.c | 54 ++++++++++++++++++++++++++++++++++++
> include/linux/usb/uvc.h | 3 ++
> 2 files changed, 57 insertions(+)
>
> diff --git a/drivers/media/usb/uvc/uvc_metadata.c b/drivers/media/usb/uvc/uvc_metadata.c
> index fe2678fc795d7fd5a64e8113199012f34c419176..776d280f34afad515594a873acf075acf0438304 100644
> --- a/drivers/media/usb/uvc/uvc_metadata.c
> +++ b/drivers/media/usb/uvc/uvc_metadata.c
> @@ -10,6 +10,7 @@
> #include <linux/list.h>
> #include <linux/module.h>
> #include <linux/usb.h>
> +#include <linux/usb/uvc.h>
> #include <linux/videodev2.h>
>
> #include <media/v4l2-ioctl.h>
> @@ -187,11 +188,64 @@ static const struct v4l2_file_operations uvc_meta_fops = {
> .mmap = vb2_fop_mmap,
> };
>
> +static const u8 uvc_msxu_guid[16] = UVC_GUID_MSXU_1_5;
> +
> +#define MSXU_CONTROL_METADATA 0x9
> +static int uvc_enable_msxu(struct uvc_device *dev)
> +{
> + u32 *data __free(kfree) = NULL;
> + struct uvc_entity *entity;
> +
> + list_for_each_entry(entity, &dev->entities, list) {
> + int ret;
> +
> + if (memcmp(entity->guid, uvc_msxu_guid, sizeof(entity->guid)))
> + continue;
> +
> + if (!data)
> + data = kmalloc(sizeof(*data), GFP_KERNEL);
> + if (!data)
> + return -ENOMEM;
> +
> + ret = uvc_query_ctrl(dev, UVC_GET_CUR, entity->id,
> + dev->intfnum, MSXU_CONTROL_METADATA,
> + data, sizeof(*data));
> + if (ret)
> + continue;
> +
> + if (*data) {
> + dev->quirks |= UVC_QUIRK_MSXU_META;
> + return 0;
> + }
> +
> + ret = uvc_query_ctrl(dev, UVC_GET_MAX, entity->id,
> + dev->intfnum, MSXU_CONTROL_METADATA,
> + data, sizeof(*data));
> + if (ret || !*data)
> + continue;
> +
> + ret = uvc_query_ctrl(dev, UVC_SET_CUR, entity->id,
> + dev->intfnum, MSXU_CONTROL_METADATA,
> + data, sizeof(*data));
> + if (!ret) {
> + dev->quirks |= UVC_QUIRK_MSXU_META;
> + return 0;
> + }
> + }
> +
> + return 0;
> +}
> +
> int uvc_meta_register(struct uvc_streaming *stream)
> {
> struct uvc_device *dev = stream->dev;
> struct video_device *vdev = &stream->meta.vdev;
> struct uvc_video_queue *queue = &stream->meta.queue;
> + int ret;
> +
> + ret = uvc_enable_msxu(dev);
> + if (ret)
> + return ret;
>
> stream->meta.format = V4L2_META_FMT_UVC;
>
> diff --git a/include/linux/usb/uvc.h b/include/linux/usb/uvc.h
> index bce95153e5a65613a710d7316fc17cf5462b5bce..ee19e9f915b8370c333c426dc1ee4202c7b75c5b 100644
> --- a/include/linux/usb/uvc.h
> +++ b/include/linux/usb/uvc.h
> @@ -29,6 +29,9 @@
> #define UVC_GUID_EXT_GPIO_CONTROLLER \
> {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
> 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03}
> +#define UVC_GUID_MSXU_1_5 \
> + {0xdc, 0x95, 0x3f, 0x0f, 0x32, 0x26, 0x4e, 0x4c, \
> + 0x92, 0xc9, 0xa0, 0x47, 0x82, 0xf4, 0x3b, 0xc8}
>
> #define UVC_GUID_FORMAT_MJPEG \
> { 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v5 1/4] media: uvcvideo: Do not mark valid metadata as invalid
2025-04-04 6:37 ` [PATCH v5 1/4] media: uvcvideo: Do not mark valid metadata as invalid Ricardo Ribalda
2025-05-26 13:12 ` Hans de Goede
@ 2025-05-26 13:46 ` Laurent Pinchart
1 sibling, 0 replies; 18+ messages in thread
From: Laurent Pinchart @ 2025-05-26 13:46 UTC (permalink / raw)
To: Ricardo Ribalda
Cc: Hans de Goede, Mauro Carvalho Chehab, Guennadi Liakhovetski,
linux-media, linux-kernel, stable
Hi Ricardo,
Thank you for the patch.
On Fri, Apr 04, 2025 at 06:37:34AM +0000, Ricardo Ribalda wrote:
> Currently, the driver performs a length check of the metadata buffer
> before the actual metadata size is known and before the metadata is
> decided to be copied. This results in valid metadata buffers being
> incorrectly marked as invalid.
>
> Move the length check to occur after the metadata size is determined and
> is decided to be copied.
>
> Cc: stable@vger.kernel.org
> Fixes: 088ead255245 ("media: uvcvideo: Add a metadata device node")
> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
> drivers/media/usb/uvc/uvc_video.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
> index e3567aeb0007c1f0a766f331e4e744359e95a863..b113297dac61f1b2eecd72c36ea61ef2c1e7d28a 100644
> --- a/drivers/media/usb/uvc/uvc_video.c
> +++ b/drivers/media/usb/uvc/uvc_video.c
> @@ -1433,12 +1433,6 @@ static void uvc_video_decode_meta(struct uvc_streaming *stream,
> if (!meta_buf || length == 2)
> return;
>
> - if (meta_buf->length - meta_buf->bytesused <
> - length + sizeof(meta->ns) + sizeof(meta->sof)) {
> - meta_buf->error = 1;
> - return;
> - }
> -
> has_pts = mem[1] & UVC_STREAM_PTS;
> has_scr = mem[1] & UVC_STREAM_SCR;
>
> @@ -1459,6 +1453,12 @@ static void uvc_video_decode_meta(struct uvc_streaming *stream,
> !memcmp(scr, stream->clock.last_scr, 6)))
> return;
>
> + if (meta_buf->length - meta_buf->bytesused <
> + length + sizeof(meta->ns) + sizeof(meta->sof)) {
> + meta_buf->error = 1;
> + return;
> + }
> +
> meta = (struct uvc_meta_buf *)((u8 *)meta_buf->mem + meta_buf->bytesused);
> local_irq_save(flags);
> time = uvc_video_get_time();
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v5 2/4] media: Documentation: Add note about UVCH length field
2025-04-04 6:37 ` [PATCH v5 2/4] media: Documentation: Add note about UVCH length field Ricardo Ribalda
2025-05-26 13:12 ` Hans de Goede
@ 2025-05-26 13:49 ` Laurent Pinchart
2025-05-26 14:04 ` Ricardo Ribalda
1 sibling, 1 reply; 18+ messages in thread
From: Laurent Pinchart @ 2025-05-26 13:49 UTC (permalink / raw)
To: Ricardo Ribalda
Cc: Hans de Goede, Mauro Carvalho Chehab, Guennadi Liakhovetski,
linux-media, linux-kernel
Hi Ricardo,
On Fri, Apr 04, 2025 at 06:37:35AM +0000, Ricardo Ribalda wrote:
> The documentation currently describes the UVC length field as the "length
> of the rest of the block", which can be misleading. The driver limits the
> data copied to a maximum of 12 bytes.
>
> This change adds a clarifying sentence to the documentation to make this
> restriction explicit.
>
> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> ---
> Documentation/userspace-api/media/v4l/metafmt-uvc.rst | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/userspace-api/media/v4l/metafmt-uvc.rst b/Documentation/userspace-api/media/v4l/metafmt-uvc.rst
> index 784346d14bbdbf28348262084d5b0646d30bd1da..42599875331c0066cf529153caccb731148023b9 100644
> --- a/Documentation/userspace-api/media/v4l/metafmt-uvc.rst
> +++ b/Documentation/userspace-api/media/v4l/metafmt-uvc.rst
> @@ -44,7 +44,9 @@ Each individual block contains the following fields:
> them
> * - :cspan:`1` *The rest is an exact copy of the UVC payload header:*
> * - __u8 length;
> - - length of the rest of the block, including this field
> + - length of the rest of the block, including this field. Please note that
> + regardless of the this value, for V4L2_META_FMT_UVC the kernel will
"the this value" looks like a typo.
> + never copy more than 2-12 bytes.
Are you saying here that length can be larger than 12, but only up to 12
bytes will be copied (when both SCR and PTS are present) ? If that's the
case, it would be better to fix the driver to clamp the length value to
the number of bytes actually present in the buffer.
> * - __u8 flags;
> - Flags, indicating presence of other standard UVC fields
> * - __u8 buf[];
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v5 3/4] media: uvcvideo: Introduce V4L2_META_FMT_UVC_MSXU_1_5
2025-04-04 6:37 ` [PATCH v5 3/4] media: uvcvideo: Introduce V4L2_META_FMT_UVC_MSXU_1_5 Ricardo Ribalda
2025-05-26 13:16 ` Hans de Goede
@ 2025-05-26 13:53 ` Laurent Pinchart
1 sibling, 0 replies; 18+ messages in thread
From: Laurent Pinchart @ 2025-05-26 13:53 UTC (permalink / raw)
To: Ricardo Ribalda
Cc: Hans de Goede, Mauro Carvalho Chehab, Guennadi Liakhovetski,
linux-media, linux-kernel
On Fri, Apr 04, 2025 at 06:37:36AM +0000, Ricardo Ribalda wrote:
> The UVC driver provides two metadata types V4L2_META_FMT_UVC, and
> V4L2_META_FMT_D4XX. The only difference between the two of them is that
> V4L2_META_FMT_UVC only copies PTS, SCR, size and flags, and
> V4L2_META_FMT_D4XX copies the whole metadata section.
>
> Now we only enable V4L2_META_FMT_D4XX for the Intel D4xx family of
> devices, but it is useful to have the whole metadata section for any
> device where vendors include other metadata, such as the one described by
> Microsoft:
> https://learn.microsoft.com/en-us/windows-hardware/drivers/stream/mf-capture-metadata
>
> This patch introduces a new format V4L2_META_FMT_UVC_MSXU_1_5, that is
> identical to V4L2_META_FMT_D4XX.
>
> For now, flag this format with a new quirk.
Why can't you set dev->info->meta_format to V4L2_META_FMT_UVC_MSXU_1_5
for the devices that support this, instead of using a quirk ? This
should be explained in the commit message.
> Suggested-by: Hans de Goede <hdegoede@redhat.com>
> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> ---
> .../userspace-api/media/v4l/meta-formats.rst | 1 +
> .../media/v4l/metafmt-uvc-msxu-1-5.rst | 23 ++++++++++++
> MAINTAINERS | 1 +
> drivers/media/usb/uvc/uvc_metadata.c | 43 +++++++++++++++++++---
> drivers/media/usb/uvc/uvcvideo.h | 1 +
> drivers/media/v4l2-core/v4l2-ioctl.c | 1 +
> include/uapi/linux/videodev2.h | 1 +
> 7 files changed, 65 insertions(+), 6 deletions(-)
>
> diff --git a/Documentation/userspace-api/media/v4l/meta-formats.rst b/Documentation/userspace-api/media/v4l/meta-formats.rst
> index 86ffb3bc8ade2e0c563dd84441572ecea1a571a6..4de0d094e0702068be0c59154458c9dfecbfe28d 100644
> --- a/Documentation/userspace-api/media/v4l/meta-formats.rst
> +++ b/Documentation/userspace-api/media/v4l/meta-formats.rst
> @@ -19,6 +19,7 @@ These formats are used for the :ref:`metadata` interface only.
> metafmt-pisp-fe
> metafmt-rkisp1
> metafmt-uvc
> + metafmt-uvc-msxu-1-5
> metafmt-vivid
> metafmt-vsp1-hgo
> metafmt-vsp1-hgt
> diff --git a/Documentation/userspace-api/media/v4l/metafmt-uvc-msxu-1-5.rst b/Documentation/userspace-api/media/v4l/metafmt-uvc-msxu-1-5.rst
> new file mode 100644
> index 0000000000000000000000000000000000000000..e6f95a88c0ff061df0b066b12cefc30f946b60aa
> --- /dev/null
> +++ b/Documentation/userspace-api/media/v4l/metafmt-uvc-msxu-1-5.rst
> @@ -0,0 +1,23 @@
> +.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
> +
> +.. _v4l2-meta-fmt-uvc-msxu-1-5:
> +
> +***********************************
> +V4L2_META_FMT_UVC_MSXU_1_5 ('UVCM')
> +***********************************
> +
> +Microsoft(R)'s UVC Payload Metadata.
> +
> +
> +Description
> +===========
> +
> +V4L2_META_FMT_UVC_MSXU_1_5 buffers follow the metadata buffer layout of
> +V4L2_META_FMT_UVC with the only difference that it includes all the UVC
> +metadata, not just the first 2-12 bytes.
This needs some more details. "all the UVC metadata" is too vague, you
should explain that the metadata format follows the MS specification.
> +
> +For more details check the documentation from Microsoft(R) [1].
> +
> +.. _1:
> +
> +[1] https://docs.microsoft.com/en-us/windows-hardware/drivers/stream/uvc-extensions-1-5
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 306b1384eb6d4cb7a310ada44605eaeb88cc732f..a07ed31ab057b98cf801d919b5bbec5ee334c9ac 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -25059,6 +25059,7 @@ S: Maintained
> W: http://www.ideasonboard.org/uvc/
> T: git git://linuxtv.org/media.git
> F: Documentation/userspace-api/media/drivers/uvcvideo.rst
> +F: Documentation/userspace-api/media/v4l/metafmt-uvc-msxu-1-5.rst
> F: Documentation/userspace-api/media/v4l/metafmt-uvc.rst
> F: drivers/media/common/uvc.c
> F: drivers/media/usb/uvc/
> diff --git a/drivers/media/usb/uvc/uvc_metadata.c b/drivers/media/usb/uvc/uvc_metadata.c
> index 82de7781f5b6b70c5ba16bcba9e0741231231904..fe2678fc795d7fd5a64e8113199012f34c419176 100644
> --- a/drivers/media/usb/uvc/uvc_metadata.c
> +++ b/drivers/media/usb/uvc/uvc_metadata.c
> @@ -63,15 +63,21 @@ static int uvc_meta_v4l2_try_format(struct file *file, void *fh,
> struct uvc_streaming *stream = video_get_drvdata(vfh->vdev);
> struct uvc_device *dev = stream->dev;
> struct v4l2_meta_format *fmt = &format->fmt.meta;
> - u32 fmeta = fmt->dataformat;
> + u32 fmeta;
> +
> + if (fmt->dataformat == dev->info->meta_format)
> + fmeta = dev->info->meta_format;
> + else if (fmt->dataformat == V4L2_META_FMT_UVC_MSXU_1_5)
> + fmeta = V4L2_META_FMT_UVC_MSXU_1_5;
Doesn't this accept V4L2_META_FMT_UVC_MSXU_1_5 regardless of the quirk ?
> + else
> + fmeta = V4L2_META_FMT_UVC;
>
> if (format->type != vfh->vdev->queue->type)
> return -EINVAL;
>
> memset(fmt, 0, sizeof(*fmt));
>
> - fmt->dataformat = fmeta == dev->info->meta_format
> - ? fmeta : V4L2_META_FMT_UVC;
> + fmt->dataformat = fmeta;
> fmt->buffersize = UVC_METADATA_BUF_SIZE;
>
> return 0;
> @@ -106,6 +112,27 @@ static int uvc_meta_v4l2_set_format(struct file *file, void *fh,
> return ret;
> }
>
> +static u32 uvc_meta_idx_to_fmeta(struct uvc_device *dev, u32 index)
> +{
> + switch (index) {
> + case 0:
> + return V4L2_META_FMT_UVC;
> + case 1:
> + if (dev->info->meta_format)
> + return dev->info->meta_format;
> + if (dev->quirks & UVC_QUIRK_MSXU_META)
> + return V4L2_META_FMT_UVC_MSXU_1_5;
> + return 0;
> + case 2:
> + if (dev->info->meta_format &&
> + dev->quirks & UVC_QUIRK_MSXU_META)
> + return V4L2_META_FMT_UVC_MSXU_1_5;
> + return 0;
> + }
> +
> + return 0;
> +}
> +
> static int uvc_meta_v4l2_enum_formats(struct file *file, void *fh,
> struct v4l2_fmtdesc *fdesc)
> {
> @@ -113,16 +140,20 @@ static int uvc_meta_v4l2_enum_formats(struct file *file, void *fh,
> struct uvc_streaming *stream = video_get_drvdata(vfh->vdev);
> struct uvc_device *dev = stream->dev;
> u32 index = fdesc->index;
> + u32 fmeta;
> +
> + if (fdesc->type != vfh->vdev->queue->type)
> + return -EINVAL;
>
> - if (fdesc->type != vfh->vdev->queue->type ||
> - index > 1U || (index && !dev->info->meta_format))
> + fmeta = uvc_meta_idx_to_fmeta(dev, fdesc->index);
> + if (!fmeta)
> return -EINVAL;
>
> memset(fdesc, 0, sizeof(*fdesc));
>
> fdesc->type = vfh->vdev->queue->type;
> fdesc->index = index;
> - fdesc->pixelformat = index ? dev->info->meta_format : V4L2_META_FMT_UVC;
> + fdesc->pixelformat = fmeta;
>
> return 0;
> }
> diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
> index b4ee701835fc016474d2cd2a0b67b2aa915c1c60..123446683e22589f23b5228a00240e54f00ae6f1 100644
> --- a/drivers/media/usb/uvc/uvcvideo.h
> +++ b/drivers/media/usb/uvc/uvcvideo.h
> @@ -77,6 +77,7 @@
> #define UVC_QUIRK_DISABLE_AUTOSUSPEND 0x00008000
> #define UVC_QUIRK_INVALID_DEVICE_SOF 0x00010000
> #define UVC_QUIRK_MJPEG_NO_EOF 0x00020000
> +#define UVC_QUIRK_MSXU_META 0x00040000
>
> /* Format flags */
> #define UVC_FMT_FLAG_COMPRESSED 0x00000001
> diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
> index a16fb44c7246e35f3710306fde5dfc15329b4d95..12f1232e5ca3acdefede8f9751f9e7191eeae58b 100644
> --- a/drivers/media/v4l2-core/v4l2-ioctl.c
> +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
> @@ -1457,6 +1457,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
> case V4L2_META_FMT_VSP1_HGO: descr = "R-Car VSP1 1-D Histogram"; break;
> case V4L2_META_FMT_VSP1_HGT: descr = "R-Car VSP1 2-D Histogram"; break;
> case V4L2_META_FMT_UVC: descr = "UVC Payload Header Metadata"; break;
> + case V4L2_META_FMT_UVC_MSXU_1_5: descr = "UVC MSXU Metadata"; break;
> case V4L2_META_FMT_D4XX: descr = "Intel D4xx UVC Metadata"; break;
> case V4L2_META_FMT_VIVID: descr = "Vivid Metadata"; break;
> case V4L2_META_FMT_RK_ISP1_PARAMS: descr = "Rockchip ISP1 3A Parameters"; break;
> diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
> index c8cb2796130f8d1b864d669267d2b31f73b839aa..0cf6885a5dc8752326bd10a893d5d09d47993c21 100644
> --- a/include/uapi/linux/videodev2.h
> +++ b/include/uapi/linux/videodev2.h
> @@ -851,6 +851,7 @@ struct v4l2_pix_format {
> #define V4L2_META_FMT_VSP1_HGT v4l2_fourcc('V', 'S', 'P', 'T') /* R-Car VSP1 2-D Histogram */
> #define V4L2_META_FMT_UVC v4l2_fourcc('U', 'V', 'C', 'H') /* UVC Payload Header metadata */
> #define V4L2_META_FMT_D4XX v4l2_fourcc('D', '4', 'X', 'X') /* D4XX Payload Header metadata */
> +#define V4L2_META_FMT_UVC_MSXU_1_5 v4l2_fourcc('U', 'V', 'C', 'M') /* UVC MSXU metadata */
> #define V4L2_META_FMT_VIVID v4l2_fourcc('V', 'I', 'V', 'D') /* Vivid Metadata */
>
> /* Vendor specific - used for RK_ISP1 camera sub-system */
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v5 4/4] media: uvcvideo: Auto-set UVC_QUIRK_MSXU_META
2025-04-04 6:37 ` [PATCH v5 4/4] media: uvcvideo: Auto-set UVC_QUIRK_MSXU_META Ricardo Ribalda
2025-05-26 13:19 ` Hans de Goede
@ 2025-05-26 14:02 ` Laurent Pinchart
2025-05-26 14:17 ` Ricardo Ribalda
1 sibling, 1 reply; 18+ messages in thread
From: Laurent Pinchart @ 2025-05-26 14:02 UTC (permalink / raw)
To: Ricardo Ribalda
Cc: Hans de Goede, Mauro Carvalho Chehab, Guennadi Liakhovetski,
linux-media, linux-kernel
Hi Ricardo,
Thank you for the patch.
On Fri, Apr 04, 2025 at 06:37:37AM +0000, Ricardo Ribalda wrote:
> If the camera supports the MSXU_CONTROL_METADATA control, auto set the
> MSXU_META quirk.
Ah, that's why you introduce a quirk in 3/4.
I would prefer if you could instead add a metadata format field in the
uvc_device structure (I'd put it right after the info field, and while
at it you could move the quirks field to that section too). The metadata
format would be initialized from dev->info (when available) or set to
the UVC format, and overridden when the MSXU is detected.
> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> ---
> drivers/media/usb/uvc/uvc_metadata.c | 54 ++++++++++++++++++++++++++++++++++++
> include/linux/usb/uvc.h | 3 ++
> 2 files changed, 57 insertions(+)
>
> diff --git a/drivers/media/usb/uvc/uvc_metadata.c b/drivers/media/usb/uvc/uvc_metadata.c
> index fe2678fc795d7fd5a64e8113199012f34c419176..776d280f34afad515594a873acf075acf0438304 100644
> --- a/drivers/media/usb/uvc/uvc_metadata.c
> +++ b/drivers/media/usb/uvc/uvc_metadata.c
> @@ -10,6 +10,7 @@
> #include <linux/list.h>
> #include <linux/module.h>
> #include <linux/usb.h>
> +#include <linux/usb/uvc.h>
> #include <linux/videodev2.h>
>
> #include <media/v4l2-ioctl.h>
> @@ -187,11 +188,64 @@ static const struct v4l2_file_operations uvc_meta_fops = {
> .mmap = vb2_fop_mmap,
> };
>
> +static const u8 uvc_msxu_guid[16] = UVC_GUID_MSXU_1_5;
> +
> +#define MSXU_CONTROL_METADATA 0x9
> +static int uvc_enable_msxu(struct uvc_device *dev)
uvc_meta_detect_msxu()
> +{
> + u32 *data __free(kfree) = NULL;
> + struct uvc_entity *entity;
> +
> + list_for_each_entry(entity, &dev->entities, list) {
> + int ret;
> +
> + if (memcmp(entity->guid, uvc_msxu_guid, sizeof(entity->guid)))
> + continue;
> +
> + if (!data)
> + data = kmalloc(sizeof(*data), GFP_KERNEL);
> + if (!data)
> + return -ENOMEM;
> +
A comment here to explain how the control operates would be useful.
Reading the code I assume that GET_MAX will indicate if the MS metadata
format is supported by reporting a value different than 0 (is it always
1, or can it take other values), and SET_CUR will enable metadata
generation. I suppose the first GET_CUR call catches the case where it
has already been enabled, are there also cameras where it can't be
disabled, and where SET_CUR would fail ?
> + ret = uvc_query_ctrl(dev, UVC_GET_CUR, entity->id,
> + dev->intfnum, MSXU_CONTROL_METADATA,
> + data, sizeof(*data));
> + if (ret)
> + continue;
Can there be multiple MSXU instances, or can you break here (and below)
?
> +
> + if (*data) {
> + dev->quirks |= UVC_QUIRK_MSXU_META;
> + return 0;
> + }
> +
> + ret = uvc_query_ctrl(dev, UVC_GET_MAX, entity->id,
> + dev->intfnum, MSXU_CONTROL_METADATA,
> + data, sizeof(*data));
> + if (ret || !*data)
> + continue;
> +
> + ret = uvc_query_ctrl(dev, UVC_SET_CUR, entity->id,
> + dev->intfnum, MSXU_CONTROL_METADATA,
> + data, sizeof(*data));
> + if (!ret) {
> + dev->quirks |= UVC_QUIRK_MSXU_META;
> + return 0;
> + }
> + }
> +
> + return 0;
> +}
> +
> int uvc_meta_register(struct uvc_streaming *stream)
> {
> struct uvc_device *dev = stream->dev;
> struct video_device *vdev = &stream->meta.vdev;
> struct uvc_video_queue *queue = &stream->meta.queue;
> + int ret;
> +
> + ret = uvc_enable_msxu(dev);
> + if (ret)
> + return ret;
>
> stream->meta.format = V4L2_META_FMT_UVC;
>
> diff --git a/include/linux/usb/uvc.h b/include/linux/usb/uvc.h
> index bce95153e5a65613a710d7316fc17cf5462b5bce..ee19e9f915b8370c333c426dc1ee4202c7b75c5b 100644
> --- a/include/linux/usb/uvc.h
> +++ b/include/linux/usb/uvc.h
> @@ -29,6 +29,9 @@
> #define UVC_GUID_EXT_GPIO_CONTROLLER \
> {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
> 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03}
> +#define UVC_GUID_MSXU_1_5 \
> + {0xdc, 0x95, 0x3f, 0x0f, 0x32, 0x26, 0x4e, 0x4c, \
> + 0x92, 0xc9, 0xa0, 0x47, 0x82, 0xf4, 0x3b, 0xc8}
>
> #define UVC_GUID_FORMAT_MJPEG \
> { 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \
>
> --
> 2.49.0.504.g3bcea36a83-goog
>
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v5 2/4] media: Documentation: Add note about UVCH length field
2025-05-26 13:49 ` Laurent Pinchart
@ 2025-05-26 14:04 ` Ricardo Ribalda
2025-05-26 14:13 ` Laurent Pinchart
0 siblings, 1 reply; 18+ messages in thread
From: Ricardo Ribalda @ 2025-05-26 14:04 UTC (permalink / raw)
To: Laurent Pinchart
Cc: Hans de Goede, Mauro Carvalho Chehab, Guennadi Liakhovetski,
linux-media, linux-kernel
Hi Laurent
On Mon, 26 May 2025 at 15:49, Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:
>
> Hi Ricardo,
>
> On Fri, Apr 04, 2025 at 06:37:35AM +0000, Ricardo Ribalda wrote:
> > The documentation currently describes the UVC length field as the "length
> > of the rest of the block", which can be misleading. The driver limits the
> > data copied to a maximum of 12 bytes.
> >
> > This change adds a clarifying sentence to the documentation to make this
> > restriction explicit.
> >
> > Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> > ---
> > Documentation/userspace-api/media/v4l/metafmt-uvc.rst | 4 +++-
> > 1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/Documentation/userspace-api/media/v4l/metafmt-uvc.rst b/Documentation/userspace-api/media/v4l/metafmt-uvc.rst
> > index 784346d14bbdbf28348262084d5b0646d30bd1da..42599875331c0066cf529153caccb731148023b9 100644
> > --- a/Documentation/userspace-api/media/v4l/metafmt-uvc.rst
> > +++ b/Documentation/userspace-api/media/v4l/metafmt-uvc.rst
> > @@ -44,7 +44,9 @@ Each individual block contains the following fields:
> > them
> > * - :cspan:`1` *The rest is an exact copy of the UVC payload header:*
> > * - __u8 length;
> > - - length of the rest of the block, including this field
> > + - length of the rest of the block, including this field. Please note that
> > + regardless of the this value, for V4L2_META_FMT_UVC the kernel will
>
> "the this value" looks like a typo.
Thanks! Will fix in v2
>
> > + never copy more than 2-12 bytes.
>
> Are you saying here that length can be larger than 12, but only up to 12
> bytes will be copied (when both SCR and PTS are present) ? If that's the
> case, it would be better to fix the driver to clamp the length value to
> the number of bytes actually present in the buffer.
As the documentation says, this is an exact copy of the UVC payload header.
Assuming SCR and PTS, for devices that have metadata length will be
the real length provided by the hardware. but buf[] will only contain
12 bytes.
Replacing the value of length with the actual value will be a uAPI
breakage. I do not think that is a very good idea to change it,
considering that this number is used by parsers.
>
> > * - __u8 flags;
> > - Flags, indicating presence of other standard UVC fields
> > * - __u8 buf[];
>
> --
> Regards,
>
> Laurent Pinchart
--
Ricardo Ribalda
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v5 2/4] media: Documentation: Add note about UVCH length field
2025-05-26 14:04 ` Ricardo Ribalda
@ 2025-05-26 14:13 ` Laurent Pinchart
2025-05-26 14:20 ` Ricardo Ribalda
0 siblings, 1 reply; 18+ messages in thread
From: Laurent Pinchart @ 2025-05-26 14:13 UTC (permalink / raw)
To: Ricardo Ribalda
Cc: Hans de Goede, Mauro Carvalho Chehab, Guennadi Liakhovetski,
linux-media, linux-kernel
On Mon, May 26, 2025 at 04:04:03PM +0200, Ricardo Ribalda wrote:
> On Mon, 26 May 2025 at 15:49, Laurent Pinchart wrote:
> > On Fri, Apr 04, 2025 at 06:37:35AM +0000, Ricardo Ribalda wrote:
> > > The documentation currently describes the UVC length field as the "length
> > > of the rest of the block", which can be misleading. The driver limits the
> > > data copied to a maximum of 12 bytes.
> > >
> > > This change adds a clarifying sentence to the documentation to make this
> > > restriction explicit.
> > >
> > > Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> > > ---
> > > Documentation/userspace-api/media/v4l/metafmt-uvc.rst | 4 +++-
> > > 1 file changed, 3 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/Documentation/userspace-api/media/v4l/metafmt-uvc.rst b/Documentation/userspace-api/media/v4l/metafmt-uvc.rst
> > > index 784346d14bbdbf28348262084d5b0646d30bd1da..42599875331c0066cf529153caccb731148023b9 100644
> > > --- a/Documentation/userspace-api/media/v4l/metafmt-uvc.rst
> > > +++ b/Documentation/userspace-api/media/v4l/metafmt-uvc.rst
> > > @@ -44,7 +44,9 @@ Each individual block contains the following fields:
> > > them
> > > * - :cspan:`1` *The rest is an exact copy of the UVC payload header:*
> > > * - __u8 length;
> > > - - length of the rest of the block, including this field
> > > + - length of the rest of the block, including this field. Please note that
> > > + regardless of the this value, for V4L2_META_FMT_UVC the kernel will
> >
> > "the this value" looks like a typo.
>
> Thanks! Will fix in v2
>
> >
> > > + never copy more than 2-12 bytes.
> >
> > Are you saying here that length can be larger than 12, but only up to 12
> > bytes will be copied (when both SCR and PTS are present) ? If that's the
> > case, it would be better to fix the driver to clamp the length value to
> > the number of bytes actually present in the buffer.
>
> As the documentation says, this is an exact copy of the UVC payload header.
>
> Assuming SCR and PTS, for devices that have metadata length will be
> the real length provided by the hardware. but buf[] will only contain
> 12 bytes.
>
> Replacing the value of length with the actual value will be a uAPI
> breakage. I do not think that is a very good idea to change it,
> considering that this number is used by parsers.
Do you think there could be userspace code that relies on the value
being larger than 12, even though the metadata after the standard UVC
block isn't present in the buffer ? Are you aware of any particular
implementation of such userspace code ?
> > > * - __u8 flags;
> > > - Flags, indicating presence of other standard UVC fields
> > > * - __u8 buf[];
--
Regards,
Laurent Pinchart
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v5 4/4] media: uvcvideo: Auto-set UVC_QUIRK_MSXU_META
2025-05-26 14:02 ` Laurent Pinchart
@ 2025-05-26 14:17 ` Ricardo Ribalda
0 siblings, 0 replies; 18+ messages in thread
From: Ricardo Ribalda @ 2025-05-26 14:17 UTC (permalink / raw)
To: Laurent Pinchart
Cc: Hans de Goede, Mauro Carvalho Chehab, Guennadi Liakhovetski,
linux-media, linux-kernel
Hi Laurent
On Mon, 26 May 2025 at 16:02, Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:
>
> Hi Ricardo,
>
> Thank you for the patch.
>
> On Fri, Apr 04, 2025 at 06:37:37AM +0000, Ricardo Ribalda wrote:
> > If the camera supports the MSXU_CONTROL_METADATA control, auto set the
> > MSXU_META quirk.
>
> Ah, that's why you introduce a quirk in 3/4.
>
> I would prefer if you could instead add a metadata format field in the
> uvc_device structure (I'd put it right after the info field, and while
> at it you could move the quirks field to that section too). The metadata
> format would be initialized from dev->info (when available) or set to
> the UVC format, and overridden when the MSXU is detected.
I assume that there will be plenty of devices that do not have the
MSXU_CONTROL_METADATA control and have metadata.
With a quirk, users can try enabling the metadata without rebuilding
their kernel. They can report it to the mailing list and they or we
improve the driver. The contribution barrier is lower.
Another issue of the dev->info would be that D4XX devices will not
support the MSXU_META format. I'd expect userspace to prefer
supporting one format instead of 2.
>
> > Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> > ---
> > drivers/media/usb/uvc/uvc_metadata.c | 54 ++++++++++++++++++++++++++++++++++++
> > include/linux/usb/uvc.h | 3 ++
> > 2 files changed, 57 insertions(+)
> >
> > diff --git a/drivers/media/usb/uvc/uvc_metadata.c b/drivers/media/usb/uvc/uvc_metadata.c
> > index fe2678fc795d7fd5a64e8113199012f34c419176..776d280f34afad515594a873acf075acf0438304 100644
> > --- a/drivers/media/usb/uvc/uvc_metadata.c
> > +++ b/drivers/media/usb/uvc/uvc_metadata.c
> > @@ -10,6 +10,7 @@
> > #include <linux/list.h>
> > #include <linux/module.h>
> > #include <linux/usb.h>
> > +#include <linux/usb/uvc.h>
> > #include <linux/videodev2.h>
> >
> > #include <media/v4l2-ioctl.h>
> > @@ -187,11 +188,64 @@ static const struct v4l2_file_operations uvc_meta_fops = {
> > .mmap = vb2_fop_mmap,
> > };
> >
> > +static const u8 uvc_msxu_guid[16] = UVC_GUID_MSXU_1_5;
> > +
> > +#define MSXU_CONTROL_METADATA 0x9
> > +static int uvc_enable_msxu(struct uvc_device *dev)
>
> uvc_meta_detect_msxu()
>
> > +{
> > + u32 *data __free(kfree) = NULL;
> > + struct uvc_entity *entity;
> > +
> > + list_for_each_entry(entity, &dev->entities, list) {
> > + int ret;
> > +
> > + if (memcmp(entity->guid, uvc_msxu_guid, sizeof(entity->guid)))
> > + continue;
> > +
> > + if (!data)
> > + data = kmalloc(sizeof(*data), GFP_KERNEL);
> > + if (!data)
> > + return -ENOMEM;
> > +
>
> A comment here to explain how the control operates would be useful.
> Reading the code I assume that GET_MAX will indicate if the MS metadata
> format is supported by reporting a value different than 0 (is it always
> 1, or can it take other values), and SET_CUR will enable metadata
> generation. I suppose the first GET_CUR call catches the case where it
> has already been enabled, are there also cameras where it can't be
> disabled, and where SET_CUR would fail ?
>
> > + ret = uvc_query_ctrl(dev, UVC_GET_CUR, entity->id,
> > + dev->intfnum, MSXU_CONTROL_METADATA,
> > + data, sizeof(*data));
> > + if (ret)
> > + continue;
>
> Can there be multiple MSXU instances, or can you break here (and below)
> ?
I think it is safe to break. Thanks :)
>
> > +
> > + if (*data) {
> > + dev->quirks |= UVC_QUIRK_MSXU_META;
> > + return 0;
> > + }
> > +
> > + ret = uvc_query_ctrl(dev, UVC_GET_MAX, entity->id,
> > + dev->intfnum, MSXU_CONTROL_METADATA,
> > + data, sizeof(*data));
> > + if (ret || !*data)
> > + continue;
> > +
> > + ret = uvc_query_ctrl(dev, UVC_SET_CUR, entity->id,
> > + dev->intfnum, MSXU_CONTROL_METADATA,
> > + data, sizeof(*data));
> > + if (!ret) {
> > + dev->quirks |= UVC_QUIRK_MSXU_META;
> > + return 0;
> > + }
> > + }
> > +
> > + return 0;
> > +}
> > +
> > int uvc_meta_register(struct uvc_streaming *stream)
> > {
> > struct uvc_device *dev = stream->dev;
> > struct video_device *vdev = &stream->meta.vdev;
> > struct uvc_video_queue *queue = &stream->meta.queue;
> > + int ret;
> > +
> > + ret = uvc_enable_msxu(dev);
> > + if (ret)
> > + return ret;
> >
> > stream->meta.format = V4L2_META_FMT_UVC;
> >
> > diff --git a/include/linux/usb/uvc.h b/include/linux/usb/uvc.h
> > index bce95153e5a65613a710d7316fc17cf5462b5bce..ee19e9f915b8370c333c426dc1ee4202c7b75c5b 100644
> > --- a/include/linux/usb/uvc.h
> > +++ b/include/linux/usb/uvc.h
> > @@ -29,6 +29,9 @@
> > #define UVC_GUID_EXT_GPIO_CONTROLLER \
> > {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
> > 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03}
> > +#define UVC_GUID_MSXU_1_5 \
> > + {0xdc, 0x95, 0x3f, 0x0f, 0x32, 0x26, 0x4e, 0x4c, \
> > + 0x92, 0xc9, 0xa0, 0x47, 0x82, 0xf4, 0x3b, 0xc8}
> >
> > #define UVC_GUID_FORMAT_MJPEG \
> > { 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \
> >
> > --
> > 2.49.0.504.g3bcea36a83-goog
> >
>
> --
> Regards,
>
> Laurent Pinchart
--
Ricardo Ribalda
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH v5 2/4] media: Documentation: Add note about UVCH length field
2025-05-26 14:13 ` Laurent Pinchart
@ 2025-05-26 14:20 ` Ricardo Ribalda
0 siblings, 0 replies; 18+ messages in thread
From: Ricardo Ribalda @ 2025-05-26 14:20 UTC (permalink / raw)
To: Laurent Pinchart
Cc: Hans de Goede, Mauro Carvalho Chehab, Guennadi Liakhovetski,
linux-media, linux-kernel
On Mon, 26 May 2025 at 16:13, Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:
>
> On Mon, May 26, 2025 at 04:04:03PM +0200, Ricardo Ribalda wrote:
> > On Mon, 26 May 2025 at 15:49, Laurent Pinchart wrote:
> > > On Fri, Apr 04, 2025 at 06:37:35AM +0000, Ricardo Ribalda wrote:
> > > > The documentation currently describes the UVC length field as the "length
> > > > of the rest of the block", which can be misleading. The driver limits the
> > > > data copied to a maximum of 12 bytes.
> > > >
> > > > This change adds a clarifying sentence to the documentation to make this
> > > > restriction explicit.
> > > >
> > > > Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> > > > ---
> > > > Documentation/userspace-api/media/v4l/metafmt-uvc.rst | 4 +++-
> > > > 1 file changed, 3 insertions(+), 1 deletion(-)
> > > >
> > > > diff --git a/Documentation/userspace-api/media/v4l/metafmt-uvc.rst b/Documentation/userspace-api/media/v4l/metafmt-uvc.rst
> > > > index 784346d14bbdbf28348262084d5b0646d30bd1da..42599875331c0066cf529153caccb731148023b9 100644
> > > > --- a/Documentation/userspace-api/media/v4l/metafmt-uvc.rst
> > > > +++ b/Documentation/userspace-api/media/v4l/metafmt-uvc.rst
> > > > @@ -44,7 +44,9 @@ Each individual block contains the following fields:
> > > > them
> > > > * - :cspan:`1` *The rest is an exact copy of the UVC payload header:*
> > > > * - __u8 length;
> > > > - - length of the rest of the block, including this field
> > > > + - length of the rest of the block, including this field. Please note that
> > > > + regardless of the this value, for V4L2_META_FMT_UVC the kernel will
> > >
> > > "the this value" looks like a typo.
> >
> > Thanks! Will fix in v2
> >
> > >
> > > > + never copy more than 2-12 bytes.
> > >
> > > Are you saying here that length can be larger than 12, but only up to 12
> > > bytes will be copied (when both SCR and PTS are present) ? If that's the
> > > case, it would be better to fix the driver to clamp the length value to
> > > the number of bytes actually present in the buffer.
> >
> > As the documentation says, this is an exact copy of the UVC payload header.
> >
> > Assuming SCR and PTS, for devices that have metadata length will be
> > the real length provided by the hardware. but buf[] will only contain
> > 12 bytes.
> >
> > Replacing the value of length with the actual value will be a uAPI
> > breakage. I do not think that is a very good idea to change it,
> > considering that this number is used by parsers.
>
> Do you think there could be userspace code that relies on the value
> being larger than 12, even though the metadata after the standard UVC
> block isn't present in the buffer ? Are you aware of any particular
> implementation of such userspace code ?
Userspace code can use a value bigger than 12 to know if the actual
metadata has been enabled or not.
I have been using that to test my code. I would not be surprised if
there are more userspace implementations like mine.
There is no reason to break uAPI, especially when it is documented to
behave like that.
This patch is just a clarification of the documentation. I would have
loved to have that clarification when I started working on metadata.
>
> > > > * - __u8 flags;
> > > > - Flags, indicating presence of other standard UVC fields
> > > > * - __u8 buf[];
>
> --
> Regards,
>
> Laurent Pinchart
--
Ricardo Ribalda
^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2025-05-26 14:21 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-04 6:37 [PATCH v5 0/4] media: uvcvideo: Introduce V4L2_META_FMT_UVC_MSXU_1_5 + other meta fixes Ricardo Ribalda
2025-04-04 6:37 ` [PATCH v5 1/4] media: uvcvideo: Do not mark valid metadata as invalid Ricardo Ribalda
2025-05-26 13:12 ` Hans de Goede
2025-05-26 13:46 ` Laurent Pinchart
2025-04-04 6:37 ` [PATCH v5 2/4] media: Documentation: Add note about UVCH length field Ricardo Ribalda
2025-05-26 13:12 ` Hans de Goede
2025-05-26 13:49 ` Laurent Pinchart
2025-05-26 14:04 ` Ricardo Ribalda
2025-05-26 14:13 ` Laurent Pinchart
2025-05-26 14:20 ` Ricardo Ribalda
2025-04-04 6:37 ` [PATCH v5 3/4] media: uvcvideo: Introduce V4L2_META_FMT_UVC_MSXU_1_5 Ricardo Ribalda
2025-05-26 13:16 ` Hans de Goede
2025-05-26 13:53 ` Laurent Pinchart
2025-04-04 6:37 ` [PATCH v5 4/4] media: uvcvideo: Auto-set UVC_QUIRK_MSXU_META Ricardo Ribalda
2025-05-26 13:19 ` Hans de Goede
2025-05-26 14:02 ` Laurent Pinchart
2025-05-26 14:17 ` Ricardo Ribalda
2025-05-05 9:06 ` [PATCH v5 0/4] media: uvcvideo: Introduce V4L2_META_FMT_UVC_MSXU_1_5 + other meta fixes Ricardo Ribalda
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.