Skip to content

Commit 13e5769

Browse files
James Morsebp3tk0v
authored andcommitted
x86/resctrl: Make resctrl_mounted checks explicit
The rdt_enable_key is switched when resctrl is mounted, and used to prevent a second mount of the filesystem. It also enables the architecture's context switch code. This requires another architecture to have the same set of static keys, as resctrl depends on them too. The existing users of these static keys are implicitly also checking if the filesystem is mounted. Make the resctrl_mounted checks explicit: resctrl can keep track of whether it has been mounted once. This doesn't need to be combined with whether the arch code is context switching the CLOSID. rdt_mon_enable_key is never used just to test that resctrl is mounted, but does also have this implication. Add a resctrl_mounted to all uses of rdt_mon_enable_key. This will allow the static key changing to be moved behind resctrl_arch_ calls. Signed-off-by: James Morse <james.morse@arm.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Shaopeng Tan <tan.shaopeng@fujitsu.com> Reviewed-by: Reinette Chatre <reinette.chatre@intel.com> Reviewed-by: Babu Moger <babu.moger@amd.com> Tested-by: Shaopeng Tan <tan.shaopeng@fujitsu.com> Tested-by: Peter Newman <peternewman@google.com> Tested-by: Babu Moger <babu.moger@amd.com> Tested-by: Carl Worth <carl@os.amperecomputing.com> # arm64 Link: https://lore.kernel.org/r/20240213184438.16675-17-james.morse@arm.com Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
1 parent e557999 commit 13e5769

3 files changed

Lines changed: 28 additions & 8 deletions

File tree

arch/x86/kernel/cpu/resctrl/internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ extern bool rdt_alloc_capable;
144144
extern bool rdt_mon_capable;
145145
extern unsigned int rdt_mon_features;
146146
extern struct list_head resctrl_schema_all;
147+
extern bool resctrl_mounted;
147148

148149
enum rdt_group_type {
149150
RDTCTRL_GROUP = 0,

arch/x86/kernel/cpu/resctrl/monitor.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,11 @@ void mbm_handle_overflow(struct work_struct *work)
813813

814814
mutex_lock(&rdtgroup_mutex);
815815

816-
if (!static_branch_likely(&rdt_mon_enable_key))
816+
/*
817+
* If the filesystem has been unmounted this work no longer needs to
818+
* run.
819+
*/
820+
if (!resctrl_mounted || !static_branch_likely(&rdt_mon_enable_key))
817821
goto out_unlock;
818822

819823
r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
@@ -846,7 +850,11 @@ void mbm_setup_overflow_handler(struct rdt_domain *dom, unsigned long delay_ms)
846850
unsigned long delay = msecs_to_jiffies(delay_ms);
847851
int cpu;
848852

849-
if (!static_branch_likely(&rdt_mon_enable_key))
853+
/*
854+
* When a domain comes online there is no guarantee the filesystem is
855+
* mounted. If not, there is no need to catch counter overflow.
856+
*/
857+
if (!resctrl_mounted || !static_branch_likely(&rdt_mon_enable_key))
850858
return;
851859
cpu = cpumask_any_housekeeping(&dom->cpu_mask);
852860
dom->mbm_work_cpu = cpu;

arch/x86/kernel/cpu/resctrl/rdtgroup.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ LIST_HEAD(rdt_all_groups);
4242
/* list of entries for the schemata file */
4343
LIST_HEAD(resctrl_schema_all);
4444

45+
/* The filesystem can only be mounted once. */
46+
bool resctrl_mounted;
47+
4548
/* Kernel fs node for "info" directory under root */
4649
static struct kernfs_node *kn_info;
4750

@@ -881,7 +884,7 @@ int proc_resctrl_show(struct seq_file *s, struct pid_namespace *ns,
881884
mutex_lock(&rdtgroup_mutex);
882885

883886
/* Return empty if resctrl has not been mounted. */
884-
if (!static_branch_unlikely(&rdt_enable_key)) {
887+
if (!resctrl_mounted) {
885888
seq_puts(s, "res:\nmon:\n");
886889
goto unlock;
887890
}
@@ -2608,7 +2611,7 @@ static int rdt_get_tree(struct fs_context *fc)
26082611
/*
26092612
* resctrl file system can only be mounted once.
26102613
*/
2611-
if (static_branch_unlikely(&rdt_enable_key)) {
2614+
if (resctrl_mounted) {
26122615
ret = -EBUSY;
26132616
goto out;
26142617
}
@@ -2669,8 +2672,10 @@ static int rdt_get_tree(struct fs_context *fc)
26692672
if (rdt_mon_capable)
26702673
static_branch_enable_cpuslocked(&rdt_mon_enable_key);
26712674

2672-
if (rdt_alloc_capable || rdt_mon_capable)
2675+
if (rdt_alloc_capable || rdt_mon_capable) {
26732676
static_branch_enable_cpuslocked(&rdt_enable_key);
2677+
resctrl_mounted = true;
2678+
}
26742679

26752680
if (is_mbm_enabled()) {
26762681
r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl;
@@ -2944,6 +2949,7 @@ static void rdt_kill_sb(struct super_block *sb)
29442949
static_branch_disable_cpuslocked(&rdt_alloc_enable_key);
29452950
static_branch_disable_cpuslocked(&rdt_mon_enable_key);
29462951
static_branch_disable_cpuslocked(&rdt_enable_key);
2952+
resctrl_mounted = false;
29472953
kernfs_kill_sb(sb);
29482954
mutex_unlock(&rdtgroup_mutex);
29492955
cpus_read_unlock();
@@ -3913,7 +3919,7 @@ void resctrl_offline_domain(struct rdt_resource *r, struct rdt_domain *d)
39133919
* If resctrl is mounted, remove all the
39143920
* per domain monitor data directories.
39153921
*/
3916-
if (static_branch_unlikely(&rdt_mon_enable_key))
3922+
if (resctrl_mounted && static_branch_unlikely(&rdt_mon_enable_key))
39173923
rmdir_mondata_subdir_allrdtgrp(r, d->id);
39183924

39193925
if (is_mbm_enabled())
@@ -3990,8 +3996,13 @@ int resctrl_online_domain(struct rdt_resource *r, struct rdt_domain *d)
39903996
if (is_llc_occupancy_enabled())
39913997
INIT_DELAYED_WORK(&d->cqm_limbo, cqm_handle_limbo);
39923998

3993-
/* If resctrl is mounted, add per domain monitor data directories. */
3994-
if (static_branch_unlikely(&rdt_mon_enable_key))
3999+
/*
4000+
* If the filesystem is not mounted then only the default resource group
4001+
* exists. Creation of its directories is deferred until mount time
4002+
* by rdt_get_tree() calling mkdir_mondata_all().
4003+
* If resctrl is mounted, add per domain monitor data directories.
4004+
*/
4005+
if (resctrl_mounted && static_branch_unlikely(&rdt_mon_enable_key))
39954006
mkdir_mondata_subdir_allrdtgrp(r, d);
39964007

39974008
return 0;

0 commit comments

Comments
 (0)