From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 0899180031 for ; Tue, 24 Nov 2026 13:14:25 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AODD52u026023; Tue, 24 Nov 2026 16:13:06 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AODD52u026023 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="x19qGLYd" Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AODD4Pu026019 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Tue, 24 Nov 2026 16:13:04 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AODD4Pu026019 Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-6bab3771146so2573298a12.3 for ; Tue, 24 Nov 2026 05:13:04 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErEmpSMQZStvbHJ7lRNJEg2pr1MKlwDhd4COZgYJW/IWZRhRTRnTAXiq+KI4tg15fNvTtNxfWQ==@openvz.org X-Gm-Message-State: APuU4Z/piB8qISFnz/cj96ubc1fEP5Sn9SZPPkqn3mzbw31dFTnOG/nb zKUJ4KKu1NeDcAY/qn9uhIzO3Ce/un8WV0LVjwk6GMRWIoBN1uNdyhX3/6A7Xo6CxFpkLBZR50e iq645z8yXggY/a90S7sFpqF1u0bXCnLZAYJuIb+s4S05RXgoiToZhoQ== X-Gm-Gg: AZFdTZdRHz1Nca/0qtXi2K1P1X42t7plPnHnyVBk9/zsDb+3DNhu1IUhO5I1L+efSbX pB4Sw6ZzlAAnmSoVtQCfyzreij4NGSFNdQZVFgz9VSWf3ylAoDV1y0w6O92jkthKotAqD5quUO9 2XTMqWtOqKy2q+Y1HD1qqR/hvBpkhyjLm5WDEL5Sd/I2uBvRBEKbga4OjI3m1mgTmz6g3GLBHQQ eG3hhhb9nr7N6sYpbgE73G0NH0iKtuPmM0fCb8AoptbatKyrEkER5D9XwoQUrkIdrG4Obq0H6qa dYFxK5q9nrjJskrP70/GXiCQKXxD1TEFdwZJriLOxb7+44j3IMBSB9UrAvmM0pedqL4iFcYrFmE xgrBs4eeJWFErUZfFEeLr4dXLobVA X-Received: by 2002:a05:6402:e8a:b0:6ba:dd2:7660 with SMTP id 4fb4d7f45d1cf-6ba37ea54e2mr10639543a12.32.1795525983632; Tue, 24 Nov 2026 05:13:03 -0800 (PST) X-Received: by 2002:a05:6402:e8a:b0:6ba:dd2:7660 with SMTP id 4fb4d7f45d1cf-6ba37ea54e2mr10639519a12.32.1795525983082; Tue, 24 Nov 2026 05:13:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795525983; cv=none; d=google.com; s=arc-20260327; b=WavAu6cDz3GQ+M3/U+JsBF4XUUMW2mZ89EnEM/LYyoQaxlnbOBxwDFDgr2Wj9scmJD nEm0znoTBfslWa+jje9/qLBmCz/UpP8siKGxchPK4T65+CNrepUyUvM0SMA5VVQB8itD yU540YFg3GIEYhunZSuierzNoqWonyHjdKlymyQgO12NSnh42CGA7lfqQtN0FouYEK+p 2Y+v/eLuNKKWK7Z1QGjvkV+BaBJcuQiScMkjnWsaW2m1wFjodzkkUepX3QtvNiUwcTzX iX3u/48sZrnWKp+sKli7CJfRkiSTECrSqWCnsEQ/4jwpKXcijQstgHiQN30yMvYb15CU 4uiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=A0ptGbkah73NGSE3NU47JWbpvddgVuvtRzKvRGSWYqU=; fh=CMILZ+goaghq6B4UpCDhf0EQp6kYD0LAlmOkUiVCOvs=; b=P00OzXNFFSWv1io7+n1UCzicfH8Vha/L4JXDlS+92gNw8PMdZii345q82n4tWkPab/ UB7huUO0st4O1sG9Ybh/j7AEnYw/4VCsoLWyXfLiQpBmQXrIHeMwBH2w1qPbPkcPDkXO LzxN4PLA/MfNQf/++qVfh+KFJ9sWYKnbaGD5mpMDDd0VzIVwRhq/hrAjjXnRd9XvysoZ RArE1rKGZDGBOYrt0B4VSGcJ/OS2l/FoqwzLcTIJkeWyJrOCpGp1zaEvCJDvkgXQgKeM PFuXNLA81mPVI4/vj5YyxZOz1DEUx3927FvfJaSTyTF/+TOy3eQ0ne3N7rQ16oed6Z5h DvaQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=x19qGLYd; spf=pass (google.com: domain of alexander.ivanov@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=alexander.ivanov@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-6ba373daf3dsi12214643a12.229.2026.11.24.05.13.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2026 05:13:03 -0800 (PST) Received-SPF: pass (google.com: domain of alexander.ivanov@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=x19qGLYd; spf=pass (google.com: domain of alexander.ivanov@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=alexander.ivanov@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com 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=A0ptGbkah73NGSE3NU47JWbpvddgVuvtRzKvRGSWYqU=; b=x19qGLYdL6+f pJq3/otzoPu2/lCe3LDLZSmKiouyD8bYszhkfxe4OZkASfybFdAEPp/q6wiXkh+0x+5q2UTtYamMc ptqQQ+pSgPJTTiYdv8feojU603fyC+3aV0Ix1eHO8H/EvGmkzxTnN08JTowCzVxJEWHkYTNPA7D4C 4Ffu1RRpJfVCo4zI/3wKFonAFCS5dcIkNNTxGu+4Czm/klkCe2fku1TLQ2HE8Ph50L/S1iDQPkRA9 iBGXMn848L6ewauUnn1BWtpAfFcbzPfZmFma0YDTpmAHhKP39ajMVAb70Hrxo70D8tg+tWGSCc5eT 9X9VX0A1P6L7aFItvgn9wg==; 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 1xVqKK-00HWVI-2b; Tue, 24 Nov 2026 14:12:52 +0100 From: Alexander Ivanov To: andrey.zhadchenko@virtuozzo.com Date: Tue, 24 Nov 2026 14:12:59 +0100 Message-ID: <20261124131259.498924-1-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.53.0 MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.2] drivers/vhost/blk: return UNSUPP for write zeroes on a backend without it X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org The guest reads max_write_zeroes_sectors once at probe, but the WRITE ZEROES limit of the backend can change while it runs: a dm table reload with a target that does not pass WRITE ZEROES through drops it to 0. vhost-blk then fails every WRITE ZEROES with VIRTIO_BLK_S_IOERR, and Linux returns -EIO to the caller instead of writing zeroes itself. The VMM cannot work around it: the limit it samples may already be stale, and the destination of a migration must offer the features the guest has negotiated whatever the limit there is. Answer VIRTIO_BLK_S_UNSUPP when the backend has no WRITE ZEROES support, both when the request is parsed and when the bio fails. A request in flight while support is lost fails with BLK_STS_NOTSUPP after a dm table swap, or with BLK_STS_TARGET when dm or sd drop the limit on a target error, so, as blkdev_issue_write_zeroes() does, treat any failure of a WRITE ZEROES bio as unsupported once the limit of the backend is 0. The guest gets -EOPNOTSUPP instead of -EIO, and blkdev_issue_zeroout() falls back to writing zeroes unless called with BLKDEV_ZERO_NOFALLBACK. Users that submit WRITE ZEROES bios directly, such as dm-kcopyd, still fail. Do not check the range against the limit of the backend: the block layer splits a WRITE ZEROES bio by it. A VMM may therefore offer VIRTIO_BLK_F_WRITE_ZEROES without checking the limit of the backend, and need not cap max_write_zeroes_sectors at it. Offering it on a backend that never supports WRITE ZEROES still costs the guest: it never withdraws the limit it read at probe, so every WRITE ZEROES makes a round trip to the host before the fallback, and dm-kcopyd, which zeroes with WRITE ZEROES whenever the limit is non-zero, fails instead of writing zeroes itself. https://virtuozzo.atlassian.net/browse/VSTOR-141684 Feature: vhost-blk: in-kernel accelerator for virtio-blk guests Signed-off-by: Alexander Ivanov --- drivers/vhost/blk.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/drivers/vhost/blk.c b/drivers/vhost/blk.c index d6917f0e662e..8ef2e530bf1a 100644 --- a/drivers/vhost/blk.c +++ b/drivers/vhost/blk.c @@ -154,6 +154,9 @@ static void vhost_blk_req_done(struct bio *bio) int err; err = blk_status_to_errno(bio->bi_status); + if (err && bio_op(bio) == REQ_OP_WRITE_ZEROES && + !bdev_write_zeroes_sectors(bio->bi_bdev)) + err = -EOPNOTSUPP; if (err) req->bio_err = err; @@ -464,7 +467,6 @@ static int vhost_blk_parse_write_zeroes(struct vhost_blk_req *req, u8 *status) struct file *f = vhost_vq_get_backend(&req->blk_vq->vq); struct block_device *bdev = I_BDEV(f->f_mapping->host); sector_t bs_mask = (bdev_logical_block_size(bdev) >> SECTOR_SHIFT) - 1; - unsigned int max_sects = bdev_write_zeroes_sectors(bdev); struct virtio_blk_discard_write_zeroes seg; struct iov_iter iter; u32 flags, nr_sects; @@ -485,8 +487,8 @@ static int vhost_blk_parse_write_zeroes(struct vhost_blk_req *req, u8 *status) sector = le64_to_cpu(seg.sector); nr_sects = le32_to_cpu(seg.num_sectors); - if (vhost_blk_backend_ro(f) || !max_sects || - nr_sects > UINT_MAX >> SECTOR_SHIFT || nr_sects > max_sects || + if (vhost_blk_backend_ro(f) || + nr_sects > UINT_MAX >> SECTOR_SHIFT || (sector | nr_sects) & bs_mask || sector > bdev_nr_sectors(bdev) || nr_sects > bdev_nr_sectors(bdev) - sector) { @@ -494,6 +496,9 @@ static int vhost_blk_parse_write_zeroes(struct vhost_blk_req *req, u8 *status) return 0; } + if (!bdev_write_zeroes_sectors(bdev)) + return 0; + req->sector = sector; req->len = (size_t)nr_sects << SECTOR_SHIFT; req->bi_opf = REQ_OP_WRITE_ZEROES; @@ -733,7 +738,13 @@ static void vhost_blk_handle_host_kick(struct vhost_work *work) } vhost_blk_req_cleanup(req); - status = req->bio_err == 0 ? VIRTIO_BLK_S_OK : VIRTIO_BLK_S_IOERR; + if (!req->bio_err) + status = VIRTIO_BLK_S_OK; + else if (req->bio_err == -EOPNOTSUPP && + (req->bi_opf & REQ_OP_MASK) == REQ_OP_WRITE_ZEROES) + status = VIRTIO_BLK_S_UNSUPP; + else + status = VIRTIO_BLK_S_IOERR; if (vhost_blk_set_status(req, status)) { vhostblk_vq_err(blk, vq, "Failed to write status"); } else { -- 2.53.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel