Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp1176437rdb; Fri, 20 Oct 2023 10:24:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IESsRV18mZ9UiCWcVKDhjW2Z1K3M303rV87/gmWO3QIYjEFr5GrAag/vNVQ2GRxNJiFGPCC X-Received: by 2002:a05:6358:342a:b0:13c:eea2:d021 with SMTP id h42-20020a056358342a00b0013ceea2d021mr2947773rwd.9.1697822645286; Fri, 20 Oct 2023 10:24:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697822645; cv=none; d=google.com; s=arc-20160816; b=zI8EpIEAsGWDo8lJZrKlppm06xv7vAgA4gBmnZZOLMb8RMMer5uRTUqqk/4KlZavnO FxHGrs9Wbyez9scALau4rnEEPhjAWk3DGj1W2XnZyo+kLddfgqgURP4jWF/rH7wSy2+E ChLlurSf+5FGOE8yLEuvpY9SSs8Hzl+K09d1MjFRkQndLTZS/9BLm7TvVQSJ5SF3mHsl xHkuKO2bV7iLhbB3r2epl7DD4TgYXpUt/iAZTOGytTE0mGMsvKAGDwp2NKzlREGYpmBF mWLUd7QmovDqaFjZZEI1KWqDdmByw7jtcI9saMcEyhUA7jv0ZZVaRysbd64RY1uYzMob YRJQ== 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 2620:137:e000::3:5 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. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id bu18-20020a632952000000b0056a36f9eb0esi2418468pgb.15.2023.10.20.10.24.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 10:24:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; 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 2620:137:e000::3:5 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 1B6FD8316EE7; Fri, 20 Oct 2023 10:24:03 -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 S1377970AbjJTRXg (ORCPT + 99 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 ); 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 ; 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 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 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: 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:24:03 -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