Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm/damon/sysfs: test commit input against realistic destination

DAMON sysfs interface tests if given online parameters update request is
valid, by committing those using the DAMON kernel API, to a test-purpose
destination context. The test-purpose destination context is constructed
using damon_new_ctx(), so it has no target, no scheme.

If a source target has the obsolete field set, the test-purpose commit
will fail because damon_commit_targets() fails when there is a source
obsolete target that cannot find its matching destination target. DAMON
sysfs interface is not letting users set the field for now, so there is no
problem. However, the following commit will support that. Also there
could be similar future changes that making commit fails based on current
context structure.

Make the test purpose commit destination context similar to the current
running one, by committing the running one to the test purpose context,
before doing the real test-purpose commit.

Link: https://lkml.kernel.org/r/20251023012535.69625-3-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Reviewed-by: Bijan Tabatabai <bijan311@gmail.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

SeongJae Park and committed by
Andrew Morton
60bd24f2 adf7d6cd

+21 -1
+21 -1
mm/damon/sysfs.c
··· 1452 1452 struct damon_sysfs_context *sys_ctx); 1453 1453 1454 1454 /* 1455 + * Return a new damon_ctx for testing new parameters to commit. 1456 + */ 1457 + static struct damon_ctx *damon_sysfs_new_test_ctx( 1458 + struct damon_ctx *running_ctx) 1459 + { 1460 + struct damon_ctx *test_ctx; 1461 + int err; 1462 + 1463 + test_ctx = damon_new_ctx(); 1464 + if (!test_ctx) 1465 + return NULL; 1466 + err = damon_commit_ctx(test_ctx, running_ctx); 1467 + if (err) { 1468 + damon_destroy_ctx(test_ctx); 1469 + return NULL; 1470 + } 1471 + return test_ctx; 1472 + } 1473 + 1474 + /* 1455 1475 * damon_sysfs_commit_input() - Commit user inputs to a running kdamond. 1456 1476 * @kdamond: The kobject wrapper for the associated kdamond. 1457 1477 * ··· 1492 1472 param_ctx = damon_sysfs_build_ctx(kdamond->contexts->contexts_arr[0]); 1493 1473 if (IS_ERR(param_ctx)) 1494 1474 return PTR_ERR(param_ctx); 1495 - test_ctx = damon_new_ctx(); 1475 + test_ctx = damon_sysfs_new_test_ctx(kdamond->damon_ctx); 1496 1476 if (!test_ctx) 1497 1477 return -ENOMEM; 1498 1478 err = damon_commit_ctx(test_ctx, param_ctx);