Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp2218985ybc; Wed, 13 Nov 2019 10:48:59 -0800 (PST) X-Google-Smtp-Source: APXvYqwEmfBDduGjCajXeySYMnNyOGFWpWw3hTvMUyTOYccwimnBKOAmnOSk9RZDu7ev+LJkSSqJ X-Received: by 2002:a50:aad2:: with SMTP id r18mr5437335edc.44.1573670939772; Wed, 13 Nov 2019 10:48:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573670939; cv=none; d=google.com; s=arc-20160816; b=B3yrEL9R8iI5pm7gcMPaSvlAqdaPSCwrWCM4mxbSZHKXcXPI5fel24hf6dlABxQMSI +eWK2LMXRJcqteSVqwOiMVtZ8rvsVAaC/9cn1IRLxExfMIw2lwu8IwBH5uvamsFxCycw dCSdIqSB5wDCO+iCrdRls0G8qccTNzhGj6OxrNFR8oSl//A29iPu6NvF+YeEgJoBO+UB ab059rO7LGjA8puNislGWSgrisfmBm/NTfJtrSQ4G1UrDhVYnAcOEnm15/9w9Nl3KrbQ 6LyAVIMED2WZIve9FmN3baDeggyfZA7lClDcREaj6Yqu7aqMQs6WEA0wx4iThtSGwkW6 1y5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:in-reply-to :subject:cc:to:from:date; bh=g/iwXpfk485ueIXattaD/GI1XWqGPs7D3kHFzu/ujc0=; b=rcoGzbaRWR58sGvurWVOuKquOPs20yhlZWk09NlLA5OwVh2+MY5ehkDSBgZQsKUKVj nIHFsn2sDFvtFOn/HkYQhlY9vyC23k1V8+qcDCNGFzHyKKYdmRdTQDLst7TZImEBCJBU 5DBFh+cUat3SSY8DUkYgjhWaK68j/MeIwCLOphBRm9AqT9JeomESHELMoNcDpfhCx68e QSLWflgeqfDsySD6K/WW1NpjdbR7OKO4qW0883tAUOp/SIaHcrGYGHDgTk6x81SXT0fP muug9v84VuQNdRp2wRFPXWaMHB2heBDu+8eM07PKUN4IZ3WHT2B/hWob2eaLzrl590wr 8h3g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id nq5si1732725ejb.161.2019.11.13.10.48.33; Wed, 13 Nov 2019 10:48:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727699AbfKMPg1 (ORCPT + 99 others); Wed, 13 Nov 2019 10:36:27 -0500 Received: from iolanthe.rowland.org ([192.131.102.54]:41306 "HELO iolanthe.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1726335AbfKMPg0 (ORCPT ); Wed, 13 Nov 2019 10:36:26 -0500 Received: (qmail 2521 invoked by uid 2102); 13 Nov 2019 10:36:25 -0500 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 13 Nov 2019 10:36:25 -0500 Date: Wed, 13 Nov 2019 10:36:25 -0500 (EST) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: Peter Chen cc: Michael Olbrich , "linux-usb@vger.kernel.org" , Felipe Balbi , Greg Kroah-Hartman , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] usb: gadget: composite: split spinlock to avoid recursion In-Reply-To: <20191113063414.GA30608@b29397-desktop> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 13 Nov 2019, Peter Chen wrote: > On 19-11-12 10:33:18, Michael Olbrich wrote: > > 'delayed_status' and 'deactivations' are used completely independent but > > they share the same spinlock. This can result in spinlock recursion: > > > > BUG: spinlock recursion on CPU#1, uvc-gadget/322 > > lock: 0xffffffc0570364e0, .magic: dead4ead, .owner: uvc-gadget/322, .owner_cpu: 1 > > CPU: 1 PID: 322 Comm: uvc-gadget Tainted: G C O 5.3.0-20190916-1+ #55 > > Hardware name: XXXXX (DT) > > Call trace: > > dump_backtrace+0x0/0x178 > > show_stack+0x24/0x30 > > dump_stack+0xc0/0x104 > > spin_dump+0x90/0xa0 > > do_raw_spin_lock+0xd8/0x108 > > _raw_spin_lock_irqsave+0x40/0x50 > > composite_disconnect+0x2c/0x80 > > usb_gadget_disconnect+0x84/0x150 > > usb_gadget_deactivate+0x64/0x120 > > usb_function_deactivate+0x70/0x80 > > uvc_function_disconnect+0x20/0x58 > > uvc_v4l2_release+0x34/0x90 > > v4l2_release+0xbc/0xf0 > > __fput+0xb0/0x218 > > ____fput+0x20/0x30 > > task_work_run+0xa0/0xd0 > > do_notify_resume+0x2f4/0x340 > > work_pending+0x8/0x14 > > > > Fix this by using separate spinlocks. > > This issue may be introduced by 0a55187a1ec8c ("USB: gadget core: Issue > ->disconnect() callback from usb_gadget_disconnect()"), which adds > gadget's disconnect at usb_gadget_disconnect. Add Alan, if he is Ok > with your patch, you may cc to stable tree. I wasn't aware of the dual usage of that lock in the composite core (and 0a55187a1ec8c touches only the gadget core, not composite.c). In any case, I don't have a good feel for how the locking is supposed to work in the composite core. This is really something Felipe should look at. Would a better fix be to change usb_function_deactivate() so that it doesn't hold the lock while calling usb_gadget_deactivate()? Maybe increment cdev->deactivations unconditionally before dropping the lock (for mutual exclusion) and then decrement it again if the call fails? Alan Stern