From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.44 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796257976; b=ixI9P8r+CSCGQ9MaYdJq9YfWxiSm9lxwVaduGnjuikkyiHUmOp2KeIR5VUoNzF8+eqbc XTp/tE4NpuOO68x8wPIqLskvKaI+0kM9OPGo7w8E0Hh75Tlw0g9IUitAD6SY6gX8UN40O QNyMc+lIIa0wTdu8nqR2LKVgN/NpGQdCmtCFtwxyKCJtTgD8hs4xnd7lx0xl2YLG8QAGq wwIUjahyEEj3F2eC3DV1oV3K7SmZax1khXy1p0Q/c+BjEZXMHzuXEJKx/90RHzGppDdpF nvIm5szpU60SiKK7sk7amW805Xejk0P7giJ6c5VpeTZOpqlejPeUcBHvex2rYr7V+bQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796257976; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=TNBaiRKe5LPT6Rh/LgEsFjiL7dnwPdnsYBvEXvw2hks=; b=NMIwrymHI7u+a2xXZKjrPDJcoortPSzDX6VcNtughYOXmEYVYVudAdvHJG4hsdCfYz7g HoRoPJ0iBbHzonoOfVjKZ4IhIFdU27oAH/Za5jcImfdHHv/LooqSGUWzZ1d7r1dTod8wd hhaVkEvF70qg8Eg3JYdh8ZAaaxRXLNxd+pwDxi9fVOEgT8Nu+ocFuHgaIrHLkami7x6fG RN+kLVWJ/hH3SX9OPSnpTa0DL3Hs2UZZHPedjj9YQqfjur0QIskTwDYPTs98v/Av+Qp20 e7v7NcZDDlRkzW7UO5Vf+TsN0YmiG42/xO2uvgytIJwNaVwtC+QEvq+1Bn/3edJRj+g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=aZbPn7W9; arc=none smtp.remote-ip=209.85.210.44 Received: from mail-ot1-f44.google.com (mail-ot1-f44.google.com [209.85.210.44]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F41D2606A330 for ; Thu, 3 Dec 2026 00:32:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F41D2606A330 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=aZbPn7W9 Received: by mail-ot1-f44.google.com with SMTP id 46e09a7af769-8629ef48703so7368823a34.3 for ; Wed, 02 Dec 2026 16:32:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796257975; x=1796862775; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=TNBaiRKe5LPT6Rh/LgEsFjiL7dnwPdnsYBvEXvw2hks=; b=aZbPn7W9y3a27m5exPspEQVF/zDwnImo9CYySxeML8xOP1z30lmlPqBr0hr0mlweuZ RzdkW93neZtb0EjiSRIoHox3LKksbfxiAUbpQP9nC5fdmCA+HJJhVBzavtRdETdZfZV2 oVlWJ5EMtMn3ecc155tG0kt7uQuqNkQYlmATuqN+5AP3OEOJLoOaDX1srjC30wZstZ6S DtpxqdefiFd51HvwRj1p0KdxIFhfggQ7ScvoKTRAZeqofh2s5EY8FG3RUSL9597D17o+ YbTJsMYRXEN0SdpnQtwYDeAMSUWka4YZqPh7IWQJ0PruXWgba/QtGaOLd7I8bUUxgKdo aluA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796257975; x=1796862775; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=TNBaiRKe5LPT6Rh/LgEsFjiL7dnwPdnsYBvEXvw2hks=; b=TXVpXilMXuM3ixluDv/ZaRVxpXseP0XJWFpaPMR+KdC3bKk1B6qW8N3zx/Y5DT53R3 jviPWDZdItMSlqPZubvJyo8tYzVOfUz6RKzIDNQSeaeWbCsU0TD+SPlQ0VdWOAVvsXsB ATwAGYp5K2E87fX9d/x3KnYaEEueG5FiD2M9/W/e8t2zjlKGVQ+eQYg3Rpl1Fbbf89Mm NjTSGUU54luk3egpsGO9TVV0vsr979NVkNcLOgidy1N3Uu7hH/C/qA2TbDvuce+5TP7U PDBW6gVXjKSpQHwPwa3z3KvGQMX6YAoH4SoScl7KdEd/UXZaTQntYhAv3qXEB1lVlUzf IR9A== X-Forwarded-Encrypted: i=1; AL+hErF8LNyJinBDoSDDjFbTbOfaJZjV1T/4erAnm59O1dFfh286TXfcuAEnjY0LxAHVRFAarRjn+mI=@vger.kernel.org X-Gm-Message-State: APuU4Z9J8LcyGK1sTEDeoBGZ3RgHPOweExAxAEqadb70Upe5tmROV40r c9cGp4u5mo4He7KJPAN1jwx9MTGtnvJ4Q1AskRbKaBVmvGsnBKIwbXXh X-Gm-Gg: AZFdTZdqwrEBVh7JA3RUhT/cy6ym8JzwFpuxDSPn6xBgKWZLxh1S7KYFe7lzn6C7E0O lmAPo0lOGR3rc+WhRQwsJENizq5Os0LlUSNjoX9ATWscqQemX7G0tq0uGf7o4a4BloEtFHT97A6 yND577qEvG99/zT6gULsf45ySvPqqAVmSQ66hIEfXeOovjprvZBIqIkX8DBiWsiL902n1PQX2pt WLSTqeo/3/UgvW2cyqEGf3n4sJ0aNG6wChxbyzBLXkbSrbQov5FH25219gcHFG6DK31V8h5H29J 8x//tKII0NE47SxytRT2Fm+onnwJP/vsJ9CocgPhOup1kQrjFikJetr4Je2fsmfS9yYliEUbEYU VFtdDefjlGVWDVtEXwt0QcdQgYIiq3IWuSiuxfHr4B/GhPXohxCroC4FvmruSq3vh2OJVM+25RE lUa7JMQUPk1MJ3P5IFnjl7snETLPZ12RnLMPRkvbUHf7oj3OFoTq6Vnn2Mb3AP8yFIBhgU5s2qv mQ5U4x02wYXkhSFSUwVZaw/do5nN0qMqTTt238Rxts0MQQ9dQJdbG5UFkeIZoCvuk5depDFeBGP CpKa3xY2E6ZYt4C3RrPX6+ZvxTDgKCzlwHMMGZCV/xOdoPvsZt5JLVvKNFBzLmJqbbZpXFE/i+Y DHx++PLdGyWdsWEwD4dIQ58WplgJbv1L6IGKBrOiMbf19f/Qwt6Mc7Po2zg== X-Received: by 2002:a05:6830:7182:b0:862:c4ae:7fe2 with SMTP id 46e09a7af769-863152c5d24mr46144746a34.4.1796257974927; Wed, 02 Dec 2026 16:32:54 -0800 (PST) Received: from fedora-laptop.tail348456.ts.net ([172.245.82.59]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-863169105b7sm32213309a34.22.2026.12.02.16.32.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 16:32:54 -0800 (PST) From: Ming Lei To: Jens Axboe , linux-block@vger.kernel.org Cc: Ming Lei , Caleb Sander Mateos , Shuah Khan , linux-kselftest@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v4 3/5] ublk: don't complete a short request in full Date: Wed, 2 Dec 2026 18:32:32 -0600 Message-ID: <20261203003236.1514775-4-tom.leiming@gmail.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261203003236.1514775-1-tom.leiming@gmail.com> References: <20261203003236.1514775-1-tom.leiming@gmail.com> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Since commit a8a79eba22dc ("ublk: lift checks out of ublk_{,un}map_io()"), __ublk_complete_rq() ends the request in full and ignores io->res when there is nothing to copy back: every WRITE, and every request on a user copy, zero copy or auto buffer registration device. A short write or read from the server is reported as complete. Shmem zero copy requests have had the same problem since commit 4d4a512a1f87 ("ublk: add PFN-based buffer matching in I/O path"). Skip only the copy step, and complete READ and WRITE by io->res through blk_update_request() again, requeueing the rest. Other requests are still ended directly, including report zones, whose reply can be short. Fixes: a8a79eba22dc ("ublk: lift checks out of ublk_{,un}map_io()") Fixes: 4d4a512a1f87 ("ublk: add PFN-based buffer matching in I/O path") Cc: stable@vger.kernel.org Signed-off-by: Ming Lei Reviewed-by: Caleb Sander Mateos --- drivers/block/ublk_drv.c | 55 +++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c index 10dd20e7a3de..e38293b23b0f 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.c @@ -1586,11 +1586,9 @@ static void ublk_end_request(struct request *req, blk_status_t error) local_bh_enable(); } -/* todo: handle partial completion */ static inline void __ublk_complete_rq(struct request *req, struct ublk_io *io, bool need_map, struct io_comp_batch *iob) { - unsigned int unmapped_bytes; blk_status_t res = BLK_STS_OK; bool requeue; @@ -1599,36 +1597,53 @@ static inline void __ublk_complete_rq(struct request *req, struct ublk_io *io, goto exit; } + /* + * Only READ and WRITE are completed by the byte count in io->res. End + * any other request directly: + * + * - FLUSH, DISCARD, WRITE_ZEROES and zone management usually don't + * return a byte count + * - the reply of report zones (DRV_IN) can be shorter than the buffer, + * and a requeued rest would rerun the report + * - a requeued rest of zone append would be appended again at a moved + * write pointer + */ + if (!ublk_req_is_rw(req)) + goto exit; + /* * The result of READ and WRITE is the number of bytes done. Fail an * invalid one: more than the request, not aligned, or nothing done. */ - if (unlikely(io->res != blk_rq_bytes(req)) && ublk_req_is_rw(req) && + if (unlikely(io->res != blk_rq_bytes(req)) && !ublk_short_rw_valid(req, io->res)) { res = BLK_STS_IOERR; goto exit; } - /* shmem zero copy: no data to unmap, pages already shared */ - if (!need_map || !ublk_need_unmap_req(req) || - ublk_iod_is_shmem_zc(req->mq_hctx->driver_data, req->tag)) - goto exit; - - /* for READ request, writing data in iod->addr to rq buffers */ - unmapped_bytes = ublk_unmap_io(req, io); - /* - * Extremely impossible since we got data filled in just before - * - * Re-read simply for this unlikely case. + * Data is copied back only for a READ, and not on a user copy, zero + * copy or auto buffer registration device, nor for a shmem zero copy + * request. Either way io->res tells how many bytes are done. */ - if (unlikely(unmapped_bytes < io->res)) { - if (!ublk_short_rw_valid(req, unmapped_bytes)) { - res = BLK_STS_IOERR; - goto exit; - } + if (need_map && ublk_need_unmap_req(req) && + !ublk_iod_is_shmem_zc(req->mq_hctx->driver_data, req->tag)) { + /* for READ request, writing data in iod->addr to rq buffers */ + unsigned int unmapped_bytes = ublk_unmap_io(req, io); - io->res = unmapped_bytes; + /* + * Extremely impossible since we got data filled in just before + * + * Re-read simply for this unlikely case. + */ + if (unlikely(unmapped_bytes < io->res)) { + if (!ublk_short_rw_valid(req, unmapped_bytes)) { + res = BLK_STS_IOERR; + goto exit; + } + + io->res = unmapped_bytes; + } } /* -- 2.56.1