From: Markus Armbruster <armbru@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org, kwolf@redhat.com, qemu-block@nongnu.org
Subject: Re: [PATCH] blkdebug: ignore invalid rules in non-coroutine context
Date: Thu, 13 Oct 2022 12:56:48 +0200 [thread overview]
Message-ID: <87a660yosv.fsf@pond.sub.org> (raw)
In-Reply-To: <20221013093523.586361-1-pbonzini@redhat.com> (Paolo Bonzini's message of "Thu, 13 Oct 2022 11:35:23 +0200")
Paolo Bonzini <pbonzini@redhat.com> writes:
> blkdebug events can be called from either non-coroutine or coroutine
> contexts. However, some actions (specifically suspend actions and
> errors reported with immediately=off) only make sense from within
> a coroutine.
>
> Currently, using those action would lead to an abort() in
> qemu_coroutine_yield() ("Co-routine is yielding to no one").
> Catch them and print an error instead.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> block/blkdebug.c | 17 ++++++++++++++---
> 1 file changed, 14 insertions(+), 3 deletions(-)
>
> diff --git a/block/blkdebug.c b/block/blkdebug.c
> index bbf2948703..bf0aedb17d 100644
> --- a/block/blkdebug.c
> +++ b/block/blkdebug.c
> @@ -31,6 +31,7 @@
> #include "block/qdict.h"
> #include "qemu/module.h"
> #include "qemu/option.h"
> +#include "qemu/error-report.h"
> #include "qapi/qapi-visit-block-core.h"
> #include "qapi/qmp/qdict.h"
> #include "qapi/qmp/qlist.h"
> @@ -623,8 +624,13 @@ static int rule_check(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
>
> qemu_mutex_unlock(&s->lock);
> if (!immediately) {
> - aio_co_schedule(qemu_get_current_aio_context(), qemu_coroutine_self());
> - qemu_coroutine_yield();
> + if (qemu_in_coroutine()) {
> + aio_co_schedule(qemu_get_current_aio_context(), qemu_coroutine_self());
> + qemu_coroutine_yield();
> + } else {
> + error_report("Non-coroutine event %s needs immediately = off\n",
> + BlkdebugEvent_lookup.array[rule->event]);
rule_check() is called from blkdebug_co_preadv(), blkdebug_co_pwritev(),
blkdebug_co_pwrite_zeroes(), blkdebug_co_pdiscard(),
blkdebug_co_block_status() (all marked coroutine_fn), and
blkdebug_co_flush() (which looks like it should be marked coroutine_fn).
Ignorant question: how could it be called outside coroutine context?
Also, code smell: reporting an error without taking an error path. But
let's worry about that only after I understand the problem you're trying
to fix.
> + }
> }
>
> return -error;
> @@ -858,7 +864,12 @@ static void blkdebug_debug_event(BlockDriverState *bs, BlkdebugEvent event)
> }
>
> while (actions_count[ACTION_SUSPEND] > 0) {
> - qemu_coroutine_yield();
> + if (qemu_in_coroutine()) {
> + qemu_coroutine_yield();
> + } else {
> + error_report("Non-coroutine event %s cannot suspend\n",
> + BlkdebugEvent_lookup.array[event]);
> + }
> actions_count[ACTION_SUSPEND]--;
> }
> }
next prev parent reply other threads:[~2022-10-13 11:30 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-13 9:35 [PATCH] blkdebug: ignore invalid rules in non-coroutine context Paolo Bonzini
2022-10-13 10:56 ` Markus Armbruster [this message]
2022-10-13 13:06 ` Paolo Bonzini
2022-10-13 13:28 ` Markus Armbruster
2022-10-13 15:41 ` Paolo Bonzini
-- strict thread matches above, loose matches on Subject: below --
2022-12-15 13:02 Paolo Bonzini
2022-12-15 13:44 ` Kevin Wolf
2023-01-17 15:44 ` Kevin Wolf
2023-01-17 17:21 ` Kevin Wolf
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=87a660yosv.fsf@pond.sub.org \
--to=armbru@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/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.