Skip to content

Commit d27567a

Browse files
babumogerbp3tk0v
authored andcommitted
x86/resctrl: Move default group file creation to mount
The default resource group and its files are created during kernel init time. Upcoming changes will make some resctrl files optional based on a mount parameter. If optional files are to be added to the default group based on the mount option, then each new file needs to be created separately and call kernfs_activate() again. Create all files of the default resource group during resctrl mount, destroyed during unmount, to avoid scattering resctrl file addition across two separate code flows. Signed-off-by: Babu Moger <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Peter Newman <[email protected]> Reviewed-by: Tan Shaopeng <[email protected]> Reviewed-by: Fenghua Yu <[email protected]> Reviewed-by: Reinette Chatre <[email protected]> Reviewed-by: Ilpo Järvinen <[email protected]> Tested-by: Peter Newman <[email protected]> Tested-by: Tan Shaopeng <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent df5f3a1 commit d27567a

File tree

1 file changed

+34
-24
lines changed

1 file changed

+34
-24
lines changed

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

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ static struct kernfs_node *kn_mondata;
5454
static struct seq_buf last_cmd_status;
5555
static char last_cmd_status_buf[512];
5656

57+
static int rdtgroup_setup_root(struct rdt_fs_context *ctx);
58+
static void rdtgroup_destroy_root(void);
59+
5760
struct dentry *debugfs_resctrl;
5861

5962
void rdt_last_cmd_clear(void)
@@ -2529,10 +2532,14 @@ static int rdt_get_tree(struct fs_context *fc)
25292532
goto out;
25302533
}
25312534

2532-
ret = rdt_enable_ctx(ctx);
2535+
ret = rdtgroup_setup_root(ctx);
25332536
if (ret)
25342537
goto out;
25352538

2539+
ret = rdt_enable_ctx(ctx);
2540+
if (ret)
2541+
goto out_root;
2542+
25362543
ret = schemata_list_create();
25372544
if (ret) {
25382545
schemata_list_destroy();
@@ -2541,6 +2548,12 @@ static int rdt_get_tree(struct fs_context *fc)
25412548

25422549
closid_init();
25432550

2551+
ret = rdtgroup_add_files(rdtgroup_default.kn, RFTYPE_CTRL_BASE);
2552+
if (ret)
2553+
goto out_schemata_free;
2554+
2555+
kernfs_activate(rdtgroup_default.kn);
2556+
25442557
ret = rdtgroup_create_info_dir(rdtgroup_default.kn);
25452558
if (ret < 0)
25462559
goto out_schemata_free;
@@ -2597,6 +2610,8 @@ static int rdt_get_tree(struct fs_context *fc)
25972610
schemata_list_destroy();
25982611
out_ctx:
25992612
rdt_disable_ctx();
2613+
out_root:
2614+
rdtgroup_destroy_root();
26002615
out:
26012616
rdt_last_cmd_clear();
26022617
mutex_unlock(&rdtgroup_mutex);
@@ -2667,7 +2682,6 @@ static int rdt_init_fs_context(struct fs_context *fc)
26672682
if (!ctx)
26682683
return -ENOMEM;
26692684

2670-
ctx->kfc.root = rdt_root;
26712685
ctx->kfc.magic = RDTGROUP_SUPER_MAGIC;
26722686
fc->fs_private = &ctx->kfc;
26732687
fc->ops = &rdt_fs_context_ops;
@@ -2837,6 +2851,7 @@ static void rdt_kill_sb(struct super_block *sb)
28372851
rdt_pseudo_lock_release();
28382852
rdtgroup_default.mode = RDT_MODE_SHAREABLE;
28392853
schemata_list_destroy();
2854+
rdtgroup_destroy_root();
28402855
static_branch_disable_cpuslocked(&rdt_alloc_enable_key);
28412856
static_branch_disable_cpuslocked(&rdt_mon_enable_key);
28422857
static_branch_disable_cpuslocked(&rdt_enable_key);
@@ -3718,17 +3733,29 @@ static struct kernfs_syscall_ops rdtgroup_kf_syscall_ops = {
37183733
.show_options = rdtgroup_show_options,
37193734
};
37203735

3721-
static int __init rdtgroup_setup_root(void)
3736+
static int rdtgroup_setup_root(struct rdt_fs_context *ctx)
37223737
{
3723-
int ret;
3724-
37253738
rdt_root = kernfs_create_root(&rdtgroup_kf_syscall_ops,
37263739
KERNFS_ROOT_CREATE_DEACTIVATED |
37273740
KERNFS_ROOT_EXTRA_OPEN_PERM_CHECK,
37283741
&rdtgroup_default);
37293742
if (IS_ERR(rdt_root))
37303743
return PTR_ERR(rdt_root);
37313744

3745+
ctx->kfc.root = rdt_root;
3746+
rdtgroup_default.kn = kernfs_root_to_node(rdt_root);
3747+
3748+
return 0;
3749+
}
3750+
3751+
static void rdtgroup_destroy_root(void)
3752+
{
3753+
kernfs_destroy_root(rdt_root);
3754+
rdtgroup_default.kn = NULL;
3755+
}
3756+
3757+
static void __init rdtgroup_setup_default(void)
3758+
{
37323759
mutex_lock(&rdtgroup_mutex);
37333760

37343761
rdtgroup_default.closid = 0;
@@ -3738,19 +3765,7 @@ static int __init rdtgroup_setup_root(void)
37383765

37393766
list_add(&rdtgroup_default.rdtgroup_list, &rdt_all_groups);
37403767

3741-
ret = rdtgroup_add_files(kernfs_root_to_node(rdt_root), RFTYPE_CTRL_BASE);
3742-
if (ret) {
3743-
kernfs_destroy_root(rdt_root);
3744-
goto out;
3745-
}
3746-
3747-
rdtgroup_default.kn = kernfs_root_to_node(rdt_root);
3748-
kernfs_activate(rdtgroup_default.kn);
3749-
3750-
out:
37513768
mutex_unlock(&rdtgroup_mutex);
3752-
3753-
return ret;
37543769
}
37553770

37563771
static void domain_destroy_mon_state(struct rdt_domain *d)
@@ -3872,13 +3887,11 @@ int __init rdtgroup_init(void)
38723887
seq_buf_init(&last_cmd_status, last_cmd_status_buf,
38733888
sizeof(last_cmd_status_buf));
38743889

3875-
ret = rdtgroup_setup_root();
3876-
if (ret)
3877-
return ret;
3890+
rdtgroup_setup_default();
38783891

38793892
ret = sysfs_create_mount_point(fs_kobj, "resctrl");
38803893
if (ret)
3881-
goto cleanup_root;
3894+
return ret;
38823895

38833896
ret = register_filesystem(&rdt_fs_type);
38843897
if (ret)
@@ -3911,8 +3924,6 @@ int __init rdtgroup_init(void)
39113924

39123925
cleanup_mountpoint:
39133926
sysfs_remove_mount_point(fs_kobj, "resctrl");
3914-
cleanup_root:
3915-
kernfs_destroy_root(rdt_root);
39163927

39173928
return ret;
39183929
}
@@ -3922,5 +3933,4 @@ void __exit rdtgroup_exit(void)
39223933
debugfs_remove_recursive(debugfs_resctrl);
39233934
unregister_filesystem(&rdt_fs_type);
39243935
sysfs_remove_mount_point(fs_kobj, "resctrl");
3925-
kernfs_destroy_root(rdt_root);
39263936
}

0 commit comments

Comments
 (0)