From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796196444; b=kHLsiRIWUe5CPUkR2mDM0EBcuUxbUktMc5R0P4f1h2qBjElELHxSTANSh7osGtVkk58O DDQjAQVGJRwM9mg/0T+sUeO7x2EblIHffo4Io+LoA98l8nanWK48Hj29H9UnAnsypDWjO GJG0zmTXdOo4gjl2WX+Zlx7nWCx6WZELjbV6sO3yRU1aAnQojHPUjfVvno6lUMEQ0bChr k4+mt9IO8zZQxPQOOWusWcAlDGw6h7FrV6mpuzVcxiaX+N98c11YWBBqvlqtT6ypt1h7T jLZ6cmdPK1PFGLUKoR0IGCPmdVcVugbIQszCijAM3lvp00JmkY3HtV++r8AbJTpC9+A== 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=ProldYNj9TIsRiz/BDg0kSsDtWYfP/33Ai2OaUnL8dZ+SEdcBSUhEvmha9RwfpH0NoJS g89DX8ILfw0d5JH8H7Z7yfbTG124LoMiL7Td/hcBe03jhaug/0FnMMHJEtTudcyj5BYAr f845eF1lVAlW+sKpW1JiYZfwtLy4YS3ynzzBgC5rrnpaKSZHbNPkOkLE81bs+52eTB9dW xZ+IUzg/exWqEJvmD8wAkmxppXad1q2kHR2R4M3W+ohnWs45XMnO/Zx8udr/z5rxDexxq Qvc7m70UdN9emfBzzyOZunUhthgNZlFsepSV1hFaFVjGn1k4aRqRqbStxXrSYCtvhHQ== 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.43 Received: from mail-oo1-f43.google.com (mail-oo1-f43.google.com [209.85.161.43]) (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 8E535606A325 for ; Wed, 2 Dec 2026 07:27:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8E535606A325 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-f43.google.com with SMTP id 006d021491bc7-71ad5f20016so7905187eaf.1 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=0V9hmqvB85+yjVKvTotImJz9eYfz7RhhtUbEIkggtnrwQuzQlum45Oq7l/5a2UeeRH Bp1o7bJ6NoQUwPhFDrZ17nWVWTkWoa5U3cPDDV2vZEwcGOGcuUKJiynLxMTAjP2ZmZCT VWVQEkDAFLCPAuNl8KavRo6qpMtzQJIHV1zODA2ue6iX47zZQpod3/Wi3/jRTkQFTol1 7a/X09Cz6WydwNDiwHBO0JqZomgNICHPgx3aQuTV1U5zWDiMyEkfkF+N/6qdfNxNLtek XCxbHiUH/DGCsfznSJkfHdmelYPOOldnceBGQOF75qch5nG+IVFwb1XUkubsA+HUxFss YM6Q== X-Forwarded-Encrypted: i=1; AL+hErEpqCT0Iyau12wDP0SVtA9fQoayQGg0WOcAo8wjrUA7HAUyWB4adi/fOzWiSL29j6j+eev+tbAwky/iBQ==@vger.kernel.org X-Gm-Message-State: APuU4Z/1ANGZA59EvYcoDL38UXxCaET5Bk1Cj49Z2N13g68ctuIo6aEV 5ipyrKWkuAiaDSB0d8X7w7zySrA7l/O7on3P9N1lJf0FPJC9gEQRcHNv X-Gm-Gg: AZFdTZe83kEu584U5wOnCKaUmxVZMhYj5S8Ee0Jr7Gaucs+zdkC6mJGMNxijSCBaib6 40aXjUxGx4amocsQBjsriK+23/8gC2zrCTbRSJIcOoLmU6QcXubmSVmTmIPSNU0HOKGbev+NKXW NmfOljjq4x40CzecGbXspOA2qR615gxxpqWvSJjAnYG91vZFodt5TN3jJjNRn0AI82aLsWa1eu9 MxdSVBeMRGPXGxKvLMGrxj3bVtmXVmXi32nSu5Sv6TOOdfjH1IynL+mCTiQgtfCa/CRkcNQ91SK 4jH4J3DKpS8o8ks3TLOWg3tdgeq8N5l8MUF1N76ZtEvclO3DbybRnNln3q4UH4gXD3SNYLfZsWh OeC9y/uQHTBD3TR5td7yKVltoq/McsAchKJ7uhUTfIOHMobrweNhgyLQ8dJ6J/hI+WlUj9oDp6x gSUL7tQCgDOo7eP5hBQFQpnY80LpWs5nxp+fUIADSgsXWYJLC5+PI2NKYZ9LyhsAXYLykgudmfJ rQXENxkeG4OKSbXcYEEvYKBiUsokdBUqhQGqDqA6IFSfK2p9CPp9N56tDto2l87MQrND5acUH8f 17+8a1zzZ2Yji+kuAjofWD2QUwzM4CtgSlA2JT5B7v8oO0LIM9tSCQHsLPEtUgEVa6ggIqo9FMC GFDVDvkx5LBmd56aY5nf324tZaeG/UC4kaHsLYSQYqVG9oitXX99pEgItcQ== 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: 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 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