From: SeongJae Park <sj@kernel.org>
Cc: SeongJae Park <sj@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
damon@lists.linux.dev, kernel-team@meta.com,
linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: [RFC PATCH 01/13] mm/damon/sysfs: validate user inputs from damon_sysfs_commit_input()
Date: Tue, 25 Feb 2025 22:36:39 -0800 [thread overview]
Message-ID: <20250226063651.513178-2-sj@kernel.org> (raw)
In-Reply-To: <20250226063651.513178-1-sj@kernel.org>
Online DAMON parameters commit via DAMON sysfs interface can make
kdamond stop. This behavior was made because it can make the
implementation simpler. The implementation simply tries committing the
parameter without validation. If it finds something wrong, it returns
error without reverting partially committed parameters back. It is safe
though, since it breaks kdamond main loop in the case of the error
return.
Users can make the wrong parameters by mistake, though. Validating the
input parameters first and returning the error when some parameters
wrong, while letting kdamond continues running with the old parameters
would be the better behavior. This behavior can also make damon_call()
carrying the online commit instead of the damon_callback hook in future
easier, because damon_call() cannot directly break kdamond main loop.
Implement the better behavior.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/sysfs.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
index ccd435d234b9..87e4c6e3614e 100644
--- a/mm/damon/sysfs.c
+++ b/mm/damon/sysfs.c
@@ -1449,11 +1449,11 @@ static struct damon_ctx *damon_sysfs_build_ctx(
* damon_sysfs_commit_input() - Commit user inputs to a running kdamond.
* @kdamond: The kobject wrapper for the associated kdamond.
*
- * If the sysfs input is wrong, the kdamond will be terminated.
+ * Returns error if the sysfs input is wrong.
*/
static int damon_sysfs_commit_input(struct damon_sysfs_kdamond *kdamond)
{
- struct damon_ctx *param_ctx;
+ struct damon_ctx *param_ctx, *test_ctx;
int err;
if (!damon_sysfs_kdamond_running(kdamond))
@@ -1465,7 +1465,15 @@ static int damon_sysfs_commit_input(struct damon_sysfs_kdamond *kdamond)
param_ctx = damon_sysfs_build_ctx(kdamond->contexts->contexts_arr[0]);
if (IS_ERR(param_ctx))
return PTR_ERR(param_ctx);
+ test_ctx = damon_new_ctx();
+ err = damon_commit_ctx(test_ctx, param_ctx);
+ if (err) {
+ damon_sysfs_destroy_targets(test_ctx);
+ damon_destroy_ctx(test_ctx);
+ goto out;
+ }
err = damon_commit_ctx(kdamond->damon_ctx, param_ctx);
+out:
damon_sysfs_destroy_targets(param_ctx);
damon_destroy_ctx(param_ctx);
return err;
--
2.39.5
next prev parent reply other threads:[~2025-02-26 6:37 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-26 6:36 [RFC PATCH 00/13] mm/damon/sysfs: commit parameters online via damon_call() SeongJae Park
2025-02-26 6:36 ` SeongJae Park [this message]
2025-02-26 6:36 ` [RFC PATCH 02/13] mm/damon/core: invoke kdamond_call() after merging is done if possible SeongJae Park
2025-02-26 6:36 ` [RFC PATCH 03/13] mm/damon/core: make damon_set_attrs() be safe to be called from damon_call() SeongJae Park
2025-03-02 21:41 ` SeongJae Park
2025-02-26 6:36 ` [RFC PATCH 04/13] mm/damon/sysfs: handle commit command using damon_call() SeongJae Park
2025-02-26 6:36 ` [RFC PATCH 05/13] mm/damon/sysfs: remove damon_sysfs_cmd_request code from damon_sysfs_handle_cmd() SeongJae Park
2025-02-26 6:36 ` [RFC PATCH 06/13] mm/damon/sysfs: remove damon_sysfs_cmd_request_callback() and its callers SeongJae Park
2025-02-26 6:36 ` [RFC PATCH 07/13] mm/damon/sysfs: remove damon_sysfs_cmd_request and its readers SeongJae Park
2025-02-26 6:36 ` [RFC PATCH 08/13] mm/damon/sysfs-schemes: remove obsolete comment for damon_sysfs_schemes_clear_regions() SeongJae Park
2025-02-26 6:36 ` [RFC PATCH 09/13] mm/damon: remove damon_callback->private SeongJae Park
2025-02-26 6:36 ` [RFC PATCH 10/13] mm/damon: remove ->before_start of damon_callback SeongJae Park
2025-02-26 6:36 ` [RFC PATCH 11/13] mm/damon: remove damon_callback->after_sampling SeongJae Park
2025-02-26 6:36 ` [RFC PATCH 12/13] mm/damon: remove damon_callback->before_damos_apply SeongJae Park
2025-02-26 6:36 ` [RFC PATCH 13/13] mm/damon: remove damon_operations->reset_aggregated SeongJae Park
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250226063651.513178-2-sj@kernel.org \
--to=sj@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=damon@lists.linux.dev \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox