From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from AM0PR83CU005.outbound.protection.outlook.com (mail-westeuropeazon11020115.outbound.protection.outlook.com [52.101.69.115]) by lore.virtuozzo.com (Postfix) with ESMTPS id 7FE33803F6 for ; Wed, 18 Nov 2026 08:28:33 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KxTyDvdwaFboZKed9lPKEyulDtYvFkwyJrI8vQrsiyymWROuETz0ruqbWOqV3cLoGAx0FZDpS2uWECBrlHho6NmgYoMpMkQ46+jXu1N5dvdGE98Aql8JhD9RckdVYSo/PvJYAh8kVu+H/G87Wsl5LvpQXdxbR9vzPvOC6fW3yuPLMyBWRU8IoIFnfobhh241CdoUCrUSSzi5eKx7f0GoFfJN0hnPWretbNq9qmt/3a3KNUeee1CWmtwm9yLNSuYvqOly9PicLxTHOYBdSSZep6ibkiKOaRSFdzjVsWkoPZJtch7SUM7R/9fZwH/URaXl9ZLN/vr/Wv21ulEv60ADtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=R0bgRYoatGFLSjZkfwgw7NQp5IVEvY7lvXhXwXQdPQo=; b=AVqr77lhhmdpkri9iNkPExAwQov3pVkQ4xNU9oOzQtURNpYuFwj2JNGL+RaykB7CEhiIJvCW8hAkEDpirDOlq5QPSCYe1XiipD/IFleyjmZy0UyukJ7/vGLsCiun2k1u6I2XKAiGxXirxL4E9tK8dFf8WWeBbqLDiZGwS3tvHZagr4mjG/zhoCJTP/BogsNUvyas97Vr/jFhREqJ3eWVUPx46eEURClzcZdC5avMA579KBh8VBHjn8lVZICITfQSf+TLSuNzMMqAS+QcdxRx1mUt4ws5HIap26MERgOK4MO9Q2asAXMwsUboyDXVa2uiHzZddO3ExanLCuQFWUsNTA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 130.117.225.111) smtp.rcpttodomain=virtuozzo.com smtp.mailfrom=virtuozzo.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=virtuozzo.com; dkim=pass (signature was verified) header.d=virtuozzo.com; arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=R0bgRYoatGFLSjZkfwgw7NQp5IVEvY7lvXhXwXQdPQo=; b=r3aaryuCtjl4UFrMxgChR9vziYxknuGAbTvVb+pMVW1JSQgd2FNbrKWPLFcR5lofeoa1r2M+iuaB7JNKXNK98bb4h2TR1mrxQbfd02BYyl9URxa95S+rkA66KjPUAeX6PLJ6UfqtVAlI99+YthgUgXX4x37Yb9SDUJTLgG5JyhtIahtETXXpl7K6tCMNoosZvHG9uu/HPDw/WVV/Y5N7j6A51tEPeKlgjO8EALdSE42W09b+oTOcggjyrqgVhMlQMHD2AiVMI9G0FOGzhiZwN4IuWWOIbhdf0OQrWxUUXCPHMh3ZLFxl9853PJvw0tNW/EY5BJQZSF4EmxK79F+xFQ== Received: from AS8PR04CA0187.eurprd04.prod.outlook.com (2603:10a6:20b:2f3::12) by DBBPR08MB6043.eurprd08.prod.outlook.com (2603:10a6:10:20b::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.615.14; Wed, 18 Nov 2026 08:28:29 +0000 Received: from AM1PEPF000C1AD7.eurprd02.prod.outlook.com (2603:10a6:20b:2f3:cafe::28) by AS8PR04CA0187.outlook.office365.com (2603:10a6:20b:2f3::12) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.615.13 via Frontend Transport; Wed, 18 Nov 2026 08:28:29 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=pass (sender IP is 130.117.225.111) smtp.mailfrom=virtuozzo.com; dkim=pass (signature was verified) header.d=virtuozzo.com;dmarc=pass action=none header.from=virtuozzo.com; Received-SPF: Pass (protection.outlook.com: domain of virtuozzo.com designates 130.117.225.111 as permitted sender) receiver=protection.outlook.com; client-ip=130.117.225.111; helo=relay.virtuozzo.com; pr=C Received: from relay.virtuozzo.com (130.117.225.111) by AM1PEPF000C1AD7.mail.protection.outlook.com (10.167.242.102) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.615.4 via Frontend Transport; Wed, 18 Nov 2026 08:28:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=R0bgRYoatGFLSjZkfwgw7NQp5IVEvY7lvXhXwXQdPQo=; b=RoziFmvizvWC HMY3o/lBqb9K4ieIYP/YuRRz0N1fVetbeDWIMiK01fVvLAJA759Xcpzc060UUIgPLgv/CTdCd7sjs NQ3vG2iwwdrLeTwxdaDsMw6Epn3PPUvjkVsusuMGYUKNsoM/qWF7ZAFsVsYCRx4y8ivXIfxU+gGTW iUrUCfC0F4K7KjtWaQKtEwGMWCJ9kllzoGuCV8uxP0FLcapCDqlH0lUXYtNt9r7Bckq4oPiqMiglI Yfbjy/TN5fT3WDzY1NVMG4EGYXpfpireyVeHHYL38j9qDkhICxjKZqLkP4ehVemFWXcbuovO5peWt 4dLj1+OWeeLv9UO9fw6ZJA==; Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=sky) by relay.virtuozzo.com with esmtps (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1xTaxX-00H3eo-1D; Wed, 18 Nov 2026 09:28:28 +0100 From: Alexander Ivanov To: andrey.zhadchenko@virtuozzo.com Cc: andrey.drobyshev@virtuozzo.com, svt-core@virtuozzo.com Subject: [PATCH hci-8.2 v2 2/2] vhost-blk: pause the VM on an IO_ERROR uevent from dm-qcow2 #VSTOR-152175 Date: Wed, 18 Nov 2026 09:28:26 +0100 Message-ID: <20261118082826.3259784-3-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261118082826.3259784-1-alexander.ivanov@virtuozzo.com> References: <20261118082826.3259784-1-alexander.ivanov@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM1PEPF000C1AD7:EE_|DBBPR08MB6043:EE_ X-MS-Office365-Filtering-Correlation-Id: fc71bf81-bb63-448d-7454-08df454dec9c X-LD-Processed: 0bc7f26d-0264-416e-a6fc-8352af79c58f,ExtAddr List-Id: svt-core@virtuozzo.com X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|36860700016|376014|23010399003|6133799003|22082099003|18002099003|5113699003|261009223027099003|13003099007|56012099006|261102123227099003|261028144727099003|261026121527099003|261026140227099003|261021121427099003|261022105027099003|261022075727099003|261021135927099003|261021123027099003|10067099003; X-Microsoft-Antispam-Message-Info: TNm46uukI1wSnlmh+U8GWPwyBWhtSUsvmLvZAdBtFQxBSwHIeGsTnQykf8YzmGRtcqNVryasAKdGnL7Xk7TVX+QzTXfz4pHjafwEUWPZRlgfZ0RqjKP6Zhp22eKEwu9wyE1/mBcEf5TB4MZ2YQJy/E0Mjr+KZ+sdT3MNxzSfvVPk03KHIPYAYGcHxUacdb9D6XRG8TXm7TwxKextmqIRhDjl5dC+VCggqtAb0RZebjJv3fSjJRBTgE+AKc0NJ4tKZ935KnHV+yaf9MT2gd9XgKB9N9qQ4qIsDZsaAbksKCwJkArx6EeSwekfey+RtH76YwngB19ITW96Y4dEmhQI8uAvHLOlRtHRAIjjvf/EVGmzSDoGqKm1ACe0gEzHD7HjIe/F4+pyVgY0yI2ra+Hv/i7bKs6al4mS2YiYYBoAaFdK64k4blKF92wzzd+Wq5lq/hHA9Lfx7sCGxaA+jqc1Zir7IEAu+pqhRyWKKHb+5B33dnDLiedpTUnZI0GUiwX8c/QGTyVMrPpiRthSfAE3SIPLKdWc0YzitIU7aOu/N14BGoimzS5eQiRoV3gFgntw1J4F+ggaGDI/5u3GNMDr8z3Hlw5RqAJt7XBks2gfJa5nKJegl/sGoGLciA4CGEvzsu13UK/rmKEBbjbI5Kx3cQ== X-Forefront-Antispam-Report: CIP:130.117.225.111;CTRY:CH;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:relay.virtuozzo.com;PTR:relay.virtuozzo.com;CAT:NONE;SFS:(13230040)(1800799024)(82310400026)(36860700016)(376014)(23010399003)(6133799003)(22082099003)(18002099003)(5113699003)(261009223027099003)(13003099007)(56012099006)(261102123227099003)(261028144727099003)(261026121527099003)(261026140227099003)(261021121427099003)(261022105027099003)(261022075727099003)(261021135927099003)(261021123027099003)(10067099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 87mGSrXsWRx8ad8qM10uO9YeBhrLNIyXAleQS3g690cG8HpgRoHc6bAi1NSXbccWDQbNv7hlMOSDyFKSTzCMxD+urQUd3sKIEbkbVPz4ns9k9HyBTk4K3glfPizpW1/JARyU+04fqhlthrcLy3fflRwPhTKOJF6R9uI++1l2kdSHL56EOeEC++7GmQDWT3dU7h79AtRQfbSjeRZs+8boQqMo6JxG6L1rUDot925cIJeB9AAaOmTtZ+OPQd9zcb5QpjDZwDpX29PP3SCvuohUK98FJhQH1D6P/m5V9ZhpMpN5lkirB3nJYGnBlcI2GKhSfVHpOtdiFZWohgU6VU+oLoZyaHHMdHgO461F6jTjAUX15bBINGijXbh5Za2Z2yKrjtTB6j+bFh+0l/h5guivSSqmW9d9WOdonVyMdX5zi72MkaDttMkyjshdoBRMLsi7 X-Auto-Response-Suppress: DR, OOF, AutoReply X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2026 08:28:29.4308 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fc71bf81-bb63-448d-7454-08df454dec9c X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=0bc7f26d-0264-416e-a6fc-8352af79c58f;Ip=[130.117.225.111];Helo=[relay.virtuozzo.com] X-MS-Exchange-CrossTenant-AuthSource: AM1PEPF000C1AD7.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB6043 vhost-blk completes requests to the guest in the kernel, so werror and rerror had no effect: dm-qcow2 held the failed write under the enospc or stop policy, but the VM kept running with the request stuck. dm-qcow2 reports a held request with a change uevent carrying IO_ERROR=1, IO_ERROR_OP=read|write and IO_ERROR_ERRNO=. Parse it on the uevent socket, stop the VM with the io-error reason and emit BLOCK_IO_ERROR, as the block layer does for other devices. The device field is the id of the proxy, which is the disk alias libvirt looks the disk up by. libvirt loads the same policy into the dm-qcow2 table, so an event the policy of the device would not stop on means a misconfiguration. Warn about it, but stop anyway: the request is held in the kernel, and without the stop nobody resubmits it. The VM stops with RUN_STATE_IO_ERROR, on which vhost-blk keeps running, so the held requests survive the pause. libvirt resubmits them before cont. dm-qcow2 repeats the event on every failed retry, so ignore it once the held request has been reported. The run state does not cover this: it stays running until the main loop handles the stop request, after the whole uevent queue is read. If the VM is already stopped, e.g. by an error on another disk, still block migration and emit BLOCK_IO_ERROR, but do not request a stop. Ignore the event while vhost is stopped and in the suspended state, which has no transition to io-error. Migration and savevm from IO_ERROR do not notify the VM state handlers, so vhost-blk would keep running and its vring state would be saved stale. The held requests cannot be migrated either, so block migration until the VM runs again, and fail it in pre_save for a migration that was already running when the error came. Reject the stop policy without the ueventfd property: without the socket QEMU never learns about the held request. Accept enospc without it, as it is the default and rejecting it would break every device configured without ueventfd. https://virtuozzo.atlassian.net/browse/VSTOR-152175 Signed-off-by: Alexander Ivanov --- hw/block/vhost-blk.c | 103 +++++++++++++++++++++++++++++++++- include/hw/virtio/vhost-blk.h | 2 + 2 files changed, 102 insertions(+), 3 deletions(-) diff --git a/hw/block/vhost-blk.c b/hw/block/vhost-blk.c index 3e9653fb28c..51b40d85089 100644 --- a/hw/block/vhost-blk.c +++ b/hw/block/vhost-blk.c @@ -32,6 +32,7 @@ #include "migration/blocker.h" #include "migration/cpr.h" #include "system/runstate.h" +#include "qapi/qapi-events-block-core.h" static int vhost_blk_start(VirtIODevice *vdev) { @@ -205,6 +206,10 @@ static void vhost_blk_vm_state(void *opaque, bool running, RunState state) vhost_blk_stop(vdev); vhost_blk_reset(vdev); } else if (state == RUN_STATE_RUNNING) { + VHostBlk *s = VHOST_BLK(vdev); + + s->io_error_held = false; + migrate_del_blocker(&s->io_error_blocker); vhost_blk_start(vdev); } } @@ -293,6 +298,55 @@ static void vhost_blk_block_cpr(VHostBlk *s) } } +static void vhost_blk_io_error(VHostBlk *s, bool is_read, int error) +{ + DeviceState *dev = DEVICE(s); + DeviceState *proxy = dev->parent_bus ? dev->parent_bus->parent : NULL; + BlockdevOnError on_err = is_read ? s->conf.conf.rerror + : s->conf.conf.werror; + g_autofree char *path = NULL; + bool running; + + /* dm-qcow2 repeats the event on every failed retry of a held request */ + if (s->io_error_held || !s->vhost_started || + runstate_check(RUN_STATE_SUSPENDED)) { + return; + } + + path = object_get_canonical_path(OBJECT(dev)); + + if (on_err != BLOCKDEV_ON_ERROR_STOP && + (on_err != BLOCKDEV_ON_ERROR_ENOSPC || error != ENOSPC)) { + warn_report("vhost-blk: '%s': dm-qcow2 held a failed %s with errno " + "%d against the %s policy, stopping the VM anyway", + path, is_read ? "read" : "write", error, + BlockdevOnError_str(on_err)); + } + + s->io_error_held = true; + if (!s->io_error_blocker) { + error_setg(&s->io_error_blocker, + "vhost-blk: '%s' has requests held in the kernel after " + "an I/O error", path); + migrate_add_blocker_internal(&s->io_error_blocker, NULL); + } + + running = runstate_is_running(); + if (running) { + qemu_system_vmstop_request_prepare(); + } + qapi_event_send_block_io_error(path, + proxy && proxy->id ? proxy->id : "", + NULL, + is_read ? IO_OPERATION_TYPE_READ + : IO_OPERATION_TYPE_WRITE, + BLOCK_ERROR_ACTION_STOP, true, + error == ENOSPC, strerror(error), 0, 0); + if (running) { + qemu_system_vmstop_request(RUN_STATE_IO_ERROR); + } +} + /* * The uevent socket is created, bound and filtered by the management * layer and passed to us via the "ueventfd" property. @@ -310,6 +364,9 @@ static void vhost_blk_uevent_read(void *opaque) bool action_change = false; bool subsystem_block = false; bool resize = false; + bool io_error = false; + bool io_error_read = false; + int io_error_errno = EIO; char *field; char *end; ssize_t len; @@ -351,6 +408,17 @@ static void vhost_blk_uevent_read(void *opaque) subsystem_block = true; } else if (!strcmp(field, "RESIZE=1")) { resize = true; + } else if (!strcmp(field, "IO_ERROR=1")) { + io_error = true; + } else if (!strcmp(field, "IO_ERROR_OP=read")) { + io_error_read = true; + } else if (g_str_has_prefix(field, "IO_ERROR_ERRNO=")) { + int value; + + if (!qemu_strtoi(field + strlen("IO_ERROR_ERRNO="), NULL, 10, + &value) && value > 0) { + io_error_errno = value; + } } else if (g_str_has_prefix(field, "MAJOR=")) { uint64_t value; @@ -373,11 +441,18 @@ static void vhost_blk_uevent_read(void *opaque) field += field_len + 1; } - if (action_change && subsystem_block && resize && - event_major == major(s->backend_rdev) && - event_minor == minor(s->backend_rdev)) { + if (!action_change || !subsystem_block || + event_major != major(s->backend_rdev) || + event_minor != minor(s->backend_rdev)) { + continue; + } + + if (resize) { qemu_bh_schedule(s->resize_bh); } + if (io_error) { + vhost_blk_io_error(s, io_error_read, io_error_errno); + } } } @@ -630,6 +705,14 @@ static void vhost_blk_device_realize(DeviceState *dev, Error **errp) return; } + if (!conf->ueventfd && + (conf->conf.werror == BLOCKDEV_ON_ERROR_STOP || + conf->conf.rerror == BLOCKDEV_ON_ERROR_STOP)) { + error_setg(errp, "vhost-blk: 'stop' error policy requires the " + "'ueventfd' property"); + return; + } + if (!vhost_blk_open_backend(s, errp)) { return; } @@ -704,6 +787,7 @@ static void vhost_blk_device_unrealize(DeviceState *dev) VHostBlk *s = VHOST_BLK(dev); vhost_blk_uevent_detach(s); + migrate_del_blocker(&s->io_error_blocker); qemu_del_vm_change_state_handler(s->mighand); vhost_blk_set_status(vdev, 0); vhost_dev_cleanup(&s->dev); @@ -811,10 +895,23 @@ static const Property vhost_blk_properties[] = { DEFINE_BLOCK_ERROR_PROPERTIES(VHostBlk, conf.conf), }; +static int vhost_blk_pre_save(void *opaque) +{ + VHostBlk *s = opaque; + + if (s->io_error_held) { + error_report("vhost-blk: requests are held in the kernel after an " + "I/O error, resubmit or fail them first"); + return -EBUSY; + } + return 0; +} + static const VMStateDescription vmstate_vhost_blk = { .name = "vhost-blk", .minimum_version_id = 1, .version_id = 1, + .pre_save = vhost_blk_pre_save, .fields = (VMStateField[]) { VMSTATE_VIRTIO_DEVICE, VMSTATE_END_OF_LIST() diff --git a/include/hw/virtio/vhost-blk.h b/include/hw/virtio/vhost-blk.h index 059f1ebc701..935b35f6d6b 100644 --- a/include/hw/virtio/vhost-blk.h +++ b/include/hw/virtio/vhost-blk.h @@ -48,6 +48,8 @@ typedef struct VHostBlk { uint64_t backend_rdev; QEMUBH *resize_bh; Error *cpr_blocker; + Error *io_error_blocker; + bool io_error_held; } VHostBlk; #endif -- 2.53.0