mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2026-08-14 06:22:34 +02:00
a5b98009f1("sched/psi: fix race between file release and pressure write") made pressure_write() hold cgroup_mutex across psi_trigger_create(), which forks the psimon kthread for the first rtpoll trigger. As kthread creation depends on the whole fork path, the commit inadvertently created a lot of unwanted locking dependencies from cgroup_mutex. sched_ext got hit by one: its enable path blocks forks and then grabs cgroup_mutex, so a pressure write racing a scheduler enable deadlocks, with every other fork piling up behind. Fix it by splitting trigger creation so that the worker is forked with cgroup_mutex dropped and the kernfs active reference left broken. The latter matters because rmdir and cgroup.pressure writes drain active references under cgroup_mutex. Publishing the trigger last keeps error reporting synchronous and preserves the of->priv lifetime rules. The trigger registered in the first stage pins the group's rtpoll machinery across the unlocked window, leaving only creation races to resolve. The catch-up poll on installation covers scheduling attempts dropped while there was no worker. v2: Retagged sched/psi (was cgroup). Fixes:a5b98009f1("sched/psi: fix race between file release and pressure write") Cc: stable@vger.kernel.org Cc: Edward Adam Davis <eadavis@qq.com> Cc: Chen Ridong <chenridong@huaweicloud.com> Reported-by: Matt Fleming <mfleming@cloudflare.com> Closes: https://lore.kernel.org/all/20260710100441.2653477-1-matt@readmodwrite.com/ Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Johannes Weiner <hannes@cmpxchg.org> Tested-by: Matt Fleming <mfleming@cloudflare.com> Acked-by: Suren Baghdasaryan <surenb@google.com>
73 lines
1.9 KiB
C
73 lines
1.9 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef _LINUX_PSI_H
|
|
#define _LINUX_PSI_H
|
|
|
|
#include <linux/jump_label.h>
|
|
#include <linux/psi_types.h>
|
|
#include <linux/sched.h>
|
|
#include <linux/poll.h>
|
|
#include <linux/cgroup-defs.h>
|
|
#include <linux/cgroup.h>
|
|
|
|
struct seq_file;
|
|
struct css_set;
|
|
|
|
#ifdef CONFIG_PSI
|
|
|
|
extern struct static_key_false psi_disabled;
|
|
extern struct psi_group psi_system;
|
|
|
|
void psi_init(void);
|
|
|
|
void psi_memstall_enter(unsigned long *flags);
|
|
void psi_memstall_leave(unsigned long *flags);
|
|
|
|
int psi_show(struct seq_file *s, struct psi_group *group, enum psi_res res);
|
|
struct psi_trigger *psi_trigger_create(struct psi_group *group, char *buf,
|
|
enum psi_res res, struct file *file,
|
|
struct kernfs_open_file *of,
|
|
bool *need_rtpoll_worker);
|
|
int psi_trigger_create_rtpoll_worker(struct psi_group *group);
|
|
void psi_trigger_destroy(struct psi_trigger *t);
|
|
|
|
__poll_t psi_trigger_poll(void **trigger_ptr, struct file *file,
|
|
poll_table *wait);
|
|
|
|
#ifdef CONFIG_CGROUPS
|
|
static inline struct psi_group *cgroup_psi(struct cgroup *cgrp)
|
|
{
|
|
return cgroup_ino(cgrp) == 1 ? &psi_system : cgrp->psi;
|
|
}
|
|
|
|
int psi_cgroup_alloc(struct cgroup *cgrp);
|
|
void psi_cgroup_free(struct cgroup *cgrp);
|
|
void cgroup_move_task(struct task_struct *p, struct css_set *to);
|
|
void psi_cgroup_restart(struct psi_group *group);
|
|
#endif
|
|
|
|
#else /* CONFIG_PSI */
|
|
|
|
static inline void psi_init(void) {}
|
|
|
|
static inline void psi_memstall_enter(unsigned long *flags) {}
|
|
static inline void psi_memstall_leave(unsigned long *flags) {}
|
|
|
|
#ifdef CONFIG_CGROUPS
|
|
static inline int psi_cgroup_alloc(struct cgroup *cgrp)
|
|
{
|
|
return 0;
|
|
}
|
|
static inline void psi_cgroup_free(struct cgroup *cgrp)
|
|
{
|
|
}
|
|
static inline void cgroup_move_task(struct task_struct *p, struct css_set *to)
|
|
{
|
|
rcu_assign_pointer(p->cgroups, to);
|
|
}
|
|
static inline void psi_cgroup_restart(struct psi_group *group) {}
|
|
#endif
|
|
|
|
#endif /* CONFIG_PSI */
|
|
|
|
#endif /* _LINUX_PSI_H */
|