Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3302862pxt; Mon, 9 Aug 2021 23:48:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwyYsqW1H3bsjSLYkmlPbv1rWAkwI51ZNrPv6vUfaCl+ZydwNn0OD939YuHj3ZvLk7h4eZW X-Received: by 2002:aa7:de92:: with SMTP id j18mr3083467edv.141.1628578117471; Mon, 09 Aug 2021 23:48:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628578117; cv=none; d=google.com; s=arc-20160816; b=tMdp/Zy0KF7BXPt4yWbD5P35O0rSHrQ0b53UaC5HnwY0RWOpV/Q1EgpB87vQ2JmfEb FxE8iCMoI1+pw/PzxfC8wpBeSocbsKwzioNdyxxmp6HJscKOQqK5BnBPqSlSZUNJkWa3 2WcUJbvwlNle6uZ+N2W32A17UGG38GY64LcbAOGutLmcBzLD5vVFBQorDnOflZPHOL2N zTaQ4Jmvw1JaSakifAxUXmb4AJH95ZeZHXt+aFqVxWs6iTF7vAxcXFEdyhIKq5BRK4jk kJrwMA8Wy/4ickT8mMzkp7BsiWAIQl1btlMdWu4RxW95Ndre0IK8KFrNkwK013OBNqbI sK7Q== 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=8UxNrUeLSStMldoAcFeW2Lw3XcfaO3qq0rvI+4obbHY=; b=lgHzE8IEYiHbbpc/6GId5SzjGS19aE29MvQv7Pa/vaPU5bjrs03XF0+EZvgW3OLfsR C1267abqZ0PS/CgP/9gAmEHE4BIVV7htb2TQpWgsScPQesftMuP9xAvjV7oEaAGi8JJc dMc6+6ZXW5yCzAsCfs+5DKoUGReGpvp771omDNRI40qhwjHfPG0RDlO9GlSCXBv3e2wr LxOeCLjsvoC9olK4fwaAtXRKcNyF4uDYBwrsA00rCIMbeyBtnwMIWctJ05erIF9Da+iK 291xX0ixeLlTCmKoXSyBWOP4wclMDC5y8HpYmDurmUDljaGGofL5ccoKFEVO8bXx/7ir Ce1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=txpVeGXx; 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=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v4si6810868edq.318.2021.08.09.23.48.11; Mon, 09 Aug 2021 23:48:37 -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=@canonical.com header.s=20210705 header.b=txpVeGXx; 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=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237035AbhHJEiI (ORCPT + 99 others); Tue, 10 Aug 2021 00:38:08 -0400 Received: from smtp-relay-canonical-0.canonical.com ([185.125.188.120]:51942 "EHLO smtp-relay-canonical-0.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234115AbhHJEiH (ORCPT ); Tue, 10 Aug 2021 00:38:07 -0400 Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) (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 BAFDC3F34C for ; Tue, 10 Aug 2021 04:37:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1628570254; bh=8UxNrUeLSStMldoAcFeW2Lw3XcfaO3qq0rvI+4obbHY=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=txpVeGXxE2HzkqnAVq18fD6kOdKypVbQKbelYe472IO7pUNOyaSBZsBypxKOU5wK/ nv1nBaRaFz6+r5/PBu1YHnGdYXug+SeLjjmVwQUtOsjnIDlzflycVb3CUFGo4MzK0z Vc00OhzSi5fVuqepwOnE155stbequDrgWwEeu3WYFQ2DuhVhSRsAOL1uatrSfU9eCE 0zS/eMqcKYbRtPUUznhXLCrxfCYwmvDNWACXWUy2I5ZgIbR2pGoqXU5N2FO6k6QrhG 27YqRrYr4gA4vSJGxGD+KM3bmFj10c41wHulmqcvI9sBGah2IaUdGYf4FkmWJ5ZKjL Dh1CCw+emxzDg== Received: by mail-ed1-f71.google.com with SMTP id u25-20020aa7d8990000b02903bb6a903d90so10133564edq.17 for ; Mon, 09 Aug 2021 21:37:34 -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=8UxNrUeLSStMldoAcFeW2Lw3XcfaO3qq0rvI+4obbHY=; b=Jx5wiXspJwMZBN6CivdtnMPum36nFGV5HYyFnIfGjXVGFwRmXfEFsZ4qn7yIeuWHB/ qbXqhChhMeJ1zqoDQnPnU6dcBs42FYrg+1FJDz3hQiEPZ0TXPoIft75ncOPAmorDrk1J 1Rk/KP4hyMXW10gpAQ7jZcdlf5uBo8jZm+7OgJit8CcrXBhGOgGgq2oNpTyKUeoED4IF 8lRAq+7TXhUkYJOvwOBA4dYf1ih/F+o72iXGiT3tjZQGf5iXrp1fE9l1+pUCBsErlfum yA4jqPgDdmYWzkJJrrlXycBhGy6RCIAeW0L/lOgETpleTXSD1Jq9RW1nXyEp+xwZGUER D4OA== X-Gm-Message-State: AOAM533zDISepuf9mjeZGpyS1PmM36s4ykJ1e5HjQQ79QFS7wi6rZ+v2 4Wg2T8+VfFdmL1mTS2I9dnoUhpQmKd7lvIw6o4nGUe+e4VdmkTzdVvA5pCCySfp6SuG4uYjCVaI lHBm15sYeSKgIBthOU67XIjpJTPp1yY4kDONCGF9XGwZnBv3QIm415A3dGcZ4Ig== X-Received: by 2002:aa7:d14b:: with SMTP id r11mr2544052edo.259.1628570254394; Mon, 09 Aug 2021 21:37:34 -0700 (PDT) X-Received: by 2002:aa7:d14b:: with SMTP id r11mr2544039edo.259.1628570254182; Mon, 09 Aug 2021 21:37:34 -0700 (PDT) MIME-Version: 1.0 References: <20210809174358.163525-1-kai.heng.feng@canonical.com> In-Reply-To: From: Kai-Heng Feng Date: Tue, 10 Aug 2021 12:37:22 +0800 Message-ID: Subject: Re: [PATCH] Bluetooth: Move shutdown callback before flushing tx and rx queue To: Hsin-Yi Wang 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 12:10 PM Hsin-Yi Wang wrote: > > 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. Ah, sorry for causing your trouble, I am the one who got confused :( HCI_UP is obviously required for hci_req_sync() to work. Let me resend one, and sorry again! Kai-Heng > > > > > > 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 > >