Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp1176167rdb; Fri, 20 Oct 2023 10:23:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGyMyHqZTLYOZK24kuTlDkLEjvzRK+XEtg1K+7cSPMvkqIKc5nrsehujDnGTuQ0AUQVVNPK X-Received: by 2002:a05:6a20:1595:b0:17a:f0e0:ed07 with SMTP id h21-20020a056a20159500b0017af0e0ed07mr2984169pzj.15.1697822612748; Fri, 20 Oct 2023 10:23:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697822612; cv=none; d=google.com; s=arc-20160816; b=P9BlenYYMmSl7mBWMg9rD0XnOG74UfKkGFvhUoJ7g2QjR0aFulXg6jPZMTftOEMkxj m+t4ze6/BAnn8hfh3S9eZRp18jmZM8k8DHYsB8fKceDAOutLB3mIcTN/CjL3H24PLENb zOpIgzlQ1mv0f0Crv+B4+0dgG8rVK2ZFTf4GXhO1TIyJcgGWr+zlEjGS2jx5Kva82R/G zNVzku7b/kJYevbOjdvN4CfrJmUBrgC4hafJgw6JvML+0wSrXsVsPO8dqf90yJypVbfE ByYywW2e1QCVPHJQ2W977+FxoA2P/X0G2eBgpMGtGekeQ9Vg8rvUsM0JlO6yoMA90W9Z Okcw== 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=gHG3JngsXmc6BwWUvB8MOvbIsEavnDuQdNxca10fgBw=; fh=nlZbZM/lrRfzHQcwYZKnNixXg4ySijwiL5np8ihS7AE=; b=Y56qHE5UcY7gOVARegbfscYUVd5VQvnpnQCDQlBAP4kqpdOAevHlKPDVj487t92A7t 0z99sD3Eh5wsw+XiE04kuw+fRJo6EOrNaMF903D6PeOlXFFz2iOHK7HEg0QaZx9pcjwp VW/TsLVEQap1h8AVq2k3cQ9LKlL9zXBUWL+2gRuoOAwpAF7XCyTc+lvhmLfpriD+havQ 0tpDfqa2EPHCeczTMYLFESXyGCFfrtb7cCRrROk6RsA0HzFQrFzv3ivjlP5cJO7hvbRK Cz/vW/8lBSqwq63W3pUrbmPcOQ+8oZ+CR6LH3vBKef8XH+xSVfHBVMEylfS2moL5krWX LLCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tibiLrMD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id cb12-20020a056a02070c00b005855e5e2f98si2520275pgb.75.2023.10.20.10.23.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 10:23:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tibiLrMD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id BB36F830C329; Fri, 20 Oct 2023 10:23:31 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377924AbjJTRX2 (ORCPT + 99 others); Fri, 20 Oct 2023 13:23:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229909AbjJTRX0 (ORCPT ); Fri, 20 Oct 2023 13:23:26 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA258D4C; Fri, 20 Oct 2023 10:23:24 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1487BC433C7; Fri, 20 Oct 2023 17:23:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697822604; bh=OyGTPA4KF2+eYVdgVawdmd836X4nvWEWuxM0J39C7SY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tibiLrMDEW1tJPRD83m27OwLCd/3DldWtN6HSY+GRNl2CN2/lGFqdA8TQQ727MbK1 RXghEBiUVpRYW2wWEiF2yiDTw4Mz9aUN/5jKYr74Dv/eki3xYKDE93RdSo9tqctrMh CQYh7C/JT6Pd/m/Lx4jnpiYh3AL+5ZGjJ0Dgwm8qeCTjxEkZ//jSvkKcBywnn8qJsk xIov6mao/lOfYVmBmQThgDh3lKi7Zq5LeWX+G0A45G30D5VHCYpRwm1A1Anhin9GeL YqhXZxPUTshcAwA2xiNxXzGXvG7BgM88reL/1z9rKcS6B3dNgRns0LUK1vsgdWaqlG PvGSzwlgnkpAg== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , Jakub Acs , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v2 2/5] mm/damon/core: avoid divide-by-zero during monitoring results update Date: Fri, 20 Oct 2023 17:23:14 +0000 Message-Id: <20231020172317.64192-3-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=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Fri, 20 Oct 2023 10:23:31 -0700 (PDT) When monitoring attributes are changed, DAMON updates access rate of the monitoring results accordingly. For that, it 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. Reported-by: Jakub Acs Fixes: 2f5bef5a590b ("mm/damon/core: update monitoring results for new monitoring attributes") Cc: # 6.3.x Signed-off-by: SeongJae Park --- mm/damon/core.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 9f4f7c378cf3..e194c8075235 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -500,20 +500,14 @@ static unsigned int damon_age_for_new_attrs(unsigned int age, static unsigned int damon_accesses_bp_to_nr_accesses( unsigned int accesses_bp, struct damon_attrs *attrs) { - unsigned int max_nr_accesses = - attrs->aggr_interval / attrs->sample_interval; - - return accesses_bp * max_nr_accesses / 10000; + return accesses_bp * damon_max_nr_accesses(attrs) / 10000; } /* convert nr_accesses to access ratio in bp (per 10,000) */ static unsigned int damon_nr_accesses_to_accesses_bp( unsigned int nr_accesses, struct damon_attrs *attrs) { - unsigned int max_nr_accesses = - attrs->aggr_interval / attrs->sample_interval; - - return nr_accesses * 10000 / max_nr_accesses; + return nr_accesses * 10000 / damon_max_nr_accesses(attrs); } static unsigned int damon_nr_accesses_for_new_attrs(unsigned int nr_accesses, -- 2.34.1