From: Paolo Bonzini <pbonzini@redhat.com>
To: Marc Morcos <marcmorcos@google.com>,
Richard Henderson <richard.henderson@linaro.org>,
Eduardo Habkost <eduardo@habkost.net>,
"Dr . David Alan Gilbert" <dave@treblig.org>
Cc: "Michael S . Tsirkin" <mst@redhat.com>,
Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
Markus Armbruster <armbru@redhat.com>,
Marcelo Tosatti <mtosatti@redhat.com>,
qemu-devel@nongnu.org, kvm@vger.kernel.org
Subject: Re: [PATCH 3/4] qmp: Fix thread race
Date: Mon, 15 Dec 2025 15:52:27 +0100 [thread overview]
Message-ID: <b6f193d4-b780-439a-80eb-bb8b43acac4e@redhat.com> (raw)
In-Reply-To: <20251213001443.2041258-4-marcmorcos@google.com>
On 12/13/25 01:14, Marc Morcos wrote:
> @@ -346,7 +347,15 @@ static void monitor_qapi_event_emit(QAPIEvent event, QDict *qdict)
> }
>
> qmp_mon = container_of(mon, MonitorQMP, common);
> - if (qmp_mon->commands != &qmp_cap_negotiation_commands) {
> + do_send = false;
> +
> + WITH_QEMU_LOCK_GUARD(&mon->mon_lock) {
> + if (qmp_mon->commands != &qmp_cap_negotiation_commands) {
> + do_send = true;
> + }
> + }
> +
> + if (do_send) {
> qmp_send_response(qmp_mon, qdict);
> }
> }
We cannot use WITH_QEMU_LOCK_GUARD with "continue" or "break" inside,
but we can use QEMU_LOCK_GUARD:
@@ -347,17 +346,13 @@ static void monitor_qapi_event_emit(QAPIEvent
event, QDict *qdict)
}
qmp_mon = container_of(mon, MonitorQMP, common);
- do_send = false;
-
- WITH_QEMU_LOCK_GUARD(&mon->mon_lock) {
- if (qmp_mon->commands != &qmp_cap_negotiation_commands) {
- do_send = true;
+ {
+ QEMU_LOCK_GUARD(&mon->mon_lock);
+ if (qmp_mon->commands == &qmp_cap_negotiation_commands) {
+ continue;
}
}
-
- if (do_send) {
- qmp_send_response(qmp_mon, qdict);
- }
+ qmp_send_response(qmp_mon, qdict);
}
}
Let me know if this is okay for you!
Paolo
next prev parent reply other threads:[~2025-12-15 14:53 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-13 0:14 [PATCH 0/4] Clean up TSAN warnings Marc Morcos
2025-12-13 0:14 ` [PATCH 1/4] apic: Resize APICBASE Marc Morcos
2025-12-15 9:48 ` Alex Bennée
2025-12-13 0:14 ` [PATCH 2/4] thread-pool: Fix thread race Marc Morcos
2025-12-15 14:43 ` Paolo Bonzini
2025-12-15 17:51 ` Marc Morcos
2025-12-13 0:14 ` [PATCH 3/4] qmp: " Marc Morcos
2025-12-15 14:52 ` Paolo Bonzini [this message]
2025-12-15 17:48 ` Marc Morcos
2025-12-13 0:14 ` [PATCH 4/4] apic: Make apicbase accesses atomic to fix data race Marc Morcos
-- strict thread matches above, loose matches on Subject: below --
2025-12-13 0:12 [PATCH 0/4] Clean up TSAN warnings Marc Morcos
2025-12-13 0:12 ` [PATCH 3/4] qmp: Fix thread race Marc Morcos
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=b6f193d4-b780-439a-80eb-bb8b43acac4e@redhat.com \
--to=pbonzini@redhat.com \
--cc=armbru@redhat.com \
--cc=dave@treblig.org \
--cc=eduardo@habkost.net \
--cc=kvm@vger.kernel.org \
--cc=marcel.apfelbaum@gmail.com \
--cc=marcmorcos@google.com \
--cc=mst@redhat.com \
--cc=mtosatti@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.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).