From: Reinette Chatre <reinette.chatre@intel.com>
To: Babu Moger <babu.moger@amd.com>, <tony.luck@intel.com>,
<Dave.Martin@arm.com>, <james.morse@arm.com>, <bp@alien8.de>,
<ben.horgan@arm.com>
Cc: <corbet@lwn.net>, <skhan@linuxfoundation.org>,
<rdunlap@infradead.org>, <tglx@kernel.org>, <mingo@redhat.com>,
<dave.hansen@linux.intel.com>, <hpa@zytor.com>,
<fenghuay@nvidia.com>, <akpm@linux-foundation.org>,
<rppt@kernel.org>, <dapeng1.mi@linux.intel.com>,
<elver@google.com>, <jlayton@kernel.org>,
<enelsonmoore@gmail.com>, <kuba@kernel.org>,
<ebiggers@kernel.org>, <seanjc@google.com>,
<peterz@infradead.org>, <chao.gao@intel.com>,
<jmattson@google.com>, <naveen@kernel.org>,
<ricardo.neri-calderon@linux.intel.com>, <tiala@microsoft.com>,
<chang.seok.bae@intel.com>, <prathyushi.nangia@amd.com>,
<kim.phillips@amd.com>, <elena.reshetova@intel.com>,
<darwi@linutronix.de>, <linux-doc@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <x86@kernel.org>
Subject: Re: [PATCH v5 14/16] fs/resctrl: Add interface to modify kernel mode via info/kernel_mode
Date: Tue, 15 Sep 2026 22:50:06 -0700 [thread overview]
Message-ID: <3bc39dd7-b7b0-4203-a493-0bd872fdc644@intel.com> (raw)
In-Reply-To: <d50aaf18d60787e960b600494d7f33926fb0b51a.1787772750.git.babu.moger@amd.com>
Hi Babu,
On 8/26/26 12:32 PM, Babu Moger wrote:
> ---
> Documentation/filesystems/resctrl.rst | 33 +++
> fs/resctrl/pseudo_lock.c | 5 +
> fs/resctrl/rdtgroup.c | 319 +++++++++++++++++++++++++-
> 3 files changed, 356 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/filesystems/resctrl.rst b/Documentation/filesystems/resctrl.rst
> index c6e8cf828e18..490e8f534d37 100644
> --- a/Documentation/filesystems/resctrl.rst
> +++ b/Documentation/filesystems/resctrl.rst
> @@ -557,6 +557,39 @@ conveyed in the error returns from file operations. E.g.
> [inherit_user]
> assign_global_enable_per_cpu:ctrl=assign;mon=assign;group=//
>
> + Writes use the same line format as read, without square brackets and
> + with a trailing newline. To select inherit_user, write that mode name
> + alone.
> +
> + For assign_global_enable_per_cpu:
> +
> + - Writing the mode name alone selects ctrl=assign, mon=assign, and the
> + default CTRL_MON group.
Please do not commit resctrl to use specific defaults. The documentation can just mention
that read of the file provides the defaults.
> + - ctrl=, mon=, and group= are optional, use the same syntax as on read,
> + and may appear in any order. ctrl= and mon= default to assign;
> + group= defaults to the default CTRL_MON group.
This just repeats previous point?
> + - Empty ctrl=, mon=, or group= values are rejected.
> + - A write with both ctrl=inherit and mon=inherit is a no-op.
... because this assumes there are only two kernel modes that can ever be supported
and the other one must be "inherit_user" and thus providing "inherit" for
these two parameters imply that "inherit_user" kernel mode? Could you *please*
consider other architectures?
> diff --git a/fs/resctrl/pseudo_lock.c b/fs/resctrl/pseudo_lock.c
> index dea2b4bf966f..a0b22b95fc08 100644
> --- a/fs/resctrl/pseudo_lock.c
> +++ b/fs/resctrl/pseudo_lock.c
> @@ -536,6 +536,11 @@ int rdtgroup_locksetup_enter(struct rdtgroup *rdtgrp)
> return -EINVAL;
> }
>
> + if (rdtgrp->kmode) {
> + rdt_last_cmd_puts("Group has an active kernel-mode association\n");
> + return -EINVAL;
> + }
> +
These snippets (also the changes to rdtgroup_mode_write() and rdtgroup_rename()) noting
when it is and is not ok to make other resctrl changes is not related to support for
modifying the kernel mode and should be in a separate patch.
...
> +
> +static int resctrl_kmode_parse_ctrl_mon(char *options, const char *field,
> + enum kmode_state *state)
run checkpatch.pl --strict as part of your patch prep.
> +{
> + char *opt, *val, *end;
> + int ret = 0;
> +
> + opt = strstr(options, field);
> + if (!opt)
> + return 0;
> +
> + val = opt + strlen(field);
> + end = strchr(val, ';');
> + if (end)
> + *end = '\0';
> + if (resctrl_kmode_parse_option(val, state))
> + ret = -EINVAL;
> +
> + if (end)
> + *end = ';';
> + return ret;
> +}
This is an unexpected and new pattern to use a temporary NUL in a buffer
then restore the original character. resctrl has a couple of instances where
options separated with ";" needs to be parsed - many of them written by you!
ctrlmondata.c:parse_line(), ctrlmondata.c:resctrl_io_alloc_parse_line(),
monitor.c:resctrl_parse_mbm_assignment() - why invent a new pattern?
sashiko seems to believe there is a issue here. Some of the other sashiko issues
look real to me. Please consider the sashiko feedback:
https://sashiko.dev/#/patchset/cover.1787772750.git.babu.moger%40amd.com
> +
> +static int resctrl_kmode_parse_group(char *options, struct rdtgroup **rdtgrp)
> +{
> + const char *ctrl_name, *mon_name;
> + char *group_str, *end, *slash;
> + struct rdtgroup *grp;
> + int ret = 0;
> +
> + /* Skip parsing when group= is not present. */
> + group_str = strstr(options, "group=");
> + if (!group_str)
> + return 0;
> +
> + /* Isolate the group= value from any following options. */
> + group_str += strlen("group=");
> + end = strchr(group_str, ';');
> + if (end)
> + *end = '\0';
> + group_str = strim(group_str);
> + if (!*group_str) {
> + rdt_last_cmd_puts("group= requires <CTRL_MON>/<MON>/\n");
> + ret = -EINVAL;
> + goto out_parse;
> + }
> + /* Split <CTRL_MON>/<MON>/ at the first slash. */
> + slash = strchr(group_str, '/');
> + if (!slash) {
> + rdt_last_cmd_puts("Group must be <CTRL_MON>/<MON>/\n");
> + ret = -EINVAL;
> + goto out_parse;
> + }
> + *slash = '\0';
> + ctrl_name = group_str;
> + mon_name = slash + 1;
> + /* Require a trailing slash after the monitor group name. */
> + slash = strchr(mon_name, '/');
> + if (!slash || slash[1] != '\0') {
> + rdt_last_cmd_puts("Group must be <CTRL_MON>/<MON>/\n");
> + ret = -EINVAL;
> + goto out_parse;
> + }
> + *slash = '\0';
> + /* Resolve the path to an existing rdtgroup. */
> + grp = rdtgroup_by_kmode_path(ctrl_name, mon_name);
> + if (!grp) {
> + rdt_last_cmd_puts("Group not found\n");
> + ret = -EINVAL;
> + goto out_parse;
> + }
> + *rdtgrp = grp;
> +
> +out_parse:
> + /* Restore the option string after temporary null termination. */
> + if (end)
> + *end = ';';
same here ... removing characters from buffer and then restoring them is
unexpected.
> + return ret;
> +}
> +
> +/**
> + * resctrl_kernel_mode_write() - Set the active kernel mode policy
> + * @of: kernfs open file
> + * @buf: Write buffer; use the resctrl_kernel_mode_show() line format without
> + * brackets and with a trailing newline
> + * @nbytes: length of @buf
> + * @off: unused
> + *
> + * Parse and validate the request, then update the active kernel mode
> + * association.
> + *
> + * Return: @nbytes on success, negative errno on error.
> + */
> +static ssize_t resctrl_kernel_mode_write(struct kernfs_open_file *of,
> + char *buf, size_t nbytes, loff_t off)
> +{
> + enum kmode_state ctrl_mode = KMODE_ASSIGN, mon_mode = KMODE_ASSIGN;
> + char *mode_str, *options;
> + enum resctrl_kernel_mode mode;
needs reverse fir
> + struct rdtgroup *rdtgrp;
> + int ret = 0;
> +
> + if (!info_kn_lock(of->kn))
> + return -ENOENT;
> +
> + rdt_last_cmd_clear();
> +
> + if (nbytes == 0 || buf[nbytes - 1] != '\n') {
> + rdt_last_cmd_puts("kernel_mode_write: Invalid input\n");
> + ret = -EINVAL;
> + goto out_unlock;
> + }
> + buf[nbytes - 1] = '\0';
> +
> + buf = strim(buf);
> + options = strchr(buf, ':');
> + if (options) {
> + *options = '\0';
> + options++;
> + }
> + mode_str = strim(buf);
> +
> + for (mode = 0; mode < RESCTRL_NUM_KERNEL_MODES; mode++)
> + if (!strcmp(mode_str, resctrl_mode_str[mode]))
> + break;
> +
> + if (mode == RESCTRL_NUM_KERNEL_MODES) {
> + rdt_last_cmd_puts("Unknown kernel mode\n");
> + ret = -EINVAL;
> + goto out_unlock;
> + }
> +
> + if (!test_bit(mode, resctrl_kcfg.caps.kmode_sup)) {
> + rdt_last_cmd_puts("Kernel mode not available\n");
> + ret = -EINVAL;
> + goto out_unlock;
> + }
> +
> + if (mode == RESCTRL_INHERIT_USER) {
> + rdtgrp = NULL;
> + goto update_mode;
> + }
> +
> + rdtgrp = &rdtgroup_default;
> +
> + if (!options)
> + goto validate_kmode;
> +
> + ret = resctrl_kmode_parse_ctrl_mon(options, "ctrl=", &ctrl_mode);
> + if (ret) {
> + rdt_last_cmd_puts("Invalid ctrl= option\n");
> + goto out_unlock;
> + }
> + ret = resctrl_kmode_parse_ctrl_mon(options, "mon=", &mon_mode);
> + if (ret) {
> + rdt_last_cmd_puts("Invalid mon= option\n");
> + goto out_unlock;
> + }
> +
> + ret = resctrl_kmode_parse_group(options, &rdtgrp);
> + if (ret)
> + goto out_unlock;
> +
> + if (ctrl_mode == KMODE_INHERIT && mon_mode == KMODE_INHERIT)
> + goto out_unlock;
> +
> +validate_kmode:
This long function is difficult to follow and this usage of goto is a big
part of making it difficult to understand since it just jumps to the middle
of the function instead of a cleanup label as is custom in the kernel.
Please refactor.
Stopping here. Something is off with this series. It seems to be created
without the learnings and patterns accumulated from your previous resctrl
contributions while also ignoring x86 (and even kernel) customs.
Reinette
next prev parent reply other threads:[~2026-09-16 5:50 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-26 19:32 [PATCH v5 00/16] x86/resctrl: Add kernel-mode (e.g., PLZA) support to the resctrl subsystem Babu Moger
2026-08-26 19:32 ` [PATCH v5 01/16] x86/cpufeatures: Support Privilege Level Zero Association (PLZA) Babu Moger
2026-09-16 5:12 ` Reinette Chatre
2026-09-16 20:45 ` Babu Moger
2026-08-26 19:32 ` [PATCH v5 02/16] x86/resctrl: Add PLZA support to command-line options Babu Moger
2026-09-16 5:12 ` Reinette Chatre
2026-09-16 20:45 ` Babu Moger
2026-08-26 19:32 ` [PATCH v5 03/16] x86/resctrl: Add PLZA configuration definitions and data structures Babu Moger
2026-09-16 5:16 ` Reinette Chatre
2026-09-16 20:53 ` Babu Moger
2026-08-26 19:32 ` [PATCH v5 04/16] fs/resctrl: Introduce kernel mode policy enum Babu Moger
2026-09-16 5:14 ` Reinette Chatre
2026-09-16 20:53 ` Babu Moger
2026-08-26 19:32 ` [PATCH v5 05/16] x86,fs/resctrl: Introduce architecture hooks to program kernel mode Babu Moger
2026-09-16 5:26 ` Reinette Chatre
2026-09-16 20:57 ` Babu Moger
2026-08-26 19:32 ` [PATCH v5 06/16] fs/resctrl: Introduce kernel mode states for resctrl Babu Moger
2026-09-16 5:28 ` Reinette Chatre
2026-08-26 19:32 ` [PATCH v5 07/16] fs/resctrl: Introduce resctrl_set_kmode_support() to register supported modes Babu Moger
2026-09-16 5:29 ` Reinette Chatre
2026-08-26 19:32 ` [PATCH v5 08/16] x86/resctrl: Expose assign_global_enable_per_cpu when PLZA is available Babu Moger
2026-08-26 19:32 ` [PATCH v5 09/16] fs/resctrl: Add interface to display supported and active kernel modes Babu Moger
2026-09-16 5:32 ` Reinette Chatre
2026-08-26 19:32 ` [PATCH v5 10/16] fs/resctrl: Add support for hidden resource group files Babu Moger
2026-09-16 5:33 ` Reinette Chatre
2026-08-26 19:32 ` [PATCH v5 11/16] fs/resctrl: Introduce kmode_cpus/kmode_cpus_list per rdtgroup Babu Moger
2026-09-16 5:34 ` Reinette Chatre
2026-08-26 19:32 ` [PATCH v5 12/16] fs/resctrl: Program kernel mode assignments on CPU hotplug Babu Moger
2026-09-16 5:35 ` Reinette Chatre
2026-08-26 19:32 ` [PATCH v5 13/16] fs/resctrl: Deactivate the kernel mode association when a group is removed Babu Moger
2026-09-16 5:36 ` Reinette Chatre
2026-08-26 19:32 ` [PATCH v5 14/16] fs/resctrl: Add interface to modify kernel mode via info/kernel_mode Babu Moger
2026-09-16 5:50 ` Reinette Chatre [this message]
2026-08-26 19:32 ` [PATCH v5 15/16] fs/resctrl: Allow user space to write kmode_cpus/kmode_cpus_list Babu Moger
2026-08-26 19:32 ` [PATCH v5 16/16] fs/resctrl: Add documentation on kernel_mode with example Babu Moger
2026-09-01 21:14 ` Luck, Tony
2026-09-01 23:28 ` Moger, Babu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3bc39dd7-b7b0-4203-a493-0bd872fdc644@intel.com \
--to=reinette.chatre@intel.com \
--cc=Dave.Martin@arm.com \
--cc=akpm@linux-foundation.org \
--cc=babu.moger@amd.com \
--cc=ben.horgan@arm.com \
--cc=bp@alien8.de \
--cc=chang.seok.bae@intel.com \
--cc=chao.gao@intel.com \
--cc=corbet@lwn.net \
--cc=dapeng1.mi@linux.intel.com \
--cc=darwi@linutronix.de \
--cc=dave.hansen@linux.intel.com \
--cc=ebiggers@kernel.org \
--cc=elena.reshetova@intel.com \
--cc=elver@google.com \
--cc=enelsonmoore@gmail.com \
--cc=fenghuay@nvidia.com \
--cc=hpa@zytor.com \
--cc=james.morse@arm.com \
--cc=jlayton@kernel.org \
--cc=jmattson@google.com \
--cc=kim.phillips@amd.com \
--cc=kuba@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=naveen@kernel.org \
--cc=peterz@infradead.org \
--cc=prathyushi.nangia@amd.com \
--cc=rdunlap@infradead.org \
--cc=ricardo.neri-calderon@linux.intel.com \
--cc=rppt@kernel.org \
--cc=seanjc@google.com \
--cc=skhan@linuxfoundation.org \
--cc=tglx@kernel.org \
--cc=tiala@microsoft.com \
--cc=tony.luck@intel.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®