Skip to content

Commit df5f3a1

Browse files
babumogerbp3tk0v
authored andcommitted
x86/resctrl: Unwind properly from rdt_enable_ctx()
rdt_enable_ctx() enables the features provided during resctrl mount. Additions to rdt_enable_ctx() are required to also modify error paths of rdt_enable_ctx() callers to ensure correct unwinding if errors are encountered after calling rdt_enable_ctx(). This is error prone. Introduce rdt_disable_ctx() to refactor the error unwinding of rdt_enable_ctx() to simplify future additions. This also simplifies cleanup in rdt_kill_sb(). Suggested-by: Reinette Chatre <[email protected]> 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 d415924 commit df5f3a1

File tree

1 file changed

+32
-21
lines changed

1 file changed

+32
-21
lines changed

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

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,14 +2308,6 @@ int resctrl_arch_set_cdp_enabled(enum resctrl_res_level l, bool enable)
23082308
return 0;
23092309
}
23102310

2311-
static void cdp_disable_all(void)
2312-
{
2313-
if (resctrl_arch_get_cdp_enabled(RDT_RESOURCE_L3))
2314-
resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L3, false);
2315-
if (resctrl_arch_get_cdp_enabled(RDT_RESOURCE_L2))
2316-
resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L2, false);
2317-
}
2318-
23192311
/*
23202312
* We don't allow rdtgroup directories to be created anywhere
23212313
* except the root directory. Thus when looking for the rdtgroup
@@ -2395,19 +2387,42 @@ static int mkdir_mondata_all(struct kernfs_node *parent_kn,
23952387
struct rdtgroup *prgrp,
23962388
struct kernfs_node **mon_data_kn);
23972389

2390+
static void rdt_disable_ctx(void)
2391+
{
2392+
resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L3, false);
2393+
resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L2, false);
2394+
set_mba_sc(false);
2395+
}
2396+
23982397
static int rdt_enable_ctx(struct rdt_fs_context *ctx)
23992398
{
24002399
int ret = 0;
24012400

2402-
if (ctx->enable_cdpl2)
2401+
if (ctx->enable_cdpl2) {
24032402
ret = resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L2, true);
2403+
if (ret)
2404+
goto out_done;
2405+
}
24042406

2405-
if (!ret && ctx->enable_cdpl3)
2407+
if (ctx->enable_cdpl3) {
24062408
ret = resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L3, true);
2409+
if (ret)
2410+
goto out_cdpl2;
2411+
}
24072412

2408-
if (!ret && ctx->enable_mba_mbps)
2413+
if (ctx->enable_mba_mbps) {
24092414
ret = set_mba_sc(true);
2415+
if (ret)
2416+
goto out_cdpl3;
2417+
}
2418+
2419+
return 0;
24102420

2421+
out_cdpl3:
2422+
resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L3, false);
2423+
out_cdpl2:
2424+
resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L2, false);
2425+
out_done:
24112426
return ret;
24122427
}
24132428

@@ -2515,13 +2530,13 @@ static int rdt_get_tree(struct fs_context *fc)
25152530
}
25162531

25172532
ret = rdt_enable_ctx(ctx);
2518-
if (ret < 0)
2519-
goto out_cdp;
2533+
if (ret)
2534+
goto out;
25202535

25212536
ret = schemata_list_create();
25222537
if (ret) {
25232538
schemata_list_destroy();
2524-
goto out_mba;
2539+
goto out_ctx;
25252540
}
25262541

25272542
closid_init();
@@ -2580,11 +2595,8 @@ static int rdt_get_tree(struct fs_context *fc)
25802595
kernfs_remove(kn_info);
25812596
out_schemata_free:
25822597
schemata_list_destroy();
2583-
out_mba:
2584-
if (ctx->enable_mba_mbps)
2585-
set_mba_sc(false);
2586-
out_cdp:
2587-
cdp_disable_all();
2598+
out_ctx:
2599+
rdt_disable_ctx();
25882600
out:
25892601
rdt_last_cmd_clear();
25902602
mutex_unlock(&rdtgroup_mutex);
@@ -2816,12 +2828,11 @@ static void rdt_kill_sb(struct super_block *sb)
28162828
cpus_read_lock();
28172829
mutex_lock(&rdtgroup_mutex);
28182830

2819-
set_mba_sc(false);
2831+
rdt_disable_ctx();
28202832

28212833
/*Put everything back to default values. */
28222834
for_each_alloc_capable_rdt_resource(r)
28232835
reset_all_ctrls(r);
2824-
cdp_disable_all();
28252836
rmdir_all_sub();
28262837
rdt_pseudo_lock_release();
28272838
rdtgroup_default.mode = RDT_MODE_SHAREABLE;

0 commit comments

Comments
 (0)