Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-doc
Path: blob/main/website/static/security/patches/EN-10:02/sched_ule.patch
18096 views
1
Index: sys/kern/sched_ule.c
2
===================================================================
3
--- sys/kern/sched_ule.c (revision 202744)
4
+++ sys/kern/sched_ule.c (working copy)
5
@@ -1822,18 +1822,24 @@
6
*/
7
spinlock_enter();
8
thread_block_switch(td); /* This releases the lock on tdq. */
9
- TDQ_LOCK(tdn);
10
- tdq_add(tdn, td, flags);
11
- tdq_notify(td->td_sched);
12
+
13
/*
14
- * After we unlock tdn the new cpu still can't switch into this
15
- * thread until we've unblocked it in cpu_switch(). The lock
16
- * pointers may match in the case of HTT cores. Don't unlock here
17
- * or we can deadlock when the other CPU runs the IPI handler.
18
+ * Acquire both run-queue locks before placing the thread on the new
19
+ * run-queue to avoid deadlocks created by placing a thread with a
20
+ * blocked lock on the run-queue of a remote processor. The deadlock
21
+ * occurs when a third processor attempts to lock the two queues in
22
+ * question while the target processor is spinning with its own
23
+ * run-queue lock held while waiting for the blocked lock to clear.
24
*/
25
- if (TDQ_LOCKPTR(tdn) != TDQ_LOCKPTR(tdq)) {
26
+ if (TDQ_LOCKPTR(tdn) == TDQ_LOCKPTR(tdq)) {
27
+ TDQ_LOCK(tdq);
28
+ tdq_add(tdn, td, flags);
29
+ tdq_notify(td->td_sched);
30
+ } else {
31
+ tdq_lock_pair(tdn, tdq);
32
+ tdq_add(tdn, td, flags);
33
+ tdq_notify(td->td_sched);
34
TDQ_UNLOCK(tdn);
35
- TDQ_LOCK(tdq);
36
}
37
spinlock_exit();
38
#endif
39
40