Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp583820rdb; Thu, 19 Oct 2023 12:50:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHKtQJL0ld5+DEUDU5yWajZfwlxNzJ5gTkPnexy0OXGbdr+8fHFzsWCglbw39dUSlSl0aXo X-Received: by 2002:a17:902:c406:b0:1ca:3241:c679 with SMTP id k6-20020a170902c40600b001ca3241c679mr4158678plk.16.1697745000001; Thu, 19 Oct 2023 12:50:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697744999; cv=none; d=google.com; s=arc-20160816; b=D8FQo6r7Eg1yA4QPpzLevj2vUBe/S35sx27CLgn7xYL+3WnY25RcxC2bAbQ6mP+NWB tuKBST/3ClOB5pdESEvogIMAd72q4ATlUxEQs9amv0VYT9gcHNvNzRgJCBTd/tmhoMjp McF+OFys/ANDvFiFVJlzylFYenfhfQRFXTnYtE4urQzmrGMsMSGplEvQAZ70cw7oZ03F 8QVxbWsNXtqd4Fen0jd+QniDW3XgjL3iQBc/KlFd3QSrcEWaJMyZSqOYf0GdEjCuYRR8 39J/q1ugkj57pT/w+II/otk863qR9DilfEqG/OBNgJQm5mm2UspY0mOgwlFFwfkUzB9Q wU9Q== 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.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id j8-20020a170903024800b001c752da513asi161398plh.405.2023.10.19.12.49.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 12:49:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; 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.38 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 fry.vger.email (Postfix) with ESMTP id 6CB7F83F1CE5; Thu, 19 Oct 2023 12:49:43 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346514AbjJSTte (ORCPT + 99 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 ); 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 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 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 fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Thu, 19 Oct 2023 12:49:43 -0700 (PDT) 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); -- 2.34.1