Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp477357iog; Wed, 29 Jun 2022 04:16:39 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u89ZHDpydrl9Vg7SGpvC4N3xYZpGGe+hP9xakNOOV1/hIjPCheLZaviZm4rGyLKt6uCkxk X-Received: by 2002:a17:902:f7d3:b0:16a:208e:b2c4 with SMTP id h19-20020a170902f7d300b0016a208eb2c4mr9926575plw.64.1656501399196; Wed, 29 Jun 2022 04:16:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656501399; cv=none; d=google.com; s=arc-20160816; b=eljMTowHdscK8IFnyC4hIetOAwYyk7AUPFLolgvH6nqVNRvP1mIxIwJMhDRj/WJmWU xKTpRfhIjpvUhUnOVhx0ucaAdSNuM9q86Abf0LiH+dpEscb0N22arJ+cQcIMxkZX7IgJ sgGGvtdOm2AhNkO9jrKmh4Quh4egHF1tqAhJ1cUKTqWHUj2vKpM0SwAy0GYVGhYm8gxQ CP8HFYzhHzTfII8ozv0X6c0rfLm+RFC2xDgc7+Zlg79o9u8IaguVnfZ1sC3LFEs4Q6N8 GYU7HK/2WyBdNTbeZZSKMzY+Z+mnwqX3lgzBbYjnOvvd/x3Go63UPzNvvAHY7mxKxeEZ XMCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=QWamT3SvP5aGqFGRG12lO8p/R33qwjSLyTGvWivC4x4=; b=gQKbz515G3juZ+qGkHXRqRdeV6RQsco6kqicCpLlFAP6suA8s8+ErvE5r7wvQiIyCa Ovzq/qzRGjeRnAPwd7NgEk4ByQijxO+XhejbejXwLY2MDsNWRTP8LtHnL6+8jsza/wIR nHGt2JBRaP2X4aqo3AJAXc00/TaTPZr15yfJV7pFuCCHmQbHZ+WTVOAbx6TkItc7JEiC pFjYKBbMRjwm3aWoLghXK4ZqDaFgaut7AuMDiU2Rzj55/mhzh3eA4W32u56gZgRWIldk mwIHkmNNl12FBQBFfGK72ghOJWvccYm8uoWMfSAdwnjpSW8sUSws6EEEYCi3uCexsBbk W+Ug== 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=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k193-20020a6284ca000000b00527b95d9959si7380818pfd.161.2022.06.29.04.16.27; Wed, 29 Jun 2022 04:16:39 -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=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231887AbiF2LHd (ORCPT + 99 others); Wed, 29 Jun 2022 07:07:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231787AbiF2LHb (ORCPT ); Wed, 29 Jun 2022 07:07:31 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 006983D482 for ; Wed, 29 Jun 2022 04:07:29 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 98138152B; Wed, 29 Jun 2022 04:07:29 -0700 (PDT) Received: from [10.1.196.218] (eglon.cambridge.arm.com [10.1.196.218]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 21A483F66F; Wed, 29 Jun 2022 04:07:27 -0700 (PDT) Subject: Re: [PATCH v5 04/21] x86/resctrl: Group struct rdt_hw_domain cleanup To: "tan.shaopeng@fujitsu.com" , "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" , Jamie Iles , Cristian Marussi , Xin Hao , "xingxin.hx@openanolis.org" , "baolin.wang@linux.alibaba.com" References: <20220622164629.20795-1-james.morse@arm.com> <20220622164629.20795-5-james.morse@arm.com> From: James Morse Message-ID: <4ae1e6d4-89c9-ee6a-f74f-73fa84b406e5@arm.com> Date: Wed, 29 Jun 2022 12:07:20 +0100 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=iso-2022-jp Content-Language: en-GB Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 Hi Shaopeng, On 29/06/2022 09:33, tan.shaopeng@fujitsu.com wrote: >> 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. >> 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) { >> + 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); > domain_free(hw_dom) is executed when fails allocated hw_dom->ctrl_val > by kmalloc_array() in domain_setup_ctrlval(r, d), > but hw_dom->ctrl_val is freed in domain_free(hw_dom). > > Also, hw_dom->mbps_val is not allocated at this time, > but it is freed in domain_free(hw_dom). Yes, this is deliberate. These cases end up doing: | kfree(NULL); which is harmless. kfree() checks for a NULL argument and does nothing. The alternative would be to spread the cleanup all over the place, so it only calls kfree() on something that has been allocated - this would be more complex and easier to miss something. > In addition,I tested this patch series on Intel(R) Xeon(R) Gold 6254 CPU with resctrl selftest. > It is no problem. Thanks! James