* 6.6-stable inclusion request
@ 2025-06-12 17:40 Jens Axboe
2025-06-17 13:19 ` Greg Kroah-Hartman
0 siblings, 1 reply; 2+ messages in thread
From: Jens Axboe @ 2025-06-12 17:40 UTC (permalink / raw)
To: stable, Greg Kroah-Hartman; +Cc: Rom Lemarchand
[-- Attachment #1: Type: text/plain, Size: 253 bytes --]
Hi,
Can you add these three patches to 6.6-stable? It fixes a behavioral
change with 6.6-stable that Rom reported, affecting OpenBMC. Other
stable versions not affected, as they got the required fixes on top
backported already.
Thanks,
--
Jens Axboe
[-- Attachment #2: 0003-io_uring-rw-fix-wrong-NOWAIT-check-in-io_rw_init_fil.patch --]
[-- Type: text/x-patch, Size: 1374 bytes --]
From 3390df92ec38f364e7d770988cf116ed7b426489 Mon Sep 17 00:00:00 2001
From: Jens Axboe <axboe@kernel.dk>
Date: Sat, 19 Oct 2024 09:16:51 -0600
Subject: [PATCH 3/3] io_uring/rw: fix wrong NOWAIT check in io_rw_init_file()
Commit ae6a888a4357131c01d85f4c91fb32552dd0bf70 upstream.
A previous commit improved how !FMODE_NOWAIT is dealt with, but
inadvertently negated a check whilst doing so. This caused -EAGAIN to be
returned from reading files with O_NONBLOCK set. Fix up the check for
REQ_F_SUPPORT_NOWAIT.
Reported-by: Julian Orth <ju.orth@gmail.com>
Link: https://github.com/axboe/liburing/issues/1270
Fixes: f7c913438533 ("io_uring/rw: allow pollable non-blocking attempts for !FMODE_NOWAIT")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
io_uring/rw.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/io_uring/rw.c b/io_uring/rw.c
index 6344006cf718..4ff3442ac2ee 100644
--- a/io_uring/rw.c
+++ b/io_uring/rw.c
@@ -696,7 +696,7 @@ static int io_rw_init_file(struct io_kiocb *req, fmode_t mode)
* reliably. If not, or it IOCB_NOWAIT is set, don't retry.
*/
if (kiocb->ki_flags & IOCB_NOWAIT ||
- ((file->f_flags & O_NONBLOCK && (req->flags & REQ_F_SUPPORT_NOWAIT))))
+ ((file->f_flags & O_NONBLOCK && !(req->flags & REQ_F_SUPPORT_NOWAIT))))
req->flags |= REQ_F_NOWAIT;
if (ctx->flags & IORING_SETUP_IOPOLL) {
--
2.49.0
[-- Attachment #3: 0002-io_uring-rw-allow-pollable-non-blocking-attempts-for.patch --]
[-- Type: text/x-patch, Size: 3154 bytes --]
From 759b078e8395322668d9a0023df25ae32f2e356f Mon Sep 17 00:00:00 2001
From: Jens Axboe <axboe@kernel.dk>
Date: Sun, 6 Oct 2024 10:40:36 -0600
Subject: [PATCH 2/3] io_uring/rw: allow pollable non-blocking attempts for
!FMODE_NOWAIT
Commit f7c9134385331c5ef36252895130aa01a92de907 upstream.
The checking for whether or not io_uring can do a non-blocking read or
write attempt is gated on FMODE_NOWAIT. However, if the file is
pollable, it's feasible to just check if it's currently in a state in
which it can sanely receive or send _some_ data.
This avoids unnecessary io-wq punts, and repeated worthless retries
before doing that punt, by assuming that some data can get delivered
or received if poll tells us that is true. It also allows multishot
reads to properly work with these types of files, enabling a bit of
a cleanup of the logic that:
c9d952b9103b ("io_uring/rw: fix cflags posting for single issue multishot read")
had to put in place.
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
io_uring/rw.c | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/io_uring/rw.c b/io_uring/rw.c
index 230f553d1428..6344006cf718 100644
--- a/io_uring/rw.c
+++ b/io_uring/rw.c
@@ -28,9 +28,19 @@ struct io_rw {
rwf_t flags;
};
-static inline bool io_file_supports_nowait(struct io_kiocb *req)
+static bool io_file_supports_nowait(struct io_kiocb *req, __poll_t mask)
{
- return req->flags & REQ_F_SUPPORT_NOWAIT;
+ /* If FMODE_NOWAIT is set for a file, we're golden */
+ if (req->flags & REQ_F_SUPPORT_NOWAIT)
+ return true;
+ /* No FMODE_NOWAIT, if we can poll, check the status */
+ if (io_file_can_poll(req)) {
+ struct poll_table_struct pt = { ._key = mask };
+
+ return vfs_poll(req->file, &pt) & mask;
+ }
+ /* No FMODE_NOWAIT support, and file isn't pollable. Tough luck. */
+ return false;
}
#ifdef CONFIG_COMPAT
@@ -685,8 +695,8 @@ static int io_rw_init_file(struct io_kiocb *req, fmode_t mode)
* supports async. Otherwise it's impossible to use O_NONBLOCK files
* reliably. If not, or it IOCB_NOWAIT is set, don't retry.
*/
- if ((kiocb->ki_flags & IOCB_NOWAIT) ||
- ((file->f_flags & O_NONBLOCK) && !io_file_supports_nowait(req)))
+ if (kiocb->ki_flags & IOCB_NOWAIT ||
+ ((file->f_flags & O_NONBLOCK && (req->flags & REQ_F_SUPPORT_NOWAIT))))
req->flags |= REQ_F_NOWAIT;
if (ctx->flags & IORING_SETUP_IOPOLL) {
@@ -752,7 +762,7 @@ static int __io_read(struct io_kiocb *req, unsigned int issue_flags)
if (force_nonblock) {
/* If the file doesn't support async, just async punt */
- if (unlikely(!io_file_supports_nowait(req))) {
+ if (unlikely(!io_file_supports_nowait(req, EPOLLIN))) {
ret = io_setup_async_rw(req, iovec, s, true);
return ret ?: -EAGAIN;
}
@@ -927,7 +937,7 @@ int io_write(struct io_kiocb *req, unsigned int issue_flags)
if (force_nonblock) {
/* If the file doesn't support async, just async punt */
- if (unlikely(!io_file_supports_nowait(req)))
+ if (unlikely(!io_file_supports_nowait(req, EPOLLOUT)))
goto copy_iov;
/* File path supports NOWAIT for non-direct_IO only for block devices. */
--
2.49.0
[-- Attachment #4: 0001-io_uring-add-io_file_can_poll-helper.patch --]
[-- Type: text/x-patch, Size: 5036 bytes --]
From bf48072fe1ca2006b620292d1909748a30565c7d Mon Sep 17 00:00:00 2001
From: Jens Axboe <axboe@kernel.dk>
Date: Sun, 28 Jan 2024 20:08:24 -0700
Subject: [PATCH 1/3] io_uring: add io_file_can_poll() helper
Commit 95041b93e90a06bb613ec4bef9cd4d61570f68e4 upstream.
This adds a flag to avoid dipping dereferencing file and then f_op to
figure out if the file has a poll handler defined or not. We generally
call this at least twice for networked workloads, and if using ring
provided buffers, we do it on every buffer selection. Particularly the
latter is troublesome, as it's otherwise a very fast operation.
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
include/linux/io_uring_types.h | 3 +++
io_uring/io_uring.c | 2 +-
io_uring/io_uring.h | 12 ++++++++++++
io_uring/kbuf.c | 3 +--
io_uring/poll.c | 2 +-
io_uring/rw.c | 4 ++--
6 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/include/linux/io_uring_types.h b/include/linux/io_uring_types.h
index 0fadef2983e0..dad2f9e4d53d 100644
--- a/include/linux/io_uring_types.h
+++ b/include/linux/io_uring_types.h
@@ -416,6 +416,7 @@ enum {
/* keep async read/write and isreg together and in order */
REQ_F_SUPPORT_NOWAIT_BIT,
REQ_F_ISREG_BIT,
+ REQ_F_CAN_POLL_BIT,
/* not a real bit, just to check we're not overflowing the space */
__REQ_F_LAST_BIT,
@@ -483,6 +484,8 @@ enum {
REQ_F_CLEAR_POLLIN = BIT(REQ_F_CLEAR_POLLIN_BIT),
/* hashed into ->cancel_hash_locked, protected by ->uring_lock */
REQ_F_HASH_LOCKED = BIT(REQ_F_HASH_LOCKED_BIT),
+ /* file is pollable */
+ REQ_F_CAN_POLL = BIT(REQ_F_CAN_POLL_BIT),
};
typedef void (*io_req_tw_func_t)(struct io_kiocb *req, struct io_tw_state *ts);
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 43b46098279a..9c383afeaf8e 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -1953,7 +1953,7 @@ void io_wq_submit_work(struct io_wq_work *work)
if (req->flags & REQ_F_FORCE_ASYNC) {
bool opcode_poll = def->pollin || def->pollout;
- if (opcode_poll && file_can_poll(req->file)) {
+ if (opcode_poll && io_file_can_poll(req)) {
needs_poll = true;
issue_flags |= IO_URING_F_NONBLOCK;
}
diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h
index 0ffec66deee7..59f5f71037ff 100644
--- a/io_uring/io_uring.h
+++ b/io_uring/io_uring.h
@@ -5,6 +5,7 @@
#include <linux/lockdep.h>
#include <linux/resume_user_mode.h>
#include <linux/kasan.h>
+#include <linux/poll.h>
#include <linux/io_uring_types.h>
#include <uapi/linux/eventpoll.h>
#include "io-wq.h"
@@ -410,4 +411,15 @@ static inline size_t uring_sqe_size(struct io_ring_ctx *ctx)
return 2 * sizeof(struct io_uring_sqe);
return sizeof(struct io_uring_sqe);
}
+
+static inline bool io_file_can_poll(struct io_kiocb *req)
+{
+ if (req->flags & REQ_F_CAN_POLL)
+ return true;
+ if (file_can_poll(req->file)) {
+ req->flags |= REQ_F_CAN_POLL;
+ return true;
+ }
+ return false;
+}
#endif
diff --git a/io_uring/kbuf.c b/io_uring/kbuf.c
index 8c6611fe4f46..addd7c973657 100644
--- a/io_uring/kbuf.c
+++ b/io_uring/kbuf.c
@@ -148,8 +148,7 @@ static void __user *io_ring_buffer_select(struct io_kiocb *req, size_t *len,
req->buf_list = bl;
req->buf_index = buf->bid;
- if (issue_flags & IO_URING_F_UNLOCKED ||
- (req->file && !file_can_poll(req->file))) {
+ if (issue_flags & IO_URING_F_UNLOCKED || !io_file_can_poll(req)) {
/*
* If we came in unlocked, we have no choice but to consume the
* buffer here, otherwise nothing ensures that the buffer won't
diff --git a/io_uring/poll.c b/io_uring/poll.c
index cf8e86bc96de..2390bf5f1710 100644
--- a/io_uring/poll.c
+++ b/io_uring/poll.c
@@ -717,7 +717,7 @@ int io_arm_poll_handler(struct io_kiocb *req, unsigned issue_flags)
if (!def->pollin && !def->pollout)
return IO_APOLL_ABORTED;
- if (!file_can_poll(req->file))
+ if (!io_file_can_poll(req))
return IO_APOLL_ABORTED;
if (!(req->flags & REQ_F_APOLL_MULTISHOT))
mask |= EPOLLONESHOT;
diff --git a/io_uring/rw.c b/io_uring/rw.c
index 75b001febb4d..230f553d1428 100644
--- a/io_uring/rw.c
+++ b/io_uring/rw.c
@@ -629,7 +629,7 @@ static bool io_rw_should_retry(struct io_kiocb *req)
* just use poll if we can, and don't attempt if the fs doesn't
* support callback based unlocks
*/
- if (file_can_poll(req->file) || !(req->file->f_mode & FMODE_BUF_RASYNC))
+ if (io_file_can_poll(req) || !(req->file->f_mode & FMODE_BUF_RASYNC))
return false;
wait->wait.func = io_async_buf_func;
@@ -783,7 +783,7 @@ static int __io_read(struct io_kiocb *req, unsigned int issue_flags)
if (ret == -EAGAIN || (req->flags & REQ_F_REISSUE)) {
req->flags &= ~REQ_F_REISSUE;
/* if we can poll, just do that */
- if (req->opcode == IORING_OP_READ && file_can_poll(req->file))
+ if (req->opcode == IORING_OP_READ && io_file_can_poll(req))
return -EAGAIN;
/* IOPOLL retry should happen for io-wq threads */
if (!force_nonblock && !(req->ctx->flags & IORING_SETUP_IOPOLL))
--
2.49.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: 6.6-stable inclusion request
2025-06-12 17:40 6.6-stable inclusion request Jens Axboe
@ 2025-06-17 13:19 ` Greg Kroah-Hartman
0 siblings, 0 replies; 2+ messages in thread
From: Greg Kroah-Hartman @ 2025-06-17 13:19 UTC (permalink / raw)
To: Jens Axboe; +Cc: stable, Rom Lemarchand
On Thu, Jun 12, 2025 at 11:40:15AM -0600, Jens Axboe wrote:
> Hi,
>
> Can you add these three patches to 6.6-stable? It fixes a behavioral
> change with 6.6-stable that Rom reported, affecting OpenBMC. Other
> stable versions not affected, as they got the required fixes on top
> backported already.
Now queued up, thanks.
greg k-h
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-06-17 13:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-12 17:40 6.6-stable inclusion request Jens Axboe
2025-06-17 13:19 ` Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox