virtio-blk broken after system reset
Hi,
both after hard and guest-initiated reset, something is seriously broken with virtio block devices. If I reset my Linux guest while still in grub, the bios will simply fail to read from the disk after the reboot. If I reset after Linux touched the device, qemu terminates:
Breakpoint 1, 0x00007ffff4b945b0 in _exit () from /lib64/libc.so.6 (gdb) bt
#0 0x00007ffff4b945b0 in _exit () from /lib64/libc.so.6 #1 0x00007ffff4b2948d in __run_exit_handlers () from /lib64/libc.so.6 #2 0x00007ffff4b29535 in exit () from /lib64/libc.so.6 #3 0x0000000000568da3 in virtqueue_num_heads (vq=0x17040e0, idx=0) at /data/qemu/hw/virtio.c:258 #4 0x0000000000569511 in virtqueue_pop (vq=0x17040e0, elem=0x17cea58) at /data/qemu/hw/virtio.c:388 #5 0x0000000000419e31 in virtio_blk_get_request (s=0x1704010) at /data/qemu/hw/virtio-blk.c:132 #6 virtio_blk_handle_output (vdev=0x1704010, vq=<value optimized out>) at /data/qemu/hw/virtio-blk.c:369
This is with current qemu.git head, haven't tried older versions. Known bug?
Jan
Quoted 17 lines · Jan Kiszka
Hi,
both after hard and guest-initiated reset, something is seriously broken with virtio block devices. If I reset my Linux guest while still in grub, the bios will simply fail to read from the disk after the reboot. If I reset after Linux touched the device, qemu terminates:
Breakpoint 1,
0x00007ffff4b945b0in_exit() from/lib64/libc.so.6
(gdb) bt
#0 0x00007ffff4b945b0 in_exit() from/lib64/libc.so.6
#1 0x00007ffff4b2948d in__run_exit_handlers() from/lib64/libc.so.6
#2 0x00007ffff4b29535 in exit () from/lib64/libc.so.6
#3 0x0000000000568da3 invirtqueue_num_heads(vq=0x17040e0, idx=0) at /data/qemu/hw/virtio.c:258 #4 0x0000000000569511 invirtqueue_pop(vq=0x17040e0, elem=0x17cea58) at /data/qemu/hw/virtio.c:388 #5 0x0000000000419e31 invirtio_blk_get_request(s=0x1704010) at /data/qemu/hw/virtio-blk.c:132 #6 virtio_blk_handle_output (vdev=0x1704010, vq=<value optimized out>) at /data/qemu/hw/virtio-blk.c:369
Quoted 1 line
This is with current qemu.git head, haven't tried older versions. Known bug?
This is a known issue. Gleb has posted a SeaBIOS fix:
http://www.mail-archive.com/[email protected]/msg45849.html
Currently the patch only appears in SeaBIOS master. Gleb and Kevin have discussed putting it into 0.6.1.2 stable (see linked thread). QEMU should then pick that release up.
Stefan
Quoted 20 lines · Stefan Hajnoczi
Quoted 17 lines · Jan Kiszka
Hi,
both after hard and guest-initiated reset, something is seriously broken with virtio block devices. If I reset my Linux guest while still in grub, the bios will simply fail to read from the disk after the reboot. If I reset after Linux touched the device, qemu terminates:
Breakpoint 1,
0x00007ffff4b945b0in_exit() from/lib64/libc.so.6(gdb) bt#0 0x00007ffff4b945b0 in _exit () from /lib64/libc.so.6 #1 0x00007ffff4b2948d in __run_exit_handlers () from /lib64/libc.so.6 #2 0x00007ffff4b29535 in exit () from /lib64/libc.so.6 #3 0x0000000000568da3 in virtqueue_num_heads (vq=0x17040e0, idx=0) at /data/qemu/hw/virtio.c:258 #4 0x0000000000569511 in virtqueue_pop (vq=0x17040e0, elem=0x17cea58) at /data/qemu/hw/virtio.c:388 #5 0x0000000000419e31 in virtio_blk_get_request (s=0x1704010) at /data/qemu/hw/virtio-blk.c:132 #6 virtio_blk_handle_output (vdev=0x1704010, vq=<value optimized out>) at /data/qemu/hw/virtio-blk.c:369Quoted 1 line
This is with current qemu.git head, haven't tried older versions. Known bug?
Quoted 7 lines
This is a known issue. Gleb has posted a SeaBIOS fix:
http://www.mail-archive.com/[email protected]/msg45849.html
Currently the patch only appears in SeaBIOS master. Gleb and Kevin have discussed putting it into 0.6.1.2 stable (see linked thread). QEMU should then pick that release up.
Ah, good.
And what about the guest-triggerable qemu exit above?
Jan
Quoted 9 lines · Jan Kiszka
Quoted 8 lines · Stefan Hajnoczi
Quoted 7 lines · Jan Kiszka
Hi,
both after hard and guest-initiated reset, something is seriously broken with virtio block devices. If I reset my Linux guest while still in grub, the bios will simply fail to read from the disk after the reboot. If I reset after Linux touched the device, qemu terminates:
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Breakpoint 1,
0x00007ffff4b945b0in_exit() from/lib64/libc.so.6(gdb) bt#0 0x00007ffff4b945b0 in _exit () from /lib64/libc.so.6 #1 0x00007ffff4b2948d in __run_exit_handlers () from /lib64/libc.so.6 #2 0x00007ffff4b29535 in exit () from /lib64/libc.so.6 #3 0x0000000000568da3 in virtqueue_num_heads (vq=0x17040e0, idx=0) at /data/qemu/hw/virtio.c:258 #4 0x0000000000569511 in virtqueue_pop (vq=0x17040e0, elem=0x17cea58) at /data/qemu/hw/virtio.c:388 #5 0x0000000000419e31 in virtio_blk_get_request (s=0x1704010) at /data/qemu/hw/virtio-blk.c:132 #6 virtio_blk_handle_output (vdev=0x1704010, vq=<value optimized out>) at /data/qemu/hw/virtio-blk.c:369
[]
Quoted 1 line
And what about the guest-triggerable qemu exit above?
There are _lots_ of guest-triggerable qemu exits out there.
static int virtqueue_num_heads(VirtQueue *vq, unsigned int idx)
{
uint16_t num_heads = vring_avail_idx(vq) - idx;
/* Check it isn't doing very strange things with descriptor numbers. */
if (num_heads > vq->vring.num) {
fprintf(stderr, "Guest moved used index from %u to %u",
idx, vring_avail_idx(vq));
exit(1);
}
return num_heads;
}This is done when guest behaves insanely (or qemu thinks it does). On a real hw similar behavour most likely will lead to a system lockup, qemu just exits.
Why it is trying to print things to stderr is a different matter, it should be using a proper error-reporting routine, but this is a different story.
Speaking of the bios bug, I included the fix to debian qemu-kvm package quite some time ago (19 Aug 2010), it is included since 0.12.5+dfsg-2 debian release. This one:
/mjt
Quoted 39 lines · Michael Tokarev
Quoted 9 lines · Jan Kiszka
Quoted 8 lines · Stefan Hajnoczi
Quoted 7 lines · Jan Kiszka
Hi,
both after hard and guest-initiated reset, something is seriously broken with virtio block devices. If I reset my Linux guest while still in grub, the bios will simply fail to read from the disk after the reboot. If I reset after Linux touched the device, qemu terminates:
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Breakpoint 1,
0x00007ffff4b945b0in_exit() from/lib64/libc.so.6(gdb) bt#0 0x00007ffff4b945b0 in _exit () from /lib64/libc.so.6 #1 0x00007ffff4b2948d in __run_exit_handlers () from /lib64/libc.so.6 #2 0x00007ffff4b29535 in exit () from /lib64/libc.so.6 #3 0x0000000000568da3 in virtqueue_num_heads (vq=0x17040e0, idx=0) at /data/qemu/hw/virtio.c:258 #4 0x0000000000569511 in virtqueue_pop (vq=0x17040e0, elem=0x17cea58) at /data/qemu/hw/virtio.c:388 #5 0x0000000000419e31 in virtio_blk_get_request (s=0x1704010) at /data/qemu/hw/virtio-blk.c:132 #6 virtio_blk_handle_output (vdev=0x1704010, vq=<value optimized out>) at /data/qemu/hw/virtio-blk.c:369[]
Quoted 1 line
And what about the guest-triggerable qemu exit above?
There are _lots_ of guest-triggerable qemu exits out there.
static int
virtqueue_num_heads(VirtQueue *vq, unsigned int idx){ uint16_t num_heads = vring_avail_idx(vq) - idx; /* Check it isn't doing very strange things with descriptor numbers. */ if (num_heads > vq->vring.num) { fprintf(stderr, "Guest moved used index from %u to %u", idx, vring_avail_idx(vq)); exit(1); } return num_heads; }
Quoted 3 lines
This is done when guest behaves insanely (or qemu thinks it does). On a real hw similar behavour most likely will lead to a system lockup, qemu just exits.
There is also real hw out there that goes into an error state if it's misprogrammed.
I think we have to remove all those premature exits. They also prevent handing the device inside the guest to an untrusted driver (relevant once we have IOMMU emulation).
Quoted 4 lines
Why it is trying to print things to stderr is a different matter, it should be using a proper error-reporting routine, but this is a different story.
Jep. Even worse: the above message is not dumped to the console as the stream isn't flushed on exit.
Jan
Quoted 44 lines · Jan Kiszka
Quoted 36 lines · Michael Tokarev
Quoted 9 lines · Jan Kiszka
Quoted 8 lines · Stefan Hajnoczi
Quoted 7 lines · Jan Kiszka
Hi,
both after hard and guest-initiated reset, something is seriously broken with virtio block devices. If I reset my Linux guest while still in grub, the bios will simply fail to read from the disk after the reboot. If I reset after Linux touched the device, qemu terminates:
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Breakpoint 1,
0x00007ffff4b945b0in_exit() from/lib64/libc.so.6
(gdb) bt
#0 0x00007ffff4b945b0 in_exit() from/lib64/libc.so.6
#1 0x00007ffff4b2948d in__run_exit_handlers() from/lib64/libc.so.6
#2 0x00007ffff4b29535 in exit () from/lib64/libc.so.6
#3 0x0000000000568da3 invirtqueue_num_heads(vq=0x17040e0, idx=0) at /data/qemu/hw/virtio.c:258 #4 0x0000000000569511 invirtqueue_pop(vq=0x17040e0, elem=0x17cea58) at /data/qemu/hw/virtio.c:388 #5 0x0000000000419e31 invirtio_blk_get_request(s=0x1704010) at /data/qemu/hw/virtio-blk.c:132 #6 virtio_blk_handle_output (vdev=0x1704010, vq=<value optimized out>) at /data/qemu/hw/virtio-blk.c:369[]
Quoted 1 line
And what about the guest-triggerable qemu exit above?
There are _lots_ of guest-triggerable qemu exits out there.
static int
virtqueue_num_heads(VirtQueue *vq, unsigned int idx){
uint16_tnum_heads=vring_avail_idx(vq)- idx;/* Check it isn't doing very strange things with descriptor numbers. */ if (
num_heads>vq->vring.num) {
fprintf(stderr, "Guest moved used index from %u to %u", idx, vring_avail_idx(vq));
exit(1);
}Quoted 6 lines
return
num_heads;
}This is done when guest behaves insanely (or qemu thinks it does). On a real hw similar behavour most likely will lead to a system lockup, qemu just exits.
Quoted 6 lines
There is also real hw out there that goes into an error state if it's misprogrammed.
I think we have to remove all those premature exits. They also prevent handing the device inside the guest to an untrusted driver (relevant once we have IOMMU emulation).
Interesting point about IOMMU.
Quoted 6 lines
Quoted 3 lines
Why it is trying to print things to stderr is a different matter, it should be using a proper error-reporting routine, but this is a different story.
Jep. Even worse: the above message is not dumped to the console as the stream isn't flushed on exit.
stderr is normally unbuffered. Are you running via libvirt?
Stefan
Quoted 10 lines · Stefan Hajnoczi
Quoted 7 lines · Jan Kiszka
Quoted 3 lines · Michael Tokarev
Why it is trying to print things to stderr is a different matter, it should be using a proper error-reporting routine, but this is a different story.
Jep. Even worse: the above message is not dumped to the console as the stream isn't flushed on exit.
stderr is normally unbuffered. Are you running via libvirt?
No, I was wrong. I probably missed the output as it does not issue a newline.
Jan
Am 13.11.2010 11:09, schrieb Jan Kiszka:
Quoted 44 lines · Michael Tokarev
Quoted 39 lines
Quoted 9 lines · Jan Kiszka
Quoted 8 lines · Stefan Hajnoczi
Quoted 7 lines · Jan Kiszka
Hi,
both after hard and guest-initiated reset, something is seriously broken with virtio block devices. If I reset my Linux guest while still in grub, the bios will simply fail to read from the disk after the reboot. If I reset after Linux touched the device, qemu terminates:
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Breakpoint 1,
0x00007ffff4b945b0in_exit() from/lib64/libc.so.6(gdb) bt#0 0x00007ffff4b945b0 in _exit () from /lib64/libc.so.6 #1 0x00007ffff4b2948d in __run_exit_handlers () from /lib64/libc.so.6 #2 0x00007ffff4b29535 in exit () from /lib64/libc.so.6 #3 0x0000000000568da3 in virtqueue_num_heads (vq=0x17040e0, idx=0) at /data/qemu/hw/virtio.c:258 #4 0x0000000000569511 in virtqueue_pop (vq=0x17040e0, elem=0x17cea58) at /data/qemu/hw/virtio.c:388 #5 0x0000000000419e31 in virtio_blk_get_request (s=0x1704010) at /data/qemu/hw/virtio-blk.c:132 #6 virtio_blk_handle_output (vdev=0x1704010, vq=<value optimized out>) at /data/qemu/hw/virtio-blk.c:369[]
Quoted 1 line
And what about the guest-triggerable qemu exit above?
There are _lots_ of guest-triggerable qemu exits out there.
static int
virtqueue_num_heads(VirtQueue *vq, unsigned int idx){ uint16_t num_heads = vring_avail_idx(vq) - idx; /* Check it isn't doing very strange things with descriptor numbers. */ if (num_heads > vq->vring.num) { fprintf(stderr, "Guest moved used index from %u to %u", idx, vring_avail_idx(vq)); exit(1); } return num_heads; }Quoted 3 lines
This is done when guest behaves insanely (or qemu thinks it does). On a real hw similar behavour most likely will lead to a system lockup, qemu just exits.
Quoted 6 lines
There is also real hw out there that goes into an error state if it's misprogrammed.
I think we have to remove all those premature exits. They also prevent handing the device inside the guest to an untrusted driver (relevant once we have IOMMU emulation).
I agree, those exits are bugs. There are a lot of them in virtio code. At some point, someone should go through the whole virtio code and fix them all.
Kevin
Quoted 8 lines · Jan Kiszka
There is also real hw out there that goes into an error state if it's misprogrammed.
I think we have to remove all those premature exits. They also prevent handing the device inside the guest to an untrusted driver (relevant once we have IOMMU emulation).
I think the key to achieving this is to isolate the device within QEMU.
IOW, have all fd callbacks, bottom halves, etc. tagged with a device context. Have a mechanism that raises an error on a device that can then be used to stop issuing any type of callback to the device until reset.
Obviously, we can fix some of these by just simple code refactoring.
Regards,
Anthony Liguori
Quoted 10 lines
Quoted 4 lines
Why it is trying to print things to stderr is a different matter, it should be using a proper error-reporting routine, but this is a different story.
Jep. Even worse: the above message is not dumped to the console as the stream isn't flushed on exit.
Jan