All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	patches@lists.linux.dev, Austin Schuh <austin.linux@gmail.com>,
	Jens Axboe <axboe@kernel.dk>
Subject: [PATCH 7.3 15/38] io_uring/wait: wake real-time waiters from hard interrupt context
Date: Wed, 28 Oct 2026 18:00:02 +0100	[thread overview]
Message-ID: <20261028165940.784349460@linuxfoundation.org> (raw)
In-Reply-To: <20261028165940.394092994@linuxfoundation.org>

7.3-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Austin Schuh <austin.linux@gmail.com>

commit 5b01d5955ac206e38097f777eff6ab2a8b948c41 upstream.

Since commit cebf123c634a ("io_uring: implement our own schedule timeout
handling"), a CQ wait with a timeout sleeps on io_uring's own hrtimer
instead of an hrtimer sleeper.  On PREEMPT_RT, an hrtimer that isn't
marked for hard interrupt expiry expires in the per-CPU ktimers thread,
which runs at SCHED_FIFO 1.  A real-time task waiting in io_uring_enter()
is therefore not woken at its deadline while any other real-time task is
runnable on its CPU: the wakeup waits until every one of them has blocked.

hrtimer sleepers, which schedule_hrtimeout_range_clock() used to give
io_uring, don't have this problem: __hrtimer_setup_sleeper() marks the
timer hard when the sleeping task is in a real-time or deadline class.
Both of io_uring's callbacks are fine in hard interrupt context:
io_cqring_timer_wakeup() sets a flag and calls wake_up_process(), and
io_cqring_min_timer_wakeup() only reads ring state, under RCU, before
doing the same or re-arming the timer.  Apply the sleeper rule to them.

Measured on a Jetson Orin Nano running 6.18.39-rt with this change
backported: a SCHED_FIFO 40 task waits in io_uring_enter() for 40,000
deadlines 500us apart, while a SCHED_FIFO 20 task runs bursts of up to
1ms on the same CPU.  Before, 6,647 wakeups were more than 100us late,
the latest by 1,040us, and 2,758 deadlines passed without a wakeup at
all.  After, none were more than 100us late and the latest was 18us.

This mirrors epoll: epoll_pwait2() waits on an hrtimer sleeper, so its
timeout is already hard for real-time tasks, and on the same setup it
was never more than 17us late.

Fixes: cebf123c634a ("io_uring: implement our own schedule timeout handling")
Cc: stable@vger.kernel.org
Assisted-by: LLM
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
Link: https://patch.msgid.link/20261017171726.601443-1-austin.linux@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 io_uring/wait.c |   16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

--- a/io_uring/wait.c
+++ b/io_uring/wait.c
@@ -3,6 +3,7 @@
  * Waiting for completion events
  */
 #include <linux/kernel.h>
+#include <linux/sched/rt.h>
 #include <linux/sched/signal.h>
 #include <linux/io_uring.h>
 #include <linux/time_namespace.h>
@@ -112,23 +113,32 @@ out_wake:
 	return io_cqring_timer_wakeup(timer);
 }
 
+/* Same policy as for hrtimer sleepers, see __hrtimer_setup_sleeper(). */
+static enum hrtimer_mode io_cqring_timer_mode(void)
+{
+	if (IS_ENABLED(CONFIG_PREEMPT_RT) && rt_or_dl_task_policy(current))
+		return HRTIMER_MODE_ABS_HARD;
+	return HRTIMER_MODE_ABS;
+}
+
 static int io_cqring_schedule_timeout(struct io_wait_queue *iowq,
 				      clockid_t clock_id, ktime_t start_time)
 {
+	enum hrtimer_mode mode = io_cqring_timer_mode();
 	ktime_t timeout;
 
 	if (iowq->min_timeout) {
 		timeout = ktime_add_ns(iowq->min_timeout, start_time);
 		hrtimer_setup_on_stack(&iowq->t, io_cqring_min_timer_wakeup, clock_id,
-				       HRTIMER_MODE_ABS);
+				       mode);
 	} else {
 		timeout = iowq->timeout;
 		hrtimer_setup_on_stack(&iowq->t, io_cqring_timer_wakeup, clock_id,
-				       HRTIMER_MODE_ABS);
+				       mode);
 	}
 
 	hrtimer_set_expires_range_ns(&iowq->t, timeout, 0);
-	hrtimer_start_expires(&iowq->t, HRTIMER_MODE_ABS);
+	hrtimer_start_expires(&iowq->t, mode);
 
 	if (!READ_ONCE(iowq->hit_timeout))
 		schedule();



  parent reply	other threads:[~2026-10-28 17:04 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-28 16:59 [PATCH 7.3 00/38] 7.3.1-rc1 review Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.3 01/38] genirq/proc: Fix missing CPU header in /proc/interrupts Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.3 02/38] mm/damon/core: error damos_commit_quota_goal() for zero target_value Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.3 03/38] Bluetooth: L2CAP: refuse __l2cap_chan_add if chan already has conn Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.3 04/38] tools/dma: fix building with O= Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.3 05/38] tracing: Hold trace_types_lock when updating modules in persistent instances Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.3 06/38] tracing: Hold trace_types_lock when resetting last boot data from readers Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.3 07/38] tracing: Reject incomplete event filter expressions Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.3 08/38] tracing: Save the event file instead of the compatible histogram Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.3 09/38] tracing: Unregister field variable histograms when the command fails Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.3 10/38] tracing: Add the bucket size to expr_field_str() Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.3 11/38] tracing: Fix 64-bit and signed histogram fields on 32-bit kernels Greg Kroah-Hartman
2026-10-28 16:59 ` [PATCH 7.3 12/38] tracing/histograms: Verify event_call identity when updating synth_event refcount Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 13/38] tracing/syscalls: Use copy_from_user for the faultable syscall buffer Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 14/38] io_uring/poll: avoid retry wakeup loss when dropping ownership Greg Kroah-Hartman
2026-10-29  7:53   ` Jiri Slaby
2026-10-29  9:07     ` Greg Kroah-Hartman
2026-10-28 17:00 ` Greg Kroah-Hartman [this message]
2026-10-28 17:00 ` [PATCH 7.3 16/38] io_uring/net: keep recv buffer select length within MAX_RW_COUNT Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 17/38] io_uring/waitid: prevent cancel reference wrap Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 18/38] io_uring: end the drain when the drain request completes Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 19/38] keys: Avoid the owner account dereference in named keyring lookup Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 20/38] keys: Check the authorization payload in process keyring searches Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 21/38] keys: Protect the type name while describing a key Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 22/38] keys: make keyring indexes independent of kernel addresses Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 23/38] keys: Protect the read method check against type removal Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 24/38] KEYS: Fix key_reject_and_link() race with keyring restriction Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 25/38] KEYS: trusted: Fix blob allocation size in tpm2_key_decode() Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 26/38] keys/trusted_keys: return immediately after TPM unseal failure Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 27/38] asymmetric_keys: reject trust keys without IDs Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 28/38] ftrace: Initialize modname and offset in print_rec() Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 29/38] coredump: hold RCU while releasing parked threads Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 30/38] signal: only SIGKILL and the freezers interrupt a coredumping task Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 31/38] io-wq: order the exit bit against worker creation task work Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 32/38] signal: dont retarget shared signals in a dying thread group Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 33/38] ptrace: refuse to change the signal mask of a user worker Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 34/38] fork: release the files of a failed fork after sched_cancel_fork() Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 35/38] exit: hang up the tty before closing the files Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 36/38] coredump: prevent TIF_NOTIFY_SIGNAL from interrupting coredumps Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 37/38] pid_namespace: prevent TIF_NOTIFY_SIGNAL from interrupting the reaper Greg Kroah-Hartman
2026-10-28 17:00 ` [PATCH 7.3 38/38] signal: allow taks to temporarily block TIF_NOTIFY_SIGNAL Greg Kroah-Hartman
2026-10-28 18:08 ` [PATCH 7.3 00/38] 7.3.1-rc1 review Ronald Warsow
2026-10-28 19:40 ` Brett A C Sheffield
2026-10-29  4:01 ` Takeshi Ogasawara
2026-10-29  5:00 ` Peter Schneider
2026-10-29 12:06 ` Barry K. Nathan
2026-10-29 13:53 ` Miguel Ojeda
2026-10-29 14:12 ` Ron Economos
2026-10-29 14:42 ` SJ Park
2026-10-29 15:17 ` Shuah Khan

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=20261028165940.784349460@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=austin.linux@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=patches@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.