Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp7052866rwl; Mon, 9 Jan 2023 17:17:23 -0800 (PST) X-Google-Smtp-Source: AMrXdXtmdzwEsRujEI5v/1zzSVhTBO9YS8uForlnoz7mE5aWvyXp3vTDkZCbnn0Q1b7ALmQYT7kI X-Received: by 2002:a05:6a21:3a94:b0:9d:efbe:52c3 with SMTP id zv20-20020a056a213a9400b0009defbe52c3mr14920215pzb.51.1673313443546; Mon, 09 Jan 2023 17:17:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673313443; cv=none; d=google.com; s=arc-20160816; b=pWburlIqs7ju3rUD8FO3maUjGlZ4uOGW9Zxz9h+M3pCqRem9rFVZtC7pp6dPYq0+QX v7MlRdiP5utODUx2GDnySu4FqbhmanhiOrPmrEOZPPouQEfUuso1h5nq4WKA8u7fKpwR ar0gEcLKFaDKvEwPIN0IL3f8dYVuv5hzq1//rzKyYBjlGhDAoHoAeaXY7qxgWxqUNffq BBSGGU4VlhC8J/qhOj0ng57a3ES3FJ9W4fnFhkPwiUXKMhYz+bMNm7aD3WqytQH9XnHn SUd9JE0s0QfBTnDeOzJlg/bKt1Ie6AYTv0u0r4Bde0+T26GVjTgBzCvuiXozza58IrHI HeHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=W125sPn+8wBy0FyBRg+kOOWV1bQbHFxqGG0xZrDFLRI=; b=W6W9lFRF0JJglInpUE5qMDh3UKuOw7FubFwinHJLC8ErfS2BEJGNAnkT4YQfvjAkar OYqanJz63AXv8k4fK6uLrHROKtFuci4Y0n4HL6SQYhQFifxRdXjsNpWpD0VXBdOVm8K5 /Oog60+zIblesJSVfOwiVkHdLNfJ+40WZTe7Z1EYaA1D9YuRpGp69YmAjm+FlGN1Edzr ztQoAm+u0EdMw+7hni8X46MW60UXQEh05zO8v7coLQLL96Cw7/UDct2fEbPHsVm1og9m 38LPL4vKeChvONsIqCR1/K1D8QgMm92QUvI6JCY/ByavIfHXoJB/bTO9eA3RUU2/MZzz m3ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Jk1pzHwJ; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 140-20020a630092000000b004ad157c46bbsi9549356pga.649.2023.01.09.17.17.17; Mon, 09 Jan 2023 17:17:23 -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=Jk1pzHwJ; 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 S229706AbjAJBHT (ORCPT + 53 others); Mon, 9 Jan 2023 20:07:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229545AbjAJBHR (ORCPT ); Mon, 9 Jan 2023 20:07:17 -0500 Received: from mail-io1-xd34.google.com (mail-io1-xd34.google.com [IPv6:2607:f8b0:4864:20::d34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0678B6334 for ; Mon, 9 Jan 2023 17:07:15 -0800 (PST) Received: by mail-io1-xd34.google.com with SMTP id b192so5427538iof.8 for ; Mon, 09 Jan 2023 17:07:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=W125sPn+8wBy0FyBRg+kOOWV1bQbHFxqGG0xZrDFLRI=; b=Jk1pzHwJRwpVAuHVNiRwDUvE3ZYpG7NTHiabA1vQ2XDS5EvvuIu1HmZYGRwtJB58OF 0Rv+0uU4GgnKc52HKOklGhY7RoXGqGrT9wwJ2rCL7fdmcNlTz2qsV4W4/J+JNMEHd8Lp fpGLbgJ9uo5U2vwnmMxELNpDzXvq4xdL+TszY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=W125sPn+8wBy0FyBRg+kOOWV1bQbHFxqGG0xZrDFLRI=; b=EKkczeomRFGYy5+ICyx1FgrTuDrp4LDh08VgGNk5u51M3sLFF0p7D5WTAvUy5gIApW PTVRwGbUyH3ifnMGTqyS/VvwXW+tM+sSUUYJGNQQ1usHuZ/GClBTTLtYrOKuhwYyVnF0 NIzrGaed4KYWMfvmsDq6uS447CcXvKVILUBg0PsZ1EQrxoS2DTpG6f60JrlyMmG2KiOr MP3vaOLuKRy3Mx8ko9oEudJCWr95hQpnwQKQdP1fD5kxZy2dFfOb3s0cui4BgeUJF0Uk a9gZRHE2WozGKXPaylWTC7I5o4RRjVcOhwhAmkUMPCitiAP1y1CVEFk45Tk8pFImbidu 0dzg== X-Gm-Message-State: AFqh2kr1PoeFdETcTMAzIjSBeyXCzyWMmBtY07wCH9ldJghxm8V7tPbI Q+zzhA1o3E39JjfO1pu/xqoSRg== X-Received: by 2002:a5e:db42:0:b0:6e2:dc1e:527b with SMTP id r2-20020a5edb42000000b006e2dc1e527bmr40263547iop.19.1673312834308; Mon, 09 Jan 2023 17:07:14 -0800 (PST) Received: from localhost (30.23.70.34.bc.googleusercontent.com. [34.70.23.30]) by smtp.gmail.com with UTF8SMTPSA id x12-20020a026f0c000000b0039e60720706sm3088317jab.25.2023.01.09.17.07.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Jan 2023 17:07:13 -0800 (PST) Date: Tue, 10 Jan 2023 01:07:13 +0000 From: Matthias Kaehlcke To: Stefan Wahren Cc: Greg Kroah-Hartman , Johan Hovold , linux-usb@vger.kernel.org, Alexander Stein , Icenowy Zheng , Douglas Anderson , stable@vger.kernel.org, linux-kernel@vger.kernel.org, Ravi Chandra Sadineni Subject: Re: [PATCH 2/2] usb: misc: onboard_hub: Move 'attach' work to the driver Message-ID: References: <20230105230119.1.I75494ebee7027a50235ce4b1e930fa73a578fbe2@changeid> <20230105230119.2.I16b51f32db0c32f8a8532900bfe1c70c8572881a@changeid> <09d76f45-9dfe-19a0-33ec-badaac280772@i2se.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <09d76f45-9dfe-19a0-33ec-badaac280772@i2se.com> 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 On Mon, Jan 09, 2023 at 09:19:02PM +0100, Stefan Wahren wrote: > Hi Matthias, > > Am 09.01.23 um 18:40 schrieb Matthias Kaehlcke: > > On Sun, Jan 08, 2023 at 11:47:13AM +0100, Stefan Wahren wrote: > > > Am 07.01.23 um 18:23 schrieb Stefan Wahren: > > > > Hi Matthias, > > > > > > > > Am 06.01.23 um 00:03 schrieb Matthias Kaehlcke: > > > > > Currently each onboard_hub platform device owns an 'attach' work, > > > > > which is scheduled when the device probes. With this deadlocks > > > > > have been reported on a Raspberry Pi 3 B+ [1], which has nested > > > > > onboard hubs. > > > > > > > > > > The flow of the deadlock is something like this (with the onboard_hub > > > > > driver built as a module) [2]: > > > > > > > > > > - USB root hub is instantiated > > > > > - core hub driver calls onboard_hub_create_pdevs(), which creates the > > > > >    'raw' platform device for the 1st level hub > > > > > - 1st level hub is probed by the core hub driver > > > > > - core hub driver calls onboard_hub_create_pdevs(), which creates > > > > >    the 'raw' platform device for the 2nd level hub > > > > > > > > > > - onboard_hub platform driver is registered > > > > > - platform device for 1st level hub is probed > > > > >    - schedules 'attach' work > > > > > - platform device for 2nd level hub is probed > > > > >    - schedules 'attach' work > > > > > > > > > > - onboard_hub USB driver is registered > > > > > - device (and parent) lock of hub is held while the device is > > > > >    re-probed with the onboard_hub driver > > > > > > > > > > - 'attach' work (running in another thread) calls driver_attach(), which > > > > >     blocks on one of the hub device locks > > > > > > > > > > - onboard_hub_destroy_pdevs() is called by the core hub driver when one > > > > >    of the hubs is detached > > > > > - destroying the pdevs invokes onboard_hub_remove(), which waits for the > > > > >    'attach' work to complete > > > > >    - waits forever, since the 'attach' work can't acquire the device > > > > > lock > > > > > > > > > > Use a single work struct for the driver instead of having a work struct > > > > > per onboard hub platform driver instance. With that it isn't necessary > > > > > to cancel the work in onboard_hub_remove(), which fixes the deadlock. > > > > > The work is only cancelled when the driver is unloaded. > > > > i applied both patches for this series on top of v6.1 > > > > (multi_v7_defconfig), but usb is still broken on Raspberry Pi 3 B+ > > Thanks for testing. > > > > > here is the hung task output: > > > > > > [  243.682193] INFO: task kworker/1:0:18 blocked for more than 122 seconds. > > > [  243.682222]       Not tainted 6.1.0-00002-gaa61d98d165b #2 > > > [  243.682233] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables > > > this message. > > > [  243.682242] task:kworker/1:0     state:D stack:0     pid:18 ppid:2 > > > flags:0x00000000 > > > [  243.682267] Workqueue: events onboard_hub_attach_usb_driver > > > [onboard_usb_hub] > > > [  243.682317]  __schedule from schedule+0x4c/0xe0 > > > [  243.682345]  schedule from schedule_preempt_disabled+0xc/0x10 > > > [  243.682367]  schedule_preempt_disabled from > > > __mutex_lock.constprop.0+0x244/0x804 > > > [  243.682394]  __mutex_lock.constprop.0 from __driver_attach+0x7c/0x188 > > > [  243.682421]  __driver_attach from bus_for_each_dev+0x70/0xb0 > > > [  243.682449]  bus_for_each_dev from onboard_hub_attach_usb_driver+0xc/0x28 > > > [onboard_usb_hub] > > > [  243.682494]  onboard_hub_attach_usb_driver [onboard_usb_hub] from > > > process_one_work+0x1ec/0x4d0 > > > [  243.682534]  process_one_work from worker_thread+0x50/0x540 > > > [  243.682559]  worker_thread from kthread+0xd0/0xec > > > [  243.682582]  kthread from ret_from_fork+0x14/0x2c > > > [  243.682600] Exception stack(0xf086dfb0 to 0xf086dff8) > > > [  243.682615] dfa0:                                     00000000 00000000 > > > 00000000 00000000 > > > [  243.682631] dfc0: 00000000 00000000 00000000 00000000 00000000 00000000 > > > 00000000 00000000 > > > [  243.682646] dfe0: 00000000 00000000 00000000 00000000 00000013 00000000 > > > [  243.682692] INFO: task kworker/1:2:82 blocked for more than 122 seconds. > > > [  243.682703]       Not tainted 6.1.0-00002-gaa61d98d165b #2 > > > [  243.682713] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables > > > this message. > > > [  243.682721] task:kworker/1:2     state:D stack:0     pid:82 ppid:2 > > > flags:0x00000000 > > > [  243.682741] Workqueue: events_power_efficient hub_init_func2 > > > [  243.682764]  __schedule from schedule+0x4c/0xe0 > > > [  243.682785]  schedule from schedule_preempt_disabled+0xc/0x10 > > > [  243.682808]  schedule_preempt_disabled from > > > __mutex_lock.constprop.0+0x244/0x804 > > > [  243.682833]  __mutex_lock.constprop.0 from hub_activate+0x584/0x8b0 > > > [  243.682859]  hub_activate from process_one_work+0x1ec/0x4d0 > > > [  243.682883]  process_one_work from worker_thread+0x50/0x540 > > > [  243.682907]  worker_thread from kthread+0xd0/0xec > > > [  243.682927]  kthread from ret_from_fork+0x14/0x2c > > > [  243.682944] Exception stack(0xf1509fb0 to 0xf1509ff8) > > > [  243.682958] 9fa0:                                     00000000 00000000 > > > 00000000 00000000 > > > [  243.682974] 9fc0: 00000000 00000000 00000000 00000000 00000000 00000000 > > > 00000000 00000000 > > > [  243.682988] 9fe0: 00000000 00000000 00000000 00000000 00000013 00000000 > > > [  243.683023] INFO: task kworker/1:4:257 blocked for more than 122 seconds. > > > [  243.683034]       Not tainted 6.1.0-00002-gaa61d98d165b #2 > > > [  243.683043] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables > > > this message. > > > [  243.683051] task:kworker/1:4     state:D stack:0     pid:257 ppid:2 > > > flags:0x00000000 > > > [  243.683071] Workqueue: events_power_efficient hub_init_func2 > > > [  243.683092]  __schedule from schedule+0x4c/0xe0 > > > [  243.683113]  schedule from schedule_preempt_disabled+0xc/0x10 > > > [  243.683135]  schedule_preempt_disabled from > > > __mutex_lock.constprop.0+0x244/0x804 > > > [  243.683160]  __mutex_lock.constprop.0 from hub_activate+0x584/0x8b0 > > > [  243.683184]  hub_activate from process_one_work+0x1ec/0x4d0 > > > [  243.683209]  process_one_work from worker_thread+0x50/0x540 > > > [  243.683233]  worker_thread from kthread+0xd0/0xec > > > [  243.683253]  kthread from ret_from_fork+0x14/0x2c > > > [  243.683270] Exception stack(0xf09d9fb0 to 0xf09d9ff8) > > > [  243.683283] 9fa0:                                     00000000 00000000 > > > 00000000 00000000 > > > [  243.683299] 9fc0: 00000000 00000000 00000000 00000000 00000000 00000000 > > > 00000000 00000000 > > > [  243.683313] 9fe0: 00000000 00000000 00000000 00000000 00000013 00000000 > > Does commenting the following help: > > > > while (work_busy(&attach_usb_driver_work) & WORK_BUSY_RUNNING) > > msleep(10); > > > > ? > Yes, it does. I restarted the board multiple times and it never hang :-) Thanks again for testing! I'll post a version without that loop, which shouldn't be needed as per the rationale in my previous mail.