From patchwork Wed Dec 13 19:03:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13491785 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A3E3C4332F for ; Wed, 13 Dec 2023 19:03:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 69AF78D0052; Wed, 13 Dec 2023 14:03:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 622138D0049; Wed, 13 Dec 2023 14:03:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3D9028D0053; Wed, 13 Dec 2023 14:03:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 03D368D0049 for ; Wed, 13 Dec 2023 14:03:56 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id CB44C160B7D for ; Wed, 13 Dec 2023 19:03:55 +0000 (UTC) X-FDA: 81562719630.07.4C1E940 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf02.hostedemail.com (Postfix) with ESMTP id 757D38002A for ; Wed, 13 Dec 2023 19:03:52 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gh6j4zF8; spf=pass (imf02.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702494232; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=DxjDroIjLb/yV0SRilP6CnvUfpB6EMvy8qlj20QciKs=; b=BFg/yPMwDpZehvfp7cnIa8/q8tGFd6bBOWtCVYFeg/eVs/QuAp+snUP7NtZFp3SxEz49N+ DESLyNPY67u+tFPHbNjQFqyJZz9zWjArKS+ocolhUzcDPfY6oSDYfIFevtiAdlcWJRYGIF RJu8C4bH7MKzGRLLXK/FnNMEFSOUbxM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702494232; a=rsa-sha256; cv=none; b=vqI59ptqp4eZjRlf5IXa7K/mSZKTFgey0IJnoNITEBPJ8rEx5usqBDmmDJyiUh+ZEB1rye R3nVaocA8ujSIndZmNjOLUdOsQQQuZD6thLrxH8IkYUgP1pJFCFLEJ1q+7dOOAa/U97E0o 6sI2wHrWLW3hQbd2j8zyYkxEQBnhRNM= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=gh6j4zF8; spf=pass (imf02.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id 53172B81F1C; Wed, 13 Dec 2023 19:03:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC743C433C8; Wed, 13 Dec 2023 19:03:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702494229; bh=gjBQjP/YI+pvMOKNh4ddMdbLJ3KLmfM9HXn1Dp4kPVs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gh6j4zF8l93bobVI7GSErZD+7LyrzAOafaTw/R+gygXqiWV4CRdqWwXQ4WHnfcO5A ntCVTNa3MG2BjUATa9SvAKwQAfINk5MJbH1cQsimTz2xBRm2XyU16JA/pkCDCVZBLM tYqx26QhH06nd6+RI/CnV0NU7hK5ynOAW+Z0EaxqXgVK7aTJLDK+cN15J+KLBe+wGl FPY1GTm8dlM/DZ8CdH2eMVZ9cww7cSXDsMBAbUrukA7Khyyau/bnOZiSGqHIhpwnXk UQuZluFbU+/gS0nN3hGdfFYeZSaojRVgc0zs0RTAEI3p5ZqKWxiCp7cU9I6UkJIWWW PXaXBm0veoOYA== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/6] mm/damon/core-test: test max_nr_accesses overflow caused divide-by-zero Date: Wed, 13 Dec 2023 19:03:34 +0000 Message-Id: <20231213190338.54146-3-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231213190338.54146-1-sj@kernel.org> References: <20231213190338.54146-1-sj@kernel.org> MIME-Version: 1.0 X-Stat-Signature: wybjjzwugfkbd74mtsu6f641hukp5jnq X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 757D38002A X-Rspam-User: X-HE-Tag: 1702494232-575547 X-HE-Meta: U2FsdGVkX1/Po2R+CdExgxIwri2wCTWeUfCGiUZ2R3F/JECkrI+S4rwy/GFCUWZYOL0CtTSq1qM3xkSrya2iMBLQKi4B0KyCFr3dfUQFjiwdmwpHiOa0PyYdSDXbukDQ5l7uufUABgmOkQwUVS0yJIoLylzBUrNcMPLSht32tqIvmowUhH1UU/c5q269Wkz9YPLetkQbClAuj0qV837RSuTg0gfeq0NjnVk9uphQjTFE6ZAMt5g5PtJ1XlUVTa+Me5Ng9zGwJahGcTUqiSnfKQMcgSQJIMjSFMzbzEYDvOJPVKvixdXGbJpjOxatYYpQvCZQEP+LZMlwW2QeshLrxU77i9FYz1Wn5dJB/gsowyMeXCti3pQFHqH8o2pin+dWFtCjigutLD9HHz91o1FLfSQxBxyxNKwp6JotqLVlfl2nGi+64rD7lLKNFybRMc+p0J5V9YZo6BlrY04utHaesmSA/EiQdl1p777GY8biD5H5k7oj+K2EYs87T5y2Pyq5FLXtP8Q0GAw2Wc4LMROzuAXXVFbx9pSvHHBj2VrKMi+H0P4YnsbTJO4soCsLj4Vsx9zCXjqyamn1+hbtrNHLDDifcOQvZnElk0pANPPVQZ5FuU/l2yTn/7kn/EkO+rDQwN9FgMiSV3YbCop0gKoNMZyPumPVO0uDikWKvZy7jzjRyWz+PdEvltI5jaxwUlhdYn7baBftD0Vbj7BsZZvYHyzX0ya6nrWsymD0AiA7U8t3Z3H2SkNSg22By9MhckpcyD2rTPvjcPblb6oHacjGyfxHRAzYBGouJiCWK+8I4Cweje94TubHIZz3OpamBnn1QpR4cW43CogjJFb+hdfIwxfwKJOdTTH2LFWE0QHg8T6tnAfWZ6+AATThot1Y28X3xcgpaQ58mVFBvlrqP6brNfX5V14zUAnMotS5/yrnOGkJQCoiEe95Zxguu84b1KVSLjFIVHLdlGL8w+7BiFP 4e7ZErvD BYdL8lHhVIDwV51ZMeEcBjaLrTdFblriQkyJWQYmA2+jUF+TK7rJpJv3HH5pYxW5HcIX1SEFDT6eS+a8+kZKc9rrDhgdDqLlxERTSQuoAKM5i+EdgwTL+scNPeqvk7nNiyUPVisMHYMCXi8AgL0RyuNMd0GWERQNkjUeMTjtdbZgfvMX3V3AKhMWlD3IX0vHi9Iw9AC2n86Bm6FFw5NK5U/e1+hxai6V43czyY9ntARoQwgrXRzCHI3CAo3OeZJDk/c/I82qgRbr9QcFkpdYw8lvIXg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Commit 35f5d94187a6 ("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. Signed-off-by: SeongJae Park --- mm/damon/core-test.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h index 876e398557b0..0cee634f3544 100644 --- a/mm/damon/core-test.h +++ b/mm/damon/core-test.h @@ -302,6 +302,16 @@ static void damon_test_set_regions(struct kunit *test) damon_destroy_target(t); } +static void damon_test_nr_accesses_to_accesses_bp(struct kunit *test) +{ + struct damon_attrs attrs = { + .sample_interval = 10, + .aggr_interval = ((unsigned long)UINT_MAX + 1) * 10 + }; + + KUNIT_EXPECT_EQ(test, damon_nr_accesses_to_accesses_bp(123, &attrs), 0); +} + static void damon_test_update_monitoring_result(struct kunit *test) { struct damon_attrs old_attrs = { @@ -487,6 +497,7 @@ static struct kunit_case damon_test_cases[] = { KUNIT_CASE(damon_test_split_regions_of), KUNIT_CASE(damon_test_ops_registration), KUNIT_CASE(damon_test_set_regions), + KUNIT_CASE(damon_test_nr_accesses_to_accesses_bp), KUNIT_CASE(damon_test_update_monitoring_result), KUNIT_CASE(damon_test_set_attrs), KUNIT_CASE(damon_test_moving_sum),