mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] virtio_blk: write back the block cache before resetting the device
@ 2026-08-26  9:33 Ahmad Fatoum
  2026-08-28 11:55 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2026-08-26  9:33 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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@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




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-08-28 11:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-26  9:33 [PATCH] virtio_blk: write back the block cache before resetting the device Ahmad Fatoum
2026-08-28 11:55 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox