From nobody Sat Sep 26 08:37:12 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 BF39726ED46; Thu, 3 Sep 2026 01:03:42 +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=1788397423; cv=none; b=hT2ZhTp+J9iCHMtbTXxV6k1NU9do5pjqFXjb9BKJHZuo8Z+i1zrSqXHC0dPwPug2ns2JFHc05iCNFCuP8jjwuG/pQ3rp1+EWmT1I67smejemZVOAyIOIf4ewt2qoA66MOLo1ZGLRl9lq/qOQbDrfG46dDfFE7/cLkVgB9LEG2Fs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788397423; c=relaxed/simple; bh=4n2JrDaXTq+2UkFHl6GafHQBO+bShXu/XQEgbt/9mkA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QrbwlVvvMIBc69xM+cTUM2TDVqzNZPpJWhq6u2Go7JOqWZ03oDSO8NAuoxEMGEOjzgFVwt1uDKi1Z0Ibu1zVZsqYSCqt4oHUkpgCtixrZXwcJItNLuBgjl89fFpSCCP8bCUU78dRKlbzxNTs1pBZqGtPZ7gMIyrqlr8gs2flH+k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JxkebG5+; 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="JxkebG5+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6EB0C1F00A3E; Thu, 3 Sep 2026 01:03:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788397422; bh=IGhJqVBSrLsY1DzUKQNwEOVO0mpPemu5G2qZNzm4L3A=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=JxkebG5+E8aGwnRfz/OniYrZag3n4/XPkJqX5Tm87e4rNVmo6wdRr90sWwcjiQVBN 9Zq4LsUbD6kBbBE0PPZbanuKErFKPRY7yaqR8fwJkwlmqcLccHiPSpvtphAAjFpHn6 h0RJYVerE0G4KsesZiqoRlgb+QTaoU2r8xHAoE/NPmKpBrkz2BVx8wzcWz1mU55FUV 5VTEewVF9LnBXMXV6cV19OI/+B3qPjyCGD3syTkbYprtTZQLOptL4ULZVFIJVG7vql lUlllxycWVippoZ+v0yTHSX689mOWA1MSTm/hT0u8RUFTFWbUNE1agPI5DQTAK9djK KJVd6fB6wp9tw== From: SJ Park To: Andrew Morton Cc: SJ Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 1/4] mm/damon/core: handle NULL ctx parameter in damon_call() Date: Wed, 2 Sep 2026 18:03:30 -0700 Message-ID: <20260903010334.93622-2-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260903010334.93622-1-sj@kernel.org> References: <20260903010334.93622-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 85d29c76c00cf..03407cf7f9646 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -2206,6 +2206,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 Sat Sep 26 08:37:12 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 56ECA2BEC3F; Thu, 3 Sep 2026 01:03:43 +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=1788397424; cv=none; b=ebe//plXEYNP6xxR+8p4aph3b881ZkI8FydiW7NJQOEZi9UBc+f1R++egX3A9I6uz5FOAZEJw47nxyxVr20bFcOUHwf8Oc6Gt+AmkpXJRRisj3ERG0PZ4d3lcF2051ki59+qop0gDBfdjlv8gyGYrZWAb8RHhPIhFjNxMvboscQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788397424; c=relaxed/simple; bh=Slv7pumsn2CC0X+FQYZYLR2zRF9nh++Owdrkmb+6U+E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mbGNm0EqWEBwSmxX5eiwx+EJv0OF+E45/WyIxcdzT7XRnKPoGAklToEDJArxX4kb1KSd+2rF0uLIc6shlMQXFDX1OYWZNCy6ciC7vXIqAAOV7mnPw+kwfhOQRb+m9EpONdgL1a/8xcRYr8LZIGwFQBUkbNIaA1eaK/yZ0uokAL0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nn7Rv6iv; 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="nn7Rv6iv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BEA3B1F00A3D; Thu, 3 Sep 2026 01:03:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788397422; bh=HJD5ZHvDFQYZJci1lPr3K8KnFdwPjoFcLlwtAdnyK30=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=nn7Rv6ivC7Qq3N9Q2O4N+b11S4V40oQFQ1DMEUSOc/E3rrnbSK2u4VNh6NhBmDPbJ 10Ukb3Lr8fBfgKaWUKILYwqQM2xEtwj+SXDP67kxC8hzc3zbqD3/4VSn81ZZjJRLrZ Cg8UWDcIFvnQvHzeDr3NRAxkhCur9GAkwDSf+jvuKvuI23a0nQ6M+4PCJDags8pRss G2bG6mEdeZboujbyG+BAjbPvX/AlPm3V6ATtCQ0zhBLQ5lE/BJ6dT+D575csVvzD1w JL2pDlVCrXMyWoHhdoCJCvucgWP4w0Q6jIhN/vArJy/0JN4Qult420Z7OgKRbdNpk8 jUH2cCJd61QaA== From: SJ Park To: Andrew Morton Cc: SJ Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 2/4] mm/damon/core: set ctx->call_controls_obsolete in damon_new_ctx() Date: Wed, 2 Sep 2026 18:03:31 -0700 Message-ID: <20260903010334.93622-3-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260903010334.93622-1-sj@kernel.org> References: <20260903010334.93622-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 03407cf7f9646..56ec6f616fa9a 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -933,6 +933,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; @@ -2196,10 +2197,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 Sat Sep 26 08:37:12 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 56E4C29898F; Thu, 3 Sep 2026 01:03:43 +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=1788397424; cv=none; b=ekSbxE/zziJSWz80YSCwLM3u3W7mLNHpxbkMty5TxYl4/g6aR0agYg1WsCUrjGtcUb4jcnbPwMnz3gXRDWQ+zheAf/WjyyZWClmA958HrIJs0bbA5S3uhPLScjTLyP4ylO+fKCTH9R8PnCH/8jHrntf4o8tA/n3i+m45/zOddmw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788397424; c=relaxed/simple; bh=wAZLCviLOkwAGlvhZFB48gga6WtfFacHiZ14c/z8NiE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gWGy/YEtI58cOkBlG4Mekgimwx5/XsVx0WSskBr2pHnOMXoif/MFYc2Y1fAUqaJ8fEQNNLgi7Lk6fTyZEy/ElCa5kU0K9ji1pgUU42B6JK1H0Bg67e8ZBO7rxGD1It/eTrn1GwYmA1Sq+bm2Jaw/XVe3h5NdPkvSP4biRp5soAU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=W21hnb7e; 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="W21hnb7e" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 16CB21F00A3F; Thu, 3 Sep 2026 01:03:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788397423; bh=bFqUVYf2n04Uixau/NkzvcP/6puf0JnXDQxViDXP7BQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=W21hnb7eXdHFi5C1WDTJxhG7jrXJ3GRTxTkW9kXHLAflDXVKTfvdNeQzKfzYZJDIM OkyuKIY20zYacrL6Y26G9sSwNzVPZ4nvRHrnky32h5IIPr/oVwCa2C/PZzglsSq35q i2VcWvgmSs40pPuPwUtSTJMM1UPrOr00aRXUPck0Uz10xwYvokDhPHA22vBhQuwKYl Seudwxv3FLimUuSQindVD9+RBkBQpqcL2X/K11Y8AgJo9aX4/KSeFiVA/HMxNUFXnE 2dXpn67RadvEj2yUpBivnV2xL+IaInOeiH0beKyN1yX8XsbBl8W2eOWka1L608IIm/ 64zleUSZnJ+6g== From: SJ Park To: Andrew Morton Cc: SJ Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 3/4] mm/damon/reclaim: remove unnecessary damon_call() param validation Date: Wed, 2 Sep 2026 18:03:32 -0700 Message-ID: <20260903010334.93622-4-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260903010334.93622-1-sj@kernel.org> References: <20260903010334.93622-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 Sat Sep 26 08:37:12 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 A0EB01E8332; Thu, 3 Sep 2026 01:03:43 +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=1788397424; cv=none; b=t5ZCYlQ14v7rySsFw0DlK6gC7LCESeCl+eSLqQ69jRnSFm1XAqM2ZhdvG1XYhFBA3AncdS+0+0d2ZeGZbP7221E9A3YZphSAT3B6Hh+OfgHgDu7n5jdNNYWHEv7yihegfgcqU+bD20HEdzJNP+VGCNIK1chDyNQJCPuXSHIIyMk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788397424; c=relaxed/simple; bh=+w3rxutfnYBNIul7l279XZJ8W0YahLijvuvU2FVYbRw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MjgfqII7MvEwftmiIB1gTNAsYpw7lEVGJfHeKgShZ9ZTnHw1+7xGHWNKhtMnM6uJsriIA8Iku5zQg4wNiju4uda6sMRkbpj4bHA49bvrHnnnzZfbVkkvICU61NOsEPcWDcZ1pf/gVCVs0Vb/Ed3cT9irRVnRrgZq7mij7VazGwc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LodVKFzm; 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="LodVKFzm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 611081F00A3A; Thu, 3 Sep 2026 01:03:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788397423; bh=a+KFNc38yAs5cF8y2PPkR2gfi2v/4V0wSG+v466VkTs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=LodVKFzm7cPA/XKyLRrziPacDwGJLlxAjosgz7vkLzndAd43UwGSSmeTy3nRv2M7/ P6Lstm9ApfK3wchi1TzvLIWDnUw4W2iM5ybBascq3HepMB8FEbtGlopObj8r9LweMG LaSH7hLz0s1lSfUaTG+bgYyPiZFhCuyvAOGGcRSgOVvq+0OkH42gIyECD34Uzw6Xvx +Q2MT8DiCFKURE+bUs4iEZnP9Ce3aFeFd06bLbXhJe31queYCqZM0u7jc1ZFAt/He+ vO+lzpR02gxrpahg8y4YHOto7X8/N5J72vykyibw7X9QMZeneaPHd2OrjbT1AERYWu UQjWF0VZiOpJA== From: SJ Park To: Andrew Morton Cc: SJ Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 4/4] mm/damon/lru_sort: remove unnecessary damon_call() param validation Date: Wed, 2 Sep 2026 18:03:33 -0700 Message-ID: <20260903010334.93622-5-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260903010334.93622-1-sj@kernel.org> References: <20260903010334.93622-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