From nobody Mon Feb 9 17:22:58 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E0DF337881F; Tue, 3 Feb 2026 21:47:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770155247; cv=none; b=LjVOFWf5iQbjiEy05EZx4aHPgiJz04+PMGIXoGp83PlN9XAX9IOyW2+Gmk0RLmJjN1akqavTStslgYAkAEMsyR58YhzJ9IeTANOv1ii3IwMVesS5NI477x/DXS7fl4zCpd3W5lLNM93zjlsxGsjPJZ5QpckAMxoslfyTA4a1GLw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770155247; c=relaxed/simple; bh=5g/37QAaXexwTJUI3jXVNNPuepQREqIC+T0Bj70ZzAI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A/FfIZikZLiayXuG8m5yIkB3/o5yj0CT6YwvY10P7giL8rEWN5BWG98F7Z/+qiGQoffasIgS4luDGaCB1mU3oBGf5obZpujvVFU1IPBCi153cVxiXr4u11N4d460UIfWbp78vHDn8xUEYXeupXqzAgK0wh/FTIdJjY22UKWeciU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 27F47339; Tue, 3 Feb 2026 13:47:19 -0800 (PST) Received: from e134344.cambridge.arm.com (e134344.arm.com [10.1.196.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 00DF63F778; Tue, 3 Feb 2026 13:47:19 -0800 (PST) From: Ben Horgan To: ben.horgan@arm.com Cc: amitsinght@marvell.com, baisheng.gao@unisoc.com, baolin.wang@linux.alibaba.com, carl@os.amperecomputing.com, dave.martin@arm.com, david@kernel.org, dfustini@baylibre.com, fenghuay@nvidia.com, gshan@redhat.com, james.morse@arm.com, jonathan.cameron@huawei.com, kobak@nvidia.com, lcherian@marvell.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, peternewman@google.com, punit.agrawal@oss.qualcomm.com, quic_jiles@quicinc.com, reinette.chatre@intel.com, rohit.mathew@arm.com, scott@os.amperecomputing.com, sdonthineni@nvidia.com, tan.shaopeng@fujitsu.com, xhao@linux.alibaba.com, catalin.marinas@arm.com, will@kernel.org, corbet@lwn.net, maz@kernel.org, oupton@kernel.org, joey.gouly@arm.com, suzuki.poulose@arm.com, kvmarm@lists.linux.dev, zengheng4@huawei.com, linux-doc@vger.kernel.org, Shaopeng Tan Subject: [PATCH v4 35/41] arm_mpam: resctrl: Call resctrl_init() on platforms that can support resctrl Date: Tue, 3 Feb 2026 21:43:36 +0000 Message-ID: <20260203214342.584712-36-ben.horgan@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260203214342.584712-1-ben.horgan@arm.com> References: <20260203214342.584712-1-ben.horgan@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: James Morse Now that MPAM links against resctrl, call resctrl_init() to register the filesystem and setup resctrl's structures. Tested-by: Gavin Shan Tested-by: Shaopeng Tan Tested-by: Peter Newman Reviewed-by: Jonathan Cameron Signed-off-by: James Morse Signed-off-by: Ben Horgan --- Changes since v2: Use for_each_mpam... error path tidying Changes since v3: Don't consider abmc in teardown --- drivers/resctrl/mpam_devices.c | 32 ++++++++++++-- drivers/resctrl/mpam_internal.h | 4 ++ drivers/resctrl/mpam_resctrl.c | 76 ++++++++++++++++++++++++++++++++- 3 files changed, 107 insertions(+), 5 deletions(-) diff --git a/drivers/resctrl/mpam_devices.c b/drivers/resctrl/mpam_devices.c index 965384c667f6..6c81821a9a04 100644 --- a/drivers/resctrl/mpam_devices.c +++ b/drivers/resctrl/mpam_devices.c @@ -73,6 +73,14 @@ static DECLARE_WORK(mpam_broken_work, &mpam_disable); /* When mpam is disabled, the printed reason to aid debugging */ static char *mpam_disable_reason; =20 +/* + * Whether resctrl has been setup. Used by cpuhp in preference to + * mpam_is_enabled(). The disable call after an error interrupt makes + * mpam_is_enabled() false before the cpuhp callbacks are made. + * Reads/writes should hold mpam_cpuhp_state_lock, (or be cpuhp callbacks). + */ +static bool mpam_resctrl_enabled; + /* * An MSC is a physical container for controls and monitors, each identifi= ed by * their RIS index. These share a base-address, interrupts and some MMIO @@ -1635,7 +1643,7 @@ static int mpam_cpu_online(unsigned int cpu) mpam_reprogram_msc(msc); } =20 - if (mpam_is_enabled()) + if (mpam_resctrl_enabled) return mpam_resctrl_online_cpu(cpu); =20 return 0; @@ -1681,7 +1689,7 @@ static int mpam_cpu_offline(unsigned int cpu) { struct mpam_msc *msc; =20 - if (mpam_is_enabled()) + if (mpam_resctrl_enabled) mpam_resctrl_offline_cpu(cpu); =20 guard(srcu)(&mpam_srcu); @@ -2543,6 +2551,7 @@ static void mpam_enable_once(void) } =20 static_branch_enable(&mpam_enabled); + mpam_resctrl_enabled =3D true; mpam_register_cpuhp_callbacks(mpam_cpu_online, mpam_cpu_offline, "mpam:online"); =20 @@ -2602,24 +2611,39 @@ static void mpam_reset_class(struct mpam_class *cla= ss) void mpam_disable(struct work_struct *ignored) { int idx; + bool do_resctrl_exit; struct mpam_class *class; struct mpam_msc *msc, *tmp; =20 + if (mpam_is_enabled()) + static_branch_disable(&mpam_enabled); + mutex_lock(&mpam_cpuhp_state_lock); if (mpam_cpuhp_state) { cpuhp_remove_state(mpam_cpuhp_state); mpam_cpuhp_state =3D 0; } + + /* + * Removing the cpuhp state called mpam_cpu_offline() and told resctrl + * all the CPUs are offline. + */ + do_resctrl_exit =3D mpam_resctrl_enabled; + mpam_resctrl_enabled =3D false; mutex_unlock(&mpam_cpuhp_state_lock); =20 - static_branch_disable(&mpam_enabled); + if (do_resctrl_exit) + mpam_resctrl_exit(); =20 mpam_unregister_irqs(); =20 idx =3D srcu_read_lock(&mpam_srcu); list_for_each_entry_srcu(class, &mpam_classes, classes_list, - srcu_read_lock_held(&mpam_srcu)) + srcu_read_lock_held(&mpam_srcu)) { mpam_reset_class(class); + if (do_resctrl_exit) + mpam_resctrl_teardown_class(class); + } srcu_read_unlock(&mpam_srcu, idx); =20 mutex_lock(&mpam_list_lock); diff --git a/drivers/resctrl/mpam_internal.h b/drivers/resctrl/mpam_interna= l.h index 549faa9df0f3..05561d447938 100644 --- a/drivers/resctrl/mpam_internal.h +++ b/drivers/resctrl/mpam_internal.h @@ -431,12 +431,16 @@ int mpam_get_cpumask_from_cache_id(unsigned long cach= e_id, u32 cache_level, =20 #ifdef CONFIG_RESCTRL_FS int mpam_resctrl_setup(void); +void mpam_resctrl_exit(void); int mpam_resctrl_online_cpu(unsigned int cpu); void mpam_resctrl_offline_cpu(unsigned int cpu); +void mpam_resctrl_teardown_class(struct mpam_class *class); #else static inline int mpam_resctrl_setup(void) { return 0; } +static inline void mpam_resctrl_exit(void) { } static inline int mpam_resctrl_online_cpu(unsigned int cpu) { return 0; } static inline void mpam_resctrl_offline_cpu(unsigned int cpu) { } +static inline void mpam_resctrl_teardown_class(struct mpam_class *class) {= } #endif /* CONFIG_RESCTRL_FS */ =20 /* diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c index db1aba14b41d..91e46503c9a5 100644 --- a/drivers/resctrl/mpam_resctrl.c +++ b/drivers/resctrl/mpam_resctrl.c @@ -72,6 +72,12 @@ static bool cdp_enabled; static bool cacheinfo_ready; static DECLARE_WAIT_QUEUE_HEAD(wait_cacheinfo_ready); =20 +/* + * If resctrl_init() succeeded, resctrl_exit() can be used to remove suppo= rt + * for the filesystem in the event of an error. + */ +static bool resctrl_enabled; + /* Whether this num_mbw_mon could result in a free_running system */ static int __mpam_monitors_free_running(u16 num_mbwu_mon) { @@ -333,6 +339,9 @@ static int resctrl_arch_mon_ctx_alloc_no_wait(enum resc= trl_event_id evtid) { struct mpam_resctrl_mon *mon =3D &mpam_resctrl_counters[evtid]; =20 + if (!mpam_is_enabled()) + return -EINVAL; + if (!mon->class) return -EINVAL; =20 @@ -375,6 +384,9 @@ static void resctrl_arch_mon_ctx_free_no_wait(enum resc= trl_event_id evtid, { struct mpam_resctrl_mon *mon =3D &mpam_resctrl_counters[evtid]; =20 + if (!mpam_is_enabled()) + return; + if (!mon->class) return; =20 @@ -469,6 +481,9 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, stru= ct rdt_domain_hdr *hdr, =20 resctrl_arch_rmid_read_context_check(); =20 + if (!mpam_is_enabled()) + return -EINVAL; + if (eventid >=3D QOS_NUM_EVENTS || !mon->class) return -EINVAL; =20 @@ -1313,6 +1328,9 @@ int resctrl_arch_update_one(struct rdt_resource *r, s= truct rdt_ctrl_domain *d, lockdep_assert_cpus_held(); lockdep_assert_irqs_enabled(); =20 + if (!mpam_is_enabled()) + return -EINVAL; + /* * No need to check the CPU as mpam_apply_config() doesn't care, and * resctrl_arch_update_domains() relies on this. @@ -1375,6 +1393,9 @@ int resctrl_arch_update_domains(struct rdt_resource *= r, u32 closid) lockdep_assert_cpus_held(); lockdep_assert_irqs_enabled(); =20 + if (!mpam_is_enabled()) + return -EINVAL; + list_for_each_entry_rcu(d, &r->ctrl_domains, hdr.list) { for (enum resctrl_conf_type t =3D 0; t < CDP_NUM_TYPES; t++) { struct resctrl_staged_config *cfg =3D &d->staged_config[t]; @@ -1763,7 +1784,11 @@ int mpam_resctrl_setup(void) return -EOPNOTSUPP; } =20 - /* TODO: call resctrl_init() */ + err =3D resctrl_init(); + if (err) + return err; + + WRITE_ONCE(resctrl_enabled, true); =20 return 0; =20 @@ -1773,6 +1798,55 @@ int mpam_resctrl_setup(void) return err; } =20 +void mpam_resctrl_exit(void) +{ + if (!READ_ONCE(resctrl_enabled)) + return; + + WRITE_ONCE(resctrl_enabled, false); + resctrl_exit(); +} + +static void mpam_resctrl_teardown_mon(struct mpam_resctrl_mon *mon, struct= mpam_class *class) +{ + u32 num_mbwu_mon =3D resctrl_arch_system_num_rmid_idx(); + + if (!mon->mbwu_idx_to_mon) + return; + + __free_mbwu_mon(class, mon->mbwu_idx_to_mon, num_mbwu_mon); + mon->mbwu_idx_to_mon =3D NULL; +} + +/* + * The driver is detaching an MSC from this class, if resctrl was using it, + * pull on resctrl_exit(). + */ +void mpam_resctrl_teardown_class(struct mpam_class *class) +{ + struct mpam_resctrl_res *res; + enum resctrl_res_level rid; + struct mpam_resctrl_mon *mon; + enum resctrl_event_id eventid; + + might_sleep(); + + for_each_mpam_resctrl_control(res, rid) { + if (res->class =3D=3D class) { + res->class =3D NULL; + break; + } + } + for_each_mpam_resctrl_mon(mon, eventid) { + if (mon->class =3D=3D class) { + mon->class =3D NULL; + + mpam_resctrl_teardown_mon(mon, class); + break; + } + } +} + static int __init __cacheinfo_ready(void) { cacheinfo_ready =3D true; --=20 2.43.0