Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5524825rdb; Wed, 13 Dec 2023 11:04:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IH4xYbyJaDuNb1YDpClrHKhNtZiP7rCyHY+RT7HUv3vpZ70sO+/LnenGEF5GNrLuOH9te4D X-Received: by 2002:a05:6a00:1303:b0:6b6:5ed4:dd42 with SMTP id j3-20020a056a00130300b006b65ed4dd42mr10070951pfu.31.1702494243257; Wed, 13 Dec 2023 11:04:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702494243; cv=none; d=google.com; s=arc-20160816; b=Slhge6YejYeR+dT+M8rmHt1CKsGY5KBzOfouklCmD476ZCp8Oc8hGda5wA3XvFS8GO hOV1T8x+ZUOd8bMT5gZasxSm4P9AA4H4qvDC8TFLA6aXIXTvPBHvneLMeVlzjOGzRs3j Lu1lhaWDnzCdecw1kVpxPsMPQwbypSqMjuExUfJo4F1LWxogAwv4/qa6ecNV6hmK3M6w vIVi25EbVNNM5n1nW32ZkfhSEd+2ryO6wYXZkKRm8UjWijhhnpNd2ZEfDykDzui0V8ud wgx8BzYoDoQc5t6dtnY3slOXJSlatEv17BRTT+QqL4TcF66dAx4srfbi/bpQYkbQrhGh vmwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DxjDroIjLb/yV0SRilP6CnvUfpB6EMvy8qlj20QciKs=; fh=BzdeVYqZhG5iuwuKJRNLP969rvCput73lx0iwx2zu7A=; b=XK3X9AIat/28F6lmmDywcmm2cRpmnvSPguyYXSz+J2XhCtJ/O7Tyfg35oO5KpYgOai W7HRfiLm5MZCUMK3bDv3BZmNDLyfrGILyIZ7mbRFxEUok6plN8IAzBW8yTZyE0pPnaUf a2E1Jl4dEZHTugvVGRUHJ8PbgDQ50FBaOPK/IIaniKwQSHeD3a8QWGUKoHKP8mihkXo3 a5Qnr76DvqjaGTTbsf9AucvmUy/dVFeLTMravZxK7xDykexrVskyXFYekO0C2w7YvplG EfQ1QLVb3KixOuu1wYY63ZTJWDzfIXLWyRxJ9g1+dNBNIYPukRXKhjkbkWth8WfYQZFk a+Pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gh6j4zF8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id bx2-20020a056a02050200b005bdfb8a9048si10409845pgb.67.2023.12.13.11.04.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 11:04:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gh6j4zF8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 06A8D8029C7A; Wed, 13 Dec 2023 11:04:00 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441829AbjLMTDp (ORCPT + 99 others); Wed, 13 Dec 2023 14:03:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379292AbjLMTDm (ORCPT ); Wed, 13 Dec 2023 14:03:42 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9126595 for ; Wed, 13 Dec 2023 11:03:49 -0800 (PST) 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 13 Dec 2023 11:04:00 -0800 (PST) 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), -- 2.34.1