Repository navigation
Commit 6e2df05
Peter Zijlstra
sched: Fix pick_next_task() vs 'change' pattern race
Commit 6769243 ("sched: Rework pick_next_task() slow-path")
inadvertly introduced a race because it changed a previously
unexplored dependency between dropping the rq->lock and
sched_class::put_prev_task().
The comments about dropping rq->lock, in for example
newidle_balance(), only mentions the task being current and ->on_cpu
being set. But when we look at the 'change' pattern (in for example
sched_setnuma()):
queued = task_on_rq_queued(p); /* p->on_rq == TASK_ON_RQ_QUEUED */
running = task_current(rq, p); /* rq->curr == p */
if (queued)
dequeue_task(...);
if (running)
put_prev_task(...);
/* change task properties */
if (queued)
enqueue_task(...);
if (running)
set_next_task(...);
It becomes obvious that if we do this after put_prev_task() has
already been called on @p, things go sideways. This is exactly what
the commit in question allows to happen when it does:
prev->sched_class->put_prev_task(rq, prev, rf);
if (!rq->nr_running)
newidle_balance(rq, rf);
The newidle_balance() call will drop rq->lock after we've called
put_prev_task() and that allows the above 'change' pattern to
interleave and mess up the state.
Furthermore, it turns out we lost the RT-pull when we put the last DL
task.
Fix both problems by extracting the balancing from put_prev_task() and
doing a multi-class balance() pass before put_prev_task().
Fixes: 6769243 ("sched: Rework pick_next_task() slow-path")
Reported-by: Quentin Perret <qperret@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: Quentin Perret <qperret@google.com>
Tested-by: Valentin Schneider <valentin.schneider@arm.com>1 parent e3b8b6a commit 6e2df05
7 files changed
Lines changed: 112 additions & 58 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3929 | 3929 | | |
3930 | 3930 | | |
3931 | 3931 | | |
| 3932 | + | |
3932 | 3933 | | |
3933 | | - | |
3934 | | - | |
| 3934 | + | |
| 3935 | + | |
| 3936 | + | |
| 3937 | + | |
| 3938 | + | |
| 3939 | + | |
3935 | 3940 | | |
3936 | | - | |
3937 | | - | |
3938 | | - | |
| 3941 | + | |
| 3942 | + | |
| 3943 | + | |
| 3944 | + | |
| 3945 | + | |
| 3946 | + | |
| 3947 | + | |
3939 | 3948 | | |
3940 | 3949 | | |
3941 | 3950 | | |
| |||
6201 | 6210 | | |
6202 | 6211 | | |
6203 | 6212 | | |
6204 | | - | |
| 6213 | + | |
6205 | 6214 | | |
6206 | 6215 | | |
6207 | 6216 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1691 | 1691 | | |
1692 | 1692 | | |
1693 | 1693 | | |
| 1694 | + | |
| 1695 | + | |
| 1696 | + | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + | |
| 1706 | + | |
| 1707 | + | |
| 1708 | + | |
| 1709 | + | |
1694 | 1710 | | |
1695 | 1711 | | |
1696 | 1712 | | |
| |||
1758 | 1774 | | |
1759 | 1775 | | |
1760 | 1776 | | |
| 1777 | + | |
1761 | 1778 | | |
1762 | | - | |
1763 | 1779 | | |
1764 | 1780 | | |
1765 | 1781 | | |
1766 | | - | |
1767 | | - | |
1768 | | - | |
| 1782 | + | |
1769 | 1783 | | |
1770 | 1784 | | |
1771 | 1785 | | |
1772 | 1786 | | |
1773 | | - | |
1774 | 1787 | | |
1775 | | - | |
1776 | 1788 | | |
1777 | | - | |
1778 | 1789 | | |
1779 | 1790 | | |
1780 | 1791 | | |
1781 | | - | |
| 1792 | + | |
1782 | 1793 | | |
1783 | 1794 | | |
1784 | 1795 | | |
1785 | 1796 | | |
1786 | 1797 | | |
1787 | 1798 | | |
1788 | | - | |
1789 | | - | |
1790 | | - | |
1791 | | - | |
1792 | | - | |
1793 | | - | |
1794 | | - | |
1795 | | - | |
1796 | | - | |
1797 | | - | |
1798 | | - | |
1799 | | - | |
1800 | 1799 | | |
1801 | 1800 | | |
1802 | 1801 | | |
| |||
2442 | 2441 | | |
2443 | 2442 | | |
2444 | 2443 | | |
| 2444 | + | |
2445 | 2445 | | |
2446 | 2446 | | |
2447 | 2447 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6570 | 6570 | | |
6571 | 6571 | | |
6572 | 6572 | | |
| 6573 | + | |
| 6574 | + | |
| 6575 | + | |
| 6576 | + | |
| 6577 | + | |
| 6578 | + | |
| 6579 | + | |
| 6580 | + | |
| 6581 | + | |
6573 | 6582 | | |
6574 | 6583 | | |
6575 | 6584 | | |
| |||
6746 | 6755 | | |
6747 | 6756 | | |
6748 | 6757 | | |
6749 | | - | |
| 6758 | + | |
6750 | 6759 | | |
6751 | 6760 | | |
6752 | 6761 | | |
| |||
6884 | 6893 | | |
6885 | 6894 | | |
6886 | 6895 | | |
6887 | | - | |
| 6896 | + | |
6888 | 6897 | | |
6889 | 6898 | | |
6890 | 6899 | | |
| |||
10414 | 10423 | | |
10415 | 10424 | | |
10416 | 10425 | | |
10417 | | - | |
10418 | 10426 | | |
10419 | 10427 | | |
10420 | 10428 | | |
10421 | 10429 | | |
| 10430 | + | |
10422 | 10431 | | |
10423 | 10432 | | |
10424 | 10433 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
365 | 365 | | |
366 | 366 | | |
367 | 367 | | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
368 | 374 | | |
369 | 375 | | |
370 | 376 | | |
| |||
375 | 381 | | |
376 | 382 | | |
377 | 383 | | |
378 | | - | |
| 384 | + | |
379 | 385 | | |
380 | 386 | | |
381 | 387 | | |
| |||
460 | 466 | | |
461 | 467 | | |
462 | 468 | | |
| 469 | + | |
463 | 470 | | |
464 | 471 | | |
465 | 472 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1469 | 1469 | | |
1470 | 1470 | | |
1471 | 1471 | | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
| 1486 | + | |
| 1487 | + | |
1472 | 1488 | | |
1473 | 1489 | | |
1474 | 1490 | | |
| |||
1552 | 1568 | | |
1553 | 1569 | | |
1554 | 1570 | | |
1555 | | - | |
1556 | 1571 | | |
1557 | 1572 | | |
1558 | 1573 | | |
1559 | | - | |
| 1574 | + | |
1560 | 1575 | | |
1561 | 1576 | | |
1562 | 1577 | | |
1563 | | - | |
1564 | 1578 | | |
1565 | | - | |
1566 | 1579 | | |
1567 | 1580 | | |
1568 | 1581 | | |
1569 | | - | |
| 1582 | + | |
1570 | 1583 | | |
1571 | 1584 | | |
1572 | 1585 | | |
| |||
1578 | 1591 | | |
1579 | 1592 | | |
1580 | 1593 | | |
1581 | | - | |
1582 | | - | |
1583 | | - | |
1584 | | - | |
1585 | | - | |
1586 | | - | |
1587 | | - | |
1588 | | - | |
1589 | | - | |
1590 | | - | |
1591 | | - | |
1592 | | - | |
1593 | 1594 | | |
1594 | 1595 | | |
1595 | 1596 | | |
| |||
2366 | 2367 | | |
2367 | 2368 | | |
2368 | 2369 | | |
| 2370 | + | |
2369 | 2371 | | |
2370 | | - | |
2371 | 2372 | | |
2372 | 2373 | | |
2373 | 2374 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1727 | 1727 | | |
1728 | 1728 | | |
1729 | 1729 | | |
1730 | | - | |
| 1730 | + | |
1731 | 1731 | | |
1732 | 1732 | | |
1733 | 1733 | | |
| 1734 | + | |
1734 | 1735 | | |
1735 | 1736 | | |
1736 | 1737 | | |
| |||
1773 | 1774 | | |
1774 | 1775 | | |
1775 | 1776 | | |
1776 | | - | |
| 1777 | + | |
1777 | 1778 | | |
1778 | 1779 | | |
1779 | 1780 | | |
| |||
1787 | 1788 | | |
1788 | 1789 | | |
1789 | 1790 | | |
| 1791 | + | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
1790 | 1795 | | |
1791 | | - | |
| 1796 | + | |
1792 | 1797 | | |
1793 | 1798 | | |
1794 | 1799 | | |
1795 | 1800 | | |
1796 | 1801 | | |
1797 | 1802 | | |
1798 | 1803 | | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
| 1807 | + | |
| 1808 | + | |
| 1809 | + | |
| 1810 | + | |
| 1811 | + | |
| 1812 | + | |
| 1813 | + | |
| 1814 | + | |
| 1815 | + | |
| 1816 | + | |
| 1817 | + | |
| 1818 | + | |
| 1819 | + | |
| 1820 | + | |
| 1821 | + | |
| 1822 | + | |
1799 | 1823 | | |
1800 | 1824 | | |
1801 | 1825 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
18 | 24 | | |
19 | 25 | | |
20 | 26 | | |
| |||
31 | 37 | | |
32 | 38 | | |
33 | 39 | | |
34 | | - | |
35 | | - | |
36 | 40 | | |
37 | 41 | | |
38 | | - | |
| 42 | + | |
39 | 43 | | |
40 | 44 | | |
41 | | - | |
42 | | - | |
43 | | - | |
| 45 | + | |
| 46 | + | |
44 | 47 | | |
45 | 48 | | |
46 | 49 | | |
| |||
60 | 63 | | |
61 | 64 | | |
62 | 65 | | |
63 | | - | |
| 66 | + | |
64 | 67 | | |
65 | 68 | | |
66 | 69 | | |
| |||
129 | 132 | | |
130 | 133 | | |
131 | 134 | | |
| 135 | + | |
132 | 136 | | |
133 | 137 | | |
134 | 138 | | |
| |||
0 commit comments