From patchwork Thu Apr 3 21:31:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 878509 Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 74C761F12E7 for ; Thu, 3 Apr 2025 21:31:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743715891; cv=none; b=iTwPf/jIUUzAoNG1f+IYtsNxVTlsKaXHOf36VdPXAFvDSMh4dbqrqkELkR7YP4/w85wlSrN1lT86TIIZHPFFKhn2S4mvVTJOvI0sEMp+HihFD2knM86XEJ2G+Sx8csI97E+wdZ/Z6V7dPhIeq7mCzahnDYpZW5UOG7Pc3F4ZPmA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743715891; c=relaxed/simple; bh=LA7uZ6q3Sc7Jg4Eh7U3qdrnVOUP1fZHPRdVwZ90iFbI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jEBtMtQvV0kBHcP6RBdkUwaKy2tjHNwNBkH1kfcykpxTcObRIZ2CR0aqjpRamhMGVz7b9zhbQjUNKiBMkPGe0iYYWYdm9/AUj0SjSgS+XpoNw1tjHmikNu73uN1YVMciWfeJPmgCPfWzLGllDiQk75L5xhP0BsbvgYKAdorSg+c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=IY88jJEV; arc=none smtp.client-ip=209.85.167.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="IY88jJEV" Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-54963160818so1629335e87.2 for ; Thu, 03 Apr 2025 14:31:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1743715887; x=1744320687; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ptSauccsQCiihyTIqD40ILfoZlJ+Jkp9zzyDCujSkmg=; b=IY88jJEVVcMjS16BXc3JYSWqvTVkuMJ+eFVoAN4MqvNa+xgT2sgjUDRNTgK0xshgoU FfrvmPsg85f2/8n5co6bplEwQEwhecB42avY4tNTT8uDyv+U7+n6HFNWUj9iUEstvwUz Qa2ZelX3TlDAeYAkX3O2pFxyz78PDFY+lZHiI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743715887; x=1744320687; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ptSauccsQCiihyTIqD40ILfoZlJ+Jkp9zzyDCujSkmg=; b=ndEaAYrTV0aIg/0xlr7W0+tck9YuNE/DZtVGjVKEQUTuBqtFPejeG1AYvaD6b0V8iG +klfmcaeeyuC/ZQQ2oJfSH3LWg0I40KQRBkAgpuiw9uXLSfDx+Di7/1cDyl7BaMW4iFC Yijrf+rD8/cAOIRc5dc6aqkmjmBvvpszkOkGb8BMd49s9TQwkrsXQ4rp9CeOv+YL/p1e zwxzIblQOBy/h7wRN5L+EspeSXakiAm3VrJTpyZbEc3YR3CEX0DJwsAxDh3KwCwPe58s pJsqrMjyfQygPgz7U1orKAiiqhzyW6KjOtruLiuotaRBhqQDxkytkjfPrG976KWQLx6I S10Q== X-Gm-Message-State: AOJu0Yw5ikRd6TbmhxOIo+/+zmOeoNckQ1A40jVdmZbVK7QOly9hcPRz udy2TpNPHe6JhpR67TCAUgX1HW4z49D7mJixNDgTMa2SdmMfbCFSCK7vg68kog== X-Gm-Gg: ASbGncvrTCwqFSXwDU2MwLqv/AvA+rfeVnJY7jLP5YGCQpy/vB+CJEVDEZaXGugKsRL mldEDgoFI1ftsRZZ7bPEJNMvxXBXE9knVdGnAxtUNeJHHs/D4MKac9ZvY97Pav6KKFPM/UVfamx AdRcwmd+dryeQDcOJ8KOpPJuhUleImaz7+8HVixu+Py7pahaJpMl/b+dIm1WkoIPTFsrLMX3YbV mu/SV7LfRvOL7nOTvVKv8FhLQJoKCgHKKUfqudTbYB/rIkdCi5/6jihL662E+Or4TPKZtzlAgoc 7ZxcnQ1E262YYeeuJZzOHhcPEkXTnPWkYUruiqOjF1U7SXw1bXvY9qQXocpLsPP+ciPXGDXI5nZ WnMZp2Cp4jOQs7dfRFHc4+pVx X-Google-Smtp-Source: AGHT+IHIzqGAEc7RpQLkJ1WXd/DNbrh96pu+9FFacP/jNhgNPL2Z9Mg7lblGijukf30AT3j8gNlUNg== X-Received: by 2002:a05:6512:1092:b0:540:2fd2:6c87 with SMTP id 2adb3069b0e04-54c232dc08emr59772e87.16.1743715887457; Thu, 03 Apr 2025 14:31:27 -0700 (PDT) Received: from ribalda.c.googlers.com (216.148.88.34.bc.googleusercontent.com. [34.88.148.216]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-54c1e65d6d5sm252938e87.181.2025.04.03.14.31.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Apr 2025 14:31:26 -0700 (PDT) From: Ricardo Ribalda Date: Thu, 03 Apr 2025 21:31:24 +0000 Subject: [PATCH v4 1/4] media: uvcvideo: Do not mark valid metadata as invalid Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250403-uvc-meta-v4-1-877aa6475975@chromium.org> References: <20250403-uvc-meta-v4-0-877aa6475975@chromium.org> In-Reply-To: <20250403-uvc-meta-v4-0-877aa6475975@chromium.org> To: Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab , Guennadi Liakhovetski Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , stable@vger.kernel.org X-Mailer: b4 0.14.2 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 --- 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(); From patchwork Thu Apr 3 21:31:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 878069 Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7FFEF1C6FE2 for ; Thu, 3 Apr 2025 21:31:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743715892; cv=none; b=LXcOv8sTEVLZQ1+J5DgcgMi8hUcguFaw9/gZZYCuofvqDyhOx55DlP9C1G13w2fgJAuHZ9KCORYd2G45xbWM/GC5hSBF/uBZL5LPi9PamYRtZpGCyouyf2Lof3jjENqAhYWYboalLABZAsKnJQVAkp18/w617MEN6PvZOEbcN1U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743715892; c=relaxed/simple; bh=A+EYzZLGQHIPJ5VAoM/+3fe53Af6CgodqviiAM/ONBM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VciQv3y5vwQKXM9tG1qOqHp4qRUJIZAskqkL8TBhorCNs2u/DjFzX674RgUHP8IlgdZcdYXJOYd42dz62qTi7nhGMaGI2fYC5mlcx5MGnT4ZP3h+G4Yi6v3aRANQQ6FBghF4u9917BurFCJRpH4K05DiFmryB0AkpAcBNjaK3pQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=RBoMnZZ0; arc=none smtp.client-ip=209.85.167.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="RBoMnZZ0" Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-54af20849adso1313969e87.1 for ; Thu, 03 Apr 2025 14:31:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1743715888; x=1744320688; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=uAivlvh8Vrg1UGAUIkAMwQONWXUXc2TvgNk5knB4y0c=; b=RBoMnZZ0u/tUHLRK1bssySq5ikkgvf1ls37o0ILNW6qzkgKJCfIy5m1T8mjrpJotE3 NavUwfK9degbloOOuf+jGgb+wbLb9w0pv7k9ZBX7JMIRwDaB1GjU6gxaIXe38C1uKe2/ wLdxWcH0EJkncsJ5361zJfhfTtmF3J806HAqA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743715888; x=1744320688; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uAivlvh8Vrg1UGAUIkAMwQONWXUXc2TvgNk5knB4y0c=; b=vYe9d7au8AaEz4+N6HQmtDsHTJi0rLB48slWqIsNRDSngNNVrDJYoPKxXP5uxpGvQ7 ZoYwbV3C9AyGrr/grpcSPE220SgeKXsU2pPDz9EXLtJ+P0TDd9e3DYNj6SJ1Hy5ORD2z +dJsFIhg1YILioHGVklsufhPUdXFBKFJn8ZcMvhAabJ3BLCYvlPgY8CtjyzgvZShC0dg /tuowV/mwxN89Oba4Z20fTA63JvCsghJcSUiUWROtJHZAlFph+Xp6G5nqK3gW3+b7cvF +AsBIDFrvEvYoHx+A820WpLR4rYv4GcrfvoeoMWI6TouNQTZoZacjTzwrYYD18hhLDIo i2aQ== X-Gm-Message-State: AOJu0YxkwILPnVlMZUPmz4mz2WeD1Qu6fG0Gi+MPUPKpslMYzzXL6deN srRna+yZtK+5CRuojQZSsw+8lgBw5FG84rlZQFhTZpVHLbRjuwA+c674mxFRKA== X-Gm-Gg: ASbGncuIN47erUkYMniNoCOZ5gxR9SSUjOY76Afe1WHHcj37513KCTAQ8Lb0Z4wRzwM jptrhdJHrwzpXhMLfrnFoffFICCs8FqbrtyWpD4PUtM8u4YoXedlagh1//qrVCVB5eVZwtLz7lV 4n4HPOtX5T9KNCQvQkMdyC8tZ34ysUf/NwGYP/4HIiJpfWZr2hTHaCSNS5N4Zxyd0SZv1xLWsQm yK+Med3CzmALK+azp9q6gMuZ5PI5S3EjbqNKTThIkbkmnXQfYaoX3TL7gBSbkRSWiJ28w7D3GxX LFAiZbStlpa8vjDrVyukUPt8giZP1H/RNQQ53LI7dxHANIEvjQ0vmuCqBJgCWub2cO3FThjLyoh 0pJMrHD+FLx51E047rdyp59DqMPbzPeQ5uMQ= X-Google-Smtp-Source: AGHT+IEgkYZflIY62I3D0j+z07leuEa6xOn//asxpOiQ1NhbRMdh9wxzWYxoJvi7ZlfsK+HV44q73A== X-Received: by 2002:a05:6512:2c88:b0:549:981a:1eeb with SMTP id 2adb3069b0e04-54c1ca56dd5mr1924310e87.5.1743715888535; Thu, 03 Apr 2025 14:31:28 -0700 (PDT) Received: from ribalda.c.googlers.com (216.148.88.34.bc.googleusercontent.com. [34.88.148.216]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-54c1e65d6d5sm252938e87.181.2025.04.03.14.31.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Apr 2025 14:31:27 -0700 (PDT) From: Ricardo Ribalda Date: Thu, 03 Apr 2025 21:31:25 +0000 Subject: [PATCH v4 2/4] media: Documentation: Add note about UVCH length field Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250403-uvc-meta-v4-2-877aa6475975@chromium.org> References: <20250403-uvc-meta-v4-0-877aa6475975@chromium.org> In-Reply-To: <20250403-uvc-meta-v4-0-877aa6475975@chromium.org> To: Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab , Guennadi Liakhovetski Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.14.2 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 --- 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[]; From patchwork Thu Apr 3 21:31:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 878508 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 735C61F9F51 for ; Thu, 3 Apr 2025 21:31:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743715893; cv=none; b=tTdC0jN8Y5GGG3C9ssW6LXghP399fuahsXWh1MA/88s0J1CpggNx1fjCCjkhIlSURZuYfNVsrKyPdI5ZQIlo8GEugmqEncR9zZkTqoJxe23eg0ZgY0PT7tqVg9iCzEDtjYNqypnnhGTUht4J0cuVaJg3z43bCohD40GpUgY+HiQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743715893; c=relaxed/simple; bh=L7y5JgtHlBuaCQXRqFHbuJtPei3FDRhe9+sz6StA404=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hvWqsGyxmVqzhexy3IkCecrM/BnQcKIHpeK/PGFKW+w9kF9SRkkvs/20mqkmqt/8Nw+PUFhPEVITxUuylqR+kdph69GrmzNFQuUgApH6C0s21T17e+UcpqzY29wC7nFASne3+YEO16j5F5/B9/pt4B+8LIp5/9XuOF/YVetn5+g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=eYcKEZG2; arc=none smtp.client-ip=209.85.167.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="eYcKEZG2" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-5499c5d9691so1577099e87.2 for ; Thu, 03 Apr 2025 14:31:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1743715889; x=1744320689; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=+thbh0+TpU/cLXc8EBGcJ8aUoG9xyAqyDChZ9I91Sg4=; b=eYcKEZG2aAYliPPMzUe5zzWQtCi5qvwmwO+cDqFc7PhYnMhWMUqteJ4TukbeR/9cwr ecVLNF3FVbw6pej+u7P17kEoVBV5G004gFyNYPTFkedLVE5VhxXdrkzKsER5Ifs21izs K+jjjNHmleyooShEnH/a6HpLnUJjIgRWl0VsI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743715889; x=1744320689; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+thbh0+TpU/cLXc8EBGcJ8aUoG9xyAqyDChZ9I91Sg4=; b=AXgYYBX8W4hjjcvZoQDuJFuvkj9zY0slI7Hh7oydt9W2AvieHFRO4x7H7JnFcYJJef e2hxNAKuz/rlUYl8+liYO1Jm7qtsLaTh53XlHS8hUUqvr5jKJXV6MruwsGY7ZsYd3/g4 OBL4R0osVHWiyWELA6zFWZ1sNI/+jPmHLKHzR48C5RVQpcSHxyREsUeXXgQptdHfn28F EIcS5dm20/bDcTgtadj8DvHo4EB72S9SNo5yKpD85UgG5fXZi8fqzqr8n0uZqbPXRWqM ZujB+PpDGuHQzL5CqLlMFq8Ll+jE8QVnDG01fHNUNrXOie85n5Nr6npQ1nKTGDOXTvi5 7lSg== X-Gm-Message-State: AOJu0YzXm3fuhvVINQh95SmPPR+J3rAZIu+es52rZi/B840SDClZeQeH j9LXsNkVBFa7AYFfdCHgp78r2e+jeb/qn8tVX5NcSQELr2ElAs8cTszvZXESMQ== X-Gm-Gg: ASbGncvVq5OA4741mqR+jw6We8mgfQ/0Lt5TwM1XOYxpaRQ5TC/eSfEomhxOBhNu6DR w5MgQdutjyzzT2vWXY3bXSTI62cpxhgKLpkpzD1F1hDSSrqLQhUO2C2GjwrEt6tjbqBLsmvgV97 3kW32BOsJMsWRUJ95yEuJtzI0bY6UuC0loIMossfFK+9OihFms5XHRc6x/6Tg6In4bWq86f1pPT DsVrF0Sge9SK6jJ9CEzySFGIprU2DaGD1ZKWWc1jhyV8XW3v16AYL2Pm4qKlkJUkRYsV1u6tK0I jRNSxK5HtI71OLvHn2NHYT4s4LhdtCEvBwq1BpTihR1S4oGfK/cBi2iG1vQAZcVUPc6EcGIEI1a 9bEkLbM+OccosedsyIRpmQwoV X-Google-Smtp-Source: AGHT+IGlY97KwhiEi7m172O5iTRFLg+XYA3D62E4/JwTE+9ktBo0wZMO1HJ2NvIZm1Pz9Y/79OdyMA== X-Received: by 2002:a05:6512:10d1:b0:54a:cbfb:b62e with SMTP id 2adb3069b0e04-54c227dc7c9mr177515e87.35.1743715889253; Thu, 03 Apr 2025 14:31:29 -0700 (PDT) Received: from ribalda.c.googlers.com (216.148.88.34.bc.googleusercontent.com. [34.88.148.216]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-54c1e65d6d5sm252938e87.181.2025.04.03.14.31.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Apr 2025 14:31:28 -0700 (PDT) From: Ricardo Ribalda Date: Thu, 03 Apr 2025 21:31:26 +0000 Subject: [PATCH v4 3/4] media: uvcvideo: Introduce V4L2_META_FMT_UVC_MSXU_1_5 Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250403-uvc-meta-v4-3-877aa6475975@chromium.org> References: <20250403-uvc-meta-v4-0-877aa6475975@chromium.org> In-Reply-To: <20250403-uvc-meta-v4-0-877aa6475975@chromium.org> To: Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab , Guennadi Liakhovetski Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.14.2 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 Signed-off-by: Ricardo Ribalda --- .../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..f211d33ac6d89e1a6684fbafc43bab6287b6a4a4 --- /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 + +.. _metafmt-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 */ From patchwork Thu Apr 3 21:31:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 878068 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A1341F1312 for ; Thu, 3 Apr 2025 21:31:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743715894; cv=none; b=U0opPAwbiwtUmk3f7dJge11DBKhszRPkbp2jvO9y4SfVPRm/+mMeMMfLVk51TysDsvegEQcB7+pRm5OJYdOpAr2GjEAU6DKqqmNch/nwsYyYBRx/YOsFLuusjAAhEFafWPkxa6tfbHu6m/mK6M0eif3bBAGHGH/UTqk1kRxCYEE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743715894; c=relaxed/simple; bh=86KyjaRAGjjTKuXy7mDWoRbScnGEMhFa4ax77t2ho8E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=akjHZZW3MO3XxJfVOcnxtOuQKZGVq1eTS2bmCxtyLkssMai25t5kTLZ0cPi5RmE8D7YdnvMak/zXrDPkbZ+OKiW/urNc3d+sT8gZfq7qBR5yhzVcDd/CXwaiWNmnVccBdT80kcywVjZESgqSIqKnN1TXS3PQj0aL9neiQoqr5Vw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=CuCqjzWC; arc=none smtp.client-ip=209.85.167.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="CuCqjzWC" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-5493b5bc6e8so1630198e87.2 for ; Thu, 03 Apr 2025 14:31:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1743715890; x=1744320690; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=6MGj5UpsHm+GZxbdk2LCox0kgO/5V4KNTxUQIcaSNWI=; b=CuCqjzWCUUFg689ZDk/rYO9TSCNpC11Pa450I6E57Lf/EMh/KrdrJOHzAxOBxnbdjr Av/pRkRBwqLhV9RJ1fWM0n/kUee7jC7TFUXg9TiHBVJd0VwMKa1kMw1IMGKSwFGH4Kc8 QqulYh2cd+z5ID6mOu+slFL2KAfNscL+ykL3E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743715890; x=1744320690; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6MGj5UpsHm+GZxbdk2LCox0kgO/5V4KNTxUQIcaSNWI=; b=PEsCrM4dn3BfI9cAk128FTWxBMPDwJPB2ff4u4IlUbWbkPpD5takoT34BzHyw3+jyL 9RYQ2gWKzmWgcl3bpWC0HJaC4e4cjAcR8ZA+wGDdakU5BuEwGnyjuIzcLdpajbMxWD/Y 3ZaY5VGp7dPlz6ZFzBbC/adevJlhTTRLGO4WhoFfjK/N7ksr9ebfReXFYA7QBUGBbTZv sm6z7/pqNyRiXM8xLe5nRPy2skTeo0yZN0q+9mk+19zdpyE/6HBbO4r7a8JigVHp1cKc KY/8PIu1/l0oWFhFMvowT5cbWW90g+0vzUtQfSFsWd7Gm/ye0pgp1OQd/0RoA9LnprI1 +AEQ== X-Gm-Message-State: AOJu0YwNbWWj/kk6Vtz2ULvu/VTCKVaG9YjjaPmqI0bBW1EHq8/vbQG6 VzvrHsgoHEMC87cDxwbg6d8lPFqRPb3MxWCQd+J9tVfJ679xQ94Lus0kfLSdhQ== X-Gm-Gg: ASbGncvLNWC7mj2mvRu3G5ZOHhFIvPy5qU5H5dWLcgcmdojrtEaZGziNKHB48IQd1Hv V2RBJebrqUoCkpifM+7Tl5r8Rmk4UZNU6HugAZd0DtjAsHU3mKg6lXOrKkV8mH20/s/DBXuntro KAAaZavgjY4lNLZx5MRUz5mNIYtiKszqz5H//4o1PCqiChHSXhgBXZmcCPr05fG+xQ7YCOX7MBX B36hOYH6AwEyXbCzCGtpH0nQRBT5XMPA9VeBhpDP80fHil583yOQld9cOr1DmDrtoQybggeAOhO mLNCow82sAshsEKU4KCE8EcF6VF4/WV5LyokdLsckfxYxc577blt1Gelx6lqWApyd6ksE4uNehw X3UxP2n3L/WeRvOBZUQJ5ApzV X-Google-Smtp-Source: AGHT+IHTbGg1GaWfCnPg2ymof4WQjtefKbcIM/OyDImt2UtLGpbIf8+qPYBSCQ/kBkFjcmGNx4MtWQ== X-Received: by 2002:a05:6512:68c:b0:549:31e4:9ea with SMTP id 2adb3069b0e04-54c2338b38cmr46045e87.52.1743715890371; Thu, 03 Apr 2025 14:31:30 -0700 (PDT) Received: from ribalda.c.googlers.com (216.148.88.34.bc.googleusercontent.com. [34.88.148.216]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-54c1e65d6d5sm252938e87.181.2025.04.03.14.31.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Apr 2025 14:31:29 -0700 (PDT) From: Ricardo Ribalda Date: Thu, 03 Apr 2025 21:31:27 +0000 Subject: [PATCH v4 4/4] media: uvcvideo: Auto-set UVC_QUIRK_MSXU_META Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250403-uvc-meta-v4-4-877aa6475975@chromium.org> References: <20250403-uvc-meta-v4-0-877aa6475975@chromium.org> In-Reply-To: <20250403-uvc-meta-v4-0-877aa6475975@chromium.org> To: Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab , Guennadi Liakhovetski Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.14.2 If the camera supports the MSXU_CONTROL_METADATA control, auto set the MSXU_META quirk. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_metadata.c | 53 ++++++++++++++++++++++++++++++++++++ include/linux/usb/uvc.h | 3 ++ 2 files changed, 56 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_metadata.c b/drivers/media/usb/uvc/uvc_metadata.c index fe2678fc795d7fd5a64e8113199012f34c419176..fb3fc75a0af20c471b87f459593418d3ac021193 100644 --- a/drivers/media/usb/uvc/uvc_metadata.c +++ b/drivers/media/usb/uvc/uvc_metadata.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -187,11 +188,63 @@ static const struct v4l2_file_operations uvc_meta_fops = { .mmap = vb2_fop_mmap, }; +#define MSXU_CONTROL_METADATA 0x9 +static int uvc_enable_msxu(struct uvc_device *dev) +{ + static const u8 uvc_msxu_guid[16] = UVC_GUID_MSXU_1_5; + 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, \