Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp155464pxt; Wed, 4 Aug 2021 08:03:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjZH0gCysCfcdw8mbhiSxC53zq3G9or30YXHlHhuIdaxh2Q1/KKdHeAqZJ4RvBzsV3IM7l X-Received: by 2002:a05:6402:7d3:: with SMTP id u19mr205725edy.188.1628089417627; Wed, 04 Aug 2021 08:03:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628089417; cv=none; d=google.com; s=arc-20160816; b=FalbK59gOkRDyaYZXDdX90iTtj6yo82u7yvFOXrss/MEomrjJzFny9IrmfxxEiDB8P xdXYq0pPYUENg2XxTI9POpMNma3DaK/g0lp5XeCoqP3DiCbmRG3gQ2hHYH870gzp21Wq UXH7SuCJLbhXtGj+ErQtdIyC45zYjhUiQN4u4ZKUTaMjiLKA26MA8vMaWs9L4S7QGgY1 noPd/lmwDI3xbXBsBSN8JcKxLbKwdIaAkc1U2moJqD7sWar9M0bghCtVoYeOncndI/7E Yw+h6x8siGk2/r9LESKbxZybAlKMciLfaoT0R2Qo9o/JWvCQMrH5ZlkNK7mDyNeViEZs YBOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=3wAPLTNTz+K6PssPvD29DSKcaFgyHs1tGU9uPv0wDys=; b=Znu0b6it+rgZhL0us6ufHaY5xgnT+YPXcE3BJ0MFsufoZMixa177R7oMgK4eWtIPEV w4/QkhgHxYqPB+vR5MZYqA8/YthPEYSOKWG2v4wNS+u1v94jay558xjSlhoOhucWH0i3 db8dWZ1bt97mSIib5CvMsQd4wxg8qk8VuQEYxNIRx6OnnGvy33AGW56wNliFUbw3i2Pk 2JNH5K4xiOVo7/4v6B7YiUBriZDTa9w2cfFHNe23uQDiSND9Wu2v/f5puu6yFHWyMt89 w4MYLJZgtASwLIXyU7f+Ka5fRNfXghZVOuRZwIGGzq4LvKkvyZ6lMCUdLX2/36nQO28Y eA8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=t5nOOzKI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dn7si2346467edb.408.2021.08.04.08.03.11; Wed, 04 Aug 2021 08:03:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=t5nOOzKI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238134AbhHDOmj (ORCPT + 99 others); Wed, 4 Aug 2021 10:42:39 -0400 Received: from smtp-relay-canonical-0.canonical.com ([185.125.188.120]:59888 "EHLO smtp-relay-canonical-0.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237523AbhHDOmj (ORCPT ); Wed, 4 Aug 2021 10:42:39 -0400 Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPS id E3CB63F349 for ; Wed, 4 Aug 2021 14:42:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1628088145; bh=3wAPLTNTz+K6PssPvD29DSKcaFgyHs1tGU9uPv0wDys=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=t5nOOzKIA2o6Rgd0nulKNvf3B/Ubf/sIK6NtMKr8ljPhuZqB+t49k/GGjp2b8kHO0 ThBFJHcYCxvzft7lTvo07iRC3nGaiBw52igrmR92kp/uvLqyAu+vEhmpADFe9bAPRX GYAROzCmx/Mh+uLG9S619/N62bDDMDHa1SNx6riHwNrqnX4qNS4Y4uj54RkN+xtojT UZFVxVJKrIw7vxzQRgDgtl/Af6G4geRgdjB3jkCw1NanCVrFq5gSSdQ6VerMDFSjfQ GujC9qZa1F/0oOvp3txlMLKN9u0v0mmxokSCpBHRAzlY7kHgrQl6nWPhS1ekWHZ3hN Fop2jdU7Rp/pw== Received: by mail-ed1-f69.google.com with SMTP id u4-20020a50eac40000b02903bddc52675eso1404844edp.4 for ; Wed, 04 Aug 2021 07:42:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3wAPLTNTz+K6PssPvD29DSKcaFgyHs1tGU9uPv0wDys=; b=p+HR+p+dpLWP9TMCmJcUhn7MCHz5zQCl4DjPzlYCx8chuMaU85y48fbmfhgFGx6Nra cYBc4uk2dINJBi3g3u7ZJSXL5PKmJaR+TlcxhbJL1srYEBLIpHpCO4w7bn5tq5yqEPXB R+GRai+FgOvRlMbpjq2QRHMGEvJErA4EdKg0CpYePCD6QYW+4CGLzeQzsER66aZBKPK7 ZQ6WNi451Vpy8C+yDNDEisRr5pwWTsbr03nraqT2w60v+eQvGm0ZlBfilkcbLfUOlT1o 1zbQAnre5zCgt+hRAJv4ir6KIOhD6yyKYSijMGDp7nApaH1JMq/MPZXJKrD6wAj4SV6Z nvPQ== X-Gm-Message-State: AOAM532U4jbBSl55jPd/sn32/tTSBD6rvFHLEiyQFu70cVoEYl9bjsgF zP+nOW9vq72D0Ndml5XlnsJOjM4tRnoJ21Z8ORwXIoJexC04DujMeYWLghv6xwoxCj6VWjkkSGh BH+35dgG8FCZXKLrjJG4aU6YSnElVjch+P4LwC+OmNpSGoaRkZplWsDVbVg== X-Received: by 2002:a17:907:9d2:: with SMTP id bx18mr9112343ejc.117.1628088145477; Wed, 04 Aug 2021 07:42:25 -0700 (PDT) X-Received: by 2002:a17:907:9d2:: with SMTP id bx18mr9112321ejc.117.1628088145254; Wed, 04 Aug 2021 07:42:25 -0700 (PDT) MIME-Version: 1.0 References: <20210514071452.25220-1-kai.heng.feng@canonical.com> <576B26FD-81F8-4632-82F6-57C4A7C096C4@holtmann.org> <8735ryk0o7.fsf@baylibre.com> <87y29o58su.fsf@baylibre.com> <87a6lzx7jf.fsf@baylibre.com> In-Reply-To: <87a6lzx7jf.fsf@baylibre.com> From: Kai-Heng Feng Date: Wed, 4 Aug 2021 22:42:09 +0800 Message-ID: Subject: Re: [PATCH v2] Bluetooth: Shutdown controller after workqueues are flushed or cancelled To: Mattijs Korpershoek Cc: Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , "David S. Miller" , Jakub Kicinski , Fabien Parent , Sean Wang , "open list:BLUETOOTH SUBSYSTEM" , "open list:NETWORKING [GENERAL]" , open list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 3, 2021 at 4:21 PM Mattijs Korpershoek wrote: > > Hi Kai-Heng, > > Kai-Heng Feng writes: > > > Hi Mattijs, > > > > On Fri, Jul 30, 2021 at 7:40 PM Mattijs Korpershoek > > wrote: > >> > >> Hi Kai-Heng, > > > > [snipped] > > > >> Thank you for your help. Sorry I did not post the logs previously. > >> > >> dmesg: https://pastebin.com/tpWDNyQr > >> ftrace on btmtksdio: https://pastebin.com/jmhvmwUw > > > > Seems like btmtksdio needs shudown() to be called before flush(). > > Since the order was there for a very long time, changing the calling > > order indeed can break what driver expects. > > Can you please test the following patch: > > diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c > > index 2560ed2f144d..a61e610a400c 100644 > > --- a/net/bluetooth/hci_core.c > > +++ b/net/bluetooth/hci_core.c > > @@ -1785,6 +1785,14 @@ int hci_dev_do_close(struct hci_dev *hdev) > > aosp_do_close(hdev); > > msft_do_close(hdev); > > > > + if (!hci_dev_test_flag(hdev, HCI_UNREGISTER) && > > + !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && > > + test_bit(HCI_UP, &hdev->flags)) { > > + /* Execute vendor specific shutdown routine */ > > + if (hdev->shutdown) > > + hdev->shutdown(hdev); > > + } > > + > > if (hdev->flush) > > hdev->flush(hdev); > > > > @@ -1798,14 +1806,6 @@ int hci_dev_do_close(struct hci_dev *hdev) > > clear_bit(HCI_INIT, &hdev->flags); > > } > > > > - if (!hci_dev_test_flag(hdev, HCI_UNREGISTER) && > > - !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && > > - test_bit(HCI_UP, &hdev->flags)) { > > - /* Execute vendor specific shutdown routine */ > > - if (hdev->shutdown) > > - hdev->shutdown(hdev); > > - } > > - > > /* flush cmd work */ > > flush_work(&hdev->cmd_work); > > Thanks for the patch and your help. > I've tried it, but it seems that it does not improve for me. > I'm still observing: > > i500-pumpkin login: root > root@i500-pumpkin:~# hciconfig hci0 up > Can't init device hci0: Connection timed out (110) > > Logs for this session: > dmesg: https://pastebin.com/iAFk5Tzi > ftrace: https://pastebin.com/kEMWSYrE Thanks for the testing! What about moving the shutdown() part right after hci_req_sync_lock() so tx/rx can still work: diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 2560ed2f144d4..be3113fb7d4b0 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -1727,6 +1727,14 @@ int hci_dev_do_close(struct hci_dev *hdev) hci_request_cancel_all(hdev); hci_req_sync_lock(hdev); + if (!hci_dev_test_flag(hdev, HCI_UNREGISTER) && + !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && + test_bit(HCI_UP, &hdev->flags)) { + /* Execute vendor specific shutdown routine */ + if (hdev->shutdown) + hdev->shutdown(hdev); + } + if (!test_and_clear_bit(HCI_UP, &hdev->flags)) { cancel_delayed_work_sync(&hdev->cmd_timer); hci_req_sync_unlock(hdev); @@ -1798,14 +1806,6 @@ int hci_dev_do_close(struct hci_dev *hdev) clear_bit(HCI_INIT, &hdev->flags); } - if (!hci_dev_test_flag(hdev, HCI_UNREGISTER) && - !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && - test_bit(HCI_UP, &hdev->flags)) { - /* Execute vendor specific shutdown routine */ - if (hdev->shutdown) - hdev->shutdown(hdev); - } - /* flush cmd work */ flush_work(&hdev->cmd_work); > > > > > > Kai-Heng > > > >> > >> Mattijs > >> > > >> > Kai-Heng > >> > > >> >> > >> >> Thanks, > >> >> Mattijs Korpershoek > >> >> > >> >> > >> >> > > >> >> > Regards > >> >> > > >> >> > Marcel