Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3297698pxt; Mon, 9 Aug 2021 23:38:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxF+F9NpRMEYsGUvNm9Qvdq2+0nrfdiZR/GPPIDlTWOSpE/FF29duyKcqHBdtd/XaT1w7ya X-Received: by 2002:a17:906:d20a:: with SMTP id w10mr27075808ejz.426.1628577516800; Mon, 09 Aug 2021 23:38:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628577516; cv=none; d=google.com; s=arc-20160816; b=pUxRAdP+4OIxjQROqTFnF13ZsO6JGUnUx8rG/4987Q2Xg9BoTn94nCr7jvuA/W5sSQ VSgmcQOaofsH5GMJAaLquKGjHSrt1s7OaXiUlUj3/vVTFZCC1Z1I3EFkQFEy0MaDy6Up UWejuwRHU2ETDNPTuugxr6Xd0Ld8oJXnQ1iX2OWebGtHIrgCN7BMX7Jye8EXSJfXXbqV foh/nqfNOaKlG06NGIhP/w66PZULq33v1wM1/Rd7SLiLSUKaWvXtOrcpXYhYnFY3PQKo G5DFMjSn2gsjVWZpK+dF6KWAz4z6SJnHogYVHnnD4zpcaMVYGsWV9dzUsKl1tjzg0xX6 9j0g== 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=Np0f18ZFlXmVe8dVpMu2fWUn3OdUUMnRBlt9eEUVc9Q=; b=bEiBQDR7rRJG5u5ggKMpWkkoPndfHOx30sEF9KcDMVUVkIljhXot5U4p1FhAva3ulU UGLemftwP7FEBjED6iDf0/fhGL8ivETZy2gd6gqwSKWIWwSaaba0nzuoqhaXCE+QT7LU 1CqFY7216Eu/se5s6WaJlTncx9gBRCgZSNG/Xa8KF5J0UNZaCldqhm7EsDOLrM349y3L LZHGo/UPFekemhhkoM38VSdliQOiLnzGNyTIiTOl0+qep+E9Sk7ONzp0dvJZE4bF6OtW iOd9JauP+u3Vx1qqpkgn/4yYOwd7ELk/KsOUVQgAvyo854Q4MEAIPZnGcNYjAuFYxEui WbtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=FDo82R3+; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j17si2379445ejm.446.2021.08.09.23.37.54; Mon, 09 Aug 2021 23:38:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-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=@chromium.org header.s=google header.b=FDo82R3+; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-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 S236053AbhHJELR (ORCPT + 99 others); Tue, 10 Aug 2021 00:11:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229827AbhHJELN (ORCPT ); Tue, 10 Aug 2021 00:11:13 -0400 Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 755C6C061796 for ; Mon, 9 Aug 2021 21:10:52 -0700 (PDT) Received: by mail-io1-xd29.google.com with SMTP id i7so24264605iow.1 for ; Mon, 09 Aug 2021 21:10:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Np0f18ZFlXmVe8dVpMu2fWUn3OdUUMnRBlt9eEUVc9Q=; b=FDo82R3+gzErO0YtuHji4oPRmykg+aMaEAbpRX3sfZ+CtijaZIq6cFmI3nEWa1CLkC aLTcILu+RnmFNIalWVJt+DIOqPpx7BEZ6j4sTvR35w7Fu0mqEogBIlsVEwcPGFF1xKpZ uFPAVHDVYdFrtpHh+HnUg5OMXXP+NuywtVu0w= 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=Np0f18ZFlXmVe8dVpMu2fWUn3OdUUMnRBlt9eEUVc9Q=; b=epjuxL5FdnbYSacPWIj5kDogW12naxwWSuQXvvneFfpCURV0wfavZzETgUdWugi/Dl FF0jaxoFA8+UgVIcUD45YsXk0bwUUMpvm/CwTdsIn2F1b6sIM2PzhSlIusVifxJeYHPW Ppx4G0vrTrMX2ReqzXfYmMicxbQbRTZik+hqfWUGF4/PPOcpejVZ9Jzu84YDsD3l4GNN BSENSsMP3qpq8n0PRGd7oGc4DNJhZv+nBxk/Ns7TL+8F3/2p098fcsset4ADdoL8cKvM KgI6GRR33RhIMtwqk6MmDOLmQfc9IhYH44yuoKHTZxE13nnIalkjMJAmBB6PaTN4ST+I ZPKA== X-Gm-Message-State: AOAM5336Ti3BCml9Jlm/lcH82wQ0vJUiDnz8FEDp2ACD1BLRvTYraR1y 4iD1QKJpJSO+TkUUH9h7MyIeSVoc/sJG0r8n3MYYMw== X-Received: by 2002:a5d:938a:: with SMTP id c10mr114512iol.0.1628568651827; Mon, 09 Aug 2021 21:10:51 -0700 (PDT) MIME-Version: 1.0 References: <20210809174358.163525-1-kai.heng.feng@canonical.com> In-Reply-To: <20210809174358.163525-1-kai.heng.feng@canonical.com> From: Hsin-Yi Wang Date: Tue, 10 Aug 2021 12:10:26 +0800 Message-ID: Subject: Re: [PATCH] Bluetooth: Move shutdown callback before flushing tx and rx queue To: Kai-Heng Feng Cc: Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , Mattijs Korpershoek , Guenter Roeck , "David S. Miller" , Jakub Kicinski , "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-bluetooth@vger.kernel.org On Tue, Aug 10, 2021 at 1:44 AM Kai-Heng Feng wrote: > > Commit 0ea9fd001a14 ("Bluetooth: Shutdown controller after workqueues > are flushed or cancelled") introduced a regression that makes mtkbtsdio > driver stops working: > [ 36.593956] Bluetooth: hci0: Firmware already downloaded > [ 46.814613] Bluetooth: hci0: Execution of wmt command timed out > [ 46.814619] Bluetooth: hci0: Failed to send wmt func ctrl (-110) > > The shutdown callback depends on the result of hdev->rx_work, so we > should call it before flushing rx_work: > -> btmtksdio_shutdown() > -> mtk_hci_wmt_sync() > -> __hci_cmd_send() > -> wait for BTMTKSDIO_TX_WAIT_VND_EVT gets cleared > > -> btmtksdio_recv_event() > -> hci_recv_frame() > -> queue_work(hdev->workqueue, &hdev->rx_work) > -> clears BTMTKSDIO_TX_WAIT_VND_EVT > > So move the shutdown callback before flushing TX/RX queue to resolve the > issue. > > Reported-and-tested-by: Mattijs Korpershoek > Tested-by: Hsin-Yi Wang Hello, Sorry for confusion, but the version I tested is this one: https://lkml.org/lkml/2021/8/4/486 (shutdown is prior to the test_and_clear HCI_UP) I tested this version and still see the error I've seen before. > Cc: Guenter Roeck > Fixes: 0ea9fd001a14 ("Bluetooth: Shutdown controller after workqueues are flushed or cancelled") > Signed-off-by: Kai-Heng Feng > --- > net/bluetooth/hci_core.c | 16 ++++++++-------- > 1 file changed, 8 insertions(+), 8 deletions(-) > > diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c > index cb2e9e513907..8da04c899197 100644 > --- a/net/bluetooth/hci_core.c > +++ b/net/bluetooth/hci_core.c > @@ -1735,6 +1735,14 @@ int hci_dev_do_close(struct hci_dev *hdev) > > hci_leds_update_powered(hdev, false); > > + 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 RX and TX works */ > flush_work(&hdev->tx_work); > flush_work(&hdev->rx_work); > @@ -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); > > -- > 2.31.1 >