From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796118732; b=xgk7f9QWPzoVE2KSl9vsXmQGwQbNKN9BBVGgNb2OCKFPKIRIAhqmViVmODDi8PTsy/Gd ztIwjSjGHwsL9ppY8EKIFBXbAU8+gDDanuZponBHzfgK9dMwAI5iOQT/YHXYObZdpLdGF VO0t5Vm4Ik9EzKo0qJ9nqibN2cgHpEBRv+ia4g4+F7hl0jB/Zcr21SxKW9XwFjWKEgQIP jYaKUH7d5bTZ0eSMqfOunVFT9xOBkzl1EDew4rkk0KeYF1ae26On4YC9RSyQXU8k7pFjt 0Iag1OJD5GWbm3r5/irOopBie/KEToJX0EtJLtNJGpAkexyiKXYlxfAyeHso/OZSyEg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796118732; 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=x9bOGAN9hb0ZlKeB5wxL2+u8dP7XbW3Jwu8BcVySc4E=; b=cFMCOvF4Rxb9pmWfH4BntOpftGiF5timFBwaX/5dYOnJ2EMqIEoJHYBM+NJixCpJg1oR GDa07z0W3R1M2pUkOcRXyokSOsU7pc71Opv+GZaDQMFlXtJP+JLPnD4iFACrzANT/Q331 j6HpudDgHk1zuALrJanPmXFBZkmzl96t+MelPmlb5JhPQeIh4S/dAf7sssFDGONYBEoVd 0il0j/dRuD+/9usvsqO+5KQiU0/iv5pFcTGcswdJLcUupc2fW/pAG7LeawX2/WNt7NhU3 LWvrPEfmJvuieIPeXjy8+Uh9bQGgohBFg/0wvxoJZXcWTR8m+xNKlLeIgTe9sKtUvMQ== 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=JIz8OFHF; arc=none smtp.remote-ip=209.85.161.49 Received: from mail-oo1-f49.google.com (mail-oo1-f49.google.com [209.85.161.49]) (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 CA2D7606A330 for ; Tue, 1 Dec 2026 09:52:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CA2D7606A330 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=JIz8OFHF Received: by mail-oo1-f49.google.com with SMTP id 006d021491bc7-71b7b706946so2856521eaf.3 for ; Tue, 01 Dec 2026 01:52:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796118731; x=1796723531; 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=x9bOGAN9hb0ZlKeB5wxL2+u8dP7XbW3Jwu8BcVySc4E=; b=JIz8OFHFj7EJ0DZt3EbHwVPioGZ6yjf1up19zyHJ/s8/hr9kNEggYG86OWuAzprrcq upxH5zIGnIjpbjirBr0jOqEEiweMJ22bHrx/X+nUoKJXLZ4pYcPc/53Az6Xeu+mZes+T phfRy0ikK/xWPRivRZP6DCtElLFy6YCx9lW8rm/y4hGXPIuXZlTBeFkzevdcoOoSmvwq 5NSBwx214BH5AhoDc77qg0JSg4MhJ/vLRFtv3aiPPY1DAxwbntJk42XqGxi967uAtcvD xIt1Hra810V2/yZea3t10zih8X6XdFhODZrsVH6EPChcQv31IkpIQvA0O5pUMNPHSPYP a6qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796118731; x=1796723531; 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=x9bOGAN9hb0ZlKeB5wxL2+u8dP7XbW3Jwu8BcVySc4E=; b=dHQQoSgpOqtmwGWSzmuBKD+FRrPgZAtKYuUU38HqwvpI5N66LH8MfHo9tH2z02Wy0A 92xwx5+w04li7l+D/RSv4EXl2i0VHcT97Qq5bIHGP9OLg5gYUp878VruvrbpMtmZvkLe vwhlr5us604r48Y9xTTapUe30CcX2NOj45vQuxPVpC1gcOuwU0+So61g/IMDVULd59iP h6lwtwwBz+lcp9Xd4GNDrs4ZDx6cTwN3A0iKUJPwjpTajKJpkSNOFXCofwzXryjcImV7 TkZW+bFfMuyzbyGss6A2Lua1/5ml51taaoSl3Oyp8gMu3Pls2tuDGDO01lfnXK2vic5w Ua9w== X-Forwarded-Encrypted: i=1; AL+hErH5zlikqzOLhYlUHKKGqvF9Te5dhzHsnWpXp4+VWQYK8OuXmn73/NE3Ifr2uTI/PCxuBfQF9zuvrSmMMA==@vger.kernel.org X-Gm-Message-State: APuU4Z8fO89lNzZArQ8sv7Y/DHXXw947yQC6Z42MPqlC8Y2vN2fAUvOF F/XpSzyQ1Vt7vSlFNsxUj/7MSed8gDCuQZhq83Nch2tl0/kQVeBBoex+ X-Gm-Gg: AZFdTZfu1FJptgkKHAsufyVBsylr8mYINP9QQ1kBNhMw9AOebt3XkRb4t5GAHNtFUOS OnajBJjHyysULwbXm9R6Jc49kMyr8sKjieVerAB6d6+/cMq6RvJG9zSaPlF+bdgfvC8j8pkJHNc 6EfiWBfOYQj6RqZQY3Eybn/pWKDuaBVGhX5SSwxg5e2eiftWKxD3t0O8VPxNna8d/5yd2hTzT2v QKFdoyimN/W5PfZqdzxyAJMMMutI06sur1Oqy/oghepwiWQkA54FCdfkQU26eCaGxAh5cMOwDJN c3L7YwjZ0wh12EtxUlL678tBhBR8rPfddkP4l9cWTA8iiOJrLKYxwQgOqapZ9vkOBxDBDUlW7IP nXEUJlkoXScPbe2Qu0PpqcFn5NKPc+40bc4SKEhJ1hqgcxxB6iSZtiKQBMaGubf8IjIA6tvEqqS pVRgVqQzpwG2DtaKjBD4Tc13IVorhv+imozZegCypiD2GfYE1r8qLE8TAehCrz+xfqYH8si9Jmw wbtjRYHsUAPDc8gg3PtlWttSzEymNUuSk2ZK3o29q7pQs1FKRW99Ub5clDL7FlhM/bsFmsoO2mY oAArkgiPaXC4vEavgwv0rIhM/0Hkd+Hjvog2DUTLPUom3+7vFEcU+y5UYGWgZ/t8FgG+JazbX4E pO2GrZmhCHEIi9oZcQcGjIXrXFp/ID7e37pN/cEQVKpArbj+0FX3BYeuuwkBBQKybTrs50ssUMI Ycsgw= X-Received: by 2002:a05:6820:1501:b0:71a:e4a8:bed0 with SMTP id 006d021491bc7-71b395c0ce0mr28696331eaf.90.1796118730767; Tue, 01 Dec 2026 01:52:10 -0800 (PST) Received: from fedora-laptop.tail348456.ts.net ([172.245.82.59]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-71b380b6f82sm22698287eaf.10.2026.12.01.01.52.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 01:52:10 -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 v2 3/5] ublk: don't complete a short request in full Date: Tue, 1 Dec 2026 03:51:49 -0600 Message-ID: <20261201095153.1012606-4-tom.leiming@gmail.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261201095153.1012606-1-tom.leiming@gmail.com> References: <20261201095153.1012606-1-tom.leiming@gmail.com> X-Mailing-List: linux-block@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 --- drivers/block/ublk_drv.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c index 1a0cbaf5690a..5cffd8c4e0a3 100644 --- a/drivers/block/ublk_drv.c +++ b/drivers/block/ublk_drv.c @@ -1569,7 +1569,6 @@ 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) { @@ -1594,10 +1593,24 @@ static inline void __ublk_complete_rq(struct request *req, struct ublk_io *io, goto exit; } - /* shmem zero copy: no data to unmap, pages already shared */ + /* + * FLUSH, DISCARD, WRITE_ZEROES and zone management requests usually + * don't return a byte count, so end them directly. So is report zones + * (DRV_IN): its reply can be shorter than the buffer, and a requeued + * rest would rerun the report. So is zone append: a requeued rest would + * be appended again at a moved write pointer. + */ + if (req_op(req) != REQ_OP_READ && req_op(req) != REQ_OP_WRITE) + goto exit; + + /* + * Nothing to copy for WRITE, user copy, zero copy, auto buffer + * registration or shmem zero copy, but io->res still tells how many + * bytes are done. + */ if (!need_map || !ublk_need_unmap_req(req) || ublk_iod_is_shmem_zc(req->mq_hctx->driver_data, req->tag)) - goto exit; + goto update; /* for READ request, writing data in iod->addr to rq buffers */ unmapped_bytes = ublk_unmap_io(req, io); @@ -1618,6 +1631,7 @@ static inline void __ublk_complete_rq(struct request *req, struct ublk_io *io, io->res = unmapped_bytes; } +update: /* * Run bio->bi_end_io() with softirqs disabled. If the final fput * happens off this path, then that will prevent ublk's blkdev_release() -- 2.56.1