From 69374cb1f7e54b05243fa43a19526d94618c830b Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 10 Mar 2023 13:08:02 +0100 Subject: [PATCH] 6.1-stable patches added patches: io_uring-fix-two-assignments-in-if-conditions.patch io_uring-poll-allow-some-retries-for-poll-triggering-spuriously.patch --- ...fix-two-assignments-in-if-conditions.patch | 74 +++++++++++++++ ...tries-for-poll-triggering-spuriously.patch | 93 +++++++++++++++++++ queue-6.1/series | 2 + 3 files changed, 169 insertions(+) create mode 100644 queue-6.1/io_uring-fix-two-assignments-in-if-conditions.patch create mode 100644 queue-6.1/io_uring-poll-allow-some-retries-for-poll-triggering-spuriously.patch diff --git a/queue-6.1/io_uring-fix-two-assignments-in-if-conditions.patch b/queue-6.1/io_uring-fix-two-assignments-in-if-conditions.patch new file mode 100644 index 00000000000..469191f1154 --- /dev/null +++ b/queue-6.1/io_uring-fix-two-assignments-in-if-conditions.patch @@ -0,0 +1,74 @@ +From df730ec21f7ba395b1b22e7f93a3a85b1d1b7882 Mon Sep 17 00:00:00 2001 +From: Xinghui Li +Date: Wed, 2 Nov 2022 16:25:03 +0800 +Subject: io_uring: fix two assignments in if conditions + +From: Xinghui Li + +commit df730ec21f7ba395b1b22e7f93a3a85b1d1b7882 upstream. + +Fixes two errors: + +"ERROR: do not use assignment in if condition +130: FILE: io_uring/net.c:130: ++ if (!(issue_flags & IO_URING_F_UNLOCKED) && + +ERROR: do not use assignment in if condition +599: FILE: io_uring/poll.c:599: ++ } else if (!(issue_flags & IO_URING_F_UNLOCKED) &&" +reported by checkpatch.pl in net.c and poll.c . + +Signed-off-by: Xinghui Li +Reported-by: kernel test robot +Link: https://lore.kernel.org/r/20221102082503.32236-1-korantwork@gmail.com +[axboe: style tweaks] +Signed-off-by: Jens Axboe +Signed-off-by: Greg Kroah-Hartman +--- + io_uring/net.c | 16 +++++++++------- + io_uring/poll.c | 7 +++++-- + 2 files changed, 14 insertions(+), 9 deletions(-) + +--- a/io_uring/net.c ++++ b/io_uring/net.c +@@ -126,13 +126,15 @@ static struct io_async_msghdr *io_msg_al + struct io_cache_entry *entry; + struct io_async_msghdr *hdr; + +- if (!(issue_flags & IO_URING_F_UNLOCKED) && +- (entry = io_alloc_cache_get(&ctx->netmsg_cache)) != NULL) { +- hdr = container_of(entry, struct io_async_msghdr, cache); +- hdr->free_iov = NULL; +- req->flags |= REQ_F_ASYNC_DATA; +- req->async_data = hdr; +- return hdr; ++ if (!(issue_flags & IO_URING_F_UNLOCKED)) { ++ entry = io_alloc_cache_get(&ctx->netmsg_cache); ++ if (entry) { ++ hdr = container_of(entry, struct io_async_msghdr, cache); ++ hdr->free_iov = NULL; ++ req->flags |= REQ_F_ASYNC_DATA; ++ req->async_data = hdr; ++ return hdr; ++ } + } + + if (!io_alloc_async_data(req)) { +--- a/io_uring/poll.c ++++ b/io_uring/poll.c +@@ -678,10 +678,13 @@ static struct async_poll *io_req_alloc_a + if (req->flags & REQ_F_POLLED) { + apoll = req->apoll; + kfree(apoll->double_poll); +- } else if (!(issue_flags & IO_URING_F_UNLOCKED) && +- (entry = io_alloc_cache_get(&ctx->apoll_cache)) != NULL) { ++ } else if (!(issue_flags & IO_URING_F_UNLOCKED)) { ++ entry = io_alloc_cache_get(&ctx->apoll_cache); ++ if (entry == NULL) ++ goto alloc_apoll; + apoll = container_of(entry, struct async_poll, cache); + } else { ++alloc_apoll: + apoll = kmalloc(sizeof(*apoll), GFP_ATOMIC); + if (unlikely(!apoll)) + return NULL; diff --git a/queue-6.1/io_uring-poll-allow-some-retries-for-poll-triggering-spuriously.patch b/queue-6.1/io_uring-poll-allow-some-retries-for-poll-triggering-spuriously.patch new file mode 100644 index 00000000000..58a41255b6c --- /dev/null +++ b/queue-6.1/io_uring-poll-allow-some-retries-for-poll-triggering-spuriously.patch @@ -0,0 +1,93 @@ +From c16bda37594f83147b167d381d54c010024efecf Mon Sep 17 00:00:00 2001 +From: Jens Axboe +Date: Sat, 25 Feb 2023 12:53:53 -0700 +Subject: io_uring/poll: allow some retries for poll triggering spuriously + +From: Jens Axboe + +commit c16bda37594f83147b167d381d54c010024efecf upstream. + +If we get woken spuriously when polling and fail the operation with +-EAGAIN again, then we generally only allow polling again if data +had been transferred at some point. This is indicated with +REQ_F_PARTIAL_IO. However, if the spurious poll triggers when the socket +was originally empty, then we haven't transferred data yet and we will +fail the poll re-arm. This either punts the socket to io-wq if it's +blocking, or it fails the request with -EAGAIN if not. Neither condition +is desirable, as the former will slow things down, while the latter +will make the application confused. + +We want to ensure that a repeated poll trigger doesn't lead to infinite +work making no progress, that's what the REQ_F_PARTIAL_IO check was +for. But it doesn't protect against a loop post the first receive, and +it's unnecessarily strict if we started out with an empty socket. + +Add a somewhat random retry count, just to put an upper limit on the +potential number of retries that will be done. This should be high enough +that we won't really hit it in practice, unless something needs to be +aborted anyway. + +Cc: stable@vger.kernel.org # v5.10+ +Link: https://github.com/axboe/liburing/issues/364 +Signed-off-by: Jens Axboe +Signed-off-by: Greg Kroah-Hartman +--- + io_uring/poll.c | 14 ++++++++++++-- + io_uring/poll.h | 1 + + 2 files changed, 13 insertions(+), 2 deletions(-) + +--- a/io_uring/poll.c ++++ b/io_uring/poll.c +@@ -668,6 +668,14 @@ static void io_async_queue_proc(struct f + __io_queue_proc(&apoll->poll, pt, head, &apoll->double_poll); + } + ++/* ++ * We can't reliably detect loops in repeated poll triggers and issue ++ * subsequently failing. But rather than fail these immediately, allow a ++ * certain amount of retries before we give up. Given that this condition ++ * should _rarely_ trigger even once, we should be fine with a larger value. ++ */ ++#define APOLL_MAX_RETRY 128 ++ + static struct async_poll *io_req_alloc_apoll(struct io_kiocb *req, + unsigned issue_flags) + { +@@ -683,14 +691,18 @@ static struct async_poll *io_req_alloc_a + if (entry == NULL) + goto alloc_apoll; + apoll = container_of(entry, struct async_poll, cache); ++ apoll->poll.retries = APOLL_MAX_RETRY; + } else { + alloc_apoll: + apoll = kmalloc(sizeof(*apoll), GFP_ATOMIC); + if (unlikely(!apoll)) + return NULL; ++ apoll->poll.retries = APOLL_MAX_RETRY; + } + apoll->double_poll = NULL; + req->apoll = apoll; ++ if (unlikely(!--apoll->poll.retries)) ++ return NULL; + return apoll; + } + +@@ -712,8 +724,6 @@ int io_arm_poll_handler(struct io_kiocb + return IO_APOLL_ABORTED; + if (!file_can_poll(req->file)) + return IO_APOLL_ABORTED; +- if ((req->flags & (REQ_F_POLLED|REQ_F_PARTIAL_IO)) == REQ_F_POLLED) +- return IO_APOLL_ABORTED; + if (!(req->flags & REQ_F_APOLL_MULTISHOT)) + mask |= EPOLLONESHOT; + +--- a/io_uring/poll.h ++++ b/io_uring/poll.h +@@ -12,6 +12,7 @@ struct io_poll { + struct file *file; + struct wait_queue_head *head; + __poll_t events; ++ int retries; + struct wait_queue_entry wait; + }; + diff --git a/queue-6.1/series b/queue-6.1/series index 0fa60d40b75..0a645d6860a 100644 --- a/queue-6.1/series +++ b/queue-6.1/series @@ -192,3 +192,5 @@ drm-display-dp_mst-fix-payload-addition-on-a-disconnected-sink.patch drm-i915-dp_mst-add-the-mst-topology-state-for-modesetted-crtcs.patch drm-i915-fix-system-suspend-without-fbdev-being-initialized.patch media-uvcvideo-fix-race-condition-with-usb_kill_urb.patch +io_uring-fix-two-assignments-in-if-conditions.patch +io_uring-poll-allow-some-retries-for-poll-triggering-spuriously.patch -- 2.47.3