From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from PA4PR04CU001.outbound.protection.outlook.com (mail-francecentralazon11023083.outbound.protection.outlook.com [40.107.162.83]) by lore.virtuozzo.com (Postfix) with ESMTPS id 06D6B80031 for ; Tue, 24 Nov 2026 13:40:17 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=GBF6SM/NeqUq+gTI7mZ+ZrDBNvc3OgPCfj8JaHj7vFBJJSrFtTwSLNxNhJV2Q+fSVWvoRfxGxHdXU2X7h9RcBqF5Eeahdm8yutGDtmNHyJtl3ryvDB7ksWDl3U5Son06sxHsuFE+wQPJWgtwoWIWoRQm691/+F6rWeIhNKthn6XNlZrfwwME5q9rFuWf25niPNtI1IKC3+jQRhdDYfo0sZL4K4ZaIqwz9e49cHxlrghLX0QIR7nCfJ5mRQpFmIxx5sdMeKktpojb5PnFlYnDf/23NRzdmoHinMRY1yGE0cCu6f+WPdDKM+hqzwJNQ7Qy6RQahdDw73sK4xxVWA1YnQ== 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=OYnDWLOKOhIRtGjAW5y61JbWOujDExrSCiwyhGCZu7I=; b=AxMe2CEnivsEES+wVzTvd+f6h2XYozjYEG1ttT1vKgS0J/8FiUpWyQGiyVd7ddXVWOHFfuVOYn+xbijVwqrXgJLCNC49ibXuV+08RQVMiZo1PBirQSZiQ9S+pg9Tb5E/UjuLNPDJ6XjsflgY2h4Q3G8UsiceMncCT1D35TwaZNUnU5nKBHzjnyF1wo1l78g8mSOQ34U8CAqT/jp6EjQSs+rs4ru5cADz3bUMNP2hg5NuSvSoJMf2vr2yjKiv14eYU3in5YtcgoB1CC6hT1JVkbI9QQu+4C/m9kx+GD+u+8jtIcPFui2Fi1pxXYe7cloggLDOZ7ACsN3sFOAaSIwzaQ== 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=OYnDWLOKOhIRtGjAW5y61JbWOujDExrSCiwyhGCZu7I=; b=BXAILE61uyWoB+UjuvXhv+Tg4Mbn7uj0Mi1zvbwtiETIterVpjd6SdXK4RtAro7TBFaoSGlnxmqgXSx8iWsRAEZLmdfUaiBUPiVtfNsbgb1wFxTfUMPg8yw1wZPqWoXSFFBjXZb7oIsp/pVNcMRhLyFaKUdteRh6GN4LD5gDRlpTMOxF+9CwD2Kr9G8pNA2lbXkcRRE3JqWTgF28g3ADmA6dv+EvNsvnvZCBEZZWIGEFdXb4xYsN0cvHE4ZOLXPk7KwD1eniKYM4CBhHEXUYBaruqxsNzeZFEs45Ysh6y28YeHgQFIL3xBs+VPfHip/pVnq9r22XFIocrCigj8Xk5g== Received: from DB8PR06CA0038.eurprd06.prod.outlook.com (2603:10a6:10:120::12) by PAWPR08MB11157.eurprd08.prod.outlook.com (2603:10a6:102:46c::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.639.14; Tue, 24 Nov 2026 13:40:10 +0000 Received: from DB1PEPF000509F3.eurprd02.prod.outlook.com (2603:10a6:10:120:cafe::3e) by DB8PR06CA0038.outlook.office365.com (2603:10a6:10:120::12) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.639.14 via Frontend Transport; Tue, 24 Nov 2026 13:40:09 +0000 X-MS-Exchange-Authentication-Results: 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 DB1PEPF000509F3.mail.protection.outlook.com (10.167.242.149) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.662.3 via Frontend Transport; Tue, 24 Nov 2026 13:40:08 +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=OYnDWLOKOhIRtGjAW5y61JbWOujDExrSCiwyhGCZu7I=; b=B3kLAC3k3jQx u7jE1Bu8hohF6qrYvNwbjge22nw8sEuke/qO+o6886cKN0WaJ7Pw5mdBlk22uzYYYpuriHvhZAm3w fRB2zKdbkpyaHTKs+IHjaNm5uOqjYMVwY8uNyR7+kCgobugdoL+L0yaAqba4v8D3tUWxB/Pm1v2nr /LiR9SkfC0BcRbAZK3MQmWoGl9PsiCuJoRhGDAXflttQhmxVaprQ1elEdq9PLqLRYC6R9kOiJaN8l 2kIAV2b/piIGl04T0pSvpWIptAFYLx883TaCp00Cahi0BBR/3HXHJGR3hLS9FD6u+HPctU2AQT7wZ ySrpsEwEl8KAEF0JbzRFCw==; 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 1xVqkY-000ARe-1T; Tue, 24 Nov 2026 14:39:58 +0100 From: Alexander Ivanov To: andrey.zhadchenko@virtuozzo.com Cc: andrey.drobyshev@virtuozzo.com, svt-core@virtuozzo.com Subject: [PATCH hci-8.2 v3] vhost-blk: implement the write-zeroes property Date: Tue, 24 Nov 2026 14:40:05 +0100 Message-ID: <20261124134005.508103-1-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.53.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB1PEPF000509F3:EE_|PAWPR08MB11157:EE_ X-MS-Office365-Filtering-Correlation-Id: 1574d5b6-368e-44f8-47ea-08df4a3074b7 X-LD-Processed: 0bc7f26d-0264-416e-a6fc-8352af79c58f,ExtAddr List-Id: svt-core@virtuozzo.com X-MS-Exchange-Transport-Rules-Loop: 1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|1800799024|376014|82310400026|23010399003|10067099003|261102123227099003|261021121427099003|261021133027099003|56012099006|261022075727099003|261021135927099003|261009223027099003|261021130227099003|261022113327099003|261026121527099003|261021123027099003|261022105027099003|261026130827099003|261026140227099003|261026135527099003|261028144727099003|261022115727099003|18002099003|5113699003|13003099007; X-Microsoft-Antispam-Message-Info: djYgDz8Ai99HfmVd8/0N7omy+ydkFn1Ej8Shz0dvjyRY32k+RmFpPoIRZtQjGf3dO8QBJ7WeaO7e4Qcav3OfBFhmvaM4fyyNGh4EOg81zz93n75ktXD/u5ym8Lpi7AH0lmMnuQTw7dA41GGEkD+pTw192Ju8bMW9EMXvXlShpwaCzsuz+ppHHzU6xBVfAvVNFI6Xtqw1aIF4sO53/xbFEzQ9tsVTGqQHkUNaqHqk1WkcB9rbc72mtWQPqQrJW38lfCUi6KsEm+5mUxmt6haPNdJNjo6wl2RaRDTof+qOd6qlWrEbRBcqB/VeDUMdePrMkfP3zovztRwnGxiKv/qsRwQaRcbsrARM8WFtogqetDJVpnyFeIGjUIuCI5A8IetQWlTDqqy04CfZ9agKvE1d3Wuw7cfR1nThQ+wWqCyn4V+uUc6fWkNPY5IpxgFy3OSG8CQJ3eckAY/wJjLZzafF2SKtKvO/kd6+bcjeW9Abo+jgKY2UL65o+Tl03ML3sruApi1x7sWQVP7ymJmb9KiFQVgdArmiccAuqLBuSc59WOzIK7noYp7NCEu6GQEQ8FE+XHisXoBohxg+p4cbmPj5njLERoWy24/VF+8GpwhPdNLpO5m/OI25iyNwDa2Bylaf7fiqfPKF/e5qTJq/PajSG7KVnaRRu8BnNRzt8f9rKRhBkyj2STkDyncevC5IfUsNsZf7pKDCTyWwHB9Q2yEIVg== 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)(36860700016)(1800799024)(376014)(82310400026)(23010399003)(10067099003)(261102123227099003)(261021121427099003)(261021133027099003)(56012099006)(261022075727099003)(261021135927099003)(261009223027099003)(261021130227099003)(261022113327099003)(261026121527099003)(261021123027099003)(261022105027099003)(261026130827099003)(261026140227099003)(261026135527099003)(261028144727099003)(261022115727099003)(18002099003)(5113699003)(13003099007);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 41bVHoNGJ/iWAvBu1fBEnkgXi32CHa202cXC4RU6xwVmrettRDOtsgeRRl6Pc/F6gzxmoBJH3pFw23H2vHNctIIKvwak4ZfBbmSPd3Dt8xn84sINO2Bp0NXWTCYqQPKSUJ7ZQPZI3lH2j7+yLiAvA7OQSO7BCFj8KP4BfhXz013OlCiwrG7sRXOFqMUPH/bRCIcyUvB8uSv5UH0q5J0+Yfep7uEAkAWJj8b+4CEKOa1aai4it5FMIoW71HwLAVlqORdSkGYdodLSeaJ0PP9j5uUSQ5VhWZ4Cusv05Dd3COfBhhQMErfxuiaQJ55regGvn7BPXpPCO6ag6uYu/CjU6HgfwdiaHEiQ5DS9zkzk6GM2ulGxfA71c/TpjGeW4wLvsdmH7YTArN11ULbTWTb7Api0LDK3j54pNbLoAP8xQvObXVLWhzNHWEDXF0qRz20u X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Nov 2026 13:40:08.6904 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1574d5b6-368e-44f8-47ea-08df4a3074b7 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: DB1PEPF000509F3.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR08MB11157 vhost-blk in the kernel now handles VIRTIO_BLK_T_WRITE_ZEROES. It sends each request to the backend as a single WRITE ZEROES bio and answers VIRTIO_BLK_S_UNSUPP when the backend does not support WRITE ZEROES at the time of the request, so the guest falls back to writing zeroes. With the write-zeroes property on, offer VIRTIO_BLK_F_WRITE_ZEROES and set max_write_zeroes_sectors to the largest range one bio can carry, rounded down to 64 KiB. The kernel fails a range not aligned to the logical block size of the backend, and a constant keeps the guest-visible limit the same on every host. Do not offer the feature for a read-only device. Do not derive the feature or the limit from the WRITE ZEROES limit of the backend. It changes while QEMU has the device open, e.g. when a dm table is reloaded with a target that does not pass WRITE ZEROES through, while the guest reads the config only at probe and the destination of a migration or qemu-update must offer the features the guest has negotiated. Fail realize if the property is on and the kernel does not offer the feature. Masking it silently would make the guest ABI depend on the host: a migration to a node with an older kernel would start the destination without the feature and fail only in virtio_load(), after RAM has been transferred. The property stays off by default. The first kernel version with the support answered VIRTIO_BLK_S_IOERR for a backend without WRITE ZEROES: do not turn the property on with it. https://virtuozzo.atlassian.net/browse/VSTOR-141684 Signed-off-by: Alexander Ivanov --- v3: - rename from "advertise write zeroes with the backend limit". - do not read write_zeroes_max_bytes from sysfs: it changes while the device is open and the guest reads the config only at probe. The kernel now answers VIRTIO_BLK_S_UNSUPP on a backend without WRITE ZEROES, so advertise a constant limit, the same on every host. - fail realize if the property is on and the kernel does not offer the feature, instead of masking it. - rebase on the worker ioctl series. hw/block/vhost-blk.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/hw/block/vhost-blk.c b/hw/block/vhost-blk.c index f88c1c304e8..24982ea7834 100644 --- a/hw/block/vhost-blk.c +++ b/hw/block/vhost-blk.c @@ -9,6 +9,7 @@ */ #include "qemu/osdep.h" +#include "qemu/units.h" #include "qapi/error.h" #include "qemu/cutils.h" #include "qemu/error-report.h" @@ -33,6 +34,11 @@ #include "migration/cpr.h" #include "system/runstate.h" +/* The kernel issues the range as one bio and fails it if not lbs-aligned */ +#define VHOST_BLK_MAX_WRITE_ZEROES_SECTORS \ + QEMU_ALIGN_DOWN(UINT32_MAX >> BDRV_SECTOR_BITS, \ + (64 * KiB) >> BDRV_SECTOR_BITS) + /* * Spread the virtqueues round-robin over nworkers kernel threads. Thread 0 is * the default worker VHOST_SET_OWNER created; vq 0 and every nworkers-th vq @@ -724,6 +730,16 @@ static void vhost_blk_device_realize(DeviceState *dev, Error **errp) goto cleanup; } + if (virtio_has_feature(s->host_features, VIRTIO_BLK_F_WRITE_ZEROES) && + !virtio_has_feature(s->dev.features, VIRTIO_BLK_F_WRITE_ZEROES)) { + error_setg(errp, "vhost-blk: write-zeroes is not supported by the " + "vhost-blk kernel module"); + vhost_dev_cleanup(&s->dev); + /* vhost_dev_cleanup() closes vhostfd */ + s->vhostfd = -1; + goto cleanup; + } + return; cleanup: @@ -795,6 +811,7 @@ static uint64_t vhost_blk_get_features(VirtIODevice *vdev, if (s->conf.readonly) { virtio_add_feature(&features, VIRTIO_BLK_F_RO); + virtio_clear_feature(&features, VIRTIO_BLK_F_WRITE_ZEROES); } if (s->conf.num_queues > 1) { @@ -838,6 +855,12 @@ static void vhost_blk_update_config(VirtIODevice *vdev, uint8_t *config) blkcfg.physical_block_exp = get_physical_block_exp(conf); blkcfg.alignment_offset = 0; virtio_stw_p(vdev, &blkcfg.num_queues, s->conf.num_queues); + if (virtio_host_has_feature(vdev, VIRTIO_BLK_F_WRITE_ZEROES)) { + virtio_stl_p(vdev, &blkcfg.max_write_zeroes_sectors, + VHOST_BLK_MAX_WRITE_ZEROES_SECTORS); + blkcfg.write_zeroes_may_unmap = 1; + virtio_stl_p(vdev, &blkcfg.max_write_zeroes_seg, 1); + } memcpy(config, &blkcfg, sizeof(struct virtio_blk_config)); } @@ -858,7 +881,7 @@ static const Property vhost_blk_properties[] = { DEFINE_PROP_UINT16("num-threads", VHostBlk, conf.num_threads, 1), DEFINE_PROP_BIT64("flush", VHostBlk, host_features, VIRTIO_BLK_F_FLUSH, true), -/* Discard and write-zeroes not yet implemented in kernel module */ +/* Discard not yet implemented in kernel module */ DEFINE_PROP_BIT64("discard", VHostBlk, host_features, VIRTIO_BLK_F_DISCARD, false), DEFINE_PROP_BIT64("write-zeroes", VHostBlk, host_features, -- 2.53.0