hw/scsi/scsi-disk.c | 277 +++++++++++++++++++-------------- tests/qtest/virtio-scsi-test.c | 173 ++++++++++++++++---- 2 files changed, 308 insertions(+), 142 deletions(-)
scsi-disk splits UNMAP into one discard per descriptor and a non-zero WRITE SAME into 512 KiB writes, submitting each step from the completion callback of the previous one. A drain in between only waits for the step in flight; the next one is queued by blk_wait_while_drained() and resumed by drain_end. When the drain is the one in bdrv_inactivate_all() (end of live migration, blockdev-set-active), the resumed request hits an inactive node: bdrv_co_write_req_prepare: Assertion `!(bs->open_flags & BDRV_O_INACTIVE)' failed. We hit this in production on a guest UNMAP with 38 descriptors. The fix follows the one Kevin did for IDE TRIM: https://lore.kernel.org/qemu-devel/20260421161132.99878-1-kwolf@redhat.com/ Signed-off-by: Denis V. Lunev <den@openvz.org> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Kevin Wolf <kwolf@redhat.com> Cc: Hanna Reitz <hreitz@redhat.com> Cc: Fabiano Rosas <farosas@suse.de> Cc: Laurent Vivier <lvivier@redhat.com> Cc: qemu-stable@nongnu.org Denis V. Lunev (5): scsi-disk: check all UNMAP descriptors before discarding any scsi-disk: fix UNMAP racing with inactivation of block nodes scsi-disk: fix WRITE SAME racing with inactivation of block nodes virtio-scsi-test: split virtio_scsi_do_command() into submit and wait virtio-scsi-test: test UNMAP and WRITE SAME during inactivation hw/scsi/scsi-disk.c | 277 +++++++++++++++++++-------------- tests/qtest/virtio-scsi-test.c | 173 ++++++++++++++++---- 2 files changed, 308 insertions(+), 142 deletions(-) base-commit: d73149283205645625bfa9fe029cfb68e4c4a9ae -- 2.53.0
On 10/26/26 18:42, Denis V. Lunev wrote: > This email originated from an IP that might not be authorized by the domain it was sent from. > Do not click links or open attachments unless it is an email you expected to receive. > scsi-disk splits UNMAP into one discard per descriptor and a non-zero > WRITE SAME into 512 KiB writes, submitting each step from the > completion callback of the previous one. A drain in between only waits > for the step in flight; the next one is queued by > blk_wait_while_drained() and resumed by drain_end. When the drain is > the one in bdrv_inactivate_all() (end of live migration, > blockdev-set-active), the resumed request hits an inactive node: > > bdrv_co_write_req_prepare: Assertion > `!(bs->open_flags & BDRV_O_INACTIVE)' failed. > > We hit this in production on a guest UNMAP with 38 descriptors. > > The fix follows the one Kevin did for IDE TRIM: > https://lore.kernel.org/qemu-devel/20260421161132.99878-1-kwolf@redhat.com/ > > Signed-off-by: Denis V. Lunev <den@openvz.org> > Cc: Paolo Bonzini <pbonzini@redhat.com> > Cc: Kevin Wolf <kwolf@redhat.com> > Cc: Hanna Reitz <hreitz@redhat.com> > Cc: Fabiano Rosas <farosas@suse.de> > Cc: Laurent Vivier <lvivier@redhat.com> > Cc: qemu-stable@nongnu.org > > Denis V. Lunev (5): > scsi-disk: check all UNMAP descriptors before discarding any > scsi-disk: fix UNMAP racing with inactivation of block nodes > scsi-disk: fix WRITE SAME racing with inactivation of block nodes > virtio-scsi-test: split virtio_scsi_do_command() into submit and wait > virtio-scsi-test: test UNMAP and WRITE SAME during inactivation > > hw/scsi/scsi-disk.c | 277 +++++++++++++++++++-------------- > tests/qtest/virtio-scsi-test.c | 173 ++++++++++++++++---- > 2 files changed, 308 insertions(+), 142 deletions(-) > > base-commit: d73149283205645625bfa9fe029cfb68e4c4a9ae > ping
Hi Denis,
Am 26.10.26 um 7:09 PM schrieb Denis V. Lunev:
> scsi-disk splits UNMAP into one discard per descriptor and a non-zero
> WRITE SAME into 512 KiB writes, submitting each step from the
> completion callback of the previous one. A drain in between only waits
> for the step in flight; the next one is queued by
> blk_wait_while_drained() and resumed by drain_end. When the drain is
> the one in bdrv_inactivate_all() (end of live migration,
> blockdev-set-active), the resumed request hits an inactive node:
>
> bdrv_co_write_req_prepare: Assertion
> `!(bs->open_flags & BDRV_O_INACTIVE)' failed.
>
> We hit this in production on a guest UNMAP with 38 descriptors.
thank you for tackling the issue! Unfortunately, I was still able to run
into a crash with your series applied on top of v11.2.0-rc0:
> Thread 12 "qemu-system-x86" received signal SIGABRT, Aborted.
> [Switching to Thread 0x7e5ff390f6c0 (LWP 382537)]
> __GI_abort () at ./stdlib/abort.c:95
> warning: 95 ./stdlib/abort.c: No such file or directory
> (gdb) bt
> #0 __GI_abort () at ./stdlib/abort.c:95
> #1 0x00007e5ff7ef7420 in __assert_fail_base (fmt=<optimized out>, assertion=<optimized out>, file=<optimized out>, line=2000,
> function=<optimized out>) at ./assert/assert.c:118
> #2 0x000064d2985a7d47 in bdrv_co_write_req_prepare (child=0x64d2b3419550, offset=0, bytes=512, req=0x7e5e468ebdd8, flags=0)
> at ../block/io.c:2000
> #3 0x000064d2985a786b in bdrv_co_pdiscard (child=0x64d2b3419550, offset=0, bytes=512) at ../block/io.c:3217
> #4 0x000064d29858ee94 in blk_co_do_pdiscard (blk=0x64d2b3419050, offset=0, bytes=512, flags=BDRV_REQ_NO_QUEUE)
> at ../block/block-backend.c:1821
> #5 0x000064d29858eded in blk_co_pdiscard (blk=0x64d2b3419050, offset=0, bytes=512, flags=BDRV_REQ_NO_QUEUE)
> at ../block/block-backend.c:1849
> #6 0x000064d29817105b in scsi_unmap_co (iocb=0x7e5fe0001c90) at ../hw/scsi/scsi-disk.c:1873
> #7 0x000064d2981712aa in scsi_disk_co_aio_entry (opaque=0x7e5fe0001c90) at ../hw/scsi/scsi-disk.c:1797
> #8 0x000064d298785586 in coroutine_trampoline (i0=-1308221744, i1=25810) at ../util/coroutine-ucontext.c:175
> #9 0x00007e5ff7f27810 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
> #10 0x00007ffd671cda00 in ?? ()
> #11 0x0000000000000000 in ?? ()
I issued an UNMAP with 4095 descriptors, all discarding the first
sector, via sg_raw in the guest and then sent 'blockdev-set-active' to
deactivate via QMP.
The device is
> -device 'scsi-hd,bus=virtioscsi1.0,channel=0,scsi-id=0,lun=1,drive=drive-scsi1,id=scsi1,device_id=drive-scsi1,write-cache=on'
and the blockdev
> {
> "detect-zeroes": "unmap",
> "discard": "unmap",
> "driver": "throttle",
> "file": {
> "cache": {
> "direct": true,
> "no-flush": false
> },
> "detect-zeroes": "unmap",
> "discard": "unmap",
> "driver": "qcow2",
> "file": {
> "aio": "io_uring",
> "cache": {
> "direct": true,
> "no-flush": false
> },
> "detect-zeroes": "unmap",
> "discard": "unmap",
> "driver": "file",
> "filename": "/mnt/pve/nfs/images/100/vm-100-disk-1.qcow2",
> "node-name": "ef0f65238260b2e5517e288d10debc8",
> "read-only": false
> },
> "node-name": "ff0f65238260b2e5517e288d10debc8",
> "read-only": false
> },
> "node-name": "drive-scsi1",
> "read-only": false,
> "throttle-group": "throttle-drive-scsi1"
> }
Best Regards,
Fiona
On 11/12/26 17:02, Fiona Ebner wrote:
> Hi Denis,
>
> Am 26.10.26 um 7:09 PM schrieb Denis V. Lunev:
>> scsi-disk splits UNMAP into one discard per descriptor and a non-zero
>> WRITE SAME into 512 KiB writes, submitting each step from the
>> completion callback of the previous one. A drain in between only waits
>> for the step in flight; the next one is queued by
>> blk_wait_while_drained() and resumed by drain_end. When the drain is
>> the one in bdrv_inactivate_all() (end of live migration,
>> blockdev-set-active), the resumed request hits an inactive node:
>>
>> bdrv_co_write_req_prepare: Assertion
>> `!(bs->open_flags & BDRV_O_INACTIVE)' failed.
>>
>> We hit this in production on a guest UNMAP with 38 descriptors.
> thank you for tackling the issue! Unfortunately, I was still able to run
> into a crash with your series applied on top of v11.2.0-rc0:
>
>> Thread 12 "qemu-system-x86" received signal SIGABRT, Aborted.
>> [Switching to Thread 0x7e5ff390f6c0 (LWP 382537)]
>> __GI_abort () at ./stdlib/abort.c:95
>> warning: 95 ./stdlib/abort.c: No such file or directory
>> (gdb) bt
>> #0 __GI_abort () at ./stdlib/abort.c:95
>> #1 0x00007e5ff7ef7420 in __assert_fail_base (fmt=<optimized out>, assertion=<optimized out>, file=<optimized out>, line=2000,
>> function=<optimized out>) at ./assert/assert.c:118
>> #2 0x000064d2985a7d47 in bdrv_co_write_req_prepare (child=0x64d2b3419550, offset=0, bytes=512, req=0x7e5e468ebdd8, flags=0)
>> at ../block/io.c:2000
>> #3 0x000064d2985a786b in bdrv_co_pdiscard (child=0x64d2b3419550, offset=0, bytes=512) at ../block/io.c:3217
>> #4 0x000064d29858ee94 in blk_co_do_pdiscard (blk=0x64d2b3419050, offset=0, bytes=512, flags=BDRV_REQ_NO_QUEUE)
>> at ../block/block-backend.c:1821
>> #5 0x000064d29858eded in blk_co_pdiscard (blk=0x64d2b3419050, offset=0, bytes=512, flags=BDRV_REQ_NO_QUEUE)
>> at ../block/block-backend.c:1849
>> #6 0x000064d29817105b in scsi_unmap_co (iocb=0x7e5fe0001c90) at ../hw/scsi/scsi-disk.c:1873
>> #7 0x000064d2981712aa in scsi_disk_co_aio_entry (opaque=0x7e5fe0001c90) at ../hw/scsi/scsi-disk.c:1797
>> #8 0x000064d298785586 in coroutine_trampoline (i0=-1308221744, i1=25810) at ../util/coroutine-ucontext.c:175
>> #9 0x00007e5ff7f27810 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
>> #10 0x00007ffd671cda00 in ?? ()
>> #11 0x0000000000000000 in ?? ()
> I issued an UNMAP with 4095 descriptors, all discarding the first
> sector, via sg_raw in the guest and then sent 'blockdev-set-active' to
> deactivate via QMP.
>
> The device is
>
>> -device 'scsi-hd,bus=virtioscsi1.0,channel=0,scsi-id=0,lun=1,drive=drive-scsi1,id=scsi1,device_id=drive-scsi1,write-cache=on'
> and the blockdev
>
>> {
>> "detect-zeroes": "unmap",
>> "discard": "unmap",
>> "driver": "throttle",
>> "file": {
>> "cache": {
>> "direct": true,
>> "no-flush": false
>> },
>> "detect-zeroes": "unmap",
>> "discard": "unmap",
>> "driver": "qcow2",
>> "file": {
>> "aio": "io_uring",
>> "cache": {
>> "direct": true,
>> "no-flush": false
>> },
>> "detect-zeroes": "unmap",
>> "discard": "unmap",
>> "driver": "file",
>> "filename": "/mnt/pve/nfs/images/100/vm-100-disk-1.qcow2",
>> "node-name": "ef0f65238260b2e5517e288d10debc8",
>> "read-only": false
>> },
>> "node-name": "ff0f65238260b2e5517e288d10debc8",
>> "read-only": false
>> },
>> "node-name": "drive-scsi1",
>> "read-only": false,
>> "throttle-group": "throttle-drive-scsi1"
>> }
> Best Regards,
> Fiona
Great thing. Thanks a look for spending time for that.
I'll dig further!
Den
Am 12.11.26 um 5:02 PM schrieb Fiona Ebner:
> Hi Denis,
>
> Am 26.10.26 um 7:09 PM schrieb Denis V. Lunev:
>> scsi-disk splits UNMAP into one discard per descriptor and a non-zero
>> WRITE SAME into 512 KiB writes, submitting each step from the
>> completion callback of the previous one. A drain in between only waits
>> for the step in flight; the next one is queued by
>> blk_wait_while_drained() and resumed by drain_end. When the drain is
>> the one in bdrv_inactivate_all() (end of live migration,
>> blockdev-set-active), the resumed request hits an inactive node:
>>
>> bdrv_co_write_req_prepare: Assertion
>> `!(bs->open_flags & BDRV_O_INACTIVE)' failed.
>>
>> We hit this in production on a guest UNMAP with 38 descriptors.
> thank you for tackling the issue! Unfortunately, I was still able to run
> into a crash with your series applied on top of v11.2.0-rc0:
>
>> Thread 12 "qemu-system-x86" received signal SIGABRT, Aborted.
>> [Switching to Thread 0x7e5ff390f6c0 (LWP 382537)]
>> __GI_abort () at ./stdlib/abort.c:95
>> warning: 95 ./stdlib/abort.c: No such file or directory
>> (gdb) bt
>> #0 __GI_abort () at ./stdlib/abort.c:95
>> #1 0x00007e5ff7ef7420 in __assert_fail_base (fmt=<optimized out>, assertion=<optimized out>, file=<optimized out>, line=2000,
>> function=<optimized out>) at ./assert/assert.c:118
>> #2 0x000064d2985a7d47 in bdrv_co_write_req_prepare (child=0x64d2b3419550, offset=0, bytes=512, req=0x7e5e468ebdd8, flags=0)
>> at ../block/io.c:2000
>> #3 0x000064d2985a786b in bdrv_co_pdiscard (child=0x64d2b3419550, offset=0, bytes=512) at ../block/io.c:3217
>> #4 0x000064d29858ee94 in blk_co_do_pdiscard (blk=0x64d2b3419050, offset=0, bytes=512, flags=BDRV_REQ_NO_QUEUE)
>> at ../block/block-backend.c:1821
>> #5 0x000064d29858eded in blk_co_pdiscard (blk=0x64d2b3419050, offset=0, bytes=512, flags=BDRV_REQ_NO_QUEUE)
>> at ../block/block-backend.c:1849
>> #6 0x000064d29817105b in scsi_unmap_co (iocb=0x7e5fe0001c90) at ../hw/scsi/scsi-disk.c:1873
>> #7 0x000064d2981712aa in scsi_disk_co_aio_entry (opaque=0x7e5fe0001c90) at ../hw/scsi/scsi-disk.c:1797
>> #8 0x000064d298785586 in coroutine_trampoline (i0=-1308221744, i1=25810) at ../util/coroutine-ucontext.c:175
>> #9 0x00007e5ff7f27810 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
>> #10 0x00007ffd671cda00 in ?? ()
>> #11 0x0000000000000000 in ?? ()
>
> I issued an UNMAP with 4095 descriptors, all discarding the first
> sector, via sg_raw in the guest and then sent 'blockdev-set-active' to
> deactivate via QMP.
>
> The device is
>
Sorry, forgot to include
> -device 'virtio-scsi-pci,id=virtioscsi0,bus=pci.3,addr=0x1,iothread=iothread-virtioscsi0'
i.e. it's using an iothread.
>> -device 'scsi-hd,bus=virtioscsi1.0,channel=0,scsi-id=0,lun=1,drive=drive-scsi1,id=scsi1,device_id=drive-scsi1,write-cache=on'
> and the blockdev
>
>> {
>> "detect-zeroes": "unmap",
>> "discard": "unmap",
>> "driver": "throttle",
>> "file": {
>> "cache": {
>> "direct": true,
>> "no-flush": false
>> },
>> "detect-zeroes": "unmap",
>> "discard": "unmap",
>> "driver": "qcow2",
>> "file": {
>> "aio": "io_uring",
>> "cache": {
>> "direct": true,
>> "no-flush": false
>> },
>> "detect-zeroes": "unmap",
>> "discard": "unmap",
>> "driver": "file",
>> "filename": "/mnt/pve/nfs/images/100/vm-100-disk-1.qcow2",
>> "node-name": "ef0f65238260b2e5517e288d10debc8",
>> "read-only": false
>> },
>> "node-name": "ff0f65238260b2e5517e288d10debc8",
>> "read-only": false
>> },
>> "node-name": "drive-scsi1",
>> "read-only": false,
>> "throttle-group": "throttle-drive-scsi1"
>> }
>
> Best Regards,
> Fiona
© 2016 - 2026 Red Hat, Inc.