From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796257976; b=gYWvztofj+XJiGIPGE9UJVEOAQiOnRWapQMQhw1ilFt18eIQbWJ18Y1LEI/xA7gjzmZi z3DNIWo9X7Z11grEck1DDUA7ikeM8X2Hq7RXB/TLGN49yinv0Locz2SlxdiGjLGd4lAT1 waOtk7NDXtAhelhXiGZ5X9UakwOBLYVY9tt2al6820vg1RYsWN+z+ixfYpeDW77F83G7j dDmaJg4f0jVTIDM1l32RKTtZXXv31Tb00zIb/e4gCwXwdEWc0vY1fScbxKoEmKjQrZqBA PoCC6fHXRluhM1Qpxx+EuBd3U1Ao1Oz9WwX9YFXUMfQQAjPJw74ZAUleIkEmvPQp2GA== 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=3O43mUef55EU//hZW0czKEvNr03cW5caF7zO0qNBcboZPejTpL5f2Gzfg8IpsXjp3ZQr WrJub+yVPJP0RLJ2kxj4kD3QyD/eDBhftEP2sqrv+vxmO9litss+viBsherAnYW/XpRIj isdxqvCLFqcN1WcFP3yrZcRqvpEld/iY/EGYhJGbtOOwfd+uE3k2Xuy2c4Sryyd/GSt6R wxb4oo/Bjo/P3AZlWM+4DJ+euByzRrwkcZgXJ7I9c0T73g6mSHSNCpZQfB3KtF+DXp5TT a2E9OapPvqp6/bveliYEkXDKnyv0vLpqZGn246mKr1bFhQaF68zdpU+SSfKVNaGD9vQ== 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.47 Received: from mail-ot1-f47.google.com (mail-ot1-f47.google.com [209.85.210.47]) (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 EBB7C606A32C for ; Thu, 3 Dec 2026 00:32:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EBB7C606A32C 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-f47.google.com with SMTP id 46e09a7af769-862a5b64755so7413899a34.2 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=aKrgvvUc2NdLLb8W0I02WhnMRnBdsw3UXtnOsmMCIuERtf7wwX1tzG43fUQbdWu+Fl 9epFGkX2Kw/u4z+MVs08gLGj7T/GfsFGbUlBOgQgAphubtwc8qQGsZUT9sxe7d1LGsp4 WuG3ojSz9J2PMWfXBiaZrg4kQn6EruiuHBtTaVQfqQZ5OKFg9txxk6hQnpmhCfHKIL8X LiHEcEgH7qVEFudFoZC5923NjEKinJ9vdBEhcnA9aunRTW+XM/TcqBIskZG3FbvU4T4K KZEcjXzQs5ViGnc+jme7lnnqWHm131SfJz0vvFeU76nSRzJacI5ugeAYILJSR1mTK98G YnYA== X-Forwarded-Encrypted: i=1; AL+hErHRMWf8sOX1Kzu++WM2aYIms5PPzYJK5Aay9U/zKx4WGbTCKIYcgGehjd5yvUvkOoE3dGREPUU9moqreA4f6g0=@vger.kernel.org X-Gm-Message-State: APuU4Z8A4uBG4h055rMYqDXgEsQK8PqGXi1talRev+Vy7OgH0nIGAG8o +dD/KZt8LBkubL1yqjQsyX1E0r5TlPZyKO5DxHjayCO8YBly7YSnGOam X-Gm-Gg: AZFdTZdiLtvo+hgQ+nt2hfO390cTpysiBw1L/uCGzl3/Tn//SNsb4WOFW+bgld6JoV6 l0U/na9jgw7Jz2CmgCMyW7ApBXtzveKNznYkDdU6v7qtSCUb77f98xQGA2hcIe05ACki+BTxd/Y Uwk42jtL/2nEVxuazj+bznQ923bi6L2H4GlT1GxWCHXz0iMhYScn7mKkDiVKf/+TkTzBKRfrr6b F+DmJGYXOfxdDm/brMCuBFdeq3VHMqbU0pA6Qmoi8bJY/mpZNz9QBoXpzLbb5q0mSO17/OakhGY dszzPGLreHEjxsQSQu+g45YrG0xuCbozGsh1yojPMF/rppIYDzPvql+NHtO+dRGSUeNjMjX5L2P Hs0EvrzceS1bfffcopTJAZtGAgxSwRigHgG69+inNB3qOjMVsAToi/IaDbr8eOTvpUMOgY+ycY+ JXKSCxnPHfXYGZOUsZQk11NbSyUuboVivwdAqUYhejZbd/qoXYSs0fHoCjlYO/r8nNrLDuS2HaF DFRNGQLp7bSdh9am1oBaYJ5DJo1HSR6AtL1JO6fc2Kws1FF834J6jyQJNRyhPGUYw671D0+ZQdo RRJk400hHwELc6OQIAQtW2hOrI8DOc2U57ymR0eN1Y/rZouA9wvY4wCRQ3wMKTW/M/0mh6rY1EG o2Z8jmDGB4kua/bKOX7ri/cvZ2FH2XC0tmmqG253ih4S8lCJ+8Lnvsuzycg== 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-kselftest@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