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: 178262 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8003391dys; Wed, 13 Dec 2023 11:03:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IG3gosRtb3xl9u+3XwYvVJyMz0sGh5lYKnaN4VgHZML6kbRshhTpk+PnkliqF3itoRHe1va X-Received: by 2002:a05:6a20:4295:b0:190:38ef:3a57 with SMTP id o21-20020a056a20429500b0019038ef3a57mr11823749pzj.28.1702494239167; Wed, 13 Dec 2023 11:03:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702494239; cv=none; d=google.com; s=arc-20160816; b=xvc4Fosa55jxClnQ4/3EWfhQQUrLuQu41AQgea83Sem4nW192kv+7ICiwdhm7MbvSw oXUUphYvx/hx37Z6cMIqSyhvqLLPlpd9VXuqdzhhXJyf35CytUpi0zMjwJg50D5jSS12 LDNTD4epe4Kxw8D7+k9emIxJ1FnD5sSJDwRuJmssXLE9spoEmEIIujvoGq9EVpUiQBpD fHPs5erXGKeewJkWmhvgaRIYxXtPFTujmAn6qADAm3sDBKrxiH0qYftBrmMuaIWsei4c v4nt+nW5dcX1sPPs47FsuGUa+gs/UhTRNXyUCphAaQTkf5vPbDYW4Ye+MY+mO4ZQd9Gm TnKQ== 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 Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id k24-20020a6568d8000000b005c66616240bsi9978093pgt.567.2023.12.13.11.03.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 11:03:59 -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 5FCC08029D01; Wed, 13 Dec 2023 11:03:55 -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 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:03:55 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785194598938472777 X-GMAIL-MSGID: 1785194598938472777 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),