Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp583747rdb; Thu, 19 Oct 2023 12:49:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE/uqoja/XS6YpI9pYMsPUHNyVTTb3P7iww9dUGf7xz2pZi7Jkfj7csPHkv+0jUf2zWbh9Q X-Received: by 2002:a05:6a00:994:b0:692:822a:2250 with SMTP id u20-20020a056a00099400b00692822a2250mr3389892pfg.17.1697744990491; Thu, 19 Oct 2023 12:49:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697744990; cv=none; d=google.com; s=arc-20160816; b=JgBNH0rDJ5AvV1OjPy1XOXcaQOPsFAVD70GPTczMcrJwmauMrsvM8FDLvo0Fapsz7B RvAaWnuV1b7Plgky6oYG+ZUviy88YADJeNsDmBt/vzK3ZWDAP+1xs9nmypO46iY167gn RK2WO+PS96nKf+nznf0j5Lttn3SbUVcQ6eAVyVI2JKiFV9NL8cpwuYazG054iQ2SaJ24 HHnlwzhhkFTNA1Sr5kHPlX4ZOxv8jo3QOvChAMiN1Z+6cPFVZdHofcbEZoNtcvX1FA+O Uv+636wAuGlpfHyBgEd4c7tcqzrUz+kiCSKgRc4W3tzXTn3z7YBxBgM60mZ880DpXpzh xccQ== 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=fTlqNdzbFdc9R72dERn2BM6lGJw+6/d2x02vllJOm3c=; fh=BzdeVYqZhG5iuwuKJRNLP969rvCput73lx0iwx2zu7A=; b=BLvtFDEqATyA32Mj8B1loteqCocUz/RVhvYrBL6uOPutE3K7epnzfMHOycT4h0pMeT 6X+5ADUQToSAH7BCt3BGlb87VODro8NLvKNwqLFXy+bYQMwvdRBATdxlpv8UB3ID3DbJ ldP4j4ybcG+vRJF55V4I9277q3LGbrxfYQIaTx4yXJOPsMBgrAGz/xJWOosYoiDT7fCo i11ZiSzxpZMACtOm3+QWSKAx4TYr01jjd5/zRtO5NKr7eboutccPJ1SRMqlZ++P2s2WW qKZUE5FxO3KpqPBxepzHYjKYENcpbeKJhRGJY/Sku2eyOd0iVIdteMZFBCy//6/Y+Bmb +9Xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lNgSoOfs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id x8-20020aa78f08000000b006b77c54544dsi295400pfr.195.2023.10.19.12.49.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 12:49:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lNgSoOfs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id C1F938347B40; Thu, 19 Oct 2023 12:49:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346546AbjJSTtn (ORCPT + 99 others); Thu, 19 Oct 2023 15:49:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346517AbjJSTte (ORCPT ); Thu, 19 Oct 2023 15:49:34 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FB5711F for ; Thu, 19 Oct 2023 12:49:33 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6BB7C433C9; Thu, 19 Oct 2023 19:49:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697744973; bh=A7qQGX2x61HuX9WngSjrxy/tMdxThwG7cO+vlCnt/oI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lNgSoOfsk3ij3VEBkFziLTTOeodtOyWouwKEqFx+/Vc1mq4dpwxhRKSnXoRwsoucb xmeYm9yqQYBthSax96jDtI9ODtXEb7yTCOZCjdebg76CWIbn9yQVDy2jFkZj8rYXd7 oNq9xzrIQ25Tmf5XiVN2Aee+jPubzu3B3kxz7bjVCA4KdCtkt8pFLhJZjYzNyONzZQ PkVOy9fqQoNU8ok3jV6I4nU555Th406ewtAd/tBdhmST6Bpzl33dF6VUag7JudpLqA tc87Na/V54yov3Z36qOUQBq0gpwPA3O3j6ZH+zXwVdSxO1X3vjDD/8mnwLNYKGgs1n qQNgxlmk5W1XA== 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: Thu, 19 Oct 2023 19:49:24 +0000 Message-Id: <20231019194924.100347-6-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231019194924.100347-1-sj@kernel.org> References: <20231019194924.100347-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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.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 (morse.vger.email [0.0.0.0]); Thu, 19 Oct 2023 12:49:48 -0700 (PDT) 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); -- 2.34.1