Linux-Bluetooth Archive on lore.kernel.org
 help / color / Atom feed
* [RFC v3] Bluetooth: Add debugfs option to enable runtime debug statements
@ 2020-02-03 15:36 Marcel Holtmann
  2020-02-13  7:27 ` Marcel Holtmann
  0 siblings, 1 reply; 4+ messages in thread
From: Marcel Holtmann @ 2020-02-03 15:36 UTC (permalink / raw)
  To: linux-bluetooth

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
---
 include/net/bluetooth/bluetooth.h | 10 +++++
 net/bluetooth/Kconfig             |  7 +++
 net/bluetooth/af_bluetooth.c      |  2 +
 net/bluetooth/lib.c               | 73 +++++++++++++++++++++++++++++++
 4 files changed, 92 insertions(+)

diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
index e42bb8e03c09..1670953178a0 100644
--- a/include/net/bluetooth/bluetooth.h
+++ b/include/net/bluetooth/bluetooth.h
@@ -129,6 +129,10 @@ void bt_warn(const char *fmt, ...);
 __printf(1, 2)
 void bt_err(const char *fmt, ...);
 __printf(1, 2)
+#if IS_ENABLED(CONFIG_BT_DEBUGFS_OPTION)
+void bt_dbg(const char *fmt, ...);
+__printf(1, 2)
+#endif
 void bt_warn_ratelimited(const char *fmt, ...);
 __printf(1, 2)
 void bt_err_ratelimited(const char *fmt, ...);
@@ -136,7 +140,11 @@ void bt_err_ratelimited(const char *fmt, ...);
 #define BT_INFO(fmt, ...)	bt_info(fmt "\n", ##__VA_ARGS__)
 #define BT_WARN(fmt, ...)	bt_warn(fmt "\n", ##__VA_ARGS__)
 #define BT_ERR(fmt, ...)	bt_err(fmt "\n", ##__VA_ARGS__)
+#if IS_ENABLED(CONFIG_BT_DEBUGFS_OPTION)
+#define BT_DBG(fmt, ...)	bt_dbg(fmt "\n", ##__VA_ARGS__)
+#else
 #define BT_DBG(fmt, ...)	pr_debug(fmt "\n", ##__VA_ARGS__)
+#endif
 
 #define bt_dev_info(hdev, fmt, ...)				\
 	BT_INFO("%s: " fmt, (hdev)->name, ##__VA_ARGS__)
@@ -393,6 +401,8 @@ void bt_procfs_cleanup(struct net *net, const char *name);
 
 extern struct dentry *bt_debugfs;
 
+void bt_lib_debugfs_init(void);
+
 int l2cap_init(void);
 void l2cap_exit(void);
 
diff --git a/net/bluetooth/Kconfig b/net/bluetooth/Kconfig
index 165148c7c4ce..2871d0770c11 100644
--- a/net/bluetooth/Kconfig
+++ b/net/bluetooth/Kconfig
@@ -128,4 +128,11 @@ config BT_DEBUGFS
 	  Provide extensive information about internal Bluetooth states
 	  in debugfs.
 
+	  When dynamic debug is not used, then this option also includes
+	  a switch to enable/disable internal debug statements.
+
+config BT_DEBUGFS_OPTION
+	bool
+	default y if BT_DEBUGFS && !DYNAMIC_DEBUG
+
 source "drivers/bluetooth/Kconfig"
diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
index 3fd124927d4d..fa0cd665f32a 100644
--- a/net/bluetooth/af_bluetooth.c
+++ b/net/bluetooth/af_bluetooth.c
@@ -731,6 +731,8 @@ static int __init bt_init(void)
 
 	bt_debugfs = debugfs_create_dir("bluetooth", NULL);
 
+	bt_lib_debugfs_init();
+
 	bt_leds_init();
 
 	err = bt_sysfs_init();
diff --git a/net/bluetooth/lib.c b/net/bluetooth/lib.c
index c09e0a3a0ed9..29f9edb57c5c 100644
--- a/net/bluetooth/lib.c
+++ b/net/bluetooth/lib.c
@@ -27,6 +27,7 @@
 #define pr_fmt(fmt) "Bluetooth: " fmt
 
 #include <linux/export.h>
+#include <linux/debugfs.h>
 
 #include <net/bluetooth/bluetooth.h>
 
@@ -135,6 +136,57 @@ int bt_to_errno(__u16 code)
 }
 EXPORT_SYMBOL(bt_to_errno);
 
+#ifdef CONFIG_BT_DEBUGFS_OPTION
+static bool debug_enable;
+
+static ssize_t debug_enable_read(struct file *file, char __user *user_buf,
+				 size_t count, loff_t *ppos)
+{
+	char buf[3];
+
+	buf[0] = debug_enable ? 'Y': 'N';
+	buf[1] = '\n';
+	buf[2] = '\0';
+	return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
+}
+
+static ssize_t debug_enable_write(struct file *file,
+				  const char __user *user_buf,
+				  size_t count, loff_t *ppos)
+{
+	bool enable;
+	int err;
+
+	err = kstrtobool_from_user(user_buf, count, &enable);
+	if (err)
+		return err;
+
+	if (enable == debug_enable)
+		return -EALREADY;
+
+	debug_enable = enable;
+
+	return count;
+}
+
+static const struct file_operations debug_enable_fops = {
+	.open		= simple_open,
+	.read		= debug_enable_read,
+	.write		= debug_enable_write,
+	.llseek		= default_llseek,
+};
+
+void bt_lib_debugfs_init(void)
+{
+	debugfs_create_file("debug_enable", 0644, bt_debugfs, NULL,
+			    &debug_enable_fops);
+}
+#else
+void bt_lib_debugfs_init(void)
+{
+}
+#endif
+
 void bt_info(const char *format, ...)
 {
 	struct va_format vaf;
@@ -183,6 +235,27 @@ void bt_err(const char *format, ...)
 }
 EXPORT_SYMBOL(bt_err);
 
+#ifdef CONFIG_BT_DEBUGFS_OPTION
+void bt_dbg(const char *format, ...)
+{
+	struct va_format vaf;
+	va_list args;
+
+	if (likely(!debug_enable))
+		return;
+
+	va_start(args, format);
+
+	vaf.fmt = format;
+	vaf.va = &args;
+
+	printk(KERN_DEBUG pr_fmt("%pV"), &vaf);
+
+	va_end(args);
+}
+EXPORT_SYMBOL(bt_dbg);
+#endif
+
 void bt_warn_ratelimited(const char *format, ...)
 {
 	struct va_format vaf;
-- 
2.24.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC v3] Bluetooth: Add debugfs option to enable runtime debug statements
  2020-02-03 15:36 [RFC v3] Bluetooth: Add debugfs option to enable runtime debug statements Marcel Holtmann
@ 2020-02-13  7:27 ` Marcel Holtmann
  2020-02-13 17:33   ` Tedd An
  2020-02-13 23:03   ` Tedd Ho-Jeong An
  0 siblings, 2 replies; 4+ messages in thread
From: Marcel Holtmann @ 2020-02-13  7:27 UTC (permalink / raw)
  To: Bluez mailing list

Hi,

> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
> ---
> include/net/bluetooth/bluetooth.h | 10 +++++
> net/bluetooth/Kconfig             |  7 +++
> net/bluetooth/af_bluetooth.c      |  2 +
> net/bluetooth/lib.c               | 73 +++++++++++++++++++++++++++++++
> 4 files changed, 92 insertions(+)

does anybody have any comments on this. It is not the final solution, but as an interim it might be a good start.

I have not seen any kbuild issues popping up. However I like to get some Tested-By, Reviewed-By lines added to the patch and I can send a patch version with proper commit message if there is interest in getting this upstream.

Regards

Marcel


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC v3] Bluetooth: Add debugfs option to enable runtime debug statements
  2020-02-13  7:27 ` Marcel Holtmann
@ 2020-02-13 17:33   ` Tedd An
  2020-02-13 23:03   ` Tedd Ho-Jeong An
  1 sibling, 0 replies; 4+ messages in thread
From: Tedd An @ 2020-02-13 17:33 UTC (permalink / raw)
  To: Marcel Holtmann, Bluez mailing list

Hi Marcel,
    
I have some cycle today and tomorrow and I can run quick test.
Is there any procedure you want me to test other than enabling kernel config and enable via debugfs?
Let me know.
    
Regards,
Tedd

On 2/12/20, 11:31 PM, "Marcel Holtmann" <linux-bluetooth-owner@vger.kernel.org on behalf of marcel@holtmann.org> wrote:

    Hi,
    
    > Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
    > ---
    > include/net/bluetooth/bluetooth.h | 10 +++++
    > net/bluetooth/Kconfig             |  7 +++
    > net/bluetooth/af_bluetooth.c      |  2 +
    > net/bluetooth/lib.c               | 73 +++++++++++++++++++++++++++++++
    > 4 files changed, 92 insertions(+)
    
    does anybody have any comments on this. It is not the final solution, but as an interim it might be a good start.
    
    I have not seen any kbuild issues popping up. However I like to get some Tested-By, Reviewed-By lines added to the patch and I can send a patch version with proper commit message if there is interest in getting this upstream.
    
    Regards
    
    Marcel
    
    



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC v3] Bluetooth: Add debugfs option to enable runtime debug statements
  2020-02-13  7:27 ` Marcel Holtmann
  2020-02-13 17:33   ` Tedd An
@ 2020-02-13 23:03   ` Tedd Ho-Jeong An
  1 sibling, 0 replies; 4+ messages in thread
From: Tedd Ho-Jeong An @ 2020-02-13 23:03 UTC (permalink / raw)
  To: Marcel Holtmann, Bluez mailing list

Hi Marcel,

On Thu, 2020-02-13 at 08:27 +0100, Marcel Holtmann wrote:
> Hi,
> 
> > Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
> > ---
> > include/net/bluetooth/bluetooth.h | 10 +++++
> > net/bluetooth/Kconfig             |  7 +++
> > net/bluetooth/af_bluetooth.c      |  2 +
> > net/bluetooth/lib.c               | 73 +++++++++++++++++++++++++++++++
> > 4 files changed, 92 insertions(+)
> 
> does anybody have any comments on this. It is not the final solution, but as
> an interim it might be a good start.
> 

I did quick test and it worked fine. Below is the testing output.
Let me know if need further testing..


root@tester-VirtualBox:/sys/kernel/debug/bluetooth# dmesg -c
root@tester-VirtualBox:/sys/kernel/debug/bluetooth# cat debug_enable 
N
root@tester-VirtualBox:/sys/kernel/debug/bluetooth# echo 'Y' > debug_enable 
root@tester-VirtualBox:/sys/kernel/debug/bluetooth# hciconfig -a
hci0:	Type: Primary  Bus: USB
	BD Address: 9C:DA:3E:F2:8E:46  ACL MTU: 1021:4  SCO MTU: 96:6
	UP RUNNING 
	RX bytes:1367 acl:0 sco:0 events:68 errors:0
	TX bytes:3729 acl:0 sco:0 commands:68 errors:0
	Features: 0xbf 0xfe 0x0f 0xfe 0xdb 0xff 0x7b 0x87
	Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
	Link policy: RSWITCH SNIFF 
	Link mode: SLAVE ACCEPT 
	Name: 'tester-VirtualBox'
	Class: 0x0c0000
	Service Classes: Rendering, Capturing
	Device Class: Miscellaneous, 
	HCI Version: 5.0 (0x9)  Revision: 0x100
	LMP Version: 5.0 (0x9)  Subversion: 0x100
	Manufacturer: Intel Corp. (2)

root@tester-VirtualBox:/sys/kernel/debug/bluetooth# dmesg
[  891.432216] Bluetooth: sock 00000000ec80bfe5
[  891.432448] Bluetooth: cmd 800448d2 arg 565442b6c260
[  891.432465] Bluetooth: channel 2 len 36
[  891.432480] Bluetooth: cmd 800448d3 arg 565441d4b860
[  891.432485] Bluetooth: 0
[  891.432489] Bluetooth: hci0 orig refcnt 5
[  891.432493] Bluetooth: hci0 orig refcnt 6
[  891.434491] Bluetooth: sock 00000000a8d1e746
[  891.434511] Bluetooth: sock 00000000a8d1e746 sk 00000000ea127ff9
[  891.434514] Bluetooth: 0
[  891.434517] Bluetooth: hci0 orig refcnt 5
[  891.434527] Bluetooth: channel 2 len 36
[  891.434538] Bluetooth: sk 00000000ea127ff9, opt 2
[  891.434546] Bluetooth: sk 00000000ea127ff9, opt 2
[  891.434558] Bluetooth: sock 00000000a8d1e746 sk 00000000ea127ff9
[  891.434577] Bluetooth: hci0 cmd_cnt 1 cmd queued 1
[  891.434584] Bluetooth: hci0 type 1 len 3
[  891.434588] Bluetooth: hdev 00000000124fe225 len 3
[  891.434593] Bluetooth: hci0
[  891.532680] Bluetooth: intf 00000000ed2b072f
[  891.532682] Bluetooth: intf 00000000600468f3
[  891.532683] Bluetooth: hci0
[  891.532696] Bluetooth: hci0
[  891.532702] Bluetooth: hci0
[  891.533095] Bluetooth: hci0 urb 0000000015f7b113 status 0 count 3
[  891.534575] Bluetooth: hci0 urb 00000000f939b99d status 0 count 64
[  891.535214] Bluetooth: hci0 urb 00000000f939b99d status 0 count 64
[  891.535885] Bluetooth: hci0 urb 00000000f939b99d status 0 count 64
[  891.536831] Bluetooth: hci0 urb 00000000f939b99d status 0 count 62
[  891.536852] Bluetooth: hci0
[  891.536854] Bluetooth: hdev 00000000124fe225 len 254
[  891.536860] Bluetooth: hci0 Event packet
[  891.536862] Bluetooth: hci0 status 0x00
[  891.536864] Bluetooth: opcode 0x0c14 status 0x00
[  891.536865] Bluetooth: hci0 opcode 0x0c14
[  891.536880] Bluetooth: sock 00000000a8d1e746, sk 00000000ea127ff9
[  891.536885] Bluetooth: sk 00000000ea127ff9, opt 2
[  891.536905] Bluetooth: sock 00000000a8d1e746 sk 00000000ea127ff9
[  891.536907] Bluetooth: channel 2 len 10
[  891.536909] Bluetooth: hci0 orig refcnt 6
[  891.536921] Bluetooth: sock 000000004b3ad07d
[  891.536927] Bluetooth: sock 000000004b3ad07d sk 00000000ea127ff9
[  891.536928] Bluetooth: 0
[  891.536929] Bluetooth: hci0 orig refcnt 5
[  891.536932] Bluetooth: channel 2 len 36
[  891.536935] Bluetooth: sk 00000000ea127ff9, opt 2
[  891.536937] Bluetooth: sk 00000000ea127ff9, opt 2
[  891.536941] Bluetooth: sock 000000004b3ad07d sk 00000000ea127ff9
[  891.536946] Bluetooth: hci0 cmd_cnt 1 cmd queued 1
[  891.536948] Bluetooth: hci0 type 1 len 3
[  891.536949] Bluetooth: hdev 00000000124fe225 len 3
[  891.536950] Bluetooth: hci0
[  891.537315] Bluetooth: hci0 urb 00000000bf489ae9 status 0 count 3
[  891.537789] Bluetooth: hci0 urb 00000000f939b99d status 0 count 9
[  891.537807] Bluetooth: hci0
[  891.537808] Bluetooth: hdev 00000000124fe225 len 9
[  891.537812] Bluetooth: hci0 Event packet
[  891.537813] Bluetooth: hci0 status 0x00
[  891.537814] Bluetooth: hci0 class 0x0c0000
[  891.537816] Bluetooth: opcode 0x0c23 status 0x00
[  891.537817] Bluetooth: hci0 opcode 0x0c23
[  891.537827] Bluetooth: sock 000000004b3ad07d, sk 00000000ea127ff9
[  891.537832] Bluetooth: sk 00000000ea127ff9, opt 2
[  891.537853] Bluetooth: sock 000000004b3ad07d sk 00000000ea127ff9
[  891.537855] Bluetooth: channel 2 len 10
[  891.537856] Bluetooth: hci0 orig refcnt 6
[  891.537865] Bluetooth: sock 00000000847c4083
[  891.537870] Bluetooth: sock 00000000847c4083 sk 00000000ea127ff9
[  891.537871] Bluetooth: 0
[  891.537872] Bluetooth: hci0 orig refcnt 5
[  891.537874] Bluetooth: channel 2 len 36
[  891.537877] Bluetooth: sk 00000000ea127ff9, opt 2
[  891.537879] Bluetooth: sk 00000000ea127ff9, opt 2
[  891.537882] Bluetooth: sock 00000000847c4083 sk 00000000ea127ff9
[  891.537886] Bluetooth: hci0 cmd_cnt 1 cmd queued 1
[  891.537888] Bluetooth: hci0 type 1 len 3
[  891.537889] Bluetooth: hdev 00000000124fe225 len 3
[  891.537890] Bluetooth: hci0
[  891.538149] Bluetooth: hci0 urb 00000000bf489ae9 status 0 count 3
[  891.538822] Bluetooth: hci0 urb 00000000f939b99d status 0 count 14
[  891.538854] Bluetooth: hci0
[  891.538856] Bluetooth: hdev 00000000124fe225 len 14
[  891.538862] Bluetooth: hci0 Event packet
[  891.538864] Bluetooth: hci0 status 0x00
[  891.538866] Bluetooth: opcode 0x1001 status 0x00
[  891.538868] Bluetooth: hci0 opcode 0x1001
[  891.538883] Bluetooth: sock 00000000847c4083, sk 00000000ea127ff9
[  891.538889] Bluetooth: sk 00000000ea127ff9, opt 2
[  891.538924] Bluetooth: sock 00000000847c4083 sk 00000000ea127ff9
[  891.538927] Bluetooth: channel 2 len 10
[  891.538930] Bluetooth: hci0 orig refcnt 6
[  891.539051] Bluetooth: sock 00000000ec80bfe5 sk 0000000035240669
[  891.539053] Bluetooth: channel 2 len 10
[  893.959807] Bluetooth: intf 00000000600468f3
[  893.961620] Bluetooth: hci0 urb 00000000f939b99d status -2 count 0
[  893.963498] Bluetooth: hci0 urb 00000000abc1f0d6 status -2 count 0
[  893.964657] Bluetooth: hci0 urb 000000002a96d38f status -2 count 0
[  893.964993] Bluetooth: intf 00000000ed2b072f
root@tester-VirtualBox:/sys/kernel/debug/bluetooth# dmesg -c > /dev/null 2>&1
root@tester-VirtualBox:/sys/kernel/debug/bluetooth# echo 'N' > debug_enable 
root@tester-VirtualBox:/sys/kernel/debug/bluetooth# hciconfig -a
hci0:	Type: Primary  Bus: USB
	BD Address: 9C:DA:3E:F2:8E:46  ACL MTU: 1021:4  SCO MTU: 96:6
	UP RUNNING 
	RX bytes:1644 acl:0 sco:0 events:71 errors:0
	TX bytes:3738 acl:0 sco:0 commands:71 errors:0
	Features: 0xbf 0xfe 0x0f 0xfe 0xdb 0xff 0x7b 0x87
	Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
	Link policy: RSWITCH SNIFF 
	Link mode: SLAVE ACCEPT 
	Name: 'tester-VirtualBox'
	Class: 0x0c0000
	Service Classes: Rendering, Capturing
	Device Class: Miscellaneous, 
	HCI Version: 5.0 (0x9)  Revision: 0x100
	LMP Version: 5.0 (0x9)  Subversion: 0x100
	Manufacturer: Intel Corp. (2)

root@tester-VirtualBox:/sys/kernel/debug/bluetooth# dmesg
root@tester-VirtualBox:/sys/kernel/debug/bluetooth# 




> I have not seen any kbuild issues popping up. However I like to get some
> Tested-By, Reviewed-By lines added to the patch and I can send a patch version
> with proper commit message if there is interest in getting this upstream.
> 
> Regards
> 
> Marcel
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-03 15:36 [RFC v3] Bluetooth: Add debugfs option to enable runtime debug statements Marcel Holtmann
2020-02-13  7:27 ` Marcel Holtmann
2020-02-13 17:33   ` Tedd An
2020-02-13 23:03   ` Tedd Ho-Jeong An

Linux-Bluetooth Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-bluetooth/0 linux-bluetooth/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-bluetooth linux-bluetooth/ https://lore.kernel.org/linux-bluetooth \
		linux-bluetooth@vger.kernel.org
	public-inbox-index linux-bluetooth

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-bluetooth


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git