[PATCH 1/2] x86/resctrl: Add io_alloc_min_cbm_all interface for CBM reset

Aaron Tomlin posted 2 patches 3 months ago
[PATCH 1/2] x86/resctrl: Add io_alloc_min_cbm_all interface for CBM reset
Posted by Aaron Tomlin 3 months ago
This patch introduces the new resctrl interface file "io_alloc_min_cbm_all"
to provide users with a clean mechanism to reset all I/O allocation CBMs
(Cache-Block Masks) to their minimum configuration.

Writing '0' to this file triggers the logic to set each corresponding CBM
to the minimum number of consecutive bits (effectively clearing them to 0
or their smallest supported mask). This simplifies the process of clearing
or resetting the I/O allocation state without requiring manual CBM string
calculations and eliminating the need for multiple writes to "io_alloc_cbm".

Signed-off-by: Aaron Tomlin <atomlin@atomlin.com>
---
 Documentation/filesystems/resctrl.rst     |  13 +++
 arch/x86/kernel/cpu/resctrl/core.c        |   2 +-
 arch/x86/kernel/cpu/resctrl/ctrlmondata.c |  23 +++--
 fs/resctrl/ctrlmondata.c                  | 117 ++++++++++++++++++----
 fs/resctrl/internal.h                     |   3 +
 fs/resctrl/rdtgroup.c                     |  10 +-
 include/linux/resctrl.h                   |  30 +++++-
 7 files changed, 165 insertions(+), 33 deletions(-)

diff --git a/Documentation/filesystems/resctrl.rst b/Documentation/filesystems/resctrl.rst
index ccc425b65b27..9899bc716459 100644
--- a/Documentation/filesystems/resctrl.rst
+++ b/Documentation/filesystems/resctrl.rst
@@ -213,6 +213,19 @@ related to allocation:
 		written to /sys/fs/resctrl/info/L3DATA/io_alloc_cbm may be reflected by
 		/sys/fs/resctrl/info/L3CODE/io_alloc_cbm and vice versa.
 
+"io_alloc_min_cbm_all":
+		Set each CBM to their minimum number of consecutive bits.
+
+		Example::
+
+			# cat /sys/fs/resctrl/info/L3/io_alloc_cbm
+			0=ffff;1=00ff
+
+			# echo 0 > /sys/fs/resctrl/info/L3/io_alloc_min_cbm_all
+
+			# cat /sys/fs/resctrl/info/L3/io_alloc_cbm
+			0=0;1=0
+
 Memory bandwidth(MB) subdirectory contains the following files
 with respect to allocation:
 
diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c
index 3792ab4819dc..44aea6b534e0 100644
--- a/arch/x86/kernel/cpu/resctrl/core.c
+++ b/arch/x86/kernel/cpu/resctrl/core.c
@@ -276,7 +276,7 @@ static void rdt_get_cdp_config(int level)
 
 static void rdt_set_io_alloc_capable(struct rdt_resource *r)
 {
-	r->cache.io_alloc_capable = true;
+	r->cache.io_alloc.io_alloc_capable = true;
 }
 
 static void rdt_get_cdp_l3_config(void)
diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
index b20e705606b8..0f051d848422 100644
--- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
+++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
@@ -57,14 +57,19 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid)
 		hw_dom = resctrl_to_arch_ctrl_dom(d);
 		msr_param.res = NULL;
 		for (t = 0; t < CDP_NUM_TYPES; t++) {
-			cfg = &hw_dom->d_resctrl.staged_config[t];
-			if (!cfg->have_new_ctrl)
-				continue;
-
-			idx = resctrl_get_config_index(closid, t);
-			if (cfg->new_ctrl == hw_dom->ctrl_val[idx])
-				continue;
-			hw_dom->ctrl_val[idx] = cfg->new_ctrl;
+			if (resctrl_should_io_alloc_min_cbm(r)) {
+				idx = resctrl_get_config_index(closid, t);
+				hw_dom->ctrl_val[idx] = apply_io_alloc_min_cbm(r);
+			} else {
+				cfg = &hw_dom->d_resctrl.staged_config[t];
+				if (!cfg->have_new_ctrl)
+					continue;
+
+				idx = resctrl_get_config_index(closid, t);
+				if (cfg->new_ctrl == hw_dom->ctrl_val[idx])
+					continue;
+				hw_dom->ctrl_val[idx] = cfg->new_ctrl;
+			}
 
 			if (!msr_param.res) {
 				msr_param.low = idx;
@@ -123,7 +128,7 @@ int resctrl_arch_io_alloc_enable(struct rdt_resource *r, bool enable)
 {
 	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
 
-	if (hw_res->r_resctrl.cache.io_alloc_capable &&
+	if (hw_res->r_resctrl.cache.io_alloc.io_alloc_capable &&
 	    hw_res->sdciae_enabled != enable) {
 		_resctrl_sdciae_enable(r, enable);
 		hw_res->sdciae_enabled = enable;
diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c
index b2d178d3556e..6cbf4cfaf974 100644
--- a/fs/resctrl/ctrlmondata.c
+++ b/fs/resctrl/ctrlmondata.c
@@ -688,7 +688,7 @@ int resctrl_io_alloc_show(struct kernfs_open_file *of, struct seq_file *seq, voi
 
 	mutex_lock(&rdtgroup_mutex);
 
-	if (r->cache.io_alloc_capable) {
+	if (r->cache.io_alloc.io_alloc_capable) {
 		if (resctrl_arch_get_io_alloc_enabled(r))
 			seq_puts(seq, "enabled\n");
 		else
@@ -758,6 +758,50 @@ u32 resctrl_io_alloc_closid(struct rdt_resource *r)
 		return resctrl_arch_get_num_closid(r) - 1;
 }
 
+/*
+ * check_io_alloc_support() - Establish if io_alloc is supported
+ *
+ * @s: resctrl resource schema.
+ *
+ * This function must be called under the cpu hotplug lock
+ * and rdtgroup mutex
+ *
+ * Return: 0 on success, negative error code otherwise.
+ */
+static int check_io_alloc_support(struct resctrl_schema *s)
+{
+	struct rdt_resource *r = s->res;
+
+	if (!r->cache.io_alloc.io_alloc_capable) {
+		rdt_last_cmd_printf("io_alloc is not supported on %s\n", s->name);
+		return -ENODEV;
+	}
+
+	return 0;
+}
+
+/*
+ * check_io_alloc_enabled() - Establish if io_alloc is enabled
+ *
+ * @s: resctrl resource schema
+ *
+ * This function must be called under the cpu hotplug lock
+ * and rdtgroup mutex
+ *
+ * Return: 0 on success, negative error code otherwise.
+ */
+static int check_io_alloc_enabled(struct resctrl_schema *s)
+{
+	struct rdt_resource *r = s->res;
+
+	if (!resctrl_arch_get_io_alloc_enabled(r)) {
+		rdt_last_cmd_printf("io_alloc is not enabled on %s\n", s->name);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 ssize_t resctrl_io_alloc_write(struct kernfs_open_file *of, char *buf,
 			       size_t nbytes, loff_t off)
 {
@@ -777,11 +821,9 @@ ssize_t resctrl_io_alloc_write(struct kernfs_open_file *of, char *buf,
 
 	rdt_last_cmd_clear();
 
-	if (!r->cache.io_alloc_capable) {
-		rdt_last_cmd_printf("io_alloc is not supported on %s\n", s->name);
-		ret = -ENODEV;
+	ret = check_io_alloc_support(s);
+	if (ret)
 		goto out_unlock;
-	}
 
 	/* If the feature is already up to date, no action is needed. */
 	if (resctrl_arch_get_io_alloc_enabled(r) == enable)
@@ -828,6 +870,47 @@ ssize_t resctrl_io_alloc_write(struct kernfs_open_file *of, char *buf,
 	return ret ?: nbytes;
 }
 
+ssize_t resctrl_io_alloc_cbm_min_write(struct kernfs_open_file *of, char *buf,
+				       size_t nbytes, loff_t off)
+{
+	struct resctrl_schema *s = rdt_kn_parent_priv(of->kn);
+	struct rdt_resource *r = s->res;
+	bool reset;
+	u32 io_alloc_closid;
+	int ret;
+
+	ret = kstrtobool(buf, &reset);
+	if (ret)
+		return ret;
+	if (reset)
+		return -EINVAL;
+
+	cpus_read_lock();
+	mutex_lock(&rdtgroup_mutex);
+
+	rdt_last_cmd_clear();
+
+	ret = check_io_alloc_support(s);
+	if (ret)
+		goto out_unlock;
+
+	ret = check_io_alloc_enabled(s);
+	if (ret)
+		goto out_unlock;
+
+	r->cache.io_alloc.io_alloc_min_cbm = true;
+
+	io_alloc_closid = resctrl_io_alloc_closid(r);
+	ret = resctrl_arch_update_domains(r, io_alloc_closid);
+
+	r->cache.io_alloc.io_alloc_min_cbm = false;
+out_unlock:
+	mutex_unlock(&rdtgroup_mutex);
+	cpus_read_unlock();
+
+	return ret ?: nbytes;
+}
+
 int resctrl_io_alloc_cbm_show(struct kernfs_open_file *of, struct seq_file *seq, void *v)
 {
 	struct resctrl_schema *s = rdt_kn_parent_priv(of->kn);
@@ -839,17 +922,13 @@ int resctrl_io_alloc_cbm_show(struct kernfs_open_file *of, struct seq_file *seq,
 
 	rdt_last_cmd_clear();
 
-	if (!r->cache.io_alloc_capable) {
-		rdt_last_cmd_printf("io_alloc is not supported on %s\n", s->name);
-		ret = -ENODEV;
+	ret = check_io_alloc_support(s);
+	if (ret)
 		goto out_unlock;
-	}
 
-	if (!resctrl_arch_get_io_alloc_enabled(r)) {
-		rdt_last_cmd_printf("io_alloc is not enabled on %s\n", s->name);
-		ret = -EINVAL;
+	ret = check_io_alloc_enabled(s);
+	if (ret)
 		goto out_unlock;
-	}
 
 	/*
 	 * When CDP is enabled, the CBMs of the highest CLOSID of CDP_CODE and
@@ -928,17 +1007,13 @@ ssize_t resctrl_io_alloc_cbm_write(struct kernfs_open_file *of, char *buf,
 	mutex_lock(&rdtgroup_mutex);
 	rdt_last_cmd_clear();
 
-	if (!r->cache.io_alloc_capable) {
-		rdt_last_cmd_printf("io_alloc is not supported on %s\n", s->name);
-		ret = -ENODEV;
+	ret = check_io_alloc_support(s);
+	if (ret)
 		goto out_unlock;
-	}
 
-	if (!resctrl_arch_get_io_alloc_enabled(r)) {
-		rdt_last_cmd_printf("io_alloc is not enabled on %s\n", s->name);
-		ret = -EINVAL;
+	ret = check_io_alloc_enabled(s);
+	if (ret)
 		goto out_unlock;
-	}
 
 	io_alloc_closid = resctrl_io_alloc_closid(r);
 
diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h
index bff4a54ae333..f50f1ab562b0 100644
--- a/fs/resctrl/internal.h
+++ b/fs/resctrl/internal.h
@@ -442,6 +442,9 @@ int resctrl_io_alloc_cbm_show(struct kernfs_open_file *of, struct seq_file *seq,
 			      void *v);
 ssize_t resctrl_io_alloc_cbm_write(struct kernfs_open_file *of, char *buf,
 				   size_t nbytes, loff_t off);
+ssize_t resctrl_io_alloc_cbm_min_write(struct kernfs_open_file *of, char *buf,
+				       size_t nbytes, loff_t off);
+
 u32 resctrl_io_alloc_closid(struct rdt_resource *r);
 
 #ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK
diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index ea320dcf8aba..bd41ab5a8eb4 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -1995,6 +1995,12 @@ static struct rftype res_common_files[] = {
 		.seq_show	= resctrl_io_alloc_cbm_show,
 		.write		= resctrl_io_alloc_cbm_write,
 	},
+	{
+		.name		= "io_alloc_min_cbm_all",
+		.mode		= 0644,
+		.kf_ops		= &rdtgroup_kf_single_ops,
+		.write		= resctrl_io_alloc_cbm_min_write,
+	},
 	{
 		.name		= "max_threshold_occupancy",
 		.mode		= 0644,
@@ -2195,11 +2201,13 @@ static void io_alloc_init(void)
 {
 	struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
 
-	if (r->cache.io_alloc_capable) {
+	if (r->cache.io_alloc.io_alloc_capable) {
 		resctrl_file_fflags_init("io_alloc", RFTYPE_CTRL_INFO |
 					 RFTYPE_RES_CACHE);
 		resctrl_file_fflags_init("io_alloc_cbm",
 					 RFTYPE_CTRL_INFO | RFTYPE_RES_CACHE);
+		resctrl_file_fflags_init("io_alloc_min_cbm_all",
+					 RFTYPE_CTRL_INFO | RFTYPE_RES_CACHE);
 	}
 }
 
diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
index 54701668b3df..7987d458ebf8 100644
--- a/include/linux/resctrl.h
+++ b/include/linux/resctrl.h
@@ -215,7 +215,10 @@ struct resctrl_cache {
 	unsigned int	shareable_bits;
 	bool		arch_has_sparse_bitmasks;
 	bool		arch_has_per_cpu_cfg;
-	bool		io_alloc_capable;
+	struct {
+		bool	io_alloc_capable;
+		bool	io_alloc_min_cbm;
+	} io_alloc;
 };
 
 /**
@@ -415,6 +418,31 @@ static inline bool resctrl_is_mbm_event(enum resctrl_event_id eventid)
 		eventid <= QOS_L3_MBM_LOCAL_EVENT_ID);
 }
 
+/*
+ * apply_io_alloc_min_cbm() - Apply minimum io_alloc CBM
+ *
+ * @r: resctrl resource
+ *
+ * Return: Minimum number of consecutive io_alloc CBM bits to be set.
+ */
+static inline u32 apply_io_alloc_min_cbm(struct rdt_resource *r)
+{
+	return r->cache.min_cbm_bits;
+}
+
+/*
+ * resctrl_should_io_alloc_min_cbm() - Should the minimum io_alloc
+ *				       CBM be applied
+ * @r: resctrl resource
+ *
+ * Return: True if the minimum number of consecutive
+ * bits to be set in the io_alloc CBM should be applied.
+ */
+static inline bool resctrl_should_io_alloc_min_cbm(struct rdt_resource *r)
+{
+	return r->cache.io_alloc.io_alloc_min_cbm;
+}
+
 u32 resctrl_get_mon_evt_cfg(enum resctrl_event_id eventid);
 
 /* Iterate over all memory bandwidth events */
-- 
2.51.0
Re: [PATCH 1/2] x86/resctrl: Add io_alloc_min_cbm_all interface for CBM reset
Posted by Moger, Babu 3 months ago
Hi Aaron,

Thanks for trying the patches.

On 11/6/2025 7:24 PM, Aaron Tomlin wrote:
> This patch introduces the new resctrl interface file "io_alloc_min_cbm_all"
> to provide users with a clean mechanism to reset all I/O allocation CBMs
> (Cache-Block Masks) to their minimum configuration.
> 
> Writing '0' to this file triggers the logic to set each corresponding CBM
> to the minimum number of consecutive bits (effectively clearing them to 0
> or their smallest supported mask). This simplifies the process of clearing
> or resetting the I/O allocation state without requiring manual CBM string
> calculations and eliminating the need for multiple writes to "io_alloc_cbm".

Your patch replaces the need for

[1] # echo "0=0;1=0" > /sys/fs/resctrl/info/L3/io_alloc_cbm

Instead it does

[2] # echo 0 > /sys/fs/resctrl/info/L3/io_alloc_min_cbm_all

Both approaches involve a single system call, with no multiple writes in 
either case.

I don’t see a strong justification for keeping both options. Option [1] 
is consistent with the existing interfaces and is also efficient, so I 
don’t see the need for an additional mechanism.


> 
> Signed-off-by: Aaron Tomlin <atomlin@atomlin.com>
> ---
>   Documentation/filesystems/resctrl.rst     |  13 +++
>   arch/x86/kernel/cpu/resctrl/core.c        |   2 +-
>   arch/x86/kernel/cpu/resctrl/ctrlmondata.c |  23 +++--
>   fs/resctrl/ctrlmondata.c                  | 117 ++++++++++++++++++----
>   fs/resctrl/internal.h                     |   3 +
>   fs/resctrl/rdtgroup.c                     |  10 +-
>   include/linux/resctrl.h                   |  30 +++++-
>   7 files changed, 165 insertions(+), 33 deletions(-)
> 
> diff --git a/Documentation/filesystems/resctrl.rst b/Documentation/filesystems/resctrl.rst
> index ccc425b65b27..9899bc716459 100644
> --- a/Documentation/filesystems/resctrl.rst
> +++ b/Documentation/filesystems/resctrl.rst
> @@ -213,6 +213,19 @@ related to allocation:
>   		written to /sys/fs/resctrl/info/L3DATA/io_alloc_cbm may be reflected by
>   		/sys/fs/resctrl/info/L3CODE/io_alloc_cbm and vice versa.
>   
> +"io_alloc_min_cbm_all":
> +		Set each CBM to their minimum number of consecutive bits.
> +
> +		Example::
> +
> +			# cat /sys/fs/resctrl/info/L3/io_alloc_cbm
> +			0=ffff;1=00ff
> +
> +			# echo 0 > /sys/fs/resctrl/info/L3/io_alloc_min_cbm_all
> +
> +			# cat /sys/fs/resctrl/info/L3/io_alloc_cbm
> +			0=0;1=0
> +
>   Memory bandwidth(MB) subdirectory contains the following files
>   with respect to allocation:
>   
> diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c
> index 3792ab4819dc..44aea6b534e0 100644
> --- a/arch/x86/kernel/cpu/resctrl/core.c
> +++ b/arch/x86/kernel/cpu/resctrl/core.c
> @@ -276,7 +276,7 @@ static void rdt_get_cdp_config(int level)
>   
>   static void rdt_set_io_alloc_capable(struct rdt_resource *r)
>   {
> -	r->cache.io_alloc_capable = true;
> +	r->cache.io_alloc.io_alloc_capable = true;
>   }
>   
>   static void rdt_get_cdp_l3_config(void)
> diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
> index b20e705606b8..0f051d848422 100644
> --- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
> +++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
> @@ -57,14 +57,19 @@ int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid)
>   		hw_dom = resctrl_to_arch_ctrl_dom(d);
>   		msr_param.res = NULL;
>   		for (t = 0; t < CDP_NUM_TYPES; t++) {
> -			cfg = &hw_dom->d_resctrl.staged_config[t];
> -			if (!cfg->have_new_ctrl)
> -				continue;
> -
> -			idx = resctrl_get_config_index(closid, t);
> -			if (cfg->new_ctrl == hw_dom->ctrl_val[idx])
> -				continue;
> -			hw_dom->ctrl_val[idx] = cfg->new_ctrl;
> +			if (resctrl_should_io_alloc_min_cbm(r)) {
> +				idx = resctrl_get_config_index(closid, t);
> +				hw_dom->ctrl_val[idx] = apply_io_alloc_min_cbm(r);
> +			} else {
> +				cfg = &hw_dom->d_resctrl.staged_config[t];
> +				if (!cfg->have_new_ctrl)
> +					continue;
> +
> +				idx = resctrl_get_config_index(closid, t);
> +				if (cfg->new_ctrl == hw_dom->ctrl_val[idx])
> +					continue;
> +				hw_dom->ctrl_val[idx] = cfg->new_ctrl;
> +			}
>   
>   			if (!msr_param.res) {
>   				msr_param.low = idx;
> @@ -123,7 +128,7 @@ int resctrl_arch_io_alloc_enable(struct rdt_resource *r, bool enable)
>   {
>   	struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r);
>   
> -	if (hw_res->r_resctrl.cache.io_alloc_capable &&
> +	if (hw_res->r_resctrl.cache.io_alloc.io_alloc_capable &&
>   	    hw_res->sdciae_enabled != enable) {
>   		_resctrl_sdciae_enable(r, enable);
>   		hw_res->sdciae_enabled = enable;
> diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c
> index b2d178d3556e..6cbf4cfaf974 100644
> --- a/fs/resctrl/ctrlmondata.c
> +++ b/fs/resctrl/ctrlmondata.c
> @@ -688,7 +688,7 @@ int resctrl_io_alloc_show(struct kernfs_open_file *of, struct seq_file *seq, voi
>   
>   	mutex_lock(&rdtgroup_mutex);
>   
> -	if (r->cache.io_alloc_capable) {
> +	if (r->cache.io_alloc.io_alloc_capable) {
>   		if (resctrl_arch_get_io_alloc_enabled(r))
>   			seq_puts(seq, "enabled\n");
>   		else
> @@ -758,6 +758,50 @@ u32 resctrl_io_alloc_closid(struct rdt_resource *r)
>   		return resctrl_arch_get_num_closid(r) - 1;
>   }
>   
> +/*
> + * check_io_alloc_support() - Establish if io_alloc is supported
> + *
> + * @s: resctrl resource schema.
> + *
> + * This function must be called under the cpu hotplug lock
> + * and rdtgroup mutex
> + *
> + * Return: 0 on success, negative error code otherwise.
> + */
> +static int check_io_alloc_support(struct resctrl_schema *s)
> +{
> +	struct rdt_resource *r = s->res;
> +
> +	if (!r->cache.io_alloc.io_alloc_capable) {
> +		rdt_last_cmd_printf("io_alloc is not supported on %s\n", s->name);
> +		return -ENODEV;
> +	}
> +
> +	return 0;
> +}
> +
> +/*
> + * check_io_alloc_enabled() - Establish if io_alloc is enabled
> + *
> + * @s: resctrl resource schema
> + *
> + * This function must be called under the cpu hotplug lock
> + * and rdtgroup mutex
> + *
> + * Return: 0 on success, negative error code otherwise.
> + */
> +static int check_io_alloc_enabled(struct resctrl_schema *s)
> +{
> +	struct rdt_resource *r = s->res;
> +
> +	if (!resctrl_arch_get_io_alloc_enabled(r)) {
> +		rdt_last_cmd_printf("io_alloc is not enabled on %s\n", s->name);
> +		return -EINVAL;
> +	}
> +
> +	return 0;
> +}
> +
>   ssize_t resctrl_io_alloc_write(struct kernfs_open_file *of, char *buf,
>   			       size_t nbytes, loff_t off)
>   {
> @@ -777,11 +821,9 @@ ssize_t resctrl_io_alloc_write(struct kernfs_open_file *of, char *buf,
>   
>   	rdt_last_cmd_clear();
>   
> -	if (!r->cache.io_alloc_capable) {
> -		rdt_last_cmd_printf("io_alloc is not supported on %s\n", s->name);
> -		ret = -ENODEV;
> +	ret = check_io_alloc_support(s);
> +	if (ret)
>   		goto out_unlock;
> -	}
>   
>   	/* If the feature is already up to date, no action is needed. */
>   	if (resctrl_arch_get_io_alloc_enabled(r) == enable)
> @@ -828,6 +870,47 @@ ssize_t resctrl_io_alloc_write(struct kernfs_open_file *of, char *buf,
>   	return ret ?: nbytes;
>   }
>   
> +ssize_t resctrl_io_alloc_cbm_min_write(struct kernfs_open_file *of, char *buf,
> +				       size_t nbytes, loff_t off)
> +{
> +	struct resctrl_schema *s = rdt_kn_parent_priv(of->kn);
> +	struct rdt_resource *r = s->res;
> +	bool reset;
> +	u32 io_alloc_closid;
> +	int ret;
> +
> +	ret = kstrtobool(buf, &reset);
> +	if (ret)
> +		return ret;
> +	if (reset)
> +		return -EINVAL;
> +
> +	cpus_read_lock();
> +	mutex_lock(&rdtgroup_mutex);
> +
> +	rdt_last_cmd_clear();
> +
> +	ret = check_io_alloc_support(s);
> +	if (ret)
> +		goto out_unlock;
> +
> +	ret = check_io_alloc_enabled(s);
> +	if (ret)
> +		goto out_unlock;
> +
> +	r->cache.io_alloc.io_alloc_min_cbm = true;
> +
> +	io_alloc_closid = resctrl_io_alloc_closid(r);
> +	ret = resctrl_arch_update_domains(r, io_alloc_closid);
> +
> +	r->cache.io_alloc.io_alloc_min_cbm = false;
> +out_unlock:
> +	mutex_unlock(&rdtgroup_mutex);
> +	cpus_read_unlock();
> +
> +	return ret ?: nbytes;
> +}
> +
>   int resctrl_io_alloc_cbm_show(struct kernfs_open_file *of, struct seq_file *seq, void *v)
>   {
>   	struct resctrl_schema *s = rdt_kn_parent_priv(of->kn);
> @@ -839,17 +922,13 @@ int resctrl_io_alloc_cbm_show(struct kernfs_open_file *of, struct seq_file *seq,
>   
>   	rdt_last_cmd_clear();
>   
> -	if (!r->cache.io_alloc_capable) {
> -		rdt_last_cmd_printf("io_alloc is not supported on %s\n", s->name);
> -		ret = -ENODEV;
> +	ret = check_io_alloc_support(s);
> +	if (ret)
>   		goto out_unlock;
> -	}
>   
> -	if (!resctrl_arch_get_io_alloc_enabled(r)) {
> -		rdt_last_cmd_printf("io_alloc is not enabled on %s\n", s->name);
> -		ret = -EINVAL;
> +	ret = check_io_alloc_enabled(s);
> +	if (ret)
>   		goto out_unlock;
> -	}
>   
>   	/*
>   	 * When CDP is enabled, the CBMs of the highest CLOSID of CDP_CODE and
> @@ -928,17 +1007,13 @@ ssize_t resctrl_io_alloc_cbm_write(struct kernfs_open_file *of, char *buf,
>   	mutex_lock(&rdtgroup_mutex);
>   	rdt_last_cmd_clear();
>   
> -	if (!r->cache.io_alloc_capable) {
> -		rdt_last_cmd_printf("io_alloc is not supported on %s\n", s->name);
> -		ret = -ENODEV;
> +	ret = check_io_alloc_support(s);
> +	if (ret)
>   		goto out_unlock;
> -	}
>   
> -	if (!resctrl_arch_get_io_alloc_enabled(r)) {
> -		rdt_last_cmd_printf("io_alloc is not enabled on %s\n", s->name);
> -		ret = -EINVAL;
> +	ret = check_io_alloc_enabled(s);
> +	if (ret)
>   		goto out_unlock;
> -	}
>   
>   	io_alloc_closid = resctrl_io_alloc_closid(r);
>   
> diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h
> index bff4a54ae333..f50f1ab562b0 100644
> --- a/fs/resctrl/internal.h
> +++ b/fs/resctrl/internal.h
> @@ -442,6 +442,9 @@ int resctrl_io_alloc_cbm_show(struct kernfs_open_file *of, struct seq_file *seq,
>   			      void *v);
>   ssize_t resctrl_io_alloc_cbm_write(struct kernfs_open_file *of, char *buf,
>   				   size_t nbytes, loff_t off);
> +ssize_t resctrl_io_alloc_cbm_min_write(struct kernfs_open_file *of, char *buf,
> +				       size_t nbytes, loff_t off);
> +
>   u32 resctrl_io_alloc_closid(struct rdt_resource *r);
>   
>   #ifdef CONFIG_RESCTRL_FS_PSEUDO_LOCK
> diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
> index ea320dcf8aba..bd41ab5a8eb4 100644
> --- a/fs/resctrl/rdtgroup.c
> +++ b/fs/resctrl/rdtgroup.c
> @@ -1995,6 +1995,12 @@ static struct rftype res_common_files[] = {
>   		.seq_show	= resctrl_io_alloc_cbm_show,
>   		.write		= resctrl_io_alloc_cbm_write,
>   	},
> +	{
> +		.name		= "io_alloc_min_cbm_all",
> +		.mode		= 0644,
> +		.kf_ops		= &rdtgroup_kf_single_ops,
> +		.write		= resctrl_io_alloc_cbm_min_write,
> +	},
>   	{
>   		.name		= "max_threshold_occupancy",
>   		.mode		= 0644,
> @@ -2195,11 +2201,13 @@ static void io_alloc_init(void)
>   {
>   	struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
>   
> -	if (r->cache.io_alloc_capable) {
> +	if (r->cache.io_alloc.io_alloc_capable) {
>   		resctrl_file_fflags_init("io_alloc", RFTYPE_CTRL_INFO |
>   					 RFTYPE_RES_CACHE);
>   		resctrl_file_fflags_init("io_alloc_cbm",
>   					 RFTYPE_CTRL_INFO | RFTYPE_RES_CACHE);
> +		resctrl_file_fflags_init("io_alloc_min_cbm_all",
> +					 RFTYPE_CTRL_INFO | RFTYPE_RES_CACHE);
>   	}
>   }
>   
> diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
> index 54701668b3df..7987d458ebf8 100644
> --- a/include/linux/resctrl.h
> +++ b/include/linux/resctrl.h
> @@ -215,7 +215,10 @@ struct resctrl_cache {
>   	unsigned int	shareable_bits;
>   	bool		arch_has_sparse_bitmasks;
>   	bool		arch_has_per_cpu_cfg;
> -	bool		io_alloc_capable;
> +	struct {
> +		bool	io_alloc_capable;
> +		bool	io_alloc_min_cbm;
> +	} io_alloc;
>   };
>   
>   /**
> @@ -415,6 +418,31 @@ static inline bool resctrl_is_mbm_event(enum resctrl_event_id eventid)
>   		eventid <= QOS_L3_MBM_LOCAL_EVENT_ID);
>   }
>   
> +/*
> + * apply_io_alloc_min_cbm() - Apply minimum io_alloc CBM
> + *
> + * @r: resctrl resource
> + *
> + * Return: Minimum number of consecutive io_alloc CBM bits to be set.
> + */
> +static inline u32 apply_io_alloc_min_cbm(struct rdt_resource *r)
> +{
> +	return r->cache.min_cbm_bits;
> +}
> +
> +/*
> + * resctrl_should_io_alloc_min_cbm() - Should the minimum io_alloc
> + *				       CBM be applied
> + * @r: resctrl resource
> + *
> + * Return: True if the minimum number of consecutive
> + * bits to be set in the io_alloc CBM should be applied.
> + */
> +static inline bool resctrl_should_io_alloc_min_cbm(struct rdt_resource *r)
> +{
> +	return r->cache.io_alloc.io_alloc_min_cbm;
> +}
> +
>   u32 resctrl_get_mon_evt_cfg(enum resctrl_event_id eventid);
>   
>   /* Iterate over all memory bandwidth events */

Re: [PATCH 1/2] x86/resctrl: Add io_alloc_min_cbm_all interface for CBM reset
Posted by Aaron Tomlin 3 months ago
On Fri, Nov 07, 2025 at 04:02:39PM -0600, Moger, Babu wrote:
> Hi Aaron,
> 
> Thanks for trying the patches.

Hi Babu,

Thank you very much for taking the time to review the patch and for
pointing out the efficiency of the existing interface. You are correct that
option [1], echo "0=0;1=0" > io_alloc_cbm, is also accomplished with a
single system call.

However, the primary justification for introducing "io_alloc_min_cbm_all"
lies in abstraction and the knowledge burden placed upon the user, not the
system call count.

To successfully execute option [1], the user is required to have advanced
knowledge of the system's current cache topology and capabilities:

    Domain ID Knowledge: The user must know every active Domain ID (e.g.,
                         0, 1, 2, etc.) that supports the resource and
                         manually enumerate them in the write string. If a
                         domain is missed, it will not be reset.

    Minimal CBM Knowledge: The user must know the minimal supported number
                           of consecutive bits that constitute a "cleared"
                           state for each domain. While this is often 0,
                           relying on this is not architecture-aware.

The new interface, is designed to abstract this complexity entirely. Also,
applies the hardware's guaranteed minimum supported CBM (based on
r->cache.min_cbm_bits) to each domain automatically.

This unified approach provides a robust and efficient mechanism to
guarantee a full, architecture-aware reset across all domains, eliminating
the need for userspace to parse the topology and construct a complex,
domain-specific input string.

Please let me know if this clarifies the motivation.



Kind regards,
-- 
Aaron Tomlin
Re: [PATCH 1/2] x86/resctrl: Add io_alloc_min_cbm_all interface for CBM reset
Posted by Moger, Babu 3 months ago

On 11/7/2025 4:25 PM, Aaron Tomlin wrote:
> On Fri, Nov 07, 2025 at 04:02:39PM -0600, Moger, Babu wrote:
>> Hi Aaron,
>>
>> Thanks for trying the patches.
> 
> Hi Babu,
> 
> Thank you very much for taking the time to review the patch and for
> pointing out the efficiency of the existing interface. You are correct that
> option [1], echo "0=0;1=0" > io_alloc_cbm, is also accomplished with a
> single system call.
> 
> However, the primary justification for introducing "io_alloc_min_cbm_all"
> lies in abstraction and the knowledge burden placed upon the user, not the
> system call count.
> 
> To successfully execute option [1], the user is required to have advanced
> knowledge of the system's current cache topology and capabilities:
> 
>      Domain ID Knowledge: The user must know every active Domain ID (e.g.,
>                           0, 1, 2, etc.) that supports the resource and
>                           manually enumerate them in the write string. If a
>                           domain is missed, it will not be reset.
> 
>      Minimal CBM Knowledge: The user must know the minimal supported number
>                             of consecutive bits that constitute a "cleared"
>                             state for each domain. While this is often 0,
>                             relying on this is not architecture-aware.
> 
> The new interface, is designed to abstract this complexity entirely. Also,
> applies the hardware's guaranteed minimum supported CBM (based on
> r->cache.min_cbm_bits) to each domain automatically.
> 
> This unified approach provides a robust and efficient mechanism to
> guarantee a full, architecture-aware reset across all domains, eliminating
> the need for userspace to parse the topology and construct a complex,
> domain-specific input string.
> 
> Please let me know if this clarifies the motivation.
> 

No, I don’t agree with introducing this new interface.

These settings are intended to be modified only by system 
administrators, not general users.

Administrators are already expected to have complete knowledge of the 
hardware and corresponding configuration details. They also typically 
rely on benchmark data to determine appropriate settings.

Additionally, this approach is not consistent with our existing CBM 
setting model.

Thanks
Babu

Re: [PATCH 1/2] x86/resctrl: Add io_alloc_min_cbm_all interface for CBM reset
Posted by Aaron Tomlin 3 months ago
On Fri, Nov 07, 2025 at 05:08:03PM -0600, Moger, Babu wrote:
> No, I don’t agree with introducing this new interface.
> 
> These settings are intended to be modified only by system administrators,
> not general users.
> 
> Administrators are already expected to have complete knowledge of the
> hardware and corresponding configuration details. They also typically rely
> on benchmark data to determine appropriate settings.
> 
> Additionally, this approach is not consistent with our existing CBM setting
> model.

Hi Babu,

I fully appreciate your point that system administrators are expected to
have complete knowledge of the hardware configuration. I believe my initial
motivation may have been unclear, so let me clarify the intention behind
"io_alloc_min_cbm_all".

The intention of this new interface is not to hide lower-level details from
the administrator, but rather to simplify a specific, high-overhead
administration task and prevent human error, which I encountered during
testing of your series.



By default, it is my understanding that when I/O allocation CBM is enabled,
all applicable shared L3 resources typically have their CBM bits set (e.g.,
ffff). If an administrator wishes to revert to a clean baseline before
applying a subset of dedicated bits, the manual process requires them to
not only have knowledge of every single Domain ID
applicable to the shared L3 resource but manually construct a long,
error-prone input string.

The objective of "io_alloc_min_cbm_all" is to provide a quick and accurate
medium to revert this topology-dependent default configuration to the
minimal supported state, thereby avoiding possible miscalculation or
omission of a Domain ID in the CBM string. As shown in the usage flow
below, the new interface drastically reduces the complexity of setting up a
specific configuration:

# cat /sys/fs/resctrl/info/L3/io_alloc_cbm
0=ffff;2=ffff;4=ffff;6=ffff;8=ffff;10=ffff;12=ffff;14=ffff;16=ffff;18=ffff;20=ffff;22=ffff;24=ffff;26=ffff;28=ffff;30=ffff;32=ffff;34=ffff;36=ffff;38=ffff;40=ffff;42=ffff;44=ffff;46=ffff;48=ffff;50=ffff;52=ffff

# echo 0=0;2=0;4=0;6=4;8=4;10=0;12=0;14=0;16=ffff;18=ffff;20=0;22=0;24=0;26=0;28=0;30=0;32=0;34=4;36=0;38=0;40=0;42=0;44=0;46=0;48=0;50=0;52=0 > /sys/fs/resctrl/info/L3/io_alloc_cbm

# After (using the new interface):
# Administrator uses the new interface to clear all domains automatically:
echo 0 > /sys/fs/resctrl/info/L3/io_alloc_min_cbm_all

# Then applies only the specific, custom masks needed:
echo 6=4;8=4;16=ffff;18=ffff;34=4 > /sys/fs/resctrl/info/L3/io_alloc_cbm



In essence, the new file automates the clearing phase across the entire
topology, allowing the administrator to immediately proceed to the
customization phase with a much shorter, focused command.

I believe the efficiency and guaranteed correctness for this specific use
case justifies the addition. Please let me know if this clarifies the
motivation and if you have an alternative suggestion for achieving this
guaranteed full-topology reset.

If, after considering this clarification, you still feel this approach
should not be merged, I will certainly defer to your judgment and withdraw
the patch.



Kind regards,
-- 
Aaron Tomlin
Re: [PATCH 1/2] x86/resctrl: Add io_alloc_min_cbm_all interface for CBM reset
Posted by Babu Moger 2 months, 4 weeks ago
Hi Aaron,

On 11/7/25 18:19, Aaron Tomlin wrote:
> On Fri, Nov 07, 2025 at 05:08:03PM -0600, Moger, Babu wrote:
>> No, I don’t agree with introducing this new interface.
>>
>> These settings are intended to be modified only by system administrators,
>> not general users.
>>
>> Administrators are already expected to have complete knowledge of the
>> hardware and corresponding configuration details. They also typically rely
>> on benchmark data to determine appropriate settings.
>>
>> Additionally, this approach is not consistent with our existing CBM setting
>> model.
> Hi Babu,
>
> I fully appreciate your point that system administrators are expected to
> have complete knowledge of the hardware configuration. I believe my initial
> motivation may have been unclear, so let me clarify the intention behind
> "io_alloc_min_cbm_all".
>
> The intention of this new interface is not to hide lower-level details from
> the administrator, but rather to simplify a specific, high-overhead
> administration task and prevent human error, which I encountered during
> testing of your series.
>
>
>
> By default, it is my understanding that when I/O allocation CBM is enabled,
> all applicable shared L3 resources typically have their CBM bits set (e.g.,
> ffff). If an administrator wishes to revert to a clean baseline before
> applying a subset of dedicated bits, the manual process requires them to
> not only have knowledge of every single Domain ID
> applicable to the shared L3 resource but manually construct a long,
> error-prone input string.
>
> The objective of "io_alloc_min_cbm_all" is to provide a quick and accurate
> medium to revert this topology-dependent default configuration to the
> minimal supported state, thereby avoiding possible miscalculation or
> omission of a Domain ID in the CBM string. As shown in the usage flow
> below, the new interface drastically reduces the complexity of setting up a
> specific configuration:
>
> # cat /sys/fs/resctrl/info/L3/io_alloc_cbm
> 0=ffff;2=ffff;4=ffff;6=ffff;8=ffff;10=ffff;12=ffff;14=ffff;16=ffff;18=ffff;20=ffff;22=ffff;24=ffff;26=ffff;28=ffff;30=ffff;32=ffff;34=ffff;36=ffff;38=ffff;40=ffff;42=ffff;44=ffff;46=ffff;48=ffff;50=ffff;52=ffff
>
> # echo 0=0;2=0;4=0;6=4;8=4;10=0;12=0;14=0;16=ffff;18=ffff;20=0;22=0;24=0;26=0;28=0;30=0;32=0;34=4;36=0;38=0;40=0;42=0;44=0;46=0;48=0;50=0;52=0 > /sys/fs/resctrl/info/L3/io_alloc_cbm


Does the following option work for you?

# echo "*=0" > /sys/fs/resctrl/info/L3/io_alloc_cbm


Here,|*| represents all domains.


This functionality was introduced when adding support for the*"mbm_event" assign mode* (see [1]).
[1]https://lore.kernel.org/lkml/b894ad853e6757d40da1469bf9fca4c64684df65.1757108044.git.babu.moger@amd.com/ <https://lore.kernel.org/lkml/b894ad853e6757d40da1469bf9fca4c64684df65.1757108044.git.babu.moger@amd.com/> <https://lore.kernel.org/lkml/b894ad853e6757d40da1469bf9fca4c64684df65.1757108044.git.babu.moger@amd.com/>
Also, this needs to be done for all the settings like L3, MBA also SMBA.

# echo "L3:*=f" > /sys/fs/resctrl/schemata

# echo "MB:*=128" > /sys/fs/resctrl/schemata

I’d like to hear from Reinette and Tony if this seems like an acceptable 
approach.

Thanks

Babu

Re: [PATCH 1/2] x86/resctrl: Add io_alloc_min_cbm_all interface for CBM reset
Posted by Aaron Tomlin 2 months, 4 weeks ago
On Mon, Nov 10, 2025 at 10:34:48AM -0600, Babu Moger wrote:
> Does the following option work for you?
> 
> # echo "*=0" > /sys/fs/resctrl/info/L3/io_alloc_cbm
> 
> 
> Here,|*| represents all domains.

Hi Babu,

Thank you for your response.

Unfortunately, this approach will not work.

If I understand correctly, the assumption that echo 0 (which translates to
a CBM of all zeros) would always be accepted as a "minimum" value is
incorrect since r->cache.min_cbm_bits could be greater than zero
(e.g., under Intel hardware). See rdt_init_res_defs_intel().

The goal is not just to "clear" the CBM, but to reset it to the smallest
valid mask.



Kind regards,
-- 
Aaron Tomlin
RE: [PATCH 1/2] x86/resctrl: Add io_alloc_min_cbm_all interface for CBM reset
Posted by Luck, Tony 2 months, 4 weeks ago
> The goal is not just to "clear" the CBM, but to reset it to the smallest
> valid mask.

"smallest valid mask" seems like a fuzzy concept.

Intel had one CPU that required 2 bits to be set in an L3 mask.
Subsequent CPUs only requires 1 bit.

AMD allows setting zero bits.

So for AMD "smallest valid mask" is zero. Very simple there.

But on Intel you must have either one or two bits set
(but it doesn't matter which bits).

In some cases you might want to pick a bit that
overlaps with the space shared in the cache for
non-CPU devices (typically top two valid bits of the
mask, but should check CPUID leaf 0x10 for the exact
bits).

Or you might want a bit that does NOT overlap with those
non-CPU allocations.

-Tony
Re: [PATCH 1/2] x86/resctrl: Add io_alloc_min_cbm_all interface for CBM reset
Posted by Reinette Chatre 2 months, 4 weeks ago

On 11/10/25 4:51 PM, Luck, Tony wrote:
>> The goal is not just to "clear" the CBM, but to reset it to the smallest
>> valid mask.
> 
> "smallest valid mask" seems like a fuzzy concept.
> 
> Intel had one CPU that required 2 bits to be set in an L3 mask.
> Subsequent CPUs only requires 1 bit.
> 
> AMD allows setting zero bits.
> 
> So for AMD "smallest valid mask" is zero. Very simple there.
> 
> But on Intel you must have either one or two bits set
> (but it doesn't matter which bits).

Right, and this is exposed to user space via, for example for L3,  
/sys/fs/resctrl/info/L3/min_cbm_bits.

> 
> In some cases you might want to pick a bit that
> overlaps with the space shared in the cache for
> non-CPU devices (typically top two valid bits of the
> mask, but should check CPUID leaf 0x10 for the exact
> bits).

... and this is exposed to user space via /sys/fs/resctrl/info/L3/shareable_bits
and for this new feature the domain specific values can be seen from
io_alloc_cbm.

> 
> Or you might want a bit that does NOT overlap with those
> non-CPU allocations.
> 
Seems like user space has needed information to perform a sane reset?

Reinette
RE: [PATCH 1/2] x86/resctrl: Add io_alloc_min_cbm_all interface for CBM reset
Posted by Luck, Tony 2 months, 4 weeks ago
> Seems like user space has needed information to perform a sane reset?

Like this:

1) 	Read info files to figure out what minimum mask is needed for this system
2)	Use Babu's suggested syntax of
		# echo "L3:*={min_mask_from_step_1}" > schemata

Rather than Aaron's

	# echo "L3:*=0" > schemata

I'm OK with this for L3, but still see it being less useful for L2 with asymmetric domains.

It can meet the "set a minimum value across all domains" need.

But can fail setting a value that isn't supported by some of the domains.

-Tony
Re: [PATCH 1/2] x86/resctrl: Add io_alloc_min_cbm_all interface for CBM reset
Posted by Aaron Tomlin 2 months, 4 weeks ago
On Tue, Nov 11, 2025 at 01:40:45AM +0000, Luck, Tony wrote:
> > Seems like user space has needed information to perform a sane reset?
> 
> Like this:
> 
> 1) 	Read info files to figure out what minimum mask is needed for this system
> 2)	Use Babu's suggested syntax of
> 		# echo "L3:*={min_mask_from_step_1}" > schemata
> 
> Rather than Aaron's
> 
> 	# echo "L3:*=0" > schemata

Hi Tony,

I am satisfied with either approach.

However, to clarify, the primary function of the "io_alloc_min_cbm_all"
interface is to efficiently set the lowest architecturally valid CBM across
all shared L3 domains. This operation relies entirely on
r->cache.min_cbm_bits. Since this value is guaranteed by the hardware to be
valid, this approach is robust and will not return an error (e.g., -EINVAL)
to userspace.


Kind regards,
-- 
Aaron Tomlin
Re: [PATCH 1/2] x86/resctrl: Add io_alloc_min_cbm_all interface for CBM reset
Posted by Babu Moger 2 months, 4 weeks ago
Hi Everyone,

On 11/10/25 20:44, Aaron Tomlin wrote:
> On Tue, Nov 11, 2025 at 01:40:45AM +0000, Luck, Tony wrote:
>>> Seems like user space has needed information to perform a sane reset?
>> Like this:
>>
>> 1) 	Read info files to figure out what minimum mask is needed for this system
>> 2)	Use Babu's suggested syntax of
>> 		# echo "L3:*={min_mask_from_step_1}" > schemata
>>
>> Rather than Aaron's
>>
>> 	# echo "L3:*=0" > schemata
> Hi Tony,
>
> I am satisfied with either approach.
>
> However, to clarify, the primary function of the "io_alloc_min_cbm_all"
> interface is to efficiently set the lowest architecturally valid CBM across
> all shared L3 domains. This operation relies entirely on
> r->cache.min_cbm_bits. Since this value is guaranteed by the hardware to be
> valid, this approach is robust and will not return an error (e.g., -EINVAL)
> to userspace.
>
>

Here’s my understanding of the discussion from this thread:


We plan to support the following operation:

    #echo "*=value" > /sys/fs/resctrl/info/L3/io_alloc_cbm


Its users responsibility to make sure the value is valid based on

/sys/fs/resctrl/info/L3/min_cbm_bits and /sys/fs/resctrl/info/L3/cbm_mask.


There’s no need for an additional interface like
|/sys/fs/resctrl/info/L3/io_alloc_min_cbm_all|.


Did I miss anything?


Thanks
Babu

Re: [PATCH 1/2] x86/resctrl: Add io_alloc_min_cbm_all interface for CBM reset
Posted by Babu Moger 2 months, 3 weeks ago
Hi Reinette,

On 11/11/25 09:29, Babu Moger wrote:
> Hi Everyone,
>
> On 11/10/25 20:44, Aaron Tomlin wrote:
>> On Tue, Nov 11, 2025 at 01:40:45AM +0000, Luck, Tony wrote:
>>>> Seems like user space has needed information to perform a sane reset?
>>> Like this:
>>>
>>> 1)     Read info files to figure out what minimum mask is needed for 
>>> this system
>>> 2)    Use Babu's suggested syntax of
>>>         # echo "L3:*={min_mask_from_step_1}" > schemata
>>>
>>> Rather than Aaron's
>>>
>>>     # echo "L3:*=0" > schemata
>> Hi Tony,
>>
>> I am satisfied with either approach.
>>
>> However, to clarify, the primary function of the "io_alloc_min_cbm_all"
>> interface is to efficiently set the lowest architecturally valid CBM 
>> across
>> all shared L3 domains. This operation relies entirely on
>> r->cache.min_cbm_bits. Since this value is guaranteed by the hardware 
>> to be
>> valid, this approach is robust and will not return an error (e.g., 
>> -EINVAL)
>> to userspace.
>>
>>
>
> Here’s my understanding of the discussion from this thread:
>
>
> We plan to support the following operation:
>
>    #echo "*=value" > /sys/fs/resctrl/info/L3/io_alloc_cbm
>
Looks like we are going with the above approach where "*" represents all 
the domain.

Couple of things to consider.

a. Send a separate patch to add this feature after [1] is merged.

b. Add this change as part of [1] series in patch 9. The series is 
mostly ready for merge. I can add the changes. Only concern is, it will 
might delay the series merge little bit.  My expectation is to have this 
series ready for next merge window.

[1] https://lore.kernel.org/lkml/cover.1761844489.git.babu.moger@amd.com/

Any thoughts?

Thanks

Babu

Re: [PATCH 1/2] x86/resctrl: Add io_alloc_min_cbm_all interface for CBM reset
Posted by Aaron Tomlin 2 months, 3 weeks ago
On Tue, Nov 11, 2025 at 03:04:55PM -0600, Babu Moger wrote:
> > Here’s my understanding of the discussion from this thread:
> > 
> > 
> > We plan to support the following operation:
> > 
> >    #echo "*=value" > /sys/fs/resctrl/info/L3/io_alloc_cbm
> > 
> Looks like we are going with the above approach where "*" represents all the
> domain.
> 
> Couple of things to consider.
> 
> a. Send a separate patch to add this feature after [1] is merged.
> 
> b. Add this change as part of [1] series in patch 9. The series is mostly
> ready for merge. I can add the changes. Only concern is, it will might delay
> the series merge little bit.  My expectation is to have this series ready
> for next merge window.
> 
> [1] https://lore.kernel.org/lkml/cover.1761844489.git.babu.moger@amd.com/
> 
> Any thoughts?
> 
> Thanks
> 

Hi Babu, Tony, Reinette,

I believe the most prudent course of action would be to hold off on this
particular change until the main series has been merged.

As I was the one who specifically requested this supporting functionality,
I would be happy to prepare and submit the follow-up patch for this detail
myself.


Kind regards,
-- 
Aaron Tomlin
Re: [PATCH 1/2] x86/resctrl: Add io_alloc_min_cbm_all interface for CBM reset
Posted by Moger, Babu 2 months, 3 weeks ago
Hi Aaron,

On 11/11/2025 4:34 PM, Aaron Tomlin wrote:
> On Tue, Nov 11, 2025 at 03:04:55PM -0600, Babu Moger wrote:
>>> Here’s my understanding of the discussion from this thread:
>>>
>>>
>>> We plan to support the following operation:
>>>
>>>     #echo "*=value" > /sys/fs/resctrl/info/L3/io_alloc_cbm
>>>
>> Looks like we are going with the above approach where "*" represents all the
>> domain.
>>
>> Couple of things to consider.
>>
>> a. Send a separate patch to add this feature after [1] is merged.
>>
>> b. Add this change as part of [1] series in patch 9. The series is mostly
>> ready for merge. I can add the changes. Only concern is, it will might delay
>> the series merge little bit.  My expectation is to have this series ready
>> for next merge window.
>>
>> [1] https://lore.kernel.org/lkml/cover.1761844489.git.babu.moger@amd.com/
>>
>> Any thoughts?
>>
>> Thanks
>>
> 
> Hi Babu, Tony, Reinette,
> 
> I believe the most prudent course of action would be to hold off on this
> particular change until the main series has been merged.
> 
> As I was the one who specifically requested this supporting functionality,
> I would be happy to prepare and submit the follow-up patch for this detail
> myself.

Sounds good. I will go ahead with the current series. You can send the 
patch(s) after series is merged.

Thanks
Babu
Re: [PATCH 1/2] x86/resctrl: Add io_alloc_min_cbm_all interface for CBM reset
Posted by Reinette Chatre 2 months, 4 weeks ago
Hi Tony,

On 11/10/25 5:40 PM, Luck, Tony wrote:
>> Seems like user space has needed information to perform a sane reset?
> 
> Like this:
> 
> 1) 	Read info files to figure out what minimum mask is needed for this system
> 2)	Use Babu's suggested syntax of
> 		# echo "L3:*={min_mask_from_step_1}" > schemata

Exactly, but without the "L3:" and with s/schemata/io_alloc_cbm/. Specifically,
	# echo "*={min_mask_from_step_1}" > /sys/fs/resctrl/info/L3/io_alloc_cbm

I do not believe this feature is being considered for the schemata file (at this time?),
just for io_alloc_cbm.

> 
> Rather than Aaron's
> 
> 	# echo "L3:*=0" > schemata
> 
> I'm OK with this for L3, but still see it being less useful for L2 with asymmetric domains.

That would first require that these L2 with asymmetric domains be made available
as resource for IO allocation. At this time the feature is limited to L3 but when/if it
expands to L2 an interface like this could remain sane by allowing values that overlap all
domains to be set on all domains with one user space call and a clear failure presented
to user via last_cmd_status on first failure if it is not possible. 

> 
> It can meet the "set a minimum value across all domains" need.

ack.

> 
> But can fail setting a value that isn't supported by some of the domains.
> 

ack.

Reinette
RE: [PATCH 1/2] x86/resctrl: Add io_alloc_min_cbm_all interface for CBM reset
Posted by Luck, Tony 2 months, 4 weeks ago
> Does the following option work for you?
>
> # echo "*=0" > /sys/fs/resctrl/info/L3/io_alloc_cbm
>
>
> Here,|*| represents all domains.
>
>
> This functionality was introduced when adding support for the*"mbm_event" assign mode* (see [1]).
> [1]https://lore.kernel.org/lkml/b894ad853e6757d40da1469bf9fca4c64684df65.1757108044.git.babu.moger@amd.com/ <https://lore.kernel.org/lkml/b894ad853e6757d40da1469bf9fca4c64684df65.1757108044.git.babu.moger@amd.com/> <https://lore.kernel.org/lkml/b894ad853e6757d40da1469bf9fca4c64684df65.1757108044.git.babu.moger@amd.com/>
> Also, this needs to be done for all the settings like L3, MBA also SMBA.
>
> # echo "L3:*=f" > /sys/fs/resctrl/schemata
>
> # echo "MB:*=128" > /sys/fs/resctrl/schemata
>
> I’d like to hear from Reinette and Tony if this seems like an acceptable
> approach.
>
> Thanks

Babu,

It does look like a logical extension of the mbm_event assignment syntax.

But might be awkward to use if the system has asymmetric domains. We don't
currently. But if we wanted to support L2 cache allocation on hybrid platforms
with a mix of P-core and E-core, those have historically supported different
bit masks because the L2 caches may allow 12 bits for one core type and
16 for another. On such a platform:

# echo "L2:*=fff" > schemata

would work,. But

# echo "L2:*=ffff" > schemata

would try to set unimplemented bits on some cores and would fail.

-Tony
Re: RE: [PATCH 1/2] x86/resctrl: Add io_alloc_min_cbm_all interface for CBM reset
Posted by Babu Moger 2 months, 4 weeks ago
Hi Tony,

On 11/10/25 11:50, Luck, Tony wrote:
>> Does the following option work for you?
>>
>> # echo "*=0" > /sys/fs/resctrl/info/L3/io_alloc_cbm
>>
>>
>> Here,|*| represents all domains.
>>
>>
>> This functionality was introduced when adding support for the*"mbm_event" assign mode* (see [1]).
>> [1]https://lore.kernel.org/lkml/b894ad853e6757d40da1469bf9fca4c64684df65.1757108044.git.babu.moger@amd.com/ <https://lore.kernel.org/lkml/b894ad853e6757d40da1469bf9fca4c64684df65.1757108044.git.babu.moger@amd.com/> <https://lore.kernel.org/lkml/b894ad853e6757d40da1469bf9fca4c64684df65.1757108044.git.babu.moger@amd.com/>
>> Also, this needs to be done for all the settings like L3, MBA also SMBA.
>>
>> # echo "L3:*=f" > /sys/fs/resctrl/schemata
>>
>> # echo "MB:*=128" > /sys/fs/resctrl/schemata
>>
>> I’d like to hear from Reinette and Tony if this seems like an acceptable
>> approach.
>>
>> Thanks
> Babu,
>
> It does look like a logical extension of the mbm_event assignment syntax.
>
> But might be awkward to use if the system has asymmetric domains. We don't
> currently. But if we wanted to support L2 cache allocation on hybrid platforms
> with a mix of P-core and E-core, those have historically supported different
> bit masks because the L2 caches may allow 12 bits for one core type and
> 16 for another. On such a platform:
>
> # echo "L2:*=fff" > schemata
>
> would work,. But
>
> # echo "L2:*=ffff" > schemata
>
> would try to set unimplemented bits on some cores and would fail.


I would consider this a user error, as the user is expected to know the 
supported value for the domain.
This situation can occur even now — we simply report the error and exit.

Thanks

Babu

RE: RE: [PATCH 1/2] x86/resctrl: Add io_alloc_min_cbm_all interface for CBM reset
Posted by Luck, Tony 2 months, 4 weeks ago
> > # echo "L2:*=fff" > schemata
> >
> > would work,. But
> >
> > # echo "L2:*=ffff" > schemata
> >
> > would try to set unimplemented bits on some cores and would fail.
>
>
> I would consider this a user error, as the user is expected to know the
> supported value for the domain.
> This situation can occur even now — we simply report the error and exit.

Babu

Maybe it was a poor explanation on my part.

On a hybrid P-core/E-core system with different L2 cache topology schemata
may look like this (8 L2 domains of one type, 4 L2 domains of other type.

$ cat schemata
L2:0=ffff;1=ffff;2=ffff;3=ffff;4=ffff;5=ffff;6=ffff;7=ffff;8=7f;9=7f;10=7f;11=7f

The proposed wildcard syntax is only useful to set all domains to a value
that is legal for all domains. It cannot be used for the "reset back to defaults"
case because different domains have different defaults.

-Tony
Re: [PATCH 1/2] x86/resctrl: Add io_alloc_min_cbm_all interface for CBM reset
Posted by Reinette Chatre 2 months, 4 weeks ago
Hi Tony,

On 11/10/25 11:56 AM, Luck, Tony wrote:
>>> # echo "L2:*=fff" > schemata
>>>
>>> would work,. But
>>>
>>> # echo "L2:*=ffff" > schemata
>>>
>>> would try to set unimplemented bits on some cores and would fail.
>>
>>
>> I would consider this a user error, as the user is expected to know the
>> supported value for the domain.
>> This situation can occur even now — we simply report the error and exit.
> 
> Babu
> 
> Maybe it was a poor explanation on my part.
> 
> On a hybrid P-core/E-core system with different L2 cache topology schemata
> may look like this (8 L2 domains of one type, 4 L2 domains of other type.
> 
> $ cat schemata
> L2:0=ffff;1=ffff;2=ffff;3=ffff;4=ffff;5=ffff;6=ffff;7=ffff;8=7f;9=7f;10=7f;11=7f
> 
> The proposed wildcard syntax is only useful to set all domains to a value
> that is legal for all domains. It cannot be used for the "reset back to defaults"
> case because different domains have different defaults.

Disabling and re-enabling of io_alloc may be substitute for "reset back to defaults".

The '*' syntax would be useful to initialize domains to minimal allocations ...
assuming all cache instances support the same minimum. 

Would it be an issue if user attempts to assign a value that is not supported to
all domains? resctrl could fail on first invalid bitmask and the last_cmd_status can
then be expected to indicate the details of error.

Reinette
RE: [PATCH 1/2] x86/resctrl: Add io_alloc_min_cbm_all interface for CBM reset
Posted by Luck, Tony 3 months ago
> The intention of this new interface is not to hide lower-level details from
> the administrator, but rather to simplify a specific, high-overhead
> administration task and prevent human error, which I encountered during
> testing of your series.

If you do this often, make a bash script or function to do:

sed -i -e 's/\([0-9][0-9]*\)=\([0-9a-f][0-9a-f]*\)/\1=0/g' /sys/fs/resctrl/info/L3/io_alloc_cbm

[That regex would probably be more readable using extended syntax]

-Tony