Hello,There are two ways to set favordynmods. The first is through kernel config or
On Fri, Sep 05, 2025 at 10:16:30AM +0800, escape wrote:
I don't think that's necessarily true. favordynmods can also be specified ashave_favordynmods is read-only after initialization and will not change+ if (have_favordynmods)Hmm... I wonder whether turning on/off the flag is racy. ie. what prevents
+ up_read(&tsk->signal->group_rwsem);
percpu_up_read(&cgroup_threadgroup_rwsem);
have_favordynmods flipping while a task is between change_begin and end?
during runtime.
a mount option and mount can race against forks, execs and exits. Also,
IIRC, cgroup2 doesn't allow remounts but there's nothing preventing someone
from unmounting and mounting it again with different options.
You are right. If the thread group leader changes, the task passed toBut the leader can change, right? So, we can end up in a situation whereWhen a non-leader thread in a thread group executes the exec system call,@@ -3010,15 +3008,27 @@ struct task_struct *cgroup_procs_write_start(char *buf, bool threadgroup,I'm not sure this relocation is safe. What prevents e.g. @tsk changing its
*/
if (tsk->no_cgroup_migration || (tsk->flags & PF_NO_SETAFFINITY)) {
tsk = ERR_PTR(-EINVAL);
- goto out_unlock_threadgroup;
+ goto out_unlock_rcu;
}
-
get_task_struct(tsk);
- goto out_unlock_rcu;
-out_unlock_threadgroup:
- cgroup_attach_unlock(*threadgroup_locked);
- *threadgroup_locked = false;
+ rcu_read_unlock();
+
+ /*
+ * If we migrate a single thread, we don't care about threadgroup
+ * stability. If the thread is `current`, it won't exit(2) under our
+ * hands or change PID through exec(2). We exclude
+ * cgroup_update_dfl_csses and other cgroup_{proc,thread}s_write
+ * callers by cgroup_mutex.
+ * Therefore, we can skip the global lock.
+ */
+ lockdep_assert_held(&cgroup_mutex);
+ *threadgroup_locked = pid || threadgroup;
+
+ cgroup_attach_lock(tsk, *threadgroup_locked);
group leader or signal struct before lock is grabbed?
the thread group leader is updated, but the signal_struct remains unchanged,
so this part is safe.
threadgroup is set but the task is not the leader which I think can lead to
really subtle incorrect behaviors like write succeeding but nothing
happening when racing against exec.
Thanks.