Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp583695rdb; Thu, 19 Oct 2023 12:49:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFkpFjSeYBG5N5Xi7Hu9fidFLuDLg84Pk7NAgfxl+XYezkaeaQCV08l2nIEvSVUF7Ecs9eI X-Received: by 2002:a17:902:c782:b0:1c9:d6f8:1908 with SMTP id w2-20020a170902c78200b001c9d6f81908mr2872975pla.9.1697744981496; Thu, 19 Oct 2023 12:49:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697744981; cv=none; d=google.com; s=arc-20160816; b=IRfiHAwupPHSwKUqLDsmQ61+EmHhErFVOBNf4z3N1wC/rU6wjB189WLMFYTst282o0 q7LJN2wUv0gQ8CII6RIkqQWgtjh3qo0/H48vz8edMjUUdnf1c7NieUTw1rWFFwZAmOr+ 43NqRhHmZ6rC32GOPcFwjngV6W9Txm6PG/HefS6X4er63DVKGo/GxqD9QX2NT9dKAY2L QjmTipeRS+YHBAESdan1fHW72muGgtrXzP3inVaAqZQe8YQ/DqwTH4uerJLYGRwkDL0Z mK16JflEdZqFvjTcE9j0T+yq3bi8bnFAs9sSi56jpB4tvZJBm1aNnoNcwKzhr5GGWsBj t2aA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=mVA1+rWunKOIv7Pl5HxvXUWBUIp5QPO8jBUGJAxu80c=; fh=BzdeVYqZhG5iuwuKJRNLP969rvCput73lx0iwx2zu7A=; b=dJe1avUfTyZ9xgQy3vNF4wTHvv3euWcWu+zmbv4D8ISzETLa6+8dpKsTL1DfndJcd4 04Y5SAEvpiG5EiniA29ONJc4Pvbvin3CvH2lkdMcBM3G7yj6T/NnYRJe0s/7LjMtoEyc BlCxbgo/6o2cMj4ocw6hn5X8hTUreUQ73NILiaxwbS35Mkci5cJTTwAxKGq9qoPa1IH5 n2c5vFikHkqgU8b1++LcNmelZD/WKrL9zcWM/8RDsCTilTt2ZWGYZz+ycLzCDrLzNs0J lBqXGnqBt9JMRD6nQV6Qjvj2Bz9PzPBxwjtHL2VLIHQXWztYGsaAFuHbbvF51vt+G1mD 3y4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CuUPzS+N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id z19-20020a1709028f9300b001c73626a1ffsi182210plo.412.2023.10.19.12.49.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 12:49:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CuUPzS+N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id B899C81DF243; Thu, 19 Oct 2023 12:49:37 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346442AbjJSTtc (ORCPT + 99 others); Thu, 19 Oct 2023 15:49:32 -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 S1345366AbjJSTtb (ORCPT ); Thu, 19 Oct 2023 15:49:31 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76816CA for ; Thu, 19 Oct 2023 12:49:30 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A79ACC433C7; Thu, 19 Oct 2023 19:49:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697744970; bh=hrrza+crBd0RjMFZAgh+3yDyKNEWLMDaW4dbIT2n9jQ=; h=From:To:Cc:Subject:Date:From; b=CuUPzS+NiENfFW4IGkmjF1bIWMGzjCQS3iWVUOePE5rhfXDWxQte786cYVifxeVzx GrusnsW84WOyMJCPzhi3dOzPjSZbDevDjkyXI7MCiqo08/rKT0phGUitlODzcDpPvA DvtSZBqIgt3a6OilHFjCisaHGwHT4q7him0DbNN7eSOLHYaW+xrQcm5RQ/gr255Wr4 +idbbXK+i9HClhI5L3MD8qLFUwodlAdLn3hQC7Xp6A4mslYvrIeQv7J/RAgd1cYbh/ +KhbQCiGeuMhqyTDT0vc5ilNhJwDrMG5lYAE3kylIerEvyFdvggU2shT/VU/IZ5SKA a7DlWTT1r0r6Q== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 0/5] avoid divide-by-zero due to max_nr_accesses overflow Date: Thu, 19 Oct 2023 19:49:19 +0000 Message-Id: <20231019194924.100347-1-sj@kernel.org> X-Mailer: git-send-email 2.34.1 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 pete.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 (pete.vger.email [0.0.0.0]); Thu, 19 Oct 2023 12:49:37 -0700 (PDT) The maximum nr_accesses of given DAMON context can be calculated by dividing the aggregation interval by the sampling interval. Some logics in DAMON uses the maximum nr_accesses as a divisor. Hence, the value shouldn't be zero. Such case is avoided since DAMON avoids setting the agregation interval as samller than the sampling interval. However, since nr_accesses is unsigned int while the intervals are unsigned long, the maximum nr_accesses could be zero while casting. Avoid the divide-by-zero by implementing a function that handles the corner case (first patch), and replaces the vulnerable direct max nr_accesses calculations (remaining patches). Note that the patches for the replacements are divided for broken commits, to make backporting on required tres easier. Especially, the last patch is for a patch that not yet merged into the mainline but in mm tree. SeongJae Park (5): mm/damon: implement a function for max nr_accesses safe calculation mm/damon/core: avoid divide-by-zero during monitoring results update mm/damon/ops-common: avoid divide-by-zero during region hotness calculation mm/damon/lru_sort: avoid divide-by-zero in hot threshold calculation mm/damon/core: avoid divide-by-zero from pseudo-moving window length calculation include/linux/damon.h | 7 +++++++ mm/damon/core.c | 12 +++--------- mm/damon/lru_sort.c | 4 +--- mm/damon/ops-common.c | 5 ++--- 4 files changed, 13 insertions(+), 15 deletions(-) base-commit: e845524c56a529768a8793e96304db09134eafdf -- 2.34.1