From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4624756C639; Wed, 9 Sep 2026 14:15:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788963352; cv=none; b=Cg5WuLHR654oYWyPQEc+La2OsDbJu0JrKHt96hw1phLJ9YC4mjoxK79EjpDZW7Kq1bo8yhllRizCnx+LZPkiFBeHgKg9957I+TaiY/D5nxq9biSiRjE8mm2EKJWNDCa5YpcZ8/cJqo0N3CNphf4S7EnWLFvyCgIfCzj9tACzx/M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788963352; c=relaxed/simple; bh=g9uL3ZLTCJ5GthZ2DCkDOFpHAVF4HwbyddtXtOzGEjc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FVRkrpA1NQt8Y23uq233HaJmsHeUQlLlDRBmS/v1hG7t1rUT9OvffF7Xw1S35kbKVBn+mR3gd3AoWfD6b89lF5yNraUnPm9htFLxhMyJLvxOeIq0Y+RoE8ic5UZLfnuXZt/YB/VSf6JSFm5ZK/rvjNkq2lE06ReVquyUkdntkbg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=gcIUP7LU; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="gcIUP7LU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9DE1A1F00A3A; Wed, 9 Sep 2026 14:15:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1788963351; bh=OgQJyGBULoV43YbODd11YHDE+VD5MOs/yUwAR4OnrUA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gcIUP7LUY6vmPPzZRW5s9eiiIXKSd6Xfr/ZHU62MGmgIK1ShiM2efT79Lckzu2n/j o0jKuRk432TGgsq1Gp08g73aNc8xPvcVtmSrp7a1v9F+Uhe+orP3i7+tIKyQAlOitR 4kq9g94FmbrLiEM62eY5fL6DhVtNuv+R3HLnQvaA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, SJ Park , Zenghui Yu , Andrew Morton Subject: [PATCH 6.18 050/583] samples/damon/prcl: handle damon_start() failure Date: Wed, 9 Sep 2026 15:35:35 +0200 Message-ID: <20260909134239.696498985@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260909134237.773280130@linuxfoundation.org> References: <20260909134237.773280130@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: SJ Park commit 8b724349229bb6ebbf781178be011ba9bc2cca57 upstream. damon_sample_prcl_start() callers assume it will clean up resources when it fails. And the function does the cleanup for context buildup failures. However, it is not doing the cleanup for damon_start() failure. As a result, when damon_start() fails, it leaks the memory for DAMON context. Free the context in case of the failure to fix the issues. Note that the issue can reliably be reproduced because the module calls damon_start() in the exclusive mode. For example, $ sudo damo start $ echo $$ | sudo tee /sys/module/damon_sample_prcl/parameters/target_pid $ echo Y | sudo tee /sys/module/damon_sample_prcl/parameters/enabled $ sudo cat /proc/allocinfo | grep damon_new_ctx Because the first command is running another DAMON instance, the third command fails the damon_start() call because the new DAMON instance cannot exclusively run. And without this fix, by repeating the third and the fourth commands above, we can show the memory consumption is only increasing due to the leaks. It requires the sudo permission though. The issue was discovered [1] by Sashiko. Link: https://lore.kernel.org/20260628215447.96166-3-sj@kernel.org Link: https://lore.kernel.org/20260609145814.70163-1-sj@kernel.org [1] Fixes: 2aca254620a8 ("samples/damon: introduce a skeleton of a smaple DAMON module for proactive reclamation") Signed-off-by: SJ Park Reviewed-by: Zenghui Yu Cc: # 6.14.x Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- samples/damon/prcl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/samples/damon/prcl.c +++ b/samples/damon/prcl.c @@ -106,8 +106,10 @@ static int damon_sample_prcl_start(void) damon_set_schemes(ctx, &scheme, 1); err = damon_start(&ctx, 1, true); - if (err) + if (err) { + damon_destroy_ctx(ctx); return err; + } repeat_call_control.data = ctx; return damon_call(ctx, &repeat_call_control);