mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yun Wang <arsenova@a7snv.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: Pavel Begunkov <asml.silence@gmail.com>,
	Hao Xu <haoxu@linux.alibaba.com>,
	Mengmeng Zhao <mengmeng.zhao@linux.dev>,
	io-uring@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 0/3] io_uring/rw: bound the -EAGAIN/-EOPNOTSUPP reissue
Date: Sun, 29 Nov 2026 18:32:49 +0000	[thread overview]
Message-ID: <20261129183214.3303492-1-arsenova@a7snv.com> (raw)

A read or write that completes with -EAGAIN or -EOPNOTSUPP from a
nonblocking attempt is reissued from io-wq. This series fixes two cases
where that reissue has no bound, and stops the retry for dma-buf
requests, where it can never succeed.

I found this while testing the ext4 dma-buf series [1] for bugs. A
direct read into a dma-buf registered buffer that covers [mapped | hole]
of a sparse file fails with -EOPNOTSUPP at the hole every time. The
completion runs outside io-wq, so io_rw_should_reissue() lets the
request be reissued again and again, and the CQE is never posted. An
8 KiB read of 4 KiB of data followed by a hole took 348 device reads
instead of 2 before it returned. A read of 2 MiB of data followed by a
hole had not returned after 5 seconds and had read 15.6 GiB (15932 MiB)
from the device by then. Only exiting the ring stops it.

The loop is not specific to dma-buf or ext4. It happens whenever the
completion of a blocking attempt keeps returning -EAGAIN or -EOPNOTSUPP
and does not run in the io-wq worker that issued it. On v7.4-rc2 it can
be reproduced on a raw NVMe namespace with fault injection (see patch
1), or with a FUSE server that uses FUSE_ASYNC_DIO and FOPEN_DIRECT_IO.
The loop exists since v6.14. Before that, these completions were not
reissued at all.

Patch 1 makes io_rw_should_reissue() look at IOCB_NOWAIT in the kiocb
instead of at the current thread. A request is still reissued once after
a nonblocking attempt, so the nvme multipath case from commit
b08e02045002 and the LVM snapshot case from commit 927069c4ac2c keep
working.

Patch 2 clears REQ_F_FORCE_ASYNC on reissue. Without it, an IOSQE_ASYNC
request on a pollable file (FUSE) is issued nonblocking again from
io-wq, and patch 1 alone does not stop the loop.

Patch 3 stops converting -EOPNOTSUPP to -EAGAIN, and stops reissuing,
for REQ_F_DMABUF requests. dma-buf I/O has no buffered fallback, so the
blocking retry fails the same way. This costs a second device read, and
with RWF_NOWAIT the application is told to retry something that cannot
succeed. Unlike patches 1 and 2, this is only a cost and not a loop, so
it is not marked for stable.

Patches 1 and 2 are needed together to fix the loop for every case.
Patch 3 is independent of them.

Testing, all on v7.4-rc2 unless noted:
- NVMe fault injection in QEMU, raw device and ext4: without the series
  a single 4 KiB read uses up every injected failure and then succeeds.
  With it, the read fails with -EOPNOTSUPP after two attempts, or one
  with IOSQE_ASYNC. The patched kernel gives the same result on a
  KIOXIA BG5.
- FUSE reproducer, default and IOSQE_ASYNC, with -EAGAIN and
  -EOPNOTSUPP: without the series the request is reissued until the
  reproducer's server gives up after 20 failures (21 READs). With it,
  the server sees 2 READs. Also run with KASAN and lockdep: no reports.
- dma-buf on a raw NVMe namespace (patch 3): see the patch. A buffered
  write from user memory to the same device is still retried and
  succeeds.
- With the ext4 dma-buf series: the sparse-file read above returns after
  two device reads with patches 1 and 2, and after one with patch 3.

The series is based on v7.4-rc2 and also applies to io_uring-7.4.
Patches 2 and 3 conflict with the io_req_{set,clear}_flags() conversion
in for-7.5/io_uring. I can rebase them onto it if you prefer.

On tool use: Gemini (gemini-4-neon-high) found the IOSQE_ASYNC path that
my first version of patch 1 missed, which patch 2 fixes. The patches,
the changelogs and this cover letter were written with AI assistance
(Claude, claude-opus-5-5). Claude was also used to build the tests that
do not depend on the ext4 series (NVMe fault injection, FUSE, dma-buf on
a raw NVMe namespace), to check that the problem is not caused by that
series. I reviewed the patches and the test results.

[1] https://lore.kernel.org/all/20261113070621.273953-1-mengmeng.zhao@linux.dev/

Yun Wang (3):
  io_uring/rw: don't reissue requests that were issued blocking
  io_uring: clear REQ_F_FORCE_ASYNC when reissuing a request
  io_uring/rw: don't retry dma-buf requests that fail with -EOPNOTSUPP

 io_uring/io_uring.c |  2 +-
 io_uring/rw.c       | 16 +++++++++++-----
 2 files changed, 12 insertions(+), 6 deletions(-)


base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
-- 
2.56.1



             reply	other threads:[~2026-11-29 18:32 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 18:32 Yun Wang [this message]
2026-11-29 18:33 ` [PATCH 1/3] io_uring/rw: don't reissue requests that were issued blocking Yun Wang
2026-11-29 18:33 ` [PATCH 2/3] io_uring: clear REQ_F_FORCE_ASYNC when reissuing a request Yun Wang
2026-11-29 18:34 ` [PATCH 3/3] io_uring/rw: don't retry dma-buf requests that fail with -EOPNOTSUPP Yun Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261129183214.3303492-1-arsenova@a7snv.com \
    --to=arsenova@a7snv.com \
    --cc=asml.silence@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=haoxu@linux.alibaba.com \
    --cc=io-uring@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mengmeng.zhao@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®