From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88B06C38145 for ; Wed, 7 Sep 2022 06:29:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229552AbiIGG3g (ORCPT ); Wed, 7 Sep 2022 02:29:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229771AbiIGG3Z (ORCPT ); Wed, 7 Sep 2022 02:29:25 -0400 Received: from out30-45.freemail.mail.aliyun.com (out30-45.freemail.mail.aliyun.com [115.124.30.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 551FE9E8A1 for ; Tue, 6 Sep 2022 23:29:07 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R301e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045170;MF=xhao@linux.alibaba.com;NM=1;PH=DS;RN=20;SR=0;TI=SMTPD_---0VOwWscf_1662532140; Received: from 30.240.98.182(mailfrom:xhao@linux.alibaba.com fp:SMTPD_---0VOwWscf_1662532140) by smtp.aliyun-inc.com; Wed, 07 Sep 2022 14:29:02 +0800 Message-ID: <33bedd74-a19e-8919-64c3-432c2eaba11d@linux.alibaba.com> Date: Wed, 7 Sep 2022 14:28:59 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.1.2 Subject: Re: [PATCH v6 04/21] x86/resctrl: Group struct rdt_hw_domain cleanup To: James Morse , x86@kernel.org, linux-kernel@vger.kernel.org Cc: Fenghua Yu , Reinette Chatre , Thomas Gleixner , Ingo Molnar , Borislav Petkov , H Peter Anvin , Babu Moger , shameerali.kolothum.thodi@huawei.com, D Scott Phillips OS , lcherian@marvell.com, bobo.shaobowang@huawei.com, tan.shaopeng@fujitsu.com, Jamie Iles , Cristian Marussi , xingxin.hx@openanolis.org, baolin.wang@linux.alibaba.com, xhao@linux.alibaba.com References: <20220902154829.30399-1-james.morse@arm.com> <20220902154829.30399-5-james.morse@arm.com> From: haoxin In-Reply-To: <20220902154829.30399-5-james.morse@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2022/9/2 下午11:48, James Morse 写道: > domain_add_cpu() and domain_remove_cpu() need to kfree() the child > arrays that were allocated by domain_setup_ctrlval(). > > As this memory is moved around, and new arrays are created, adjusting > the error handling cleanup code becomes noisier. > > To simplify this, move all the kfree() calls into a domain_free() helper. > This depends on struct rdt_hw_domain being kzalloc()d, allowing it to > unconditionally kfree() all the child arrays. > > Reviewed-by: Jamie Iles > Tested-by: Xin Hao > Reviewed-by: Shaopeng Tan > Tested-by: Shaopeng Tan > Tested-by: Cristian Marussi > Reviewed-by: Reinette Chatre > Signed-off-by: James Morse > --- > Changes since v2: > * Made domain_free() static. > > Changes since v1: > * This patch is new > --- > arch/x86/kernel/cpu/resctrl/core.c | 17 ++++++++++------- > 1 file changed, 10 insertions(+), 7 deletions(-) > > diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c > index 25f30148478b..e37889f7a1a5 100644 > --- a/arch/x86/kernel/cpu/resctrl/core.c > +++ b/arch/x86/kernel/cpu/resctrl/core.c > @@ -414,6 +414,13 @@ void setup_default_ctrlval(struct rdt_resource *r, u32 *dc, u32 *dm) > } > } > > +static void domain_free(struct rdt_hw_domain *hw_dom) add inline ? > +{ > + kfree(hw_dom->ctrl_val); > + kfree(hw_dom->mbps_val); > + kfree(hw_dom); > +} > + > static int domain_setup_ctrlval(struct rdt_resource *r, struct rdt_domain *d) > { > struct rdt_hw_resource *hw_res = resctrl_to_arch_res(r); > @@ -488,7 +495,7 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r) > rdt_domain_reconfigure_cdp(r); > > if (r->alloc_capable && domain_setup_ctrlval(r, d)) { > - kfree(hw_dom); > + domain_free(hw_dom); > return; > } > > @@ -497,9 +504,7 @@ static void domain_add_cpu(int cpu, struct rdt_resource *r) > err = resctrl_online_domain(r, d); > if (err) { > list_del(&d->list); > - kfree(hw_dom->ctrl_val); > - kfree(hw_dom->mbps_val); > - kfree(hw_dom); > + domain_free(hw_dom); > } > } > > @@ -547,12 +552,10 @@ static void domain_remove_cpu(int cpu, struct rdt_resource *r) > if (d->plr) > d->plr->d = NULL; > > - kfree(hw_dom->ctrl_val); > - kfree(hw_dom->mbps_val); > bitmap_free(d->rmid_busy_llc); > kfree(d->mbm_total); > kfree(d->mbm_local); > - kfree(hw_dom); > + domain_free(hw_dom); > return; > } >