[5/5] mm/damon/core: avoid divide-by-zero from pseudo-moving window length calculation
Message ID | 20231019194924.100347-6-sj@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp616362vqb; Thu, 19 Oct 2023 12:50:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE22N9pH/mGBw9ywP58KVySEiq5I6eWSylUy/NhY0NRO7705cFeP7/W/2+S2HMPkYYa0H/j X-Received: by 2002:a05:6a20:8412:b0:17b:3cd6:b1d7 with SMTP id c18-20020a056a20841200b0017b3cd6b1d7mr3916813pzd.43.1697745000233; Thu, 19 Oct 2023 12:50:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697745000; cv=none; d=google.com; s=arc-20160816; b=aorUY6aTANBwJ2mxRhEZ5EKM/Emby2enYw/gS0lRkMO44OAtzxbRuHluxy3lbc1s6F j+HkHRZ/2tVVAvbgDjM+DrsI/oXxaU8+fo7ersqisEZ540tr0dfccHeIPq5XqjF2z0xL O9iQeIMa2GzmAOUQ3Q2Zk4CEEJgaR6NA7A1tzUGgwnyA2wqWqVs51Xu3nbQdnvAwMLGd sbfWsItaRT8CkcUL3QJukWXx1K99YesQpke5B3HTw9LvrmI73FAZnPEzfPHc/HLa8mMF lt40Tp03PmaAMoJxkfiPHGeVXhcVN35C9ZNJdzwA4HyZNgwLGwwMjfh38QaJEOt2k2/E dWDw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fTlqNdzbFdc9R72dERn2BM6lGJw+6/d2x02vllJOm3c=; fh=BzdeVYqZhG5iuwuKJRNLP969rvCput73lx0iwx2zu7A=; b=BLvtFDEqATyA32Mj8B1loteqCocUz/RVhvYrBL6uOPutE3K7epnzfMHOycT4h0pMeT 6X+5ADUQToSAH7BCt3BGlb87VODro8NLvKNwqLFXy+bYQMwvdRBATdxlpv8UB3ID3DbJ ldP4j4ybcG+vRJF55V4I9277q3LGbrxfYQIaTx4yXJOPsMBgrAGz/xJWOosYoiDT7fCo i11ZiSzxpZMACtOm3+QWSKAx4TYr01jjd5/zRtO5NKr7eboutccPJ1SRMqlZ++P2s2WW qKZUE5FxO3KpqPBxepzHYjKYENcpbeKJhRGJY/Sku2eyOd0iVIdteMZFBCy//6/Y+Bmb +9Xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lNgSoOfs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id ay8-20020a1709028b8800b001c9d7d70d7bsi199891plb.4.2023.10.19.12.49.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 12:50:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lNgSoOfs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 5885681D68FA; Thu, 19 Oct 2023 12:49:57 -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 S1346545AbjJSTtn (ORCPT <rfc822;a1648639935@gmail.com> + 26 others); Thu, 19 Oct 2023 15:49:43 -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 S1346517AbjJSTte (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 19 Oct 2023 15:49:34 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FB5711F for <linux-kernel@vger.kernel.org>; Thu, 19 Oct 2023 12:49:33 -0700 (PDT) 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 <sj@kernel.org> To: Andrew Morton <akpm@linux-foundation.org> Cc: SeongJae Park <sj@kernel.org>, 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 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: <linux-kernel.vger.kernel.org> 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:57 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780214661218624924 X-GMAIL-MSGID: 1780214661218624924 |
Series |
avoid divide-by-zero due to max_nr_accesses overflow
|
|
Commit Message
SeongJae Park
Oct. 19, 2023, 7:49 p.m. UTC
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 <sj@kernel.org>
---
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);