]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
x86/resctrl: Generate default_ctrl instead of sharing it
authorJames Morse <james.morse@arm.com>
Tue, 11 Mar 2025 18:36:53 +0000 (18:36 +0000)
committerBorislav Petkov (AMD) <bp@alien8.de>
Wed, 12 Mar 2025 11:22:44 +0000 (12:22 +0100)
The struct rdt_resource default_ctrl is used by both the architecture code for
resetting the hardware controls, and sometimes by the filesystem code as the
default value for the schema, unless the bandwidth software controller is in
use.

Having the default exposed by the architecture code causes unnecessary
duplication for each architecture as the default value must be specified, but
can be derived from other schema properties. Now that the maximum bandwidth is
explicitly described, resctrl can derive the default value from the schema
format and the other resource properties.

Signed-off-by: James Morse <james.morse@arm.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Reviewed-by: Fenghua Yu <fenghuay@nvidia.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Babu Moger <babu.moger@amd.com>
Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64
Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Amit Singh Tomar <amitsinght@marvell.com> # arm64
Tested-by: Shanker Donthineni <sdonthineni@nvidia.com> # arm64
Tested-by: Babu Moger <babu.moger@amd.com>
Link: https://lore.kernel.org/r/20250311183715.16445-9-james.morse@arm.com
arch/x86/kernel/cpu/resctrl/core.c
arch/x86/kernel/cpu/resctrl/ctrlmondata.c
arch/x86/kernel/cpu/resctrl/rdtgroup.c
include/linux/resctrl.h

index 4504a12efc971dc76eab9d653a21f1950b8dcd97..d001ca43b53d97ba609de36cae2c56bede38347a 100644 (file)
@@ -155,7 +155,6 @@ static inline void cache_alloc_hsw_probe(void)
                return;
 
        hw_res->num_closid = 4;
-       r->default_ctrl = max_cbm;
        r->cache.cbm_len = 20;
        r->cache.shareable_bits = 0xc0000;
        r->cache.min_cbm_bits = 2;
@@ -211,7 +210,6 @@ static __init bool __get_mem_config_intel(struct rdt_resource *r)
        cpuid_count(0x00000010, 3, &eax.full, &ebx, &ecx, &edx.full);
        hw_res->num_closid = edx.split.cos_max + 1;
        max_delay = eax.split.max_delay + 1;
-       r->default_ctrl = MAX_MBA_BW;
        r->membw.max_bw = MAX_MBA_BW;
        r->membw.arch_needs_linear = true;
        if (ecx & MBA_IS_LINEAR) {
@@ -250,7 +248,6 @@ static __init bool __rdt_get_mem_config_amd(struct rdt_resource *r)
 
        cpuid_count(0x80000020, subleaf, &eax, &ebx, &ecx, &edx);
        hw_res->num_closid = edx + 1;
-       r->default_ctrl = 1 << eax;
        r->membw.max_bw = 1 << eax;
 
        /* AMD does not use delay */
@@ -276,13 +273,13 @@ static void rdt_get_cache_alloc_cfg(int idx, struct rdt_resource *r)
        union cpuid_0x10_1_eax eax;
        union cpuid_0x10_x_ecx ecx;
        union cpuid_0x10_x_edx edx;
-       u32 ebx;
+       u32 ebx, default_ctrl;
 
        cpuid_count(0x00000010, idx, &eax.full, &ebx, &ecx.full, &edx.full);
        hw_res->num_closid = edx.split.cos_max + 1;
        r->cache.cbm_len = eax.split.cbm_len + 1;
-       r->default_ctrl = BIT_MASK(eax.split.cbm_len + 1) - 1;
-       r->cache.shareable_bits = ebx & r->default_ctrl;
+       default_ctrl = BIT_MASK(eax.split.cbm_len + 1) - 1;
+       r->cache.shareable_bits = ebx & default_ctrl;
        if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL)
                r->cache.arch_has_sparse_bitmasks = ecx.split.noncont;
        r->alloc_capable = true;
@@ -329,7 +326,7 @@ static u32 delay_bw_map(unsigned long bw, struct rdt_resource *r)
                return MAX_MBA_BW - bw;
 
        pr_warn_once("Non Linear delay-bw map not supported but queried\n");
-       return r->default_ctrl;
+       return MAX_MBA_BW;
 }
 
 static void mba_wrmsr_intel(struct msr_param *m)
@@ -438,7 +435,7 @@ static void setup_default_ctrlval(struct rdt_resource *r, u32 *dc)
         * For Memory Allocation: Set b/w requested to 100%
         */
        for (i = 0; i < hw_res->num_closid; i++, dc++)
-               *dc = r->default_ctrl;
+               *dc = resctrl_get_default_ctrl(r);
 }
 
 static void ctrl_domain_free(struct rdt_hw_ctrl_domain *hw_dom)
index 23a01eaebd58701278d4ea3dd3f4eb1e3c831106..5d87f279085f78243a400d3664587cdcf6a8550b 100644 (file)
@@ -113,8 +113,9 @@ static int parse_bw(struct rdt_parse_data *data, struct resctrl_schema *s,
  */
 static bool cbm_validate(char *buf, u32 *data, struct rdt_resource *r)
 {
-       unsigned long first_bit, zero_bit, val;
+       u32 supported_bits = BIT_MASK(r->cache.cbm_len) - 1;
        unsigned int cbm_len = r->cache.cbm_len;
+       unsigned long first_bit, zero_bit, val;
        int ret;
 
        ret = kstrtoul(buf, 16, &val);
@@ -123,7 +124,7 @@ static bool cbm_validate(char *buf, u32 *data, struct rdt_resource *r)
                return false;
        }
 
-       if ((r->cache.min_cbm_bits > 0 && val == 0) || val > r->default_ctrl) {
+       if ((r->cache.min_cbm_bits > 0 && val == 0) || val > supported_bits) {
                rdt_last_cmd_puts("Mask out of range\n");
                return false;
        }
index 1e0bae1a9d9505278515542ba34f30fe4ad194a1..cd8f65c12124b34fcf91c8074855916773da41f8 100644 (file)
@@ -978,7 +978,7 @@ static int rdt_default_ctrl_show(struct kernfs_open_file *of,
        struct resctrl_schema *s = of->kn->parent->priv;
        struct rdt_resource *r = s->res;
 
-       seq_printf(seq, "%x\n", r->default_ctrl);
+       seq_printf(seq, "%x\n", resctrl_get_default_ctrl(r));
        return 0;
 }
 
@@ -2882,7 +2882,7 @@ static int reset_all_ctrls(struct rdt_resource *r)
                hw_dom = resctrl_to_arch_ctrl_dom(d);
 
                for (i = 0; i < hw_res->num_closid; i++)
-                       hw_dom->ctrl_val[i] = r->default_ctrl;
+                       hw_dom->ctrl_val[i] = resctrl_get_default_ctrl(r);
                msr_param.dom = d;
                smp_call_function_any(&d->hdr.cpu_mask, rdt_ctrl_update, &msr_param, 1);
        }
@@ -3417,7 +3417,7 @@ static void rdtgroup_init_mba(struct rdt_resource *r, u32 closid)
                }
 
                cfg = &d->staged_config[CDP_NONE];
-               cfg->new_ctrl = r->default_ctrl;
+               cfg->new_ctrl = resctrl_get_default_ctrl(r);
                cfg->have_new_ctrl = true;
        }
 }
index 465f3cf8c4bcbdf4256fb672ea8c4d6132dca175..d16dc960f1fce7f54300a9e7c2c599ab24ca4162 100644 (file)
@@ -216,7 +216,6 @@ enum resctrl_schema_fmt {
  * @ctrl_domains:      RCU list of all control domains for this resource
  * @mon_domains:       RCU list of all monitor domains for this resource
  * @name:              Name to use in "schemata" file.
- * @default_ctrl:      Specifies default cache cbm or memory B/W percent.
  * @schema_fmt:                Which format string and parser is used for this schema.
  * @evt_list:          List of monitoring events
  * @cdp_capable:       Is the CDP feature available on this resource
@@ -233,7 +232,6 @@ struct rdt_resource {
        struct list_head        ctrl_domains;
        struct list_head        mon_domains;
        char                    *name;
-       u32                     default_ctrl;
        enum resctrl_schema_fmt schema_fmt;
        struct list_head        evt_list;
        bool                    cdp_capable;
@@ -268,6 +266,23 @@ struct resctrl_schema {
        u32                             num_closid;
 };
 
+/**
+ * resctrl_get_default_ctrl() - Return the default control value for this
+ *                              resource.
+ * @r:         The resource whose default control type is queried.
+ */
+static inline u32 resctrl_get_default_ctrl(struct rdt_resource *r)
+{
+       switch (r->schema_fmt) {
+       case RESCTRL_SCHEMA_BITMAP:
+               return BIT_MASK(r->cache.cbm_len) - 1;
+       case RESCTRL_SCHEMA_RANGE:
+               return r->membw.max_bw;
+       }
+
+       return WARN_ON_ONCE(1);
+}
+
 /* The number of closid supported by this resource regardless of CDP */
 u32 resctrl_arch_get_num_closid(struct rdt_resource *r);
 u32 resctrl_arch_system_num_rmid_idx(void);