* [PATCH] monitor: fix abort when a rate-limited event races with its timer
@ 2026-11-23 21:29 Denis V. Lunev
2026-11-23 23:03 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 8+ messages in thread
From: Denis V. Lunev @ 2026-11-23 21:29 UTC (permalink / raw)
To: qemu-devel; +Cc: den, Markus Armbruster, Dr. David Alan Gilbert, qemu-stable
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.
*/
qobject_unref(evstate->qdict);
evstate->qdict = qobject_ref(qdict);
base-commit: 8f66cb79044c370e3813c56ceb7a75a5ca2d0a0e
--
2.55.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH] monitor: fix abort when a rate-limited event races with its timer 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 0 siblings, 1 reply; 8+ messages in thread From: Philippe Mathieu-Daudé @ 2026-11-23 23:03 UTC (permalink / raw) To: Denis V. Lunev, qemu-devel Cc: Markus Armbruster, Dr. David Alan Gilbert, qemu-stable 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. ? Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> > */ > qobject_unref(evstate->qdict); > evstate->qdict = qobject_ref(qdict); > > base-commit: 8f66cb79044c370e3813c56ceb7a75a5ca2d0a0e ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] monitor: fix abort when a rate-limited event races with its timer 2026-11-23 23:03 ` Philippe Mathieu-Daudé @ 2026-11-24 8:39 ` Markus Armbruster 2026-11-24 9:57 ` Philippe Mathieu-Daudé 0 siblings, 1 reply; 8+ messages in thread From: Markus Armbruster @ 2026-11-24 8:39 UTC (permalink / raw) To: Philippe Mathieu-Daudé Cc: Denis V. Lunev, qemu-devel, Markus Armbruster, Dr. David Alan Gilbert, qemu-stable 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 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] monitor: fix abort when a rate-limited event races with its timer 2026-11-24 8:39 ` Markus Armbruster @ 2026-11-24 9:57 ` Philippe Mathieu-Daudé 2026-11-25 16:58 ` Denis V. Lunev 0 siblings, 1 reply; 8+ messages in thread From: Philippe Mathieu-Daudé @ 2026-11-24 9:57 UTC (permalink / raw) To: Markus Armbruster Cc: Denis V. Lunev, qemu-devel, Markus Armbruster, Dr. David Alan Gilbert, qemu-stable 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: >>> 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? 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." > >> Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> >> >>> */ >>> qobject_unref(evstate->qdict); >>> evstate->qdict = qobject_ref(qdict); >>> base-commit: 8f66cb79044c370e3813c56ceb7a75a5ca2d0a0e > ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] monitor: fix abort when a rate-limited event races with its timer 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-26 4:03 ` Markus Armbruster 0 siblings, 2 replies; 8+ messages in thread From: Denis V. Lunev @ 2026-11-25 16:58 UTC (permalink / raw) To: Philippe Mathieu-Daudé, Markus Armbruster Cc: Denis V. Lunev, qemu-devel, Markus Armbruster, Dr. David Alan Gilbert, qemu-stable 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: >>>> 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? > 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. Den ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] monitor: fix abort when a rate-limited event races with its timer 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 1 sibling, 1 reply; 8+ messages in thread From: Philippe Mathieu-Daudé @ 2026-11-25 17:04 UTC (permalink / raw) To: Denis V. Lunev, Markus Armbruster Cc: Denis V. Lunev, qemu-devel, Markus Armbruster, Dr. David Alan Gilbert, qemu-stable On 25/11/26 17:58, Denis V. Lunev wrote: > 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: >>>>> 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? >> 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. Fine by me. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] monitor: fix abort when a rate-limited event races with its timer 2026-11-25 17:04 ` Philippe Mathieu-Daudé @ 2026-11-25 17:05 ` Denis V. Lunev 0 siblings, 0 replies; 8+ messages in thread From: Denis V. Lunev @ 2026-11-25 17:05 UTC (permalink / raw) To: Philippe Mathieu-Daudé, Markus Armbruster Cc: Denis V. Lunev, qemu-devel, Markus Armbruster, Dr. David Alan Gilbert, qemu-stable On 11/25/26 18:04, Philippe Mathieu-Daudé wrote: > On 25/11/26 17:58, Denis V. Lunev wrote: >> 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: >>>>>> 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? >>> 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. > Fine by me. Thanks a lot for review :-) Den ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] monitor: fix abort when a rate-limited event races with its timer 2026-11-25 16:58 ` Denis V. Lunev 2026-11-25 17:04 ` Philippe Mathieu-Daudé @ 2026-11-26 4:03 ` Markus Armbruster 1 sibling, 0 replies; 8+ messages in thread From: Markus Armbruster @ 2026-11-26 4:03 UTC (permalink / raw) To: Denis V. Lunev Cc: Philippe Mathieu-Daudé, Denis V. Lunev, qemu-devel, Markus Armbruster, Dr. David Alan Gilbert, qemu-stable "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> ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-11-26 4:04 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 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.