linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Reinette Chatre <reinette.chatre@intel.com>
To: Babu Moger <babu.moger@amd.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: Tue, 15 Aug 2023 15:47:02 -0700	[thread overview]
Message-ID: <42d034d1-1fed-8d3f-a2aa-b9dcc5ea1243@intel.com> (raw)
In-Reply-To: <169178459367.1147205.14975628669652538089.stgit@bmoger-ubuntu>

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.
Could you please instead have direct error handling by only undoing
what was already done at the time of the error?

>  }
>  
> @@ -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.

Reinette

  reply	other threads:[~2023-08-15 22:48 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 [this message]
2023-08-16 18:17     ` Moger, Babu
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=42d034d1-1fed-8d3f-a2aa-b9dcc5ea1243@intel.com \
    --to=reinette.chatre@intel.com \
    --cc=adrian.hunter@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=babu.moger@amd.com \
    --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=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;
as well as URLs for NNTP newsgroup(s).