mm/damon: move damos filter range arguments validation to core
Subsystems (4)
SJ Park
maintainerv2 cover mm/damon: move damos filter range arguments validation to core
DAMOS filter range arguments are being validated in the DAMON sysfs interface. Some of those have minor time-of-check to time-of-use (TOCTOU) bugs. In future, other callers might have duplicated validations with similar bugs.
Fix the bugs and further refactor the code to move the validation to the core layer. Also add kunit test cases for the validations.
Patches 1 and 2 fix the existing TOCTOU bugs. Patches 3 and 4 adds the validation in the core layer. Patch 5 drops the replicated validation in DAMON sysfs interface. Patch 6 further cleanup the code. Patches 7 and 8 extends kunit tests to test the validation.
Changes from RFC
- RFC: https://lore.kernel.org/[email protected]
- Handle error from damos_commit_filter_arg() on all call sites.
SJ Park (8):
mm/damon/sysfs-schemes: read sysfs_filter->addr_range only once mm/damon/sysfs-schemes: read sysfs_filter->sz_range only once mm/damon/core: return an error from damos_commit_filter_arg() mm/damon/core: disallow max < min damos filter range arguments commit mm/damon/sysfs-schemes: drop centralized filter range arg validations mm/damon/sysfs-schemes: use switch-case in add_scheme_filters() mm/damon/core-kunit: extend damos_commit_filter_for() for wrong input mm/damon/core-kunit: test invalid damos filter commits
mm/damon/core.c | 47 +++++++++++++++++++++++++++---------- mm/damon/sysfs-schemes.c | 32 ++++++++++--------------- mm/damon/tests/core-kunit.h | 38 +++++++++++++++++++++++------- 3 files changed, 76 insertions(+), 41 deletions(-)
base-commit: 9b2df9f07a4a7a5d9f625d26f9482486859d64aa
Signature · 1 line
2.47.3
SJ Park
maintainerRFC PATCH v2 1/8 mm/damon/sysfs-schemes: read sysfs_filter->addr_range only once
DAMON sysfs interface reads the user-provided address range arguments for addr type DAMOS filter twice. Once for validation, and once again for assignments to the variable that will be passed to the core layer. If the user updates the argument in parallel, an invalid address range could be passed to the core layer. Avoid it by doing the assignments first, and then validating the assigned variables before passing those to the core layer.
User impact of the bug should be trivial. From the core layer's perspective, the invalid address range is not really invalid. It just works as having a weird address range. No critical issues such as a crash or a leak could happen. And sane users ain't do such parallel arguments update anyway. If they do, such racy behavior is arguably somewhat expected and deserved. That said, there is no reason to keep such races.
--- mm/damon/sysfs-schemes.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
mm/damon/sysfs-schemes.c +3 -3
@@ -2831,12 +2831,12 @@ static int damon_sysfs_add_scheme_filters(struct damos *scheme,return err; } }else if (filter->type ==DAMOS_FILTER_TYPE_ADDR ) { -if (sysfs_filter->addr_range.end < - sysfs_filter->addr_range.start) { + filter->addr_range = sysfs_filter->addr_range; +if (filter->addr_range.end < + filter->addr_range.start) {damos_destroy_filter (filter);return -EINVAL ; } - filter->addr_range = sysfs_filter->addr_range; }else if (filter->type ==DAMOS_FILTER_TYPE_TARGET ) { filter->target_idx = sysfs_filter->target_idx; }else if (filter->type ==DAMOS_FILTER_TYPE_HUGEPAGE_SIZE ) {
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [RFC PATCH v2 1/8] mm/damon/sysfs-schemes: read sysfs_filter->addr_range only once
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 16 lines
DAMON sysfs interface reads the user-provided address range arguments for addr type DAMOS filter twice. Once for validation, and once again for assignments to the variable that will be passed to the core layer. If the user updates the argument in parallel, an invalid address range could be passed to the core layer. Avoid it by doing the assignments first, and then validating the assigned variables before passing those to the core layer.
User impact of the bug should be trivial. From the core layer's perspective, the invalid address range is not really invalid. It just works as having a weird address range. No critical issues such as a crash or a leak could happen. And sane users ain't do such parallel arguments update anyway. If they do, such racy behavior is arguably somewhat expected and deserved. That said, there is no reason to keep such races.
Quoted 3 lines
Fixes 2f1abcfccd86 ("mm/damon/sysfs-schemes: support address range type DAMOS filter")Cc <[email protected]> # 6.6.xSigned-off-by SJ Park <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
SJ Park
maintainerRFC PATCH v2 2/8 mm/damon/sysfs-schemes: read sysfs_filter->sz_range only once
In reply to SJ ParkDAMON sysfs interface reads the user-provided size range arguments for hugepage_size type DAMOS filter twice. Once for validation, and once again for assignments to the variable that will be passed to the core layer. If the user updates the arguments in parallel, an invalid size range could be passed to the core layer. Avoid it by doing the assignments first, and then validating the assigned variables before passing those to the core layer.
User impact of the bug should be trivial. From the core layer's perspective, the invalid size range is not really invalid. It just works as having a weird size range. No critical issues such as a crash or a leak could happen. And sane users ain't do such parallel arguments update anyway. If they do, such racy behavior is arguably somewhat expected and deserved. That said, there is no reason to keep such races.
--- mm/damon/sysfs-schemes.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
mm/damon/sysfs-schemes.c +3 -4
@@ -2840,13 +2840,12 @@ static int damon_sysfs_add_scheme_filters(struct damos *scheme, }else if (filter->type ==DAMOS_FILTER_TYPE_TARGET ) { filter->target_idx = sysfs_filter->target_idx; }else if (filter->type ==DAMOS_FILTER_TYPE_HUGEPAGE_SIZE ) { -if (sysfs_filter->range_min > - sysfs_filter->range_max) { + filter->sz_range.min = sysfs_filter->range_min; + filter->sz_range.max = sysfs_filter->range_max; +if (filter->range_min > filter->range_max) {damos_destroy_filter (filter);return -EINVAL ; } - filter->sz_range.min = sysfs_filter->range_min; - filter->sz_range.max = sysfs_filter->range_max; }else if (filter->type ==DAMOS_FILTER_TYPE_PROBE_HITS_WSUM ) { filter->range_min = sysfs_filter->range_min; filter->range_max = sysfs_filter->range_max;
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [RFC PATCH v2 2/8] mm/damon/sysfs-schemes: read sysfs_filter->sz_range only once
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 16 lines
DAMON sysfs interface reads the user-provided size range arguments for
hugepage_sizetype DAMOS filter twice. Once for validation, and once again for assignments to the variable that will be passed to the core layer. If the user updates the arguments in parallel, an invalid size range could be passed to the core layer. Avoid it by doing the assignments first, and then validating the assigned variables before passing those to the core layer.User impact of the bug should be trivial. From the core layer's perspective, the invalid size range is not really invalid. It just works as having a weird size range. No critical issues such as a crash or a leak could happen. And sane users ain't do such parallel arguments update anyway. If they do, such racy behavior is arguably somewhat expected and deserved. That said, there is no reason to keep such races.
Quoted 3 lines
Fixes ea1f204ba29a ("mm/damon/sysfs-schemes: add files for setting damos_filter->sz_range")Cc <[email protected]> # 6.15.xSigned-off-by SJ Park <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
SJ Park
maintainerRFC PATCH v2 3/8 mm/damon/core: return an error from damos_commit_filter_arg()
In reply to SJ Parkdamos_commit_filter_arg() is supposed to always succeed. It may not in future, for example, if the given filter is invalid. Prepare the case by modifying its signature to return an error when it failed. Also pipe the return value to its callers and let them handle the error.
--- mm/damon/core.c | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-)
mm/damon/core.c +28 -13
@@ -1317,7 +1317,7 @@ static struct damos_filter *damos_nth_ops_filter(int n, struct damos *s)return NULL ; } -static void damos_commit_filter_arg ( +static int damos_commit_filter_arg (struct damos_filter *dst,struct damos_filter *src) {switch (dst->type) {
@@ -1340,28 +1340,32 @@ static void damos_commit_filter_arg(default :break ; } +return 0 ; } -static void damos_commit_filter ( +static int damos_commit_filter (struct damos_filter *dst,struct damos_filter *src) { dst->type = src->type; dst->matching = src->matching; dst->allow = src->allow; -damos_commit_filter_arg (dst, src); +return damos_commit_filter_arg (dst, src); }static int damos_commit_core_filters (struct damos *dst,struct damos *src) {struct damos_filter *dst_filter, *next, *src_filter, *new_filter; -int i =0 , j =0 ; +int i =0 , j =0 , err;damos_for_each_core_filter_safe (dst_filter, next, dst) { src_filter =damos_nth_core_filter (i++, src); -if (src_filter) -damos_commit_filter (dst_filter, src_filter); -else +if (src_filter) { + err =damos_commit_filter (dst_filter, src_filter); +if (err) +return err; + }else {damos_destroy_filter (dst_filter); + } }damos_for_each_core_filter_safe (src_filter, next, src) {
@@ -1373,7 +1377,11 @@ static int damos_commit_core_filters(struct damos *dst, struct damos *src) src_filter->allow);if (!new_filter)return -ENOMEM ; -damos_commit_filter_arg (new_filter, src_filter); + err =damos_commit_filter_arg (new_filter, src_filter); +if (err) { +damos_destroy_filter (new_filter); +return err; + }damos_add_filter (dst, new_filter); }return 0 ;
@@ -1382,14 +1390,17 @@ static int damos_commit_core_filters(struct damos *dst, struct damos *src)static int damos_commit_ops_filters (struct damos *dst,struct damos *src) {struct damos_filter *dst_filter, *next, *src_filter, *new_filter; -int i =0 , j =0 ; +int i =0 , j =0 , err;damos_for_each_ops_filter_safe (dst_filter, next, dst) { src_filter =damos_nth_ops_filter (i++, src); -if (src_filter) -damos_commit_filter (dst_filter, src_filter); -else +if (src_filter) { + err =damos_commit_filter (dst_filter, src_filter); +if (err) +return err; + }else {damos_destroy_filter (dst_filter); + } }damos_for_each_ops_filter_safe (src_filter, next, src) {
@@ -1401,7 +1412,11 @@ static int damos_commit_ops_filters(struct damos *dst, struct damos *src) src_filter->allow);if (!new_filter)return -ENOMEM ; -damos_commit_filter_arg (new_filter, src_filter); + err =damos_commit_filter_arg (new_filter, src_filter); +if (err) { +damos_destroy_filter (new_filter); +return err; + }damos_add_filter (dst, new_filter); }return 0 ;
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [RFC PATCH v2 3/8] mm/damon/core: return an error from damos_commit_filter_arg()
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines
damos_commit_filter_arg()is supposed to always succeed. It may not in future, for example, if the given filter is invalid. Prepare the case by modifying its signature to return an error when it failed. Also pipe the return value to its callers and let them handle the error.Signed-off-by SJ Park <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [RFC PATCH v2 3/8] mm/damon/core: return an error from damos_commit_filter_arg()
In reply to SJ ParkQuoted 98 lines · On Sun, 13 Sep 2026 10:17:00 -0700 SJ Park <[email protected]> wrote:
damos_commit_filter_arg()is supposed to always succeed. It may not in future, for example, if the given filter is invalid. Prepare the case by modifying its signature to return an error when it failed. Also pipe the return value to its callers and let them handle the error.Signed-off-by SJ Park <[email protected]>--- mm/damon/core.c | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-)mm/damon/core.c +23
-12@@ -1317,7 +1317,7 @@ static struct damos_filter *damos_nth_ops_filter(int n, struct damos *s)return NULL ; } -static void damos_commit_filter_arg ( +static int damos_commit_filter_arg (struct damos_filter *dst,struct damos_filter *src) {switch (dst->type) {@@ -1340,28 +1340,32 @@ static void damos_commit_filter_arg(default :break ; } +return 0 ; } -static void damos_commit_filter ( +static int damos_commit_filter (struct damos_filter *dst,struct damos_filter *src) { dst->type = src->type; dst->matching = src->matching; dst->allow = src->allow; -damos_commit_filter_arg (dst, src); +return damos_commit_filter_arg (dst, src); }static int damos_commit_core_filters (struct damos *dst,struct damos *src) {struct damos_filter *dst_filter, *next, *src_filter, *new_filter; -int i =0 , j =0 ; +int i =0 , j =0 , err;damos_for_each_core_filter_safe (dst_filter, next, dst) { src_filter =damos_nth_core_filter (i++, src); -if (src_filter) -damos_commit_filter (dst_filter, src_filter); -else +if (src_filter) { + err =damos_commit_filter (dst_filter, src_filter); +if (err) +return err; + }else {damos_destroy_filter (dst_filter); + } }damos_for_each_core_filter_safe (src_filter, next, src) {@@ -1373,7 +1377,11 @@ static int damos_commit_core_filters(struct damos *dst, struct damos *src) src_filter->allow);if (!new_filter)return -ENOMEM ; -damos_commit_filter_arg (new_filter, src_filter); + err =damos_commit_filter_arg (new_filter, src_filter); +if (err) { +damos_destroy_filter (new_filter); +return err; + }damos_add_filter (dst, new_filter); }return 0 ;@@ -1382,14 +1390,17 @@ static int damos_commit_core_filters(struct damos *dst, struct damos *src)static int damos_commit_ops_filters (struct damos *dst,struct damos *src) {struct damos_filter *dst_filter, *next, *src_filter, *new_filter; -int i =0 , j =0 ; +int i =0 , j =0 , err;damos_for_each_ops_filter_safe (dst_filter, next, dst) { src_filter =damos_nth_ops_filter (i++, src); -if (src_filter) -damos_commit_filter (dst_filter, src_filter); -else +if (src_filter) { + err =damos_commit_filter (dst_filter, src_filter); +if (err) +return err; + }else {damos_destroy_filter (dst_filter); + } }damos_for_each_ops_filter_safe (src_filter, next, src) {
mm/damon/core.c static int damos_commit_ops_filters(struct damos *dst, struct damos *src) · line 1419
Quoted 9 lines
mm/damon/core.c +5
-1@@ -1401,7 +1412,11 @@ static int damos_commit_ops_filters(struct damos *dst, struct damos *src) src_filter->allow);if (!new_filter)return -ENOMEM ; -damos_commit_filter_arg (new_filter, src_filter); + err =damos_commit_filter_arg (new_filter, src_filter); +if (err) { +damos_destroy_filter (new_filter); +return err; + }
I re-checked this version, and the error return from damos_commit_filter_arg() is now handled at all call sites, including the new-filter paths.
I'll take another look at the remaining patches.
Thanks,
Kunwu
Quoted 6 lines
mm/damon/core.c +0
-0damos_add_filter (dst, new_filter); }return 0 ;Signature · 1 line
2.47.3
Sent using hkml (https://github.com/sjp38/hackermail)
SJ Park
maintainerRe: [RFC PATCH v2 3/8] mm/damon/core: return an error from damos_commit_filter_arg()
Hi Kunwu,
Quoted 1 line · On Tue, 15 Sep 2026 11:30:49 +0800 Kunwu Chan <[email protected]> wrote:
On Sun, 13 Sep 2026 10:17:00 -0700 SJ Park <[email protected]> wrote:
[...]
Quoted 1 line
Reviewed-by Kunwu Chan <[email protected]>
Thank you!
Quoted 2 lines
I'll take another look at the remaining patches.
A new version of this series is available at
https://lore.kernel.org/all/[email protected]/
It has no real difference to this version, but it would be better to review on the latest version in my humble opinion.
Thanks,
SJ
[...]
Re: [RFC PATCH v2 3/8] mm/damon/core: return an error from damos_commit_filter_arg()
Quoted 12 lines · SJ Park
Hi Kunwu,
Quoted 1 line · On Tue, 15 Sep 2026 11:30:49 +0800 Kunwu Chan <[email protected]> wrote:
On Sun, 13 Sep 2026 10:17:00 -0700 SJ Park <[email protected]> wrote:
[...]
Quoted 1 line
Reviewed-by Kunwu Chan <[email protected]>Thank you!
Quoted 1 line
Quoted 7 lines
Quoted 1 line
I'll take another look at the remaining patches.
A new version of this series is available at
https://lore.kernel.org/all/[email protected]/It has no real difference to this version, but it would be better to review on the latest version in my humble opinion.
Thanks, SJ. I'll review the latest version.
Thanks,
Kunwu
Quoted 6 lines
Thanks,
SJ[...]
SJ Park
maintainerRFC PATCH v2 4/8 mm/damon/core: disallow max < min damos filter range arguments commit
In reply to SJ Parkdamos_commit_filter_arg() receives range arguments for a few types of DAMOS filters. It allows any range including max < min range. It is fine for the logic, but makes no sense to support it. Actually DAMON sysfs interface is doing the validation on its own. To avoid duplicated validations in multiple DAMON API callers, it would be better to do the validation in the core layer. Add a validation of the given range.
--- mm/damon/core.c | 6 ++++++ 1 file changed, 6 insertions(+)
mm/damon/core.c +6 -0
@@ -1325,15 +1325,21 @@ static int damos_commit_filter_arg( dst->memcg_id = src->memcg_id;break ;case DAMOS_FILTER_TYPE_ADDR : +if (src->addr_range.end < src->addr_range.start) +return -EINVAL ; dst->addr_range = src->addr_range;break ;case DAMOS_FILTER_TYPE_TARGET : dst->target_idx = src->target_idx;break ;case DAMOS_FILTER_TYPE_HUGEPAGE_SIZE : +if (src->sz_range.max < src->sz_range.min) +return -EINVAL ; dst->sz_range = src->sz_range;break ;case DAMOS_FILTER_TYPE_PROBE_HITS_WSUM : +if (src->range_max < src->range_min) +return -EINVAL ; dst->range_min = src->range_min; dst->range_max = src->range_max;break ;
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [RFC PATCH v2 4/8] mm/damon/core: disallow max < min damos filter range arguments commit
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 8 lines
damos_commit_filter_arg()receives range arguments for a few types of DAMOS filters. It allows any range including max < min range. It is fine for the logic, but makes no sense to support it. Actually DAMON sysfs interface is doing the validation on its own. To avoid duplicated validations in multiple DAMON API callers, it would be better to do the validation in the core layer. Add a validation of the given range.Signed-off-by SJ Park <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
SJ Park
maintainerRFC PATCH v2 5/8 mm/damon/sysfs-schemes: drop centralized filter range arg validations
In reply to SJ ParkDAMON sysfs interface is validating wrong range arguments for DAMOS filters. Now the core layer is doing the same validation. Drop the duplicated validation in DAMON sysfs interface.
--- mm/damon/sysfs-schemes.c | 13 ------------- 1 file changed, 13 deletions(-)
mm/damon/sysfs-schemes.c +0 -13
@@ -2832,27 +2832,14 @@ static int damon_sysfs_add_scheme_filters(struct damos *scheme, } }else if (filter->type ==DAMOS_FILTER_TYPE_ADDR ) { filter->addr_range = sysfs_filter->addr_range; -if (filter->addr_range.end < - filter->addr_range.start) { -damos_destroy_filter (filter); -return -EINVAL ; - } }else if (filter->type ==DAMOS_FILTER_TYPE_TARGET ) { filter->target_idx = sysfs_filter->target_idx; }else if (filter->type ==DAMOS_FILTER_TYPE_HUGEPAGE_SIZE ) { filter->sz_range.min = sysfs_filter->range_min; filter->sz_range.max = sysfs_filter->range_max; -if (filter->range_min > filter->range_max) { -damos_destroy_filter (filter); -return -EINVAL ; - } }else if (filter->type ==DAMOS_FILTER_TYPE_PROBE_HITS_WSUM ) { filter->range_min = sysfs_filter->range_min; filter->range_max = sysfs_filter->range_max; -if (filter->range_min > filter->range_max) { -damos_destroy_filter (filter); -return -EINVAL ; - } }damos_add_filter (scheme, filter);
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [RFC PATCH v2 5/8] mm/damon/sysfs-schemes: drop centralized filter range arg validations
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 5 lines
DAMON sysfs interface is validating wrong range arguments for DAMOS filters. Now the core layer is doing the same validation. Drop the duplicated validation in DAMON sysfs interface.
Signed-off-by SJ Park <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
SJ Park
maintainerRFC PATCH v2 6/8 mm/damon/sysfs-schemes: use switch-case in add_scheme_filters()
In reply to SJ Parkdamon_sysfs_add_scheeme_filters() has long if-else chains for DAMOS filter types. Convert the code to use switch-case, which would be cleaner and more efficient.
--- mm/damon/sysfs-schemes.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
mm/damon/sysfs-schemes.c +13 -5
@@ -2822,7 +2822,8 @@ static int damon_sysfs_add_scheme_filters(struct damos *scheme,if (!filter)return -ENOMEM ; -if (filter->type ==DAMOS_FILTER_TYPE_MEMCG ) { +switch (filter->type) { +case DAMOS_FILTER_TYPE_MEMCG : err =damon_sysfs_memcg_path_to_id ( sysfs_filter->memcg_path, &filter->memcg_id);
@@ -2830,16 +2831,23 @@ static int damon_sysfs_add_scheme_filters(struct damos *scheme,damos_destroy_filter (filter);return err; } - }else if (filter->type ==DAMOS_FILTER_TYPE_ADDR ) { +break ; +case DAMOS_FILTER_TYPE_ADDR : filter->addr_range = sysfs_filter->addr_range; - }else if (filter->type ==DAMOS_FILTER_TYPE_TARGET ) { +break ; +case DAMOS_FILTER_TYPE_TARGET : filter->target_idx = sysfs_filter->target_idx; - }else if (filter->type ==DAMOS_FILTER_TYPE_HUGEPAGE_SIZE ) { +break ; +case DAMOS_FILTER_TYPE_HUGEPAGE_SIZE : filter->sz_range.min = sysfs_filter->range_min; filter->sz_range.max = sysfs_filter->range_max; - }else if (filter->type ==DAMOS_FILTER_TYPE_PROBE_HITS_WSUM ) { +break ; +case DAMOS_FILTER_TYPE_PROBE_HITS_WSUM : filter->range_min = sysfs_filter->range_min; filter->range_max = sysfs_filter->range_max; +break ; +default : +break ; }damos_add_filter (scheme, filter);
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [RFC PATCH v2 6/8] mm/damon/sysfs-schemes: use switch-case in add_scheme_filters()
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 5 lines
damon_sysfs_add_scheeme_filters()has long if-else chains for DAMOS filter types. Convert the code to use switch-case, which would be cleaner and more efficient.Signed-off-by SJ Park <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
SJ Park
maintainerRFC PATCH v2 7/8 mm/damon/core-kunit: extend damos_commit_filter_for() for wrong input
In reply to SJ Parkdamos_commit_filter_for() supposes damos_commit_filter() to always succeed with given inputs. damos_commit_filter() could return an error for invalid inputs. Existing callers always pass only valid inputs, but they may pass invalid inputs in future, for test purposes. Extend the function to be able to be used for wrong inputs-caused error testing.
--- mm/damon/tests/core-kunit.h | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-)
mm/damon/tests/core-kunit.h +15 -9
@@ -1127,9 +1127,15 @@ static void damos_test_commit_dests(struct kunit *test) }static void damos_test_commit_filter_for (struct kunit *test, -struct damos_filter *dst,struct damos_filter *src) +struct damos_filter *dst,struct damos_filter *src, +bool expect_fail) { -damos_commit_filter (dst, src); +int err; + + err =damos_commit_filter (dst, src); +KUNIT_EXPECT_EQ (test, err !=0 , expect_fail); +if (expect_fail) +return ;KUNIT_EXPECT_EQ (test, dst->type, src->type);KUNIT_EXPECT_EQ (test, dst->matching, src->matching);KUNIT_EXPECT_EQ (test, dst->allow, src->allow);
@@ -1168,47 +1174,47 @@ static void damos_test_commit_filter(struct kunit *test) .type = DAMOS_FILTER_TYPE_ANON, .matching = true, .allow = true, - }); + }, false);damos_test_commit_filter_for (test, &dst, &(struct damos_filter ){ .type =DAMOS_FILTER_TYPE_MEMCG , .matching = false, .allow = false, .memcg_id =123 , - }); + }, false);damos_test_commit_filter_for (test, &dst, &(struct damos_filter ){ .type =DAMOS_FILTER_TYPE_YOUNG , .matching = true, .allow = true, - }); + }, false);damos_test_commit_filter_for (test, &dst, &(struct damos_filter ){ .type =DAMOS_FILTER_TYPE_HUGEPAGE_SIZE , .matching = false, .allow = false, .sz_range = {.min =234 , .max =345 }, - }); + }, false);damos_test_commit_filter_for (test, &dst, &(struct damos_filter ){ .type =DAMOS_FILTER_TYPE_UNMAPPED , .matching = true, .allow = true, - }); + }, false);damos_test_commit_filter_for (test, &dst, &(struct damos_filter ){ .type =DAMOS_FILTER_TYPE_ADDR , .matching = false, .allow = false, .addr_range = {.start =456 , .end =567 }, - }); + }, false);damos_test_commit_filter_for (test, &dst, &(struct damos_filter ){ .type =DAMOS_FILTER_TYPE_TARGET , .matching = true, .allow = true, .target_idx =6 , - }); + }, false); }static void damos_test_help_initailize_scheme (struct damos *scheme)
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [RFC PATCH v2 7/8] mm/damon/core-kunit: extend damos_commit_filter_for() for wrong input
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines
damos_commit_filter_for()supposesdamos_commit_filter()to always succeed with given inputs.damos_commit_filter()could return an error for invalid inputs. Existing callers always pass only valid inputs, but they may pass invalid inputs in future, for test purposes. Extend the function to be able to be used for wrong inputs-caused error testing.Signed-off-by SJ Park <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
SJ Park
maintainerRFC PATCH v2 8/8 mm/damon/core-kunit: test invalid damos filter commits
In reply to SJ ParkAdd test cases for testing the validation of damos filter arguments in commit time.
--- mm/damon/tests/core-kunit.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
mm/damon/tests/core-kunit.h +14 -0
@@ -1195,6 +1195,13 @@ static void damos_test_commit_filter(struct kunit *test) .allow = false, .sz_range = {.min = 234, .max = 345}, }, false); +damos_test_commit_filter_for (test, &dst, + &(struct damos_filter ){ + .type =DAMOS_FILTER_TYPE_HUGEPAGE_SIZE , + .matching = false, + .allow = false, + .sz_range = {.min =456 , .max =123 }, + }, true); damos_test_commit_filter_for(test, &dst, &(struct damos_filter){ .type = DAMOS_FILTER_TYPE_UNMAPPED,
@@ -1208,6 +1215,13 @@ static void damos_test_commit_filter(struct kunit *test) .allow = false, .addr_range = {.start = 456, .end = 567}, }, false); +damos_test_commit_filter_for (test, &dst, + &(struct damos_filter ){ + .type =DAMOS_FILTER_TYPE_ADDR , + .matching = false, + .allow = false, + .addr_range = {.start =567 , .end =456 }, + }, true); damos_test_commit_filter_for(test, &dst, &(struct damos_filter){ .type = DAMOS_FILTER_TYPE_TARGET,
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [RFC PATCH v2 8/8] mm/damon/core-kunit: test invalid damos filter commits
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Incomplete implementation: missing test coverage for DAMOS_FILTER_TYPE_PROBE_HITS_WSUM invalid…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Incomplete implementation: missing test coverage for DAMOS_FILTER_TYPE_PROBE_HITS_WSUM invalid commits. --
commit d95c459dddaa5a1cc3be54d53b10942b9bd9ba9f
Author: SJ Park <[email protected]>
mm/damon/core-kunit: test invalid damos filter commits
This commit adds KUnit test cases to verify the validation of damos filter arguments at commit time.
Quoted 19 lines
mm/damon/tests/core-kunit.h +7
-0@@ -1184,6 +1184,13 @@ static void damos_test_commit_filter(struct kunit *test) .allow = false, .sz_range = {.min = 234, .max = 345}, }, false); +damos_test_commit_filter_for (test, &dst, + &(struct damos_filter ){ + .type =DAMOS_FILTER_TYPE_HUGEPAGE_SIZE , + .matching = false, + .allow = false, + .sz_range = {.min =456 , .max =123 }, + }, true); damos_test_commit_filter_for(test, &dst, &(struct damos_filter){ .type = DAMOS_FILTER_TYPE_UNMAPPED,
mm/damon/tests/core-kunit.h static void damos_test_commit_filter(struct kunit *test) · line 1213
Quoted 10 lines
mm/damon/tests/core-kunit.h +7
-0@@ -1197,6 +1204,13 @@ static void damos_test_commit_filter(struct kunit *test) .allow = false, .addr_range = {.start = 456, .end = 567}, }, false); +damos_test_commit_filter_for (test, &dst, + &(struct damos_filter ){ + .type =DAMOS_FILTER_TYPE_ADDR , + .matching = false, + .allow = false, + .addr_range = {.start =567 , .end =456 }, + }, true);
[Severity: Medium]
Is a test case for DAMOS_FILTER_TYPE_PROBE_HITS_WSUM missing here?
Previous changes introduced range validation (max < min) for ADDR, HUGEPAGE_SIZE, and PROBE_HITS_WSUM. While ADDR and HUGEPAGE_SIZE are being tested for invalid commits, PROBE_HITS_WSUM seems to be omitted.
Additionally, if a test for PROBE_HITS_WSUM is added, does damos_test_commit_filter_for() also need an update? The switch statement verifying copied filter fields lacks a case for it and would fall through to default, failing to verify the range arguments:
damos_test_commit_filter_for() {
...
switch (src->type) {
case DAMOS_FILTER_TYPE_MEMCG:
...
case DAMOS_FILTER_TYPE_HUGEPAGE_SIZE:
...
default:
break;
}
}Quoted 3 lines
mm/damon/tests/core-kunit.h +0
-0damos_test_commit_filter_for(test, &dst, &(struct damos_filter){ .type = DAMOS_FILTER_TYPE_TARGET,
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
SJ Park
maintainerRe: [RFC PATCH v2 8/8] mm/damon/core-kunit: test invalid damos filter commits
Quoted 54 lines · On Sun, 13 Sep 2026 17:28:01 +0000 [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Incomplete implementation: missing test coverage forDAMOS_FILTER_TYPE_PROBE_HITS_WSUMinvalid commits. --commit
d95c459dddaa5a1cc3be54d53b10942b9bd9ba9f
Author: SJ Park <[email protected]>
mm/damon/core-kunit: test invalid damos filter commitsThis commit adds KUnit test cases to verify the validation of damos filter arguments at commit time.
Quoted 19 lines
mm/damon/tests/core-kunit.h +7
-0@@ -1184,6 +1184,13 @@ static void damos_test_commit_filter(struct kunit *test) .allow = false, .sz_range = {.min = 234, .max = 345}, }, false); +damos_test_commit_filter_for (test, &dst, + &(struct damos_filter ){ + .type =DAMOS_FILTER_TYPE_HUGEPAGE_SIZE , + .matching = false, + .allow = false, + .sz_range = {.min =456 , .max =123 }, + }, true); damos_test_commit_filter_for(test, &dst, &(struct damos_filter){ .type = DAMOS_FILTER_TYPE_UNMAPPED,mm/damon/tests/core-kunit.h static void damos_test_commit_filter(struct kunit *test) · line 1213
Quoted 10 lines
mm/damon/tests/core-kunit.h +7
-0@@ -1197,6 +1204,13 @@ static void damos_test_commit_filter(struct kunit *test) .allow = false, .addr_range = {.start = 456, .end = 567}, }, false); +damos_test_commit_filter_for (test, &dst, + &(struct damos_filter ){ + .type =DAMOS_FILTER_TYPE_ADDR , + .matching = false, + .allow = false, + .addr_range = {.start =567 , .end =456 }, + }, true);[Severity: Medium]
Is a test case forDAMOS_FILTER_TYPE_PROBE_HITS_WSUMmissing here?Previous changes introduced range validation (max < min) for ADDR,
HUGEPAGE_SIZE, andPROBE_HITS_WSUM. While ADDR andHUGEPAGE_SIZEare being tested for invalid commits,PROBE_HITS_WSUMseems to be omitted.Additionally, if a test for
PROBE_HITS_WSUMis added, doesdamos_test_commit_filter_for()also need an update? The switch statement verifying copied filter fields lacks a case for it and would fall through to default, failing to verify the range arguments:
Quoted 11 lines
damos_test_commit_filter_for() {
...
switch (src->type) {
case DAMOS_FILTER_TYPE_MEMCG:
...
case DAMOS_FILTER_TYPE_HUGEPAGE_SIZE:
...
default:
break;
}
}I will add that as a followup in future.
Quoted 8 lines
Quoted 4 lines
mm/damon/tests/core-kunit.h +0
-0damos_test_commit_filter_for(test, &dst, &(struct damos_filter){ .type = DAMOS_FILTER_TYPE_TARGET,Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
Thanks,
SJ