Re: [RESEND PATCH v4 08/15] fs/resctrl: Add interface to display supported and active kernel-mode policy
"Moger, Babu" <[email protected]>
| Newsgroups | org.kernel.vger.linux-doc,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
Hi Reinette, On 8/10/2026 10:18 PM, Reinette Chatre wrote: > Hi Babu, > > On 7/7/26 2:50 PM, Babu Moger wrote: >> Kernel-mode resctrl policies define how kernel work is associated with >> resource allocation and monitoring relative to the user task. Generic >> resctrl tracks the supported policies, the active policy, and the resctrl >> group backing any global assignment policy. However, this information is >> not exposed to user space. >> >> Introduce a new resctrl file, info/kernel_mode, to expose the global >> kernel-mode policy and its associated resource group (when applicable). >> This read-only sysfs file lists all supported policies, one per line, and >> highlights the active policy using square brackets. > > (please rewrite with consistent terms) > Sure. >> >> Signed-off-by: Babu Moger <[email protected]> > > > >> +/** >> + * resctrl_kernel_mode_show() - Display supported and active kernel-mode policies >> + * @of: kernfs open file >> + * @seq: output seq_file >> + * @v: unused >> + * >> + * Displays one line per mode set in resctrl_kcfg.kmode. Bracket the active >> + * policy (resctrl_kcfg.kmode_cur). >> + * >> + * INHERIT_CTRL_AND_MON is displayed as "[inherit_ctrl_and_mon]" when active >> + * or "inherit_ctrl_and_mon" when supported but inactive, with no :group= >> + * suffix in either case. >> + * >> + * Global-assign modes append :group=. An inactive mode is emitted as >> + * "<mode>:group=uninitialized". An active mode with a bound group is emitted >> + * as "[<mode>:group=<ctrl>/<mon>/]", where <ctrl>/<mon>/ is derived from >> + * resctrl_kcfg.k_rdtgrp. >> + * >> + * Return: 0 on success, or -ENOENT on error. >> + */ >> +static int resctrl_kernel_mode_show(struct kernfs_open_file *of, >> + struct seq_file *seq, void *v) >> +{ >> + enum resctrl_kernel_mode mode; >> + struct rdtgroup *rdtgrp; >> + const char *ctrl, *mon; >> + bool active; >> + int ret = 0; >> + >> + mutex_lock(&rdtgroup_mutex); > > The changes to make resctrl more robust have since been merged. Please consider: > 2d77f9768850 ("fs/resctrl: Prevent deadlock and use-after-free in info file handlers") > > When you rebase, please use the new info_kn_lock()/info_kn_unlock() helpers. Sure. Will do. > >> + for (mode = 0; mode < RESCTRL_NUM_KERNEL_MODES; mode++) { >> + if (!test_bit(mode, &resctrl_kcfg.kmode)) >> + continue; >> + >> + active = (resctrl_kcfg.kmode_cur == mode); >> + >> + if (mode == INHERIT_CTRL_AND_MON) { >> + seq_printf(seq, active ? "[%s]\n" : "%s\n", >> + resctrl_mode_str[mode]); >> + continue; >> + } >> + >> + if (!active) { >> + seq_printf(seq, "%s:group=uninitialized\n", >> + resctrl_mode_str[mode]); >> + continue; >> + } >> + >> + /* >> + * There should be a valid group when any of the global >> + * assign mode is active; otherwise, report an error. > > This would indicate a resctrl bug, no? Yes. > >> + */ >> + rdtgrp = resctrl_kcfg.k_rdtgrp; >> + if (!rdtgrp) { >> + ret = -ENOENT; >> + goto out_unlock; > > If this fails there needs to be content in last_cmd_status. Otherwise this > fails and then last_cmd_status reads "ok" or worse .. an old failure message. if (WARN_ON(!rdtgrp)) { rdt_last_cmd_puts("Invalid kernel mode group\n"); ret = -ENOENT; goto out_unlock; } Thanks Babu