Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp5293682rwb; Tue, 6 Sep 2022 23:54:02 -0700 (PDT) X-Google-Smtp-Source: AA6agR7kEoTIVN9Ek+7wfUPTFgR2mlg01kQK763HtCq0m8bJUtCI+18MQyILaZWwPPeNi5y5P4VD X-Received: by 2002:a17:90b:4d92:b0:1fd:aec0:1c26 with SMTP id oj18-20020a17090b4d9200b001fdaec01c26mr2342089pjb.133.1662533642314; Tue, 06 Sep 2022 23:54:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662533642; cv=none; d=google.com; s=arc-20160816; b=ZYUHDrZo0HJwBvQGnPwO7ePQ1sg97DOJwvN44bK2sivGQTLrUj8zZuI5WULXvi0G1P t7gUmw30PVcSSWIsbTLLYmziZYxlmG3BWV+U0zjszi/NK5+ue9zrsrzryhvqqaDFFR9P QOMcghwuLUFi3vHJ4dApyi30pnncoDH9jX+LN59St8v2kOWeGuIZXg4YIPWg+QwE3aYP xe26iKU4gUsfxjc2jCAmLSJAmpMoLonhaGichYRea1Lp2c1CwO8CaBM14VrkLonMt7Y7 yYazHkT5dwHtRQxcX1DZkSbUldG5I3ATkl68di52KrOF61wdIR35LFUmPqmXjJP4koGh 8YRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=pIeRt4aqkTIwohEph6rFlYEqZb0S9mcQxw+fPj6W72E=; b=BGBh9cTJnwI1c1yK+4K67Xc0BvqNQqZqrvjD6tdKFQnZBBDAfrX6OZPcfxs9OcHko6 owodrYg6ihaNzMUqGrKrV59My9WMyXMWahm81ZXZHVQ5dHF9ptUAIB4F9BWZ8snagpwp kjQokhvLyQHJhRAKyQSKY35mlGpnMXuIYPX3cadgaz2gSlW2WLNrP0m38DWTctM6aoW6 lFpha4J0lMxnR4nRtIsMYn1130twDNZPpGpJmCx6mfUqPbz48KPYKivT/v4kfdm79i0o 6DeOrBmys++Gn0vhE0p962VDkEb0GlFvzsiFXR5sNWC2urDR1ZcQ5UtbwO+tQn/TPl8o B1EA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e2-20020a17090a4a0200b001fdf5fec918si15173048pjh.25.2022.09.06.23.53.51; Tue, 06 Sep 2022 23:54:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229948AbiIGG3e (ORCPT + 99 others); Wed, 7 Sep 2022 02:29:34 -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 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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; > } >