From patchwork Thu Oct 19 19:49:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13429771 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 AA20DCDB465 for ; Thu, 19 Oct 2023 19:49:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EBB2E8D01AC; Thu, 19 Oct 2023 15:49:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E43758D001A; 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 C9720800B1; Thu, 19 Oct 2023 15:49:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B740C8D001A for ; Thu, 19 Oct 2023 15:49:36 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 94C0B410F7 for ; Thu, 19 Oct 2023 19:49:36 +0000 (UTC) X-FDA: 81363250752.01.6DA1B5F Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf22.hostedemail.com (Postfix) with ESMTP id 78063C001B for ; Thu, 19 Oct 2023 19:49:34 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Oe6x2sCU; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf22.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=1697744974; 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:in-reply-to:references:references:dkim-signature; bh=J+W9qLA3WO5W8qkckKCVdeyrs/hKuMnVmg+YTOVRsQM=; b=4iwk4EBH0bDlg+Kl2lXmqv0beyd/E06Oefi4KJcErKl5uNSZO5evXODkVycrUQsF2Ugjbq 1B5/pHg1Of1UrlLmT3HWNcFiOFZrjp1R3c2r51y7jXuGnM6goEjRxw4Lpajk2tVnPYGxTH 7BRHyg5TpYY3KbzTs9sKVJ5lXve6bBY= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Oe6x2sCU; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf22.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=1697744974; a=rsa-sha256; cv=none; b=IE+fXud8sZsEyEsYDQJ+b0x7j/qxmZYjwjVtiSHvyTD7XmnsYDO9K5z6urCkjl8UTCYNzy U0tNAZBOrbAjEVz4YrGYOqmM3idni7MrB3S00zAmbzeYedA+t6wQX9spMzgblg12v5IL4I vEDi7lQGyh+8Fh1Hi6c8G/gR4NfPPaE= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 863C7CE31DD; Thu, 19 Oct 2023 19:49:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 56F74C433C9; Thu, 19 Oct 2023 19:49:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697744970; bh=JqMVIy0mCbZQnCjtrYElDQM3Dsnc1xV+CtQNq7jTX4o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Oe6x2sCUCq4JfvkLqpDa4AQ+8p4t2drxdj8w0WFjYf1hxoNLFLp0vaQyeQ2Fc7j+J 2dPCch5ISN4TtP+cfgKjTVNCyIucKm3x3veg9XYIDq0nZ4dw4WO49I1KZAiEq6mQae DH+2HwS7+ej8MoOkb74v7OTx04+XRrJNyzlFwsK2oquSwLQYbewr/2rZMAZXriQUMv wP5LugNRndnmkqm9QCG3rgRkJd5JOb8OBuvRjAFkg4352A/MgAeCdCe0ZPxyuoju6h Ax7kASeHfQQLqMi3wUh8GQTMqxg65h0B92mS1Cxv7gGLnvwDjOk4281T9dP7jqX7BC 19G38VMbA3q2w== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 1/5] mm/damon: implement a function for max nr_accesses safe calculation Date: Thu, 19 Oct 2023 19:49:20 +0000 Message-Id: <20231019194924.100347-2-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231019194924.100347-1-sj@kernel.org> References: <20231019194924.100347-1-sj@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 78063C001B X-Stat-Signature: xhpmfyitgzprmca7d91iddwwuiuxx493 X-HE-Tag: 1697744974-189276 X-HE-Meta: U2FsdGVkX1/B9oLn5nMNsNwjR99INW+dZpzQVLl3vBetUBHlYKFnzgyOC7znQO6wL6O1iFcPXUdbR90mORvmGBUp9BclWfSkmm3QSaWDzVPjK6I5fk1j6aj4h3UpvqOUMg0mO0BbPg2yts/9J4Uxp72b6iOUFx5T8EJmWyfONZrVsJKS4z7MBCULxjg+bEMRaucbfzSthuuB+H7xQC70qVEa6wIk9/ifH0GBlVXUkOasxDsHp/yfV4wRkEs24q7V+jRlxAwKn0hnzjQDeomkSP0FoKyq+UAgS3wqj/7Egy/QwNrlkwfgoYPxoQYRRJxqei1uMTTigKOsyFLt1GjXWdYeqkx4YLq1wyvZLOxLX/+naXplhK1GNqcHT6q8EYSH9iYTpB63sKunK6sydAg50KWiu9b0DWzTlLb/n86FDfzMstn898q5rKI/KbbQBQJu+Q10X7PidilFog7IrI/4gX0yCaE2I7fnJv0kHuqDpq/T/xD8SBxH/h+Sz0aDcFK7ZnjLDOskjpkKNC1u0BBMl5LkReF2bJlV1qqS+IGGM0eoAZGe0CH+1UKxjrEFNBvGZZH83qHtWPlkLkC2JtnQBkL7uEbGRCxr2Q+wNszQzQ8LY1axabbq7maxaq352GoBgJ+Tsr5iZ0+oey1dkxXVLHrMQB4NnWO0KNVguIh+238vMsRNrzkaDddyBIq1RuXZpILn5yQfmJQHeRJXA+ZSgPr4HcseyqkTRndPQDHOGZFMco39eDpMKTLDkp5il8zE34+9eOKX9RJr+PpMFUyhArAeG46MSHoagBNErli1mNs7CB4jujBs9Kynl/GqosSaLXERPnQZpBfyyPDMWFJA440050GyKbbCGRh76kqREUMyCPnGMfPZW7TMWwUGhJTawwwU7O9AxVAA5Y+KLsFdUBuh9xjpLUQs++lHd3AdNnyz5vvHb2f9nzZcWLVUUhi9+4P3DEOXf8UuU+pp4bm OkCUNSsN QZBzaVWyKSwe5GfiVlbAY2wSIpQhdDJ77IlAxt1wKrwc5vf6tKyu0RoonRF+nJn31EsToXn3qMKU753V3GxwZONI6bb7TTiemhh0WfTgO8KR0XY66gDjIak66PW2H2AUwlIPtpbaXKPPmefUoI23VxOL/3Z/OWC3l/8e/S1mXYrBt996QfRWcNjZC0OT+1595DaMdsiewQytMTb16Pvm0j1/f7vDUx1nGXq3QXSUwDTXJHcfGfoDPNu8Xe+sMKjePLq2fuiaMB/yABByK/5AESfuXDA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, 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. Implement a function that handles the corner case. Note that this commit is not fixing the real issue since this is only introducing the safe function that will replaces the problematic divisions. The replacements will be made by followup commits, to make backporting on stable series easier. Fixes: 198f0f4c58b9 ("mm/damon/vaddr,paddr: support pageout prioritization") Cc: # 5.16.x Signed-off-by: SeongJae Park --- include/linux/damon.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/linux/damon.h b/include/linux/damon.h index 27b995c22497..ab2f17d9926b 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -681,6 +681,13 @@ static inline bool damon_target_has_pid(const struct damon_ctx *ctx) return ctx->ops.id == DAMON_OPS_VADDR || ctx->ops.id == DAMON_OPS_FVADDR; } +static inline unsigned int damon_max_nr_accesses(const struct damon_attrs *attrs) +{ + /* {aggr,sample}_interval are unsigned long, hence could overflow */ + return min(attrs->aggr_interval / attrs->sample_interval, + (unsigned long)UINT_MAX); +} + int damon_start(struct damon_ctx **ctxs, int nr_ctxs, bool exclusive); int damon_stop(struct damon_ctx **ctxs, int nr_ctxs); From patchwork Thu Oct 19 19:49:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13429773 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 A13D5CDB485 for ; Thu, 19 Oct 2023 19:49:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 67DDA800B3; Thu, 19 Oct 2023 15:49:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5DF6F800B1; Thu, 19 Oct 2023 15:49:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E4CB800B4; Thu, 19 Oct 2023 15:49:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 0D4D7800B1 for ; Thu, 19 Oct 2023 15:49:37 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C01D51CBE8F for ; Thu, 19 Oct 2023 19:49:36 +0000 (UTC) X-FDA: 81363250752.25.FEC3DCB Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf29.hostedemail.com (Postfix) with ESMTP id C58F0120002 for ; Thu, 19 Oct 2023 19:49:34 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=DIpRll2d; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf29.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:in-reply-to:references:references:dkim-signature; bh=B/CCsTDa+XZDlq5k3rMLYJEgO7TntQ3l0uMTeRRAAts=; b=gClYq9oafGdBBzoP3UHZvxpVpq5fJlu7lgcr7mA41e46NDt+wraupvSfZwKdhCqz8vh50x tMx9QQBvmPSRhltx3x6z+Cxx9YGOH8SC+A5qguHTIJxIu83oL1hkyk9NxRqXClp2rfqxZa 8WrUOAu17bvWHfwXViwIf7f2F4aMrdU= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=DIpRll2d; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf29.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=XLlV9av2kLUtYf9AOrEeS65jYDaXvha4XHjs8/4LEEcy0CdpPwmJF4Czr7gA2GZNmYCMWB Oj5tpGQtM0BBEUsZ8kMNwyrVuaopvcUEr5+9S7dlXxji0hoztYqBNMaDGhigcpPNF9oQKL VNMI4mClS4mo+UJf+UE+8OWvbK/WIiU= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 3135CCE31DF; Thu, 19 Oct 2023 19:49:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01A42C433CB; Thu, 19 Oct 2023 19:49:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697744971; bh=mCKYxJG6okaaxTlaAJiDWBfMeecgvhed2+n6U1OL4CI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DIpRll2dkGyuM/W1HY/OtCJ0rVq9bgajq0d8Ehg4VUWQ+lGFeTkQxBJjxh7927Hi9 uKHjKJjL5AQ5O6adkHXP684YQsUouzmOfAujbPozk8M3KHgXEKdIzLfxfiwsDdnxES boqYYS+F2Jcj+R1reI40WC6tfNeK0UiQnh1EFUyCvLYx6pyLPpEbJJGzu46FKY0IoY Fvl84swfOFhwCdZh9ZJzhO3w35UPmexJuKUte56Gfe7CwJJGB/j0sX3xffpEeDHNmN 6bP2glF0upzkOFUED5Q+3MUI51uFt0C67sqqVbo4OutJCy735/57FsWLl7U5qaOmjD A31VZ5YTiz7Jg== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 2/5] mm/damon/core: avoid divide-by-zero during monitoring results update Date: Thu, 19 Oct 2023 19:49:21 +0000 Message-Id: <20231019194924.100347-3-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231019194924.100347-1-sj@kernel.org> References: <20231019194924.100347-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: C58F0120002 X-Stat-Signature: cktzto4j1fhpj4befxerfuqw96sk546w X-Rspam-User: X-HE-Tag: 1697744974-179725 X-HE-Meta: U2FsdGVkX18MqwfggWcdUvbLDffSXqCvekJaXUO9XqQeirQhaybekHJSKbhxD7uz3TGWKMG8bueEhysBxXrU2//uRBzRwPqc/hhi2+yn+K3nFt+aJQEsecdRhojzd/OSFc4qBkkKcMjayp9W2azf8R4VYuNObLIg/sjjOuCcPpDhWBr9upVkkTtVg5lVDqXyjckGzKyuqa05AT/fh8C/Chrq5aNDbQ9r51VWAivUsNa5hRb8AkP++NXhjgxw80S+cAo+zvIGRIiL8r/Myl+mMStTLqTyh87MH51FmQF10U2ulGJxcdJx0MI49G/8zphNnNODCVcg2RxD2jb5j6VMySgqzFU88QA7/L6O2e39uOa0j57h3nxJFWzxitI0RvDb2bHKKOPRekN84T1NSKlu/7tAkX5YDs0/RIpQV/3Tbv6h8SjwTNveT8gy2fRdjRawPWtc6ack12D06IrbQiE8ptiowanvveDfK8x1L+lhfPP25n4d2FIUY2lKxf7QdtzsAeRawLaiaaDP3zI0GmdO5CeGK7TTgbLdHLrwlqiUtr3qjWX/G8IgRDm/gppgnEpPAZBrLDnxkZyAbN+QrIf/NiJOeK/nz2l2GTuc+TMnEUEsvUHVU9bS+rAKPXVbS2suD3q+pc5x1rW1eQfrHgnxH+6uAEvJ6IPVbeYwIoYSP64VvzudDRj19CgOIU0P3oqg81qmGJuyLs8IZBp0HA9oU16pmDEKv0147ovaSWMdZzhE7R358+x0kuAkVtMwYIajKH7+YELJYUE/hn3fL3sbpqaRD50jIDXcsIhtR/fIeMJHOjvBxqtuyj+m9qy8u8izCEIZQYdIYRCMSviPUMy7dMGDqjgEdN9FDVzNMoXMcEevsrejpO6uMu4eF8hif0KuIJEbqCth4w+QBqdjKm/WpZ6WC6RbcsCW6MTMqIbT3YpzFclAjbGMtvny2EAvra0WeAPwkAYKPbgkcHXh0Jx 9u+0ZDRZ +eMbkGkshB95Y4PkSwVZuelYQcVRaVJwj+6gHoys/kpgY9N8zeFjl0I3JrSmDg5N31qdBNEYXMyxNjilDNZdtRnUuK1hGMkRRE/KVEw2rxIRoKgIbUcVDV7mmaSEFRMpIDJAYwquyv+pWdDHHLZfso96DUR8ZqcDoOnacGS9t9drIKx7MNEP6kcOb/nWh7iuxJxp3xWfI/ithZywV/sh4R7xV3UqsFi6oaxPqrnpRpey4aCU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: When monitoring attributes are changed, DAMON updates access rate of the monitoring results accordingly. For that, it 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. Fixes: 2f5bef5a590b ("mm/damon/core: update monitoring results for new monitoring attributes") Cc: # 6.3.x Signed-off-by: SeongJae Park --- mm/damon/core.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 9f4f7c378cf3..e194c8075235 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -500,20 +500,14 @@ static unsigned int damon_age_for_new_attrs(unsigned int age, static unsigned int damon_accesses_bp_to_nr_accesses( unsigned int accesses_bp, struct damon_attrs *attrs) { - unsigned int max_nr_accesses = - attrs->aggr_interval / attrs->sample_interval; - - return accesses_bp * max_nr_accesses / 10000; + return accesses_bp * damon_max_nr_accesses(attrs) / 10000; } /* convert nr_accesses to access ratio in bp (per 10,000) */ static unsigned int damon_nr_accesses_to_accesses_bp( unsigned int nr_accesses, struct damon_attrs *attrs) { - unsigned int max_nr_accesses = - attrs->aggr_interval / attrs->sample_interval; - - return nr_accesses * 10000 / max_nr_accesses; + return nr_accesses * 10000 / damon_max_nr_accesses(attrs); } static unsigned int damon_nr_accesses_for_new_attrs(unsigned int nr_accesses, From patchwork Thu Oct 19 19:49:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13429775 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 A2BAACDB482 for ; Thu, 19 Oct 2023 19:49:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F3286800B5; Thu, 19 Oct 2023 15:49:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E6E19800B4; Thu, 19 Oct 2023 15:49:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B105B800B5; Thu, 19 Oct 2023 15:49:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 97D9D800B1 for ; Thu, 19 Oct 2023 15:49:37 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 75577140694 for ; Thu, 19 Oct 2023 19:49:37 +0000 (UTC) X-FDA: 81363250794.22.B47BFC9 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf05.hostedemail.com (Postfix) with ESMTP id 6FBB3100006 for ; Thu, 19 Oct 2023 19:49:35 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=OOgE1jz3; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf05.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:in-reply-to:references:references:dkim-signature; bh=k3jW9/aa516YLgiCw2729Ckj7mfBIGuYgRCR/BJg5Q8=; b=l4QWL3R98MZ27LX/MDKn9WWpArKE2Cg75wBGJ8oDmn4CIfL5eeOtY8wqgUWHZkdk6RLOyF yhifEmDKnuGwUWg6kh0my/89NOo+iyrmNjkevrvpaeJAMlJUy/sZVz+EUtM/63IwqVp8ge ck8x4M8y+fvld/pBMZvHuGtYqRMnY6Y= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=OOgE1jz3; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf05.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=D+KWJR+1swftFXdxJsUJeBq+PlgCyB1iNNN03OZPID+F1ueUz8Rnnmm4r9YoKofuYDY6kx JKfIH2Z/d5XwCgUcVIpUL/FC0aKqHqti1Nw/mA7nLDJhlgaF8q/M52XfLM9v6a/xKWbd1r Mw2kSwYNMq/iibdspXd7lQITa8qWz7U= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id CE5E6CE31E0; Thu, 19 Oct 2023 19:49:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F662C433C8; Thu, 19 Oct 2023 19:49:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697744972; bh=mpZ0rzQnlOTIrrYJTnG5fwff80O37UKmtsf+aHi2YNo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OOgE1jz3lvMQfVP7TQZSOyc2aRshLkRxLJ6fzn2xEUat6kCKF9dHCXjOeqKgMRUkn JciYs/7W2GFKrLW8hHfKWb7PqfogevqMt/W8HSQOH0D+82UwlpAdZ4kkAZlACm/7Yd lD6zHpOrNamlwYL1JvFr3UqFSKsZRQ1C83Lu4MTrb569Z96fQBnp9j01s7w6xZ9Yus L+XY6w6H9dDlGykT60OConZ8snDx2JZCuR0vhKoLc74v3VmzIH7s8RZFN1aRYiH6OY +7tcNIopiD0jvwS2tVxbGdb8rayh09UhaZvj0Vg1VvBTo7/44eLy16O3BQ4MwcSBs7 FXMYu/8h+hHrw== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 3/5] mm/damon/ops-common: avoid divide-by-zero during region hotness calculation Date: Thu, 19 Oct 2023 19:49:22 +0000 Message-Id: <20231019194924.100347-4-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231019194924.100347-1-sj@kernel.org> References: <20231019194924.100347-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 6FBB3100006 X-Stat-Signature: xuqumbc7ydwhkqdm8q93prqm1ss95uiu X-Rspam-User: X-HE-Tag: 1697744975-311597 X-HE-Meta: U2FsdGVkX1+jV3+0smLLK0j2p966yMbwS1F1mbDKQug0PLi3m2Y4T0bbYvz6sLhJYXhN/QeGsLrrpZioKeYfZScYPfNN1mhtc+1Cf1elrrf1tcU5VOpRUYNSU2hL/l11IXZqsnT0vKh/zyZT/iCz2QwNogC0TdAykPOHyZcsQwZXP9Mf5iOqwX3EnctLl3puIl+eRFLxAo3agEVmyDYq4E1YzByNrwgCP7hkKxG7OxCBwhlmLn1fyvEvTV6P8ZrcwzK2XrYuSbkJs1xjcD9DTQ20jgIM+RT37GP/Nejn0izyRe4yKgp4JahIz9U+hlDoxuaqsCc0tUqWREsz7yR9F7p4iQhqDd/C/qqYuHfcIeLy4QgFsvJ4nJjljv8KQtct4ventWeyHy5jCozGuFaAs00XIB2dmLwGBlDfSbSc+j3pV+ETf1pyWs0evjkpXvpC552m9SaReVSx3brcKBB++4x+w2VMjAI7QzX0wFZzaVMnyEZxAQC6LYg3cbdMX7z03kyisen4eesPJsPTNGqXUsCfSLGDUcUga47/tZlzIAnRU74PggG0mDGkBNvunU5VlKXEuSdiUYaXDR4XS/tTib2NQVEgynXiO5SvtJqgaP7OuU/LgO1sdXog7AriOc02u3UHPe6DV+MnsLt2+MFvJXMLnnfjIUzsKYJPuadpNMmlayCcoYXtd0OPaAwsIHfnJx9FJ/O/b5xqhCVIYQYHGl/fN+BMm9+A646hWN7BvNDgEPUd9MeG1YwL7Y1jxTdCLIQJ6FBOjHeyCMQCPvT9i6JocttBAcJ3l9pRVQ8VKE93z9MZKLDnGlgUB19ENoHVIJNrc6gqDy8Hl2YkhOrMDxULESX1l7abbF3j3RhYPMBZ6zDmUUey1Uvx+/eNjKrz+toQNvD5g2BtxwQ4eflvx9SQUee0GPeZxIUNOHyoPGNCwyEfxdg75GvTTHXe91FU6SYHFDPthflPDYmI6DT 1Mfyo9Yf 7831Ysh/hvwkLF94AsmWUH3IOt2tDYboudosU28+DAohz3nj92fWWIg2R/EAdOxZ9FeL6e97RuMVBk4MXnRD5k3Xmwrg+u8ugGCI0BU3+pX77u9aVH3Nq4uizZVFbxtR8lzbBiV2WYD8eMz2FehBz4UwUjd3RuVgvwY4a/E1uF0+AuZIRwE8ZEckzDUxMCdPbM4vFFSY7Y1vUO5saPDI6feQf0TmuuNSurm5uUOKuKWGRtE4= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000803, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: When calculating the hotness of each region for the under-quota regions prioritization, DAMON 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. Fixes: 198f0f4c58b9 ("mm/damon/vaddr,paddr: support pageout prioritization") Cc: # 5.16.x Signed-off-by: SeongJae Park --- mm/damon/ops-common.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mm/damon/ops-common.c b/mm/damon/ops-common.c index ac1c3fa80f98..d25d99cb5f2b 100644 --- a/mm/damon/ops-common.c +++ b/mm/damon/ops-common.c @@ -73,7 +73,6 @@ void damon_pmdp_mkold(pmd_t *pmd, struct vm_area_struct *vma, unsigned long addr int damon_hot_score(struct damon_ctx *c, struct damon_region *r, struct damos *s) { - unsigned int max_nr_accesses; int freq_subscore; unsigned int age_in_sec; int age_in_log, age_subscore; @@ -81,8 +80,8 @@ int damon_hot_score(struct damon_ctx *c, struct damon_region *r, unsigned int age_weight = s->quota.weight_age; int hotness; - max_nr_accesses = c->attrs.aggr_interval / c->attrs.sample_interval; - freq_subscore = r->nr_accesses * DAMON_MAX_SUBSCORE / max_nr_accesses; + freq_subscore = r->nr_accesses * DAMON_MAX_SUBSCORE / + damon_max_nr_accesses(&c->attrs); age_in_sec = (unsigned long)r->age * c->attrs.aggr_interval / 1000000; for (age_in_log = 0; age_in_log < DAMON_MAX_AGE_IN_LOG && age_in_sec; From patchwork Thu Oct 19 19:49:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13429776 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 E0B3DCDB483 for ; Thu, 19 Oct 2023 19:49:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3719E800B1; Thu, 19 Oct 2023 15:49:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2FA81800B4; Thu, 19 Oct 2023 15:49:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F31B1800B1; Thu, 19 Oct 2023 15:49:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id D97BE800B1 for ; Thu, 19 Oct 2023 15:49:37 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id B6701C0475 for ; Thu, 19 Oct 2023 19:49:37 +0000 (UTC) X-FDA: 81363250794.19.8E597BA Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf24.hostedemail.com (Postfix) with ESMTP id B40C0180015 for ; Thu, 19 Oct 2023 19:49:35 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="Q/fE20KR"; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf24.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=1697744976; 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:in-reply-to:references:references:dkim-signature; bh=BkVrEp98V3Y9dznK1aCI8PGO49GlQEZO+UOltbZCM3Y=; b=J2MR02yb5DUWHbDLdS2dhG7P+bm+MxB/9UPnvvX/apfny6ddgdHZoK56UMRG5rLBXt/TOV kq4A3JPE5rmME8T0n1xO05pxkQwBEBaukFd7npT+aWLjXyTeLfFAjV9UCNpngoqrxvCNc8 DjGKZzHi+gUr57xJM4yiyP6xQVjYEXo= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="Q/fE20KR"; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf24.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=1697744976; a=rsa-sha256; cv=none; b=nRDA8NCrNbELIOWVXO3lbpVYO1zn9SUfefAyJ/Pq7c0n4sr2eDm6mzno6wf8tdBEy0wfxG HTc7fDJ/ZV+CUXdXW+Tpd/v7hMxRmiZKDRkvS7UMbhRGA0/QiP9grrJ2CoJiIYs0qb2ozP 6JVZA5QbVE+Y5BQtN3tQ5HRkBzRuMBc= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 1C222CE31E1; Thu, 19 Oct 2023 19:49:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48C9FC433CA; Thu, 19 Oct 2023 19:49:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697744972; bh=JxnxpQi8Ul6nOhB30Sf8ttPU+Mbj0MwnPDqKZ/PALpM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q/fE20KRyvJSGgRHegK3R+DBDTlM3NC4FaQxFC4fEJqSqwQHdqJucdhbh4cngKoMc 4Rii7MDRtomRT4L7TDzKSxzplwSoImsmMyfa3pLNK93O+F5ZWCTyb7IQdswuPcgchl 965fTzfU8pgybiLDqIrTq1WN72VSV27JSHJAoaMnrSmnzGcIde1GR1YtAwuXZXGr1W eg5GU5zj3caGORuA48hBOJgeswWu4AroqifVxo5HnxmR0uD99zC0Uig6ysPuqW9ijc ypsclOhxptVMU8Q7x6XKah1QWLn8ZPJiX2DEFntORfQiabj4NwIhRpZUTb/thUZHzA ufQlp0F+OjBaQ== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 4/5] mm/damon/lru_sort: avoid divide-by-zero in hot threshold calculation Date: Thu, 19 Oct 2023 19:49:23 +0000 Message-Id: <20231019194924.100347-5-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231019194924.100347-1-sj@kernel.org> References: <20231019194924.100347-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: B40C0180015 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: dumr9qrdmhh45js4tkb9dnw9fi5xpwam X-HE-Tag: 1697744975-189777 X-HE-Meta: U2FsdGVkX1/oubH4xk5Wx8JAJ684YpEBdGA9Q4hYRhJt9iruYfzRelDOP5iC0Zv8rp0qTMmTiLiUhQmTaSmbSCC75FSrCVwBEEvtGEVPs3nwf5PPzKo6yLEtvl1cs8OPWSCVK/FIZxswJYKB0kH1YbccJYbEjBRb7HP4AxIrjEW+GLplRPxB0D90JlDi+8ZOQUZQuPqaL6TCh0dbYJ5UuuOOXlUQ/D56AQ7Ni1dtLXj8awSMiHpDKp6nZQ54eRZ25Ls4XQfABusUJmDPaC6mN3sGLABE/IKc+DYpfiby7UHhl8o64deXoGwXxM52F5xgAeG8O+1suCC4qKzr9MRVhNEYeXGfz4qPe73T8EIZApxHQ6fdVeg64dvjgjczywjBecjug8zpOTbUCWIJMIpGJ0yAo13jDHm1Pk1uXghv8AMxVGVz4nTPLeZv0+wJyZl31D/bPMUKIeTpjNK4dFmwQi+VgcRC6BOCpUYz13r8HsUyeVIPEFQvRCPKVPCg3hbfmZbtjOyyJ/x/8GpKfw6fFqKwisNAoZRbpK1VcOIRo+73PAx0Jxq/HZPsF8orbVy3hWM7HH7gmo3PlPdZricUveOw1+efyQz30Hnmu7eKa/wW3XoXqjDfHqTYUjsKt67/wmOr00PBZwsGQuCmtuwH6bCW7kfyHFDD09Ib6mxI/dQXkJMgTnojBAyGRHCRzxEMo7b9ZyUO4xwMQfAjpgli7ZJKghbx0KG93jnjYZIEPwi1uJY3iRxv+e/sy8yHwIsoap62yiqIupki6cVxzhQyd+CI5tCw7cHsTNsYnuVnN3mEp5bQT6uY/NG5+mZT8iyv8/aLCoWJeyf5VzD3dmktbt8FAMukCDxpajGNNebcj0SJQ7UTr/6LnKQzLD7s2LnJzn02M1seIKiG1UzytQCUIkm11yw3dr9/NwZ5gK+DwWpjEp+fKk9sEJIh/zB37skDfiwsD6/jdzVusNh1/bs 4fOyb0KP nQKuRr9pcO6XEfPL5EG5B12ohNSt9a9cUedQGM92QLv3ZONWFPQqw/FuS+Sn4EdJEKAvIPtsiN/gxNc35wAfbG4OZTQvsFwINYionICujcWEVgOcWc6iNQf8rVoNY1EwRKk59LaxZDPLU9y5OUTpp3T9Ks/0iwkqIu5j8h2V0KzvdGI/zoO7d5iCT57Apc3z7Ej8z2sbTDy7lmAPygLpwnLutl+TiLolV5JmRIjjRSQb7BrPx6dgNysu7r74bIduUmL19ib+R7s+6Iz1sbfAL0ZwRyaO9ZJo8thrd X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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. 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) From patchwork Thu Oct 19 19:49:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13429774 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 CC5BDCDB465 for ; Thu, 19 Oct 2023 19:49:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B128A800B6; Thu, 19 Oct 2023 15:49:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A4CF6800B4; Thu, 19 Oct 2023 15:49:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 80414800B5; Thu, 19 Oct 2023 15:49:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 708D8800B4 for ; Thu, 19 Oct 2023 15:49:37 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 494B0C058C for ; Thu, 19 Oct 2023 19:49:37 +0000 (UTC) X-FDA: 81363250794.22.DF7D8E0 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf26.hostedemail.com (Postfix) with ESMTP id 75C61140015 for ; Thu, 19 Oct 2023 19:49:35 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=lNgSoOfs; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf26.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=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:in-reply-to:references:references:dkim-signature; bh=fTlqNdzbFdc9R72dERn2BM6lGJw+6/d2x02vllJOm3c=; b=wEXTDtoYguKeTapDij+fc9PQU/WUStENplmppKSqDk4RkPQ0dRSVETJIqMWLFIALvUhVMA TBwAql2mV3JJPGrwqSUIpNMvWQ75DNNs1N5xhAu1yNR3oy0MpLeMuYZWHo4+KTH8zuXExm C3lsCA+gVzsmo5/6Mt69QqU0ytYnySs= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=lNgSoOfs; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf26.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=1697744975; a=rsa-sha256; cv=none; b=PZxS0xz5oabw9ERs3UZ7/4my2Y6nl81cDbW3kx/Zb8zgnC1mUFQSVAYar3BKtrPuprRiUe zUuk+2mPYguecQw47Uuovwzu8wf/py2g3vwTt5UFnfiwRL13Mi9IHeY0TsTlj/pCD4vLiC ptbgSqR3sehhLCqrjPodgX+oNcIkDyw= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id 9B706B82A78; Thu, 19 Oct 2023 19:49:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6BB7C433C9; Thu, 19 Oct 2023 19:49:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697744973; bh=A7qQGX2x61HuX9WngSjrxy/tMdxThwG7cO+vlCnt/oI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lNgSoOfsk3ij3VEBkFziLTTOeodtOyWouwKEqFx+/Vc1mq4dpwxhRKSnXoRwsoucb xmeYm9yqQYBthSax96jDtI9ODtXEb7yTCOZCjdebg76CWIbn9yQVDy2jFkZj8rYXd7 oNq9xzrIQ25Tmf5XiVN2Aee+jPubzu3B3kxz7bjVCA4KdCtkt8pFLhJZjYzNyONzZQ PkVOy9fqQoNU8ok3jV6I4nU555Th406ewtAd/tBdhmST6Bpzl33dF6VUag7JudpLqA tc87Na/V54yov3Z36qOUQBq0gpwPA3O3j6ZH+zXwVdSxO1X3vjDD/8mnwLNYKGgs1n qQNgxlmk5W1XA== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/5] mm/damon/core: avoid divide-by-zero from pseudo-moving window length calculation Date: Thu, 19 Oct 2023 19:49:24 +0000 Message-Id: <20231019194924.100347-6-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231019194924.100347-1-sj@kernel.org> References: <20231019194924.100347-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 75C61140015 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 3ntniermrf4mdb64tm3euiz7ssire55y X-HE-Tag: 1697744975-433264 X-HE-Meta: U2FsdGVkX1+OMVBk53JHbsPVRDPtWWgwLRh7dsUqZdoCgggy1+eKYI0JGQdtbaDSnAXyBZg9rxtjfjJFMHsrmt1TyIF5a0QA984Fr3Nr07YKxt2ZRg7L+EBrpmsHwIxRZ2lTIBLoxbTEtXN68hWS6mt69vBwd72AFIfJ0weFNBWCwhya5Y9OYJVXwN/gGf6gCvWtO2WpLaJgNHWDR+oCOKL3v26ZEkQZyFOqHilKffG9KaWxZHRAJQhkKtUrKvxl7TN2EA8HcJ2nf/k8ueyv4kPySFNHL2dKwwVY5iffvRMov5Cm2btVykATCD6UomsIqTtAmn+ssSvnfqdUoD2WXzWZq7AXjW3vIqhr93xvA/rx7UBBhhgQ4o2VmSH/Z684W313c3czh68J2R6qRH9aPiMSXwGy5+CJsQPwe/SBXtIFaK4pO4ns3fs+36J+A4lsgwnTj1xf8qKXtPMl/hHEagptRVIGDR0Lv5HEbldD9sZrgrat5dQAMmeryUbVkfSzvI5qYCM3eU54/rXCqTrPYfFviMoA4cE8HBFQVY5SR/0YaNSbu8fhK9ld3RlpNdUxuLkXHoVnnWkzKXXNvC64aJG4KQOawXdYbI8W+GTYOMijqDOxbuHqAsRsRY24NJAfxWjyfswTHn5LBrYy/3IoY09vSaGoqjvWkszDoFBi4ZpWHSQBuN5PVNw0uqAL4338VJkvIi6EtRBMESU5oAUPm6PExjND0NZKShvsWovkZ+tt4E0mtc58OD/baoU8BKNIL7LkxjyGfEe7+5rm0AFlZzaqEAzcjuQ6uW68iMWaX3NU/U6QPmFpK687W0ZxH08SUfFFJzhGxqDWGhWjJVf0M950NOFr2u3au3l5eCI4dbv1K/R/4UCHVsm2tZ40GTS34G6IEXDZKDxhsq2HOWjeGfW91TQwcl4imXlKXsRUtoD7p79TM+2qb1Xb+4gVD3gwGcAhEzxPMS/WYatzIoA aWumovLI 9CImrnSmi87aOrzTN84msOyhlXeDqKB96eb7/sE3IxYu36XqqfkuZykWnRb0PuPZ/MMN7BJv/FJFq+URIDKkIWpaq3Dj1vffspHYZ35Wp46ZOggwZJvq05AGahmtQeY3P3+QjnZZl9BKN4TGDaDdDK+tz2MSC2/Dl1nJSCxs5gt/dTJTGpLWKQfLcCtBXXRxtOUFeaC0IIVCazXvWW/EGEFayBZdVd94DR+RixKraG5Ud4WI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: When calculating the pseudo-moving access rate, DAMON 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. Note that this is a fix for a commit that not in the mainline but mm tree. Fixes: ace30fb21af5 ("mm/damon/core: use pseudo-moving sum for nr_accesses_bp") Signed-off-by: SeongJae Park --- Note that this is for a patch in mm-stable that not yet merged into the mainline. mm/damon/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index e194c8075235..aa2dc7087cd9 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1665,7 +1665,7 @@ void damon_update_region_access_rate(struct damon_region *r, bool accessed, * aggr_interval, owing to validation of damon_set_attrs(). */ if (attrs->sample_interval) - len_window = attrs->aggr_interval / attrs->sample_interval; + len_window = damon_max_nr_accesses(attrs); r->nr_accesses_bp = damon_moving_sum(r->nr_accesses_bp, r->last_nr_accesses * 10000, len_window, accessed ? 10000 : 0);