All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@pond.sub.org>
To: "Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>
Cc: "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: Tue, 24 Nov 2026 09:39:44 +0100	[thread overview]
Message-ID: <87o6be4o8f.fsf@pond.sub.org> (raw)
In-Reply-To: <dec9aea7-8fc9-419b-8178-8e61917f02e2@oss.qualcomm.com> ("Philippe Mathieu-Daudé"'s message of "Tue, 24 Nov 2026 00:03:02 +0100")

Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> writes:

> On 23/11/26 22:29, Denis V. Lunev wrote:
>> From: Denis V. Lunev <den@openvz.org>
>> Rate-limited events can be raised from iothreads, outside the BQL.
>> QUORUM_REPORT_BAD always could be. Since 2155d2dd7f73 BLOCK_IO_ERROR is
>> rate limited too, and any disk on an iothread raises it.
>> The rate-limit timer runs in the main loop. timerlist_run_timers()
>> takes it off the active list before it calls the handler, and only then
>> does the handler take monitor_lock. An iothread raising the same event
>> for the same device in between finds the rate-limit entry with a timer
>> that is no longer pending, and QEMU aborts with:
>>    Assertion `!evstate || timer_pending(evstate->timer)' failed.
>> This hits virtio-blk on an iothread with an error policy other than
>> stop when the storage goes away and every guest request fails.
>> The state is fine, the assert is wrong. Once the timer has fired, the
>> handler is committed to run: it takes the lock as soon as the iothread
>> drops it, sends the stored event and re-arms the timer, exactly as for
>> an event stored while the timer was pending. The event goes out at the
>> same moment it would have had the iothread come in after the handler.
>> The entry is only created, re-armed and freed under monitor_lock, so it
>> cannot go away under the iothread. Drop the assert.
>> Fixes: a24712af5425 ("monitor: Turn monitor_qapi_event_state[] into a hash table")
>> Fixes: 2155d2dd7f73 ("block-backend: per-device throttling of BLOCK_IO_ERROR reports")
>> Signed-off-by: Denis V. Lunev <den@openvz.org>
>> Cc: Markus Armbruster <armbru@redhat.com>
>> Cc: Dr. David Alan Gilbert <dave@treblig.org>
>> Cc: qemu-stable@nongnu.org
>> ---
>>   monitor/monitor.c | 7 ++++---
>>   1 file changed, 4 insertions(+), 3 deletions(-)
>> 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?

> Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
>
>>                */
>>               qobject_unref(evstate->qdict);
>>               evstate->qdict = qobject_ref(qdict);
>> base-commit: 8f66cb79044c370e3813c56ceb7a75a5ca2d0a0e


  reply	other threads:[~2026-11-24  8:40 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 [this message]
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

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=87o6be4o8f.fsf@pond.sub.org \
    --to=armbru@pond.sub.org \
    --cc=armbru@redhat.com \
    --cc=dave@treblig.org \
    --cc=den@openvz.org \
    --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.