cgroup: fix cftype->file_offset handling
Tejun Heo
maintainerPATCH 1/1 cgroup: fix cftype->file_offset handling
6f60eade2433 ("cgroup: generalize obtaining the handles of and notifying cgroup files") introduced cftype->file_offset so that the handles for per-css file instances can be recorded. These handles then can be used, for example, to generate file modified notifications.
Unfortunately, it made the wrong assumption that files are created once for a given css and removed on its destruction. Due to the dependencies among subsystems, a css may be hidden from userland and then later shown again. This is implemented by removing and re-creating the affected files, so the associated kernfs_node for a given cgroup file may change over time. This incorrect assumption led to the corruption of css->files lists.
Reimplement cftype->file_offset handling so that cgroup_file->kn is protected by a lock and updated as files are created and destroyed. This also makes keeping them on per-cgroup list unnecessary.
--- include/linux/cgroup-defs.h | 4 ---- include/linux/cgroup.h | 14 +------------- kernel/cgroup.c | 42 ++++++++++++++++++++++++++++++++++-------- 3 files changed, 35 insertions(+), 25 deletions(-)
include/linux/cgroup-defs.h +0 -4
@@ -90,7 +90,6 @@ enum {*/ struct cgroup_file {/* do not access any fields from outside cgroup core */ -struct list_head node;/* anchored at css->files */ struct kernfs_node *kn; };
@@ -134,9 +133,6 @@ struct cgroup_subsys_state {*/ u64 serial_nr; -/* all cgroup_files associated with this css */ -struct list_head files; -/* percpu_ref killing and RCU release */ struct rcu_head rcu_head;struct work_struct destroy_work;
include/linux/cgroup.h +1 -13
@@ -88,6 +88,7 @@ int cgroup_transfer_tasks(struct cgroupint cgroup_add_dfl_cftypes (struct cgroup_subsys *ss,struct cftype *cfts);int cgroup_add_legacy_cftypes (struct cgroup_subsys *ss,struct cftype *cfts);int cgroup_rm_cftypes (struct cftype *cfts); +void cgroup_file_notify (struct cgroup_file *cfile);char *task_cgroup_path (struct task_struct *task,char *buf,size_t buflen);int cgroupstats_build (struct cgroupstats *stats,struct dentry *dentry);
@@ -516,19 +517,6 @@ static inline void pr_cont_cgroup_path(s pr_cont_kernfs_path(cgrp->kn); } -/** -* cgroup_file_notify - generate a file modified event for a cgroup_file -* @cfile: target cgroup_file -* -* @cfile must have been obtained by setting cftype->file_offset. -*/ -static inline void cgroup_file_notify (struct cgroup_file *cfile) -{ -/* might not have been created due to one of the CFTYPE selector flags */ -if (cfile->kn) -kernfs_notify (cfile->kn); -} -#else /* !CONFIG_CGROUPS */ struct cgroup_subsys_state ;
kernel/cgroup.c +34 -8
88 lines not on this page · raw message
Quoted 14 lines · Tejun Heo
6f60eade2433("cgroup: generalize obtaining the handles of and notifying cgroup files") introducedcftype->file_offsetso that the handles for per-css file instances can be recorded. These handles then can be used, for example, to generate file modified notifications.Unfortunately, it made the wrong assumption that files are created once for a given css and removed on its destruction. Due to the dependencies among subsystems, a css may be hidden from userland and then later shown again. This is implemented by removing and re-creating the affected files, so the associated
kernfs_nodefor a given cgroup file may change over time. This incorrect assumption led to the corruption ofcss->fileslists.
Quoted 7 lines
Reimplement
cftype->file_offsethandling so thatcgroup_file->knis protected by a lock and updated as files are created and destroyed. This also makes keeping them on per-cgroup list unnecessary.Signed-off-by Tejun Heo <[email protected]>Reported-by James Sedgwick <[email protected]>Fixes 6f60eade2433 ("cgroup: generalize obtaining the handles of and notifying cgroup files")
Kudos to whoever debugged this.
Quoted 14 lines · Tejun Heo
6f60eade2433("cgroup: generalize obtaining the handles of and notifying cgroup files") introducedcftype->file_offsetso that the handles for per-css file instances can be recorded. These handles then can be used, for example, to generate file modified notifications.Unfortunately, it made the wrong assumption that files are created once for a given css and removed on its destruction. Due to the dependencies among subsystems, a css may be hidden from userland and then later shown again. This is implemented by removing and re-creating the affected files, so the associated
kernfs_nodefor a given cgroup file may change over time. This incorrect assumption led to the corruption ofcss->fileslists.
Quoted 7 lines
Reimplement
cftype->file_offsethandling so thatcgroup_file->knis protected by a lock and updated as files are created and destroyed. This also makes keeping them on per-cgroup list unnecessary.Signed-off-by Tejun Heo <[email protected]>Reported-by James Sedgwick <[email protected]>Fixes 6f60eade2433 ("cgroup: generalize obtaining the handles of and notifying cgroup files")
Quoted 14 lines · Tejun Heo
6f60eade2433("cgroup: generalize obtaining the handles of and notifying cgroup files") introducedcftype->file_offsetso that the handles for per-css file instances can be recorded. These handles then can be used, for example, to generate file modified notifications.Unfortunately, it made the wrong assumption that files are created once for a given css and removed on its destruction. Due to the dependencies among subsystems, a css may be hidden from userland and then later shown again. This is implemented by removing and re-creating the affected files, so the associated
kernfs_nodefor a given cgroup file may change over time. This incorrect assumption led to the corruption ofcss->fileslists.
Quoted 3 lines
Reimplement
cftype->file_offsethandling so thatcgroup_file->knis protected by a lock and updated as files are created and destroyed. This also makes keeping them on per-cgroup list unnecessary.
Applied to cgroup/for-4.4-fixes.
Signature · 1 line
tejun