From nobody Thu Apr 2 16:14:50 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8339CC001B5 for ; Fri, 2 Sep 2022 15:55:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237604AbiIBPz4 (ORCPT ); Fri, 2 Sep 2022 11:55:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237524AbiIBPys (ORCPT ); Fri, 2 Sep 2022 11:54:48 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E2A3E2BDD for ; Fri, 2 Sep 2022 08:49:15 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8B1DB15BF; Fri, 2 Sep 2022 08:49:21 -0700 (PDT) Received: from merodach.members.linode.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 045C83F766; Fri, 2 Sep 2022 08:49:12 -0700 (PDT) From: James Morse To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: Fenghua Yu , Reinette Chatre , Thomas Gleixner , Ingo Molnar , Borislav Petkov , H Peter Anvin , Babu Moger , James Morse , shameerali.kolothum.thodi@huawei.com, D Scott Phillips OS , lcherian@marvell.com, bobo.shaobowang@huawei.com, tan.shaopeng@fujitsu.com, Jamie Iles , Cristian Marussi , Xin Hao , xingxin.hx@openanolis.org, baolin.wang@linux.alibaba.com Subject: [PATCH v6 08/21] x86/resctrl: Create mba_sc configuration in the rdt_domain Date: Fri, 2 Sep 2022 15:48:16 +0000 Message-Id: <20220902154829.30399-9-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220902154829.30399-1-james.morse@arm.com> References: <20220902154829.30399-1-james.morse@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" To support resctrl's MBA software controller, the architecture must provide a second configuration array to hold the mbps_val[] from user-space. This complicates the interface between the architecture specific code and the filesystem portions of resctrl that will move to /fs/, to allow multiple architectures to support resctrl. Make the filesystem parts of resctrl create an array for the mba_sc values. The software controller can be changed to use this, allowing the architecture code to only consider the values configured in hardware. Reviewed-by: Jamie Iles Tested-by: Xin Hao Reviewed-by: Shaopeng Tan Tested-by: Shaopeng Tan Tested-by: Cristian Marussi Reviewed-by: Reinette Chatre Signed-off-by: James Morse --- Changes since v4: * Use supports_mba_mbps() in resctrl_{on,off}line_domain(). * Don't call mba_sc_domain_destroy() for error handling - it can't happen. * Whitespace. Changes since v3: * Always allocate the array. * Move the array allocation above the r->mon_capable check. Changes since v2: * Split patch in two, the liftime parts are a separate patch. * Added reset in set_mba_sc() now that we can't depend on the lifetime. * Initialise ret in mba_sc_allocate(), * Made mbps_val allocation/freeing symmetric for cpuhp calls. * Removed reference to squashed-out struct. * Preserved kerneldoc for mbps_val. Changes since v1: * Added missing error handling to mba_sc_domain_allocate() in domain_setup_mon_state() * Added comment about mba_sc_domain_allocate() races * Squashed out struct resctrl_mba_sc * Moved mount time alloc/free calls to set_mba_sc(). * Removed mount check in resctrl_offline_domain() * Reword commit message --- arch/x86/kernel/cpu/resctrl/internal.h | 1 - arch/x86/kernel/cpu/resctrl/rdtgroup.c | 39 ++++++++++++++++++++++++++ include/linux/resctrl.h | 7 +++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/r= esctrl/internal.h index e12b55f815bf..a7e2cbce29d5 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -36,7 +36,6 @@ #define MBM_OVERFLOW_INTERVAL 1000 #define MAX_MBA_BW 100u #define MBA_IS_LINEAR 0x4 -#define MBA_MAX_MBPS U32_MAX #define MAX_MBA_BW_AMD 0x800 #define MBM_CNTR_WIDTH_OFFSET_AMD 20 =20 diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/r= esctrl/rdtgroup.c index 4ee26264ecfc..f7ebd019e7a5 100644 --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c @@ -1889,6 +1889,30 @@ void rdt_domain_reconfigure_cdp(struct rdt_resource = *r) l3_qos_cfg_update(&hw_res->cdp_enabled); } =20 +static int mba_sc_domain_allocate(struct rdt_resource *r, struct rdt_domai= n *d) +{ + u32 num_closid =3D resctrl_arch_get_num_closid(r); + int cpu =3D cpumask_any(&d->cpu_mask); + int i; + + d->mbps_val =3D kcalloc_node(num_closid, sizeof(*d->mbps_val), + GFP_KERNEL, cpu_to_node(cpu)); + if (!d->mbps_val) + return -ENOMEM; + + for (i =3D 0; i < num_closid; i++) + d->mbps_val[i] =3D MBA_MAX_MBPS; + + return 0; +} + +static void mba_sc_domain_destroy(struct rdt_resource *r, + struct rdt_domain *d) +{ + kfree(d->mbps_val); + d->mbps_val =3D NULL; +} + /* * MBA software controller is supported only if * MBM is supported and MBA is in linear scale. @@ -1908,12 +1932,20 @@ static bool supports_mba_mbps(void) static int set_mba_sc(bool mba_sc) { struct rdt_resource *r =3D &rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl; + u32 num_closid =3D resctrl_arch_get_num_closid(r); + struct rdt_domain *d; + int i; =20 if (!supports_mba_mbps() || mba_sc =3D=3D is_mba_sc(r)) return -EINVAL; =20 r->membw.mba_sc =3D mba_sc; =20 + list_for_each_entry(d, &r->domains, list) { + for (i =3D 0; i < num_closid; i++) + d->mbps_val[i] =3D MBA_MAX_MBPS; + } + return 0; } =20 @@ -3247,6 +3279,9 @@ void resctrl_offline_domain(struct rdt_resource *r, s= truct rdt_domain *d) { lockdep_assert_held(&rdtgroup_mutex); =20 + if (supports_mba_mbps() && r->rid =3D=3D RDT_RESOURCE_MBA) + mba_sc_domain_destroy(r, d); + if (!r->mon_capable) return; =20 @@ -3311,6 +3346,10 @@ int resctrl_online_domain(struct rdt_resource *r, st= ruct rdt_domain *d) =20 lockdep_assert_held(&rdtgroup_mutex); =20 + if (supports_mba_mbps() && r->rid =3D=3D RDT_RESOURCE_MBA) + /* RDT_RESOURCE_MBA is never mon_capable */ + return mba_sc_domain_allocate(r, d); + if (!r->mon_capable) return 0; =20 diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h index 5d283bdd6162..93dfe553b364 100644 --- a/include/linux/resctrl.h +++ b/include/linux/resctrl.h @@ -15,6 +15,9 @@ int proc_resctrl_show(struct seq_file *m, =20 #endif =20 +/* max value for struct rdt_domain's mbps_val */ +#define MBA_MAX_MBPS U32_MAX + /** * enum resctrl_conf_type - The type of configuration. * @CDP_NONE: No prioritisation, both code and data are controlled or moni= tored. @@ -53,6 +56,9 @@ struct resctrl_staged_config { * @cqm_work_cpu: worker CPU for CQM h/w counters * @plr: pseudo-locked region (if any) associated with domain * @staged_config: parsed configuration to be applied + * @mbps_val: When mba_sc is enabled, this holds the array of user + * specified control values for mba_sc in MBps, indexed + * by closid */ struct rdt_domain { struct list_head list; @@ -67,6 +73,7 @@ struct rdt_domain { int cqm_work_cpu; struct pseudo_lock_region *plr; struct resctrl_staged_config staged_config[CDP_NUM_TYPES]; + u32 *mbps_val; }; =20 /** --=20 2.30.2