Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6846338rdb; Fri, 15 Dec 2023 09:44:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IG52tgZ4AJl4LI5P/n+8zkhvKm5WvZLQJ+forCYXl6b09L5c7tUj/WeUWan2Z8MyXUp3dPI X-Received: by 2002:a05:620a:165b:b0:77f:3da8:89b6 with SMTP id c27-20020a05620a165b00b0077f3da889b6mr9555239qko.24.1702662289174; Fri, 15 Dec 2023 09:44:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702662289; cv=none; d=google.com; s=arc-20160816; b=NvmT6aIoQwgN6IYGbmZ+oHMpBPuJEuXTR7ZRFsgezV6OuRF2NYwlvRWT094PjsUfar vd+khhrfOgEntOtNUitkY4w3Z8CYRT6Si1iPCCCOUDSPPE9261obGawLQOCa4RHVrCma mW7m+3fwlIiWmI+DJlQ654tUor7P++92majUNxuPUUdho9wV+aoMc/bEfeH5yDjZdF8k wbTwE9CT18R0m2HpOidPBMnQsdfJKpunh4oKCSnySWWHNNYt1b5MtJ9M3h4ggbgW3Kmk UEI1lB/Pbkrd0/ZSwUzNMGCK93sQWf9JEWN1lPUzZRVpxz8/xUdbZ26ZIb3wtjimatms q+Bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=ZQ3+aSiL5tK7P5UJRbtyyZOfm4lpewO3DctFnYM6gUM=; fh=B41BSS80/g48MVbql1jW7CCXTAGMSWslnmHIfPLpVL4=; b=AhkPumi0vNTEe4Mi9TBTGQqLPF9aZrL6oWy2z4iQuAHlDZeS8P7N+6+fvBpwESJ9rs XPn919nCvHCGYYl9eaADWYm5ksNLNzbXXQuxb5IlbEgGz9Pe/oboQ1n5Zry/vTwxiV3N t8LykkvTxmjmHsD0ecoJN0Z8Z4jUQxyYb1xi9Mlx0IynGbr/FUnSmAP2qgwPr3jkxHTf 3ro6OaB1X0eRzgTNnuhbJpS+vumJknq8hMCn8Agdud2HLy4cCakYeIUjBiUT9IbQ9TIl 9KT9TiYRcRsE/6M9ZC2H6DZfu1YwkkH1zyvFPcSprAbyIyX8Mlgct+xi/tE4MRw2qD5b +7bQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-1441-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1441-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id h4-20020a05620a284400b0077f039bb628si18526018qkp.422.2023.12.15.09.44.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 09:44:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-1441-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-1441-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1441-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 564161C24588 for ; Fri, 15 Dec 2023 17:44:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1D0D182ECD; Fri, 15 Dec 2023 17:44:11 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4E81930130 for ; Fri, 15 Dec 2023 17:44:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 E040115DB; Fri, 15 Dec 2023 09:44:53 -0800 (PST) Received: from merodach.members.linode.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E32A63F5A1; Fri, 15 Dec 2023 09:44:05 -0800 (PST) From: James Morse To: x86@kernel.org, linux-kernel@vger.kernel.org Cc: Fenghua Yu , Reinette Chatre , Thomas Gleixner , Ingo Molnar , Borislav Petkov , H Peter Anvin , Babu Moger , James Morse , shameerali.kolothum.thodi@huawei.com, D Scott Phillips OS , carl@os.amperecomputing.com, lcherian@marvell.com, bobo.shaobowang@huawei.com, tan.shaopeng@fujitsu.com, baolin.wang@linux.alibaba.com, Jamie Iles , Xin Hao , peternewman@google.com, dfustini@baylibre.com, amitsinght@marvell.com, Babu Moger Subject: [PATCH v8 02/24] x86/resctrl: kfree() rmid_ptrs from resctrl_exit() Date: Fri, 15 Dec 2023 17:43:21 +0000 Message-Id: <20231215174343.13872-3-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20231215174343.13872-1-james.morse@arm.com> References: <20231215174343.13872-1-james.morse@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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_put_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. Signed-off-by: James Morse Tested-by: Babu Moger Reviewed-by: Babu Moger --- Changes since v5: * This patch is new Changes since v6: * Removed struct rdt_resource argument, added __exit markers to match the only caller. * Adedd a whole stack of functions to maintain symmetry. Changes since v7: * Moved the eventual kfree() call to be after rdtgroup_exit() --- arch/x86/kernel/cpu/resctrl/core.c | 6 ++++++ arch/x86/kernel/cpu/resctrl/internal.h | 1 + arch/x86/kernel/cpu/resctrl/monitor.c | 15 +++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c index 19e0681f0435..b5d4b76f97c5 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -992,8 +992,14 @@ late_initcall(resctrl_late_init); static void __exit resctrl_exit(void) { + struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_L3].r_resctrl; + cpuhp_remove_state(rdt_online); + rdtgroup_exit(); + + if (r->mon_capable) + rdt_put_mon_l3_config(r); } __exitcall(resctrl_exit); diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h index a4f1aa15f0a2..f68c6aecfa66 100644 --- a/arch/x86/kernel/cpu/resctrl/internal.h +++ b/arch/x86/kernel/cpu/resctrl/internal.h @@ -546,6 +546,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 __exit rdt_put_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 f136ac046851..5d9864919f1c 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; } +static void __exit dom_data_exit(struct rdt_resource *r) +{ + mutex_lock(&rdtgroup_mutex); + + kfree(rmid_ptrs); + rmid_ptrs = NULL; + + mutex_unlock(&rdtgroup_mutex); +} + static struct mon_evt llc_occupancy_event = { .name = "llc_occupancy", .evtid = QOS_L3_OCCUP_EVENT_ID, @@ -830,6 +840,11 @@ int __init rdt_get_mon_l3_config(struct rdt_resource *r) return 0; } +void __exit rdt_put_mon_l3_config(struct rdt_resource *r) +{ + dom_data_exit(r); +} + void __init intel_rdt_mbm_apply_quirk(void) { int cf_index; -- 2.20.1