From: "Moger, Babu" <babu.moger@amd.com>
To: Reinette Chatre <reinette.chatre@intel.com>,
corbet@lwn.net, tglx@linutronix.de, mingo@redhat.com,
bp@alien8.de
Cc: fenghua.yu@intel.com, dave.hansen@linux.intel.com,
x86@kernel.org, hpa@zytor.com, paulmck@kernel.org,
akpm@linux-foundation.org, quic_neeraju@quicinc.com,
rdunlap@infradead.org, damien.lemoal@opensource.wdc.com,
songmuchun@bytedance.com, peterz@infradead.org,
jpoimboe@kernel.org, pbonzini@redhat.com,
chang.seok.bae@intel.com, pawan.kumar.gupta@linux.intel.com,
jmattson@google.com, daniel.sneddon@linux.intel.com,
sandipan.das@amd.com, tony.luck@intel.com, james.morse@arm.com,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
bagasdotme@gmail.com, eranian@google.com,
christophe.leroy@csgroup.eu, jarkko@kernel.org,
adrian.hunter@intel.com, quic_jiles@quicinc.com,
peternewman@google.com
Subject: Re: [PATCH v7 5/8] x86/resctrl: Unwind the errors inside rdt_enable_ctx()
Date: Wed, 16 Aug 2023 13:17:09 -0500 [thread overview]
Message-ID: <1178bf68-f355-1509-0849-b740d2906bae@amd.com> (raw)
In-Reply-To: <42d034d1-1fed-8d3f-a2aa-b9dcc5ea1243@intel.com>
Hi Reinette,
On 8/15/23 17:47, Reinette Chatre wrote:
> Hi Babu,
>
> On 8/11/2023 1:09 PM, Babu Moger wrote:
>> 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.
>>
>> Suggested-by: Reinette Chatre <reinette.chatre@intel.com>
>> Signed-off-by: Babu Moger <babu.moger@amd.com>
>> ---
>> arch/x86/kernel/cpu/resctrl/rdtgroup.c | 44 ++++++++++++++++++++++++--------
>> 1 file changed, 33 insertions(+), 11 deletions(-)
>>
>> diff --git a/arch/x86/kernel/cpu/resctrl/rdtgroup.c b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
>> index 3010e3a1394d..0805fac04401 100644
>> --- a/arch/x86/kernel/cpu/resctrl/rdtgroup.c
>> +++ b/arch/x86/kernel/cpu/resctrl/rdtgroup.c
>> @@ -2377,19 +2377,44 @@ static int mkdir_mondata_all(struct kernfs_node *parent_kn,
>> struct rdtgroup *prgrp,
>> struct kernfs_node **mon_data_kn);
>>
>> +static void rdt_disable_ctx(struct rdt_fs_context *ctx)
>> +{
>> + if (ctx->enable_cdpl2)
>> + resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L2, false);
>> +
>> + if (ctx->enable_cdpl3)
>> + resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L3, false);
>> +
>> + if (ctx->enable_mba_mbps)
>> + set_mba_sc(false);
>> +}
>
> I am not sure if rdt_disable_ctx() should depend on the
> fs context (more later).
>
>> +
>> static int rdt_enable_ctx(struct rdt_fs_context *ctx)
>> {
>> int ret = 0;
>>
>> - if (ctx->enable_cdpl2)
>> + if (ctx->enable_cdpl2) {
>> ret = resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L2, true);
>> + if (ret)
>> + goto out_disable;
>> + }
>>
>> - if (!ret && ctx->enable_cdpl3)
>> + if (ctx->enable_cdpl3) {
>> ret = resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L3, true);
>> + if (ret)
>> + goto out_disable;
>> + }
>>
>> - if (!ret && ctx->enable_mba_mbps)
>> + if (ctx->enable_mba_mbps) {
>> ret = set_mba_sc(true);
>> + if (ret)
>> + goto out_disable;
>> + }
>> +
>> + return 0;
>>
>> +out_disable:
>> + rdt_disable_ctx(ctx);
>> return ret;
>
> This is not the exit pattern we usually follow. Also note
> that it could lead to incorrect behavior if there is an early failure
> in this function but all unwinding would end up being done in
> rdt_disable_ctx() because error unwinding is done based on whether
> a feature _should_ be enabled not whether it was enabled.
Yes. That is correct.
> Could you please instead have direct error handling by only undoing
> what was already done at the time of the error?
Sure.
>
>> }
>>
>> @@ -2497,13 +2522,13 @@ static int rdt_get_tree(struct fs_context *fc)
>> }
>>
>> ret = rdt_enable_ctx(ctx);
>> - if (ret < 0)
>> - goto out_cdp;
>> + if (ret)
>> + goto out;
>>
>> ret = schemata_list_create();
>> if (ret) {
>> schemata_list_destroy();
>> - goto out_mba;
>> + goto out_ctx;
>> }
>>
>> closid_init();
>> @@ -2562,11 +2587,8 @@ static int rdt_get_tree(struct fs_context *fc)
>> kernfs_remove(kn_info);
>> out_schemata_free:
>> schemata_list_destroy();
>> -out_mba:
>> - if (ctx->enable_mba_mbps)
>> - set_mba_sc(false);
>> -out_cdp:
>> - cdp_disable_all();
>> +out_ctx:
>> + rdt_disable_ctx(ctx);
>> out:
>> rdt_last_cmd_clear();
>> mutex_unlock(&rdtgroup_mutex);
>>
>>
>
> rdt_enable_ctx() is called in rdt_get_tree() and thus its work should
> also be cleaned up in rdt_kill_sb(). Note how the cleanup you replace
> here is also duplicated in rdt_kill_sb(), meaning the unwinding continues
> to be open coded and patch #7 propagates this.
> Could rdt_kill_sb() not also call rdt_disable_ctx()? This brings me
> back to the earlier comment about it depending on the fs context. I
> do not know if the context will be valid at this time. I do not
> think that the context is required though it could have no parameters
> and do cleanup as is done at the moment.
At rdt_kill_sb() the fs context is already freed. But, we can call
rdt_disable_ctx() with no parameter. We will have to depend on other
parameters to free the enabled features. We can use the same call both in
rdt_get_tree() (the failure path above) and in rdt_kill_sb().
The function rdt_disable_ctx will look like this.
+static void rdt_disable_ctx(void)
+{
+ if (resctrl_arch_get_cdp_enabled(RDT_RESOURCE_L3))
+ resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L3, false);
+
+ if (resctrl_arch_get_cdp_enabled(RDT_RESOURCE_L2))
+ resctrl_arch_set_cdp_enabled(RDT_RESOURCE_L2, false);
+
+ if (is_mba_sc(&rdt_resources_all[RDT_RESOURCE_MBA].r_resctrl))
+ set_mba_sc(false);
+}
--
Thanks
Babu Moger
next prev parent reply other threads:[~2023-08-16 18:18 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-11 20:08 [PATCH v7 0/8] x86/resctrl: Miscellaneous resctrl features Babu Moger
2023-08-11 20:08 ` [PATCH v7 1/8] x86/resctrl: Add multiple tasks to the resctrl group at once Babu Moger
2023-08-15 22:43 ` Reinette Chatre
2023-08-11 20:08 ` [PATCH v7 2/8] x86/resctrl: Simplify rftype flag definitions Babu Moger
2023-08-11 20:09 ` [PATCH v7 3/8] x86/resctrl: Rename rftype flags for consistency Babu Moger
2023-08-11 20:09 ` [PATCH v7 4/8] x86/resctrl: Add comments on RFTYPE flags hierarchy Babu Moger
2023-08-15 22:45 ` Reinette Chatre
2023-08-16 15:34 ` Moger, Babu
2023-08-16 18:36 ` Reinette Chatre
2023-08-17 14:20 ` Moger, Babu
2023-08-17 15:37 ` Reinette Chatre
2023-08-17 17:07 ` Moger, Babu
2023-08-17 17:42 ` Reinette Chatre
2023-08-17 19:21 ` Moger, Babu
2023-08-11 20:09 ` [PATCH v7 5/8] x86/resctrl: Unwind the errors inside rdt_enable_ctx() Babu Moger
2023-08-15 22:47 ` Reinette Chatre
2023-08-16 18:17 ` Moger, Babu [this message]
2023-08-16 19:07 ` Reinette Chatre
2023-08-17 14:22 ` Moger, Babu
2023-08-11 20:10 ` [PATCH v7 6/8] x86/resctrl: Move default control group creation during mount Babu Moger
2023-08-15 22:50 ` Reinette Chatre
2023-08-16 19:14 ` Moger, Babu
2023-08-16 23:02 ` Reinette Chatre
2023-08-17 14:23 ` Moger, Babu
2023-08-11 20:10 ` [PATCH v7 7/8] x86/resctrl: Introduce "-o debug" mount option Babu Moger
2023-08-15 22:51 ` Reinette Chatre
2023-08-16 19:15 ` Moger, Babu
2023-08-11 20:10 ` [PATCH v7 8/8] x86/resctrl: Display hardware ids of resource groups Babu Moger
2023-08-15 22:52 ` Reinette Chatre
2023-08-17 19:24 ` Moger, Babu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1178bf68-f355-1509-0849-b740d2906bae@amd.com \
--to=babu.moger@amd.com \
--cc=adrian.hunter@intel.com \
--cc=akpm@linux-foundation.org \
--cc=bagasdotme@gmail.com \
--cc=bp@alien8.de \
--cc=chang.seok.bae@intel.com \
--cc=christophe.leroy@csgroup.eu \
--cc=corbet@lwn.net \
--cc=damien.lemoal@opensource.wdc.com \
--cc=daniel.sneddon@linux.intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=eranian@google.com \
--cc=fenghua.yu@intel.com \
--cc=hpa@zytor.com \
--cc=james.morse@arm.com \
--cc=jarkko@kernel.org \
--cc=jmattson@google.com \
--cc=jpoimboe@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=paulmck@kernel.org \
--cc=pawan.kumar.gupta@linux.intel.com \
--cc=pbonzini@redhat.com \
--cc=peternewman@google.com \
--cc=peterz@infradead.org \
--cc=quic_jiles@quicinc.com \
--cc=quic_neeraju@quicinc.com \
--cc=rdunlap@infradead.org \
--cc=reinette.chatre@intel.com \
--cc=sandipan.das@amd.com \
--cc=songmuchun@bytedance.com \
--cc=tglx@linutronix.de \
--cc=tony.luck@intel.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®