From patchwork Thu Jan 4 21:50:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avichal Rakesh X-Patchwork-Id: 185155 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5888251dyb; Thu, 4 Jan 2024 13:50:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IH2t0tQJn6oK8gpt2nyAnlc0EYyakpfIqFG+8K3WgCepJtYgLJvYgL19w/OL//3omWzXY3M X-Received: by 2002:a17:903:110f:b0:1d4:2650:9366 with SMTP id n15-20020a170903110f00b001d426509366mr1565883plh.42.1704405050213; Thu, 04 Jan 2024 13:50:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704405050; cv=none; d=google.com; s=arc-20160816; b=HO7KzPBN6xFWxBgKuyxFbHW8ANCIwwuZgsktnKDh4Q6mT9KRSieyKNFKUsrEVpehE1 coM5Dhy4ukgXaeRJHvzIgHKoNCa6EerBuEAFyRpRegWPlEWf91u0v8urxY0egmUWMZIU Qj0w6HHu1yvBz7D8Yr0w+qKKWXnozun8ESA6VYdE7hT7m9nHxqf+1cenaaycfTXAW/GL MpnPZBKNOwtklODnppZ0L+D8ufI+ZJOndy4XDF/NvbydU6zEe7zcmjjM+lhvG++pFDH7 Wn21DAV4fcrVnbOrNaM5qLHqPwfAUPj+NxHN8Vni9HoPn93WhyIWVjcKk3aWPczF7HzY 6d3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=w5MKHKztC7x8oMRAwxikjHpMa6UtBIIOu9HjDctnSZc=; fh=qphTbyYaxSNZydGmCtSXvlfL12x+ngk+HsUTd0fNDM8=; b=MgQok/0TSE+G0PY+eh7oYY6h7EaC9sYWIcNYDjbeP1RE4Tr8kM+YYRqFy8eM284d/u 2acQBOkfKjdxl+uBtUrRereNwJLeWn/TS67nK+vVn6amjl50gAKM1JI5mitbgyJCBWPM jneGzUklYnm0TvMMACSVb3cg6QQoB0YhtQtvIWq+E13g1gwadtHLyzoP5amZSSrQ662o jaLlEpUDBalJulzboNsyCc4hPow7myCXZtopKATmrtkI0f6MSicRidH4nLv5zp41HCdm yiyCE3UaBN6WqmXPfK50K1NQypqiGjwItQOFHyQ/gSt/XfGQT+EUvL3qJ4H6EXy2Q41a FdOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=gXVti8pJ; spf=pass (google.com: domain of linux-kernel+bounces-17255-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17255-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id q207-20020a632ad8000000b005cdf8bb3ffdsi222082pgq.162.2024.01.04.13.50.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 13:50:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17255-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=gXVti8pJ; spf=pass (google.com: domain of linux-kernel+bounces-17255-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17255-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id E5C5D28709C for ; Thu, 4 Jan 2024 21:50:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DBF212C870; Thu, 4 Jan 2024 21:50:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="gXVti8pJ" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 0DB792C871 for ; Thu, 4 Jan 2024 21:50:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--arakesh.bounces.google.com Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-28c05e74e36so982982a91.0 for ; Thu, 04 Jan 2024 13:50:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704405017; x=1705009817; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=w5MKHKztC7x8oMRAwxikjHpMa6UtBIIOu9HjDctnSZc=; b=gXVti8pJDnBaztizqwCBnrrOGp3l+lNkHIDaIfOu4+f4Q8RoTqLwcsV2vE9YaExgCp nAfvCMe9z6iK1EW5yFFJu4YezqjFHn6SqCc4sQKLzgcDxRkKDOIs3Crk7cfU8+XiRUfl sPr964entFWYV+EvUXIf1nSveBPiZ3q7ghTegEenQ78LAviL5CuLKdx5MaA63IAYVEm7 Ut2U0a8KTipMLVIxXAqt/Tc6NLbBzjhUxled52FovWam+eECJD8rtf9Y3lbiz4bJJO5r 89SJHv48De5Ad2C5UQzAPwvMXbIVhnF8maFwC4+aU4OYqPUuQrwqsvhxyO+zrAlAexwT /YPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704405017; x=1705009817; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=w5MKHKztC7x8oMRAwxikjHpMa6UtBIIOu9HjDctnSZc=; b=c6FQkaxkNsyaikBbh3wL3eOb8zmKEAB6rrgnCY5dUwRWHSFtNrlAX5B72GR2NbRbNO BR1Ao4j69aFMK8p0ViSnBqtnVmaTC4WmpNZtGMr2E1xE/p0MEgSCy50vAcqP83naR/db 7JRtFM2zuC5BZyMRUE14gYuPRRDVwVgj2Wd23d0HGn/O+SZfhivXoNeuh2YX5EM61YVH AN0g1Gu1LFt1lI6Q2MPQdH/sSpgmR4JPGiVSp4lioY9IQ/ooR/XOtmjVl1CKIo1LkGRV 0hv4VHIP2RxCSoQ/JPbmkIiv69kBkNDlmMUGQnMCyxeIdrqiiKP0NgKp4niBcQzylrva ejQA== X-Gm-Message-State: AOJu0YzIE+myfDhk6NQepiEybH+kYdUxEECCdrRtwUb0Zu9+NP6nau7M l3hgOJnXlt9nWFxoWaIeJkqWIV2rFAY9aBeXEm8= X-Received: from hi-h2o-specialist.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:3cef]) (user=arakesh job=sendgmr) by 2002:a17:90b:33ce:b0:28b:e0cd:64a4 with SMTP id lk14-20020a17090b33ce00b0028be0cd64a4mr13149pjb.3.1704405017283; Thu, 04 Jan 2024 13:50:17 -0800 (PST) Date: Thu, 4 Jan 2024 13:50:09 -0800 In-Reply-To: <20240104215009.2252452-1-arakesh@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20231215210746.821494-1-arakesh@google.com> <20240104215009.2252452-1-arakesh@google.com> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Message-ID: <20240104215009.2252452-2-arakesh@google.com> Subject: [PATCH v2 2/2] usb: gadget: uvc: Remove nested locking From: Avichal Rakesh To: arakesh@google.com, gregkh@linuxfoundation.org Cc: dan.scally@ideasonboard.com, etalvala@google.com, jchowdhary@google.com, laurent.pinchart@ideasonboard.com, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785383626649893460 X-GMAIL-MSGID: 1787198229974928260 When handling error status from uvcg_video_usb_req_queue, uvc_video_complete currently calls uvcg_queue_cancel with video->req_lock held. uvcg_queue_cancel internally locks queue->irqlock, which nests queue->irqlock inside video->req_lock. This isn't a functional bug at the moment, but does open up possibilities for ABBA deadlocks in the future. This patch fixes the accidental nesting by dropping video->req_lock before calling uvcg_queue_cancel. Fixes: 6acba0345b68 ("usb:gadget:uvc Do not use worker thread to pump isoc usb requests") Signed-off-by: Avichal Rakesh --- v1 -> v2: Add "Fixes" tag. drivers/usb/gadget/function/uvc_video.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) -- 2.43.0.472.g3155946c3a-goog diff --git a/drivers/usb/gadget/function/uvc_video.c b/drivers/usb/gadget/function/uvc_video.c index 7f18dc471be3..dd3241fc6939 100644 --- a/drivers/usb/gadget/function/uvc_video.c +++ b/drivers/usb/gadget/function/uvc_video.c @@ -469,13 +469,15 @@ uvc_video_complete(struct usb_ep *ep, struct usb_request *req) * Put request back in req_free for it to be cleaned * up later. */ - uvcg_queue_cancel(queue, 0); list_add_tail(&to_queue->list, &video->req_free); } } else { uvc_video_free_request(ureq, ep); + ret = 0; } spin_unlock_irqrestore(&video->req_lock, flags); + if (ret < 0) + uvcg_queue_cancel(queue, 0); } static int