From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from GVXPR05CU001.outbound.protection.outlook.com (mail-swedencentralazon11023106.outbound.protection.outlook.com [52.101.83.106]) by lore.virtuozzo.com (Postfix) with ESMTPS id EF5F480027 for ; Fri, 20 Nov 2026 13:23:27 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=InxLAENLHjz1uouqBZBcntf+f1A9DsTsieh2ROWFkGdhtxnp7sEb6LLruKehrOzHF1eiYx6dqpkbt4QtIVvKtGPtOzGDd30S5BvezkAPgOzh8qPkb8yJNQkyVyjzBjsoIZ/nVzRNIwOYCYPemb6DYNBpZVoAdH64W751GtiklG3PEXG+6qIQ+7j9/2Uicqp1yhnRM53Vo4E1FEI6EIkMdaxschtXIKXZtuhdJzJRpP9jFNVrGKdGKwWmyC8p1LHFsRVG5rhTV1b21iHQ8PxmcnJ29/vXM5w0ver1RtE1Z7QHzTmvqSOB3hnoBsLTzHNRqkkn4jUufc1sOMNRPff3MQ== 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=ga/PSEZvzJU5WMgjv2OaN2aQC4uqsVTfpd6M3HNL8lU=; b=bui3N8U7dF6B+IMnthZuaW7v6pvr6ixfFXjUEB0Gz/oS97AEWMFczmH87FREwznxYPqcpiDsyvDVSoLl5rUloS1C+rFgnjcc8HXBa/Bys50waAGZ4gHgzzV26dBxzDcCDX/CdNpjmrvkPN0LdRZlgiOPmW4nX0ZUDRlhn6SFmlL4/o1Vj0xOBBpPZc3mrFeCYpsijQm8sa9qHQVn95PqFGfhG7cldyU7D4jvtKyTSJWTSZl+zPWCiZezuf7D4cZF67Jdu42dB5N+WTlzIHPldeVRxeH7jfbRSmMbzq0jGpxU/uoAGMdOy7sRIqnZwWHouOuE89N4UvurwJI24EsbCg== 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=ga/PSEZvzJU5WMgjv2OaN2aQC4uqsVTfpd6M3HNL8lU=; b=VabpbfEI8TdEPYWeD86xlZDRW/IJlJ7QwXWlQmXAl2aCtITHyMpdAcui/LI484LS+xJ4K88KTkTvjq64qQUvpwcEfItqBkF5gmn7H/cMW2EDa0jxCp2boF/LOLFatbVK70AbModDg67onycaSiIJxjkSEMmQKZKzeEJ2oxYX8OosG9VutGGmCQPk1Wmf3lA9+5lThcRjNk9Byv+eaU9wpMIe/ZIDzpEe6KoeuM8H6mxZ7fAQ86cHBlEMs/8nF9BA994FNdZCJ/1y+kNy1qmU0fkolfO8N3c8M+AA4nNAr5Q+dWtUpkzXxGS56DL4h5zkpu86FhJMjRQ7qD1YkUgADA== Received: from PAZP264CA0155.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:1f9::19) by GV2PR08MB524981.eurprd08.prod.outlook.com (2603:10a6:150:38a::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.639.12; Fri, 20 Nov 2026 13:23:22 +0000 Received: from ZR1PEPF0000E6B5.eurprd07.prod.outlook.com (2603:10a6:102:1f9:cafe::68) by PAZP264CA0155.outlook.office365.com (2603:10a6:102:1f9::19) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.639.12 via Frontend Transport; Fri, 20 Nov 2026 13:23:22 +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 ZR1PEPF0000E6B5.mail.protection.outlook.com (10.167.241.68) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.639.5 via Frontend Transport; Fri, 20 Nov 2026 13:23:20 +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=ga/PSEZvzJU5WMgjv2OaN2aQC4uqsVTfpd6M3HNL8lU=; b=bKMOPX6Mx5xg znox9aczmjHG2Rk3zeje4oaEGOKXY38HjEno/lZbxoQXlFZN1Ud+ir7E4R//0j8mtYsyrafGiNDb7 Q9BReAPR/EQzZHO1JgX/oQty0fTqbTdTpqdBo4gRMKTN4UGiK+pyC1YGf1NZViogLC4w9xZFpgxwJ 31pfgbpyehNL39RA847cocwwnAfx9EDfJ9vggIwVtGDiHn3NtcnXtOw4a7LU/iQLmhTDfD/3ilds6 XOLtf0TF6n4+YrHDH6iBgFxPH/c0h5BPCVBgeCVF9QJjVeP8+angxD7/NmCVp/SPfDlKxPHsTOhPs 1+n6q+FKmjxPH3VAwiKXUg==; 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 1xUOaC-006ulb-0D; Fri, 20 Nov 2026 14:23:16 +0100 From: Alexander Ivanov To: andrey.zhadchenko@virtuozzo.com Cc: andrey.drobyshev@virtuozzo.com, svt-core@virtuozzo.com Subject: [PATCH hci-8.2 v2] vhost-blk: advertise write zeroes with the backend limit Date: Fri, 20 Nov 2026 14:23:17 +0100 Message-ID: <20261120132317.3867152-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: ZR1PEPF0000E6B5:EE_|GV2PR08MB524981:EE_ X-MS-Office365-Filtering-Correlation-Id: 629eb979-ba85-4cd4-ddf9-08df470971ea 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|23010399003|1800799024|82310400026|376014|261026121527099003|261026140227099003|261026130827099003|261026135527099003|261021135927099003|261022075727099003|261022115727099003|261022113327099003|261022105027099003|261028144727099003|261021133027099003|261021123027099003|261021130227099003|261021121427099003|261102123227099003|10067099003|261009223027099003|18002099003|57112099003|5113699003; X-Microsoft-Antispam-Message-Info: A6qSWGkTYgBp1Vu9e5QxD3LlsysIBawFr7CpUSSkHC3c3xH66ZjcjP0Njj86FOTFxZ+sP7jdetG3Fm1ic9Y+PI/VMoDnxLRDI3uBQ0HoDg157mtuwJCQ6mElts19CtOgnck1fJi2KcINim6+/T8/4I1hOYh2ApwXTWTYG6t9FiJD0R1hc4jeHl0h3SsKbNwWHdLqMYe7djWNKRxExPMLV/j+/1If4Hx4FTSXqWgpiE3ZAGT7NZEXPdzFZiuil5VDWxYM72YhBoXIdHm8uUvrTMuTvFm1mRGpt4zC19UKwVN996fQrBoCi2tC+XDz5Gp0CTqabzpuJ0epVj5KxazPmkqr/uD5YKdSJxwG5Qm5Wk5QwvvhT4bUXY17CsWUuD8tk+YvrfpiTq9oCX68ylqmpKB2AFfKndwCywgl/cXvuNrEdYNy54F4UP1EcCHaqsleG8t+gRE12xozNis3CsebwzesJzYGAaKKHCcGx/s4mhD711W8xXpLCxAqfdgX+dU2Ol+tyBMawt1eRBaUDbmvGZRsc7sESM/wfS//qT9HNgIkDzrcCcSuEzmn1V9rQYx5kZcqWj1QnFv1eTPnUD0H0RSGft2CsCD/WX6BPHZRK/LPDggqXcmJhR7eQMkHO2qcljNPFpkKuAcmejFxm4zfSZNfCZ7bT5eT/mPqJzDfur63Svn8LC+UNGNomRYhzmN9+iCwV6E5aTdMGDLjaYgo/qUVY27qbvAvw6rs5OLCK6ijEBgS6ox33S1oK3B4xnGpLOyfmAZLio93qQ8UEY98v7lmzjpHeM3xpDLf/E7qedkk8Kh4dShiNR7RLUo69ViFjdOqnfyx9dKTF7xFi0EDnqvhPpc6S5nhbqNYxZbLhB2hN5KT4hcmQAsO3jb29vJp 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)(23010399003)(1800799024)(82310400026)(376014)(261026121527099003)(261026140227099003)(261026130827099003)(261026135527099003)(261021135927099003)(261022075727099003)(261022115727099003)(261022113327099003)(261022105027099003)(261028144727099003)(261021133027099003)(261021123027099003)(261021130227099003)(261021121427099003)(261102123227099003)(10067099003)(261009223027099003)(18002099003)(57112099003)(5113699003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: OYEDE1OirWssVfh4MteJMHkiuARBzF/RQb4hJGYPr+fz7qSGwZUYtkm4wkPyAu9exXSFONwigLPCEkUCUkk4Pfis8yLOQK3rz0sIfO/q/dB7Tutrzl0kUvt6Texvz7qY1mmXjXEjG83LkyeGKdB3Xih2dV0gZUmXvktdylfdHdBjOmxZ9XI4T07tiamt6GJzm0/y+tBmDo4p0gdGkrdhYBcCyaY1ftdgK1KRFXfbFMpHVI4A+SQ7VmpcDwpufBENM7r0FJsT2M1P/2PFWCcJtBFPvYplZa7UyhPJv2ZJAYQs2S1nn2FhqhavfU04kEeGR0QxoFLzmbQzC4pdNbaOfEk1uZPMSJUsF9z695rX2r1yug/nSDI9xRHcbbQMKc0HyvVrSD8bBCPSMbta5BU70gfZpvaAoeso1MC1OovwKCFB4Frf3WP+ZUkHIkUvaJY+ X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Nov 2026 13:23:20.0756 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 629eb979-ba85-4cd4-ddf9-08df470971ea 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: ZR1PEPF0000E6B5.eurprd07.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV2PR08MB524981 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 does not fall back to writing zero pages, so the feature only works on a backend that supports WRITE ZEROES and for a range that fits in one bio. With the write-zeroes property on, read write_zeroes_max_bytes of a writable backend from sysfs and advertise it as max_write_zeroes_sectors, capped to what one bio can carry. A partition has no queue/ directory of its own, so read the limit of the whole disk, whose queue it shares. Do not offer VIRTIO_BLK_F_WRITE_ZEROES when the backend reports no limit, the limit cannot be read, or the backend is opened read-only. The property stays off by default. A kernel without write zeroes support in vhost-blk does not offer the feature, so it is not negotiated there. https://virtuozzo.atlassian.net/browse/VSTOR-141684 Signed-off-by: Alexander Ivanov --- v2: - read write_zeroes_max_bytes of the whole disk for a partition, which has no queue/ directory of its own. - do not advertise the feature and warn when the limit cannot be read. hw/block/vhost-blk.c | 45 ++++++++++++++++++++++++++++++++++- include/hw/virtio/vhost-blk.h | 1 + 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/hw/block/vhost-blk.c b/hw/block/vhost-blk.c index abddff02c6d..153cc7604d0 100644 --- a/hw/block/vhost-blk.c +++ b/hw/block/vhost-blk.c @@ -521,6 +521,30 @@ static bool vhost_blk_uevent_attach(VHostBlk *s, Error **errp) return true; } +static int vhost_blk_get_write_zeroes_sectors(VHostBlk *s) +{ + g_autofree char *dev = NULL; + g_autofree char *part = NULL; + g_autofree char *path = NULL; + g_autofree char *val = NULL; + uint64_t bytes; + + dev = g_strdup_printf("/sys/dev/block/%u:%u", + major(s->backend_rdev), minor(s->backend_rdev)); + part = g_strdup_printf("%s/partition", dev); + path = g_strdup_printf("%s/%squeue/write_zeroes_max_bytes", dev, + g_file_test(part, G_FILE_TEST_EXISTS) ? "../" : ""); + if (!g_file_get_contents(path, &val, NULL, NULL) || + qemu_strtou64(g_strstrip(val), NULL, 10, &bytes)) { + return -1; + } + + /* The kernel issues the whole range as one bio */ + s->max_write_zeroes_sectors = MIN(bytes >> BDRV_SECTOR_BITS, + UINT32_MAX >> BDRV_SECTOR_BITS); + return 0; +} + static bool vhost_blk_open_backend(VHostBlk *s, Error **errp) { ERRP_GUARD(); @@ -562,6 +586,16 @@ static bool vhost_blk_open_backend(VHostBlk *s, Error **errp) s->conf.devpath); goto fail; } + + if (virtio_has_feature(s->host_features, VIRTIO_BLK_F_WRITE_ZEROES)) { + if (vhost_blk_get_write_zeroes_sectors(s)) { + warn_report("vhost-blk: unable to read write zeroes limit " + "of '%s'", s->conf.devpath); + } else if (!s->max_write_zeroes_sectors) { + warn_report("vhost-blk: '%s' does not support write zeroes", + s->conf.devpath); + } + } } vhost_blk_update_size(s, errp); @@ -722,6 +756,9 @@ static uint64_t vhost_blk_get_features(VirtIODevice *vdev, uint64_t res; features |= s->host_features; + if (!s->max_write_zeroes_sectors) { + virtio_clear_feature(&features, VIRTIO_BLK_F_WRITE_ZEROES); + } virtio_add_feature(&features, VIRTIO_BLK_F_BLK_SIZE); virtio_add_feature(&features, VIRTIO_BLK_F_SEG_MAX); @@ -775,6 +812,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 (s->max_write_zeroes_sectors) { + virtio_stl_p(vdev, &blkcfg.max_write_zeroes_sectors, + s->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)); } @@ -789,7 +832,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, diff --git a/include/hw/virtio/vhost-blk.h b/include/hw/virtio/vhost-blk.h index 059f1ebc701..e4bcbe49127 100644 --- a/include/hw/virtio/vhost-blk.h +++ b/include/hw/virtio/vhost-blk.h @@ -46,6 +46,7 @@ typedef struct VHostBlk { bool vhost_started; uint64_t length; uint64_t backend_rdev; + uint32_t max_write_zeroes_sectors; QEMUBH *resize_bh; Error *cpr_blocker; } VHostBlk; -- 2.53.0