[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <963710cb374d55856053989e4edc61d7fd033662.1745275431.git.babu.moger@amd.com>
Date: Mon, 21 Apr 2025 17:43:49 -0500
From: Babu Moger <babu.moger@....com>
To: <tony.luck@...el.com>, <reinette.chatre@...el.com>, <tglx@...utronix.de>,
<mingo@...hat.com>, <bp@...en8.de>, <dave.hansen@...ux.intel.com>
CC: <babu.moger@....com>, <corbet@....net>, <x86@...nel.org>, <hpa@...or.com>,
<akpm@...ux-foundation.org>, <paulmck@...nel.org>, <rostedt@...dmis.org>,
<thuth@...hat.com>, <ardb@...nel.org>, <gregkh@...uxfoundation.org>,
<thomas.lendacky@....com>, <mario.limonciello@....com>, <perry.yuan@....com>,
<seanjc@...gle.com>, <kai.huang@...el.com>, <xiaoyao.li@...el.com>,
<kan.liang@...ux.intel.com>, <riel@...riel.com>, <xin3.li@...el.com>,
<xin@...or.com>, <sohil.mehta@...el.com>, <ak@...ux.intel.com>,
<ebiggers@...gle.com>, <andrew.cooper3@...rix.com>, <gautham.shenoy@....com>,
<Xiaojian.Du@....com>, <linux-doc@...r.kernel.org>,
<linux-kernel@...r.kernel.org>, <james.morse@....com>, <fenghuay@...dia.com>,
<peternewman@...gle.com>
Subject: [PATCH v4 5/8] x86/resctrl: Add user interface to enable/disable io_alloc feature
The io_alloc feature in resctrl is a mechanism that enables direct
insertion of data from I/O devices into the L3 cache.
On AMD systems, io_alloc feature is backed by SDCIAE (L3 Smart Data Cache
Injection Allocation Enforcement). When enabled, SDCIAE forces all SDCI
lines to be placed into the L3 cache partitions identified by the
highest-supported L3_MASK_n register as reported by CPUID
Fn0000_0010_EDX_x1.MAX_COS. For example, if MAX_COS=15, SDCI lines will
be allocated into the L3 cache partitions determined by the bitmask in
the L3_MASK_15 register.
When CDP is enabled, io_alloc routes I/O traffic using the highest CLOSID
allocated for the instruction cache (L3CODE).
Introduce user interface to enable/disable "io_alloc" feature.
Signed-off-by: Babu Moger <babu.moger@....com>
---
v4: Updated the change log.
Updated the user doc.
The "io_alloc" interface will report "enabled/disabled/not supported".
Updated resctrl_io_alloc_closid_get() to verify the max closid availability.
Updated the documentation for "shareable_bits" and "bit_usage".
Introduced io_alloc_init() to initialize fflags.
Printed the group name when io_alloc enablement fails.
NOTE: io_alloc is about specific CLOS. rdt_bit_usage_show() is not designed
handle bit_usage for specific CLOS. Its about overall system. So, we cannot
really tell the user which CLOS is shared across both hardware and software.
We need to discuss this.
v3: Rewrote the change to make it generic.
Rewrote the documentation in resctrl.rst to be generic and added
AMD feature details in the end.
Added the check to verify if MAX CLOSID availability on the system.
Added CDP check to make sure io_alloc is configured in CDP_CODE.
Added resctrl_io_alloc_closid_free() to free the io_alloc CLOSID.
Added errors in few cases when CLOSID allocation fails.
Fixes splat reported when info/L3/bit_usage is accesed when io_alloc
is enabled.
https://lore.kernel.org/lkml/SJ1PR11MB60837B532254E7B23BC27E84FC052@SJ1PR11MB6083.namprd11.prod.outlook.com/
v2: Renamed the feature to "io_alloc".
Added generic texts for the feature in commit log and resctrl.rst doc.
Added resctrl_io_alloc_init_cat() to initialize io_alloc to default
values when enabled.
Fixed io_alloc show functinality to display only on L3 resource.
---
Documentation/arch/x86/resctrl.rst | 34 +++++
arch/x86/kernel/cpu/resctrl/rdtgroup.c | 185 ++++++++++++++++++++++++-
2 files changed, 218 insertions(+), 1 deletion(-)
diff --git a/Documentation/arch/x86/resctrl.rst b/Documentation/arch/x86/resctrl.rst
index 6768fc1fad16..7672c5c52c1a 100644
--- a/Documentation/arch/x86/resctrl.rst
+++ b/Documentation/arch/x86/resctrl.rst
@@ -95,6 +95,11 @@ related to allocation:
some platforms support devices that have their
own settings for cache use which can over-ride
these bits.
+
+ When the "io_alloc" feature is enabled, a portion of the cache
+ is reserved for shared use between hardware and software. Refer
+ to "bit_usage" to see which portion is allocated for this purpose.
+
"bit_usage":
Annotated capacity bitmasks showing how all
instances of the resource are used. The legend is:
@@ -135,6 +140,35 @@ related to allocation:
"1":
Non-contiguous 1s value in CBM is supported.
+"io_alloc":
+ The "io_alloc" enables system software to configure the portion
+ of the L3 cache allocated for I/O traffic.
+
+ The feature routes the I/O traffic via specific CLOSID reserved
+ for io_alloc feature. By configuring the CBM (Capacity Bit Mask)
+ for the CLOSID, users can control the L3 portions available for
+ I/0 traffic. The reserved CLOSID will be excluded for group creation.
+
+ The interface provides a means to query the status of feature support.
+
+ Example::
+
+ # cat /sys/fs/resctrl/info/L3/io_alloc
+ disabled
+
+ Feature can be enabled/disabled by writing to the interface.
+ Example::
+
+ # echo 1 > /sys/fs/resctrl/info/L3/io_alloc
+ # cat /sys/fs/resctrl/info/L3/io_alloc
+ enabled
+
+ On AMD systems, the io_alloc feature is supported by the L3 Smart
+ Data Cache Injection Allocation Enforcement (SDCIAE). The CLOSID for
+ io_alloc is determined by the highest CLOSID supported by the resource.
+ When CDP is enabled, io_alloc routes I/O traffic using the highest
+ CLOSID allocated for the instruction cache (L3CODE).
+
Memory bandwidth(MB) subdirectory contains the following files
with respect to allocation:
diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
index 85796a186374..d53a2068cde4 100644
--- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
+++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
@@ -68,6 +68,7 @@ static char last_cmd_status_buf[512];
static int rdtgroup_setup_root(struct rdt_fs_context *ctx);
static void rdtgroup_destroy_root(void);
+static int rdtgroup_init_cat(struct resctrl_schema *s, u32 closid);
struct dentry *debugfs_resctrl;
@@ -199,6 +200,19 @@ void closid_free(int closid)
__set_bit(closid, &closid_free_map);
}
+static int resctrl_io_alloc_closid_alloc(u32 io_alloc_closid)
+{
+ if (__test_and_clear_bit(io_alloc_closid, &closid_free_map))
+ return io_alloc_closid;
+ else
+ return -ENOSPC;
+}
+
+static void resctrl_io_alloc_closid_free(u32 io_alloc_closid)
+{
+ closid_free(io_alloc_closid);
+}
+
/**
* closid_allocated - test if provided closid is in use
* @closid: closid to be tested
@@ -1033,6 +1047,31 @@ static int rdt_shareable_bits_show(struct kernfs_open_file *of,
return 0;
}
+/*
+ * resctrl_io_alloc_closid_get - io_alloc feature uses max CLOSID to route
+ * the IO traffic. Get the max CLOSID and verify if the CLOSID is available.
+ *
+ * The total number of CLOSIDs is determined in closid_init(), based on the
+ * minimum supported across all resources. If CDP (Code Data Prioritization)
+ * is enabled, the number of CLOSIDs is halved. The final value is returned
+ * by closids_supported() and stored in s->num_closid for each resource.
+ * Make sure this value aligns with the maximum CLOSID supported by the
+ * respective resource.
+ */
+static int resctrl_io_alloc_closid_get(struct rdt_resource *r,
+ struct resctrl_schema *s)
+{
+ int num_closids = closids_supported();
+
+ if (resctrl_arch_get_cdp_enabled(r->rid))
+ num_closids *= 2;
+
+ if (num_closids != resctrl_arch_get_num_closid(r))
+ return -ENOSPC;
+ else
+ return s->num_closid - 1;
+}
+
/*
* rdt_bit_usage_show - Display current usage of resources
*
@@ -1076,9 +1115,20 @@ static int rdt_bit_usage_show(struct kernfs_open_file *of,
for (i = 0; i < closids_supported(); i++) {
if (!closid_allocated(i))
continue;
+ /*
+ * If io_alloc is enabled, the CLOSID will be
+ * allocated but will not be associated with any
+ * groups. The region is available for sharing with
+ * io_alloc feature as well as resctrl groups.
+ */
+ if (i == resctrl_io_alloc_closid_get(r, s) &&
+ resctrl_arch_get_io_alloc_enabled(r))
+ mode = RDT_MODE_SHAREABLE;
+ else
+ mode = rdtgroup_mode_by_closid(i);
+
ctrl_val = resctrl_arch_get_config(r, dom, i,
s->conf_type);
- mode = rdtgroup_mode_by_closid(i);
switch (mode) {
case RDT_MODE_SHAREABLE:
sw_shareable |= ctrl_val;
@@ -1877,6 +1927,121 @@ int resctrl_arch_io_alloc_enable(struct rdt_resource *r, bool enable)
return 0;
}
+static int resctrl_io_alloc_show(struct kernfs_open_file *of,
+ struct seq_file *seq, void *v)
+{
+ struct resctrl_schema *s = rdt_kn_parent_priv(of->kn);
+ struct rdt_resource *r = s->res;
+
+ if (r->cache.io_alloc_capable && !(s->conf_type == CDP_DATA)) {
+ if (resctrl_arch_get_io_alloc_enabled(r))
+ seq_puts(seq, "enabled\n");
+ else
+ seq_puts(seq, "disabled\n");
+ } else {
+ seq_puts(seq, "not supported\n");
+ }
+
+ return 0;
+}
+
+/*
+ * Initialize io_alloc CLOSID cache resource with default CBM values.
+ */
+static int resctrl_io_alloc_init_cat(struct rdt_resource *r,
+ struct resctrl_schema *s, u32 closid)
+{
+ int ret;
+
+ rdt_staged_configs_clear();
+
+ ret = rdtgroup_init_cat(s, closid);
+ if (ret < 0)
+ goto out_init_cat;
+
+ ret = resctrl_arch_update_domains(r, closid);
+
+out_init_cat:
+ rdt_staged_configs_clear();
+ return ret;
+}
+
+static const char *rdtgroup_name_by_closid(int closid)
+{
+ struct rdtgroup *rdtgrp;
+
+ list_for_each_entry(rdtgrp, &rdt_all_groups, rdtgroup_list) {
+ if (rdtgrp->closid == closid)
+ return rdtgrp->kn->name;
+ }
+
+ return NULL;
+}
+
+static ssize_t resctrl_io_alloc_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;
+ char const *grp_name;
+ u32 io_alloc_closid;
+ bool enable;
+ int ret;
+
+ ret = kstrtobool(buf, &enable);
+ if (ret)
+ return ret;
+
+ cpus_read_lock();
+ mutex_lock(&rdtgroup_mutex);
+
+ rdt_last_cmd_clear();
+
+ if (!r->cache.io_alloc_capable || s->conf_type == CDP_DATA) {
+ rdt_last_cmd_puts("io_alloc feature is not supported on the resource\n");
+ ret = -ENODEV;
+ goto out_io_alloc;
+ }
+
+ io_alloc_closid = resctrl_io_alloc_closid_get(r, s);
+ if (io_alloc_closid < 0) {
+ rdt_last_cmd_puts("Max CLOSID to support io_alloc is not available\n");
+ ret = -EINVAL;
+ goto out_io_alloc;
+ }
+
+ if (resctrl_arch_get_io_alloc_enabled(r) != enable) {
+ if (enable) {
+ ret = resctrl_io_alloc_closid_alloc(io_alloc_closid);
+ if (ret < 0) {
+ grp_name = rdtgroup_name_by_closid(io_alloc_closid);
+ rdt_last_cmd_printf("CLOSID for io_alloc is used by %s group\n",
+ grp_name ? grp_name : "another");
+ ret = -EINVAL;
+ goto out_io_alloc;
+ }
+
+ ret = resctrl_io_alloc_init_cat(r, s, io_alloc_closid);
+ if (ret) {
+ rdt_last_cmd_puts("Failed to initialize io_alloc allocations\n");
+ resctrl_io_alloc_closid_free(io_alloc_closid);
+ goto out_io_alloc;
+ }
+
+ } else {
+ resctrl_io_alloc_closid_free(io_alloc_closid);
+ }
+
+ ret = resctrl_arch_io_alloc_enable(r, enable);
+ }
+
+out_io_alloc:
+ mutex_unlock(&rdtgroup_mutex);
+ cpus_read_unlock();
+
+ return ret ?: nbytes;
+}
+
/* rdtgroup information files for one cache resource. */
static struct rftype res_common_files[] = {
{
@@ -2029,6 +2194,13 @@ static struct rftype res_common_files[] = {
.seq_show = rdtgroup_schemata_show,
.fflags = RFTYPE_CTRL_BASE,
},
+ {
+ .name = "io_alloc",
+ .mode = 0644,
+ .kf_ops = &rdtgroup_kf_single_ops,
+ .seq_show = resctrl_io_alloc_show,
+ .write = resctrl_io_alloc_write,
+ },
{
.name = "mba_MBps_event",
.mode = 0644,
@@ -2137,6 +2309,15 @@ static void thread_throttle_mode_init(void)
RFTYPE_CTRL_INFO | RFTYPE_RES_MB);
}
+static void io_alloc_init(void)
+{
+ struct rdt_resource *r = resctrl_arch_get_resource(RDT_RESOURCE_L3);
+
+ if (r->cache.io_alloc_capable)
+ resctrl_file_fflags_init("io_alloc",
+ RFTYPE_CTRL_INFO | RFTYPE_RES_CACHE);
+}
+
void resctrl_file_fflags_init(const char *config, unsigned long fflags)
{
struct rftype *rft;
@@ -4381,6 +4562,8 @@ int __init resctrl_init(void)
thread_throttle_mode_init();
+ io_alloc_init();
+
ret = resctrl_mon_resource_init();
if (ret)
return ret;
--
2.34.1
Powered by blists - more mailing lists