Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp786247lqs; Fri, 14 Jun 2024 05:55:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUpf4PDQOIvyYXXgdOov4QiLeW5BSmIXwz8dqW0UNLgjKbBeqWQVc8QAxU9GiTV1qS4UsTrm9cKiPyfDKTqEy0XfBZv0sMFuT9+DrKPwQ== X-Google-Smtp-Source: AGHT+IEDtwwj5LoCANP0y4wuyOheTw7m/vA09Mqez4V8/DQochESs/myLoLnHz3xOjJl4PuehV4C X-Received: by 2002:a05:6a00:4b96:b0:6f3:8990:665c with SMTP id d2e1a72fcca58-705d712058cmr2696211b3a.18.1718369703411; Fri, 14 Jun 2024 05:55:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718369703; cv=pass; d=google.com; s=arc-20160816; b=FZRRADPns6a0v2EPmZWWiFd9taO5ljXLSMHzeheyrifhsI3XxbXl78eDeyLQCPBWtH I4cYmEefzkHEkmipAPmMml9dMVDU5QJKKtCKkQF4VwX08qqQDmKunbq+kecs6Bfw6aG9 yCR82sGyXGXBz6XBqRykPymgpjOvTqavPq/TOtIIhAnp1NHZHj2jwk6+9C4X5dsBptzh +aq395ccr05TyVCCuhSsoApH8PICsIHbpNCVTAW2MD9ZFmDc8slK/nzFD9ehx97Y+Tb3 9HZj0qjHEOMLn4CrbKpb0NLy7N2VjobJETAzQVpV09kDYwlvQeZrAe1OzMQwp00Oakxf syrg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:from :dkim-signature; bh=KkK/kPgUL4odHiBy6guZH3ikqbdzkjrt8yaE6xDHlz0=; fh=VV8jEf6vWtV6BtS3WiZal7Ew9loS79VUcC8IqTuBCBg=; b=rdMVt27/6nIr0wScZ6hU5+EJjlgSuDsMbTuFAPrsCdG3UzIc2GnWEa0JFfhhiG9lag vddiaCyW3K/sr0cVQyPBi4BiyJ9Yd7EjDLh+6NuJBzaYZ5pUY2QLhtf+fsee1mpcPqui IeAyK19XCGqxLtlUYgBsWLebWNAOJExJ0yOOxWVnejb4sYME7Z2PX7V0XdJtn71Hrh0s 2KPpI6Tcxk1XF49GWzhRccZpafla1SN9q8mvvxsKIUKGve94TMw+0vfaBxnr1KVRhKYc ViPhb5uaCfWo0oHS3BwxJAIumZORXrwX3KNowWL7irzD1QLS8ya415kEtNaJDXizXcwh /u8A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=cwjx2ORl; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-214905-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-214905-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id d2e1a72fcca58-705ccbc39d2si3634494b3a.368.2024.06.14.05.55.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 05:55:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-214905-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=cwjx2ORl; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-214905-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-214905-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id AAE52B20FC6 for ; Fri, 14 Jun 2024 12:41:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2CC8E199234; Fri, 14 Jun 2024 12:41:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="cwjx2ORl" Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) (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 A00AA196D8F for ; Fri, 14 Jun 2024 12:41:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718368901; cv=none; b=fHLEiiZbTZh8DHZAHu4w7vnxyJOdQZb2RP0oS5NnGFMscJyCtJjvuctkDJdV9Ne4YeYk0JRuFYrqSVMBPKMVfoQqduYWvSe744Z3/CkPROWpSL93pZSZroO/NYx2NSSHLeTrD5sfKM0b0+YF1JrhxUbvWaPnP2yoTqDc5CZDRV4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718368901; c=relaxed/simple; bh=5YUAy/v9vbOWgyn64F/ohClnfmw7OfyrVXzdrl7025U=; h=From:Subject:Date:Message-Id:MIME-Version:Content-Type:To:Cc; b=t9YJpXS0wgZPG9J92JaBSyRcueSWKVEY1/ouXYRkc0u7KJyqAaiu5SKUVCw2+Qcjmy6sQc2CesbcLFkVj5yQz44EqG/JhkcW4O8VlWFOkQHCyhRZhHST64ceCV8BZE+M37EJXrpGsJBi4GjoZ5Mgc/ir3AIl6FeBkvjp9W87iiE= 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=cwjx2ORl; arc=none smtp.client-ip=209.85.222.170 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 Received: by mail-qk1-f170.google.com with SMTP id af79cd13be357-797a7f9b552so134686885a.0 for ; Fri, 14 Jun 2024 05:41:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1718368898; x=1718973698; darn=vger.kernel.org; h=cc:to:content-transfer-encoding:mime-version:message-id:date :subject:from:from:to:cc:subject:date:message-id:reply-to; bh=KkK/kPgUL4odHiBy6guZH3ikqbdzkjrt8yaE6xDHlz0=; b=cwjx2ORlSyxrCeSIBhLQJeI+18ev5J6CUKQkK1iUpmh56NDrrJ4lZg2K84Q/MueNuc q4aoutYAddIBwIgoohqvpwwMKCol/U2HXe2++zeARZgkFq4gUWfKcCfS5tDao4G47knI CJMCWWDIJV5QxvQHS1MoODAxTWEEt94SMhVbE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718368898; x=1718973698; h=cc:to:content-transfer-encoding:mime-version:message-id:date :subject:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=KkK/kPgUL4odHiBy6guZH3ikqbdzkjrt8yaE6xDHlz0=; b=J+Tu1TZnDgzNSAaiUjB3kHEYtUOV5R6Q4ulUjc3gp4oKgP8hOfve3yvk4FCzvqoQ9M 5LOs1kzZViWg8AA3n9CqcIecmcSKLMIivtQYf+8aQ7Yk/xIvKdDLgI5doph6wbLEvsM7 KoLwhFY4pOhqJemAo4BLwr67Xglez5741AFxtLXftwxndu8zk1HNoy5HUKz9HfrfFCzq J0SwZYecbwjxGDxFZJuyaeelFAj5rCxY3y/MnSICHCIydWCtYOxiNYNIVkAS1MsQm32v 5t4Ldpru1FZyPMc385+HTzmXSjJqrghKYMvWktCOXLwHX59Z4Z8dhZY5Ek46tS/RUP6D Ll7g== X-Forwarded-Encrypted: i=1; AJvYcCXhkUhMXKGq2SzprWiMRLcEx+m82ue2mgCaIP5MQtXGxwcPw782EglGMuR0/udvNX1AtRfKGDfyW/vWjTeJWaXI5I8wRst5jDJw4JpW X-Gm-Message-State: AOJu0YywRhmGWqfFEqWs99zxkonUfyaovmwOJdctT/W6PrU+Ari3TMjC RyqvUUStftFL/+Bv4tZbQBohBD3bVjjZ2rGRcHsTydWrHOf0COxDWu+gUA6S5Q== X-Received: by 2002:ad4:551b:0:b0:6b0:67d0:ff76 with SMTP id 6a1803df08f44-6b2afcd2338mr23501166d6.26.1718368898477; Fri, 14 Jun 2024 05:41:38 -0700 (PDT) Received: from denia.c.googlers.com (123.178.145.34.bc.googleusercontent.com. [34.145.178.123]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b2a5c202e8sm17734056d6.50.2024.06.14.05.41.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 05:41:37 -0700 (PDT) From: Ricardo Ribalda Subject: [PATCH v6 0/4] uvcvideo: Attempt N to land UVC race conditions fixes Date: Fri, 14 Jun 2024 12:41:26 +0000 Message-Id: <20240614-guenter-mini-v6-0-7b7fdc3b21b3@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-B4-Tracking: v=1; b=H4sIAHY6bGYC/33PTWrEMAwF4KsMXtdF/o3dVe9RZhHbSmKYOGBPA mXI3UcUSktIuxJP8D2hB2tYMzb2dnmwiltueSkU7MuFxakvI/KcKDMJUoECz8cVyx0rn3PJ3Hl nRQCncRCMSOgb8lD7EidCZb3daDnldl/q59eJTdD4+KNtExy4lV0SEAeL3r7HqS5zXufXpY7sS l2b/M9L8mi1gGQ8JK1OvPr2GpQ0B6/IRx2iFYlegjOvf/vu4DV57b0xUXiHPZ548+OtEAdvyIP ugh3QJHDh4Pd9fwJY75PFsAEAAA== To: Mauro Carvalho Chehab Cc: Guenter Roeck , Tomasz Figa , Laurent Pinchart , Alan Stern , Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Paul , Ricardo Ribalda , Sakari Ailus , Sergey Senozhatsky X-Mailer: b4 0.13.0 Back in 2020 Guenter published a set of patches to fix some race conditions in UVC: https://lore.kernel.org/all/20200917022547.198090-5-linux@roeck-us.net/ That kind of race conditions are not only seen in UVC, but are a common seen in 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 lot off (all?) of the video_is_registered() checks in Guenter's patches. Besides those checks, there were some other valid races fixed in his patches. This patchset tries to fix the races still present in our code. Thanks! Signed-off-by: Ricardo Ribalda --- Changes in v6: Thanks Hans - s/uvc_queue_streamoff/uvc_queue_release/ - Link to v5: https://lore.kernel.org/r/20240611-guenter-mini-v5-0-047b6fe5d08b@chromium.org Changes in v5: Thanks Hans! - Refactor unregister as vb2_video_unregister_device - I have tested the first patch independently from the others, so it could be merged in two steps if needed. - Link to v4: https://lore.kernel.org/r/20240327-guenter-mini-v4-0-49955c198eae@chromium.org Changes in v4: Thanks Sergey and Guenter - Fix typos - Move location of mutex_init - Split patch to make the suspend change explicit - Link to v3: https://lore.kernel.org/r/20240325-guenter-mini-v3-0-c4bc61d84e03@chromium.org Changes in v3: Thanks Hans! - Stop streaming during uvc_unregister() - Refactor the uvc_status code - Link to v2: https://lore.kernel.org/r/20230309-guenter-mini-v2-0-e6410d590d43@chromium.org 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 --- Ricardo Ribalda (4): media: uvcvideo: Stop stream during unregister media: uvcvideo: Refactor the status irq API media: uvcvideo: Avoid race condition during unregister media: uvcvideo: Exit early if there is not int_urb drivers/media/usb/uvc/uvc_driver.c | 45 +++++++++++++++++++-------- drivers/media/usb/uvc/uvc_status.c | 62 +++++++++++++++++++++++++++++++++++--- drivers/media/usb/uvc/uvc_v4l2.c | 22 ++++---------- drivers/media/usb/uvc/uvcvideo.h | 10 +++--- 4 files changed, 103 insertions(+), 36 deletions(-) --- base-commit: b14257abe7057def6127f6fb2f14f9adc8acabdb change-id: 20230309-guenter-mini-89861b084ef1 Best regards, -- Ricardo Ribalda