From nobody Wed Sep 30 09:03:22 2026 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 2D9FB370AE3; Thu, 13 Aug 2026 03:50:09 +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=1786593012; cv=none; b=egykkP3J+T+pyyQKOMzVYT6tUuwuHZxHHuW5xNbIsYusa5wpYurOqqRACCqu946wDLXWh/QODh8B3ped3IiFS39AsO8rgL0dk3I+POsYhsgaqBbaZu3tAfYkhJlBjdoIu9LPLs8MbhYEnp46bcB0lXFY/fhWUNpVydln9KLWG6s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786593012; c=relaxed/simple; bh=mj11QH1OehidAc4GPX+bN8d559dYdSB4IO5jIUf5aNc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CiiDARyYiHzNa7McNt6zeQT0b0rPBdCE9zsEBzd+w6+DMFvert7W9U9BVi4vjyekxIT1G09kpaSn1q3vRjcVNaNSB/3y8Ske1n5dXMbael2BIIodGx7MLYNhTMcwEY8LHdIrK19jCiAmK/JzIr5JkW4v3HNTyTPBQh8/54AhryM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iJoGGSdG; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iJoGGSdG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C05661F00A3D; Thu, 13 Aug 2026 03:50:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1786593008; bh=c9oXf7EAMULfNbhY5cYkXmrBshcuP/mpp00wWMiTWfA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=iJoGGSdGaEjb4GhhyfrN/DoXc4RJ8drILlJO9rtj/6VSiBf5E350SajVv0HD7Dsn/ kivaaLfRnNabpYQPi1uHU6nMutuuSvoqzhK3UieLdJb2v4whSYLf1pHgqRbXfa93mv rgpFFMK25+A76cfUDRiOlFBnP+eL42WhFwclzR6QhI2VcA0Su7ANfIzoNn60XU2M9s xNQ+I+bJWMBVoky87N81qfDWJ1hV4tdhdX2Dn/XyaY79wNvlioBm1tQllB643agRp1 EuQS5htblur55P9VnQEqKfOdOvJ8T3cKDxlboiZfngUq+6msFNHcPF5zbsVniw3rNi uh0OLA851Hvjw== From: SJ Park To: Cc: SJ Park , Andrew Morton , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 1/4] mm/damon/core: handle NULL ctx parameter in damon_call() Date: Wed, 12 Aug 2026 20:49:56 -0700 Message-ID: <20260813035001.97364-2-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260813035001.97364-1-sj@kernel.org> References: <20260813035001.97364-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When NULL damon_ctx pointer parameter is passed, damon_call() could do NULL dereference. The caller is responsible to avoid that. It is easy to forget, and there are many damon_call() callers. Meanwhile, damon_call() is never meant to be performance critical. It uses mutex and completion. Add the NULL pointer check inside damon_call() so that callers can pass the parameter without NULL checks. Signed-off-by: SJ Park --- mm/damon/core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/damon/core.c b/mm/damon/core.c index 92631a36d7b51..5882f9c94c47f 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -2188,6 +2188,8 @@ int damon_kdamond_pid(struct damon_ctx *ctx) */ int damon_call(struct damon_ctx *ctx, struct damon_call_control *control) { + if (!ctx) + return -EINVAL; if (!control->repeat) init_completion(&control->completion); control->canceled =3D false; --=20 2.47.3 From nobody Wed Sep 30 09:03:22 2026 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 32883370D47; Thu, 13 Aug 2026 03:50:09 +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=1786593013; cv=none; b=EZtfgefvv6UHp9/U16K4aCt0O0diLetsfM/+4Y99jiKO1zNkR00bCXIk0IVSkjv4r8b/xHDhZzf9VPOcBsgdKS6ymDUKOyExMllhYHGF//enuJk47aWIkT+757S0sK70rP7fIvVUWA4RBW81lblbeXXExmB7QARLOMbPJliI1Gw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786593013; c=relaxed/simple; bh=IzZH0KLtVQFZQRWLGKYTWw1G13IZ+dPrZMm6NGIzIUI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XGeACiVO2ORbnpHnoV0EWaaImd6oGX+MHIIUZyV6Rg9WT4kmYqkxUHZemuxPOYUbw+MHgXm9DTETKQstk/bg8KocZWPFtQUHGb+1fKuNVN3eOqs3J9rPV1aqextNUu2TKHRHAAjq/VFagrsQDOlgz6/rkZPS4pd+QzlvuqqRd+8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=H3FcusnP; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="H3FcusnP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19D4A1F00A3A; Thu, 13 Aug 2026 03:50:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1786593009; bh=AIpHwpSSS3esAV2BDnJ9BAffq+YFA4gOCk++VRGi3uY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=H3FcusnPSKD7eR3+hfvXu3GeDcUbm4gEBBey02p7UEbMUK8JxSmPyxQ3dGc+w2QaZ cte+MAnkoXvhiDbEXJjXUnEk9/Fy1NjaOzEqwHbCB3kouVGJIJrfdLBxnWtKVG9dks rsblvXbYZkHeHuqoZQ8sgz43sSUPnuJipKzBiRFEkPFfs9IBMXxMH1VHeDWJ/NwR1C bRUF6UHU4GNXneoDX+kDjGI5le4gJu+lTfNUmLYFSKHWoCweehU2zj/AK0yF67uV1J FDQ/mbmNjXRSR6wz2F41lTL02PLhwFguE9mPamMVlXP1+VJ2mxxPn2IXUKE1e9iv/A l6eIobiGU0wDA== From: SJ Park To: Cc: SJ Park , Andrew Morton , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 2/4] mm/damon/core: set ctx->call_controls_obsolete in damon_new_ctx() Date: Wed, 12 Aug 2026 20:49:57 -0700 Message-ID: <20260813035001.97364-3-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260813035001.97364-1-sj@kernel.org> References: <20260813035001.97364-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" damon_ctx->call_controls_obsolete is used to disallow damon_call() requests when the request cannot be served. The field is unset and set when the context execution is started and terminated, respectively. The intention is to allow damon_call() requests only while the context is actively being executed. damon_ctx constructor, damon_new_ctx() unsets the field, though. As a result, passing the damon_ctx parameter that never successfully damon_start()-ed to damon_call() can indefinitely hang. The callers should ensure to avoid the case. Such parameter validation is not always simple. Actually such bugs in DAMON_RECLAIM and DAMON_LRU_SORT have been found and fixed [1]. Set the field in damon_new_ctx(), so that DAMON API callers can pass the context parameter to damon_call() without the additional check. [1] https://lore.kernel.org/20260803134646.16640-1-sj@kernel.org Signed-off-by: SJ Park --- mm/damon/core.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 5882f9c94c47f..5a92e4fac6d92 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -920,6 +920,7 @@ struct damon_ctx *damon_new_ctx(void) INIT_LIST_HEAD(&ctx->adaptive_targets); INIT_LIST_HEAD(&ctx->schemes); =20 + ctx->call_controls_obsolete =3D true; prandom_seed_state(&ctx->rnd_state, get_random_u64()); =20 return ctx; @@ -2178,10 +2179,6 @@ int damon_kdamond_pid(struct damon_ctx *ctx) * synchronization. The return value of the function will be saved in * &damon_call_control->return_code. * - * Note that this function should be called only after damon_start() with = the - * @ctx has succeeded. Otherwise, this function could fall into an indefi= nite - * wait. - * * When this function is failed, the @ctx is guaranteed to be stopped. * * Return: 0 on success, negative error code otherwise. --=20 2.47.3 From nobody Wed Sep 30 09:03:22 2026 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 301B03612E8; Thu, 13 Aug 2026 03:50:10 +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=1786593013; cv=none; b=Xc3Rx71QsGKgptOpz3koyqo63wrfEy9/Q/tkP0Ll+7KFlw99nPFOtrualPYE2Ppec3IkquBLC+AnWrJ3045mrDOFpHMViwtoeLoi+w7vXg6ULHpzbJ1jfmNzfb7No5rEybgJe+RFYloAvjAclF1uhmeBBc63U0rFOelKTakzfRo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786593013; c=relaxed/simple; bh=wAZLCviLOkwAGlvhZFB48gga6WtfFacHiZ14c/z8NiE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ds8cokYh9NZBFzRJvTMxuwD7VtzMhv4qJIC2aaoOjhr2ZkDjvpc/nrpLCRjcLYISiLhIVfGaTwX6AzNOTm0I9KW5uZK+JFaykuS6uk//TQG4ePFi+AZStvh5fV3OgyHGURqUiSf7RIwOHW4ipTWCgqCV2nLOhR0OZ56mXJTsWN4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZOj3dCJ/; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZOj3dCJ/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A9CF1F00A3E; Thu, 13 Aug 2026 03:50:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1786593009; bh=bFqUVYf2n04Uixau/NkzvcP/6puf0JnXDQxViDXP7BQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ZOj3dCJ/1d3ON081pPcVJreuyCmWBp+g9lWZeT672RpxyAgNE0u/xEa0VbttpZVSB RXQi/h/A/XyUh6lqJXEMCowjcMLF9EvJsIFKiUx0o+LFheHNXSrZ4Jr5aTOUdnmEOw 0966Xms2D6m+ziu5O+Z75zFAdTnDlx0BybIKL6n0gJWTFRVK94enFhCM+1o1HJyHGO Weo4J041qAte4Gawte5oeZ2B298hmFP0Dg9/IB8mowtQHU+w+550V3OWS3vBqp4Zo8 282vrVqncGxGDbyZtUGyenSjZQwvewRbSRsW+qT3+0MgNgerYhRkYk0RfspjGKVS+X jtrvCMexIeW3g== From: SJ Park To: Cc: SJ Park , Andrew Morton , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 3/4] mm/damon/reclaim: remove unnecessary damon_call() param validation Date: Wed, 12 Aug 2026 20:49:58 -0700 Message-ID: <20260813035001.97364-4-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260813035001.97364-1-sj@kernel.org> References: <20260813035001.97364-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" DAMON_RECLAIM avoids passing NULL or unstarted damon_ctx to damon_call() with its own validation. The validation is no longer needed, because the DAMON core layer now handles the corner cases itself. Remove the unnecessary check. Signed-off-by: SJ Park --- mm/damon/reclaim.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c index 45d5557cc575a..42a2c9cb13431 100644 --- a/mm/damon/reclaim.c +++ b/mm/damon/reclaim.c @@ -271,8 +271,6 @@ static int damon_reclaim_commit_inputs_fn(void *arg) return damon_reclaim_apply_parameters(); } =20 -static bool damon_reclaim_damon_has_started; - static int damon_reclaim_commit_inputs_store(const char *val, const struct kernel_param *kp) { @@ -293,10 +291,6 @@ static int damon_reclaim_commit_inputs_store(const cha= r *val, if (!commit_inputs_request) return 0; =20 - /* Skip damon_call() if ctx has not successfully started. */ - if (!damon_reclaim_damon_has_started) - return -EINVAL; - err =3D damon_call(ctx, &control); =20 return err ? err : control.return_code; @@ -343,8 +337,6 @@ static int damon_reclaim_turn(bool on) err =3D damon_start(&ctx, 1, true); if (err) return err; - if (!damon_reclaim_damon_has_started) - damon_reclaim_damon_has_started =3D true; return damon_call(ctx, &call_control); } =20 --=20 2.47.3 From nobody Wed Sep 30 09:03:22 2026 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 B156533E34E; Thu, 13 Aug 2026 03:50:11 +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=1786593014; cv=none; b=SbnNKj9WgX8ssjBURTpCZP7Y3TuX4DxcQtvd9v9xvbFp9MnDcF1HQa40hHoK8hVKo5ekyr4tEY8cVquDajYLLj/ESUZCdCUJeooXKMcMOeBhQ77VVmUggXGBN4HuRIssmq+h2+0Kw7aMAx4/hbouz03RDrYtMDdaQrjrdi1WflA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786593014; c=relaxed/simple; bh=+w3rxutfnYBNIul7l279XZJ8W0YahLijvuvU2FVYbRw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kb1i4efsSIgB4lHa4F5I35xR18wCEC2kOsLSr4iJFjpggowTWT2XDF8kqYSdqhziM/ZgfCUHX5PlLjxjzXlsMVDb3cvOJDkvPHu+jnGlIraZUekjxhlAEh7KKJ9ynxu3XlbxEBgHQ2ge8jamg9M9+2l48ztzkBs9wjzLnsq2RK8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=d6KR54/r; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="d6KR54/r" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC7E21F00A3F; Thu, 13 Aug 2026 03:50:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1786593009; bh=a+KFNc38yAs5cF8y2PPkR2gfi2v/4V0wSG+v466VkTs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=d6KR54/rLJ6ePQb83TqoNr8jusNymXRiNaj14b1zv8TRr3k3J+ryDyr8d+rkhKygi U5fDBygBfVu0bhTdsz8bB7ZbWwyHPexkewIv2J+VKov83KofK4K59jFtdBY7PLpGzO um5jy0k/35nTdRW0wblktzbuZZ6qAoNe4cjdyMyrvtAiGNNsxDMCZg9rk8mDiu5Nyg orXJhay8agEVn6stcxkWGnoR+cnU1isxlDgl3uo+7xddVNIfJUqlVH+cDMo65LXzas ZLzRUvAr16bExumbamKbgV7i9en9Wb0VrlFc71DF9occwI+Dkz9q6Ki9S6wzaMa4A1 o1aVT6ZpO8Kqw== From: SJ Park To: Cc: SJ Park , Andrew Morton , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 4/4] mm/damon/lru_sort: remove unnecessary damon_call() param validation Date: Wed, 12 Aug 2026 20:49:59 -0700 Message-ID: <20260813035001.97364-5-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260813035001.97364-1-sj@kernel.org> References: <20260813035001.97364-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" DAMON_LRU_SORT avoids passing NULL or unstarted damon_ctx to damon_call() with its own validation. The validation is no longer needed, because the DAMON core layer now handles the corner cases itself. Remove the unnecessary check. Signed-off-by: SJ Park --- mm/damon/lru_sort.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c index bd847829a9907..f25ee7326e87c 100644 --- a/mm/damon/lru_sort.c +++ b/mm/damon/lru_sort.c @@ -346,8 +346,6 @@ static int damon_lru_sort_commit_inputs_fn(void *arg) return damon_lru_sort_apply_parameters(); } =20 -static bool damon_lru_sort_damon_has_started; - static int damon_lru_sort_commit_inputs_store(const char *val, const struct kernel_param *kp) { @@ -368,10 +366,6 @@ static int damon_lru_sort_commit_inputs_store(const ch= ar *val, if (!commit_inputs_request) return 0; =20 - /* Skip damon_call() if ctx has not successfully started. */ - if (!damon_lru_sort_damon_has_started) - return -EINVAL; - err =3D damon_call(ctx, &control); =20 return err ? err : control.return_code; @@ -422,8 +416,6 @@ static int damon_lru_sort_turn(bool on) err =3D damon_start(&ctx, 1, true); if (err) return err; - if (!damon_lru_sort_damon_has_started) - damon_lru_sort_damon_has_started =3D true; return damon_call(ctx, &call_control); } =20 --=20 2.47.3