2020-04-21 20:13:52 +00:00
|
|
|
From 733fd0de9c18647a56f62e4b18288a7025cc476a Mon Sep 17 00:00:00 2001
|
2018-08-27 14:32:32 +00:00
|
|
|
From: Thomas Gleixner <tglx@linutronix.de>
|
2019-04-08 23:49:20 +00:00
|
|
|
Date: Wed, 7 Mar 2012 20:51:03 +0100
|
2020-04-21 20:13:52 +00:00
|
|
|
Subject: [PATCH 182/325] rt: Introduce cpu_chill()
|
|
|
|
Origin: https://www.kernel.org/pub/linux/kernel/projects/rt/4.19/older/patches-4.19.115-rt48.tar.xz
|
2018-08-27 14:32:32 +00:00
|
|
|
|
|
|
|
Retry loops on RT might loop forever when the modifying side was
|
|
|
|
preempted. Add cpu_chill() to replace cpu_relax(). cpu_chill()
|
|
|
|
defaults to cpu_relax() for non RT. On RT it puts the looping task to
|
|
|
|
sleep for a tick so the preempted task can make progress.
|
|
|
|
|
|
|
|
Steven Rostedt changed it to use a hrtimer instead of msleep():
|
|
|
|
|
|
|
|
|
|Ulrich Obergfell pointed out that cpu_chill() calls msleep() which is woken
|
|
|
|
|up by the ksoftirqd running the TIMER softirq. But as the cpu_chill() is
|
|
|
|
|called from softirq context, it may block the ksoftirqd() from running, in
|
|
|
|
|which case, it may never wake up the msleep() causing the deadlock.
|
|
|
|
|
|
|
|
+ bigeasy later changed to schedule_hrtimeout()
|
|
|
|
|If a task calls cpu_chill() and gets woken up by a regular or spurious
|
|
|
|
|wakeup and has a signal pending, then it exits the sleep loop in
|
|
|
|
|do_nanosleep() and sets up the restart block. If restart->nanosleep.type is
|
|
|
|
|not TI_NONE then this results in accessing a stale user pointer from a
|
|
|
|
|previously interrupted syscall and a copy to user based on the stale
|
|
|
|
|pointer or a BUG() when 'type' is not supported in nanosleep_copyout().
|
|
|
|
|
|
|
|
+ bigeasy: add PF_NOFREEZE:
|
|
|
|
| [....] Waiting for /dev to be fully populated...
|
|
|
|
| =====================================
|
|
|
|
| [ BUG: udevd/229 still has locks held! ]
|
|
|
|
| 3.12.11-rt17 #23 Not tainted
|
|
|
|
| -------------------------------------
|
|
|
|
| 1 lock held by udevd/229:
|
|
|
|
| #0: (&type->i_mutex_dir_key#2){+.+.+.}, at: lookup_slow+0x28/0x98
|
|
|
|
|
|
|
|
|
| stack backtrace:
|
|
|
|
| CPU: 0 PID: 229 Comm: udevd Not tainted 3.12.11-rt17 #23
|
|
|
|
| (unwind_backtrace+0x0/0xf8) from (show_stack+0x10/0x14)
|
|
|
|
| (show_stack+0x10/0x14) from (dump_stack+0x74/0xbc)
|
|
|
|
| (dump_stack+0x74/0xbc) from (do_nanosleep+0x120/0x160)
|
|
|
|
| (do_nanosleep+0x120/0x160) from (hrtimer_nanosleep+0x90/0x110)
|
|
|
|
| (hrtimer_nanosleep+0x90/0x110) from (cpu_chill+0x30/0x38)
|
|
|
|
| (cpu_chill+0x30/0x38) from (dentry_kill+0x158/0x1ec)
|
|
|
|
| (dentry_kill+0x158/0x1ec) from (dput+0x74/0x15c)
|
|
|
|
| (dput+0x74/0x15c) from (lookup_real+0x4c/0x50)
|
|
|
|
| (lookup_real+0x4c/0x50) from (__lookup_hash+0x34/0x44)
|
|
|
|
| (__lookup_hash+0x34/0x44) from (lookup_slow+0x38/0x98)
|
|
|
|
| (lookup_slow+0x38/0x98) from (path_lookupat+0x208/0x7fc)
|
|
|
|
| (path_lookupat+0x208/0x7fc) from (filename_lookup+0x20/0x60)
|
|
|
|
| (filename_lookup+0x20/0x60) from (user_path_at_empty+0x50/0x7c)
|
|
|
|
| (user_path_at_empty+0x50/0x7c) from (user_path_at+0x14/0x1c)
|
|
|
|
| (user_path_at+0x14/0x1c) from (vfs_fstatat+0x48/0x94)
|
|
|
|
| (vfs_fstatat+0x48/0x94) from (SyS_stat64+0x14/0x30)
|
|
|
|
| (SyS_stat64+0x14/0x30) from (ret_fast_syscall+0x0/0x48)
|
|
|
|
|
|
|
|
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
|
|
|
|
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
|
|
|
|
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
|
|
|
|
---
|
2019-04-08 23:49:20 +00:00
|
|
|
include/linux/delay.h | 6 ++++++
|
|
|
|
kernel/time/hrtimer.c | 21 +++++++++++++++++++++
|
2018-08-27 14:32:32 +00:00
|
|
|
2 files changed, 27 insertions(+)
|
|
|
|
|
2019-04-08 23:49:20 +00:00
|
|
|
diff --git a/include/linux/delay.h b/include/linux/delay.h
|
|
|
|
index b78bab4395d8..7c4bc414a504 100644
|
2018-08-27 14:32:32 +00:00
|
|
|
--- a/include/linux/delay.h
|
|
|
|
+++ b/include/linux/delay.h
|
2019-04-08 23:49:20 +00:00
|
|
|
@@ -64,4 +64,10 @@ static inline void ssleep(unsigned int seconds)
|
2018-08-27 14:32:32 +00:00
|
|
|
msleep(seconds * 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
+#ifdef CONFIG_PREEMPT_RT_FULL
|
|
|
|
+extern void cpu_chill(void);
|
|
|
|
+#else
|
|
|
|
+# define cpu_chill() cpu_relax()
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
#endif /* defined(_LINUX_DELAY_H) */
|
2019-04-08 23:49:20 +00:00
|
|
|
diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
|
2020-01-19 00:54:59 +00:00
|
|
|
index b800efb64238..98a771065818 100644
|
2018-08-27 14:32:32 +00:00
|
|
|
--- a/kernel/time/hrtimer.c
|
|
|
|
+++ b/kernel/time/hrtimer.c
|
2020-01-19 00:54:59 +00:00
|
|
|
@@ -1897,6 +1897,27 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp,
|
2018-08-27 14:32:32 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
+#ifdef CONFIG_PREEMPT_RT_FULL
|
|
|
|
+/*
|
|
|
|
+ * Sleep for 1 ms in hope whoever holds what we want will let it go.
|
|
|
|
+ */
|
|
|
|
+void cpu_chill(void)
|
|
|
|
+{
|
|
|
|
+ ktime_t chill_time;
|
|
|
|
+ unsigned int freeze_flag = current->flags & PF_NOFREEZE;
|
|
|
|
+
|
|
|
|
+ chill_time = ktime_set(0, NSEC_PER_MSEC);
|
|
|
|
+ set_current_state(TASK_UNINTERRUPTIBLE);
|
|
|
|
+ current->flags |= PF_NOFREEZE;
|
|
|
|
+ sleeping_lock_inc();
|
|
|
|
+ schedule_hrtimeout(&chill_time, HRTIMER_MODE_REL_HARD);
|
|
|
|
+ sleeping_lock_dec();
|
|
|
|
+ if (!freeze_flag)
|
|
|
|
+ current->flags &= ~PF_NOFREEZE;
|
|
|
|
+}
|
|
|
|
+EXPORT_SYMBOL(cpu_chill);
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
/*
|
|
|
|
* Functions related to boot-time initialization:
|
|
|
|
*/
|
2020-01-03 23:36:11 +00:00
|
|
|
--
|
2020-04-09 19:44:24 +00:00
|
|
|
2.25.1
|
2020-01-03 23:36:11 +00:00
|
|
|
|