Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp124163pxb; Thu, 14 Jan 2021 21:38:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJxltfFDtdggMq7sOUdoaHXHSYk56aLolZwViawPeP2idduACb/QOdpCvnCOO25ynKbOXEim X-Received: by 2002:a50:becf:: with SMTP id e15mr8645594edk.138.1610689088462; Thu, 14 Jan 2021 21:38:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610689088; cv=none; d=google.com; s=arc-20160816; b=oOnLuXkeFAnYopQAR9CwOuxDPXDVdbb4JlpJvApHYhn0TGo6/SF+o9gfie7stQgHda /F+WHbUncxmDGHy54KOp6OQJU42DBg6Ul3XK4ESliRnfUxDPZKgJ2HL1yOh/bNYw2MHR 578F2KiemWx50spHKjX1iMqRSwUSUzAx0bioGTUCKOl1ZIuRVIjLYH96AVeZkD+Jqs93 lu7juRGn68bqOGQnJ8tfE8GwQDuRIYMLD0591Zf1VYh3e6ZcBb9wS4EKmRGLJ8U3upRd K0mWSYh4tZ0Kl4tpPA3HrtrRmoYqwklUjAPYfxRuWJXYa76R5iuttGNfl/KUWlWIvMYU iNOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=OLvsqob8gOgwBOBtOEKmXzO4XSLk9vifSK1jnM6SXWQ=; b=q6JptcavFBAHBS7+aIsHHxkPBH4j3gAySJhDDlvw73jHt6FIWn//BgMwFzVEr2WTKI P2LOdVilkuWdhpi9qP/bE8KhNgTDCogj88UdC01T3wCcuKFryRKsomsntPeAw3APStnM X5drfAFW/HzOmgO+s63dxoa8pmVGUF936vDEKD6JragxErBePhumOxMutumtGc02BNIi fKi6MatVgs3P+Tb7N7iVqOvmgEajhtATeJsLP8VZwyntwFJ/ZN+vcP9M9gahNYm1nRKE 53jeOZ6N3Wjmg1u2+KtypvKKrdDUekF6jzkRAvGExl8XGlplzaBsCeCmCIjChix+N7a1 8X3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iAmL3yZ1; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m26si4019145edp.209.2021.01.14.21.37.44; Thu, 14 Jan 2021 21:38:08 -0800 (PST) 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=@chromium.org header.s=google header.b=iAmL3yZ1; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731935AbhAOCSc (ORCPT + 99 others); Thu, 14 Jan 2021 21:18:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730159AbhAOCSb (ORCPT ); Thu, 14 Jan 2021 21:18:31 -0500 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25A3BC061575 for ; Thu, 14 Jan 2021 18:17:51 -0800 (PST) Received: by mail-lf1-x133.google.com with SMTP id x20so10958895lfe.12 for ; Thu, 14 Jan 2021 18:17:51 -0800 (PST) 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:content-transfer-encoding; bh=OLvsqob8gOgwBOBtOEKmXzO4XSLk9vifSK1jnM6SXWQ=; b=iAmL3yZ12K+1umXIme+9d6pyVBuYw0+7Qci2p0F9FnemqeMn70Z656nT3O0/hrbj65 +5fntniLlwU4JjUd7qoPZqLzrTOOvsWhRkYnRtbeJKMP6D9JtUOLWO7PQEPBtZUb6bl+ fTYJNm/EasTY1fvURJYFC1PtfjqxcNWdkzbF8= 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:content-transfer-encoding; bh=OLvsqob8gOgwBOBtOEKmXzO4XSLk9vifSK1jnM6SXWQ=; b=ai15UEdqknWQAaCJz8xSmIanxyBw684kVATH2ekabD1/VEGZm6mWBmMh1MHFFIjK/X IDPHl75YiMsAvSkXPgWqD0hRkbTbkZf/BV03uyWWi6OXXypDGHP0hD+S0w/sdYHhED8S 0O0KQhapS6VURxyMtaP1X5DwHd9Z5zu7Z5jxaSKXGq9zEqskamf1fmnlnVhcLKzkTF5D q/na/WaYshy0bckOMIikH92fiN//8AIIq0baq96SEVbbETsihDeIXSlWRQrYK0EGxyH6 OV47/pqGcj9mwAhSRLSJWRU+XTiHxm5VbtLCJo5k3JTqa568VH/wh5oP5YNCJVFYVjKA 24dw== X-Gm-Message-State: AOAM530ROlDFietoHJjVbCVYO3af2WuBWxJeNmWo4RKU2+Ze9mY+pHQ9 SeWtpqqec3WMuHPiObMC9Au7QZ15jrIySsQnoj1L5Q== X-Received: by 2002:a05:6512:944:: with SMTP id u4mr4626838lft.433.1610677069441; Thu, 14 Jan 2021 18:17:49 -0800 (PST) MIME-Version: 1.0 References: <20201217145149.v2.1.Id9bc5434114de07512661f002cdc0ada8b3d6d02@changeid> <7B6FEB99-5102-4A67-986C-4A5DEFDE2166@holtmann.org> In-Reply-To: <7B6FEB99-5102-4A67-986C-4A5DEFDE2166@holtmann.org> From: Miao-chen Chou Date: Thu, 14 Jan 2021 18:17:38 -0800 Message-ID: Subject: Re: [PATCH v2 1/4] Bluetooth: Keep MSFT ext info throughout a hci_dev's life cycle To: Marcel Holtmann Cc: Bluetooth Kernel Mailing List , Alain Michaud , Luiz Augusto von Dentz , Archie Pusaka , Abhishek Pandit-Subedi , "David S. Miller" , Jakub Kicinski , Johan Hedberg , Luiz Augusto von Dentz , LKML , netdev Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Marcel, On Fri, Dec 18, 2020 at 1:39 PM Marcel Holtmann wrote= : > > Hi Miao-chen, > > > This moves msft_do_close() from hci_dev_do_close() to > > hci_unregister_dev() to avoid clearing MSFT extension info. This also > > avoids retrieving MSFT info upon every msft_do_open() if MSFT extension > > has been initialized. > > what is the actual benefit of this? > > It is fundamentally one extra HCI command and that one does no harm. You = are trying to outsmart the hdev->setup vs the !hdev->setup case. I don=E2= =80=99t think this is a good idea. > > So unless I see a real argument why we want to do this, I am leaving this= patch out. And on a side note, I named these function exactly this way so = they are symmetric with hci_dev_do_{open,close}. > > Regards > > Marcel > Thanks for pointing that out. I totally agree that it's not a wise thing to outsmart the symmetric hci_dev_do_{open,close}. However, the following two cases justify why we need this change. (1) The current symmetric calls to msft_do{open,close} in hci_dev_do_{open,close} cause incorrect MSFT features during bluetoothd start-up. After the kernel powers on the controller to register the hci_dev, it performs hci_dev_do_close() which call msft_do_close() and MSFT data gets wiped out. And then during the startup of bluetoothd, Adv Monitor Manager relies on reading the MSFT features from the kernel to present the feature set of the controller to D-Bus clients. However, the power state of the controller is off during the init of D-Bus interfaces. As a result, invalid MSFT features are returned by the kernel, since it was previously wiped out due to hci_dev_do_close(). (2) Assuming bluetoothd has started, and users can be toggling the power state of the adapter. Powering off the adapter invokes hci_power_off()->hci_dev_do_close()->msft_do_close(), and MSFT features get wiped out. During powered-off period, D-Bus client can still add/remove monitor from the kernel, and the kernel needs to issue corresponding MSFT HCI commands to the controller. However, the MSFT opcode has been reset and invalid. And here is the trace (for case 1 above) that I captured without this chang= e. 2021-01-15T01:34:43.800155Z INFO kernel: [ 2.754911] Bluetooth: hci_power_on() @@ call hci_dev_do_open 2021-01-15T01:34:45.145025Z INFO kernel: [ 4.272376] Bluetooth: hci_dev_do_open() @@ call msft_do_open 2021-01-15T01:34:45.145050Z INFO kernel: [ 4.272382] Bluetooth: msft_do_open() @@ 2021-01-15T01:34:45.146020Z INFO kernel: [ 4.273139] Bluetooth: read_supported_features() @@ features 000000000000003f 2021-01-15T01:34:47.176410Z INFO kernel: [ 6.303439] Bluetooth: hci_power_off() @@ call hci_dev_do_close 2021-01-15T01:34:47.189020Z INFO kernel: [ 6.316152] Bluetooth: hci_dev_do_close() @@ call msft_do_close 2021-01-15T01:34:47.189032Z INFO kernel: [ 6.316158] Bluetooth: msft_do_close() @@ 2021-01-15T01:34:47.957401Z INFO bluetoothd[2591]: Bluetooth daemon 5.54 // skip some logs here 2021-01-15T01:34:48.004066Z INFO bluetoothd[2591]: Bluetooth management interface 1.14 initialized 2021-01-15T01:34:48.167703Z INFO bluetoothd[2591]: @@ call btd_adv_monitor_manager_create 2021-01-15T01:34:48.167832Z INFO bluetoothd[2591]: @@ call MGMT_OP_READ_ADV_MONITOR_FEATURES 2021-01-15T01:34:48.167886Z INFO bluetoothd[2591]: Battery Provider Manager created 2021-01-15T01:34:48.171924Z INFO bluetoothd[2591]: @@ features supported_features 00000000 enabled_features 00000000 2021-01-15T01:34:48.172088Z INFO kernel: [ 7.299305] Bluetooth: hci_power_on() @@ call hci_dev_do_open 2021-01-15T01:34:48.172083Z INFO bluetoothd[2591]: Adv Monitor Manager created with supported features:0x00000000, enabled features:0x00000000, max number of supported monitors:32, max number of supported patterns:16 2021-01-15T01:34:48.207800Z INFO bluetoothd[2591]: Endpoint registered: sender=3D:1.52 path=3D/org/chromium/Cras/Bluetooth/A2DPSource 2021-01-15T01:34:48.212522Z INFO bluetoothd[2591]: Player registered: sender=3D:1.52 path=3D/org/chromium/Cras/Bluetooth/DefaultPlayer 2021-01-15T01:34:48.214813Z INFO bluetoothd[2591]: BlueZ log level is set t= o 1 2021-01-15T01:34:48.230035Z INFO kernel: [ 7.357118] Bluetooth: hci_dev_do_open() @@ call msft_do_open 2021-01-15T01:34:48.230063Z INFO kernel: [ 7.357124] Bluetooth: msft_do_open() @@ 2021-01-15T01:34:48.231027Z INFO kernel: [ 7.358131] Bluetooth: read_supported_features() @@ features 000000000000003f 2021-01-15T01:34:48.248967Z INFO bluetoothd[2591]: adapter /org/bluez/hci0 has been enabled 2021-01-15T01:34:49.176198Z INFO bluetoothd[2591]: adapter /org/bluez/hci0 set power to 1 Thanks, Miao