From: Markus Armbruster <armbru@pond.sub.org>
To: "Denis V. Lunev" <den@virtuozzo.com>
Cc: "Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>,
"Denis V. Lunev" <den@openvz.org>,
qemu-devel@nongnu.org, "Markus Armbruster" <armbru@redhat.com>,
"Dr. David Alan Gilbert" <dave@treblig.org>,
qemu-stable@nongnu.org
Subject: Re: [PATCH] monitor: fix abort when a rate-limited event races with its timer
Date: Thu, 26 Nov 2026 05:03:14 +0100 [thread overview]
Message-ID: <87ik1k6xz1.fsf@pond.sub.org> (raw)
In-Reply-To: <5b13cf6f-0222-4029-96de-0464299f6bab@virtuozzo.com> (Denis V. Lunev's message of "Wed, 25 Nov 2026 17:58:54 +0100")
"Denis V. Lunev" <den@virtuozzo.com> writes:
> On 11/24/26 10:57, Philippe Mathieu-Daudé wrote:
>> On 24/11/26 09:39, Markus Armbruster wrote:
>>> Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> writes:
>>>
>>>> On 23/11/26 22:29, Denis V. Lunev wrote:
[...]
>>>>> diff --git a/monitor/monitor.c b/monitor/monitor.c
>>>>> index 2654b81890..22c00b6195 100644
>>>>> --- a/monitor/monitor.c
>>>>> +++ b/monitor/monitor.c
>>>>> @@ -360,13 +360,14 @@ monitor_qapi_event_queue_no_reenter(QAPIEvent event, QDict *qdict)
>>>>> MonitorQAPIEventState key = { .event = event, .data = data };
>>>>>
>>>>> evstate = g_hash_table_lookup(monitor_qapi_event_state, &key);
>>>>> - assert(!evstate || timer_pending(evstate->timer));
>>>>>
>>>>> if (evstate) {
>>>>> /*
>>>>> * Timer is pending for (at least) evconf->rate ns after
>>>>> - * last send. Store event for sending when timer fires,
>>>>> - * replacing a prior stored event if any.
>>>>> + * last send, or it has expired and its handler has not
>>>>> + * taken monitor_lock yet. Either way the handler will
>>>>> + * send what is stored here. Store event for sending
>>>>> + * then, replacing a prior stored event if any.
>>>>
>>>> How about:
>>>>
>>>> + * last send, or its handler has not taken monitor_lock
>>>> + * yet (the timer may have fired, or not been armed yet).
>>>> + * Either way the handler will send what is stored here.
>>>> + * Store event for sending then, replacing a prior stored
>>>> + * event if any.
>>>>
>>>> ?
>>>
>>> I find this version harder to understand. What scenario exactly is
>>> missing from Denis's version? And is it important here?
>>
>> The issue Denis fixed also exists in the gap before the first
>> timer_mod_ns() under monitor_lock and between timer_mod_ns() calls
>> after later sends, now described as "or has not been armed yet":
>>
>> "the timer has fired [, or has not been armed yet], and its handler has
>> not taken monitor_lock."
>
> We hold monitor_lock from the hash insertion through the first
> timer_mod_ns(), so another thread can't see the entry before the timer is
> armed. The handler holds the same lock while it sends the event and rearms
> the timer.
>
> Another thread can see the entry with the timer no longer pending only after
> the timer fires and before the handler takes monitor_lock. I'd keep the
> posted wording.
This makes sense, thank you!
Reviewed-by: Markus Armbruster <armbru@redhat.com>
prev parent reply other threads:[~2026-11-26 4:04 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 21:29 [PATCH] monitor: fix abort when a rate-limited event races with its timer Denis V. Lunev
2026-11-23 23:03 ` Philippe Mathieu-Daudé
2026-11-24 8:39 ` Markus Armbruster
2026-11-24 9:57 ` Philippe Mathieu-Daudé
2026-11-25 16:58 ` Denis V. Lunev
2026-11-25 17:04 ` Philippe Mathieu-Daudé
2026-11-25 17:05 ` Denis V. Lunev
2026-11-26 4:03 ` Markus Armbruster [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=87ik1k6xz1.fsf@pond.sub.org \
--to=armbru@pond.sub.org \
--cc=armbru@redhat.com \
--cc=dave@treblig.org \
--cc=den@openvz.org \
--cc=den@virtuozzo.com \
--cc=philmd@oss.qualcomm.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@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.