From patchwork Thu Oct 19 19:49:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 15638 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp616270vqb; Thu, 19 Oct 2023 12:49:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEyL2cKBgl/QH577x8GK+vQEkm6EkH/ovmA5jZgLvCSDBBoNRrEx9xdF/+fAzuJNCtDlMLN X-Received: by 2002:a17:903:2113:b0:1c4:fae:bf28 with SMTP id o19-20020a170903211300b001c40faebf28mr2477281ple.32.1697744987812; Thu, 19 Oct 2023 12:49:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697744987; cv=none; d=google.com; s=arc-20160816; b=xbHJle132AujoXin+1aGGsvKakglo1LSu5skCyIbvmT9v9QC38fHq6U51D58eb+D10 ziLWeeel4o2jBfOMhRdO8NAdjYZvL5fR1RlyJ2faZ311v3q21VrfLSicY5h9J+rHxE/a ZR/vg8eBHv69ejIO9QZaE1oL9VGdoSn/FCr2+UzN3yCXBlCT1EBH9RkMUPvMHivrsoid 1K/jwic/zOZmHZ/IVifGZluyj2hqpkfvo4AuSG2kRq7vJJ3tCf4aNSH71c/l+iC2UQ0b M6cLpGaO+qJb7qiOQ2eM/1GECfDnKNTF2ogVNPSlnX9uh7sY5CKmmQLr6h+pIy3VJ1uZ Ykig== 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 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id y6-20020a170902ed4600b001bc02b730f3si177651plb.242.2023.10.19.12.49.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 12:49:47 -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=CuUPzS+N; 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 56FE8827B491; Thu, 19 Oct 2023 12:49:46 -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 S1346457AbjJSTtc (ORCPT + 26 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 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:46 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780214648704515170 X-GMAIL-MSGID: 1780214648704515170 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