Re: [RESEND PATCH v4 08/15] fs/resctrl: Add interface to display supported and active kernel-mode policy

From: Reinette Chatre

Date: Mon Aug 10 2026 - 23:18:59 EST


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)

>
> Signed-off-by: Babu Moger <babu.moger@xxxxxxx>



> +/**
> + * 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.

> + 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?

> + */
> + 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.

> + }
> +
> + ctrl = "";
> + mon = "";
> + if (rdtgrp->type == RDTMON_GROUP) {
> + ctrl = rdt_kn_name(rdtgrp->mon.parent->kn);
> + mon = rdt_kn_name(rdtgrp->kn);
> + } else {
> + ctrl = rdt_kn_name(rdtgrp->kn);
> + }
> + seq_printf(seq, "[%s:group=%s/%s/]\n",
> + resctrl_mode_str[mode], ctrl, mon);
> + }
> +
> +out_unlock:
> + mutex_unlock(&rdtgroup_mutex);
> + return ret;
> +}
> +
> void *rdt_kn_parent_priv(struct kernfs_node *kn)
> {
> /*
> @@ -1915,6 +1999,13 @@ static struct rftype res_common_files[] = {
> .seq_show = rdt_last_cmd_status_show,
> .fflags = RFTYPE_TOP_INFO,
> },
> + {
> + .name = "kernel_mode",
> + .mode = 0444,
> + .kf_ops = &rdtgroup_kf_single_ops,
> + .seq_show = resctrl_kernel_mode_show,
> + .fflags = RFTYPE_TOP_INFO,
> + },
> {
> .name = "mbm_assign_on_mkdir",
> .mode = 0644,

Reinette