Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp583709rdb; Thu, 19 Oct 2023 12:49:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHrbjp2NpDh60ELvP4KLr2p+wSWFfKRectU6papAbpLwr1+WN6bNCldl8hk0OdhctK9zUph X-Received: by 2002:a05:6a20:2325:b0:172:9b19:66b6 with SMTP id n37-20020a056a20232500b001729b1966b6mr2719746pzc.32.1697744983622; Thu, 19 Oct 2023 12:49:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697744983; cv=none; d=google.com; s=arc-20160816; b=fUDODhmYNC8f+3W2eLNlPzTX6VnGmf+SQSWnAFyoddaajT7yv7kDTQoP3pxahHiOtW TWa/PvGj52MWeoLJTQyCW+hJF7lNhJJYvtlo7C+aRwYoeJvss1OQHVJqKFkVNJ3VtSKb yItxPzkotpTDe8MAMwANc2r7dwRR7aUdIMTiwXw4ayJ1oKori7lULraCjFK5HanK4Zhl IxFXXvDncud4PzT9ToLm6W8OZM78JMwD15GQpdfeysOzTZ/WgVDWlg3nxar7A6YsxYHu DC+qDar1rilU6zob+dVx15q1PsR8dd17whzDBqdsFRd++44GNLByLCDvslJmqJHR0xv8 qhzw== 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=B/CCsTDa+XZDlq5k3rMLYJEgO7TntQ3l0uMTeRRAAts=; fh=WXAAPMfSxLmsB2WJ8A0s7FPd+eTotx5bYas/XF5lzN4=; b=l0JQdG4tzxo0JdzHAnAF9rZvIGLJ1yJoWtIJXkSmj7ImfjJBVFl4lq9taxmgGW706p am6KBFB/q5loL1bnrCLK2Drm9DrWzSqeaKdDjWUPiqSzUM4vHkqLdiHPyKIFtJJwenfI rzPIPbRV9W2fpeu+/luuX4VBlyh08Yolthn3XbdJnCnq9chG5041Bi8FPfZxieZ9hLe3 oz63CXa4bigDe9Ye7jZtgJdCCFgFEcAPSbbVCrFL0RsOjm4d0YnXibQC2NznxOu57w2N aU6StUfsy4mWcY1zoaR2TEaSAulw8geNYmWxZbyKnhKL+PBUgJVoA08vL2FteBLWSPiM TYEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DIpRll2d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id d8-20020a170902654800b001c9ed124cd7si178432pln.650.2023.10.19.12.49.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 12:49:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DIpRll2d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 C4F038275E61; Thu, 19 Oct 2023 12:49:42 -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 S1346547AbjJSTti (ORCPT + 99 others); Thu, 19 Oct 2023 15:49:38 -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 S1346477AbjJSTtd (ORCPT ); Thu, 19 Oct 2023 15:49:33 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD157CA; Thu, 19 Oct 2023 12:49:31 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01A42C433CB; Thu, 19 Oct 2023 19:49:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697744971; bh=mCKYxJG6okaaxTlaAJiDWBfMeecgvhed2+n6U1OL4CI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DIpRll2dkGyuM/W1HY/OtCJ0rVq9bgajq0d8Ehg4VUWQ+lGFeTkQxBJjxh7927Hi9 uKHjKJjL5AQ5O6adkHXP684YQsUouzmOfAujbPozk8M3KHgXEKdIzLfxfiwsDdnxES boqYYS+F2Jcj+R1reI40WC6tfNeK0UiQnh1EFUyCvLYx6pyLPpEbJJGzu46FKY0IoY Fvl84swfOFhwCdZh9ZJzhO3w35UPmexJuKUte56Gfe7CwJJGB/j0sX3xffpEeDHNmN 6bP2glF0upzkOFUED5Q+3MUI51uFt0C67sqqVbo4OutJCy735/57FsWLl7U5qaOmjD A31VZ5YTiz7Jg== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 2/5] mm/damon/core: avoid divide-by-zero during monitoring results update Date: Thu, 19 Oct 2023 19:49:21 +0000 Message-Id: <20231019194924.100347-3-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=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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]); Thu, 19 Oct 2023 12:49:42 -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. 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