From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org, Peter Maydell <peter.maydell@linaro.org>
Cc: Fam Zheng <fam@euphon.net>, Kevin Wolf <kwolf@redhat.com>,
qemu-block@nongnu.org, Max Reitz <mreitz@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Eric Ernst <eric.g.ernst@gmail.com>, John Snow <jsnow@redhat.com>
Subject: [PULL 2/5] util/async: print leaked BH name when AioContext finalizes
Date: Thu, 8 Jul 2021 14:11:40 +0100 [thread overview]
Message-ID: <20210708131143.240647-3-stefanha@redhat.com> (raw)
In-Reply-To: <20210708131143.240647-1-stefanha@redhat.com>
BHs must be deleted before the AioContext is finalized. If not, it's a
bug and probably indicates that some part of the program still expects
the BH to run in the future. That can lead to memory leaks, inconsistent
state, or just hangs.
Unfortunately the assert(flags & BH_DELETED) call in aio_ctx_finalize()
is difficult to debug because the assertion failure contains no
information about the BH!
Use the QEMUBH name field added in the previous patch to show a useful
error when a leaked BH is detected.
Suggested-by: Eric Ernst <eric.g.ernst@gmail.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-Id: <20210414200247.917496-3-stefanha@redhat.com>
---
util/async.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/util/async.c b/util/async.c
index 9a668996b8..9a41591319 100644
--- a/util/async.c
+++ b/util/async.c
@@ -344,8 +344,20 @@ aio_ctx_finalize(GSource *source)
assert(QSIMPLEQ_EMPTY(&ctx->bh_slice_list));
while ((bh = aio_bh_dequeue(&ctx->bh_list, &flags))) {
- /* qemu_bh_delete() must have been called on BHs in this AioContext */
- assert(flags & BH_DELETED);
+ /*
+ * qemu_bh_delete() must have been called on BHs in this AioContext. In
+ * many cases memory leaks, hangs, or inconsistent state occur when a
+ * BH is leaked because something still expects it to run.
+ *
+ * If you hit this, fix the lifecycle of the BH so that
+ * qemu_bh_delete() and any associated cleanup is called before the
+ * AioContext is finalized.
+ */
+ if (unlikely(!(flags & BH_DELETED))) {
+ fprintf(stderr, "%s: BH '%s' leaked, aborting...\n",
+ __func__, bh->name);
+ abort();
+ }
g_free(bh);
}
--
2.31.1
next prev parent reply other threads:[~2021-07-08 13:23 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-08 13:11 [PULL 0/5] Block patches Stefan Hajnoczi
2021-07-08 13:11 ` [PULL 1/5] util/async: add a human-readable name to BHs for debugging Stefan Hajnoczi
2021-07-08 13:11 ` Stefan Hajnoczi [this message]
2021-07-08 13:11 ` [PULL 3/5] block/file-posix: Optimize for macOS Stefan Hajnoczi
2021-07-08 13:11 ` [PULL 4/5] block: Add backend_defaults property Stefan Hajnoczi
2021-07-08 13:11 ` [PULL 5/5] block/io: Merge discard request alignments Stefan Hajnoczi
2021-07-09 13:29 ` [PULL 0/5] Block patches Peter Maydell
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=20210708131143.240647-3-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=eric.g.ernst@gmail.com \
--cc=fam@euphon.net \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).