2023-03-02 23:16:00

by Manish Mandlik

[permalink] [raw]
Subject: [PATCH v7 2/4] Bluetooth: Add vhci devcoredump support

Add devcoredump support for vhci that creates forcce_devcoredump debugfs
entry. This is used for mgmt-tester tests.

Signed-off-by: Manish Mandlik <[email protected]>
---

Changes in v7:
- New patch in the series

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

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..8a74e66f8b8e 100644
--- a/drivers/bluetooth/hci_vhci.c
+++ b/drivers/bluetooth/hci_vhci.c
@@ -278,6 +278,75 @@ static int vhci_setup(struct hci_dev *hdev)
return 0;
}

+static void vhci_coredump(struct hci_dev *hdev)
+{
+ /* No need to do anything */
+}
+
+static int vhci_coredump_hdr(struct hci_dev *hdev, char *buf, size_t size)
+{
+ char *ptr = buf;
+ size_t rem = size;
+ size_t read = 0;
+
+ read = snprintf(ptr, rem, "Controller Name: vhci_ctrl\n");
+ rem -= read;
+ ptr += read;
+
+ read = snprintf(ptr, rem, "Firmware Version: vhci_fw\n");
+ rem -= read;
+ ptr += read;
+
+ read = snprintf(ptr, rem, "Driver: vhci_drv\n");
+ rem -= read;
+ ptr += read;
+
+ read = snprintf(ptr, rem, "Vendor: vhci\n");
+ rem -= read;
+ ptr += read;
+
+ return size - rem;
+}
+
+static ssize_t force_devcoredump_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;
+ char buf[512];
+ int ret;
+
+ ret = simple_write_to_buffer(&buf, sizeof(buf), ppos, user_buf, count);
+ if (ret < count)
+ return ret;
+
+ skb = alloc_skb(count, GFP_ATOMIC);
+ if (!skb)
+ return -ENOMEM;
+ skb_put_data(skb, &buf, count);
+
+ hci_devcoredump_register(hdev, vhci_coredump, vhci_coredump_hdr, NULL);
+
+ ret = hci_devcoredump_init(hdev, skb->len);
+ if (ret) {
+ BT_ERR("Failed to generate devcoredump");
+ kfree_skb(skb);
+ return ret;
+ }
+
+ hci_devcoredump_append(hdev, skb);
+ hci_devcoredump_complete(hdev);
+
+ return count;
+}
+
+static const struct file_operations force_devcoredump_fops = {
+ .open = simple_open,
+ .write = force_devcoredump_write,
+};
+
static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
{
struct hci_dev *hdev;
@@ -355,6 +424,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);
--
2.40.0.rc0.216.gc4246ad0f0-goog



2023-03-03 00:34:33

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH v7 2/4] Bluetooth: Add vhci devcoredump support

Hi Manish,

On Thu, Mar 2, 2023 at 3:15 PM Manish Mandlik <[email protected]> wrote:
>
> Add devcoredump support for vhci that creates forcce_devcoredump debugfs
> entry. This is used for mgmt-tester tests.
>
> Signed-off-by: Manish Mandlik <[email protected]>
> ---
>
> Changes in v7:
> - New patch in the series
>
> drivers/bluetooth/Kconfig | 1 +
> drivers/bluetooth/hci_vhci.c | 72 ++++++++++++++++++++++++++++++++++++
> 2 files changed, 73 insertions(+)
>
> 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..8a74e66f8b8e 100644
> --- a/drivers/bluetooth/hci_vhci.c
> +++ b/drivers/bluetooth/hci_vhci.c
> @@ -278,6 +278,75 @@ static int vhci_setup(struct hci_dev *hdev)
> return 0;
> }
>
> +static void vhci_coredump(struct hci_dev *hdev)
> +{
> + /* No need to do anything */
> +}
> +
> +static int vhci_coredump_hdr(struct hci_dev *hdev, char *buf, size_t size)
> +{
> + char *ptr = buf;
> + size_t rem = size;
> + size_t read = 0;
> +
> + read = snprintf(ptr, rem, "Controller Name: vhci_ctrl\n");
> + rem -= read;
> + ptr += read;

Don't really like these pointer operations, can't we pass the skb here
and then use the likes of skb_push?

> + read = snprintf(ptr, rem, "Firmware Version: vhci_fw\n");
> + rem -= read;
> + ptr += read;
> +
> + read = snprintf(ptr, rem, "Driver: vhci_drv\n");
> + rem -= read;
> + ptr += read;
> +
> + read = snprintf(ptr, rem, "Vendor: vhci\n");
> + rem -= read;
> + ptr += read;
> +
> + return size - rem;
> +}
> +
> +static ssize_t force_devcoredump_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;
> + char buf[512];
> + int ret;
> +
> + ret = simple_write_to_buffer(&buf, sizeof(buf), ppos, user_buf, count);
> + if (ret < count)
> + return ret;
> +
> + skb = alloc_skb(count, GFP_ATOMIC);
> + if (!skb)
> + return -ENOMEM;
> + skb_put_data(skb, &buf, count);
> +
> + hci_devcoredump_register(hdev, vhci_coredump, vhci_coredump_hdr, NULL);
> +
> + ret = hci_devcoredump_init(hdev, skb->len);
> + if (ret) {
> + BT_ERR("Failed to generate devcoredump");
> + kfree_skb(skb);
> + return ret;
> + }
> +
> + hci_devcoredump_append(hdev, skb);
> + hci_devcoredump_complete(hdev);
> +
> + return count;
> +}
> +
> +static const struct file_operations force_devcoredump_fops = {
> + .open = simple_open,
> + .write = force_devcoredump_write,
> +};
> +
> static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
> {
> struct hci_dev *hdev;
> @@ -355,6 +424,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);
> --
> 2.40.0.rc0.216.gc4246ad0f0-goog
>


--
Luiz Augusto von Dentz