Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp1176223rdb; Fri, 20 Oct 2023 10:23:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHW+vc0GoohehOu1gP3JutekpIC/vho85P1ZOeHb0271zp6HgFhifKKJyUI2K01LLuijPo5 X-Received: by 2002:a17:90a:c70c:b0:267:f9c4:c0a8 with SMTP id o12-20020a17090ac70c00b00267f9c4c0a8mr2428595pjt.4.1697822617707; Fri, 20 Oct 2023 10:23:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697822617; cv=none; d=google.com; s=arc-20160816; b=QY3tOg+gdDgOJ4l8PZs71JVxriy1pe1oB80KzYBO2kuG/62JzCh7nCq86SUN90Pkdz ZOJJqyjSRuF47Eq/Sf7hS7J8u6GoBcUZcQFJcpNCueq3bD7CKapEjhZe16L3z0H/Bv0X JXdo0ebA/y343iLDiFetH5XZsnfattj5ESNgUFywEEao9VXO+zzhtSyMa9OjdzCp/o0w ooYOJNdBaoFqr36Tjtp167PFSBGIlkcPJgvmh6RPRsFazTlk5yzK8u8RUFi/A0rAFvUj ji3o0An5YmAir3ZPQ5CcKnHGW+fbCeohsw6b564ELWsUb7aQgjFDbfXcndgCY+7CaNlj vs+A== 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=HLqUQe00dMgNr2OfwqUnWCJdJQVpHibxoVFBKdDb3FE=; fh=nlZbZM/lrRfzHQcwYZKnNixXg4ySijwiL5np8ihS7AE=; b=GenxRDsuh/Lqr9NglF0rqBgFQN554/m7PIDGFvcmNKVnGWccK9wTLNkco6U6HmGM6w UJr9RAWODcVtzt7pRi9f4oeQY3vxq+CSvKZ2jRA/7jpLEjXNlHHwLlHjSo0nu2TwkYWQ EYfEO20YCMXOzbzEkz0JJbHhqAkk4oA9/MWAfPUN8gpKhtNARs4iGq9zFKOQ0gyg1fYD Nb3juc6Yr335mOm1dht47LYlTDuyJWkQhUCsjJafefeajyPoRpqxsCWtITkBH2X+kDNr mY/5Qz1SaPUVXAhZEPBNf9/wTyM5oYaYoqrhcMAVWrBmwWud8oPC/M9XBAynhyf/LbVU X5rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jHtmFc93; 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 a11-20020a17090ad80b00b00274c8943b59si4962442pjv.64.2023.10.20.10.23.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 10:23:37 -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=jHtmFc93; 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 A8991830C32C; Fri, 20 Oct 2023 10:23:36 -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 S1377934AbjJTRXd (ORCPT + 99 others); Fri, 20 Oct 2023 13:23:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377916AbjJTRX3 (ORCPT ); Fri, 20 Oct 2023 13:23:29 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B067511B; Fri, 20 Oct 2023 10:23:27 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E62BEC433CB; Fri, 20 Oct 2023 17:23:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697822607; bh=6lmYsv8XJqW/eM+lXLzhU7HxZ5CdX1w8lmt0qOdrzr8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jHtmFc93b57yZn/bDpAh7gBhcfHbj20IeY+fuu4053yIw8MoFaaDnmQ0MsrNV8IEo X1ZOjlEl1Kmq4ngCLAeoC0621PhULQJp8lkT0Kw5Kc+APiSyMONoLooY1MQILhnSDk 1W2Lt47fEK5O7FwRtUdgtoRCWawLtS8RrNJAvD6jDE3sWD3ipUbb1AYqpnahNa2Anz tLyFDzmIrQ4k/2QD4TQMawE617DS+D+Cktc6QL7UdhoZ140dK+/y11tdkGzEEIlkn7 D8LoBKqBNUcwmM8as1ufxtbE2HDuPWHtSNOJh3KGLxL+1+9gAKAdCjl0b2J+e8c26P Q5JlslM9OsQqQ== 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 4/5] mm/damon/lru_sort: avoid divide-by-zero in hot threshold calculation Date: Fri, 20 Oct 2023 17:23:16 +0000 Message-Id: <20231020172317.64192-5-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:36 -0700 (PDT) When calculating the hotness threshold for lru_prio scheme of DAMON_LRU_SORT, the module 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: 40e983cca927 ("mm/damon: introduce DAMON-based LRU-lists Sorting") Cc: # 6.0.x Signed-off-by: SeongJae Park --- mm/damon/lru_sort.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c index 3ecdcc029443..f2e5f9431892 100644 --- a/mm/damon/lru_sort.c +++ b/mm/damon/lru_sort.c @@ -195,9 +195,7 @@ static int damon_lru_sort_apply_parameters(void) if (err) return err; - /* aggr_interval / sample_interval is the maximum nr_accesses */ - hot_thres = damon_lru_sort_mon_attrs.aggr_interval / - damon_lru_sort_mon_attrs.sample_interval * + hot_thres = damon_max_nr_accesses(&damon_lru_sort_mon_attrs) * hot_thres_access_freq / 1000; scheme = damon_lru_sort_new_hot_scheme(hot_thres); if (!scheme) -- 2.34.1