From patchwork Fri Oct 20 17:23:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13430977 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3D27C001DF for ; Fri, 20 Oct 2023 17:23:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 27C6C8D001E; Fri, 20 Oct 2023 13:23:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 22A198D0003; Fri, 20 Oct 2023 13:23:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 119208D001E; Fri, 20 Oct 2023 13:23:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 032778D0003 for ; Fri, 20 Oct 2023 13:23:25 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C782E411D8 for ; Fri, 20 Oct 2023 17:23:24 +0000 (UTC) X-FDA: 81366511128.28.24A38B2 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf13.hostedemail.com (Postfix) with ESMTP id 0A6992002C for ; Fri, 20 Oct 2023 17:23:22 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=UQhrh7+6; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf13.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697822603; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=9mRENkl4NOUx3H36jA8HkUdIKz6si0TG43C56zhZjxQ=; b=sVICivtq1MDvi+x9Qfx6ESkm0VMQ61au5xaUyzgjMYX/typQAIl/udw5iH3z2jOCyCVXmi gj7jeyCrvNhDP024ZeBHPx31xZvyiqtgOXntemGBQ1rQh1jz1oP4VLYdlnh92ZPWXbYGjc y1ZLhtEKNnea7ko4HyN2asmZASZcEVY= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=UQhrh7+6; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf13.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697822603; a=rsa-sha256; cv=none; b=il2N4APNvq+Xrb79jnZeiG61mU3qlbpYARB/qFVtjeB7b7LCbdiYIVzqUhz0IpouR4dzf7 Y5Xy1Dsl3tZXVsCEFqgPU0+kflIPw+Xk9S8M/O4Ekyp0qqmrjbH6cUdzCXbZniKqoM5Rfy UzGnXh7CoHx6CteCI+4gPcyAPrTtNnY= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id 0EDDEB83377; Fri, 20 Oct 2023 17:23:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6732C433C7; Fri, 20 Oct 2023 17:23:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697822600; bh=9DTH2ejZ6gRx9v5Kr+Y3Lfgwo0SmTNuA/A5IR8D58/Y=; h=From:To:Cc:Subject:Date:From; b=UQhrh7+6S/MSu4IcYRnXuy7EYcConABwkV5hydTwSyGaPGdbM+HMqPvgfmUEdx3Q2 2pBWW6qmhoe340ImjiAKa6WW0FD71QgmiHBHceMfRdW4VLA1W3NQyHUjHIXN+eXJP/ VlBL0uJMjRaOjf/o5PY5oVU6dzu7hzgNv6yKwCT7zH+CxhfMgHie2tydm/d+/n7S+N CZNwWgm3CF7e66+DDpUriULU2laVgMqusZkUK7RZkGYU/tb698rfmgSsfILGziBHQE brznPtN20sErmnwVXeT5lynnssIpxOJhevA05ao1A4x8QeQG4b4ek2Ioxqg1VwmSzs OZcVn5GEq5lGA== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , Jakub Acs , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 0/5] avoid divide-by-zero due to max_nr_accesses overflow Date: Fri, 20 Oct 2023 17:23:12 +0000 Message-Id: <20231020172317.64192-1-sj@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspamd-Queue-Id: 0A6992002C X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: pewhg3s8dnnqsuzxnbabdsefpt17soeh X-HE-Tag: 1697822602-284372 X-HE-Meta: U2FsdGVkX1+5qrRbGOe3a33DMfF8GAkBdnBn7ibITDA/fxUKKIF4mPld/94jaxd5H8rMxo9bvcEflRozQrJptApJgmnEikgLwCYko+K0O+gHF6RtOLGQnipJvkdkI1GeRE5oTBjcovWhLVqxpiFMWP8SZosnijHZARS0budToW2xF0wvWRSQzv+SW+HHhNZl0yzYHN0tK0MhwjiqC4+QaXl79KWqq/YLHRg92pDpO9rCdtq1pB+CBkd9tnXzHQo5zCti8JjX7J/hmYT+uh716oZ96FmhhNgJCMCzBHqXK6TUx/f49FMI+oTpEXn4hqtZV2lI1cg1d9BHD6WO9r0ohiAohcm6tsSBAVWUdLElcZoePRU+yu/wXEAs9AgyQN1Yt0ku7NZCkjwPBAEK512fnc5RQkSUJHzXlw3s0/9X/aqCLXp/dhmVV28SrJter9GWSJaEHzL7Or1Ksa0LinzfwBB4XMHKIqBBOI9tjntDsmlplhvF9p+MPgZ1rjroMC1Obspj+nr83rpRn+EZ1qfH08xwkpy/QEbGcvjfXQ6Rmo718iaWAlM7wj7LyjOROCMnx5RthvCVAlrSi/o0WxGFymaIL/1fwtgFNttZ1pxb8OKPXyPXyUjGzLIeBabqYklyx3lXrLE4XiEI9iZlAGdkQH6DUUzESJbpfD6bR7OfLzXMVwfborsW7OL4Q7z6z02UiczH6FUIkFIYRDyk8Nf8YnXno5yju3YhFMGNDZywg/I+vQlvq9x3HfgPp3PzOkhemBXgTQ3bvcAIrw9YdJ7nRC28d+p78J4Kc99YZKOG4ELngieB1oyhiNicl9JtQtu0Zf6eJpd56Nt8x4HyChSV61+nm9G+Q6dsr49TEwnSOcJrqy3P1Dv9S2V9RyjKj/kd9etw85qDDsBpZI0dMbuFm1zP+CgiV1fv/jFJ1mQtCfRUjvArmznLyBL99yNeW23ngJy3Ju0siHJp6l4Tmry I0KWXTmh E9myX3QZH+/wZvoD9cSmzZoQdiE3NZGkAU1+GdCVLJKg+y+M+wdAwkcqAfUcjDpqYXlClkr/sVqdH6RrgW9VP6LpM2qxUYHF+1QZWppJI6eM4Gd0kNahTYPrRahiZClVXjTYjZ9W90IUGYXWgq3B/oi/xKkp2gCupg1/BNchOaMG3FSln73oYiXfWRDPE5u+Zt/DnH29VhMY4txAl5GSrR+LJ1ok48Lo89Rf6ON09wdiSKpMpvsm22bAJwRl8IajhL9pYDym22xiBcXc9Xq2Rk/sYJQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000021, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Changes from v1 (https://lore.kernel.org/damon/20231019194924.100347-1-sj@kernel.org/) - Add Reported-by: Jakub Acs 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