From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796196444; b=g5sp/byNk+ZdAPGIgjcKDEtH7NSJpjmqXNW84WhJ0rIA62VloDwBnfVPoNRWX5MNRQrn YwLlcFHxkfyxvtm6shsFq9FCcEPoJaH9JX8uSBSMPEFnh/uDskpGm7QRtagTqanpIy7PH E3fo9uqKmCkzFRIrz8+vWt2ZsS4LNzRUqgCR76upuvrJNDfnP84X3GTdLuGDBIwdMxl9M ktQBOx2GvvmUTlPYE3mocNhOtU9xaIChm2n4Zc5hgzBZRrSTNzyxL2lsxwSTgNhT3imUA sU3ldrztUgg0Fea/qtZVL2+3OAIMcl8C7B9ZK3UwsnpWfNHXoXpLqxBcEnVLvkUeCgQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796196444; 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=CQF5Kpn94/HgSFpJaD9pUq1b9JjZcF3vjLpfeB9ZE7M=; b=YBmXpmikdNsAqWMebDodalfQwF2ICA0/wps1NtcZcCJdNjYdPn8Iy5cBIfuMqY138Hq5 PnZyJwJJOBlrYDHAeqSzu7PM/0+C7+4JdfNdtzlEvnFu6UVEHwT6ONdR1HXsP+RU00URc GH3o9D0BLuPrhQPN2UzZvd/gSyrWKIWfvK1sqM5OrCRjopou8bpLDxL8nM75bzkgcL/fi WYTQGTJGaxPXHURJwnGUsqzeKXNcPXszBod2LpalwnjPRI064aVN4xD2e3YUOUXQppRrK F/l2qstdRJb3vb+0mZWD/EuCqtw6kE4BhejfLMN3lOxZ4G00ChAOFLDQnr5h36hkprw== 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=D2KsJ73X; arc=none smtp.remote-ip=209.85.161.52 Received: from mail-oo1-f52.google.com (mail-oo1-f52.google.com [209.85.161.52]) (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 771C5606A31A for ; Wed, 2 Dec 2026 07:27:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 771C5606A31A 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=D2KsJ73X Received: by mail-oo1-f52.google.com with SMTP id 006d021491bc7-6ddef424972so10163173eaf.3 for ; Tue, 01 Dec 2026 23:27:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796196443; x=1796801243; 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=CQF5Kpn94/HgSFpJaD9pUq1b9JjZcF3vjLpfeB9ZE7M=; b=D2KsJ73XeXQGEtmuwlhwE05ROmquBvsNCkqOlRABJc+CYz12ekLnEgv8JtP4KlJ7Jh WUoZTC7cIk7yNLnC//pREmcwUjycJ2QAo6cEzWiDCxrMR4i6a6e20XzIjpe+J4gCwPyf +8vmUlc4XnNStNon2Mip2VLTUibYDHgZs9vuNLEia05tROj2coGBCQJRlhT8lk3RQKn7 FKiF4+Hlmk+xFgGoNxdXkS4W5AjQtahjE/479ArCNyiGCIM3nZoN1Xi7zBLRtYvEVapL RXQxdZQl+S8C7nJCgk4eaGV4mpd7dMz31rkXN5OqfXfoqpd3TizfJWT3KhYDKeM+ISzC u0dQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796196443; x=1796801243; 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=CQF5Kpn94/HgSFpJaD9pUq1b9JjZcF3vjLpfeB9ZE7M=; b=CnUXKWdiifGWb3ttqkXm9dCtoV0Leq4iI82Z+DqBTILTvhLbPz150eMVBqzCH1ifvV x/WzA1k+qy2id2CIidRvleG0+QKFjxuFMBDZJSHZYnpAAelqnRrHEQcNXyf1k+b1uP4A 4WNNabGZBevzWRyvFP+aRhpj3s2XtYJwNrD6iryWavGf1VHchzXmxF98ehOeDKYyazQd GNuyE7Ki30YkCaFVWYSCHRxWsVEnHvK7bWewOVpt8NX0qdliP323Da30sMDYtPfXnY+J hqG5nZ1k1DMvwNdYZtyOOYSqJh3s1X3ZVANl96edaUk6FZMnU9WoVssK6i08GimvDK9b sIKA== X-Forwarded-Encrypted: i=1; AL+hErFmsNWxFwjyof41aLWfiOd87bvQ4LnKp+dSG3rI7Lwzzo3m6Ta9c7UYnh8ckSPo0SnSacs5aEY=@vger.kernel.org X-Gm-Message-State: APuU4Z8yqhsiP3Trutpb1mEqafigjtIZNSUg7Qm8NTC/NJ6fIwALgyMO +Z0tKc6fFC6Qq25UIyFQGvf7/TkNaAv2tvUrNC0P6wWgV3wPWj0lbHX6 X-Gm-Gg: AZFdTZdoCUuFAuG+lR3YUFPJlNLTVDss9hendU4XP3LvNkx99x+Omz3fwRp6mP2X3v8 oNBiJ95Ut0ew1ZmMxM3Fe9AZKemvk3HKjczgmVs+2aLYK00+kTBufKCm+GgQL625skRfZaHcP6f eAa4mRsgR2rBTW4eoO4Gyv2OPYzHGKgW2XZPArGW7BK+STK3dHwq1br/Rt6tj/GEsYr716HHkmY KpJc3XSIdKQ92+a/+Qz93bbUWXQWKzvdt1qYidLd7G3bjw4Sqvxk3TrPQMffV0uDnIgpJpTNvZV xrL1k51wpWGGmXwe53wk15fVEqrlcSal00ebnd0R3rCZwa0HzvvZxD9kKs08KWg3l6WFant+XHB vHSFrijsS8WDsduLGae66SVMqXZvGAmRXw3kbKrp7lSnrN7ysbtb8KBGpZvfWMKVtwqXIuCHrzP N7cY1cKL7a8LJFqVQ5ZFjz7vSz94Ohj/jnN24VDnTtr9ym3zNRH8h8h9P0VDOsxfWGAk5vxcudW w0Pf1Hv4OnfjnTCKTmTkYLZP+sdkdlqVkkdjwl5LMW2NgvfBDPLAL+uGKpm82wYdJW6TahgTf7i XCuES7Tf2mjDGuEXj+0JFrpEYOsuM5Nrk8Ygbm3wbvHpa5ytnWA7yOICqT1lVJr5HO+tzVdQEH2 0XEFJ2Pk9/bGmERHwPu5a0uMSpWdSfJRP/zP+zaebYHmKOG1mAS0Fxc/RUw== X-Received: by 2002:a05:6820:2583:b0:71a:fdba:b61 with SMTP id 006d021491bc7-71b3942fbc5mr25138245eaf.23.1796196443419; Tue, 01 Dec 2026 23:27:23 -0800 (PST) Received: from fedora-laptop.tail348456.ts.net ([172.245.82.59]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-863168bdaf7sm29355597a34.5.2026.12.01.23.27.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 23:27:23 -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, Utkarsh Singh Subject: [PATCH v3 3/5] ublk: don't complete a short request in full Date: Wed, 2 Dec 2026 01:27:01 -0600 Message-ID: <20261202072705.1288588-4-tom.leiming@gmail.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261202072705.1288588-1-tom.leiming@gmail.com> References: <20261202072705.1288588-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 Tested-by: Utkarsh Singh --- drivers/block/ublk_drv.c | 52 ++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c index 1a0cbaf5690a..61da50dcc298 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,28 +1593,45 @@ 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 */ - if (!need_map || !ublk_need_unmap_req(req) || - ublk_iod_is_shmem_zc(req->mq_hctx->driver_data, req->tag)) + /* + * 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 (req_op(req) != REQ_OP_READ && req_op(req) != REQ_OP_WRITE) 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. + * Only a READ on a device without user copy, zero copy, auto buffer + * registration or shmem zero copy has data to copy back. Either way + * io->res tells how many bytes are done. */ - if (unlikely(unmapped_bytes < io->res)) { - if (unlikely(!unmapped_bytes || - !IS_ALIGNED(unmapped_bytes, - queue_logical_block_size(req->q)))) { - 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 */ + 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 (unlikely(!unmapped_bytes || + !IS_ALIGNED(unmapped_bytes, + queue_logical_block_size(req->q)))) { + res = BLK_STS_IOERR; + goto exit; + } + + io->res = unmapped_bytes; + } } /* -- 2.56.1