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: 13429772 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 D53CCCDB487 for ; Thu, 19 Oct 2023 19:49:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 25C69800B2; Thu, 19 Oct 2023 15:49:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 14C82800B3; Thu, 19 Oct 2023 15:49:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D5974800B2; Thu, 19 Oct 2023 15:49:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id BD5AD8D01AC for ; Thu, 19 Oct 2023 15:49:36 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 866A41CB88C for ; Thu, 19 Oct 2023 19:49:36 +0000 (UTC) X-FDA: 81363250752.28.387A4D6 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf18.hostedemail.com (Postfix) with ESMTP id 8D1951C0002 for ; Thu, 19 Oct 2023 19:49:34 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=CuUPzS+N; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf18.hostedemail.com: domain of sj@kernel.org designates 145.40.73.55 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=1697744975; 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=mVA1+rWunKOIv7Pl5HxvXUWBUIp5QPO8jBUGJAxu80c=; b=BE4/nzuze55r9al6rSwvmRhG/oFlJrleZXUFqLVJ7dD/415Fpy8EGOHwxZwfVBWd+7/b2G D+TN+sw8+jkeO4SpO8a8OTeD+CKsw/tAtc5LHxSu/fbqQQi9Jmu6wQ98j9MU/2sutrAm32 kGbn7pJZCxa5uHV3RtOjNznZ38m8los= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=CuUPzS+N; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf18.hostedemail.com: domain of sj@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697744975; a=rsa-sha256; cv=none; b=aHWkphzPotAEoRttrvlDrEeSqcf81xc9Q7oxDbd9qWtXVEy0WoUHwuConEGESaqRgsZd0J w+XlBilzdL+kc0WSz9TNK/7UaLJOiIiuxNCixFBI8RBxzGyiv1PurZgMHuhsvHLxCqRuur 70y7COS8oDOrCj32hiQ3U1IPcCGh/6w= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id DDC69CE315B; Thu, 19 Oct 2023 19:49:30 +0000 (UTC) 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-Rspamd-Queue-Id: 8D1951C0002 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: fma6zrop3uw9n43zmutm3tw7id787ot9 X-HE-Tag: 1697744974-824594 X-HE-Meta: U2FsdGVkX1+pNBI5tl+IkFoU6Q0sgY9CGWTXH4varYLiVOmBHCeK8XS8fYteZptEXVFFVkY4AkHQNu3nrqksphAN0YCX4LIM4nlIemCwxl49usbCF/C8WnXwGi+5Rw8r1z4FicmujJ73/cVTvbUPC1H38zvnHfb7Hx+kvbfZU33YWxcXcAueHG6aiMOIu2GvcfvkHgEycWjJi5DmpKKh7K8LOUUrpMK4Y56St6wM7/0LNHFEwL4ng2kG1DIGXSMAexjK7P8eEzmOLUQtxq+ZD1Qn29x06ImPI/cDs6g5ERJqalU1bCfgWNsxMvJHYwdKx/Ht7wxOjqBXRuRqdkfJL52r7AAhMIdkf1ndqAX0AZc0Dmvey7EYBc5KAGpnA5HQ3SOskiFZAjlPxsYYLhDxxYSrIzMNjbvy7AZdjE4ZO7k5ye6K7be1mzAPMj72DhXQaWCtBnS73X7nro3Mriysd/9y5Dd5Gp7/Vi9hQqgcpd+lXTbAOX4IAi9XV4nsKDftwie6rRAjxycpBFj1yVu0YLVvZVq5V8hh0y4ZO/gg8AtPPlOKy+m4gZlc4WmxPCQn4m8r12YPYc+7OwfPS8I+FzQTPaPV8E+OpACh5E6NfSaLG65Q2S/JPiujf0+dyaJcSS4PJ+900DCLtWVPa3cHR0G3wXFBVw8Y+9hhwdzLZ49LWJ7o2bDIdBzlWwvaYEaLVQeR1QW4cbpfMyexSy68cI9++JaJzNP790pgo/mYTtNcgH6/vM1ttfY/QlqBTDPxKWsFNeooHTfPsK5OLC+OjtRKLkuUBZBQOsl0sFmGPYp6NyakrbKDZ92vPZryYNRH/vA3cvCb8IWvE+9WH5WX9EsuB7ibmGkeXZZ7aitVI3DnluZt1rEC2IjEodmUHmRIvtCHowM3R563QafUPob9y/O6LZYUJN6eKUA5dnTSHVp2N+CnTko+cugZ4Y+Kln+GN1DYmnczeGUt4YE//do A5a43Sez qyiTrlOCPyaqcRtxnL6/QN8CENvuyOfb0ioOPahT7YxkhTZDFoglB9B/9ENMx/BBkAcpcqYrQqekZiLtKwjq2DyxBKzHk6eLiI+tiPe4vbGr8NC5lq2tpzSatatgzih1ihR8yUB6E5EdYxZ1jEyLWRlkYP9MwlJt+vT32SXhv8bIQGgBPxaoysvBLVbtqNx9t7mLhxQnMx8prktHu6WCbzyChawNHpIWwKbqL X-Bogosity: Ham, tests=bogofilter, spamicity=0.000752, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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