Message ID | 20231019194924.100347-2-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 fe16csp616253vqb; Thu, 19 Oct 2023 12:49:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFf7npQkZwPnWOmTxwQwXaAziYqoQXfvSvq8OavSFXy9fDwhzOWVGTBT5/EwUjtp3rUI0Fh X-Received: by 2002:a17:902:6b47:b0:1c5:76b6:d94f with SMTP id g7-20020a1709026b4700b001c576b6d94fmr2948329plt.31.1697744985449; Thu, 19 Oct 2023 12:49:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697744985; cv=none; d=google.com; s=arc-20160816; b=SOkcIGHMZzzMVW7be/BhZp1N3CkSqHL0+rr3cFmEKAkrLCnt0M9PUVUZRH3Pz3cJZh aZwuuQFW48a9IGTI7KcTERS+HSMQCP5xiWDN71PGORZ4E2rR6t1LcZ+HBWAWY/ZfdE9x BNcnlM5Ckd2noBhAD9V7Xox81ZysTAjjF5mjGNb8//sf1ZzfvDSeN0z7ihN36qozmJlD e42YiXOgFa9FJp/aHIWMg/+Klgkxk0oDfJLSh5+3FORWD8Lqn3tgzwcF4aE55Al9hFnT hRu0eJ0QRcv5xMjJY6GgJmc4fliW5lWecd3yeDKqHwCw2EzT8J42COg6qczcO/4mFlHB HzeA== 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=J+W9qLA3WO5W8qkckKCVdeyrs/hKuMnVmg+YTOVRsQM=; fh=WXAAPMfSxLmsB2WJ8A0s7FPd+eTotx5bYas/XF5lzN4=; b=ufC3ugQLpr3JvUpJ+SPtvrY2UnukE6BvPQXLXi/185dwU8qcQDLR5QhTpLcyqbsTJc Cek/cC+v5bLsx3zbcAUDVjfsnKvTZBjUAeUQuFuyryNLwmBvz4eydiU8dxccFa8yxDbo t/UynhKwR4QkfGiHBG3dVPpfUtrCEpgMnhKDtPm/LRwQJe/wQRFV/Y3qES/R1vNfFcOm t/gsNq/xCHckq6pU5ZW1xBY3T3Cq5njqclcdANmmelj/iAFJvQ0HMwMnZ+PmfhVzutbm 4dA8xK5h5Ms9+nljG01x1bI1Lqk1Bm2wr6ZA1YB1elLyD6MEBJfzaYriYhNXOsN8Dc62 ZNGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Oe6x2sCU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id f15-20020a170902ce8f00b001bba894ac4asi195544plg.274.2023.10.19.12.49.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 12:49:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Oe6x2sCU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id B48988347B46; Thu, 19 Oct 2023 12:49:42 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346521AbjJSTte (ORCPT <rfc822;a1648639935@gmail.com> + 26 others); Thu, 19 Oct 2023 15:49:34 -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 S1346466AbjJSTtd (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 19 Oct 2023 15:49:33 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F745114; Thu, 19 Oct 2023 12:49:31 -0700 (PDT) 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 <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, 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 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 morse.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 (morse.vger.email [0.0.0.0]); Thu, 19 Oct 2023 12:49:42 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780214645685678466 X-GMAIL-MSGID: 1780214645685678466 |
Series |
avoid divide-by-zero due to max_nr_accesses overflow
|
|
Commit Message
SeongJae Park
Oct. 19, 2023, 7:49 p.m. UTC
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: <stable@vger.kernel.org> # 5.16.x
Signed-off-by: SeongJae Park <sj@kernel.org>
---
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);