Message ID | 20230424124852.12625-2-johan+linaro@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2721173vqo; Mon, 24 Apr 2023 05:55:02 -0700 (PDT) X-Google-Smtp-Source: AKy350Yzuuno5TCXUAgc4GTqk3Vzx9IkvwFfQhZzlZMx4/gN8dWAJlb5Vhg+cXbuJQB0dvtxhCj1 X-Received: by 2002:a17:902:ea03:b0:1a6:961e:fcfe with SMTP id s3-20020a170902ea0300b001a6961efcfemr17295589plg.30.1682340902366; Mon, 24 Apr 2023 05:55:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682340902; cv=none; d=google.com; s=arc-20160816; b=PxMbf+HqSbDDXEM9ObJjYAx8cLo/h1UFPP4CwHhoIBWsd9M7YvSKQh748dp0VregFZ TaK3wncZD/KWXLFZyuRwj/vfUTOQXmCkrS07U71PPuxCl0Jy/bt2FbwsuR1IZVsIlXI1 nK4wKmGe8zIPc4PlnmT8P+ozz5Vlvk/+DgZJ1iC8e1mh9qJMUH8a6vd75O8mNtC0P7xq 4ryI7neWqYOTZ0xcofrtPNxVKRP2tOKWznJTcAxheqbBwF/8Vyb2ffk99wLUEvWWVa3V xLiFKO5viUQ8WsiVxwhjyKg0sYOs7c5bQ7R/bRm1DKHJPjhAVXGWIkWvsm7jzRSz5uUs rfgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3cO9oYBVSRL3OLoYElVkRSt2h9c//mcTs9RB8weBV40=; b=Xy4flqIxrwKT1pwmgxJqbIlY61wYBtW2xFq2t0bEF119KdkYFP0xRKr2+eTjS9Gy/s NAJra2vZscu2B+iEG+fgrHdETVvZIb1Upe7PC4efRMZHA3s1cZeiWQo1T5WPdBGT7oBy eJVoCilJsaYDqyILIOke3fVz3P+bsyORSRMnyDCVVTZU4J9ISC+E5OUAn9wGsYqvhF5/ P6FS4weI2Jt8fp54FxaUXwIk+qFshMsEUaXjpGXJmxCTCqbBpxv6Q1jy45Kd0/qDelJq 0BgtpM1BiW3FGx6Y7m9tnAUHZXdHUhm79I45MWNPI/+XL2nxH+cflBZAV37e7TfRZ+z/ bVYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=B3E+bHqo; 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=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m1-20020a1709026bc100b001a24521e826si10613008plt.61.2023.04.24.05.54.49; Mon, 24 Apr 2023 05:55:02 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b=B3E+bHqo; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231847AbjDXMu1 (ORCPT <rfc822;zxc52fgh@gmail.com> + 99 others); Mon, 24 Apr 2023 08:50:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231818AbjDXMuY (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 24 Apr 2023 08:50:24 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13C184C0E; Mon, 24 Apr 2023 05:50:03 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6D25E61F2D; Mon, 24 Apr 2023 12:50:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B67E2C433EF; Mon, 24 Apr 2023 12:50:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1682340602; bh=doty7Nzt+HL2eXizgefudpBTTJskbLd1/KbCneDfvBo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B3E+bHqoklmEQDfyF6vGU4XrflewNvEr9ugq5EkTvqYq3TkA3rdNPFnPVzpLpayR2 aC3CRIGGm2dcI9JX6c4CwWlQswX5IK1JlTdAVWnmsaTZYIxgZ54/aZTpMP+2mMxVa+ OyJRsQPIiKlmPESbtEYJB1uihIgBkfWITm5Lv4kGrhgcoQn0SCjd1UpP7CEaVzqjh0 TosHtmvyg6tk02NV7ZOzk83U3D6Upz6tJ3Pq803oSo5TEsNuObxbsRd3i8e49Dygzp Im7YTrRwN01AC1vo2VvgrO5exFWwRwi563bvuN6YVqUqLbGkBcJATcKISR8B09jE5e qlxFb5cmRj8CQ== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from <johan+linaro@kernel.org>) id 1pqve7-0003IX-6f; Mon, 24 Apr 2023 14:50:19 +0200 From: Johan Hovold <johan+linaro@kernel.org> To: Marcel Holtmann <marcel@holtmann.org>, Johan Hedberg <johan.hedberg@gmail.com>, Luiz Augusto von Dentz <luiz.dentz@gmail.com> Cc: "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Johan Hovold <johan+linaro@kernel.org>, stable@vger.kernel.org Subject: [PATCH 1/2] Bluetooth: fix debugfs registration Date: Mon, 24 Apr 2023 14:48:51 +0200 Message-Id: <20230424124852.12625-2-johan+linaro@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230424124852.12625-1-johan+linaro@kernel.org> References: <20230424124852.12625-1-johan+linaro@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764062063725402722?= X-GMAIL-MSGID: =?utf-8?q?1764062293710999322?= |
Series |
Bluetooth: fix debugfs registration
|
|
Commit Message
Johan Hovold
April 24, 2023, 12:48 p.m. UTC
Since commit ec6cef9cd98d ("Bluetooth: Fix SMP channel registration for
unconfigured controllers") the debugfs interface for unconfigured
controllers will be created when the controller is configured.
There is however currently nothing preventing a controller from being
configured multiple time (e.g. setting the device address using btmgmt)
which results in failed attempts to register the already registered
debugfs entries:
debugfs: File 'features' in directory 'hci0' already present!
debugfs: File 'manufacturer' in directory 'hci0' already present!
debugfs: File 'hci_version' in directory 'hci0' already present!
...
debugfs: File 'quirk_simultaneous_discovery' in directory 'hci0' already present!
Add a controller flag to avoid trying to register the debugfs interface
more than once.
Fixes: ec6cef9cd98d ("Bluetooth: Fix SMP channel registration for unconfigured controllers")
Cc: stable@vger.kernel.org # 4.0
Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
---
include/net/bluetooth/hci.h | 1 +
net/bluetooth/hci_sync.c | 3 +++
2 files changed, 4 insertions(+)
Comments
Hi Johan, On Mon, Apr 24, 2023 at 5:50 AM Johan Hovold <johan+linaro@kernel.org> wrote: > > Since commit ec6cef9cd98d ("Bluetooth: Fix SMP channel registration for > unconfigured controllers") the debugfs interface for unconfigured > controllers will be created when the controller is configured. > > There is however currently nothing preventing a controller from being > configured multiple time (e.g. setting the device address using btmgmt) > which results in failed attempts to register the already registered > debugfs entries: > > debugfs: File 'features' in directory 'hci0' already present! > debugfs: File 'manufacturer' in directory 'hci0' already present! > debugfs: File 'hci_version' in directory 'hci0' already present! > ... > debugfs: File 'quirk_simultaneous_discovery' in directory 'hci0' already present! > > Add a controller flag to avoid trying to register the debugfs interface > more than once. > > Fixes: ec6cef9cd98d ("Bluetooth: Fix SMP channel registration for unconfigured controllers") > Cc: stable@vger.kernel.org # 4.0 > Signed-off-by: Johan Hovold <johan+linaro@kernel.org> > --- > include/net/bluetooth/hci.h | 1 + > net/bluetooth/hci_sync.c | 3 +++ > 2 files changed, 4 insertions(+) > > diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h > index 400f8a7d0c3f..b8bca65bcd79 100644 > --- a/include/net/bluetooth/hci.h > +++ b/include/net/bluetooth/hci.h > @@ -335,6 +335,7 @@ enum { > enum { > HCI_SETUP, > HCI_CONFIG, > + HCI_DEBUGFS_CREATED, > HCI_AUTO_OFF, > HCI_RFKILLED, > HCI_MGMT, > diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c > index 632be1267288..a8785126df75 100644 > --- a/net/bluetooth/hci_sync.c > +++ b/net/bluetooth/hci_sync.c > @@ -4501,6 +4501,9 @@ static int hci_init_sync(struct hci_dev *hdev) > !hci_dev_test_flag(hdev, HCI_CONFIG)) > return 0; > > + if (hci_dev_test_and_set_flag(hdev, HCI_DEBUGFS_CREATED)) > + return 0; Can't we just use HCI_SETUP like we do with in create_basic: if (hci_dev_test_flag(hdev, HCI_SETUP)) hci_debugfs_create_basic(hdev); Actually we might as well move these checks directly inside the hci_debugfs function to make sure these only take effect during the setup/first init. > hci_debugfs_create_common(hdev); > > if (lmp_bredr_capable(hdev)) > -- > 2.39.2 >
On Tue, May 02, 2023 at 04:37:51PM -0700, Luiz Augusto von Dentz wrote: > Hi Johan, > > On Mon, Apr 24, 2023 at 5:50 AM Johan Hovold <johan+linaro@kernel.org> wrote: > > > > Since commit ec6cef9cd98d ("Bluetooth: Fix SMP channel registration for > > unconfigured controllers") the debugfs interface for unconfigured > > controllers will be created when the controller is configured. > > > > There is however currently nothing preventing a controller from being > > configured multiple time (e.g. setting the device address using btmgmt) > > which results in failed attempts to register the already registered > > debugfs entries: > > > > debugfs: File 'features' in directory 'hci0' already present! > > debugfs: File 'manufacturer' in directory 'hci0' already present! > > debugfs: File 'hci_version' in directory 'hci0' already present! > > ... > > debugfs: File 'quirk_simultaneous_discovery' in directory 'hci0' already present! > > > > Add a controller flag to avoid trying to register the debugfs interface > > more than once. > > > > Fixes: ec6cef9cd98d ("Bluetooth: Fix SMP channel registration for unconfigured controllers") > > Cc: stable@vger.kernel.org # 4.0 > > Signed-off-by: Johan Hovold <johan+linaro@kernel.org> > > --- > > diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c > > index 632be1267288..a8785126df75 100644 > > --- a/net/bluetooth/hci_sync.c > > +++ b/net/bluetooth/hci_sync.c > > @@ -4501,6 +4501,9 @@ static int hci_init_sync(struct hci_dev *hdev) > > !hci_dev_test_flag(hdev, HCI_CONFIG)) > > return 0; > > > > + if (hci_dev_test_and_set_flag(hdev, HCI_DEBUGFS_CREATED)) > > + return 0; > > Can't we just use HCI_SETUP like we do with in create_basic: > > if (hci_dev_test_flag(hdev, HCI_SETUP)) > hci_debugfs_create_basic(hdev); > > Actually we might as well move these checks directly inside the > hci_debugfs function to make sure these only take effect during the > setup/first init. The problem is that commit ec6cef9cd98d ("Bluetooth: Fix SMP channel registration for unconfigured controllers") started deferring creation of most parts of the debugfs interface until the controller is configured (e.g. as some information is not available until then). Moving everything back to setup-time would effectively revert that. Perhaps the interface can be changed in some way so that everything is again registered at setup-time (e.g. with placeholder values instead of conditionally created attributes), but that would at least not be something that we could backport. > > hci_debugfs_create_common(hdev); > > > > if (lmp_bredr_capable(hdev)) Johan
Hi Johan, On Wed, May 3, 2023 at 12:04 AM Johan Hovold <johan@kernel.org> wrote: > > On Tue, May 02, 2023 at 04:37:51PM -0700, Luiz Augusto von Dentz wrote: > > Hi Johan, > > > > On Mon, Apr 24, 2023 at 5:50 AM Johan Hovold <johan+linaro@kernel.org> wrote: > > > > > > Since commit ec6cef9cd98d ("Bluetooth: Fix SMP channel registration for > > > unconfigured controllers") the debugfs interface for unconfigured > > > controllers will be created when the controller is configured. > > > > > > There is however currently nothing preventing a controller from being > > > configured multiple time (e.g. setting the device address using btmgmt) > > > which results in failed attempts to register the already registered > > > debugfs entries: > > > > > > debugfs: File 'features' in directory 'hci0' already present! > > > debugfs: File 'manufacturer' in directory 'hci0' already present! > > > debugfs: File 'hci_version' in directory 'hci0' already present! > > > ... > > > debugfs: File 'quirk_simultaneous_discovery' in directory 'hci0' already present! > > > > > > Add a controller flag to avoid trying to register the debugfs interface > > > more than once. > > > > > > Fixes: ec6cef9cd98d ("Bluetooth: Fix SMP channel registration for unconfigured controllers") > > > Cc: stable@vger.kernel.org # 4.0 > > > Signed-off-by: Johan Hovold <johan+linaro@kernel.org> > > > --- > > > > diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c > > > index 632be1267288..a8785126df75 100644 > > > --- a/net/bluetooth/hci_sync.c > > > +++ b/net/bluetooth/hci_sync.c > > > @@ -4501,6 +4501,9 @@ static int hci_init_sync(struct hci_dev *hdev) > > > !hci_dev_test_flag(hdev, HCI_CONFIG)) > > > return 0; > > > > > > + if (hci_dev_test_and_set_flag(hdev, HCI_DEBUGFS_CREATED)) > > > + return 0; > > > > Can't we just use HCI_SETUP like we do with in create_basic: > > > > if (hci_dev_test_flag(hdev, HCI_SETUP)) > > hci_debugfs_create_basic(hdev); > > > > Actually we might as well move these checks directly inside the > > hci_debugfs function to make sure these only take effect during the > > setup/first init. > > The problem is that commit ec6cef9cd98d ("Bluetooth: Fix SMP channel > registration for unconfigured controllers") started deferring creation > of most parts of the debugfs interface until the controller is > configured (e.g. as some information is not available until then). > > Moving everything back to setup-time would effectively revert that. Not moving back but just doing something like: diff --git a/net/bluetooth/hci_debugfs.c b/net/bluetooth/hci_debugfs.c index ec0df2f9188e..a6e94c29fc5a 100644 --- a/net/bluetooth/hci_debugfs.c +++ b/net/bluetooth/hci_debugfs.c @@ -310,6 +310,9 @@ DEFINE_INFO_ATTRIBUTE(firmware_info, fw_info); void hci_debugfs_create_common(struct hci_dev *hdev) { + if (!hci_dev_test_flag(hdev, HCI_SETUP)) + return; + debugfs_create_file("features", 0444, hdev->debugfs, hdev, &features_fops); debugfs_create_u16("manufacturer", 0444, hdev->debugfs, > Perhaps the interface can be changed in some way so that everything is > again registered at setup-time (e.g. with placeholder values instead of > conditionally created attributes), but that would at least not be > something that we could backport. > > > > hci_debugfs_create_common(hdev); > > > > > > if (lmp_bredr_capable(hdev)) > > Johan
On Wed, May 03, 2023 at 10:34:06AM -0700, Luiz Augusto von Dentz wrote: > Hi Johan, > > On Wed, May 3, 2023 at 12:04 AM Johan Hovold <johan@kernel.org> wrote: > > > > On Tue, May 02, 2023 at 04:37:51PM -0700, Luiz Augusto von Dentz wrote: > > > Hi Johan, > > > > > > On Mon, Apr 24, 2023 at 5:50 AM Johan Hovold <johan+linaro@kernel.org> wrote: > > > > > > > > Since commit ec6cef9cd98d ("Bluetooth: Fix SMP channel registration for > > > > unconfigured controllers") the debugfs interface for unconfigured > > > > controllers will be created when the controller is configured. > > > > > > > > There is however currently nothing preventing a controller from being > > > > configured multiple time (e.g. setting the device address using btmgmt) > > > > which results in failed attempts to register the already registered > > > > debugfs entries: > > > > > > > > debugfs: File 'features' in directory 'hci0' already present! > > > > debugfs: File 'manufacturer' in directory 'hci0' already present! > > > > debugfs: File 'hci_version' in directory 'hci0' already present! > > > > ... > > > > debugfs: File 'quirk_simultaneous_discovery' in directory 'hci0' already present! > > > > > > > > Add a controller flag to avoid trying to register the debugfs interface > > > > more than once. > > > > > > > > Fixes: ec6cef9cd98d ("Bluetooth: Fix SMP channel registration for unconfigured controllers") > > > > Cc: stable@vger.kernel.org # 4.0 > > > > Signed-off-by: Johan Hovold <johan+linaro@kernel.org> > > > > --- > > > > > > diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c > > > > index 632be1267288..a8785126df75 100644 > > > > --- a/net/bluetooth/hci_sync.c > > > > +++ b/net/bluetooth/hci_sync.c > > > > @@ -4501,6 +4501,9 @@ static int hci_init_sync(struct hci_dev *hdev) > > > > !hci_dev_test_flag(hdev, HCI_CONFIG)) > > > > return 0; > > > > > > > > + if (hci_dev_test_and_set_flag(hdev, HCI_DEBUGFS_CREATED)) > > > > + return 0; > > > > > > Can't we just use HCI_SETUP like we do with in create_basic: > > > > > > if (hci_dev_test_flag(hdev, HCI_SETUP)) > > > hci_debugfs_create_basic(hdev); > > > > > > Actually we might as well move these checks directly inside the > > > hci_debugfs function to make sure these only take effect during the > > > setup/first init. > > > > The problem is that commit ec6cef9cd98d ("Bluetooth: Fix SMP channel > > registration for unconfigured controllers") started deferring creation > > of most parts of the debugfs interface until the controller is > > configured (e.g. as some information is not available until then). > > > > Moving everything back to setup-time would effectively revert that. > > Not moving back but just doing something like: > > diff --git a/net/bluetooth/hci_debugfs.c b/net/bluetooth/hci_debugfs.c > index ec0df2f9188e..a6e94c29fc5a 100644 > --- a/net/bluetooth/hci_debugfs.c > +++ b/net/bluetooth/hci_debugfs.c > @@ -310,6 +310,9 @@ DEFINE_INFO_ATTRIBUTE(firmware_info, fw_info); > > void hci_debugfs_create_common(struct hci_dev *hdev) > { > + if (!hci_dev_test_flag(hdev, HCI_SETUP)) > + return; > + > debugfs_create_file("features", 0444, hdev->debugfs, hdev, > &features_fops); > debugfs_create_u16("manufacturer", 0444, hdev->debugfs, > What I tried to explain above is that doing this would always create the attributes as setup-time rather than at config-time, which effectively reverts commit ec6cef9cd98d ("Bluetooth: Fix SMP channel registration for unconfigured controllers"). And doing so looks like it would amount to a regression. Johan
diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h index 400f8a7d0c3f..b8bca65bcd79 100644 --- a/include/net/bluetooth/hci.h +++ b/include/net/bluetooth/hci.h @@ -335,6 +335,7 @@ enum { enum { HCI_SETUP, HCI_CONFIG, + HCI_DEBUGFS_CREATED, HCI_AUTO_OFF, HCI_RFKILLED, HCI_MGMT, diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 632be1267288..a8785126df75 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -4501,6 +4501,9 @@ static int hci_init_sync(struct hci_dev *hdev) !hci_dev_test_flag(hdev, HCI_CONFIG)) return 0; + if (hci_dev_test_and_set_flag(hdev, HCI_DEBUGFS_CREATED)) + return 0; + hci_debugfs_create_common(hdev); if (lmp_bredr_capable(hdev))