Received: by 2002:a05:7412:518d:b0:e2:908c:2ebd with SMTP id fn13csp444320rdb; Thu, 5 Oct 2023 10:16:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGjoaG75FN+xAdLg8tqfC5VORMncLpWiBSf76akkPr1LdggMkq1kLgQRtEMELWa6VmEyR19 X-Received: by 2002:a05:6a20:12c1:b0:154:e7e6:85bd with SMTP id v1-20020a056a2012c100b00154e7e685bdmr6599554pzg.20.1696526181913; Thu, 05 Oct 2023 10:16:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696526181; cv=none; d=google.com; s=arc-20160816; b=qwHXRufAplOw2uuxHVggSBDcd/1aylMA3M/mNtTQ6innSpgV4of1+FBeHQVOoN78pI 6gaMTUjzTF5Rghh0tDVNcs22+Y1bkhYFZDYuv9iF2ixeaIszundCo/ljewrlGArgFHb0 mLb7Q+BsBYbGUBnetVRoXRJJlEu2y4sqXoKmGbXZVabWuuVzVf75yZ29zzawoB+QNJ2X PCORxqwTsSIToy2Lvq+wEHz1CGQl5Wj9nlDq1ZlL3b1ww6N0Ll65A4sl7o+ZR61Pk10I pVgwsN8hdnbaM4/GL8ulzOixg7tdw1XAGF86idSlo2qE8IUtAKj0vHP7pJa+IhCNQW6y jYjw== 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:content-language:subject:user-agent:mime-version :date:message-id; bh=kLvEqasxF6d9wwXhBm/fHOYi8FTOP0Kv+2jur4WOMuw=; fh=9O97hdzEezSdAQ/hEUF6K6/7TfN/3Uf0QBPpPtoaJ2Y=; b=n6AtXXayjxwcqjTval0lXREh/15WDcJwI6tvMoAatmgXmv3hG1yz+JAOZMhQLs/98O 6hxdzR9gwFyJNXAUJsMW2j6+734dO6pipvuPUMchdvs2LBDg/CJZawAcc62+gSv5ae6v KdS6EYhOjvuj567qSVAU8SUoLEWJEccxSdsqaSuTUBJ0wU7JOZq7om2ZCUAsSCnTDI0L SiByuPIlZ2FwsmiyIVH3AZUK0yv06XISzLOP+YzURRr2DnAAYWjrQdxraPfMjqI0lAPi 6sMINaVnuOu+rJN/bda9rJO9uFYLM0ZmWqJC9zxFjV96EWEJeTyZWC1k9oa6MEvEKxuf 6QBg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id c9-20020a056a00248900b0068e4c3f3ac2si1840411pfv.245.2023.10.05.10.16.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 10:16:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 4F30A807C57E; Thu, 5 Oct 2023 10:16:10 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229939AbjJERP3 (ORCPT + 99 others); Thu, 5 Oct 2023 13:15:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231248AbjJEROy (ORCPT ); Thu, 5 Oct 2023 13:14:54 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 523B5359D for ; Thu, 5 Oct 2023 10:06: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 CB946C15; Thu, 5 Oct 2023 10:07:07 -0700 (PDT) Received: from [10.1.197.60] (eglon.cambridge.arm.com [10.1.197.60]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 467903F5A1; Thu, 5 Oct 2023 10:06:26 -0700 (PDT) Message-ID: Date: Thu, 5 Oct 2023 18:06:19 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH v6 02/24] x86/resctrl: kfree() rmid_ptrs from rdtgroup_exit() Content-Language: en-GB To: babu.moger@amd.com, x86@kernel.org, linux-kernel@vger.kernel.org Cc: Fenghua Yu , Reinette Chatre , Thomas Gleixner , Ingo Molnar , Borislav Petkov , H Peter Anvin , shameerali.kolothum.thodi@huawei.com, D Scott Phillips OS , carl@os.amperecomputing.com, lcherian@marvell.com, bobo.shaobowang@huawei.com, tan.shaopeng@fujitsu.com, xingxin.hx@openanolis.org, baolin.wang@linux.alibaba.com, Jamie Iles , Xin Hao , peternewman@google.com, dfustini@baylibre.com, amitsinght@marvell.com References: <20230914172138.11977-1-james.morse@arm.com> <20230914172138.11977-3-james.morse@arm.com> <7f95e9c8-73a6-4ccd-97e4-0d3723fbeafb@amd.com> From: James Morse In-Reply-To: <7f95e9c8-73a6-4ccd-97e4-0d3723fbeafb@amd.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.3 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 05 Oct 2023 10:16:11 -0700 (PDT) Hi Babu, On 04/10/2023 19:00, Moger, Babu wrote: > On 9/14/23 12:21, James Morse wrote: >> rmid_ptrs[] is allocated from dom_data_init() but never free()d. >> >> While the exit text ends up in the linker script's DISCARD section, >> the direction of travel is for resctrl to be/have loadable modules. >> >> Add resctrl_exit_mon_l3_config() to cleanup any memory allocated >> by rdt_get_mon_l3_config(). >> >> There is no reason to backport this to a stable kernel. >> diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h >> index 85ceaf9a31ac..57cf1e6a57bd 100644 >> --- a/arch/x86/kernel/cpu/resctrl/internal.h >> +++ b/arch/x86/kernel/cpu/resctrl/internal.h >> @@ -537,6 +537,7 @@ void closid_free(int closid); >> int alloc_rmid(void); >> void free_rmid(u32 rmid); >> int rdt_get_mon_l3_config(struct rdt_resource *r); >> +void resctrl_exit_mon_l3_config(struct rdt_resource *r); >> bool __init rdt_cpu_has(int flag); >> void mon_event_count(void *info); >> int rdtgroup_mondata_show(struct seq_file *m, void *arg); >> diff --git a/arch/x86/kernel/cpu/resctrl/monitor.c b/arch/x86/kernel/cpu/resctrl/monitor.c >> index ded1fc7cb7cb..cfb3f632a4b2 100644 >> --- a/arch/x86/kernel/cpu/resctrl/monitor.c >> +++ b/arch/x86/kernel/cpu/resctrl/monitor.c >> @@ -741,6 +741,16 @@ static int dom_data_init(struct rdt_resource *r) >> return 0; >> } >> >> +void resctrl_exit_mon_l3_config(struct rdt_resource *r) >> +{ >> + mutex_lock(&rdtgroup_mutex); >> + >> + kfree(rmid_ptrs); >> + rmid_ptrs = NULL; >> + >> + mutex_unlock(&rdtgroup_mutex); >> +} > What is the need for passing "rdt_resource *r" here? My vain belief that monitors should be supported on something other than L3, but I agree that isn't what resctrl does today. I'll remove it. > Is mutex_lock required? Reads and writes to rmid_ptrs[] are protected by that lock. This ensures no-one reads the value while its being free()d, and after this function releases the lock, anyone trying sees NULL. (This is all moot as its only caller is marked __exit, so gets discarded by the linker) Thanks, James