[5/5] mm/damon/core: avoid divide-by-zero from pseudo-moving window length calculation
Message ID | 20231020172317.64192-6-sj@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1213403vqb; Fri, 20 Oct 2023 10:24:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFwAF9B9TeRjou2CZNunOZ7GN1I3UeLq5JtKudAHDOP5YV0KRu0Y67CfqEN88EEw+00q4G/ X-Received: by 2002:a17:902:e809:b0:1c9:d908:d60c with SMTP id u9-20020a170902e80900b001c9d908d60cmr2226847plg.63.1697822640342; Fri, 20 Oct 2023 10:24:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697822640; cv=none; d=google.com; s=arc-20160816; b=EturohyC+dFF93bfCMCkLSzaS3SeHbAbFqk3udImL6HJvVk4jTO4SqIMWuKCyE8i32 CXmRVReXDpy3pfn8qwhb/zB7zWqQ9rNLbWg6KwJuPiHjKJyK6aZ21lKRr9GNY67x8U8w Rm+Ca3xitu6tOsRcidecplcO6DPBYN1SXdTmlbJat3gEhF71ICOUcUGK7gWr4eL2D/pz DJtpcOMZhgFJleqZ10ZhpWMAXaAnMuA3xKtH9l1mXQj9h3XXoh1BpiU3rQ5M6laXFbXo OXOS5AnQy5RI5pTx6GsLcNuACGbhXFmDTMYIpGSaVdz5dNb5occV2MX8BpzBzuo3Ea4e wRfA== 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=VFP6PRL4mR126zCoKmNEbu+s6BBtAdhf6/+K6GZhfHH0nxAmBRdKbvSRLgIQCwzCOL cw8rXAYhkiPGFCegjHXHwo5kY+8U5DsrwWwav9ICQNi9Zn4EI8b3mYA9bxu5jUi1M30c 0+ZwPkGRznt/cFuKu5YVdoyCxIG+MG8Q5aQaFya7c0RwMTLV/am52f+X0OdhAEoFNHJA ZIc7ieb9zHt9irP5IbYSPpdmHFwVGeg3AkfzTfeIEON0YuHi/m6PGmKQZuGijhBPwfdS tbKuQMpTbDWvU4Zg1K1KNeLWXysr9bWoMzmgX7M/ZQb41z64WyD+dIu8MZMbw1lhpwmS +5BQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=R2Uo8d1d; 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 w13-20020a1709027b8d00b001bf0e15c0a9si2089879pll.269.2023.10.20.10.23.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 10:24:00 -0700 (PDT) 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=R2Uo8d1d; 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 36D48831748B; Fri, 20 Oct 2023 10:23:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377971AbjJTRXg (ORCPT <rfc822;a1648639935@gmail.com> + 26 others); Fri, 20 Oct 2023 13:23:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377945AbjJTRXc (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 20 Oct 2023 13:23:32 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24B9813E for <linux-kernel@vger.kernel.org>; Fri, 20 Oct 2023 10:23:29 -0700 (PDT) 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 <sj@kernel.org> To: Andrew Morton <akpm@linux-foundation.org> Cc: SeongJae Park <sj@kernel.org>, 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 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 groat.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> 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]); Fri, 20 Oct 2023 10:23:57 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780296073194217845 X-GMAIL-MSGID: 1780296073194217845 |
Series |
avoid divide-by-zero due to max_nr_accesses overflow
|
|
Commit Message
SeongJae Park
Oct. 20, 2023, 5:23 p.m. UTC
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 <sj@kernel.org>
---
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);