diff mbox series

[v12,2/4] Bluetooth: Add vhci devcoredump support

Message ID 20230329230447.v12.2.Ief9a81a3643d2291f6db2b3695c3a6e0159467dc@changeid (mailing list archive)
State Superseded
Headers show
Series [v12,1/4] Bluetooth: Add support for hci devcoredump | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/CheckPatch success CheckPatch PASS
tedd_an/GitLint success Gitlint PASS
tedd_an/SubjectPrefix success Gitlint PASS
tedd_an/IncrementalBuild success Incremental Build PASS

Commit Message

Manish Mandlik March 30, 2023, 6:05 a.m. UTC
Add devcoredump support for vhci that creates forcce_devcoredump debugfs
entry. This is used for mgmt-tester tests.

Signed-off-by: Manish Mandlik <mmandlik@google.com>
---

Changes in v12:
- Rename force_devcoredump_write() to force_devcd_write()
- Update force_devcd_write() to handle coredump state and timeout

Changes in v9:
- Rename hci_devcoredump_*() to hci_devcd_*()

Changes in v8:
- Update vhci_coredump_hdr() to use skb

Changes in v7:
- New patch in the series

 drivers/bluetooth/Kconfig    |  1 +
 drivers/bluetooth/hci_vhci.c | 89 ++++++++++++++++++++++++++++++++++++
 2 files changed, 90 insertions(+)

Comments

kernel test robot March 30, 2023, 9:21 a.m. UTC | #1
Hi Manish,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on bluetooth/master]
[also build test ERROR on bluetooth-next/master linus/master v6.3-rc4 next-20230330]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Manish-Mandlik/Bluetooth-Add-vhci-devcoredump-support/20230330-140719
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth.git master
patch link:    https://lore.kernel.org/r/20230329230447.v12.2.Ief9a81a3643d2291f6db2b3695c3a6e0159467dc%40changeid
patch subject: [PATCH v12 2/4] Bluetooth: Add vhci devcoredump support
config: csky-randconfig-r034-20230329 (https://download.01.org/0day-ci/archive/20230330/202303301732.rPkAOhqw-lkp@intel.com/config)
compiler: csky-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/a96b21e272af3d91f47b77b297f1289c867259b4
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Manish-Mandlik/Bluetooth-Add-vhci-devcoredump-support/20230330-140719
        git checkout a96b21e272af3d91f47b77b297f1289c867259b4
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=csky olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=csky SHELL=/bin/bash drivers/bluetooth/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202303301732.rPkAOhqw-lkp@intel.com/

All errors (new ones prefixed by >>):

   drivers/bluetooth/hci_vhci.c: In function 'force_devcd_write':
>> drivers/bluetooth/hci_vhci.c:334:21: error: 'struct hci_dev' has no member named 'dump'
     334 |                 hdev->dump.timeout = msecs_to_jiffies(dump_data.timeout * 1000);
         |                     ^~


vim +334 drivers/bluetooth/hci_vhci.c

   310	
   311	static ssize_t force_devcd_write(struct file *file, const char __user *user_buf,
   312					 size_t count, loff_t *ppos)
   313	{
   314		struct vhci_data *data = file->private_data;
   315		struct hci_dev *hdev = data->hdev;
   316		struct sk_buff *skb = NULL;
   317		struct devcoredump_test_data dump_data;
   318		int ret;
   319	
   320		ret = simple_write_to_buffer(&dump_data, sizeof(dump_data), ppos,
   321					     user_buf, count);
   322		if (ret < count)
   323			return ret;
   324	
   325		skb = alloc_skb(sizeof(dump_data.data), GFP_ATOMIC);
   326		if (!skb)
   327			return -ENOMEM;
   328		skb_put_data(skb, &dump_data.data, sizeof(dump_data.data));
   329	
   330		hci_devcd_register(hdev, vhci_coredump, vhci_coredump_hdr, NULL);
   331	
   332		/* Force the devcoredump timeout */
   333		if (dump_data.timeout)
 > 334			hdev->dump.timeout = msecs_to_jiffies(dump_data.timeout * 1000);
   335	
   336		ret = hci_devcd_init(hdev, skb->len);
   337		if (ret) {
   338			BT_ERR("Failed to generate devcoredump");
   339			kfree_skb(skb);
   340			return ret;
   341		}
   342	
   343		hci_devcd_append(hdev, skb);
   344	
   345		switch (dump_data.state) {
   346		case HCI_DEVCOREDUMP_DONE:
   347			hci_devcd_complete(hdev);
   348			break;
   349		case HCI_DEVCOREDUMP_ABORT:
   350			hci_devcd_abort(hdev);
   351			break;
   352		case HCI_DEVCOREDUMP_TIMEOUT:
   353			/* Do nothing */
   354			break;
   355		default:
   356			return -EINVAL;
   357		}
   358	
   359		return count;
   360	}
   361
kernel test robot March 30, 2023, 10:02 a.m. UTC | #2
Hi Manish,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on bluetooth/master]
[also build test ERROR on bluetooth-next/master linus/master v6.3-rc4 next-20230330]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Manish-Mandlik/Bluetooth-Add-vhci-devcoredump-support/20230330-140719
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth.git master
patch link:    https://lore.kernel.org/r/20230329230447.v12.2.Ief9a81a3643d2291f6db2b3695c3a6e0159467dc%40changeid
patch subject: [PATCH v12 2/4] Bluetooth: Add vhci devcoredump support
config: hexagon-randconfig-r045-20230329 (https://download.01.org/0day-ci/archive/20230330/202303301735.9Keuj1Mu-lkp@intel.com/config)
compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project 67409911353323ca5edf2049ef0df54132fa1ca7)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/a96b21e272af3d91f47b77b297f1289c867259b4
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Manish-Mandlik/Bluetooth-Add-vhci-devcoredump-support/20230330-140719
        git checkout a96b21e272af3d91f47b77b297f1289c867259b4
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash drivers/bluetooth/ lib/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202303301735.9Keuj1Mu-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from drivers/bluetooth/hci_vhci.c:22:
   In file included from include/linux/skbuff.h:17:
   In file included from include/linux/bvec.h:10:
   In file included from include/linux/highmem.h:12:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/hexagon/include/asm/io.h:334:
   include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           val = __raw_readb(PCI_IOBASE + addr);
                             ~~~~~~~~~~ ^
   include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
                                                           ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu'
   #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
                                                     ^
   In file included from drivers/bluetooth/hci_vhci.c:22:
   In file included from include/linux/skbuff.h:17:
   In file included from include/linux/bvec.h:10:
   In file included from include/linux/highmem.h:12:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/hexagon/include/asm/io.h:334:
   include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
                                                           ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu'
   #define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
                                                     ^
   In file included from drivers/bluetooth/hci_vhci.c:22:
   In file included from include/linux/skbuff.h:17:
   In file included from include/linux/bvec.h:10:
   In file included from include/linux/highmem.h:12:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:13:
   In file included from arch/hexagon/include/asm/io.h:334:
   include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writeb(value, PCI_IOBASE + addr);
                               ~~~~~~~~~~ ^
   include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
                                                         ~~~~~~~~~~ ^
   include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
                                                         ~~~~~~~~~~ ^
>> drivers/bluetooth/hci_vhci.c:334:9: error: no member named 'dump' in 'struct hci_dev'
                   hdev->dump.timeout = msecs_to_jiffies(dump_data.timeout * 1000);
                   ~~~~  ^
   6 warnings and 1 error generated.


vim +334 drivers/bluetooth/hci_vhci.c

   310	
   311	static ssize_t force_devcd_write(struct file *file, const char __user *user_buf,
   312					 size_t count, loff_t *ppos)
   313	{
   314		struct vhci_data *data = file->private_data;
   315		struct hci_dev *hdev = data->hdev;
   316		struct sk_buff *skb = NULL;
   317		struct devcoredump_test_data dump_data;
   318		int ret;
   319	
   320		ret = simple_write_to_buffer(&dump_data, sizeof(dump_data), ppos,
   321					     user_buf, count);
   322		if (ret < count)
   323			return ret;
   324	
   325		skb = alloc_skb(sizeof(dump_data.data), GFP_ATOMIC);
   326		if (!skb)
   327			return -ENOMEM;
   328		skb_put_data(skb, &dump_data.data, sizeof(dump_data.data));
   329	
   330		hci_devcd_register(hdev, vhci_coredump, vhci_coredump_hdr, NULL);
   331	
   332		/* Force the devcoredump timeout */
   333		if (dump_data.timeout)
 > 334			hdev->dump.timeout = msecs_to_jiffies(dump_data.timeout * 1000);
   335	
   336		ret = hci_devcd_init(hdev, skb->len);
   337		if (ret) {
   338			BT_ERR("Failed to generate devcoredump");
   339			kfree_skb(skb);
   340			return ret;
   341		}
   342	
   343		hci_devcd_append(hdev, skb);
   344	
   345		switch (dump_data.state) {
   346		case HCI_DEVCOREDUMP_DONE:
   347			hci_devcd_complete(hdev);
   348			break;
   349		case HCI_DEVCOREDUMP_ABORT:
   350			hci_devcd_abort(hdev);
   351			break;
   352		case HCI_DEVCOREDUMP_TIMEOUT:
   353			/* Do nothing */
   354			break;
   355		default:
   356			return -EINVAL;
   357		}
   358	
   359		return count;
   360	}
   361
diff mbox series

Patch

diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig
index 5a1a7bec3c42..7bc7a765ad69 100644
--- a/drivers/bluetooth/Kconfig
+++ b/drivers/bluetooth/Kconfig
@@ -363,6 +363,7 @@  config BT_HCIBLUECARD
 
 config BT_HCIVHCI
 	tristate "HCI VHCI (Virtual HCI device) driver"
+	select WANT_DEV_COREDUMP
 	help
 	  Bluetooth Virtual HCI device driver.
 	  This driver is required if you want to use HCI Emulation software.
diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c
index c443c3b0a4da..3aaf9a64ffe9 100644
--- a/drivers/bluetooth/hci_vhci.c
+++ b/drivers/bluetooth/hci_vhci.c
@@ -278,6 +278,92 @@  static int vhci_setup(struct hci_dev *hdev)
 	return 0;
 }
 
+static void vhci_coredump(struct hci_dev *hdev)
+{
+	/* No need to do anything */
+}
+
+static void vhci_coredump_hdr(struct hci_dev *hdev, struct sk_buff *skb)
+{
+	char buf[80];
+
+	snprintf(buf, sizeof(buf), "Controller Name: vhci_ctrl\n");
+	skb_put_data(skb, buf, strlen(buf));
+
+	snprintf(buf, sizeof(buf), "Firmware Version: vhci_fw\n");
+	skb_put_data(skb, buf, strlen(buf));
+
+	snprintf(buf, sizeof(buf), "Driver: vhci_drv\n");
+	skb_put_data(skb, buf, strlen(buf));
+
+	snprintf(buf, sizeof(buf), "Vendor: vhci\n");
+	skb_put_data(skb, buf, strlen(buf));
+}
+
+#define MAX_COREDUMP_LINE_LEN	40
+
+struct devcoredump_test_data {
+	enum devcoredump_state state;
+	unsigned int timeout;
+	char data[MAX_COREDUMP_LINE_LEN];
+};
+
+static ssize_t force_devcd_write(struct file *file, const char __user *user_buf,
+				 size_t count, loff_t *ppos)
+{
+	struct vhci_data *data = file->private_data;
+	struct hci_dev *hdev = data->hdev;
+	struct sk_buff *skb = NULL;
+	struct devcoredump_test_data dump_data;
+	int ret;
+
+	ret = simple_write_to_buffer(&dump_data, sizeof(dump_data), ppos,
+				     user_buf, count);
+	if (ret < count)
+		return ret;
+
+	skb = alloc_skb(sizeof(dump_data.data), GFP_ATOMIC);
+	if (!skb)
+		return -ENOMEM;
+	skb_put_data(skb, &dump_data.data, sizeof(dump_data.data));
+
+	hci_devcd_register(hdev, vhci_coredump, vhci_coredump_hdr, NULL);
+
+	/* Force the devcoredump timeout */
+	if (dump_data.timeout)
+		hdev->dump.timeout = msecs_to_jiffies(dump_data.timeout * 1000);
+
+	ret = hci_devcd_init(hdev, skb->len);
+	if (ret) {
+		BT_ERR("Failed to generate devcoredump");
+		kfree_skb(skb);
+		return ret;
+	}
+
+	hci_devcd_append(hdev, skb);
+
+	switch (dump_data.state) {
+	case HCI_DEVCOREDUMP_DONE:
+		hci_devcd_complete(hdev);
+		break;
+	case HCI_DEVCOREDUMP_ABORT:
+		hci_devcd_abort(hdev);
+		break;
+	case HCI_DEVCOREDUMP_TIMEOUT:
+		/* Do nothing */
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return count;
+}
+
+static const struct file_operations force_devcoredump_fops = {
+	.open		= simple_open,
+	.write		= force_devcd_write,
+};
+
 static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
 {
 	struct hci_dev *hdev;
@@ -355,6 +441,9 @@  static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
 		debugfs_create_file("aosp_capable", 0644, hdev->debugfs, data,
 				    &aosp_capable_fops);
 
+	debugfs_create_file("force_devcoredump", 0644, hdev->debugfs, data,
+			    &force_devcoredump_fops);
+
 	hci_skb_pkt_type(skb) = HCI_VENDOR_PKT;
 
 	skb_put_u8(skb, 0xff);