Skip to content

Commit dc65b4b

Browse files
mstsirkinVudentz
authored andcommitted
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 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. squashed fixup: bluetooth: virtio_bt: fix an error code in probe() Signed-off-by: Dan Carpenter <[email protected]> Reported-by: Hulk Robot <[email protected]> Signed-off-by: Yang Yingliang <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Message-Id: <[email protected]> Signed-off-by: Luiz Augusto von Dentz <[email protected]> Tested-by: Igor Skalkin <[email protected]>
1 parent 97dfaf0 commit dc65b4b

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

drivers/bluetooth/virtio_bt.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,11 @@ static int virtbt_add_inbuf(struct virtio_bluetooth *vbt)
5050

5151
static int virtbt_open(struct hci_dev *hdev)
5252
{
53-
struct virtio_bluetooth *vbt = hci_get_drvdata(hdev);
53+
return 0;
54+
}
5455

56+
static int virtbt_open_vdev(struct virtio_bluetooth *vbt)
57+
{
5558
if (virtbt_add_inbuf(vbt) < 0)
5659
return -EIO;
5760

@@ -61,7 +64,11 @@ static int virtbt_open(struct hci_dev *hdev)
6164

6265
static int virtbt_close(struct hci_dev *hdev)
6366
{
64-
struct virtio_bluetooth *vbt = hci_get_drvdata(hdev);
67+
return 0;
68+
}
69+
70+
static int virtbt_close_vdev(struct virtio_bluetooth *vbt)
71+
{
6572
int i;
6673

6774
cancel_work_sync(&vbt->rx);
@@ -354,8 +361,15 @@ static int virtbt_probe(struct virtio_device *vdev)
354361
goto failed;
355362
}
356363

364+
virtio_device_ready(vdev);
365+
err = virtbt_open_vdev(vbt);
366+
if (err)
367+
goto open_failed;
368+
357369
return 0;
358370

371+
open_failed:
372+
hci_free_dev(hdev);
359373
failed:
360374
vdev->config->del_vqs(vdev);
361375
return err;
@@ -368,6 +382,7 @@ static void virtbt_remove(struct virtio_device *vdev)
368382

369383
hci_unregister_dev(hdev);
370384
virtio_reset_device(vdev);
385+
virtbt_close_vdev(vbt);
371386

372387
hci_free_dev(hdev);
373388
vbt->hdev = NULL;

0 commit comments

Comments
 (0)