From: Kevin Wolf <kwolf@redhat.com>
To: Boudewijn van der Heide <boudewijn@delta-utec.com>
Cc: qemu-block@nongnu.org, qemu-devel@nongnu.org, hreitz@redhat.com,
pbonzini@redhat.com, stefanha@redhat.com
Subject: Re: [PATCH] block: switch to co_wrapper_mixed for blk_lock_medium() and blk_eject()
Date: Mon, 8 Jun 2026 14:17:46 +0200 [thread overview]
Message-ID: <aiay6pgFEurQMtrx@redhat.com> (raw)
In-Reply-To: <20260530175822.10321-1-boudewijn@delta-utec.com>
[Cc: Paolo, Stefan]
Am 30.05.2026 um 19:58 hat Boudewijn van der Heide geschrieben:
> scsi_disk_emulate_command() can be called from a coroutine;
> when req->cmd.buf[0] is ALLOW_MEDIUM_REMOVAL, the synchronous
> blk_lock_medium() is called, which hits assert(!qemu_in_coroutine()),
> and crashes:
>
> qemu-system-hppa: block/block-gen.c:1692: blk_lock_medium:
> Assertion `!qemu_in_coroutine()' failed.
>
> blk_eject() has the same problem, it can be called from coroutine,
> because the same vtable entry (SCSIReqOps.send_command,
> scsi_disk_emulate_command() here) calls blk_eject when req->cmd.buf[0]
> is START_STOP.
>
> Fix by switching to co_wrapper_mixed for blk_lock_medium() and
> blk_eject() instead of just co_wrapper.
>
> Signed-off-by: Boudewijn van der Heide <boudewijn@delta-utec.com>
Yes, that will fix your immediate symptoms. I'm not completely sure if
that's the level where we want to fix things, though, which is why I
added Paolo and Stefan to Cc.
> ---
> Observed crash on fedora qemu-10.1.5-1.fc43 on x86_64 host using qemu-system-hppa.
>
> trace:
>
> Thread 1 (...):
> # 5 __assert_fail (...) at assert.c
> # 6 blk_lock_medium (...) at block/block-gen.c
> # 7 scsi_disk_emulate_command (...) at ../hw/scsi/scsi-disk.c
> # 8 scsi_req_enqueue (...) at ../hw/scsi/scsi-bus.c
> # 9 lsi_do_command (...) at ../hw/scsi/lsi53c895a.c
> # 10 lsi_execute_script (...) at ../hw/scsi/lsi53c895a.c
> # 11 scsi_read_complete_noio (...) at ../hw/scsi/scsi-disk.c
> # 12 blk_aio_complete (...) at ../block/block-backend.c
> # 14 blk_aio_read_entry (...) at ../block/block-backend.c
> # 15 in coroutine_trampoline (...) at ../util/coroutine-ucontext.c
>
> blk_eject() has the same path, but req->cmd.buf[0] is START_STOP instead
> of ALLOW_MEDIUM_REMOVAL inside scsi_disk_emulate_command(),
> so fix that aswell.
This would be useful information to have in the commit message proper.
The step from #10 to #11 seems to be a rather big one that left out
intermediate function calls, so I'm not sure if I fully understand it.
Either way, I don't think lsi_execute_script() and the functions called
by it were ever written with the intention to run in a coroutine. I'm
almost sure that problems can be in more than just the two functions
you're changing here. So my question is mostly, should the path involve
a BH somewhere to break out of coroutine context, instead of making one
or two specific cases work?
If the general feeling is that we do want to make essentially all of the
SCSI code coroutine_mixed_fn and are prepared to fix any issues arising
from it, then this patch is fine as far as I am concerned.
Kevin
> ---
> include/system/block-backend-io.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/include/system/block-backend-io.h b/include/system/block-backend-io.h
> index fd84723d9d..7368ad5c09 100644
> --- a/include/system/block-backend-io.h
> +++ b/include/system/block-backend-io.h
> @@ -81,10 +81,10 @@ bool coroutine_fn GRAPH_RDLOCK blk_co_is_available(BlockBackend *blk);
> bool co_wrapper_mixed_bdrv_rdlock blk_is_available(BlockBackend *blk);
>
> void coroutine_fn blk_co_lock_medium(BlockBackend *blk, bool locked);
> -void co_wrapper blk_lock_medium(BlockBackend *blk, bool locked);
> +void co_wrapper_mixed blk_lock_medium(BlockBackend *blk, bool locked);
>
> void coroutine_fn blk_co_eject(BlockBackend *blk, bool eject_flag);
> -void co_wrapper blk_eject(BlockBackend *blk, bool eject_flag);
> +void co_wrapper_mixed blk_eject(BlockBackend *blk, bool eject_flag);
>
> int64_t coroutine_fn blk_co_getlength(BlockBackend *blk);
> int64_t co_wrapper_mixed blk_getlength(BlockBackend *blk);
> --
> 2.54.0
>
prev parent reply other threads:[~2026-06-08 12:18 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-30 17:58 [PATCH] block: switch to co_wrapper_mixed for blk_lock_medium() and blk_eject() Boudewijn van der Heide
2026-06-08 12:17 ` Kevin Wolf [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aiay6pgFEurQMtrx@redhat.com \
--to=kwolf@redhat.com \
--cc=boudewijn@delta-utec.com \
--cc=hreitz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.