Skip to content

Commit 5e06ad5

Browse files
sjp38akpm00
authored andcommitted
mm/damon/core-test: test max_nr_accesses overflow caused divide-by-zero
Commit 35f5d94 ("mm/damon: implement a function for max nr_accesses safe calculation") has fixed an overflow bug that could cause divide-by-zero. Add a kunit test for the bug to ensure similar bugs are not introduced again. Link: https://lkml.kernel.org/r/20231213190338.54146-3-sj@kernel.org Signed-off-by: SeongJae Park <sj@kernel.org> Cc: Jonathan Corbet <corbet@lwn.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 6ad59a3 commit 5e06ad5

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

mm/damon/core-test.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,16 @@ static void damon_test_set_regions(struct kunit *test)
302302
damon_destroy_target(t);
303303
}
304304

305+
static void damon_test_nr_accesses_to_accesses_bp(struct kunit *test)
306+
{
307+
struct damon_attrs attrs = {
308+
.sample_interval = 10,
309+
.aggr_interval = ((unsigned long)UINT_MAX + 1) * 10
310+
};
311+
312+
KUNIT_EXPECT_EQ(test, damon_nr_accesses_to_accesses_bp(123, &attrs), 0);
313+
}
314+
305315
static void damon_test_update_monitoring_result(struct kunit *test)
306316
{
307317
struct damon_attrs old_attrs = {
@@ -487,6 +497,7 @@ static struct kunit_case damon_test_cases[] = {
487497
KUNIT_CASE(damon_test_split_regions_of),
488498
KUNIT_CASE(damon_test_ops_registration),
489499
KUNIT_CASE(damon_test_set_regions),
500+
KUNIT_CASE(damon_test_nr_accesses_to_accesses_bp),
490501
KUNIT_CASE(damon_test_update_monitoring_result),
491502
KUNIT_CASE(damon_test_set_attrs),
492503
KUNIT_CASE(damon_test_moving_sum),

0 commit comments

Comments
 (0)