Bluetooth: virtio_bt: fix device removal
PATCH v2 1/1 Bluetooth: virtio_bt: fix device removal
Device removal is clearly out of virtio spec: it attempts to remove unused buffers from a VQ before invoking device reset. To fix, make open/close NOPs and do all cleanup/setup in probe/remove.
NB: This is a hacky way to handle this - virtbt_{open,close} as NOP is not really what a driver is supposed to be doing. These are transport enable/disable callbacks from the BT core towards the driver. It maps to a device being enabled/disabled by something like bluetoothd for example. So if disabled, users expect that no resources/queues are in use. It does work with all other transports like USB, SDIO, UART etc. There should be no buffer used if the device is powered off. We also don’t have any USB URBs in-flight if the transport is not active.
The way to implement a proper fix would be using vq reset if supported, or even using a full device reset.
The cost of the hack used here is a single skb wasted on an unused bt device.
NB2: with this fix in place driver still suffers from a race condition if an interrupt triggers while device is being reset. To fix, in the virtbt_close() callback we should deactivate all interrupts. To be fixed.
Includes a squashed fixup: bluetooth: virtio_bt: fix an error code in probe()
--- drivers/bluetooth/virtio_bt.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
drivers/bluetooth/virtio_bt.c +17 -2
@@ -50,8 +50,11 @@ static int virtbt_add_inbuf(struct virtio_bluetooth *vbt)static int virtbt_open (struct hci_dev *hdev) { -struct virtio_bluetooth *vbt =hci_get_drvdata (hdev); +return 0 ; +} +static int virtbt_open_vdev (struct virtio_bluetooth *vbt) +{if (virtbt_add_inbuf (vbt) <0 )return -EIO ;
@@ -61,7 +64,11 @@ static int virtbt_open(struct hci_dev *hdev)static int virtbt_close (struct hci_dev *hdev) { -struct virtio_bluetooth *vbt =hci_get_drvdata (hdev); +return 0 ; +} + +static int virtbt_close_vdev (struct virtio_bluetooth *vbt) +{int i;cancel_work_sync (&vbt->rx);
@@ -354,8 +361,15 @@ static int virtbt_probe(struct virtio_device *vdev) goto failed; } +virtio_device_ready (vdev); + err =virtbt_open_vdev (vbt); +if (err) + goto open_failed; +return 0 ; +open_failed: +hci_free_dev (hdev); failed: vdev->config->del_vqs (vdev);return err;
@@ -368,6 +382,7 @@ static void virtbt_remove(struct virtio_device *vdev)hci_unregister_dev (hdev);virtio_reset_device (vdev); +virtbt_close_vdev (vbt);hci_free_dev (hdev); vbt->hdev =NULL ;
Signature · 1 line
MST
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=666797
---Test result---
Test Summary:
CheckPatch FAIL 1.23 seconds GitLint PASS 0.72 seconds SubjectPrefix PASS 0.57 seconds BuildKernel PASS 33.46 seconds BuildKernel32 PASS 29.34 seconds Incremental Build with patchesPASS 41.81 seconds TestRunner: Setup PASS 494.72 seconds TestRunner: l2cap-tester PASS 17.54 seconds TestRunner: bnep-tester PASS 6.66 seconds TestRunner: mgmt-tester PASS 103.84 seconds TestRunner: rfcomm-tester PASS 10.01 seconds TestRunner: sco-tester PASS 9.85 seconds TestRunner: smp-tester PASS 9.93 seconds TestRunner: userchan-tester PASS 6.82 seconds
Details
##############################
Test: CheckPatch - FAIL - 1.23 seconds
Run checkpatch.pl script with rule in .checkpatch.conf
[v2] Bluetooth: virtio_bt: fix device removal\WARNING:COMMIT_LOG_LONG_LINE: Possible unwrapped commit description (prefer a maximum 75 chars per line) #110:
The cost of the hack used here is a single skb wasted on an unused bt device.
total: 0 errors, 1 warnings, 46 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/github/workspace/src/12941237.patch has style problems, please review.
NOTE: Ignored message types: UNKNOWN_COMMIT_ID
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
---
Regards,
Linux Bluetooth