2023-04-24 12:51:19

by Johan Hovold

[permalink] [raw]
Subject: [PATCH 1/2] Bluetooth: fix debugfs registration

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: [email protected] # 4.0
Signed-off-by: Johan Hovold <[email protected]>
---
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;
+
hci_debugfs_create_common(hdev);

if (lmp_bredr_capable(hdev))
--
2.39.2


2023-05-03 07:07:46

by Johan Hovold

[permalink] [raw]
Subject: Re: [PATCH 1/2] Bluetooth: fix debugfs registration

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 <[email protected]> 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: [email protected] # 4.0
> > Signed-off-by: Johan Hovold <[email protected]>
> > ---

> > 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

2023-05-03 17:43:51

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH 1/2] Bluetooth: fix debugfs registration

Hi Johan,

On Wed, May 3, 2023 at 12:04 AM Johan Hovold <[email protected]> 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 <[email protected]> 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: [email protected] # 4.0
> > > Signed-off-by: Johan Hovold <[email protected]>
> > > ---
>
> > > 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



--
Luiz Augusto von Dentz