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 B6AF333970F for ; Fri, 31 Jul 2026 02:43:45 +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=1785465827; cv=none; b=XcFiIKruzfdC73yU0csjFB+gtNFDUq2qDj7HYQII6lfO8kY7VUd0q/qjbvZtU/DE/Ka5sRdKizCWspRyRL+QQXRBaG7pP0i5iqFUknbITFpqHWBX45m85sZO8ZBO5aySk27oox8hcLcLZFkVSgWAfqZ6jfVryRHXtv8mFOB8P8M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785465827; c=relaxed/simple; bh=ug7eJp3vr3TJS3JN+H650+u7Z32zyYHP4RXdFciOA4o=; h=Date:To:From:Subject:Message-Id; b=b4nHHtfwrr5So4WF8cyEBSBfE0+v5zGmjFfDM+m67x4DGpCuhp4NAaGwOiBYvzx16IzHSfKLH1Sn9mSTiDiXBIUQhq3YXupEaxTQ6hyYT0Z99nOydk5oUfvhLnWRO7XNZIqciLHXpLia/czjtPtFk53iJNKZP4FuiRqW2z3JNGo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=UQZ51Ni2; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="UQZ51Ni2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E8791F00A3E; Fri, 31 Jul 2026 02:43:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1785465825; bh=WLmyOPuOaz3JSPpshTVnxxNgCLHbCxug/3Dgi7ZMhXk=; h=Date:To:From:Subject; b=UQZ51Ni2NIYctzoFFEidEO9MkaekPmYSfllQ8IMCZcOzoQCYnTwPOOSPWWKU83ggi wr9vLMEnovohBOrG0oefXKDymFWxhSojjQJH7T30jnxQmbw8ggyhaFiRFXfWnnGzmc ki49sEAZj9srJ5hZ4TWbMK6AZ1hBdeiFaOHCmnnM= Date: Thu, 30 Jul 2026 19:43:45 -0700 To: mm-commits@vger.kernel.org,sj@kernel.org,akpm@linux-foundation.org From: Andrew Morton Subject: [merged mm-stable] mm-damon-core-safely-validate-src-on-damon_commit_ctx.patch removed from -mm tree Message-Id: <20260731024345.6E8791F00A3E@smtp.kernel.org> Precedence: bulk X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: The quilt patch titled Subject: mm/damon/core: safely validate src on damon_commit_ctx() has been removed from the -mm tree. Its filename was mm-damon-core-safely-validate-src-on-damon_commit_ctx.patch This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm ------------------------------------------------------ From: SJ Park Subject: mm/damon/core: safely validate src on damon_commit_ctx() Date: Sun, 5 Jul 2026 08:55:52 -0700 Patch series "mm/damon: validate all parameters in the core". DAMON has a number of parameters. Some of the parameters are validated by DAMON, while some are validated by DAMON API callers. Each caller has their own set of parameters that are exposed to users. Hence each caller has their own ways to do the validation. There is no clear lines for the responsibilities. It is confusing and easy to make mistakes at validations. Actually we found a few bugs in the class. Define DAMON core as the place to do all the validations and implement those. damon_set_regions(), damon_start() and damon_commit_ctx() are the three main DAMON core API functions for setup of DAMON parameters. Make the three functions to do safe and holistic parameter checks. The first one is already providing the validation, so changes are only for the last two functions. This might add unnecessary validations for some use cases. The overhead should be negligible as parameters update is expected to only rarely happen. It reduces the number of places to check and fix for bugs of the class from all callers to the single component. The maintenance efficiency gain is obvious. Further cleanup documents and caller code. Make the lines of validation duties clearer. Remove validations that are no more needed owing to the core validations. Patches Sequence ================ Patch 1 implements the core holistic parameters validation for damon_commit_ctx(). Patch 2 extends the validation to damon_start(). Patch 3 removes the duplicated holistic parameters validation in DAMON sysfs interface, which is now embedded into the core layer. Patches 4 and 5 remove duplicated min_region_sz validation in DAMON modules. Patches 6 updates kernel doc to clarify damon_set_regions() is doing the range validation. Patches 7 and 8 remove monitoring target range validations that doesn't necessary thanks to the validation in damon_set_regions(). This patch (of 8): damon_commit_ctx() does its holistic parameter set validation while applying the new parameter in the set one by one. If it finds a parameter is invalid, because some invalid parameters may already be committed (it is called "commit" but not atomic and irreversable), it stops the running DAMON context. The callers of the function therefore have to validate the parameters before calling it. Because the function already embeds holistic validation, DAMON_SYSFS reuses it in a safe way. It creates a test-purpose context that is not running but mimics the running one, and calls damon_commit_ctx() against the test purpose context. If it succeeds, the parameters are considered valid, and a real damon_commit_ctx() call against the running context is made with those. Other callers such as DAMON_RECLAIM and DAMON_LRU_SORT do not expose full parameters to users. For efficiency, they validate only the known set of parameters. The efficiency gain is arguably small and doubtful, though. Meanwhile the maintenance overhead of the multiple different validations is clearly high. We actually found and fixed a few bugs in the class. Update damon_commit_ctx() to embed DAMON_SYSFS' safe and holistic validation approach. Callers can simply call damon_commit_ctx() without worrying if their parameters are invalid. Note that damon_commit_ctx() can still cause an unexpected stop of the running context, if internal memory allocation fails. It is arguably unlikely since those internal allocations are too small to fail, but theoretically possible. It should also be better addressed, but not necessarily a blocker of this small and incremental improvement effort. Link: https://lore.kernel.org/20260705155600.96555-1-sj@kernel.org Link: https://lore.kernel.org/20260705155600.96555-2-sj@kernel.org Signed-off-by: SJ Park Signed-off-by: Andrew Morton --- mm/damon/core.c | 61 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 14 deletions(-) --- a/mm/damon/core.c~mm-damon-core-safely-validate-src-on-damon_commit_ctx +++ a/mm/damon/core.c @@ -1664,20 +1664,7 @@ static int damon_commit_probes(struct da return 0; } -/** - * damon_commit_ctx() - Commit parameters of a DAMON context to another. - * @dst: The commit destination DAMON context. - * @src: The commit source DAMON context. - * - * This function copies user-specified parameters from @src to @dst and update - * the internal status and results accordingly. Users should use this function - * for context-level parameters update of running context, instead of manual - * in-place updates. - * - * This function should be called from parameters-update safe context, like - * damon_call(). - */ -int damon_commit_ctx(struct damon_ctx *dst, struct damon_ctx *src) +static int __damon_commit_ctx(struct damon_ctx *dst, struct damon_ctx *src) { int err; struct damos *scheme; @@ -1732,6 +1719,52 @@ int damon_commit_ctx(struct damon_ctx *d return 0; } +static struct damon_ctx *damon_new_test_ctx(struct damon_ctx *dst) +{ + struct damon_ctx *test_ctx; + int err; + + test_ctx = damon_new_ctx(); + if (!test_ctx) + return NULL; + err = __damon_commit_ctx(test_ctx, dst); + if (err) { + damon_destroy_ctx(test_ctx); + return NULL; + } + return test_ctx; +} + +/** + * damon_commit_ctx() - Commit parameters of a DAMON context to another. + * @dst: The commit destination DAMON context. + * @src: The commit source DAMON context. + * + * This function copies user-specified parameters from @src to @dst and update + * the internal status and results accordingly. Users should use this function + * for context-level parameters update of running context, instead of manual + * in-place updates. + * + * This function should be called from parameters-update safe context, like + * damon_call(). + */ +int damon_commit_ctx(struct damon_ctx *dst, struct damon_ctx *src) +{ + struct damon_ctx *test_ctx; + int err; + + test_ctx = damon_new_test_ctx(dst); + if (!test_ctx) + return -ENOMEM; + err = __damon_commit_ctx(test_ctx, src); + if (err) + goto out; + err = __damon_commit_ctx(dst, src); +out: + damon_destroy_ctx(test_ctx); + return err; +} + /** * damon_nr_running_ctxs() - Return number of currently running contexts. */ _ Patches currently in -mm which might be from sj@kernel.org are mm-damon-adjust-isolated-pages-stat-for-damos_migrate_hotcold.patch mm-damon-core-stop-ctxs-in-damon_start-before-returning-an-error.patch samples-damon-mtier-do-not-stop-first-context-for-damon_start-failure.patch mm-damon-core-make-damon_stop-never-fails.patch mm-damon-sysfs-ignore-damon_stop-return-value.patch mm-damon-reclaaim-ignore-damon_stop-return-value.patch mm-damon-lru_sort-ignore-damon_stop-return-value.patch mm-damon-core-change-damon_stop-return-type-to-void.patch samples-damon-mtier-stop-all-contexts-with-single-damon_stop-call.patch mm-damon-core-wait-ctx-stop-in-damon_call-before-reruning-an-error.patch samples-damon-wsse-do-not-stop-ctx-for-damon_call-failure.patch samples-damon-prcl-do-not-stop-damon-for-damon_call-failure.patch mm-damon-core-remove-comment-and-test-for-nr_to_bp-divide-by-zero.patch mm-damon-core-s-damon_max_nr_accesses-damon_nr_samples_per_aggr.patch mm-damon-core-s-accesses_bp_to_nr_accesses-sample_bp_to_count.patch mm-damon-core-s-nr_accesses_to_accesses_bp-sample_count_to_bp.patch mm-damon-core-s-nr_accesses_for_new_attrs-nr_samples_for_new_attrs.patch mm-damon-core-update-probe-hits-for-new-parameter-commit.patch mm-damon-core-handle-unreset-probe_hits-in-probe_hits_mvsum.patch mm-damon-core-introduce-damon_probe-weight.patch mm-damon-core-ask-apply_probes-ops-callback-to-set-sampling-address.patch mm-damon-paddr-set-samples-in-apply_probes-if-requested.patch mm-damon-core-ask-apply_probe-to-return-max-probe-hits-weighted-sum.patch mm-damon-core-implement-damon_probe_hits_wsum.patch mm-damon-paddr-respect-return_max_wsum.patch mm-damon-core-use-abs_diff-instead-of-abs.patch mm-damon-core-extend-merge-function-to-work-with-probe-hits.patch mm-damon-core-disallow-probe_hits-overflow-on-attrs-only-monitoring.patch mm-damon-core-validate-params-for-probe-hits-weighted-sum-overflow.patch mm-damon-core-disable-access-monitoring-when-probe-weights-are-set.patch mm-damon-core-set-samples-in-apply_probes-if-probe-weights-are-set.patch mm-damon-core-s-max_nr_accesses-max_merge_score-in-kdamond_fn.patch mm-damon-core-get-merge-threshold-from-probe-hits-when-weights-are-set.patch mm-damon-core-implement-damon_has_probe_weight.patch mm-damon-sysfs-implement-probe-weight-file.patch docs-mm-damon-design-document-attrs-only-monitoring.patch docs-admin-guide-mm-damon-usage-document-weight-sysfs-file.patch docs-abi-damon-document-probe-weight-file.patch mm-damon-core-skip-aging-from-repeated-aggressive-merging.patch mm-damon-core-hide-private-damon_region-fields.patch mm-damon-core-hide-private-damon_target-fields.patch mm-damon-core-hide-private-damos_quota_goal-fields.patch mm-damon-core-hide-private-damos_quota-fields.patch mm-damon-core-hide-private-damos_filter-fields.patch mm-damon-core-hide-private-damos-fields.patch mm-damon-core-hide-private-damon_filter-fields.patch mm-damon-core-hide-private-damon_probe-fields.patch mm-damon-sysfs-do-not-directly-access-damon_ctx-ops.patch mm-damon-core-hide-core-private-damon_ctx-fields.patch mm-damon-core-avoid-infinite-kdamond_merge_regions-internal-loop.patch mm-damon-tests-core-kunit-catch-test-failure-in-test_merge_regions_of.patch mm-damon-vaddr-drop-last-same-folio-access-check-optimization.patch mm-damon-paddr-drop-last-same-folio-access-check-reuse-optimization.patch mm-damon-sysfs-read-addr_unit-only-once-in-damon_sysfs_apply_inputs.patch mm-damon-sysfs-read-ops_id-only-once-in-damon_sysfs_apply_inputs.patch mm-damon-core-initialize-damos-last_applied.patch mm-damon-core-kunit-check-region-count-before-testing-in-split_at.patch mm-damon-vaddr-kunit-check-region-count-in-three_regions-test.patch mm-damon-core-kunit-handle-region-split-failure-in-filter_out.patch mm-damon-core-kunit-skip-wrong-dest-walk-in-commit_dests_for.patch mm-damon-core-kunit-skip-wrong-quota-goal-walk-in-commit_quota_goals.patch mm-damon-core-kunit-skip-wrong-region-walk-in-commit_target_regions.patch mm-damon-ops-common-use-nr_accesses-moving-sum-for-quota-score.patch mm-damon-core-handle-region-split-failure-in-apply_min_nr_regions.patch