From patchwork Fri Oct 20 17:23:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13430981 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 9C227CDB474 for ; Fri, 20 Oct 2023 17:23:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DC86C8D01CF; Fri, 20 Oct 2023 13:23:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D276F8D0003; Fri, 20 Oct 2023 13:23:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B2CCD8D01CF; Fri, 20 Oct 2023 13:23:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 9F0768D0003 for ; Fri, 20 Oct 2023 13:23:32 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 74817120867 for ; Fri, 20 Oct 2023 17:23:32 +0000 (UTC) X-FDA: 81366511464.01.768AD4D Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf30.hostedemail.com (Postfix) with ESMTP id BF42C80002 for ; Fri, 20 Oct 2023 17:23:30 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=R2Uo8d1d; spf=pass (imf30.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=1697822610; 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=fTlqNdzbFdc9R72dERn2BM6lGJw+6/d2x02vllJOm3c=; b=5q8yqz+wNTFdRxYp0iY9W2nGC9q8ChQOmL8F/9U7wTAHOVKuFjv+wed3+jKvfNXgWbj0s/ sv2OhQwpf6AtXPGeo32bp7VzpHShZr5PCSZG7MKQTtRzQEZVWulxC4L6TRlbT0Fk4mA4Wf WoBeKcY9bZ6yqe9yf/WiE/mnsNyVcu0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697822610; a=rsa-sha256; cv=none; b=gKuYbQFSj3ysQj77rHBoeEyxSu6MmQwIOlZFYkpufre2EIpPl7gfIu7C38KUHYEBxq0Oo+ dh/SeXNYLDw/H8kNvTHwgs41+u+PjsZ8vswGZIO6uLOBRAP+lgDkvc9Md1rGEAxdAncsLL nHTrwe+hDpTOHD4SK1iysL/C47z1yWY= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=R2Uo8d1d; spf=pass (imf30.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 6EEB4B83313; Fri, 20 Oct 2023 17:23:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 744D4C433C9; Fri, 20 Oct 2023 17:23:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697822608; bh=A7qQGX2x61HuX9WngSjrxy/tMdxThwG7cO+vlCnt/oI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R2Uo8d1dOObRxHmQhvT+GaBkbeipS3EDjJHzlrqnXCOqDtzreW0cAfNfLBKnVc8lc lCprkGxeggXj98oVNf/z2gNIDicTFnmBoUSvD8XtZKmqF8BGuA1vA5ufLZh4OjhNfY xc9+xQc4jg/efEPeUXH3jErpnXwLGo738cZmOScqm/dYnZfejUTXwGj+LjFdURrRTu pAbE3gO8gyfQ/zOq8DRIK0aUFpnm+GIxyJPhGLoPRDPqkfz3HJWzOyFpKlnff7OBsQ 1he8H2Uc1OZyM9peBjSqaiWiqy51/HuuUooffHS1eN5ncUvPAJQtvNwZEIHW/YnzZt O2zyOi3nvaUSA== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/5] mm/damon/core: avoid divide-by-zero from pseudo-moving window length calculation Date: Fri, 20 Oct 2023 17:23:17 +0000 Message-Id: <20231020172317.64192-6-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231020172317.64192-1-sj@kernel.org> References: <20231020172317.64192-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: BF42C80002 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: igtbycjzshd7r6f6qi5rc7puqedt7155 X-HE-Tag: 1697822610-758377 X-HE-Meta: U2FsdGVkX19eZ11Sg4DWRuQyjSc2EQeTyA8ERT5cxTloa2Rr91U90poIFzzfSqlr+yjGtXdLDJ2uE7rl5ZjOmPVyCo9VN2oK9snTJiU3QLp+eepBPp2kaKS05EPmYGthDDsFF+Y9lxcXmTY5mDJvB/14cWjZUCDa1Uq8WLiRCsGaa/RTX35z7Mvpje4lhsT5gJHtqzGqZuLQtDPqVBOOqbv4foGTuzxB6UPAXgAGHw6I/T0oBfNFxkU5JLMhuzaPc3a1lwMJ9nDNyiNfII8Ar55QFl3JoostY5HY2tt/uoPhwBk68YqZhFa3y3dmu9Wnupo1ypzcJJr+9MZpo/p1gnKC3MnlQimnAriZSeEi8+iD/P2sqDLG7JhkwYJr4WSchtRUp/AhzKLNZE2EyCnUQadz4RxhZ2JdVGRv35nWqgiGWTh4coiEp9yi5Hv1pFLMP483Wq82b8h5aJDyIB2IZkR6hgd8NCxCAQqoihzxDP612Pgf0ztwqubLGlmT+OCi7+w5+7WzS/c+DpUct7QHBpkld4ACoYQ35Er718IiHVMtcnQinReOV9E0a6MZN0rpYx3PcgtieVLWzPoqiNJ8dYhVLIoIurdm7EQTNR2itS13bopg4V4MNyJlFhCxhyZmBJnOS/he+tc5w9aQibxVkuPT7UTVH4LUMeOp7SCkHdHZc3/4Us/CuNJjOIx/wI+mQO9p8IaNLUntNZKsmDYVDJ+emHEbP5I4OqQOrxXUuuOUTgQZeuyTTiYR0XTven7SRyChptKYAO5Vb4hOAM4B9Fdrb67hR03B6C+trZ/qOC0APh940/vJe1B3buKy/NgPStOPjpmvbB+o0G2nX2amC24f+fHyG3EgBvGSGuhJIWvZnuncr10O3Al/YtmoQSwAk9bZCIV6wW8GcWUXQKmBTu0wo4Y9ZOWXg84uPpsthy6V4jLb6s58qTjFSLoZfaffYi2xfGwD99k0M7tn5SV X0YOuxbZ bl62m8TmXKWPOvbA+W3FsGtJYWUnQ19qP1hGHrPIbZ9ITZ46wvvpwr3MthDKAuU4OhDWglg4n+RjwbBlcEcvaoiJSTP20ftd+pGH/ofwl9rbVFsLB7zFhTB5rKyJn/gtkItO81Lo6PN0NLCjnlvuFnhoGfx9G1eKb0YqYCDleXgnxB1EJPyfbl72MvVoYzq2yyNpaEtA0LtlPsNtOjh+snRZ0ACxmuM53uXH+UEMp+FWxwGA= 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: When calculating the pseudo-moving access rate, DAMON divides some values by the maximum nr_accesses. However, due to the type of the related variables, simple division-based calculation of the divisor can return zero. As a result, divide-by-zero is possible. Fix it by using damon_max_nr_accesses(), which handles the case. Note that this is a fix for a commit that not in the mainline but mm tree. Fixes: ace30fb21af5 ("mm/damon/core: use pseudo-moving sum for nr_accesses_bp") Signed-off-by: SeongJae Park --- Note that this is for a patch in mm-stable that not yet merged into the mainline. mm/damon/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index e194c8075235..aa2dc7087cd9 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1665,7 +1665,7 @@ void damon_update_region_access_rate(struct damon_region *r, bool accessed, * aggr_interval, owing to validation of damon_set_attrs(). */ if (attrs->sample_interval) - len_window = attrs->aggr_interval / attrs->sample_interval; + len_window = damon_max_nr_accesses(attrs); r->nr_accesses_bp = damon_moving_sum(r->nr_accesses_bp, r->last_nr_accesses * 10000, len_window, accessed ? 10000 : 0);