From patchwork Thu Mar 9 14:44:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 6363 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp340902wrd; Thu, 9 Mar 2023 07:07:08 -0800 (PST) X-Google-Smtp-Source: AK7set9k+Ej8KHdTgA2bSeD8N5xpoI0lXYp/PygtJ6tn/iWDdT44yOxmuLbqJ2yex4nO0qU4FD9B X-Received: by 2002:a05:6e02:1be9:b0:31e:517a:40a7 with SMTP id y9-20020a056e021be900b0031e517a40a7mr11039598ilv.4.1678374427885; Thu, 09 Mar 2023 07:07:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678374427; cv=none; d=google.com; s=arc-20160816; b=stkfXv+Lo0R513aGBRmcAjOS0tPeTRsyURWUeVx7yICKY4U5PwBKFkRKwSPDSmwpI8 ypjRZD5Q4n4D91NnTQHHGaugfCxua9oL70CWssVSgRigGYJe44QcnOW8an/79pLk/1Bv xocNGWHOT7zyueFAAqVEfrLlG5UZ4JUoe/rlY3n+Lo3B3c6BaHF+mFa4DFMFWoR5BHsy V8YT2kZU5sfWOAYPswkWR6hlhWHvGeWs33z4eq+UsgXajz4FLp9MhITF/E0RWghqdTeI gR0vEm8ogT59rObcWfclSvV4vtp3MzJPSZR8dkitKKbHF+1KIKuESOtGJzAivCilCHtn Z7Mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:message-id:date:from :content-transfer-encoding:mime-version:subject:dkim-signature; bh=j0QCaTZpFQda66tbkDh4NA2798g5mrFM2KijxKnqpqY=; b=bgvUeTR/StZfrp9qrkmY0OgaxocB+v2XBWzZkGXuV0TV8olKl39SE8JDtjjXzxygtS KP4nF0L52lOgIoDdY4RVDtxKrJ3N31rymLqshWfPiufuKG5dgxQUVnb7uhtLsJ7TMVHV 5luNMoWiRPtCJ7pftGUC64UUkVJlguha9vcekSCizD8QFtiGcj/DLirQi1aE5BQWFgGU YrOXgemk83XoaFG7eYAl0wCJ+r3L8SX1voE3EGYcXhQLxR509iaY027x12f1nhPeMgms DtC9m4EW1wsI/KK/CYkhBVIVhHvMA2B20cOOxrXWwNonaAmWlox7+MfJ+OlyKHCC5iYJ KCRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=JXlcZf5T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l6-20020a922806000000b0030b18dcc0e8si16811928ilf.41.2023.03.09.07.06.52; Thu, 09 Mar 2023 07:07:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=JXlcZf5T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232036AbjCIOp5 (ORCPT + 99 others); Thu, 9 Mar 2023 09:45:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232116AbjCIOpC (ORCPT ); Thu, 9 Mar 2023 09:45:02 -0500 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BE4BF9EFF for ; Thu, 9 Mar 2023 06:44:21 -0800 (PST) Received: by mail-ed1-x533.google.com with SMTP id g3so8005572eda.1 for ; Thu, 09 Mar 2023 06:44:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1678373059; h=cc:to:message-id:date:from:content-transfer-encoding:mime-version :subject:from:to:cc:subject:date:message-id:reply-to; bh=j0QCaTZpFQda66tbkDh4NA2798g5mrFM2KijxKnqpqY=; b=JXlcZf5TJBTXPGC4CRaGGUxnbLNWt6tq33auMN/90FORiWH3AMH77DpWVbvaymIWwB SW89Bb99rq8cYHyJwN1KtIo951dij/3LxxmD8xXkrEsLVgOG+Ww/jjk9zV5HSlHY/P04 iJhKxP+XILgPJjWgASKARUzJh39GHmxlDktWY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678373059; h=cc:to:message-id:date:from:content-transfer-encoding:mime-version :subject:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=j0QCaTZpFQda66tbkDh4NA2798g5mrFM2KijxKnqpqY=; b=A5/IwSKVej3ERCGltOoykFF16R/YBAhkiF9g6fSFIeImgZY385j/q2i7os3g4dvVfw H86jwF3NvYc+ijNV8UPKGmlYCCt+PzMkAprKFPlh/PqaeO9a76cNHcMDWtuuKGqqw96f uwEFC8tX5R4fZd/3/IMnDqqrMhCaSibsxeEDXx9WTwH4Vpomq1VMZ/Jz8rJlhszQpLPa AgcPVWUdu3JUmxUZxSGNwWYzLSSCGdppC6LSM/IgV75z+xiPyDLAKx17IB5a7sy1830w Y9ABrbpjIchIAqFOKT3ErpedkliM/hfcapOsuw5OudMO2FqJy30jhjnwnYxt5kJqaxmw e0pA== X-Gm-Message-State: AO0yUKVDOlZMgzCCgPEiy1V8x9tzBSbsVC1IxrHyPBrL8W6EsSSQxOyE KERbT0w0nR7b/0HytfSC1SYK/DOwHuD7X3wdnrNhHg== X-Received: by 2002:a17:906:1604:b0:879:bff:55c with SMTP id m4-20020a170906160400b008790bff055cmr24474305ejd.1.1678373059532; Thu, 09 Mar 2023 06:44:19 -0800 (PST) Received: from alco.roam.corp.google.com ([2620:0:1059:10:1645:7aa4:a765:1966]) by smtp.gmail.com with ESMTPSA id l6-20020a50d6c6000000b004bdcc480c41sm9708931edj.96.2023.03.09.06.44.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Mar 2023 06:44:19 -0800 (PST) Subject: [PATCH v2 0/3] uvcvideo: Attempt N to land UVC race conditions fixes MIME-Version: 1.0 X-B4-Tracking: v=1; b=H4sIALTwCWQC/3WNwQqDMBBEf0X23C1JLKn21P8oPZi4mgVNYKNCkf x7Q+89DW/gzZyQSZgyPJoThA7OnGIFc2nAhyHOhDxWBqNMq1rV47xT3Ehw5cjY9Z3VTnU3mjRUxQ 2Z0MkQfahS3JelloHzluTzuzh0jdeftUOjQmvuo1Z+stTbpw+SVt7Xa5IZ3qWUL2dRYMywAAAA From: Ricardo Ribalda Date: Thu, 09 Mar 2023 15:44:04 +0100 Message-Id: <20230309-guenter-mini-v2-0-e6410d590d43@chromium.org> To: Mauro Carvalho Chehab Cc: Ricardo Ribalda , Laurent Pinchart , Max Staudt , Alan Stern , Sakari Ailus , Guenter Roeck , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Paul , Tomasz Figa , Hans Verkuil X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=3209; i=ribalda@chromium.org; h=from:subject:message-id; bh=QHnRbL/75sY1mg763dtX1ee9LADH3yYE98GBTazRZhk=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBkCfC2dCdyamuJtcwg32/a/jrzGAHWDnDucmFsS0bW 3fMT20yJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCZAnwtgAKCRDRN9E+zzrEiEOjD/ wI+h055aamjDQj8n6RWHDvLNqfRqM6BUIQGHopUnkQZRlFoK5Sucbg2e6n9ZIJ2pEe6BlEPZYrxv6g 8MHx0gI1BLjSj5aEDpWwQ5emZ9wlvYsm6K3l4z67lmLr6ARj2TbBzvWql8hIeypb22oxEnNtzpdYzc EL4e/Umrg5Dx7WJWipslAr70Tg4kfZctuzSnnJaqd70I0ThSBjfFsYrs+6MvZtlCUZJxGvw+ecsIVu 42imzYtKHsDb0+wGwkcUszX8zww5HYW1MSKQLd1eficFMdlh4RnrPV0VN7xG/PWeL0i8BqRZ0inETj +QQy4f6BZItd2++M+CxDuuj5+lu1H+Fc+pMDTaY3k5JaW1W7yFDFXPnlnr92H3UcFhIahUWWhWbzsp keEleIyGsDXQIazJWBHUd1Q2SvS0leefGoC6UTGt/MUzyw0UGL0brVSOdEv/zBm9Mw9R5G031Y6fva mn8vZK1yAnDW5tvIen4fWq0E4mvJ9WarvUNsL8RHWmE6W0nKE+4Bn3c+bOrJuXKzGgnohCTmch7R5P 8dhjuQVaqO27vZSgw8khjgtL1Q9piU/u2mI45wQcEPg5vX1xJwCa65PQ8t0D9JMs9/QIS7f/e3+WLy kuzaHmE5BduEzpnMrA0HWvCtONkA9GlufqK3dw+PZQN/CwEiKxrwpGiY3LAg== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759903143936549369?= X-GMAIL-MSGID: =?utf-8?q?1759903143936549369?= Back in 2020 Guenter published a set of patches to fix some race conditions on UVC. https://lore.kernel.org/all/20200917022547.198090-5-linux@roeck-us.net/ That kind of race conditions are not only seen on UVC, but are a common sin on almost all the kernel, so this is what it was decided back then that we should try to fix them at higher levels. After that. A lot of video_is_registered() were added to the core: ``` ribalda@alco:~/work/linux$ git grep is_registered drivers/media/v4l2-core/ drivers/media/v4l2-core/v4l2-compat-ioctl32.c: if (!video_is_registered(vdev)) drivers/media/v4l2-core/v4l2-dev.c: if (video_is_registered(vdev)) drivers/media/v4l2-core/v4l2-dev.c: if (video_is_registered(vdev)) drivers/media/v4l2-core/v4l2-dev.c: if (video_is_registered(vdev)) { drivers/media/v4l2-core/v4l2-dev.c: if (video_is_registered(vdev)) drivers/media/v4l2-core/v4l2-dev.c: if (!video_is_registered(vdev)) drivers/media/v4l2-core/v4l2-dev.c: if (video_is_registered(vdev)) drivers/media/v4l2-core/v4l2-dev.c: if (vdev == NULL || !video_is_registered(vdev)) { drivers/media/v4l2-core/v4l2-dev.c: if (video_is_registered(vdev)) drivers/media/v4l2-core/v4l2-dev.c: if (!vdev || !video_is_registered(vdev)) drivers/media/v4l2-core/v4l2-ioctl.c: if (!video_is_registered(vfd)) { drivers/media/v4l2-core/v4l2-subdev.c: if (video_is_registered(vdev)) { ``` And recently Sakari is trying to land: https://lore.kernel.org/linux-media/20230201214535.347075-1-sakari.ailus@linux.intel.com/ Which will make obsolete a lof (all?) of the video_is_registered() checks on Guenters patches. Besides those checks, there were some other valid races fixed on his patches. This series is just a rebase of what I think is missing on UVC even if we fixed v4l2/core with all the video_is_register() checks removed. Thanks! To: Mauro Carvalho Chehab Cc: Guenter Roeck Cc: Max Staudt Cc: Tomasz Figa Cc: Sakari Ailus Cc: Laurent Pinchart Cc: Alan Stern Cc: Hans Verkuil Cc: linux-media@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: Sean Paul Signed-off-by: Ricardo Ribalda --- Changes in v2: - Actually send the series to the ML an not only to individuals. - Link to v1: https://lore.kernel.org/r/20230309-guenter-mini-v1-0-627d10cf6e96@chromium.org --- Guenter Roeck (3): media: uvcvideo: Cancel async worker earlier media: uvcvideo: Lock video streams and queues while unregistering media: uvcvideo: Release stream queue when unregistering video device drivers/media/usb/uvc/uvc_ctrl.c | 11 +++++++---- drivers/media/usb/uvc/uvc_driver.c | 12 ++++++++++++ drivers/media/usb/uvc/uvcvideo.h | 1 + 3 files changed, 20 insertions(+), 4 deletions(-) --- base-commit: 63355b9884b3d1677de6bd1517cd2b8a9bf53978 change-id: 20230309-guenter-mini-89861b084ef1 Best regards,