[PATCH] virtio_blk: write back the block cache before resetting the device

Ahmad Fatoum a.fatoum at pengutronix.de
Wed Aug 26 02:33:26 PDT 2026


virtio_blk_remove() resets the virtio device first and unregisters the
block device afterwards, but that second step is what writes barebox'
block cache back: blockdevice_unregister() calls writebuffer_flush(),
which issues ->write() for every dirty chunk and then ->flush(). Both go
to a device that no longer has a driver-owned virtqueue, so nothing
answers them.

Booting an OS makes this visible, as ExitBootServices() shuts the devices
down:

  EFI stub: Exiting boot services...
  ERROR: virtio_blk virtio0: I/O error: type 4 sector 0 count 0 status 1 ret Connection timed out

Here it is only the flush that is lost, but a dirty chunk - a variable
file written just before booting, say - would be dropped just as quietly.

Reset after unregistering, like Linux' virtblk_remove() does around
del_gendisk().

Assisted-by: Claude:opus-5
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 drivers/block/virtio_blk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index f1ee76da9750..a82d6774c385 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -115,8 +115,8 @@ static void virtio_blk_remove(struct virtio_device *vdev)
 {
 	struct virtio_blk_priv *priv = vdev->priv;
 
-	vdev->config->reset(vdev);
 	blockdevice_unregister(&priv->blk);
+	vdev->config->reset(vdev);
 	vdev->config->del_vqs(vdev);
 
 	free(priv);
-- 
2.47.3




More information about the barebox mailing list