^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Debug controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * WARNING: This controller is for cgroup core debugging only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Its interfaces are unstable and subject to changes at any time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "cgroup-internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) static struct cgroup_subsys_state *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) debug_css_alloc(struct cgroup_subsys_state *parent_css)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) struct cgroup_subsys_state *css = kzalloc(sizeof(*css), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) if (!css)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) return css;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) static void debug_css_free(struct cgroup_subsys_state *css)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) kfree(css);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * debug_taskcount_read - return the number of tasks in a cgroup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * @cgrp: the cgroup in question
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static u64 debug_taskcount_read(struct cgroup_subsys_state *css,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct cftype *cft)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) return cgroup_task_count(css->cgroup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) static int current_css_set_read(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct kernfs_open_file *of = seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct css_set *cset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct cgroup_subsys *ss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct cgroup_subsys_state *css;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) int i, refcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) if (!cgroup_kn_lock_live(of->kn, false))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) spin_lock_irq(&css_set_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) cset = task_css_set(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) refcnt = refcount_read(&cset->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) seq_printf(seq, "css_set %pK %d", cset, refcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) if (refcnt > cset->nr_tasks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) seq_printf(seq, " +%d", refcnt - cset->nr_tasks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) seq_puts(seq, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * Print the css'es stored in the current css_set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) for_each_subsys(ss, i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) css = cset->subsys[ss->id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) if (!css)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) seq_printf(seq, "%2d: %-4s\t- %p[%d]\n", ss->id, ss->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) css, css->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) spin_unlock_irq(&css_set_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) cgroup_kn_unlock(of->kn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static u64 current_css_set_refcount_read(struct cgroup_subsys_state *css,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct cftype *cft)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) u64 count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) count = refcount_read(&task_css_set(current)->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) static int current_css_set_cg_links_read(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct cgrp_cset_link *link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct css_set *cset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) char *name_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) name_buf = kmalloc(NAME_MAX + 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) if (!name_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) spin_lock_irq(&css_set_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) cset = task_css_set(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) list_for_each_entry(link, &cset->cgrp_links, cgrp_link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) struct cgroup *c = link->cgrp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) cgroup_name(c, name_buf, NAME_MAX + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) seq_printf(seq, "Root %d group %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) c->root->hierarchy_id, name_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) spin_unlock_irq(&css_set_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) kfree(name_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #define MAX_TASKS_SHOWN_PER_CSS 25
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static int cgroup_css_links_read(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) struct cgroup_subsys_state *css = seq_css(seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct cgrp_cset_link *link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) int dead_cnt = 0, extra_refs = 0, threaded_csets = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) spin_lock_irq(&css_set_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) list_for_each_entry(link, &css->cgroup->cset_links, cset_link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) struct css_set *cset = link->cset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct task_struct *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) int refcnt = refcount_read(&cset->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * Print out the proc_cset and threaded_cset relationship
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * and highlight difference between refcount and task_count.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) seq_printf(seq, "css_set %pK", cset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (rcu_dereference_protected(cset->dom_cset, 1) != cset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) threaded_csets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) seq_printf(seq, "=>%pK", cset->dom_cset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if (!list_empty(&cset->threaded_csets)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct css_set *tcset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) int idx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) list_for_each_entry(tcset, &cset->threaded_csets,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) threaded_csets_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) seq_puts(seq, idx ? "," : "<=");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) seq_printf(seq, "%pK", tcset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) idx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) seq_printf(seq, " %d", refcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) if (refcnt - cset->nr_tasks > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) int extra = refcnt - cset->nr_tasks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) seq_printf(seq, " +%d", extra);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) * Take out the one additional reference in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * init_css_set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) if (cset == &init_css_set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) extra--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) extra_refs += extra;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) seq_puts(seq, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) list_for_each_entry(task, &cset->tasks, cg_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) if (count++ <= MAX_TASKS_SHOWN_PER_CSS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) seq_printf(seq, " task %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) task_pid_vnr(task));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) list_for_each_entry(task, &cset->mg_tasks, cg_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) if (count++ <= MAX_TASKS_SHOWN_PER_CSS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) seq_printf(seq, " task %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) task_pid_vnr(task));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) /* show # of overflowed tasks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) if (count > MAX_TASKS_SHOWN_PER_CSS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) seq_printf(seq, " ... (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) count - MAX_TASKS_SHOWN_PER_CSS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) if (cset->dead) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) seq_puts(seq, " [dead]\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) dead_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) WARN_ON(count != cset->nr_tasks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) spin_unlock_irq(&css_set_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if (!dead_cnt && !extra_refs && !threaded_csets)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) seq_puts(seq, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) if (threaded_csets)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) seq_printf(seq, "threaded css_sets = %d\n", threaded_csets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) if (extra_refs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) seq_printf(seq, "extra references = %d\n", extra_refs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (dead_cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) seq_printf(seq, "dead css_sets = %d\n", dead_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static int cgroup_subsys_states_read(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) struct kernfs_open_file *of = seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) struct cgroup *cgrp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) struct cgroup_subsys *ss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) struct cgroup_subsys_state *css;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) char pbuf[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) cgrp = cgroup_kn_lock_live(of->kn, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (!cgrp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) for_each_subsys(ss, i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) css = rcu_dereference_check(cgrp->subsys[ss->id], true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (!css)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) pbuf[0] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /* Show the parent CSS if applicable*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) if (css->parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) snprintf(pbuf, sizeof(pbuf) - 1, " P=%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) css->parent->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) seq_printf(seq, "%2d: %-4s\t- %p[%d] %d%s\n", ss->id, ss->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) css, css->id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) atomic_read(&css->online_cnt), pbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) cgroup_kn_unlock(of->kn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) static void cgroup_masks_read_one(struct seq_file *seq, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) u16 mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) struct cgroup_subsys *ss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) int ssid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) bool first = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) seq_printf(seq, "%-17s: ", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) for_each_subsys(ss, ssid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) if (!(mask & (1 << ssid)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) if (!first)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) seq_puts(seq, ", ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) seq_puts(seq, ss->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) first = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) seq_putc(seq, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) static int cgroup_masks_read(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) struct kernfs_open_file *of = seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) struct cgroup *cgrp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) cgrp = cgroup_kn_lock_live(of->kn, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) if (!cgrp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) cgroup_masks_read_one(seq, "subtree_control", cgrp->subtree_control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) cgroup_masks_read_one(seq, "subtree_ss_mask", cgrp->subtree_ss_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) cgroup_kn_unlock(of->kn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) static u64 releasable_read(struct cgroup_subsys_state *css, struct cftype *cft)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) return (!cgroup_is_populated(css->cgroup) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) !css_has_online_children(&css->cgroup->self));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) static struct cftype debug_legacy_files[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) .name = "taskcount",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) .read_u64 = debug_taskcount_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) .name = "current_css_set",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) .seq_show = current_css_set_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) .flags = CFTYPE_ONLY_ON_ROOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) .name = "current_css_set_refcount",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) .read_u64 = current_css_set_refcount_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) .flags = CFTYPE_ONLY_ON_ROOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) .name = "current_css_set_cg_links",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) .seq_show = current_css_set_cg_links_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) .flags = CFTYPE_ONLY_ON_ROOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) .name = "cgroup_css_links",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) .seq_show = cgroup_css_links_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) .name = "cgroup_subsys_states",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) .seq_show = cgroup_subsys_states_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) .name = "cgroup_masks",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) .seq_show = cgroup_masks_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) .name = "releasable",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) .read_u64 = releasable_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) { } /* terminate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) static struct cftype debug_files[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) .name = "taskcount",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) .read_u64 = debug_taskcount_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) .name = "current_css_set",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) .seq_show = current_css_set_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) .flags = CFTYPE_ONLY_ON_ROOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) .name = "current_css_set_refcount",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) .read_u64 = current_css_set_refcount_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) .flags = CFTYPE_ONLY_ON_ROOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) .name = "current_css_set_cg_links",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) .seq_show = current_css_set_cg_links_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) .flags = CFTYPE_ONLY_ON_ROOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) .name = "css_links",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) .seq_show = cgroup_css_links_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) .name = "csses",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) .seq_show = cgroup_subsys_states_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) .name = "masks",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) .seq_show = cgroup_masks_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) { } /* terminate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) struct cgroup_subsys debug_cgrp_subsys = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) .css_alloc = debug_css_alloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) .css_free = debug_css_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) .legacy_cftypes = debug_legacy_files,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) * On v2, debug is an implicit controller enabled by "cgroup_debug" boot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) * parameter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) void __init enable_debug_cgroup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) debug_cgrp_subsys.dfl_cftypes = debug_files;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) debug_cgrp_subsys.implicit_on_dfl = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) debug_cgrp_subsys.threaded = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }