From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from OSPPR02CU001.outbound.protection.outlook.com (mail-norwayeastazon11023142.outbound.protection.outlook.com [40.107.159.142]) by lore.virtuozzo.com (Postfix) with ESMTPS id 7C9B78002A for ; Tue, 24 Nov 2026 13:32:23 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=HyaCZJ9Quk4phVjI59C/46uFZWiN1s4+A2+45MSd4+hLLJupudGAaYiOMWVWKewdezo/zRdWbD5xLNetSW4Njyo9Yqwrk7uMwgosGwcUOF7+zX1ozQ76wWcaby0vM5a1iBAxi5IsKpG0L4CVrn2sS13pzAg8CqZG1htZPnLXayLIDeCOkdOd23RpfJISMjpgb1iXXv3A8cp4DeE5dRWA1mdX/tgz4i11cc1K+YGSBMWdMCvmuMnf3gggUUgl12vho+RaEsN5t+PqseM633zIXKD2aFErhCtgBHEsb/YKExZshnH5Cs5IZcWTaBq+UO7QLtLIWLgQdcSOuvoZzbgOgA== 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=EaOxtsCdobP+7a+bQsYw8hHejA1yz52LrfJRy3m6zgY=; b=DL2iZYATHElWtxOu8uW6Vm1/MpLyKCDrYnnL8QLmUFetVw9Q2sXJvj8rbdwyCpLYw+fsNYW8Fyu4Up4qoOfAK529IlTevm76CQAL/5tQPo0eqklQSctwHUrBJEvIEiK1F23sXFt1wguDRG6t4msb7HRNuHkrp9go6gjFAvEgcCM+094YVTUHVVeewD6LKM08GjdGlUkKadYiIRYeeNgsYYNK/KbMHHSxAELcAkyfwYxNTmOqS5Vw951LWNJeRXUh0lcYm8IqSGhOD1dUlcnpshVoO6XDJpI+GZUuAd3q0IvQbgGGGIvYNB7f9FlRs0YAVS8oipRD86ldpAOgZJKpWA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none 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=EaOxtsCdobP+7a+bQsYw8hHejA1yz52LrfJRy3m6zgY=; b=TQnUBdt0lzmmmgjH2Asx2A1GNjvNQPF6CJAk9ax5BJPm6c2ji9hjYwCQxy+eZ8y81LcUtYNMZsgGgrc6B8nkf1jpM3Mob9itDyUYBIXhK/Ei03hlTcT1h0LCxKp1lUiORogAaeNfVlCtryymbVvrwxVZpdU6mYNz7eX94k1m9UO4u+yMl1EB9B6WNisK/b1HJ0GqtSmBbnZqhgpVyqVv6eyWz56870esVl5bt0gg/bbX1HJK6QnU+EPEWFJ14EMAW/DrLJUfCQ2SnTyMkmyvSXJbD20IxosDPgMOOFTzcmgzDDHVQZzu/gV79R1UMTVZtOmNjd66R76nQFAYsAjc5g== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from VI0PR08MB10743.eurprd08.prod.outlook.com (2603:10a6:800:205::19) by PAWPR08MB9829.eurprd08.prod.outlook.com (2603:10a6:102:2e6::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.639.13; Tue, 24 Nov 2026 13:32:18 +0000 Received: from VI0PR08MB10743.eurprd08.prod.outlook.com ([fe80::7a7c:d078:f125:f16a]) by VI0PR08MB10743.eurprd08.prod.outlook.com ([fe80::7a7c:d078:f125:f16a%3]) with mapi id 15.21.0639.012; Tue, 24 Nov 2026 13:32:18 +0000 Message-ID: <3db56d05-bf1f-47bc-a2d0-79930709441e@virtuozzo.com> Date: Tue, 24 Nov 2026 14:32:16 +0100 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH hci-8.2 v2] vhost-blk: advertise write zeroes with the backend limit To: Andrey Drobyshev Cc: andrey.zhadchenko@virtuozzo.com, svt-core@virtuozzo.com References: <20261120132317.3867152-1-alexander.ivanov@virtuozzo.com> <20261123163311.76889-1-andrey.drobyshev@virtuozzo.com> Content-Language: en-US From: Alexander Ivanov In-Reply-To: <20261123163311.76889-1-andrey.drobyshev@virtuozzo.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: GV0P278CA0068.CHEP278.PROD.OUTLOOK.COM (2603:10a6:710:2a::19) To VI0PR08MB10743.eurprd08.prod.outlook.com (2603:10a6:800:205::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI0PR08MB10743:EE_|PAWPR08MB9829:EE_ X-MS-Office365-Filtering-Correlation-Id: 29816978-fc13-4379-8e60-08df4a2f5c51 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|366016|376014|23010399003|10067099003|261102123227099003|261021121427099003|260925021311599003|261021133027099003|56012099006|5023799004|261022075727099003|261021135927099003|260925021911599003|4143699003|260925022911599003|261009223027099003|261021130227099003|261022113327099003|261026121527099003|261021123027099003|261022105027099003|261026130827099003|261026140227099003|261026135527099003|261028144727099003|261022115727099003|18002099003|5113699003|22082099003; X-Microsoft-Antispam-Message-Info: L6jP3iywT9ySYDQIWpZk0/pzxqRQvi9gK7yhx9RmEOeYf0PeFUGhR14pfy9KtZbGypkNpiuRKBrr6lwry1gh9LgSUHpqoc11iKlz4QSxAu19oXG9D/f5pwmz39woKZn2PiVxSlsgyFsWp4+KHfTc+RZmxyLeavJMMdNzQ71D9b9o42FzlHUx1BMHkKHm59DhtkevEc9hlqsLCow4icRYWVF3XBrGqcirr93ddPsXF8R0/JiJlcZ1jNsY0rlgVM3RNdlWX/fBHU7P2ktkxthbDZASVkkQ+KjtIRrfCC3hpT5ZG0bApeQ2bY+F3qbhjBELUDVIy5X+qRb7n5mNnjCR3F2YwR6We2eVuioQiSjtiktcQojo/ZSbwCcx91whLgxc8YUOFPqye+n5LNs89WanznGXPhNt+y47k9vGFUfNQ91QfUAwUngD7U6O6JwwpUjQl6dGEIYV3E0Tha+fGL8PfOVa+aC/JO81LIOPnCCDVqisqt+OHjLmPcWxNx+BYyR1zzmRZI8FJ8EubvdHCXOXZdFXEJ6ztC6nHldqcc2HPZ1Br5k1uFfEinz1wWP6DdZbGej5GPUsLpmrCRQEH26ilisK019+tW5JfjnrvcJy7wFhgmE0Xk5P4T4IhRmN5Ad1W6o+uPHBIvNHkiDMF6sxUJmyLFxL9Tr/qQF2ovyB59o= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI0PR08MB10743.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014)(23010399003)(10067099003)(261102123227099003)(261021121427099003)(260925021311599003)(261021133027099003)(56012099006)(5023799004)(261022075727099003)(261021135927099003)(260925021911599003)(4143699003)(260925022911599003)(261009223027099003)(261021130227099003)(261022113327099003)(261026121527099003)(261021123027099003)(261022105027099003)(261026130827099003)(261026140227099003)(261026135527099003)(261028144727099003)(261022115727099003)(18002099003)(5113699003)(22082099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?MHlOYkRYMHhXNHc4R0xNNHpLTjVseXphS2VIRDJRVFNLTUFNMHVTNzZ2aVkr?= =?utf-8?B?N2ZBOXA0Tk1aMnVQSGg1QlRSbnJRWnBUYTBFOWtoTERZVW9sN3l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MvV284SWEzU3pVTlJBWXNwWW5jdEVzNWIxVFF6WnJw?= =?utf-8?B?TFF0RG1WYUcxYTZFNFBGbzNveEtORWwwL2dBUGlZSVlWa29TOGl3Q2tjTU1D?= =?utf-8?B?eW5pSi8vR3VaYVZrbERFUzJPdDJRU2wrU2ZGenpSZG41MGdXZDhENHBBSXhq?= =?utf-8?B?T1g3SWE1VDU2empucjVrTGYvejVZV3YycG9vVFI0MEk0VExPNmxhNktNMlcz?= =?utf-8?B?bW1qZ1pIdVRjSFU1YkIxUU13ZGhrM0ZxNFYzUE94OE9UQkpTRUNQcGp5MnRw?= =?utf-8?B?cEFhT3VXc2NFMVYwd3pwT3JwZ3JQTmwvOU9sUHhBWk8wUVZ4NG1XeUNzVEJO?= =?utf-8?B?czBZL3VtUGpKUi9iZjlMVjBJUWlKK1hMZlh2Zkc5ZXZuTVM2VlFvMUZCZGJ2?= =?utf-8?B?Ris0amlhVE9hQnd1VXVRU1FLYjVpb25EQlIrZzY4bGdNaG1uMnlINHFBODVx?= =?utf-8?Q?+ovZUQW8L/JF+1ew=3D?= X-Auto-Response-Suppress: DR, OOF, AutoReply X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 29816978-fc13-4379-8e60-08df4a2f5c51 X-MS-Exchange-CrossTenant-AuthSource: VI0PR08MB10743.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Nov 2026 13:32:18.4709 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Af53Y7MKcY+WyfyJY8TkxPH55TAtMYsusW9fDIZsv2TryPiQVo5Yinp8hqhxLwskSj5RBXeGwXKhXXZ35h5TkuixpvRWAm1tWVm5T5d7aYo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR08MB9829 >> +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; >> + } > (6) [nit] Bare -1 return, result stored in *s as a side effect, GError > from g_file_get_contents() dropped. The caller cannot say whether the > file is missing, unreadable or unparsable. Usual shape: > > static bool vhost_blk_get_write_zeroes_sectors(VHostBlk *s, > uint32_t *sectors, > Error **errp) > > with the caller reporting via warn_report_err(), or propagating the > error, see (2). Since we send sectors pointer as an argument of the function, we no longer need the VHostBlk pointer. Changed to: static bool vhost_blk_get_write_zeroes_sectors(dev_t rdev, uint32_t *sectors,                                                Error **errp) >> + >> + /* The kernel issues the whole range as one bio */ >> + s->max_write_zeroes_sectors = MIN(bytes >> BDRV_SECTOR_BITS, >> + UINT32_MAX >> BDRV_SECTOR_BITS); > (4) [low] The limit is not rounded down to the logical block size of > the backend. The kernel commit requires it: > > The VMM must advertise the feature only for a backend with WRITE > ZEROES support and set max_write_zeroes_sectors from its limit, > capped at 8388607 so that the range fits in one bio and rounded > down to the logical block size, and max_write_zeroes_seg to 1. > > vhost_blk_parse_write_zeroes() fails a request with > (sector | nr_sects) & bs_mask. 8388607 is odd, so whenever the cap > applies on a backend with a 4K logical block size, a guest that chunks > a large range at the advertised limit gets VIRTIO_BLK_S_IOERR on every > chunk. The cap applies to common limits: loop and nbd report exactly > 4294966784 bytes. dm-qcow2 takes its logical block size from the block > device under the image's filesystem (qcow2_io_hints()), so a 4Kn host > disk gives 4096. > > logical_block_size is still hard-coded to BDRV_SECTOR_SIZE for the > guest, so 4Kn backends have other problems, but this part is cheap: > > int lbs; > > if (ioctl(s->backend_fd, BLKSSZGET, &lbs) < 0) { > ... > } > sectors = MIN(bytes >> BDRV_SECTOR_BITS, > UINT32_MAX >> BDRV_SECTOR_BITS); > sectors = QEMU_ALIGN_DOWN(sectors, lbs >> BDRV_SECTOR_BITS); Agreed, fixed. The limit is now rounded down to the logical block size of the backend, taken with BLKSSZGET on the backend fd. It also covers the uncapped case: loop reports UINT_MAX >> 9 sectors, which is odd as well. If BLKSSZGET fails, the feature is not offered, as when the sysfs limit cannot be read. A limit that rounds down to zero hits the existing "does not support write zeroes" path. >> + 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); >> + } >> + } > (1) [major] The limit is sampled once here, but the table of the open > device is replaced at runtime, and the kernel checks the live limit. > > Every backup of a running VM does this. ploop-backup calls > ploop_tg_init(path, "push_backup", ...), which does (ploop lib/dm.c, > paraphrased): > > 1 dmsetup reload ploopXXX --table "0 ... error" > 2 dmsetup create ploopXXX.push_backup ... qcow2 ... > 3 dmsetup reload ploopXXX --table \ > "0 ... push_backup ... /dev/mapper/ploopXXX.push_backup" > 4 dmsetup resume ploopXXX > > The dev_t QEMU has open stops being a qcow2 target and becomes > push_backup stacked over a new dm-qcow2 device. dm-push-backup sets > only num_discard_bios (same for dm-tracking, which ploop copy stacks > the same way), and dm_table_supports_write_zeroes() requires > num_write_zeroes_bios on every target. The limit of ploopXXX therefore > drops to 0 for the duration of the backup regardless of dm-qcow2 > underneath. Any target without it shows the effect: a loop device > reports 4294966784, dm-delay on top of it reports 0. > > Consequences: > > a) Running guest. QEMU keeps advertising the value from realize, the > guest keeps sending WRITE ZEROES, and the kernel does > > max_sects = bdev_write_zeroes_sectors(bdev); > ... > if (vhost_blk_backend_ro(f) || !max_sects || ... > *status = VIRTIO_BLK_S_IOERR; > > Every such request fails until the backup ends. A 6.12 guest does > not hide it: blkdev_issue_zeroout() falls back to writing zero > pages only on -EOPNOTSUPP; -EIO goes to the caller (filesystem, > mkfs, fallocate on the block device). > > b) QEMU realized while the stack is in place. qemu-update re-runs > realize in the new process, reads 0, and vhost_blk_get_features() > clears a bit the guest has already negotiated. virtio_load() then > fails with "Features 0x... unsupported. Allowed features: 0x...". > With cpr-exec that is after exec, with no old process to return to. > No check for an active ploop backup was found in libvirt's > qemuDomainGuestQemuUpdate(); other callers were not searched. > > QEMU cannot fix this alone. Re-reading the limit on a uevent and > raising a config change interrupt does not help: Linux virtio-blk > re-reads only the capacity (virtblk_config_changed_work()), queue > limits are set once at probe. It needs one of the following on the > kernel side before the feature is enabled: > > - dm-push-backup and dm-tracking pass WRITE ZEROES through with the > limit of the underlying dm-qcow2 device, so the limit of ploopXXX is > the same before, during and after the swap; or > - vhost-blk stops failing on the live limit (the block layer already > splits an oversized WRITE ZEROES bio; a zero limit could fall back > to writing zeroes or at least return VIRTIO_BLK_S_UNSUPP). > > The commit message should state the invariant the patch relies on: > "the WRITE ZEROES limit of the backend device does not change while > QEMU has it open". Added a kernel patch:  [PATCH hci-8.2] drivers/vhost/blk: return UNSUPP for write zeroes on a backend without it Removed vhost_blk_get_write_zeroes_sectors(). > > (2) [design] write-zeroes=on is silently best-effort, so the same > command line produces a different guest ABI depending on the host. > > The feature is dropped in three cases: the limit cannot be read > (warning), the limit is 0 (warning), the kernel has no vhost-blk > support for it (masked by vhost_get_features(), no message). > Management cannot tell from the command line or from an error which > VMs have the feature. > > Failure scenario, rolling upgrade: a VM started on an upgraded node > negotiates WRITE ZEROES. When it moves to a node that is not upgraded > yet (older vhost-blk, or older dm-qcow2 reporting 0), the destination > QEMU starts without the bit and says nothing; the migration fails only > at virtio_load() with the generic "Features ... unsupported", after RAM > has been transferred. > > Conventional fix: OnOffAuto. "on" fails realize with a specific error > if the kernel or the backend cannot provide the feature, "auto" probes > quietly. A destination that cannot honour the feature then refuses to > start. If the bit property stays, the kernel case needs the same > warning as the other two. > >> } >> >> 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); >> + } > This is where (1b) and (2) become a failed load: the bit depends on a > value read from the host at realize, and virtio_load() checks the > guest's features against it. > >> 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); >> + } > (3) [design] max_write_zeroes_sectors is guest-visible state derived > from the host; it is neither migrated nor checked on load. > > If the destination backend reports a smaller limit than the source > (a different kernel's dm-qcow2 is enough), the feature bits match, the > load succeeds, and the guest keeps using the limit it read at probe on > the source. The destination kernel fails every range above its own > limit (nr_sects > max_sects -> VIRTIO_BLK_S_IOERR), and the guest is > not told until it reboots or rebinds the driver. Unlike (2), this > failure is silent. > > Possible fixes: > > - carry the advertised value in a vmstate subsection; on load keep > advertising the source's value if the destination backend can take > it, fail the load otherwise; or > - make it a property, as virtio-blk does with > max-write-zeroes-sectors, so that management pins one value per VM, > and fail realize if the backend limit is below it. After the previous changes the limit is not derived from the backend: vhost-blk rejects only ranges above UINT32_MAX >> 9 or not lbs-aligned, and the block layer splits the bio to the queue limit, so a different dm-qcow2 on the destination cannot cause IOERR. The lbs rounding did make the value host-dependent; it is now a constant (UINT32_MAX >> 9 aligned down to 64 KiB), so nothing needs migrating. > (5) [nit] The fields are filled in based on s->max_write_zeroes_sectors, > not on whether the feature is offered. On a kernel without vhost-blk > support the bit is masked by vhost_get_features(), but the config still > carries the limit, may_unmap and seg. Harmless by the spec, but it is > host-dependent config for no reason. Single source of truth: > > if (virtio_host_has_feature(vdev, VIRTIO_BLK_F_WRITE_ZEROES)) { > >> memcpy(config, &blkcfg, sizeof(struct virtio_blk_config)); >> } Moot, since realize fails without kernel support, but done anyway: config is now filled under virtio_host_has_feature(). > [...] > > Summary: (1) blocks enabling the property, since every backup of the VM > becomes a window of guest I/O errors. (2) and (3) affect migration. > (4)-(6) are minor.