From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796257976; b=VEL6wYWgfFMraVMLF9YrkFl1HnTEfL8XhPypF94TENJfhlYvicmrDUMw7u/oXT9dEgNC uFylIh9AnifoP+8EKHSqxaasocUfLIQ+a5qXJi9d+wHy0sl/gzqrsv9rWolbWMLViuahI yofL3jzsNY+6z0q3MJyWGEXv4IfMFNJbSFyNKBepc5PN1J0M3/ijz2OsQHoEY8cYaNoAQ V4KJmGgNKwu6qMxqCF3bE0sJL+0CeBd4leozw5urtmroL6A/+V3rt+vO4jXM00rGKBWL/ SsK/701Qu7fFll4e+2gxKMcBH8Z4ugRMSHT4GZsS3oCOuSzcSjplMNDKTPrEAi/vKTg== 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=ptDjcaPUh5yTTEads2HagUyYUhsR1fRUmagqycqyx1DUltR/cZT6bp3m7jd2tuneZBKX g8wnt/7RiHcbVOk8ht86zfahyQTTP8+/Umlx0WrKa6WrYgpvTWdIf3pxAxe69TPqB+TIq 4xE/A2yd+1B3rAyhOm+OABjs3bS3CUVc6+ZHgmKUtN9Dcjbj7SPQBUToe/JZ9GAKUHA7u EbGNGI3Y4tlEZkm5sfLPR4REIJ9JOhwRbMS2MpfQQS72nqUp4zE5Q8l7XXFr3JaYXdoTE hKoJoDLYqCRmP05YaQCOlX4rDqXT6aLDwLLDFJhCqlSxzgEDel2b9MswQH+NCkEEskg== 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.51 Received: from mail-ot1-f51.google.com (mail-ot1-f51.google.com [209.85.210.51]) (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 EDA74606A32D for ; Thu, 3 Dec 2026 00:32:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EDA74606A32D 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-f51.google.com with SMTP id 46e09a7af769-8629fc8ad64so7322851a34.1 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=xibSIa/awuapFyZ4/bosTcGHW19f0xzh4R42/jB1FHBE8nXscrhhjO5g97Yzxwz8mx xpT1mg5kqVceAIfTfzZ8kHdXz4WK4o8wVOO3X3k8nkRwC20Nfq8zOHz3IN2dNvZ4d/+s CxV83KvM0/UAU5sTnFsOe2P99QSGXppneUpYPJEu+uCgBY4ySntcYWKJkNNlYhLwHyl5 X2pPDjP6Ou8/gbyUnY+pjKaUlROEOHslkeki9Ws2jdSh5m/4EcrjZjnqNZ7izf8keMPC THXPIJRMHO85vqk3tcf87yyIRsSRCRQ2xdZWG1vrkglEmqwPAPyG6XW/pSC+riaED4eH FdzA== X-Forwarded-Encrypted: i=1; AL+hErF32djOBtNSCEWC9+9Iifb0dPwdGtPSuOWT0ycx/qF6nIbfh41dIBf8sIbfgda/KJjiGXys3Ak/FR/mUw==@vger.kernel.org X-Gm-Message-State: APuU4Z+2ooffRIA9XmfDpUChdrRgmOP563v6TALd/ZJgJXkAMj4Tnhdt fyOix2plSQubhETGmdP9IyI4giWJ1LnEHe+H/uDe4yVnAFmkFTOL24lx X-Gm-Gg: AZFdTZeOYVd9wFbQyalnP55T2Hygp75TxAq+SEHv932T8fpojrowU1dt8XUVeQRndE5 1dL9AjE0jtQWYY/lEjH/zGitLgNLptGa3zEuJsHe6WzRXT8RkydAfcGjT7PMSrTNhTYcxFXIy4z Gv5/62DFmqu/ZPorh4hDhl94O1ligVpZmEwSUZUWLq5k9bnVL/VZyLwcsZRsz8g09pJvXt9oAfM HBxU/hmIhLu0Z2z5GzvS3Z3HvLWFqr8+8drWQ5Strd8pMOwN41UPmVepq2PonIrekcYl6QybHIb TbRHP3VhfvK3/9eXTw28/OpD9dBxW9kjFm75kLppRMQVnZeJF5Gh9ch3jSzuxFj4RP4hYyaILCY vmYh7Lc2Plp8QOCKGePnlBzH9iblua6z2dL4bbo3CUwpcAGycJdjv/Ws3CkyVKAZxRyXXGTwcqF MPtnX79JAhLNLRH4jS4cQr7VqOyCmlixxj8VqocWcc63dgfWRREI21a0gjp4Bdqm1hAakdw6zYR 55+BXrCmDzEZflKcoaW1UlQ//ppSMV8gJJHOeDsfoTw54TSPevnTt5KY38HQMOsnlCWQBt2lRwY WT0+eYKX5uqZr5m0iKY2RjAl2scFyufq2u6Xbb+YCGdeYu2jd2RhHLnU8nxpD1iG9vMlM6NchCy SiTX8tvB5WL/OQtBnFiWc7B/hg5jfUcuzfnzyJM4ttJcZvtfW7AzNutlviw== 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: 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 --- 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