Skip to contentSkip to conversation

block: Never drop BLOCK_IO_ERROR with action=stop for rate limiting

PATCH Superseded Kevin Wolf 4 participants 7 messages Feb 12 – Mar 9

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

PATCH 1/1 block: Never drop BLOCK_IO_ERROR with action=stop for rate limiting

Commit 2155d2dd introduced rate limiting for BLOCK_IO_ERROR to emit an event only once a second. This makes sense for cases in which the guest keeps running and can submit more requests that would possibly also fail because there is a problem with the backend.

However, if the error policy is configured so that the VM is stopped on errors, this is both unnecessary because stopping the VM means that the guest can't issue more requests and in fact harmful because stopping the VM is an important state change that management tools need to keep track of even if it happens more than once in a given second. If an event is dropped, the management tool would see a VM randomly going to paused state without an associated error, so it has a hard time deciding how to handle the situation.

This patch disables rate limiting for action=stop by essentially considering all BLOCK_IO_ERRORs with action=stop different errors. If the error is reported to the guest or ignored, the rate limiting stays in place.

Fixes 2155d2dd7f73 ('block-backend: per-device throttling of BLOCK_IO_ERROR reports')
---
 qapi/block-core.json |  2 +-
 monitor/monitor.c    | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
qapi/block-core.json +1 -1
index b82af742561..4118d884f46 100644
@@ -5789,7 +5789,7 @@
 # .. note:: If action is "stop", a `STOP` event will eventually follow
 #    the `BLOCK_IO_ERROR` event.
 #
-# .. note:: This event is rate-limited.
+# .. note:: This event is rate-limited, except if action is "stop".
 #
 # Since: 0.13
 #
monitor/monitor.c +12 -0
index 1273eb72605..93bd2b93e65 100644
@@ -525,6 +525,18 @@ static gboolean qapi_event_throttle_equal(const void *a, const void *b)
                        qdict_get_str(evb->data, "node-name"));
     }
 
+    /*
+     * If the VM is stopped after an I/O error, this is important information
+     * for the management tool to keep track of the state of QEMU and we can't
+     * merge any events. At the same time, stopping the VM means that the guest
+     * can't send additional requests and the number of events is already
+     * limited, so we can do without rate limiting.
+     */
+    if (eva->event == QAPI_EVENT_BLOCK_IO_ERROR &&
+        !strcmp(qdict_get_str(eva->data, "action"), "stop")) {
+        return FALSE;
+    }
+
     if (eva->event == QAPI_EVENT_MEMORY_DEVICE_SIZE_CHANGE ||
         eva->event == QAPI_EVENT_BLOCK_IO_ERROR) {
         return !strcmp(qdict_get_str(eva->data, "qom-path"),
Signature · 1 line
2.53.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 19 lines · Kevin Wolf

Commit 2155d2dd introduced rate limiting for BLOCK_IO_ERROR to emit an event only once a second. This makes sense for cases in which the guest keeps running and can submit more requests that would possibly also fail because there is a problem with the backend.

However, if the error policy is configured so that the VM is stopped on errors, this is both unnecessary because stopping the VM means that the guest can't issue more requests and in fact harmful because stopping the VM is an important state change that management tools need to keep track of even if it happens more than once in a given second. If an event is dropped, the management tool would see a VM randomly going to paused state without an associated error, so it has a hard time deciding how to handle the situation.

This patch disables rate limiting for action=stop by essentially considering all BLOCK_IO_ERRORs with action=stop different errors. If the error is reported to the guest or ignored, the rate limiting stays in place.

Quoted 6 lines
Fixes 2155d2dd7f73 ('block-backend: per-device throttling of BLOCK_IO_ERROR reports')
---
 qapi/block-core.json |  2 +-
 monitor/monitor.c    | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
Reviewed-by on v1 1/1
#2 lore raw
In reply to Kevin Wolf
Quoted 14 lines · Kevin Wolf

Commit 2155d2dd introduced rate limiting for BLOCK_IO_ERROR to emit an event only once a second. This makes sense for cases in which the guest keeps running and can submit more requests that would possibly also fail because there is a problem with the backend.

However, if the error policy is configured so that the VM is stopped on errors, this is both unnecessary because stopping the VM means that the guest can't issue more requests and in fact harmful because stopping the VM is an important state change that management tools need to keep track of even if it happens more than once in a given second. If an event is dropped, the management tool would see a VM randomly going to paused state without an associated error, so it has a hard time deciding how to handle the situation.

Quoted 7 lines

This patch disables rate limiting for action=stop by essentially considering all BLOCK_IO_ERRORs with action=stop different errors. If the error is reported to the guest or ignored, the rate limiting stays in place.

Fixes 2155d2dd7f73 ('block-backend: per-device throttling of BLOCK_IO_ERROR reports')
Signature · 2 lines
Best regards,
Vladimir
author
#3 lore raw
In reply to Kevin Wolf

Am 12.02.2026 um 22:27 hat Kevin Wolf geschrieben:

Quoted 32 lines

Commit 2155d2dd introduced rate limiting for BLOCK_IO_ERROR to emit an event only once a second. This makes sense for cases in which the guest keeps running and can submit more requests that would possibly also fail because there is a problem with the backend.

However, if the error policy is configured so that the VM is stopped on errors, this is both unnecessary because stopping the VM means that the guest can't issue more requests and in fact harmful because stopping the VM is an important state change that management tools need to keep track of even if it happens more than once in a given second. If an event is dropped, the management tool would see a VM randomly going to paused state without an associated error, so it has a hard time deciding how to handle the situation.

This patch disables rate limiting for action=stop by essentially considering all BLOCK_IO_ERRORs with action=stop different errors. If the error is reported to the guest or ignored, the rate limiting stays in place.

Fixes 2155d2dd7f73 ('block-backend: per-device throttling of BLOCK_IO_ERROR reports')
monitor/monitor.c +2 -0
index 1273eb72605..93bd2b93e65 100644
@@ -525,6 +525,18 @@ static gboolean qapi_event_throttle_equal(const void *a, const void *b)
                        qdict_get_str(evb->data, "node-name"));
     }
 
+    /*
+     * If the VM is stopped after an I/O error, this is important information

monitor/monitor.c static gboolean qapi_event_throttle_equal(const void *a, const void *b) · line 539

Quoted 10 lines
monitor/monitor.c +10 -0
+     * for the management tool to keep track of the state of QEMU and we can't
+     * merge any events. At the same time, stopping the VM means that the guest
+     * can't send additional requests and the number of events is already
+     * limited, so we can do without rate limiting.
+     */
+    if (eva->event == QAPI_EVENT_BLOCK_IO_ERROR &&
+        !strcmp(qdict_get_str(eva->data, "action"), "stop")) {
+        return FALSE;
+    }
+

It turns out that this approach is completely wrong. The harmless part is that the hash table is filled up with many events that don't actually need throttling. The worse part is that events aren't even considered equal to themselves, which means that the hash table can't find them to remove them, which in turn causes use after free crashes.

I'll post a v2 that avoids the whole rate limiting code path for I/O errors that don't need the throttling.

Kevin

#4 lore raw
In reply to Kevin Wolf
Quoted 14 lines · Kevin Wolf

Commit 2155d2dd introduced rate limiting for BLOCK_IO_ERROR to emit an event only once a second. This makes sense for cases in which the guest keeps running and can submit more requests that would possibly also fail because there is a problem with the backend.

However, if the error policy is configured so that the VM is stopped on errors, this is both unnecessary because stopping the VM means that the guest can't issue more requests and in fact harmful because stopping the VM is an important state change that management tools need to keep track of even if it happens more than once in a given second. If an event is dropped, the management tool would see a VM randomly going to paused state without an associated error, so it has a hard time deciding how to handle the situation.

Quoted 7 lines

This patch disables rate limiting for action=stop by essentially considering all BLOCK_IO_ERRORs with action=stop different errors. If the error is reported to the guest or ignored, the rate limiting stays in place.

Fixes 2155d2dd7f73 ('block-backend: per-device throttling of BLOCK_IO_ERROR reports')

This looks like a qemu-stable material (10.0.x, 10.1.x, 10.2.x).

Please let me know if it isn't.

Thanks,

/mjt

#5 lore raw
Quoted 1 line · Michael Tokarev

This looks like a qemu-stable material (10.0.x, 10.1.x, 10.2.x).

It is already Cc'd qemu-stable, N/M.

Thanks,

/mjt

author
#6 lore raw

Am 08.03.2026 um 09:34 hat Michael Tokarev geschrieben:

Quoted 4 lines · Michael Tokarev
Quoted 2 lines

This looks like a qemu-stable material (10.0.x, 10.1.x, 10.2.x).

It is already Cc'd qemu-stable, N/M.

Oops, seems I forgot the Cc: tag in the commit message. Sorry! I'll try to remember doing that again next time.

Kevin