Commit c941d73
committed
sched_ext: Close root-enable vs sched_ext_dead() race with SCX_TASK_INIT_BEGIN
scx_root_enable_workfn() drops the iter rq lock for ops.init_task() and a
TASK_DEAD @p can fall through sched_ext_dead() in that window. The race hits
when sched_ext_dead() observes SCX_TASK_INIT (the intermediate state before
@p->scx.sched is published) and dereferences NULL via SCX_HAS_OP(NULL,
exit_task), or observes SCX_TASK_NONE during the unlocked init window and
skips cleanup so exit_task() never runs.
Add SCX_TASK_INIT_BEGIN. The enable path writes NONE -> INIT_BEGIN under the
iter rq lock, then takes the rq lock again after init to walk INIT_BEGIN ->
INIT -> READY. sched_ext_dead() that wins the rq-lock race observes
INIT_BEGIN and sets DEAD without calling into ops; the post-init recheck
unwinds via scx_sub_init_cancel_task().
scx_fork() runs single-threaded against sched_ext_dead() (the task is not on
scx_tasks until scx_post_fork() adds it) so its INIT_BEGIN -> INIT walk
needs no rq-lock pairing; it rolls back to NONE on ops.init_task() failure.
The validation matrix grows the INIT_BEGIN row and the INIT_BEGIN -> DEAD
edge; INIT now requires INIT_BEGIN as the predecessor. scx_sub_disable()'s
migration writes INIT_BEGIN as a synthetic predecessor to satisfy the
tightened verification.
The sub-sched paths still race with sched_ext_dead() during the unlocked
init window. This will be fixed by the next patch.
Reported-by: zhidao su <suzhidao@xiaomi.com>
Link: https://lore.kernel.org/all/20260429133155.3825247-1-suzhidao@xiaomi.com/
Signed-off-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Andrea Righi <arighi@nvidia.com>1 parent cceb8fa commit c941d73
2 files changed
Lines changed: 55 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| 109 | + | |
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
| |||
116 | 117 | | |
117 | 118 | | |
118 | 119 | | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
123 | 125 | | |
124 | 126 | | |
125 | 127 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
725 | 725 | | |
726 | 726 | | |
727 | 727 | | |
728 | | - | |
| 728 | + | |
729 | 729 | | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
730 | 733 | | |
731 | 734 | | |
732 | 735 | | |
| |||
737 | 740 | | |
738 | 741 | | |
739 | 742 | | |
740 | | - | |
| 743 | + | |
| 744 | + | |
741 | 745 | | |
742 | 746 | | |
743 | 747 | | |
| |||
3753 | 3757 | | |
3754 | 3758 | | |
3755 | 3759 | | |
| 3760 | + | |
3756 | 3761 | | |
3757 | | - | |
| 3762 | + | |
| 3763 | + | |
3758 | 3764 | | |
| 3765 | + | |
3759 | 3766 | | |
3760 | 3767 | | |
3761 | 3768 | | |
| |||
3856 | 3863 | | |
3857 | 3864 | | |
3858 | 3865 | | |
| 3866 | + | |
| 3867 | + | |
| 3868 | + | |
| 3869 | + | |
3859 | 3870 | | |
3860 | 3871 | | |
3861 | 3872 | | |
3862 | 3873 | | |
3863 | 3874 | | |
3864 | 3875 | | |
3865 | | - | |
| 3876 | + | |
| 3877 | + | |
3866 | 3878 | | |
3867 | 3879 | | |
3868 | 3880 | | |
| |||
5773 | 5785 | | |
5774 | 5786 | | |
5775 | 5787 | | |
| 5788 | + | |
5776 | 5789 | | |
5777 | 5790 | | |
5778 | 5791 | | |
| |||
6878 | 6891 | | |
6879 | 6892 | | |
6880 | 6893 | | |
| 6894 | + | |
| 6895 | + | |
| 6896 | + | |
6881 | 6897 | | |
6882 | 6898 | | |
6883 | 6899 | | |
| |||
6886 | 6902 | | |
6887 | 6903 | | |
6888 | 6904 | | |
| 6905 | + | |
| 6906 | + | |
| 6907 | + | |
| 6908 | + | |
| 6909 | + | |
| 6910 | + | |
| 6911 | + | |
| 6912 | + | |
| 6913 | + | |
| 6914 | + | |
6889 | 6915 | | |
6890 | 6916 | | |
6891 | 6917 | | |
| 6918 | + | |
| 6919 | + | |
| 6920 | + | |
6892 | 6921 | | |
| 6922 | + | |
| 6923 | + | |
| 6924 | + | |
6893 | 6925 | | |
6894 | 6926 | | |
6895 | 6927 | | |
6896 | 6928 | | |
6897 | 6929 | | |
6898 | 6930 | | |
6899 | 6931 | | |
6900 | | - | |
6901 | | - | |
6902 | | - | |
| 6932 | + | |
| 6933 | + | |
| 6934 | + | |
| 6935 | + | |
| 6936 | + | |
| 6937 | + | |
| 6938 | + | |
| 6939 | + | |
| 6940 | + | |
| 6941 | + | |
| 6942 | + | |
| 6943 | + | |
6903 | 6944 | | |
| 6945 | + | |
6904 | 6946 | | |
6905 | 6947 | | |
6906 | 6948 | | |
| |||
0 commit comments