From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=109.224.244.22 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795977251; b=BOZIYSKldGR4Y31VEwUE/pKzfOY6OaBxXrGsE4rsJr+bSdOAcekF8xOPPkwCWCVPtRrm h3tHYQLHosdwEGHLqAR7aufvzYw3XxuonRpciFiY9ydgBvc8Zso+/BvkZCptSZFL+EqQn /LFqEVJVrNEFs5ZhsVoK2I7M/OVRUt8YovH5W7fPVFZr+sMYcX/FvsJ4k9lrCSzEsN6Ax b9AggdKFvkxBPIhC+dhgtWo+TyTfj2sNYkn3oDtxqbBcm0xWfSiqfNY5TZi1V9We71pUu kiiTSENY9vhwxBglmvddM8Ef9LMuey/TdUeVA9CxdnjqdEc7bHn3jZl1SDS2KldD9FQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795977251; h=DMARC-Filter:DKIM-Signature:Date:To:From:Cc:Subject:Message-ID: In-Reply-To:References:Feedback-ID:X-Pm-Message-ID:MIME-Version: Content-Type:Content-Transfer-Encoding; bh=gEp756QMHPZJwqzMeZPWVOemzhV+P9XUKDeYPYFYXGY=; b=jSuhH5EG7Lqg8W1wf5tUIkH5SfZ5xHtamUv/GgrO/B49iWmt3pfj8g/zhyIO63FpY4QU TMP8jCKvG9Wjbn/Gp90zp2Td4D79FvsMTV7WktPx1kBCZsh7d+D8VNMkYpZyVf2x4xq1o /tq38ACInx6E8/TkwcDgL5xDnCjQx0EwrQ+k0NQ9jdRH0w+iB3MmuHu/4xFwP6be++KCZ dgRHhSGR3hZD6csJYHDge8haqaKJxHtscrckpdcE2YHi6lYlCzAm9zMPFJshrNJQuum5x oAUNNyg8qqpxsikX4z1+V3P2iuhmr+qyZokxs1zh4zOc+uQAkMShIFs/72PRTF9rMMg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=a7snv.com; spf=pass smtp.mailfrom=a7snv.com; dkim=pass header.d=a7snv.com header.i=@a7snv.com header.a=rsa-sha256 header.s=protonmail header.b="mzl/1QXp"; arc=none smtp.remote-ip=109.224.244.22 Received: from mail-24422.protonmail.ch (mail-24422.protonmail.ch [109.224.244.22]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70157606A329 for ; Sun, 29 Nov 2026 18:34:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 70157606A329 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=a7snv.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=a7snv.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=a7snv.com header.i=@a7snv.com header.a=rsa-sha256 header.s=protonmail header.b=mzl/1QXp DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=a7snv.com; s=protonmail; t=1795977247; x=1796236447; bh=gEp756QMHPZJwqzMeZPWVOemzhV+P9XUKDeYPYFYXGY=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=mzl/1QXphvguI66Fc5SvLMvST52YMoCry25j3EytoPnPDioj/McxnsaefKrAQprVr 4A6T4Xd4+2lz8sRQWl3D5NFqM7GChm0g+q6NdxphQYzsTegBONPgi3jDoN6TBTgOAO gNWnBmfkwkWpY/eRsacXhqHc+CaDP0j03WkpjCPrvwkM+/einY2LhW/38PA+i72t9V KICs/8z1KNmQ135oNfLAmAFwqrzRCmB9n8C0ghbYNFLOD6djQqfdILnWhpieUzZZFO jGY/GfxIHEBuGXX5HvD5jiasCLRxyL1unR8D2SR7Uvunk+qdih7W+x5clTNd5HBpN/ GnCRXit64B+Fw== Date: Sun, 29 Nov 2026 18:34:03 +0000 To: Jens Axboe From: Yun Wang Cc: Pavel Begunkov , Hao Xu , Mengmeng Zhao , io-uring@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] io_uring/rw: don't retry dma-buf requests that fail with -EOPNOTSUPP Message-ID: <20261129183214.3303492-4-arsenova@a7snv.com> In-Reply-To: <20261129183214.3303492-1-arsenova@a7snv.com> References: <20261129183214.3303492-1-arsenova@a7snv.com> Feedback-ID: 235448903:user:proton X-Pm-Message-ID: cf99cc99561cb1034fffaa8b9642436497f343c6 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable io_uring treats -EOPNOTSUPP from a nonblocking read or write like -EAGAIN and retries the request from io-wq, both when ->read_iter() or ->write_iter() returns it and when it is passed to ->ki_complete(), because some filesystems and block devices return -EOPNOTSUPP for IOCB_NOWAIT requests that they can serve when allowed to block. That retry cannot succeed for a request that uses a dma-buf registered buffer. dma-buf I/O has no buffered fallback, so wherever the I/O path gives up with -EOPNOTSUPP, it gives up again from blocking context, even where the first -EOPNOTSUPP was caused by IOCB_NOWAIT. For example, register a dma-buf against a raw NVMe namespace opened with O_DIRECT, then clear O_DIRECT with F_SETFL. blkdev_read_iter() refuses the buffered read of a dma-buf iterator with -EOPNOTSUPP. A write fails in blkdev_write_iter() because IOCB_NOWAIT is set without IOCB_DIRECT, and then fails again in blkdev_buffered_write() because of the dma-buf iterator. With the ext4 dma-buf support under review, a direct read that reaches a hole inside the file fails the same way, and so does a write to a file with data journalling, which ext4 turns into a buffered write. The retry costs a second issue. For a read that covers mapped blocks before the hole, those blocks are read from the device a second time. With RWF_NOWAIT, the -EOPNOTSUPP is turned into -EAGAIN and returned to userspace, which asks the application to retry something that cannot succeed. Leave -EOPNOTSUPP alone for REQ_F_DMABUF requests. The flag is still set after io_detach_dmabuf_map(), so io_complete_rw() can check it. The one IOCB_NOWAIT-specific -EOPNOTSUPP that a blocking retry can fix comes from submit_bio_noacct() for a device without NOWAIT support. dma-buf I/O does not reach it today: only NVMe implements ->init_dma_buf_io_ctx, and NVMe namespaces and multipath devices support NOWAIT. This needs another look if stacking drivers gain dma-buf support. Tested on v7.4-rc2 with QEMU NVMe and udmabuf buffers, using the raw device case above: with RWF_NOWAIT, reads and writes now fail with -EOPNOTSUPP instead of -EAGAIN, and the write is no longer queued to io-wq a second time. A buffered write from user memory to the same device, the case the -EOPNOTSUPP retry exists for, is still retried from io-wq and succeeds. Also tested with the ext4 dma-buf series, on QEMU NVMe and on a KIOXIA BG5: a hole read with RWF_NOWAIT gets -EOPNOTSUPP, and a read of [mapped | hole] issues one device read instead of two. Fixes: 62e4bf5b25d4 ("io_uring/rsrc: add dmabuf backed registered buffers") Signed-off-by: Yun Wang --- io_uring/rw.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/io_uring/rw.c b/io_uring/rw.c index 7917d1536c47..0ab7cf3d503a 100644 --- a/io_uring/rw.c +++ b/io_uring/rw.c @@ -545,7 +545,9 @@ static void __io_complete_rw_common(struct io_kiocb *re= q, long res) { =09if (res =3D=3D req->cqe.res) =09=09return; -=09if ((res =3D=3D -EOPNOTSUPP || res =3D=3D -EAGAIN) && io_rw_should_reis= sue(req)) { +=09if ((res =3D=3D -EAGAIN || +=09 (res =3D=3D -EOPNOTSUPP && !(req->flags & REQ_F_DMABUF))) && +=09 io_rw_should_reissue(req)) { =09=09req->flags |=3D REQ_F_REISSUE | REQ_F_BL_NO_RECYCLE; =09} else { =09=09req_set_fail(req); @@ -944,7 +946,8 @@ static int __io_read(struct io_kiocb *req, struct io_br= _sel *sel, =09 * issue, even though they should be returning -EAGAIN. To be safe, =09 * retry from blocking context for either. =09 */ -=09if (ret =3D=3D -EOPNOTSUPP && force_nonblock) +=09if (ret =3D=3D -EOPNOTSUPP && force_nonblock && +=09 !(req->flags & REQ_F_DMABUF)) =09=09ret =3D -EAGAIN; =20 =09if (ret =3D=3D -EAGAIN) { @@ -1172,7 +1175,8 @@ int io_write(struct io_kiocb *req, unsigned int issue= _flags) =09 * Raw bdev writes will return -EOPNOTSUPP for IOCB_NOWAIT. Just =09 * retry them without IOCB_NOWAIT. =09 */ -=09if (ret2 =3D=3D -EOPNOTSUPP && (kiocb->ki_flags & IOCB_NOWAIT)) +=09if (ret2 =3D=3D -EOPNOTSUPP && (kiocb->ki_flags & IOCB_NOWAIT) && +=09 !(req->flags & REQ_F_DMABUF)) =09=09ret2 =3D -EAGAIN; =09/* no retry on NONBLOCK nor RWF_NOWAIT */ =09if (ret2 =3D=3D -EAGAIN && (req->flags & REQ_F_NOWAIT)) --=20 2.56.1