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=Ni2GRUW76moVDpWRGAcSKk6YKc0aFcYRV4EJf0Npf+FVxDcpwhQm4JJ5hvlCNBC60Vk4 S+eEb0IwML8v3dsGzxQ2vKFvC7ErMnKlld/vN9UUB1ZGBjKbO5gse17Nkg1sj0sBJPxNd 7lNvLeSd+rzPL3MNJVjDud3K0ix3PdXmTSXQIi8eP5EfGMhx7hUBiR67EU0Fz1+NsNVUW 3uOK5Obi85PQWZk2I/5QU1X+9pIQD8gBrWHYAOzx15qzfMZZlA0g6RYgr0aOFijFnPCn9 5jCLI9KZjX7vl7Jy2qXSCQGUeu1DiTHqE1Xb6HLc0IQskMHs6miVgNHyubjlHtmDctw== 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=GrPacxpINtfFXaVEOY/6usG4XbMyXduQb31xYFcq/BPGyjIN3rTmHBJxg6Ln+JDUxu4d Xs3rnPMW9DfL4Wt0WWjT6gE90bNhJWc767+yHLUZ29/Krdnyeg/ItQsQ+cg1SZ9BzGzki ooZHIA7L6ZZZ80mjOgGJQlPhmeWcfcjYPW9i6E3lRnCLuhuAoqwJpez2nB2FW8ucA2w4d I68KDgdpC6paoxrbst7v6GcmIcPPEpDUZeKmIwQifXuZpVIlzAuDYLhMWTeuFhJB9haFy gQQJX/EJllyd5vlaeKzQeQFKzA+9vbh5xYmO8gyJ/AlzEfJ6U5kKof/ncnMOKNYvv+A== 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 CA3E1606A33C for ; Tue, 1 Dec 2026 09:52:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CA3E1606A33C 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-6d290b10a35so4889705eaf.2 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=MfycN1ONTJeyWqvTdl2kn0SttTAmFIKCMMZc9rxpb5eE44spGVf8/2DsQHBy7Vr2UK nCqYQ4RTiCBz3dT/JttIYV1XSk4gqlOzMLSQkTbOrG6RIYbGx0LXM94CTpZNjHuAiJnK xJXwLcrPieTv8xjMwVpXKSnwNKBq83heIcKILiV+4LHAUAT7Eo+Heyqu35cnFOQt0OzY 2nJHrBOA/xg4N14XT/xtF5yJRYOTLab04IHn4HIxQ8HjQDF7X502fr4NQQy45lQpdZfW EgTOPwGbfg8Ks5lexp2YT81gxQTHKQj1eFjLnrBnYhabUX20JRGvoChs66Qdb3efmeev F8gA== X-Forwarded-Encrypted: i=1; AL+hErF4uKyeD6RN33aAcqd2/9VggRWsH+dM7Q/wyuk+S3dImNowNVxbfHvF+pjc4zWCNYPHLK5Eb8M=@vger.kernel.org X-Gm-Message-State: APuU4Z/bhMeyRKkm1KrtNEPsbux+7tZrWHD2h7jNgMazFKG0QYLrP0s0 Sw1cyMfn8J2AlI25m4tAl/zwYYH97OKG34GH8VLjM13SoN97Un8zUZgT X-Gm-Gg: AZFdTZdrN9I2N26KCTpzS2xqNT9qufY6MIUQt6Qy6W0ga5jrX/xz8/gMWBjzWmlsc3w VWT0X0UgbWlZyzb96scSh4tsD9KOnYnCYwgkahHGhHFgHmnJTj1RJ3hisz5WVwVd/EJ0HFJvDGO mKxNAotObUQjqP1Hy447bqYgzJ96UPyC1OBK258Qf43BNRPX8GlVHvCWllFh9YogM+8r6C6+7AN XpQ/D3u2G5uRgnEtTOUOqHXUpLpcpSfhF55K7alxoC4V06+vgajsCh4iCmV5GKqYPYMbJP+EqQJ dFfNPEyEPoYLG9DWkHnXl31TnN7hZJLFBKnjqXA6NyrWC8EvCJg48Ifx4nSvPQlVKXSQqv3zLJM fbcMBbNA/bBKIneFg2COfy/xewfVgN+RybKdqxXIv8nyA0Gi3F3GeebLTCvDNO3bGYvOr61p+Vt 7uQ8aOa8OBCK/kKzmalcNrWx9/wEV0xhM2UFJYdKXNk27KjrEKV9XayoTl3rWkzVmQGU30Giwjl GQqVgugZSp/RtSnqasNAj76k1lylOsuWJzzl/F1YhunGvnPjGZBuAzKscvxmJUef7DyeCeNWhr+ JgroWOZBRwahDYpUQwKBvAOoDl5XSc9ykiNEkhrtHAYLCcJtnRY8/l91KtH3AykXFSpZMjuM79t dYJ/SlyTQzLE9v8F9yHj7+n6ruK2reTsNwmBpYaqesmBNTPdh03lI2JRwO/lzwNJ7SW1JGmgOFz 2rDbY= 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: 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 --- 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