Re: [RESEND PATCH v4 12/15] fs/resctrl: Hide kmode_cpus[_list] on groups not bound to kernel-mode

From: Reinette Chatre

Date: Mon Aug 10 2026 - 23:31:02 EST


Hi Babu,

On 7/7/26 2:50 PM, Babu Moger wrote:
> kmode_cpus and kmode_cpus_list describe the CPU scope for the rdtgroup that
> owns the active kernel-mode binding. They are meaningful only for
> resctrl_kcfg.k_rdtgrp.
>
> On groups that do not own the kernel-mode binding, they appear as inactive
> stubs and can let user space inspect or update state that does not apply to
> that group.
>
> Hide kmode_cpus and kmode_cpus_list on groups that are not bound to
> kernel-mode. Keep the files hidden when groups are created, show them when
> rdtgroup_config_kmode() binds the group, and hide them again when the
> binding is released.
>
> Signed-off-by: Babu Moger <babu.moger@xxxxxxx>
> ---
> v4: Updated the changelog and code comments.
>
> v3: New patch to hide/show "kmode_cpus" and "kmode_cpus_list" when kernel
> modes binding changes.
> ---
> fs/resctrl/rdtgroup.c | 33 +++++++++++++++++++++++++++++++++
> 1 file changed, 33 insertions(+)
>
> diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
> index 413d3ff14546..c537846d9264 100644
> --- a/fs/resctrl/rdtgroup.c
> +++ b/fs/resctrl/rdtgroup.c
> @@ -1127,6 +1127,35 @@ static int resctrl_kernel_mode_show(struct kernfs_open_file *of,
> return ret;
> }
>
> +/**
> + * resctrl_kmode_files_set_visible() - Toggle visibility of the per-group
> + * kernel-mode CPU files under @rdtgrp.
> + * @rdtgrp: Resctrl group whose "kmode_cpus" / "kmode_cpus_list" files
> + * should be hidden or shown.
> + * @visible: %true to expose the files, %false to hide them via
> + * kernfs_show().
> + *
> + * Each file is resolved independently as a sibling under @rdtgrp->kn.
> + * Failures from kernfs_find_and_get() are deliberately ignored, allowing
> + * callers to invoke this before activation, during group creation, or when
> + * the kernel-mode binding is updated.
> + */
> +static void resctrl_kmode_files_set_visible(struct rdtgroup *rdtgrp, bool visible)
> +{
> + /* Keep in sync with res_common_files[] entries for these files. */
> + static const char * const files[] = { "kmode_cpus", "kmode_cpus_list" };
> + struct kernfs_node *kn;
> + int i;
> +
> + for (i = 0; i < ARRAY_SIZE(files); i++) {
> + kn = kernfs_find_and_get(rdtgrp->kn, files[i]);
> + if (!kn)
> + continue;
> + kernfs_show(kn, visible);
> + kernfs_put(kn);
> + }
> +}
> +
> /**
> * rdtgroup_config_kmode_reset() - Tear down the kernel-mode binding on @rdtgrp
> * @rdtgrp: Resctrl group whose kernel-mode binding is being released.
> @@ -1155,6 +1184,7 @@ static void rdtgroup_config_kmode_reset(struct rdtgroup *rdtgrp,
>
> out_clear:
> cpumask_clear(&rdtgrp->kmode_cpu_mask);
> + resctrl_kmode_files_set_visible(rdtgrp, false);
> rdtgrp->kmode = false;
> }
>
> @@ -3068,6 +3098,7 @@ static int rdt_get_tree(struct fs_context *fc)
> if (ret)
> goto out_closid_exit;
>
> + resctrl_kmode_files_set_visible(&rdtgroup_default, false);
> kernfs_activate(rdtgroup_default.kn);
>
> ret = rdtgroup_create_info_dir(rdtgroup_default.kn);
> @@ -4098,6 +4129,7 @@ static int rdtgroup_mkdir_mon(struct kernfs_node *parent_kn,
> goto out_unlock;
> }
>
> + resctrl_kmode_files_set_visible(rdtgrp, false);
> kernfs_activate(rdtgrp->kn);
>
> /*
> @@ -4142,6 +4174,7 @@ static int rdtgroup_mkdir_ctrl_mon(struct kernfs_node *parent_kn,
> if (ret)
> goto out_closid_free;
>
> + resctrl_kmode_files_set_visible(rdtgrp, false);
> kernfs_activate(rdtgrp->kn);
>
> ret = rdtgroup_init_alloc(rdtgrp);

Sprinkling these resctrl_kmode_files_set_visible() in every path that creates these files
seem error prone. Could this be simplified with a new, for example, rftype::create_hidden that
will instruct the file to be created hidden. This would just create the file correctly from the
beginning and eliminate these calls that go back and "fix things up" for kernel mode use. This may
also eliminate the need to ignore errors in resctrl_kmode_files_set_visible() making this
more robust while making it obvious how the file visibility is actually connected to the
kernel mode since that would be the only points where the file visibility is changed.

Reinette